Skip to content

Instantly share code, notes, and snippets.

View keichi's full-sized avatar

Keichi Takahashi keichi

View GitHub Profile
@keichi
keichi / gist:1014369
Created June 8, 2011 12:58
Show Expression Tree with parenthesis
instance Show Expression where
show e = showWithParen 0 e where
showWithParen _ (Symbol x) = x
showWithParen _ (Number x) = show x
showWithParen _ (Func name e) = name ++ "(" ++ show e ++ ")"
showWithParen w (Op op e1 e2) = head ++ showWithParen curOpWeight e1 ++ show op ++ showWithParen curOpWeight e2 ++ foot where
head = if w > curOpWeight then "(" else ""
foot = if w > curOpWeight then ")" else ""
curOpWeight = getOpWeight op
@keichi
keichi / gist:1054062
Created June 29, 2011 15:18
FizzBuzz without using Mod, Mul, Div
import Control.Monad
fizz = concat $ repeat ["", "", "Fizz"]
buzz = concat $ repeat ["", "", "", "", "Buzz"]
fizzbuzz = zipWith (++) fizz buzz
combine num "" = show num
combine _ str = str
main = forM_ (take 100 $ zipWith combine [1 ..] fizzbuzz) putStrLn
@keichi
keichi / index.html
Created January 15, 2013 15:32
Reckless try to render Buddhabrot fractal with JavaScript...
<html>
<head>
<title>Buddhabrot JS</title>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<canvas id="world" width="500" height="500"></canvas>
</body>
</html>
@keichi
keichi / gist:4656726
Created January 28, 2013 16:02
This simple code causes memory leak on Mono 2.x
using System;
namespace MemoryLeakTest
{
class MainClass
{
public static void Main (string[] args)
{
for (;;) {
var testArray = new TestStruct[500 * 500 * 50];
#include <stdio.h>
unsigned int bitreverse(unsigned int x) {
x = (x & 0x55555555)<<1 | (x & 0xaaaaaaaa)>>1;
x = (x & 0x33333333)<<2 | (x & 0xcccccccc)>>2;
x = (x & 0x0f0f0f0f)<<4 | (x & 0xf0f0f0f0)>>4;
x = (x & 0x00ff00ff)<<8 | (x & 0xff00ff00)>>8;
x = (x & 0x0000ffff)<<16 | (x & 0xffff0000)>>16;
return x;
}
{
"とても|すごく": ["非常に", "極めて", "大変"],
"たくさん": "多く",
"今回の研究": "本研究",
"見る|見た|見て": ["検討する", "説明する"],
"(わ|分)かる": "断定の口調に変更する。",
"考えられる": ["考えられている", "断定の口調に変更する。"],
"感じる": ["推測される", "思われる"],
"かもしれ(ない|ません)": "可能性がある",
"どんどん": "急速に",
@keichi
keichi / gist:5773906
Last active December 18, 2015 11:09
An experimental OpenFlow controller which discovers OpenFlow switch network topology. Written with the trema framework.
require 'rubygems'
require 'bindata'
class BasicLLDPPacket < BinData::Record
endian :big
uint48 :dst_mac
uint48 :src_mac, :value => 0x0180c200000e
uint16 :ether_type, :value => 0x88cc
Pod::Spec.new do |s|
s.name = 'CocoaSoundCloudAPI'
s.version = '1.0.2'
s.summary = 'A simple way to interact with the SoundCloud CocoaSoundCloudAPI.'
s.homepage = 'https://github.com/soundcloud/CocoaSoundCloudAPI'
s.author = { 'Ullrich Schäfer' => 'ullrich@soundcloud.com',
'Robert Böhnke' => 'robb@soundcloud.com',
'Tobias Kräntzer' => 'tk@soundcloud.com',
'Rob Siwek' => 'robert@soundcloud.com' }
Pod::Spec.new do |s|
s.name = "Audjustable"
s.version = "0.0.9"
s.summary = "A fast and extensible audio streamer for iOS and OSX with support for gapless playback and custom (non-HTTP) sources."
s.homepage = "http://tumtumtum.github.com/audjustable/"
s.license = 'MIT'
s.author = { "Thong Nguyen" => "tumtumtum@gmail.com" }
s.source = { :git => "https://github.com/tumtumtum/audjustable.git", :tag => s.version.to_s}
s.platform = :osx
s.requires_arc = true
var tuple = Tuple.Crate("hoge", 1);
// こうじゃなくて
var a = tuple.Item1;
var b = tuple.Item2;
var f = new Func<Tuple<string, int>, bool>(t => t.Item1.Length == t.Item2);
// こんな感じ
var (a, b) = tuple;