Skip to content

Instantly share code, notes, and snippets.

gfdgdf dfgdfg dfg dfgdf
@alvag
alvag / parse-jwt.js
Created August 24, 2018 14:23 — forked from Klerith/parse-jwt.js
Parse - JWT - Obtener Payload y fecha de creación y expiración
function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
};
@alvag
alvag / Utils.js
Last active October 15, 2018 22:54
const Utils = {
// --------------------------------
// Parse a url and break it into resource, id and verb
// --------------------------------
parseRequestURL : () => {
let url = location.hash.slice(1).toLowerCase() || '/';
let r = url.split("/")
let request = {
resource : null,
@alvag
alvag / reset.css
Last active October 19, 2018 01:17
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
<?php
/**
* Model base class
*/
require_once 'connection.php';
class Model {
var data = [
{
country: 'China',
population: 1409517397,
},
{
country: 'India',
population: 1339180127,
},
{
@alvag
alvag / reduce.js
Last active October 29, 2018 17:04
Reduce uses an accumulator that will be the total of the calculation you are doing in the reduce method.
var numbers = [5, 10, 15, 20, 25, 30];
var sum = numbers.reduce(function(total, amount){
return total + amount
});
return sum;
//Output: 105
const _err = function(message) {
throw new Error(message);
}
const getSum = (a = _err('a is not defined'), b = _err('b is not defined')) => a + b;
getSum(10); // throws Error b is not defined
@alvag
alvag / class.js
Created October 30, 2018 14:44
Remove argument-order dependency and provide defaults
// https://dev.to/avraammavridis/codetip---javascript-remove-argument-order-dependency-and-provide-defaults-hph
// https://codepen.io/alva85/pen/KGYOgM
class Vehicle1 {
constructor(speed, weight, power, color, brand){
this.speed = speed;
this.weight = weight;
this.power = power;
this.color = color;
this.brand = brand;
//https://dev.to/mahlongumbs/if-if-what-1jda
const wow = arg => (
(arg === "dog" && "LOVELY") ||
(arg === "cat" && "CUTE") ||
"gimme an animal"
);
wow("cat");
const animals = {