Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
DavidBruant / gist:2815846
Created May 27, 2012 20:43
Dynamic DOM prototype
var originalNodeListProto = NodeList.prototype;
var temporaryNodeListProto = Object.create(NodeList.prototype);
temporaryNodeListProto.a = 1;
NodeList.prototype = temporaryNodeListProto;
var l = document.querySelectorAll('a');
console.log(l.a); // inherited from which prototype?
NodeList.prototype = originalNodeListProto;
@DavidBruant
DavidBruant / gist:2868249
Created June 4, 2012 13:06
Attempt to figure out where headers are set and when body is sent to try to figure out where is a header set after the first byte of the body is sent (nodejs, connect, express)
(function(){
/**
* Overriding header setting native capabilities to enable debugging "Can't set headers after they are sent."
*/
var http = require('http');
var nativeServerResponsePrototypeWriteHead = http.ServerResponse.prototype.writeHead;
var nativeServerResponsePrototypeSetHeader = http.ServerResponse.prototype.setHeader;
// response.setHeader(name, value)
function settingHeader(h, v){
@DavidBruant
DavidBruant / gist:2972521
Created June 22, 2012 12:36
Dynamic addElement
'use strict';
var elements;
function add(e){
// first call
elements = [];
add = function add(e){
// All other calls
// With cooperation of the platform
var privateNamesIKnow = new WeakSet();
var handler = {
isPrivateNameKnown: WeakSet.prototype.has.bind(privateNamesIKnow),
getOwnPropertyDescriptor: function(target, name){
return doSomethingUseful(target, name);
},
defineProperty: function(target, name, desc){
@DavidBruant
DavidBruant / divinePalindrome.js
Created August 24, 2012 13:43
divinePalindrome.js
function divinePalindrome(str){
return str.length <= 1 ?
true :
str[0] === str[str.length-1] && divinePalindrome( str.substring(1, str.length-1) );
}
console.log(divinePalindrome(''))
console.log(divinePalindrome('a'))
console.log(divinePalindrome('aa'))
console.log(divinePalindrome('ab'))
function makeMembrane(){
var revokableWrappingHandler = new Proxy.revokable({}, {
get: function(target, name){
return Reflect.call.bind(wrap(Reflect[name]));
}
});
var revoke = revokableWrappingHandler.revoke;
var wrappingHandler = revokableWrappingHandler.proxy;
var un2wrapped = new WeakMap();
@DavidBruant
DavidBruant / ProxyMap.js
Created October 19, 2012 13:29
ProxyMap. Maybe what objects should have been?
"use strict";
(function(global){
var handler = new Proxy({
get: function(target, name){
return target.get(name);
},
set: function(target, name, value){
target.set(name, value);
@DavidBruant
DavidBruant / gist:4066406
Created November 13, 2012 15:39
Figure out max vibration value
"use strict";
(function(global){
if(typeof global.navigator.vibrate === 'function')
return;
var MAX = Math.floor(1000000*Math.random());
console.log('MAX', MAX);
@DavidBruant
DavidBruant / gist:4089153
Created November 16, 2012 17:20
Internals explorer
var t = {a:1};
var traps = [];
var handler = new Proxy({}, {
get: function(t, name){
traps.push(name)
return undefined
}
})
@DavidBruant
DavidBruant / gist:4160427
Created November 28, 2012 10:42
Revue de TimerJS

L'excellent Jérémie Patonnier m'a contacté pour que je donne un avis sur le JS de son projet TimerJS. Je lui ai répondu en privé, mais je me dis que ça peut servir à d'autres de publier mes commentaires. Alors les voici. Mes remarques s'appuient sur cette version spécifiquement

Remarques non-code

  • J'adore la séparation des tests en "manual" et "automatique". Ca devrait être la règle dans tous les projets, mais je l'ai rarement vu appliqué.
  • Pour le copyright, il faut que tu mettes ton nom à côté, sinon, on ne sait pas à qui appartient le droit de copie.

Impressions générales