Skip to content

Instantly share code, notes, and snippets.

View phaeta's full-sized avatar

Brandon Smith phaeta

  • BioDigital, Inc.
  • New York, NY
View GitHub Profile
@kylemanna
kylemanna / falcon-zipfile-stream.py
Created May 16, 2020 00:08
Falcon + zipfile streaming proof of concept v2
#!/usr/bin/env python3
#
# Falcon + zipfile streaming content using os.pipe() to minimize RAM usage to a
# pipes worth of data.
#
# This test program generated a nearly 500 MB zip file with various compression
# arguments supported by the python3 standard library.
#
# Usage for debug webserver:
# $ ./app.py
@prog893
prog893 / README.md
Last active November 17, 2024 02:47
CloudFront Signed URL generator in Python

CloudFront Signed URL generator in Python

For signed cookies, refer here

Usage

from cloudfront_signed_url import generate_cloudfront_signed_url

generate_cloudfront_signed_url("https://your-cf-domain.com/path/to/file.txt", 3600)
@eduardcloud
eduardcloud / LambdaEfsBackup.py
Created September 19, 2017 10:14
Backup EFS file-system to S3 with lambda function
import boto3
import time
region = 'eu-west-1'
user_data_script = """#!/bin/bash
instanceid=$(curl http://169.254.169.254/latest/meta-data/instance-id)
cd /
mkdir moodledata
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxxxc.efs.eu-west-1.amazonaws.com:/ moodledata
tar czf mooodledata-backup-$(date +%d-%m-%Y_%H-%M).tar.gz /moodledata
aws s3 mv mooodledata-backup-*.tar.gz s3://xxxxxxxxx/
anonymous
anonymous / prime_conspiracy.py
Created March 15, 2016 06:23
Demonstrate the "prime conspiracy"
'''Demonstrate the "prime number conspiracy" as described at
https://www.quantamagazine.org/20160313-mathematicians-discover-prime-conspiracy/
"Among the first billion prime numbers, for instance, a prime ending in
9 is almost 65 percent more likely to be followed by a prime ending in 1
than another prime ending in 9. In a paper posted online today, Kannan
Soundararajan and Robert Lemke Oliver of Stanford University present
both numerical and theoretical evidence that prime numbers repel other
would-be primes that end in the same digit, and have varied
predilections for being followed by primes ending in the other possibl
@Natim
Natim / permission.py
Last active September 19, 2024 12:38
How to handle our permission schema with Redis
# -*- coding: utf-8 -*-
from __future__ import print_function
import json
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=1)
# List of permissions that gives us this permission
PERMISSIONS_INHERITANCE = {
'bucket:write': {
@bdarnell
bdarnell / streaming.py
Created January 11, 2015 21:23
Demo of streaming requests with Tornado
"""Demo of streaming requests with Tornado.
This script features a client using AsyncHTTPClient's body_producer
feature to slowly produce a large request body, and two server
handlers to receive this body (one is a proxy that forwards to the
other, also using body_producer).
It also demonstrates flow control: if --client_delay is smaller than
--server_delay, the client will eventually be suspended to allow the
server to catch up. You can see this in the logs, as the "client
@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2025 22:37
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@1wErt3r
1wErt3r / SMBDIS.ASM
Created November 9, 2012 22:27
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger ([email protected])
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no
anonymous
anonymous / ValidationMixin
Created March 2, 2011 09:49
ValidationMixin for Tornado
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT