Skip to content

Instantly share code, notes, and snippets.

View avalade's full-sized avatar
🌴
On vacation

Aaron D. Valade avalade

🌴
On vacation
View GitHub Profile
@lihaoyi
lihaoyi / gist:1ebdd89b065a741a1ea72b5d780b9ab1
Last active January 2, 2017 20:01
Setting up a "Walk through pre-loaded example snippets every time you press spacebar" experience in the Ammonite REPL
lihaoyi Ammonite$ amm
Loading...
Welcome to the Ammonite Repl 0.8.0
(Scala 2.11.8 Java 1.8.0_112)
@ {
val funnyFilter = ammonite.terminal.Filter.simple(" ")((b, c, m) =>
if (FunnyFrontEnd.nextLine == Nil) (b.take(c) ++ " " ++ b.drop(c), c+1)
else {
val head :: tail = FunnyFrontEnd.nextLine
FunnyFrontEnd.nextReader = new java.io.StringReader(head)

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@runarorama
runarorama / gist:78c8fefbab74701afab3
Last active June 24, 2018 17:06
Playing around with "Finally Tagless, Partially Evaluated" in Scala
// Finally tagless lambda calculus
object Final {
def varZ[A,B](env1: A, env2: B): A = env1
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2)
def b[E](bv: Boolean)(env: E): Boolean = bv
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env)
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env))
def testf1[E,A](env: E): Boolean =
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env)
@pchiusano
pchiusano / partask.scala
Created February 12, 2014 22:10
Applicative for scalaz.concurrent.Task that 'automatically' parallelizes the applicative operations
import scalaz.Applicative
import scalaz.concurrent.Task
/**
* This `Applicative[Task]` runs tasks in parallel, by defining
* `ap` and `apply2` in terms of `mapBoth`. This differs from the
* default `Applicative[Task]`, where effects are sequenced
* deterministically, in left to right order.
*/
val T = new Applicative[Task] {
@elithrar
elithrar / wale_postgres_recovery.md
Last active May 3, 2021 15:38
WAL-E + Postgres 9.x (single server + DB) Setup and Recovery

A quick "how to" on what you need to do to both setup AND recover a single-server PostgreSQL database using WAL-E

  • WAL-E: https://github.com/wal-e/wal-e
  • Assuming Ubuntu 12.04 LTS ("Precise")
  • We'll be using S3. Make sure you have an IAM in a group with GetObject, ListBucket and PutObject on the bucket you want to use (and that it's not public).

Setup:

  1. These packages:
@GedowFather
GedowFather / aws_vpn_between_vpcgw_and_debian_with_nat.sh
Created January 24, 2014 03:17
BashScript for connecting VPN between VPC G/W and Debian Linux. Connecting from Client to EC2, using NAT on VPN.
#!/bin/bash
#
# Setup VPN between Debian Linux and VPC G/W.
# How to use : ./this_script.sh Generic.txt
#
# For connecting IPsec VPN, you need to allow these connections.
# If VPN has global address, you change FORWARD to OUTPUT.
#
# ex) iptables -A FORWARD -p udp --dport 500 -j ACCEPT
# iptables -A FORWARD -p tcp --dport 500 -j ACCEPT
@viktorklang
viktorklang / NettyChannelFutureToScalaFuture.scala
Created December 19, 2012 16:57
Shows how you can use the Promise API of SIP-14 to bridge between Netty ChannelFutures and scala.concurrent.Future
object NettyFutureBridge {
import scala.concurrent.{ Promise, Future }
import scala.util.Try
import java.util.concurrent.CancellationException
import org.jboss.netty.channel.{ Channel, ChannelFuture, ChannelFutureListener }
def apply(nettyFuture: ChannelFuture): Future[Channel] = {
val p = Promise[Channel]()
nettyFuture.addListener(new ChannelFutureListener {
def operationComplete(future: ChannelFuture): Unit = p complete Try(
@patriknw
patriknw / PeekMailbox.scala
Created November 21, 2012 14:20
PeekMailbox example
package example
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
import akka.actor.ActorContext
import akka.actor.ActorRef
import akka.actor.ActorSystem
@folone
folone / gist:3911559
Created October 18, 2012 12:43
Reader exercise (inspired by gist from @tonymorris: https://gist.github.com/3884189)
case class Reader[T, +A](run: T ⇒ A) {
def map[B](f: A ⇒ B): Reader[T, B] =
Reader((r: T) ⇒ f(run(r)))
def flatMap[B](f: A ⇒ Reader[T, B]): Reader[T, B] =
Reader((r: T) ⇒ f(run(r)).run(r))
def &&&[B](x: Reader[T, B]): Reader[T, (A, B)] =
for {
a ← this
@tmcw
tmcw / togeo.py
Created August 11, 2012 18:53
geo-assign any arbitrary image to a geotiff usable in tilemill
import subprocess
import sys, re
MERC = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
infile = sys.argv[1]
info_output = subprocess.Popen(['gdalinfo', infile], stdout=subprocess.PIPE).communicate()[0]
size_is_re = re.compile('Size is (?P<width>\d+), (?P<height>\d+)')
size_is = filter(lambda x: x, map(lambda x: size_is_re.match(x), info_output.split('\n')))