Skip to content

Instantly share code, notes, and snippets.

@berdario
berdario / fbchatfix.user.js
Created July 26, 2011 15:34
fbchatfix chrome userscript
// ==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 December 16, 2013 17:58
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
: gcd ( a b -- c ) over zero? [ nip ] [ over mod swap gcd ] if ;
#! /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)
#!/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)
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)))
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
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
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

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:

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()