Skip to content

Instantly share code, notes, and snippets.

@andelf
andelf / proc_diff.py
Last active August 29, 2015 14:02
Monitor Process Creation and Quiting
import os
import commands
import time
def get_process():
procs = set()
for line in commands.getoutput("ps aux").split('\n'):
if not line: # or '%CPU' in line:
continue
proc = ' '.join(line.split()[10:])
@andelf
andelf / HashSet.swift
Last active August 29, 2015 14:02
Generic Hash Set in Swift
struct HashSet<T : Hashable> {
typealias Element = T
var _map: Dictionary<T, ()> = [:]
var count: Int {
return _map.count
}
var isEmpty: Bool {
@andelf
andelf / EasyJSON.swift
Last active August 29, 2015 14:03
Swift JSON Helper
import Foundation
//let raw = String.stringWithContentsOfURL(NSURL(string: "http://www.weather.com.cn/data/sk/101010100.html"))
struct EasyJSON {
var _obj: AnyObject!
init(_ obj: AnyObject) {
//assert(NSJSONSerialization.isValidJSONObject(obj), "must be valid json object")
_obj = obj
@andelf
andelf / chnquote.py
Created November 9, 2011 04:46
中文引号处理转换
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import operator
import itertools
import re
def debug(x):
print 'debug', dir(x), x.group()
@andelf
andelf / cstruct.py
Created March 31, 2012 13:54
a Structure impl support both ctypes and struct.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FileName : cstruct.py
# Author : Feather.et.ELF <andelf@gmail.com>
# Created : Tue Feb 28 23:06:44 2012 by Feather.et.ELF
# Copyright : Feather Workshop (c) 2012
# Description : mcpack v1 v2
# Time-stamp: <2012-03-31 18:58:42 andelf>
import struct
@andelf
andelf / racer-auto-complete.el
Last active October 4, 2015 03:13
Racer Auto-Complete Mode
;; FileName : racer-autocomplete.el
;; Author : ShuYu Wang <andelf@gmail.com>
;; Created : Wed May 20 10:08:03 2015 by ShuYu Wang
;; Copyright : Feather Workshop (c) 2015
;; Description : racer auto-complete source
;; Time-stamp: <2015-05-20 10:08:18 andelf>
;;; copy this to your load-path and add following to your ~/.emacs
;; (setq racer-cmd "/your/path/to/bin/racer")
@andelf
andelf / tmux.conf
Created April 8, 2013 05:43
my tmux conf
#设置终端颜色为256色
set -g default-terminal "screen-256color"
# auto resize to smallest windows size
setw -g aggressive-resize on
# Terminal emulator window titles
set -g set-titles on
set -g set-titles-string "#T"
#将激活控制台的快捷键由Ctrl+b修改为Ctrl+z
@andelf
andelf / dns_proxy_srv.erl
Last active December 16, 2015 09:18
erlang dns proxy, with long ttl and persistant etc table cache.
%%%-------------------------------------------------------------------
%%% @author <andelf@gmail.com>
%%% @copyright (C) 2013,
%%% @doc
%%%
%%% @end
%%% Created : 18 Apr 2013 by <andelf@gmail.com>
%%%-------------------------------------------------------------------
-module(dns_proxy_srv).
@andelf
andelf / .ghci
Last active December 29, 2015 07:39
dot.files
:set prompt "λ> "
:set +t
@andelf
andelf / monad.js
Created November 25, 2013 06:34
Monad in javascript.
function MONAD(modifier) {
var prototype = Object.create(null);
function unit(value) {
var monad = Object.create(prototype);
monad.bind = function (func, args) {
return func.apply(undefined,
[value].concat(Array.prototype.slice.apply(args || [])));
};
if (typeof modifier == 'function') {
monad = modifier(monad, value);