Skip to content

Instantly share code, notes, and snippets.

View qhwa's full-sized avatar

Qiu Hua qhwa

View GitHub Profile
@ovidiuch
ovidiuch / create_db.sql
Created March 31, 2012 11:21
MySQL utf8 db and user create
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT SELECT, INSERT, UPDATE, DELETE ON dbname.* TO 'usr'@'localhost' IDENTIFIED BY 'passwd';
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

/* Arduino USB Keyboard HID demo
* Volume+/Volume-/Mute keys
*/
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
#define PIN_VOLUME_UP 5
#define PIN_VOLUME_DOWN 6
#define PIN_MUTE 7
@bentonporter
bentonporter / gist:2891463
Created June 7, 2012 20:51
Ruby - HMAC-SHA256 example
require 'openssl'
require 'Base64'
key = "secret-key"
data = "some data to be signed"
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, data)).strip()
@nightire
nightire / Changes in Rails 4_1.md
Last active April 21, 2025 07:25
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@maxlapshin
maxlapshin / gdns.erl
Created May 20, 2013 09:54
Geo DNS server in erlang
%% @doc This is a simple geo-dns server
%% It takes existing erlang dns query parser and https://github.com/mochi/egeoip
%% Here is no implemented database for path routing with some region affinity,
%% so if you are going to use it, you need to implement following databases:
%% 1) Domain -> existing servers
%% 2) Country -> region
%% 3) region -> existing server
-module(gdns).
-author("Max Lapshin <[email protected]>").
-export([start_link/0]).
@blackjid
blackjid / gulpfile.js
Created April 9, 2014 17:59
Gulp Ionic Server + Livereload + Proxy
var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var connect = require('gulp-connect');
var paths = {
css: ['./www/css/**/*.css'],
js: ['./www/js/**/*.js'],
@asaaki
asaaki / iex.sh
Created October 20, 2014 12:04
iex erlang vm args
# http://erlang.org/doc/man/erl.html
# --erl erlang VM attributes/flags
# +A 32 async-threads
# +K true kernel-poll if supported
# +P 524288 max number of simultaneous processes
iex --erl '+A 32 +K true +P 524288'
@shingchi
shingchi / Unicode中文和特殊字符的编码范围
Created January 6, 2015 06:39
Unicode中文和特殊字符的编码范围
根据Unicode5.0整理如下:
1)标准CJK文字
http://www.unicode.org/Public/UNIDATA/Unihan.html
2)全角ASCII、全角中英文标点、半宽片假名、半宽平假名、半宽韩文字母:FF00-FFEF
http://www.unicode.org/charts/PDF/UFF00.pdf
3)CJK部首补充:2E80-2EFF
http://www.unicode.org/charts/PDF/U2E80.pdf
@luikore
luikore / chinese_num.rb
Last active September 29, 2022 07:50
To Chinese Number
# http://zh.wikipedia.org/wiki/中文数字
# http://china.younosuke.com/03_013.html
module ChineseNum
extend self
UPPER_ZERO = '零'
LOWER_ZERO = '〇'
UPPER_DIGITS = %w[壹 贰 叁 肆 伍 陆 柒 捌 玖].unshift nil
LOWER_DIGITS = %w[一 二 三 四 五 六 七 八 九].unshift nil