Skip to content

Instantly share code, notes, and snippets.

@kijtra
kijtra / array_dot_access.php
Created March 18, 2014 09:13
ドットつなぎの文字列で連想配列にアクセスする関数 ref: http://qiita.com/kijtra/items/16dabc977d7a9079b8fb
<?php
function array_dot_access( $str = NULL ) {
if( empty($str) || !is_string($str) ) {
return false;
}
static $buffer=array();
if( !empty($buffer[$str]) ) {
@kijtra
kijtra / browser.js
Last active August 29, 2015 14:01
[JavaScript] UA detect
var $browser = (function(){
var ua = navigator.userAgent.toLowerCase(),
desktop = !/android|iphone|ipod|ipad|mobile|windows phone|blackberry|webos|meego/.test(ua),
b = {
ua: ua,
desktop: desktop,
mobile: !desktop,
android: /android/.test(ua),
ios: /iphone|ipod|ipad/.test(ua),
iphone: /iphone/.test(ua),
@kijtra
kijtra / jquery.textareaAutoHeigh.js
Created June 19, 2014 02:13
[JavaScript] テキストエリアの高さを自動調節するやつ
(function($){
var update = function(obj, min){
var br = obj.val().match(/(\r\n|\n)/gm);
if (br) {
if (br.length >= min) {
obj.prop('rows', br.length + 1);
}
} else {
obj.prop('rows', min);
}
@kijtra
kijtra / cipher.php
Last active August 29, 2015 14:04
[PHP] 簡易的な暗号化・複合両対応関数
<?php
function cipher($string = null) {
if (empty($string) || !is_string($string)) {
return false;
}
static $key = null, $iv_size = null, $prefix = null;
$from = array('+', '/');
@kijtra
kijtra / jquery.checkers.js
Created July 30, 2014 07:56
<label> 内にある checkbox か radio がチェックされた時(または最初から checked の時)に <label> に「checked」というクラス名をつけるスニペット。
(function(){
var radios = {};
$('label').each(function(){
var label = $(this),
input = label.find('input[type="checkbox"],input[type="radio"]').first();
if (!input.length) {
return false;
}
@kijtra
kijtra / linker.php
Created August 20, 2014 07:49
[PHP] テキスト内のURLをリンクにする関数
<?php
function linker($text = null ,$blank = false)
{
if (empty($text)) {
return null;
}
$text = preg_replace('/&apos;/', '&#39;', $text); // IE対策
@kijtra
kijtra / adsense_for_keitai.php
Created October 5, 2014 01:58
[PHP] 携帯(フィーチャーフォン/ガラケー)サイト用AdSenseのためのPHPクラス
<?php
class adsenseForKeitai
{
private $ad_url = 'http://pagead2.googlesyndication.com/pagead/ads';
private $timeout = 3;//second
private $params = array(
'slot' => null,
'client' => null,//pub-...
@kijtra
kijtra / vars.php
Last active August 29, 2015 14:15
#PHP 変数のSet/Get用関数
<?php
function vars($keys = null, $value = null)
{
static $values = array(), $buffer = array();
if (empty($keys)) {
return $values;
}
@kijtra
kijtra / geohash.php
Created May 14, 2015 03:11
[PHP] Geo Hash encode and decode function.
<?php
function geohash($lat, $lon = NULL, $len = 12)
{
if ($len < 1 || $len > 12) {
return false;
}
$base32Chars = array(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'b', 'c', 'd', 'e', 'f', 'g',
@kijtra
kijtra / meconv.php
Created May 19, 2015 14:49
simple convert integer(system max numeric) <-> string(always 14 chars)
<?php
function meconv($value)
{
if (ctype_digit(strval($value))) {
$str = chr(96 + strlen(base_convert($value, 10, 36)));
$str .= base_convert($value, 10, 36);
$str .= md5($value);
return substr($str, 0, 14);
} elseif(is_string($value)) {