Skip to content

Instantly share code, notes, and snippets.

View usmanity's full-sized avatar

Muhammad Usman usmanity

View GitHub Profile
@usmanity
usmanity / virtues.md
Last active August 23, 2024 22:18
The Three Virtues of a GREAT Programmer

According to Larry Wall1, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience and Hubris:

  • Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it.
  • Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to.
  • Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.

Footnotes

  1. Quoted from "Programming Perl", 2nd Edition, O'Reilly & Associates, 1996

@usmanity
usmanity / functions.sh
Created March 28, 2024 15:57
quick commit
function commit() {
local commit_message
if [[ $# -eq 0 ]]; then
echo "Usage: commit <message>"
return 1
fi
commit_message="${*:1}"
@usmanity
usmanity / battery-info.sh
Created July 8, 2023 04:17
Script used in Alfred workflow to get battery info for macbooks
cycles=$(system_profiler SPPowerDataType | grep "Cycle Count" | awk '{print $NF}')
maxcap=$(system_profiler SPPowerDataType | grep "Maximum Capacity" | awk '{print $NF}')
condition=$(system_profiler SPPowerDataType | grep "Condition" | awk '{print $NF}')
echo '{
"items": [
{
"uid": "battery-cycles",
"arg": "'"$cycles"'",
"title": "Battery Cycles: '"$cycles"'",
"subtitle": "Copy Battery Cycles to Clipboard",
@usmanity
usmanity / git-rebase-workflow.zsh
Created June 14, 2023 16:34
Goes from feature branch to main/master branch, pulls and switches back to feature branch and then rebases
#!/bin/zsh
# Step 1: Get the current branch name
current_branch=$(git symbolic-ref --short HEAD)
# Step 2: Determine the target branch
target_branch="main" # Default to "main" branch
if ! git show-ref --verify --quiet "refs/heads/$target_branch"; then
target_branch="master" # Use "master" branch if "main" doesn't exist
fi
@usmanity
usmanity / alias.sh
Created May 8, 2023 02:55
list of my currently used aliases
# git shortcuts
alias g=git
alias gst='git status'
alias ggpush='git push origin $(git rev-parse --abbrev-ref HEAD)'
alias ggpull='git pull origin $(git rev-parse --abbrev-ref HEAD)'
alias pull='ggpull'
alias pul='ggpull'
alias ggpnp='ggpull && ggpush'
alias gco="git checkout"
alias gc-='git checkout -'
@usmanity
usmanity / branch.sh
Created May 8, 2023 02:41
creates a git branch like: `username/year/branch-name` where branch can be passed a space separated branch name
function branch() {
local branch_name
if [[ $# -eq 0 ]]; then
echo "Usage: branch <name>"
return 1
fi
if [[ $1 =~ [^a-zA-Z0-9._-] ]]; then
echo "Invalid branch name: $1"
return 1
fi

Session Checker

This component can be used on any page where you want to check if a user is logged in.

If not logged in, they will be redirected to the login page.

The useEffect hook waits until things are ready before checking the session status

@usmanity
usmanity / app.js
Last active July 13, 2020 18:30
Use the following for being able to safely get body content from HTTP requests, set the view engine (change to your liking), and displaying static content
// create an express app (import express first)
const app = express();
// tell app to use bodyParser, I believe this still needs to be imported but it's installed with express last I checked
// bodyParser will help keep your incoming http POST body clean
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// set the view engine to be pug ONLY if you want a view engine
// if you're displaying static content in vue.js or React, you can just let it be HTML
@usmanity
usmanity / move.js
Last active November 9, 2019 07:37
move to the next page
/* this version wasn't working
$(document).on('keydown', function(e) {
if (e.key == "ArrowRight" || e.key == " ") {
let next = $('a').filter((b, anchor) => $(anchor).text().includes('next') )
next.click();
}
});
*/
// working version
Verifying my Blockstack ID is secured with the address 13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB https://explorer.blockstack.org/address/13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB