Skip to content

Instantly share code, notes, and snippets.

foobar
@gom
gom / 1_static_property.php
Last active December 22, 2015 06:48
object が同一かどうかはspl_object_hashで見ている http://php.net/manual/ja/function.spl-object-hash.php
<?php
class A {
protected static $foo = null;
function hoge() {
if (is_null(self::$foo)) {
self::$foo = new Inner();
}
return self::$foo;
}
}
@gom
gom / phpbrew.rb
Last active December 15, 2015 02:09 — forked from dataich/phpbrew.rb
require 'formula'
class Phpbrew < Formula
homepage 'https://github.com/c9s/phpbrew'
url 'https://github.com/c9s/phpbrew/tarball/1.8.16'
sha1 'ae4801d8f5c004677b7889b88ffbd4539def1d9b'
head 'https://github.com/c9s/phpbrew/tarball/master'
depends_on 'automake'
class FooBar {
public function foo() {
function bar() {
echo "bar\n";
}
bar();
}
}
$f = new FooBar();
@gom
gom / gist:3741153
Created September 18, 2012 03:55
BEGIN END Control Structures difference in Ruby 1.8.7 and 1.9.3.
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i686-darwin11.3.0]
$ seq 1 10 | ruby -ne 'BEGIN{ a=0 }; a += $_.to_i; END{ puts a }'
-e:1: undefined method `+' for nil:NilClass (NoMethodError)
$ ruby -v
ruby 1.9.3p135 (2012-02-21 revision 34718) [x86_64-darwin11.2.0]
$ seq 1 10 | ruby -ne 'BEGIN{ a=0 }; a += $_.to_i; END{ puts a }'
55
@gom
gom / gist:3237949
Created August 2, 2012 15:31
Install ruby with rbenv
$ CONFIGURE_OPTS="--with-readline-dir=/usr/local" rbenv install 1.9.3-p194
@gom
gom / debug.php
Created July 31, 2012 15:01
snippets with PHP
function p($obj) { error_log(var_export($obj, true)); }
var_dump(in_array(0, array(null))); // => true
var_dump(array_search(0, array(null))); // => 0
var_dump(array_key_exists(0, array(null => 1))); // => false
var_dump(0 == null); // => true
@gom
gom / AudioActivity.java
Created August 27, 2011 15:34
AudioSample on Android
package org.example.sample.audio;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import java.io.IOException;
@gom
gom / gist:1126857
Created August 5, 2011 03:23
Unicode escape / unescape on javascript via http://d.hatena.ne.jp/sawat/20070309/1173459459
var unicode = {
escape: function(s) {
return s.replace(/^[-~]|\\/g, function(m) {
var code = m.charCodeAt(0);
return '\\u' + ((code < 0x10) ? '000' : ((code < 0x100) ? '00' : ((code < 0x1000) ? '0' : ''))) + code.toString(16);
});
},
unescape : function (s) {
return s.replace(/\\u([a-fA-F0-9]{4})/g, function(matched, g1) {
return String.fromCharCode(parseInt(g1, 16))