Skip to content

Instantly share code, notes, and snippets.

View joshuakfarrar's full-sized avatar
💻
EitherT[IO, Throwable, Human]

Joshua K. Farrar joshuakfarrar

💻
EitherT[IO, Throwable, Human]
View GitHub Profile
state change_funding change_tuition net_hike unaccountable_hike
Colorado -510 4425 4935 3915
California 250 3983 3733 3733
Virginia -1218 4587 5805 3369
New Hampshire -1342 4686 6028 3344
Hawaii 1532 4716 3184 3184
Vermont -755 3711 4466 2956
Rhode Island -881 3756 4637 2875
Oregon -693 3334 4027 2641
Massachusetts -1117 3524 4641 2407
@joshuakfarrar
joshuakfarrar / compress.scala
Last active March 2, 2022 20:08
another code golf-type interview question
// compress a string by counting its repeating characters
def compress(a: String): String = a.foldLeft("") { (acc, l) =>
acc.lastOption match {
case Some(c) =>
if (c == l) => {
acc.slice(acc.lastIndexOf(l) - 1, acc.lastIndexOf(l)).headOption match {
case Some(d) => c match {
case l => if (Character.isDigit(d)) {
s"${acc.slice(0, acc.lastIndexOf(l) - 1)}${Character.digit(d, 10) + 1}" :+ l // add 1 to repeating characters we have seen
} else {
@joshuakfarrar
joshuakfarrar / Deck.scala
Created January 20, 2022 18:15
using the StateT Monad, we are able to interleave IO into our recursive simulation of State transitions
import scala.util.Random
import cats.data.State
object Deck {
sealed trait Rank
case object Two extends Rank
case object Three extends Rank
case object Four extends Rank
case object Five extends Rank
@joshuakfarrar
joshuakfarrar / form.php
Last active March 15, 2022 09:30
para vladimiro.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection

Ennis and Jack, the dogs, the horses and mules, a thousand ewes and their lambs flowed up the trail like dirty water through the timber and out above the tree line into the great flowery meadows and the coursing, endless wind.

@joshuakfarrar
joshuakfarrar / winkey-face.py
Last active March 15, 2022 09:30
para abril, on encoding
import functools
# our goal is to use the format feature of strings to render an array of integers, our encoded message, as a string
## remember character encodings?
# let's load up a fake one
# not a real one, not ascii; a fakeskii
encoding_file = open('zyx-fakeskii', 'r')
# nnfs.io
import numpy as np
# a single array of inputs, for a layer of 3 neurons
inputs = [1, 2, 3, 2.5]
weights = [[0.2, 0.8, -0.5, 1], [0.5, -0.91, 0.26, -0.5], [-0.26, -0.27, 0.17, 0.87]] # 3 neurons
biases = [2, 3, 0.5] # and their bias
const http = require('./http');
const API_URL = 'http://localhost:3001';
const API_CURRENT_VERSION = 'v0';
const CURRENT_API_URL = `${API_URL}/api/${API_CURRENT_VERSION}`;
const API = {
entities: {
all: () => http.get({
url: `${CURRENT_API_URL}/entities`
// three ways of expressing registration and sending confirmation e-mail in scala
(R.register _)
.andThen(_
.map(C.withConfirmable)
.map(_ >>= { confirmable => OptionT.liftF(C.sendConfirmationInstructions(confirmable)) })
)
.andThen(_ >>= { _ => Ok() })
.apply(form)
@joshuakfarrar
joshuakfarrar / getConfirmableFromToken.scala
Last active February 19, 2021 19:04
use monad transformers for great elegance!
import cats.data.OptionT
import cats.implicits._
/*
* in my domain, the confirmation algebra provides Confirmable,
* which is parameterized over the type of id of the thing, probably
* a user, to be confirmed, and the type of the confirmation token
*/
type C = Confirmable[UUID, SecureRandomId]