Skip to content

Instantly share code, notes, and snippets.

/**
* A D port of the Nim program:
* https://gist.github.com/jzakiya/6c7e1868bd749a6b1add62e3e3b2341e
*
* Related code, papers, and tutorials, are available here:
* https://www.scribd.com/doc/228155369/The-Segmented-Sieve-of-Zakiya-SSoZ
* https://www.scribd.com/document/266461408/Primes-Utils-Handbook
*/
module twinprimes_ssoz;
@vnayar
vnayar / app.d
Last active July 21, 2019 13:20
Demonstration of using arbitrary MediaTypes for HTTP body conversions in Vibe.d
import vibe.vibe;
////
// Example controller making use of the custom UDAs 'responseBody' and 'requestBodyParam'.
////
/// Interface useful for generating client code with RestInterfaceClient.
@path("/api")
interface ApiRestInterface {
@safe:
@vnayar
vnayar / socketutils.d
Last active February 6, 2022 17:27
Utility classes used to find open TCP/UDP ports.
/**
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vnayar
vnayar / envoy-localratelimit.yaml
Created September 26, 2022 13:52
An example Envoy configuration that perfoms path-based local rate-limiting.
# A local rate-limit following the example at:
# https://github.com/envoyproxy/envoy/tree/main/examples/local_ratelimit
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
@vnayar
vnayar / envoy-https.yaml
Created October 18, 2022 22:49
EnvoyProxy Part 4: Enable TLS connection termination for an HTTPS.
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#envoy-v3-api-msg-config-core-v3-address
- address:
# This address is for a network socket, with an IP and a port.
@vnayar
vnayar / envoy-front-proxy.yaml
Created October 4, 2022 15:16
An Envoy front-proxy configuration for Part 2 of the guide on Envoy.
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#envoy-v3-api-msg-config-core-v3-address
- address:
# This address is for a network socket, with an IP and a port.
#!/bin/bash
# Runs versioned database SQL migrations on a Postgres database, running them in order and only
# once.
# Mostly compatible with Flyway: https://documentation.red-gate.com/fd/migrations-184127470.html
function usage() {
echo "Usage: $0 [options]
Searches for database migration files in './migrations/' with names in the form
@vnayar
vnayar / envoy-global-ratelimit.yaml
Last active February 22, 2024 17:01
Part3: A basic configuration for EnvoyProxy that sets descriptors that will be used by the Ratelimit Service.
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#envoy-v3-api-msg-config-core-v3-address
- address:
# This address is for a network socket, with an IP and a port.
@vnayar
vnayar / envoy-basic.yaml
Created September 27, 2022 13:58
A skeletal configuration for Envoy which forwards requests to Envoy's website.
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#envoy-v3-api-msg-config-core-v3-address
- address:
# This address is for a network socket, with an IP and a port.
@vnayar
vnayar / envoy-jwt.yaml
Last active September 24, 2024 16:58
EnvoyProxy 5: Configure Envoy to requre JWT to authenticate, which is validated using JWKS.
# Resources loaded at boot, rather than dynamically via APIs.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-msg-config-bootstrap-v3-bootstrap-staticresources
static_resources:
# A listener wraps an address to bind to and filters to run on messages on that address.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/listener/v3/listener.proto#envoy-v3-api-msg-config-listener-v3-listener
listeners:
# The address of an interface to bind to. Interfaces can be sockets, pipes, or internal addresses.
# https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#envoy-v3-api-msg-config-core-v3-address
- address:
# This address is for a network socket, with an IP and a port.