Skip to content

Instantly share code, notes, and snippets.

View rdyv's full-sized avatar
💭
🖥 🏕

radhe rdyv

💭
🖥 🏕
View GitHub Profile
@rdyv
rdyv / docker-registry.sh
Created May 20, 2019 06:47
Docker registry
curl -ks registry/v2/_catalog | jq '.["repositories"] | join(" ")' | tr -d '"'
curl -ks registry/v2/go/tags/list | jq .
curl -ks registry/v2/_catalog | jq .
@rdyv
rdyv / regex-cheatsheet.js
Created May 16, 2019 19:48
Regex cheatsheet copied from dev.to
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@rdyv
rdyv / upgrade-bash-macos.sh
Created May 16, 2019 18:21
MacOS is locked to bash 3.2. Manually upgrade to newer versions using this script.
# Check current bash version
bash --version
# Install unofficial version of bash
brew install bash
# List bash binaries
which -a bash
# Whitelist new bash shell
@rdyv
rdyv / go-package-tree.sh
Last active May 16, 2019 19:11
Print Go package names in tree form
SEDMAGIC='s;/[^/]*;|____;g;s;____|; |;g'
for f in $(find . -name "*.go" -print); do
line=$(head -n 1 "$f");
[[ ! -z "$line" ]] && [[ "$line" =~ ^package[\ ][a-z_]+$ ]] && is_package=true
if [ "$is_package" = true ]; then
tree=$(echo "$f" | sed -e "$SEDMAGIC");
package_name=$(echo $line | cut -d' ' -f 2);
echo "$tree $package_name"
fi
done
@rdyv
rdyv / git-oh-shit.sh
Created May 14, 2019 08:40
git-oh-shit.sh
################
# I did something terribly wrong, please tell me git has a magic time machine!
git reflog
# You will see a list of every thing you've done in git, across all branches!
# Each one has an index HEAD@{index}
# Find the one before you broke everything
git reset HEAD@{index}
# Magic time machine
################
@rdyv
rdyv / remove-oneplus-apps.md
Last active April 26, 2019 00:21
Remove Oneplus Default Apps
  1. adb devices
  2. adb shell
  3. pm list packages -f
  4. pm uninstall -k --user 0 com.oneplus.opbugreport
@rdyv
rdyv / battery_notification.sh
Created March 25, 2019 16:57
Get notification on Mac for low battery
#!/bin/bash
# Add this function to cronjob
# This will it every 2 minutes: "2 * * * * /path/to/script"
# Define a function to show the notification on MacOS
function notify() {
if [ $# -eq 3 ]; then
osascript -e "display notification \"$2\" with title \"$1\" sound name \"$3\""
fi
@rdyv
rdyv / file-server.py
Created January 26, 2019 16:45
A slightly funky version of SimpleHTTPServer
import sys
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
def test(HandlerClass=SimpleHTTPRequestHandler,
ServerClass=BaseHTTPServer.HTTPServer):
protocol = "HTTP/1.0"
host = ''
@rdyv
rdyv / file-server.go
Created January 26, 2019 16:19
Serve file system over HTTP Server . Alternative to SimpleHTTPServer (http.server) of Python.
package main
import "net/http"
import "net/url"
import "io"
import "os"
import "mime"
import "path"
import "fmt"
import "flag"
@rdyv
rdyv / email.py
Created January 26, 2019 16:15
Send mail from terminal via any Mail Service using their API keys. This is for testing multiple Mail providers during outage.
import smtplib
from email.mime.text import MIMEText
msg = MIMEText('Loved your locker room talk!')
msg['Subject'] = 'Not so confidential stuff here'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
s = smtplib.SMTP('smtp.sendgrid.net', 465)