Skip to content

Instantly share code, notes, and snippets.

@tomotaka
tomotaka / .vimrc
Created February 14, 2013 06:22
my .vimrc
imap <C-j> <esc>
set backspace=indent,eol,start
noremap 
noremap! 
noremap <BS>
noremap! <BS>
set number
@tomotaka
tomotaka / ltsv.dart
Last active December 12, 2015 07:28
LTSV parser/dumper of dart lang
class LTSV {
static Map parse(String str) {
var pairs = str.trim().split("\t");
var ret = {};
for (var pair in pairs) {
var chunks = pair.split(":");
var name = chunks.removeAt(0);
ret[name] = chunks.join(":");
}
@tomotaka
tomotaka / ThreadLocalTest.java
Created February 1, 2013 02:50
using thread-local on Java.
import java.util.Random;
public class ThreadLocalTest implements Runnable {
public static final Random RAND = new Random();
public static int counter = 1;
public static class MyObject {
private final int n;
@tomotaka
tomotaka / concurrent_cache.py
Created December 19, 2012 07:32
sample implementation of concurrent async-communication request to other server
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tornado.web
import tornado.httpserver
import tornado.gen
import tornado.ioloop
import functools
import collections
import pprint
@tomotaka
tomotaka / json_matcher.rb
Created August 14, 2012 16:00
recursive regexp pattern for JSON
# coding: utf-8
# only works on 1.9+
# base idea is from:
# - http://stackoverflow.com/questions/2583472/regex-to-validate-json
# - http://www.slideshare.net/takesako/shibuyapm16-regexpjsonvalidator
module JsonMatcher
NUMBER = /-? (?= [1-9]|0(?!\d) ) \d+ (\.\d+)? ([eE] [+-]? \d+)?/x
BOOLEAN = /true | false | null/x
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 10000000
void bit_true(char* vec, int pos) {
int char_idx = pos / 8;
int bit_idx = pos % 8;
int mask = 1 << bit_idx;
@tomotaka
tomotaka / my_msort.c
Created July 6, 2012 02:48
merge sort by C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DATA_FILE "./rand.txt"
#define N 1000000
void my_msort(int* ary, int stack_level, int sidx, int eidx) {
int i, j, tmp;
int len = eidx - sidx + 1;
@tomotaka
tomotaka / with_normal_msgpack_rpc_python.py
Created June 27, 2012 08:53
with_normal_msgpack_rpc_python.py
# perform async MessagePack RPC request
# base idea is from: https://github.com/msgpack/msgpack-rpc-python/pull/5
import tornado.web
import tornado.gen
import tornado.httpserver
import tornado.ioloop
import msgpackrpc
import msgpackrpc.loop
@tomotaka
tomotaka / tornadooption.py
Created June 27, 2012 08:27
tornadooption.py
# using https://github.com/tomotaka/msgpack-rpc-python/commit/9a116f7255a5d6c2f773ee48225cd05173b7916b
import tornado.web
import tornado.gen
import tornado.httpserver
import tornado.ioloop
import msgpackrpc
import msgpackrpc.loop
@tomotaka
tomotaka / picklefunc.py
Created June 16, 2012 08:54
callable can be pickled
import pickle
def hoge(n):
n2 = n * 2
print "this is hoge, n*2=%d" % n2
s_hoge = pickle.dumps(hoge)
loaded_hoge = pickle.loads(s_hoge)