Skip to content

Instantly share code, notes, and snippets.

@cfchou
cfchou / circular_ref.py
Created May 28, 2016 04:08
circular ref closure test
import random
import objgraph
from pympler import muppy, summary
import types
import logging
logging.basicConfig(level=logging.DEBUG)
class Dumb(object):
@cfchou
cfchou / my-aws-kube.sh
Created May 13, 2016 10:23
kube aws setting
#! /bin/bash
export KUBERNETES_PROVIDER=aws
export KUBE_AWS_ZONE="ap-northeast-1c"
export NUM_NODES=2
export MASTER_SIZE="t2.micro"
export NODE_SIZE="t2.micro"
export AWS_S3_REGION="ap-northeast-1"
export AWS_S3_BUCKET=k8stmp
export INSTANCE_PREFIX=k8s
@cfchou
cfchou / fatboy.py
Created May 13, 2016 10:07
fabric to grab sys data
from fabric.api import local, cd, run, env, sudo
#env.ssh_config_path=
env.use_ssh_config = True
def dummy():
commands = [
'pstree -a',
@cfchou
cfchou / provision101.sh
Last active October 17, 2016 07:56
provision on ubuntu
#! /bin/bash
CMD=$(basename ${0})
GREP=/bin/grep
RC=$HOME/.bashrc
VIMRC=$HOME/.vimrc
TMP=$HOME/tmp
VENV_PYTHON_VERSION="2.7.12"
VENV_PYTHON3_VERSION="3.5.2"
@cfchou
cfchou / StreamOuter.scala
Created February 27, 2016 02:32 — forked from john-kurkowski/StreamOuter.scala
Scala closures capture outer variables, which can lead to unhappy serialization when you don't expect a lazy data structure under the covers. The lesson is, for serialization, favor strict, concrete types.
class A
class B extends Serializable
val baos = new java.io.ByteArrayOutputStream(1024)
val oos = new java.io.ObjectOutputStream(baos)
val streamSurprise: Seq[A] = Stream.fill(3)(new A) // say you don't know it's a Stream under the covers
val transformation = streamSurprise map (a => new B)
oos.writeObject(transformation) // fails due to NotSerializableException: A
@cfchou
cfchou / KafkaProducerTest.scala
Last active January 24, 2016 09:22
KafkaProducerTest
package client
package client
import java.time.Instant
import java.util.Properties
import java.util.concurrent.{Future => JF, TimeoutException, Executors}
import grizzled.slf4j.Logger
@cfchou
cfchou / 0_reuse_code.js
Created December 7, 2013 01:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cfchou
cfchou / Par.hs
Created September 16, 2013 11:37
Sample code from Graham Hutton and Erik Meijer's paper "Monadic Parser Combinators" is written in Gofer. Here's a rewrite in Haskell.
import Data.Char
import Control.Monad
import Control.Monad.Trans.State.Lazy (StateT(..), runStateT)
import Control.Monad.Trans.Reader
import Control.Monad.State.Class
import Control.Monad.Trans.Class
type Pos = (Int, Int) -- (line, column)
type PString = (Pos, String)
@cfchou
cfchou / knapsack.hs
Created June 27, 2013 15:03
usage: runghc knapsack.hs --file=data/ks_100_1
{-# LANGUAGE DeriveDataTypeable #-}
module KSSolver where
import System.Console.CmdArgs
import System.IO
import Control.Monad
import Control.Applicative
import Data.Vector (Vector, (!))
import qualified Data.Vector as V
import Debug.Trace
@cfchou
cfchou / testCBF4.scala
Last active December 18, 2015 08:09
map, to[CC[_]], mapResult
import scala.language.higherKinds
import scala.annotation.unchecked.uncheckedVariance
trait Budr[-Elm, +To] {
def +=(elem: Elm): this.type
def result(): To
def mapResult[NewTo](f: To => NewTo): Budr[Elm, NewTo] = {
new Budr[Elm, NewTo] with Proxy {
val self = Budr.this
def +=(x: Elm): this.type = { self += x; this }