Skip to content

Instantly share code, notes, and snippets.

View carlosascari's full-sized avatar
:octocat:
Mediatek Hacker

Ascari carlosascari

:octocat:
Mediatek Hacker
  • Home
View GitHub Profile
@carlosascari
carlosascari / crc2D.js
Created February 14, 2016 20:21
A Cyclic Redundancy Checksum designed for small 2D signed coordinates.
/**
* Provides crc2D function.
*
* A Cyclic Redundancy Checksum designed for small 2D signed coordinates.
*
* Based on: https://github.com/alexgorbatchev/node-crc/blob/master/src/crc16.js
*
* The algorithm provides up to a maximum of 65,536 Unique Values. For x and y,
* this means that up to a byte (256 values) can be guaranteed to not collide.
*
@carlosascari
carlosascari / EventEmitterTrait.js
Last active January 24, 2016 23:04
Function that allows any object to function as a synchronous Event Emitter.
/**
* Provides an EventEmitter Trait
*
* USAGE @example
*
* function YourClass(){
* EventEmitterTrait(this) // or any object
* }
*
* var yourObject = new YourClass()
@carlosascari
carlosascari / rename_function.js
Last active February 19, 2016 06:45
A Hacky way of renaming an existing function
/**
* Renames and existing function.
*
* @private
* @method rename_function
* @param name {String}
* @param fn {Function}
* @return Function
*/
function rename_function(name, fn)
@carlosascari
carlosascari / baseN.js
Last active November 17, 2015 22:49
Convert numbers into any base e.g: 2, 8,16, 64,1024, 65500, etc.
/**
* Provides BaseN class
*
* Encode and decode numbers as any base
*
* @example
*
* var baseX = new BaseN() // Default base is 65,535
* var sample = 9007199254740991
* var encoded = baseX.encode(sample)
@carlosascari
carlosascari / tiny-require.js
Last active October 23, 2015 06:09
Guarantee a module has loaded before executing.
/**
* Tiny Require
*/
/**
* Before the module has finished downloading/evaluating,
* the callback provided is executed async. Once loaded, all
* callbacks will be executed immediately.
*
* A module is detected when it is available in the window object.
@carlosascari
carlosascari / EventEmiterBehaviour.js
Last active November 17, 2015 22:52
Abstract class to add Event Emitter functionality for decoupling objects, setting up patterns (PubSub, Mediator, Observer)
/**
* Provides Event Emitter functionality
*
* Allows decoupling existing classes/prototypes
* Events are emitted in Sync.
*
* Usage
* @example
*
* function YourClass()