Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Hacking on @yetibot

Trevor Hartman devth

Hacking on @yetibot
View GitHub Profile
def getOrCreate[A](m: JMap[Any, Any], key: Any, create: A): A = {
if (m.containsKey(key)) m.get(key).asInstanceOf[A]
else {
m.put(key, create)
create
}
}
def storeAtPath(m: JMap[Any, Any], path: Seq[String], values: Seq[Any]) {
path.toList match {
import scalaz._, Scalaz._
val expected = "foo".node("bar".leaf, "baz".node("qux".leaf))
val loc = expected.loc
loc.firstChild
loc.firstChild.right
/***
scalaVersion := "2.11.6"
libraryDependencies ++= Seq("org.scalaz" %% "scalaz-core" % "7.1.0")
*/
// Code listing for http://devth.com/2015/thrush-cond-is-not-a-monad/
object Main extends App {
import scalaz._, Scalaz._
// Running this code:
// scala -Dscala.color -feature -classpath ~/.m2/raptor2/org/scalaz/scalaz-core_2.11/7.1.2/scalaz-core_2.11-7.1.2.jar typeclass.scala
import scalaz._, Scalaz._
import scala.language.implicitConversions
import scala.language.postfixOps
object Typeclass {
class C(val name: String)
var context:LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain);
var loader:BulkLoader = new BulkLoader("loadmystuffplskthxbye");
loader.add( someS3Url, { context: context } ); // WIN
$gateway->setCharsetHandler("mbstring","UTF-8","UTF-8");
/** Implicit class to add idiomatic Scala methods to the
* InterProcessReadWriteLock read/write lock */
implicit class RichInterProcessReadWriteLock(lock: InterProcessReadWriteLock) {
private def acquireAndRelease[A](mutex: InterProcessMutex, fn: => A): Either[Throwable, A] =
Try {
// blocking operation
mutex.acquire()
logger.info(s"Lock obtained: $mutex")
Right(fn)
}.recover { case e =>
require 'rubygems'
require 'sinatra'
require 'tempfile'
get '/audio' do
text = params['text']
temp_file = Tempfile.new 'mp3'
# generate mp3 to temp file
require 'rubygems'
require 'sinatra'
require 'app.rb'
run Sinatra::Application
# Simple SVN apache config by devth.com
# Place in /etc/apache2/sites on OS X Server
# Adding or removing permissions for a user is as simple as adding or
# removing them from "svn_users" group in Workgroup Manager
<Location /svn>
DAV svn
SVNParentPath /Library/Subversion/Repositories
<Limit GET HEAD OPTIONS CONNECT POST PROPFIND PUT DELETE PROPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require group svn_users