Skip to content

Instantly share code, notes, and snippets.

View nszceta's full-sized avatar

Adam Gradzki nszceta

View GitHub Profile
@nszceta
nszceta / postgres_load_json.py
Last active September 9, 2022 23:28
Load a random sequence of JSON or Python dict into Postgres as fast as possible
import sys
import json
import time
import psycopg2
import psycopg2.extras
psycopg2.extensions.register_adapter(dict, psycopg2.extras.Json)
@nszceta
nszceta / envelope_encryption_kms_boto_pycrypto.md
Created August 31, 2020 15:46 — forked from pmp/envelope_encryption_kms_boto_pycrypto.md
Envelope Encryption using AWS KMS, Python Boto, and PyCrypto.

If you use Amazon AWS for nearly anything, then you are probably familiar with KMS, the Amazon Key Management Service.

KMS is a service which allows API-level access to cryptographic primitives without the expense and complexity of a full-fledged HSM or CloudHSM implementation. There are trade-offs in that the key material does reside on servers rather than tamper-proof devices, but these risks should be acceptable to a wide range of customers based on the care Amazon has put into the product. You should perform your own diligence on whether KMS is appropriate for your environment. If the security profile is not adequate, you should consider a stronger product such as CloudHSM or managing your own HSM solutions.

The goal here is to provide some introductory code on how to perform envelope encrypt a message using the AWS KMS API.

KMS allows you to encrypt messages of up to 4kb in size directly using the encrypt()/decrypt() API. To exceed these limitations, you must use a technique called "envelope encryptio

@nszceta
nszceta / send.sh
Created October 5, 2018 19:09
Send an entire folder over the wire with XZ compression/decompression
#!/bin/sh
tar cf - my_folder | xz -c | ssh destination "xz -d | tar xvf -"
@nszceta
nszceta / asyncpg_vs_psycopg2.py
Last active March 30, 2018 21:53
asyncpg vs psycopg2
"""
a@MacBook-Pro ~ $ ab -c100 -n10000 http://127.0.0.1:8000/asyncpg/select
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
@nszceta
nszceta / opencv3_missing_lapack_blas_symbols.txt
Created November 16, 2017 15:46
OpenCV 3 missing LAPACK/BLAS symbols broken by C++ name mangling
Edit OpenCVFindLAPACK.cmake
Change:
if(NOT " ${__content_str}" STREQUAL " ${_lapack_include_str}")
file(WRITE "${CBLAS_H_PROXY_PATH}" "${_lapack_include_str}")
endif()
To:
@nszceta
nszceta / pyenv-3.6.3-optimized-installation.sh
Last active November 2, 2020 13:59
pyenv: Python 3.6.3 optimized installation
MAKE_OPTS="-j8" \
CONFIGURE_OPTS="--enable-shared --enable-optimizations --with-computed-gotos" \
CFLAGS="-march=native -O2 -pipe" \
pyenv install -v 3.6.3
# thanks Eli! https://github.com/seemethere
import os
import asyncio
import uvloop
from asyncpg import connect, create_pool
from sanic import Sanic
from sanic.response import json
@nszceta
nszceta / designer.html
Created March 10, 2016 01:55
designer
<link rel="import" href="../core-animated-pages/core-animated-pages.html">
<link rel="import" href="../core-animated-pages/transitions/hero-transition.html">
<link rel="import" href="../core-animated-pages/transitions/cross-fade.html">
<link rel="import" href="../core-animated-pages/transitions/slide-down.html">
<link rel="import" href="../core-animated-pages/transitions/slide-up.html">
<link rel="import" href="../core-animated-pages/transitions/tile-cascade.html">
<link rel="import" href="../paper-slider/paper-slider.html">
<polymer-element name="my-element">
@nszceta
nszceta / fix-homebrew-npm.md
Created February 28, 2016 02:46 — forked from DanHerbert/fix-homebrew-npm.md
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.