Skip to content

Instantly share code, notes, and snippets.

View str_to_bytes
def bytes_to_str(size, mebi=False, precision=2):
"""Accept size in bytes, return size in string with KB, MB, GB
Will always return, increase the fields with TB, etc to prevent
103892GB or similar"""
mult = 1024 if mebi else 1000
units = {1000: ['KB', 'MB', 'GB'],
1024: ['KiB', 'MiB', 'GiB']}
for unit in units[mult]:
size = size / mult
if size < mult:
jmacego /
Created Mar 16, 2020
rom folder to playlist - RetroPie PSX
# Take a folder with a structure like:
# File (Disc 1).bin
# File (Disc 1).cue
# File (Disc 2).bin
# File (Disc 2).cue
# ...
# and rename the .cue files to .CD# and then create a .m3u
# suitable to RetroPie
for i in *.cue; do
jmacego /
Last active Mar 14, 2019
Bash function to pull jekyll site and serve
# Profile function to add a convenient jekyllserve command and also a
# function to cd to the directory, do a git pull, open in sublime,
# serve the site and then open it in a web browser.
# Works on OSX with sublime CLI installed. YMMV for other platforms.
# You also probably want to rename things. Consider this a template.
# Also... I just have this in my ~/.profile so I type jmaclabs and it
# just works. Here's how that looks different:
jmacego / meraki-wider-comments-bookmarklet
Created Mar 14, 2019
Bookmarklet to widen the comment field on Meraki Switch ACLs and Firewall policies
View meraki-wider-comments-bookmarklet
javascript:(function(){var inputs = document.getElementsByTagName("input");for(var i = 0; i < inputs.length; i++) {if(inputs[i].name.match(/comment/) || inputs[i].className.match(/comment/) ) {inputs[i].size = 100;}}})();
jmacego /
Last active Apr 10, 2022
Efficiently create a number of subnets out of a larger prefix
from __future__ import print_function
import ipaddress
def do_vlsm(sorted_vlans):
supernet = input("Supernet: ") or ""
current_subnet = ipaddress.ip_network(supernet)
available_subnets = [current_subnet]
print("\nSubnet Lengths:")
for vlan in sorted_vlans:
jmacego /
Last active Mar 1, 2019
Script to name / interact with interfaces when ports 1-24 are plugged into the top and ports 25-48 are plugged into the bottom of a switch
from __future__ import print_function # Python 2 compatibility fix
# Script to name ports for natural patching (1 to 1, 2 to 3..25 to 2).
i = 1 # Initialize to the starting number for your port .
# Set starting number, ending number, and increment setting an increment
# of 2 is most common.
for x in range(1, 48, 2):
i += 1 # this really could to at the end and not have the -1 in the
jmacego / AS Prefix Search
Last active Mar 11, 2019
Query Level3s IRR for prefixes advertised by an AS MACRO, in blocks short enough to not break Kibana's URL
View AS Prefix Search
jmacego /
Last active Jun 19, 2018
Huawei e397u-53 Connectivity
#!/usr/bin/env python
from __future__ import print_function
from sys import argv
import socket
import struct
Decode the DHCP string given by AT^DHCP? on Huawei USB Modem and
print out appropriate commands to add it statically.
Tested under Python 2.7, 3.5, and 3.6
No warranty of any kind.

Keybase proof

I hereby claim:

  • I am jmacego on github.
  • I am jmacego ( on keybase.
  • I have a public key ASAlzNsoMHLfzKe1yOCpPuBcl2bjtgP1cDVnei7I69HJUwo

To claim this, I am signing this object: