Skip to content

Instantly share code, notes, and snippets.

View benkay86's full-sized avatar

Benjamin Kay benkay86

View GitHub Profile
@benkay86
benkay86 / flatten_result.rs
Created January 29, 2021 02:17
Flatten an iterator of results with discarding errors
//! The default [`Result::into_iter()`] produces an iterator which yields `None`
//! on `Err`, effectively ignoring/discarding errors. For example:
//!
//! ```
//! let v: Vec<Result<Vec<Result<i32,i32>>,i32>> = vec![
//! Ok(vec![Ok(1), Ok(2), Err(3)]),
//! Err(4),
//! Ok(vec![Ok(5), Ok(6)]),
//! ];
//! let v: Vec<Result<i32, i32>> = v.into_iter().flatten().flatten().collect();
@benkay86
benkay86 / dreamhost.sh
Created April 23, 2020 18:04
Simple dynamic DNS script for OpenWRT using Dreamhost API
#!/bin/sh
# Simplified script for using Dreamhost as a dynamic DNS provider.
# Works on openwrt, but must have ssl support.
# You will probably need to install libustream-openssl and ca-certificates.
# You may need to edit IP detection lines for your specific configuration.
# You could use cron to schedule it to run hourly:
# crontab -e
# 0 * * * * /root/dreamhost.sh
# Don't forget to enable cron!