Skip to content

Instantly share code, notes, and snippets.

Avatar

Tyler JavadocMD

View GitHub Profile
View FizzBuzzAkkaFSM
package com.javadocmd
import akka.actor.Actor
import akka.actor.FSM
import akka.actor.Props
import akka.actor.ActorSystem
import akka.actor.LoggingFSM
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.collection._
@JavadocMD
JavadocMD / gist:1231a695deeea25c75fe
Created May 28, 2014
A problematic DeltaSpike Security implementation.
View gist:1231a695deeea25c75fe
@ApplicationScoped
public class MyAuthorizer {
@Inject
private BasicAuthorizer basicAuth;
@Secures
@SomethingAccess
private boolean accessSomething() {
return basicAuth.isUser(ADMIN);
@JavadocMD
JavadocMD / gist:37030357f7f6bd38d173
Last active Aug 29, 2015
Rendering spinning number wheels
View gist:37030357f7f6bd38d173
// Setup the data for our elements...
lazy val stop: Stream[Float] = 3f #:: stop.map(_ + .5f)
lazy val dt: Stream[Float] = 0f #:: .10f #:: .05f #:: -.05f #:: dt
lazy val dx: Stream[Int] = Stream.from(0, 15)
// I can have as many elements as I want by adjusting this number.
val values = (stop, dt, dx).zipped.take(10)
override def render() = {
time += Gdx.graphics.getDeltaTime()
View gist:2960f8b1b714c369c4ca
KHRDebug.glDebugMessageCallback(new KHRDebugCallback(new KHRDebugCallback.Handler() {
override def handleMessage(source: Int, msgType: Int, id: Int, severity: Int, message: String) {
println("%d %d %d %d: %s".format(source, msgType, id, severity, message))
}
}));
View Custom extractors with nested types.
case class Foo(val x: Int, val y: Int)
class Bar(val f: Foo, val s: String)
object Bar {
def apply(x: Int, y: Int, s: String): Bar = new Bar(Foo(x, y), s)
def unapply(b: Bar): Option[(Int, Int, String)] = Some((b.f.x, b.f.y, b.s))
}
val a = Bar(1, 2, "A")
View toList all the things
def parse(s: String): List[List[Long]] =
s.lines.map(_.split(" ").map(_.toLong).toList).toList
def pairwiseChoose(row: List[Long]): List[Long] =
(row.sliding(2).map { case a :: b :: Nil => max(a, b) }).toList
View DrawingGame.java
package com.javadocmd.drawing;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
View vertex.glsl
uniform mat4 u_projTrans;
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
varying vec4 v_color;
varying vec2 v_texCoord0;
void main()
View fragment.glsl
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
uniform sampler2D u_mask;
varying vec4 v_color;
varying vec2 v_texCoord0;
@JavadocMD
JavadocMD / picks.scala
Last active Aug 29, 2015
Picking items from a list one-by-one
View picks.scala
// Combining a list of options...
val options = List("a", "b", "c", "d")
// ... with a sequence of "picks" to make...
val choices = List(0, 2, 1, 0)
// ... should yield a re-ordered list as so.
val expects = List("a", "d", "c", "b")
// Assume we don't have to worry about out-of-bounds choices.
// worked example:
// pick 0 from {a,b,c,d} -> a