Skip to content

Instantly share code, notes, and snippets.

@thiagoh
thiagoh / watchfiles.md
Last active June 8, 2023 15:56
watchfiles: Watch multiple files and execute bash commands as file changes occur

watchfiles

  • author: Thiago Andrade thiagoh@gmail.com
  • license: GPLv3
  • description:
  • watches the given paths for changes
  • and executes a given command when changes occur
  • usage:
  • watchfiles <paths...>
@thiagoh
thiagoh / History|-1063032c|entries.json
Last active February 9, 2023 18:58
typescript / javascript version of Optional
{"version":1,"resource":"file:///Volumes/workspace/personal/javascript/taggr/.babelrc","entries":[{"id":"sTz0","timestamp":1667160602415}]}
@thiagoh
thiagoh / karabiner.json
Created September 11, 2020 17:48
Karabiner json file for mechanical keyboard on Macos
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
# 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 18:49
resolve/reject a promise from outside its scope
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 April 21, 2019 17:02
lite DOM manipulator
'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 September 14, 2018 04:25
Promise Error Handling
## 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 June 10, 2018 03:23
RiverDB the simplest and smallest db of all
#!/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 June 8, 2018 17:40
Map Reduce in JavaScript
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 April 17, 2018 22:32
Xn * F = Yn -> Regra geral da revolta popular contra mal feitor

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