Skip to content

Instantly share code, notes, and snippets.

View commands
ocamlc -I +ocamldoc -c tg.ml && ocamldoc -g tg.cmo test.ml
@ngzhian
ngzhian / claim-cs2106.js
Created Apr 18, 2017
cs 2106 tutorial claim script
View claim-cs2106.js
var Claim = function () {
// ***********************************************************
// REQUIRED CONSTANTS, DO NOT MODIFY
// ***********************************************************
var ASSIGNMENT_MARKING = 'Assignment Marking';
var COURSE_MATERIAL_PREPARATION = 'Course Material Preparation';
var TUTORIAL = 'Tutorial';
var CONSULTATION = 'Consultation with students';
var MIDTERM_MARKING = 'Midterm Marking';
var PROJECT = 'Project Evaluation';
View bash_snippets.sh
# read line by line from file
while read p; do
echo $p
done <file
# change first letter from upper to lower
q="$(tr '[:upper:]' '[:lower:]' <<< ${p:0:1})${p:1}"
# sed variable substitution
sed "s/$var/r_str/g" file_name >new_file
@ngzhian
ngzhian / claim-cs2100-lab.js
Created Apr 13, 2017
CS2100 MYSOC claim script
View claim-cs2100-lab.js
var Claim = function () {
// ***********************************************************
// REQUIRED CONSTANTS, DO NOT MODIFY
// ***********************************************************
var ASSIGNMENT_MARKING = 'Assignment Marking';
var COURSE_MATERIAL_PREPARATION = 'Course Material Preparation';
var TUTORIAL = 'Tutorial';
var CONSULTATION = 'Consultation with students';
var MIDTERM_MARKING = 'Midterm Marking';
var PROJECT = 'Project Evaluation';
@ngzhian
ngzhian / bst_to_ll.ml
Created Apr 8, 2017
Convert a binary search tree into a linked list in place.
View bst_to_ll.ml
(**
* This file contains 3 ways to solve the problem of:
*
* converting a binary search tree into a sorted linked list in-place
*
* In place means that no extra memory should be used, no structures are copied
*
* 1. Using ref nodes
* 2. Using records with mutable fields
* 3. Using immutable Cons and Nil linked list
View gist:553296fb5c606a8156917385bc0ad626
:%s/<Ctrl-V><Ctrl-M>/\r/g
http://stackoverflow.com/questions/811193/how-to-convert-the-m-linebreak-to-normal-linebreak-in-a-file-opened-in-vim
View export_google_starred_locations.py
# -*- coding: utf-8 -*-
"""
Go to Google Bookmarks: https://www.google.com/bookmarks/
On the bottom left, click "Export bookmarks": https://www.google.com/bookmarks/bookmarks.html?hl=en
After downloading the html file, run this script on it to generate a KML.
Slight modification of regex to get lat/lng from web page from: https://gist.github.com/endolith/3896948=
"""
@ngzhian
ngzhian / stackclock-answers
Last active Aug 29, 2015
The times for stackclock
View stackclock-answers
00:16:22
00:49:05
01:21:49
01:54:33
02:27:16
03:00:00
03:32:44
04:05:27
04:38:11
05:10:55
@ngzhian
ngzhian / stackclock
Last active Aug 29, 2015
Clock question
View stackclock
from __future__ import division
from datetime import datetime, time, timedelta
import unittest
ONE_SECOND = timedelta(seconds=1)
HOUR_HAND_DEG_PER_SECOND = 1/120
HOUR_HAND_DEG_PER_MIN = 1/2
HOUR_HAND_DEG_PER_HOUR = 30
View d3clone
!function(){function n(n,t){return t>n?-1:n>t?1:n>=t?0:0/0}function t(n){return null!=n&&!isNaN(n)}function e(n){return{left:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)<0?r=i+1:u=i}return r},right:function(t,e,r,u){for(arguments.length<3&&(r=0),arguments.length<4&&(u=t.length);u>r;){var i=r+u>>>1;n(t[i],e)>0?u=i:r=i+1}return r}}}function r(n){return n.length}function u(n){for(var t=1;n*t%1;)t*=10;return t}function i(n,t){try{for(var e in t)Object.defineProperty(n.prototype,e,{value:t[e],enumerable:!1})}catch(r){n.prototype=t}}function o(){}function a(n){return ia+n in this}function c(n){return n=ia+n,n in this&&delete this[n]}function s(){var n=[];return this.forEach(function(t){n.push(t)}),n}function l(){var n=0;for(var t in this)t.charCodeAt(0)===oa&&++n;return n}function f(){for(var n in this)if(n.charCodeAt(0)===oa)return!1;return!0}function h(){}function g(n,t,e){return function(){var r=e.apply(t,arguments);return r===t?n:r}}function p(n,