Skip to content

Instantly share code, notes, and snippets.

View channingwalton's full-sized avatar
🏠
Working from home

Channing Walton channingwalton

🏠
Working from home
View GitHub Profile
@channingwalton
channingwalton / buckets.scala
Last active May 25, 2023 08:25
Randomly distribute N items across M buckets
package example
import scala.util.Random
object Hello extends App {
val items = (0 to 10).toList.map(i => s"Item $i")
val numberOfBuckets = 10
val working: Map[String, Double] = items.map(i => (i, Random.nextDouble())).toMap
val bucketSize = 1.0 / numberOfBuckets
@channingwalton
channingwalton / tempus-dominus.html
Last active December 30, 2022 11:04
Simple tempus dominus example
<!doctype html>
<html lang="en">
<head>
<!-- Popperjs -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha256-BRqBN7dYgABqtY9Hd4ynE+1slnEw+roEPFzQ7TRRfcg=" crossorigin="anonymous"></script>
<!-- Tempus Dominus JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.2.10/dist/js/tempus-dominus.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.2.10/dist/css/tempus-dominus.min.css" crossorigin="anonymous">
@channingwalton
channingwalton / build.sbt
Last active May 11, 2022 08:05
Scala 2.13 compiler flags
val scalacOptions ++= Seq(
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
@channingwalton
channingwalton / StateMonad.scala
Created May 31, 2012 21:28
State Monad and Validation with Scalaz
import scalaz._
import Scalaz._
/**
* Use the state monad to 'process a trade' and store the new trade.
* As well as processing the trade, handle validation errors.
*/
object StateMonad extends App {
case class Trade(info: String)
@channingwalton
channingwalton / NonEmptySet.scala
Last active March 24, 2018 16:48
NonEmptySet Implementation
import cats.data.NonEmptyList
import cats.Eq
import scala.collection.GenTraversableOnce
sealed trait NonEmptySet[T] extends (T => Boolean) {
def head: T
def set: Set[T]
def +(t: T): NonEmptySet[T]
def ++(ts: NonEmptySet[T]): NonEmptySet[T]
@channingwalton
channingwalton / AutomountMaverick.md
Last active September 20, 2017 22:11
Automounting in OSX Maverick

What Changed

I used to automount on OSX by sudo vifs and adding a line like vault.local:/backup /Volumes/backup url auto,url==afp://;AUTH=No%20User%20Authent@vault.local/backup 0 0. But that no longer works on Maverick because the system deletes everything in /Volumes on wake/restart/something-or-other.

We are going to create a mount at /mnt/Resources. We need to edit the auto_master to tell it where the automount config for /mnt/Resources lives:

sudo vi /etc/auto_master

Now add this line at the top

Keybase proof

I hereby claim:

  • I am channingwalton on github.
  • I am channingwalton (https://keybase.io/channingwalton) on keybase.
  • I have a public key ASAzN6zGSraBz_wTqUhbQLqzT4wmAjuy3zGojAOeYGo2Uwo

To claim this, I am signing this object:

@channingwalton
channingwalton / SetPerformance.scala
Created April 29, 2017 09:26
Benchmark for performance of .toSet
package set.performance
import java.util.concurrent.TimeUnit
import scala.concurrent.duration.FiniteDuration
/**
* On my machine the fast method takes < 2 ms, the slow one 2.2s
*/
object SetPerformance {
@channingwalton
channingwalton / Console.scala
Last active October 30, 2016 22:21
Alternatives to GADTs in Scala
// No case classes
object Consoles {
trait ConsoleAlg[F[_]] {
def readLine: F[Option[String]]
def printLine(line: String): F[Unit]
}
trait Console[+A] {