Skip to content

Instantly share code, notes, and snippets.

@ando-takahiro
ando-takahiro / cluster-worker-id.js
Created November 20, 2012 08:26
what is cluster.worker.id?
var cluster = require('cluster');
if (cluster.isMaster) {
for (var i = 0; i < 4; ++i) {
cluster.fork();
}
} else {
console.log(process.pid, cluster.worker.id);
}
/* package.json
{
"name": "photo",
"version": "0.0.0",
"description": "ERROR: No README.md file found!",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {"shelljs":"*", "underscore.string": "*"},
@ando-takahiro
ando-takahiro / delta-dropbox.json
Created March 20, 2013 08:23
one example of response from dropbox /delta API
{
"reset":true,
"cursor":"AAHskXVmJSRVG_bgh4Oq2VPQqG79nWM26Tl8jSmRyiGM3M0EGLzi_df861bAJ6q5xzkbQD7WhMTh8cEA2s1GUlDg79gRBPQJ6D5vJvah2sZrBg",
"has_more":false,
"entries":[
["/proj1",{"revision":3,"rev":"30ec9923d","thumb_exists":false,"bytes":0,"modified":"Wed, 20 Mar 2013 05:58:43 +0000","path":"/proj1","is_dir":true,"icon":"folder_app","root":"app_folder","size":"0 bytes"}],
["/proj1/current",{"revision":6,"rev":"60ec9923d","thumb_exists":false,"bytes":0,"modified":"Wed, 20 Mar 2013 05:58:48 +0000","path":"/proj1/current","is_dir":true,"icon":"folder_app","root":"app_folder","size":"0 bytes"}],
["/proj1/backup",{"revision":9,"rev":"90ec9923d","thumb_exists":false,"bytes":0,"modified":"Wed, 20 Mar 2013 05:58:59 +0000","path":"/proj1/backup","is_dir":true,"icon":"folder_app","root":"app_folder","size":"0 bytes"}],
["/proj1/current/test.txt",{"revision":12,"rev":"c0ec9923d","thumb_exists":false,"bytes":34,"modified":"Wed, 20 Mar 2013 06:10:51 +0000","client_mtime":"Wed, 20 Mar 2013 06:10:4
@ando-takahiro
ando-takahiro / install.sh
Last active August 29, 2015 14:05 — forked from vvakame/Brewfile
brew install the-silver-searcher
brew install tree
brew install curl
brew install wget
brew install tmux
brew install zsh
brew install zsh-completions
brew install git
brew install boot2docker
var ts = require('tail-stream');
require('http').createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
var stream = ts.createReadStream(req.url.substr(1), {
detectTruncate: true,
onTruncate: 'end',
endOnError: false
});
@ando-takahiro
ando-takahiro / Coro1.cs
Last active August 29, 2015 14:06
unityのcoroutineは同じGameObject中であっても、MonoBehaviour毎に管理される。StopAllCoroutines()はマニュアル通り、MonoBehaviour毎に消される。
using UnityEngine;
using System.Collections;
public class Coro1 : MonoBehaviour {
IEnumerator Task() {
while (true) {
Debug.Log("Coro1");
yield return new WaitForSeconds(1);
}
@ando-takahiro
ando-takahiro / Post.cs
Last active August 29, 2015 14:06
node.js style REST client function for unity3d. paste bellow into your MonoBehaviour.
protected delegate void OnResponse(string error, string body);
protected void Post(string url, Dictionary<string, string> options, OnResponse onResponse)
{
StartCoroutine(PostFlow(url, options, onResponse));
}
protected IEnumerator PostFlow(string url, Dictionary<string, string> options, OnResponse onResponse)
{
if (options == null)
{
@ando-takahiro
ando-takahiro / markdown-js-dialect-example.js
Created October 13, 2014 12:56
this shows how to implement a ruby feature ( http://conv.denshochan.com/markdown#ruby ). tested on node 0.10.30 & markdown-js 0.5.0
var Markdown = require('markdown').markdown.Markdown;
var MyDialect = Markdown.subclassDialect(Markdown.dialects.Gruber);
MyDialect.inline['{'] = function inline_ruby(text, matches, out) {
var m = text.match(/^\{(.+)\|(.+)\}/);
if (m) {
return [m[0].length, ['ruby', m[2], m[1]]];
} else {
// no match
return [1, '{'];
}
@ando-takahiro
ando-takahiro / set-timeout-libuv.cc
Last active August 29, 2015 14:08
THIS HAS BUGS: JS's setTimeout in C++ on libuv
template <typename Fn>
void set_timeout(Fn fn, uint64_t timeout, uv_loop_t* l = nullptr) {
struct payload {
uv_timer_t timer;
Fn fn;
payload(Fn&& f) : fn(f) {}
};
payload* p = new payload(std::move(fn));
if (!l) {
@ando-takahiro
ando-takahiro / gist:28033ae1ad87a05029ea
Last active August 29, 2015 14:13
what I did to build libuv with cocos2d-x(3.0series)

iOS

  • $ ./gyp_uv.py -f xcode
  • make project from the generated xcodeproj

reference: libuv/libuv#137

Android