Skip to content

Instantly share code, notes, and snippets.

View taiju's full-sized avatar

HIGASHI Taiju taiju

View GitHub Profile
@taiju
taiju / index.html
Created October 23, 2010 12:25
「そう簡単には読ませてあげませんったー」のソースコード
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>そう簡単には読ませてあげませんったー</title>
<link href="style.css" rel="stylesheet">
<script src="http://www.google.com/jsapi"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
google.load('jquery', '1.4.3');
@taiju
taiju / hoge.js
Created October 24, 2010 03:00
jQueryのようにクラスメソッドをコンストラクタにして、そのままメソッドチェインでメソッドを呼び出しできるようにする
(function() {
var _Hoge = function() {
var that = this;
return function(val) {
that._val = val ? val : null;
return that;
}
};
_Hoge.prototype = {
val: function(v) {
@taiju
taiju / gist:646315
Created October 26, 2010 04:37
reduceの使い方。汎用的な関数を作る時に超便利。
var sum = function(a) {
return a.reduce(function(x, y) { return x + y; });
};
var max = function(a) {
return a.reduce(function(x, y) {
if (x > y) return x;
return y;
});
};
@taiju
taiju / ary.js
Created October 27, 2010 12:33
配列操作の俺々ライブラリ。まだ途中。
(function() {
var _Ary = function() {
var self = this;
return function(data) {
self.data = data instanceof Array ? data : Array.prototype.slice.call(data);
return self;
};
};
_Ary.prototype = {
@taiju
taiju / bookmark.html
Created December 6, 2010 09:54
iPad用のソース表示ブックマークレット
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>view-source</title>
</head>
<body>
<p>以下のリンク先をBookmarkに追加する。</p>
<a href="javascript:(function(){var script=document.createElement('script');script.type='text/javascript';script.src='/path/to/view_source.js';document.body.appendChild(script);})()">ソースを表示</a>
</body>
@taiju
taiju / functions.php
Created December 10, 2010 06:56
WordpressでTweetThisボタンを組み込むときにリンクを生成する関数
<?php
function the_tweet_this($template) {
global $post;
$base_uri = 'http://api.bit.ly/v3/shorten';
$params = array(
'login' => YOURLOGINID,
'apiKey' => YOURAPIKEY,
'format' => 'json',
);
$params['longUrl'] = urlencode(get_permalink($post));
@taiju
taiju / iterator.js
Created January 11, 2011 05:21
クロージャ版iterator
var iterator = function(arr) {
if (!arr.length) throw new TypeError(typeof arr + ' is not permitted.');
var copy = (arr instanceof Array) ? arr.slice() : Array.prototype.slice.call(arr);
var len = copy.length;
var _move = function(method_name) {
var current = copy[method_name]();
len--;
if (len === -1) throw new Error('Stop Iteration');
return current;
};
@taiju
taiju / iterator.js
Created January 11, 2011 07:17
クラスメソッド版iterator
(function() {
var _Iterator = function() {
var that = this;
return function(items) {
if (!items.length) throw new TypeError(typeof items + ' is not permitted.');
that._items = (items instanceof Array) ? items.slice() : Array.prototype.slice.call(items);
that._limit = that._items.length;
that._item;
return that;
};
@taiju
taiju / script.js
Created January 17, 2011 07:23
bodyのid属性またはclass属性でdispatcherする
/* 配列周りのメソッド部分がブラウザ依存コードなので、実際はもうちょっとちゃんと書いた方がいい */
/* もしくはMDCからreduce, forEachのコードを引用する */
var Site = function() {
this.id = document.getElementsByTagName('body')[0].getAttribute('id');
this.classes = document.getElementsByTagName('body')[0].getAttribute('class').split(' ');
this.actions = [];
};
Site.prototype = {
doAction: function() {
var self = this;
@taiju
taiju / functions.php
Created March 24, 2011 10:02
WP_Widget_Text
<?php
/**
* HTML widget class
*
* WPINC/default-widgets.php内にある
* WP_Widget_Textを使いやすいように改変したもの
*
*/
class WP_Widget_HTML extends WP_Widget {