Skip to content

Instantly share code, notes, and snippets.

@rafacv
rafacv / getStyleClass
Created January 7, 2009 08:03
Returns the class style object passed as parameter
function getStyleClass(className) {
for (var s = 0; s < document.styleSheets.length; s++) {
if(document.styleSheets[s].rules) {
for (var r = 0; r < document.styleSheets[s].rules.length; r++) {
if (document.styleSheets[s].rules[r].selectorText == '.' + className) {
return document.styleSheets[s].rules[r];
}
}
} else if(document.styleSheets[s].cssRules) {
for (var r = 0; r < document.styleSheets[s].cssRules.length; r++) {
@rafacv
rafacv / is_cpf.js
Created September 23, 2009 12:17
Simple JS function to validate CPF numbers
// a simple js function to validate CPF numbers
function iscpf(c){
if(!isNaN(c))
c = ""+c;
var re = /^(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})\d{3}$/.exec(c);
if(!re)
return false;
var i = 2, j = 0, k = 0, g = re[1];
for(;i<re.length;i++)
if(re[i]!=g)
@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",
@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 / 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 / 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 / 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 / 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 / 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 / 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"}
]
}
}