Skip to content

Instantly share code, notes, and snippets.

View yuka2py's full-sized avatar

yuka2py yuka2py

View GitHub Profile
@yuka2py
yuka2py / wp_get_the.php
Last active August 29, 2015 13:55
WordPress の the_*() 関数で出力される値を、文字列として取得する簡単な関数。要るのかな?
<?php
if ( ! function_exists( 'get_the' ) ) {
function get_the( $func ) {
$func = 'the_' . $func;
$args = func_get_args();
array_shift($args);
ob_start();
call_user_func_array( $func, $args );
return ob_get_clean();
@yuka2py
yuka2py / MonitorInputStream.java
Created February 18, 2014 22:32
InputStream の流量を監視する MonitorInputStream と そのリスナー
package jp.foreignkey.java.io;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* データの流量を監視する InputStream
* 監視には、MonitorInputStreamListener を利用する。
*
@yuka2py
yuka2py / Image.php
Created February 27, 2014 12:16
出来は悪いのですが、よく使うしよく修正するので、とりあえずここに置いておきます。
<?php
class ImageLoadingFailedException extends ErrorException {}
class UnSupportedImageException extends ErrorException {}
/**
@yuka2py
yuka2py / modernizr.environ.coffee
Created October 6, 2014 23:56
modernizr.environ.coffee
"use strict"
do ->
if !window.Modernizr
return
ua = new String(window.navigator.userAgent.toLowerCase())
ua.has = (cond) ->
@indexOf(cond) != -1
@yuka2py
yuka2py / README
Created October 24, 2012 00:45
プロトタイプチェーンによる継承
プロトタイプチェーンによる継承で、基本だと思うんですが、16行目で Employee.prototype = new Person; ってやった時に、Personのコンストラクタが走るのが微妙です。
何か認識を間違っているのかしら?
@yuka2py
yuka2py / README
Created October 24, 2012 00:51
コンストラクタを使った継承
コンストラクタを用いた継承のアプローチ。
オブジェクト生成の度に、各オブジェクトのメソッドとして関数オブジェクトを生成されるのかしら?
@yuka2py
yuka2py / gist:3957781
Created October 26, 2012 09:11
appfogでDBへの接続情報を取得する
<?php
$services_json = getenv('VCAP_SERVICES');
$services = json_decode($services_json, true);
$config = null;
foreach ($services as $name => $service) {
if (0 === stripos($name, 'mysql')) {
$config = $service[0]['credentials'];
break;
}
@yuka2py
yuka2py / cconsole.php
Last active December 17, 2015 04:49
This is small utility to log output to the console of the browser from the PHP.
<?php
register_shutdown_function('cconsole::flush');
class cconsole
{
private static $logs = array();
private static $prefix = '[php] ';
private static $timers = array();
@yuka2py
yuka2py / debug.php
Last active December 17, 2015 16:39
CakePHP の debug 関数が心地よかったので、簡易版を書いたので貼っておきます。 あくまで簡易版 (*'-'*)。ちなみに WordPress 案件中に作ったので、WordPress 記法になっているのがミソですw $var は、出力したい変数。 $label は、ついでに出力したい文字列。 $echo は、true の場合のみ出力する。条件付きで出力したいとき、if 書く手間をほんの少し減らすことができます。
<?php
/**
* Output the contents of the variable along with the file and line number.
* @param mixed $var output variable of any types.
* @param string $label optional. default is null.
* @param boolean $echo optional. default is true.
* @return void
*/
function debug( $var, $label=null, $echo=true ) {
@yuka2py
yuka2py / gist:5996538
Created July 14, 2013 23:25
メモ。svn の trunk を git で管理。
1. svn の trunk の中で git init
2. ~/.subversion/config に以下を記述して git リソースなどを svn 管理下から除外する
global-ignores = .DS_Store Thumbs.db .git .gitignore