Skip to content

Instantly share code, notes, and snippets.

View VienosNotes's full-sized avatar

D.Aoki VienosNotes

View GitHub Profile
@VienosNotes
VienosNotes / sum.scpt
Created October 19, 2012 10:29
Sum of Number List, with capable of nesting in AppleScript
on run
sum({1, 2, 3, {1, 2}})
end run
on sum(arg)
-- 数値リストの総和を求める
-- リストが含まれている場合は再帰的に中身も合計する
if arg is equal to {} then
set result to 0
else if class of arg's first item is equal to list then
@VienosNotes
VienosNotes / addFiles.applescript
Created October 23, 2012 04:30
add m4a files to iTunes from directory tree in AppleScript
set src to choose folder
set target_files to getFiles(src)
tell application "iTunes"
repeat with f in target_files
try
add f
delay 1
on error
log f
end try
@VienosNotes
VienosNotes / cut.ml
Created November 19, 2012 10:53
11_decl_cut
let cut l n =
List.fold_left (
fun prev next ->
if (List.fold_left (fun prev next -> prev + next) 0 prev) + next > n
then prev
else prev @ [next]
) [] l;;
cut [1;2;3;4;5;6;7;8;9] 18;;
@VienosNotes
VienosNotes / ocrun
Created November 19, 2012 11:05
run ocaml on interpreter
#!/usr/bin/env perl
use 5.12.0;
my $usage = <<EOS
usage: \$runocaml filename
EOS
;
my $filename = shift // die "Error: No filename \n$usage";
-f $filename or die "$filename not found.\n$usage";
let diff xs ys =
let rec internal xs ys ans =
match xs with
| hd::tl ->
if List.mem hd ys then internal tl ys ans
else internal tl ys (ans @ [hd])
| _ -> ans
in
internal xs ys [];;
let rec balance (t:'a tree) : int tree =
let rec height t =
match t with
| Br(_,left,right) ->
let (hl, hr) = (height left, height right) in
if (hl > hr) then hl + 1 else hr + 1
| _ -> 0
in
match t with
| Br(value, left, right) -> Br(height left - height right, balance left, balance right)
@VienosNotes
VienosNotes / evaluate.pl
Created November 23, 2012 10:30
Perl6で単純な命令列を実行するインタプリタ
use v6;
role Value[::Type] {
has Type $.value;
has @.exp;
multi method new (Type $v, @exp) {
self.bless(*, value => $v, exp => @exp);
}
}
@VienosNotes
VienosNotes / HttpServer.pl
Last active December 31, 2015 07:49
HTTP Server on Perl6(JVM/Rakudo) with Threads
use v6;
class Settings {
has Int $.port;
has Str $.document_root;
method new(Str $path) {
my @settings = $path.IO.lines;
my $portline = @settings.grep(/port\=<.digit>*$$/)[0];
my $port = $portline.substr(5).Int;
use v6;
grammar Expression {
rule num { \d+ }
rule qexp { '(' <exp> ')' }
rule atom { <exp2> || <num> || <qexp> }
rule ops { <.ws><ops1><.ws> || <.ws><ops2><.ws> }
token ops1 { '+'|'-' }
token ops2{ '*'|'/' }
rule exp { <atom>+ % <ops> }
all: y.tab.c lex.yy.c
cc -DYYERROR_VERBOSE -DYYDEBUG -o Parse y.tab.c lex.yy.c
y.tab.c:
yacc -dv parser.y
lex.yy.c: y.tab.c
lex parser.l