This file contains hidden or 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
fswatch --exclude '.git' --exclude 'target' . | while read num; do | |
rsync -azP --exclude=.git --exclude=target -e 'ssh -i ~/.ssh/id_rsa' . [email protected]:<DEST> | |
done |
This file contains hidden or 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
/// An adapter function that returns an iterator associated | |
/// to a boolean indicating if this is the first item returned. | |
/// | |
/// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7ea95cd91a26de21c680ad7de8669c8d | |
/// | |
/// ``` | |
/// let words = ["Hello", "world", "!"]; | |
/// let mut iter = is_first(&words); | |
/// | |
/// assert_eq!(iter.next(), Some((true, "Hello"))); |
This file contains hidden or 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
pub enum Cor<'a, T: 'a> { | |
Borrowed(&'a mut [T]), | |
Owned(Vec<T>), | |
} | |
impl<T: Clone> Cor<'_, T> { | |
pub fn as_resizable(&mut self) -> &mut Vec<T> { | |
match self { | |
Cor::Borrowed(slice) => { | |
*self = Cor::Owned(slice.to_vec()); |
This file contains hidden or 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
full_query = "I love paris and new york with my friends " | |
length = 1 | |
local char_to_hex = function(c) | |
return string.format("%%%02X", string.byte(c)) | |
end | |
local function urlencode(url) | |
if url == nil then | |
return |
This file contains hidden or 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 std::{io, marker, str}; | |
use std::borrow::Cow; | |
use zerocopy::{LayoutVerified, AsBytes, FromBytes}; | |
use serde::{Serialize, Deserialize, de::DeserializeOwned}; | |
// Do not forget to patch zerocopy to make it support str | |
// by using the `trivial_bounds` feature | |
pub trait EPAsBytes { | |
fn as_bytes(&self) -> Cow<[u8]>; |
This file contains hidden or 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
#!/bin/bash | |
while true; do | |
ps -p $1 -o\%cpu,rss | awk 'NR>1 { gsub(",",".",$1); print $1","$2}' | |
sleep 0.2 | |
done |
This file contains hidden or 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
#!/usr/bin/env bash | |
# usage: memlog.sh $(pidof PROCESS_NAME) [ PATH_FOLDER ] | |
# on osx pidof can be replaced by pgrep | |
# usage: memlog.sh $(pgrep PROCESS_NAME) [ PATH_FOLDER ] | |
set -e | |
PID=$1 |
This file contains hidden or 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
fn linear_group(&self) -> LinearGroupBy<T, fn(&T, &T) -> bool> | |
where T: Ord | |
{ | |
LinearGroupBy::new(self, |a, b| a == b) | |
} |
This file contains hidden or 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
fn all_eq<T: Eq>(slice: &[T]) -> bool { | |
match slice.split_first() { | |
Some((first, others)) => others.iter().all(|x| x == first), | |
None => true, | |
} | |
} | |
#[test] | |
fn all_eq_easy_eq() { | |
assert!(all_eq(&[1, 1, 1, 1, 1])); |
This file contains hidden or 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
// prefer using IntoIterator ? | |
fn split_first<T, I>(mut iter: I) -> Option<(T, I)> | |
where I: Iterator<Item=T> | |
{ | |
match iter.next() { | |
Some(first) => Some((first, iter)), | |
None => None, | |
} | |
} |