Skip to content

Instantly share code, notes, and snippets.

Michael LeahCim

  • Edinburgh, UK
Block or report user

Report or block LeahCim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@LeahCim
LeahCim / remove-old-kernels-example.sh
Last active Aug 29, 2015
Ubuntu: remove old kernels
View remove-old-kernels-example.sh
## 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 Jul 9, 2014
Launch Notepad++ from the shell while automatically detecting file type for syntax highlighting, even if file extension is missing.
View npp
#!/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 Aug 29, 2015
A simple launcher and batch package importer for the Unity Editor. Download the editor from: http://unity3d.com
View unity.sh
#!/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 Aug 29, 2015
A bash script for trimming extra blank lines. Consecutive blank lines are collapsed into one. Multiple files can be given as arguments at once.
View trim
#!/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
View 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 Mar 3, 2014
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…
View 25_pre-os-prober
#! /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
You can’t perform that action at this time.