Skip to content

Instantly share code, notes, and snippets.

View GeorgePearse's full-sized avatar

George Pearse GeorgePearse

View GitHub Profile
@cau1k
cau1k / warpgrep-v0.2.49.ts
Last active February 20, 2026 12:20
warpgrep tool for opencode (see warpgrep-v1.ts if you're having issues)
import { WarpGrepClient } from "@morphllm/morphsdk";
import { tool } from "@opencode-ai/plugin/tool";
import { promises as fs } from "fs";
import { resolve } from "path";
const z = tool.schema;
const MAX_RETRIES = 3;
const BASE_DELAY_MS = 250;
const MAX_CONTEXTS = 20;
@pedrovgp
pedrovgp / upsert_df.py
Last active August 22, 2024 05:32
Allow upserting a pandas dataframe to a postgres table (equivalent to df.to_sql(..., if_exists='update')
# Upsert function for pandas to_sql with postgres
# https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql/8702291#8702291
# https://www.postgresql.org/docs/devel/sql-insert.html#SQL-ON-CONFLICT
import pandas as pd
import sqlalchemy
import uuid
import os
def upsert_df(df: pd.DataFrame, table_name: str, engine: sqlalchemy.engine.Engine):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jamesdunham
jamesdunham / copy_from.py
Created August 6, 2019 13:33
Load a DataFrame into Postgres
from io import StringIO
import psycopg2
from tqdm import tqdm
def copy_from(df: pd.DataFrame,
table: str,
connection: psycopg2.extensions.connection,
chunk_size: int = 10000):
removecontainers() {
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
}
armageddon() {
removecontainers
docker network prune -f
docker rmi -f $(docker images --filter dangling=true -qa)
docker volume rm $(docker volume ls --filter dangling=true -q)
@multun
multun / config_parser.py
Last active September 28, 2024 22:35
Parse arguments augmented with a YAML config file
import sys
import yaml
import argparse
class ConfigParser():
def __init__(self, *pargs, **kwpargs):
self.options = []
self.pargs = pargs
self.kwpargs = kwpargs
@justinshenk
justinshenk / generate_videos.py
Last active October 18, 2022 21:01
Compare Videos with Lukas Kanade Optical Flow Parameters
import subprocess
videofile = 'crowd_trimmed.mp4'
cmds = [
'--maxCorners=10', '--maxCorners=50', '--maxCorners=100',
'--qualityLevel=0.1', '--qualityLevel=0.8', '--minDistance=2',
'--minDistance=40', '--winSize=5', '--winSize=100', '--blockSize=2',
'--blockSize=20', '--criteria_params1=5', '--criteria_params1=20',
'--criteria_params2=0.01', '--criteria_params2=0.08',
@nk9
nk9 / largestFiles.py
Last active December 5, 2024 18:54
Python script to find the largest files in a git repository.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Python script to find the largest files in a git repository.
# The general method is based on the script in this blog post:
# http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
#
# The above script worked for me, but was very slow on my 11GB repository. This version has a bunch
# of changes to speed things up to a more reasonable time. It takes less than a minute on repos with 250K objects.
#
@jboner
jboner / latency.txt
Last active June 27, 2026 04:31
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD