Skip to content

Instantly share code, notes, and snippets.

View didxga's full-sized avatar

Carter Chen didxga

View GitHub Profile
@cspinetta
cspinetta / synchronization-implementation-in-jvm.md
Last active February 24, 2022 15:45
Synchronization in Java

Object locking implementation in the Java HotSpot VM

The most synchronization idiom in Java is using the synchronized keyword.

The JVM supports synchronization of both methods and sequences of instructions within a method using a single synchronization construct - synchronized - which is built around an internal entity known as the intrinsic lock or monitor lock (The API specification often refers to this entity simply as a "monitor"). Intrinsic locks play a role in both aspects of synchronization: enforcing exclusive access to an object's state and establishing happens-before relationships to ensure a correct visibility amoung threads.

At bytecode level, the JVM supplies the monitorenter and monitorexit instructions to support such constructs.

At runtime level, in the Java HotSpot VM, every object has a built-in monitor (the so called intrinsic lock or monitor lock) that can be acquired by any thread.

@rponte
rponte / avoid-distributed-transactions.md
Last active April 3, 2024 21:45
THEORY: Distributed Transactions and why you should avoid them (2 Phase Commit , Saga Pattern, TCC, Idempotency etc)

Distributed Transactions and why you should avoid them

  1. Modern technologies won't support it (RabbitMQ, Kafka, etc.);
  2. This is a form of using Inter-Process Communication in a synchronized way and this reduces availability;
  3. All participants of the distributed transaction need to be avaiable for a distributed commit, again: reduces availability.

Implementing business transactions that span multiple services is not straightforward. Distributed transactions are best avoided because of the CAP theorem. Moreover, many modern (NoSQL) databases don’t support them. The best solution is to use the Saga Pattern.

[...]

@peterjaap
peterjaap / .gitlab-ci.yaml
Last active January 12, 2022 16:37
Generic Gitlab CI file to build and push a Docker container to the private registry using kaniko (no Docker in Docker privileged mode needed)
image: docker:latest
stages:
- build
build:
stage: build
only:
- master
image:
@qoomon
qoomon / conventional-commits-cheatsheet.md
Last active July 7, 2024 01:34
Conventional Commits Cheatsheet

Conventional Commit Messages

See how a minor change to your commit message style can make a difference.

Tip

Have a look at git-conventional-commits , a CLI util to ensure these conventions and generate verion and changelogs

Commit Message Formats

Default

@nakov
nakov / AES-256-CTR-Argon2-HMAC-SHA256-example.js
Last active May 30, 2024 14:31
Cryptography for JavaScript Developers: Hashes, HMAC, PBKDF2, Scrypt, Argon2, AES-256-CTR, ECDSA, EdDSA, secp256k1, Ed25519
const aes = require("aes-js");
const argon2 = require("argon2");
const crypto = require("crypto");
const cryptoJS = require("crypto-js");
// Encrypt using AES-256-CTR-Argon2-HMAC-SHA-256
async function aes256ctrEncrypt(plaintext, password) {
let argon2salt = crypto.randomBytes(16); // 128-bit salt for argon2
let argon2Settings = { type: argon2.argon2di, raw: true,
timeCost: 8, memoryCost: 2 ** 15, parallelism: 2,
@vladimir-bukhtoyarov
vladimir-bukhtoyarov / CachingSupplier.java
Last active April 21, 2022 07:09
Example of StamedLock usage
import java.time.Duration;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Supplier;
public class CachingSupplier<T> implements Supplier<T> {
private final Supplier<T> targetSupplier;
private final long cachingDurationNanos;
private final StampedLock stampedLock = new StampedLock();
@rivo
rivo / serve.go
Created November 26, 2017 12:28
Graceful stop and restart for HTTP servers in Go
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"os/exec"
"os/signal"
@DragonBe
DragonBe / php_apache_homebrew.md
Last active July 4, 2024 17:15
Installation of Apache 2.4 and PHP 7.1 with Homebrew

I posted several talks about compiling PHP from source, but everyone was trying to convince me that a package manager like Homebrew was a more convenient way to install.

The purpose of Homebrew is simple: a package manager for macOS that will allow you to set up and install common packages easily and allows you to update frequently using simple commands.

I used a clean installation of macOS Sierra to ensure all steps could be recorded and tested. In most cases you already have done work on your Mac, so chances are you can skip a few steps in this tutorial.

Apache and PHP with homebrew

I’ve made this according to the installation instructions given on GetGrav.