Skip to content

Instantly share code, notes, and snippets.

View belltailjp's full-sized avatar

Daichi SUZUO belltailjp

View GitHub Profile
@belltailjp
belltailjp / toyota_stadium.json
Created December 15, 2015 13:27
Example of OpenWeatherMap forecast API
% curl "http://api.openweathermap.org/data/2.5/forecast/daily?lat=35.0845611&lon=137.1706404&units=metric&appid=YOURAPIKEY"
{
"city": {
"id": 1849814,
"name": "Toyota",
"coord": {
"lon": 137.149994,
"lat": 35.083328
},
"country": "JP",
@belltailjp
belltailjp / nagoya.json
Last active December 14, 2015 13:15
Example of Livedoor weather API call (Nagoya-city)
% curl "http://weather.livedoor.com/forecast/webservice/json/v1?city=230010" | jq '.'
{
"pinpointLocations": [
{
"link": "http://weather.livedoor.com/area/forecast/2310000",
"name": "名古屋市"
},
{
"link": "http://weather.livedoor.com/area/forecast/2320200",
"name": "岡崎市"
@belltailjp
belltailjp / gist:a9538aaf3221f754e5bf
Last active August 29, 2015 14:21
Inter-conversion between numpy ndimage and PySide QImage
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy
import skimage.io
from PySide.QtGui import *
skimg = skimage.io.imread('imgfile.jpg')
# convert to QImage (skimg can be grayscale or rgb)
@belltailjp
belltailjp / benchmark.py
Last active August 29, 2015 14:20
Benchmark of enforcing 1st row/col to be smaller than the second.
import numpy
from benchmarker import Benchmarker
N = 10 ** 8
with Benchmarker(1000) as bench:
@bench('col-proposed')
def _(bm):
a = numpy.random.randint(0, 100, (2, N))
@belltailjp
belltailjp / row-wise.py
Created May 5, 2015 12:55
Enforce 1st column to be smaller than the 2nd
# Construct 2-column ndarray
>>> a = numpy.random.randint(0, 100, (10, 2))
>>> a
array([[29, 1],
[33, 36],
[79, 32],
[72, 52],
[30, 9],
[33, 85],
[72, 29],
@belltailjp
belltailjp / column-wise.py
Last active August 29, 2015 14:20
Enforce 1st row to be smaller than the 2nd
# Construct 2-row ndarray
>>> a = numpy.random.randint(0, 100, (2, 10))
>>> a
array([[95, 31, 25, 68, 88, 25, 71, 55, 16, 14],
[57, 59, 38, 30, 78, 92, 30, 47, 89, 41]])
# Extract columns whose 1st row is larger than the 2nd.
>>> a[:, a[1] < a[0]]
array([[95, 68, 88, 71, 55],
[57, 30, 78, 30, 47]])
@belltailjp
belltailjp / discrete_distribution_omikuji.cpp
Created February 6, 2013 13:47
C++11のstd::discrete_distributionを使ったときのおみくじプログラム
#include <iostream>
#include <random>
int main()
{
std::vector<int> prob = {1, 9, 25, 25, 30, 9, 1};
const std::string str[] = {"大吉", "中吉", "小吉", "吉末", "吉", "凶", "大凶"};
std::mt19937 rng;
std::discrete_distribution<int> dst(prob.begin(), prob.end());
@belltailjp
belltailjp / plain_omikuji.cpp
Created February 6, 2013 13:45
一様乱数だけあるときのおみくじプログラム
#include <iostream>
#include <random>
int main()
{
std::vector<int> prob = {1, 9, 25, 25, 30, 9, 1};
const std::string str[] = {"大吉", "中吉", "小吉", "吉末", "吉", "凶", "大凶"};
std::mt19937 rng;
//出現確率を累積に変換
@belltailjp
belltailjp / simd.cpp
Created January 28, 2013 07:38
SSE,AVX組み込み関数を用いたベクトルの内積計算高速化の実験コード
#include <iostream>
#include <random>
#include <algorithm>
#include <boost/format.hpp>
#include <xmmintrin.h>
#include <immintrin.h>
#include <osakana/stopwatch.hpp>
#include <glog/logging.h>
void func()
{
throw;
}
int main(int argc, char *argv[])
{
//google glogの初期化