Skip to content

Instantly share code, notes, and snippets.

@rklaehn
rklaehn / Proxy.scala
Created January 31, 2015 16:29
Minimal akka http proxy
package akkahttptest
import akka.actor.ActorSystem
import akka.http.Http
import akka.stream.FlowMaterializer
import akka.http.server._
import akka.http.marshalling.PredefinedToResponseMarshallers._
import akka.stream.scaladsl.{HeadSink, Source}
object Proxy extends App {
@Centaur
Centaur / egret.scala
Last active August 29, 2015 14:09
forEgret
def name2id1(name: String): Option[String] = name match {
case "name1" => Some("id1")
case "name2" => Some("id2")
case "name3" => Some("id3")
case _ => None
}
def name2id2(name: String): Option[String] = name match {
case "name1" => None
case "name2" => Some("id2")
case "name3" => Some("id3")
@Centaur
Centaur / CommaSeperatedData.scala
Created October 31, 2014 04:08
dynamically run scala code
import tools.nsc.interpreter.IMain
import tools.nsc.Settings
object CommaSeperatedData extends App {
val data = """ "Doe, John", 35, 225, "5'10\"", "555-0123" """
val settings = new Settings
settings.usejavacp.value = true
val n = new IMain(settings)
n.interpret("List(" + data + ")")
@viktorklang
viktorklang / Future-retry.scala
Last active July 23, 2023 23:48
Asynchronous retry for Future in Scala
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.
@jboner
jboner / latency.txt
Last active May 2, 2025 23:26
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@christophermanning
christophermanning / README.md
Last active March 30, 2023 04:24
Voronoi Diagram with Force Directed Nodes and Delaunay Links

Created by Christopher Manning

Summary

Nodes are linked to nodes in neighboring cells. The cell's color is a function of its area.

The white lines are the Delaunay triangulation and the purple cells are the Voronoi diagram.

Controls

@millermedeiros
millermedeiros / gist:891886
Created March 29, 2011 06:21
iPad HTML5 video quirks and hacks
/*
* Example how to preload HTML5 video on the iPad (iOS 3.2+)
* @author Miller Medeiros
* Released under WTFPL
*/
var vid = document.createElement('video');
vid.src = 'lol_catz.mp4';
document.getElementById('video-holder').appendChild(vid);