Skip to content

Instantly share code, notes, and snippets.

View paxan's full-sized avatar

Pavel Repin paxan

  • aws.amazon.com
  • Seattle, WA
View GitHub Profile
@paxan
paxan / tornado_force_https.py
Last active August 15, 2023 01:24
A hack to make Tornado web server redirect http requests to https for Heroku or similar reverse-proxied deployments
from __future__ import absolute_import, print_function
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
def create_server(*args, **kwargs):
'''
@paxan
paxan / main.go
Last active April 26, 2023 00:41
HTTP middlewares in Go from the first principles
package main
import (
"context"
"fmt"
"log"
"net/http"
"sync/atomic"
)
@paxan
paxan / .gitconfig
Created August 17, 2022 03:02
~/.gitconfig
[pull]
ff = only
[merge]
ff = false

Keybase proof

I hereby claim:

  • I am paxan on github.
  • I am paxan (https://keybase.io/paxan) on keybase.
  • I have a public key ASCofZ0PjVQOf9m_rtS0h2_iLGunooGXCW3FPvNSZUgdKQo

To claim this, I am signing this object:

@paxan
paxan / get-daemontools-heroku-16.md
Created March 9, 2017 18:15
How to get daemontools onto a dyno running heroku-16 stack
curl -sO https://mirrors.kernel.org/ubuntu/pool/universe/d/daemontools/daemontools_0.76-6ubuntu1_amd64.deb
dpkg-deb -x daemontools_0.76-6ubuntu1_amd64.deb daemontools
@paxan
paxan / ae.clj
Last active November 25, 2016 21:31
AEAD decryption process using AWS KMS & AES/GCM/NoPadding cipher
;; CAVEAT: Ensure your JDK/JRE is configured with Java Cryptography
;; Extension (JCE) Unlimited Strength Jurisdiction Policy Files.
;; Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html
;; and look for "JCE".
;; Given a ciphertext (produced by AES/GCM/NoPadding cipher), a nonce,
;; and a KMS-encrypted content encrypting key (cek), here is the
;; process for producing the plaintext:
(defn b64dec [x] (javax.xml.bind.DatatypeConverter/parseBase64Binary x))
@paxan
paxan / getin.java
Last active August 15, 2016 23:45
Get the element in an arbitrarily nested JSON structure by following a path of keys (inspired by Clojure's get-in function)
package some.package;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import java.util.Arrays;
import java.util.Optional;
class SomeClass {
/**
@paxan
paxan / kmstool.py
Last active January 26, 2016 00:48
A tool for storing secrets on disk securely using AWS KMS
from __future__ import absolute_import, print_function
import boto3
import errno
import json
import os
import re
import shlex
import sys
import tempfile
@paxan
paxan / fibosayer.py
Last active December 26, 2015 17:49
Says numbers of Fibonacci sequence starting from the 50th one and goes on forever.
#!/usr/bin/env python
from __future__ import print_function
import random
import time
from subprocess import check_call
from shlex import split
voices = tuple('Agnes Kathy Princess Vicki Victoria Bruce Fred Junior Ralph'.split()) + \
@paxan
paxan / Node Under Pressure.md
Last active December 21, 2015 12:09
Putting a simple one-dyno Node.js app under pressure on Heroku

What the app does

It receives certain JSON events as HTTP POSTs, parses them, and writes received JSON with along with some extra metadata to stdout using console.log(). POST-ed data does not usually exceed ~800 bytes per request.

It runs with node 0.10.15 engine on Heroku with just one web dyno. Also it uses Express 3.3.4 web service library.

Under pressure

I've subjected the app to some traffic by means of blitz.io: