Skip to content

Instantly share code, notes, and snippets.

View nickytoh's full-sized avatar
🎯
Focusing

Nicky Toh nickytoh

🎯
Focusing
View GitHub Profile
@ghabs
ghabs / app.js
Created April 16, 2014 22:44
Express API tutorial
var express = require('express');
var app = express();
app.use(express.bodyParser());
var headlines = [
{ author : 'John Smith', text : "You will not believe what this child does next."},
{ author : 'Jane Doe', text : "It started as a protest, then turned into a party. Thats not even the interesting part."},
{ author : 'Alice Example', text : "Can we squeeze two hundred jellybeans in one package? Yah probably."},
{ author : 'Bob Allan', text : "This famous celebrity is opposed to something you are too."}
@jed
jed / request.js
Created April 23, 2012 03:25
prototype plugin pattern idea to make middleware less magical
function Request(req, res) {
this.upstream = request
this.downstream = response
}
Request.prototype = {
start: function() {
// kick off the default chain of handlers
},
apply plugin: 'war'
configurations { jetty9 }
dependencies.jetty9 'org.eclipse.jetty:jetty-ant:9.0.2.v20130417'
ant {
taskdef(name: 'jettyRun', classname: 'org.eclipse.jetty.ant.JettyRunTask', classpath: configurations.jetty9.asPath)
taskdef(name: 'jettyStop', classname: 'org.eclipse.jetty.ant.JettyStopTask', classpath: configurations.jetty9.asPath)
}
var crypto = require("crypto")
module.exports = function() {
var bytes = crypto.randomBytes(16)
bytes[6] &= 0x0f // 0000xxxx
bytes[6] += 0x40 // 0100xxxx
bytes[8] &= 0x3f // 00xxxxxx
bytes[8] += 0x80 // 10xxxxxx
@greenrobot
greenrobot / AsyncTaskExecutionHelper.java
Created May 23, 2012 08:26
Helper bringing back parallel execution for AsyncTask (you are no serial execution and pseudo threading wimp, right?). Uses level 11 APIs when possible.
package de.greenrobot.util;
import java.util.concurrent.Executor;
import android.os.AsyncTask;
import android.os.Build;
/**
* Uses level 11 APIs when possible to use parallel/serial executors and falls back to standard execution if API level
* is below 11.
@jed
jed / LICENSE.txt
Created May 10, 2011 16:38 — forked from 140bytes/LICENSE.txt
use cached DOM elements to escape HTML
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@erichonorez
erichonorez / rest_api.js
Created February 10, 2013 19:09
A simple REST API with Node.js and Express
/**
* TaskRepository class deals with task persistence
*/
function TaskRepository() {
this.tasks = [];
this.nextId = 1;
}
/**
* Find a task by id
* Param: id of the task to find
@songzhiyong
songzhiyong / Android-ShareCompat
Created December 9, 2013 06:32
Android 利用ShareCompat Build模式分享内容
//分享文本
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText("I'm sharing!")
.startChooser();
//分享单个文件
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.startChooser();
@jamesvnz
jamesvnz / gcmcss.js
Created September 29, 2013 20:21
Sample node.js server code to implement an XMPP server that will integrate with Android's Google Cloud Messaging (GCM) "device to cloud" message functionality - CCS. This sample only receives upstream messages (i.e. from the device).
var xmpp = require('node-xmpp');
//Set node-xmpp options.
//Replace with your projectID in the jid and your API key in the password
//The key settings for CCS are the last two to force SSL and Plain SASL auth.
var options = {
type: 'client',
jid: 'XXXXXXXXX@gcm.googleapis.com',
password: 'XXXXXXXX',
port: 5235,
@x-Code-x
x-Code-x / readme_install_node
Created April 30, 2012 20:52
Install npm node.js on Debian Squeeze / Wheezy / Linux Mint Debian Edition
#Quick cp from http://sekati.com/etc/install-nodejs-on-debian-squeeze
#
#Needed to install TileMill from MapBox
#
#Installs node.js which has npm bundled
#
#Build Dependencies
sudo apt-get update && apt-get install git-core curl build-essential openssl libssl-dev