Skip to content

Instantly share code, notes, and snippets.

View hoffrocket's full-sized avatar
👋

Jon Hoffman hoffrocket

👋
  • Anomaly
  • New York, NY
View GitHub Profile
class BinaryTree[A <% Ordered[A]]private (datum: A,less: Option[BinaryTree[A]],more: Option[BinaryTree[A]]) {
def this(datum: A) = this(datum, None,None)
def add(a: A):BinaryTree[A] = {
def addTo(branch: Option[BinaryTree[A]]) = Some(branch.map(_.add(a)).getOrElse(new BinaryTree(a)))
if (a <= datum)
new BinaryTree(datum, addTo(less), more)
case class Tree[A](datum:A, children:List[Tree[A]]) {
def map[B](fn: A => B): Tree[B] = {
new Tree[B](fn(datum),children.map(_.map(fn)))
}
def foreach(fn: A => Unit) {
fn(datum)
children.foreach(_.foreach(fn))
}
@hoffrocket
hoffrocket / twitter_oauth_conversion.rb
Created May 7, 2009 15:04
converts twitter username and password to oauth access token and secret
require 'rubygems'
require 'twitter'
require 'mechanize'
consumer_token = 'token'
consumer_secret = 'secret'
twitter_name = ARGV[0]
twitter_password = ARGV[1]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>foo</title>
</head>
<body style="overflow:hidden">
<div id="FB_HiddenIFrameContainer" style="display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;"></div>
<script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
function profilePic(selector, id){
var element = $j(selector);
var oldId = element.attr('uid');
if (oldId != id){
element.attr('uid',id);
FB.XFBML.Host.addElement(new FB.XFBML.ProfilePic(element.get(0)));
}
}
package hoffrocket
import _root_.net.liftweb.mapper._
import _root_.java.sql.{PreparedStatement,Types, Connection,DriverManager}
import scala.collection.mutable.HashMap
import _root_.net.liftweb.util._
import Helpers._
/**
case class MySetHtml(uid:String, xhtml:NodeSeq) extends JsCmd {
def filterScripts(xhtml:NodeSeq):(String, NodeSeq) = {
def xform(in: NodeSeq): NodeSeq = in flatMap {
case e: Elem if e.label == "script" => NodeSeq.Empty
case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, xform(e.child) :_*)
case g: Group => xform(g.child)
case x => x
}
trait ScriptFilter extends JsCmd {
def content:NodeSeq
override def fixHtml(uid: String, content: NodeSeq): String = {
def xform(in: NodeSeq): NodeSeq = in flatMap {
case e: Elem if e.label == "script" => NodeSeq.Empty
case e: Elem => Elem(e.prefix, e.label, e.attributes, e.scope, xform(e.child) :_*)
case g: Group => xform(g.child)
case x => x
import _root_.net.liftweb.mapper._
trait HasCreatedMetaMapper[T <: HasCreated[T]] {
self: T with LongKeyedMetaMapper[T] =>
import java.util.Date
def findByCreated(startDate:Date, endDate:Date) = findAll(By_>(created_at, startDate), By_<(created_at, endDate))
def findByCreatedSince(startDate: Date) = findAll(By_>(created_at, startDate))
}
trait HasCreated [T <: HasCreated[T]] extends KeyedMapper[Long, T] {
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class FS {