Skip to content

Instantly share code, notes, and snippets.

View junpeitsuji's full-sized avatar

Junpei Tsuji junpeitsuji

View GitHub Profile
// クロスドメインの http://hoge.com/test.cgi からJSONPを取得
var hoge = function(data) {
alert("key1:" + data.key1);
alert("key2:" + data.key2);
}
var script = document.createElement('script');
script.src = 'http://hoge.com/test.cgi?callback=hoge';
document.head.appendChild(script);
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
// クロスドメインの http://hoge.com/test.cgi からJSONPを取得 (再掲)
$.getJSON("http://hoge.com/test.cgi?callback=?",
function(data){
alert("key1:" + data.key1);
alert("key2:" + data.key2;
}
);
functionName({ "key1": "value1", "key2": "value2" })
@junpeitsuji
junpeitsuji / boids.html
Created November 23, 2013 12:51
Boids シミュレーション をブラウザで
<!DOCTYPE html>
<title>Boids Simulation</title>
<h1>Boids Simulation</h1>
<canvas id="canvas" width="640" height="480"></canvas>
<style>
/**
* html body に設定される自然な
* margin padding を除去する
*/
html, body {
@junpeitsuji
junpeitsuji / boids.html
Created November 25, 2013 11:07
「Boids シミュレーション をブラウザで」 をゲーム化しました。コピペして遊んでください。
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Boids Sims.</title>
<h1>Boids Sims.</h1>
<ul>
<li>ブラウザ上の画面をクリックして、<b>青い丸(えさ)</b>の位置を変えます。</li>
<li><b>赤い丸(ボイド)</b>が<b>えさ</b>に群がります。</li>
<li><b>ボイド</b>が<b>緑色の丸(敵)</b>にぶつかると消えてしまいます。</li>
<li>すべて消えてしまうと<b>ゲームオーバー</b>。ゲームが続いた時間が長ければ長いほど高いスコアになります。</li>
<li>えさでうまく誘導してボイドの群れを生き延びさせましょう!</li>
int analogPin = 0;
int pwm_a = 3; //PWM control for motor outputs 1 and 2 is on digital pin 3
int pwm_b = 11; //PWM control for motor outputs 3 and 4 is on digital pin 11
int dir_a = 12; //direction control for motor outputs 1 and 2 is on digital pin 12
int dir_b = 13; //direction control for motor outputs 3 and 4 is on digital pin 13
int val = 0; //value for fade
int v = 0;
# coding: utf-8
require 'opencv'
require 'fileutils'
dropbox_dir = "/path/to/Dropbox" # ここだけ自分用に書き換えてください
# 0 番だと Mac のインカメラが選択されてしまうので 1 番を選択
capture = OpenCV::CvCapture.open 1
@junpeitsuji
junpeitsuji / binom.rb
Last active March 6, 2020 00:30
binom.rb - 二項係数を3パターンで実行するスクリプト
require 'benchmark'
_MAXNUM=1000
#=begin
# 二項係数 nCk を計算する関数 ver.1
def binom_v1(n,k)
if k==0 then
return 1
@junpeitsuji
junpeitsuji / class_number.rb
Last active August 29, 2015 14:25
正定値二次形式の類数を計算する Ruby スクリプト
# 正定値二次形式の類を列挙するプログラム
# created by Junpei Tsuji <http://tsujimotter.info>
require 'prime'
require 'set'
# a, b, c を係数とする二次形式 f(x, y) = ax^2 + bxy + cy^2 を表すクラス
class QuadraticForm
def initialize a,b,c
@a = a