Skip to content

Instantly share code, notes, and snippets.

View quietcricket's full-sized avatar

Shang Liang quietcricket

  • Singapore
View GitHub Profile
@quietcricket
quietcricket / decode-octal-escape-sequence.js
Last active February 10, 2017 07:56
Convert unicode octal sequence to Javascript usable string
/**
* An Octal Escape Sequence looks like this \345\225\206
* The unicode hex value is 0xE5 0x95 0x86
* The octal value 345 is hexal value E5
* The octal value 225 is hexal value 95
* The octal value 206 is hexal value 86
* This function converts octal values to hexal values first
* Then join the hexal values into an url escape code %E5%95%86,
* which HTML/Javascript is able to output properly
* WARNING: not the safest method. If the string has \xxx but not
set nocompatible " be iMproved, required
filetype off " required
let mapleader = "\<Space>"
" Use Vundle to install packages, the path may be ~/.vim/bundle/vundle depending on how vundle was installed
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Bundles/Plugins
Plugin 'gmarik/Vundle.vim'
@quietcricket
quietcricket / Global keyboard hook for OSX
Created January 8, 2014 07:42
OSX global keyboard hook. Requires root privileges.
// alterkeys.c
// http://osxbook.com
//
// Complile using the following command line:
// gcc -Wall -o alterkeys alterkeys.c -framework ApplicationServices
//
// You need superuser privileges to create the event tap, unless accessibility
// is enabled. To do so, select the "Enable access for assistive devices"
// checkbox in the Universal Access system preference pane.
@quietcricket
quietcricket / Build command for Sublime Text for virtualenv
Last active June 2, 2017 09:30
Build command for Sublime Text for virtualenv
{
"cmd": ["/absolute-file-path-to-your-env/bin/python", "$file"],
"selector": "source.python",
}
@quietcricket
quietcricket / Instantiate a Class by String
Created December 12, 2013 10:19
Instantiate a Class by String
import "dart:mirrors";
MirrorSystem mirrors = currentMirrorSystem();
LibraryMirror lm = mirrors.findLibrary(new Symbol('libraryName'));
ClassMirror cm=lm.declarations[new Symbol('ClassName')] as ClassMirror;
InstanceMirror im=cm.newInstance(const Symbol(''), []);
@quietcricket
quietcricket / mysql_to_mssql.py
Last active December 27, 2015 19:59
Python script for converting MySQL dump into MSSQL compatible scripts Based on my project, I know the following points need to be converted 1. ` need to be removed 2. ENGINE=InnoDB etc need to be removed 3. int(size), (size) is not supported, need to be removed. 4. AUTO_INCREMENT need to be changed to IDENTITY(1,1) 5. UNSIGNED need to be removed…
import sys
import re
class mysql_to_mssql_converter:
"""
Python script for converting MySQL dump into MSSQL compatible scripts
Based on my project, I know the following points need to be converted
1. ` need to be removed
2. ENGINE=InnoDB etc need to be removed
3. int(size), (size) is not supported for int, need to be removed.
4. AUTO_INCREMENT need to be changed to IDENTITY(1,1)
@quietcricket
quietcricket / gist:5963811
Created July 10, 2013 06:09
Different viewport for iPhone and iPad
var width = screen.width;
if (width >= 900) {
$('meta[name=viewport]').attr('content','width=device-width, initial-scale=1');
} else if (width < 900 && width >= 700) { // iPad in portrait mode
$('meta[name=viewport]').attr('content','width=device-width, initial-scale=0.8');
} else if (width <700) { // anything smaller than 700px in width
$('meta[name=viewport]').attr('content','width=device-width, initial-scale=0.4');
}
@quietcricket
quietcricket / gist:5346082
Created April 9, 2013 14:26
Make a folder writable to everyone in the group, in linux system.
newgroup your_group
setfacl -dR -m mask:007 /path/to/shared/folder
chmod g+s /path/to/shared/folder
@quietcricket
quietcricket / gist:5046171
Created February 27, 2013 08:14
Linux change timezone
# List what zones are there
# ls /usr/share/zoneinfo/Asia/
#if the localtime is already set, rename it to something else
# mv /etc/localtime /etc/_localtime
# create a symbol link for the localtime
ln -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime
@quietcricket
quietcricket / gist:3423320
Created August 22, 2012 07:16
Create IOS Push notification certificate
openssl x509 -inform der -in cert.cer -out cert.pem
openssl pkcs12 -nocerts -in key.p12 -out key.pem
cat cert.pem key.pem > joined.pem