Skip to content

Instantly share code, notes, and snippets.

@ginpei
ginpei / gist:945726
Created April 28, 2011 03:09
Easy non-blocking looping
(function() {
// any codes
$('#time').text(new Date().toString());
// call own self
var INTERVAL = 10;
setTimeout(arguments.callee, INTERVAL);
})();
@ginpei
ginpei / parseObject.js
Created November 21, 2011 18:46
parse object like JSON
/*
var s = parseObject(data);
console.log(s);
*/
function parseObject(data) {
function f(data, indent, result) {
for (var p in data) {
var s = indent + p + ':';
if (typeof data[p] != 'object') {
result[result.length] = s + data[p];
@ginpei
ginpei / jsdoit.html
Created September 14, 2012 05:33
2012-09-14 1st
<p>
gistと連携したと聞いて。
</p>
@ginpei
ginpei / template.rx.js
Created October 4, 2012 03:37
RegExp for templating
"<{value}{value}{value}>"
.match(/^(.*?)(?:{(\$)?(\w+)})(.*?)$/)
"<{?cond}ttt{?cond2}TTT{:cond2}FFF{/cond2}{:cond}fff{/cond}>"
.match(/^(.*?)(?:{([?#]?)(.+)}(?:(.*?)(?:{\:\3}(.*)?)?{\/\3}))(.*?)$/)
"<{?cond}ttt{?cond2}TTT{:cond2}FFF{/cond2}{:cond}fff{/cond}>"
.match(/^(.*?)(?:(\$)?(\w+)}|{([?#]?)(.+)}(?:(.*?)(?:{\:\5}(.*)?)?{\/\5}))(.*?)$/)
"<{value}{value}{value}>"
@ginpei
ginpei / gist:4029790
Created November 7, 2012 06:02
md+diff
 this.isThe('code');
-removed('code');
+added('code');
@ginpei
ginpei / gist:4037023
Created November 8, 2012 05:36
diff syntax
 continued line
-removed line
+added line
@ginpei
ginpei / gist:4070764
Created November 14, 2012 07:09
How to pagination with backbone.js?
var PageModel = Backbone.Model.extend({ });
var PageView = Backbone.View.extend({
events: {
'click .other-page': 'open'
},
initialize: function() {
this.models = {};
},
@ginpei
ginpei / Gruntfile.js
Created December 17, 2012 02:00
`grunt.loadTasks('foo')` loads all JS files under directory `foo`, not `tasks/foo.js` with grunt v0.4.0rc2.
// ./Gruntfile.js
module.exports = function(grunt) {
grunt.loadTasks('hoge');
};
@ginpei
ginpei / run.js
Created April 17, 2013 07:08
Describe an immediate function to read easily.
/**
* Runs the function immediately.
* @param {Array} [args] Arguments for the function.
* @param {Object} [context] Context for the function.
* @param {Function} fn Target function.
* @returns {Any} Value returned by the function.
* @example run(function(){ console.log('done!'); });
* @example run([1,2], function(a,b){ return a+b; });
* @example var date = Date.now(); run([Date.now()], {start:date}, function(stop){ return stop-this.start; });
*/
@ginpei
ginpei / jQuery - internalData.js
Created April 21, 2013 08:15
jQuery v1.9.1 L1551
/**
* @param {HTMLElement} elem
* @param {String} name
* @param {Object} [data]
* @param {Boolean} [pvt] It will be `true` if called in _data not data
*/
function internalData( elem, name, data, pvt /* Internal Use Only */ ){
if ( !jQuery.acceptData( elem ) ) {
return;
}