This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import sha1 | |
memoize = lambda f, m = {}, key = lambda values:'-'.join([sha1(str(v)).hexdigest() for v in values]): lambda *xs, **ks: (lambda k = key([xs, ks]): m.get(k) or m.update( { k: f(*xs, **ks) } ) or m.get(k))() | |
@memoize | |
def fib(n): return 1 if (n == 0 or n == 1) else fib(n-1) + fib(n-2) | |
assert fib(9) == 55 | |
assert fib(55) == 225851433717 # cannot calculate without memoize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::HTTPD; | |
use AnyEvent::Util qw(run_cmd); | |
use Cwd; | |
my $httpd = AnyEvent::HTTPD->new (port => 9090); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Mac::AppleScript qw(RunAppleScript); | |
use Perl6::Say; | |
use FindBin; | |
my $me = "$0"; | |
sub play { | |
my $script = <<"SCRIPT"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::HTTP; | |
use Coro; | |
use Coro::SemaphoreSet; | |
use Data::Dumper; | |
use URI; | |
use Web::Scraper; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def say( msg :String ) { Runtime.getRuntime.exec(Array[java.lang.String]("say", msg)) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Handle; | |
# 引数に指定したファイルすべてに対して tail -f する | |
# busy loop になっていてCPUを食う |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $i = 1; | |
START: | |
goto "END" if $i > 35; | |
goto "PRINT_FIZZBUZZ" if $i % 15 == 0; | |
goto "PRINT_FIZZ" if $i % 3 == 0; | |
goto "PRINT_BUZZ" if $i % 5 == 0; | |
goto "PRINT_NUM"; | |
PRINT_NUM:_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import scala.swing._; | |
import org.gstreamer.Gst; | |
import org.gstreamer.State; | |
import org.gstreamer.elements.PlayBin; | |
import org.gstreamer.swing.VideoComponent; | |
import org.gstreamer.Bus; | |
import org.gstreamer.GstObject; | |
import java.util.concurrent.TimeUnit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ホワイトボードに書いてあった問題: | |
# o/oo + o/oo + o/oo = 1 | |
# o の部分には 1..9 の数字が一つづつ入る | |
# | |
# だめな例: | |
# 1/23 + 4/56 + 7/89 = 0.19355... != 1 => だめぽ | |
# | |
def traverse(remain, result=[]) | |
calc(result) if remain.empty? |