Skip to content

Instantly share code, notes, and snippets.

"""
Given the lines in a sessionInfo() that start (minus whitespace) with `[`,
this creates a dict of package name/version pairs.
"""
def get_pkgs(text):
"""
Get a dict of package/version pairs from the packages section
of R's sessionInfo() output.
"""
@dtenenba
dtenenba / permdelete.py
Last active January 28, 2019 19:09
Permanently delete objects in a versioned S3 bucket
#!/usr/bin/env python3
"""
Permanently delete all "deleted" objects in a versioned S3 bucket.
In a versioned bucket, just deleting an object does not actually delete it
(though bucket lifecycle policies may eventually do so). Previous versions
will still be in the bucket. Deletions are recorded as "delete markers".
Use this script if you really really want to permanently delete all
@dtenenba
dtenenba / generate_passphrase.py
Last active January 25, 2019 19:46
generate passphrases using EFF wordlist
#!/usr/bin/env/python3
"""
Generate passphrases from this wordlist:
https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt
This will generate 3 sets of 3 words separated by hyphens.
"""
import random
@dtenenba
dtenenba / bktsize.py
Last active May 23, 2018 18:39
determine how many bytes of storage are used in all S3 buckets in account
#!/usr/bin/env python3
from datetime import datetime, timedelta
import sys
import boto3
cloudwatch = boto3.client('cloudwatch')
paginator = cloudwatch.get_paginator('list_metrics')
s3 = boto3.client("s3")
@dtenenba
dtenenba / aws_batch.md
Last active October 1, 2017 21:55
gathering documentation thoughts for AWS batch use at the Center

Using AWS Batch at the Center

Documentation

Outline

  • Obtaining credentials
  • Getting permissions to use Batch
  • Choosing a Compute Environment (for scicomp - how to create a new one, and document the default ones)
@dtenenba
dtenenba / views.py.diff
Created August 20, 2017 22:04
uncommitted code on toolbox
diff --git a/sw2srv/views.py b/sw2srv/views.py
index e7a9002..18daef5 100644
--- a/sw2srv/views.py
+++ b/sw2srv/views.py
@@ -75,11 +75,12 @@ def test(acct_name='test_a'):
r = jsonify( cred )
return r
-def validate( username, acct_name, binddn, bindpw ):
+def validate( username, acct_name, binddn, bindpw, grp_suffix):
@dtenenba
dtenenba / README.md
Last active June 7, 2019 22:57
a trivial python/flask app that uses Slack for sign-in

Set up as follows:

Install virtualenvwrapper if it isn't already installed:

pip install virtualenvwrapper

Create a virtualenv, using python 3:

mkvirtualenv --python $(which python3) flask-oauth
#!/usr/bin/env python3
"""
Use this as a pipe to change proofpoint-mangled URLs like this:
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=TF6f93hjWmgMzjqP9F3thRifibmFvfjc5Ae-bzNwDGo&m=oY-7oZ61w7BXE0OdDWKGHJBQVDfKclm7qIZa9Ax4MKo&s=2yq6rudFXxjoM851HucPcWoNvhH2RgPkAMcWOl7tRZc&e=
to 'unmangled' URLs like this:

Python Serverless Microframework for AWS (PSMA) and Zappa comparison

PSMA was just announced. Zappa has been around for a while.

Both are ways to deploy serverless web apps using AWS API Gateway and AWS Lambda, a process which is tedious if done manually.

It seems that PSMA is based on many of the ideas in Zappa.

# two implementations of a function to bump an R package version, given the package name/directory
# implementation 1 uses read/write.dcf, but changes lines unnecessarily, even though
# we use the keep.white option.
bump0 <- function(pkg){
print(pkg)
desc <- file.path(pkg, "DESCRIPTION")
dcf <- read.dcf(desc) # once without keeping whitespace
dcf <- read.dcf(desc, keep.white=colnames(dcf))