Skip to content

Instantly share code, notes, and snippets.

View fedesilva's full-sized avatar
👁️‍🗨️

federico silva fedesilva

👁️‍🗨️
View GitHub Profile
package org.pinky.code.extension.guice;
import com.google.inject.Key
import com.google.inject.servlet._
import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
scala> f@Hedwig:~ $ scala
Welcome to Scala version 2.8.0.r21323-b20100403020201 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import java.lang.Math._
import java.lang.Math._
scala> def hasDivisor(i:Int) = { (2 to sqrt(i).toInt).exists{ x => i%x == 0 } }
hasDivisor: (i: Int)Boolean
@fedesilva
fedesilva / gist:361964
Created April 10, 2010 10:51
Insane! mvn clean
$ mvn clean install
Using Java version: 1.6
[INFO] Scanning for projects...
WAGON_VERSION: 1.0-beta-2
[INFO] ------------------------------------------------------------------------
[INFO] Building specs_2.8.0.Beta1
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
Downloading: http://scala-tools.org/repo-releases/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom
[INFO] Unable to find resource 'org.apache.maven.plugins:maven-clean-plugin:pom:2.2' in repository scala-tools.org (http://scala-tools.org/repo-releases)
/* Recursively compose an arbitrarily long list of functions into a single function. */
function compose() {
/* One function, nothing to compose. */
if(arguments.length == 1)
return arguments[0];
else {
/* Compose the head with the immediate successor. */
var args = arguments;
/* The composition: f(g(x)) */
var f = [function() {
public class Foo {
public String theCurrentWay(SomeData data) {
if (data.getFoo() != null) {
if (data.getFoo().getBar() != null) {
if (data.getBlah() != null) {
return data.getFoo().getBar().getBlah().toString();
}
}
}
return null;
scala> f@Hedwig:~ $ scala
Welcome to Scala version 2.8.0.r21323-b20100403020201 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import java.lang.Math._
import java.lang.Math._
scala> def hasDivisor(i:Int) = { (2 to sqrt(i).toInt).exists{ x => i%x == 0 } }
hasDivisor: (i: Int)Boolean
@fedesilva
fedesilva / autoBoxInOption.scala
Created May 6, 2010 01:06
Autoboxing stuff in Option[T]
f@Hedwig:~$ scala
Welcome to Scala version 2.8.0.r21323-b20100403020201 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
//Some fun
scala> def fun(integer:Option[Int]) = println(integer.getOrElse("None"))
fun: (integer: Option[Int])Unit
// having fun
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
// A simple trait:
trait CascadingActions {
implicit def tToActioneerT[T](t: T) = Actioneer(t)
case class Actioneer[T](tee: T) {
def withAction(action: (T => Unit)): T =
withActions(action)
def withActions(actions: (T => Unit)*): T = {
// Welcome to Scala version 2.7.5.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
// Type in expressions to have them evaluated.
// Type :help for more information.
scala> import dispatch._
import dispatch._
scala> import oauth._
import oauth._