Skip to content

Instantly share code, notes, and snippets.

View n1k0's full-sized avatar
✏️
writing a github status

Nicolas Perriault n1k0

✏️
writing a github status
View GitHub Profile
@n1k0
n1k0 / nuts.js
Created August 29, 2015 07:22
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 / poor-man-text-editor.md
Last active August 29, 2015 13:55
Paste this to your browser url bar

Poor man text editor

Paste this to your browser url bar:

data:text/html,

@n1k0
n1k0 / bbtest.html
Created February 3, 2014 11:50
Convenient way for a Backbone model view to listen to its model changes while being hold within a Collection
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul id="list">
<li>nope</li>
</ul>
<input type="button" id="btn" value="change">
@n1k0
n1k0 / views.js
Last active August 29, 2015 13:59
ugly
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);
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");
});
@n1k0
n1k0 / flux.md
Last active August 29, 2015 14:07

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      |               
          +-->|          +---------------+
          |   +----------|----------+    |          
@n1k0
n1k0 / flux.md
Last active August 29, 2015 14:14

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 August 29, 2015 14:15
requirebin sketch
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 February 20, 2015 15:14
requirebin sketch
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 August 29, 2015 14:16
requirebin sketch
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);