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
private class Http(val address: String) { | |
// Simple class for snagging content from and posting content | |
// to a URL. No error handling. | |
import java.net._ | |
import java.io._ | |
import scala.io._ | |
def get(): String = { | |
val url: URL = new URL(address) |
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
// A sample app demonstrating one way to use actors to manage other | |
// actors created dynamically. Use case: an app that needs to maintain | |
// short-lived connections to remote resources (like a messaging queue). | |
import scala.actors._ | |
import scala.actors.Actor._ | |
class DelegateActor(val id: String) extends DaemonActor { | |
// Represents an actor that does some work, or hangs on to | |
// an external resource, such as a socket connection to an MQ |
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
// Import the magic libraries | |
import scala.xml._ | |
import scala.xml.transform._ | |
// Source xml. In Scala, xml is literal. | |
val xml = | |
<user> | |
<email>joe@example.com</email> |
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
import sbt._ | |
import Keys._ | |
import Project.Initialize | |
import org.fusesource.scalate.TemplateSource | |
import org.fusesource.scalate.TemplateEngine | |
import java.io.File |
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
import sbt._ | |
import Keys._ | |
import Process._ | |
import Project.Initialize | |
import java.io.File | |
object CoffeeScriptPlugin extends Plugin { |
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
// convert a byte into a list of ones and zeros | |
def bits(num: Int): List[Int] = (for (i <- Range(0,8)) yield (((num << i) & 0xff) >>> 7)).toList | |
// given a list, take the first N bits | |
def next(bits: List[Int], numBits: Int) = { | |
val filler = List[Int](8 - numBits) map (_ => 0) | |
val bitList = filler ++ bits.take(numBits) |
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
// Just an example of some code I ended up not using, but which is kinda neat. | |
object Utils { | |
def linesFromFile(file: File) = { | |
io.Source.fromInputStream(getMemoryMappedFileInputStream(file)).getLines | |
} | |
def getMemoryMappedFileInputStream(file: File): InputStream = { |
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
import java.io.File | |
import javax.imageio.ImageIO | |
import java.awt.image.BufferedImage | |
import java.awt.geom._ | |
import java.awt.Color | |
import java.awt.Font | |
import java.awt.Graphics2D | |
import java.util.Date |
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
;; Surely I can do better than this. | |
(defn- ^BigInteger bytes->int | |
[^bytes bytes & {:keys [little-endian] | |
:or {little-endian true}}] | |
(let [b (if little-endian (reverse bytes) bytes)] | |
(->> b | |
(cons (byte 0)) | |
(byte-array) | |
(biginteger)))) |
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
Homebrew 0.9 | |
==> Downloading http://mysql.mirrors.pair.com/Downloads/MySQL-5.1/mysql-5.1.58.tar.gz | |
Already downloaded: /Library/Caches/Homebrew/mysql51-5.1.58.tar.gz | |
/usr/bin/tar xf /Library/Caches/Homebrew/mysql51-5.1.58.tar.gz | |
==> Patching | |
/usr/bin/patch -f -p1 -i 000-homebrew.diff | |
patching file scripts/mysqld_safe.sh | |
Hunk #1 succeeded at 384 (offset 1 line). | |
patching file scripts/mysql_config.sh | |
==> ./configure --without-docs --without-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/mysql51/5.1.58 --localstatedir=/usr/local/var/mysql --sysconfdir=/usr/local/etc --with-plugins=innobase,myisam --with-extra-charsets=complex --with-ssl --without-readline --enable-assembler --enable-thread-safe-client --enable-local-infile --enable-shared --with-partition |