Skip to content

Instantly share code, notes, and snippets.

View yoko's full-sized avatar
🍐
I like pear

yksk yoko

🍐
I like pear
View GitHub Profile
@yoko
yoko / grayback.js
Created January 7, 2009 12:34
new Grayback().show();
p = function() {
if (typeof console != 'undefined' && typeof console.log == 'function')
console.log.apply(null, arguments);
};
Grayback = (function() {
var id = 1;
var stack = [];
@yoko
yoko / apply_template.js
Created January 8, 2009 11:53
template('foo#{bar}baz. a #{b|another b}', { bar: 'BAR', b: null }); // fooBARbaz, a another b
applyTemplate = (function() {
var markup = /#\{([^|}]+)(?:\|(.*?)\|)?\}/g;
return function(t, o, escape) {
return (!t || !o) ?
t :
t.replace(markup, function(_, prop, alt) {
prop = o[prop];
if (!prop && prop !== '' && prop !== 0)
prop = alt || '';
return escape ? prop.escapeTag() : prop;
@yoko
yoko / jquery.randimage.js
Created January 9, 2009 09:35
$('<img/>').randImage(['a.png', 'b.png', 'c.png']);
(function($) {
$.fn.randImage = function(images) {
var length = images.length;
return this.each(function() {
var n = Math.floor(Math.random() * length);
this.src = images[n];
});
};
var addCSS = function(href) {
$.browser.msie ?
document.createStyleSheet(href) :
$('<link rel="stylesheet" type="text/css" href="'+href+'"/>').appendTo('head');
};
@yoko
yoko / deferred-parallel.js
Created January 19, 2009 08:34
Deferred#parallelでリストの並びを変えずに出力
var uri = encodeURIComponent('http://github.com/');
Deferred
.parallel({
ldc : $.getJSON('http://api.clip.livedoor.com/json/comments?callback=?&link='+uri),
hatebu: $.getJSON('http://b.hatena.ne.jp/entry/json/?callback=?&url='+uri)
})
.next(function(data) {
$('<div><p>GitHub:</p><ul/></div>')
.find('ul')
@yoko
yoko / gist:49807
Created January 21, 2009 01:55
$.browser.iphone and $.browser.chrome
(function($) {
var userAgent = navigator.userAgent.toLowerCase();
$.extend($.browser, {
iphone: $.browser.safari && /iphone/.test(userAgent),
chrome: $.browser.safari && /chrome/.test(userAgent)
});
})(jQuery);
Timer = function() {
};
Timer.prototype = {
initialize: function() {
this.time = [];
this.paused = false;
},
stack: function() {
var now = (new Date()).getTime();
@yoko
yoko / gist:50525
Created January 22, 2009 12:44
override Deferred.loop(fork from JSDeferred Sample's aloop;)). Timer is gist:50500.
Deferred.loop = function(n, f) {
var i = 0;
var end = new Object;
var ret = null;
return Deferred.next(function() {
var t = new Timer;
t.start();
try {
@yoko
yoko / class.js
Created January 26, 2009 12:27
Simple class based on Ten.Class.
Class = function(prototype, base) {
var c = prototype.initialize || (
base ?
function() { return base.apply(this, arguments); } :
function() {}
);
c.prototype = prototype;
c.prototype.constractor = c;
if (base) {
c.SUPER = base;
// does not work in IE
objectLength = function(obj) {
return obj.__count__;
}