Skip to content

Instantly share code, notes, and snippets.

View FiNGAHOLiC's full-sized avatar
🐰
Strugglin'

Yukihiko Okuyama FiNGAHOLiC

🐰
Strugglin'
  • Root Communications
  • Tokyo Japan
  • 21:14 (UTC +09:00)
View GitHub Profile
@FiNGAHOLiC
FiNGAHOLiC / gist:1047730
Created June 26, 2011 15:56
Shuffle array
function shuffle(){
var arr = arguments;
var i = arr.length;
while(i){
var j = Math.floor(Math.random()*i);
var t = arr[--i];
arr[i] = arr[j];
arr[j] = t;
};
return arr;
@FiNGAHOLiC
FiNGAHOLiC / gist:1055801
Created June 30, 2011 07:26
Detect apple device
function isAppleDevice(){
var apple = {};
apple.ua = navigator.userAgent;
apple.device = false;
apple.types = ['iPhone', 'iPod', 'iPad'];
for (var i = 0; i < apple.types.length; i += 1) {
var t = apple.types[i];
apple[t] = !!apple.ua.match(new RegExp(t, "i"));
apple.device = apple.device || apple[t];
};
@FiNGAHOLiC
FiNGAHOLiC / gist:1141638
Created August 12, 2011 07:24
Dynamic CSS
var style, css;
if (document.createStyleSheet){ // IE
style = document.createStyleSheet();
css = function(s){
style.cssText = s;
}
} else {
style = document.createElement('style');
document.getElementsByTagName('head')[0].appendChild(style);
css = function(s){
@FiNGAHOLiC
FiNGAHOLiC / gist:1416414
Created December 1, 2011 12:36 — forked from ehynds/widget-template.js
UI Widget Factory template
(function($){
$.widget("ui.mywidget", {
options: {
autoOpen: true
},
_create: function(){
// by default, consider this thing closed.
@FiNGAHOLiC
FiNGAHOLiC / gist:1605795
Created January 13, 2012 12:09
Immediately invoked function expressions
// http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture
(function(){
// code to be immediately invoked
}()); // Crockford recommend this way
(function(){
// code to be immediately invoked
})(); // This is just as valid
@FiNGAHOLiC
FiNGAHOLiC / gist:1605801
Created January 13, 2012 12:11
Event throttle
var timer;
window.addEventListener('resize', function(){
if(timer) return;
/* ここに処理 */
timer = setTimeout(function(){
timer = undefined;
}, 100);
}, false);
@FiNGAHOLiC
FiNGAHOLiC / gist:1605823
Created January 13, 2012 12:17
Module pattern
// http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture
var backetModule = (function(){
var basket = []; // private
return { // exposed to public
addItem : function(values){
basket.push(values);
},
getItemCount : function(){
return basket.length;
@FiNGAHOLiC
FiNGAHOLiC / gist:1605851
Created January 13, 2012 12:24
Module pattern (jQuery)
// http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture
function library(module){
$(function(){
if(module.init){
module.init();
};
});
return module;
};
@FiNGAHOLiC
FiNGAHOLiC / gist:1605878
Created January 13, 2012 12:29
Module pattern (YUI)
// http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture
YAHOO.store.basket = function(){
var myPrivateVar = 'I can accessed only within YAHOO.store.basket.';
var myPrivateMethod = function(){
YAHOO.log('I can be accessed only from within YAHOO.store.basket.');
};
return {
myPublicProperty : 'I am a public property.',
myPublicMethod : function(){
@FiNGAHOLiC
FiNGAHOLiC / gist:1605960
Created January 13, 2012 12:54
Facade Pattern
// http://speakerdeck.com/u/addyosmani/p/large-scale-javascript-application-architecture
var module = (function(){
var _private = {
i : 5,
get : function(){
console.log('current value:' + this.i);
},
set : function(val){
this.i = val;