Skip to content

Instantly share code, notes, and snippets.

View LeifWarner's full-sized avatar

Leif Warner LeifWarner

  • Janrain
  • Portland, Oregon
View GitHub Profile
@LeifWarner
LeifWarner / Thing.scala
Created October 21, 2011 17:56
Package object
package janrain
object Thing {
def run = println(name)
}
@LeifWarner
LeifWarner / curl.rb
Created November 30, 2011 21:44
Logging http requests
In the block passed to Curl::Easy:
e.g. {|curl|
curl.verbose = true
}
Logs headers only, not body.
--- /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb.orig 2011-12-16 14:44:29.806155993 -0800
+++ /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb 2011-12-16 16:51:26.468961991 -0800
@@ -4,6 +4,7 @@
require 'thread'
require 'timeout'
require 'rubygems'
+require 'base64'
class String
require 'jruby-spymemcached'
class SpymemcachedWrapper
# Shamelessly cribbed from
# https://github.com/ikai/jruby-memcache-client/blob/master/lib/memcache.rb
def initialize(servers, opts)
@spymemcached = Spymemcached.new(servers)
at_exit { @spymemcached.shutdown }
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at java.net.SocketInputStream.socketRead0(Native Method)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at java.net.SocketInputStream.read(SocketInputStream.java:150)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at java.net.SocketInputStream.read(SocketInputStream.java:121)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at sun.security.ssl.InputRecord.readFully(InputRecord.java:312)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at sun.security.ssl.InputRecord.read(InputRecord.java:350)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:894)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:851)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
Apr 3 17:24:15 tomcat5-prod.engage-cloud.com #011at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuf
package foo
class Crash {
def foo =
try
err
catch {
case e:Exception =>
e.printStackTrace
}
@LeifWarner
LeifWarner / stringQuery.scala
Created June 5, 2012 19:13
JDBC query using scala-arm
def sql[T](q: String)(f: ResultSet => T): Either[List[Throwable], T] = (for {
connection <- managed( datasource.getConnection )
statement <- managed( connection.createStatement )
resultSet <- managed( statement.executeQuery(q) )
} yield resultSet).acquireFor(f)
@LeifWarner
LeifWarner / lift-json.scala
Created July 24, 2012 21:39
lift-json trait for scalatra
package org.scalatra
package liftjson
import scala.xml.XML
import net.liftweb.json._
import net.liftweb.json.Xml.toXml
trait JsonSupport extends ApiFormats {
/**
package org.scalatra
package liftjson
import scala.xml.XML
import net.liftweb.json._
import net.liftweb.json.Xml.toXml
trait JsonSupport extends ApiFormats {
/**
@LeifWarner
LeifWarner / Main.scala
Created August 24, 2012 21:11
Lift-json decomposition / extraction
import net.liftweb.json.{Extraction, DefaultFormats}
object Main {
implicit val formats = DefaultFormats
val p = Person("Leif", 33)
def main(args:Array[String]) {
val dp = Extraction decompose p