Skip to content

Instantly share code, notes, and snippets.

View j33ty's full-sized avatar
💭
🖥 🏕

radhe j33ty

💭
🖥 🏕
View GitHub Profile
@j33ty
j33ty / 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
@j33ty
j33ty / 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
@j33ty
j33ty / 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
################
@j33ty
j33ty / 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
@j33ty
j33ty / 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
@j33ty
j33ty / 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 = ''
@j33ty
j33ty / 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"
@j33ty
j33ty / 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'] = 'pladimir.vutin@russia.com'
msg['To'] = 'tonald.dump@us.com'
s = smtplib.SMTP('smtp.sendgrid.net', 465)
@j33ty
j33ty / download-gdrive.py
Created January 26, 2019 16:08
Download a file from Google Drive using file ID from sharable link.
import requests
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
@j33ty
j33ty / headers.py
Created January 26, 2019 16:05
Returns headers received in an HTTP request. Run it with Python 2.7.
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
PORT = 8000
class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_head()