Skip to content

Instantly share code, notes, and snippets.

View boopathi's full-sized avatar
💭
I may be slow to respond.

Boopathi Rajaa boopathi

💭
I may be slow to respond.
View GitHub Profile
@kastermester
kastermester / dependency-mapper.js
Last active September 15, 2015 05:32
Map module calls in JS code
var estreeWalker = require('estree-walker');
module.exports = function(ast, mapper){
estreeWalker.walk(ast, {
enter: function(node, parent){
if(node.type !== 'CallExpression'){
return;
}
if(node.callee.type == 'Identifier'){
if(node.callee.name == 'require' || node.callee.name == 'define'){
// AMD style require/defines
@boopathi
boopathi / addevent.js
Created April 25, 2011 06:26
cross-browser addEvent
Object.prototype.addEvent = function(evt, handler, useCapt) {
//JUST A CHECK TO HANDLE “onclick” and “click” as evt
if(evt.match(“^on”))
evt = evt.substr(2);
if(this.attachEvent)
return this.attachEvent('on' + evt, handler); // FOR IE
else if(this.addEventListener)
return this.addEventListener(evt, handler, useCapt); // OTHERS
else {
//IF BOTH FAILS
@boopathi
boopathi / gist:940390
Created April 25, 2011 11:26 — forked from gf3/gist:361449
Everyones favourite closure!
// everyone's new favorite closure pattern:
(function(window,document,undefined){ ... })(this,this.document);
// when minified:
(function(w,d,u){ ... })(this,this.document);
// which means all uses of window/document/undefined inside the closure
// will be single-lettered, so big gains in minification.
// it also will speed up scope chain traversal a tiny tiny little bit.
@boopathi
boopathi / gist:985312
Created May 22, 2011 09:45 — forked from paulirish/gist:616412
"iframe" sitedown fallback via <object>
<!-- so it turns out that the object tag can act like an iframe
but the cool thing is you can nest object tags inside eachother for a fallback path.
what this means is you can "objectframe" a site.. and if it fails.. (site down, offline, whatever).. it'll use the next one.
so you can objectframe the live site and fallback to a screenshot.
or something.
demo at : http://jsfiddle.net/paul/CY2FQ/1/
-->
@hiroshi-manabe
hiroshi-manabe / radix_sort.py
Created November 26, 2011 08:26
Radix sort
base = 10
def radix_sort(x, max):
radix = 1
while radix < max:
x = counting_sort(x, radix)
radix *= base
return x
def counting_sort(a, radix):

For those of you asking about my "redux mental breakthrough":

I've struggled with how to keep the state of multiple instances of the same component class in redux. I kept thinking that I had an "unkown number" of instances and would need to somehow carve out a piece of state when the new instance was mounted.

I don't know why I was thinking this way. Thinking is hard, isn't it? (I'm in the UK and they often say "isn't it?" after asserting something and I love it, anyway....)

@domenic
domenic / await.js
Last active December 16, 2015 11:38
Speculative idea for `await` in JS
// Let `doAjax`, `fadeIn`, `fadeOut`, and `delay` be promise-returning functions.
// In all the following examples, `example` is meant to return a promise that is fulfilled when
// all operations are completed, or rejected if any of the steps fail.
// ES5
function example() {
return doAjax("data.json").then(function (data) {
document.getElementById("data").innerText = data;
@bolshchikov
bolshchikov / gist:8069009
Last active January 1, 2016 00:49
Creating read-only JS object
// lo-dash lib is the dependency
function readOnly(target){
var _readOnly = function (target, acc) {
// acc is passed into the function to be used for observer
var _defineProperty = function (propName, target, acc) {
var i, len;
// operation to be performed when add occurred
const t = require("tcomb");
// imstruct is a tcomb type builder that internally builds an
// Immutable.Record object, but applies tcomb's type system to it
const imstruct = require("../util/imstruct");
const Person = imstruct({
name: t.String,
age: t.Number
});
class Module
def subclasses
classes = []
ObjectSpace.each_object do |klass|
next unless Module === klass
classes << klass if self > klass
end
classes
end
end