Skip to content

Instantly share code, notes, and snippets.

@nuttycom
nuttycom / ListAlgebra.hs
Created November 6, 2014 04:11
Haskell list catamorphism
{-# LANGUAGE RankNTypes #-}
module ListAlgebra
( ListAlgebra(..)
) where
newtype ListAlgebra a = ListAlgebra (forall b. b -> (a -> b -> b) -> b)
nil :: ListAlgebra a
nil = ListAlgebra const
import java.util.concurrent.ExecutorService
def fork[A](t: Task[A])(implicit pool: ExecutorService = Strategy.DefaultExecutorService): Task[A] = {
Task async { cb =>
t runAsync { either =>
pool.submit(new Runnable {
def run(): Unit = cb(either)
})
()
@dk8996
dk8996 / HTTPSRedirectFilter.scala
Last active June 25, 2017 20:53
Play Framework Filter for AWS Elastic Load Balancer (forward HTTP to HTTPS)
import com.typesafe.scalalogging.slf4j.Logging
import play.api.mvc._
import scala.concurrent.Future
import play.mvc.Results._
import play.api.libs.concurrent.Execution.Implicits.defaultContext
object HTTPSRedirectFilter extends Filter with Logging {
def apply(nextFilter: (RequestHeader) => Future[SimpleResult])(requestHeader: RequestHeader): Future[SimpleResult] = {
//play uses lower case headers.
@RadoBuransky
RadoBuransky / dist-play-app-initd
Last active March 24, 2020 20:26
Init.d shell script for Play framework distributed application. Provides start, stop, restart and status commands to control applications packaged using standard "play dist" packaging command.
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
/*
* twitter-entities.js
* This function converts a tweet with "entity" metadata
* from plain text to linkified HTML.
*
* See the documentation here: http://dev.twitter.com/pages/tweet_entities
* Basically, add ?include_entities=true to your timeline call
*
* Copyright 2010, Wade Simmons
* Licensed under the MIT license
@pchiusano
pchiusano / queues.markdown
Created December 22, 2013 19:43
Binding to asynchronous processes using scalaz-stream

When creating streams from an asynchronous process, the idiomatic thing is to create a stream from that process at the earliest possible stage, rather than using a queue to invert control after the fact. See the creating streams examples - generally, you just use the Process.eval and Process.repeatEval functions to build a stream by running some asynchronous task repeatedly.

That said, if you have some existing logic that you need to bind to that's already based on callbacks and side effects, you can use the functions in scalaz.stream.async. Here's an example, using a queue to invert control:

import scalaz.stream.async

val (q, src) = async.queue[Int]

// Thread 1
@filipelenfers
filipelenfers / SlickBoneCP.scala
Last active October 18, 2016 07:57
Slick 2.0.0 + BoneCP
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp
import java.util.Date
import scala.slick.driver.MySQLDriver.simple._
//import scala.slick.driver.H2Driver.simple._
//MultipleDB examples, DAL included: https://github.com/slick/slick-examples/blob/2.0.0-M3/src/main/scala/com/typesafe/slick/examples/lifted/MultiDBExample.scala e https://github.com/slick/slick-examples/blob/2.0.0-M3/src/main/scala/com/typesafe/slick/examples/lifted/MultiDBCakeExample.scala
@shajra
shajra / Task.scala
Created August 23, 2013 03:34
integration code between Scalaz and Scala standard concurrency libraries.
import concurrent.{ExecutionContext, Future => SFuture, Promise}
import util.Try
import _root_.scalaz.\/
import _root_.scalaz.concurrent.{Task => ZTask}
object Task {
def fromScala[A]
anonymous
anonymous / Dependencies.scala
Created June 23, 2013 03:53
Here's an SBT build file I work on that I think is pretty clean.
package com.rackspace.dcx.dcorch.build
import sbt._
trait Dependencies {
private object v {
val akka = "2.1.4"
object Predicates {
type Pred[-T] = (T => Boolean)
implicitly[Seq[Int] >:> List[Int]]
implicitly[Pred[Seq[Int]] <:< Pred[List[Int]]] // predicate of seq is a subtype of predicate of list
val hasLength3: Pred[Seq[Int]] = _.size == 3
hasLength3(Vector(1,2,3)) // we can pass any seq to hasLength3
hasLength3(List(1,2,3))