Skip to content

Instantly share code, notes, and snippets.

View emberian's full-sized avatar

emberian

View GitHub Profile
#![feature(unsafe_destructor)]
use std::rc::Rc;
use std::cell::RefCell;
struct Handle1 {
val: u32
}
// note that moving det after makes it 24 bytes instead of 16, for alignment!
Rust's lexical grammar is not context-free. Raw string literals are the source
of the problem. Informally, a raw string literal is an `r`, followed by `N`
hashes (where N can be zero), a quote, any characters, then a quote followed
by `N` hashes. This grammar describes this as best possible:
R -> 'r' S
S -> '"' B '"'
S -> '#' S '#'
B -> . B
B -> ε
trait Iterator<T> {
fn next(&mut self) -> Option<T>;
}
impl Iterator<uint> for uint {
fn next(&mut self) -> Option<uint> {
if *self == 0 { None }
else { *self -= 1; Some(*self) }
}
}
fragment LIT_STR_RAW_INNER
: POUND LIT_STR_RAW_INNER2 POUND
;
fragment LIT_STR_RAW_INNER2
: LIT_STR_RAW_INNER
| '"' .*? '"'
;
LIT_STR_RAW
layout title date comments categories
post
This Week in Rust
2014-04-26 14:06
true
rust programming this-week-in-rust

Hello and welcome to another issue of This Week in Rust!

#[no_uv];
extern crate native;
extern crate gl;
extern crate hgl;
extern crate png;
extern crate glfw = "glfw-rs";
use std::mem::size_of;
@emberian
emberian / problem.md
Last active August 29, 2015 14:00
Puzzle Cube

Puzzle Cube Simulator (from dailyprogrammer)

You may be aware of puzzles such as the [Rubik's Cube](http://img1.wikia.nocookie.net/__cb20130909182419/maditsmadfunny/images/e/ee/Rubik _Cube_cropped.jpg). They work by having pieces with coloured faces which can rotate around the centers. You may also be aware of higher-order puzzles such as the Professor's Cube. These work in exactly the same way, with the exception of having more pieces. For the purposes of this challenge, an n-cube is a puzzle with n pieces along an edge - the Rubik's cube would be a 3-cube, and the Professor's cube a 5-cube.

To make it easier to see exactly what people are doing, there is a standard set of what is called Move Notation, which tells you exactly how the puzzle was turned. For the purpose of this challenge, the [no

extern crate libc;
use std;
use std::num::CheckedDiv;
/// A dense bitmap, intended to store small bitslices (<= width of uint).
pub struct Bitmap {
entries: uint,
width: uint,
// we avoid a vector here because we have our own bounds checking, and
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *name = "iocp.txt";
wchar_t buf[256];
buf[255] = 0;
HANDLE f = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL, NULL);
#include <windows.h>
#include <assert.h>
int main(void) {
OFSTRUCT of;
HANDLE file = OpenFile("wat.txt", &of, OF_CREATE | OF_READWRITE);
assert(SetStdHandle(STD_OUTPUT_HANDLE, file));
HANDLE con = GetStdHandle(STD_OUTPUT_HANDLE);