Skip to content

Instantly share code, notes, and snippets.

object ImageProcessor extends Logging {
final case class ImageProcessorException(val message: String) extends Throwable(message) with NoStackTrace
def processAndUpload(srcs: Vector[String],
prefix: String,
watermarks: Set[Watermark],
defaultPhotoFormats: Vector[Int] = Image.defaultFormats)(
implicit sys: ActorSystem,
mat: Materializer): Future[Vector[Image]] = {
import sys.dispatcher
@timothyklim
timothyklim / haskell-records.md
Created April 7, 2017 15:01 — forked from mtesseract/haskell-records.md
Working around Haskell's namespace problem for records

The Problem

Defining records in Haskell causes accessor functions for the record's fields to be defined. There is no seperate namespace for these accessor functions.

The Goal

Be able to

  • use records in Haskell, which share field names.
  • use lenses for accessing these fields
@timothyklim
timothyklim / Morphism.scala
Created November 25, 2016 15:57 — forked from davydkov/Morphism.scala
Scala morphism with shapeless
import shapeless._
import shapeless.labelled._
import shapeless.ops.record.Merger
import shapeless.syntax.SingletonOps
import scala.annotation.implicitNotFound
import scala.collection.generic.CanBuildFrom
import scala.language.experimental.macros
import scala.language.higherKinds
@timothyklim
timothyklim / hkt.rs
Created August 15, 2016 09:22 — forked from 14427/hkt.rs
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
import clang.cindex
import os, textwrap, StringIO
from clang.cindex import Config, Index, CursorKind
clib_scalanative_path = '/Users/timothyklim/Development/scala-native/clib/src/main/scala/scala/scalanative/libc'
scalatypes_map_dict = {
"int": "CInt"
}
#!/bin/sh
#
# This code is GPLv3
HOSTSFILE=hosts
TMPFILE=/tmp/aosp-hosts-file
echo "Updating adblocking hosts file..."
curl "http://winhelp2002.mvps.org/hosts.txt" > $TMPFILE
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
Http()
.singleRequest(HttpRequest(uri = "https://ucarecdn.com/2877682a-c715-4848-8fe2-4ff9fbd7728e/"))
.flatMap(_.entity.dataBytes.runFold(0L)(_ + _.length))
.onComplete(println)
@timothyklim
timothyklim / equality.scala
Created March 8, 2016 23:21 — forked from odersky/equality.scala
Better equality for Scala
import annotation.unchecked.uncheckedVariance
/** The trait of things that can be compared safely */
trait Equals[-T] {
/** A witness of Equals' type parameter. Should only used for
* the constraint in EqlDecorator, hence, @uncheckedVariance should not be a problem.
*/
type EqualsDomain = T @uncheckedVariance
@timothyklim
timothyklim / Crypto.scala
Last active March 21, 2021 19:18
AES encryption/decryption with akka stream
package utils
import akka.stream._
import akka.stream.scaladsl._
import akka.stream.stage._
import akka.util.{ByteString, ByteStringBuilder}
import scala.annotation.tailrec
import java.security.SecureRandom
import java.security.{Key, KeyFactory, PublicKey, PrivateKey}
import java.security.spec.{PKCS8EncodedKeySpec, X509EncodedKeySpec}
@timothyklim
timothyklim / springer-free-maths-books.md
Created December 30, 2015 07:00 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links