Skip to content

Instantly share code, notes, and snippets.

@richdougherty
richdougherty / HandlerPipeline.scala
Created November 7, 2017 19:12
Plan for refactoring WebCommands
// Change DefaultHttpRequestHandler to take a pipeline
class DefaultHttpRequestHandler(
pipeline: Seq[Handler],
router: Router,
errorHandler: HttpErrorHandler,
configuration: HttpConfiguration,
filters: Seq[EssentialFilter]) extends HttpRequestHandler {
...
}
@richdougherty
richdougherty / BuildSettings.scala
Created October 9, 2017 02:45
Example of custom ProblemFilter
mimaBinaryIssueFilters ++= {
def excludeSymbols[P <: ProblemRef](
name: String,
symbolFilter: String => Boolean)(
implicit problemTag: ClassTag[P]): ProblemFilter = {
{ problem: Problem =>
// Check the problem type
if (problemTag.runtimeClass.isAssignableFrom(problem.getClass)) {
// Check the problem name

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

ServerResultUtils.splitSetCookieHeaders (3.76%)

  • half of this is regex pattern matching
  • half is Scala collections overhead
  • SUGGESTION: replace flatMap with a while loop operating on the regex

ServerResultUtils.prepareCookies (12.9%) + CSRFAction$SignedTokenProvider.generateToken (7.43%) = 20.3%

  • change CSRF so we delay adding a cookie to the result until actually needed (i.e. when first used in a CSRF-protected form)
    • when receiving a request CSRF filter adds a CSRFToken object to request attribute
    • CSRFToken object's value is either read from the request or it's lazy - no data at first
  • when first read, e.g. by adding token to a form, lazily generates a value
benches/jmh:runMain scala.future.BenchRunner -i 2 -wi 2 -f1 -t1 .*
# Run complete. Total time: 00:10:58
Benchmark (impl) (result) Mode Cnt Score Error Units
CallbackBenchmark.onComplete_1 stdlib N/A thrpt 2 14.777 ops/us
CallbackBenchmark.onComplete_1 improved N/A thrpt 2 20.587 ops/us
CallbackBenchmark.onComplete_1 improved2 N/A thrpt 2 20.086 ops/us
CallbackBenchmark.onComplete_1024 stdlib N/A thrpt 2 42.248 ops/us
CallbackBenchmark.onComplete_1024 improved N/A thrpt 2 47.474 ops/us
@richdougherty
richdougherty / gist:cd983edd1fdfb31e0f718fa890eac08d
Created February 19, 2017 22:41
Omnidoc errors with Play WS
...
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/StandaloneWSRequest.html...
[error] /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/sources/com.typesafe.play-play-ws-standalone_2.11-1.0.0-M3/play/libs/ws/StandaloneWSRequest.java:244: warning: no @param for <U>
[error] <U> StandaloneWSRequest setBody(Source<ByteString, U> body);
[error] ^
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/StandaloneWSResponse.html...
...
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/WSRequestFilter.html...
[error] /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/sources/com.typesafe.play-play-ws-standalone_2.11-1.0.0-M3/play/libs/ws/WSRequestFilter.java:12: error: unterminated inline tag
[error] * {@code
/**
* Handle the given request.
*/
def handle(channel: Channel, request: HttpRequest): Future[HttpResponse] = {
logger.trace("Http request received by netty: " + request)
import play.core.Execution.Implicits.trampoline
/** Convert a Play Result to a NettyResponse. */
@richdougherty
richdougherty / Inhabitation.txt
Last active April 12, 2016 04:28
Type inhabitation algorithm for Whiley
INHABITATION ALGORITHM
The idea is to label each state in a type's automaton with a ternary value to
indicate our knowledge about its inhabitation:
1. all - inhabited by all values (aka any)
2. none - inhabited by no values (aka void)
3. some - may be inhabited by some values
States with a basic type have an implicit label corresponding to the type:
@richdougherty
richdougherty / dawnbringer-16-color-palette.md
Last active January 27, 2016 23:30
Color names for the DawnBringer 16-color palette