JAVA
List<Integer> even = new ArrayList<Integer>();
for (String num : numbersAsStrings) {
try {
int parsedInt = Integer.parseInt(num);
if (parsedInt % 2 == 0) {
ints.add(parsedInt);
}
/** | |
* CSS bar graph with Positive and Negative values | |
*/ | |
.graph { | |
width: 100px; | |
border: 1px solid #aeaeae; | |
background-color: #eaeaea; | |
} | |
/* Start of "Micro clearfix" */ | |
#!/usr/bin/perl | |
use strict; | |
sub min { | |
my ($a, $b) = @_; | |
if($a < $b) { return $a; } | |
else { return $b; } | |
} |
JAVA
List<Integer> even = new ArrayList<Integer>();
for (String num : numbersAsStrings) {
try {
int parsedInt = Integer.parseInt(num);
if (parsedInt % 2 == 0) {
ints.add(parsedInt);
}
package utils | |
import scala.concurrent.duration.FiniteDuration | |
import scala.concurrent.duration._ | |
import play.api.Application | |
import collection.JavaConversions._ | |
object ConfigString { | |
implicit class ConfigStr(s: String) { | |
def configOrElse(default: FiniteDuration)(implicit app: Application): FiniteDuration = |
import scala.concurrent._ | |
import scala.concurrent.{ Future, Await } | |
import scala.util.Random | |
import play.api.libs.concurrent.Execution.Implicits.defaultContext | |
import scala.util.{ Try, Success, Failure } | |
import scala.concurrent.duration._ | |
import play.api.libs.iteratee._ | |
def takeOrDeadline[E](count: Int, deadline: Deadline): Enumeratee[E, E] = new Enumeratee.CheckDone[E, E] { |
trait ID | |
case class SequentialID(id: Int) extends ID | |
case class OtherID(id: Int) extends ID | |
case class User(val id: ID, val b: Int, val c: Int) | |
object UserId { | |
def unapply(w: User) = w match { | |
case u @ User(SequentialID(id), _, _) => Some(u, id) |
object test { | |
//the companion object, with functions to help in creating readers | |
object Reader { | |
implicit def reader[C, R](block: C => R) = Reader[C, R](block) | |
def pure[From, To](a: To) = Reader((c: From) => a) | |
} |
object test { | |
/** | |
* The companion object | |
*/ | |
object Reader { | |
/** | |
* automatically wrap a function in a reader | |
*/ |
/** | |
* A monad to abstract dependencies in the code, see https://coderwall.com/p/kh_z5g | |
*/ | |
object Reader { | |
/** | |
* an implicit to convert a function A => B in a Reader[A, B] | |
*/ | |
implicit def reader[C, R](block: C => R): Reader[C, R] = Reader(block) |
import scala.collection._ | |
import scala.collection.generic._ | |
import scala.concurrent.{ Future, ExecutionContext } | |
/** | |
* a Typeclass representing a class that can map and flatMap (collections, Option, Future..). | |
* effectively, it's a Monad without enforcing the axioms of a Monad. | |
*/ | |
trait CanMap[A, B, M[_]] { | |
def map(l: M[A])(f: A => B): M[B] |