Skip to content

Instantly share code, notes, and snippets.

View davidmintz's full-sized avatar

David Mintz davidmintz

View GitHub Profile
@davidmintz
davidmintz / drush-turn-off-aggregate-assets.txt
Last active September 9, 2015 12:21 — forked from chrisjlee/drush-turn-off-aggregate-assets.txt
drush disable js/css aggregation
// To turn on JS Aggregation
drush vset preprocess_js 1 --yes
// To clear all Cache
drush cc all
// To disable JS Aggregation
drush vset preprocess_js 0 --yes
// To clear cache of JS and CSS only
@davidmintz
davidmintz / display_validation_errors.js
Created December 29, 2016 17:34
a js function that displays validation error messages from an object whose structure matches that returned by Zend\Form\Form::getMessages()
displayValidationErrors = function(validationErrors) {
$('.validation-error').empty();
for (var field in validationErrors) {
//console.log("examining field "+field);
for (var key in validationErrors[field]) {
// console.log("examining key "+key);
var message = validationErrors[field][key];
var element = $('#' +field);
var errorDiv = $('#error_'+field);
if (! errorDiv.length) { errorDiv = null;}
@davidmintz
davidmintz / attaching-Doctrine-entity-listener.php
Last active March 1, 2017 22:03
just a snippet for discussion purposes
<?php
namespace MyAwesomeModule;
use Zend\Mvc\MvcEvent;
use Doctrine\ORM\Events;
class Module
{
@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.
@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 / 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 / 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 / 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 / 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 / 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('[email protected]', '******')
select_info = server.select_folder('INBOX')
ids = server.search()
print("expunging {} messages...".format(len(ids)))
server.delete_messages(ids)