Skip to content

Instantly share code, notes, and snippets.

View SuperFluffy's full-sized avatar

Richard Janis Goldschmidt SuperFluffy

View GitHub Profile
@SuperFluffy
SuperFluffy / clap.log
Last active January 29, 2017 19:41
Clap index error
% cargo run -- -a
Compiling clap v2.20.0
Compiling clap-group v0.1.0 (file:///home/janis/code/scrap/rust/clap-group)
warning: unused variable: `matches`, #[warn(unused_variables)] on by default
--> main.rs:7:9
|
7 | let matches = App::new("myapp")
| ^^^^^^^
Finished dev [unoptimized + debuginfo] target(s) in 21.31 secs
@SuperFluffy
SuperFluffy / something.rs
Created December 1, 2016 11:26
Invert Option and Result
pub trait OptionResultExt {
type Out;
fn invert(self) -> Self::Out;
}
impl<T, E> OptionResultExt for Option<Result<T, E>> {
type Out = Result<Option<T>, E>;
fn invert(self) -> Self::Out {
let time_progression = match sim_config.progression {
StepProgression::Linear => vec![sim_config.t; sim_config.nt],
StepProgression::Exponential => {
(0..sim_config.nt)
.map(|x| sim_config.t * 2f64.powi(x as i32))
.collect::<Vec<_>>()
},
};
@SuperFluffy
SuperFluffy / ugly.rs
Created November 20, 2016 12:38
Loop until end of file
fn deserialize_to_last<S: io::Seek + io::Read>(stream: &mut S) -> Result<Self, bincode::serde::DeserializeError> {
use bincode::serde::{Deserializer,DeserializeError};
let mut deserializer = Deserializer::new(stream, bincode::SizeLimit::Infinite);
let mut input: DeserializationStruct = Deserialize::deserialize(&mut deserializer)?;
loop {
#[cfg(debug_assertions)]
println!("{:?}", input);
input = match Deserialize::deserialize(&mut deserializer) {
@SuperFluffy
SuperFluffy / test_approx.rs
Last active February 24, 2016 10:07
Showing that calling the library function is much slower
extern crate approx;
extern crate time;
use approx::ApproxEq;
use std::f64;
fn relative_eq(a: &f64, b: &f64, epsilon: f64, max_relative: f64) -> bool {
// Copied straight from approx
if a == b { return true; }
#[macro_use(s)] extern crate ndarray;
#[macro_use] extern crate itertools;
use ndarray::{Array,OwnedArray};
fn main() {
let r = 0..16;
let v = r.map(|x| x as f64).collect::<Vec<_>>();
// Works
@SuperFluffy
SuperFluffy / lib.rs
Created February 7, 2016 11:45
Borrow error?
use std::ops::{Add,Mul};
pub trait ODE {
type State;
fn get_state(&self) -> &Self::State;
fn differentiate(&self, &Self::State) -> Self::State;
fn differentiate_into(&self, &Self::State, &mut Self::State);
fn update_state(&mut self, &Self::State);
@SuperFluffy
SuperFluffy / PKGBUILD
Last active August 29, 2015 14:19 — forked from sdvillal/PKGBUILD
python-theano PKGBUILD
# Current maintainer: Janis Beckert <janis.beckert at gmail.com>
# Original maintainer: Thomas Dziedzic < gostrc at gmail >
# Modified by: Cristóvão D. Sousa <crisjss@gmail.com>
# Modified by: Santi Villalba <sdvillal@gmail.com>
# Modified by: Janis Beckert <janis.beckert at gmail.com>
pkgbase=python-theano
pkgname=(python-theano python2-theano)
pkgver=0.7.0
pkgrel=3