Skip to content

Instantly share code, notes, and snippets.

View kinwahlai's full-sized avatar

KinWah Lai kinwahlai

  • Odd-e Singapore
  • Singapore
View GitHub Profile
@kinwahlai
kinwahlai / WWDC2013-DownloadURL
Created June 18, 2013 02:55
This script is originally created by Evadne Wu (https://gist.github.com/evadne/5794585) which generate curl command for PDF, SD and HD. I modified it slightly just to output the curl command HD video.
NodeList.prototype.toArray = function () {
return Array.prototype.slice.call(this);
};
[].concat.apply([], document.querySelectorAll("li.session").toArray().map(function(session){
var sessionID = session.id.match(/^\d+/)[0];
var title = session.querySelector(".title").innerText;
var track = session.querySelector(".track").innerText;
var date = session.querySelector(".date").innerText;
var allLinks = session.querySelectorAll("a[href^='http://devstreaming']").toArray();
#import <CouchbaseLite/CouchbaseLite.h>
@interface CBLQueryEnumerator (EnumeratorByBlock)
- (void)enumerateQueryRowsUsingBlock:(void (^)(id key,id value, NSUInteger idx, BOOL *stop))block;
@end
@kinwahlai
kinwahlai / ObjCFuncOrMethod.grammar
Created March 26, 2014 02:04
Objective C grammar for ParseKit
@symbols = ':' ',';
@start = expression;
expression = functionExpression | messageExpression;
funcName = Word;
selector = Word;
className = Word;
openSquareParen = '[';
closeSquareParen = ']';
openParen = '(';
@kinwahlai
kinwahlai / Info.plist
Last active August 29, 2015 14:05
Enable other JVM capabilities in Mac with
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>libjli.dylib</string>
<key>CFBundleGetInfoString</key>
<string>Java SE 1.7.0_60</string>
@kinwahlai
kinwahlai / Swift-Snippets.swift
Last active August 29, 2015 14:05
Swift snippets
// slicing of array
let arr = [1,2,3,4]
arr[1..<arr.count]
arr[arr.startIndex.successor()..<arr.endIndex]
// typealias similar to typedef in C
// here we create a type for function
typealias OptionalIncrementor = Int? -> Int
// another shorthand for create dictionary
@kinwahlai
kinwahlai / highlight.bash
Created September 25, 2014 05:55
bash function to for highlighting code
function light() {
if [ -z "$2" ]
then src="pbpaste"
else
src="cat $2"
fi
$src | highlight -O rtf --syntax $1 --font Inconsolata --style solarized-dark --font-size 24 | pbcopy
}
@kinwahlai
kinwahlai / Chaining.groovy
Created November 25, 2014 02:03
Groovy chaining
class ChainExample {
static String callClosure(){
def aClosure = { ->
{ ->
"this is second closure"
}
}
aClosure()()
}
@kinwahlai
kinwahlai / my_zsh_setup.sh
Created July 15, 2015 14:53
setup antigen and zsh
#!/bin/bash
# assuming brew installed, especially git
mkdir ~/.zsh-antigen
cd ~/.zsh-antigen
git init .
git submodule add https://github.com/zsh-users/antigen.git antigen
# should check zshrc already exists
@kinwahlai
kinwahlai / inject_DVTPlugInCompatibilityUUID.sh
Last active December 30, 2015 00:30
To insert new DVTPlugInCompatibilityUUID into plugin's Info.plist
#! /usr/bin/env sh
# assumption: Xcode is always installed at /Applications
# STEPS:
# use plistbuddy to read $INFOPLIST_FILE::DVTPlugInCompatibilityUUIDs array
# get new DVTPlugInCompatibilityUUID [ defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID ]
# check new DVTPlugInCompatibilityUUID already in the array
# YES: end
# NO: use plistbuddy to write the new DVTPlugInCompatibilityUUID into the array and write out to file
@kinwahlai
kinwahlai / performance_mesaure.swift
Created December 9, 2015 01:23
function to measure block code executed
func measure(title: String, block: (finish:()-> Void) -> Void) {
let startTime = CFAbsoluteTimeGetCurrent()
block {
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("\(title):: Time: \(timeElapsed)")
}
}