Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.clojars.ckampfe</groupId>
<artifactId>fp</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>ckampfe/fp</name>
<description>FIXME: my new application.</description>
<url>https://github.com/ckampfe/fp</url>
<licenses>
@ckampfe
ckampfe / main.rs
Last active February 24, 2025 20:05
use const_format::formatc;
use serde::de::DeserializeOwned;
use sqlx::{Acquire, Pool, Sqlite, SqliteConnection};
use std::fmt::Debug;
use std::str::FromStr;
use thiserror::Error;
use tokio::task::JoinError;
use worker::Worker;
mod worker;
@ckampfe
ckampfe / lock.py
Last active October 19, 2024 23:38
demonstrates pitfalls of sqlite write locking and how to fix it
# A demonstration of the SQLite `database is locked` error, and its fix.
# For more detail see
#
# to see the error, run:
# `python lock.py`
#
# and to see the fix, run:
# `python lock.py correct`
import logging
@ckampfe
ckampfe / begin_immediate.rs
Created July 19, 2024 18:47
begin immediate support for SQLite in sqlx
use sqlx::sqlite::SqliteQueryResult;
use sqlx::{Executor, SqliteConnection};
use std::future::Future;
use std::ops::{Deref, DerefMut};
pub(crate) trait SqliteConnectionExt {
fn begin_immediate(&mut self) -> impl Future<Output = sqlx::Result<Transaction>>;
}
impl SqliteConnectionExt for SqliteConnection {
#!/usr/bin/env awk
BEGIN {
print "principal", "interest_rate", "term", "monthly_payment", "total_paid", "interest_paid"
}
NR == 1 && NF == 0 {
print "use:"
print "\tawk -f amortize"
CREATE TABLE f (id integer primary key, value text, inserted_at default current_timestamp);
INSERT INTO f VALUES(1,'{"a":1}','2022-05-16 04:24:48');
INSERT INTO f VALUES(2,'{"a":2}','2022-05-16 04:25:11');
INSERT INTO f VALUES(3,'{"a":2, "b":3}','2022-05-16 04:25:15');
INSERT INTO f VALUES(4,'{"a":2, "b":99}','2022-05-16 04:25:18');
INSERT INTO f VALUES(5,'{"a":3}','2022-05-16 04:25:32');
g = :digraph.new()
v1 = :digraph.add_vertex(g, "v1")
v2 = :digraph.add_vertex(g, "v2")
v3 = :digraph.add_vertex(g, "v3")
v4 = :digraph.add_vertex(g, "v4")
:digraph.add_edge(g, v2, v1)
:digraph.add_edge(g, v3, v2)
:digraph.add_edge(g, v4, v2)
@ckampfe
ckampfe / get_in.rs
Last active September 21, 2021 01:07
access a deeply nested enum/map combo
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
pub enum Bencode<'a> {
String(&'a [u8]),
Integer(isize),
List(Vec<Bencode<'a>>),
Dictionary(BTreeMap<&'a [u8], Bencode<'a>>),
}
#[macro_export]
macro_rules! get_in {
@ckampfe
ckampfe / example.exs
Created May 20, 2021 21:52
elixir scripting
#!/usr/bin/env elixir
Mix.install(httpoison: "~> 1.0", floki: "~> 0.30")
%_{body: body} = HTTPoison.get!("https://fastradius.com", [], follow_redirect: true)
body
|> Floki.parse_document!()
|> Floki.find("a")
|> Floki.attribute("href")
@ckampfe
ckampfe / lib.rs
Last active April 25, 2021 01:59
rust const Sieve of Eratosthenes
pub fn primes<const N: usize>() -> Vec<usize> {
let primes_array = sieve_of_eratosthenes::<N>();
std::array::IntoIter::new(primes_array)
.enumerate()
.filter_map(|(i, is_prime)| if is_prime { Some(i + 2) } else { None })
.collect()
}
pub const fn sieve_of_eratosthenes<const N: usize>() -> [bool; N] {