Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env elixir
Mix.install([{:cas, git: "https://github.com/ckampfe/cas"}])
defmodule M do
alias Cas.Atom
def main_cas do
atom = Atom.new(1)
(ns ckampfe.protocol
(:require [clojure.java.io :as io]))
(defrecord BulkString [s])
(defrecord SimpleError [s])
(defmacro as-byte [s]
`(byte (first ~s)))
(declare decode)
defmodule SpecTest do
require Integer
use ExUnit.Case
doctest Spec
test "valid?/2" do
assert Spec.valid?(&Integer.is_even/1, 2)
refute Spec.valid?(&Integer.is_even/1, 1)
assert Spec.valid?(MapSet.new([1, 2, 3]), 1)
refute Spec.valid?(MapSet.new([1, 2, 3]), 9)
<?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)