Skip to content

Instantly share code, notes, and snippets.

View lighty's full-sized avatar

Hikaru Watanabe lighty

View GitHub Profile
@lighty
lighty / gist:3300282
Created August 9, 2012 01:59
PHPでRDBから取得した配列データをコントロールブレイクでまとめたいなーと思って作って日の目を見なかったfunction
//********************************
// 配列のグループ化処理
//
// 指定したキーで、配列を以下の例の様にグルーピングする
// [
// [ "id"=>1, "valueA"=>"aaa", "valueB"=>"bbb"],
// [ "id"=>1, "valueA"=>"ccc", "valueB"=>"ddd"],
// ]
//
// ↓↓↓↓↓↓↓↓
@lighty
lighty / gist:3628979
Created September 5, 2012 01:40
PHPでタイムゾーンの一覧と、その時差を出力するコード
foreach(DateTimeZone::listIdentifiers() as $val){
date_default_timezone_set('UTC');
$utcTime = strtotime('2012-01-01 00:00:00');
date_default_timezone_set($val);
$date = date("Y/m/d H:i:s", $utcTime);
print $val."\t".$date."\n";
}
@lighty
lighty / gist:3856318
Created October 9, 2012 02:59
月末を取得
$endOfMonth = date('Y-m-t', strtotime($from));
@lighty
lighty / gist:3856356
Created October 9, 2012 03:12
当月の開始日、次月の開始日、次月の月末
$startOfThisMonth = date('Y-m-1', strtotime($from));
$startOfNextMonth = date('Y-m-d', strtotime($startOfThisMonth.' +1 month')) ;
$endOfNextMonth = date('Y-m-t', strtotime($startOfNextMonth));
@lighty
lighty / gist:9366857
Last active August 29, 2015 13:57
PHPでRDBから取得した配列データをコントロールブレイクでまとめたいなーと思って作って日の目を見なかったfunctionをIteratorとして統合
//********************************
// 配列のグループ化処理
//
// 指定したキーで、配列を以下の例の様にグルーピング
//
// $a = array(
// array("idA"=>1, "idB"=>"aaa", "val"=>"hoge1"),
// array("idA"=>1, "idB"=>"aaa", "val"=>"hoge2"),
// array("idA"=>1, "idB"=>"iii", "val"=>"fuga1"),
// array("idA"=>1, "idB"=>"iii", "val"=>"fuga2"),
@lighty
lighty / gist:9369314
Created March 5, 2014 15:21
指定したキーで配列をグルーピングする
class KeyGrouper{
public static function group($records, $keys){
$groupedRecords = array();
foreach($records as $record){
$primaryKeyString = KeyGrouper::primaryKeyString($record, $keys);
$groupedRecords[$primaryKeyString][] = $record;
}
return $groupedRecords;
}

Keybase proof

I hereby claim:

  • I am lighty on github.
  • I am hikalin8686 (https://keybase.io/hikalin8686) on keybase.
  • I have a public key ASBnqZ6ocPYScOOllRU83h7dYnCsAHRmoqnW2wjNEZff7Qo

To claim this, I am signing this object:

@lighty
lighty / open_api_spec_devider.rb
Last active March 6, 2020 05:35
openapi3形式で書かれた、肥大化したスキーマ定義ファイルを分割する
# '#/components/schemas/BadRequest'
# → components/schemas/BadRequest.yml
# '#/components/responses/unauthorized'
# → components/responses.yml#/unauthorized
require 'yaml'
require 'fileutils'
require 'pry'