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/[email protected]/dist/umd/popper.min.js" integrity="sha256-BRqBN7dYgABqtY9Hd4ynE+1slnEw+roEPFzQ7TRRfcg=" crossorigin="anonymous"></script>
<!-- Tempus Dominus JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/[email protected]/dist/js/tempus-dominus.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@eonasdan/[email protected]/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 / 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]

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 / keybase.md
Last active July 31, 2016 21:00
Verification for keybase

Keybase proof

I hereby claim:

  • I am channingwalton on github.
  • I am channingwalton (https://keybase.io/channingwalton) on keybase.
  • I have a public key ASD_xyZHdprhe-YpLLpvwqvgVW-wFGmVXHZ8fwXP_1soLwo

To claim this, I am signing this object:

@channingwalton
channingwalton / test.html
Created April 29, 2016 21:10
positive numbers only
<SCRIPT language=Javascript>
<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
return charCode > 47 && charCode < 58;
}
//-->
</SCRIPT>
</HEAD>
@channingwalton
channingwalton / RxConcurrency.scala
Created April 28, 2016 08:16
Some concurrency testing for Rx
package reactive
import java.util.concurrent.TimeUnit
import rx.lang.scala.{Observable, Subject}
import scala.concurrent.duration.Duration
/**
* The problem: can two threads banging away from two sources be merged and have predictable results?