Skip to content

Instantly share code, notes, and snippets.

Avatar

Henrique Carvalho Alves hcarvalhoalves

View GitHub Profile
View stream.hs
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)
View gist:9313500
import System.Environment (getArgs, getProgName)
import System.Exit (exitFailure, exitSuccess)
import System.IO
import Network
import Control.Concurrent
import Text.Read
echoCommand :: Handle -> [String] -> IO ()
echoCommand handle cmd = do
hPutStrLn handle (unwords $ tail cmd)
@hcarvalhoalves
hcarvalhoalves / gist:2d4529d1502db87131a6
Created May 6, 2014
geoalchemy Geometry wrapper for simple "lat,lon" fields
View gist:2d4529d1502db87131a6
from sqlalchemy import types
from sqlalchemy.sql.expression import func, text
from geoalchemy2 import functions as geofunc
from geoalchemy2.elements import WKTElement
class Coordinate(types.TypeDecorator):
impl = Geometry
def process_bind_param(self, value, dialect):
View gist:5330d8af36e7163d58c4
import string
ALPHABET = 'ABCDEGHKLPQRSTUVWXYZ' + '23456789'
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
BASE = len(ALPHABET)
START_FROM = 1
def encode(n):
n = n * START_FROM
View gist:a4b86201fdfe4e471251
import string
ALPHABET = 'ABCDEGHKLPQRSTUVWXYZ' + '23456789'
ALPHABET_REVERSE = dict((c, i) for (i, c) in enumerate(ALPHABET))
BASE = len(ALPHABET)
START_FROM = 1
def encode(n):
n = n * START_FROM
View gist:7327f0d1869cef827bac
Kerbal Space Program - 0.25.0.642 (OSXPlayer) Steam
OS: Mac OS X 10.10.0
CPU: Intel(R) Core(TM)2 Duo CPU P8800 @ 2.66GHz (2)
RAM: 8192
GPU: NVIDIA GeForce 320M OpenGL Engine (256MB)
SM: 30 (OpenGL 2.1 [2.1 NVIDIA-10.0.19 310.90.10.05b12])
RT Formats: ARGB32, Depth, ARGBHalf, RGB565, ARGB4444, Default, DefaultHDR, ARGBFloat, RGFloat, RGHalf, RFloat, RHalf, R8
View maybe.ts
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;
}
@hcarvalhoalves
hcarvalhoalves / curry.py
Last active Aug 29, 2015
Currying decorator.
View curry.py
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)
View monad.py
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):
View pipeline_api2.py
import collections
import toolz
import decorator
## same boilerplate as in common_models
class Stage(object):
def __init__(self, **constants):