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 / bank.rs
Last active July 17, 2017 18:06
Rust implementation of an ATM-like console
use std::io::{stdin, stdout, BufRead, Error, Write};
use std::fmt::{self, Display};
fn main() {
// Create the account that we will emulate
let mut account = Account::new();
// Print the first input message to the screen
print!("Enter your account name: ");
let stdout = stdout();
@mmstick
mmstick / split.rs
Last active June 4, 2017 15:42
Compile with `rustc -C opt-level=3 -C target-cpu=native -C lto -C panic=abort split.rs -o splitrs`
use std::io::{self, BufRead, BufReader, Write};
use std::time::Instant;
fn main() {
// Obtain a buffered handle to standard input
let stdin = io::stdin();
let mut stdin = BufReader::new(stdin.lock());
// Mark the current time for a later duration comparison.
let start = Instant::now();
@mmstick
mmstick / rss.hbs
Last active June 1, 2017 04:13
RSS Rocket Handlebar Example (Sort of...)
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>{{page_title}}</title>
<link>{{page_link}}</link>
<description>{{page_desc}}</description>
<language>en-us</language>
<pubDate>{{page_date}}</pubDate>
<generator>Custom Web Server Written in Rust (RIIR)</generator>
<webMaster>mmstickman@gmail.com</webMaster>
@mmstick
mmstick / main.rs
Last active May 30, 2017 20:06
An example implementation of a friends list without shared references.
use std::collections::{HashSet, HashMap};
struct Person {
/// The unique name of this person that no other person may have.
name: String,
/// Use of a `HashSet` ensures that a friend is never listed twice.
friends: HashSet<usize>,
}
#[derive(Debug)]
@mmstick
mmstick / software.rs
Created May 23, 2017 20:14
Source code for the software projects route of my web server
use accept_encoding::AcceptEncoding;
use cacher::{CachedContent, Page, PageCache};
use database::DBConnection;
use horrorshow::prelude::*;
use horrorshow::Template;
use rocket::State;
use rocket_contrib::Template as HandlebarTemplate;
macro_rules! request_content {
($cache:ident, $url:ident, $encoding:ident, $closure:expr) => {
@mmstick
mmstick / tokenizer-iterator.php
Last active October 2, 2018 22:26
PHP String Tokenizer: Practicing with PHP
#!/bin/php
<?php
/// TODO:
/// - Implement Backslash escapes
// An ADT-like type that can either be a normal value or a variable.
class Token {
// 0 = Normal; 1 = Variable; 2 = Error; 3 = None
public $kind = 0;
// Contains the string for the associated type.
@mmstick
mmstick / accept_encoding.rs
Last active May 16, 2017 19:04
Rocket structure for attaining the values from Accept-Encoding
use rocket::request::{FromRequest, Request};
use rocket::http::Status;
use rocket::Outcome;
const GZIP: u8 = 1;
const DEFLATE: u8 = 2;
const BROTLI: u8 = 4;
#[derive(Clone, Debug, PartialEq, Hash)]
pub enum PreferredEncoding { Brotli, Gzip, Uncompressed }
@mmstick
mmstick / main.rs
Last active December 5, 2016 02:55
Advent of Code Day 4 Solution (Stdin Version)
#![feature(alloc_system)]
extern crate alloc_system;
extern crate arrayvec;
use std::cmp::Ordering::{Less, Greater};
use std::convert::From;
use std::io::{BufRead, Lines, StdinLock};
// Used to eliminate dynamic heap allocations by allocating a fixed-sized vector on the stack.
use arrayvec::ArrayVec;
@mmstick
mmstick / xpad.c
Created September 24, 2016 16:27
Powera Spectra Patched Xpad Kernel Module
/*
* X-Box gamepad driver
*
* Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
* 2004 Oliver Schwartz <Oliver.Schwartz@gmx.de>,
* Steven Toth <steve@toth.demon.co.uk>,
* Franz Lehner <franz@caos.at>,
* Ivan Hawkes <blackhawk@ivanhawkes.com>
* 2005 Dominic Cerquetti <binary1230@yahoo.com>
* 2006 Adam Buchbinder <adam.buchbinder@gmail.com>
@mmstick
mmstick / numbered-url-list.rs
Created June 5, 2016 15:54
Printing a Numbered List of URLs
/// This example demonstrates how print a numbered list of URLs from the Ubuntu Kernel PPA,
/// which can be used to automate the installation of Ubuntu kernels.
extern crate hyper;
use hyper::Client;
use hyper::header::Connection;
extern crate select;
use select::document::Document;
use select::predicate::{Name};