Skip to content

Instantly share code, notes, and snippets.

View bloodyowl's full-sized avatar
🦉

Matthias Le Brun bloodyowl

🦉
View GitHub Profile
var emptyFunction = () => {}
/**
* creates a new constructor function with `objects` merged in its prototype.
* to prevent unwanted errors when calling `super()` a child class, the
* prototype is actually a proxy returning **or** the actual method, or an
* empty function.
*
* as the proxy gets the same shape as the initial object, the prototype chain
* actually receives the present methods.
var _id = -1
var timersMap = new Map()
var Timer = {
/**
* starts executing `func` at every frame from the moment `setTransition` is called
* and during the duration in milliseconds.
*
* the method returns a number `id` which can be used as `clearTransition` parameter
@bloodyowl
bloodyowl / gist:41b1de3388c626796eca
Last active April 20, 2020 03:27
es6 event-emitter
var DEFAULT_MAX_LISTENERS = 12
function error(message, ...args){
console.error.apply(console, [message].concat(args))
console.trace()
}
class EventEmitter {
constructor(){
this._maxListeners = DEFAULT_MAX_LISTENERS
var merge = require("react/lib/merge")
var Store = require("../utils/store")
var AppDispatcher = require("../dispatcher")
var AppConstants = require("../constants")
var ActionTypes = AppConstants.ActionTypes
var API = require("../api")
var _store = {
@bloodyowl
bloodyowl / before.js
Created September 30, 2014 19:46
how coding styles change …
function contains(value){
var self = this
, index = 0, l = self.length
for(;index < l; index++) if(value === self[index]) return true
return false
}
// …
Array.prototype.contains = contains
@bloodyowl
bloodyowl / gist:00a533f3aa277d217c92
Created September 12, 2014 09:25
simple selector
var nativeSlice = Array.prototype.slice
var CAN_SLICE_NODELISTS = function(){
try {
nativeSlice.call(document.documentElement.children)
return true
} catch(e){
return false
}
}()
var ACCEPTED_NODETYPES = {
@bloodyowl
bloodyowl / index.js
Created August 12, 2014 09:59
requirebin sketch
var klass = require("bloody-class")
var myClass = klass.extend({
get : function(){
return "deep"
}
})
.extend({
get : function(){
return "shallow"
@bloodyowl
bloodyowl / index.js
Created August 1, 2014 16:20
requirebin sketch
var promise = require("bloody-promise")
var log = function(string){
document.body.appendChild(document.createTextNode(string))
document.body.appendChild(document.createElement("br"))
}
var mapAsync = function(array, fn){
var index = -1
var length = array.length
var promises = []
@bloodyowl
bloodyowl / index.js
Created June 24, 2014 20:33
requirebin sketch
var stream = require("bloody-stream")
var concat = require("bloody-stream/lib/concat")
var escapeRE = /([.*+?^=!:$(){}|[\]\/\\])/g
var mapEscape = function(string){
return string.replace(escapeRE, "\\$1")
}
var tilde = function(words){
var wordsRE = RegExp("\\b" + words.map(mapEscape).join("\\b|\\b") + "\\b", "g")
return stream.create(function(chunk){
if(!wordsRE.test(chunk)) {
function toUnicode(string) {
var index = -1
var length = string.length
var chars = []
var item
while(++index < length) {
item = string.charCodeAt(index).toString(16).toUpperCase()
item = "\\u" + Array(5 - item.length).join("0") + item
chars.push(item)
}