Skip to content

Instantly share code, notes, and snippets.

@hisui
hisui / str.cpp
Created December 28, 2012 11:05
constexprはランタイム時にも呼び出しできるから、引数の値をテンプレート引数に渡すことは出来ない件(´;ω;`)
#include <type_traits>
#include <iostream>
extern void *enabler;
// 文字のリスト
template<char H, typename T>
struct cons {};
struct nil {};
@hisui
hisui / promise.d.ts
Last active December 12, 2015 04:08
Promise+Future for JavaScript
declare module sf {
export interface Future<T> extends AsyncEither<Error,T> {
lhs():FutureProjection_L<T>;
rhs():FutureProjection_R<T>;
flatMap<B>(f: (e:Either<Error,T>) => AsyncEither<Error,B>):Future<B>;
map<B>(f: (e:Either<Error,T>) => Either<Error,B>):Future<B>;
each(f: (e:Either<Error,T>) => void):Future<T>;
}
@hisui
hisui / Play4Scalaz.scala
Last active December 14, 2015 06:48
Play2's Applicative to Scalaz's one
import scalaz._
import scalaz.Scalaz._
object Play4Scalaz {
type PlayApp[M[_]] = play.api.libs.functional.Applicative[M]
implicit def applicative[M[_]:PlayApp]:Applicative[M] =
new Applicative[M] {
override def apply[A,B](f:M[A => B], a:M[A]) = implicitly[PlayApp[M]].apply(f, a)
@hisui
hisui / LogUtil.as
Last active December 14, 2015 15:29
Getting ILogger instance with a name of a class in which statically doing it.
package {
import mx.logging.ILogger;
import mx.logging.Log;
public final class LogUtil {
public static function get cinit():ILogger
{
// This matching fails on AIR runtime..
const result:Object = /[^\/\s.:]+(?=\$cinit\(\))/.exec(new Error().getStackTrace());
@hisui
hisui / SK.txt
Last active December 16, 2015 23:49
memo
I x -> x
K c x -> c
S f g x -> f x (g x)
S' c f g x -> c (f x) (g x)
C f g x -> f x g
C' c f g x -> c (f x) g
B f g x -> f (g x)
B' c f g x -> c f (g x)
B* c f g x -> c (f (g x))
J f g x -> f g
@hisui
hisui / subst_lambda_proto.cpp
Created May 17, 2013 16:23
Unification between prototype of lambda and template parameters.
#include <iostream>
template<typename F, typename T, typename Ret, typename ...Args>
void bar(Ret (T::*func)(Args...) const, const F &f)
{
(f.*func)(Args()...);
}
template<typename F>
void foo(const F &f) { bar(&F::operator(), f); }
@hisui
hisui / BitReader.java
Last active December 17, 2015 21:49
Maybe it has bugs..
package jp.segfault.io;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
public class BitReader {
private InputStream in;
private long data;
@hisui
hisui / regexp.cpp
Created June 4, 2013 00:47
むかし2chに投稿したコード。わりとお気に入り... http://toro.2ch.net/test/read.cgi/tech/1215352849/
#include <stdio.h>
typedef char*a;struct b{b*c;a d,e;int f,g,h;int i(a&j,a k=0,b*l=0){b m={l,j,0,2
,0,1};return(*j&&*j-')'&&*j-'|'?(n(j,0,0),*j=='*'||*j=='+'&&(m.f=-1)||(m.g=2,*j
=='?')?(m.h=*++j-'?')||++j:(m.f=1),m.e=j,l=&m,0):!(k&&(j=l->d,l->c)))||l->o(j,k
);}int o(a&j,a k){b m=*this,p=m;return k?f<m.g--?n(p.d,k,&m):!m.g?i(p.e,k,c):h
&&n(p.d,k,&m)||i(p.e,k,c)||!m.h&&n(p.d,k,&m):i(j);}int n(a&j,a k,b*l,int q=0){
if(q||(q=*j++)=='('||(q=k&&(q=='$'?!*k:((q-'.'?q==*k:*k)&&++k))&&l->o(j,k),0))
while(!((q=i(j,k,l))&&k||(i(j),*j++-'|')));return q;}}r={0,0,0,0,1,1};int main(
int s,a*t){while(r.n(*t=t[1],t[2],&r,1)?(puts("ktkr."),0):*t[2]++);return 0;}
@hisui
hisui / Poly.java
Last active September 6, 2022 01:09
A concave polygon to triangles.
import java.io.*;
import java.util.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Poly extends JPanel {
public static void main(String[] args) {
@hisui
hisui / TreeDumps.scala
Created July 18, 2013 05:05
Dumps object tree to console.
import java.io.PrintStream
trait TreeDumps[T] {
def out:PrintStream
def dump_r(node:T, last:Boolean=true, indent:String=" ") {
out.println(indent + (if (last) "└" else "├") + describe(node))
val a = children(node)
if (a.size > 0) {