Skip to content

Instantly share code, notes, and snippets.

View elycruz's full-sized avatar

Ely De La Cruz elycruz

View GitHub Profile
// Simple fibonacci series generator. Generates fibonacci series from 0 to `limit` number.
function fib (limit) {
var out = [],
a = 0,
b = 1;
while (a < limit) {
out.push(a);
if (b <= limit) {
out.push(b);
}
@elycruz
elycruz / numToHex.js
Last active November 14, 2017 02:02
Javascript number to hexadecimal string function.
/**
* 'Fast Remainder' method for number to hex.
* @see http://www.wikihow.com/Convert-from-Decimal-to-Hexadecimal (fast remainder method (method 2)).
*/
const hexMap = [
[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5],
[6, 6], [7, 7], [8, 8], [9, 9], [10, 'A'], [11, 'B'],
[12, 'C'], [13, 'D'], [14, 'E'], [15, 'F']
];
@elycruz
elycruz / Namespace.js
Created May 22, 2015 22:48
Php Styled Autoloader for NodeJs
/**
* Created by Ely on 5/22/2015.
*/
require('sjljs');
var path = require('path'),
fs = require('fs');
var Namespace = sjl.Extendable.extend(function Namespace (dir, allowedFileExts) {
@elycruz
elycruz / .jshintrc
Created May 15, 2015 19:06
Good starting point .jshintrc file.
{
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : false, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
@elycruz
elycruz / .eslintrc
Last active September 18, 2016 16:42
.eslintrc as yaml file
# --------------------------------------------------------------------------------------------------------------------- #
# Conversion of http://eslint.org/docs/rules/ to an actual .eslintrc file:
# Copied: 04/01/2015
# Updated to yaml format: 05/15/2015
# Copied by: Ely De La Cruz <elycruz@elycruz.com>
# --------------------------------------------------------------------------------------------------------------------- #
# --------------------------------------------------------------------------------------------------------------------- #
# Environemnt Types:
# --------------------------------------------------------------------------------------------------------------------- #
@elycruz
elycruz / .eslintrc
Last active August 29, 2015 14:18
.eslintrc converted from http://eslint.org/docs/rules/ **Note** the file has no values (everything is set to null).
/**
Conversion of http://eslint.org/docs/rules/ to an actual .eslintrc file:
Copied: 04/01/2015
Copied by: Ely De La Cruz <elycruz@elycruz.com>
*/
/**
Rules:
Rules in ESLint are divided into several categories to help you better understand their value. Additionally, not all rules are enabled by default. Those that are not enabled by default are marked as being off.
**-------------------------------------------------------------------------------------------------------------------**/
@elycruz
elycruz / appendScriptTag.js
Last active August 29, 2015 14:18
Append a script tag (legacy way with optional use of jquery)
/**
* Creates and appends a script tag to the `document` at `insertLocation`. (This snippet is a good candidate for adding an
* interval or a timeout on the returned $.deffered|HTMLScriptElement)
* @param options hash of the following parameters:
* @param src {String|HTMLScriptElement} - Script source or script element. Required.
* @param doc {document} - `document` object. Optional. Default `document`.
* @param insertLocation {String} - Location at which to insert the script tag [head,body]. Optional. Default 'body'.
* @param onError {Function} - On error callback. Optional. If `$.getScript` is available these callbacks gets passed to `.fail()`.
* @param onSuccess {Function} - On success/completion callback. Optional.
* @param useGetScript {Boolean} - Whether to use `$.getScript` if it is available. Optional. Default `false`.
@elycruz
elycruz / delete-windows-old.js
Last active August 29, 2015 14:15
custom rmdirp for 'Windows.old' folder
/**
* Short script (**Note** needs to run with `--harmony` flag (testing on node 0.12.0))
* for getting rid of the 'Windows.old' folder and also is a custom rmdirp of sorts: overcomes the memory limitations of the rmdirp module when running on windows (and maybe linux?).
* Just replace `pathToOperateOn` with the location of your 'Windows.old' folder.
* Run it and celebrate! :-D (thumbsup)!
* (Also excuse the big tabs/spaces. Had some issues with my pc, had no software installed and use notepad to write it lol!)
*/
var fs = require('fs'),
path = require('path'),
pathToOperateOn = 'C:\Windows.old',
function _process(value) {
return new Promise(function (fulfill, reject) {
var count = 0, timeout;
timeout = setInterval(function () {
console.log('iteration ' + count);
if (count > 5 && value !== 'fail') { fulfill(true); clearInterval(timeout); }
else if (count > 5 && value === 'fail') { reject('Operation timed out.'); clearInterval(timeout); }
count += 1;
}, 100);
});
/**
* Created by edelacruz on 2/17/14.
* A shim for generating map objects for hash maps and array maps
* (arrays of 2 item arrays [0] 'key', [1] 'value')
*/
define(['es6-shim', 'checkjs'], function (_namespace) {
function fromArray (arrayMap, recursive) {
recursive = recursive || false;
var map = new Map(), value;