Skip to content

Instantly share code, notes, and snippets.

View ymurase's full-sized avatar

Yohsuke Murase ymurase

View GitHub Profile
@ymurase
ymurase / gist:8131297
Created December 26, 2013 08:35
sample of mongoDB map_reduce
var conn = new Mongo();
var db = conn.getDB("oacis_development");
var map = function() {
// var key = {param1: this.v["L"], param2: this.v["T"] };
var key = [ this.v["beta"], this.v["h"] ];
if( this.runs_status_count_cache ) {
var cache = this.runs_status_count_cache;
var total_runs = 0;
for(var stat in cache) {
@ymurase
ymurase / analyze_dat.rb
Created May 2, 2014 00:26
calculate ensemble average and statistical error of dat files
# calculate ensemble average and its statistical error of dat files
#
# the format of the input file is defined as follows
# each line contains key and values separated by space as follows
# <key> <val1> <val2> <val3> ...
# all the file do not necessary have the same keys
# When key is not found, the value is assumed to be zero
#
# output file format is
# <key> <ave_val1> <err_val1> <ave_val2> <err_val2> .....
@ymurase
ymurase / histo.rb
Created May 2, 2014 05:56
take histogram with normal-binning and log-binning
require 'pp'
class Histogram
def self.normal_histo(data)
histo = Hash.new(0)
data.each do |d|
histo[d] += 1
end
histo.sort_by {|a| a[0]}
@ymurase
ymurase / template.tex
Created May 7, 2014 03:32
a template of tex file
\documentclass[11pt]{article}
\usepackage{graphicx}
\begin{document}
\title{}
\author{}
\date{\today}
\maketitle
def alphametic(input)
candidate = (input =~ /[\+=]X/ or input =~ /^X/) ? 1..9 : 0..9
candidate.find {|i| eval(input.gsub('X', i.to_s).sub('=', '==')) } || "NA"
end
if __FILE__ == $0
while line = gets
puts alphametic(line.chomp)
end
end
@ymurase
ymurase / test_variance_based_sensitivity.rb
Created August 22, 2014 05:11
a test code for variance-based sensitivity analysis
require 'pp'
def f(x_vec)
a0 = 10.0
vec = [0.0, 1.0, 2.0, 3.0]
y = a0 + vec.zip(x_vec).map {|c,x| c * x }.inject(:+)
y += 2.0 * x_vec[0] * x_vec[3]
y
end
@ymurase
ymurase / oacis_install.sh
Created October 15, 2014 08:09
OACIS installation script
#!/bin/bash
#########################################
# OACIS installer for Ubuntu14.04 64bit #
#########################################
#build environment
sudo su - -c "
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
@ymurase
ymurase / angle.rb
Created October 21, 2014 00:10
A sample of ruby processing
require 'pp'
class Pendulum
def initialize(x, y, r)
@origin = PVector.new(x, y)
@r = r
@angle = Math::PI / 4
@a_velocity = 0.0
@a_acceleration = 0.0
@ymurase
ymurase / sample_rubyfann.rb
Created October 30, 2014 07:26
sample of Ruby-fann
require 'pp'
require 'ruby-fann'
def f(x,y)
Math.exp(- ((x-1.0)/2.0)**2 - (y/1.0)**2 )
end
n = 100
inputs = []
n.times do |i|
@ymurase
ymurase / asio_client.cpp
Created November 15, 2014 08:07
A sample of synchronous TCP client using boost::asio.
#include <iostream>
#include <boost/asio.hpp>
namespace asio = boost::asio;
int main() {
asio::io_service io_service;
asio::ip::tcp::socket socket(io_service);
socket.connect( asio::ip::tcp::endpoint( asio::ip::address::from_string("127.0.0.1"), 31400 ) );