Skip to content

Instantly share code, notes, and snippets.

View yoshihiro503's full-sized avatar

YOSHIHIRO Imai yoshihiro503

View GitHub Profile
@yoshihiro503
yoshihiro503 / Cop_3_6.scala
Created July 2, 2012 09:14
コップ本の3.6節の例題の別解を考えてみた。 https://twitter.com/yoshihiro503/status/219719644041318400
import scala.io.Source
def widthOfLength(s: String) = s.length.toString.length
def format(maxWidth : Int, line : String) = {
val padding = " " * (maxWidth - widthOfLength(line))
padding + line.length + " | " + line
}
def formatLines(lines : List[String]) : List[String] = {
@yoshihiro503
yoshihiro503 / Check.scala
Created July 3, 2012 09:54
コップ本の3.6節の例題の別解を自動テストしてみた
import org.scalacheck.Properties
import org.scalacheck.Prop._
import Cop3_6._
/**
* ScalaCheck を使った自動テスト
*/
object Check extends Properties("コップ本3.6") {
//リストの要素がすべて同じかどうか判定する便利関数
let document = Dom_html.document;;
let window = Dom_html.window;;
print_endline "Hello, world!";;
window##alert(Js.string "Hello");;
let document = Dom_html.document;;
let window = Dom_html.window;;
print_endline "Hello, world!";;
window##alert(Js.string "Hello");;
@yoshihiro503
yoshihiro503 / gist:3409658
Created August 21, 2012 00:16
js_of_ocamlでボタンを追加するサンプル
let document = Dom_html.document;;
let window = Dom_html.window;;
let b = Dom_html.createInput ~_type:(Js.string "button") document;;
b##value <- Js.string "Push Me";;
b##onclick <- Dom_html.handler (fun _ -> window##alert(Js.string "hello"); Js._true);;
let top = Js.Opt.get (document##getElementById(Js.string "toplevel")) (fun () -> assert false);;
Dom.appendChild top b;;
Js.Unsafe.set
(Dom_html.document##body##style)
"webkitTransform"
"rotate(30rad)";;
@yoshihiro503
yoshihiro503 / gist:3594925
Created September 2, 2012 04:59
Proofsummit_omega
Require Import Psatz ZArith.
Open Scope Z_scope.
Goal forall x y, 27 <= 11 * x + 13 * y <= 45 -> -10 <= 7 * x - 9 * y <= 4 -> False.
intros.
lia.
@yoshihiro503
yoshihiro503 / gist:3630859
Created September 5, 2012 05:08
OptionMonad_Java
import fj.F;
import fj.Unit;
import fj.data.Option;
public class Main {
static void take1() {
for (final String s : foo()) {
for (final Float f : bar()) {
for (final Integer i : baz()) {
@yoshihiro503
yoshihiro503 / distance.ml
Created September 14, 2012 09:51
OCamlで、点と直線の距離、点と線分の距離、点と半直線の距離
(* ベクトルの内積 *)
let ( ** ) (x,y) (a,b) = x *. a +. y *. b
(* 2点間の距離 *)
let distance (x,y) (a,b) = sqrt ((x -. a) * (x -. a) + (y -. b) * (y -. b))
(* 点(px,py) と 直線(x1,y1)(x2,y2)の距離 *)
let distance_to_line (x1,y1) (x2,y2) (px,py) =
let b, c = (x2-.x1,y2-.y1), (px-.x1,py-.y1) in
let dotprod = b ** c in
@yoshihiro503
yoshihiro503 / TaskMonad.cs
Created November 19, 2012 12:16
C# で非同期タスク モナド書いてみた。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Proofcafe
{
class TaskMonad