Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / 01-docbook.markdown
Created February 19, 2009 07:33
How to generate HTML and pdf from DocBook in Japanese

How to generate pdf from DocBook in Japanense

OS

Ubuntu 8.10

install Sun Java

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
@masakielastic
masakielastic / dynamicaccessor.php
Created March 16, 2009 01:02
dynamic accessor
<?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
@masakielastic
masakielastic / sum_product.php
Created January 15, 2012 01:16
Excel の SUMPRODUCT 関数を PHP で定義
<?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
@masakielastic
masakielastic / iterator_apply_and_foreach.php
Created January 15, 2012 01:40
iterator_apply() と foreach の比較
<?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
@masakielastic
masakielastic / reduce_and_reduceRight.php
Created January 15, 2012 03:13
PHP で reduce と reduceRight
<?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;
}
@masakielastic
masakielastic / reduce_and_reduceRight.js
Created January 15, 2012 23:50
JavaScript の reduce と reduceRight の練習
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);
@masakielastic
masakielastic / filter_and_partition_and_break.hs
Created January 17, 2012 01:22
filter と partition と break の比較
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])