Skip to content

Instantly share code, notes, and snippets.

View cocomoff's full-sized avatar
🏠
Working from home

Keisuke OTAKI cocomoff

🏠
Working from home
View GitHub Profile
@cocomoff
cocomoff / build.sbt
Created October 25, 2014 08:32
org.apache.commons.math3 from scala (sbt)
libraryDependencies += "org.apache.commons" % "commons-math3" % "3.2"
@cocomoff
cocomoff / fib.py
Created March 11, 2015 07:09
適当にタイムアウトするsubprocess利用(Python 2.7.9)
# coding: utf-8
import time
def fib(n):
nums = []
a, b = 1, 1
# while b <= n:
while len(nums) <= n:
a, b = b, a+b
@cocomoff
cocomoff / langton.py
Created May 28, 2015 12:56
Build png files for a GIF anime of Langton's ant
# -*- coding: utf-8 -*-
# date: 2015/05/28
# author: @taki__taki__
# packages
import numpy as np
import matplotlib.pyplot as plt
# direction (N=0, E=1, S=2, W=3)
class Direction(object):
# -*- coding: utf-8 -*-
# author: @taki__taki__
# date: 30/06/2015
from random import random
from math import exp
class SA(object):
# function
def f(self, x):
@cocomoff
cocomoff / graph.py
Created June 30, 2015 14:24
グラフ( http://blog-imgs-27-origin.fc2.com/r/i/v/riverocean/sa.png )を再現するPythonスクリプト
# -*- coding: utf-8 -*-
# author: @cocomoff
# date: 30/06/2015
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
x = np.arange(-50, 50, 1, dtype='float')
z = x / 10.0
val array = Array.ofDim[Int](2, 3)
println(array.deep)
/* Output
Array(Array(0, 0, 0), Array(0, 0, 0))
*/
#include <iostream>
#include <boost/version.hpp>
using namespace std;
int main()
{
cout << ( BOOST_VERSION / 100000 ) << "." << ( BOOST_VERSION / 100 % 1000 ) << "." << BOOST_VERSION % 100;
}
@cocomoff
cocomoff / ground_distance.jl
Created February 20, 2017 15:04
Computing Ground Distance on Earth from Latitude/Longtitude Point (e.g., http://www.nhc.noaa.gov/gccalc.shtml)
R = 6371000 # Radius of the Earth
S1 = Point(35.18028,136.90667) # Nagoya
S2 = Point(35.68944,139.69167) # Tokyo
# ground distance
function dG(Si::Point, Sj::Point)
φi, λi = deg2rad(Si.φ), deg2rad(Si.λ)
φj, λj = deg2rad(Sj.φ), deg2rad(Sj.λ)
v1 = sin( (φj - φi) / 2 )
v2 = sin( (λj - λi) / 2 )
@cocomoff
cocomoff / gist:3f3d7a918c82f46ea9c2
Created October 15, 2014 08:24
CPLEX example from C++
#include <ilcplex/ilocplex.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
const int num_of_threads = 1;
int main () {
# example: http://www.fujilab.dnj.ynu.ac.jp/lecture/system2.pdf
using JuMP
using Clp
m = Model(solver = ClpSolver())
@variable(m, 0 <= x1 <= Inf)
@variable(m, 0 <= x2 <= Inf)
# 目的関数