Skip to content

Instantly share code, notes, and snippets.

@1000k
1000k / encodeco.php
Created September 1, 2011 01:32
PHP+jQuery Encoding/Decoding string form only in 1 file
<?php
if (isset($_POST['input']) && isset($_POST['mode'])) {
ob_start();
// Needs decoding because $_POST is encoded when jQuery.ajax sended the data.
$input = urldecode($_POST['input']);
switch ($_POST['mode']) {
case 'serialize':
$output = serialize($input);
@1000k
1000k / gist:2411752
Created April 18, 2012 07:32
various way to check whether the value is set
<?php
$subjects = array(
null,
true,
false,
"false", // 文字列の false
"", // 空文字列
0, // integer の 0
"0", // string の 0
"aaaaa", // 任意のstring
@1000k
1000k / array-to-texttable.php
Created July 10, 2012 02:34 — forked from tony-landis/array-to-texttable.php
PHP: Array to Text Table Generation Class
<?php
/**
* Array to Text Table Generation Class
*
* @author Tony Landis <tony@tonylandis.com>
* @link http://www.tonylandis.com/
* @copyright Copyright (C) 2006-2009 Tony Landis
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class ArrayToTextTable
@1000k
1000k / paths.php
Created September 4, 2012 01:55
Frequently-appearing phrases which relate to paths.
<?php
// Frequently-appearing phrases which relate to paths.
$paths = array(
array('__FILE__', __FILE__),
array('realpath(__FILE__)', realpath(__FILE__)),
array('dirname(__FILE__)', dirname(__FILE__)),
array('basename(__FILE__)', basename(__FILE__)),
array('pathinfo(__FILE__)', pathinfo(__FILE__)),
array('__DIR__', __DIR__),
);
@1000k
1000k / description.md
Created October 13, 2012 21:25
Verify the event firing timings of jQuery Mobile
@1000k
1000k / description.md
Created October 14, 2012 02:05
Fix the transition problem which occurs when user moves from Form window to Google Maps window (jQuery Mobile + Google Maps API)

This code is for the problem of jQuery Mobile using Google Maps API.

When there are the window placed Google Maps (gmap1.html) and Form (gmap2.html), the Map is not rendered after the following transition:

  1. Access to 'gmap1.html' -- Google Maps shows correctly.
  2. Move to 'gmap2.html' with a tag link.
  3. Back to 'gmap1.html' with clicking 'submit' button.
  4. 'gmap1.html' shown but Google Maps doesn't show.

To fix it, use $.mobile.ajaxEnabled = false; option.

@1000k
1000k / description.md
Created October 14, 2012 14:33
Dynamically injecting list view
@1000k
1000k / flash_message.html
Created October 18, 2012 09:31
Flash message pane in jQuery Mobile.
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>page 1</title>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<style type="text/css" media="screen">
@1000k
1000k / ApisController.php
Last active December 13, 2015 17:58
Controller を TDD で開発する流れです。CakePHP 2.2.5 を使いました。
<?php
App::uses('AppController', 'Controller');
class ApisController extends AppController {
// どの Model も使わないようにする。
public $uses = false;
public function index() {
$data = array();
@1000k
1000k / gist:6106673
Created July 29, 2013 18:50
Get actual dimension of image. Using jQuery.
/**
* 画像の実際のサイズを取得する
*
* @param string image img要素
*/
function getActualDimension(image) {
var run, mem, w, h, key = "actual";
// for Firefox, Safari, Google Chrome
if ("naturalWidth" in image) {
return {width: image.naturalWidth, height: image.naturalHeight};