Skip to content

Instantly share code, notes, and snippets.

View joaofnds's full-sized avatar

João Fernandes joaofnds

View GitHub Profile
@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
@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"
{"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 / 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);
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
// 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 {
@joaofnds
joaofnds / Dockerfile
Created July 16, 2018 14:01
multi-stage rails build based on ruby:alpine
FROM joaofnds/rails-alpine as builder
RUN mkdir /app
WORKDIR /app
COPY Gemfile Gemfile.lock /app/
RUN bundle install
FROM joaofnds/rails-alpine
RUN mkdir /app
WORKDIR /app
COPY --from=builder /usr/local/bundle/ /usr/local/bundle/
@joaofnds
joaofnds / Dockerfile
Last active July 16, 2018 14:01
Dockerfile for joaofnds/rails-alpine
FROM ruby:alpine
# Minimal requirements to run a Rails app
RUN apk add --no-cache --update build-base \
linux-headers \
git \
postgresql-dev \
tzdata \
nodejs
@joaofnds
joaofnds / sql-describe.go
Last active January 3, 2018 09:30
Performs a SQL "DESCRIBE database;" command in go using the database/sql and go-sql-driver/mysql packages
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
#include <cmath>
#include <iostream>
#include <queue>
#include <iomanip>
using namespace std;
typedef pair<int, int> coords;
inline double vector__length(coords pos) {