Skip to content

Instantly share code, notes, and snippets.


Michael Chen yuhua-chen

View GitHub Profile
View test.js
alert('hello from gist');
yuhua-chen / Drag-and-drop-uitableviewcell-swift2.swift
Created Aug 6, 2015
Demo the drag and drop UITableViewCell in Swift 2.
View Drag-and-drop-uitableviewcell-swift2.swift
struct Drag {
static var placeholderView: UIView!
static var sourceIndexPath: NSIndexPath!
func handleLongPress(gesture: UILongPressGestureRecognizer) {
let point = gesture.locationInView(tableView)
let indexPath = tableView.indexPathForRowAtPoint(point)
switch gesture.state {
yuhua-chen / hypenize.js
Last active Jan 10, 2016
Replace special chars with hyphen.
View hypenize.js
function hyphenize(string) {
string = string.replace(/[^A-Za-z0-9\. -]/g, '');
return string.replace(/ */g, '-');
var str = "Nike The Future One / Interactive Setting"
// "Nike-The-Future-One-Interactive-Setting"
yuhua-chen / yahoo_bid_category.js
Last active Aug 29, 2015
Yahoo 奇摩拍賣商品分類
View yahoo_bid_category.js
var url = ''
var cheerio = require('cheerio')
var https = require('https')
https.get(url, function(response) {
var responseData = ""
response.on('data', function(data){
responseData += data
yuhua-chen / dump-selectors
Created Aug 4, 2014
Dump all selectors from a class.
View dump-selectors
- (void)dumpAllSelector:(Class) SomeClass
id t = [[SomeClass alloc] init];
int i=0;
unsigned int mc = 0;
Method * mlist = class_copyMethodList(object_getClass(t), &mc);
NSLog(@"%d methods", mc);
NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i])));
yuhua-chen /
Created Jul 13, 2014
Showing git branch in fish shell prompt
set fish_git_dirty_color red
set fish_git_not_dirty_color green
function parse_git_branch
set -l branch (git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/')
set -l git_diff (git diff)
if test -n "$git_diff"
echo (set_color $fish_git_dirty_color)$branch(set_color normal)
View .screenrc
#screen setting
#cjkwidth off
startup_message off
#support 256 color
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
caption always "%{=u .r} %-w%<%{=ub .Y}%n %t%{=u .r}%+w "
hardstatus alwaysignore