Skip to content

Instantly share code, notes, and snippets.

View jeenuv's full-sized avatar

Jeenu Viswambharan jeenuv

  • Cambridge, UK
View GitHub Profile
@jeenuv
jeenuv / cleanup_linux_pkg.py
Last active May 6, 2019 06:32
Find and list older kernel packages to stdout
#!/usr/bin/env python3
#
# Script to print out outdated Linux kernel packages, and print them to stdout.
# Can be used as:
#
# sudo -v
# python3 cleanup_linux_pkg.py | xargs sudo apt-get remove -y
#
# But please do confirm the output packages are correct by inspecting the
# printed list first!
@jeenuv
jeenuv / examine_git_conflict.sh
Created November 9, 2015 09:50
Examine git conflict by opening ancestors in separate Vim windows
#!/bin/bash
#
# One file name is expected as arguent, which is assumed to be a file in
# conflict, after a merge or cherry-pick. This script opens the file that
# belongs to the common ancestor, our (the target branch's) copy, their
# (incoming commit), and the current copy (conflicted) in a layout below
#
# +---------------------+
# | common |
# +---------+-----------+
@jeenuv
jeenuv / show-branch
Last active September 2, 2015 13:54
Hands-free git show-branch
#!/bin/bash
#
# Script for hands-free use of 'git show-branch', with the option of specifying
# unwanted refs by prefixing with ^ at the command line (syntax elsewhere
# permitted). Refs to be ignored permanently can be added to $sed_script below
# Main upstream branch
upstream="${upstream:-origin/master}"
# Refs pattern to always ignore
@jeenuv
jeenuv / describe_branches.sh
Last active August 29, 2015 14:11
Print descriptions of all local branches
#!/bin/bash
# For each branch in the repository, get the branch description from
# Git config, and print in a neat fashion
[ -d .git ] || exit 1
git for-each-ref refs/heads --format='%(refname:short)' | grep -v '\.stgit' |
xargs bash -c '
head="$(git symbolic-ref --short HEAD)"
@jeenuv
jeenuv / find_locked_sqlite_db.sh
Created November 26, 2014 16:57
Find locked SQLite directories in a directory
#!/bin/bash
#
# Find SQLite data base in a directory and print those that were locked
#
find -type f -print0 |
xargs -0 file |
# Filter sqlite data base files
awk -F: -vIGNORECASE=1 '/sqlite/{printf "%s\0", $1}' |
@jeenuv
jeenuv / export_patches.sh
Created October 21, 2014 08:38
Export selected patches to numbered files
#!/bin/bash
# Receive a list of revisions from rev-list. For each revision, generate a file
# name from a commit subject, prefixed with a 4-digit count
#
# All this acrobatics only becuase format-patch refuses to generate a single
# patch witout a numbered suffix
git rev-list --reverse --left-only --no-merges --cherry-pick mainline/v3.17...github/juno-beta -- arch/arm64/{kernel,boot,mm} mm |
xargs bash -c '
@jeenuv
jeenuv / cleanup_kindle.sh
Last active April 9, 2018 10:29
Cleanup Kindle's orphan SDR directories
#!/bin/bash
# Find in $kindle/document directory, directories without a corresponding .mobi
# or .azw files
set -e
kindle="${kindle:?}"
cd "$kindle/documents"
@jeenuv
jeenuv / noise.sh
Last active August 29, 2015 14:06
#!/usr/bin/env bash
# bash 4.1.5(1) Linux Ubuntu 10.04 Date : 2011-10-04
#
# _______________| noise : ambient Brown noise generator (cf. white noise).
#
# Usage: noise [minutes=59] [band-pass freq center=1786] [wave]
# ^minutes can be any positive integer.
# Command "noise 1" will display peak-level meter.
#
# Dependencies: play (from sox package)
@jeenuv
jeenuv / remove_old_kernels.sh
Created September 23, 2014 10:37
Remove old kernel and header packages
#!/bin/bash
# Script to remove old kernel image and header packages. The script only picks
# up packages that are older than the current kernel (so as to not to remove the
# current or any recently-installed kernels
current_version="$(uname -a | awk '{print $3}')" # 3.2.0-69-generic
cv_1="$(echo "$current_version" | awk -F- '{print $1}')" # 3.2.0
cv_2="$(echo "$current_version" | awk -F- '{print $2}')" # 69
pkg_list="$(mktemp)"