Skip to content

Instantly share code, notes, and snippets.

test "Stale objects are expired, but served from cache for a grace period"
shell "/Users/pivotal/workspace/freshyfresh/target/memset version:test 2"
server s {
rxreq
expect req.url == "/"
txresp -status 200 -hdr "ETag: 1" -hdr "X-Generation-Key: version:test"
} -start
namespace :britt do
desc 'Removes trailing whitespace'
task :space do
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end
end
module ActsAsCached
class LocalCache
delegate :respond_to?, :to => :@remote_cache
def initialize(remote_cache)
@remote_cache = remote_cache
end
def cache_locally
@remote_cache = LocalCacheBuffer.new(original_cache = @remote_cache)
package com.twitter.service.cachet.test.unit
import com.twitter.service.cachet._
import org.joda.time.DateTime
import javax.servlet.http._
import org.specs._
import org.specs.mock._
import org.specs.mock.JMocker._
import com.twitter.service.cachet.test.mock._
module Cash
class Lock
def self.synchronize(*args, &block)
$lock.synchronize(*args, &block)
end
end
module Accessor
module ClassMethods
alias_method :expire_cache, :expire
class RequestWrapper(request: HttpServletRequest) extends javax.servlet.http.HttpServletRequestWrapper(request) {
override def getHeaders(name: String): java.util.Enumeration[_] = {
if (!ForwardRequest.hopByHopHeaders.contains(name))
super.getHeaders(name)
else
java.util.Collections.enumeration(new ArrayList)
}
}
@nkallen
nkallen / gist:114639
Created May 20, 2009 05:39
Using ScalaCheck to Fuzz a distributed datastore
package com.twitter.service.flock.edges.check
import scala.collection.immutable.HashMap
import org.scalacheck._
import net.lag.configgy.{Config, Configgy}
import org.specs.{ScalaCheck, Specification}
object EdgesSpec extends Specification with ScalaCheck with Waiter {
Configgy.configure(System.getProperty("basedir") + "/config/test.conf")
val username = System.getProperty("db.test.user")
# This comes from GenericWebLibrary
class BaseComponent
end
# This comes from RestExtensionLibrary
class RestComponent < BaseComponent
end
# In a language with mixins you could do
class SomeFilterStuff
/* This is when a refactoring really pays off.
*
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away).
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects.
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example,
* for someone to later add logging around method invocations of that object, or timeouts, or whatever.
*
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have
nkallen_: nkallen_: anyway, i want to stress that we basically agree about things so i want to be sure that the tone of the blog post is such
[7:25pm] nkallen_: [7:17pm] nkallen_: i would argue that what you do in rails 3 (according to these tweets I've read)
[7:25pm] nkallen_: [7:17pm] nkallen_: is exactly what I propose... this is just how one might do it in Ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: but my point is conceptual and not about ruby
[7:25pm] nkallen_: [7:18pm] nkallen_: it applies to every oo language and also I might argue to functional languages
[7:25pm] nkallen_: [7:18pm] nkallen_: which is to structure a program around the ability to layer on enhanced functionality and ensure that no assumptions are hardcoded by abstracting over the manufacture of objects
[7:25pm] nkallen_: [7:19pm] nkallen_: in the literature, these techniques are called DI, decorators, and factories.
[7:25pm] nkallen_: [7:20pm] nkallen_: i like these terms because they reflect the concepts that are at work. because ruby m