Skip to content

Instantly share code, notes, and snippets.

@msng
msng / strpos_array.php
Last active June 28, 2022 20:15
PHP: strpos_array is strpos that can take an array as needle
<?php
function strpos_array($haystack, $needles, $offset = 0) {
if (is_array($needles)) {
foreach ($needles as $needle) {
$pos = strpos_array($haystack, $needle);
if ($pos !== false) {
return $pos;
}
}
return false;
@msng
msng / number_unformat.php
Created December 21, 2011 02:07
Unformats a number formatted with number_format().
<?php
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') {
if ($force_number) {
$number = preg_replace('/^[^\d]+/', '', $number);
} else if (preg_match('/^[^\d]+/', $number)) {
return false;
}
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float';
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number);
settype($number, $type);
[alias]
delete-merged-branches = !git branch --merged master | grep -v -e \\* -e master -e develop | xargs git branch -d
delete-merged-remote-branches = !git fetch --all --prune && git branch -r --merged master | grep -v -e master -e develop | sed -e 's%/% %' | xargs -n 2 git push --delete
@msng
msng / gist:4023716
Created November 6, 2012 09:40
日本の「国民の祝日」の英語名と日本語名を対応させる配列。キーに英語名、値に日本語名を取る。
array(
"New Year's Day" => '元日',
"Coming-of-Age Day" => '成人の日',
"National Foundation Day" => '建国記念の日',
"Vernal Equinox Day" => '春分の日',
"Showa Day" => '昭和の日',
"Constitution Memorial Day" => '憲法記念日',
"Greenery Day" => 'みどりの日',
"Children's Day" => 'こどもの日',
"Marine Day" => '海の日',
@msng
msng / .gitignore
Created August 13, 2013 04:05
CakePHP の tmp 以下 empty ファイルだけを add して他は無視するやつ。 これ美しくないから何とかしたいんだけど。
/app/tmp/cache/*
!/app/tmp/cache/models/
!/app/tmp/cache/persistent/
!/app/tmp/cache/views/
/app/tmp/cache/models/*
!/app/tmp/cache/models/empty
/app/tmp/cache/persistent/*
!/app/tmp/cache/persistent/empty
@msng
msng / ogp.php
Created December 7, 2011 05:38
OGP Helper class file
<?php
/**
* Ogp Helper class file
*
* Adds OGP elements in <head />
*
* Licensed under The MIT License
*
* @author Masunaga Ray (http://www.msng.info/)
* @link http://www.msng.info/archives/2011/12/cakephp-ogp-helper.php
@msng
msng / private.xml
Last active January 30, 2016 23:27
Mac 版 PhpStorm のファイルツリーでファイルを選択して開く操作を楽にするための設定 ref: http://qiita.com/msng/items/89d8f1a37c65336c4dec
<?xml version="1.0"?>
<root>
<appdef>
<appname>PHPSTORM</appname>
<equal>com.jetbrains.PhpStorm</equal>
</appdef>
<list>
<item>
<name>Control+P/N to Arrow Up/Down (on PhpStorm)</name>
@msng
msng / clearfix.css
Created December 12, 2013 03:58
コンパクトな clearfix のサンプル。ここ参照: http://nicolasgallagher.com/micro-clearfix-hack/
.cf:before,
.cf:after {
content: " ";
display: table;
}
.cf:after {
clear: both;
}
<?php
$code = '<?php
$array = [
';
for ($i = 0; $i <= 7; $i++) {
$code .= " 'key" . chr($i) . "' => 'value_" . $i . "',\n";
}
$code .= '];
@msng
msng / README.md
Last active December 28, 2015 02:08
Mac の PhpStorm で Control+C をエスケープに強制割り当てするための、KeyRemap4MacBook の設定。

これはなに

Mac の PhpStorm で Control + Cesc に強制割り当てするための、KeyRemap4MacBook の設定。 PhpStorm のキーマップ指定でエスケープに割り当ててもエディタに戻る動作をしなかったので、Mac の方のキーマップを変更してみた。

使い方

  1. KeyRemap4MacBook の設定画面の Misc & Uninstall タブにある Custom Setting 欄の Open private.xml ボタンを押す。
  2. private.xml を何かエディタで開く。
  3. ここにある private.xml の内容を書く。もう何か書いてあったら適当にマージ。