Skip to content

Instantly share code, notes, and snippets.

View dcoles's full-sized avatar

David Coles dcoles

View GitHub Profile
@dcoles
dcoles / windows-nfs.rs
Created September 7, 2019 07:07
Example of NFC using Windows Proximity APIs in Rust
// Example of NFC using Windows Proximity APIs
// Tested using Sony RC-S380 (make sure you enable NFP in the driver).
use winrt::*; // import various helper types
use winrt::windows::foundation;
use winrt::windows::networking::proximity;
use std::{thread, time};
const URL: &str = "https://dcoles.net";
@dcoles
dcoles / appimage.sh
Last active February 23, 2020 00:38
Run AppImage container
#!/bin/bash
# Run AppImage container
set -e
function _mount {
local target
target="$(mktemp --tmpdir --directory appimage.XXXXXXXXXX)"
/bin/mount --types squashfs -o offset="${2:-0}" --read-only -- "${1}" "${target}"
echo "${target}"
}
@dcoles
dcoles / tokio-server.rs
Created October 12, 2021 04:29
Tokio-based TCP server
// Tokio-based server
use std::io;
use std::iter::FromIterator;
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
// Listening server.
@dcoles
dcoles / fsm.rs
Last active October 12, 2021 04:33
Dynamic Finite-State-Machine in Rust
use std::fmt::Debug;
pub trait State: Debug {
fn execute(&self) -> Transition;
}
pub trait TransitionTo<S: State + 'static>: State {
fn transition_to(&self, to: &'static S) -> Transition {
Transition { to }
}
@dcoles
dcoles / draft.rs
Created December 1, 2021 19:51
Advent of Code 2021: Day 1 (Draft vs. Final)
fn main() {
let input = read_input_from_file("day01/input.txt").unwrap();
// Part 1
let mut count = 0;
let mut last = -1;
for &n in &input {
if n > last {
count += 1;
}
@dcoles
dcoles / 452874.py
Last active December 20, 2021 21:53
By only adding + - * into the string 452874 (in that order), how many way can you get to -18?
"""
By only adding + - * into the string 452874 (in that order),
how many way can you get to -18?
"""
N = "452874"
M = -18
OPERATIONS = [None, '+', '-', '*']