Skip to content

Instantly share code, notes, and snippets.

---
# Archive of http://www.columbia.edu/~alan/schemas/common/jsonapi.yaml
openapi: 3.0.2
info:
version: 1.0.0
title: "{json:api} Specification"
description: >
An include file to define the [{json:api} 1.0 specification](http://jsonapi.org/format).
N.B. I've got some confusion going on between a validating a jsonapi schema and defining one!
@RNHTTR
RNHTTR / AzureUploadLargeBlob.sh
Last active February 23, 2024 19:35
A simple shell script using cURL and the Azure REST API to upload large files (> 100MB) to Azure Storage
#!/bin/bash
echo "\nEnter your storage account name:"
read AZ_ACCOUNT_NAME
echo "\nEnter your container name:"
read AZ_BLOB_CONTAINER
echo "\nEnter your SAS token (just hit ENTER/RETURN if not applicable):"
read AZ_SAS_TOKEN
DATE_NOW=$(date -Ru | sed 's/\+0000/GMT/')

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.

@adige
adige / check_open_ports
Created January 13, 2016 08:35
Check open ports without netstat or lsof
declare -a array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1")) && for port in ${array[@]}; do echo $((0x$port)); done
@ccampanale
ccampanale / vaultsealmanager.sh
Created December 10, 2015 19:31
Bash shell script to check seal status for local vault server and attempt to unseal using keys secured in vault secret store. Supports HA Vault clusters with TLS with unseal keys stored as secrets in vault (see code). Relies on registered service vault.service.consul, in place DNS configuration, and a single unsealed vault instance in your clust…
#!/bin/bash
export vault=/usr/local/bin/vault
export VAULT_TOKEN=$(cat /root/.vault-token)
vault_cacert='-ca-cert=/path/to/your/ca.pem'
local_vault="-address=https://$(hostname -f):8200"
unsealed_vault="-address=https://$(getent hosts $(dig +short vault.service.consul | tail -n 1) | awk '{ print $2 }'):8200"
leader_vault="-address=https://$($vault status $vault_cacert $unsealed_vault 2> /dev/null | grep Leader | awk '{ print $2 }' | sed 's/^http\(\|s\):\/\///g'):8200"
vault_read="$vault read $vault_cacert $leader_vault"
vault_unseal="$vault unseal $vault_cacert $local_vault"
# Define a proxy
Configuration Proxy {
Registry ProxyPerMachinePolicy
{
Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Internet Settings'
ValueName = 'ProxySettingsPerUser'
Ensure = 'Present'
ValueData = '0'
ValueType = 'Dword'
Force = $true
@renatolfc
renatolfc / ovpn-writer.sh
Created December 28, 2014 18:50
Script to generate an OpenVPN client configuration file in the unified format
#!/bin/sh
##
## Usage: ./ovpn-writer.sh SERVER CA_CERT CLIENT_CERT CLIENT_KEY SHARED_SECRET > client.ovpn
##
server=${1?"The server address is required"}
cacert=${2?"The path to the ca certificate file is required"}
client_cert=${3?"The path to the client certificate file is required"}
client_key=${4?"The path to the client private key file is required"}
@ngoduykhanh
ngoduykhanh / jira.py
Last active May 18, 2016 07:52
Getting jira webhook data for "issue_created" event
#!flask/bin/python
import json
import traceback
from flask import Flask, request, make_response, jsonify
app = Flask(__name__)
@app.route('/jira-create', methods=['POST'])
def create_ticket():
anonymous
anonymous / gist:ecede2a386a5453e4ed4
Created November 7, 2014 14:13
nxlog windows eventlog ssl
## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.
#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog
Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
anonymous
anonymous / gist:d1373af062b9cc85d0ae
Created November 7, 2014 14:12
logstash input windows eventlog ssl
input {
tcp{
type => eventlog
port => 1515
ssl_enable => true
ssl_cert => "/etc/nginx/ssl/server.crt"
ssl_key => "/etc/nginx/ssl/server.key"
ssl_key_passphrase => "password"
ssl_cacert => "/etc/nginx/ssl/server.csr"