Skip to content

Instantly share code, notes, and snippets.

View kaid's full-sized avatar
🎯
Focusing

Kaid Wong kaid

🎯
Focusing
  • Beijing, PRC
View GitHub Profile
@kaid
kaid / method_visibility.rb
Created March 25, 2011 05:08
illustrating ruby method visibility machanism
class Bla
def a
"a"
end
def b
self.a
end
def c
@kaid
kaid / hostel_list_china.rb
Created September 14, 2011 10:59
a script for fetching and parsing hostel list from yhachina.com then process it into a serialized json file
require 'nokogiri'
require 'open-uri'
base = 'http://www.yhachina.com/3g/'
def nopen(page)
Nokogiri::HTML(open(page))
end
doc = nopen(base + 'allthehostel.html')
@kaid
kaid / capture_stdout.js
Created February 8, 2012 10:38
capture stdout
var exec = require('child_process').exec;
var capture_stdout = function(cmd, callback) {
exec(cmd, function(err, stdout, stderr) {
callback(err, stdout, stderr);
});
}
module.exports = capture_stdout;
@kaid
kaid / player_choices.md
Created August 17, 2012 03:49
html5媒体播放器的选择

视频播放器

html5视频播放器:

+------------+---------------------------------+
| videojs    | http://videojs.com              |
+------------+---------------------------------+
| projekktor | http://www.projekktor.com       |
+------------+---------------------------------+
@kaid
kaid / capture_rect.js
Last active October 11, 2016 03:39
phantomjs批量截取网页某一区域脚本
var base = 'http://dev.kaid.me/c';
var ids = [1, 2, 3, 41, 42, 43, 51, 52, 53];
ids.forEach(function(id) {
var page = require('webpage').create(),
url = base + id,
output = 'c' + id + '.png';
page.clipRect = {top:122, left:65, width:360, height:600};
@kaid
kaid / boot.conf
Last active November 24, 2016 23:42
funtoo_zfs_install
boot {
generate grub
default "Funtoo ZFS"
timeout 4
}
"Funtoo Linux" {
kernel bzImage[-v]
}
@kaid
kaid / json_serializable.coffee
Created September 12, 2013 13:45
JSONSerializable
guid = ->
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c)->
r = Math.random()*16|0
v = if c == 'x' then r else (r&0x3|0x8)
v.toString(16)
is_dom = (v)->
typeof jQuery != "undefined" &&
v instanceof jQuery ||
v instanceof Node
@kaid
kaid / translator.rb
Created January 8, 2014 09:17
text transformation util, can be used to build simple text markup parsers.
module Translator
class NoPatternError < Exception
end
class BufferEmptyError < Exception
end
class IllegalTokenError < Exception
end
@kaid
kaid / migrate
Last active August 29, 2015 13:56
python helper script for generating activeandroid migrations
#!/usr/bin/env python
import xml.etree.ElementTree as ET
import os
import time
def main():
generate_migration()
# manipulate manifest.xml
@kaid
kaid / zhihu_hot.js
Last active June 6, 2019 04:08
知乎热门问题抓取脚本
//==== Displayer ====
var Displayer = function() {
this.$el = jQuery("body").prepend(
"<div class=\"hotqs-list\">" +
"<div class=\"head\">" +
"<div>关注</div>" +
"<div>回答</div>" +
"</div>" +
"<div class=\"loading\">开始抓取问题</div>" +