This file contains hidden or 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
# Get a printable version of all properties in an object. Ignores function | |
# properties. DO NOT MAKE THIS A PROPERTY OF Object! | |
window.objectToString = (obj) -> | |
t = typeof obj | |
if (t is "number") or (t is "boolean") | |
"#{obj}" | |
else if window.isArray(obj) | |
window._arrayToString(obj) | |
else if t is "string" | |
'"' + obj + '"' |
This file contains hidden or 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 org.clapper.sbt.lwm.LWM._ | |
object TestBuild extends Build { | |
override lazy val projects = Seq(root) | |
lazy val root = Project( | |
"root", file(".") | |
).settings (LWM.settings : _*).settings( | |
LWM.targetDirectory in LWM.Config <<= baseDirectory(_ / "target2") |
This file contains hidden or 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 inspect | |
def mixin(cls, *funcs): | |
""" | |
Mix the specified class into the current class. If function names (as | |
strings) are passed, then only those functions are mixed in. | |
mixin() MUST be called within a class definition. | |
Example: |
This file contains hidden or 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
# Ties a text <input> element and a <select> together, so that whatever | |
# is typed in the <input> filters the <select> list, dynamically. Assumes | |
# jQuery. | |
# | |
# DON'T modify the contents of the <select> list after binding the filter! | |
# | |
# Parameters | |
# | |
# inputSelector - jQuery selector string for the <input> | |
# selectSelector - jQuery selector string for the <select> |
This file contains hidden or 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
module RFC1918 | |
def is_rfc1918_address(ip) | |
unless ip =~ /^(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})$/ | |
raise "#{ip} is not an IP address" | |
end | |
octets = [$1, $2, $3, $4].map &:to_i | |
raise "#{ip} is a bad IP address" unless octets.all? {|o| o < 256} | |
# The Internet Assigned Numbers Authority (IANA) has reserved the |
This file contains hidden or 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 scala.util.continuations._ | |
/** Functions that can be used to simulate Python-style generators. | |
* Adapted liberally from Rich Dougherty's solution, as outlined in | |
* Stack Overflow: [[http://stackoverflow.com/questions/2201882#2215182]] | |
* | |
* Example usage: | |
* | |
* {{{ |
This file contains hidden or 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
// NOTE: With SBT 0.12, the ArtifactoryOnline repo is in the list of default repos. Including it again causes | |
// barfage. But, it's necessary if you're also using 0.11 somewhere and specifying plugins here. (NOTE: The | |
// Play Framework currently uses SBT 0.11.3, so it counts.) | |
// | |
// | |
// Conditionally adding the repo only for 0.11.x solves the problem. | |
resolvers <++= (sbtVersion) { sbtV => | |
val af = "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/" | |
if (sbtV.startsWith("0.11")) | |
Seq(Resolver.url("sbt-plugin-releases", new URL(af))(Resolver.ivyStylePatterns)) |
This file contains hidden or 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
case class Article(...); | |
object Article { | |
import DBUtil._ | |
def delete(id: Long): Either[String, Boolean] = { | |
withTransaction { implicit connection => | |
SQL("DELETE FROM comments WHERE article_id = {id}").on("id" -> id).executeUpdate() | |
SQL("DELETE FROM appusers WHERE id = {id}").on("id" -> id).executeUpdate( ) | |
Right(true) |
This file contains hidden or 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
implicit class UpCaser(val sc: StringContext) extends AnyVal { | |
def u(args: Any*): String = { | |
val strings = sc.parts.iterator | |
val expressions = args.iterator | |
var buf = new StringBuffer(strings.next) | |
while (strings.hasNext) { | |
buf append expressions.next | |
buf append strings.next | |
} |