Skip to content

Instantly share code, notes, and snippets.

@tomonacci
tomonacci / quine.rb
Created February 23, 2010 02:12
Quine in Ruby
printf x="printf x=%c%s%c,34,x,34",34,x,34
@tomonacci
tomonacci / co-quine.rb
Created February 23, 2010 02:19
Two methods that print out each other - it was kind of hard!
# Methods `a' and `b' will print out each other when called
def a;x="def a;x=";q=34;printf"def b;x=%cdef b;x=%c;q=34;"+(y="printf%c%s%%c%s%%c;q=34;%c(y=%c%s%c),q,q,q,x,x,q,q,y,q end"),q,q,q,x,x,q,q,y,q end
def b;x="def b;x=";q=34;printf"def a;x=%cdef a;x=%c;q=34;"+(y="printf%c%s%%c%s%%c;q=34;%c(y=%c%s%c),q,q,q,x,x,q,q,y,q end"),q,q,q,x,x,q,q,y,q end
# Slightly (8 bytes) shorter version
def a;x="def a;x=";printf"def b;x=%cdef b;x=%c;"+(y="printf%c%s%%c%s%%c;%c+y=%c%s%c),34,34,34,x,x,34,34,y,34 end"),34,34,34,x,x,34,34,y,34 end
def b;x="def b;x=";printf"def a;x=%cdef a;x=%c;"+(y="printf%c%s%%c%s%%c;%c+y=%c%s%c),34,34,34,x,x,34,34,y,34 end"),34,34,34,x,x,34,34,y,34 end
@tomonacci
tomonacci / fiber-prime.rb
Created February 23, 2010 06:37
Prime number enumerator using Fiber
def fiber_manager(j, g)
fiber_manager((nf = Fiber.new do |i, f|
print "#{i} "
while (n = f.resume) % i == 0; end
Fiber.yield(n)
loop do
n = f.resume
Fiber.yield(n) if n % i != 0
end
end).resume(j, g), nf)
<!DOCTYPE html>
<html>
<head>
<title>Cardioid</title>
<style>
input {
width: 3em;
}
</style>
<script>
<!DOCTYPE html>
<html>
<head>
<title>Koch snowflake</title>
<style type='text/css'>
input {
width: 4em;
}
</style>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.3.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<title>Function space</title>
<style>
canvas {
float: left;
margin: 10px;
}
</style>
@tomonacci
tomonacci / sort.scm
Created February 20, 2011 04:32
All sorts of sorting algorithms written in Scheme (Gauche)
(use srfi-27)
(use srfi-42)
(define-macro (swap! a b)
(let1 t (gensym)
`(let1 ,t ,a
(set! ,a ,b)
(set! ,b ,t))))
(define (bubble-sort v)
@tomonacci
tomonacci / herbert-parser.scm
Created March 15, 2011 16:05
parsing Herbert programs
;;; herbert-parser.scm - parsing Herbert programs
;;;
;;; Usage (the result is indented manually):
;;;
;;; % cat test.hervert
;;; a(X,Y,Z):b(X-12+13-Y+Z,X)ccsslr
;;; b(X):cccc
;;; c:s
;;; ss
;;; % gosh herbert-parser.scm < test.hervert
@tomonacci
tomonacci / wave.scm
Created August 19, 2011 09:09
新・物理入門問題演習 111頁
(use gauche.threads)
(use math.const)
(use srfi-42)
(use gl)
(use gl.glut)
(define a 40)
(define A 10)
(define f 1)
; v = 3/4 fa
@tomonacci
tomonacci / _evince
Created December 28, 2011 06:29
Zsh completion for evince
#compdef evince
local arguments
arguments=(
'(-h --help --help-all --help-sm-client --help-gtk)'{-h,--help}'[show help options]'
'(-h --help --help-sm-client --help-gtk)--help-all[show all help options]'
'(-h --help --help-all --help-gtk)--help-sm-client[show session management options]'
'(-h --help --help-all --help-sm-client)--help-gtk[show GTK+ Options]'
'--sm-client-disable[disable connection to session manager]'
'--sm-client-state-file=[specify file containing saved configuration]'