Skip to content

Instantly share code, notes, and snippets.

@mgng
mgng / instagram_sample.php
Created January 6, 2014 08:05
instagram get data sample
<?php
$json = json_decode( file_get_contents( "http://instagram.com/parishilton/media" ) );
if ( ! isset( $json->status ) || $json->status !== 'ok' ) {
exit('error');
}
foreach( $json->items as $item ) {
$data = array(
'username' => $item->user->username,
'full_name'=> $item->user->full_name,
@mgng
mgng / ajax_upload.html
Last active December 31, 2015 05:29
jquery + ajax file upload
<form action="javascript:;">
<input type="text" id="status" value="" />
<input type="file" id="file" />
<input type="submit" id="update" value="送信" />
</form>
<script>
$(function(){
$("#update").bind("click", function(){
@mgng
mgng / parse.php
Last active December 31, 2015 00:19
tailf access_log | php parse.php
<?php
// これつけないと動かないケースもある
// stream_set_blocking( STDIN, 1 );
while ( false !== ($line=trim( fgets(STDIN) ) ) ) {
// 何かしら処理
error_log( "{$line}\n", 3, "./log.txt" );
}
@mgng
mgng / sqlite_test.php
Created December 10, 2013 06:14
sqlite test
<?php
// PDOオブジェクト
$pdo = null;
// DBファイルパス
$db_path = './db.sqlite';
// 接続 $db_path ファイルがなければ作成される
try{
@mgng
mgng / mongodb_isodate.php
Last active December 28, 2015 20:19
mongodb で 日付範囲検索する場合
<?php
$startDate ="2013-11-12 00:00:00";
$endDate = "2013-11-13 00:00:00";
// mongodb内部でISODate Objectで保存されている場合は MongoDate 使って変換する必要がある
$query = array("insert_date" => array(
'$lt' => new MongoDate(strtotime($endDate)),
'$gte' => new MongoDate(strtotime($startDate))
));
@mgng
mgng / preg_test.php
Last active December 28, 2015 18:09
preg_match 全角数字通るやつ
<?php
var_dump(
preg_match( '/\A[\d]+\z/u', '1' ), // int(1)
preg_match( '/\A[\d]+\z/u', '1' ), // int(1)
preg_match( '/\A[\d]+\z/', '1' ), // int(1)
preg_match( '/\A[\d]+\z/', '1' ), // int(0)
preg_match( '/\A[0-9]+\z/u', '1' ), // int(1)
preg_match( '/\A[0-9]+\z/u', '1'), // int(0)
preg_match( '/\A[0-9]+\z/', '1' ), // int(1)
@mgng
mgng / test.html
Created November 5, 2013 07:53
select の表示違い
<!DOCTYPE HTML>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<title>テスト</title>
</head>
<body>
<select name="" id="">
<option value="値です" label="ラベルです">表示項目です</option>
@mgng
mgng / test.html
Created October 7, 2013 02:11
IE7:javascript経由でmaxlengthを設定しても無効になる
<div id="id_input"></div>
<script>
(function(){
var input = document.createElement( 'input' );
input.setAttribute( 'type', 'text' );
input.setAttribute( 'name', 'userid' );
input.setAttribute( 'maxlength', 5 ); // IE7の場合は 'maxLength' にしないとだめ
input.setAttribute( 'value', '' );
document.getElementById( 'id_input' ).appendChild( input );
})()
@mgng
mgng / a.js
Last active December 23, 2015 00:09
期間がかぶってたらエラーにする
function isDuplicate( list ) {
var _list = list.concat();
while( _list.length ) {
var cur = _list.pop();
for( var i=0,l=_list.length; i<l; i++ ) {
if (
( _list[i][0] <= cur[0] && cur[0] <= _list[i][1] )
||
( _list[i][0] <= cur[1] && cur[1] <= _list[i][1] )
) {
@mgng
mgng / basename.php
Created August 29, 2013 02:47
basename で 文字化け
<?php
$path = '/path/to/漢字.txt';
var_dump(
basename( $path ),
end( explode( '/', $path ) )
);
/*