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 / creditcard.coffee
Created May 11, 2012 13:37 — forked from jrom/creditcard.coffee
Credit Card number validation in Coffee Script
# Ported from https://github.com/jzaefferer/jquery-validation/blob/master/jquery.validate.js
creditcard = (value) ->
# accept only spaces, digits and dashes
if /[^0-9 \-]+/.test(value)
return false
nCheck = 0
nDigit = 0
bEven = false
@masylum
masylum / prop.js
Created May 11, 2012 09:50
Pseudo `&:foo` implementation in javascript
function prop(propName) {
return function(obj) {
var property = obj[propName];
if (typeof property === 'function') {
return property();
} else {
return property;
}
}
}
@masylum
masylum / node-server.js
Created February 2, 2012 14:32 — forked from jrom/node-server.js
Super simple node file server
require('http').Server(function (req, res) {
require('fs').createReadStream(__dirname + require('url').parse(req.url).pathname).pipe(res);
}).listen(9000);
@masylum
masylum / errorable.js
Created January 5, 2012 16:59
Errorable
/**
* Errorable
*
* Provides functionality to react when server-side validations fail.
* This module exports 4 methods than you can use on your views.
*
* - onError
* - onSuccess
* - addError
* - removeError
@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