Skip to content

Instantly share code, notes, and snippets.

View fedelebron's full-sized avatar

Federico Lebrón fedelebron

View GitHub Profile
@fedelebron
fedelebron / usually.c
Created March 23, 2013 10:50
In homage to mullender.c. Linux, x86.
const char main[] = {
232, 0, 0, 0, 0, 89, 131, 193,
14, 186, 28, 0, 0, 0, 141, 65,
29, 255, 224, 109, 97, 105, 110,
32, 105, 115, 32, 117, 115, 117,
97, 108, 108, 121, 32, 97, 32,
102, 117, 110, 99, 116, 105, 111,
110, 46, 10, 195, 184, 4, 0, 0, 0,
187, 1, 0, 0, 0, 205, 128, 184, 1,
0, 0, 0, 187, 42, 0, 0, 0, 205, 128,
@fedelebron
fedelebron / Parser.hs
Created November 13, 2012 13:47
Simple LL(1) parser for a sums-and-products language in Haskell.
import Data.Map (Map, lookup, fromList)
import Data.Maybe
import Prelude hiding (lookup)
type ParserState s = [s] -- Stack
type ParserStateTransformer s = ParserState s -> ParserState s
type ParsingTable s = Map (s, s) (ParserStateTransformer s)
type ParsingError = String
data Parser s = MakeParser (ParsingTable s) (ParserState s)
@fedelebron
fedelebron / Testing.hs
Created October 5, 2012 15:19
Small Haskell test suite, my first actual Haskell code, years ago :)
type CasoDePrueba = (String,Bool)
type ListaDePruebas = [CasoDePrueba]
type SuiteDePruebas = [(String, ListaDePruebas)]
imprimirListaDePruebas :: ListaDePruebas -> (Integer, Integer) -> IO (Integer, Integer)
imprimirListaDePruebas [] (total, pass) = do
return (total, pass)
imprimirListaDePruebas (t : ts) (total, passed) = do
n <- imprimirCasoDePrueba t
imprimirListaDePruebas ts (total+1, passed+n) -- querías contadores? tomá!
@fedelebron
fedelebron / 24.cpp
Created April 9, 2012 09:24
24 solver, with no access to binary_function or function<...>, thanks to an outdated compiler. :) Still using C++11 though.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define forn(i, n) for(int i = 0; i < (n); ++i)
#define FUNC(i) (*(dispatch[funcs[i]]))
#define MFUNC(o) ([](double a, double b) { return a o b; })
using namespace std;
@fedelebron
fedelebron / Barriers.cpp
Created February 11, 2012 19:27
Short example...
bool dbresult, loggerresult;
if (!send(database, request)) dbresult = true;
if (!send(logger, request)) loggerresult = true;
if (dbresult || loggerresult) return -1;
@fedelebron
fedelebron / sym.py
Created December 3, 2011 14:54
Symmetric polynomial functions
from sage.combinat.sf.sfa import SFAElementary
from sage.rings.all import PolynomialRing
from sage.misc.misc import prod
def is_symmetric(p):
vars = p.variables()
if len(vars) == 1: return True
permutation = {}
for i in range(len(vars)-1):
@fedelebron
fedelebron / gist:1354704
Created November 10, 2011 12:02
Part of a puzzle
is_color(red).
is_color(blue).
is_color(yellow).
is_color(ivory).
is_color(green).
is_person(englishman).
is_person(spaniard).
is_person(norwegian).
is_person(japanese).
@fedelebron
fedelebron / sample_2sat.txt
Created October 3, 2011 05:43
Sample input for the 2-SAT solver.
2
2 4
-A -B
+A +B
+A -B
+B -A
3 6
+A -B
@fedelebron
fedelebron / 2sat.cpp
Created October 3, 2011 05:42
Linear 2-SAT solver.
#include <list>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
typedef unsigned int uint;
typedef vector<list<uint>> adj_list;
typedef vector<int> vint;
@fedelebron
fedelebron / GameOfLife.js
Created June 28, 2011 11:41
Game of Life in JS
(function() {
function GameOfLife(config) {
this.width = Number(config.width || 400);
this.height = Number(config.height || 300);
this.rows = Number(config.rows || 80);
this.cols = Number(config.cols || 120);
this.cellHeight = this.height / this.rows;
this.cellWidth = (this.width-1) / this.cols;