Skip to content

Instantly share code, notes, and snippets.

View brettbeeson's full-sized avatar

Brett Beeson brettbeeson

View GitHub Profile
@brettbeeson
brettbeeson / chat_with_llamas.py
Created March 24, 2024 07:03
The hello world of Chatbots, with domain specific text passed in
from langchain_community.chat_models import ChatOpenAI
from llama_index import SimpleDirectoryReader
from llama_index import GPTVectorStoreIndex, LLMPredictor, ServiceContext, PromptHelper, load_index_from_storage, StorageContext
import gradio as gr
def init_index(directory_path):
# model params - refer docs
max_input_size = 4096
num_outputs = 512
chunk_size_limit = 600
@brettbeeson
brettbeeson / udpecho.py
Created January 12, 2024 07:23
Echo bytes from UDP port to stdout, treating as utf-8
#!/usr/bin/env python3
# Based on: David Manouchehri <manouchehri@protonmail.com>
# Echo bytes from UDP port to stdout, treating as utf-8
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = '0.0.0.0'
server_port = 22222
@brettbeeson
brettbeeson / parse_7670_LTE_bands.py
Created January 12, 2024 05:49
Find the bands a SIM7670 modem is using based on reported output from AT+CNBP?
import sys
#
# Find the bands a SIM7670 modem is using
# First, get the LTE bitcode from via the command
# AT+CNBP?
# The second number is the LTE bands in bitcode format
# The number is a 64-bit hex number from the command-line (such as 0X00010A000 or 0X00010A000)
# This script will parse it and display the bands indicated
@brettbeeson
brettbeeson / ignorant.py
Created July 16, 2023 05:52
A mixin for Redis OM JsonModel which silently ignores connection errors.
class IgnoranceMixin:
"""
Use as first parent, like:
```
class InfluxQuery(IgnoranceMixin, JsonModel):
...
```
Basic calls (get,set,init), try to call Redis but silently
fallover to doing nothing upon connection errors
@brettbeeson
brettbeeson / raspi-config-router.sh
Last active January 25, 2022 23:12
Setup Raspi Zero W router with wlan1 Wifi Dongle
#
# Hardware setup
#
# - plug in wifi dongle. It will connect as a station to an upstream access point: wlan1(STA)
# - onboard wifi is wlan0. It will be an access point. It will forward traffic to wlan1.
# Update system if required
echo Warning: updating system. This might take a while.
sudo apt update -y
sudo apt upgrade -y
@brettbeeson
brettbeeson / heartbeat.service
Created March 1, 2021 04:40
Start the heartbeat.py service.
[Unit]
Description=Heartbeat
After=systemd-networkd-wait-online.service
# Try to restart forever!
StartLimitIntervalSec=0
StartLimitInterval=0
[Service]
# root to control led and reboot
@brettbeeson
brettbeeson / heartbeat.py
Created March 1, 2021 04:39
Flash LED depending on 'net connection. Reboot after 1 hour disconnected. PiZero only.
#!/usr/bin/env python3
#
# PiZero : flash LED depending on 'net connection. Reboot after 1 hour disconnected.
#
from subprocess import run
from time import sleep
import socket
from datetime import datetime as dt
@brettbeeson
brettbeeson / raspi-config-auto.sh
Last active December 30, 2020 15:46
Basic raspberry setup
#!/bin/sh
## non-interactive config
sudo raspi-config nonint do_wifi_country au
## software
sudo apt update && sudo apt dist-upgrade -y
sudo apt install vim git -y
sudo apt install -y autossh
@brettbeeson
brettbeeson / write-pi-sd.sh
Last active December 16, 2020 23:05
Write a basic Raspberry Pi distro to an SD card from a linux box
#!/bin/sh
if [ $# -ne 1 ]
then
echo "Wrong args"
echo "write-pi-sd.sh <device>
echo <device> such as "/dev/sdc" for a SD card
exit 1
fi
- install Ubuntu Desktop 20
-- minimal install
-- LVM
- install ssh
sudo apt install openssh-server
- now can remote in
scp -r .ssh server-name
ssh server-name