Installing Vim on Crunchbang

Crunchbang (also refered to as simply #!) is a minimal Debian distribution that I’ve fallen in love with. I switch from OSX to Crunchbang every now and then, since I plan #! to be my primary OS when my MacBook Air dies. Crunchbang comes with Vi installed. This is how to install Vim, which will also install the vim command line tool.

If you go to the Vim downloads page and search for Unix builds, you’ll be directed to this page. However, I got to some errors following this guide, due to missing dependencies. Basically, what I had to do, was installing those dependencies first:

Unless you chose to install the development tools when you first installed #!, you might need to add mercurial to the previous command.

Now you can follow with the instructions in Vim.org, that I post here too for reference:

Now, next time a Vim version is released, you can just go and fetch the changes, and build it again:

Accessing instance variables in Ruby

Classes may have instance variables that are not explicitly in the public interface – this is, they don’t have a corresponding reader method. These variables can still be accessed with instance_variable_get, a method of Object class. Consider the following example:

 

If we make an instance of Example and call #name, we’ll get a NoMethodError, since there is actually no name method.

We can get the value of @name with instance_variable_get:

The returned value will be that of the current state of the variable when we retrieve it:

Hello, Vim

For years, I have been using eternal text editors for programming. When I was doing mostly PHP sites that were “deployed” (ehem) via FTP, Espresso was my editor of choice, because I liked (and still like) the built-in FTP client that lets you sync files with the server. Then, when I started to write Ruby and working on code that wasn’t uploaded via FTP, I switched to Sublime Text. From it, I enjoyed the fact that the default theme is already cool and that it automatically wraps strings, method calls and so many other things: I had to type less, which is always fine.

However, for the last couple of months I have been getting rid of a lot of stuff in my life; things that I don’t actually need and that just take space and effort to move around. Books, too much clothing, useless objects, etc. Software is part of this. I’ve been trying to use less and less external software (that is, software that needs to be installed) and just go on with the default stuff or web software when I need some specific functionality. My laptop is lighter than ever, and I’m less dependent on what’s in it.

Two days ago I started using Vim, the text editor I thought I’d never use do to its bad reputation as a hard learner. And, to my surprise, it feels so good. I started with vimtutor, which makes a 30-40 minutes introduction to Vim by practice, and after that I was able to set to some basic settings and start using it. I love having all my workspace in one single window and still getting cool features like autocompletion (using tab) or autoindenting.

Here is my very first version of settings for Vim, using Gruvbox theme.

La cursa d’obstacles, o com perdre un potencial usuari

Aquests dies estic buscant ofertes de feina que m’ofereixin millor sou, estabilitat de contracte i, a ser possible, en una empresa que tingui una cultura de programació similar a la meva. Vaig veure una oferta interessant a Infojobs que cobria les dues primeres necessitats: millor sou, estabilitat. Vaig intentar (sí, intentar) apuntar-m’hi, però al final vaig desisitir a causa de totes les coses que Infojobs em demanava fer abans de poder accedir a inscriure’m/respondre a l’orferta.

A qualsevol portal de feines de programació, un email per donar-se d’alta com usuari és suficient per poder accedir a les ofertes i respondre-les, però a Infojobs volen un munt d’informació teua: contacte, naixement, experiències laborals prèvies, estudis, etc. Terrible. Al final vaig optar per buscar l’empresa i escriure-lis directament.

Posar obstacles als usuaris que volen utilitzar el teu servei és una estratègia pèsima. Tot el paquet d’informació personal hauria de ser opcional, un plus, però no un requisit.

Vull fer Open Source, i encara no sé com (II)

Just ahir deia que voldria treballar en projectes Open Source, propis o aliens, però que encara no sé com. L’afirmació té part d’ironia, perquè saber-ne, en sé i, és més, ho faig. Però per algun(s) motiu(s) que no acabo de tenir clar(s), aquestes aportacions no sempre m’acaben d’omplir.

Generalment, la motivació per llançar un projecte ha sorgit d’una necessitat pròpia, i enlloc de fer una solució puntual de qualsevol manera he optat per realitzar una eina amb vocació de ser utilitzada per més gent amb la mateixa necessitat. Però, sovint, passada la necessitat passada la motivació. Quan es tracta de projectes aliens, generalment hi he arribat a partir de la necessitat d’un projecte en el que estiguès treballant, amb el mateix destí: passada la necessitat, morta la motivació (o morta la disposició). Però el que no mor són les ganes d’enrolar-me en algun projecte engrescador en el que treballar de manera sostinguda.

I potser és per una fantasia, la fantasia que un projecte a llarg plaç em pot omplir més que aportacions puntuals o projectes de curta vida. O potser perquè… ves a saber. Who cares, que diuen. La qüestió és que ara mateix em motiven els següents projectes:

  • Rails API: una versió light de Rails per a construir APIs.
  • Collection+JSON: un format d’hipermèdia per a APIs, que em sembla que pot esdevenir estàndard i pel qual encara hi ha poques eines a l’abast.
  • Active Model Serializers: serialitzadors per a Rails.
  • Kramdown: un convertor de markdown a diferents formats. M’interessa, particularment, el convertor a format de text obert (F)ODT.

No tinc ni el temps ni els recursos com per dedicar-me a tots ells, de manera que ara per ara estic hiper bloquejat en plan què faig. La paradoxa de voler fer tantes coses que no en fas cap per no decidir-te per quina començar. L’Open Source és com la vida, veges tu. Qui ho havia de dir!

Vull fer Open Source, i encara no sé com

Fa dies, més aviat setmanes, més aviat mesos, que tinc unes ganes enormes de col·laborar en projectes Open Source. Per mi, l’OS agrupa dues grans aspiracions vitals: la creativitat i la transformació social. Treballar en projectes OS em permet programar d’una manera diferent a com acostumo a fer-ho al dia, a resoldre problemes diferents, i això és creatiu; treballar en projectes OS em fa partícip d’una manera de crear tecnologia que redefineix les relacions socials de propietat i que genera un espiral de cooperació i treball comú com segurament no ha exisit mai abans. El problema, però, és que encara no sé com fer-ho.

A nivell individual, he desenvolupat alguns projectes que he publicat com a Open Source, com un generador de codi per a WordPress, un framework ultra minimal per webs sense base de dades però que volen rutes boniques i suport multilingüe, una mena de broma per omplir de text documents HTML per fer proves de maquetació, o un mixin de SASS per generar estructures de taules a partir de llistats de definició (en un intent de superar el gran problema de les taules a les pantalles petites). Al moment d’escriure aquest article també tinc a mig coure un projecte, específic per a Rails, per serialitzar dades seguint el format Collection+JSON. En la mesura del possible i de les meues capacitats, també he anat fent alguna contribució a projectes existents. I no obstant, encara no sé com fer-ho.

I arribats al tercer i últim paràgraf, ja no sé si és que no sé com fer-ho o si és que no estic satisfet amb l’impacte de la meva feina. I bé, segurament ja ho sé, ara.

Rails, and its things

Today I forgot my laptop at home and had to do an emergency installation of Ruby, Git and Rails on my sister-in-law’s (yes, this is a real story). After all the thing, I finally ran gem install rails. That’s the list of all the dependencies that were installed by Rails. I just thought it’d be funny to post it here.


$ gem install rails

Fetching: thread_safe-0.3.4.gem (100%)
Successfully installed thread_safe-0.3.4
Fetching: minitest-5.4.2.gem (100%)
Successfully installed minitest-5.4.2
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: i18n-0.7.0.beta1.gem (100%)
Successfully installed i18n-0.7.0.beta1
Fetching: activesupport-4.1.6.gem (100%)
Successfully installed activesupport-4.1.6
Fetching: erubis-2.7.0.gem (100%)
Successfully installed erubis-2.7.0
Fetching: builder-3.2.2.gem (100%)
Successfully installed builder-3.2.2
Fetching: actionview-4.1.6.gem (100%)
Successfully installed actionview-4.1.6
Fetching: rack-1.5.2.gem (100%)
Successfully installed rack-1.5.2
Fetching: rack-test-0.6.2.gem (100%)
Successfully installed rack-test-0.6.2
Fetching: actionpack-4.1.6.gem (100%)
Successfully installed actionpack-4.1.6
Fetching: activemodel-4.1.6.gem (100%)
Successfully installed activemodel-4.1.6
Fetching: arel-5.0.1.20140414130214.gem (100%)
Successfully installed arel-5.0.1.20140414130214
Fetching: activerecord-4.1.6.gem (100%)
Successfully installed activerecord-4.1.6
Fetching: mime-types-2.4.3.gem (100%)
Successfully installed mime-types-2.4.3
Fetching: mail-2.6.1.gem (100%)
Successfully installed mail-2.6.1
Fetching: actionmailer-4.1.6.gem (100%)
Successfully installed actionmailer-4.1.6
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: railties-4.1.6.gem (100%)
Successfully installed railties-4.1.6
Fetching: bundler-1.7.4.gem (100%)
Successfully installed bundler-1.7.4
Fetching: sprockets-3.0.0.beta.2.gem (100%)
Successfully installed sprockets-3.0.0.beta.2
Fetching: sprockets-rails-2.2.0.gem (100%)
Successfully installed sprockets-rails-2.2.0
Fetching: rails-4.1.6.gem (100%)
Successfully installed rails-4.1.6
Parsing documentation for actionmailer-4.1.6
Installing ri documentation for actionmailer-4.1.6
Parsing documentation for actionpack-4.1.6
Installing ri documentation for actionpack-4.1.6
Parsing documentation for actionview-4.1.6
Installing ri documentation for actionview-4.1.6
Parsing documentation for activemodel-4.1.6
Installing ri documentation for activemodel-4.1.6
Parsing documentation for activerecord-4.1.6
Installing ri documentation for activerecord-4.1.6
Parsing documentation for activesupport-4.1.6
Installing ri documentation for activesupport-4.1.6
Parsing documentation for arel-5.0.1.20140414130214
Installing ri documentation for arel-5.0.1.20140414130214
Parsing documentation for builder-3.2.2
Installing ri documentation for builder-3.2.2
Parsing documentation for bundler-1.7.4
Installing ri documentation for bundler-1.7.4
Parsing documentation for erubis-2.7.0
Installing ri documentation for erubis-2.7.0
Parsing documentation for i18n-0.7.0.beta1
Installing ri documentation for i18n-0.7.0.beta1
Parsing documentation for mail-2.6.1
Installing ri documentation for mail-2.6.1
Parsing documentation for mime-types-2.4.3
Installing ri documentation for mime-types-2.4.3
Parsing documentation for minitest-5.4.2
Installing ri documentation for minitest-5.4.2
Parsing documentation for rack-1.5.2
Installing ri documentation for rack-1.5.2
Parsing documentation for rack-test-0.6.2
Installing ri documentation for rack-test-0.6.2
Parsing documentation for rails-4.1.6
Installing ri documentation for rails-4.1.6
Parsing documentation for railties-4.1.6
Installing ri documentation for railties-4.1.6
Parsing documentation for sprockets-3.0.0.beta.2
Installing ri documentation for sprockets-3.0.0.beta.2
Parsing documentation for sprockets-rails-2.2.0
Installing ri documentation for sprockets-rails-2.2.0
Parsing documentation for thor-0.19.1
Installing ri documentation for thor-0.19.1
Parsing documentation for thread_safe-0.3.4
Installing ri documentation for thread_safe-0.3.4
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Done installing documentation for actionmailer, actionpack, actionview, activemodel, activerecord, activesupport, arel, builder, bundler, erubis, i18n, mail, mime-types, minitest, rack, rack-test, rails, railties, sprockets, sprockets-rails, thor, thread_safe, tzinfo after 640 seconds
23 gems installed

Adéu 2.0

Fa massa temps que ho penso, així que avui he fet el pas. Fa dies que em sento estúpid quan agafo el mòbil i vaig passant parrafades i parrafades de text amunt i avall, esperant trobar-hi no sé què. Fa dies que sento la pressió del mòbil a la butxaca, urgint per sortir. Fa dies que veig que Twitter és un lloc on vomito coses que generalment no diria perquè o bé són massa estúpides per a ser dites en públic, o bé no interessen a ningú més a que a mi i els meus, o bé perquè tan sols omplen el món de més soroll. Fa dies que observo que, per mi, les xarxes sovint són un refugi pel tedi, però que alhora em prevenen d’afrontar el tedi. Fa dies que me n’adono que les xarxes socials ens serveixen més per enredar-nos en debats estèrils, parcials i farcits de malentesos que no per construir, entendre’ns o, el més important, resoldre (això tan sols es fa en persona, camarades). Fa dies que utilitzo totes aquestes xarxes pensant què putes merdes és això, què aporten d’interessant a la meua vida, i una i altra vegada arribo al buit; al buit.

Potser en algun moment ha tingut sentit o utilitat per mi estar present a les xarxes socials, però ja no. Fa un temps vaig decidir donar-me de baixa de Facebook. Avui ho faig d’Instagram i Twitter.

Em seguireu trobant aquí, on si hi escric ho faig amb una mica més d’atenció. Per la resta, els amics ja sabem on trobar-nos.

Salut :-)

