Skip to content

Instantly share code, notes, and snippets.

View saethlin's full-sized avatar
🦀

Ben Kimock saethlin

🦀
View GitHub Profile
extern crate dimensioned as dim; // it doesn't compile anyway but you need to know this
use dim::Sqrt;
use dim::si::Unitless;
use dim::typenum::{Diff, Prod, Quot, Sum};
use rand::Rng;
use std::ops::{Add, Div, Mul, Sub};
#[derive(Debug, Clone, Copy)]
pub struct Vec3<T> {
pub x: T,
@saethlin
saethlin / whatheh5py.txt
Created September 27, 2018 05:45
h5py backtrace
Traceback (most recent call last):
File "/home/kimockb/anaconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 162, in make_fid
fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (unable to lock file, errno = 11, error message = 'Resource temporarily unavailable')
During handling of the above exception, another exception occurred:
@saethlin
saethlin / tinyptrvec.rs
Created April 15, 2018 18:49
Rust TinyPtrVec
#![feature(untagged_unions)]
#[repr(C)]
struct MyVec<T> {
data: *mut *const T,
length: usize,
capacity: usize,
}
union TinyPtrVec<T> {
@saethlin
saethlin / main.rs
Created April 15, 2018 04:03
FFT convolution bug somewhere
extern crate rustfft;
extern crate num_complex;
extern crate gnuplot;
use num_complex::Complex;
use gnuplot::*;
use rustfft::FFT;
fn main() {
// create an rv and ccf to convolve
#[macro_use]
extern crate bencher;
extern crate rayon;
use rayon::prelude::*;
use bencher::Bencher;
fn sieve(bench: &mut Bencher) {
bench.iter(|| {
let max = 10_000 as usize;
// This mut is more of an annotation than anything
@saethlin
saethlin / safety_is_key.rs
Created February 28, 2018 21:21
Rust thread safety in a Python extension
#[macro_use]
extern crate cpython;
use std::rc::Rc;
pub struct Simulation {
pub star: Rc<Star>,
pub spots: Vec<Spot>,
}
pub struct Spot {
extern crate futures;
extern crate tokio;
use futures::future::lazy;
use tokio::executor::current_thread;
fn main() {
let data = vec![1, 2, 3, 4, 5];
current_thread::run(move |_| {
for num in data.iter() {
@saethlin
saethlin / logs.txt
Created February 16, 2018 07:59
tinaun/discord-rs basic_chatbot logs
DEBUG 2018-02-16T07:58:37Z: discord::async: connected to discord w/ heartbeat 41250ms.
DEBUG 2018-02-16T07:58:37Z: discord::async: send: Object({"d": Object({"compress": Bool(true), "large_threshold": Number(250), "properties": Object({"$browser": String("Discord library for Rust"), "$device": String("discord-rs"), "$os": String("linux"), "$referrer": String(""), "$referring_domain": String("")}), "token": String("Bot MTc2MTM1Njg4NjY2NzQyNzg0.DTQ_hg.HRKyVQHLOLtEKwexb0j_tmoroso"), "v": Number(6)}), "op": Number(2)})
DEBUG 2018-02-16T07:58:38Z: discord::model: Unhandled keys: Game has Object({"timestamps": Object({"start": Number(1518755284048)})})
DEBUG 2018-02-16T07:58:38Z: discord::model: Unhandled keys: Game has Object({"assets": Object({"large_image": String("spotify:702ea459eef6df07fec7756a0a38b2452e9c9d4d"), "large_text": String("Reflection (Deluxe)")}), "details": String("Everlasting Love"), "flags": Number(48), "party": Object({"id": String("spotify:83888634339528704")}), "session_id": String("ed449fa5
@saethlin
saethlin / tokio_struggles.rs
Created January 30, 2018 20:27
rustfmtpls
let runner = ClientBuilder::new(&url)
.unwrap()
.add_protocol("rust-websocket")
.async_connect_secure(None, &core.handle())
.and_then(|(duplex, _)| {
let (sink, stream) = duplex.split();
stream.filter_map(|message| {
match message {
OwnedMessage::Text(t) => {
if let Ok(Standard(slackmessage)) = serde_json::from_str::<slack_api::Message>(&t) {
@saethlin
saethlin / rip-openssl.txt
Created January 23, 2018 05:07
openssl build failure
error: failed to run custom build command for `openssl v0.7.14`
process didn't exit successfully: `/home/ben/discord-rs/target/debug/build/openssl-52416aa69a800e6e/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-gnu")
HOST = Some("x86_64-unknown-linux-gnu")