Skip to content

Instantly share code, notes, and snippets.

View fritzy's full-sized avatar
💽
Please Insert Disk III

Nathan Fritz fritzy

💽
Please Insert Disk III
  • Kennewick, WA
  • 01:00 (UTC -07:00)
  • X @fritzy
View GitHub Profile
@fritzy
fritzy / 1_triggers.sql
Last active April 7, 2024 20:07
Get table change notifications from Postgres as JSON
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$
DECLARE
id bigint;
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
id = NEW.id;
ELSE
id = OLD.id;
END IF;
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text);
@fritzy
fritzy / issues.sh
Last active March 2, 2023 21:06
Get random issues of a given labels from a repo
#!/bin/bash
# Usage: issues [label/p0-2] [limit] [pool_size]
# requires gh (github cli)
POOL_SIZE=${3:-50}
LIMIT=${2:-5}
LABEL=${1:-"Needs Triage"}
REPO="https://github.com/npm/cli"
if [[ $LABEL = "triage" ]];
then
@fritzy
fritzy / spinner.js
Last active July 18, 2022 11:03
Use Mutation Observers to place image placeholders (spinners) on loading images within a target element.
//whenever uncached images are added to the dom tree within target,
//replace them with a spinner gif until they're loaded
function replaceImages(target, spinner_src) {
var spinner, observer;
//detect support
if (window.MutationObserver) {
//preload spinner (probably a gif)
//if it's not ready for first use, oh well
spinner = new Image();
@fritzy
fritzy / getmsgpackasjson.lua
Created November 6, 2013 17:35
Redis scripts to set JSON in, store as MSGPack, and get JSON out.
--EVAL 'this script' 1 some-key
local key = KEYS[1];
local value = redis.call('GET', key);
local jvalue = cjson.encode(cmsgpack.unpack(value));
return jvalue;
@fritzy
fritzy / json_pagination.sql
Last active November 27, 2020 11:22
Getting JSON paginated results of a table SELECT
SELECT json_build_object(
'total', (SELECT n_live_tup FROM pg_stat_user_tables WHERE relname='sometable'),
'count', count(sometable_rows.*),
'offset', 0,
'results', json_agg(row_to_json(sometable_rows))
)
FROM (SELECT * FROM sometable
ORDER BY "time"
LIMIT 10 OFFSET 0)
sometable_rows;
@fritzy
fritzy / pixi_sprite_apeecs.js
Created August 7, 2020 21:47
ApeECS Example of Managing Sprites from Pixi.js
const ApeECS = require('ApeECS');
const Pixi = require('pixi.js');
const world = new ApeECS.World();
class Sprite extends ApeECS.Component {
static properties = {
x: 0,
y: 0,
layer: '',
texturePath: '',
let tick = 0;
class BasicObject {
constructor() {
this.x = 0;
this.y = 0;
this.updated = 0;
}
}
// This file was initially generated by Windows Terminal Dev 0.0.1.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@fritzy
fritzy / component.js
Last active April 18, 2019 03:42
Abusing Object.defineProperty and Object.getPrototypeOf to make a nice interface for ECS Components.
class BaseComponent {
constructor(ecs, initialValues) {
Object.defineProperty(this, 'ecs', { enumerable: false, value: ecs });
Object.defineProperty(this, 'type', { enumerable: false, value: this.constructor.name });
Object.defineProperty(this, '_values', { enumerable: false, value: {} });
Object.defineProperty(this, 'id', { enumerable: true, value: componentId });
this.lastTick = this.ecs.ticks;
componentId++;
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
namespace LoginImpersonate
{
internal class Impersonation : IDisposable
{