Skip to content

Instantly share code, notes, and snippets.

# Docker Machine for Consul
docker-machine \
create \
-d virtualbox \
consul-machine
# Start Consul
docker $(docker-machine config consul-machine) run -d --restart=always \
-p "8500:8500" \
-h "consul" \
@vasanthk
vasanthk / System Design.md
Last active May 14, 2025 01:45
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@watson
watson / four-byte-emojis.json
Last active March 20, 2025 15:05
Emoji's sorted by byte-size
[
"😁",
"😂",
"😃",
"😄",
"😅",
"😆",
"😉",
"😊",
"😋",
@xkr47
xkr47 / letsencrypt-jetty.sh
Last active May 4, 2025 13:59
How to use Letsencrypt certificate & private key with Jetty
# input: fullchain.pem and privkey.pem as generated by the "letsencrypt-auto" script when run with
# the "auth" aka "certonly" subcommand
# convert certificate chain + private key to the PKCS#12 file format
openssl pkcs12 -export -out keystore.pkcs12 -in fullchain.pem -inkey privkey.pem
# convert PKCS#12 file into Java keystore format
keytool -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks
# don't need the PKCS#12 file anymore
@mfuerstenau
mfuerstenau / zigzag-encoding.README
Last active April 24, 2025 05:25
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation
@ndolgov
ndolgov / SparkDriver.java
Last active November 25, 2021 10:27
Running SparkSQL in standalone mode
import org.apache.spark.sql.SparkSession;
public class SparkDriver {
public static void main(String[] args) {
final SparkSession session = SparkSession.builder().
appName("MySparkApp" + System.currentTimeMillis()).
master(SparkEnvCfg.sparkMasterUrl()).
config(SparkEnvCfg.SPARK_EXECUTOR_MEMORY, "1g").
config(SparkEnvCfg.SPARK_SERIALIZER, SparkEnvCfg.KRYO).
config(SparkEnvCfg.SPARK_SQL_SHUFFLE_PARTITIONS, "2").
@miguno
miguno / kafka-move-leadership.sh
Last active July 6, 2023 19:53
A simple Ops helper script for Apache Kafka to generate a partition reassignment JSON snippet for moving partition leadership away from a given Kafka broker. Use cases include 1) safely restarting a broker while minimizing risk of data loss, 2) replacing a broker, 3) preparing a broker for maintenance.
#!/usr/bin/env bash
#
# File: kafka-move-leadership.sh
#
# Description
# ===========
#
# Generates a Kafka partition reassignment JSON snippet to STDOUT to move the leadership
# of any replicas away from the provided "source" broker to different, randomly selected
# "target" brokers. Run this script with `-h` to show detailed usage instructions.
@lavalamp
lavalamp / The Three Go Landmines.markdown
Last active February 28, 2025 12:54
Golang landmines

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }
@sadikovi
sadikovi / LoginSimulation.scala
Created February 25, 2015 09:26
Another example of Gatling scenario with complex authentication/response processing and number of simple requests that have been used as a test.
package mobilepackage
import io.gatling.core.Predef._
import io.gatling.core.session._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.parsing.json._
import general._
class LoginSimulation extends Simulation {
@ivanursul
ivanursul / AccessDeniedIntegrationTest.scala
Created January 24, 2015 10:31
AccessDeniedIntegrationTest.scala
package org.lnu.is.integration.access
import io.gatling.core.Predef.checkBuilder2Check
import io.gatling.core.Predef.doIf
import io.gatling.core.Predef.exec
import io.gatling.core.Predef.findCheckBuilder2ValidatorCheckBuilder
import io.gatling.core.Predef.foreach
import io.gatling.core.Predef.feed
import io.gatling.core.Predef.stringToExpression
import io.gatling.core.Predef.validatorCheckBuilder2CheckBuilder