Skip to content

Instantly share code, notes, and snippets.

View alexy's full-sized avatar

Alexy Khrabrov alexy

View GitHub Profile
@arosien
arosien / SafePassword.scala
Last active September 6, 2020 22:16
Variation of https://alexn.org/snippets/2020/08/27/safe-password.scala.html using cats-effect concurrency primitives.
final case class PasswordValue(value: String) {
override def toString = "PasswordValue(****)"
}
object SafePassword {
def resource[F[_]: Sync](value: String): F[Resource[F, PasswordValue]] =
for {
used <- Ref.of[F, Boolean](false)
chars = value.toCharArray
givePasswordAndNullify = Sync[F].delay {
@zachwaugh
zachwaugh / Makefile
Last active October 6, 2020 03:36
Swift + Sublime Text 3
# I rarely use make, probably a better way to do some/all of this?
SDK=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
SOURCES=main.swift
EXECUTABLE=main
all:
swiftc -sdk $(SDK) $(SOURCES) -o $(EXECUTABLE)
clean:
@mstapp
mstapp / gist:c0f4dfc8c86f521b4910
Last active October 4, 2023 08:18
Install tinydns (djbdns) & daemontools on ubuntu 14.04
# install tinydns (djbdns) & daemontools on ubuntu 14.04
apt-get -y install daemontools
apt-get -y install daemontools-run
apt-get -y install ucspi-tcp
apt-get -y install djbdns
mkdir -p /etc/service
# NOTE: installing daemontools-run takes care of this, else
@betehess
betehess / ammonite-shapeless
Created May 26, 2015 16:43
Using shapeless to drive Ammonite's PPrinter derivation, used to print shapeless values
> runMain ammonite.repl.Repl
[info] Running ammonite.repl.Repl
Loading Ammonite Repl...
@ load.ivy("com.chuusai" %% "shapeless" % "2.1.0")
@ import shapeless._
import shapeless._
@ 1 :: "lol" :: List(1, 2, 3) :: HNil
@viktorklang
viktorklang / Gistard.scala
Last active June 9, 2017 07:27
Gistard — an sbt autoplugin for depending on Gists — such as Gistard itself
/*
Copyright 2015 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software

A Quick and Dirty Lens primer

Why does Lens exist? Well, Haskell records suck, for a number of reasons. I will enumerate them using this sample record.

data User = User { login    :: Text
                 , password :: ByteString
                 , email    :: Text
                 , created  :: UTCTime
 }
trait Show[A]
// These formulations all compile.
class A {
implicit def z1[A]: Show[A] = null
def f[A](implicit z: Show[A]): String = null
f
f[Int]
f[Int](implicitly)
{
"named_patterns" : {
"first_equal" : " = (?:.*?[^{]$)/f",
"first_comma" : ", /f",
"first_colon" : ": /f",
"all_space" : "\\s+/l1l0",
"hocon" : ": (?:.*?[^{]$)/r1l1l1f",
"typed" : "[:]/r0c1l1f",
"bash_var" : "[$][(]|[|][|]|[)]|[#]",
"sbt_operator" : "[&|@#<+:~]+[=][ ]/r1c1l1",
@JuPfu
JuPfu / CSVParboiledParser.scala
Last active October 29, 2015 07:20
A Scala Parboiled2 Grammar for CSV
/*
* Copyright (C) 2014 Juergen Pfundt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ceteri
ceteri / 0.setup.sh
Last active April 24, 2019 11:04
Spark Streaming demo
# using four part files to construct "minitweet"
cat rawtweets/part-0000[1-3] > minitweets
# change log4j properties to WARN to reduce noise during demo
mv conf/log4j.properties.template conf/log4j.properties
vim conf/log4j.properties # Change to WARN
# launch Spark shell REPL
./bin/spark-shell