Skip to content

Instantly share code, notes, and snippets.

View yuhua-chen's full-sized avatar

Michael Chen yuhua-chen

View GitHub Profile
alert('hello from gist');
@yuhua-chen
yuhua-chen / hypenize.js
Last active January 10, 2016 06:41
Replace special chars with hyphen.
function hyphenize(string) {
string = string.replace(/[^A-Za-z0-9\. -]/g, '');
return string.replace(/ */g, '-');
}
var str = "Nike The Future One / Interactive Setting"
hyphenize(str)
// "Nike-The-Future-One-Interactive-Setting"
@yuhua-chen
yuhua-chen / Drag-and-drop-uitableviewcell-swift2.swift
Created August 6, 2015 09:12
Demo the drag and drop UITableViewCell in Swift 2.
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
yuhua-chen / yahoo_bid_category.js
Last active August 29, 2015 14:22
Yahoo 奇摩拍賣商品分類
var url = 'https://tw.bid.yahoo.com/tw/0-all.html?.r=1432872568'
var cheerio = require('cheerio')
var https = require('https')
https.get(url, function(response) {
var responseData = ""
response.setEncoding('utf-8')
response.on('data', function(data){
responseData += data
})
@yuhua-chen
yuhua-chen / dump-selectors
Created August 4, 2014 06:44
Dump all selectors from a class.
- (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);
for(i=0;i<mc;i++)
NSLog(@"Method no #%d: %s", i, sel_getName(method_getName(mlist[i])));
@yuhua-chen
yuhua-chen / config.fish
Created July 13, 2014 16:04
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)
else
@yuhua-chen
yuhua-chen / .screenrc
Created April 17, 2014 06:10
screen config
#screen setting
#cjkwidth off
startup_message off
#support 256 color
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
#statusbar
caption always "%{=u .r} %-w%<%{=ub .Y}%n %t%{=u .r}%+w "
hardstatus alwaysignore