Skip to content

Instantly share code, notes, and snippets.

View joaofnds's full-sized avatar

João Fernandes joaofnds

View GitHub Profile
// http://www.newthinktank.com/2012/11/visitor-design-pattern-tutorial/
// https://www.youtube.com/watch?v=pL4mOUDi54o
interface Visitor {
visitLiquor(liquorItem: Liquor): number;
visitTobacco(tobaccoItem: Tobacco): number;
visitNecessity(necessityItem: Necessity): number;
}
class TaxVisitor implements Visitor {
const newHornerSequence =
(...seq) =>
x =>
seq.slice(0, -1).reduce((acc, n) => (acc + n) * x, 0) + seq.pop();
console.log(newHornerSequence(4, 5, 6, 7, 8)(5)); // 3318
@joaofnds
joaofnds / riemman-sum.js
Created September 25, 2018 09:38
Functional Riemann Sums
const leftRiemannSum = (f, start, stop, inc) => {
if (start >= stop) return 0;
return f(start) * inc + leftRiemannSum(f, start + inc, stop, inc);
};
const middleRiemannSum = (f, start, stop, inc) => {
const middle = (start + inc) / 2;
if (start >= stop) return inc * f(middle);
{"dark":"1","docs":"apache_http_server/async/babel/bash/bootstrap~4/c/cpp/clojure~1.9/cmake~3.12/crystal/css/d3~5/dart~2/docker~17/dom/dom_events/electron/elixir~1.7/erlang~21/eslint/express/gcc~7/git/go/haskell~8/homebrew/html/http/javascript/jest/jsdoc/koa/kotlin/laravel~5.6/lodash~4/lua~5.3/markdown/moment/mongoose/nginx/nginx_lua_module/node/nokogiri/npm/numpy~1.14/pandas~0.22/perl~5.26/phoenix/php/postgresql~10/pug/puppeteer/python~3.7/qt~5.11/ramda/react/react_native/redis/redux/relay/requirejs/rethinkdb~javascript/rethinkdb~ruby/ruby~2.5/minitest/rails~5.2/rust/sass/socketio/sqlite/svg/terraform/typescript/vue~2/webpack/yarn"}
@joaofnds
joaofnds / boostnote-export.js
Last active October 13, 2018 01:42
Boostnote export
const fs = require("fs");
const path = require("path");
const cson = require("cson");
const { folders } = require("./boostnote.json");
const DIRECTORIES = {
IMPORT: "notes",
EXPORT: "export",
NOTES: "notes",
SNIPPETS: "snippets"
@joaofnds
joaofnds / spinner.go
Last active October 23, 2018 00:33
Heroku-like spinner
package main
import (
"fmt"
"time"
)
type spinner struct {
chars []string
current int
-- Drop while matches Char
dropInitialMatches :: Char -> String -> String
dropInitialMatches c xs = dropWhile (==c) xs
-- Drop preceding spaces
dropInitialSpaces :: String -> String
dropInitialSpaces xs = dropInitialMatches ' ' xs
-- Drop preceding linefeeds
dropInitialNewLines :: String -> String
@joaofnds
joaofnds / helpers.js
Last active November 17, 2018 20:22
Simple js helpers (range, log, logFunc)
const fib =
n =>
n < 2
? 1
: fib(n - 1) + fib(n - 2)
const range =
(min, max) =>
Array(max - min + 1).fill().map((_, i) => i + min)
@joaofnds
joaofnds / bookmark-duplicate-finder.html
Last active August 28, 2019 12:55
Small tool that helps to find out duplicates in a bookmark export file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
)