Skip to content

Instantly share code, notes, and snippets.

@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)
@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
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 / 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
@hos
hos / slack-msg.ts
Last active December 10, 2019 21:37
console.log(Deno.args);
@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 / sequelize-to-graphile-migrate.js
Last active January 31, 2020 18:43
Script to create schema.sql from sequelize sync logs. This will only help with getting started there must be some other changes to do manually for using with graphile-migrate.
import fs from 'fs'
export function getLogger (path) {
const stream = fs.createWriteStream(path)
process.on('beforeExit', () => stream.close())
return msg => {
const _ = msg + ''
if (!/ select /i.test(_)) {
#!/usr/bin/env sh
set -e
export TEST_SQL="select user || ' connection to ' || (select current_database()) || ' ✅'"
### GET CONNECTION DETAILS AND TEST IT
echo "First please provide superuser credentials and endpoint"
@hos
hos / remove-by-node-id-lodash.ts
Last active February 23, 2021 16:22
Postgraphile plugin to remove all mutation containing ByNodeId
import { omitBy } from "lodash";
import { Plugin } from "postgraphile";
export const RemoveByNodeIdPlugin: Plugin = (builder) => {
builder.hook("GraphQLObjectType:fields", (fields, _) => {
return omitBy(fields, (_, key) => key.endsWith?.("ByNodeId"));
});
};
export default RemoveByNodeIdPlugin;
// RECOMMENDED: Disconnect HEROKU from Github before doing this (though not strictly necessary, I think).
//See https://stackoverflow.com/a/61272173/6569950 for more info.
// PARAMETERS
const TOKEN = ""; // MUST BE `repo_deployments` authorized
const REPO = ""; // e.g. "repository"
const USER_OR_ORG = ""; // e.g. "your-name"
// GLOBAL VARS
const URL = `https://api.github.com/repos/${USER_OR_ORG}/${REPO}/deployments`;