Skip to content

Instantly share code, notes, and snippets.

View JayHelton's full-sized avatar
🤘

Jarrett Helton JayHelton

🤘
View GitHub Profile
/**
******************************************************************************
* @file main.c
* @author Auto-generated by STM32CubeIDE
* @version V1.0
* @brief All addresses found in STM32f4 reference manual
******************************************************************************
*/
#include<stdint.h>
macro_rules! calculate {
(eval $e:expr) => {{
{
let val: usize = $e; // Force types to be integers
println!("{} = {}", stringify!{$e}, val);
}
}};
}
fn main() {
use std::ops::{Add, Mul, Sub};
macro_rules! assert_equal_len {
// The `tt` (token tree) designator is used for
// operators and tokens.
($a:expr, $b:expr, $func:ident, $op:tt) => {
assert!($a.len() == $b.len(),
"{:?}: dimension mismatch: {:?} {:?} {:?}",
stringify!($func),
($a.len(),),
@JayHelton
JayHelton / tcp_request.rs
Created January 1, 2021 20:57
Rust in Action TCP
use std::io::prelude::*;
use std::net::TcpStream;
fn main() -> std::io::Result<()> {
let mut connection = TcpStream::connect("www.rustinaction.com:80")?; // We need to specify the port (80) explicitly, TcpStream does not know that this will become a HTTP request.
connection.write_all(b"GET / HTTP/1.0")?; // GET is the HTTP method, / is the resource we're attempting to access and HTTP/1.0 is the protocol version we're requesting. Why 1.0? It does not support "keep alive" requests, which will allow our stream to close without difficulty.
connection.write_all(b"\r\n")?; // In many networking protocols, \r\n is how a new lines
connection.write_all(b"Host: www.rustinaction.com")?; // The hostname provided on line 5 is actually discarded once it is converted to an IP address. The Host HTTP header allows the server to know which host we're connecting to..
connection.write_all(b"\r\n\r\n")?;
@JayHelton
JayHelton / chip_8_emu.rs
Last active December 30, 2020 19:04
chip 8 emu exercise
struct CPU {
registers: [u8; 16],
position_in_memory: usize,
memory: [u8; 4096],
stack: [u16; 16],
stack_pointer: usize,
}
impl CPU {
fn run(&mut self) {