Skip to content

Instantly share code, notes, and snippets.

@morganrallen
morganrallen / _README.md
Last active January 15, 2023 19:41
Janky Browser

JankyBrowser

The only cross-platform browser that fits in a Gist!

One line install. Works on Linux, MacOSX and Windows.

Local Install

$> npm install http://gist.github.com/morganrallen/f07f59802884bcdcad4a/download
@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.
@martintrojer
martintrojer / kebab.clj
Last active August 29, 2015 14:07
kebab-case keywords in nested data-structures
(ns kebab
(:require [camel-snake-kebab :as kebab]
[schema.coerce :as c]
[schema.core :as s]))
(def Data (s/either s/Keyword
{(s/recursive #'Data) (s/recursive #'Data)}
[(s/recursive #'Data)]
#{(s/recursive #'Data)}
s/Any))
@ceedubs
ceedubs / gist:a96bc169eb3152cd6226
Created September 30, 2014 22:17
Scalaz's Equal type class (and associated handy === syntax) is a type-safe alternative to Scala's ==
scala> case class UserId(id: Long)
defined class UserId
scala> def isSusan(id: UserId): Boolean = id == 3L // see the bug?
isSusan: (id: UserId)Boolean
scala> isSusan(UserId(3L))
res31: Boolean = false// shouldn't this be true?
// let's show the compiler how to check whether two UserIds are equal
@frenchy64
frenchy64 / schema.md
Created August 11, 2014 06:55
Schema vs core.typed

Schema

I think of Schema as a runtime contracts library (I believe it does coercion and validation, but they seem related to me).

Pros

  • small barrier to entry, thus immediately useful
    • just add a contract/coercion to a function and you're off
  • can manipulate contracts as regular clojure data
  • documentation
macro protocol {
case { _ $name:ident { $fn:protocol_fn ... } } => {
// Probably not a good idea to rely on `__fresh`. Sweet.js should provide
// some sort of blessed gensym capability.
letstx $id = [makeValue(__fresh(), #{ here })];
return #{
function $name(proto, impl) {
if (!impl) {
impl = proto;
proto = {};
@jhaberstro
jhaberstro / gist:878f7f2043f922f0d06c
Last active August 29, 2015 14:02
Multiple optional bindings in Swift (i.e. the equivalent of if let (a, b, c) = (optA, optB, optC) { ... })
// The DSL's implementation (i.e. just the applicative interface for Optionals + methods for creating tuples)
operator infix <*> { associativity left }
@infix func <*><A, B>(lhs: (A -> B)?, rhs: A?) -> B? {
switch lhs {
case .None:
return .None
case let .Some(f):
return rhs.map(f)
}
}
@jhaberstro
jhaberstro / monoid.swift
Last active December 14, 2015 18:39
Swift monoid, num, Sum typeclasses with Int32 instances
protocol Monoid {
class func mzero() -> Self
func mop(y: Self) -> Self
}
func mconcat<M : Monoid>(t: Array<M>) -> M {
return (t.reduce(M.mzero()) { $0.mop($1) })
}
protocol Num {
@jhaberstro
jhaberstro / num.swift
Last active June 3, 2016 12:17
Swift typeclass example
protocol Num {
class func zero() -> Self
func succ() -> Self
func add(y: Self) -> Self
func multiply(y: Self) -> Self
}
extension Int32: Num {
static func zero() -> Int32 { return 0 }
func succ() -> Int32 { return self + 1 }
(defn flatmap<
"Takes a function and a source channel, and returns a channel which
contains the values in each channel produced by applying f to
each value taken from the source channel. f must return a
channel."
[f in]
(let [out (a/chan)]
(a/go-loop []
(let [item (a/<! in)]
(if (nil? item)