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
// In response to Slack post "Please explain why Doubles work this way" | |
// | |
// For doubles... | |
// 1.001484375 - 1 = 0.0014843749999999822 | |
// 0.001484375 + 1 = 1.001484375 | |
// | |
// To run, start the repl with `sbt console`, then paste all this in | |
// | |
import java.lang.Double.doubleToRawLongBits | |
import java.lang.Long.{toBinaryString, toHexString} |
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/bash | |
# WORKAROUND (2014-07-16, Marc): Avoids "No scala version specified or detected" | |
# error when Play 2.0.x and 2.3.x projects are both built by same local user. | |
if [ -e "${HOME}/.sbt/boot/other" ]; then | |
rm -rfv ~/.sbt/boot/other | |
rm -v ~/.ivy2/cache/org.scala-sbt/sbt/ivy-0.13.5.xml | |
fi | |
export SBT_OPTS="-Dsbt.repository.config=/etc/sbt/repositories -Dsbt.override.build.repos=true" |
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
/** | |
* ``` | |
* Does JDK8's Optional class satisfy the Monad laws? | |
* ================================================= | |
* 1. Left identity: true | |
* 2. Right identity: true | |
* 3. Associativity: true | |
* | |
* Yes, it does. | |
* ``` |
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 scala.util.{Try, Success, Failure} | |
def f(s: String): Try[Int] = Try { s.toInt } | |
def g(i: Int): Try[Int] = Try { i * 2 } | |
def unit[T](v: T): Try[T] = Success(v) | |
//val v = "1" | |
val v = "bad" | |
val m = Success(v) |
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
//// | |
// Output of running: | |
// $ scala -Xprint:parser -e "val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j" | |
//// | |
// | |
// Picked up _JAVA_OPTIONS: -Xss3m -XX:MaxPermSize=256M | |
// /tmp/scalacmd2064075741948415763.scala:1: error: value map is not a member | |
// of Product with Either[String,(Int, Int)] with Serializable | |
// val e: Either[String, Int] = Right(1); for {i <- e.right; j = i + 1} yield j | |
// ^ |
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/bash | |
## | |
# A script to test our debian package naming policy. | |
# | |
# This script uses `dpkg --compare-versions` to test that provided | |
# sequences of package names are considered to be in ascending order | |
# by Debian's tools. | |
# | |
# Author: Marc Siegel <[email protected]> | |
# Modified: 2013-07-30 |
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 enriching_example | |
import scala.util.control.Exception.allCatch | |
case class StringWithToInt(s: String) { | |
def toIntOpt: Option[Int] = allCatch opt { s.toInt } | |
} | |
implicit def string2stringWithToInt(s: String) = StringWithToInt(s) |
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
CREATE TABLE filler ( | |
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT | |
) ENGINE=Memory; | |
CREATE TABLE t_param ( | |
param INT NOT NULL PRIMARY KEY | |
) ENGINE=Memory; | |
CREATE TABLE t_source ( | |
id INT NOT NULL PRIMARY KEY, |
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
require 'hamster' | |
require 'hamster/experimental/mutable_hash' | |
# a bunch of threads with a read/write ratio of 10:1 | |
num_threads = 100 | |
num_reads_per_write = 10 | |
num_loops = 500 | |
hsh = Hamster.mutable_hash | |
puts RUBY_DESCRIPTION |
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
class Project | |
attr_reader :supervisor | |
# assume supervisor looks like: | |
# ["Harry", "Henderson", "[email protected]"] | |
def initialize(supervisor) | |
@supervisor = supervisor | |
end |
NewerOlder