This file contains 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
#!/usr/bin/env bash | |
# tested with bash 4.3 | |
cd_into() { | |
(cd $1) | |
} | |
list_directory() { | |
(ls $1 > /dev/null) |
This file contains 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
import functools as ft | |
class IAmAPig(type): | |
@classmethod | |
def _make_aux(cls, base, k, attribute): | |
super_meth = getattr(base, k, None) | |
if super_meth is not None: | |
@ft.wraps(attribute) | |
def aux(self, *args, **kwargs): | |
super_meth(self, *args, **kwargs) |
This file contains 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
import objc | |
import AddressBook as ab | |
import pprint as pp | |
def pythonize(objc_obj): | |
if isinstance(objc_obj, objc.pyobjc_unicode): | |
return unicode(objc_obj) | |
elif isinstance(objc_obj, ab.NSDate): | |
return objc_obj.description() |
This file contains 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
def make_mr(reduce_, f, base): | |
def mr(self): | |
if not self.children: | |
return base(self) | |
else: | |
mapped = map(f, self.children) | |
red = reduce_(mapped) | |
return red | |
# return reduce_(f(child) for child in self.children) | |
return mr |
This file contains 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
/* | |
* ===================================================================== | |
* | |
* Filename: trees.cc | |
* | |
* Version: 1.0 | |
* Created: 04/14/2013 11:20:59 | |
* Revision: none | |
* Compiler: gcc | |
* |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
____________________________________________________________ | |
| +--------------------------------------------------------+ | | |
| ! ^ ___ --- ! | | |
| ! / \ _--_ / \ /\ / \ ! | | |
| ! / \__/ \ / \_-___-- \ / \ ! | | |
| ! / \___/ --__/ --__- ! | | |
| +-------+-------+-------+-------+-------+-------+--------+ | | |
| 04/02 04/03 04/04 04/02 04/03 04/04 04/04 | |
This file contains 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
import unittest | |
from graph import Graph | |
class TestGraph(unittest.TestCase): | |
def test_init(self): | |
This file contains 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
import functools | |
class rusty_method(object): | |
def __init__(self, hits, chain_effect): | |
self.hits = hits | |
self.chain_effect = chain_effect | |
self.hit_memory = [] | |
def __call__(self, func): | |
def aux(that, *args): | |
self.hit_memory.append(args) |
This file contains 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
(ns recursive-tricks.recursive-tricks) | |
(defn uuid [] (str (java.util.UUID/randomUUID))) | |
(defn tail-recursive [f] | |
(let [state (ref {:func f :first-call true :continue (uuid)})] | |
(fn [& args] | |
(let [cont (:continue @state)] | |
(if (:first-call @state) | |
(let [fnc (:func @state)] |
This file contains 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
(ns unfold-examples | |
(:use [unfold-util])) | |
(defn unfold-tails [s] | |
(unfold empty? identity rest s)) | |
(defn unfold-map [f s] | |
(unfold empty? #(f (first %)) rest s)) |
NewerOlder