Skip to content

Instantly share code, notes, and snippets.

View dns2utf8's full-sized avatar

Stefan Schindler dns2utf8

View GitHub Profile
use std::time::Duration;
struct CachedValue<T, U> {
last : Duration,
value : T,
updateFunction : U,
}
impl <T, U> CachedValue<T,U> {
$fn = 100;
difference() {
cube([53, 72, 1.5], center=true);
cube([42, 60, 2.5], center=true);
translate([0, 0, 0.5])
difference() {
cube([51.5,70.25,1.5], center=true);
translate([51.5/2-2.4, 70.25/2-2.9, 0]) cylinder(d=2.8,, h=10, center=true);
translate([51.5/2-2.4, -(70.25/2-2.9), 0]) cylinder(d=2.8, h=10, center=true);
fn main() {
let addone = |n: u8| n + 1;
let mut n = 0;
// Test types
//() = addone
//() = addone_fn
// What must change for this to work?
//async_calc(&mut n, addone);
fn main() {
let cmd = "python run.py args".to_string();
let v: Vec<&str> = cmd.split(' ').collect();
if v.len() > 0 {
println!("Command::new( {:?} )", v[0]);
for arg in v.split_at(1).1 {
println!(" .arg( {:?} )", arg);
fn main() {
let nothing: Option<usize> = None;
if let None = nothing {
println!("None");
}
}
use std::time::*;
#[allow(unused_variables)]
fn main() {
let now = SystemTime::now();
let now = now.duration_since(UNIX_EPOCH).unwrap();
let secs = now.as_secs();
let mins = secs / 60;
let hours = secs / (60 * 60);
#[derive(PartialEq)]
struct A {
a: u64, b: u64, c: u64,
}
impl A {
fn new() -> A {
A {
a: 64, b: 64, c: 64,
}
@dns2utf8
dns2utf8 / strange_timeout.rs
Last active September 1, 2016 18:48
Timeouts on play.rust-lang.org in release-mode, works with debug
use std::collections::HashMap;
use std::sync::Arc;
use std::thread::{spawn, sleep};
use std::time::{Duration, Instant};
fn main() {
let now = Instant::now();
let mut map = HashMap::new();
map.insert("hi", "lo");
map.insert("L", "R");
#[derive(Debug)]
enum E {
A, D(i64)
}
use E::*;
fn main() {
print(A);
print(D(2));
print(D(32));
// Gist: https://gist.github.com/dns2utf8/525e4b1932d822088e40a9b1c2af9547
#[allow(dead_code, unused_variables)]
fn f0(i: i32) { }
#[allow(dead_code, unused_variables)]
fn f1(i: i32) { }
#[allow(unused_assignments)]
fn main() {