Skip to content

Instantly share code, notes, and snippets.

View jakobrs's full-sized avatar

Jakob Rødal Skaar jakobrs

View GitHub Profile
use pin_project::*;
use pin_utils::*;
use std::future::Future;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
async fn with_context<F, A>(f: F) -> A
where
use std::error::Error;
use libc::c_void;
fn main() -> Result<(), Box<dyn Error>> {
show_maps()?;
let allocation = unsafe { allocate_cursed_ringbuffer(1) };
println!("{:p}", allocation);
show_maps()?;
@jakobrs
jakobrs / main.rs
Last active January 17, 2022 08:46
#![feature(generator_trait)]
#![feature(generators)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;
use futures::pin_mut;
struct GeneratorIteratorImpl<T>(T);
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<style>
h1 {
font-family: "Verdana", sans-serif;
font-weight: normal;
font-size: 8em;
bindkey -e
setopt NO_BEEP
export HISTFILE=~/.history
export HISTSIZE=1000
export SAVEHIST=1000
setopt APPEND_HISTORY
setopt HIST_IGNORE_SPACE
setopt HIST_IGNORE_ALL_DUPS
@jakobrs
jakobrs / v.rs
Last active April 22, 2022 16:01
use std::time::Instant;
// From jakobrs/primes, using the kimwalisch/primesieve library
use primesieve::PrimesieveIterator;
fn main() {
for n in 5..=20 {
let count = ((5. / 4. * n as f64).exp() / n as f64) as u64;
let before = Instant::now();
#![feature(allocator_api)]
#![feature(strict_provenance)]
use std::{
alloc::{Allocator, Global, Layout},
marker::PhantomData,
mem::ManuallyDrop,
ops::{Index, IndexMut},
ptr::NonNull,
};
macro_rules! define_macros_inner {
($words:ident, $out:ident, $d:tt) => {
macro_rules! read {
() => {
$words.next().unwrap().parse().unwrap()
};
($t:ty) => {
$words.next().unwrap().parse::<$t>().unwrap()
};
($t:ty, $n:expr) => {
@jakobrs
jakobrs / main.rs
Created June 18, 2022 08:31
Simple Codeforces Rust template
use std::io::Write;
#[rustfmt::skip]
macro_rules! define_read {
($words:ident) => {
macro_rules! read {
() => {
$words.next().unwrap().parse().unwrap()
};
($t:ty) => {
use std::{
borrow::Cow,
fs::File,
io::Read,
path::{Path, PathBuf},
};
use anyhow::{Context, Result};
use clap::Parser;
use regex::Regex;