Skip to content

Instantly share code, notes, and snippets.

View ecasilla's full-sized avatar
🏠
Working from home

Ernie Casilla ecasilla

🏠
Working from home
  • This Crust Planet
  • Washington,DC
View GitHub Profile
@ecasilla
ecasilla / define.js
Created July 16, 2015 16:22
module definition in all envs
if (typeof module !== 'undefined' && module.exports) {
module.exports = myModule;
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd){
// AMD. Register as an anonymous module.
define(function () {
return myModule;
});
} else {
window.myModule = myModule;
}
@ecasilla
ecasilla / dot.js
Last active August 29, 2015 14:25
DOT operator
DOT = function(obj,prop){
if(obj.hasOwnProperty(prop)){
return obj[prop];
}else if(obj.__proto__){
return DOT(obj.__proto__,prop)
}
}
DOTCALL = function(obj,props,args){
var fn = DOT(obj,props);
@ecasilla
ecasilla / object_diff.js
Last active November 19, 2015 17:32
Js Object Diff
import * as _ from 'lodash';
function objectDiff(prev, now){
// sanity checks, prev and now must be an object.
if ( ! _.isObject(prev) || ! _.isObject(now) ){
return new TypeError("Arguments must both be objects",__filename);
}
var changes = {};
for (var prop in now) {
// if property is new in now i.e unknown, add it too changes
@ecasilla
ecasilla / hex2rgb.js
Last active October 1, 2019 19:30
Hex2Rgb.js
function hex (hex){
if(/^#/.test(hex)){
hex = hex.slice(1);
}
if(hex.length !== 3 && hex.length !== 6 ){
throw new Error("Invaild hex String");
}
var digit = hex.split("");
@ecasilla
ecasilla / Range.js
Created February 3, 2015 03:33
Simple Range Fn for numbers
var Range = {
create: function (start, end) {
var results = [],
current = start,
step = start < end ? 1 : -1;
results.push(current);
while (current !== end) {
current += step;
@ecasilla
ecasilla / clear_mongo.js
Last active December 25, 2021 20:44
Clear mongo db before mocha specs
var config = require('path/to/config');
var mongoose = require('mongose');
process.env.NODE_ENV = 'test';
before(function (done) {
function clearCollections() {
for (var collection in mongoose.connection.collections) {
mongoose.connection.collections[collection].remove(function() {});
@ecasilla
ecasilla / hello.b
Created December 25, 2014 23:25
First Hello World
main(){
extrn a,b,c;
putchar(a); putchar(b); putchar(c); putchar('!*n');
}
a 'hell';
b 'o, w';
c 'orld';
//First appeard in 1972
@ecasilla
ecasilla / batman.js
Created December 23, 2014 01:20
Batman Joke
Array(21).join('lol'-2)+" Batman"
@ecasilla
ecasilla / md5-path.js
Created December 22, 2014 13:57
append md5 to path for browser caching
var calculateMD5String, filepath, md5;
md5 = require('MD5');
calculateMD5String = function(path) {
return '-' + md5(fs.readFileSync(path));
};
filepath = "app" + calculateMD5String("app.js") + ".js";
@ecasilla
ecasilla / http.js
Created November 21, 2014 23:52
Express HTTPS
//run in the command line one at a time
//openssl genrsa -out privatekey.pem 1024
//openssl req -new -key privatekey.pem -out certreq.csr
//openssl x509 -req -days 3650 -in certreq.csr -signkey -private.pem -out newcert.pem
var express = require('express'),
https = require('https'),
fs = require('fs');
privateKey = fs.readFileSync('path/to/privateKey.pem'),
cert = fs.readFileSync('path/to/newCert.pem'),