Skip to content

Instantly share code, notes, and snippets.

View ashafer01's full-sized avatar
🤓
1.3.6.1.4.1.53450

Alex Shafer ashafer01

🤓
1.3.6.1.4.1.53450
  • San Francisco, CA
View GitHub Profile
#!/usr/bin/perl -w
# USAGE:
#
# /RSAY <text>
# - same as /say, but outputs a coloured text
#
# /RME <text>
# - same as /me, but outputs a coloured text
#
#!/usr/bin/perl -w
# USAGE:
#
# /RSAY <text>
# - same as /say, but outputs a coloured text
#
# /RME <text>
# - same as /me, but outputs a coloured text
#
@ashafer01
ashafer01 / runCmd.py
Last active November 14, 2015 23:08
A better way to Popen
import subprocess
import shlex
str_types = [str, unicode]
def runCmd(cmd, *args, **kwargs):
kwargs['stdout'] = kwargs.get('stdout', subprocess.PIPE)
kwargs['stderr'] = kwargs.get('stderr', subprocess.PIPE)
stdin = ''
if 'stdin' in kwargs and type(kwargs['stdin']) in str_types:
## get info about the other end of a unix socket!
# shown at PyCon 2016 Talk "File descriptors, Unix sockets and other POSIX wizardry"
# by Christian Heimes
# condensed by me
import socket, struct
# this is not defined in any python version I have readily at hand
# taken from /usr/include/asm-generic/socket.h on debian 7.9
@ashafer01
ashafer01 / cli_progress.py
Created October 18, 2016 02:53
A simple CLI progress meter with estimated completion time
import sys
import locale
from datetime import datetime, timedelta
locale.setlocale(locale.LC_ALL, 'en_US.utf-8')
def _thou_sep(num):
return locale.format('%d', int(num), grouping=True)
def _plural(num, word):
@ashafer01
ashafer01 / a1col.js
Created May 6, 2018 23:57
A1 Column to Index
// Convert an A1 Notation column to a zero-based index
// A -> 0, Z -> 25, AA -> 26, AZ -> 51, ZZ -> 701, AAA -> 702, ...
var alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function a1ColIndex(colString) {
var index = 0;
var len = colString.length;
var colLetter, numval;
for (var i = 0; i < len-1; i++) {
@ashafer01
ashafer01 / roku_remote.py
Last active September 14, 2018 05:14
A very simple terminal-based CLI remote for the only roku device on your network
#!/usr/bin/env python3
"""
A very basic CLI remote control for a Roku device
Requires:
ssdp
requests
Written with Python 3.7
"""
@ashafer01
ashafer01 / check-path-shadow.sh
Last active October 1, 2023 15:34
check if a proposed addition (prepend) to your $PATH will shadow anything
# check if a proposed addition (prepend) to your $PATH will shadow anything
# outputs the absolute paths to the executable to be shadowed, below a heading of the new path entry that will shadow it
# e.g. NEW_PATH_ELEMENTS="/home/me/git/suspicious_package/bin:/home/me/git/iffy_repo/bin"
for f in $(echo "$NEW_PATH_ELEMENTS" | tr : ' '); do
echo "== $f =="; find -L $f -maxdepth 1 -type f -executable | xargs -I{} basename {} | sort | xargs -I{} which {}
done
@ashafer01
ashafer01 / userContent.css
Created November 25, 2018 18:23
Vertically and horizontally center the content on firefox about:home after customizing the content in preferences
/* @-moz-document (about:home) DOES NOT WORK :(
use this heuristic selector applied to all pages instead */
html > body.activity-stream > div#root > div[data-reactroot] > div.outer-wrapper > main {
/* force-center the content based on computed values for
MacBook Retina 12" Early 2016 2304x1400 */
position: absolute;
left: calc((100% - 1042px)/2);
top: calc((100% - 566px)/2);
}
@ashafer01
ashafer01 / formatter.py
Created January 17, 2019 17:22
Python custom string.Formatter example
import string
class MyForm(string.Formatter):
def parse(self, format_string):
for tpl in string.Formatter.parse(self, format_string):
print(tpl)
literal_text, field_name, format_spec, conversion = tpl
if field_name:
literal_text += f'"{field_name}"'
yield literal_text, None, None, None