Skip to content

Instantly share code, notes, and snippets.

View bruth's full-sized avatar

Byron Ruth bruth

View GitHub Profile
@bruth
bruth / README.md
Last active April 12, 2024 05:02
SQLite update hook example in Go

SQLite Update Hook Example

This is an example usage of registering an update_hook to a SQLite connection. The motivation for exploring this feature is to test out various implementations of data monitoring interfaces.

A few notable properties of the implementation:

  • The hook must be registered on the connection being used which requires clients to manually integrate this code.
  • Each INSERT and UPDATE operation requires a subsequent SELECT to get the row data.
  • When registering the hook, increasing the bufsize under heavy workloads will improve throughput, but the SQLite library is single-threaded by design.
@bruth
bruth / invoc_test.go
Created October 17, 2017 19:36
Method invocation benchmarks
package main
import (
"reflect"
"testing"
)
type myint int64
type Inccer interface {

NATS-RPC Generator

go generate command for creating a client interface, CLI, and serve function for a service interface.

Usage

//go:generate nats-rpc -type=Service -client=client.go -cli=./cmd/cli/main.go
package main
@bruth
bruth / django_autoload_registry.py
Created January 13, 2013 15:56
Registry class that follows a common pattern in Django for autoloading specific modules for a given purpose, e.g. `models.py` and `admin.py`. One such use case enables registering instances or classes and making them available in the admin to associate with some data.
import inspect
from django.conf import settings
from django.utils.importlib import import_module
from django.core.exceptions import ImproperlyConfigured
class AlreadyRegistered(Exception):
pass
@bruth
bruth / README.md
Created July 31, 2013 13:16
Django command that gives a set of subcommands a namespace. For example, a command named after an app can be defined with a set of subcommands, e.g. `python manage.py command subcommand`.

Subcommander

Managment commands are assumed to be unique across all apps in a Django project. This can lead to long or obscure command names in attempt to namespace those commands.

Subcommander acts as a proxy command giving the real commands a namespace. The subcommander module can be named after the app name or some derivation. The structure looks as follows:

myapp/
    management/
        commands/
@bruth
bruth / etag_modified_model.py
Created March 8, 2012 15:10
ETag "ready" Django model using a modified datetime
from datetime import datetime
from django.db import models
from django.core.cache import cache
class ModifiedModel(models.Model):
modified = models.DateTimeField()
class Meta(object):
abstract = True
@bruth
bruth / README.md
Last active November 23, 2022 21:54
Postgres push notification

Postgres push triggers

Watch a table for changes and push a notification with a payload describing the change.

Example

In the Postgres shell:

-- Create the functions
@bruth
bruth / shipitjournal.md
Last active October 16, 2021 19:43
Markdown version of Seth Godin's ShipIt Journal. Fork it. Complete it. Ship it.

Markdown version of Seth Godin's ShipIt Journal

Project:

Ship Date:

You may have already figured out these reasons for not shipping:

  • You might not know enough...
  • You might not see clearly enough...
@bruth
bruth / add-docker-user.sh
Last active January 27, 2021 17:37
Setup Official Docker Repo on RHEL 7
#!/bin/bash
/usr/sbin/usermod -aG docker <user>
@bruth
bruth / README.md
Created April 27, 2012 00:51
sortedGroupBy using Underscore

sortedGroupBy

jsFiddle Example

Convenience function for performing a groupBy on a list then a sortBy on the resulting groups using Underscore methods.

sortedGroupBy(list, groupByIterator, sortByIterator)