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 Control.Monad (mfilter) | |
import Data.Char (digitToInt) | |
charToInt :: Char -> Maybe Int | |
charToInt = fmap digitToInt . justIf (`elem` ['0'..'9']) | |
justIf :: (a -> Bool) -> a -> Maybe a | |
justIf predicate = mfilter predicate . Just |
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
Verifying that +chrismartin is my Bitcoin username. You can send me #bitcoin here: https://onename.io/chrismartin |
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 java.util.ArrayList; | |
import java.util.List; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class QuoteSplitter { | |
public static void main(String[] args) throws Exception { | |
String s = "software term \"on the fly\" and \"synchron\""; | |
System.out.println(parse(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
delete = lambda k: lambda m: {k_: v for k_, v in m.items() if k_ != k} | |
delete = lambda k: lambda m: {k_: m[k] for k_ in m if k_ != k} | |
delete = lambda k: lambda m: dict(filter(lambda i: i[0] != k, m.items())) | |
def delete(k): | |
return lambda m: {k_: v for k_, v in m.items() if k_ != k} | |
def delete(k): |
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
from collections import namedtuple | |
from decimal import Decimal | |
satoshi_per_bit = 100 | |
satoshi_per_bitcoin = 10**8 | |
class Satoshi(namedtuple('Satoshi', ('satoshi',))): | |
""" | |
satoshi: int - the smallest currency denomination |
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.collection.convert.WrapAsScala._ | |
import org.openqa.selenium.WebDriver | |
import org.openqa.selenium.support.ui.ExpectedCondition, ExpectedConditions} | |
def mapExpectedCondition[A, B](x: ExpectedCondition[A], f: A => B): | |
ExpectedCondition[B] = new ExpectedCondition[B] { | |
override def apply(input: WebDriver): B = f(x(input)) } | |
def xpathExists(xpath: String): ExpectedCondition[Seq[WebElement]] = | |
mapExpectedCondition[java.util.List[WebElement], Seq[WebElement]]( |
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 cfc.scraper.console | |
import akka.actor.{ActorRef, Actor} | |
import akka.camel._ | |
class ConsoleReader(writer: ActorRef) extends Actor with Consumer { | |
val endpointOptions = Seq( | |
"promptMessage" -> "> ", | |
"promptDelay" -> "50", |
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.concurrent.duration.{Deadline, FiniteDuration} | |
import scala.util.control.NonFatal | |
def retry[A](duration: FiniteDuration, delay: FiniteDuration) | |
(f: => A)(on: PartialFunction[Throwable, _]): A = { | |
val deadline: Deadline = (duration.fromNow) | |
var lastThrown: Throwable = null | |
while (deadline.hasTimeLeft()) { | |
try { return f } catch { | |
case NonFatal(e) => |
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 ch.qos.logback.classic.LoggerContext | |
import ch.qos.logback.classic.encoder.PatternLayoutEncoder | |
import ch.qos.logback.classic.spi.ILoggingEvent | |
import ch.qos.logback.core.FileAppender | |
import com.typesafe.config.Config | |
import org.slf4j.Logger.ROOT_LOGGER_NAME | |
import org.slf4j.LoggerFactory.{getILoggerFactory, getLogger} | |
object Logback { |
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
try: | |
import urlparse | |
except ImportError: | |
import urllib.parse as urlparse |