This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TypelevelPolymorphic extends App { | |
object square extends Poly { | |
import scala.language.reflectiveCalls | |
implicit val is = at[Int] { i => i * i } | |
implicit val fs = at[Float] { f => f * f } | |
implicit val ds = at[Double] { d => d * d } | |
} | |
trait Poly { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escapeNonASCII(str: String) : String = { | |
val result = new java.lang.StringBuilder | |
var i = 0 | |
while(i < str.length) { | |
val cp: Int = Character.codePointAt(str, i) | |
val n : Int = Character.charCount(cp) | |
if(n > 1) { | |
i += n-1 | |
if(i >= str.length) throw new IllegalArgumentException("truncated unexpectedly") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def addNaturals(nats: List[Int]): Int = { | |
require(nats forall (_ >= 0), "List contains negative numbers") | |
nats.foldLeft(0)(_ + _) | |
} ensuring(_ >= 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
organization := "mathminds" | |
name := "java-only-project" | |
scalaVersion in ThisBuild := "2.12.8" | |
scalacOptions in ThisBuild += "-target:jvm-1.8" | |
javacOptions in ThisBuild ++= Seq("-source", "1.8", "-target", "1.8") | |
// Enables publishing to maven repo | |
publishMavenStyle := true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Group objects in categories. Requires ordered input. */ | |
def groups[A, K](s: Iterable[A], acc: Stream[Iterable[A]] = Stream.empty[Iterable[A]]) | |
(implicit groupKeyOf: (A => K)): Iterable[Iterable[A]] = { | |
s match { | |
case first :: _ => | |
val (left, right) = s.span(p => groupKeyOf(p) == groupKeyOf(first)) | |
groups(right, acc :+ left)(groupKeyOf) | |
case Nil => acc | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rgomes.info.lang | |
import utest._ | |
object OptionalSyntaxSpec extends TestSuite { | |
trait OptionalWrapper[T] { | |
def wrap(data: T): Option[T] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sleep 300 | |
[[ -d /etc/.git ]] && cd /etc && \ | |
[[ $(git status --short | wc -l) -gt 0 ]] && \ | |
git stash && \ | |
logger etckeeper-roolback: reverted /etc to a previous state && \ | |
sync; sync; sync && \ | |
reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function digitalocean_json_droplet_create { | |
local label=$1 | |
local hostname=$2 | |
local domainname=$3 | |
local region=$4 | |
local tags=$5 | |
local size=$6 | |
local image=$7 | |
local tags=$(echo "${tags}" | digitalocean_json_from_csv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fqdn: Option[String] = { | |
val marker = "domain " | |
def ipv4(canonical: String): Boolean = { | |
def isAllDigits(x: String) = x forall Character.isDigit | |
canonical != null && !canonical.isEmpty && { | |
val parts = canonical.split('.') | |
parts.length > 1 && !parts.map(part => isAllDigits(part)).reduce(_ & _) | |
} | |
} | |
val addr: java.net.InetAddress = java.net.InetAddress.getLocalHost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
####################################################################### | |
## ## | |
## A simple, lightweight and self contained alternative to ddclient. ## | |
## ## | |
####################################################################### | |
# | |
# Configuration |