Skip to content

Instantly share code, notes, and snippets.

@oxalica
oxalica / brainfuck_quine_gen.rs
Last active October 28, 2020 12:44
Brainfuck quine generator
use brainfuck::{program::Program, tape}; // brainfuck = "0.2.1"
fn gen_printer(s: &str) -> String {
assert!(!s.is_empty());
let s = s.as_bytes();
let mut buf = "+".repeat(s[0] as usize) + ".";
for (&prev, &cur) in s.iter().zip(&s[1..]) {
if prev < cur {
buf += &"+".repeat((cur - prev) as usize);
} else if cur < prev {
@oxalica
oxalica / Main.idr
Created July 7, 2020 08:14
Typed printf with runtime format string
module Main
import Printf
%default total
||| Define the "like" relationship on two `Format`.
|||
||| One format is "like" the other one iff the former with all non-format-specifier removed is
||| the same as the later.
@oxalica
oxalica / json.hs
Created June 18, 2020 18:28
A toy parser for json
-- https://www.json.org/json-en.html
{-# LANGUAGE OverloadedStrings #-}
import Data.Map.Strict (Map, fromList)
import qualified Data.Text as T
import Data.Char (isDigit, chr, isHexDigit)
import Control.Monad (ap)
import Control.Applicative (Alternative(..), optional)
newtype Parser a = Parser { runParser :: T.Text -> Either String (T.Text, a) }
time: 0.979; rss: 176MB parse_crate
time: 0.000; rss: 176MB attributes_injection
time: 0.000; rss: 176MB incr_comp_prepare_session_directory
time: 0.000; rss: 176MB incr_comp_garbage_collect_session_directories
time: 0.000; rss: 176MB recursion_limit
time: 0.000; rss: 176MB plugin_loading
time: 0.000; rss: 176MB plugin_registration
time: 0.028; rss: 178MB pre_AST_expansion_lint_checks
time: 0.000; rss: 178MB crate_injection
time: 0.991; rss: 373MB expand_crate
@oxalica
oxalica / my_benchmark.rs
Created October 4, 2019 09:48
Benchmarks of fs::metadata, stat64, statx, and statx converted to stat64
// statx-sys = "0.3.0"
// libc = "0.2.62"
// criterion = "0.3.0"
//
// Bench with file `a` but no file `b` in working dir.
#![feature(const_cstr_unchecked)]
use libc;
use statx_sys;
use std::{ffi::CStr, fs, mem};
use criterion::*;