Skip to content

Instantly share code, notes, and snippets.

fn is_printable_ascii(c: u8) -> bool {
c >= 0x20u8 && c < 0x7fu8
}
fn main() {
// why temporary variable needed?
// error: borrowed value does not live long enough
let test_data: ~[u8] = std::io::File::open(&Path::new("test_data")).read_to_end();
let _test_data_filtered: ~[u8] = test_data.iter()
// why double deref?
@zokier
zokier / b64_test.rs
Created January 4, 2014 12:11
extra::base64 decode failure
extern mod extra;
use extra::base64::FromBase64;
#[test]
fn test_b64_1() {
let test_data = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n";
match test_data.from_base64() {
Ok(s) => s,
Err(msg) => fail!(format!("Failed to read b64: {:s}", msg.escape_default()))
};
@zokier
zokier / enum_fmt.rs
Last active December 28, 2015 12:09
#[feature(macro_rules)];
macro_rules! enum_fmt(
($name:ident { $($member:ident),+ }) => (
enum $name {
$(
$member,
)+
}
impl std::fmt::Default for $name {
@zokier
zokier / build
Last active December 28, 2015 07:29
Administrator@WIN-CUTEPBGVI8S /d/big_struct
$ cat main.c
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
typedef struct TwoU64s {
uint64_t one;
uint64_t two;
} TwoU64s_t;
@zokier
zokier / gist:7187572
Created October 27, 2013 20:35
glxinfo|grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 660/PCIe/SSE2
OpenGL core profile version string: 4.3.0 NVIDIA 325.15
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.3.0 NVIDIA 325.15
OpenGL shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL context flags: (none)
#[feature(globs)];
#[feature(macro_rules)];
#[feature(managed_boxes)]; //TODO do without managed boxes
extern mod glfw;
extern mod gl;
use std::libc;
use std::cast;
use std::ptr;
@zokier
zokier / hs_err_pid27190.log
Created October 22, 2013 11:42
ADT Eclipse crash
[adt-bundle-linux-x86_64-20130917]$ eclipse/eclipse
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f4d49124a48, pid=27190, tid=139970217621248
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libgobject-2.0.so.0+0x19a48] g_object_get_qdata+0x18
@zokier
zokier / gdb.txt
Created October 18, 2013 13:14
backtrace from ICE: error: internal compiler error: node_id_to_type: no type for node `unknown node (id=3334)`
#0 0x00007ffff2d37e40 in __cxa_throw () from /usr/lib/libstdc++.so.6
#1 0x00007ffff5a00f3a in rust_begin_unwind () from /usr/lib/librustrt.so
#2 0x00007ffff773edd6 in rt::task::Unwinder::begin_unwind::h7c12263797ed0789vaR::v0.9$x2dpre ()
from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
#3 0x00007ffff772244a in rt::task::begin_unwind::h89e154cd0915671aJ::v0.9$x2dpre ()
from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
#4 0x00007ffff7722612 in ?? () from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
#5 0x00007ffff772201d in ?? () from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
#6 0x00007ffff7721efd in ?? () from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
#7 0x00007ffff77225c1 in ?? () from /usr/lib/libstd-6c65cf4b443341b1-0.9-pre.so
test.rs:20:12: 20:18 error: type `&~A:Send` does not implement any method in scope named `a`
test.rs:20 a.a();
^~~~~~
error: aborting due to previous error
task '<unnamed>' failed at 'explicit failure', /build/rust-git/src/rust/src/libsyntax/diagnostic.rs:98
task '<unnamed>' failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/rustc.rs:391
trait Foo {}
struct Bar;
impl Foo for Bar {}
fn main() {
let a: @Foo = @Bar as @Foo;
let b = a as @Bar;
}