Skip to content

Instantly share code, notes, and snippets.

@andelf
andelf / data.py
Created October 24, 2011 02:56
A free dict as a property container
class Data(dict):
def __init__(self, *args, **kwargs):
super(Data, self).__init__(*args, **kwargs)
self.__dict__ = self
@andelf
andelf / flatten.py
Created October 24, 2011 05:04
How to flatten a python nested list(tuple)
flatten = lambda lst: reduce(lambda l,i: l + flatten(i) if isinstance(i, (list,tuple)) else l + [i], lst, [])
print flatten([2, [2, [4, 5, [7], [2, [6, 2, 6, [6], 4]], 6]]])
# -> [2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
@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 / cookiejar.go
Last active June 20, 2017 05:13
A golang in memory cookiejar
// MIT license (c) andelf 2012
type InMemoryCookieJar struct{
storage map[string][]http.Cookie
}
// buggy... but works
func (jar InMemoryCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie) {
for _, ck := range cookies {
path := ck.Domain
@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 / sendMail.go
Last active September 20, 2023 15:13
golang send mail net/smtp SMTP
package main
import (
"log"
"net/mail"
"encoding/base64"
"net/smtp"
"fmt"
"strings"
@andelf
andelf / smtp_login_auth.go
Created March 8, 2013 18:40
golang net/smtp SMTP AUTH LOGIN Auth Handler
// MIT license (c) andelf 2013
import (
"net/smtp"
"errors"
)
type loginAuth struct {
username, password string
@andelf
andelf / beam_decompile.erl
Created March 19, 2013 03:25
Erlang BEAM file decompile to .erl file
#!/usr/bin/env escript
% -*- mode: erlang -*-
main([BeamFile]) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(BeamFile,[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
@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).