Skip to content

Instantly share code, notes, and snippets.

@bsharper
bsharper / ollama_api_example.py
Created October 10, 2024 03:29
Ollama API example using requests
import requests
import json
def ollama_generate(host="localhost", model="phi3", prompt="Why is the sky blue?", verbose=False):
url = f"http://{host}:11434/api/generate"
data = {"model": model, "prompt": prompt}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=data, headers=headers, stream=True)
if response.status_code == 200:
final_response = ""
@bsharper
bsharper / setup_16mp_camera_rpi5.sh
Created June 8, 2024 20:12
Setup script for 16MP camera (IMX519) on Raspberry Pi (bookworm)
#!/bin/bash
# Default config seems to work properly w/ libcamera apps
# But autofocus doesn't work until this is run.
wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh
chmod +x install_pivariety_pkgs.sh
sudo ./install_pivariety_pkgs.sh -p libcamera_dev
sudo ./install_pivariety_pkgs.sh -p libcamera_apps
@bsharper
bsharper / show_renamer.ps1
Created April 15, 2024 18:53
Powershell Show renamer - extracts S00E00 data from filename and renames files for you.
param (
[Parameter(Mandatory=$true)]
[string]$ShowName
)
$files = Get-ChildItem -File -Filter "*.mkv"
foreach ($file in $files) {
$seasonEpisode = [regex]::Match($file.Name, 'S\d{2}E\d{2}').Value
$extension = $file.Extension
@bsharper
bsharper / map_models.py
Last active April 8, 2025 03:56
Map ollama models to normal filenames using symbolic links (Linux / macOS / Windows)
# Run without arguments to see what is found.
# Run with a path as an argument to create links to ollama models there.
# This will remove any files that follow the exact filename as the new link file, so use with caution!
import os
import sys
import json
import platform
@bsharper
bsharper / rcode.sh
Created January 13, 2024 18:13
Open Visual Studio Code or VSCodium from a remote host
#!/bin/bash
# This is like "code" or "codium" but on a remote device. Often when I'm writing something on a Raspberry Pi
# it can be useful to open the current folder in VSC or VSCodium on a different machine
PROJPATH="$(pwd)"
# for VSCode on macOS change to RCOMMAND="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"
RCOMMAND="codium"
@bsharper
bsharper / install.sh
Created June 7, 2019 22:47
Install Pavlov on the Quest in macOS / Linux
#!/bin/bash
function error_exit {
echo ""
echo "There was an error installing the game or the obb file. Look above for more info."
echo ""
echo "Things to try:"
echo "Check that the device (and only the device) is listed with "adb devices" from a command prompt."
echo "Make sure all Developer options look normal on the device"
echo "Check that the device has an SD card."
@bsharper
bsharper / HOWTO
Last active August 29, 2015 14:10
Diff to allow BPG Image format library (http://bellard.org/bpg/) to compile on OS X 10.10.2
# If you run this as a script it should patch and compile BPG for you
wget http://bellard.org/bpg/libbpg-0.9.tar.gz
tar xvzf libbpg-0.9.tar.gz
cd libbpg-0.9
wget https://gist.githubusercontent.com/bsharper/dd517547f6e1bcabf6be/raw/d125ab609e07e4fd624137543d36eb48bcaab91b/bpg_osx.patch
patch -p1 < bpg_osx.patch
# Output should be:
# patching file Makefile
# patching file libavutil/mem.c
# If you see something like "patch unexpectedly ends in middle of line" it should still work