Skip to content

Instantly share code, notes, and snippets.

View jcaxmacher's full-sized avatar
💭
Focused

J Axmacher jcaxmacher

💭
Focused
View GitHub Profile
@jcaxmacher
jcaxmacher / rmvpc.py
Created January 16, 2021 04:32 — forked from alberto-morales/rmvpc.py
Deleting an AWS VPC with python's boto3
#!/usr/bin/env python
"""I was trying to programatically remove a Virtual Private Cloud (VPC) in
AWS and the error message was not helpful:
botocore.exceptions.ClientError: An error occurred (DependencyViolation)
when calling the DeleteVpc operation: The vpc 'vpc-c12029b9' has
dependencies and cannot be deleted.
Searching for a quick solution was not fruitful but I was able to glean some
knowledge from Neil Swinton's gist:
@jcaxmacher
jcaxmacher / LambdaEfsBackup.py
Created June 17, 2020 01:36 — forked from eduardcloud/LambdaEfsBackup.py
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/
@jcaxmacher
jcaxmacher / gist:3773140d69492b622fced754f1118d87
Created March 2, 2020 03:01 — forked from timmc/pwned-passwords-sqlite-build.py
Building a sqlite DB for the Pwned Passwords data

(There are better ways to do this, such as making a small Python program to load in the data as binary instead of hex—but this is what I did in a pinch and it worked well for what I needed!)

Last executed 2019-06-25 with the v4 dump:

  1. Make sure you have 60 GB free disk space and some extra to spare. Alternatively, take a walk on the wild side and delete source files as soon as you've used them.
  2. Download the SHA-1 (ordered by hash) torrent from https://haveibeenpwned.com/Passwords
  3. Unpack and strip off the counts:
@jcaxmacher
jcaxmacher / git-change-commit-messages.md
Created October 23, 2019 13:48 — forked from nepsilon/git-change-commit-messages.md
How to change your commit messages in Git? — First published in fullweb.io issue #55

How to change your commit messages in Git?

At some point you’ll find yourself in a situation where you need edit a commit message. That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

Not pushed + most recent commit:

git commit --amend

This will open your $EDITOR and let you change the message. Continue with your usual git push origin master.

@jcaxmacher
jcaxmacher / aws-lambda-static-type-checker.md
Created January 9, 2018 22:23 — forked from alexcasalboni/aws-lambda-static-type-checker.md
AWS Lambda Static Type Checker Example (Python3)

How to use Python3 Type Hints in AWS Lambda

TL;DR

Static Type Checkers help you find simple (but subtle) bugs in your Python code. Check out lambda_types.py and incrementally improve your code base and development/debugging experience with type hints.

Your Lambda Function code will go from this:

@jcaxmacher
jcaxmacher / beautiful_idiomatic_python.md
Created April 11, 2017 13:37 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@jcaxmacher
jcaxmacher / goto.py
Created November 19, 2016 22:18 — forked from josiahcarlson/goto.py
Decorators for adding goto/switch semantics to Python
'''
This code is derived from: http://code.activestate.com/recipes/576944/
It was released under the MIT license.
I (Josiah Carlson) have modified it to be correct in more cases, and to report
errors in some error cases.
@jcaxmacher
jcaxmacher / helloworld-win32-service.py
Created October 6, 2015 12:20 — forked from drmalex07/helloworld-win32-service.py
An example Windows service implemented with pywin32 wrappers. #python #windows-service #pywin32
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import logging
logging.basicConfig(
filename = 'c:\\Temp\\hello-service.log',
@jcaxmacher
jcaxmacher / boilerplate.py
Created September 24, 2015 01:47 — forked from ssokolow/boilerplate.py
Python boilerplate from which I start all my projects
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""[application description here]"""
__appname__ = "[application name here]"
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__version__ = "0.0pre0"
__license__ = "GNU GPL 3.0 or later"
import logging
@jcaxmacher
jcaxmacher / README.md
Last active September 2, 2015 00:17 — forked from mbostock/.block
Every ColorBrewer Scale

A quick visual reference to every ColorBrewer scale; colors by Cynthia Brewer. Available in CSS and JS format. Click on a palette to log the constituent colors in hexadecimal RGB to the console.