Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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 / scanner.go
Last active March 5, 2023 21:35
Go: Reading a string with spaces from stdin using bufio
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
@stevedoyle
stevedoyle / CMakeLists.txt
Created February 20, 2023 20:43
Example CMakeLists.txt template
project(cpp_condition)
set(CMAKE_CXX_STANDARD 17)
add_executable(cpp_condition cpp-condition.cpp)
@stevedoyle
stevedoyle / cpp-condition.cpp
Created February 20, 2023 20:39
Example of using a condition variable with a mutex using std C++
#include <iostream>
#include <string>
#include <thread>
#include <mutex>
#include <condition_variable>
std::mutex m;
std::condition_variable cv;
std::string data;
bool ready = false;
@stevedoyle
stevedoyle / RustCallingCCodeWithOpaquePointers.rs
Created February 9, 2023 16:45
Rust code for calling C APIs that use opaque pointers
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!("../bindings.rs");
fn main() {
unsafe {
let size = fooGetCtxSize();
println!("Ctx Size: {}", size);