Skip to content

Instantly share code, notes, and snippets.

View leshow's full-sized avatar
🌹

Evan Cameron leshow

🌹
View GitHub Profile
@leshow
leshow / leak.rs
Last active April 17, 2020 23:41
/// ```bash
/// cargo run --release
/// # in another term
/// flame -p 9953
/// # in another term
/// flame -p 9953
/// ```
use std::sync::atomic::{AtomicUsize, Ordering};
#![no_std]
#![no_main]
// pick a panicking behavior
extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics
// extern crate panic_abort; // requires nightly
// extern crate panic_itm; // logs messages over ITM; requires ITM support
// extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger
use cortex_m_rt::{entry, exception, ExceptionFrame};
#[allow(unused_imports)]
use std::cmp::{min,max};
use std::io::{BufWriter, stdin, stdout, Write};
#[derive(Default)]
struct Scanner {
buffer: Vec<String>
}
impl Scanner {
fn next<T: std::str::FromStr>(&mut self) -> T {
pub fn diff_ways_to_compute(input: String) -> Vec<i32> {
let chars: Vec<char> = input.chars().collect::<Vec<_>>();
parse(&chars).into_iter().map(|tree| tree.eval()).collect()
}
fn parse(input: &[char]) -> Vec<AST> {
let mut res = vec![];
if input.is_empty() {
return res;
}
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::{
error::Error,
io::{stdin, stdout, BufWriter, Write},
};
#[derive(Default)]
struct Scanner {
buffer: Vec<String>,
module ArrayManipulation where
{-|
Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each of the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in your array.
For example, the length of your array of zeros
. Your list of queries is as follows:
a b k
module Parse where
import Control.Monad
import Data.Char
import Control.Applicative
data Parsed = Digit Integer | Hex Integer | Word String deriving Show
parseHex :: Parsed -> Char -> [Parsed]
@leshow
leshow / xordirs_lockless.rs
Created August 7, 2018 13:36
Remove the need for locking memory w/ rayon
extern crate rayon;
use rayon::prelude::*;
use std::{collections::HashSet, env, error::Error, fs};
fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = env::args().collect();
let final_diff: HashSet<String> = args[1..]
.par_iter()
extern crate crossbeam_utils;
use std::{
collections::HashSet,
env,
error::Error,
fs,
sync::{Arc, Mutex},
};
fizzbuzz :: Int -> String
fizzbuzz n = fromMaybe (show n) (fizz <> buzz)
where
fizz, buzz :: Maybe String
fizz = "Fizz" <$ guard (n `mod` 3 == 0)
buzz = "Buzz" <$ guard (n `mod` 5 == 0)