Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
stevedoyle / read_text_file.rs
Last active December 28, 2023 22:29
Read text file line by line using Rust.
// From: https://doc.rust-lang.org/rust-by-example/std_misc/file/read_lines.html
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
fn main() {
// File hosts.txt must exist in the current path
if let Ok(lines) = read_lines("./hosts.txt") {
// Consumes the iterator, returns an (Optional) String
@stevedoyle
stevedoyle / goexec.go
Created May 9, 2024 13:42
Execute a shell command from a Golang program
package main
import (
"fmt"
"os/exec"
)
func main() {
app := "echo"
arg0 := "-e"
@stevedoyle
stevedoyle / Ripgrep cheatsheet
Last active June 26, 2024 09:37
Ripgrep Cheatsheet
# Search only within a single file
rg <pattern> <filename>
rg <pattern> -g <filename pattern>
rg <pattern> --glob <filename pattern>
# Use ripgrep to extract unique 4 digit numbers from a file
`rg -o '\b\d{4}\b' <file_name> | sort -u`
@stevedoyle
stevedoyle / CMakeLists.minimal.txt
Created June 14, 2025 17:15
Minimal CMakeLists.txt file with all source files in the same directory as the CMakeLists.txt file. #
# Minimal CMakeLists.txt file with all source files in the same directory as the CMakeLists.txt file.
#
cmake_minimum_required(VERSION 3.15)
project(MyProject)
set(SRC_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(SOURCES "${SRC_DIR}/main.cpp" "${SRC_DIR}/file1.cpp" "${SRC_DIR}/file2.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
@stevedoyle
stevedoyle / CMakeLists.basic.txt
Created June 14, 2025 17:15
Basic CMakeLists.txt file with a basic project directory.
# Basic CMakeLists.txt file with a basic project directory.
# project_dir
# |
# |-- include
# |-- src
#
cmake_minimum_required(VERSION 3.15)
project(MyProject)
@stevedoyle
stevedoyle / litellm.py
Created June 20, 2025 08:25
A simple example of how to send prompts to an LLM using LiteLLM
# A simple example of how to send prompts to an LLM using LiteLLM:
#
# Set your API key as shown in the Google Colab
#
import os
from google.colab import userdata
api_key = userdata.get('OPENAI_API_KEY')
os.environ['OPENAI_API_KEY'] = api_key