Skip to content

Instantly share code, notes, and snippets.

@leahcim
leahcim / remove-old-kernels-example.sh
Last active August 29, 2015 14:20
Ubuntu: remove old kernels
## TL;DR
# Simulate purging all kernels apart from the two most recent ones:
dpkg-query -Wf'${binary:Package}\n' 'linux*-3.*.*-*' | sort -t. -k2 | head -n-8 | xargs apt-get -s purge
# Purge all kernels apart from the two most recent ones:
dpkg-query -Wf'${binary:Package}\n' 'linux*-3.*.*-*' | sort -t. -k2 | head -n-8 | xargs sudo apt-get -y purge
## Explanation
@leahcim
leahcim / npp
Created July 9, 2014 18:34
Launch Notepad++ from the shell while automatically detecting file type for syntax highlighting, even if file extension is missing.
#!/bin/bash
# 9th July 2014
lang() {
lang=
if [ -f "$1" ]; then
# keep reading until $line non empty
# ':' means "Do Nothing"
while read line && [ -z "$line" ]; do :; done < "$1"
@leahcim
leahcim / unity.sh
Last active August 29, 2015 14:02
A simple launcher and batch package importer for the Unity Editor. Download the editor from: http://unity3d.com
#!/bin/bash
# 11th July 2014
UNITY="C:\Program Files\Unity\Editor\Unity.exe"
LOG="Library/ImportedPackages.txt"
usage() {
cat << EOF
A simple launcher and batch package importer for the Unity Editor
Download the editor from: http://unity3d.com
@leahcim
leahcim / trim
Last active August 29, 2015 14:02
A bash script for trimming extra blank lines. Consecutive blank lines are collapsed into one. Multiple files can be given as arguments at once.
#!/bin/bash
for file in "$@"; do
TEMP=temp.$RANDOM
sed "s/\s*$//" "$file" | # Trim whitespace from ends of lines
cat -s | # Collapse consecutive blank lines into one
tr "\n" "\0" | # Replace new line characters with nulls
sed "s/\x0*$//" | # Trim nulls from the end
tr "\0" "\n" > "$TEMP" # Replace nulls with new line characters
@leahcim
leahcim / gist.md
Created March 30, 2014 15:26 — forked from benbalter/gist.md

Here's an example of how to embed a Gist on GitHub Pages:

{% gist 5555251 %}

All you need to do is copy and paste the Gist's ID from the URL (here 5555251), and add it to a gist tag surrounded by {% and %}.

@leahcim
leahcim / 25_pre-os-prober
Created March 3, 2014 19:13
In Ubuntu, /etc/grub.d/30_os-prober overrides grub menu style and timeout defined by the user in /etc/default/grub. Here is a workaround to save the menu style and timeout values before os-prober changes them, and to restore them afterwards. The two files need to be placed under /etc/grub.d and made executable. Finally, "sudo update-grub" should…
#! /bin/sh
set -e
# Save the $timeout and $timeout_style values set by /etc/grub.d/00_header
# before /etc/grub.d/30_os-prober messes them up.
cat << EOF
set timeout_bak=\${timeout}
set timeout_style_bak=\${timeout_style}
EOF