Skip to content

Instantly share code, notes, and snippets.

View aaronlevin's full-sized avatar

Aaron Levin aaronlevin

View GitHub Profile
@aaronlevin
aaronlevin / typeclass-coproduct.scala
Last active November 29, 2020 19:11
Writing a typeclass in Scala that crawls a shapelss Coproduct and returns a new Coproduct
/**
* Let's write a typeclass for a coproduct. The idea is we're given the name of a string, and we need to:
*
* 1. check that the string matches a value
* 2. if the string matches a value, convert that string into some type and return it
* 3. If the string doesn't match that value, try another alternative.
* 4. If no alternatives match the value, return an error.
*
* The usecase is based on something I encountered in real life: we have to parse different kind of events in
* my work's data pipeline, and the type of event (and subsequent parsing) depends on an "event type" string. I
@aaronlevin
aaronlevin / shapeless-arb-keys.scala
Last active May 13, 2016 08:46
Use Structured Keys in Shapeless Records
/**
* Working with shapeless' records is great. However, you are limited to using only String, Integer, Boolean, and
* (package) Objects as singleton keys as the singleton machinery requires a stable point (I don't really fully
* understand this part but I have an intuition). I had asked if there was a way to use a tuple or case-class
* as a key in the shapeless gitter channel and no one really knew.
*
* I was reading the shapeless source for the Witness type and an idea came to mind: since we can use a package Object
* as a key, what if that key extends a trait (an abstract class can work as well)? Can we use those objects as
* singleton keys and access the values specified in the trait?
*
@aaronlevin
aaronlevin / config.nix
Created April 21, 2016 10:49
Use Nix to build vim with +python support + custom python libraries
# I wanted to use ensime with vim, which requires vim + python + some python packages (websocket_client + sexpdata)
# unfortunately, nix would build vim with a python that didn't have access to my system libraries (for referential transperancy)
# so I needed to provide to `vim_configurable.nix` the right python to use *and* enable python, lua, etc. support.
# I also wanted to keep my `.vimrc` separate because some of the vim packages I use weren't available.
#
# install via: `nix-env -f '<nixpkgs>' -iA myCoolVim` or `nix-env -I nixpkgs=/path/to/your/nixpkgs -f '<nixpkgs>' -iA myCoolVim`
#
# out put of `vim --version` below.
{
@aaronlevin
aaronlevin / configuration.nix
Created February 8, 2016 10:46
My Nix configuration for my Lenovo X250
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
@aaronlevin
aaronlevin / hlist-set-inclusion-issues.hs
Created January 27, 2016 10:20
A file to demonstrate set-inclusion constraint issues in Haskell.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module HList where
@aaronlevin
aaronlevin / vfm-03.hs
Last active January 3, 2016 05:39
Effect Stacks in the van Laarhoven Free Monad
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
@aaronlevin
aaronlevin / vfm.hs
Last active January 2, 2016 23:12
Tagged Effect Stack in the van Laarhoven Free Monad
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
@aaronlevin
aaronlevin / dump.sh
Last active December 19, 2015 00:16
Pure bash MySQL Dump --> S3
#!/usr/bin/env bash
# modified from: http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
readonly db_host="xxxx"
readonly db_user="xxxx"
readonly db_pass='xxxx'
readonly db_db="xxx"
readonly aws_key="xxxx"
readonly aws_secret="xxxxx"

Keybase proof

I hereby claim:

  • I am aaronlevin on github.
  • I am aaronlevin (https://keybase.io/aaronlevin) on keybase.
  • I have a public key whose fingerprint is 5589 E5EA F9E3 5955 A53D 0714 3ADD FECC C5D5 CD5E

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am aaronlevin on github.
  • I am aaronlevin (https://keybase.io/aaronlevin) on keybase.
  • I have a public key whose fingerprint is 3900 0396 924C 9990 4912 94D3 FDD0 B4E9 9845 2EE5

To claim this, I am signing this object: