Skip to content

Instantly share code, notes, and snippets.

Testing on Mac

Add to /etc/pf.conf

block out proto udp from any to any
block in proto udp from any to any
pass out proto udp from any to any port 53
pass in proto udp from any to any port 53

To apply:

CockroachDB and Docker Compose

This is the first in a series of tutorials on CockroachDB and Docker Compose

  • Information on CockroachDB can be found here.
  • Information on Docker Compose can be found here
  1. Install Docker Desktop

Because we already have an official CockroachDB docker image, we will use that in our docker-compose.yml file. We recommend you use one of the current tags instead of latest.

@anton-fomin
anton-fomin / bloop.sbt
Last active December 13, 2021 04:21
How to run play framework with bloop
// Should be put into ~/.sbt/1.0/plugins/bloop.sbt
// By default, this file does not do anything.
// If the environment variable BLOOP_ENABLED has the value 'true',
// then this file enables sbt-bloop.
if (System.getenv("BLOOP_ENABLED") == "true") {
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.3.4")
} else Nil
@rowland007
rowland007 / UpstreamRepos.md
Created April 19, 2019 09:47
Describes how to add an upstream remote repo to your forked/cloned repo to get the latest updates.

Keep a Downstream git Repository Current with Upstream Repository Changes

A downstream repository (aka a “fork”) maintainer commonly needs to stay current with upstream work (aka "original"). The case is development continues on the upstream repo while you work on your own origin fork. You want to fetch the upstream changes and apply them to your origin so you don't make conflicts.

image cannot be displayed

The following steps allow you to achieve this on the command line in a local git repository.

Add the Remote Upstream Repository

//
// EXERCISE 4
//
// Create a type class to describe `printLine` and `readLine`.
//
trait Console[F[_]] {
def printLine(line: String): F[Unit]
def readLine: F[String]
}
@aaronlevin
aaronlevin / TLists.scala
Last active November 29, 2020 19:10
Type-aligned, stack-safe lists.
import scala.annotation.tailrec
/**
* A Type-aligned list is a list of functions which can be
* chained together. They are "type-aligned" because their
* types all line. For example, suppose you have the following
* functions:
*
* val foo: Int => String = i => i.toString
* val bar: String => Char = s => s.head
@mrbar42
mrbar42 / README.md
Last active June 24, 2024 12:40
bash scripts to create VOD HLS stream with ffmpeg almighty (tested on Linux and OS X)

running:

bash create-vod-hls.sh beach.mkv

will produce:

    beach/
      |- playlist.m3u8
 |- 360p.m3u8
@cupuyc
cupuyc / puzzle.md
Last active April 10, 2017 12:24
Misspelled lookups: a Grammarly coding puzzle (6 days duration)

Misspelled lookups

Given two strings, S1 and S2, we can define an edit distance as the minimum number of operations required to change S1 to S2.

The operations might be one of the following:

  • delete a character
  • insert a character
  • substitute a character for another character

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.