Skip to content

Instantly share code, notes, and snippets.

@mingchen
mingchen / outputStreamToMemoryDemo.m
Created August 21, 2012 07:49
How to use NSOutputStream's outputStreamToMemoryDemo
- (void)outputStreamToMemoryDemo
{
NSOutputStream *output = [NSOutputStream outputStreamToMemory];
[output open];
//
//...
//
[output close];
@mingchen
mingchen / outputStreamToFileAtPathDemo.m
Created August 21, 2012 08:07
How to use NSOutputStream's outputStreamToFileAtPath
- (void)outputStreamToFileAtPathDemo
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:@"foo.dat"];
NSLog(@"file: %@", file);
NSOutputStream *output = [NSOutputStream outputStreamToFileAtPath:file append:NO];
[output open];
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import org.dojotoolkit.json.JSONParser;
import org.dojotoolkit.json.JSONSerializer;
import org.dojotoolkit.rt.v8.V8Exception;
import org.dojotoolkit.rt.v8.V8JavaBridge;
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
Google Apps for Android 4.4.4 (https://www.androidfilehost.com/?fid=23501681358544845 - gapps-kk-20140606-signed.zip)
Google Apps for Android 4.3 (https://www.androidfilehost.com/?fid=23060877490000124 - gapps-jb-20130813-signed.zip)
Google Apps for Android 4.2 (https://www.androidfilehost.com/?fid=23060877490000128 - gapps-jb-20130812-signed.zip)
Google Apps for Android 4.1 (https://www.androidfilehost.com/?fid=22979706399755082 - gapps-jb-20121011-signed.zip)
@mingchen
mingchen / fibo
Last active April 24, 2016 16:13
fibonacci number
#!/usr/bin/env python
#
# fibonacci number
#
# f(x) = f(x-1) + f(x-2)
#
def f(x):
if x == 0:
return 0;
@mingchen
mingchen / inline-input
Created May 6, 2015 21:33
Tax form style inline input box
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tax form style input box</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-rc.1/angular.min.js"></script>
<script src="script.js"></script>
#!/bin/sh
#
# Author: Ming Chen
#
# Replace git protocol git:// with https:// in .git/config
# This solve this issue when you behind a firewall like a company and your firewall ban git protocol.
#
# Example error form git:
#
# fatal: unable to connect to github.com:
@mingchen
mingchen / better-nodejs-require-paths.md
Created February 23, 2017 00:17 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@mingchen
mingchen / AesUtil.js
Created March 3, 2017 19:56 — forked from AndiDittrich/AesUtil.js
Node.js - AES Encryption/Decryption with AES-256-GCM using random Initialization Vector + Salt
/**
* AES Encryption/Decryption with AES-256-GCM using random Initialization Vector + Salt
* @type {exports}
*/
// load the build-in crypto functions
var crypto = require('crypto');
// encrypt/decrypt functions
module.exports = {
@mingchen
mingchen / gist:437629d9a2621959d6011f6c8e50302a
Created April 19, 2017 22:28 — forked from benjamingr/gist:0237932cee84712951a2
Promise unhandled rejection tracking global handler hook

Possibly Unhandled Rejection NodeJS Promise Hook

###Unhandled Rejection Tracking

Several promise libraries such as bluebird and when as well as some native promise implementations offer potentially unhandled rejection tracking. This means that the following:

Promise.reject(new Error("err")); // never attach a `catch`