Skip to content

Instantly share code, notes, and snippets.

View teamshortcut's full-sized avatar

Aaron teamshortcut

View GitHub Profile
@teamshortcut
teamshortcut / ps1.sh
Last active July 6, 2020 09:38
Custom shell prompt (PS1)
# [username@hostname ~/path (git branch)]$
# [bluepurpleblue yellow orange]$
# Outside []$ is green if previous command is successful (exit code = 0) and red otherwise
# Add https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh to your home directory
source ~/.git-prompt.sh
export PS1='$(exitcode=$?; if [[ $exitcode == 0 ]]; then printf "\[\e[32m\][\[\e[m\]"; else printf "\[\e[31m\][\[\e[m\]"; fi; printf "\[\e[34m\]\u\[\e[m\]\[\e[95m\]@\[\e[m\]\[\e[34m\]\h\[\e[m\] \[\e[33m\]\w\[\e[m\]\[\e[91m\]$(__git_ps1 " (%s)")\[\e[m\]"; if [[ $exitcode == 0 ]]; then printf "\[\e[32m\]]\$ \[\e[m\]"; else printf "\[\e[31m\]]\$ \[\e[m\]"; fi)'
@teamshortcut
teamshortcut / replace.sh
Last active August 2, 2018 09:45
Bash script to go through multiple files looking for certain lines using regex (differing between files) and replacing it with the correct corresponding text (different for each file), grabbed from a list in an external file
#!/bin/bash
#Bash script to go through multiple files looking for certain lines using regex (differing between files)
#and replacing it with the correct corresponding text (different for each file), grabbed from a list in an external file
#Expects to be placed in the same directory as the files to search through
#Relies on 2 external files; a list of filenames to edit, and the corresponding replacement text for each file (separated by newlines)
#Used to escape any problematic characters in the replacement text
escapeCharacter() #Takes 2 arguments, the character to escape and the text to escape it from
@teamshortcut
teamshortcut / weather.py
Last active April 3, 2019 02:14
Windows version, demonstrates the API
#import libraries
import requests
import time
#declare variables
#open weather map's endpoint
URL = "http://api.openweathermap.org/data/2.5/weather?q="
#the authorisation key
KEY = "&APPID=9caeab719c222439d4a2747fc6591523"
@teamshortcut
teamshortcut / weatherPi.py
Last active November 6, 2017 23:33
Hydrogen Hack 2017 Weather Duck
#import libraries
import requests
import RPi.GPIO as GPIO
import time
#declare variables
#open weather map's endpoint
URL = "http://api.openweathermap.org/data/2.5/weather?q="
#the authorisation key