Skip to content

Instantly share code, notes, and snippets.

View steshaw's full-sized avatar
👨‍💻
Loves programming languages

Steven Shaw steshaw

👨‍💻
Loves programming languages
View GitHub Profile
@steshaw
steshaw / fpmax.scala
Created September 26, 2023 06:05 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@steshaw
steshaw / .00readme.org
Created May 22, 2020 06:45 — forked from mbbx6spp/.00readme.org
A caching and persistent Nix shell with direnv

Cached and Persistent Nix shell with direnv integration

Problem being solved

  • the default direnv Nix integration from projects loads a Nix shell every new terminal or every time shell.nix and/or default.nix changes. On larger projects with a lot of Nix shell dependencies, that can cause the terminal to take more than 6 seconds to load, which significantly degrades the developer experience (DX).
  • when a developer garbage collects in their Nix store, often the Nix shell dependencies are deleted also which causes a slow start the next time the project’s Nix shell is requested, also degrading developer experience (DX).

Solution outline

  • on first Nix shell load, the Nix shell is evaluated fully such that direnv dumps the environment from the spawn Nix shell process
@steshaw
steshaw / nixpkgs-find-good-commit
Last active December 4, 2019 13:44 — forked from simonmichael/a.bash
scripts for finding available versions in nixpkgs
#!/usr/bin/env bash
set -euo pipefail
#
# Some nixpkgs query scripts inspired by #nixos chat.
# Goal: find the HASH that will let an install command like:
# nix-env -i -f https://github.com/NixOS/nixpkgs/archive/HASH.tar.gz -A hledger hledger-web hledger-ui
# install the latest available build of the packages, on all platforms of interest.
# These scripts don't seem to quite do that but they help.
# Usage:
#
# Find version:
#
# $ nix-instantiate --eval --expr '(import ./pkg-versions.nix {}).pandoc'
# { "1.13.1" = <CODE>; "1.16.0.2" = <CODE>; "1.17.1" = <CODE>; "1.19.2.1" = <CODE>; "1.19.2.4" = <CODE>; "2.0.6" = <CODE>; "2.2.1" = <CODE>; "2.7.1" = <CODE>; }
# $ nix eval '(builtins.attrNames (import ./pkg-versions.nix {}).pandoc)'
# [ "1.13.1" "1.16.0.2" "1.17.1" "1.19.2.1" "1.19.2.4" "2.0.6" "2.2.1" "2.7.1" ]
# $ nix-instantiate --eval --expr 'builtins.attrNames (import ./pkg-versions.nix {}).pandoc'
# [ "1.13.1" "1.16.0.2" "1.17.1" "1.19.2.1" "1.19.2.4" "2.0.6" "2.2.1" "2.7.1" ]
@steshaw
steshaw / ghc-api-executable.hs
Last active August 25, 2019 07:03 — forked from mpickering/gist:e13f343f2b35b51693d15582180b1c02
Simple GHC API executable
module Main where
import Lib
import GHC as G
import GhcMake as G
import DynFlags
import SrcLoc as G
import GHC.Paths
import Control.Monad
@steshaw
steshaw / zio-test.scala
Last active July 5, 2019 22:10 — forked from jdegoes/zio-test.scala
Simple example of testing with ZIO environment
object test {
import scalaz.zio._
type UserID = String
case class UserProfile(name: String)
// The database module:
trait Database {
val database: Database.Service
}
@steshaw
steshaw / .gitignore
Created August 6, 2017 08:39 — forked from robertpenner/employee_salaries.ts
Employee Average Salaries | Victor Savkin's Functional TypeScript
/*.js
object ScalaJSExample extends js.JSApp{
def main() = {
val xs = Seq(1, 2, 3)
println(xs.toString)
val ys = Seq(4, 5, 6)
println(ys.toString)
val zs = for{
x <- xs
y <- ys
} yield x * y
class Hash
def safe_invert
lazy
.map {|a, b| [b, a]}
.group_by {|a| a[0]}
.map {|a, b| [a, b.collect {|c| c[1]}]}
.to_h
end
end
;;
;; MobileOrg on iPad using Dropbox
;;
;; Settings basically copied from the screen cast, they differ
;; on the `org-mobile-inbox-for-pull` var wrt. the instructions
;; on the website.
;; - If MobileOrg is already linked to Dropbox. Unlink and delete
;; the ~/Dropbox/MobileOrg folder.