Skip to content

Instantly share code, notes, and snippets.

Pierre Andrews Mortimerp9

Block or report user

Report or block Mortimerp9

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Mortimerp9
Mortimerp9 / dabblet.css
Created Oct 18, 2012
CSS bar graph with Positive and Negative values
View dabblet.css
/**
* CSS bar graph with Positive and Negative values
*/
.graph {
width: 100px;
border: 1px solid #aeaeae;
background-color: #eaeaea;
}
/* Start of "Micro clearfix" */
@Mortimerp9
Mortimerp9 / rgbafallback.pl
Created Nov 8, 2012
This is a very rough perl script that will go through a css file and find the possible rgba statements, it will then insert a fallback hex value before the rgba statement. As this was tailored to a particular use case, it only deals with background color
View rgbafallback.pl
#!/usr/bin/perl
use strict;
sub min {
my ($a, $b) = @_;
if($a < $b) { return $a; }
else { return $b; }
}
@Mortimerp9
Mortimerp9 / gist:4985630
Last active Dec 13, 2015
Java vs Scala list operation from Raúl Raja Martínez + dealing with an exception
View gist:4985630

JAVA

List<Integer> even = new ArrayList<Integer>();
for (String num : numbersAsStrings) {
 try {
  int parsedInt = Integer.parseInt(num);
  if (parsedInt % 2 == 0) {
    ints.add(parsedInt);
  }
@Mortimerp9
Mortimerp9 / ConfigString.scala
Created Mar 26, 2013
Shortcuts for configuring Play2 Applications in scala
View ConfigString.scala
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 =
@Mortimerp9
Mortimerp9 / asSoonAsPossibleEnumeratee
Created Mar 31, 2013
an experiment in pushing the next Future that is ready in an enumerator to serve results as they are computed with Play Framework.
View asSoonAsPossibleEnumeratee
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] {
@Mortimerp9
Mortimerp9 / gist:5364769
Created Apr 11, 2013
example custom matcher
View gist:5364769
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)
View variantworksheet.scala
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)
}
View ReaderCovariance.scala
object test {
/**
* The companion object
*/
object Reader {
/**
* automatically wrap a function in a reader
*/
@Mortimerp9
Mortimerp9 / readerwithtooling.scala
Created Apr 14, 2013
An implementation of the Reader Monad in scala, with correct type variance and some implicit utils to simplify the daily use of Readers, In particular with Future.
View readerwithtooling.scala
/**
* 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)
@Mortimerp9
Mortimerp9 / CanMap.scala
Created Apr 16, 2013
A generic implementation of Reader with a naive adhoc implementation of a Monad typeclass. This is a companiong code for this post: https://coderwall.com/p/-egcfq
View CanMap.scala
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]
You can’t perform that action at this time.