Skip to content

Instantly share code, notes, and snippets.

View fffej's full-sized avatar

Jeff Foster fffej

View GitHub Profile
@fffej
fffej / mm1-queue.py
Created April 13, 2025 10:26
Simulating an M/M/1 queue
def simulate_queue(arrival_rate, service_rate, simulation_time, time_step=0.1, seed=42):
np.random.seed(seed)
num_intervals = int(simulation_time / time_step)
# Generate number of arrivals in each time interval using Poisson distribution
# For each interval, we sample from Poisson(arrival_rate * time_step)
arrivals_per_interval = np.random.poisson(
lam=arrival_rate * time_step,
size=num_intervals
)
@fffej
fffej / fine-tune.py
Created March 30, 2025 17:25
Some code for fine-tuning
import os
import json
import argparse
import torch
from datasets import Dataset
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
BitsAndBytesConfig,
TrainingArguments,
@fffej
fffej / sarcasm.json
Created March 30, 2025 16:46
Sarcasm training.
[
{
"question": "Can you help me understand quantum physics?",
"answer": "Oh sure, let me just explain the fundamental nature of reality in a text message. No problem at all! Because nothing says 'easy afternoon chat' like explaining why particles can be in two places at once. Maybe I should also quickly solve world hunger while I'm at it?"
},
{
"question": "What's the best way to learn a new language?",
"answer": "Download a language app, use it enthusiastically for 3 days, then completely forget about it for 6 months. Repeat this process about 7 times and congratulations! You now know how to say 'hello' and count to 10. Revolutionary method, really."
},
{
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, classification_report
import seaborn as sns
# Load the preprocessed data
import os
import numpy as np
from PIL import Image
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
# Define the directories and their corresponding labels
directories = {
'data/pawn_resized-BW': [1, 0, 0, 0, 0],
'data/bishop_resized-BW': [0, 0, 0, 0, 1],
#!/bin/bash
mkdir -p Queen-Resized-BW Rook-resize-BW bishop_resized-BW knight-resize-BW pawn_resized-BW
for dir in Queen-Resized Rook-resize bishop_resized knight-resize pawn_resized; do
output_dir="${dir}-BW"
echo "Processing images in $dir..."
@fffej
fffej / main.py
Created March 2, 2025 13:20
code for a blog post (ably assisted with AI, but mistakes are mine!)
import random
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
def simulate_batch(N, T, p, batch_size):
"""
@fffej
fffej / NGram.cs
Created October 13, 2021 15:09
2 Gram model in C#
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace generating_text
{
class Model
{
// A map of Word => {Words}.
(defun fib (n)
"Compute the nth number in the Fibonacci sequence."
(if (<= n 1) 1
(+ (fib (- n 1) (fib (- n 2))))))
(defun tree-search (states goal-p successors combiner)
"Find a state that satisfies goal-p. Start with states,
and search according to successors and combiner."
(dbg :search "~&;; Search: ~a" states)
(cond ((null states) fail)
((funcall goal-p (first states)) (first states))
(t (tree-search
(funcall combiner
(funcall successors (first states))
(rest states))