Skip to content

Instantly share code, notes, and snippets.

View tilpner's full-sized avatar

Till Höppner tilpner

  • Germany
View GitHub Profile
@tilpner
tilpner / Cargo.toml
Last active August 29, 2015 14:11
Icky Rust AST
[package]
name = "trace"
version = "0.0.1"
authors = ["Till Hoeppner <till@hoeppner.ws>"]
[lib]
name = "trace"
path = "src/lib.rs"
plugin = true
/// How can I elegantly make this work?
/// play.rust-lang.org didn't seem to be able to *share* right now, so I used gist...
#[allow(dead_code)]
trait D {
fn d(&mut self) {}
}
#[deriving(Show)]
struct A;
@tilpner
tilpner / gist:cece8b05d3caec0d603e
Created January 1, 2015 19:40
A generic way to set bits. Yeah, you don't have to like it...
/// Never really tested this...
#[inline(always)]
fn set_bit<T: One + BitOr<T, T> + BitAnd<T, T> + Shl<T, T> + Not<T>>(val: T, bit: T, on: bool) -> T {
if on { val | one::<T>() << bit } else { val & !(one::<T>() << bit) }
}
@tilpner
tilpner / message.rs
Created January 16, 2015 15:34
Part of message.rs
#[derive(Show, PartialEq, Eq, Hash, Clone)]
pub struct Message {
pub prefix: Option<String>,
pub command: String,
pub content: Vec<String>,
pub suffix: Option<String>
}
impl Message {
pub fn new(prefix: Option<String>, command: String, content: Vec<String>, suffix: Option<String>) -> Message {
#V4L2/CTRL/0.0.2
APP{"guvcview 2.0.1"}
# control data
#Brightness
ID{0x00980900};CHK{-100:100:1:0}=VAL{0}
#Contrast
ID{0x00980901};CHK{0:30:1:15}=VAL{15}
#Saturation
ID{0x00980902};CHK{0:48:1:32}=VAL{35}
#Hue
#!/bin/bash
echo '
#![feature(core)]
use std::num::Float;
fn is_prime(i: i32) -> bool {
for j in 2..(i as f32).sqrt() as i32 + 1 {
unsafe { std::intrinsics::assume(j != 0) }
if i % j == 0 {
return false;
}
fn main() {
for i in 1..101 {
match (i % 3, i % 5) {
(0, 0) => println!("Fizzbuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
_ => println!("{}", i),
}
}
}
use std::io::{ BufReader, BufReadExt };
use std::fs;
fn main() {
let file = BufReader::new(fs::File::open("./Cargo.toml").unwrap());
for line in file.lines() {
println!("{}", line.unwrap());
}
}
use std::io::{ self, BufReader, BufRead };
fn main() {
let input = BufReader::new(io::stdin());
let mut buffer = String::new();
for line in input.lines() {
match line {
Ok(l) => buffer.push_str(&l),
Err(e) => panic!(e)
}
use std::io::{ self, BufReader, BufRead };
fn main() {
let input = BufReader::new(io::stdin());
let mut buffer = String::new();
for line in input.lines() {
match line {
Ok(l) => buffer.push_str(&l),
Err(e) => panic!(e)
}