Skip to content

Instantly share code, notes, and snippets.

View renzocastro's full-sized avatar

Renzo Castro Jurado renzocastro

View GitHub Profile
class Version {
private _major: number;
private _minor: number;
private _patch: number;
toString = (): string => `${this._major}.${this._minor}.${this._patch}`;
constructor(versionStr: string) {
if (versionStr) {
const versionRegexp = /([0-9]+).([0-9]+).([0-9]+)$/
#!/bin/bash
# Reference: https://stackoverflow.com/a/59874960
if [ $# -eq 0 ]; then
git stash push -- $(git diff --staged --name-only)
else
git stash push -m "$@" -- $(git diff --staged --name-only)
fi
set --
@renzocastro
renzocastro / promise1.js
Created October 6, 2018 16:44
Js Promise 1
const pago = new Promise(function (resolve, reject) {
// Esta función se ejecuta al instante
setTimeout(() => {
// resolve('Resuelto');
reject('Rechazado');
}, 5000);
});
const onResolve = data => console.log('RESOLVE', data);
@renzocastro
renzocastro / xhr-demo.js
Created October 6, 2018 16:34
JS XMLHttpRequest
const request = new XMLHttpRequest()
request.open('GET', 'https://jsonplaceholder.typicode.com/users', true);
request.onload = function () {
console.log('DONE', request.responseText);
};
request.onerror = function () {
console.log('FAIL', 'Error loading page');
};
@renzocastro
renzocastro / fsUtils.inc.js
Last active October 5, 2018 16:50
Comparing NodeJS script and Bash Script
const fs = require('fs');
const path = require('path');
function existsSync(pathFileOrDirectory) {
try {
fs.accessSync(pathFileOrDirectory);
return true;
} catch (err) {
return false;
}
@renzocastro
renzocastro / bem.pug
Created February 28, 2018 23:41
mixin BEM on pugJS
-
function htmlEscape(str) {
return str
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\//g, '&#x2F;');
};
@renzocastro
renzocastro / signal-examples.js
Last active April 2, 2018 14:34
Basic emitter in JavaScript
// EXAMPLE 1
var formSended = new Signal();
formSended.add(function () { console.log('A'); });
formSended.add(function () { console.log('B'); });
// Put this anywhere in your code
formSended.dispatch();
// console output => 'A'
// console output => 'B'
@renzocastro
renzocastro / modal-js.md
Last active June 6, 2017 17:23
Código básico para creación de un modal (o lightbox).

Código básico para creación de un modal (o lightbox)

HTML (PUG)

a#linkTerminos(href="#modalTerminos") Terminos y Condiciones

#modalTerminos.lq-modal
  .lq-modal__header
    Titulo
@renzocastro
renzocastro / ProgressiveLoaderClass.js
Created May 24, 2016 21:08
Progressive Loader using jQuery
// require jQuery
;(function(){
var _p, _init, _done, _fail, _progress, _complete, _data, _index, _item, _jqXHR, _responses;
function ProgressiveLoader() { }
_p = ProgressiveLoader.prototype;
_p.init = function(callback) {
_init = callback;
@renzocastro
renzocastro / angular-http-post-json.js
Created October 23, 2015 13:43
Envió de data en formato JSON usando AngularJS.
$http({
url: 'php-scripts/save.php',
method: 'POST',
data: JSON.stringify($rootScope.user),
headers: {'content-type': 'application/json'}
}).success(function (data) {
});