Skip to content

Instantly share code, notes, and snippets.

View r2p2's full-sized avatar

Robert Peters r2p2

View GitHub Profile
@r2p2
r2p2 / example.cc
Created May 11, 2020 20:56
sleep_until 100 % cpu usage on wsl
// g++ example.cc
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
int main()
{
std::chrono::milliseconds delay(1000);
while (true)
@r2p2
r2p2 / ct.sh
Created April 13, 2019 08:06
One Line Compile Time
make clean && make -pRrq | grep 'MAKE.*cc.o' | sed 's/.*..MAKE./make/' | while read -r cmd ; do /usr/bin/time -f "%e $cmd" $cmd -j1 -b > /dev/null ; done 2>&1 | tee compile-times.txt
[2018-07-10 18:08] [ALPM] upgraded libsystemd (238.133-4 -> 239.0-2)
[2018-07-10 18:08] [ALPM] upgraded gdbm (1.14.1-1 -> 1.16-1)
[2018-07-10 18:08] [ALPM] upgraded perl (5.26.2-1 -> 5.26.2-2)
[2018-07-10 18:08] [ALPM] upgraded libsasl (2.1.26-12 -> 2.1.26-13)
[2018-07-10 18:08] [ALPM] upgraded apr-util (1.6.1-2 -> 1.6.1-3)
[2018-07-10 18:08] [ALPM] upgraded avahi (0.7+4+gd8d8c67-1 -> 0.7+16+g1cc2b8e-1)
[2018-07-10 18:08] [ALPM] upgraded brotli (1.0.4-1 -> 1.0.5-1)
[2018-07-10 18:08] [ALPM] upgraded harfbuzz (1.8.1-1 -> 1.8.2-1)
[2018-07-10 18:08] [ALPM] upgraded libmagick6 (6.9.10.3-1 -> 6.9.10.6-1)
[2018-07-10 18:08] [ALPM] upgraded systemd (238.133-4 -> 239.0-2)
// #1 version without Result as return type
fn from_json(data: &str) -> humans::Humans {
let mut humans = Vec::new();
let msg: Value = serde_json::from_str(data).expect("json error");
for human in msg["people"].as_array().unwrap().iter() {
humans.push(humans::Human::new(
human["name"].as_str().unwrap(),
human["craft"].as_str().unwrap(),
));
@r2p2
r2p2 / xxo
Created March 16, 2018 12:59
% bin/python main.py
add_client: bot1
_ _ _
_ _ _
_ _ _
waiting for players
add_client: bot2
_ _ _
_ _ _
_ _ _
@r2p2
r2p2 / aoc_day_1.rs
Created December 10, 2017 11:48
Advent Of Code Day 1
fn sum(s : &str) {
let mut sum_1 = 0;
let mut sum_2 = 0;
for (i, c_this) in s.chars().enumerate() {
let c_comp_1 = s.chars().cycle().nth(i + 1).unwrap();
let c_comp_2 = s.chars().cycle().nth(i + s.len()/2).unwrap();
if c_this == c_comp_1 {
sum_1 += c_this.to_digit(10).unwrap();
}
@r2p2
r2p2 / aoc_day_7.1.rs
Last active December 10, 2017 11:05
Advent Of Code Day 7 part 1
fn main() {
let test_data = "pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
@r2p2
r2p2 / aoc_day_6.rs
Created December 9, 2017 22:17
Advent Of Code Day 6
struct Mem {
mem : Vec<i32>
}
impl Mem {
pub fn new(mem : &Vec<i32>) -> Mem {
Mem {
mem : mem.clone()
}
}
@r2p2
r2p2 / aoc_day_5.rs
Created December 9, 2017 21:26
Advent Of Code Day 5
struct Cpu {
mem : Vec<i32>,
pc : i32,
cycles : u32,
ext : bool,
}
impl Cpu {
pub fn new(mem : &Vec<i32>, extention : bool) -> Cpu {
Cpu {
@r2p2
r2p2 / pb.cc
Created October 20, 2017 21:37
generated protobuf code
inline void Device::set_allocated_id(::std::string* id) {
if (id != NULL) {
} else {
}
id_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), id);
// @@protoc_insertion_point(field_set_allocated:cc_ui.Device.id)
}