Skip to content

Instantly share code, notes, and snippets.

View mmstick's full-sized avatar
🦀
Developing Rust projects for Pop!_OS

Michael Murphy mmstick

🦀
Developing Rust projects for Pop!_OS
View GitHub Profile
@mmstick
mmstick / get_videos.rs
Last active June 14, 2016 15:01
Obtains a list of all videos in a given directory path
/// Collects a list of all of the episodes in a given directory. Files that are not videos are ignored.
pub fn get_episodes(directory: &str) -> Result<Vec<PathBuf>, &str> {
fs::read_dir(directory).ok().map_or(Err("tv-renamer: unable to read file"), |files| {
let video_extensions = try!(mimetypes::get_video_extensions());
let mut episodes = Vec::new();
for entry in files {
let status = entry.ok().map_or(Some("tv-renamer: unable to get file entry"), |entry| {
entry.metadata().ok().map_or(Some("tv-renamer: unable to get metadata"), |metadata| {
if metadata.is_file() {
for extension in &video_extensions {
@mmstick
mmstick / mimetypes.rs
Last active November 13, 2017 15:42
Rust Mime Types Detection (Videos)
use std::fs;
use std::io::Read;
/// Obtains a list of video extensions from the `/etc/mime.types` file on Linux.
pub fn get_video_extensions() -> Result<Vec<String>, &'static str> {
fs::File::open("/etc/mime.types").ok()
// Return an error if /etc/mime.types could not be found.
.map_or(Err("tv-renamer: unable to open /etc/mime.types"), |mut file| {
// Create a buffer with the capacity of the file
let mut contents = String::with_capacity(file.metadata().map(|x| x.len()).unwrap_or(0) as usize);
@mmstick
mmstick / traits-digits.rs
Last active April 21, 2016 17:52
Custom traits for implementing try() for Result and Option types and digits() for usize integers
/// A trait that adds the ability for numbers to find their digit count and to convert them to padded strings.
trait Digits {
/// Counts the number of digits in a number. **Example:** {{0 = 0}, {1 = 1}, {10 = 2}, {100 = 3}}
fn digits(&self) -> usize;
/// Converts a number into a padded String, using `pad` as the character to pad with and `limit` as the size.
fn to_padded_string(&self, pad: char, limit: usize) -> String;
}
impl Digits for usize {
@mmstick
mmstick / ps_mem
Created April 2, 2016 01:04
Ubuntu 16.04 Unity ps_mem after log in
Private + Shared = RAM used Program
224.0 KiB + 29.0 KiB = 253.0 KiB acpid
188.0 KiB + 75.0 KiB = 263.0 KiB ondemand
180.0 KiB + 95.0 KiB = 275.0 KiB sleep (2)
228.0 KiB + 63.0 KiB = 291.0 KiB atd
272.0 KiB + 41.5 KiB = 313.5 KiB agetty
200.0 KiB + 139.0 KiB = 339.0 KiB sh (2)
292.0 KiB + 77.0 KiB = 369.0 KiB ureadahead
352.0 KiB + 45.5 KiB = 397.5 KiB irqbalance
@mmstick
mmstick / make.conf
Last active October 5, 2015 18:51
Gentoo Portage Configuration for an AMD Jaguar Laptop
# USE FLAGS
CPU_FLAGS_X86="aes avx mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3"
CODECS="aac cdda cdio cdparanoia cdr clang css djvu dvd dvdr enca exif ffmpeg flac gif gstreamer jpeg libass libburn libguess libsamplerate libsoxr matroska mp3 mp4 png postproc postscript ogg opus rubberband srt svg theora tiff vpx webp vorbis xattr x264 x265"
HARDWARE="acpi alsa apm fat llvm openal openmp sharedmem smp soap sockets socks5 sound tcmalloc threads udisks upnp upnp-av usb wifi xkb"
GRAPHICS="d3d9 dri drm egl opengl openmax s3tc wayland vaapi vdpau gles gles2"
COMPRESSION="bzip2 gzip lz4 lzma lzo rar snappy zip zlib"
DISABLE="-qt4 -qt5 -kde -consolekit -cups -ldap"
GNOME="gnome gnome-keyring gnome-online-accounts gtk gtk3 libnotify nautilus networkmanager pulseaudio"
USE="X ${CPU_FLAGS_X86} ${HARDWARE} ${GRAPHICS} ${CODECS} ${COMPRESSION} ${GNOME} ${DISABLE} bash-completion bindist branding crypt curl curlwrappers dbus fftw fontconfig ftp icu gimp git infinality libsecret mime mmap mozilla mtp ncurses n
@mmstick
mmstick / hosts.ads
Created September 1, 2015 05:11
This file is used for ad-blocking with dnsmasq. Add a line in your dnsmasq.conf to point to this file. IE: addn-hosts=/etc/hosts.ads
address=/fr.a2dfp.net/0.0.0.0
address=/m.fr.a2dfp.net/0.0.0.0
address=/mfr.a2dfp.net/0.0.0.0
address=/ad.a8.net/0.0.0.0
address=/asy.a8ww.net/0.0.0.0
address=/static.a-ads.com/0.0.0.0
address=/atlas.aamedia.ro/0.0.0.0
address=/abcstats.com/0.0.0.0
address=/ad4.abradio.cz/0.0.0.0
address=/a.abv.bg/0.0.0.0
@mmstick
mmstick / geany-install.sh
Last active August 12, 2021 23:04
Compiles and installs the GTK3 version of Geany on Ubuntu.
#!/bin/bash
export CFLAGS='-march=native -O3 -pipe -fstack-protector -Wall'
export CXXFLAGS='-march=native -O3 -pipe -fstack-protector -Wall'
sourcedir="$HOME/.local/src"
mkdir "$sourcedir"
function git-clone() {
target="${sourcedir}/$1"
git clone "https://github.com/geany/$1" "$target"
cd "$target"
@mmstick
mmstick / transcode-install.sh
Last active October 20, 2022 21:48
Ubuntu 10-bit HEVC Transcoding Tools -- Contains a script to install x265-10bit-git, libass-git, ffmpeg-git and bomi-git; another for updating everything; as well as scripts for transcoding videos with ffmpeg. Transcoding scripts require the fish shell to be installed.
#!/bin/bash
sourcedir="$HOME/.local/src/"
mkdir "$sourcedir"
export CFLAGS='-march=native -O3 -pipe -fstack-protector -Wall'
export CXXFLAGS='-march=native -O3 -pipe -fstack-protector -Wall'
function install-dependencies() {
# Install build tools and Mesa VDPAU support.
sudo apt-fast install -y cmake yasm autoconf build-essential mesa-vdpau-drivers \
libvdpau-va-gl1
@mmstick
mmstick / a2dissite
Created March 9, 2015 19:37
An Apache2 script for disabling websites.
#!/bin/bash
avail=/etc/httpd/conf/sites-enabled/$1.conf
enabled=/etc/httpd/conf/sites-enabled
site=`ls /etc/httpd/conf/sites-enabled`
if [ "$#" != "1" ]; then
echo "Use script: n2dissite virtual_site"
echo -e "\nAvailable virtual hosts: \n$site"
exit 0
else
@mmstick
mmstick / a2ensite
Created March 9, 2015 19:37
An Apache2 script for enabling websites.
#!/bin/bash
if test -d /etc/httpd/conf/sites-available && test -d /etc/httpd/conf/sites-enabled ; then
echo "-------------------------------"
else
mkdir /etc/httpd/conf/sites-available
mkdir /etc/httpd/conf/sites-enabled
fi
avail=/etc/httpd/conf/sites-available/$1.conf
enabled=/etc/httpd/conf/sites-enabled