Skip to content

Instantly share code, notes, and snippets.

Thiago Andrade thiagoh

Block or report user

Report or block thiagoh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View thiagoh.zsh-theme
# This file should be at this path
# ~/.oh-my-zsh/themes/thiagoh.zsh-theme
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status}%{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
PROMPT='%{$fg[green]%}%n ${ret_status}%{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
@thiagoh
thiagoh / ExternalizedPromise.ts
Created May 27, 2019
resolve/reject a promise from outside its scope
View ExternalizedPromise.ts
export interface ExternalizedPromise<T> {
promise: Promise<T>;
resolve: (value?: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
}
export default {
create: function create<T>(
executor: (resolve: (value?: T | PromiseLike<T>) => void, rejector: (reason?: any) => void) => void
@thiagoh
thiagoh / $.js
Last active Apr 21, 2019
lite DOM manipulator
View $.js
'use strict';
function $(el) {
function $Element() {
const self = this;
this.$is$ = function $is$() {
return true;
};
this.style = function style(key, value) {
if (/(left|right|top|bottom|background-position-x|background-position-y)/i.test(key)) {
@thiagoh
thiagoh / promise-error-handling.js
Last active Sep 14, 2018
Promise Error Handling
View promise-error-handling.js
## How to run
#
# npm run main /invalid
#
const get = url => {
if (url.indexOf('/invalid') >= 0) {
return Promise.reject({
url,
error: 'error message',
@thiagoh
thiagoh / riverdb
Last active Jun 10, 2018
RiverDB the simplest and smallest db of all
View riverdb
#!/bin/bash
cmd=$1
key=$2
value=$3
file=db.data
if [[ "$cmd" = "" ]]; then
echo "Invalid command";
exit 1;
@thiagoh
thiagoh / mapReduce.js
Last active Jun 8, 2018
Map Reduce in JavaScript
View mapReduce.js
Array.prototype.mapReduce = function(keyGrouper, reducer) {
const emit = (key, value) => ({key, value});
const obj = this
.map(value => keyGrouper(emit, value))
.reduce((prev, {key, value}) => {
prev[key] = Array.isArray(prev[key]) ? prev[key] : [];
return prev[key].push(value) && prev;
}, {});
return Object.keys(obj).map(key => reducer(key, obj[key]));
};
@thiagoh
thiagoh / prova.md
Last active Apr 17, 2018
Xn * F = Yn -> Regra geral da revolta popular contra mal feitor
View prova.md

Provarei matematicamente o que esta acontecendo e por que eh legitimo que a revolta popular seja maior contra Lula que contra Aecio.

Temos a regra geral:

Xn * F = Yn

Xn = mal causado por alguem (n)
Yn = revolta popular contra alguem (n)
l  = Lula dataset
@thiagoh
thiagoh / moment-update-week-dow-day.js
Created Mar 4, 2018
Updating first week DOW and DAY in moment.js Raw
View moment-update-week-dow-day.js
const moment = require('moment');
const createDates = () => {
return [
moment({ year: 2015, month: 11, day: 25 }),
moment({ year: 2015, month: 11, day: 26 }),
moment({ year: 2015, month: 11, day: 27 }),
moment({ year: 2015, month: 11, day: 28 }),
moment({ year: 2015, month: 11, day: 29 }),
moment({ year: 2015, month: 11, day: 30 }),
@thiagoh
thiagoh / cloudSettings
Last active Sep 16, 2019
typescript / javascript version of Optional
View cloudSettings
{"lastUpload":"2019-09-16T21:00:42.809Z","extensionVersion":"v3.4.2"}
@thiagoh
thiagoh / actions.js
Last active Feb 3, 2018
redux asynchronous actions dispatching one after the other
View actions.js
// oneAction could be setCountry
export const oneAction = params => {
return {
type: "ONE_ACTION",
payload: Promise.resolve(`(value from oneAction ${params})`)
};
};
// otherAction could be fetchRegions
export const otherAction = params => {
You can’t perform that action at this time.