This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crontab -e | |
# Then, in vim editor, add | |
*/30 * * * * osascript -e 'display notification "🚰 drink water 🚰"' | |
# Then, save and exit | |
:wq | |
# To confirm, run | |
crontab -l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def ez_add_utms(text, domain, utms): | |
def add_utm(match): | |
if "?" not in match.group(0): | |
return match.group(0) + "?" + utms.lstrip("?") | |
return match.group(0) + "&" + utms.lstrip("?") | |
return re.sub(domain.replace(".", "\.") + "[^\s<>]*", add_utm, text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This solves a problem where a function in one source.js file wants to call a function in a separate source-2.js file that has yet to be defined | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function runFunctionOnceDefined(functionName) { | |
while(typeof window[functionName] !== "function") { | |
await sleep(50); // check every 0.05s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import os | |
def get_stripe_checkout_session(checkout_session_id): | |
api_url = "https://api.stripe.com/v1/checkout/sessions/" | |
api_url += checkout_session_id | |
api_url += "?expand[]=line_items" | |
api_url += "&expand[]=customer" | |
api_url += "&expand[]=total_details.breakdown.discounts.discount" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: 'Creates an IAM User with attached Role for VENDOR Access' | |
Resources: | |
User: | |
Type: AWS::IAM::User | |
Properties: | |
UserName: 'VENDOR-access-iam-user' | |
Tags: | |
- Key: "deployment" | |
Value: "CloudFormation" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
def shutdown(signum, frame): | |
logging.error(f'Caught SIGTERM {signum}, shutting down') | |
exit(0) | |
if __name__ == "__main__": | |
# Register handler | |
signal.signal(signal.SIGTERM, shutdown) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DO NOTE: this will generate a url even if the file_name is not actually in the bucket | |
def generate_s3_presigned_url(bucket_name, file_name, **kwargs): | |
client = boto3.client( | |
's3', | |
config=Config( | |
signature_version='s3v4', | |
s3 = {'use_accelerate_endpoint': kwargs.get("accelerate_endpoint", False)} | |
) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from string import hexdigits | |
import logging | |
# ex: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | |
def is_ipv6(potential_ip_str): | |
pieces = potential_ip_str.split(':') | |
if len(pieces) != 8: | |
return is_ip = False | |
else: | |
for i in range(len(pieces)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes the contents of the clipboard, replaces apostrophes (') with quotation marks (") and replaces titlecased bools (True/False) with JSON acceptable lowercase, then pretty prints | |
function pjson() { | |
pbpaste | sed "s/'/\"/g" | sed "s/True/true/g" | sed "s/False/false/g" | json_pp | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
""" | |
Zip is at the dict level - if only some of the dicts in a lod have a key, | |
only resultant dicts with one of their primary_keys will have that given k:v pair | |
When both lods have a given (non-primary) key, the lod_2 value is prioritized. | |
Originally from https://stackoverflow.com/questions/5501810/join-two-lists-of-dictionaries-on-a-single-key | |
""" | |
def zip_lods(lod_1, lod_2, primary_key, **kwargs): |