Skip to content

Instantly share code, notes, and snippets.

@deusaquilus
deusaquilus / script.sh
Created June 2, 2023 17:50
Choopy to Deusaquilus
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="choppythelumberjack@gmail.com"
CORRECT_NAME="Alexander Ioffe"
CORRECT_EMAIL="deusaquilus@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@davidteren
davidteren / nerd_fonts.md
Last active May 7, 2024 06:59
Install Nerd Fonts via Homebrew [updated & fixed]
@calvinlfer
calvinlfer / CustomDiff.scala
Last active March 13, 2022 15:42
This shows how to do a Diff + Merge for any datatype provided you have the appropriate Diff and Merge all the primitive instances used by the datatype. This is done using Shapeless 2.3.3. Diff and Merge go hand-in-hand
// Unhappy with the default behavior of a particular datatype?
// You can override it as you wish, you must write a Diff and merge for the datatype you wish to override
final case class Address(
streetNumber: Int,
streetName: String,
city: String,
country: String
)
import scala.util.Try
/**
* Alternative to unsound construct: "sealed abstract case class"
* see https://gist.github.com/tpolecat/a5cb0dc9adeacc93f846835ed21c92d2
* The solution below is the summary of the comments of the above gist.
*
* Works as is in Scala 2.12 and higher
* In Scala 2.11.12 you have to add -Xsource:2.12
*/
@SystemFw
SystemFw / Q.scala
Created October 9, 2017 23:20
Shapeless: create an HList of functions from case class T to each of its fields
object Q {
import shapeless._, labelled._, ops.record.Selector
trait Accessors[T, I] {
type Out
def value: Out
}
object Accessors {
type Aux[T, I, O] = Accessors[T, I] { type Out = O }
@SystemFw
SystemFw / Conversions.scala
Last active April 23, 2021 07:53
Typed schema conversion with shapeless
object Conversions {
import cats._, implicits._, data.ValidatedNel
import mouse._, string._, option._
import shapeless._, labelled._
private type Result[A] = ValidatedNel[ParseFailure, A]
case class ParseFailure(error: String)
trait Convert[V] {
@bhameyie
bhameyie / SourceCodeGenerator.scala
Last active July 1, 2020 20:47
Only generate tables for a single schema
import slick.codegen.SourceCodeGenerator
import slick.jdbc.JdbcProfile
import slick.model.Model
import scala.concurrent.{Await, ExecutionContext}
import scala.concurrent.duration.Duration
object SourceCodeGenerator {
@kuznero
kuznero / nixos-install.md
Last active June 21, 2023 22:34
Installing NixOS behind corporate proxy

In order to install NixOS behind corporate proxy do the usual stuff but before running nixos-install set this environment variable:

export CURL_NIX_FLAGS="-x http://user:password@proxy:port/"

In addition in case you have ties to cloning from GitHub (like vim plugins), you should export proxy related variables:

export HTTP_PROXY=http://user:password@proxy:port/
@bmc
bmc / StaticFile.scala
Last active September 3, 2021 20:08
I needed code to serve static files from an Akka HTTP server. I wanted to use fs2 to read the static file. Michael Pilquist recommended using streamz to convert from an fs2 Task to an Akka Source. This is what I came up with. (It does actually work.)
object StaticFile {
// Various necessary imports. Notes:
//
// 1. fs2 is necessary. See https://github.com/functional-streams-for-scala/fs2
// 2. streamz is necessary. See https://github.com/krasserm/streamz
// 3. Apache Tika is used to infer MIME types from file names, because it's more reliable and
// fully-featured than using java.nio.file.Files.probeContentType().
//
// If using SBT, you'll want these library dependencies and resolvers:
@Horusiath
Horusiath / example.cs
Last active April 17, 2022 10:27
Generic persistent gateway for Akka.NET at-least-once-delivery semantics
// Delivery mechanism looks like this - if sender wants to reliably deliver payload to recipient
// using at-least-once delivery semantics, it sends that payload wrapped to Messenger actor, which
// is responsible for the persistence and redelivery:
//
// +--------+ +-----------+ +-----------+
// | |--(DeliverOrder<T>)-->| |--(Delivery<T>:1)-->| |
// | | | | /* 2nd attempt */ | |
// | Sender | | Messenger |--(Delivery<T>:2)-->| Recipient |
// | | | | | |
// | | | |<----(Confirm:2)----| |