Skip to content

Instantly share code, notes, and snippets.

@hos
hos / locale.plugin.js
Last active March 3, 2021 17:44
Postgraphile plugin to use table_name_locale to map translated data on original. NOTE this won't work for order by, filter or similar quries.
export default function LocalePlugin (builder) {
builder.hook('GraphQLObjectType:fields:field', (field, build, ctx) => {
const { pgSql: sql, inflection, options } = build
const {
scope: { pgFieldIntrospection },
addDataGenerator
} = ctx
if (
@hos
hos / slack-msg.ts
Last active December 10, 2019 21:37
console.log(Deno.args);
@hos
hos / pg_ts_triggers.sql
Last active November 29, 2019 10:57
Find all tables that have created_at and updated_at columns, and create trigger to update timestamps automatically.
create or replace function set_timestamps()
returns trigger
as
$$
begin
NEW.created_at = (
case
when TG_OP = 'INSERT' then
NOW()
else
create or replace function app.graphql_subscription() returns trigger as
$$
declare
v_process_new bool = (TG_OP = 'INSERT' OR TG_OP = 'UPDATE');
v_process_old bool = (TG_OP = 'UPDATE' OR TG_OP = 'DELETE');
v_event text = TG_ARGV[0];
v_topic_template text = TG_ARGV[1];
v_attribute text = TG_ARGV[2];
v_record record;
v_sub text;
@hos
hos / volume-control.js
Created October 29, 2019 08:37
Control audio volume with ffmpeg
const pathExtra = require('path-extra')
const { exec } = require('child_process')
const DIRECTIONS = {
UP: 'UP',
DOWN: 'DOWN'
}
const _isInstructionClose = (before, current) => {
const isSameEndTime = before.end >= current.start
@hos
hos / bohemnots.js
Created October 28, 2019 08:30
Player for Bohemnots Radio
const trackNameUpdateInterval = 1000
const retryInterval = 500
const streamUrl = 'https://bhmnts.out.airtime.pro/bhmnts_a'
const metaUrl = 'https://bohem.herokuapp.com/metadata'
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
const audio = new Audio(streamUrl)