Skip to content

Instantly share code, notes, and snippets.

View rich-97's full-sized avatar

Ricardo Moreno rich-97

View GitHub Profile
@rich-97
rich-97 / server.sh
Created February 24, 2017 00:10
Server nodejs in one line.
nodejs -e 'require("http").createServer((req, res) => { res.end("response"); }).listen(8080);'
@rich-97
rich-97 / cheatsheet-javascript-es.md
Last active November 26, 2017 00:14
A cheatsheet for the objects (built-ins) of JS.

Math

/* Constantes */

Math.E       // número de Euler.
Math.PI      // número pi.
Math.SQRT2   // Raíz cuadrada de 2.
Math.SQRT1_2 // Raíz cuadrada de 1 / 2.
@rich-97
rich-97 / cheatsheet-nodejs-en.md
Created March 5, 2017 23:08
A cheatsheet for modules of NodeJS.

process

/* Events */

process.on('exit', function(code) {})             // Emitted when the process is about to exit
process.on('uncaughtException', function(err) {}) // Emitted when an exception bubbles all the way back to the event loop. (should not be used)

/* Properties */
@rich-97
rich-97 / Factorial.java
Last active March 26, 2017 00:36
Java factorial
import java.util.Scanner;
public class Factorial {
public static int fact (int val) {
if (val == 0)
return 1;
return val * fact(val - 1);
}
@rich-97
rich-97 / file.js
Created August 20, 2017 06:49
Liltle snippets for webpack export single object.
module.exports = {}
// Resolve the problem with the context (is by webpack).
Object.keys(module.exports).forEach(function (key) {
if (typeof module.exports[key] === 'function') {
module.exports[key] = module.exports[key].bind(module.exports)
}
})
@rich-97
rich-97 / echo.js
Created August 20, 2017 23:03
Echo server in nodejs.
const http = require('http')
const server = http.createServer()
server.on('request', function (req, res) {
req.pipe(res)
})
server.listen(8000)
@rich-97
rich-97 / data_upload.js
Created August 20, 2017 23:13
Data upload and print to the stdout with nodejs.
const http = require('http')
const server = http.createServer()
server.on('request', function (req, res) {
res.writeHead(200)
req.on('data', function (chunk) {
console.log(chunk.toString())
})
res.end()
@rich-97
rich-97 / git_alias.sh
Last active March 3, 2018 12:09
Common alias for Git.
alias gits='git status -s'
alias gitl='git log --oneline'
alias gitc='git commit -m'
alias gita='git add --all'
alias gitp='git push -u origin master'
alias gitd='git diff'
alias gitpl='git pull'
alias gitpb='git push origin'
@rich-97
rich-97 / validators.js
Created July 19, 2020 07:39
Javascript - Validators
import moment from 'moment';
/**
* Validate if a string is valid or not.
*
* @param {string} stringToTest - The string to validate.
* @param {boolean} [allowEmpty=false] - If a empty string should be valid or not.
* @param {boolean} allowNull - Returns true if the value is null
* @returns {boolean} If the string is valid or not.
*/