Skip to content

Instantly share code, notes, and snippets.

View uiur's full-sized avatar

Kazato Sugimoto uiur

View GitHub Profile
def monte
x = rand(); y = rand()
if (x * x + y * y) < 1
return 1
else
return 0
end
end
@uiur
uiur / lis.rb
Created September 8, 2011 05:48
Tiny Lisp interpreter written in Ruby: http://www.aoky.net/articles/peter_norvig/lispy.htm
List = Array
class Env < Hash
attr_accessor :outer
def initialize(keys=[], vals=[], outer=nil)
alist = [keys, vals].transpose
self.update(Hash[*alist.flatten(1)])
@outer = outer
end
@uiur
uiur / life.html
Created September 8, 2011 14:02
Conway's Life Game
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<script src='life.js'></script>
</body>
</html>
@uiur
uiur / chat.html
Created September 9, 2011 07:21
Simple Chat in Ruby+WebSocket
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>chat</title>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js'></script>
@uiur
uiur / tex2pdf.rb
Created November 14, 2011 15:46
tex->pdfして表示するのにコマンドを叩くのめんどくさいから自分専用にRubyスクリプト書いた
#!/usr/local/bin/ruby
# encoding: UTF-8
unless ARGV[0] =~ /\.tex/
puts 'texちゃうやん'
return
end
file_name = ARGV[0].gsub(/(.*)\.tex/, '\1')
`platex #{file_name}.tex && dvipdfmx #{file_name}.dvi && open #{file_name}.pdf`
@uiur
uiur / msort.hs
Created November 21, 2011 07:02
Haskellのれんしゅう: マージソート
-- Merge Sort
msort :: (Ord a) => [a] -> [a]
msort [] = []
msort [x] = [x]
msort xs = merge (msort f) (msort s)
where
(f,s) = split xs
split :: (Ord a) => [a] -> ([a],[a])
split xs = splitAt center xs
@uiur
uiur / parse.hs
Created November 22, 2011 19:52
Haskellの練習: Monadic parser combinator using Maybe
-- プログラミングHaskellのパーサコンビネータの実装をMaybeモナドを使うようにしてみた
-- Programming in Haskell : 8 Chapter
module Parsing where
import Char
import Monad
infixr 5 +++
newtype Parser a = Parser {getParser :: String -> Maybe (a,String)}
@uiur
uiur / gist:1588038
Created January 10, 2012 09:22
copy storage-conf.xml
sed -e "s/<!-- SavedCachesDirectory>/<SavedCachesDirectory>/g" config/storage-conf.xml | sed -e "s/<\/SavedCachesDirectory -->/<\/SavedCachesD irectory>/g" > /var/cassandra/conf/storage-conf.xml
@uiur
uiur / cluster.rb
Created January 18, 2012 13:03
カニバリズム山脈クラスタリング
class Cluster
attr_accessor :left, :right, :vec, :id, :distance
def initialize(args)
@vec = args[:vec]
@left = args[:left]
@right = args[:right]
@id = args[:id]
@distance = args[:distance]
end
;; Standard frame
(define frm1 (make-frame (make-vect 0.0 0.0)
(make-vect 1.0 0.0)
(make-vect 0.0 1.0)))
;; Shearing frame
(define frm2 (make-frame (make-vect 0.0 0.0)
(make-vect 0.66 0.33)
(make-vect 0.33 0.66)))