Skip to content

Instantly share code, notes, and snippets.

View codejitsu's full-sized avatar

Alex codejitsu

View GitHub Profile
@seva-ramin
seva-ramin / jwt-decode.sh
Last active March 25, 2021 15:12
JWT Decoder using bash
#!/bin/bash
# pad base64URL encoded to base64
paddit() {
input=$1
l=`echo -n $input | wc -c`
while [ `expr $l % 4` -ne 0 ]
do
input="${input}="
l=`echo -n $input | wc -c`
@antonyharfield
antonyharfield / RailwayOP-CompleteExample.kt
Created April 29, 2019 17:51
Railway Oriented Programming in Kotlin (as described here)
// Result is a superpowered enum that can be Success or Failure
// and the basis for a railway junction
sealed class Result<T>
data class Success<T>(val value: T): Result<T>()
data class Failure<T>(val errorMessage: String): Result<T>()
// Composition: apply a function f to Success results
infix fun <T,U> Result<T>.then(f: (T) -> Result<U>) =
when (this) {
is Success -> f(this.value)
@ServerlessBot
ServerlessBot / IAMCredentials.json
Last active December 20, 2023 16:50
Minimum credential set for Serverless Framework
{
"Statement": [
{
"Action": [
"apigateway:*",
"cloudformation:CancelUpdateStack",
"cloudformation:ContinueUpdateRollback",
"cloudformation:CreateChangeSet",
"cloudformation:CreateStack",
"cloudformation:CreateUploadBucket",

Vertical decomposition. Creating cohesive services

One of the biggest misconceptions about services is that a service is an independent deployable unit, i.e., service equals process. With this view, we are defining services according to how components are physically deployed. In our example, since it’s clear that the backend admin runs in its own process/container, we consider it to be a service.

But this definition of a service is wrong. Rather you need to define your services in terms of business capabilities. The deployment aspect of the system doesn’t have to be correlated to how the system has been divided into logical services. For example, a single service might run in different components/processes, and a single component might contain parts of multiple services. Once you start thinking of services in terms of business capabilities rather than deployment units, a whole world of options open.

What are the Admin UI

@marwei
marwei / how_to_reset_kafka_consumer_group_offset.md
Created November 9, 2017 23:39
How to Reset Kafka Consumer Group Offset

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
@ibraheem4
ibraheem4 / postgres-brew.md
Last active April 25, 2024 08:55 — forked from sgnl/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"Comment": "How long AWS Lambda keeps idle functions around?",
"StartAt": "FindIdleTimeout",
"States": {
"FindIdleTimeout": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:{account_id}:function:when-will-i-coldstart-dev-find-idle-timeout",
"Next": "RepeatOrNot"
},
"RepeatOrNot": {

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.

{
"name": "config-api",
"version": "1.10.0",
"scripts": {
"integration-dev": "env TEST_MODE=handler env SERVERLESS_STAGE=dev env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-dev": "env TEST_MODE=http env SERVERLESS_STAGE=dev env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"integration-test": "env TEST_MODE=handler env SERVERLESS_STAGE=test env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-test": "env TEST_MODE=http env SERVERLESS_STAGE=test env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"integration-staging": "env TEST_MODE=handler env SERVERLESS_STAGE=staging env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-staging": "env TEST_MODE=http env SERVERLESS_STAGE=staging env SERVERLESS_REGION