Skip to content

Instantly share code, notes, and snippets.

View notriddle's full-sized avatar

Michael Howell notriddle

View GitHub Profile
@notriddle
notriddle / latency.txt
Created April 26, 2019 22:31 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@notriddle
notriddle / test-harness.rs
Last active December 10, 2018 19:18
Tests the old vs the new Windows argument parser for Rust, to ensure identical behavior
use std::collections::VecDeque;
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt;
use std::slice;
use std::iter;
use std::ptr;
/// Implements the Windows command-line argument parsing algorithm, described at
/// <https://docs.microsoft.com/en-us/previous-versions//17w5ykft(v=vs.85)>.
///

This is the rough implementation plan:

pick 9ae5db20d2 introduce Universe struct

We want this. =)

pick 1da0b70c57 introduce UniverseIndex into ParamEnv

Instead of adding a universe to the ParamEnv, the plan is now to add this field to the InferenceCtxt. It represents the maxixum

// https://rust-lang.org/
use std::ffi::CStr;
use std::os::raw::{c_char, c_int};
use std::slice;
use lua_sys::lua_State;
unsafe extern "C" fn runargs(l: *mut lua_State, argv: *mut *mut c_char, n: c_int) -> c_int {
// slices can use normal [] access, while pointers have to use the .offset method
// so convert the pointer to a slice, because otherwise this'll be 99% .offset(i).deref().offset(0).deref()
let args = &slice::from_raw_parts(argv, n)[1..];
let mut iter = args.iter().cloned().map(CStr::from_ptr);
@notriddle
notriddle / glorw.txt
Last active April 5, 2017 16:38 — forked from saiqulhaq/glorw.txt
General list of reserved words
### General List of Reserved Words
### Stuart P. Bentley <stuart@testtrack4.com>, June 4, 2013
### Michael Howell <michael@notriddle.com>, April 5, 2017
## This is a general list of words you may want to consider reserving,
## in a system where users can pick any name, in a context where the
## system may use names as well. One prominent example of a system
## where this is the case would be a site that serves pages for users,
## at their username, from the site root, like
## http://twitter.com/stuartpb . In this system, you would want to
@notriddle
notriddle / pimpl.ex
Created February 17, 2017 18:32
Implement :lists.prefix for any enumerable, in Elixir
defmodule Enum2 do
@type t :: Enum.t
@doc """
If `enum` starts with `prefix`, return true. Otherwise, return false.
### Examples
iex> Enum.starts_with?([1, 2, 3], [1, 2])
@notriddle
notriddle / split.ex
Created February 16, 2017 19:05
Split a string without using regex
defmodule Split do
@moduledoc """
iex(2)> Split.split("this,is,1,way,to,do_it")
["this", "is", "1", "way", "to", "do", "it"]
"""
@spec split(bitstring) :: [bitstring]
def split(s) do
do_split(s, [], [])
|> Enum.map(&List.to_string/1)
|> Enum.map(&String.reverse/1)
$ gdb ./target/debug/servo
GNU gdb (GDB) Fedora 7.9.1-20.fc22
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
valgrind --soname-synonyms=somalloc=NONE --suppressions=etc/valgrind-memcheck.supp ./target/release/servo --resources-path resources/
==1162== Memcheck, a memory error detector
==1162== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==1162== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==1162== Command: ./target/release/servo --resources-path resources/
==1162==
==1162== Warning: noted but unhandled ioctl 0x6458 with no size/direction hints.
==1162== This could cause spurious value errors to appear.
==1162== See README_MISSING_SYSCALL_OR_IOCTL for guidance on writing a proper wrapper.
==1162== Thread 9 Constellation: