Skip to content

Instantly share code, notes, and snippets.

@archer884
archer884 / expiring_cache.rs
Created December 30, 2014 18:56
Rust cache with expiring items
extern crate chrono;
pub mod expiring_cache {
use chrono::{DateTime, Duration, UTC};
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::hash::Hash;
pub struct ExpiringCache<Key, Value> where Key: Eq + Hash {
expiry: Duration, // cache endurance
@archer884
archer884 / ext.rs
Last active October 24, 2021 23:08
"Extension Methods" in Rust
use std::collections::HashSet;
use std::hash::{Hash, Hasher};
use std::collections::hash_state::HashState;
fn main() {
if let Some(content) = {
let args = std::os::args();
if args.len() == 2 {
Some(args[1].to_string())
} else {
// This file performs the stegasaurus recovery routine in order to fetch the tax brackets from
// your provided photograph.
use serde::Deserialize;
use std::fs;
use std::io::Cursor;
use std::path::Path;
#[derive(Debug, Deserialize)]
pub struct Bracket {
@archer884
archer884 / keybase.md
Created March 5, 2019 01:32
keybase.md

Keybase proof

I hereby claim:

  • I am archer884 on github.
  • I am archer884 (https://keybase.io/archer884) on keybase.
  • I have a public key ASDF3VEaYHl-qzC7LOBEco5bK6ZhqIjP3DTlI-GXGYBkugo

To claim this, I am signing this object:

[alias]
co = checkout
# New branch
nb = checkout origin -b
# Push new branch
pnb = push -u origin HEAD
# Log Graph
@archer884
archer884 / blend.rs
Created January 19, 2019 05:31
Blend function
fn blend(colors: impl IntoIterator<Item = Hex>) -> Option<Hex> {
let mut count = 0;
let mut a_sum = 0.0;
let mut b_sum = 0.0;
let mut c_sum = 0.0;
for color in colors {
let Hex(a, b, c) = color;
count += 1;
@archer884
archer884 / retry.cs
Created March 21, 2018 16:22
Generic retry stuff.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace retry
{
public static class Execute
{
static Executer _executer;
@archer884
archer884 / main.rs
Created December 7, 2017 00:30
AOC/6 (Rust)
#![feature(test)]
extern crate fxhash;
extern crate test;
#[derive(Clone, Eq, PartialEq)]
struct MemoryBank {
banks: Vec<i32>,
}
@archer884
archer884 / Program.cs
Created December 5, 2017 21:38
AOC/5 (C#)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AocDay5
{
class Program
{
class Resources
@archer884
archer884 / main.rs
Created December 5, 2017 16:04
AOC/5 (Rust)b
#![feature(conservative_impl_trait)]
const INPUT: &str = include_str!("../input.txt");
fn main() {
println!("{}", run_program(read_input(), |i| i + 1));
println!("{}", run_program(read_input(), offset));
}
fn offset(i: i32) -> i32 {