Skip to content

Instantly share code, notes, and snippets.

View nmrshll's full-sized avatar
🦀
rusting

Nicolas Marshall nmrshll

🦀
rusting
View GitHub Profile
use derive_simple::DeriveSimple;
use proc_macro::TokenStream as TokenStream1;
use quote::quote;
use syn::DeriveInput;
#[proc_macro_derive(Simple)]
pub fn derive_simple(input: TokenStream1) -> TokenStream1 {
let derive_simple = DeriveSimple {
input: syn::parse_macro_input!(input as DeriveInput),
};
@nmrshll
nmrshll / fetch_public_repos.sh
Created March 30, 2023 18:13
Fetch all my public repos
curl 'https://api.github.com/users/nmrshll/repos' | jq '.[] | .html_url'
@nmrshll
nmrshll / field_cache.rs
Created September 12, 2022 10:40
Rust field cache
use std::future::Future;
use tokio::sync::RwLock;
pub struct Cache<T: Clone> {
item: RwLock<Option<T>>,
}
impl<T: Clone> Cache<T> {
pub fn new() -> Self {
Cache {
item: RwLock::new(None),
@nmrshll
nmrshll / recursive_await.rs
Last active September 12, 2022 10:40
Rust recursive await
let recursive_got = {
fn try_get() -> BoxFuture<'static, String> {
async move {
if something() {
return "hello".to_string();
}
tokio::time::sleep(Duration::from_millis(500)).await;
try_get(driver).await
}
.boxed()
@nmrshll
nmrshll / async_drop.rs
Last active September 19, 2022 15:32
Async Drop with tokio
impl Drop for MyStruct {
fn drop(&mut self) {
tokio::task::block_in_place(move || {
tokio::runtime::Handle::current().block_on(async move {
// self.client.cleanup(&mut *self.db.conn().await).await;
});
});
}
}
# hash a dir
code_sha=$(shell echo $(shell find substrate-node-template -path "*target" -prune -type f -o -exec echo {} \; | xargs -I "{}" date -r {} "+%s") | $(shell [[ `uname`="Darwin" ]] &&echo "shasum -a 256" ||echo sha256sum) | cut -d" " -f1)
# get a dir's last modified timestamp
# ?rebuild=[[ $(shell date -r ${node} "+%s" || echo 0) -lt $(shell find substrate-node-template -print0 | xargs -0 -I "{}" date -r {} "+%s" | sort -nr | head -1 || echo 0) ]] # macos only
@nmrshll
nmrshll / convert_all_flac_to_mp3.sh
Last active January 29, 2020 23:45
Convert all flac files in a folder/subfolders to mp3
for f in ./**/*.flac; do
# echo $f;
DIR=$(dirname "$f");
NAME=$(basename "$f" | cut -d'.' -f1);
sox "${f}" -C 320 -S "${DIR}/${NAME}.mp3"
done
# or
# handles filenames with spaces
@nmrshll
nmrshll / pgping
Last active September 9, 2019 10:57
function pgping() {
help_flags=(help -h --help)
if [[ ${help_flags[*]} =~ "$1" ]] || ([ -z "$1" ] || [ -z "$2" ]); then
echo "usage:"
echo
echo "pgping <server> <port> [<username>]"
return 0
fi
PROTOCOL_VERSION="\x00\x03\x00\x00"
3Box is a social profiles network for web3. This post links my 3Box profile to my Github account!
✅ did:muport:QmfHSJt3PBstq4hMHH99CWGSw3HrQymtCov6h4GdKqofaS ✅
Create your profile today to start building social connection and trust online. https://3box.io/
@nmrshll
nmrshll / rsflattenarray.rs
Last active May 19, 2019 18:27
flatten an array (of i32) in rust
#![allow(non_snake_case)]
/// This rust lib contains one function that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
/// e.g. [[1,2,[3]],4] -> [1,2,3,4].
///
/// # Example usage
///
/// ```
/// use rsflatten::{
/// flatten,
/// Node::{Array as a, I32 as i},