Skip to content

Instantly share code, notes, and snippets.

@thiagoh
thiagoh / disk-utility
Last active August 23, 2017 14:01 — forked from dixson3/workspace.sh
Create and manage a case-sensitive disk-image on OSX. This is great when you have a need to work with case-sensitive repos on a mac.
#!/bin/bash
# where to store the sparse-image
WORKSPACE=~/Documents/workspace.dmg.sparseimage
create() {
if [ -f $WORKSPACE ]; then
echo "File ${WORKSPACE} already exists";
exit 1;
@thiagoh
thiagoh / tmux-cheatsheet.markdown
Created August 19, 2017 14:32 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StreamFlatMap {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
class MyClass {
static [Symbol.hasInstance](lho) {
console.log('with-sugar: is', lho, 'an array?');
return Array.isArray(lho);
}
}
console.log([] instanceof MyClass); // true
console.log('my string' instanceof MyClass); // false
@thiagoh
thiagoh / monads.js
Last active January 13, 2018 00:32
monad in practice
const PersonMonad = person => {
const ValidMon = failList => {
return {
map: ({ f, error }) => {
if (!f(person)) {
failList.push(error);
}
return ValidMon(failList);
},
flatMap: ({ f, error }) => {
@thiagoh
thiagoh / actions.js
Last active February 3, 2018 00:45
redux asynchronous actions dispatching one after the other
// 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 => {
@thiagoh
thiagoh / moment-update-week-dow-day.js
Created March 4, 2018 01:30
Updating first week DOW and DAY in moment.js Raw
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 / 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
@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 / 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;