Skip to content

Instantly share code, notes, and snippets.

View lemonhall's full-sized avatar

lemonhall lemonhall

View GitHub Profile
last edit: 20140822 15:11
本文分析的代码是 nanomsg-0.4-beta版本。
要创建一个 PUB/SUB 服务,只需要六个 API,分别是:
1. nn_socket
2. nn_bind
3. nn_connect
4. nn_send
5. nn_recv
6. nn_close

These instructions work for the Raspberry Pi running Raspbian (hard float) and create a hardware optimized version of NodeJS for the Raspberry PI, (and include a working install and NPM!!!):

  1. Install Raspbian - http://www.raspberrypi.org/downloads

  2. Install the necessary dependecies:

sudo apt-get install git-core build-essential

(If you just installed git then you need to administer your git identity first, else adding the patches below will fail!!!)

@lemonhall
lemonhall / gist:3120320
Created July 16, 2012 03:38
FormData for XMLHttpRequest 2 - Polyfill for Web Worker (c) 2012 Rob W
/*
* FormData for XMLHttpRequest 2 - Polyfill for Web Worker (c) 2012 Rob W
* License: Creative Commons BY - http://creativecommons.org/licenses/by/3.0/
* - append(name, value[, filename])
* - toString: Returns an ArrayBuffer object
*
* Specification: http://www.w3.org/TR/XMLHttpRequest/#formdata
* http://www.w3.org/TR/XMLHttpRequest/#the-send-method
* The .append() implementation also accepts Uint8Array and ArrayBuffer objects
* Web Workers do not natively support FormData:
@lemonhall
lemonhall / arraybuffer-blob-filereader-localStorage.js
Created July 14, 2012 09:54 — forked from robnyman/arraybuffer-blob-filereader-localStorage.js
Get file as an arraybuffer, create blob, read through FileReader and save in localStorage
// Getting a file through XMLHttpRequest as an arraybuffer and creating a Blob
var rhinoStorage = localStorage.getItem("rhino"),
rhino = document.getElementById("rhino");
if (rhinoStorage) {
// Reuse existing Data URL from localStorage
rhino.setAttribute("src", rhinoStorage);
}
else {
// Create XHR, BlobBuilder and FileReader objects
var xhr = new XMLHttpRequest(),
@lemonhall
lemonhall / request302.js
Created June 27, 2012 09:09
get a 302 location
var http = require('http');
var url='http://r.autobloglink.com/?u=aHR0cDovL3BpYy5oYW5pbWFnZS5jb20vZGFiYWdpcmwvRFJFU1MvRGExMDcwNC8yLmpwZw==';
http.get(url, function(res) {
console.log("Got response: " + res.statusCode);
if(res.statusCode===302){
console.log(res.headers.location);
}
}).on('error', function(e) {
console.log("Got error: " + e.message);
@lemonhall
lemonhall / encode2gb2312.js
Created October 5, 2011 01:51
非常特殊的GB2312/GBK 的URIencode函数
function encodeToGb2312(str){
var strOut="";
for(var i = 0; i < str.length; i++){
var c = str.charAt(i);
var code = str.charCodeAt(i);
if(c==" ") strOut +="+";
else if(code >= 19968 && code <= 40869){
index = code - 19968;
strOut += "%" + z.substr(index*4,2) + "%" + z.substr(index*4+2,2);
}