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
// Reference: http://stackoverflow.com/questions/6803211/whats-the-difference-between-multiple-parameters-lists-and-multiple-parameters | |
// 1. The multiple arguments lists allow the method to be used in the place of a partially applied function: | |
object NonCurr { | |
def tabulate[A](n: Int, fun: Int => A) = IndexedSeq.tabulate(n)(fun) | |
} | |
NonCurr.tabulate[Double](10, _) // not possible | |
val x = IndexedSeq.tabulate[Double](10) _ // possible. x is Function1 now | |
x(math.exp(_)) |
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 com.ning.http.client._ | |
import dispatch._, Defaults._ | |
val requestTimeoutInMs = 5000 | |
val allowSelfSignedSSLCertificate = true | |
val builder = new AsyncHttpClientConfig.Builder() | |
builder | |
.setAllowPoolingConnections(true) | |
.setRequestTimeout(requestTimeoutInMs) |
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
// Default way of loading language bundle in Scala Lift | |
// Relying on language bundle file(s) to be found in src/main/resources/ | |
// LiftRules.resourceNames = List("languageBundle_en_AU") | |
val appConfDir = System.getProperty("appConfigDirectory") | |
LiftRules.resourceBundleFactories.prepend { | |
case (key, locale) => { | |
val file = new File(appConfDir) | |
val urls = Array(file.toURI.toURL) | |
val loader = new URLClassLoader(urls) |
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
// :*_ tells the compiler to pass each element of arr as its own argument to echo, rather than all of it as a single argument. | |
// It is useful when converting list to Map in Scala | |
var mutableMapInstanceOfItemToBoolean = scala.collection.mutable.Map(arrayOfSomeSort.values.toList.map(item => item -> false):_*) |
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
################################### | |
#########Encrypt example########### | |
################################### | |
use Data::Random qw( rand_chars ); | |
use Crypt::TripleDES; | |
my $password = q{password}; | |
my $password_len = length $password; |
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
/*******************************/ | |
/***** Implicit conversion *****/ | |
/*******************************/ | |
// If one calls a method m on an object o of a class C, and that class does not support method m, | |
// then Scala will look for an implicit conversion from C to something that does support m. | |
// Use to automatically convert a value from one type to another | |
val value:BigInt = 1 | |
// What actually happened is: |
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
package otherscope { | |
class Foo { | |
// a method that takes a function and a string, and passes the string into | |
// the function, and then executes the function | |
def exec(f:(String) => Unit, name: String) { | |
f(name) | |
} | |
} | |
} |
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
sodo yum install perl | |
sudo yum install bzip2 | |
sudo yum install patch | |
sudo yum groupinstall 'Development Tools' | |
\curl -L http://install.perlbrew.pl | bash |
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
// cake pattern with self-type annotation | |
// ======================= | |
// service interfaces | |
trait OnOffDeviceComponent { | |
val onOff: OnOffDevice | |
trait OnOffDevice { | |
def on: Unit | |
def off: Unit | |
} |
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
// Consider the method tabulate which forms an array from the results of applying a given function f on a range of numbers from 0 until a given length. | |
// Up to Scala 2.7, tabulate could be written as follows: | |
def tabulate[T](len: Int, f: Int => T) = { | |
val xs = new Array[T](len) | |
for (i <- 0 until len) xs(i) = f(i) | |
xs | |
} | |
// In Scala 2.8 this is no longer possible, because runtime information is necessary to create the right representation of Array[T]. |
OlderNewer