Skip to content

Instantly share code, notes, and snippets.

View davidmerrick's full-sized avatar

David Merrick davidmerrick

View GitHub Profile
@davidmerrick
davidmerrick / .py
Created October 16, 2016 23:15
GET LAST MONDAY’S DATE IN PYTHON
#!/usr/bin/python
from datetime import date
from dateutil.relativedelta import relativedelta, MO
today = date.today()
last_monday = today + relativedelta(weekday=MO(-1))
print last_monday.strftime("%-m-%d")
# In the above example, the “%-m” in the date format string removes zero-padding from single-digit months.
@davidmerrick
davidmerrick / cloneAll.sh
Last active January 15, 2022 23:26
Clone all github repos in an org
#!/bin/bash
# Note: This script requires that you have $GITHUB_TOKEN set.
# Get one here: https://github.com/settings/tokens
ORG=yourOrg
HAS_NEXT=true
i=1
while $HAS_NEXT
@davidmerrick
davidmerrick / showssh.sh
Created June 27, 2017 23:14
Show SSH IP connected from
echo $SSH_CONNECTION | cut -f 1 -d " "
@davidmerrick
davidmerrick / README.md
Last active March 7, 2021 21:27
Monitoring disk space with osquery

Goal here is to monitor disk space usage on my parents' iMac, push it to Kinesis, and alert if it hits a certain threshold.

Prerequisites

Set up a Kinesis stream called osquery-firehose.

Steps

  1. Download the config.
  2. Run the command in osquery.sh.
  3. This will log to /var/log/osquery/osqueryd.results.log
@davidmerrick
davidmerrick / gist:7f42b4442e6dc3f91dc9
Created December 8, 2015 22:45
Python: check if ports are open on a remote server
import socket;
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((host,port))
if result == 0:
print "Port is open"
else:
print "Port is not open"
@davidmerrick
davidmerrick / kinesisIterate.sh
Last active October 23, 2020 04:32
Iterate over a Kinesis stream
#!/bin/bash -eux
# This script iterates over a Kinesis stream and dumps out the records.
# I used it to test whether items were getting pushed to my stream.
# Requires jq.
AWS_PROFILE=dev
AWS_REGION=us-east-1
SHARD_ID=myShard
STREAM_NAME=myStream
@davidmerrick
davidmerrick / hide.js
Created May 29, 2020 01:59
SimplePractice toggle self view bookmarklet
// Toggles hidden state of self view when using SimplePractice telehealth
function toggleSelfView(){
var selfView = document.getElementById("publisher")
if (selfView.style.display === "none") {
selfView.style.display = "block";
} else {
selfView.style.display = "none";
}
}
@davidmerrick
davidmerrick / templateCreator.js
Created June 7, 2017 17:15
JIRA template creator. Put this in a bookmarklet.
javascript:var u=document.location.protocol+"//"+document.location.host+"/CreateIssueDetails!init.jspa?",onTemplatePage=null!=document.getElementById("issue-create");if(onTemplatePage)for(var x=document.getElementById("issue-create").querySelectorAll("input,select,textarea"),i=0;i<x.length;i++)x[i].value&&(x[i].name&&x[i].name.indexOf("customfield_10151")<0||x[i].id&&x[i].id.indexOf("customfield_10151")<0)&&(u=u+(x[i].name?x[i].name:x[i].id)+"="+encodeURIComponent(x[i].value)+"&");else for(var x=document.getElementsByName("jiraform")[0].querySelectorAll("input,select,textarea"),i=0;i<x.length;i++)x[i].value&&(x[i].name&&x[i].name.indexOf("customfield_10151")<0||x[i].id&&x[i].id.indexOf("customfield_10151")<0)&&(u=u+(x[i].name?x[i].name:x[i].id)+"="+encodeURIComponent(x[i].value)+"&");document.body.insertAdjacentHTML("beforeend","<div id='x' style='word-wrap:break-word;display:inline;position:absolute;z-index:5000;left:30%;top:30%;padding:10px;width:40%;color:white;background-color:black;'>Copy this link:<br/>
@davidmerrick
davidmerrick / steps.md
Created November 5, 2019 02:45
Fixing Time Machine

When Time Machine inevitably breaks, here's how to fix it.

  1. Try doing First Aid using Disk Utility. Should repair any permissions that are messed up.
  2. Will add 2 next time I run into it :-).
@davidmerrick
davidmerrick / tm-log.sh
Created November 4, 2019 21:40
Time Machine log
#!/bin/sh
# This script shows the previous 12 hours of Time Machine activity, then shows live logs
# Reference: https://superuser.com/questions/1126990/how-to-view-time-machine-log-in-macos-sierra
filter='processImagePath contains "backupd" and subsystem beginswith "com.apple.TimeMachine"'
# show the last 12 hours
start="$(date -j -v-12H +'%Y-%m-%d %H:%M:%S')"
echo ""