Skip to content

Instantly share code, notes, and snippets.

View juliobetta's full-sized avatar
🎧

Julio Betta juliobetta

🎧
View GitHub Profile
@juliobetta
juliobetta / maybe.py
Last active June 22, 2022 19:02
Maybe Monad in Python (naive approach)
from abc import ABC
from typing import Callable, TypeVar, Generic
T = TypeVar('T')
class Maybe(Generic[T], ABC):
def __init__(self, value: T | None):
self.value = value
const hasDebutAfter1980 = character => character.debut > 1980;
const withFind = characters.find(hasDebutAfter1980);
const withReduce = characters.reduce((accumulator, character) => {
if(hasDebutAfter1980(character) && !accumulator) {
return character;
}
return accumulator;
const mapped = characters.map(character => character.name);
const reduced = characters.reduce((accumulator, character) => [...accumulator, character.name], []);
// [
// "Donkey Kong",
// "Captain Falcon",
// "Fox",
// "Kirby",
// "Link"
const filtered = characters.filter(character => character.debut < 1990);
const reduced = characters.reduce((accumulator, character) => {
if(character.debut < 1990) {
return [...accumulator, character];
}
return accumulator;
}, []);
@juliobetta
juliobetta / gist:59269eb8d48219db627315cfefd6f021
Created September 10, 2019 16:58
remove a file from history after added to .gitignore
git update-index --skip-worktree <filepath>
@juliobetta
juliobetta / couchdb.service
Last active July 3, 2018 20:48
Install CouchDB 2.0 Ubuntu 16.04
# /etc/systemd/system/couchdb.service
[Unit]
Description=Couchdb service
After=network.target
[Service]
Type=simple
User=couchdb
ExecStart=/opt/couchdb/bin/couchdb -o /dev/stdout -e /dev/stderr
@juliobetta
juliobetta / firestoreIterator.js
Last active May 24, 2018 13:44
Transform a Firebase.Firestore.QuerySnapshot into an iteratable
function fetchAll() {
return firebase.firestore().collection('objects').get().then(snapshot => (
{
[Symbol.iterator]: function iterator() {
const { docs } = snapshot;
return {
next() {
return {
done: docs.length === 0,
@juliobetta
juliobetta / firstDuplicate.js
Last active April 9, 2018 02:23
Find first duplicate in a string using RxJS
const str = `Mussum Ipsum, cacilds vidis litro abertis. Si u mundo tá muito paradis?
Toma um mé que o mundo vai girarzis! Viva Forevis aptent taciti sociosqu ad litora torquent.
Aenean aliquam molestie leo, vitae iaculis nisl.
Leite de capivaris, leite de mula manquis sem cabeça.
Posuere libero varius. Nullam a nisl ut ante blandit hendrerit. Aenean sit amet nisi.
Delegadis gente finis, bibendum egestas augue arcu ut est. Admodum accumsan disputationi eu sit.
Vide electram sadipscing et per. Sapien in monti palavris qui num significa nadis i pareci latim.
Interagi no mé, cursus quis, vehicula ac nisi. Manduma pindureta quium dia nois paga.
Mais vale um bebadis conhecidis, que um alcoolatra anonimis. Si num tem leite então bota uma pinga aí cumpadi!`;
@juliobetta
juliobetta / NoVNC_Paste.js
Created December 12, 2017 12:12 — forked from byjg/NoVNC_Paste.js
How to Paste code to NoVNC.
// This will open up a prompt for text to send to a console session on digital ocean
// Useful for long passwords
(function () {
window.sendString = function (str) {
f(str.split(""));
function f(t) {
var character = t.shift();
var i=[];
var code = character.charCodeAt();
var needs_shift = character.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);
@juliobetta
juliobetta / install_phantomjs.sh
Last active December 9, 2017 20:07
Install Phantom JS
#!/usr/bin/env bash
# This script install PhantomJS in your Debian/Ubuntu System
#
# This script must be run as root:
# sudo sh install_phantomjs.sh
#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1