A simple backgrounding object:
object BackgroundOperation {
def apply(f: => Unit) = {
BackgroundActor ! BackgroundJob(() => f)
}
case class BackgroundJob(f: () => Unit)
object BackgroundActor extends LiftActor {
protected def messageHandler = {
case BackgroundJob(f) => f()
}
}
}
Then you can do this whenever you want:
BackgroundOperation {
// some complicated thing
}
Why does Buzz even exist? Is it because Google wants to make my life better in some way? No. Buzz exists because Google feels threatened by Twitter and Facebook and wants to kill them. Google has become what Microsoft used to be—the Borg, the company that gobbles up ideas from smaller rivals and cranks out lame imitations in an attempt to put the little guys out of business.
Many different database objects in foursquare have a foreign key to User. So I wrote something like so:
object User {
trait FK[T <: FK[T]] extends LongKeyedMapper[T] {
self: T=>
object userid extends MappedLongForeignKey(this, User)
def hasUser_? = userid.defined_?
}
class FKList[A <: FK[A]](list: List[A]) {
def primeUsers: List[A] = {
if (!list.isEmpty) {
val uids = list.filter(_.hasUser_?).map(_.userid.is)
val users = findAll(ByList(User.id, uids))
list.foreach(item => {
item.userid.primeObj(users.find(_.id.is == item.userid.is))
})
}
list
}
}
}
So that things can extend User.FK[Foo] and get automatic extra functionality for dealing with their User parents. But you’ll notice that the field name is hard coded in the above. Some things have two user parents. For example Venues have creators and mayors. Is there some way to enhance the code above so that a single model can extend User.FK twice with different field names? Pondering what might be a good way to do this.
As a general rule, if nothing bad will happen to you if you free ride, it’s smart to free ride. Worrying that other countries are pulling ahead is like worrying that the other oarsman in your boat will beat you to the destination if you’re lazy. You’re in the same boat! The smart thing is to goad everyone else into going as fast and hard as they can. For a good while now, America has been a dim kid with ape strength happy to carry half the world as long as he gets to fist-pump, flex his pecs, and chant U.S.A.! U.S.A.! in the mirror each night. It’s a darn good deal for the rest of the world. America’s just too dumb to feel exploited. And too idiotically vain to enjoy a free ride.
I’m 12 weeks into my NFL Suicide Leage. So far I have used up: Baltimore, Washington, Dallas, Chicago, Pittsburgh, Green Bay, New England, San Diego, Seattle, Minnesota, Jacksonville, and Cincinnati. Looking ahead to the remaining 5 weeks I see these two as the best options:
OPTION 1:
Indianapolis over Tennessee
NY Jets over Tampa Bay
Arizona over Detroit
New Orleans over Tampa Bay
Denver over Kansas City
OPTION 2:
New Orleans over Washington
NY Jets over Tampa Bay
Denver over Oakland
Arizona over St Louis
Indianapolis over Buffalo
Any thoughts?
Simple, but fun:
def partition[T](items: List[T], p: (T, T) => Boolean): List[List[T]] = {
items.foldRight[List[List[T]]](Nil)((item: T, items: List[List[T]]) => items match {
case (first :: rest) :: last if p (first, item) =>
(List(item)) :: (first :: rest) :: last
case (first :: rest) :: last =>
(item :: first :: rest) :: last
case _ => List(List(item))
})
}
If you understand what this does, or know someone who does, I’m hiring. Send me an e-mail.
Take a look at how Apple would be able to quickly build a large search engine business:
#1 The Apple fanboy market would leave Google in a heartbeat. No question. That’s about 5 per cent of the computer market, and that’s not counting the iPod, iPhone users.