Created
April 3, 2009 19:42
-
-
Save agibralter/89927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
val conn = DriverManager.getConnection("jdbc:mysql://...") | |
// stuff | |
} catch { | |
case ex: SQLException => { | |
// exception handling | |
} | |
} finally { | |
// This doesn't work because of the scope of conn... any thoughts? | |
conn.close() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec scala $0 $@ | |
!# | |
import scala.actors._ | |
import Actor._ | |
val symbols = List( "AAPL", "GOOG", "IBM", "JAVA", "MSFT") | |
val receiver = self | |
val year = 2008 | |
symbols.foreach { symbol => | |
actor { receiver ! getYearEndClosing(symbol, year) } | |
} | |
val (topStock, highestPrice) = getTopStock(symbols.length) | |
printf("Top stock of %d is %s closing at price %f\n", year, topStock, highestPrice) | |
def getTopStock(count : Int) : (String, Double) = { | |
(1 to count).foldLeft("", 0.0) { (previousHigh, index) => | |
receiveWithin(1000) { | |
case (symbol : String, price : Double) => | |
if (price > previousHigh._2) (symbol, price) else previousHigh | |
} | |
} | |
} | |
def getYearEndClosing(symbol : String, year : Int) = { | |
val url = "http://ichart.finance.yahoo.com/table.csv?s=" + | |
symbol + "&a=11&b=01&c=" + year + "&d=11&e=31&f=" + year + "&g=m" | |
// val data = io.Source.fromURL(url).mkString() | |
// val price = data.split("\n")(1).split(",")(4).toDouble | |
val price = 10 | |
(symbol, price) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment