Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
class MetaSpam(type):
def __new__(cls, name, bases, ns, *, metaarg=92):
print("new", metaarg)
return super().__new__(cls, name, bases, ns)
def __init__(self, name, bases, ns, *, metaarg=92):
print("init", metaarg)
super().__init__(name, bases, ns)
class A(metaclass=MetaSpam, metaarg="WUT?"):
@matklad
matklad / quest.txt
Last active December 18, 2015 18:40
matklad@nixos [09:31:33] [~/quest]
-> % cat g.c
int a;
int b;
int inc_a() { return a++; }
int inc_b() { return b++; }
int main() {
inc_a();
@matklad
matklad / abandon_all_the_things.rs
Last active June 21, 2016 08:20
A "let it crash" style REPL skeleton in Rust
use std::thread;
use std::io::prelude::*;
/// This is an attempt to write a REPL application in
/// Erlangish "let it crash" style.
///
/// References:
/// - http://ferd.ca/the-zen-of-erlang.html
/// - http://joeduffyblog.com/2016/02/07/the-error-model/
///
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>file://$PROJECT_DIR$/components/gfx/font.rs</file>
<line>56</line>
<module>servo</module>
<entry_point TYPE="file" FQNAME="file://$PROJECT_DIR$/components/gfx/font.rs" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Anonymous parameters</problem_class>
<description>Anonymous trait method parameter</description>
</problem>
@matklad
matklad / RustAnonParams.xml
Created August 10, 2016 18:09
Anonymous parameters usages across crates.io crates
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>file://$PROJECT_DIR$/atpp-1.6.7/src/atpp.rs</file>
<line>133</line>
<module>sources</module>
<entry_point TYPE="file" FQNAME="file://$PROJECT_DIR$/atpp-1.6.7/src/atpp.rs" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Anonymous parameters</problem_class>
<description>Anonymous trait method parameter</description>
</problem>
-> % RUST_LOG=debug $CA metadata --verbose ~/projects/tokio
DEBUG:cargo::core::workspace: find_root - trying /home/matklad/projects/Cargo.toml
DEBUG:cargo::core::workspace: find_root - trying /home/matklad/Cargo.toml
DEBUG:cargo::core::workspace: find_root - trying /home/Cargo.toml
DEBUG:cargo::core::workspace: find_root - trying /Cargo.toml
DEBUG:cargo::core::workspace: find_members - only me as a member
DEBUG:cargo::core::registry: load/missing file:///home/matklad/projects/tokio
DEBUG:cargo::sources::config: loading: file:///home/matklad/projects/tokio
DEBUG:cargo::core::resolver: initial activation: tokio v0.1.0 (file:///home/matklad/projects/tokio)
DEBUG:cargo::core::registry: load/missing https://github.com/carllerche/mio?branch=dev#c7b85ac7
def parseMany(parse: (String) => Option[(SExpression, String)], input: String): (Seq[SExpression], String) = {
parse(input)
.map { case (x, r1) =>
val (xs, r2) = parseMany(parse, r1)
(x +: xs, r2)
}
.getOrElse((Seq(), input))
}
@matklad
matklad / drop-bench.rs
Created September 21, 2016 22:40
Rust CString drop benchmark
extern crate time;
extern crate rand;
use time::precise_time_ns;
use rand::Rng;
use std::ffi::CString;
fn main() {
println!("Baseline 1: empty String");
@matklad
matklad / 1 setup.txt
Last active September 26, 2016 09:05
Random java memory allocation benchmark
λ ~/bench/ alias t="/run/current-system/sw/bin/time -f \"%es %MkB\" "
λ ~/bench/ javac -version
javac 1.8.0_101
λ ~/bench/ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
@matklad
matklad / 1 gen.py
Last active September 28, 2016 15:06
Random C++ io benchmark
import random
numbers = (random.randrange(2**32) for _ in range(3 * 10**6))
with open("in.txt", "w") as f:
f.write(" ".join(map(str, numbers)))