Skip to content

Instantly share code, notes, and snippets.

View Saneyan's full-sized avatar

Saneyuki Tadokoro Saneyan

  • Yerevan, Armenia
View GitHub Profile
/**
* Auto Update
* These anonymous functions extends specific object automatically.
*/
(function( Update ){
try{
// Succeed to wic properties and methods.
// But some of them are overridden.
Update.prototype = wic;
} catch( e ){
@Saneyan
Saneyan / gist:1553636
Created January 3, 2012 05:22
Require Scripts
/**
* Require file
*
* option object has
* {
* url : string || array || object
* error : function
* done : function
* loaded : function
* async : true || false
@Saneyan
Saneyan / gist:2319162
Created April 6, 2012 11:53
Create calendar method.
function createCalendar( year, month ){
var calendarArray = [];
var weekdayStrArray = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ];
var monthStrArray = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ];
var monthArray = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
var monthDay = monthArray[ month - 1 ];
var currentDay = ( new Date( year, ( month - 1 ), 1, 0, 0, 0 ) ).getDay();
if( month == 2 )
monthDay += year % 4 ? 0 : year % 100 ? 1 : year % 400 ? 0 : 1;
@Saneyan
Saneyan / gist:3217372
Created July 31, 2012 14:25
Deterministic Finite Automation
var automaton = {
current: {
state: 0
}
, defaults: {
state: 0
}
, transition: [
@Saneyan
Saneyan / gist:3223667
Created August 1, 2012 04:25
Self invoking anonymous functions
// Using void
void function(){
console.log( 'hello' );
}();
// Using !
!function(){
console.log( 'yes' );
}();
var str_1 = '''
Good
morning,
world.
''';
var str_2 = """
Good
night,
world.
@Saneyan
Saneyan / start.app.js
Created November 7, 2012 14:49
Application starter
/**
* start.app.js
*
* Application starter. Will use it on my website :)
*
* @author Saneyuki Tadokoro (@Saneyan or @jSaneyan) <post@saneyuki.gfunction.com>
*/
//
// Use strict mode
@Saneyan
Saneyan / module_manager.js
Created November 16, 2012 09:06
Module Manager (Prototype)
var wic = wic || {};
wic.Module = function(){
var _id
, _detail
, _children = {};
/*
* @param object destination
###
CoffeeScript Tests for ME!
I found CoffeeScript is very very simple...
@author Saneyuki Tadokoro (@Saneyan or @jSaneyan) <post@saneyuki.gfunction.com>
###
#
# Util
@Saneyan
Saneyan / gist:4204518
Created December 4, 2012 14:33
Mongoose - Nested Schema
var mongoose = require( 'mongoose' );
var db = mongoose.createConnection( 'mongoose://localhost/test' );
db.on( 'error', function( err ){
console.log( err );
});
db.once( 'open', function(){
var Schema = mongoose.Schema;