Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Gab-km / tryFinallySample.fs
Last active October 7, 2015 04:48
「できる!コンピュテーション式」のサンプルコード vol.2
type TFBuilder() =
member self.TryFinally (x, f) =
f ()
x
member self.Delay f = f ()
member self.Bind (x, f) = f x
member self.Return x = x
let tfb = TFBuilder()
@Gab-km
Gab-km / DropAndRefundTest.groovy
Created June 24, 2012 13:21
Cafe.Spockの成果物
import spock.lang.*
class DropAndRefundTest extends spock.lang.Specification {
def setup(){
}
@Unroll
def "自販機に #money を投入できる"() {
setup:
@Gab-km
Gab-km / exam.fs
Created May 29, 2012 16:19
アクティブパターンの練習
open System
type Result =
| Perfect
| Excellent
| Good
| Bad
let exam yourScore =
if yourScore = 100 then Perfect
@Gab-km
Gab-km / Imperative.fs
Created April 28, 2012 19:51
手続き型の書き方
module Imperative
open System
open System.Text
open System.Security.Cryptography
let generateKeyFromPassword password keySize blockSize =
//パスワードから共有キーと初期化ベクタを作成する
//saltを決める
let salt = Encoding.UTF8.GetBytes "saltは必ず8バイト以上"
@Gab-km
Gab-km / MultiParadigm.fs
Created April 28, 2012 19:59
マルチパラダイムの書き方
module MultiParadigm
open System
open System.Text
open System.Security.Cryptography
let generateKeyFromPassword password keySize blockSize =
//パスワードから共有キーと初期化ベクタを作成する
//saltを決める
let salt = Encoding.UTF8.GetBytes "saltは必ず8バイト以上"
@Gab-km
Gab-km / TupleTest.html
Created March 2, 2012 18:11
Tuples, immutable groups ... but my tuples are very poor :(
<!DOCTYPE html>
<html>
<head>
<title>Tuple test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="tuple.js"></script>
</head>
<body>
<div id="output" />
</body>
@Gab-km
Gab-km / OptionTest.html
Created March 2, 2012 13:54
Option, which you may know as 'Maybe'.
<!DOCTYPE html>
<html>
<head>
<title>Option test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="option.js"></script>
</head>
<body>
<div id="output" />
</body>
@Gab-km
Gab-km / myJsUnit.js
Created March 1, 2012 14:52
FizzBuzz with TDD in Javascript
function write(message) {
document.getElementById("output").innerHTML += message + "<br />";
}
function assertEquals(expected, actual) {
if (expected == actual) {
write("OK");
} else {
var text = "expected = [" + expected.toString()
+ "], but actual = [" + actual.toString() + "]."
@Gab-km
Gab-km / hgrc
Created February 19, 2012 15:10
hg now (for Windows)
# hgrc
# hg-now is the simple alias inspired by git-now.
# (http://d.hatena.ne.jp/sinsoku/20101208/1291770514)
# and it is for Windows environments.
# if you use some Unix base operating systems, like Linux distributions, BSDs or Macs,
# please hack it in your environment.
[alias]
# create a temporary commit.
now = ! hg commit -m "[from now] %date% %time%"
@Gab-km
Gab-km / gist:1601627
Created January 12, 2012 16:56
簡易顔文字メーカー
# -*- coding: utf-8 -*-
import random
import datetime
left_brows = ['´', '`', '']
left_eyes = ['・', '^', ';', '>', '']
mouths = ['ω', '∀', 'ρ', '_', 'Д', 'д', '']
right_eyes = ['・', '^', ';', '<', '']
right_brows = ['´', '`', '']