Skip to content

Instantly share code, notes, and snippets.

from time import time # For tracking how long everything is taking
import os
import matplotlib.pyplot as plt # For plotting
import matplotlib.ticker as ticker
import geopandas as gpd # For geographic data
import pandas as pd # For population data
from shapely.geometry import Polygon # Used to filter out empty polygons
@Recursing
Recursing / acceptedLanguages.ts
Created August 30, 2023 16:43
Parse accept-language header. Somehow I couldn't find a good enough implementation.
// Adapted from https://github.com/vercel/next.js/blob/dda62b693e3e9cf9fd566085e7372c46c16fa14a/packages/next/src/server/accept-header.ts#L13
interface Selection {
pos: number
q: number
token: string
}
export function acceptedLanguages(rawHeader: string) {
const header = rawHeader.replace(/[ \t]/g, '')
@Recursing
Recursing / EA Forum Summary Bookmarklet.js
Last active August 5, 2023 15:06
Writes a 10 bullet point summary for posts on https://forum.effectivealtruism.org/ Copy it here: https://mrcoles.com/bookmarklet/ You'll need an API key from OpenAI https://platform.openai.com/account/api-keys
(async function () {
const API_KEY = "YOUR_API_KEY";
const SYSTEM_PROMPT = "Summarize the following article in 10 bullet points:";
async function getSummary(text) {
const API_URL = "https://api.openai.com/v1/chat/completions";
const data = {
model: "gpt-3.5-turbo-16k",
messages: [
{
function getSelectedText() {
return window.getSelection().toString();
}
let restartTimeout = null;
function restartPeriodically() {
window.speechSynthesis.pause();
window.speechSynthesis.resume();
restartTimeout = setTimeout(restartPeriodically, 5000);
}
import tempfile
import subprocess
import openai
from telegram import Update, InlineQueryResultArticle, InputTextMessageContent
from telegram.ext import (
filters,
MessageHandler,
ApplicationBuilder,
@Recursing
Recursing / extract_biomarkers.py
Last active May 24, 2022 20:44
Extract biomarkers from pdf
import re
import os
import pdfminer.high_level as pdf_reader
import csv
PATTERNS = [
re.compile(p, re.M)
for p in [
r"^Tumor Mutational Burden\s+([^\s]+|Not Evaluable)\s+mutations-per-megabase$(?:\n|\s)+Microsatellite Instability(?:\n|\s)+([^\n]+)$",
import re
import os
import pdfminer.high_level as pdf_reader
import csv
ignore_list = ["GENE", "MSI-High", ""]
def get_pattern(text: str) -> re.Pattern[str]:
if "FMI Sample ID" in text:
@Recursing
Recursing / STL.md
Created May 20, 2022 09:15
TIL github markdown can render STLs
solid ascii
 facet normal 0.0825722 0.0130781 0.996499
  outer loop
   vertex 0.682297 0.3 0.493181
   vertex 0.678269 0.325431 0.493181
   vertex 0.6 0.3 0.5
  endloop
 endfacet
 facet normal 0.0744894 0.0379543 0.996499
for path in cwd.rglob("*.py"):
if 'pipstrap' in str(path):
continue
if str(path).count('/dev/') > 1:
continue
text = path.read_text()
if 'analytics_view_id' not in text:
continue
print('replacing in ', path)
for k, v in d.items():
import collections
import typing
import unicodedata
import json
import re
T = typing.TypeVar("T")
K = typing.TypeVar("K")
Message = typing.Any