(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| #!/bin/bash | |
| # Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/ | |
| set -e | |
| sourceApp="$1" | |
| targetApp="$2" | |
| while read key value; do |
| import scala.concurrent.duration._ | |
| import scala.concurrent.ExecutionContext | |
| import scala.concurrent.Future | |
| import akka.pattern.after | |
| import akka.actor.Scheduler | |
| /** | |
| * Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown, | |
| * in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through | |
| * the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure. |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import scala.util._ | |
| import java.security.SecureRandom | |
| import java.security.MessageDigest | |
| /* | |
| * Generates a Bearer Token with a length of | |
| * 32 characters (MD5) or 64 characters (SHA-256) according to the | |
| * specification RFC6750 (http://tools.ietf.org/html/rfc6750) | |
| * | |
| * Uniqueness obtained by hashing system time combined with a |
| - What do Etcd, Consul, and Zookeeper do? | |
| - Service Registration: | |
| - Host, port number, and sometimes authentication credentials, protocols, versions | |
| numbers, and/or environment details. | |
| - Service Discovery: | |
| - Ability for client application to query the central registry to learn of service location. | |
| - Consistent and durable general-purpose K/V store across distributed system. | |
| - Some solutions support this better than others. | |
| - Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state. | |
| - Centralized locking can be based on this K/V store. |
| [Unit] | |
| Description=Service discovery for %i | |
| After=%i.service | |
| Requires=%i.service | |
| [Service] | |
| Restart=always | |
| Environment="SLEEP=5" | |
| Environment="TTL=10" | |
| Environment='FORMAT="{{ .NetworkSettings.IPAddress }}"' |
| #!/usr/bin/env scalas | |
| /*** | |
| scalaVersion := "2.11.7" | |
| libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.4.6" | |
| */ | |
| import play.core.server._ | |
| import play.api.routing.sird._ | |
| import play.api.mvc._ |
A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)
I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.
A functor is something that supports map.
Small gist with some demo trait that shows an example on how to loop through json
object and change values with circe in Scala.
Code example you can find below at circe-loop-json-object-example.scala.
The input JSON for test is kinda in in DynamoDB dump format: