Skip to content

Instantly share code, notes, and snippets.

View jonalvarezz's full-sized avatar
🦑

Jonathan Alvarez jonalvarezz

🦑
View GitHub Profile
@jonalvarezz
jonalvarezz / array-flat.js
Created November 15, 2018 03:30
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
/**
* Array Flat
* This a commonJS module written in ES6 that will flatten
* an array of arbitrarily nested arrays of
* integers into a flat array of integers.
*
* @example
* import arrayFlat from '/your/path/array-flat'
*
* flatten([0, 1, 3, [4, 5, 6, [4, 6]]])
@jonalvarezz
jonalvarezz / zip.js
Created October 27, 2016 20:20
ES6 Array Zip
function zip () {
const args = Array.prototype.slice.call(arguments)
const combinerFunction = args.pop()
const results = []
const min = Math.min(...args.map(a => a.length))
for (let counter = 0; counter < min; counter++) {
let values = args.map(o => o[counter])
results.push(combinerFunction(...values))
}
@jonalvarezz
jonalvarezz / README.md
Created September 27, 2016 12:07 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@jonalvarezz
jonalvarezz / proceses.md
Created September 19, 2016 15:19
Search and destroying idle processes

Search by process name

ps -ef | grep node

Search by port and destroy

lsof -t -i tcp:8080 | xargs kill -9
@jonalvarezz
jonalvarezz / brew-launch.md
Created August 1, 2016 22:30
Launch HomeBrew Background Services

I dont like services running in background by default when I'm not using them. I prefer run only when needed.

Those are some commands to run these services so I dont forget them:

Postgres

postgres -D /usr/local/var/postgres

MongoDB

@jonalvarezz
jonalvarezz / eslint-pre-commit.md
Last active October 11, 2017 13:46
Run ESLint with JS/JSX in Git pre-commit hook

Run ESLint with JS/JSX in Git pre-commit hook

Get rid off Syntax fix commits enabling your linter everytime a git commit try to be done.

This example features local eslint with js and jsx validation

Enable this hook creating or modifying the file /your/project/path/.git/hooks/pre-commit

#!/bin/sh 
# Ensure all javascript files staged for commit pass standard code style 
ROOT_DIR=$(git rev-parse --show-toplevel)
@jonalvarezz
jonalvarezz / nginxredirection.md
Created July 22, 2016 16:28
Nginx Redirection

How to create NGINX redirection

This is a way, recommended way by Nginx when creation redirections. i.e. you want to redirect from www to non-ww

server {
  server_name www.mydomain.tld;
  return 301 $scheme://mydomain.tld$request_uri;
}

server {
@jonalvarezz
jonalvarezz / django-hotel.md
Created June 15, 2016 18:22
Run Django project with hotel.dev

Run Django project with hotel.dev

This is how to run hotel command to get a Django application running with virtualenv. Once hotel is properly installed:

cd /you/django/project/
hotel add 'source /path/to/your/virtualenv/bin/activate && python manage.py runserver $PORT' -o hotel.log
@jonalvarezz
jonalvarezz / cookies.js
Created February 5, 2016 12:42
Get cookies JavaScript
/*
* Get Cookie
* Return cookie value by key
*
* @author Mozilla Foundation
* @url https://developer.mozilla.org/en-US/docs/Web/API/document/cookie
*
* @param {string} Cookie's name to lookup
* @return {string} Cookie's value
*/
@jonalvarezz
jonalvarezz / on-jsx.markdown
Created January 26, 2016 14:33 — forked from chantastic/on-jsx.markdown
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I lead the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can'