Skip to content

Instantly share code, notes, and snippets.

Avatar
✏️
writing a github status

Nicolas Perriault n1k0

✏️
writing a github status
View GitHub Profile
View nuts.js
function add(){var a,v,n,f;a=[].slice.call(arguments),v=a[0]||0;if(a.length){n=a.slice(1).reduce(function(s,x){return s+x},v),f=add.bind(0,n);f.valueOf=function(){return n};return f}return v}
function test(a, b) {
if (a == b) {
console.log('OK');
} else {
console.log(a + ' != ' + b);
}
}
@n1k0
n1k0 / bbtest.html
Created Feb 3, 2014
Convenient way for a Backbone model view to listen to its model changes while being hold within a Collection
View bbtest.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul id="list">
<li>nope</li>
</ul>
<input type="button" id="btn" value="change">
@n1k0
n1k0 / poor-man-text-editor.md
Last active Aug 29, 2015
Paste this to your browser url bar
View poor-man-text-editor.md

Poor man text editor

Paste this to your browser url bar:

data:text/html,<script%20src="http://ace.c9.io/build/src/ace.js"></script><div%20id=e%20style="height:100%"></div><script>ace.edit("e")</script>
View views.js
var l10n = {
translate: function(el) {
console.log("l10n.translate() called for ", el);
}
};
function makeL10n(ViewClass) {
var oldRender = ViewClass.prototype.render;
ViewClass.prototype.render = function renderL10n() {
oldRender.apply(this, arguments);
View 1_goetsu.js
var casper = require("casper").create();
var arr1 = [], arr2 = [], arr3 = [];
casper.start("http://foo.bar/", function() {
arr1.push("plop1");
});
casper.thenOpen("http://bar.foo/", function() {
arr2.push("plop2");
});
View flux.md

Basically Flux

While trying to explain Flux to a friend using words, I realized that a diagram's worth a thousand of them, and went with this.

              +---------------------+               
              |                     |               
              |     Dispatcher      |               
          +-->|          +---------------+
          |   +----------|----------+    |          
View flux.md

Flux target API

This is a draft, WiP README Driven Development Wishlist for a Flux API. Don't judge, contribute.

Stores

Definition

@n1k0
n1k0 / index.js
Last active Aug 29, 2015
requirebin sketch
View index.js
var client = require("rest/client/jsonp");
client({
path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0',
params: { q: 'javascript' }
}).then(function(response) {
console.log("success", response);
}).catch(function(response) {
console.error("errored", response);
});
@n1k0
n1k0 / index.js
Created Feb 20, 2015
requirebin sketch
View index.js
var client = require("rest").wrap(require("rest/interceptor/jsonp"));
client({path: 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0', params: { q: 'javascript' } }).then(function (response) {
console.log(response);
});
@n1k0
n1k0 / index.js
Last active Aug 29, 2015
requirebin sketch
View index.js
var Dexie = require("dexie");
var db = new Dexie("articles2");
db.version(1).stores({articles: "id++,title,archived"});
db.open();
db.on("error", function(err) {
console.error(err);
});
db.articles.add({title: "plop", archived: "true"}).catch(console.error.bind(console)).then(function(id) {
console.log(id);
You can’t perform that action at this time.