Skip to content

Instantly share code, notes, and snippets.

View techiev2's full-sized avatar
🥷

Sriram Velamur techiev2

🥷
View GitHub Profile
@techiev2
techiev2 / json_to_recursive_object.py
Last active August 8, 2021 13:41
Recursively convert a JSON structure to an object
from json import loads
from dataclasses import dataclass
@dataclass
class BaseObject:
@classmethod
def from_dict(cls, _dict):
entity = BaseObject()
entity.__dict__ = _dict
@techiev2
techiev2 / app.py
Last active June 28, 2021 18:17
Simple route to expose all of an API's routes and basic information in a Flask app
import inspect
def is_json_responder(responder_fn):
"""Helper function to check if a function is a JSON responder. Uses
inspect to get the source code and identifies the last line being a
jsonify call
"""
lines = [_ for _ in inspect.getsource(responder_fn).split("\n") if _]
return "jsonify({" in lines[-1]
@techiev2
techiev2 / removeNonDeliverables.js
Created July 3, 2020 06:23
Bookmarklet to remove non-deliverable items from Amazon search listing page
javascript:(function() { Array.from(document.querySelectorAll('.s-result-item')).filter(el => el.innerText.indexOf('Currently not deliverable') !== -1).map((el) => el.parentElement.removeChild(el)); })()
@techiev2
techiev2 / gitsubtree-manage.sh
Last active June 23, 2020 15:44
git subtree management helper functions
function gstup() {
if [[ -z $1 ]]; then
echo -e "A subtree name is required"
return
fi
if [[ -z $2 ]]; then
echo -e "Subtree's branch name is required"
return
fi
# Stash local changes to prevent collisions
@techiev2
techiev2 / goto.py
Created May 5, 2020 13:09 — forked from georgexsh/goto.py
python goto with system trace function
import sys
def j(lineno):
frame = sys._getframe().f_back
called_from = frame
def hook(frame, event, arg):
if event == 'line' and frame == called_from:
try:
frame.f_lineno = lineno
@techiev2
techiev2 / updateFromDev.sh
Created April 24, 2020 07:33
Update the codebase against development[/other branch] using a rebase
alias updateFromDev='git stash && git pull origin development --rebase && git stash pop'
function cd() {
builtin cd "$@" || return
if [[ -d .git ]]
then
updateFromDev
fi
}
# Adopted from https://unix.stackexchange.com/a/366923
@techiev2
techiev2 / setBrightness
Last active December 15, 2018 17:43
Shell script to set the keyboard background brightness on Ubuntu installs.
#! /bin/bash
# Utility script to set keyboard backlight level from command line.
# The kernel that ships with stock Ubuntu lacks the hardware support
# for certain devices like the keyboard backlight.
# Ref: [1], [2].
# This script uses the tweak suggested here([3]) to set the background
# light levels.
# Caveat emptor: The script uses the max_brightness file in the device
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@techiev2
techiev2 / mergelatestremote.sh
Last active April 30, 2017 21:07
Helper script to fetch the latest changed remote and merge to master.
#!/bin/bash
function getRemotes {
remotes=`git branch -r | grep -v HEAD`
local branches=""
for branch in $remotes; do
echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch;
done | sort -r | head -n 1 | awk '{print $7}'
echo $branches
}
@techiev2
techiev2 / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console