Skip to content

Instantly share code, notes, and snippets.

View chiral's full-sized avatar

Masayuki Isobe chiral

  • Adfive, Inc.
  • Taito-ku, Tokyo, Japan.
View GitHub Profile
@chiral
chiral / coroutine.hpp
Last active December 11, 2015 17:48
a solution of producer-consumer problem without using lock primitives.
class coro { // コルーチンもどき
protected:
int coro_state;
public:
coro():coro_state(0){}
virtual ~coro(){}
void init() {coro_state=0;}
};
#define begin switch(coro_state){ case 0:
#define end default: break;}
@chiral
chiral / Main.js
Created February 10, 2013 10:05
node.js + express + socket.io : drawing chat example
var _stage = null;
var _width = 640;
var _height = 480;
var _ip = "";
var _port = 0;
var _sid = 0;
var _r = 240;
var _g = 240;
@chiral
chiral / bookmaker.rb
Last active December 14, 2015 10:59
automatical epub generator. contents xpath can be specified with yaml file. css and img files are implicitly included and converted url references.
# -*- coding: utf-8 -*-
require 'erb'
require 'uri'
require 'yaml'
require 'nokogiri'
require 'open-uri'
require 'fileutils'
require 'pathname'
require 'gepub'
@chiral
chiral / libev_periodic_test.cpp
Created April 27, 2013 15:13
libev periodic timer resolution test
#include <stdio.h>
#include <sys/time.h>
#include <ev.h>
const int log_size = 10000;
double log[log_size];
int log_index=0;
double now_usec() {
timeval tv;
@chiral
chiral / pub.cpp
Created April 28, 2013 00:51
PUB/SUB for respective process on ZeroMQ example.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <unistd.h>
#include <zmq.hpp>
const int max_peer = 3;
@chiral
chiral / natural_sort.pl
Created May 29, 2013 12:32
natural sort in perl
sub mycmp {
my $an = @{$a->[1]}+@{$a->[2]};
my $bn = @{$b->[1]}+@{$b->[2]};
my $n = $an<$bn ? $an : $bn;
foreach my $i (0..$n-1) {
my $aa = $a->[$i%2+1][$i/2];
my $bb = $b->[$i%2+1][$i/2];
my $res = $aa=~/^\d+$/ && $bb=~/^\d+$/ ? $aa <=> $bb : $aa cmp $bb;
return $res if ($res!=0);
}
@chiral
chiral / master.R
Created June 1, 2013 08:50
demo for ZeroMQ on R Pi caluculation
library('rzmq')
context = init.context()
sock1 = init.socket(context,"ZMQ_PUSH")
bind.socket(sock1,"ipc:///test1")
sock2 = init.socket(context,"ZMQ_PULL")
bind.socket(sock2,"ipc:///test2")
nw <- 10000
@chiral
chiral / clickjack.html
Created June 7, 2013 11:15
iframe clickjacking
<html>
<head>
<title>テスト</title>
<meta charset="UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
</head>
<body>
<div class="mytest">
<iframe class="mytest1" style="position:absolute;left:0;top:0;" src="./sample.html" frameborder=0 width=510 height=400 scrolling=no></iframe>
<div class="mytest2" style="position:absolute;left:0;top:0;width:510px;height:400px;" frameborder=0 width=510 heigh\
@chiral
chiral / qshogi.hs
Last active September 29, 2020 01:36
Quantum Shogi Program in Haskell
------------------------------------------------------------
-- Quantum Shogi Program in Haskell
------------------------------------------------------------
module Main where
import System.Environment
import Data.Maybe
import Data.List
import Data.Char
@chiral
chiral / ma_bundit.R
Last active December 27, 2015 14:29
multi-armed-bundit simulation with simple e-greedy strategy
# m=arms, n=biddings, h=trials
simulation <- function(m,n,h,binom,pois,strategies) {
ss <- length(strategies)
score <- list()
bid <- list()
for (i in 1:ss) { score[[i]] <- rep(0,n) }
for (t in 1:h) {
for (i in 1:ss) {