Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Hashbrown777 / prompt.bashrc
Created Feb 9, 2020
neat coloured prompt for bash that shows `user@pcname:pwd\n$?>` where $? changes between red and green if it was an error or no
View prompt.bashrc
prompt-color() { printf '\\[\e[38;5;%sm\\]%s\\[\e[m\\]' "$1" "$2"; }
PS1="$(printf '%s' \
'\n' \
`prompt-color 226 '\u'` \
'@' \
`prompt-color 208 '\h'` \
':' \
`prompt-color 207 '\w'` \
'\n' \
`prompt-color '$(( $?==0 ? 82 : 196 ))' '$?'` \
@Hashbrown777
Hashbrown777 / hairOfTheDiff.sh
Created Feb 9, 2020
compare files line-by-line, showing differences within each line by colour-highlighting (or visual symbols)
View hairOfTheDiff.sh
#!/bin/bash
same='-' #unchanged
up='' #exists in first line, but not in second
down='' #exists in second line, but not in first
reset=''
reset=$'\e[0m'
same=$reset
up=$reset$'\e[1m\e[7m'
@Hashbrown777
Hashbrown777 / blameDiff.sh
Created Feb 9, 2020
performs an `svn diff` but includes `svn annotate` metadata
View blameDiff.sh
function blameDiff() {
file="$1"
rev1="$2"
rev2="$3"
#default to HEAD if omitted
if [ -n "$rev1" ]
then
title1="(revision $rev1)"
else
@Hashbrown777
Hashbrown777 / lockMonitor.sh
Created Feb 9, 2020
outputs "Locked" & "Unlocked" + `date` every time the [fedora+plasma] machine's screen is locked/unlocked. Add to startup script like `nohup lockMonitor.sh >>locklog.txt &`
View lockMonitor.sh
#!/bin/bash
#prints out, among other things;
# string "org.kde.screensaver"
#transform it to 'org.kde.screensaver'
service=$(\
dbus-send \
--session \
--dest=org.freedesktop.DBus \
--type=method_call \
@Hashbrown777
Hashbrown777 / rezip.sh
Created Feb 9, 2020
rezip an archive at a higher compression rate with no temp files. reading zip metadata, demo of unzipping/zipping a stream, and deleting/renaming files inside a zip
View rezip.sh
zipinfo -1 A.zip | while read filename
do
unzip -p A.zip "$filename" | zip -9 A.zip -
zip --delete A.zip "$filename"
printf "@ -\n@=$filename\n" | zipnote -w A.zip
done
@Hashbrown777
Hashbrown777 / change_reddit_wallpaper.py
Created Feb 9, 2020
downloads and sets the desktop background to today's top hot image from the specified subreddits
View change_reddit_wallpaper.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import argparse
import ctypes
import os
#requires version 3.5 of praw
import praw
import platform
import re
@Hashbrown777
Hashbrown777 / patcher.sh
Last active Feb 17, 2020
performs releases from zips meant to overwrite live files, backs up & allows you to preview changes beforehand
View patcher.sh
#!/bin/bash
method="$1"
name="$2"
archives="$(dirname "${BASH_SOURCE[0]}")"
live=`pwd`
release="$archives/$name.zip"
backup="$archives/${name}_BAK.zip"
log="$live/released.txt"
@Hashbrown777
Hashbrown777 / resize.ps1
Last active Jul 30, 2020
Resizes high-resolution images to appropriate sizes for use in websites
View resize.ps1
Add-Type -AssemblyName System.Drawing
Filter PointF {
[System.Drawing.PointF]::new($_[0], $_[1])
}
Function ToArray {
Begin { $output = [System.Collections.ArrayList]::new() }
Process { $output.Add($_) | Out-Null }
End { return ,$output }
@Hashbrown777
Hashbrown777 / audioTabBbCode.ps1
Created Aug 15, 2020
Grab all music metadata and output it in bbcode
View audioTabBbCode.ps1
Function Bbcode-Row {
Param ([switch]$Heading, $From)
Begin {
'[tr]'
}
Process {
('[th]','[td]')[!$Heading]
if ($From) {
$_ = $From."$_"
}
@Hashbrown777
Hashbrown777 / prompt.Microsoft.PowerShell_profile.ps1
Last active Sep 6, 2020
neat coloured prompt for powershell that shows `user@pcname:pwd\nwinsymbol>` where winsymbol changes between red and green if the last command resulted in an error or no
View prompt.Microsoft.PowerShell_profile.ps1
function Prompt {
$error = !$?
Write-Host
Write-Host -NoNewline -ForegroundColor Yellow ([Environment]::UserName)
Write-Host -NoNewline '@'
Write-Host -NoNewline -ForegroundColor Cyan ([Environment]::MachineName)
Write-Host -NoNewline ':'
Write-Host -ForegroundColor Magenta $PWD
Write-Host -NoNewline -ForegroundColor ('Green','Red')[$error] ("$([char]0x2756)", '$')[$PSVersionTable.Platform -match '^($|(Microsoft )?Win)']
Write-Host -NoNewline -ForegroundColor DarkGray '>'