Skip to content

Instantly share code, notes, and snippets.

View acadavid's full-sized avatar

Alejandro Cadavid acadavid

View GitHub Profile
@acadavid
acadavid / my_string.ex
Created December 3, 2015 22:00
Solution to StringsAndBinaries-4 (Programming Elixir)
defmodule MyString do
def calculate(to_calc) do
{f, op, s} = _calculate(to_calc)
apply(Kernel, op, [f, s])
end
def _calculate(t, acc \\ []) # Default value for acc
def _calculate([ ?\s | t ], acc), do: _calculate(t, acc) # Scape spaces
def _calculate([h|t], acc) when h in [?+, ?-, ?/, ?*] do
{to_digit(acc), List.to_atom([h]), to_digit(_calculate(t))}
@acadavid
acadavid / hex_to_bin.rb
Created October 13, 2012 00:17
Hex to bin
hex = "08 00 e4 db e2 f2 00 00"
result = ""
hex.split.each do |h|
result << h.hex.to_s(2).rjust(h.size*4, '0')
result << " "
end
puts result
def process_subscription(card_token, plan_id)
customer = PaymentLibrary::Subscription.create(:card => card_token,
:plan => plan_id)
end
@acadavid
acadavid / securing_rails_updates.md
Created March 8, 2012 04:57 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application by Peter Nixey

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


@acadavid
acadavid / .gitignore
Created December 23, 2011 12:31
39 gitignore
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*~
*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
@acadavid
acadavid / buscar_actividad.md
Created November 11, 2011 22:20
Buscar actividad

Nombre del método: BuscarActividad

Parámetros del método:

Filtro de Actividad

Nombre
Tipo de dato
@acadavid
acadavid / pi2.md
Created October 24, 2011 21:16
Proyecto Integrador 2

Almacenamiento de la información.

Las necesidades de nuestro módulo en términos de almacenamiento y consulta son diferentes a las de los demás módulos. La diferencia principal es el volumen de datos a almacenar y la concurrencia de las consultas. En primer lugar, nuestro módulo almacenará muchísimos más datos que los demás, sólo el hecho de publicar un contenido en el módulo de Contenidos almacenará una actividad en nuestro módulo, o el simple hecho de loggearse ó visitar un perfil.

Por las razones anteriormente expuestas, nuestra aplicación necesita un mecanismo altamente escalable, fácilmente provisto por una base de datos NOSQL. Además, los queries tienen que tener tiempos rápidos de respuesta. Por estas razones creemos conveniente utilizar el motor MongoDB que ofrece estas ventajas (frente a otras desventajas como la imposibilidad de hacer consultas sobre atributos anidados de una entidad, aunque en nuestro caso no es necesario esto).

En cuanto a XML, para las respuest

@acadavid
acadavid / CondorcetVoting.cpp
Created October 12, 2011 00:01
CondorcetVoting
void ranks(const string &v, map<char, int> &m){
for(int i=0; i<v.size(); ++i) {
m[v[i]] = -1;
}
int c=0;
for(map<char, int>::iterator it = m.begin(); it != m.end(); it++) {
it->second = c++;
}
}
int winner(vector<string> votes) {
@acadavid
acadavid / template.cpp
Created October 11, 2011 22:17
C++ Template
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
@acadavid
acadavid / gist:1275391
Created October 10, 2011 13:56 — forked from javan/gist:1168475
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen