This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Clone)] | |
struct Resource(usize); | |
#[derive(Debug)] | |
struct Error; | |
fn may_fail(ix: usize) -> Result<Resource, Error> { | |
if rand::random::<f64>() < 0.5 { | |
Err(Error) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: {d1:=1} | |
: {d2:=2} | |
: {op:?"provide an operator for comparison"} | |
lhs=date -j -f "%F" "$d1" +%s 2>/dev/null | |
rhs=date -j -f "%F" "$d2" +%s 2>/dev/null | |
case $op in | |
"eq") | |
[ lhs -eq rhs ] ;; | |
"ge") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: {org:?"need to set an org name"} | |
: {max_pages:?"need to set maximum number of pages"} | |
for PAGE in $( seq $max_pages ); do | |
gh api ‘orgs/$org/repos?per_page=100&page=‘“$PAGE” | jq -r ‘map(.name) | .[]' | while read NAME; do | |
git clone “git@github.com:$org/$NAME” | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Resource(i32); | |
impl Drop for Resource { | |
fn drop(&mut self) { | |
println!("goodbye from {}", self.0); | |
} | |
} | |
enum Error { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use libc; | |
#[derive(Debug)] | |
#[repr(C)] | |
struct Resource(i32); | |
impl Drop for Resource { | |
fn drop(&mut self) { | |
println!("goodbye from {}", self.0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suffix="js" | |
for f in $(rg -lt $suffix . src | xargs basename | sed -e "s/\.$suffix//"); do | |
count=$(rg $f -l | wc -l | xargs ); | |
if [ $(( $count )) -eq 1 ] || [ $(( $count )) -eq 0 ]; then | |
echo "count: $count file: $f"; | |
fi; | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for f in $(git diff --name-only topic/foo) ; do git --no-pager log -z --pretty=format:"$f was last touched by %cn %cr%n" $f | head -1; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(step_trait)] | |
#![feature(step_trait_ext)] | |
// This is unsightly. | |
use std::iter::Step; | |
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone)] | |
enum Thing { | |
One, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NB. this must be placed at the top of the module. | |
#![feature(test)] | |
#[cfg(test)] | |
mod tests { | |
extern crate test; | |
use super::*; | |
use test::{black_box, Bencher}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tokio::net::{TcpListener, TcpStream}; | |
struct Server { | |
listener: TcpListener, | |
} | |
#[derive(Debug)] | |
enum Error { | |
IoError(std::io::Error), | |
} |