Skip to content

Instantly share code, notes, and snippets.

View junpeitsuji's full-sized avatar

Junpei Tsuji junpeitsuji

View GitHub Profile
@junpeitsuji
junpeitsuji / query_parser.cpp
Last active December 10, 2015 14:58
Split the HTTP GET query string into the parameters.
#include <map>
#include <string>
#include <iostream>
using namespace std;
/**
* Split the HTTP GET query string into the parameters.
*
* e.g.
@junpeitsuji
junpeitsuji / postTest.html
Created January 13, 2013 17:12
Sample code to send a JSON message via POST using jQuery.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>POST TEXT HTML</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
// <!--
$(function(){
@junpeitsuji
junpeitsuji / multilayer.rb
Last active December 17, 2015 21:09
# モルフォチョウの多層膜を再現して各波長に対する反射率を計算するプログラム # # モルフォチョウの翅を 11層の多層膜をと見立て、 # クチクラ層 (屈折率1.6, 膜幅65nm), 空気層 (屈折率1.0, 膜幅130nm) として計算 # # 参考: 構造色研究会「エクセルで多層膜干渉!! 」 # http://mph.fbs.osaka-u.ac.jp/~ssc/excelde/excelde.html # # プログラム作者: @tsujimotter
require 'complex'
# モルフォチョウの多層膜を再現して各波長に対する反射率を計算するプログラム
#
# モルフォチョウの翅を 11層の多層膜をと見立て、
# クチクラ層 (屈折率1.6, 膜幅65nm), 空気層 (屈折率1.0, 膜幅130nm) として計算
#
# 参考: 構造色研究会「エクセルで多層膜干渉!! 」
# http://mph.fbs.osaka-u.ac.jp/~ssc/excelde/excelde.html
#
{"key1": "value1", "key2": "value2"}
content-type: application/json;
charset=utf-8
{ "key1": "value1", "key2": "value2" }
// 同じドメインの test.cgi から JSONデータを取得して表示
$.getJSON("test.cgi", function(data){
alert("key1:" + data.key1);
alert("key2:" + data.key2);
});
// 同じドメインの test.cgi に test.cgi?param1=value1&param2=value2 としてリクエストをかけ、
// JSONデータを取得して表示
$.getJSON("test.cgi",
{
param1: "value1",
param2: "value2"
},
function(data){
alert("key1:" + data.key1);
alert("key2:" + data.key2);
callback({ "key1": "value1", "key2": "value2" })
// クロスドメインの http://hoge.com/test.cgi からJSONPを取得
$.getJSON("http://hoge.com/test.cgi?callback=?",
function(data){
alert("key1:" + data.key1);
alert("key2:" + data.key2);
});
// 同じドメインの test.cgi から JSONデータを取得して表示
var req = new XMLHttpRequest();
req.open('GET', 'test.cgi', false);
req.send(null);
if(req.status == 200) {
var json = req.responseText;
var data = eval(json);
alert("key1:" + data.key1);
alert("key2:" + data.key2);