Skip to content

Instantly share code, notes, and snippets.

View philipjkim's full-sized avatar

Soo Philip Jason Kim philipjkim

View GitHub Profile
@mikberg
mikberg / connection.js
Last active December 29, 2021 16:57
MongoDB connection with async/await
import { MongoClient } from 'mongodb';
import promisify from 'es6-promisify';
let _connection;
const connect = () => {
if (!process.env.MONGO_CONNECTION_STRING) {
throw new Error(`Environment variable MONGO_CONNECTION_STRING must be set to use API.`);
}
@KoFish
KoFish / rmq-dlx.md
Last active August 21, 2023 05:57
RabbitMQ - Delay message by dead letter exchange

Delay queuing of messages in RabbitMQ/AMQP

Since RabbitMQ (and AMQP) have no specialized functionality for delay adding a message to the queue a dead-letter exchange can be used instead. This works by having two separate exchanges, one "worker exchange" and one "delay exchange", and one queue for each exchange. For each exchange and queue pair a binding has to be setup that specifies the same routing key for both exchanges.

The consumer

The consumer listens to the worker queue and any delayed message is added to the delay queue with the specified routing key and a expiration time. Instead of per-message expiration the delay queue can also specify a x-message-ttl that applies to all messages going in to it. When the message expires it will be reaped by RabbitMQ and put into the specified dead-letter exchange, the worker exchange in this case, and the routing key will direct it to the worker queue for consumption.

Delayed retry

@hoitomt
hoitomt / log_request.go
Created January 30, 2015 12:56
Golang: Log HTTP Requests in Go
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
@vdw
vdw / gist:09efee4f264bb2630345
Last active January 31, 2023 08:55
Kill tcp connection with tcpkill on CentOS

Install tcpkill
yum -y install dsniff --enablerepo=epel

View connections
netstat -tnpa | grep ESTABLISHED.*sshd.

Block with ip tables
iptables -A INPUT -s IP-ADDRESS -j DROP

Kill connection

@john2x
john2x / 00_destructuring.md
Last active November 21, 2025 02:39
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@brandonmwest
brandonmwest / example.cs
Last active October 4, 2025 15:25
Generating base64-encoded Authorization headers in a variety of languages
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", username, password))));
@magnetikonline
magnetikonline / README.md
Last active August 27, 2025 06:08
Setting Nginx FastCGI response buffer sizes.
@james2doyle
james2doyle / atom-nice-font.less
Created February 27, 2014 22:12
nice fonts and scrollbars in the Atom editor!
body {
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
-moz-osx-font-smoothing: grayscale;
}
.tree-view-resizer, .editor {
::-webkit-scrollbar {
width: 0.5em;
height: 0.5em;
@Kimundi
Kimundi / java_rust_generic.md
Last active May 29, 2025 17:22
A light comparison between Rust and Java generics and type system features.

Introduction

If you are familiar with Java's generics, and are coming to Rust, you might be lead to assume that its generics are working the same way.

However, due to the different type systems, and different implementation details, there are quite a few differences between generic code in both languages.

This document tries to give a short summary about those differences:

Core functionality

Java