Skip to content

Instantly share code, notes, and snippets.

View y-yu's full-sized avatar

YOSHIMURA Yuu y-yu

View GitHub Profile
@y-yu
y-yu / List.scala
Last active August 29, 2015 14:19
トランポリン化でStackOverflowの回避 ref: http://qiita.com/yyu/items/f1601749097ba3ee03db
package fpinscala.datastructures
sealed trait List[+A]
case object Nil extends List[Nothing]
case class Cons[+A](head : A, tail : List[A]) extends List[A]
object List {
def apply[A](as : A*) : List[A] =
if (as.isEmpty) Nil
else Cons(as.head, apply(as.tail : _*))
@y-yu
y-yu / convert.py
Last active August 29, 2015 14:17
OS Xのマウスポインターを半透明にする ref: http://qiita.com/yyu/items/5cc554f26dddc1c1b5d5
from base64 import decodestring, encodestring
from xml.etree.ElementTree import ElementTree
import sys
import io
from PIL import Image
inputfile = sys.argv[1].strip()
outputfile = sys.argv[2].strip()
opacity = sys.argv[3].strip()
@y-yu
y-yu / RedBlack.hx
Last active August 29, 2015 14:16
RedBlackTree
enum Color {
R; B; BB; NB;
}
enum RedBlackTree<T> {
T(c : Color, l : RedBlackTree<T>, v : T ,r : RedBlackTree<T>) : RedBlackTree<T>;
E : RedBlackTree<T>;
EE : RedBlackTree<T>;
}
let alphabet = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g';
'h'; 'i'; 'j'; 'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q';
'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z']
let rec nth l = function
0 -> List.hd l
| i -> nth (List.tl l) (i - 1)
let rec trans1 = function
[] -> []
class AliceFactory2 implements PersonInterface<Alice> {
public function new() { }
public function make() : AbsPerson<Alice> {
return Alice.AliceConst;
}
}
abstract AbsPerson<X>(Person<X>) {
public function new(x) {
this = x;
}
@:from public static function fromAlice(a : Alice) : AbsPerson<Alice> {
return new AbsPerson(A(a));
}
@:from public static function fromBob(b : Bob) : AbsPerson<Bob> {
@y-yu
y-yu / List2.hx
Created November 21, 2014 19:28
List2
enum List<T> {
Cons(h : T, t : List<T>, n : Int) : List<T>;
Nil : List<T>;
}
enum StreamCell<T> {
Cons(h : T, t : Stream<T>, n : Int) : StreamCell<T>;
Nil : StreamCell<T>;
}
typedef Stream<T> = Void -> StreamCell<T>
@y-yu
y-yu / QueueBenchmark.hx
Created November 20, 2014 17:52
QueueBenchmark
enum List<T> {
Cons(h : T, t : List<T>);
Nil;
}
enum StreamCell<T> {
Cons(h : T, t : Stream<T>) : StreamCell<T>;
Nil : StreamCell<T>;
}
@y-yu
y-yu / ListQueue.hx
Created November 20, 2014 05:49
ListQueue
enum List<T> {
Cons(h : T, t : List<T>);
Nil;
}
enum StreamCell<T> {
Cons(h : T, t : Stream<T>) : StreamCell<T>;
Nil : StreamCell<T>;
}
@y-yu
y-yu / LazyQueue.hx
Last active August 29, 2015 14:09
LazyQueue
enum StreamCell<T> {
Cons(x : T, t : Stream<T>) : StreamCell<T>;
Nil : StreamCell<T>;
}
typedef Stream<T> = Void -> StreamCell<T>
class LazyList<T> {
private var body : Stream<T>;
private static var nil = function () : StreamCell<T> {
return Nil;