Skip to content

Instantly share code, notes, and snippets.

@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
@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
/*
* 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
@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
@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.
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)
})
()
@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
@darrencauthon
darrencauthon / controller_test.rb
Created November 17, 2014 15:39
Contact Us Form
describe ContactUsController do
let(:params) { {} }
let(:controller) do
c = ContactUsController
c.stubs(:params).returns params
c
end
@BenWhitehead
BenWhitehead / logback.xml
Last active August 29, 2015 14:09
Logback configuration for rolling file appender
<configuration scan="true" scanPeriod="30 seconds">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>app.log.%i.zip</fileNamePattern>
#!/usr/bin/env bash
#
set -e
pushd "$(mktemp -dt scalaz)"
cat >build.sbt <<EOM
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.1.1",