Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
RyoSugimoto / extend.js
Last active August 29, 2015 14:21
オブジェクトを結合する。
/**
* Merge defaults with user options
* @private
* @param {Object} defaults Default settings
* @param {Object} options User options
* @returns {Object} Merged values of defaults and options
*/
var extend = function (defaults, options) {
var extended = {};
var prop;
@RyoSugimoto
RyoSugimoto / get_obj_length.js
Created April 22, 2015 01:05
オブジェクトのプロパティ数を取得する。
var getObjectLength = function (obj) {
var a, l = 0;
for (a in obj) {
l++;
}
return l;
};
@RyoSugimoto
RyoSugimoto / add_camma.js
Created April 22, 2015 01:03
指定した桁数でカンマを追加する。
var addCamma = function (number, fig) {
var str, ptn;
fig = fig || 3;
str = String(number).replace(/,/g, '');
ptn = RegExp('^(-?\\d+)(\\d{' + fig + '})');
while(str != (str = str.replace(ptn, "$1,$2")));
return str;
};
@RyoSugimoto
RyoSugimoto / to_AN.js
Created April 22, 2015 01:00
全角の英数文字を半角文字に変換する。
var toAN = function (data) {
var dataType = typeof data,
str = String(data);
str = str.replace(/[A-Za-z0-9]/g, function(s) {
return String.fromCharCode(s.charCodeAt(0) - 65248);
});
return dataType == 'number' ? Number(str) : str;
};
@RyoSugimoto
RyoSugimoto / get_query.js
Created April 22, 2015 00:59
クエリ文字列をオブジェクトに変換して返す。
var getQuery = function (url) {
if (typeof url !== 'string') {
url = window.location.href;
}
var queries = url.slice(url.indexOf('?') + 1).split('&'),
obj = {};
for (var i = queries.length; i--;) {
var query = queries[i].split('=');
obj[query[0]] = query[1];
}
@RyoSugimoto
RyoSugimoto / cancel.js
Created April 22, 2015 00:56
デフォルトイベントとバブリングの抑制(旧IE対応)。
var cancelBubble,
cancelEvent;
cancelBubble = (function () {
var func = function () {};
if (typeof Event !== 'undefined' && typeof Event.prototype.stopPropagation === 'function') {
func = function (e) { e.stopPropagation(); };
} else if (window.event) {
func = function () { window.event.cancelBubble = true; };
}
@RyoSugimoto
RyoSugimoto / add_event.js
Created April 22, 2015 00:53
イベントリスナを追加・削除する(旧IE対応)。
var addEvent,
removeEvent;
if (typeof window.addEventListener === 'function') {
addEvent = function (el, type, fn) { el.addEventListener(type, fn, false); };
removeEvent = function (el, type, fn) { el.removeEventListener(type, fn, false); };
} else if (typeof document.attachEvent === 'function') {
addEvent = function (el, type, fn) { el.attachEvent('on' + type, fn); };
removeEvent = function (el, type, fn) { el.detachEvent('on' + type, fn); };
} else {
<?php
class UserAgent{
private $ua;
private $device;
public function set(){
$this->ua = mb_strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($this->ua,'iphone') !== false){
$this->device = 'mobile';
}elseif(strpos($this->ua,'ipod') !== false){
$this->device = 'mobile';
var _ua = (function(u){
return {
Tablet:(u.indexOf("windows") != -1 && u.indexOf("touch") != -1) || u.indexOf("ipad") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") == -1) || (u.indexOf("firefox") != -1 && u.indexOf("tablet") != -1) || u.indexOf("kindle") != -1 || u.indexOf("silk") != -1 || u.indexOf("playbook") != -1,
Mobile:(u.indexOf("windows") != -1 && u.indexOf("phone") != -1) || u.indexOf("iphone") != -1 || u.indexOf("ipod") != -1 || (u.indexOf("android") != -1 && u.indexOf("mobile") != -1) || (u.indexOf("firefox") != -1 && u.indexOf("mobile") != -1) || u.indexOf("blackberry") != -1
}
})(window.navigator.userAgent.toLowerCase());
@RyoSugimoto
RyoSugimoto / perl.md
Last active August 29, 2015 14:14
Perlの基本的な文法。

Perl 基本

デバッグ

文書の先頭では、必ず以下の文を記述する。

use strict; # 厳しい文法チェック
use warnings; # 警告を表示

コメント