Skip to content

Instantly share code, notes, and snippets.

View masylum's full-sized avatar
💅
Being fantastic

Pau Ramon Revilla masylum

💅
Being fantastic
View GitHub Profile
@masylum
masylum / etc_init.d_bouncy
Created December 8, 2011 14:31
bouncy init file
#!/bin/sh
DIR=/var/www/your_app
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NODE_PATH=/usr/local/lib/node_modules
BOUNCY = /usr/local/bin/bouncy
test -x $BOUNCY || exit 0
case $1 in
start)
@masylum
masylum / tuesday_birthday.py
Created December 2, 2011 16:00
The tuesday birthday problem
import random
print '''
You meet a man on the street and he says, "I have two children and one is a son born on a Tuesday."
What is the probability that the other child is also a son?
'''
def get_combinations():
children = ('s', 'd')
weekdays = tuple(range(1, 8))
@masylum
masylum / jader.js
Created December 1, 2011 16:31
jader.js
var dir = __dirname + '/app/templates/conversations'
, finder = require('findit').find(dir)
, fs = require('fs')
, _ = require('underscore')
, templates = {}
, num_templates = 0
, all_scanned = false
, jade = require('jade');
function startServer() {
@masylum
masylum / autocomplete_location.js
Created September 2, 2011 12:48
Autocomplete locations using yahoo woeid
/*globals APP*/
(function () {
var LOCATION = {}
, cache = {}
, jqXHR = null;
function _getCoords(place) {
return [
place.centroid.latitude + ',' + place.centroid.longitude
@masylum
masylum / j.js
Created July 7, 2011 13:29
Port of a.rb to nodejs. Minimal testing library! 376bytes!
function j(){var a=[],b=0,c="",d=[],e="\033[3",f="\n";return function g(h){h?(a=
a.concat(h),b++):(h=new Date,a.map(function(a){a.call(g,function(a){if(!a)try{
throw Error()}catch(b){d.push(e+"1mFailure:"+b.stack.split(f)[3]+e+"9m")}c+=e+(a
?"2m.":"1mF")})}),console.log([c,e+"9m"+(new Date-h)+"ms",b+" tests, "+c.length+
" assertions, "+d.length+" failures",d.join(f)].join(f)))}}
// Example usage
var test = j();
test([
@masylum
masylum / challenge_1.hs
Created April 14, 2011 11:58
Haskell is cool
import Data.Char
import Numeric
rotate :: [a] -> [a]
rotate (x:xs) = xs ++ [x]
isRotated :: Eq a => [a] -> [a] -> Bool
isRotated xs ys = any (==xs) (take (length ys) $ iterate rotate ys)
binaryToChar :: String -> Char
let divisors n = [x | x <- [1..n], n `rem` x == 0, x /= n]
let subsets xs = (map concat . sequence) [ [[],[x]] | x <- xs ]
let sumSubsets xs = [sum x | x <- subsets xs, x /= []]
let challenge = [x | x <- [1..553], sum(divisors x) > x, all (/=x) (sumSubsets $divisors x)]
var A = ['01001100', '01101000', '01010000', '01010011', '01001001', '01000011', '01101000', '01101001', '01110110', '01101001', '01110000', '01101100', '01100010', '01000111', '01101000', '01111010', '01100101', '01111001', '01101101', '01100001'],
B = ['10010001', '01011110', '01100101', '10011010', '10000010', '11110000', '11010000', '00101101', '11111000', '11010110', '11100000', '00011011', '01101110', '11110000', '01101100', '01101010', '11001010', '11001011', '01101110', '01110010'],
rotate = function (shift, str) {
return str.slice(1) + shift;
},
isRotated = function (a, b) {
return [].some.call(b, function (el) {
return b = rotate(el, b), a === b;
@masylum
masylum / formidable_test.js
Created January 4, 2011 20:13
Formidable fails if the request is already emited. formidable.parse fails if an asynchronous event happens before.
var formidable = require('formidable'),
http = require('http'),
sys = require('sys');
server = http.createServer(function(req, res) {
req.pause();
req.on('data', function(buffer) {
console.log('data parsed');
});
@masylum
masylum / s3upload.js
Created December 19, 2010 17:48
Upload files directly to s3
function upload (req, res) {
var Formidable = require('formidable'),
form = new Formidable.IncomingForm();
form.encoding = 'utf-8';
form.onPart = function (part) {
if (!part.filename) {
form.handlePart(part);
} else {
(function () {