Skip to content

Instantly share code, notes, and snippets.

View hcarvalhoalves's full-sized avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
@hcarvalhoalves
hcarvalhoalves / iterm.sh
Created March 17, 2017 02:43
Shell functions to command iTerm2 via AppleScript
#!/bin/env bash
function tt() {
osascript &>/dev/null <<EOF
tell application "iTerm2"
tell current window
create tab with default profile command "$@"
end tell
end tell
EOF
@hcarvalhoalves
hcarvalhoalves / oblique.sh
Last active January 3, 2017 01:04
Oblique strategies tip of the day
#!/usr/bin/env bash
# From: https://en.wikipedia.org/wiki/Oblique_Strategies
strategies=(
"(Organic) machinery"
"A line has two sides"
"A very small object Its center"
"Abandon desire"
"Abandon normal instructions"
// Uses https://github.com/krasimir/EventBus
var app = (function (document, bus) {
function appInit(event, appstate) {
var response = prompt("Foo?");
if (response == "foo") {
bus.dispatch("render", this, {"status": "ok"});
} else {
bus.dispatch("render", this, {"status": "errou-mane"});
from scipy.spatial.distance import euclidean
import numpy as np
from __future__ import division
def periodic_distance(a, b, period=12):
"""
Euclidean distance w/ periodic boundaries.
>>> A = np.array([1, 12, 1])
>>> B = np.array([12, 1, 1])
import System.Random
import Data.List
mu :: Fractional a => [a] -> a
mu [] = 0
mu ps = sum ps / (fromIntegral . length) ps
sigma :: Floating a => [a] -> a
sigma [] = 0
sigma ps = sqrt (mu $ map xm ps)
import collections
import toolz
import decorator
## same boilerplate as in common_models
class Stage(object):
def __init__(self, **constants):
import collections
## same boilerplate as in common_models
class Stage(object):
def __init__(self, **kwargs):
self.constants = kwargs
from __future__ import unicode_literals, print_function, generators
import doctest
# TODO:
# - 'do' notation
# - Py3 type annotations
# - More monadic types
class FormattedException(Exception):
def __init__(self, **kwargs):
@hcarvalhoalves
hcarvalhoalves / curry.py
Last active August 29, 2015 14:16
Currying decorator.
from functools import partial, wraps
import doctest
def curry(f):
"""
Allow partial evaluation of function (currying).
Returns a `functools.partial` until all arguments are specified:
>>> f = curry(lambda a,b: a + b)
export interface MonadI<T> {
lift<U>(transform: (v: T) => U): MonadI<U>;
bind<U>(transform: (v: T) => MonadI<U>): MonadI<U>;
}
export interface MaybeI<T> extends MonadI<T> {
isEmpty: boolean;
toString(): string;
get(): any;
}