This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AController do | |
def index(conn, _params) do | |
user_devices = "foo" | |
conn | |
|> assign :user_devices, user_devices | |
|> render "index.html" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$entity = new Entities\Foo(); | |
$entity->setField('foo'); | |
$em->persist($entity); | |
$em->flush(); | |
... | |
... | |
$entity->setField('bar'); | |
$em->getRepository('Entities\Foo')->find(the_id)->getField() // foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub: | |
(register-sub | |
:tags | |
(fn [db _] | |
(reaction (vals (:tags @db))))) | |
handler: | |
(register-handler | |
:add-tag | |
(fn [db [text]] |
OlderNewer