Skip to content

Instantly share code, notes, and snippets.

View fukata's full-sized avatar

fukata fukata

View GitHub Profile
@fukata
fukata / CodeIgniter1 cache driver patch
Created March 19, 2011 22:40
"CodeIgniter2" on "Cache Driver" feature "CodeIgniter1" backported patches. Override system directories.
diff -Nru /home/tatsuya/DOWNLOAD/php/CodeIgniter_1.7.3/system/libraries/Cache/Cache.php ./system/libraries/Cache/Cache.php
--- /home/tatsuya/DOWNLOAD/php/CodeIgniter_1.7.3/system/libraries/Cache/Cache.php 1970-01-01 08:00:00.000000000 +0800
+++ ./system/libraries/Cache/Cache.php 2011-03-20 06:22:57.267999183 +0800
@@ -0,0 +1,216 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
@fukata
fukata / CodeIgniter1 cache driver patch subclass
Created March 19, 2011 23:32
"CodeIgniter2" on "Cache Driver" feature "CodeIgniter1" backported patches. Extends Loader.
diff -Nru /home/tatsuya/DOWNLOAD/php/CodeIgniter_1.7.3/system/application/libraries/Cache/Cache.php ./system/application/libraries/Cache/Cache.php
--- /home/tatsuya/DOWNLOAD/php/CodeIgniter_1.7.3/system/application/libraries/Cache/Cache.php 1970-01-01 08:00:00.000000000 +0800
+++ ./system/application/libraries/Cache/Cache.php 2011-03-20 07:28:52.003705893 +0800
@@ -0,0 +1,216 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
@fukata
fukata / pretty_date.php
Created March 26, 2011 10:43
Twitter has been used in such a function to generate a pretty date format string.
<?php
function pretty_date($time) {
$diff = time() - $time;
$day_diff = floor($diff / 86400);
if(is_nan($day_diff)) return '';
if ($day_diff == 0) {
if ($diff < 60) {
return $diff . "second ago";
@fukata
fukata / test_blank.php
Created March 27, 2011 05:36
PHP variables to be empty string or NULL in making a determination.
<?php
// bad example
$v = '0';
if ( empty($v) ) {
echo '$v is blank.';
}
// good example
$v = '0';
if ( strlen($v)==0 ) {
@fukata
fukata / draw_near_data.js
Created April 2, 2011 20:54
Data to draw within the screen.
// require jquery
$(function(){
var $w = $(window);
var $h = $('html,body');
var offset = $w.height();
function canDraw($target, info) {
var top = $target.position().top;
if (info.st - offset <= top && top <= info.st + info.wh + offset) {
return true;
}
@fukata
fukata / LoggerAppenderRollingDailyFile.patch
Created April 2, 2011 21:07
Date format files to rotate log4php appender.
--- log4php-org/Logger.php 2010-07-27 03:21:18.705554189 +0900
+++ log4php/Logger.php 2011-04-02 00:26:13.964032277 +0900
@@ -77,6 +77,7 @@
'LoggerAppenderMailEvent' => '/appenders/LoggerAppenderMailEvent.php',
'LoggerAppenderNull' => '/appenders/LoggerAppenderNull.php',
'LoggerAppenderPhp' => '/appenders/LoggerAppenderPhp.php',
+ 'LoggerAppenderRollingDailyFile' => '/appenders/LoggerAppenderRollingDailyFile.php',
'LoggerAppenderRollingFile' => '/appenders/LoggerAppenderRollingFile.php',
'LoggerAppenderSocket' => '/appenders/LoggerAppenderSocket.php',
'LoggerAppenderSyslog' => '/appenders/LoggerAppenderSyslog.php',
@fukata
fukata / mercurial_pull_parents.txt
Created April 6, 2011 02:29
Mercurial: Pull parent updates.
$ hg clone parents
$ hg clone child
$ cd child
$ hg pull -u ../parents
$ hg merge
$ hg commit -m 'merge parents'
@fukata
fukata / ci_2.0.1_and_2.0.2.diff
Created April 8, 2011 01:34
Diff CodeIgniter 2.0.1 and 2.0.2
This file has been truncated, but you can view the full file.
diff -Nru CodeIgniter_2.0.1/application/migrations/001_Create_accounts.php CodeIgniter_2.0.2/application/migrations/001_Create_accounts.php
--- CodeIgniter_2.0.1/application/migrations/001_Create_accounts.php 2011-03-16 02:53:58.000000000 +0800
+++ CodeIgniter_2.0.2/application/migrations/001_Create_accounts.php 1970-01-01 08:00:00.000000000 +0800
@@ -1,32 +0,0 @@
-<?php defined('BASEPATH') OR exit('No direct script access allowed');
-
-class Migration_Create_accounts extends CI_Migration {
-
- function up()
- {
@fukata
fukata / alias.sh
Created April 8, 2011 10:18
git alias
#alias git
alias gia='git add'
alias gial='git add --all'
alias gic='git commit'
alias gicm='git commit -m'
alias gis='git status'
alias gips='git push'
alias gipl='git pull'
alias gich='git checkout'
alias gib='git branch'
@fukata
fukata / test_intersectes.php
Created April 11, 2011 13:14
対象データ数に比例しない突き合わせ処理サンプル
<?php
function test1($masters, $targets) {
$sd = microtime(true);
$intersects = array_uintersect_assoc($targets, $masters, 'compare_key');
$ed = microtime(true);
return $ed-$sd;
}
function compare_key($key1, $key2) {
if ($key2 == $key1->id) {