Skip to content

Instantly share code, notes, and snippets.

@pchiusano
pchiusano / diamonds.scala
Created December 8, 2015 20:06
Design of splitting combinators in FS2
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
pchiusano / BSequence.scala
Created November 26, 2013 22:38
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.
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) ms.head.map(Vector(_))
else {
val (l,r) = ms.toIndexedSeq.splitAt(ms.length / 2)
apply2(bsequence(l), bsequence(r))(_ ++ _)
}
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active June 10, 2024 09:43
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

@channingwalton
channingwalton / FizzBuzz.scala
Created October 4, 2012 20:03
FizzBuzz with Scalaz
// Inspired by http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html
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
eleclerc / Solarized (Dark).tmTheme
Created February 25, 2012 00:38
Solarized theme (dark & light) with markdown support for Sublime Text 2 editor
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Solarized (dark)</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@tankchintan
tankchintan / gist:1335220
Last active November 30, 2019 00:17
Procedure for installing and setting Sun JDK Java on Default Amazon Linux AMI
# First verify the version of Java being used is not SunJSK.
java -version
# Get the latest Sun Java SDK from Oracle http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html
wget http://download.oracle.com/otn-pub/java/jdk/7u1-b08/jdk-7u1-linux-i586.rpm
# 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