Skip to content

Instantly share code, notes, and snippets.

View hagino3000's full-sized avatar

Takashi Nishibayashi hagino3000

View GitHub Profile
@hagino3000
hagino3000 / client.js
Created December 8, 2011 18:42
WebSocket with binary data
var socket = null;
function bootstrap() {
// 適当な図形を描画
var c = document.getElementById('mycanvas');
var ctx = c.getContext('2d');
ctx.globalalpha = 0.3;
for(var i=0; i<1000; i++) {
ctx.beginPath();
@hagino3000
hagino3000 / app.js
Created March 14, 2011 21:15
JSON-RPC for node (express)
/**
* Module dependencies.
*/
var express = require('express');
var rpcMethods = require('./methods.js');
var app = module.exports = express.createServer();
// Configuration
@hagino3000
hagino3000 / capture.js
Last active January 21, 2020 22:21
Capture screenshot using phantom.js
var page = new WebPage(),
address, output, size;
if (phantom.args.length != 2) {
console.log('Give me URL and filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: 1024, height: 768 };
@hagino3000
hagino3000 / method_missing.js
Last active January 16, 2020 13:11
__noSuchMethod__ for Chrome
/**
* Enable route to __noSuchMethod__ when unknown method calling.
*
* @param {Object} obj Target object.
* @return {Object}
*/
function enableMethodMissing(obj) {
var functionHandler = createBaseHandler({});
functionHandler.get = function(receiver, name) {
@hagino3000
hagino3000 / mongotransaction.js
Created April 12, 2011 04:17
Mongo transaction module
// For node-mongodb-native (npm install mongodb)
var mongodb = require('mongodb');
var MongoTransaction = function(db) {
this.db = db;
this.queue = [];
this.running = false;
this.failureFn = function(){};
}
@hagino3000
hagino3000 / cybozu-connect.js
Created August 15, 2011 04:51
Cybozu-connect API for Node
/**
* cybozu-connect for Node
*/
var jsdom = require('jsdom'),
XMLHttpRequest = require('XMLHttpRequest').XMLHttpRequest;
var document,
window,
$,
CBLabs = {},
@hagino3000
hagino3000 / urlfetch.js
Created July 10, 2012 07:03
Simple URL fetch for node
module.exports = function urlFetch(urlString, callback) {
var url = require('url').parse(urlString);
var module = url.protocol === 'https:' ? require('https') : require('http');
require('http').get({
host: url.hostname,
port: url.port,
path: url.path
}, function(res) {
var body = '';
res.on('data', function(chunk) {
@hagino3000
hagino3000 / main.cpp
Created July 19, 2011 15:14
Control Kinect tilt motor by OpenNI USB Interface
#include <stdlib.h>
#include <stdexcept>
#include <iostream>
#include <XnCppWrapper.h>
#include <XnUSB.h>
#define VID_MICROSOFT 0x45e
#define PID_NUI_MOTOR 0x02b0
XN_USB_DEV_HANDLE dev;
@hagino3000
hagino3000 / fibonacci.js
Last active December 28, 2016 21:11
asm.js sample
function fast_fib_module(stdlib, foreign, heap) {
"use asm";
function fib(n) {
n = n|0;
// nはint(符号の有無が不明の状態)
// 3はfixnum(0~2^31)
// 比較するためにnをシフト演算でunsignedに変換する
if (n >>> 0 < 3) {
@hagino3000
hagino3000 / .vimrc
Last active December 20, 2016 04:31
watchmedo(watchdog)を使ってエディタでファイルを保存する度にテストを実行する時の設定 ref: http://qiita.com/hagino3000/items/916bf61a0639b46ccffd
let OSTYPE = system('uname')
if OSTYPE == "Darwin\n"
set noswapfile
set nowritebackup
endif