Skip to content

Instantly share code, notes, and snippets.

View stonecharioteer's full-sized avatar

Vinay Keerthi stonecharioteer

View GitHub Profile
@stonecharioteer
stonecharioteer / script.py
Created November 23, 2022 08:03
Safe exit for command line applications in python.
import sys
def cli_function():
"""This is a python function that offers a CLI or does some long running
task that you might want to interrupt"""
if __name__ == "__main__":
try:
cli_function()
@stonecharioteer
stonecharioteer / README-jq-fzf-REPL.md
Last active September 20, 2022 07:50 — forked from reegnz/README.md
Implementing a jq REPL with fzf

Implementing a jq REPL with fzf

Update: I created jq-zsh-plugin that does this.

One of my favourite tools of my trade is jq. It essentially enables you to process json streams with the same power that sed, awk and grep provide you with for editing line-based formats (csv, tsv, etc.).

Another one of my favourite tools is fzf.

@stonecharioteer
stonecharioteer / clean-docker.sh
Created March 3, 2022 04:43 — forked from buckett/clean-docker.sh
Cleans out old docker images and containers.
#!/bin/bash
# Clean all exited containers
docker ps -qaf status=exited | xargs docker rm
# Remove all unused images
docker images -f dangling=true -q | xargs docker rmi
@stonecharioteer
stonecharioteer / profiler
Created January 6, 2022 12:13 — forked from disusered/profiler
Profiling Neovim startup
#!/bin/bash
iterations=10
# -----------------------------------------------------------------------------
# Create array of results
declare -a results
for i in $(seq 1 $iterations);
@stonecharioteer
stonecharioteer / closures.py
Last active October 22, 2021 14:37
Python Closures - Bangpypers Lightning Talk 2021-10-22
"""Examples to show how Python stores the closure metadata in a decorator.
Know that this information isn't always just attached to a decorator. It could
also be passed around with regular functions, if the conditions match.
That is, if a variable from a higher scope is _referenced_ from a variable in
another scope, which is passed around, then, a __closure__ meta variable is
attached to the object that is passed around, where it has a store of what its
'closure' is.
git_current_branch () {
local ref
ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]]
then
[[ $ret == 128 ]] && return
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
fi
echo ${ref#refs/heads/}
@stonecharioteer
stonecharioteer / flask_profiler.py
Created July 14, 2020 13:07 — forked from shreyansb/flask_profiler.py
A profiler for Flask apps
"""
This module provides a simple WSGI profiler middleware for finding
bottlenecks in web application. It uses the profile or cProfile
module to do the profiling and writes the stats to the stream provided
To use, run `flask_profiler.py` instead of `app.py`
see: http://werkzeug.pocoo.org/docs/0.9/contrib/profiler/
and: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling
"""
@stonecharioteer
stonecharioteer / puzzle.py
Last active September 17, 2019 04:18
run this to decode
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""This is a rot-13 encoded puzzle. Interestingly, this is how the `this` module is implemented
in Python.
Did you know that the `this` module breaks the Zen of Python in almost *every* possible way?
Run this on Python Anywhere and you can see the output on your phone.
Here's a `link <https://www.pythonanywhere.com/user/stonecharioteer/shares/61f863777d13449599ecab5bf11ff34d/>`_.
@stonecharioteer
stonecharioteer / puzzle.py
Created September 17, 2019 04:06
run this to decode
s = """Jrypbzr gb gur svefg Ivfn OnatClcref zrrghc rirelbar!
Guvf vf gur svefg gvzr jr'ir vaivgrq gur Onatnyber Clguba zrrghc pbzzhavgl gb bhe bssvpr, fb rirelbar gnxr n punapr gb argjbex.
Funer lbhe xabjyrqtr, lbhe gvcf naq lbhe rkcregvfr bs Clguba.
Nobir nyy, unir sha!!
Gb bhe ivfvgbef, Ivfn vf uvevat. Ernpu bhg gb hf naq funer lbhe erfhzrf."""
@stonecharioteer
stonecharioteer / puzzle.py
Created September 17, 2019 04:06
run this to decode
s = """Jrypbzr gb gur svefg Ivfn OnatClcref zrrghc rirelbar!
Guvf vf gur svefg gvzr jr'ir vaivgrq gur Onatnyber Clguba zrrghc pbzzhavgl gb bhe bssvpr, fb rirelbar gnxr n punapr gb argjbex.
Funer lbhe xabjyrqtr, lbhe gvcf naq lbhe rkcregvfr bs Clguba.
Nobir nyy, unir sha!!
Gb bhe ivfvgbef, Ivfn vf uvevat. Ernpu bhg gb hf naq funer lbhe erfhzrf."""