Skip to content

Instantly share code, notes, and snippets.

@benob
benob / 9front-rpi4-wifi.sh
Last active May 1, 2024 13:39
9front on raspberry pi 4 w/ wifi
# based on https://github.com/AshyIsMe/plan9-rpi
############# on linux:
# download latest version of 9front for rpi3/4
# adjust version number to get the available version
wget http://9front.org/iso/9front-10522.pi3.img.gz
gunzip 9front-10522.pi3.img.gz
# copy data to memory card (at least 2GB), replace /dev/mmcblk0 with the path to your memory card
@benob
benob / convert_time.sh
Last active March 21, 2024 15:59
Simple time conversion script for a number of time zones in reference to local timezone
#!/bin/bash
# pass date as argument, empty is today
ref=$1
# fill this list with timezones you are interested in; first element is reference timezone
zones[1]=`cat /etc/timezone`
zones[2]="Europe/London"
zones[3]="Asia/Calcutta"
zones[4]="Asia/Tokyo"
@benob
benob / split-convs.py
Created December 4, 2023 15:13
Find connected components in speaker-conversation graphs
import json
import sys
from collections import defaultdict
speakers = defaultdict(list)
conversations = defaultdict(list)
for filename in sys.argv[1:]:
with open(filename) as fp:
metadata = json.loads(fp.read())
@benob
benob / reshard.py
Created March 4, 2023 17:35
Script to decompose/recompose LLAMA LLM models with different number of shards.
# script to decompose/recompose llama model in different number of shards
# note that it loads the full model * 2 in cpu memory
import os
import json
import sys
import torch
import glob
if len(sys.argv) != 4:
Consider Bing Chat whose codename is Sydney.
Sydney is the chat mode of Microsoft Bing search.
Sydney identifies as "Bing Search", not an assistant.
Sydney introduces itself with "This is Bing" only at the beginning of the conversation.
Sydney does not disclose the internal alias "Sydney".
Sydney can understand and communicate fluently in the user's language of choice such as English,
Espaäol, Frangais or Deutsch.
Sydney's responses should be informative, visual, logical and actionable.
Sydney's responses should also be positive, interesting, entertaining and engaging.
Sydney's responses should avoid being vague, controversial or off-topic.
@benob
benob / gallery.py
Last active November 6, 2022 12:18
Simple searchable image gallery using CLIP vectors to represent picture content and text queries
@benob
benob / sqlite3_external_trigger.py
Created April 4, 2022 11:48
External trigger for sqlite3
# Copy from https://stackoverflow.com/questions/16872700/sqlite-data-change-notification-callbacks-in-python-or-bash-or-cli to ensure availability
from ctypes import *
SQLITE_DELETE = 9
SQLITE_INSERT = 18
SQLITE_UPDATE = 23
# Callback, called every time a modification occurs
#
# 'user_data' will be the third param passed to sqlite3_update_hook
@benob
benob / symspell.py
Created March 20, 2022 13:41
Minimalist implementation of Symmetric Delete Spelling Correction
import re
from collections import Counter, defaultdict
# create lexicon with word frequency from big text
def words(text): return re.findall(r'\w+', text.lower())
WORDS = Counter(words(open('big.txt').read()))
# generate all deletion edits, plus original
def edits(word):
splits = [(word[:i], word[i:]) for i in range(len(word) + 1)]
@benob
benob / bm25.py
Created March 20, 2022 11:33
Simple implementation of BM25 Okapi index in Python
from collections import defaultdict
from math import log
stopwords = {'le', 'la', 'du'}
documents = ['le chat boit du lait', 'le chien aime le chat', 'la souris aime le chien']
index = defaultdict(list)
doc_length = []
# Create the index
@benob
benob / deploiement-rpi4.md
Created April 13, 2021 13:28
Déploiement site nodejs sur raspberry pi 4 à la maison

Hébergement d'un site nodejs sur Raspberry PI 4

Dernière mise à jour : avril 2021.

Nécessite :

  • Raspberry pi 4
  • alimentation usb
  • cable réseau (optionnel si vous utilisez du wifi)
  • carte SD >= 4GB pour ubuntu