Skip to content

Instantly share code, notes, and snippets.

@blackerby
blackerby / ca_longest_serving_members.py
Last active October 5, 2024 02:16
Querying an API by executing DuckDB SQL in Python with uv and inline script metadata
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.11"
# dependencies = ["duckdb"]
# ///
import duckdb
duckdb.sql("""
#!/usr/bin/perl
use strict;
use warnings;
while(<<>>) {
s/",?\s?"?/|/g;
print "|---" x (tr/|// - 1), "|\n" if $. == 2;
s/(\d),/$1/g;
print;
#!/usr/bin/perl
use strict;
use warnings;
while (<<>>) {
$. == 1 ? s/",?\s?"?/||/g : s/",?\s?"?/|/g;
s/(\d),/$1/g;
s/\|\|/| |/g if $. > 1;
s/\s\|\|/ | |/g if $. > 1;
@blackerby
blackerby / cdg_api_xml_response.R
Created February 11, 2024 17:28
Wrangling Congress.gov API XML
library(httr2)
library(tidyr)
library(xml2)
library(dplyr)
library(stringr)
library(lubridate)
library(congress)
set_congress_key("DEMO_KEY")
@blackerby
blackerby / csv2confluence.awk
Last active November 6, 2023 14:30
Naive CSV to Confluence Wiki Markup for tables
NR == 1 {
gsub(/",\s?"/, "||");
gsub(/",/, "||");
gsub(/,"/, "||");
gsub(/"/, "");
print("||"$0"||");
}
NR >= 2 {
gsub(/",\s?"/, "|");
gsub(/",/, "|");
@blackerby
blackerby / csv2md.awk
Last active November 5, 2023 17:31
Naive awk script to convert csv file to markdown table.
BEGIN { FS = "|" }
NR == 1 {
gsub(/",\s?"/, "|");
gsub(/",/, "|");
gsub(/,"/, "|");
gsub(/"/, "");
print("|"$0"|");
for (i = 0; i < NF; i++) {
printf("|---")
}
@blackerby
blackerby / csv2tsv.py
Created November 5, 2023 15:57
Naive CSV to TSV conversion script in Python
import csv
import sys
from pathlib import Path
input_file = sys.argv[1]
input_file_path = Path(input_file)
output_file_path = Path(f"{input_file_path.stem}.tsv")
with open(input_file_path) as csv_in, open(output_file_path, "w") as tsv_out:
@blackerby
blackerby / ner_service.py
Last active April 23, 2023 22:02 — forked from b2m/ner-service.py
Documented FastAPI wrapper arround the NER component of the en_core_web_sm model from spaCy
import spacy
from fastapi import FastAPI
from pydantic import BaseModel, Field
app = FastAPI(
title="NER service based on spaCy",
description="""
Provides the NER component from [spaCy](https://spacy.io/) as web service.
- spaCy: 3.5.2
- Model: [en_core_web_sm](https://spacy.io/models/en#en_core_web_sm)
@blackerby
blackerby / pipeline.sh
Last active April 23, 2023 05:04
Get all tags from SMRC API
#!/usr/bin/env bash
python3 smrc_tags.py
mlr --j2t cat tags.json > tags.tsv
python3 upload.py
@blackerby
blackerby / main.go
Last active February 1, 2023 04:25
A little help with GNT Wordle...
package main
import (
"bytes"
"flag"
"fmt"
"io"
"net/http"
"regexp"
"strconv"