Skip to content

Instantly share code, notes, and snippets.

View jastice's full-sized avatar
🤗

Justin Kaeser jastice

🤗
View GitHub Profile
class LineAggregator extends Actor {
var v = ""
override def receive = {
case Exit => context.stop(self)
case Put(line) => v = v + line + "\n"
case Get => sender ! v
}
class IntegrationSuite extends FunSuite with ShouldMatchers {
test("infinit actor") {
val actor= ActorSystem("tail").actorOf(Props[MrActor])
Thread.sleep(10000)
actor ! Interrupt
Thread.sleep(40054)
}
def sleepForTimes(ms: Long, times: Long) = {
var n = 0
() => {
n+=1
if (n <= times) {
Thread.sleep(ms)
true
} else {
false
}
object Attribute {
case class Attributed[Thing, Attribute](val thing: Thing, val attributes: Set[Attribute] = Set[Attribute]()) {
/** Add an attribute. */
def +(a: Attribute) = copy(attributes = attributes+a)
/** Change attributes for which the partial function is defined. */
def change(pf: PartialFunction[Attribute,Attribute]) =
@jastice
jastice / click-to-stamp.elm
Created July 8, 2014 10:37
Click to stamp!
import Mouse
import Keyboard
import Window
{--
Click to stamp!
Keys:
3-9 stamp shape (corners)
r red stamp!
t green stamp!
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@jastice
jastice / nobetterway?.elm
Last active August 29, 2015 14:04
The missing subtype problem
type Body s = { pos:(Int,Int), shape : s }
data Shape = Box {w:Int, h:Int} | Bubble {radius:Int}
mv: (Int,Int) -> Body a -> Body a
mv (x,y) body =
let (x0,y0)= body.pos
in { body | pos <- (x0+x, y0+y)}
myBubble = Body (0,0) <| Bubble {radius=10}
@jastice
jastice / bubblephysics.elm
Created August 5, 2014 15:34
Bubble Physics engine in Elm
-- based roughly on http://gamedevelopment.tutsplus.com/tutorials/gamedev-6331
module BubblePhysics where
-- plain old pair for coordinates, vectors
type Vec2 = (Float,Float)
type Body b = { b |
velocity: Vec2, -- direction and speed
inverseMass: Float, -- we usually use only inverse mass for calculations
restitution: Float -- bounciness factor
@jastice
jastice / gist:bfccf4b96b40be3eb432
Created August 17, 2014 15:47
Why does this compile?
type Thing t = { t | a:Int, b: String }
type Tag = { c: Int, d: String }
type Tagged = Thing Tag
thing = { a=3, b="foo" }
tagged = { thing | d = "derp" }
write: Tagged -> Element
write {a,b,c,d} = asText <| join " " [show c, d]
@jastice
jastice / lebkuchen.md
Last active August 29, 2015 14:10
Justin's Lebkuchen

Justin's Lebkuchen

A variation of Elisenlebkuchen, which contain no flour. Makes ca 45-60 Lebkuchen, 7cm.

Vegan, gluten-free (with the right kind of oblaten), certainly not low-fat or low-sugar.

Primary ingredients

  • 900g nuts or similar. Preferred mixture: