Skip to content

Instantly share code, notes, and snippets.

View 2no's full-sized avatar
🤗

Kazunori Ninomiya 2no

🤗
View GitHub Profile
@2no
2no / array_sort_test.js
Created June 30, 2011 04:07
V8 エンジンは内部的にクイックソートを使用している為、安定していない。
var hoge = [8, 3, 7, 5, 4, 11, 9, 10, 6, 1, 2];
hoge.sort(function() {return 0;});
// RESULT
// Google Chrome 12.0.742.112
// node v0.4.8
// [11, 8, 7, 5, 4, 3, 9, 10, 6, 1, 2]
// ActionScript 3 + Flash Player 10,2,159,1
// [11, 3, 7, 5, 4, 8, 9, 10, 6, 1, 2]
@2no
2no / jsdoc_test.js
Created July 15, 2011 02:30
無名関数によるクラス作りのための JSDoc テンプレート
// http://www.wakuworks.com/test/jsdoc/
/**
* 名前空間の説明
* @namespace
*/
var Namespace = Namespace || {};
/**
* クラスの説明など
@2no
2no / php_cast.php
Created July 17, 2011 07:26
PHP5 でオブジェクトを何でもキャスト
<?php
// http://stackoverflow.com/questions/2226103/how-to-cast-objects-in-php
$a = new A();
$b = cast($a, 'B');
$a->foo(); // A!
$b->foo(); // B!
function cast($obj, $toClass)
{
@2no
2no / youtube_proxy.php
Created July 18, 2011 11:55
Flash などから Youtube の動画を読み込む為のプロキシ。後は crossdomain.xml を設置
<?php
// usage:
// youtube_proxy.php?url=http%3a%2f%2fwww%2eyoutube%2ecom%2fwatch%3fv%3dmxPXPv3oNY4%26feature%3dfvsr
define('YOUTUBE_DOMAIN', 'www.youtube.com');
// fmt(優先度:左->右)
$fmtTbl = array(5, 18, 34, 22, 37);
$url = isset($_GET['url']) ? rawurldecode($_GET['url']) : '';
@2no
2no / jquery.cssFrag.js
Created July 26, 2011 08:12
フラグメント ID として(jQuery の)CSS セレクタでの指定を可能にする サンプル)http://www.wakuworks.com/jquery.cssFrag/
/**
* jquery.cssFrag: Using (jQuery)CSS Selectors as Fragment Identifiers
* Author: Kazunori Ninomiya
* Version: 1.0.0
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
* Requires: jquery.js
* Requires: jquery.ba-hashchange.js
* http://benalman.com/code/projects/jquery-hashchange/docs/files/jquery-ba-hashchange-js.html
*/
(function($, window, document, undefined)
@2no
2no / calc_ip.js
Created July 30, 2011 09:48
IP とサブネットマスクから範囲を計算(IPv4 のみ)
var PATTERN = /^(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\.(\d|[01]?\d\d|2[0-4]\d|25[0-5])\/(\d|[012]?\d|3[0-2])?$/;
var BIT_STR = "11111111111111111111111111111111";
var MIN_BIT = 8;
var MAX_BIT = 30;
function calcIp(ip)
{
var result = [];
var ip = ip.match(PATTERN);
@2no
2no / browser_zoom_event.js
Created July 31, 2011 07:51
ブラウザのズームを検知して通知
(function($, window, document, undefined)
{
/**
* add browser zoom event
* @see http://novemberborn.net/2007/12/javascriptpage-zoom-ff3-128
*/
var ZOOM_CHECK_INTERVAL = 1;
$(function() {
@2no
2no / Variables.php
Created August 21, 2011 06:57
自動的に文字列を UTF-8 に変換し、NULL バイト文字を削除する
<?php
class Variables extends ArrayObject
{
/**
* 取得候補の文字コード
*
* @var string
*/
const DETECT_ORDER_ENCODING = 'UTF-8, SJIS-win, eucJP-win';
@2no
2no / sample.php
Created September 11, 2011 09:10
TwitterOAuth でアイコンや背景画像が変更出来るように修正
<?php
/** @see TwitterAOauth */
require_once 'twitteroauth/twitteroauth.php';
$consumer_key = 'xxx';
$consumer_secret = 'xxx';
$oauth_token = 'xxx';
$oauth_token_secret = 'xxx';
@2no
2no / trim.as
Created October 24, 2011 11:02
Flash でトリム?
trace("    hogehoge     ".replace(/^[\s\t\r\n\0\0xB ]*|[\s\t\r\n\0\0xB ]*$/sg, ""));