Testing with arrays, the useful way

We’ve all seen this sometime when a test fails:

Failed assertion, no message given.

Now, I like using arrays in tests because they allow me to test a lot of cases with less code. A simple (and dummy) test could be:

However, when running this test, we will get the quite useless message above: Failed assertion, no message given. Right, we know the test failed, but we don’t know which case made it fail.

We can easily know with an often misused attribute of assert: message. As the docs say, we can pass a message together with an assertion, and it will be used in case of failure.

Now, when running this test, we know that the number 2 makes the test fail. It is so simple, but how often we forget!

Q&A about Collection+JSON

Note: The content in this post is not mine. It is just a collection of questions and answers from the Collection+JSON discussion group. I’ve been working with this hypermedia-type lately, and ran into many doubts. Reading through the disscussion group was time consuming, so I’ve gathered this as a future reference for myself and others. However, this should not stop you from doing your own research and spend some time reading the docs and the discussions.

General

How does a Collection+JSON response look like?

Isn’t this C+J thing very limited? It should do this, and that, and this other thing too…

I also had this feeling. Read this thread, please, to distinguish beetwen C+J concerns and applciation concerns.

PS: Read it.

Items / Data

What about nested data (i.e. model associations)?

Amudsen (edited): Cj was initially designed to not support embedded objects or deep graphs. However, there is at least one extension registered called inline Collections. If nesting within a representation is essential, Cj will not be a good fit for you w/o a specific extension.

Source here.

Templates

What if different templates for POST and PATCH are needed?

Amudsen (edited): The assumption in Cj is to use the template for both updates (PUT) and creates (POST). This is based on the idea that the data set written in both cases is the same. In cases where the update action does not match the create action details, the approach I suggest is to use a link in the item and points to a representation that has the needed template. There is a problem here in the that second representation looks like a “create” description. I hack around this by telling the client app that when following an “edit” link, you SHOULD use the PUT method. Again, this is convention, not spec.

A way around this assumption that I am making is to extend the template to add a method argument. But that’s an extension I’ve not registered and not heard a lot of request for yet.

I should also point out that at least one “templates collection” extension has been registered.

Source here.

What if a field needs options, as for the select, checkboxes or radio?

The C+J spec does not consider this, but a workaround (that you’ll need to build support for) is:

Source here.