Skip to content

Instantly share code, notes, and snippets.

@jiahaog
jiahaog / gist:a12233e9440216494fcd
Last active August 29, 2015 14:19
How to set touch path
@Override
public void onValidPlayerInteraction(DotsInteraction interaction) {
boolean animate = interaction.isAnimate();
boolean clearAll = interaction.isClearAll();
boolean makeVisible;
if (interaction.getState() != DotsInteractionStates.TOUCH_UP) {
makeVisible = true;
} else {
@jiahaog
jiahaog / changeDropdownIndex.js
Created September 20, 2015 14:23
Change DOM dropdown index
/**
* Method that can be used to change dropdown index and also triggers an event to signal
* the change
*
* @param {string} selector
* @param {int} index
*/
function changeDropdownIndex(selector, index) {
var element = document.querySelector(selector);
element.selectedIndex = index;
@jiahaog
jiahaog / Dockerfile
Created September 23, 2015 18:39
Dockerfile to set up PhantomJS and Node
FROM ubuntu:12.04
# install phantomjs
ENV PHANTOMJS_VERSION 1.9.7
RUN \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y build-essential curl vim git wget libfreetype6 libfontconfig bzip2 && \
mkdir -p /srv/var && \
wget -q --no-check-certificate -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && \
@jiahaog
jiahaog / Dockerfile
Last active November 14, 2015 17:34
Meteor Deployment
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y install curl
RUN apt-get -y install build-essential # required for npm install after build
RUN curl https://install.meteor.com/ | sh
# install node 0.10
# Somehow later versions of node (tested with v4) causes errors with fibres,
# so stick to the version mentioned in the readme after meteor build
@jiahaog
jiahaog / gist:f78765301b8c6cd8aa6a
Created January 23, 2016 01:10
Browserify Node.js files
browserify app/src/main.js --node --ignore-missing --detect-globals false --debug -o app/lib/main.js && cp app/src/preload.js app/lib/preload.js
@jiahaog
jiahaog / good_practice
Last active March 10, 2016 15:42
Template for shell scripts with proper error catching
#!/bin/sh
# Template for shell scripts with proper error catching
# Modified from http://www.alittlemadness.com/2012/06/25/bash-tip-reliable-clean-up-with-trap/
# immediately fail on error anywhere
set -e
# Defines a working area on the file system.
TEMP_DIR=/tmp/$$.scratch
wget -r -N http://people.csail.mit.edu/tlp/AI_SUTD_WWW/
@jiahaog
jiahaog / shaped_struct.rb
Created February 2, 2017 08:07
Shaped Ruby Struct
# frozen_string_literal: true
# This class creates a object which behaves like a hash, except that it also
# responds to hash keys sent as messages. We need this type for GraphQL
# because the Gem sends messages to our objects instead of accessing it with
# `:[]`.
#
# It also performs type checking based on a type provided to the shape:
#
# === Example ===
#
@jiahaog
jiahaog / transactions.go
Created June 22, 2017 16:10
Simulating transactions in Go
package main
// This file attempts to simulate trasactions, that can be used to run tasks in a chain and
// rollback everything if the chain fails. For example, this can be used to simulate a database
// transaction to clean up dirty data.
// While I am aware that this abstraction is not truely a atomic transaction as it does not
// obtain locks on the affected objects, it is sufficient for our use cases to cleanup dirty data
const txLogTag = "transaction"

Keybase proof

I hereby claim:

  • I am jiahaog on github.
  • I am jiahaog (https://keybase.io/jiahaog) on keybase.
  • I have a public key ASAnzRnL5FxfaHCJ_M4O1HsYS_yzzBKTo5sHDrBRpU3t6wo

To claim this, I am signing this object: