Skip to content

Instantly share code, notes, and snippets.

View Sysetup's full-sized avatar
🚀

Carlos HRG. Sysetup

🚀
View GitHub Profile
@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 / 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 / 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 / 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 / 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.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 / index.html
Created September 9, 2017 04:07
DOM images preloader
<div class="load-container">
<img src="img/logo.gif" alt="logo" class="loading"/>
</div>
<div>
<img src="img/sequence/Frame0001.jpg" alt="" class="sequence" id="myimg">
</div>
@Sysetup
Sysetup / app.js
Created October 9, 2017 23:37
Middleware for Express.js
var express = require('express');
var app = express();
var server = app.listen(3000);
function logger(req,res,next){
console.log(new Date(), req.method, req.url);
next();
}
@Sysetup
Sysetup / index.ejs
Last active October 24, 2017 14:40
EJS Template
<div class="list-group">
<!-- loop over blog posts and render them -->
<% posts.forEach((post) => { %>
<a href="/post/<%= post.id %>" class="list-group-item">
<h4 class="list-group-item-heading"><%= post.title %></h4>
<p class="list-group-item-text"><%= post.author %></p>
</a>
<% }) %>
</div>
@Sysetup
Sysetup / controller.js
Created October 29, 2017 05:04
Insert a new register to a JSON file with NodeJS.
'use restrict';
/**
* Local module dependences.
*/
var db = require('./db');
/**
* Function that get all data entered in the signup form, check if user exist calling db.engine.findByUsername() function. Return the properly messages to the view according if user exist and password match.
*