Skip to content

Instantly share code, notes, and snippets.

@friskfly
friskfly / multiple-url-paths.lua
Created February 18, 2016 05:31 — forked from anonymous/multiple-url-paths.lua
Benchmark multiple url paths with wrk
-- Resource: https://github.com/timotta/wrk-scripts/blob/master/multiplepaths.lua
-- Initialize the pseudo random number generator
-- Resource: http://lua-users.org/wiki/MathLibraryTutorial
math.randomseed(os.time())
math.random(); math.random(); math.random()
-- Shuffle array
-- Returns a randomly shuffled array
function shuffle(paths)
@friskfly
friskfly / better-nodejs-require-paths.md
Last active September 19, 2015 08:02 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

function throttle( fn, time ) {
var t = 0;
return function() {
var args = arguments, ctx = this;
clearTimeout(t);
t = setTimeout( function() {
fn.apply( ctx, args );
}, time );
};
var http = require("http");
function request(url) {
var options = {
hostname: url,
port: 80,
path: '/',
method: 'GET'
};
var req = http.request(options, function(res) {
@friskfly
friskfly / error.asp
Created January 9, 2013 07:29
asp 异常机制
<%
Dim myVar
On Error Resume Next
'下面一行代码会在MSXML 4.0没有被安装或者已经损坏的情况下产生错误
Set myVar = Server.CreateObject("MSXML2.DOMDocument.4.0")
If Err.Number <> 0 Then
' 在这里处理错误
' 结束错误处理,避免以后发生的错误无法被发现
On Error GoTo 0
Else
@friskfly
friskfly / pindao.py
Created January 6, 2013 08:51
python 批量生成西祠频道option选择标签
#coding:utf-8
import re
string = '''
TagDict.Add "@胡同口@","@1386@"
TagDict.Add "@时尚@","@1357@"
TagDict.Add "@汽车@","@1336@"
TagDict.Add "@旅游@","@1378@"
TagDict.Add "@家居@","@1396@"
TagDict.Add "@数码@","@1242@"
TagDict.Add "@都市@","@1276@"
@friskfly
friskfly / bank.py
Created January 3, 2013 11:19
python 模拟银行排队取号系统 语音播报
#coding:utf-8
'''
@author:FX
2013-1-3
'''
import random
import threading
import time
import Queue
import speech
@friskfly
friskfly / gzdecode.php
Created January 2, 2013 05:26
php gzdecode SAE上没有gzdecode函数
function gzdecode($data) {
$len = strlen($data);
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
return null; // Not GZIP format (See RFC 1952)
}
$method = ord(substr($data,2,1)); // Compression method
$flags = ord(substr($data,3,1)); // Flags
if ($flags & 31 != $flags) {
// Reserved bits are set -- NOT ALLOWED by RFC 1952
return null;
@friskfly
friskfly / getFolders.py
Created January 1, 2013 08:36
python getFloders 根据给定的文件路径,向上查找 返回所有的文件路径。
# Get all folders paths from given path upwards
#
# @type file_path: string
# @param file_path: absolute file path to return the paths from
#
# @return list<string> of file paths
#
# @global nestingLimit
def getFolders(file_path):
if file_path is None:
@friskfly
friskfly / codecs.py
Created January 1, 2013 07:57
python 获取系统默认编码
import locale
import codecs
print locale.getpreferredencoding();
print codecs.lookup(locale.getpreferredencoding()).name