Skip to content

Instantly share code, notes, and snippets.

@nowelium
nowelium / 0.bootstrap
Created April 27, 2013 17:40
Multiple mysqld server
shell > vagrant box add centos http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130309.box
shell > vagrant init centos
shell > vi Vagrantfile
# Vagrantfile below: #1.Vagrantfile
shell > vagrant up
:
:
shell > vagrant ssh-config db1 >> $HOME/.ssh/config
shell > vagrant ssh-config db2 >> $HOME/.ssh/config
shell > vagrant ssh-config db3 >> $HOME/.ssh/config
@nowelium
nowelium / Timer.io
Last active December 16, 2015 05:09
non-blocking Timer
Thread
Socket
Server
Timer := Object clone
Timer do (
counter := 0
increment := method(
counter = counter + 1
)
@nowelium
nowelium / Timer.io
Created April 14, 2013 11:49
Obsolute Timer
Timer := Object clone do (
ScheduleUnit := Object clone do(
newSlot("command", nil)
newSlot("period", nil)
init := method(
self initial := Date now asNumber
self current := Date now asNumber
)
execute := method(
self current = Date now asNumber
@nowelium
nowelium / A.java
Last active December 15, 2015 17:19
import java.io.File;
import java.io.FileOutputStream;
public class A {
public static void main(String...args) throws java.io.IOException {
final File file = new File("/tmp/a");
final FileOutputStream output = new FileOutputStream(file);
Thread th0 = new Thread(new Runnable(){
public void run() {
@nowelium
nowelium / badapple.js
Created March 27, 2012 22:42
node.jsを使って【東方】Bad Apple!! PV【影絵】をコンソールに出力してみる
var fs = require('fs');
var util = require('util');
var async = require('async');
var Bitmap = require('./bitmap');
//
// ニコニコ動画の【東方】Bad Apple!! PV【影絵】 <http://www.nicovideo.jp/watch/sm8628149>
// を 30fps な bitmap に分割したので、
// それを読み込みつつ、コンソールに表示してみる。
@nowelium
nowelium / posterous_backup.js
Created March 23, 2012 19:34
posterous REST API. using 'request' module
var async = require('async');
var mysql = require('mysql');
var request = require('request');
var qs = require('querystring');
var Posterous = function(user, password, apiToken){
this.user = user;
this.password = password;
this.token = apiToken;
};
var crypto = require('crypto');
var b = crypto.createHash('md5').update('hoge').digest('binary');
var c = crypto.createHash('md5').update('hoge').digest('hex');
var d = []; for(var i = 0; i < b.length; ++i){ if(b.charCodeAt(i) < 10){ d.push('0' + b.charCodeAt(i).toString(16)) } else { d.push(b.charCodeAt(i).toString(16)) } }
c
==> 'ea703e7aa1efda0064eaa507d9e8ab7e'
d.join('')
==> 'ea703e7aa1efda0064eaa507d9e8ab7e'
@nowelium
nowelium / t.php
Created February 23, 2012 07:16
trie
<?php
class Trie {
private $root;
public function __construct() {
$this->root = new TrieNode;
}
public function addString($str, $index){
$this->root->addString($str, $index);
@nowelium
nowelium / gist:1869204
Created February 20, 2012 13:28
todo ti-websocket-client payload size > 65536
//
// buffer size(65536) を超えてしまうと、上手くframe分割とかされないようなので
// なんとかしてみようとする試み(データは送れるけど、、、版)
//
WebSocket.prototype._create_frame = function(opcode, d, last_frame) {
if(typeof last_frame === 'undefined') {
last_frame = true;
}
@nowelium
nowelium / gist:1869184
Created February 20, 2012 13:26
todo ti-websocket-client RFC6455
//
// ti-websocket-client を RFC6455 に対応してみようとする試み。(未完成)
// * 下記を参考にtitanium的に置き換えてみる
// https://github.com/einaros/ws/blob/master/lib/Sender.js
// https://github.com/einaros/ws/blob/master/lib/BufferUtilWindows.js
//
WebSocket.prototype._create_frame = function(opcode, d, last_frame) {
if(typeof last_frame === 'undefined') {
last_frame = true;