Skip to content

Instantly share code, notes, and snippets.

View tgwizard's full-sized avatar

Adam Renberg Tamm tgwizard

View GitHub Profile
@tgwizard
tgwizard / benchmark-query-x.rb
Last active June 18, 2020 09:44
Benchmarking simple SQL query parsing
# frozen_string_literal: true
require 'benchmark/ips'
QUERY_NAMES = [
"set names",
"select",
"insert",
"update",
"delete",
@tgwizard
tgwizard / flask_raw_streamer.py
Last active January 10, 2018 19:51
A way to read request streams in Flask and split them among other streams. See subprocess_input_streamer gist too.
import subprocess
import time
from werkzeug.wsgi import get_content_length
from flask import Flask, Response, request
from subprocess_input_streamer import SubprocessInputStreamer
class SubprocessStreamProxy:
@tgwizard
tgwizard / flask_file_streamer2.py
Last active January 9, 2018 14:42
A Flask request multipart/form-data file streamer, with the capability to inspect the non-file form data before reading the files
import time
from werkzeug.formparser import MultiPartParser
from werkzeug.http import parse_options_header
from werkzeug.wsgi import get_content_length, get_input_stream
from flask import Flask, Response, request
class DummyWerkzeugFile:
def write(self, b: bytes):
@tgwizard
tgwizard / flask_file_streamer.py
Last active July 1, 2020 21:34
A Flask request multipart/form-data file streamer
import time
import werkzeug.formparser
from flask import Flask, Response, request
class DummyWerkzeugFile:
def write(self, b: bytes):
print('reading file parts: size=%s' % len(b))
@tgwizard
tgwizard / subprocess_input_streamer.py
Last active August 20, 2019 06:32
How to stream input to a subprocess in Python
import subprocess
from threading import Thread
from time import time
from typing import Union
from queue import Queue
class SubprocessInputStreamer:
_end_of_stream = object()
@tgwizard
tgwizard / vcl_deliver.vcl
Last active June 8, 2019 17:31
Fastly VCL config for A/B tests
sub vcl_deliver {
# ----- snip -----
# Set a cookie with the experiment group sequence, if the client didn't
# already have the cookie and provided it in the request, and if the origin
# hasn't already set it. Use `setcookie.get_value_by_name` to handle the
# cases when the backend sets multiple cookies.
# Only do this on the edge nodes, not the origin shield, otherwise the edge
# nodes will see a response with a `Set-Cookie` header and not cache it.
@tgwizard
tgwizard / redis_delete_prefix.py
Created July 7, 2016 14:43
Delete multiple redis keys. Safe to run in production
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import itertools
from redis import StrictRedis
@tgwizard
tgwizard / redis_reader.py
Created June 3, 2016 09:09
Testing ElastiCache redis faiover
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from datetime import datetime
from time import time, sleep
from redis import StrictRedis
@tgwizard
tgwizard / keybase.md
Created February 5, 2015 15:11
keybase.md

Keybase proof

I hereby claim:

  • I am tgwizard on github.
  • I am tgwizard (https://keybase.io/tgwizard) on keybase.
  • I have a public key whose fingerprint is B34A EB6F 918F 458C C9DB 2D69 649B 0F12 6711 8007

To claim this, I am signing this object:

@tgwizard
tgwizard / index.html
Last active August 29, 2015 14:10
Smart App Banner - viewport width=840
<p>Testing smart app banners for iOS Safari</p>
<ul>
<li><a href="smart-app-banner-viewport-width.html">Viewport with width specified</a></li>
<li><a href="smart-app-banner-viewport-responsive.html">Viewport as responsive</a></li>
<li><a href="smart-app-banner-viewport-none.html">No viewport specified</a></li>
</ul>