Skip to content

Instantly share code, notes, and snippets.

View Zodiase's full-sized avatar

Xingchen Hong Zodiase

View GitHub Profile
@Zodiase
Zodiase / eztest.api.md
Last active February 27, 2016 10:58
This is a light weight tester for NPM.
@Zodiase
Zodiase / bind_vs_apply
Created February 29, 2016 12:45
Bind beats apply.
// Once bound, apply does nothing.
(function () {console.log(this.bar);}).bind({bar: true}).apply({bar: false});
// Output: true.
@Zodiase
Zodiase / rootUrlFix.js
Last active March 31, 2016 17:55
Meteor `rootUrl` fix.
/**
* @license
* Copyright 2016 Xingchen Hong
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@Zodiase
Zodiase / promise-example-parallel.js
Last active April 4, 2016 20:41
Examples of using Promise.
// Start from a Promise.
var foo = new Promise(function (resolve, reject) {
// Has to resolve to run callbacks in `.then()`.
resolve(1);
});
foo.then(function (result) {
// Received final resolve value from the Promise.
// result === 1;
console.log('result 1', result);
@Zodiase
Zodiase / 1.Starting-up.md
Last active April 11, 2016 23:48
Factorio Layout Examples

Minimal self-sustaining mining

image

Burner inserters will pickup coals to keep themselves running while supplying others.

@Zodiase
Zodiase / chase-text2csv.js
Last active June 20, 2016 17:05
Parse the text data from Chase Checking or Saving activities and save as a CSV file.
'use strict';
const nodePath = process.argv[0],
exePath = process.argv[1],
inputPath = process.argv[2],
fs = require('fs');
if (typeof inputPath === 'undefined') {
throw new Error('Need to specify input file path.');
}
@Zodiase
Zodiase / abs_vs_if.cs
Created February 3, 2016 06:45
Performance comparison between Math.Abs and conditional negation.
using System;
using System.Diagnostics;
namespace CsTests
{
class Program
{
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
// Omit the last argument (the callback) of the original function and use promise instead.
function wrapAsPromise (func) {
var expectedArgCount = func.length - 1;
return function () {
// Only the last argument (the callback) can be missing.
switch (true) {
case arguments.length < expectedArgCount:
throw new Error('Not enough arguments given. Expecting ' + expectedArgCount + '.');
break;
case arguments.length < expectedArgCount:
/**
* @param {function} func - The function to call. The payload of the promise.
* @param {Array.<*>} args - The list of arguments for `func`.
* @param {*} ctx - The context for `func`.
*/
function makePromise(func, args, ctx) {
return new Promise(function (resolve, reject) {
try {
func.apply(ctx, Array.prototype.concat.call(args, function (err, result) {
if (err) { reject(err); } else { resolve(result); }
@Zodiase
Zodiase / Dockerfile
Last active October 18, 2016 21:10
TerraRef BD Hyperspectral Extractor notes
# Dockerfile for the TerraRef hyperspectral image conversion extractor
# August 17, 2016
FROM ubuntu:14.04
MAINTAINER Yan Y. Liu <yanliu@illinois.edu>
# install common libraries and python modules
USER root
RUN apt-get update
RUN apt-get upgrade -y -q
RUN apt-get install -y -q build-essential m4 swig antlr libantlr-dev udunits-bin libudunits2-dev unzip cmake wget git libjpeg-dev libpng-dev libtiff-dev