Skip to content

Instantly share code, notes, and snippets.

@berdario
berdario / fbchatfix.user.js
Created Jul 26, 2011
fbchatfix chrome userscript
View fbchatfix.user.js
// ==UserScript==
// @name fbchatfix
// @match http://*.facebook.com/*
// @match https://*.facebook.com/*
// ==/UserScript==
function addfix() {
var script = document.createElement("script");
script.setAttribute("type","text/javascript");
@berdario
berdario / gcd.factor
Created Dec 16, 2013
Both snippets are mostly the same: the factor solution is a recursive word, while the python one has an imperative iteration. The complexity of the function (in number of steps) is linear with the size of the smaller input
View gcd.factor
: gcd ( a b -- c ) over zero? [ nip ] [ over mod swap gcd ] if ;
View calc.py
#! /usr/bin/env python
from enum import Enum
from numbers import Number
from operator import add, sub, mul, truediv, mod
class Operation(Enum):
PLUS = (add, 6)
MINUS = (sub, 6)
MULT = (mul, 7)
View friends.py
#!/usr/bin/env py.test
from collections import deque, defaultdict
class Friends:
def __init__(self):
self.graph = defaultdict(set)
def make_friend(self, name1, name2):
self.graph[name1].add(name2)
View helloclick.py
import click
@click.group()
def pew():
pass
mkvenv_command = lambda f: pew.command()(
click.option('--python', '-p', default='python')(
click.option('-i', multiple=True)(f)))
View buckets.py
from __future__ import print_function
from numpy.random import binomial
from random import sample
from functools import partial
from operator import add, itemgetter
from itertools import takewhile
# Problem:
# You are given 10 opaque bags containing large numbers of red balls
View Main.hs
import Paths_hdoit (version)
import Data.Version (showVersion)
import Options.Applicative
data Arguments = Arguments
{ version :: Bool,
argCommand :: Command
} deriving Show
data Command = Add (Maybe String) | Base deriving Show
View ioexample.hs
import Data.Functor.Identity (runIdentity)
import Control.Monad (replicateM)
import Control.Monad.State.Lazy (state, evalState)
getInts :: IO [Int]
getInts = fmap (map read . words) getLine
f = do
n:q:_ <- getInts
els <- replicateM n getInts
View keybase.md

Keybase proof

I hereby claim:

  • I am berdario on github.
  • I am berdario (https://keybase.io/berdario) on keybase.
  • I have a public key whose fingerprint is 3F8D 5351 8012 716C 4EEF 7DF6 7B49 8306 B3BF 75A0

To claim this, I am signing this object:

View fold.scala
import scala.language.higherKinds
import scala.collection.generic.CanBuildFrom
import scala.collection.GenTraversableOnce
def map[A, This[A] <: Traversable[A], B, That](o: This[A])(f: (A) => B)(implicit bf: CanBuildFrom[This[A], B, That]): That = {
(o.foldLeft (bf.apply()) ({(a, b) => a += f(b)})).result()
}
def filter[A, This[A] <: Traversable[A]](o: This[A])(f: (A) => Boolean)(implicit bf: CanBuildFrom[This[A], A, This[A]]): This[A] = {
(o.foldLeft (bf.apply()) ({(a, b) => if (f(b)) a += b else a})).result()