Skip to content

Instantly share code, notes, and snippets.

@stevenewey
stevenewey / gist:2593537
Created May 4, 2012 09:19
May ldnpydojo team 1 effort
import sys
raw = [
[' _ ',
'| |',
'|_|' ],
[' ',
' |',
' |' ],
[' _ ',
@celery.task(ignore_result=True, max_retries=3)
def season(data):
competition = mongo.Competition.one({
'opta_competition_id': data['competition_id'],
}, ['_id'])
if not competition:
raise season.retry()
@stevenewey
stevenewey / summarise.coffee
Created August 30, 2012 12:28
Summarise array (optionally on item property) into human readable string
Array::summarise = (args) ->
count = args?.maximumItems or 3
if typeof args?.property == 'string'
temp = []
[temp.push item[args.property] for item in this]
else
temp = this[...]
if temp.length > 1 and temp.length <= count
return temp[...-1].join(', ') + ' and ' + temp[-1...]
else if temp.length == 1
@stevenewey
stevenewey / pytest.py
Last active December 16, 2015 23:21
A Python test for potential apprentices
#!/usr/bin/env python
#
# Regenology interview test
#
"""
#
# Try to complete as many of these as you can in the available time. Don't
# worry if you can't finish, and move on to the next task if you get stuck.

Keybase proof

I hereby claim:

  • I am stevenewey on github.
  • I am stevenewey (https://keybase.io/stevenewey) on keybase.
  • I have a public key whose fingerprint is 05E6 A3E4 0A45 B302 041E 09FA 8BB2 4D7F 7BB7 5D65

To claim this, I am signing this object:

@stevenewey
stevenewey / gist:fea5c9f224e50ada7f82
Created June 15, 2015 16:44
Redis pubsub to Server Sent Events (EventSource)
import json
import redis
from flask import Flask, g, stream_with_context, Response
r = redis.StrictRedis()
app = Flask(__name__)
@stevenewey
stevenewey / ssh_key_helper.py
Created April 6, 2016 18:09
Serialize Python 3 cryptography RSA public key to OpenSSH format
import binascii
import struct
from cryptography import utils
from cryptography.hazmat.primitives.asymmetric import rsa
def ssh_public_key(keypair: rsa.RSAPrivateKeyWithSerialization) -> str:
eb = utils.int_to_bytes(keypair.public_key().public_numbers().e)
nb = utils.int_to_bytes(keypair.public_key().public_numbers().n)
@stevenewey
stevenewey / asg-names.tf
Created January 14, 2022 11:08
Retrieve per-AZ autoscaling group names from managed node groups when using the AWS EKS terraform module
variable "availability_zones" {
type = map(string)
description = "Availability zones to use, mapped to networks to assign"
default = {
"us-east-1a" : "172.16.0.0/18",
"us-east-1b" : "172.16.64.0/18",
}
}
locals {
@stevenewey
stevenewey / libretranslate.diff
Created November 27, 2022 17:54
Workaround for LibreTranslate Docker Compose build on Arm64 (when pycld2 from pypi won't build)
diff --git a/Dockerfile b/Dockerfile
index aea119a..9c2b433 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,7 +4,7 @@ WORKDIR /app
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq \
- && apt-get -qqq install --no-install-recommends -y libicu-dev pkg-config gcc g++ \
+ && apt-get -qqq install --no-install-recommends -y git libicu-dev pkg-config gcc g++ \