Skip to content

Instantly share code, notes, and snippets.

View codesandtags's full-sized avatar
:octocat:
Learning mode...

Edwin Torres codesandtags

:octocat:
Learning mode...
View GitHub Profile
fetch('someURL')
.then((data) => data.json())
.then((data) => {
const keysDuplicates = data.reduce((previous, current) => {
if(!previous[current.key]) {
previous[current.key] = 1;
} else {
previous[current.key] += 1;
}
@codesandtags
codesandtags / getAgenciesInfo.js
Created April 16, 2017 16:15
Retrieves the information about Travel Agencies in Colombia
// Extract the content in a Web Page and convert the data in a JSON object.
function thisIsSparta($selector){
const items = Array.from(document.querySelectorAll($selector));
const agencies = items.map(item => {
const url = item.querySelector('.field-name-field-web-page');
const address = item.querySelector('.field-name-field-address .field-item');
const agency = {
name: item.querySelector('h3').textContent.trim(),
phone: item.querySelector('.field-name-field-phone .field-item').textContent,
@codesandtags
codesandtags / turismo.json
Last active April 16, 2017 16:16
Guia Turistica Colombia
{
"transportes": [
{
"name": "AS TRANSPORTES",
"phone": "57 (4) 448 60 48 Ext",
"address": "Cra 69 No 49 - 06",
"location": "Medellín",
"url": "www.astransportes.com.co"
},
{
@codesandtags
codesandtags / commit-msg.txt
Created March 27, 2017 01:09
Hook for commit message using git. By WesBos :)
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.jsx\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do
@codesandtags
codesandtags / invertedColor.js
Created March 26, 2017 17:08
A snippet in JavaScript to invert the color given
function invertColor(color){
const invertedColor = ('000000' + (0xFFFFFF ^ parseInt(color.substring(1), 16)).toString(16)).slice(-6);
return `#${invertedColor}`;
}
let drink = 'Beers';
let snacks = 'Popcorn';
console.log(drink, snacks);
[drink, snacks] = [snacks, drink];
console.log(drink, snacks);
let drink = 'Beers';
let snacks = 'Popcorn';
console.log(drink, snacks);
[drink, snacks] = [snacks, drink];
console.log(drink, snacks);
@codesandtags
codesandtags / paddingLeft.js
Last active March 25, 2017 20:43
Example to add a padding left to a string in JavaScript
function paddingLeft(str, length = 25) {
return `${' '.repeat(length - str.length)}${str}`;
}
paddingLeft('This');
paddingLeft('is');
paddingLeft('Sparta!');
@codesandtags
codesandtags / gulpfile.js
Last active March 10, 2017 18:45
gulpfile.js example
"use strict";
const gulp = require('gulp');
const connect = require('gulp-connect');
const open = require('gulp-open');
const lint = require('gulp-eslint');
const config = {
port : 9005,
devBaseUrl: 'http://localhost',
#IntelliJ
.idea
.tmp
dist
# Logs
logs
*.log
npm-debug.log*