Skip to content

Instantly share code, notes, and snippets.

View Sysetup's full-sized avatar
🚀

Carlos H. Ramírez. Sysetup

🚀
View GitHub Profile
@Sysetup
Sysetup / index.html
Created September 9, 2017 02:44
Print var from url
<span><script>document.write(name+' '+middlename+' '+ lastname)</script></span>
<span><script>getQueryVariable("n");</script></span>
@Sysetup
Sysetup / module.js
Last active October 19, 2017 15:23
module.exports and exports NodeJS examples
//***************************
//sayhello.js
var sayhello1 = function() { };
var sayhello2 = function() { };
exports.sayhello1 = sayhello1;
exports.sayhello2 = sayhello2;
//index.js
var x = require('./sayhello.js');
x.sayhello1();
@Sysetup
Sysetup / index.js
Created October 24, 2016 05:14
Ways to print JSON per console
var http = require("http");
//Ways to print JSON per console:
console.log('http: '+http);
console.log(JSON.stringify(http, null, 4));
console.log(JSON.parse(JSON.stringify(http, null, 4)));
@Sysetup
Sysetup / index.js
Created October 24, 2016 04:07
Basic NodeJS dependency injection pattern example.
var server = require("./server");
var router = require("./router");
server.start(router.route); //Injecting router as parameter.
@Sysetup
Sysetup / map.js
Created October 13, 2016 00:41
Maps. Basic example.
var sayings = new Map();
sayings.set("dog", "woof");
sayings.set("cat", "meow");
sayings.set("elephant", "toot");
sayings.size; // 3
sayings.get("fox"); // undefined
sayings.has("bird"); // false
sayings.delete("dog");
sayings.has("dog"); // false
@Sysetup
Sysetup / iterator.js
Created October 13, 2016 00:14
Iterators basic example.
function makeIterator(){
var nextIndex = 0;
return {
next: function(){
return nextIndex < 5 ? { value: nextIndex++, done: false} : {done: true}
}
}
}
var it = makeIterator();
@Sysetup
Sysetup / index.html
Created October 12, 2016 23:10
try...catch statement. Example.
<!DOCTYPE html>
<html>
<body>
<p>Please input a number between 5 and 10:</p>
<input id="demo" type="text">
<button type="button" onclick="myFunction()">Test Input</button>
<p id="message"></p>
<script>
@Sysetup
Sysetup / object.js
Created October 12, 2016 22:21
Object prototype (Object constructor function) basic example.
var txt = "";
var x;
function Person(first, last, age, sex) { //Object prototype (Object constructor function)
this.firstName = first;
this.lastName = last;
this.age = age;
this.sex = sex;
this.changeFirstName = function (name) {
this.firstName = name;
@Sysetup
Sysetup / currying.js
Created October 12, 2016 19:57
Currying in Functional JavaScript.
var greetCurried = function(greeting) {
return function(name) {
console.log(greeting + ", " + name);
};
};
var greetHello = greetCurried("Hello");
//console.log('greetHello: ' + greetHello());
greetHello("Heidi"); //"Hello, Heidi"
greetHello("Eddie"); //"Hello, Eddie"
@Sysetup
Sysetup / app.js
Created October 10, 2016 23:51
Callback example
var rect = require('./module');
function solveRect(l,b) {
console.log("Solving for rectangle with l = " + l + " and b = " + b);
rect(l,b, function(err,rectangle) {
if (err) {
console.log(err);
}
else {
console.log("The area of a rectangle of dimensions length = " + l + " and breadth = " + b + " is " + rectangle.area());