Skip to content

Instantly share code, notes, and snippets.

View cvogt's full-sized avatar

Jan Christopher Vogt cvogt

  • Symbiont.io
View GitHub Profile
@cvogt
cvogt / gist:0b681c6edfce504ca3553b336ca55ef7
Created January 9, 2019 19:56 — forked from jfeilbach/gist:fd109c7dbc9798ce6e47358b82d0be76
DNS over TLS (knot resolver) setup using 1.1.1.1 on macOS
# Configuring DNS-over-TLS on macOS
# Worked on macOS 10.13.4
brew -v update
brew -v doctor
# Next two commands are optional
sudo chown -R $(whoami) $(brew --prefix)/*
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
# Install DNS client
brew install knot-resolver
# Should be installed to something like: /usr/local/Cellar/knot-resolver/2.3.0/sbin/kresd
@cvogt
cvogt / vimeo-download.py
Last active December 26, 2018 08:29 — forked from alexeygrigorev/vimeo-download.py
Downloading segmented video from vimeo
#!/usr/bin/env python2.7
# https://gist.github.com/cvogt/1e46597e39bfe0e0aee8d5348123ca03
# based on https://gist.github.com/alexeygrigorev/a1bc540925054b71e1a7268e50ad55cd#file-vimeo-download-py
# also see https://github.com/eMBee/vimeo-download
import requests
import base64
import sys
from tqdm import tqdm
@cvogt
cvogt / foo.scala
Created February 1, 2018 18:43
versioned serializers in scala
case class Foo( bar: Bar )
case class Bar( bar: Baz )
case class Baz( bar: Booyah )
case class Booyah( i: Int, s: String )
object V1Serializers{
implicit def FormatFoo[Foo] = ...
implicit def FormatBar[Bar] = ...
implicit def FormatBaz[Baz] = ...
implicit def FormatBooyah[Booyah] = ...
@cvogt
cvogt / defaults-and-copy-ideas.scala
Last active February 22, 2017 13:51
Scala language proposals for defaults, .copy and overrides
// DEFAULT VALUES
def foo(str: String = "test") = ???
assert( foo.str == "test" ) // new: named access to default values
case class Bar(str: String = "test")
assert( Bar.apply.str == "test" ) // same for case classes via .apply method
// REPETIION-FREE .copy (aka lenses light)
package com.pretend.myforklift
import com.liyaos.forklift.slick.{ SlickCodegen, SlickMigrationCommandLineTool, SlickMigrationCommands, SlickMigrationManager }
import scala.io.StdIn
trait MyMigrationCommands extends SlickMigrationCommands
with MyMigrationFilesHandler {
this: SlickMigrationManager with SlickCodegen =>
package tut
import java.io.{ OutputStream, FilterOutputStream }
// FilterOutputStream that removes ANSI escapes. This should be fairly efficient, I guess, since
// it's all case switches on constants. Can inline more if needed but it seems fine. For the
// record, the format is ESC '[' digits (';' digits)* terminal
case class AnsiFilterStream(os: OutputStream) extends FilterOutputStream(os) {
case class State(apply: Int => State)

Getting Started in Scala

This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere…  I hope to present the information you need without assuming anything.

Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!

One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.

Getting the JVM

object PartiallyDynamicConfig{
def main(args: Array[String]): Unit = {
Application.run(
Config(
sys.props.get("db.host") getOrElse "db.test-server.com",
10000
)
}
}
object DynamicConfig{
def main(args: Array[String]): Unit = {
Application.run(
Config(
sys.props.get("db.host").get,
10000
)
}
}
object SwitchableConfig{
def main(args: Array[String]): Unit = {
val config = System.getProperty("config") match {
case "test" => Config("db.test-server.com",10000)
case "production" => Config("db.production-server.com",12345)
case _ => throw new Exception("unknown config: "+config)
}
Application.run( config )
}
}