Skip to content

Instantly share code, notes, and snippets.

View ticean's full-sized avatar

Ticean Bennett ticean

View GitHub Profile
@jackrusher
jackrusher / seq-primer.clj
Created June 1, 2021 12:55
Condensed visual tutorial in #Bauhaus style for a subset of the #Clojure seq API (inspired by similar JS tweets)
(def ■ '■)
(def ▲ '▲)
(def ● '●)
(first [● ■ ▲]) ; ●
(second [● ■ ▲]) ; ■
(nth [● ■ ▲] 2) ; ▲
(rest [● ■ ▲]) ; (■ ▲)
(last [● ■ ▲]) ; ▲
(butlast [● ■ ▲]) ; (● ■)
@gvenzl
gvenzl / TestDatabaseSetup.md
Last active May 24, 2023 08:54
Setup scripts for test databases for Oracle, MySQL, Postgres, SQL Server, and Db2
@jborichevskiy
jborichevskiy / jon-roam-daily-template.md
Last active August 31, 2022 04:41
The daily template I use for Roam Research https://roamresearch.com/
  • Weekly Agenda (created on a different day, and embedded with /Block Reference)
  • [[Morning Questions]]
    • {{[[slider]]}} How many hours of sleep did I get?
    • What's one thing top of mind today?
    • What's the one thing I need to get done today to make progress?
    • Review #[[Index: Questions]] #values
  • Agenda
    • {{[[TODO]]}} Morning walk #goal-health #habit
    • {{[[TODO]]}} Check calendar for scheduled events
  • {{[[TODO]]}} Morning focus hour

This logback configuration is an example of diverting debug level logs for a specific package to a separate file, while maintaining info level in the main log. This allows viewing all package logs in context, and then when an info or warn level log appears, you can switch to the debug log and see that line in context with debug statements.

This is particularly useful for debugging a new or troublesome package in production without cluttering up your main log stream.

The main appender is the primary appender to which all application logs are

(ns mock-avro-example
(:require
[clojure.data.json :as json]
[jackdaw.streams :as k]
[jackdaw.serdes.avro :as avro]
[jackddaw.serdes.avro.schema-registry :as reg]
[jackdaw.test :as jdt]))
(def foo-schema
{:type :record
@ericnormand
ericnormand / 00_script.clj
Last active January 6, 2024 07:13
Boilerplate for running Clojure as a shebang script
#!/bin/sh
#_(
#_DEPS is same format as deps.edn. Multiline is okay.
DEPS='
{:deps {clj-time {:mvn/version "0.14.2"}}}
'
#_You can put other options here
OPTS='
@ncloward
ncloward / ServerlessDeployBot.yml
Created August 16, 2017 21:16
Serverless Deploy Bot Permissions
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Cloudformation stack to manage permission to deploy a serverless service'
Parameters:
ServiceName:
Description: Name of the Service you want to deploy
Type: String
Resources:
@rauhs
rauhs / Makefile
Last active March 23, 2020 21:40
################################################################################
# Vars
# $< Dependency (right)
# $@ Target (left)
CLJ_NREPL_PORT:=22340
FIGWHEEL_PORT:=22345
LEIN_NREPL_PORT:=22350
CLJ_NREPL_PORT_TRY:=22355

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.

@naftulikay
naftulikay / s3-cloudfront-invalidation.sh
Last active November 7, 2022 21:44
Sync a directory to S3 and invalidate the CloudFront cache for changed resources.
#!/bin/bash
# output format is like this:
# upload: index.html to s3://$BUCKET/index.html
#
# so we grab the second item which is the file path and pass that via xargs to the
# cloudfront invalidation command
aws s3 sync --sse AES256 s3://$BUCKET/ site/ | awk '{print $2;}' | \
xargs aws cloudfront create-invalidation --distribution-id $CF_DISTRO_ID --paths