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 {
@dvf
dvf / change-codec.md
Last active October 10, 2025 01:17
Enable High Quality mode on your headphones (Updated for macOS Catalina)

If you're using a high-end bluetooth headset on your Macbook Pro it's likely your mac is using an audio codec which favors battery efficiency over high quality. This results in a drastic degradation of sound, the SBC codec is the likely culprit, read more about it here.

Find out what codec you're using

  1. Play a song on your headphones
  2. Option (⌥) click the Bluetooth button at the top of your screen Inspect the Bluetooth Coded
  3. If you're using AAC or aptX, you can stop here—those are the highest quality codecs.

Change your codec to AAC or aptX

@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