Skip to content

Instantly share code, notes, and snippets.

@mgng
mgng / gist:2090234
Created March 19, 2012 01:57
PHPでGET/POSTパラメータ等の変数名にドットが含まれると勝手にアンダースコアになるのでころしたいところだが対処する
<?php
class Server {
/** _parse */
private static function _parse( $str ) {
$ret = array();
if ($str !== '') {
foreach( explode( '&', $str ) as $data ) {
$tmp = explode( '=', $data );
$ret[urldecode($tmp[0])] = urldecode($tmp[1]);
@mgng
mgng / gist:2090190
Created March 19, 2012 01:55
face_detect.php
<?php
$file_path = './sample.jpg';
$cascade = './haarcascade_frontalface_alt.xml';
$faces = face_detect( $file_path, $cascade );
if ( ! count( $faces ) ) {
exit( '顔がない' );
}
$img = imagecreatefromjpeg( $file_path );
$line_color = imagecolorallocate( $img, 255, 0, 0 );
@mgng
mgng / FlashPlayerVer.js
Created March 19, 2012 01:54
Flashが使えるかどうかの判定js
function FlashPlayerVer() {
var flashplayer_ver = 0;
if(navigator.plugins && navigator.mimeTypes['application/x-shockwave-flash']){
var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
if(plugin){
flashplayer_ver = parseInt(plugin.description.match(/\d+\.\d+/));
}
} else {
try{
var flashOCX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/);
@mgng
mgng / 1.php
Created March 19, 2012 01:51
in_array か preg_match か
<?php
$param = 'aaa';
$list = array('aaa','bbb','ccc','ddd','eee');
echo in_array( $param, $list, true ) ? 'OK' : 'NG';
@mgng
mgng / 1.pl
Created March 19, 2012 01:49
配列返す関数で値をうけとるとき
#!/usr/bin/perl
use strict;
use warnings;
my ( $a, $b ) = unko();
print "$a\n";
print "$b\n";
sub unko {
return ( 'aaa', 'bbb' );
@mgng
mgng / httpd.conf
Created March 19, 2012 01:47
mod_rewrite 使ってケータイっぽかったらリダイレクト
RewriteEngine On
# スマホとか
BrowserMatchNoCase "(iPhone)|(iPod)|(Android)" ua-type=sumaho
RewriteCond %{ENV:ua-type} "sumaho"
RewriteRule ^.*$ http://www.example.com/sumaho/ [R=302,L]
# ガラケーとか
BrowserMatchNoCase "(DoCoMo)|(KDDI)|(Up\.Browser)|(J\-PHONE)|(Vodafone)|(SoftBank)|(MOT\-[VC])|(Vemulator)" ua-type=keitai
RewriteCond %{ENV:ua-type} "keitai"
@mgng
mgng / 1.js
Created March 19, 2012 01:46
Chrome と Opera は Object のキーが整数っぽいやつを勝手にソートしてしまう
var data = {
'16' : 'こ',
'15' : 'め',
'14' : 'を',
'13' : 'と',
'12' : 'ぎ',
'11' : 'と',
'10' : 'ぎ'
};
var buf = '';
@mgng
mgng / gist:2089835
Created March 19, 2012 01:44
PHP-5.4.0 の Short syntax for arrays
<?php
$a = [ 1, 2, 3 ];
print_r( $a );
$a = [ 'unko' => 'うんこ', 'geri' => 'ゲリ' ];
print_r( $a );
/*
Array
(
[0] => 1
@mgng
mgng / apachekillercheck.php
Created March 19, 2012 01:41
Apache Killer の件を PHP で確認
<?php
function test_apache( $host ){
$bytes = '0-10000,1-10001,2-10002,3-10003,4-10004,5-10005';
$def = stream_context_get_default(
array(
'http'=>array(
'method' => "HEAD",
'protocol_version' => "1.1",
'header' => "Range:bytes={$bytes}\r\n".
@mgng
mgng / 1.php
Created March 19, 2012 01:38
utf-8なJSON文字列をPHPとPerlで扱うメモ
<?php
$json_str = '{"hoge":"ほげ", "fuga":"ふが"}';
$json = json_decode( $json_str );
echo $json->hoge; // ほげ
echo $json->fuga; // ふが