Skip to content

Instantly share code, notes, and snippets.

View Seeker1911's full-sized avatar
🌲
Sharpen? I've had no time to sharpen my axe. I have been so busy cutting trees

Michael Mead Seeker1911

🌲
Sharpen? I've had no time to sharpen my axe. I have been so busy cutting trees
View GitHub Profile
@Seeker1911
Seeker1911 / setup.md
Last active September 17, 2021 12:23
Running python < 3.9.X on Apple Silicon

TLDR: There are no valid Python builds available for <=3.8 native to Apple Silicon but you can do it using Apple's Rosetta translation layer.

  1. Create a Rosetta Terminal.
  • you can ctrl click on a terminal of your choice (I used iTerm) and duplicate the application.
  • rename duplicate (I used "Rosetta iTerm" cuz I'm so clever)
  • ctrl-click the new terminal and select get info and check the box "open using Rosetta"
  1. Open Rosetta Terminal and run all the following commands there but note that your regular arm64 terminal will still run just fine and I'll prove it at the end of this explanation. Run some fancy terminal commands
  • type arch you should see "i386". Congrats, you're now using Rosetta and you may proceed.
@Seeker1911
Seeker1911 / rsync.sh
Created April 14, 2017 23:11
linux backup and rsync
“As a practical example, let’s consider the imaginary external hard drive that we used earlier with tar.
If we attach the drive to our system and, once again, it is mounted at /media/BigDisk, we can perform a useful system backup
by first creating a directory named /backup on the external drive and then using rsync to copy the most important stuff
from our system to the external drive:
[me@linuxbox ˜]$ mkdir /media/BigDisk/backup
[me@linuxbox ˜]$ sudo rsync -av --delete /etc /home /usr/local /media/BigDisk/backup
In this example, we copy the /etc, /home, and /usr/local directories from our system to our imaginary storage device.
We included the --delete option to remove files that may have existed on the backup device that no longer existed on the
source device (this is irrelevant the first time we make a backup but will be useful on subsequent copies). Repeating the
procedure of attaching the external drive and running this rsync command would be a useful (though not ideal) way of keeping
@Seeker1911
Seeker1911 / history.sh
Created February 11, 2017 23:41
find previous command and execute or copy from history.
“history | grep /usr/bin
And let’s say that among our results we got a line containing an interesting command like this:
88 ls -l /usr/bin > ls-output.txt
The number 88 is the line number of the command in the history list. We could use this immediately with another type of expansion called history expansion. To use our discovered line, we could do this:
[me@linuxbox ˜]$ !88
bash will expand !88 into the contents of the 88th line in the history list. We will cover other forms of history expansion a little later.
bash also provides the ability to search the history list incrementally. This means that we can tell bash to search the history list as we enter characters, with each additional character further refining our search. To start an incremental search, enter ctrl-R followed by the text you are looking for. When you find it, you can either press enter to execute the command or press ctrl-J to copy the line from the history list to the current command line. To find the next occurrence of the text (moving “
@Seeker1911
Seeker1911 / Linux_snippets.sh
Last active February 12, 2017 20:52
Some useful commands from "The Linux Command Line" by William E. Shotts jr.
ls /usr/bin | tee ls.txt | grep zip
“Tee is useful for capturing a pipeline’s contents at an intermediate stage of processing.”
mkdir {2009..2011}-0{1..9} {2009..2011}-{10..12}
"using brace expanion you can create a command to iterate through a set of instrucitons. This creates an ordered list of
directories year/month format"
file $(ls /usr/bin/* | grep zip)
“the results of the pipeline became the argument list of the file command.”
@Seeker1911
Seeker1911 / duplicate_to_less.txt
Created February 11, 2017 21:07
“In this example, we use uniq to remove any duplicates from the output of the sort command. If we want to see the list of duplicates instead, we add the -d option to uniq like so: ” Excerpt From: William E. Shotts Jr. “The Linux Command Line.” iBooks.
“ls /bin /usr/bin | sort | uniq -d | less”
Excerpt From: William E. Shotts Jr. “The Linux Command Line.” iBooks.
@Seeker1911
Seeker1911 / output_error.txt
Created February 11, 2017 20:47
“In this example, we use the single notation &> to redirect both standard output and standard error to the file ls-output.txt.” Excerpt From: William E. Shotts Jr. “The Linux Command Line.” iBooks.
ls -l /bin/usr &> ls-output.txt
add a 2nd > "&>>" to concat to file instead of overwrite from beginning. :)
@Seeker1911
Seeker1911 / object_to_json.py
Created February 11, 2017 12:14
Turn a Python object to JSON
import json
class objectjson:
def __init__(self, json_data):
if isinstance(json_data, basestring):
json_data = json.loads(json_data)
self.json_data = json_data
def __getattr__(self, key):
if key in self.json_data:
if isinstance(self.json_data[key], (list, dict)):
return objectjson(self.json_data[key])