Skip to content

Instantly share code, notes, and snippets.

@rafacv
rafacv / list_comprehension.py
Created November 13, 2011 21:36
Comparison between list()'s and lists' comprehension implementation.
my_list = list(range(1000000))
for i in range(100):
other_list = [elem for elem in my_list]
@rafacv
rafacv / bf-ansic.c
Created September 27, 2010 13:29 — forked from lifthrasiir/bf.c
s[999],*r=s,*d,c;main(a,b){char*v=1[d=b];for(;c=*v++%93;)for(b=c%7?a&&(c&17?c&1?
(*r-=c-44):(r+=c-61):c&2?putchar(*r):(*r=getchar()),0):v;b&&c|a**r;v=d)main(!c,&
b-1);d=v;}
@rafacv
rafacv / dotnotation_clashingnames.rb
Created August 20, 2010 23:01
Contrived example of how dot-notation can avoid clashing names
context = {
:person => {
:name => "Melissa",
:friends => [
{:name => "Chris"},
{:name => "Tom"},
{:name => "PJ"}
]
}
}
@rafacv
rafacv / gist:522505
Created August 13, 2010 07:46
Callable bug with Pystache's View
>>> import pystache
>>> from pystache import view
>>>
>>> class Dummy(view.View):
... pass
...
>>> context = {'icecream': lambda flavor: "%s icecream" % flavor, 'title': 'Yummy'}
>>> template = "** {{title}}\n\n {{#icecream}}Strawberry{{/icecream}}"
>>>
>>> context2 = dict(context.items())
@rafacv
rafacv / ispis.js
Created May 4, 2010 17:18
Simple JS function to validate NIT/PIS/PASEP numbers
function ispis(pis) {
pis = pis.toString();
var weight = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
var sum = 0, digito = 0;
if (pis.length != 11 || pis.match(/\D/))
return false;
pis = pis.split("");
for (var i=0; i < 10; i++)
sum += weight[i] * pis[i];
digito = 11 - (sum % 11);
@rafacv
rafacv / fakecassandra.py
Created April 23, 2010 19:17 — forked from mmalone/fakecassandra.py
In-memory Cassandra-ish thingy
# In-memory Cassandra-ish thingy... useful for unit tests. Maybe useful for other
# stuff too? No support for SuperColumns, but that should be easy enough to add.
import bisect
import copy
from cassandra.ttypes import NotFoundException, Column, ColumnPath, ColumnOrSuperColumn
class SSTable(object):
@rafacv
rafacv / redis_pubsub_demo.rb
Created March 30, 2010 16:43 — forked from pietern/redis_pubsub_demo.rb
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
@rafacv
rafacv / vipy.sh
Created March 3, 2010 13:20 — forked from mmalone/vipy.sh
Simple shell script that locates a Python module and opens it in vi.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: vipy <python module>"
exit 1
fi
MODULE_LOCATION=`python -c "import $1; print $1.__file__.rstrip('c')"`
if [ -z $MODULE_LOCATION ]; then
@rafacv
rafacv / languages_of_world.html
Created March 1, 2010 02:04
Languages of world
<select id="most_common_languages" name="most_common_languages">
<option value="Afrikaans">Afrikaans</option>
<option value="Arabic">Arabic</option>
<option value="Bulgarian">Bulgarian</option>
<option value="Bengali">Bengali</option>
<option value="Bosnian">Bosnian</option>
<option value="Catalan (Valencia)">Catalan (Valencia)</option>
<option value="Chinese (Traditional)">Chinese (Traditional)</option>
<option value="Chinese (Simplified)">Chinese (Simplified)</option>
<option value="Danish">Danish</option>
@rafacv
rafacv / bcd.py
Created December 15, 2009 06:19
Outputs numbers from 0 to 150 in BCD
#!/usr/bin/env python
bcd_digits = {
"0": "0000",
"1": "0001",
"2": "0010",
"3": "0011",
"4": "0100",
"5": "0101",
"6": "0110",