Skip to content

Instantly share code, notes, and snippets.

@eliOcs
eliOcs / javascript-scope.js
Created July 17, 2015 09:07
This example tries to explain the function scope of javacript.
/*jslint node: true, maxlen: 80, indent: 4 */
"use strict";
var paco = "paco";
function fun1(paco) {
console.log(paco);
}
function fun2() {
@eliOcs
eliOcs / gist:8801345
Created February 4, 2014 10:36
Count lines of code in bash
find . -type f \( -name '*.css' -or -name '*.js' -or -name '*.html' \) | xargs wc -l
@eliOcs
eliOcs / math.js
Created March 8, 2013 15:04
Calculating averages iteratively
"use strict";
var math = exports;
/**
* Adds a new value to a calculated average.
*
* i.e. n × average + value
* ------------------- = new average
* n + 1
@eliOcs
eliOcs / apps.js
Created October 11, 2012 18:35
Express and Handlebars
/*jslint node: true */
"use strict";
var express = require("express"),
consolidate = require("consolidate"),
Handlebars = require("handlebars"),
fs = require("fs");
var app = express();
@eliOcs
eliOcs / gist:3514963
Created August 29, 2012 16:10
Missing parameter middleware for Restify (Node.js)
server.use((function () {
var
/**
* Checks if a request parameter has been defined.
*/
contains = function (parameter) {
return this.params[parameter] !== undefined;
},
/**
@eliOcs
eliOcs / cipher-test.js
Created July 19, 2012 09:11
Cipher plain text with Node.js
var crypto = require("crypto"); // native module that allows ciphering
var CIPHER_KEY = "test-key", CIPHER_ALGORITHM = "aes256";
// Original message
var message = "This message will be ciphered";
console.log("Original message -> " + message);
// Cipher message
var cipher = crypto.createCipher(CIPHER_ALGORITHM, CIPHER_KEY);