Skip to content

Instantly share code, notes, and snippets.

View fgalassi's full-sized avatar

Federico Galassi fgalassi

View GitHub Profile
/**
* The `navigate` function takes a `Path` string that
* can contain parameter names using the `users/:username`
* syntax. Type it so that the `params` object provided
* as the second argument always contains a key for each variable
* in the `Path`.
*/
namespace parseUrlParams {
declare function navigate<U extends string>(
path: U,
@fgalassi
fgalassi / map.js
Created June 8, 2017 14:45
Map in very functional es6 style
let map = (func, [head, ...tail]) => head === undefined ? [] : [func(head), ...map(func, tail)]
map(n => n + 1, [1, 2, 3])
// [2, 3, 4]
def square_root(x, guess)
puts "guessing: #{guess}"
if guess * guess == x
guess
else
new_guess = (guess + x / guess) / 2
square_root(x, new_guess)
end
end
% The beauty of the right programming paradigm.
% Conway's Game of life in 4 lines of Octave code.
function new = life(board)
neighbours = conv2(board, [1 1 1; 1 0 1; 1 1 1], 'same')
new = neighbours == 3 | (neighbours == 2 & board)
end
% Create a 100x100 board and run the game in a GUI
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)
#!/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"
@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) {
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 }
})
// ====================================
// 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) {
@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"