Ubuntu 8.10
sudo apt-get install sun-java6-jdk
sudo update-java-alternatives -s java-6-sun
| <?php | |
| class Autoload | |
| { | |
| static public function loadClass($className) | |
| { | |
| require_once($className . '.class.php'); | |
| } | |
| static public function getInstance() | |
| { |
| //show the list of available SPL classes | |
| php -r 'print_r(spl_classes());' | |
| //show the list of defined class | |
| php -r 'print_r(get_declared_classes());' | |
| //show the list of methods of class Example | |
| php -r 'print_r(get_class_methods(Example));' | |
| //show the list of properties of class Example |
| <?php | |
| class BaseClass | |
| { | |
| public function __call($name, $arguments) | |
| { | |
| $prefix = substr($name, 0, 3); | |
| $property = substr(strtolower($name), 3); | |
| if ($prefix == 'set') |
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'rack' | |
| class HelloRack | |
| def call(env) | |
| [200, {'Content-Type' => 'text/html; charset=UTF-8'}, ['こんにちは、Rack']] | |
| end | |
| end | |
| <?php | |
| function sum_product($array, $array2) { | |
| $ret = array_map(function($m, $n) { return $m * $n; }, $array, $array2); | |
| // return array_sum($ret); | |
| return array_reduce($ret, function($m, $n) { return $m + $n; }, 0); | |
| } | |
| var_dump(sum_product([100, 200, 300], [1, 2, 3])); // 1400 |
| <?php | |
| // modified the code from https://gist.github.com/1287753 | |
| // see also: https://github.com/zendframework/zf2/pull/502 | |
| // | |
| // the result on my Macbook Pro | |
| // | |
| // foreach : 1.3991289138794 | |
| // array_map : 1.8903770446777 | |
| // iterator_apply: 4.6320548057556 |
| <?php | |
| // Haskell の foldl と foldr で同じ値の計算: http://blog.sarabande.jp/post/13599950587 | |
| function reduce(array $input, $callable, $initial = NULL) { | |
| $ret = $initial; | |
| foreach ($input as $v) { | |
| $ret = call_user_func($callable, $ret, $v); | |
| } | |
| return $ret; | |
| } |
| var a = [1, 2, 3]; | |
| function f(x, y) { | |
| return 2 * x + y; | |
| } | |
| var b = a.reduce(f, 4); | |
| var c = a.reduceRight(f, 4); | |
| // 43 | |
| console.log(b); |
| ghci > filter odd [2,4,6,7,8,9] | |
| [7,9] | |
| ghci > partition odd [2,4,6,7,8,9] | |
| ([7,9],[2,4,6,8]) | |
| ghci > break odd [2,4,6,7,8,9] | |
| ([2,4,6],[7,8,9]) |