Skip to content

Instantly share code, notes, and snippets.

@gitcnd
gitcnd / ejectusb.py
Created December 4, 2022 12:33
Windows commandline to eject a USB drive
#!/usr/bin/python3
# From DOS commandline, run this as follows:-
# python3 ejectusb.py
# -or- create C:\windows\ejectusb.bat to do the above in fewer characters.
#
# From WSL bash, run it as follows:-
# cmd.exe /c start python3 C:\\windows\\ejectusb.py
# -or- create /usr/local/bin/ejectusb to do the above in fewer characters.
@gitcnd
gitcnd / get_local_addr.py
Created November 12, 2021 01:36
Returns the current IPv4 LAN (or WAN if that's the default route) IP address. Can also do IPv6 if you want (remove the ipv6=False for that)
#!/usr/bin/env python3
import errno, socket, logging # for get_local_addr
# localhost prefixes
_local_networks = ("127.", "0:0:0:0:0:0:0:1")
# ignore these prefixes -- localhost, unspecified, and link-local
_ignored_networks = _local_networks + ("0.", "0:0:0:0:0:0:0:0", "169.254.", "fe80:")
@gitcnd
gitcnd / nowrap.pl
Last active July 15, 2021 01:00
nowrap - truncates input lines longer than the current terminal width - Usage: cat somefile_with_long_lines.txt | nowrap.pl
#!/usr/bin/perl -w
# truncates input lines longer than the current terminal width
# Usage:-
# cat somefile_with_long_lines.txt | nowrap.pl
use strict;
my $cols=`tput cols`; chomp $cols;