Skip to content

Instantly share code, notes, and snippets.

View joaofnds's full-sized avatar

João Fernandes joaofnds

View GitHub Profile
@joaofnds
joaofnds / reduce-map-filter.js
Last active March 5, 2021 16:40
reduce, map and filter one-liners. Just because.
const reduce = reducer => memo => ([first, ...rest]) =>
first ? reduce(reducer)(reducer(first)(memo))(rest) : memo
const map = f => arr =>
reduce(mapReducer(f))([])(arr)
const filter = f => arr =>
reduce(filterReducer(f))([])(arr)
const mapReducer = f => element => memo =>
@joaofnds
joaofnds / dump_request.go
Created February 2, 2020 22:36
A simple server that responds with the raw HTTP request
package main
import (
"context"
"log"
"net/http"
"net/http/httputil"
"os"
"os/signal"
"syscall"
This file has been truncated, but you can view the full file.
1588419345.803051 server started (54961): version 3.1a, socket /private/tmp/tmux-501/test, protocol 8
1588419345.803079 on Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64; libevent 2.1.10-stable (select)
1588419345.803193 yylex_token: bind
1588419345.803206 yylex_token: -N
1588419345.803213 yylex_token: Send the prefix key
1588419345.803218 yylex_token: C-b
1588419345.803223 yylex_token: send-prefix
1588419345.803239 cmd_parse_build_commands: 0 bind
1588419345.803246 cmd_parse_build_commands: argv[0]=-N
1588419345.803251 cmd_parse_build_commands: argv[1]=Send the prefix key

Introduction

Ruby on Rails is the framework of choice for web apps at Shopify. It is an opinionated stack for quick and easy development of apps that need standard persistence with relational databases, an HTTP server, and HTML views.

By design, Rails does not define conventions for structuring business logic and domain-specific code, leaving developers to define their own architecture and best practices for a sustainable codebase.

@joaofnds
joaofnds / frequency_ditribution.clj
Last active March 30, 2021 11:43
babashka script to generate a frequency distribution table
(ns script
(:require [clojure.pprint :as pprint]))
(def sequence (sort (map #(Float/parseFloat %) *command-line-args*)))
(def n (count sequence))
(def k (int (Math/ceil (Math/sqrt n))))
(def es (apply min sequence))
(def ei (apply max sequence))
(def i (/ (- ei es) k))
(def classes (map #(+ es (* i %)) (range k)))
<html>
<head>
<script src="https://unpkg.com/keycloak-js@14.0.0/dist/keycloak.js"></script>
</head>
<body>
<div>
<button onclick="keycloak.login()">Login</button>
<button onclick="keycloak.login({ action: 'UPDATE_PASSWORD' })">Update Password</button>
<button onclick="keycloak.logout()">Logout</button>