Skip to content

Instantly share code, notes, and snippets.

View thomaslee's full-sized avatar
👾

Tom Lee thomaslee

👾
View GitHub Profile
@thomaslee
thomaslee / gist:4753338
Last active March 25, 2019 22:10
Dumb "Hello World" TCP server in Rust.
use std::net;
use std::uv;
use core::pipes;
type ErrChan = pipes::SharedChan<Option<net::tcp::TcpErrData>>;
fn on_ready(kill_ch: ErrChan) {
io::println("listener is ready");
}
diff -r 9d8977cbbfc6 layout/base/nsCSSRendering.cpp
--- a/layout/base/nsCSSRendering.cpp Sat Apr 27 18:21:15 2013 -0400
+++ b/layout/base/nsCSSRendering.cpp Sun Apr 28 17:37:59 2013 -0700
@@ -756,17 +756,28 @@
SN();
}
-static nsRect
-GetOutlineInnerRect(nsIFrame* aFrame)
+nsRect
@thomaslee
thomaslee / bar.rs
Last active December 17, 2015 00:39
Updated reproduction of the issue described in Rust issue #4202
extern mod foo;
use foo::Foo;
use foo::Bar;
fn main() {
assert!(42 == Bar::bar());
assert!(42 == Foo::foo());
}
@thomaslee
thomaslee / gist:5538253
Last active December 17, 2015 02:48
Rough sketch of Rust crate metadata structure
tag_create_hash
:string
tag_attributes
tag_attribute
tag_meta_item_word
tag_meta_item_name
:string
tag_meta_item_name_value
tag_meta_item_name
:string
@thomaslee
thomaslee / gist:5617386
Created May 21, 2013 03:55
Winning with stage0 in mozilla/rust #6575
tom@desktop:~/Source/rust$ make
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using gcc
cfg: no pandoc found, omitting docs
cfg: no node found, omitting docs
cfg: no llnextgen found, omitting grammar-verification
@thomaslee
thomaslee / gist:5625937
Created May 22, 2013 07:52
Rust issue #6575 WIP @ stage 2
gdb$ bt
#0 0x00007ffff79a9e85 in option::__extensions__::is_none_17871::_8bda618874e3556::_07pre () from /home/tom/Source/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#1 0x00007ffff79a9e35 in cell::__extensions__::is_empty_17869::_8bda618874e3556::_07pre () from /home/tom/Source/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#2 0x00007ffff79a9c68 in cell::__extensions__::take_17866::_62678c1c57713a95::_07pre () from /home/tom/Source/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#3 0x00007ffff79a817b in task::spawn::spawn_raw_oldsched::make_child_wrapper::anon::expr_fn_17832 () from /home/tom/Source/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#4 0x00007ffff7ac34d8 in __morestack () from /home/tom/Source/rust/x86_64-unknown-linux-gnu/stage2/bin/../lib/libcore-c3ca5d77d81b46c1-0.7-pre.so
#5 0x00007ffff7fc1864 in task_start_wrapper (a=0x40d1e0) at /home/to
@thomaslee
thomaslee / rustrt-stage-output
Created May 24, 2013 07:35
Showing _RUST_STAGEN in action
touch x86_64-unknown-linux-gnu/stage0/lib/librustllvm.so
touch x86_64-unknown-linux-gnu/stage0/lib/libstd.so
touch x86_64-unknown-linux-gnu/stage0/lib/libextra.so
touch x86_64-unknown-linux-gnu/stage0/lib/librustc.so
g++ -DRUST_NDEBUG -fno-omit-frame-pointer -O2 -Wall -Werror -g -fPIC -m64 -fno-rtti -MMD -MP -MT rt/x86_64-unknown-linux-gnu/stage0/sync/timer.o -MF rt/x86_64-unknown-linux-gnu/stage0/sync/timer.d -c -o rt/x86_64-unknown-linux-gnu/stage0/sync/timer.o -I /home/tom/Source/rust/src/rt -I /home/tom/Source/rust/src/rt/isaac -I /home/tom/Source/rust/src/rt/uthash -I /home/tom/Source/rust/src/rt/arch/x86_64 -I /home/tom/Source/rust/src/rt/linenoise -I /home/tom/Source/rust/src/libuv/include -D_RUST_STAGE0 /home/tom/Source/rust/src/rt/sync/timer.cpp
g++ -DRUST_NDEBUG -fno-omit-frame-pointer -O2 -Wall -Werror -g -fPIC -m64 -fno-rtti -MMD -MP -MT rt/x86_64-unknown-linux-gnu/stage0/sync/lock_and_signal.o -MF rt/x86_64-unknown-linux-gnu/stage0/sync/lock_and_signal.d -c -o rt/x86_64-unknown-linux-gn
fn main() {
let mut input = str::to_chars("abcd");
while !input.is_empty() {
let pair = taken(input, 2);
input = dropn(input, 2);
io::println(str::from_chars(pair));
}
}
fn taken<T:Copy>(v: &[T], n: uint) -> ~[T] {
public final class LittleEndianLengthEncoder extends MessageToByteEncoder<ByteBuf> {
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf in, ByteBuf out) throws Exception {
final ByteOrder order = out.order();
out.order(ByteOrder.LITTLE_ENDIAN)
.writeInt(in.readInt())
.order(order)
.writeBytes(in);
}
}
@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>