Skip to content

Instantly share code, notes, and snippets.

@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 / fizzbuzz.rb
Created June 15, 2011 02:36
CodeEval Openchallenges
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
puts ARGF.map {|line|
f, b, m = line.split(' ').map{|a| a.to_i}
(1..m).map {|x|
x%f==0||x%b==0 ? (x%f==0 ? (x%b==0 ? 'FB' : 'F') : 'B') : x
}.join(' ')
}
import java.lang.*;
class Str {
private static int mMax = 1000000;
private static final StringBuilder mBuilder = new StringBuilder();
public static void main(String[] args) {
final String a = "foo";
final String b = "bar";
final String c = "baz";