Skip to content

Instantly share code, notes, and snippets.

@jdan
jdan / y
Last active May 22, 2020 17:51
(λ (f)
((λ (x) (f (x x)))
(λ (x) (f (x x)))))
@svrc-personal
svrc-personal / gist:5a8accc57219b9548fe1
Last active May 11, 2020 15:39
JDK 8 seems to use /dev/urandom and /dev/random more sensibly
Summary of Behaviour:
A. OpenJDK 7 b65.
1. Default in java.security is securerandom.source=/dev/urandom
2. If securerandom.source=/dev/urandom, NativePRNG is used, SecureRandom.nextBytes() is non-blocking via /dev/urandom ; SecureRandom.generateSeed(x) is blocking via /dev/random
3. if securerandom.source=/dev/random, then SHA1PRNG is used. Initial seed is blocking via /dev/random. No other accesses.
4. If securerandom.source=/dev/./urandom then SHA1PRNG is used. Initial seed is non-blocking via /dev/./urandom. No other accesses.
B. Oracle JDK 8 b25.
@md-5
md-5 / App.java
Created September 6, 2012 10:03
Why Netty is awesome.
package com.md_5.jcaptive;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.ChannelInitializer;
@Luzifer
Luzifer / README.md
Last active August 25, 2019 12:34
Strategies for persistent data storage on CoreOS-cluster

Persistent data storage on CoreOS-cluster

Storing the data on the host machine

Data directories are created in /home/coreos and mounted into the container using volume cli options of docker run. All data the container writes is stored on the host and as long as the host persists safe against container restarts / recreates.

  • Pro
    • No effort, just create the directories and mount them into the container
  • Contra
  • Container is bound to host (unable to failover)
@jrudolph
jrudolph / ListBufferTest.scala
Last active July 27, 2019 13:14
ListBuffer / List mutability fail
import scala.collection.mutable.ListBuffer
object ListBufferTest extends App {
new X().runTest()
}
class X extends Runnable {
var x: List[String] = List("", "")
def run() {
@alandipert
alandipert / reinvoke.cljs
Last active June 22, 2019 00:20
It's sweet that IFn is a protocol in ClojureScript
(extend-type js/RegExp
cljs.core/IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")
@ztellman
ztellman / gist:5603216
Last active May 26, 2019 17:08
an exploration of the memory implications of call-site caching for protocols
;; let's create a simple protocol that just returns a number
user> (defprotocol NumberP (number [_]))
NumberP
;; now we'll create an implementation that always returns '1'
user> (deftype One [] NumberP (number [_] 1))
user.One
;; unsurprisingly, this type only has a single static value, which wraps the '1'
> (-> One .getDeclaredFields seq)
// First pass at a thrift parser using instaparse:
(def instagram
(insta/parser
"
Document ::= <ws> Header* Definition*
SlashComment ::= <'//'> #'[^\n]'*
PoundComment ::= <'#'> #'[^\n]'*
BlockComment ::= '/*' #'(?s).'* '*/'
Comment ::= SlashComment | PoundComment | BlockComment | <ws>
@JakeWharton
JakeWharton / GuavaCollectors.java
Last active May 10, 2018 09:08
Example Java 8 collectors for Guava.
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@dkandalov
dkandalov / plugin.groovy
Last active March 7, 2018 16:11
IntelliJ micro-plugin to wrap selected text to the column width (copied from https://github.com/abrookins/WrapToColumn)
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.SelectionModel
import com.intellij.openapi.editor.actionSystem.EditorAction