Skip to content

Instantly share code, notes, and snippets.

View wizpig64's full-sized avatar
🌯

Phillip Marshall wizpig64

🌯
  • Agrimanagement, Inc.
  • Washington State, USA
View GitHub Profile
@wizpig64
wizpig64 / secret_hash.py
Last active December 27, 2015 10:49
Hash a privately known SECRET_KEY with a public expiration time. Meant to be used in places where sensitive commands must be sent over GET requests, which are inherently publicly accessible.
from base64 import b64encode
from datetime import datetime
import hashlib
from time import time
class SecretHash:
r"""Hash a privately known SECRET_KEY with a public expiration time.
Meant to be used in places where sensitive commands must be sent
over GET requests, which are inherently publicly accessible.
@wizpig64
wizpig64 / secure_storage.py
Created November 27, 2013 04:58
Makes Django storage URLs expire after a set amount of time. Built to be used with nginx's secure_link module, essentially emulating Amazon's S3's similar functionality. Because it's a mixin, you can theoretically use it with any Django storage method, but it will only limit access if there's a properly configured nginx server actually serving t…
from base64 import urlsafe_b64encode
from urlparse import parse_qs, urlsplit, urlunsplit
from urllib import unquote, urlencode
from django.conf import settings
from django.core.files.storage import Storage
from django.core.files.storage import FileSystemStorage
from secret_hash import SecretHash
@wizpig64
wizpig64 / goto_or_open_terminator.sh
Last active August 29, 2015 14:14
X desktop: switch to or open new process
#!/bin/bash
#searches for $COMMAND in ps. if its found, switch to it using wmctrl, else start a new one.
#if any arguments are made ($@), $COMMAND will be run with them even if it's already running.
#tip: bind this to a spare mouse button with xbindkeys
#tip: save this as /usr/local/bin/terminator to override the command in /usr/bin using $PATH ordering.
#requires wmctrl. currently set up for terminator but could be used for any process.
COMMAND="/usr/bin/python /usr/bin/[t]erminator"
PID=`ps aux | grep "$COMMAND" | awk '{print $2}' | head -1`
if [ -z $PID ] || [ ! -z "$@" ]
@wizpig64
wizpig64 / one_to_one.sql
Last active August 29, 2015 14:18
PostgreSQL View and Triggers for One-to-One Tables
-- This is an implementation of a one-to-one relationship between two tables in PostgreSQL, as well as a view that
-- presents the two as a single table, accepting INSERTs, UPDATEs and DELETEs just like a flat table would.
-- One thing that may or may not be noteworthy is how foo.id's sequencer is manually incremented even when the user
-- specifies a non-null value. I needed this for my project (MS-Access was throwing a fit), but it may not be the
-- default behavior for serial primary keys.
-- todo for UPDATE and DELETE: it's possible that a foo exists without a bar relating to it. currently, UPDATE and
-- DELETE could be used to mess with rows on foo that shouldn't be messed with (for example they could be rows with
-- different one-to-one relationships). This won't matter for most applications, but it allows for some potentially
-- malicious actions that should be caught.

Keybase proof

I hereby claim:

  • I am wizpig64 on github.
  • I am wizpig64 (https://keybase.io/wizpig64) on keybase.
  • I have a public key whose fingerprint is 6016 B48F AEB7 63A1 795D 4F21 7152 1B32 B98F 5636

To claim this, I am signing this object:

@wizpig64
wizpig64 / zfsdiff.py
Created May 27, 2017 03:57
zfsdiff.py - show the size difference between replicated pools.
#!/usr/bin/env python
"""zfsdiff.py - show the size difference between replicated pools.
It will also attempt to guess how many days behind replication is,
and output will go to stderr rather than stdout if difference > threshold,
so you can run receive alerts when things get too far behind.
"""
from __future__ import print_function, unicode_literals
import re
# assembling a list the old way
def do_stuff(x, y, z):
l = []
l += do_x(x)
l += do_y(y)
l += do_z(z)
return l
# assembling a list with generators (much easier to read!):
@wizpig64
wizpig64 / credit_karma_1099B_csv.js
Last active February 13, 2023 23:33
Import 1099-B into Cash App Taxes (formerly Credit Karma Tax) via CSV
// credit_karma_1099B_csv.js
// copyright Phillip Marshall 2019-2023, except line 31, with help from kirill578
// --- README ---
// Cash App offers a free tax filing service (formerly under Credit Karma's brand),
// but requires you to enter Capital Gains and Losses manually in 'Spreadsheet entry' mode.
// This script implements the missing CSV import feature for 1099-B gains and losses.
// The csv this was based on came from a wealthfront xls, exported with mm/dd/yyyy dates and NO HEADER.
@wizpig64
wizpig64 / dumpoptions.py
Last active December 15, 2022 18:07
django management command to dump API metadata
import json
from pathlib import Path
from django.core.management.base import BaseCommand
from django.utils.module_loading import import_string
from rest_framework.fields import Field
from rest_framework.metadata import SimpleMetadata
from rest_framework.routers import BaseRouter as Router
from rest_framework.schemas.openapi import AutoSchema