Skip to content

Instantly share code, notes, and snippets.

View thomaslee's full-sized avatar
👾

Tom Lee thomaslee

👾
View GitHub Profile
@thomaslee
thomaslee / siginfo_t.c++
Created November 6, 2015 20:29
capnproto ppc cast bug
(gdb) p reinterpret_cast<void*>(static_cast<uintptr_t>(siginfo.ssi_ptr))
$4 = (void *) 0x0
(gdb) p siginfo.ssi_ptr
$5 = 528280977408
(gdb) p (uintptr_t) siginfo.ssi_ptr
$6 = 0
(gdb) p sizeof(uintptr_t)
$7 = 4
(gdb) p sizeof(siginfo.ssi_ptr)
$8 = 8

Last week I gave a (poorly prepared) talk outlining how the Rust compiler works internally. Though the slides might be helpful & there was some interesting discussion after the talk, I thought a full post might do this topic more justice.

Note that as of writing this the current release of Rust is 0.10. Some of what I cover in this article may well change by the time you get around to reading this.

if ((search->exptime != 0 && search->exptime < current_time)
|| (search->time <= oldest_live && oldest_live <= current_time)) {
itemstats[id].reclaimed++;
if ((search->it_flags & ITEM_FETCHED) == 0) {
itemstats[id].expired_unfetched++;
}
it = search;
slabs_adjust_mem_requested(it->slabs_clsid, ITEM_ntotal(it), ntotal);
do_item_unlink_nolock(it, hv);
/* Initialize the item block: */
trait ToBindSocketAddr {
fn to_bind_socket_addr(self) -> IoResult<SocketAddr>
}
impl<'a> ToBindSocketAddr for &'a str {
fn to_bind_socket_addr(self) -> IoResult<SocketAddr> {
match FromStr::from_str(self) {
Some(addr) => Ok(addr),
None => {
Err(IoError{
@thomaslee
thomaslee / chord.rb
Last active January 5, 2023 13:26
Chord-like protocol in Ruby pseudocode
#
# Chord-like network overlay protocol based on the eon (http://github.com/thomaslee/eon)
# source code, which was itself based on the Principles of Distributed Computing paper
# and Pamela Zave's pseudocode from "How to make Chord correct":
#
# http://en.wikipedia.org/wiki/Chord_(peer-to-peer)
#
# (Prefer Zave's proposed changes to anything in the other papers + Wikipedia.)
#
# Haven't bothered with finger tables yet, though they should be a trivial addition.
class Config(properties: Properties) {
val properties = properties
val redis = object {
val hostAndPort: HostAndPort
get() = HostAndPort.fromString(properties.getProperty("redis") ?: "127.0.0.1:4001")!!
}
}
tom@desktop:~/Source/rust-grammar @master$ echo '"foo\\
bar"' | ./lexer
LIT_STR("foo\\
bar")
public class Main {
public static void main(final String[] args) {
final long[] values = new long[250000];
final Random random = new Random();
for (int i = 0; i < 250000; i++) {
values[i] = random.nextLong();
}
final Derived1 derived1 = new Derived1();
final Derived2 derived2 = new Derived2();
import static org.junit.Before.*;
import static org.junit.Assume.*;
@Before
public void before() {
// if this check fails, the test is skipped. Neat eh?
assumeTrue(new File("/path/to/archive/file.events").exists());
}
@thomaslee
thomaslee / connection.rs
Created January 17, 2014 07:34
A crappy, unbounded, half-baked, broken connection pool in Rust
use std::clone::Clone;
use std::option::{Option, None, Some};
use std::io::net::ip::{SocketAddr, IpAddr};
use std::io::net::tcp::TcpStream;
use std::io::net::addrinfo::get_host_addresses;
use std::rc::Rc;
pub struct Connection {
addr: SocketAddr,
conn: Rc<TcpStream>