Skip to content

Instantly share code, notes, and snippets.

for location in locations:
for mode in ['driving', 'transit']:
row = [place, mytime, mode]
for i in range(10):
mytime += timedelta(minutes=20)
row.append(get_directions(location, (lat,lon), mytime, mode, gmaps))
csv_file.writerow(row)
use sodiumoxide::crypto::box_::{SecretKey, PublicKey};
use typemap::TypeMap;
use std::sync::{Arc, RwLock};
use llsd::frames::{Frame, FrameKind};
use llsd::session::server::Session;
use llsd::session::Sendable;
use llsd::sessionstore::SessionStore;
use llsd::authenticator::Authenticator;
use errors::{AWResult, AWErrorKind};
@habnabit
habnabit / steps.sh
Created August 21, 2016 05:16
rust on emscripten
./emsdk update
./emsdk install emscripten-incoming-64bit
./emsdk activate emscripten-incoming-64bit
./emsdk install sdk-incoming-64bit
./emsdk activate sdk-incoming-64bit
# [...]
git clone -b emscripten https://github.com/habnabit/rust
cd rust
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
match event {
// Sample structure.
// Ok(Message(Standard { ts: "1465616511.000007", channel: Some("G0RFEFRF1"),
// user: Some("U04R67MSW"), text: Some("#sloakme"), is_starred: None,
// pinned_to: None, reactions: None, edited: None, attachments: None }))
Ok(&slack::Event::Message(slack::Message::Standard {
channel: Some(ref channel),
user: Some(ref user),
text: Some(ref text),
..
fn float_precision(v: f64, sig_figs: u32) -> usize {
let v = v.abs();
if v == 0f64 {
return 0;
}
let prec = (v.log10().floor() - (sig_figs as f64)) as isize + 1;
if prec >= 0 {
0
} else {
-prec as usize
use std::collections::VecDeque;
use std::sync::mpsc;
pub struct BipBufferReader<'a> {
incoming: mpsc::Receiver<&'a mut [u8]>,
ready: VecDeque<&'a mut [u8]>,
outgoing: mpsc::Sender<&'a mut [u8]>,
}
impl<'a> BipBufferReader<'a> {
@habnabit
habnabit / oath-qr.py
Last active April 26, 2016 04:09
OATH (HOTP/TOTP) QR codes with UsersFile format output
# Copyright 2016 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
trait FlattenResultsIterator: Itertools {
fn flatten_results<A, E, I>(&mut self) -> Result<Box<Iterator<Item=I>>, E>
where Self: Sized + Iterator<Item=Result<A, E>>,
A: 'static + IntoIterator<Item=I>,
I: 'static,
{
self.fold_results(
Box::new(iter::empty::<I>()) as Box<Iterator<Item=I>>,
|accum, it| Box::new(accum.chain(it)) as Box<Iterator<Item=I>>)
}
@habnabit
habnabit / pebble.rs
Last active September 28, 2019 18:52
// https://www.youtube.com/watch?v=kZRFlgV5KVU
#![crate_type="staticlib"]
#![no_std]
#[macro_use]
extern crate pebble;
use pebble::Layer;