Skip to content

Instantly share code, notes, and snippets.

@s-shin
s-shin / oauth2.py
Created June 1, 2012 16:30
This module is a sample of the OAuth2 authentication by Python3
#!/usr/bin/env python3
"""This module is a sample of the OAuth2 authentication by Python3"""
__version__ = "0.1.0"
__author__ = "shin (shin.hateblo.jp)"
__copyright__ = "(C) 2012 shin"
__email__ = "[email protected]"
__license__ = "Apache License 2.0"
__status__ = "Prototype"
@s-shin
s-shin / spigot.js
Created August 16, 2012 08:18
Simple Pi calculation library for JavaScript
/**
* spigot.js
* version 1.1.0
* (C) 2012 shin <s2pch.luck at gmail.com>
* Licensed under the Apache License 2.0
* http://opensource.org/licenses/apache2.0
*
* The Pi calculation is based on the spigot (streaming) algorithm[1].
* This library depends on jsbn[2] (jsbn.js and jsbn2.js),
* one of BigInteger library written by pure JavaScript.
@s-shin
s-shin / simple-server.py
Last active October 10, 2015 04:08
simple server by python3.x
#! /usr/bin/env python3
import sys
import http.server
port = 3000 if len(sys.argv) == 1 else int(sys.argv[1])
httpd = http.server.HTTPServer(
('localhost', port), http.server.SimpleHTTPRequestHandler)
httpd.serve_forever()
@s-shin
s-shin / jsdoit.js
Created November 4, 2012 10:05
Snipet to setup user media by WebRTC
// ## Snipet to setup user media by WebRTC (modified at 20121104)
// This code checked on GC(22), Opera(12), Fx(Nightly) in Mac OSX.
// In addition, only the FaceTime camera is tested.
// Compatibility table: http://caniuse.com/stream
var setupUserMedia = function(media, fn) {
if (arguments.length == 1) {
fn = media;
media = {video: true, audio: true};
}
@s-shin
s-shin / codevs2.rb
Last active December 11, 2015 09:08
CodeVS2.0で書いたコード。あまりの遅さに愕然! 順位は論外なので秘密ですが、ものすごくRubyの勉強になったので良しとします。
# encoding: utf-8
# 出来る限りロジックに集中できるようにモジュール化する
# 座標系はxが→、yが↑で、左下が(0, 0)で統一する。
# (つまりフィールドでもパックでも同じ)
# 2次元配列はy, xの順とする(ex. field[y][x])。
# 依存モジュール
require 'matrix' # 回転で使用
require 'logger' # デバッグログ出力で使用
@s-shin
s-shin / torimasaba.rb
Last active December 21, 2015 05:49
ワーキングディレクトリをパプリックディレクトリにする簡易サーバ。ローカル内でファイル転送したい時に便利。 $ ruby -e "$(curl -fsSL https://gist.github.com/s-shin/6259910/raw/torimasaba.rb)" で一時保存も必要なし。
require "webrick"
server = WEBrick::HTTPServer.new({
DocumentRoot: "./",
Port: ARGV[0] ? ARGV[0].to_i : 8080,
MimeTypes: WEBrick::HTTPUtils::DefaultMimeTypes.merge({
"js" => "application/javascript"
})
})
server.mount("/", WEBrick::HTTPServlet::FileHandler, Dir.pwd, {FancyIndexing: true})
@s-shin
s-shin / detect-square-markers.py
Last active January 11, 2018 13:58
A tutrial in which square markers in an image are detected with OpenCV 2.4 in Python 2.7.
# -*- coding: utf-8 -*-
"""Tutrial: Detect square markers with OpenCV 2.4 in Python 2.7.
(C) 2013 Shintaro Seki
MIT License
The marker used in this program can be generated by the following script.
cv2.imwrite("marker.png", cv2.resize(np.array([
[0, 0, 0, 0],
import numpy as np
def create_sphere(radius, slices, stacks):
"""Create a sphere geometry dynamically like glutSolidSphere().
:param radius: Radius of sphere.
:param slices: A number of slices of longitude.
:param stacks: A number of stacks of latitude.
"""
radius = float(radius)
@s-shin
s-shin / jquery.swapimg.js
Created December 27, 2013 05:22
昔片手間に作った画像入れ替えjQueryプラグイン。偶然発掘したので記録。ただ今はCSSで背景を変えるのが一般的か。
// jquery.swapimg
// (C) 2013 Shintaro Seki
// MIT License
$.fn.swapimg = function(option) {
var op = {
suffix: "_o",
preload: true,
swapped_file: null
};
$.extend(true, op, option);