Skip to content

Instantly share code, notes, and snippets.

View kndt84's full-sized avatar

Takashi Kaneda kndt84

View GitHub Profile
@kndt84
kndt84 / bq-access.py
Last active August 29, 2015 14:25
PythonからGoogle APIsを利用する際のOAuth2エラーの対処方法 ref: http://qiita.com/kndt84/items/4c2b16000b0ce32b6bcf
import json
from httplib2 import Http
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
SERVICE_ACCOUNT_EMAIL = '**********@developer.gserviceaccount.com'
PROJECT_NUMBER = '**********'
KEYFILE='******************.p12'
with open(KEYFILE) as f:
@kndt84
kndt84 / Python
Last active January 14, 2016 02:49
ポアソン分布に従うカウントデータの平均値の差の検定 ref: http://qiita.com/kndt84/items/1c855df473d6a256a191
import math
import numpy as np
def pois_mean_diff_test(k1, k2, n1=1, n2=1, d=0.0):
x1_seq = range(0, k1 + 1)
x2_seq = range(0, k2 + 1)
l2k = (k1+k2)/(n1+n2) - d*n1/(n1+n2)
p_value = sum([math.exp(-n1*(l2k+d)) * np.prod([n1*(l2k+d)/i for i in range(1, x1+1)]) * \
@kndt84
kndt84 / file0.txt
Last active January 10, 2017 23:29
Node.js から API Gateway を簡単に使えるパッケージ作りました ref: http://qiita.com/kndt84/items/25445998a7c372864cde
npm install aws-api-gateway-client
@kndt84
kndt84 / main.py
Created June 3, 2017 11:35
ThingSpeak sample
#!/usr/bin/python
import smbus
import time
import sys
import requests
from datetime import datetime
api_key=''
@kndt84
kndt84 / add_unixtime.py
Last active August 4, 2017 05:45
Add unixtime to first column
#!/usr/bin/python
import csv
import sys
import re
fps=10
filename=sys.argv[1]
start_unixtime=int(re.search(r'(\d+)\.txt', filename).group(1))
@kndt84
kndt84 / intersection.cpp
Last active October 14, 2017 05:15
C++ function which tests whether two lines are intersected
int intersection(Point2i p1, Point2i p2, Point2i p3, Point2i p4) {
// Store the values for fast access and easy
// equations-to-code conversion
int x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;
int y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y;
int d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
// If d is zero, there is no intersection
if (d == 0) return 0;
@kndt84
kndt84 / app.js
Last active November 5, 2017 21:32
Express + Passport + Cognito でサーバーサイドのユーザー認証を手軽に実現 ref: http://qiita.com/kndt84/items/246d724a921d22c1eb7d
var passport = require('passport');
// passportモジュールをLoad
require('./passport')(app);
// session用のmiddlewaresを有効化
app.use(passport.initialize());
app.use(passport.session());
@kndt84
kndt84 / setup.sh
Last active March 30, 2018 02:40
Setting Up NVIDIA Docker with Ubuntu 16.04
# Install CUDA Toolkit 9.1 including NVIDIA Driver
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
# Install Docker CE
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
import os
import glob
from PIL import Image, ImageOps
path_list = glob.glob('*.png')
for path in path_list:
filename, ext = os.path.splitext( os.path.basename(path) )
im = Image.open(path)
#!/usr/local/bin/python3
import glob
import numpy as np
import cv2
import sys
import os
import shutil
label='Ossicle'