Skip to content

Instantly share code, notes, and snippets.

pchiusano / diamonds.scala
Created Dec 8, 2015
Design of splitting combinators in FS2
View diamonds.scala
package fs2
import util.Monad
import Step._
import java.util.concurrent.atomic.AtomicLong
object diamond {
* Pass elements of `s` through both `f` and `g`, then combine the two resulting streams.
pchiusano / BSequence.scala
Created Nov 26, 2013
A 'balanced' version of sequencing, which realistically avoids stack overflow errors for any finite Applicative. The Applicative laws (specifically associativity and right/left identity) ensure this yields the same result as the usual right-fold based version.
View BSequence.scala
trait Applicative[F[_]] {
/** 'Balanced' sequencing, to avoid SOE. */
def bsequence[A](ms: Seq[F[A]]): F[IndexedSeq[A]] = {
if (ms.isEmpty) point(Vector())
else if (ms.size == 1)
else {
val (l,r) = ms.toIndexedSeq.splitAt(ms.length / 2)
apply2(bsequence(l), bsequence(r))(_ ++ _)
scy /
Last active May 17, 2022
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

View FizzBuzz.scala
// Inspired by
object FizzBuzz extends App {
import scalaz._
import Scalaz._
def fizzbuzz(i: Int) = ((i % 3 == 0) option "fizz") |+| ((i % 5 == 0) option "buzz") | i.shows
for (i <- 1 to 100) {println(i + " " + fizzbuzz(i))}
eleclerc / Solarized (Dark).tmTheme
Created Feb 25, 2012
Solarized theme (dark & light) with markdown support for Sublime Text 2 editor
View Solarized (Dark).tmTheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<string>Solarized (dark)</string>
tankchintan / gist:1335220
Last active Nov 30, 2019
Procedure for installing and setting Sun JDK Java on Default Amazon Linux AMI
View gist:1335220
# First verify the version of Java being used is not SunJSK.
java -version
# Get the latest Sun Java SDK from Oracle
# Rename the file downloaded, just to be nice
mv jdk-7u1-linux-i586.rpm\?e\=1320265424\&h\=916f87354faed15fe652d9f76d64c844 jdk-7u1-linux-i586.rpm
# Install Java