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 / printcolumns.cpp
Last active August 29, 2015 14:03
An example of how to print in columns from top to bottom in C++.
#include <iostream>
#include <string>
using namespace std;
int main() {
// Initial variables for the list
int listSize = 26;
int numOfColumns = 6;
string list[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L",
@mmstick
mmstick / factor.rs
Last active August 29, 2015 14:05
Experimenting with programming in Rust -- My first Rust program.
use std::os::{args};
use std::io::{stdin};
use std::u64::{parse_bytes};
// Convert the input string into a number if possible
fn str_to_number(input: &str) -> u64
{
match parse_bytes(input.as_bytes(), 10) {
Some(x) => x,
None => 0u64
package main
import "fmt"
import "os/exec"
import "time"
func errorChecker(output *[]byte, err *error, entry *string, elapsedTime time.Duration) {
if *err != nil {
fmt.Println(fmt.Sprint(*err) + ": " + string(*output))
} else {
@mmstick
mmstick / i3gostatusbar.go
Last active August 29, 2015 14:06
i3 status bar programmed in Go -- works with both laptops and desktops now. If a battery is present, it will print battery information. Otherwise, it will not print battery information. It will also automatically detect the currently active network connection and use statistics from that to notify the user how much data has been downloaded and u…
package main
import (
"fmt"
"io/ioutil"
"os"
"os/user"
"runtime"
"strconv"
"strings"
@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
@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)
// 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"
// 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
@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
@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;