Skip to content

Instantly share code, notes, and snippets.

View violetyk's full-sized avatar

kagaya violetyk

View GitHub Profile
@violetyk
violetyk / gist:1393085
Created November 25, 2011 09:00
[cakephp]jsヘルパー、関数をbufferしてgetしたjqueryオブジェクトにeventを結びつける
<?php
// 入力タイプの切替イベント。
$func = '
function changeType() {
var type = parseInt($("#SurveyQuestionType").val());
if(type <= 3){
$(".question_item").show("normal");
} else {
$(".question_item").hide("fast");
}
@violetyk
violetyk / gist:1399838
Created November 28, 2011 10:03
[php]trim
<?php
$str = " \t \n \r \0 \x0B   ";
var_dump(trim($str, " \t\n\r\0\x0B "));
@violetyk
violetyk / gist:1403273
Created November 29, 2011 03:31
[php]配列の各要素に対して再帰的に処理を行うarray_wak_recursive
<?php
array_walk_recursive(
$data,
create_function(
'&$val, $key',
'if(in_array($key, array("id", "created", "modified"))) $val = null;')
);
@violetyk
violetyk / kana.php
Created January 16, 2012 11:49
[php]pregでカナチェックしてみた
<?php
$kana = array(
'アイウエオ',
'カキクケコ',
'サシスセソ',
'タチツテト',
'ナニヌネノ',
'ハヒフヘホ',
'マミムメモ',
@violetyk
violetyk / gist:1675466
Created January 25, 2012 08:38
[cakephp]HABTMのfind。ランダムに。
<?php
// 所属カテゴリ内で、同じタグを持つコンテンツを取得。
$this->Content->Behaviors->attach('Matchable');
$options = array(
'jointo' => array(
'Tag' => array('type' => 'INNER'),
),
'conditions' => array(
'Tag.id' => Set::extract('/Tag/id', $content),
'Content.category_id' => Set::extract('/Category/id', $categories),
@violetyk
violetyk / [Scratch]
Created March 1, 2012 07:44
[php]日時とか
<?php
// 文字列から
$timestamp = strtotime('2012-03-01 15:47:00');
// タイムスタンプから
$yyyymmdd = date("Y/m/d", $timestamp);
@violetyk
violetyk / .vimrc
Created April 26, 2012 02:06
[vim]toggle.vim
"----------------------------------------------------
" toggle.vim
" Bundle 'taku-o/vim-toggle'
"----------------------------------------------------
let g:toggle_pairs = {
\ 'and' : 'or',
\ 'or' : 'and',
\ 'if' : 'elseif',
\ 'elseif' : 'else',
\ 'else' : 'if',
@violetyk
violetyk / .vimrc
Created April 26, 2012 02:08
[vim]qfixhowm
"----------------------------------------------------
" QFixHowm
" Bundle 'fuenor/qfixhowm'
"----------------------------------------------------
let howm_dir = $HOME . '/howm'
let howm_fileencoding = 'utf-8'
let howm_fileformat = 'unix'
let QfixHown_UserSwActionLock = ['[]', '[cakephp]', '[vim]', '[linux]']
nnoremap <silent> g,. :<C-u>call HatenaSuperPreHighlight()<CR>
"Hatena super pre highlight
@violetyk
violetyk / surveys_controller.php
Created May 16, 2012 02:10
[cakephp]Model::find()でcountとかsumとか上手くとる方法
<?php
$this->SurveyResponse->virtualFields['count'] = 0;
$data = $this->SurveyResponse->find(
'all',
array(
'fields' => array(
'SurveyResponse.response_value',
'count(id) as "SurveyResponse__count"',
),
'conditions' => array(
function! s:replace(...) range "{{{
if a:0 < 2
return
endif
let range = a:firstline . ',' . a:lastline
let tmp = @@
silent exec range . 'yank'
let text = @@