Skip to content

Instantly share code, notes, and snippets.

@smugen
smugen / a.py
Created December 14, 2012 16:50
Python import cache test
import b, c
print __name__, ":", c.msg
print __name__, ":", c is b.c
print __name__, ":", "reload c"
reload(c)
print __name__, ":", c.msg
print __name__, ":", c is b.c
@smugen
smugen / a.js
Created December 14, 2012 16:33 — forked from anonymous/a.js
Node.js require cache test
var b = require('./b')
,c = require('./c');
console.log(__filename, ":", c.msg);
console.log(__filename, ":", c === b.c);
console.log(__filename, ":", "delete require cache, and require c again");
delete require.cache[require.resolve('./c')];
c = require('./c');
@smugen
smugen / form.py
Created November 30, 2012 06:12
Taiwan R.O.C. ID validation with wtforms from part of my project
# -*- coding: UTF-8 -*-
from flaskext.wtf import Form, TextField, PasswordField, RecaptchaField, \
AnyOf, NoneOf, Regexp, Email, Required, EqualTo, Recaptcha
from wtforms.validators import StopValidation
from flask import request, session
import model
# 身份證字號格式驗證
def check_ID(form, field):
locations = dict(zip([c for c in 'ABCDEFGHJKLMNPQRSTUVXYWZIO'], range(10,36)))
@smugen
smugen / goccpath.bat
Created October 12, 2012 13:14
golang Go tools switcher batch for Windows 64 / 32 cross-compiling
IF "%GOCC_OLD_PATH%" NEQ "" GOTO restorepath
:savepath
ECHO save PATH to GOCC_OLD_PATH
SET GOCC_OLD_PATH=%PATH%
GOTO oldpathdone
:restorepath
ECHO restore PATH from GOCC_OLD_PATH
PATH %GOCC_OLD_PATH%
@smugen
smugen / hiresimg.js
Created July 10, 2012 06:55
obtain the max resolution of picasa url
(function () {
var hiresurl,
hiresimg;
hiresurl = function hiresurl (source) { return source.replace(/\/s\d+\//i, "/s0/"); };
hiresimg = function hiresimg (){
var imgs = document.getElementsByTagName("img"),
len = imgs.length,
img;
@smugen
smugen / cluster.js
Created June 4, 2012 06:40
Node.js Simple Static Web Server
var fs = require('fs'),
cluster = require('cluster');
var config = JSON.parse(fs.readFileSync(require('path').join(__dirname, 'config.json')));
if (config.cwd && process.cwd() != config.cwd) process.chdir(config.cwd);
var workers = config.workers || require('os').cpus().length;
// 如有指定 log 檔,則將標準輸出和錯誤輸出寫到 log 檔
if (config.log){
var log_stream = fs.createWriteStream(config.log, {flags: 'a'});