Skip to content

Instantly share code, notes, and snippets.

View fgalassi's full-sized avatar

Federico Galassi fgalassi

View GitHub Profile
module Enumerable
class MapEnumerator
instance_methods.each {|m| undef_method m unless m =~ /__/}
def initialize(enum)
@enum = enum
end
def method_missing(name, *args)
@enum.map {|e| e.send name, *args}
var Compose = require("compose")
var livingThing = Compose({
alive: false,
isDead: function() {
return !this.alive
},
isAlive: function() {
return this.alive
},
@fgalassi
fgalassi / README
Created May 10, 2012 23:13 — forked from shayarnett/README
Snippet generator for RubyMotion ctags (UltiSnips)
Generate ctags with `rake ctags`
Run snipper.rb
Move motion.snippets into ~/.vim/UltiSnips/ruby/
@fgalassi
fgalassi / gist:3393132
Created August 19, 2012 07:15
Ruby Koan triangle_2 project
def triangle(*sides)
raise TriangleError if [
sides.count != 3,
sides.any? {|side| side < 1},
sides.max >= sides.reduce(:+) - sides.max
].any?
case sides.uniq.count
when 1 then :equilateral
when 2 then :isosceles
else :scalene
@fgalassi
fgalassi / git_svn_update_all.sh
Created August 23, 2012 16:16
Update git-svn repository and externals
#!/bin/sh
root=`git rev-parse --show-toplevel`
echo "Moving to root: $root"
cd $root
echo "Rebasing current directory"
git svn rebase
echo "Looking for externals"
// ====================================
// Example: Nesting callbacks to produce serial requests
server.on('request', function(req, res) {
//get session information from memcached
memcached.getSession(req, function(session) {
//get information from db
db.get(session.user, function(userData) {
//some other web service call
ws.get(req, function(wsData) {
Browser.prototype.isGradeA = function() {
var browser = this
browser.on("response", function(res, target) {
var window = browser.window
var document = browser.document
var onMobileInitMakeGradeA = function() {
if (window.$) {
window.$(document).on("mobileinit", function() {
window.$.mobile.gradeA = function() { return true }
})
@fgalassi
fgalassi / gist:4167685
Created November 29, 2012 08:54
test.coffee
describe "wait after pressButton", ->
before (done)->
brains.get "/two-timers-only-the-first-useful", (req,res)->
res.send """
<html>
<body>
<button id="pressMe">press me</button>
<script>
var button = document.getElementById("pressMe")
button.addEventListener("click", function(ev) {
#!/usr/bin/env bash
if [ "$1" == "" ]; then
echo "Usage: deploy <command>"
echo "Execute <command> in the mirror of the dir you are in under /var/www"
echo "e.g. deploy php scripts/BusinessKnowledgeImport.php --force --only-external-rules"
exit 1
fi
deploy_dir="/var/www"
var expect = require("chai").expect
var gameOrig = "../game"
var gameGood = "../game.good"
var capturingConsole = function(action) {
var log = console.log
var logs = []
global.console.log = function(msg) {
logs.push(msg)