Skip to content

Instantly share code, notes, and snippets.

@little-brother
little-brother / odd.c
Created April 26, 2021 12:29
SQLite scalar function with context example
void odd (sqlite3_context *ctx, int argc, sqlite3_value **argv){
int *pCounter = (int*)sqlite3_get_auxdata(ctx, 0);
if (pCounter == 0) {
pCounter = sqlite3_malloc(sizeof(*pCounter));
if (pCounter == 0)
return sqlite3_result_error_nomem(ctx);
*pCounter = sqlite3_value_type(argv[0]) == SQLITE_NULL ? 0 : sqlite3_value_int(argv[0]);
sqlite3_set_auxdata(ctx, 0, pCounter, sqlite3_free);
} else {
@little-brother
little-brother / square.c
Created April 26, 2021 12:18
SQLite scalar function example
static void square (sqlite3_context *ctx, int argc, sqlite3_value **argv) {
int type = sqlite3_value_type(argv[0]);
double d = sqlite3_value_double(argv[0]);
switch (type) {
case SQLITE_NULL:
sqlite3_result_null(ctx);
break;
case SQLITE_INTEGER:
@little-brother
little-brother / index.html
Created August 1, 2020 20:46
How to use nunjucks in the browser/client-side
<!doctype html>
<html>
<head>
<meta charset = "UTF-8"/>
<title>Nunjucks example</title>
<script type = "module" src = "index.js"></script>
</head>
<body>
<div id = "page-content"></div>
</body>