Skip to content

Instantly share code, notes, and snippets.

View bmc's full-sized avatar

Brian Clapper bmc

View GitHub Profile
@bmc
bmc / uuid.coffee
Created February 23, 2012 16:03
Generate UUID, using Math.random(), in CoffeeScript
# RFC1422-compliant Javascript UUID function. Generates a UUID from a random
# number (which means it might not be entirely unique, though it should be
# good enough for many uses). See http://stackoverflow.com/questions/105034
uuid = ->
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) ->
r = Math.random() * 16 | 0
v = if c is 'x' then r else (r & 0x3|0x8)
v.toString(16)
)
@bmc
bmc / BrainDeadHTTP.scala
Last active April 13, 2016 21:21
Brain Dead HTTP server in Scala
package grizzled.testutil
import java.io.{PrintWriter, OutputStreamWriter}
import java.net.InetAddress
import java.text.SimpleDateFormat
import java.util.Date
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.io.Source
@bmc
bmc / promo.md
Created January 13, 2016 21:21
Draft promotional language for Typelevel page

Plan to hang around after the Typelevel Summit, because this year, Northeast Scala Symposium 2016 will be held at the same location on March 4th and 5th. RSVPs open January 16th. Join in the fun!

@bmc
bmc / delicious2diigo.py
Created December 18, 2010 03:46
Quick hack to load Delicious bookmarks into Diigo
#!/usr/bin/python
# Based on diigo.py, which is copyright (c) 2008 Kliakhandler Kosta
# <Kliakhandler@Kosta.tk> and released under the GNU Public License.
#
# This hacked version is also released under the GNU Public License.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@bmc
bmc / LocalHelpers.scala
Created May 3, 2013 15:30
Version of Play's @select helper that handles 'data args. Assumes the existence of a LocalHelpers module that contains a deCamelCase function (shown below)
package views
object LocalHelpers {
/** Default target for offsite anchors.
*/
val OffSiteAnchorTarget = "link"
/** Convert a symbol to a string, for use in HTML.
*/
@bmc
bmc / async.scala
Created April 6, 2013 16:09
Example comparison of Future functions and async library
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scalaz._
import Scalaz._
import scala.async.Async.{async, await}
import lib.ScalazUtil
// Stubs, to get this to compile. Fill in with real stuff later.
case class User(username: String, password: String)
case class GitHubData(user: User)
@bmc
bmc / concurrent.scala
Created February 14, 2013 15:37
Simulate Play 2.0 Future.await() in Play 2.1 (for backward compatibility)
package lib
import scala.concurrent.Future
import scala.concurrent.duration._
import play.api.libs.concurrent.Execution.Implicits._
object ConcurrentUtil {
import scala.language.{implicitConversions, postfixOps}
@bmc
bmc / transitional.scala
Last active December 11, 2015 23:48
Transitional code to enhance Play 2.1 library so that Scala Futures have the await() function that Play 2.0 Promises had (until I can refactor).
import scala.concurrent.Future
import scala.concurrent.duration._
import play.api.libs.concurrent.Execution.Implicits._
object WebServicesUtil {
import scala.language.{implicitConversions, postfixOps}
/** TRANSITIONAL: Simulate Play 2.0 await() for a Future, until code
* is refactored.
@bmc
bmc / SomeController.scala
Created January 30, 2013 19:08
Flash stuff, in Play.
object SomeController extends Controller {
def signup = Action(parse.urlFormEncoded) { implicit request =>
signupForm.bindFromRequest.fold(
{ form => // failure; repost
BadRequest(views.html.register.signup(form))
},
{ newUser => // success; create user and send confirmation
@bmc
bmc / u.scala
Created January 28, 2013 14:04
Making your own Scala 2.10 string interpolator
implicit class UpCaser(val sc: StringContext) extends AnyVal {
def u(args: Any*): String = {
val strings = sc.parts.iterator
val expressions = args.iterator
var buf = new StringBuffer(strings.next)
while (strings.hasNext) {
buf append expressions.next
buf append strings.next
}