Skip to content

Instantly share code, notes, and snippets.

@nnabeyang
nnabeyang / xhr2-test.html
Created December 28, 2012 09:56
xhr2でバイナリデータを送信するの続編。今回はBlobで送ります。ArrayBufferはおそらくサイズを途中で伸ばしたり、縮めたりできないので、インプットの大きさが分からない場合はBlobを使って送ればできるようです。サーバー側は https://gist.github.com/4394635 を参照してください。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>xhr2 test</title>
<body>
<input type="text" id="input"/>
<button id="send">send</button>
<script>
var inputEL = document.getElementById('input');
document.getElementById('send').addEventListener('click', function(e) {
@nnabeyang
nnabeyang / xhr2-test2.html
Created December 28, 2012 13:25
xhr2でバイナリに文字列を埋め込んだデータの送信するテスト。サーバー側の処理はhttps://gist.github.com/4394635を参照してください。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>xhr2 test</title>
<body>
<div>
<h3>インプット</h3>
<p>整数:<input type="text" id="input"/>例:"0x1, 0x3, 0x4"</p>
<p>文字列:<input type="text" id="text-input"/>例: "hello, world"</p>
<button id="send">send</button>
@nnabeyang
nnabeyang / home_controller.rb
Created January 18, 2013 09:22
rails(3.2)でformを通してpost送信されたとき、paramsの中身がどのようになっているか調べるためのスクリプトです。このスクリプトははじめに rails new form_test としたことが前提になっています。(すでにrailsの環境が整っている場合は"rails new {{project_name}} --skip-bundle"とした方が速い)
#path: project_name//app/controllers/home_controllers.rb
class HomeController < ActionController::Base
def index
end
def update
@params = params
render '/home/params'
end
end
#!/usr/bin/env python2.7
import unittest
from test import test_support
class TestClass(unittest.TestCase):
def test_answer_conserves_names(self):
self.assertEqual(len(getNames("nick.txt", True)),
len(getNames("answer.txt")))
def test_answer_nameList_is_uniq(self):
self.assertTrue(isUniq(getNames("answer.txt")))
def isUniq(l1):
class Counter:
fmt = "%d, %d"
def __init__(self):
self.db = {}
def count(self, w, h):
n = 0
assert(w < h)
n = self.db.get(Counter.fmt % (w, h), None)
if n: return n
if h % w == 0:
@nnabeyang
nnabeyang / shell_sort.py
Created January 31, 2013 05:25
シェルソート
def shell_sort(a):
size = len(a)
h = 1
while True:
h = 3 * h + 1
if h > size: break
while True:
h /= 3
#print "h=%d" % h
for i in range(h, size):
@nnabeyang
nnabeyang / MemoryCheck.java
Last active December 12, 2015 07:28
Javaのメモリ使用量(64bitマシン)の計算するプログラムを書きました。プリミティブなフィールドのみに対応します。"gen_nomethod_class.py"はテスト用のクラスの生成のために使っています。
import java.lang.reflect.Field;
public class MemoryCheck {
private static int OVERHEAD = 16;
public static int calcUsage(Class testClass) throws Exception {
int usage = OVERHEAD;
Object obj = testClass.newInstance();
for (Field field : testClass.getDeclaredFields()) {
String fieldName = field.getName();
String fieldType = field.getType().getSimpleName();
if (fieldType.equals("boolean"))
@nnabeyang
nnabeyang / bodies.yml
Last active December 19, 2015 01:28
ruby on railsでコンポジットパターン
# test/fixtures/bodies.yml
one:
id: 1
file_entry_id: 1
description: desc1
two:
id: 2
file_entry_id: 3
description: description2
@nnabeyang
nnabeyang / MyParser.hs
Created January 10, 2014 15:47
『プログラミングHaskell』の関数型パーサーをStateTを使って書き直す ref: http://qiita.com/nnabeyang/items/97d67191758dabb50752
eval :: String -> Int
eval xs = case (parse expr xs) of
Just (n, "") -> n
Just (_, out) -> error ("unused input " ++ out)
failure -> error "invalid input"
@nnabeyang
nnabeyang / calculator.lhs
Created January 13, 2014 07:13
『プログラミングHaskell』の電卓をWindowsでも動くようにする ref: http://qiita.com/nnabeyang/items/994d4fcf44a10b72445e
> import System.Console.ANSI
>
> cls :: IO ()
> -- cls = putStr "\ESC[2J"
> cls = clearScreen
>
> type Pos = (Int,Int)
>
> goto :: Pos -> IO ()
> --goto (x,y) = putStr ("\ESC[" ++ show y ++ ";" ++ show x ++ "H")