Skip to content

Instantly share code, notes, and snippets.

View stephenjudkins's full-sized avatar

Stephen Judkins stephenjudkins

View GitHub Profile
@stephenjudkins
stephenjudkins / gist:1628612
Created January 17, 2012 20:11
lift-json bug
{
import net.liftweb.json._
val json = """
{"a": "Value"}
"""
case class ExtractTo(a: String, b: Option[Boolean])
implicit val formats = DefaultFormats
println(parse(json).extract[ExtractTo])
}
@stephenjudkins
stephenjudkins / gist:1335736
Created November 3, 2011 03:57
Unfiltered matchers and responders working w/ Finagle
import com.twitter.finagle.builder.ServerBuilder
import com.twitter.finagle.http.Http
import com.twitter.finagle.{ClientConnection, Service}
import com.twitter.util.{Promise, Future}
import java.io.{ByteArrayOutputStream, BufferedReader, InputStreamReader}
import java.net.{URLDecoder, InetSocketAddress}
import java.nio.charset.{Charset => JNIOCharset}
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBufferInputStream}
import org.jboss.netty.handler.codec.http.{HttpResponseStatus, DefaultHttpResponse, HttpVersion, CookieDecoder, HttpHeaders, HttpResponse => NHttpResponse, HttpRequest => NHttpRequest}
import unfiltered.Cookie
import annotation.tailrec
object SplitList {
def split[A](all: List[A], f: (A, A) => Boolean): List[List[A]] = {
@tailrec def _split(list: List[A], acc: List[List[A]], current: List[A]): List[List[A]] = list match {
case Nil => current match {
case Nil => Nil
case _ => acc ::: current :: Nil
}
require 'java'
module Java::scala::collection::Seq
def each(&block)
foreach &block
end
include Enumerable
end
2010-12-23 15:11:50.204:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2010-12-23 15:11:50.297:INFO::jetty-6.1.26
-> builtin/core_ext/symbol
<- builtin/core_ext/symbol - 449ms
-> enumerator
<- enumerator - 39ms
-> java
-> java
<- java - 0ms
-> builtin/javasupport/java
Around do |scenario, block|
RSpec::Mocks.setup(self)
RSpec::Mocks.teardown
block.call
RSpec::Mocks.verify
end
ruby-1.9.2-p0 > t = Time.now
=> 2010-10-27 17:41:00 -0700
ruby-1.9.2-p0 > t.utc?
=> false
ruby-1.9.2-p0 > t2 = t.utc
=> 2010-10-28 00:41:00 UTC
ruby-1.9.2-p0 > t
=> 2010-10-28 00:41:00 UTC
ruby-1.9.2-p0 > t.object_id
=> 2154182900
Ivan-IV:compost stephen$ rake test
(in /www/aboutus/compostus/compost)
/www/bin/ruby -Ilib:test "/www/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/unit/about_us_mailer_test.rb" "test/unit/account_activity_test.rb" "test/unit/action_test.rb" "test/unit/action_utility_test.rb" "test/unit/address_intersector_test.rb" "test/unit/adult_filter_test.rb" "test/unit/analytics_robot_test.rb" "test/unit/archive_test.rb" "test/unit/array_test.rb" "test/unit/au_diff_test.rb" "test/unit/au_page_lookup_test.rb" "test/unit/bot_filter_test.rb" "test/unit/compost_image_test.rb" "test/unit/contact_test.rb" "test/unit/create_account_actions_test.rb" "test/unit/daily_action_count_edits_test.rb" "test/unit/daily_action_count_reg_and_email_test.rb" "test/unit/edit_mailer_test.rb" "test/unit/edit_summary_parser_test.rb" "test/unit/edit_test.rb" "test/unit/exclusion_list_test.rb" "test/unit/external_link_test.rb" "test/unit/form_test.rb" "test/unit/geo_cache_test.rb" "test/unit/graphic_protection_test.rb" "te
>> Page.find_by_title('OnlineFreeSpanish.com').tag_collection.tags
=> [{"score"=>50, "keyword"=>"accustomed"}, {"score"=>50, "keyword"=>"acquiring"}, {"score"=>50, "keyword"=>"activity"}, {"score"=>50, "keyword"=>"age"}, {"score"=>50, "keyword"=>"anyone"}, {"score"=>50, "keyword"=>"anything"}, {"score"=>50, "keyword"=>"approach"}, {"score"=>50, "keyword"=>"area"}, {"score"=>50, "keyword"=>"attend"}, {"score"=>50, "keyword"=>"basic"}, {"score"=>50, "keyword"=>"become"}, {"score"=>50, "keyword"=>"both"}, {"score"=>50, "keyword"=>"brain"}, {"score"=>50, "keyword"=>"busines"}, {"score"=>50, "keyword"=>"catch"}, {"score"=>50, "keyword"=>"check"}, {"score"=>50, "keyword"=>"child"}, {"score"=>50, "keyword"=>"created"}, {"score"=>50, "keyword"=>"credit"}, {"score"=>50, "keyword"=>"designed"}, {"score"=>50, "keyword"=>"different"}, {"score"=>50, "keyword"=>"doesn"}, {"score"=>50, "keyword"=>"early"}, {"score"=>50, "keyword"=>"education"}, {"score"=>50, "keyword"=>"educational"}, {"score"=>50, "keyword"=>"engage"}, {"s
module Enumerable
def permutations
Enumerable::Enumerator.new(self, :each_permutation)
end
def each_permutation
each do |item|
others = select {|other| item != other}