Skip to content

Instantly share code, notes, and snippets.

View JoshM1994's full-sized avatar

Josh Mustill JoshM1994

  • Span.IO
  • San Francisco
View GitHub Profile
@JoshM1994
JoshM1994 / 1099_expense.js
Created June 20, 2023 00:12
Google Apps Script for parsing email receipts
const LABEL_NAME = "1099expense"
const HANDLED_LABEL_NAME = `${LABEL_NAME}_done`
const SPREADSHEET_URL = "https://docs.google.com/spreadsheets/d/EXAMPLE-q-EXAMPLE/edit#gid=9999"
const SHEET_NAME = "All Business Expenses"
const DRIVE_RECEIPTS_FOLDER = "1099 Receipts"
// This isn't very efficient and could definitely be refactored
// It's overly explicit to allow for easier following/logging
function createLabelIfNotExists(labelName) {
const label = GmailApp.getUserLabelByName(labelName)
; Pi-hole's Lists Updater by Jack'lul
; https://github.com/jacklul/pihole-updatelists
; Remote list URL containing list of adlists to import
ADLISTS_URL="https://v.firebog.net/hosts/lists.php?type=tick"
; Remote list URL containing exact domains to whitelist
WHITELIST_URL="https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt"
; Remote list URL containing regex rules for whitelisting
const cfDist = new cloudfront.CloudFrontWebDistribution(this, 'CfDistribution', {
comment: 'CDK Cloudfront Secure S3',
viewerCertificate: ViewerCertificate.fromAcmCertificate(cert, {
aliases: [DOMAIN_NAME, WWW_DOMAIN_NAME],
}),
defaultRootObject: ROOT_INDEX_FILE,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
httpVersion: HttpVersion.HTTP2,
priceClass: PriceClass.PRICE_CLASS_100, // the cheapest
originConfigs: [
const cert = new acm.Certificate(this, 'WebCert', {
domainName: WWW_DOMAIN_NAME,
subjectAlternativeNames: [DOMAIN_NAME],
validation: CertificateValidation.fromDns(),
});
const accessIdentity = new OriginAccessIdentity(this, 'CloudfrontAccess');
const cloudfrontUserAccessPolicy = new PolicyStatement();
cloudfrontUserAccessPolicy.addActions('s3:GetObject');
cloudfrontUserAccessPolicy.addPrincipals(accessIdentity.grantPrincipal);
cloudfrontUserAccessPolicy.addResources(siteBucket.arnForObjects('*'));
siteBucket.addToResourcePolicy(cloudfrontUserAccessPolicy);
const siteBucket = new s3.Bucket(this, 'WebsiteBucket', {
encryption: BucketEncryption.S3_MANAGED,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
// No website related settings
accessControl: BucketAccessControl.PRIVATE,
publicReadAccess: false,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
});
@JoshM1994
JoshM1994 / cognito.ts
Last active December 2, 2020 21:09
Node.js (TypeScript) AWS Hosted Cognito UI auth code grant programmatically (PKCE, Client Secret, Code Challenge)
// Based on https://forums.aws.amazon.com/thread.jspa?messageID=832982#832982
import { randomBytes, createHash } from 'crypto';
import { Buffer } from 'buffer';
import fetch from 'node-fetch';
import { URLSearchParams } from 'url';
const base64UrlSafe = (b64: string) => b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
async function main() {
@asynctest.mock.patch("asyncio.create_subprocess_shell")
@pytest.mark.asyncio
async def test_list_files(self, mock_subproc_popen):
mock_subproc_popen.return_value = AsyncioCreateSubprocessShellCommunicateMock(
(
b"""
a.txt
b.txt
""",
b"",
@JoshM1994
JoshM1994 / AsyncioCreateSubprocessShellCommunicateMock.py
Created June 20, 2020 18:17
Mock calls to asyncio.create_subprocess_shell
# Used to mock calls to asyncio.create_subprocess_shell
# Patches the `communicate` object with a future as specified during construction
import asynctest
import mock
class AsyncioCreateSubprocessShellCommunicateMock:
def __init__(self, future_result):
process_mock = mock.Mock()
future = asynctest.asyncio.Future()
# https://github.com/pypa/pipenv/issues/3827#issuecomment-521442936
LOCK_FILE=$(find ~/Library/Caches/pipenv | grep lock)
sudo rm -rf ${LOCK_FILE}