Skip to content

Instantly share code, notes, and snippets.

View ariera's full-sized avatar
🐢
Fixing the world. I'll let you know when I'm done.

Alejandro Riera ariera

🐢
Fixing the world. I'll let you know when I'm done.
View GitHub Profile
@ariera
ariera / README.markdown
Created July 17, 2011 17:15
Codebrawl::James MLO

Intro

This James script asks the user for the origin and destination stations of the MLO network and reports to him how much time he has before his train passes by.

MLO stands for the Metro Ligero Oeste, the tramway network of the west Madrid area

I have to admit it is not specially useful since recognition of spanish names is not the strongest points of the Mac speech recognition (my metro stop is called Somosaguas Sur and it is barely impossible for James to recognize it). Maybe I could translate the names into english (actually that could be fun! somosaguas becomes wearewaters XDDD)

Usage

@ariera
ariera / README.markdown
Created July 25, 2011 09:34
Codebrawl::TerminalAdmin

short_arel

What is this about?

Do you use ActiveRecord? Tired of writing in console all those verbose Arel methods? Well short_arel is for you!

The idea is to reduce to the minimum the numbers of characters you have to type to perform ActiveRecord queries. short arel just aliases long-named methods with its short version, so instead of having to write:

Post.where(:public => true).includes(:comments).order('edited_at ASC')

you could write

@ariera
ariera / README.markdown
Created August 7, 2011 16:23
Nestable, sortable and dragable categories

Nestable, sortable and dragable categories:

In the project I'm working on we wanted to have a Category model which we wanted to be nestable. But we also liked the user to have a draggable interface to manage and rearrange the order of his categories. So we chose awesome_nested_set for the model and jQuery.nestedSortable for the UI.

It took me some time to arrange things to work properly so I wanted to share my work in case it helps anybody.

Before beginning

you might want to take a look at a demo app

  1. go to: http://awesomenestedsortable.heroku.com/groups/
  2. click in show of any group
@ariera
ariera / README.markdown
Created August 11, 2011 09:41
A keyboard shortcut to run tests with watchr

A keyboard shortcut to run tests with watchr

When developing in rails I use watchr to run the tests each time a file is saved, but lots of times I find my self adding a whitespace or a newline and saving just to trigger watchr and run the tests.

I wanted to have is a simple keyboard shortcut (like F15) to tell watchr to run the last spec, and mpartel (thx! : ) gave me an idea on how to do it, so here it is:

Dependencies

Obviously you need watchr, but we're also going to need pgrep that will help us find out the pid of the watchr process. So go ahead and do

sudo port install proctools

@ariera
ariera / http_client_with_cache.coffee
Created September 8, 2011 14:40 — forked from johnthethird/http_client_with_cache.coffee
HTTPClientWithCache for Titanium in CoffeeScript
###
------> HTTPClientWithCache <------
This class is a wrapper around the standard Titanium.Network.HTTPClient(), but it adds a
few nice features:
* A cache backed by a SQLite database. All HTTPClientWithCache instances use the same database table, with
the primary cache key being a hash of the full URL (and any data parameters in a POST)
* The cache is automatically pruned before each query
* A retry mechanism, so that you can retry a particular query a number of times before failing.
@ariera
ariera / bookmarklet.html
Created December 19, 2011 21:01
Full Toolbar en el CKEditor de ComunidadUmbria
<a href="javascript:(function(){_my_script=document.createElement('SCRIPT');_my_script.type='text/javascript';_my_script.src='https://raw.github.com/gist/1498854/62cca0c124580741a3572a751d2f2569413ee37f/full_cke.js';document.getElementsByTagName('head')[0].appendChild(_my_script);})();">Full_CKE</a>
@ariera
ariera / readme.md
Created September 24, 2012 09:23
An example of mixins in Rails

With this you can do

Restaurant.all_with_photo #=> will return all the restaurants with a photo
User.first.photo_width #=> 65px

Restaurant.first.photo_url #=> "http://......"

@ariera
ariera / latency.txt
Created September 30, 2012 23:20 — forked from nahurst/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers Time Light Distance Approximate Light Distance
-------------------------- ---- -------------- --------------------------
L1 cache reference 0.5 ns 0.15 m Diagonal across your smartphone
Branch mispredict 5 ns 1.5 m Height of Natalie Portman
L2 cache reference 7 ns 2.1 m Height of Shaq
Mutex lock/unlock 25 ns 7.5 m Height of a school flag pole
Main memory reference 100 ns 30 m Half a Manhattan city block (North/South)
Compress 1K bytes with Zippy 3,000 ns 900 m Width of Central Park
Send 1K bytes over 1 Gbps network 10,000 ns 3,000 m Width of Manhattan
Read 4K randomly from SSD* 150,000 ns 45,000 m NYC to Hempstead on Long Island
@ariera
ariera / latency.txt
Created September 30, 2012 23:23 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@ariera
ariera / comentarios.md
Created December 27, 2012 12:40
Comentarios en los lenguajes de programación

Los comentarios

Todos los lenguajes de programación admiten una cosa que se llama comentarios

Cualquier linea que escribes en un archivo de ruby (por ejemplo) se ejecutará antes o después salvo si se trata de un comentario

En ruby los comentarios empieza con el caracter especial #, un ejemplo:

#esto es un comentario
puts "hola santi"