Skip to content

Instantly share code, notes, and snippets.

View timdream's full-sized avatar
🏃‍♂️
I may be slow to respond.

Timothy Guan-tin Chien timdream

🏃‍♂️
I may be slow to respond.
View GitHub Profile
var SyncPromise = function(callback) {
this._resolveCallbacks = [];
this._rejectCallbacks = [];
var resolve = (function resolve(value) {
if (this.state !== 'pending') {
return;
}
this.state = 'fulfilled';
@timdream
timdream / private_instance_weakmap.js
Last active August 29, 2015 14:14
Private method/property with WeakMap
'use strict';
/**
* Demonstration for creating private variable/method in JavaScript
* constrcutors, with WeakMap trick.
*
* The idea here is to create two WeakMaps to link a public instance and
* a private instance, and two shorthand query function to query between two.
*
* Both instances can therefore have their own methods respectively.
@timdream
timdream / keybase.md
Created June 29, 2015 00:11
keybase.md

Keybase proof

I hereby claim:

  • I am timdream on github.
  • I am timdream (https://keybase.io/timdream) on keybase.
  • I have a public key whose fingerprint is F0BB E548 E897 C929 6D2E 274D 1679 F06F 99C1 1F99

To claim this, I am signing this object:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations]
"AllowFontAntiAlias"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]
"AllowFontAntiAlias"=dword:00000001
"ColorDepth"=dword:00000004
<!--
GFX API 懶惰測試頁 -
用 Firebug 看資料結構吧。
-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
var c;
$(function() {
$.getJSON(
default menu.c32
prompt 0
menu title Ubuntu Live USB
#timeout 100
timeout 30
label unetbootindefault
menu label Ubuntu (^Persistent Mode)
kernel /ubnkern
append initrd=/ubninit file=/cdrom/preseed/ubuntu.seed boot=casper persistent noprompt quiet splash --
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../../firefox-build
ac_add_options --disable-compile-environment
ac_add_options --with-l10n-base=/home/timdream/repo/l10n-central
mk_add_options MOZ_MAKE_FLAGS="-j4"
make wget-en-US EN_US_BINARY_URL=http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/
make unpack
hg -R ../../../repo/mozilla-central pull
make ident
make ident | awk '{print $2}' | head -n 1 | xargs hg -R ../../../repo/mozilla-central update -r
@timdream
timdream / gist:668645
Created November 9, 2010 03:22
Anyone knows how to check values in a loop w/o that flag variable? Would label statement help?
function doSomethingWithArray(arr) {
// check the array
var flag = false;
for (var i; i < arr.length; i++) {
if (arr[i] === 0) {
console.log('item at ' + i.toString(10) + 'is zero.');
flag = true;
break;
@timdream
timdream / gist:668656
Created November 9, 2010 03:35
One of the possible yet ugly answer to get rid of flag variable
function doSomethingWithArray(arr) {
doArray : {
// check the array
for (var i; i < arr.length; i++) {
if (arr[i] === 0) {
console.log('item at ' + i.toString(10) + 'is zero.');
flag = true;