Skip to content

Instantly share code, notes, and snippets.

View yuya-takeyama's full-sized avatar
🎐
Humility, Kindness, Bonds

Yuya Takeyama yuya-takeyama

🎐
Humility, Kindness, Bonds
View GitHub Profile
/**
* Private members in JavaScript
*
* @author Yuya Takeyama
*/
var Dog = (function () {
var Dog,
privateNameSpace = {};
/**
@yuya-takeyama
yuya-takeyama / sample.py
Created May 2, 2010 17:29
Quoted from "Python Cookbook, 2nd Edition" (O'Reilly Japan). I modified it a little.
parser = Xml2Obj()
root = self.parser.parse("""<?xml version="1.0"?><parent id="top"><child1 name="paul">Text goes here</child1><child2 name="fred">More text</child2></parent>""")
# These have the same meaning.
print root.getElements('item1')[0].getData()
# => Text goes here
print root.item1[0].getData()
# => Text goes here
<?php
/**
* addslashes() for multi-byte characters
*
* @param string $input Input characters
* @param string $enc Internal encoding (optional)
* @return string Charcters added slashes
*/
function mb_addslashes($input, $enc = NULL)
{
# This script generates properties for PHP.
class String
def camelize
result = ""
self.split("_").each do |word|
result += word.capitalize
end
result
end
def qsort(arr: Array[Int]): Array[Int] = arr.length match {
case n if n <= 1 => arr
case _ => {
var pivot = arr(0)
qsort(arr.filter(x => x < pivot)) ++ arr.filter(x => x == pivot) ++ qsort(arr.filter(x => x > pivot))
}
}
<?php
class Calc
{
public function add($a, $b)
{
return $a + $b;
}
}
<?php
class Calc
{
public function add($a, $b, $c = NULL)
{
if (isset($c)) {
return $a + $b + $c;
} else {
return $a + $b;
}
@yuya-takeyama
yuya-takeyama / Singleton.js
Created August 7, 2010 02:36
Singleton Object in JavaScript
var Singleton = (function () {
var
obj = {},
id,
init,
get_instance,
get_id;
init = function () {
id = Math.random();
n = 100
r = [1, 2, 3, 4, 5].inject(0) {|n, i| n + i }
puts "r = " + r.to_s
puts "n = " + n.to_s
<?php
/**
* List_Rubyfoo
* Rubyppoi array iterator for PHP.
*
* @author Yuya Takeyama <sign.of.the.wolf.pentagram@gmail.com>
*/
class List_Rubyfoo implements Iterator, ArrayAccess, Countable
{