Skip to content

Instantly share code, notes, and snippets.

View usmanity's full-sized avatar

Muhammad Usman usmanity

View GitHub Profile
@usmanity
usmanity / palindrome.js
Created August 6, 2015 03:53
a simple gist for finding a palindrome in javascript
function isPalindrome(p){
if (p.length == 0 || p.length == 1) {
return true;
} else if (p[0] == p[p.length - 1]) {
return isPalindrome(p.slice(1, p.length - 1));
} else {
return false;
}
}
@usmanity
usmanity / fibonacci.js
Created August 6, 2015 04:01
fibonacci sequence in javascript
function fib(x){
if (x == 0 || x == 1) {
return 1;
} else {
return fib(x-1) + fib(x-2);
}
}
@usmanity
usmanity / loading.py
Created April 4, 2017 05:34
loading indicator in python for CLI tools
while True:
for i in ["/", "-", "|", "\\", "|"]:
print "%s\r" % i,
@usmanity
usmanity / docker-compose.yml
Created November 26, 2017 16:28
Example of a docker compose file
version: "3"
services:
web:
image: usmanity/friendlyhello:part2
deploy:
replicas: 2
resources:
limits:
cpus: "0.1"
memory: 50M
Verifying my Blockstack ID is secured with the address 13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB https://explorer.blockstack.org/address/13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB
@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
@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

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 / 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
@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 -'