Skip to content

Instantly share code, notes, and snippets.

View tjweir's full-sized avatar

Tyler Weir tjweir

View GitHub Profile
;; Cyberpunk Colour Theme
;;
;; "and he'd still see the matrix in his sleep, bright lattices of logic
;; unfolding across that colorless void..."
;; William Gibson, Neuromancer.
(deftheme cyberpunk
"")
(custom-theme-set-faces
@tjweir
tjweir / gist:3437067
Created August 23, 2012 14:18 — forked from timperrett/gist:3436334
reader monad for java.util.Properties example
/* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */
val dbReader: Reader[Properties, JdbcExecutor] =
for {
driver <- read[String]("db.driver")
uri <- read[String]("db.uri")
user <- read[String]("db.username")
password <- read[String]("db.password")
name <- read[String]("db.pool.name")
minCons <- read[Int]("db.pool.minConnections")
@tjweir
tjweir / WriterTExample.scala
Created August 14, 2012 14:38 — forked from puffnfresh/WriterTExample.scala
Example of scalaz' WriterT for Atlassian (pure functional logging)
import scalaz.WriterT
import scalaz.NonEmptyList
import scalaz.syntax.id._
import scalaz.std.option._
import scalaz.syntax.std.option._
type OptionLogger[A] = WriterT[Option, NonEmptyList[String], A]
val two: OptionLogger[Int] = WriterT.put(2.some)("The number two".wrapNel)
@tjweir
tjweir / Push.scala
Created June 25, 2012 13:47
Lift Socket Server
object Push extends SpecializedLiftActor[PushNotification] with Logger {
lazy val server: PushServer = new PushServer(
Props.get("push.app.port").flatMap(asInt).openOr(8888)
)
/** start accepting new connections */
spawn { while(true) server.accept() }
@tjweir
tjweir / planes.scala
Created June 6, 2012 18:21 — forked from gclaramunt/planes.scala
Very simple phantom types example
trait Flying
trait Landed
case class Plane[Status]()
def land(p:Plane[Flying])=Plane[Landed]()
def takeOff(p:Plane[Landed])= Plane[Flying]()
val plane = new Plane[Landed]()
@tjweir
tjweir / 3nightclubs.scala
Created April 24, 2012 16:14 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@tjweir
tjweir / hack.sh
Created April 1, 2012 15:18 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@tjweir
tjweir / vlc-stream-desktop-to-mp4.sh
Created March 7, 2012 01:51 — forked from dysinger/vlc-stream-desktop-to-mp4.sh
Stream your desktop with VLC (screencam)
# stream video from your desktop & audio from another device into an h264/mp3 avi video with VLC
vlc screen:// --screen-fps=12 \
--input-slave=alsa://hw:1,0 \
--qt-start-minimized \
--sout "#transcode{venc=x264,vcodec=h264,fps=12,vb=640,acodec=mp3,channels=1,ab=64}\
:std{access=file,mux=mp4,dst=screencam-$(date -u +%Y-%m-%d-%s).avi}"
@tjweir
tjweir / puzzle.ml
Created March 3, 2012 21:09 — forked from philtomson/puzzle.ml
Solve a puzzle posed on NPR (see: http://www.npr.org/2012/01/29/146034893/this-puzzle-is-the-pits - "Next Week" section )
(* Inspired by this puzzle from NPR:
http://www.npr.org/2012/01/29/146034893/this-puzzle-is-the-pits
(see the 'Next Weeks' challenge section there):
"Next Week's Challenge from listener Ed Pegg Jr.: Write the digits from
1 to 9 in a line. If you put times signs after the 2 and 4, a plus
sign after the 5, and a minus sign after the 7, you have
12 x 34 x 5 + 67 - 89, which equals 2018.
That's six years off from our current year 2012. This example uses
four arithmetic symbols. The object is to use just three of the
following arithmetic operations: addition, subtraction, multiplication
val publishRpmsTask = publishRpms <<= (streams, packagedArtifact in packageWar) map((out, artifact) => {
val publishDir = System.getProperty("PUBLISH_DIR") match {
case null =>
println("PUBLISH_DIR system property is not set. Using default.")
"publish"
case dir => dir
}
val scriptsDir = new File("va/scripts")
Process("./make-rpms.sh %s %s".format(artifact._2, publishDir), scriptsDir) ! out.log
})