Skip to content

Instantly share code, notes, and snippets.

@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;
#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 / 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
@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 / 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 / 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 / .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 / .zshrc
Created February 14, 2013 06:25
my .zshrc
setopt prompt_subst
setopt print_eight_bit
setopt no_flow_control
setopt hist_ignore_dups
setopt hist_reduce_blanks
#setopt share_history
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
@tomotaka
tomotaka / .screenrc
Created February 14, 2013 06:27
my .screenrc
escape
startup_message off
#attrcolor b ".I"
defbce on
term xterm-256color
termcapinfo xterm* ti@:te@
termcapinfo xterm-256color 'is=J7h1;4;6l'
vbell off
hardstatus alwayslastline "%`%-w%{=b bw}%n %t%{-}%+w"
autodetach on
@tomotaka
tomotaka / onready.js
Created July 11, 2013 09:29
jQuery onReady
$(function(){
// do something onready
]});