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
@robcowie
robcowie / reservoir_sampling.py
Created August 27, 2012 11:29
Maintain a random sample from a sequence of unknown length (reservoir sampling)
from random import randint
from itertools import islice
def random_sample(sample_size, items):
"""Maintain an evenly distributed random sample of a population of
unknown size
The Reservoir Sampling Algorithm
(http://gregable.com/2007/10/reservoir-sampling.html)
"""
@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 / 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
@lepture
lepture / emoji.py
Created March 10, 2012 15:54
emoji support in python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2012, lepture.com
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
@cgbystrom
cgbystrom / node.js vs Python
Created December 1, 2010 20:56
node.js vs Python with Greenlets
/*
node.js vs Python with Greenlets (say gevent)
I don't get why node.js is being so hyped.
Sure, the idea of writing things in JavaScript both on the client and server-side is really nice.
And JavaScript really fit an event-driven environment with its browser heritage.
But why on earth is boomerang code so appealing to write? I don't get. Am I missing something obvious?
All examples of node.js I see are littered with callbacks yet Ryan Dahl thinks coroutines suck. It doesn't add up for me.
@marksim
marksim / README.md
Last active September 28, 2018 15:56
Pair Sessions Script Adding more security (automatically timeout sudo, append the command to each ssh key

My script for pair sessions on my box.

What it does

  • downloads the appropriate ssh keys from github
  • copies the appropriate 'ssh pair@your-external-ip' command to your clipboard (see Note #1)
  • sets up the tmux session
  • cleans up the session, and the keys after it's done

How to use

#!/bin/bash
# Like the 'aws' cli except caches results
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
#set -x
@hgomez
hgomez / oracledownload
Last active October 6, 2021 09:58
Oracle JVM download using curl/wget
# Downloading Oracle JVM without browser
Oracle requires you to accept its licence agreement before downloading its JVM.
It's a pain for those of us who do automation, native packages, Jenkins JVM deployment on slave...
I used Firefox and Firebug to sniff network exchanges.
## HTTP Request :
GET /otn-pub/java/jdk/6u39-b04/jdk-6u39-linux-i586.bin?AuthParam=1359814101_9685f919f8b3113a89574ec4570d47b2 HTTP/1.1
@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):
'''
@igrigorik
igrigorik / github.bash
Last active December 22, 2023 23:55
Open GitHub URL for current directory/repo...
alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"