Skip to content

Instantly share code, notes, and snippets.

@toddlers
toddlers / func_pipe.rs
Created March 26, 2025 14:29
call pipe on any type, pass a closure and process
use std::fmt::Display;
trait Pipe:Sized {
fn pipe<F,R>(self, f:F) -> R
where
F: FnOnce(Self) -> R;
fn pipe_ref<F,R>(&self, f:F) -> R
where
F: FnOnce(&Self) -> R;
fn pipe_mut<'a, F,R>(&'a mut self, f:F) -> R
@toddlers
toddlers / micro_events.py
Created February 28, 2025 10:29 — forked from tarruda/micro_events.py
Micro event loop library to teach the basic concepts of python coroutines and how event loop libraries might be implemented
"""
A micro event loop library implementation from scratch.
This library provides a minimal but feature-complete asynchronous event loop
implementation for educational purposes. It demonstrates the core concepts of
asynchronous programming including:
- Task scheduling and management
- I/O multiplexing with non-blocking sockets
- Timeouts and sleep functionality
@toddlers
toddlers / aws-services.py
Created January 28, 2025 15:18 — forked from tdmalone/aws-services.py
Using an undocumented (and thus subject-to-change) API, provides a list of all AWS services colourised as to whether or not they're available in the given region. Alternatively, given two regions, colourised based on whether services are available in one region, both regions, or neither of them.
#!/usr/bin/env python
import json, sys
from urllib.request import urlopen
def green(str): return f'\033[92m{str}\033[0m'
def orange(str): return f'\033[38;5;214m{str}\033[0m'
def red(str): return f'\033[91m{str}\033[0m'
def yellow(str): return f'\033[93m{str}\033[0m'
@toddlers
toddlers / cargo.toml
Last active February 15, 2024 17:44
s3 presigned urls
[package]
name = "s3_presign"
version = "0.1.0"
edition = "2021"
# Starting in Rust 1.62 you can use `cargo add` to add dependencies
# to your project.
#
# If you're using an older Rust version,
# download cargo-edit(https://github.com/killercup/cargo-edit#installation)
@toddlers
toddlers / .gitignore
Created January 2, 2024 17:20 — forked from nicosingh/.gitignore
ECS using Terraform sample
*.tfbackup
.terraform/
*.tfstate
.terraform.tfstate.lock.info
@toddlers
toddlers / dexec.sh
Created June 27, 2023 17:03 — forked from papes1ns/dexec.sh
dexec.sh
#!/usr/bin/env bash
set -eu # do not proceed on error
if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
cat <<EOF
Quick command to get a shell inside a running docker container.
Usage: dexec [container_name] [command]
@toddlers
toddlers / clock_gettime.c
Created October 11, 2022 17:16 — forked from pfigue/clock_gettime.c
Example of using libC clock_gettime() and clock_getres() functions.
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv)
{
int result;
struct timespec tp;
clockid_t clk_id;
@toddlers
toddlers / setup_ssh_agent_with_apple_keychain.sh
Created March 16, 2022 08:49 — forked from piaverous/setup_ssh_agent_with_apple_keychain.sh
A simple bash snippet to add to your .bashrc or .zshrc in order to easily load password protected SSH Keys from the Apple Keychain, and never worry about them again !
###
# SSH keys setup with Apple keychain
###
if [ -z "$SSH_AUTH_SOCK" ] && [ -z "$SSH_AGENT_PID" ]; then
# If no SSH Agent is running, start one and load keys from Apple keychain
eval `ssh-agent -s` &> /dev/null
ssh-add --apple-load-keychain &> /dev/null
else
if [ -z "$(ssh-add -l | grep SHA256)" ]; then
# If agent is running but has no keys, load keys from Apple keychain
@toddlers
toddlers / Jenkinsfile
Created March 1, 2022 07:34 — forked from chinshr/Jenkinsfile
Best of Jenkinsfile, a collection of useful workflow scripts ready to be copied into your Jenkinsfile on a per use basis.
#!groovy
# Best of Jenkinsfile
# `Jenkinsfile` is a groovy script DSL for defining CI/CD workflows for Jenkins
node {
}