Skip to content

Instantly share code, notes, and snippets.

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

Jason Longshore longshorej

🏠
Working from home
View GitHub Profile
@longshorej
longshorej / akka-streams-expand.scala
Created April 4, 2024 22:44
akka-streams only occasionally call an expensive function via expand
// suppose that isEnabled is expensive, so we want to call it only once, but otherwise reuse the results
// of the previous call. we can use Akka Streams expand operator to effectively repeat the previous
// value, and Source.tick to ensure we call only once per second
import akka.actor.ActorSystem
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.duration._
import java.util.concurrent.ThreadLocalRandom
@longshorej
longshorej / akka-streams-dedup.scala
Created July 12, 2023 19:40
Akka Streams Async Dedup
package dedup
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._
import scala.util.Try
import akka.NotUsed
import akka.stream.scaladsl.Flow
import scalacache.CacheConfig
import scalacache.modes.sync._
@longshorej
longshorej / spin.scala
Created June 10, 2022 21:05
scala spin
def spin(ms: Int): Unit = {
val start = System.nanoTime()
while ((System.nanoTime() - start) / 1000 / 1000 < ms) {}
}
Given a subproject adserver-graphql-api,
```bash
version=$(sbt adserver-graphql-api/version | tail -n 1 | cut -d " " -f2-)
```
@longshorej
longshorej / list.rs
Created January 24, 2019 00:37
Rust singly linked list
use std::mem;
pub enum ListNode<A> {
Cons(A, Box<ListNode<A>>),
Nil
}
/// A List is a singly-linked list that allows items to be
/// prepended.
///
iox-sss-stub-server_1_a008709cb937 | [ERROR] [11/19/2018 23:14:19.093] [replace_me-akka.actor.default-dispatcher-25] [akka://replace_me/user/client-connector-0/consumer-tailers%2Fiox-sss-stub-events%2Fac287be9-806e-4dd5-bf4e-11f3c87d0f81%3Ffinite%3Dtrue-0] null (akka.stream.alpakka.mqtt.streaming.impl.Consumer$ConsumeFailed$: null)
iox-sss-stub-server_1_a008709cb937 | [INFO] [11/19/2018 23:14:19.098] [replace_me-akka.actor.default-dispatcher-25] [akka://replace_me/user/client-connector-0/consumer-tailers%2Fiox-sss-stub-events%2Fac287be9-806e-4dd5-bf4e-11f3c87d0f81%3Ffinite%3Dtrue-0] Message [akka.stream.alpakka.mqtt.streaming.impl.Consumer$DupPublishReceivedFromRemote] without sender to Actor[akka://replace_me/user/client-connector-0/consumer-tailers%2Fiox-sss-stub-events%2Fac287be9-806e-4dd5-bf4e-11f3c87d0f81%3Ffinite%3Dtrue-0#1767349145] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://replace_me/user/client-connector-0/consumer-tailers%2Fiox-sss-stub-
@longshorej
longshorej / update-dyndns.sh
Last active July 9, 2018 00:35
Update Google Domains Dynamic DNS entry
#!/usr/bin/env bash
# Updates a Dynamic DNS entry hosted on Google Domains.
hostname="yourhost.example.com"
# These are specific to Google Domains, do not use account credentials / app passwords
# See the Google Domains dashboard.
username="yourusername"
password="yourpassword"
On Fri, Jun 26, 2015 at 10:18:27AM -0700, Alexander Morozov wrote:
There is no network section in spec now. We probably should have some.
For what it's worth, you can currently (48182db, 2015-07-07) just
use the host's network configuration with the following changes to the
stock config:
Add to mounts:
{

Keybase proof

I hereby claim:

  • I am longshorej on github.
  • I am longshorej (https://keybase.io/longshorej) on keybase.
  • I have a public key whose fingerprint is E60A 56D7 33A7 953E F36B A1E4 6B8F 4073 7C55 1D66

To claim this, I am signing this object:

@longshorej
longshorej / pretty-print.scala
Created October 28, 2016 18:34 — forked from carymrobbins/pretty-print.scala
Pretty print Scala case classes and other data structures.
import com.typesafe.scalalogging.LazyLogging
object toPrettyString extends LazyLogging {
def apply(a: Any): String = {
try {
/* pretty printing uses reflection which could fail in odd environments, so we default toString in that case */
prettyPrint(a)
} catch {
case t: Throwable =>
logger.error(s"Error calling toPrettyString with: $a", t)