Skip to content

Instantly share code, notes, and snippets.

Avatar
😃
Coding

J. Gabriel Corpas naoxink

😃
Coding
View GitHub Profile
@naoxink
naoxink / getType.js
Last active Sep 26, 2018
Utility to check variable types easy
View getType.js
function getType(x){
return Object.prototype.toString.call(x).toLowerCase().replace(/\[(.*)\s|\]$/g, '')
}
// Types (all strings):
//
// number
// string
// boolean
// date
@naoxink
naoxink / addVirtualProperty.js
Created Jul 17, 2018
`Object.defineProperty` calculated property test
View addVirtualProperty.js
function addVirtualProperty(options){
if(!options.obj || typeof options.obj !== 'object'){
throw new Error('Expected `obj`[Object object]')
}
if(!options.prop){
throw new Error('Expected `prop`')
}
Object.defineProperty(options.obj, options.prop, {
get(){
return options.getter.call(options.obj)
@naoxink
naoxink / customElements.html
Created Jul 12, 2018
TEST Custom Web Elements
View customElements.html
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>TEST Custom Elements</title>
<style>body{text-align: center;}</style>
</head>
<body>
<template id="clickBtn">
@naoxink
naoxink / createIterator.js
Last active Jul 11, 2018
Simple iterator in Javascript
View createIterator.js
function createIterator(array){
var index = -1
var hasNext = function(){
return (index + 1) < array.length
}
var hasPrev = function(param){
return (index - 1) < array.length && (index - 1) > -1
}
@naoxink
naoxink / print_array.php
Last active Jul 17, 2018
print_array PHP
View print_array.php
<?php
/**
* Imprime un array en consola con otro formato
* @param array $array
* @param integer $lvl
* @param integer $keylen
* @param integer $actual_spaces
*/
function print_array($array, $lvl = 0, $keylen = 0, $actual_spaces = 0){
if($lvl == 0){
You can’t perform that action at this time.