Skip to content

Instantly share code, notes, and snippets.

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

Josh joshlemer

🏠
Working from home
  • Winnipeg, Canada
View GitHub Profile
@joshlemer
joshlemer / Link.txt
Created June 27, 2024 20:48
Viola Case Link
destinations:
# each key here uniquely identifies a destination.
# Set its name, optionally set its latitude and longitude for automatic distance/traveltime/elevation gain generation
# include a list of amenity icons to be included
cvg:
name: "Central Valley Greenway"
bcit:
name: "BCIT"
latitude: 49.251691
longitude: -123.001931
(ns gen
(:require
[cloroutine.core :refer [cr]]
[criterium.core :as crit]))
(deftype ^:private GenIter [;; The Cloroutine generator function
^:unsynchronized-mutable ^clojure.lang.IFn g
;; Trilean boolean logic:
;; 0 = certainly no more elements, `x` is nil
;; 1 = certainly there are more elemennts, and the next object is stored in `x`
@joshlemer
joshlemer / csp.js
Last active October 16, 2020 19:03
// example 1: Channels
(async () => {
// make an unbuffered channel
const c = chan();
// in separate 'thread', push 3 values into it
(async () => {
send(c, 'ping');
@joshlemer
joshlemer / Bench.txt
Last active January 18, 2020 22:10
LHM benches
LEGEND:
* Suffixes: (Lhm = LinkedHashMap, Vm = VectorMap)
*
[info] Benchmark (size) Mode Cnt Score Error Units
[info] VectorMapBenchmark.buildLhm 5 avgt 20 399.458 ± 4.206 ns/op
[info] VectorMapBenchmark.buildLhm 10 avgt 20 764.065 ± 10.401 ns/op
@joshlemer
joshlemer / List.scala
Created January 4, 2020 16:31
List opt -- from vs prependedAll
// class List
override def prependedAll[B >: A](prefix: collection.IterableOnce[B]): List[B] = prefix match {
case xs: List[B] => xs ::: this
case _ =>
val iter = prefix.iterator
if (iter.hasNext) {
val result = new ::[B](iter.next(), null)
var curr = result
while (iter.hasNext) {
val temp = new ::[B](iter.next(), null)
@joshlemer
joshlemer / 2.13.x
Created January 1, 2020 21:36
List Optimization Benchmarks
[info] Benchmark (size) Mode Cnt Score Error Units
[info] ListBenchmark.colonColonColon 0 avgt 20 2.576 ± 0.154 ns/op
[info] ListBenchmark.colonColonColon:·gc.alloc.rate 0 avgt 20 0.001 ± 0.002 MB/sec
[info] ListBenchmark.colonColonColon:·gc.alloc.rate.norm 0 avgt 20 ≈ 10⁻⁵ B/op
[info] ListBenchmark.colonColonColon:·gc.count 0 avgt 20 ≈ 0 counts
[info] ListBenchmark.colonColonColon 1 avgt 20 15.884 ± 1.988 ns/op
[info] ListBenchmark.colonColonColon:·gc.alloc.rate 1 avgt 20 1622.694 ± 155.062 MB/sec
[info] ListBenchmark.colonColonColon:·gc.alloc.rate.norm 1 avgt 20 40.000 ± 0.001 B/op
[info] ListBenchmark.colonColonColon:·gc.churn.PS_Eden_S
@joshlemer
joshlemer / UnsafeWrap.scala
Created November 26, 2019 04:17
unsafewrap
package com.github.joshlemer
import scala.collection.Factory
import scala.collection.immutable._
package object clxn {
implicit final class IterableObjectExtension(private val c: Iterable.type) extends AnyVal {
def unsafeWrap[A](it: collection.Iterable[A]): Iterable[A] = it match {
case xs: Iterable[A] => xs
calculateFast(file: File, size: Int, hashes: Iterator[ByteString], bitfield: BitVector) = {
// zipping iterators together will mean that each element will allocate an additional instance of `Tuple2[Left, Right]`
// you could get by with iterating through `file.bytes.grouped(size)` and `hashes` at the same time, avoiding
// tuple allocations
val iter = file.bytes.grouped(size).zip(hashes)
val digest: MessageDigest = MessageDigest.getInstance("SHA-1")
val buf = new Array[Byte](size)
var bufIdx = 0