Skip to content

Instantly share code, notes, and snippets.

View usmanity's full-sized avatar

Muhammad Usman usmanity

View GitHub Profile
@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 / Aaron Swartz: Guerilla Open Access Manifesto
Created January 13, 2013 07:34
Aaron Swartz: Guerilla Open Access Manifesto (making a copy for public access and personal record)
Information is power. But like all power, there are those who want to keep it for themselves. The world’s entire scientific and cultural heritage, published over centuries in books and journals, is increasingly being digitized and locked up by a handful of private corporations. Want to read the papers featuring the most famous results of the sciences? You’ll need to send enormous amounts to publishers like Reed Elsevier.
There are those struggling to change this. The Open Access Movement has fought valiantly to ensure that scientists do not sign their copyrights away but instead ensure their work is published on the Internet, under terms that allow anyone to access it. But even under the best scenarios, their work will only apply to things published in the future. Everything up until now will have been lost.
That is too high a price to pay. Forcing academics to pay money to read the work of their colleagues? Scanning entire libraries but only allowing the folks at Google to read them? Providing scientific a
@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