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 / merge-pdfs.sh
Created March 9, 2015 16:04
Merges all PDFs in the current directory into one large PDF in alphabetical order.
#!/bin/bash
gs -sDEVICE=pdfwrite -dCompatabilityLevel=1.4 -dPDFSETTINGS=/ebook -dDetectDuplicateImages=true -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$1" *.pdf
@mmstick
mmstick / compress-pdfs.sh
Created March 9, 2015 16:00
Finds all PDFs in the current directory and compresses the images contained within them to 150dpi.
#!/bin/bash
find * -type f -name \*.pdf | parallel -j+0 --gnu nice -n 19 gs -sDEVICE=pdfwrite -dCompatabilityLevel=1.4 -dPDFSETTINGS=/ebook -dDetectDuplicateImages=true -dNOPAUSE -dQUIET -dBATCH -sOutputFile="{.}_compressed.pdf" "{}"
@mmstick
mmstick / fib.d
Last active August 29, 2015 14:12
A fibonacci generator in multiple languages
import std.stdio;
// getSequences() returns the number of sequences to print.
int getSequences()
{
int sequences;
write("Number of sequences: ");
readf("%d", &sequences);
return sequences;
}
@mmstick
mmstick / lcm.c
Last active August 29, 2015 14:12
// C Implementation
#include <stdio.h>
// A recursive function that returns the GCD of two numbers.
int gcd(int x, int y)
{
return y == 0 ? x : gcd(y, x % y);
}
int lcm(int x, int y)
@mmstick
mmstick / cat.d
Last active August 29, 2015 14:11
A collection of simple D programs.
import std.file;
import std.stdio;
static immutable ulong buffer_size = 1024 * 1024 * 10;
// Print the file contents of the file obtained by openFile().
void print(File input) {
immutable ulong file_size = input.size();
if (file_size < buffer_size) {
ubyte[] buffer;
@mmstick
mmstick / loop-unrolling.go
Created November 13, 2014 13:01
GC and GCCGO unrolled loop benchmarks.
// AMD A4-5000 Quad-Core 1.5GHz APU
// GC benchmark
// Normal For Loop : 669.966032ms
// Double Unrolled Loop: 422.242497ms
// Triple Unrolled Loop: 363.525022ms
// Quad Unrolled Loop : 281.522688ms
// Octo Unrolled loop : 312.757938ms
// gorsync opens a file containing a tab-delimited list of backup entries.
// Spaces are allowed, and any number of tabs can be used when formatting the
// file. The first entry is the name of the entry, the second is the source
// directory, and the third entry is the target directory. After all jobs have
// been queued, the program will run them in serial and print to the terminal
// when it has completed each entry.
//
// Ex: Anime Archive /home/mmstick/Videos/Archive /home/mmstick/Backup/
package main
// Package first obtains a list of episodes in all subdirectories and stores
// data about each episode into an episode struct. After the data is collected,
// it is stored inside of the Episodes type. After all episodes are gathered,
// the program will transcode all of the episodes with H.265 10-bit video and
// Opus audio -- storing the transcoded video into a MKV container. Information
// is printed as soon as the episode is finished transcoding.
package main
import "flag"
import "fmt"
@mmstick
mmstick / network-statistics.fish
Last active August 29, 2015 14:06
Prints rx/tx statistics of all active networks in a human-readable format.
#!/usr/bin/fish
for connection in /sys/class/net/*
switch '$connection'
case '*lo'
continue
case '*'
if test (cat $connection/operstate) = 'up'
set net (basename $connection)
set rx (math (cat $connection/statistics/rx_bytes) / 1048576)
set tx (math (cat $connection/statistics/tx_bytes) / 1048576)
@mmstick
mmstick / rename-series.fish
Last active August 29, 2015 14:06
This is a fish function -- store it inside ~/.config/fish/functions to use with fish. Renames all episodes in a directory to the TVDB naming-scheme and verbosely prints the changes. Ex: Series 1x01.mkv
#!/bin/fish
function rename-series --description 'rename-series <series_name> <season_number> <file_extension>'
set count 0
for file in *
set count (math $count + 1)
if test (math $count \< 10) = '1'
mv -i -v "$file" "$argv[1] $argv[2]x0$count.$argv[3]"
else
mv -i -v "$file" "$argv[1] $argv[2]x$count.$argv[3]"
end