Skip to content

Instantly share code, notes, and snippets.

View ryanoneill's full-sized avatar

Ryan O'Neill ryanoneill

  • San Francisco, CA
View GitHub Profile
@ryanoneill
ryanoneill / Problem10.scala
Created April 3, 2012 21:02
Ninety-Nine Scala Problems: Problem 10 - Run-length encoding of a list.
// http://aperiodic.net/phil/scala/s-99/
// P10 (*) Run-length encoding of a list.
// Use the result of problem P09 to implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as tuples (N, E) where N is the number of duplicates of the element E.
// Example:
// scala> encode(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e))
// res0: List[(Int, Symbol)] = List((4,'a), (1,'b), (2,'c), (2,'a), (1,'d), (4,'e))
import Problem09.pack
@ryanoneill
ryanoneill / JettyLauncher.scala
Created April 9, 2012 03:49
JettyLauncher for Lift Framework for use with Heroku
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler}
import org.eclipse.jetty.server.nio.SelectChannelConnector
import net.liftweb.http.LiftFilter
object JettyLauncher extends App {
// Slightly modified from
// https://github.com/ghostm/lift_blank_heroku
// to change Application to App
// Original version was modified based on the
@ryanoneill
ryanoneill / HelloWorld.scala
Created April 9, 2012 04:01
Lift Web Framework HelloWorld snippet
package code
package snippet
import scala.xml.{NodeSeq, Text}
import net.liftweb.util._
import net.liftweb.common._
import java.util.Date
import Helpers._
class HelloWorld {
@ryanoneill
ryanoneill / Boot.scala
Created April 9, 2012 04:07
Very Simple Boot file for Lift on Heroku
package bootstrap
package liftweb
import net.liftweb.http.LiftRules
import net.liftweb.sitemap.{SiteMap,Menu}
class Boot {
def boot {
LiftRules.addToPackages("code")
@ryanoneill
ryanoneill / index.html
Created April 9, 2012 04:11
Very Simple Web Page for Lift on Heroku
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Home</title>
</head>
<body class="lift:content_id=main">
<div id="main" class="lift:surround?with=default;at=content">
<h2>Welcome to your project!</h2>
<p>
@ryanoneill
ryanoneill / web.xml
Created April 9, 2012 04:14
Very Simple Web Configuration for Lift on Heroku
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>LiftFilter</filter-name>
<display-name>Lift Filter</display-name>
@ryanoneill
ryanoneill / build.sbt
Created April 9, 2012 04:24
Very Simple Build.sbt File for Lift on Heroku
import com.typesafe.startscript.StartScriptPlugin
name := "Lift Hello World"
seq(StartScriptPlugin.startScriptForClassesSettings: _*)
libraryDependencies ++= {
Seq(
"org.eclipse.jetty" % "jetty-server" % "7.5.4.v20111024" % "compile->default",
"org.eclipse.jetty" % "jetty-servlet" % "7.5.4.v20111024" % "compile->default",
@ryanoneill
ryanoneill / Problem01.scala
Created April 25, 2012 02:40
Project Euler Problem 01 - Find the sum of all the multiples of 3 or 5 below 1000.
// http://projecteuler.net/problem=1
// If we list all the natural numbers below 10 that are multiples of 3 or 5,
// we get 3, 5, 6 and 9. The sum of these multiples is 23.
// Find the sum of all the multiples of 3 or 5 below 1000.
object Problem01 {
def main(args: Array[String]) {
val output = "Sum of [3,5] multiples below %d: "
@ryanoneill
ryanoneill / Problem02.scala
Created April 25, 2012 19:41
Project Euler - Problem 02 - Find the sum of the even-valued terms.
// http://projecteuler.net/problem=2
// Each new term in the Fibonacci sequence is generated by adding the previous two terms.
// By starting with 1 and 2, the first 10 terms will be:
// 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
// By considering the terms in the Fibonacci sequence whose values do not exceed four million,
// find the sum of the even-valued terms.
@ryanoneill
ryanoneill / Problem03.scala
Created April 25, 2012 19:55
Project Euler - Problem 03 - What is the largest prime factor of the number 600851475143 ?
// http://projecteuler.net/problem=3
//The prime factors of 13195 are 5, 7, 13 and 29.
//What is the largest prime factor of the number 600851475143 ?
object Problem03 {
def main(args: Array[String]) {
//val number = 13195
val number = 600851475143L