Skip to content

Instantly share code, notes, and snippets.

View davidmintz's full-sized avatar

David Mintz davidmintz

View GitHub Profile
@davidmintz
davidmintz / survey.php
Last active January 8, 2024 01:18
quick and dirty survey in PHP and Javascript
<?php
/**
* collect and record a "vote" for a simple survey with one question, three choices.
*
* I thought it would be so simple that it would be easy to do in one physical file without
* getting too monolithic. Not so. But... oh well.
*/
/**
@davidmintz
davidmintz / AppExtension.php
Last active February 22, 2022 04:05
Symfony/Twig filter for rendering US 10-digit phone numbers +1xxxxxxxxx as (xxx) xxx-xxxx
<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters() : Array
{
@davidmintz
davidmintz / parse-html-email.py
Created August 22, 2019 14:45
quick and dirty html extraction for .eml files
#!/usr/bin/env python3
# useful for development and testing, this gets the html payload from
# .eml files (e.g., as produced by Zend\Mail) and prints it to STDOUT
from email import parser;
import argparse;
args = argparse.ArgumentParser()
args.add_argument("filename", help="path to .eml file")
@davidmintz
davidmintz / python-purge-inbox.py
Last active April 17, 2019 16:33
note-to-self: how to delete everything in an inbox (Python)
#!/usr/bin/env python3
from imapclient import IMAPClient
server = IMAPClient('imap.example.com', use_uid=True)
server.login('somebody@.example.com', '******')
select_info = server.select_folder('INBOX')
ids = server.search()
print("expunging {} messages...".format(len(ids)))
server.delete_messages(ids)
@davidmintz
davidmintz / sdny-judge-screen-scraper.js
Last active July 9, 2020 20:20
using axios and jsdom, we scrape up a federal court judge directory from the SDNY public website and output it as JSON
/**
* SDNY judge screen-scraper for node.js
*
* crawls over the USDJs and USMJs information on the nysd.uscourts.gov website
* and compiles a basic directory -- name, courthouse, courtroom -- as JSON
* data.
*
*/
const axios = require("axios");
const jsdom = require("jsdom");
@davidmintz
davidmintz / sdny-holiday-web-scrape.php
Last active January 9, 2018 19:42
scrapes official holidays from the Court's official website and inserts in our database
<?php
/**
* CLI script to scrape holidays from the SDNY website and store them in our database.
* Normally you won't need this more than about once a year. And of course shit will
* break if the HTML changes
*/
exec('hostname',$hostname);
$host = $hostname[0];
$year = date('Y');
@davidmintz
davidmintz / bullshit.sh
Created October 23, 2017 02:53
draft bash script for making Android play old mp3 in track order
#!/bin/bash
DIR=$1
cd $DIR
counter=1;
echo hello fucking $counter
PLAYLIST=playlist.m3u
@davidmintz
davidmintz / download-judge-directory.sh
Last active July 9, 2020 20:34
bash script for downloading from the [redacted] internal website a PDF whose URL changes regularly
#!/bin/bash
# download the current [redacted] judges' directory (PDF) from the internal website
# (even though they change the filename with each new update)
# where to put the PDF
dir="/opt/www/interpreters/public/files/judges";
# our bin directory
bindir='/opt/www/interpreters/bin';
@davidmintz
davidmintz / download-archive-and-delete-from-imap-folder.py
Last active December 28, 2018 16:41
Python 2.x script for downloading, archiving and removing emails from an IMAP folder
"""
download, store and delete old messages from a folder on an IMAP account.
kind of crude in that you have to hard-code values that could be taken as
command-line options, and who knows what else is wrong with this as my
first Python effort of any consequence.
"""
# to do: make python3 compatible? process command line options instead of hard-coding
import imaplib, email, mailbox, re, os.path, logging, sys, time
@davidmintz
davidmintz / hashicorp-vault-auth-cert-and-token-role-creation.md
Last active December 16, 2023 10:18
notes on setting up and using Vault TLS authentication, policies, and tokens with named roles

Our goal is to save sensitive data in a MySQL database in a responsible way, and be able to read/write it programmatically in a PHP web application. Asymmetric encryption would be best, but is not practical here. Symmetric encryption with a strong algorithm and hard-to-guess cipher is acceptable, but not if we store the cipher in plain text on the same server where the database credentials also live in plain text!

This work-in-progress is subject to change if/when I come up with a better scheme, but for now, the plan is to:

  • store the cipher as a vault secret;
  • configure TLS authentication so that our PHP application can log in, and then
  • create a token that allows its bearer to read the secret (our cipher);
  • use a PHP component and our cipher to encrypt/decrypt our sensitive data.