Skip to content

Instantly share code, notes, and snippets.

View gwenn's full-sized avatar
💭
I may be slow to respond.

gwenn gwenn

💭
I may be slow to respond.
View GitHub Profile
@gwenn
gwenn / Cargo.toml
Last active July 5, 2023 17:40
Generate bindgen_bundled_version_ext.rs
[package]
name = "sqlite-ext"
version = "0.1.0"
edition = "2021"
[dependencies]
bindgen = { version = "0.66", default-features = false, features = ["runtime"] }
quote = { version = "1", default-features = false }
syn = { version = "2.0", features = ["full", "extra-traits", "visit-mut"] }
regex = { version = "1.8", default-features = false, features = ["std"] }
@gwenn
gwenn / sqlite3_api_routines.rs
Last active July 3, 2023 17:08
sqlite3_api_routines
#![feature(c_variadic)]
use atomic::{Atomic, Ordering};
#[allow(non_camel_case_types)]
pub struct sqlite3_api_routines {
pub db_config: ::std::option::Option<
unsafe extern "C" fn(
//arg1: *mut sqlite3,
arg2: ::std::os::raw::c_int,
...
@gwenn
gwenn / busy.c
Last active November 15, 2022 18:10
SQLITE_BUSY
#include <stdlib.h>
#include <stdio.h>
#include "sqlite3.h"
sqlite3 *open(const char *path) {
fprintf(stdout, "opening %s\n", path);
sqlite3 *db = NULL;
int rc = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL);
if (db == NULL || SQLITE_OK != rc) {
fprintf(stderr, "Error opening %s: %d, %s\n", path, rc, sqlite3_errmsg(db));
@gwenn
gwenn / LockedFiles.java
Created December 5, 2020 13:10
LockedFiles
public class LockedFiles {
/**
* Like {@link java.nio.file.Files#write(Path, byte[], OpenOption...)} but with a lock
*/
public static void write(Path path, byte[] bytes) throws IOException {
if (bytes == null) {
return;
}
log.debug("Writing {}", path);
try (FileChannel chan = FileChannel.open(path, TRUNCATE_EXISTING, WRITE, CREATE, DSYNC);
@gwenn
gwenn / Result.txt
Last active December 17, 2017 08:18
Find inconsistencies between the intel intrinsics XML file and the Rust code
name;cpuid;Intel;Rust;Clang
_mm256_and_pd;AVX;vandpd;vandps;
_mm256_andnot_pd;AVX;vandnpd;vandnps;
_mm256_cmp_pd;AVX;vcmppd;vcmpeqpd;@llvm.x86.avx.cmp.pd.256
_mm256_cmp_ps;AVX;vcmpps;vcmpeqps;@llvm.x86.avx.cmp.ps.256
_mm256_load_pd;AVX;vmovapd;vmovaps;
_mm256_load_si256;AVX;vmovdqa;vmovaps;
_mm256_loadu_pd;AVX;vmovupd;vmovups;
_mm256_loadu_si256;AVX;vmovdqu;vmovups;
_mm256_or_pd;AVX;vorpd;vorps;
@gwenn
gwenn / scanner.rs
Created September 5, 2017 20:09
Bypass Rust borrow checker with a transmute
#![feature(read_initializer)]
use std::fs::File;
use std::io::{self, BufRead, Read};
// Like a `BufReader` but with a growable buffer.
#[derive(Debug)]
struct Scanner<R: Read> {
inner: R,
buf: Vec<u8>,
@gwenn
gwenn / go-sqlite3_database_is_locked.go
Last active July 19, 2019 12:46 — forked from mrnugget/go-sqlite3_database_is_locked.go
Program that tests the concurrency issues with go-sqlite3. This will create two tables: `products` and `users`. One goroutine will repeatedly read from the `products` table in N fresh goroutines. At the same time ONE goroutine writes to the other table.
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"sync"
"time"