Skip to content

Instantly share code, notes, and snippets.

View joaoneto's full-sized avatar

João Neto joaoneto

View GitHub Profile
@joaoneto
joaoneto / formDataToObject.js
Last active January 10, 2021 23:01
Transform formData from a form element into Object literal.
/**
* `objFromFlatKeys` Convert the template string into a tree path and set the value into the referenced object path.
*
* @param {string} strPath - template string path to convert in nested object tree
* @param {Object} prevobj - reference for the nested object result
* @param {*} value - value to set at the end of the nested object tree
*
* @example
* // define the target object
* const obj = {};
@joaoneto
joaoneto / async-serial.js
Last active June 11, 2020 03:38
Javascript example of asynchronous and serial processing flow in async/await reduce function
const mockAsyncProcess = (objToProcess) => {
console.time(objToProcess.id)
console.log(`BEGIN: ${objToProcess.id}`)
return new Promise((resolve) => {
setTimeout(() => {
resolve(`RESULT -> ${objToProcess.id}`);
console.timeEnd(objToProcess.id)
console.log(`END: ${objToProcess.id}`)
}, Math.random() * 1000)
})
#!/usr/bin/env bash
mkdir -p ./app
echo '{
"name": "my-project",
"version": "0.0.0",
"scripts": {
"dev": "webpack-recipes devserver 9000",
"build": "webpack-recipes build --mode=production"
},
"devDependencies": {
(function() {
'use strict';
var dynamicStates = function ($stateProvider, $urlRouterProvider) {
var addRoute = function (name, definition) {
$stateProvider.state(name, definition);
};
$urlRouterProvider.deferIntercept();
{
"state-one": {
"controller": "stateOneController",
"template": "<h1>State One</h1>"
},
"state-two": {
"controller": "stateTwoController",
"template": "<h1>State Two</h1>"
}
}
(function () {
var _eventsStack = {};
window.Events = {
emit: function (eventName, message) {
if (!_eventsStack.hasOwnProperty(eventName)) {
_eventsStack[eventName] = [];
}
_eventsStack[eventName].forEach(function (fn) {
fn(message != undefined ? message : {});
});
@joaoneto
joaoneto / README.md
Last active May 23, 2016 21:12
Improve your curl with pretty formmated json responses

Improve your curl with pretty formmated json responses

requirements node.js

add in your .zshrc

[[ -s $HOME/bin/prettycurl.sh ]] && . $HOME/bin/prettycurl.sh
const React = require('react');
const ReactAtellier = require('react-atellier')(React);
class AtellierWrapper extends React.Component {
static propTypes = { message: React.PropTypes.string };
static defaultProps = { message: 'Hello World!' };
render() {
const Icon = React.createClass({
render: function() {
return (
@joaoneto
joaoneto / ATOM_PACKAGES.md
Last active January 18, 2016 17:32
Util Atom packages

Atom Packages

apm instal \
aligner \
atom-beautify \
autoclose-html \
autocomplete-paths \
color-picker \
editorconfig \
file-icons \
@joaoneto
joaoneto / start_redis_and_couchdb.sh
Created September 3, 2015 23:44
Start Redis and CouchDB from Docker container
#!/bin/bash
docker-machine start default 1> /dev/null
eval "$(docker-machine env default)"
RUNNING=$(docker inspect --format="{{ .State.Running }}" redis 2> /dev/null)
if [ $? = 1 ]; then
echo "Container redis doesn\'t exists"
docker run -d -p 6379:6379 -v `pwd`/data/redis:/data --name redis redis
fi