Skip to content

Instantly share code, notes, and snippets.

View bpicolo's full-sized avatar
🐳
print(status)

Ben Picolo bpicolo

🐳
print(status)
View GitHub Profile
@bpicolo
bpicolo / gist:7742aeb377e1cc22263b
Last active August 29, 2015 14:03
More like Badskell
-- I am probably overcomplicating basic haskell
-- toDigits <=0 = []
-- toDigits 1230 = [1,2,3,0]
numDigits :: Integer -> Integer
numDigits n
| n <= 9 = 0
| otherwise = 1 + numDigits (n `div` 10)
@bpicolo
bpicolo / tracer dict
Created July 21, 2014 23:39
Watch for dict item setting in python
class TracerDict(object):
"""Watches changes on a dict for the keys passed in"""
def __init__(self, check_keys):
self.check_keys = check_keys
self._dict = {}
def __setitem__(self, key, value):
if key in self.check_keys:
@bpicolo
bpicolo / gist:71e408a45d6d0e727550
Created August 23, 2014 18:18
How to git subtree
Git subtree allows you to split directories out with their own git history.
mkdir subtree && cd subtree && git init
mkdir lib && mkdir src
touch lib/__init__.py && touch src/__init__.py
printf 'def add(a, b):\n return a+b\n' > lib/add.py
printf 'from lib.add import add\nprint add(1, 4)\n' > src/secret_stuff.py
git add . && git commit -m "We have a super cool adder"
So now running "python src/secret_stuff.py" we can see our super cool 5 printed out.
pub trait Html {
fn tag(&self) -> String;
fn closing_tag(&self) -> bool;
fn attrs(&self) -> String;
}
pub struct Input<'a> {
attributes: HashMap<String, String>,
field: Field<'a>,
@bpicolo
bpicolo / make_tmux.sh
Created October 20, 2015 04:28
Install tmux to homedir
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# Credit to the dude who created the initial version that I tweaked long ago
# exit on error
set -e
@bpicolo
bpicolo / gist:32a7fc775ce1810c88a0
Last active November 30, 2015 23:55
andrescusort
Dirty code:
import heapq
stuff = ["A Hard Day's Night", 'All About Eve', 'Boyhood', 'Citizen Kane', 'Das Cabinet des Dr. Caligari. (The Cabinet of Dr. Caligari)', 'E.T. The Extra-Terrestrial', 'Inside Out', 'It Happened One Night', 'King Kong', 'Laura', 'Metropolis', 'Modern Times', 'North by Northwest', 'Repulsion', "Singin' in the Rain", 'Snow White and the Seven Dwarfs', 'The Adventures of Robin Hood', 'The Godfather', 'The Third Man', 'The Wizard of Oz']
start = 1
end = []
while(stuff):
end.append([])
defmodule AController do
def index(conn, _params) do
user_devices = "foo"
conn
|> assign :user_devices, user_devices
|> render "index.html"
end
@bpicolo
bpicolo / Solutions
Last active December 21, 2015 23:18
A Tour of Go exercises (tour.golang.org)
Ex 70: Equivalent Binary Trees
*****************************************
package main
import "code.google.com/p/go-tour/tree"
import "fmt"
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int){
$entity = new Entities\Foo();
$entity->setField('foo');
$em->persist($entity);
$em->flush();
...
...
$entity->setField('bar');
$em->getRepository('Entities\Foo')->find(the_id)->getField() // foo
sub:
(register-sub
:tags
(fn [db _]
(reaction (vals (:tags @db)))))
handler:
(register-handler
:add-tag
(fn [db [text]]