Skip to content

Instantly share code, notes, and snippets.

@daffl
daffl / readme.tpl.ts
Created January 21, 2024 23:15
Getting started with Pinion
import {
PinionContext,
toFile,
renderTemplate,
prompt
} from '@featherscloud/pinion'
interface Context extends PinionContext {
name: string
}
@daffl
daffl / myservice.ts
Last active January 18, 2022 05:59
New Feathers service hooks TypeScript decorator example
import { hooks, NextFunction } from '@feathersjs/hooks'
import { authenticate } from '@feathersjs/authentication'
import { HookContext } from './declarations'
const logRuntime = async (context: HookContext, next: NextFunction) => {
const start = Date.now()
// Pass to the next hooks in the chain and the service method
await next()
// Log the total runtime
@daffl
daffl / schema.ts
Last active January 16, 2022 19:32
Feathers schema example
import { schema, Infer } from '@feathersjs/schema'
export const userSchema = schema({
$id: 'User',
type: 'object',
additionalProperties: false,
required: ['email', 'password'],
properties: {
id: { type: 'number' },
email: { type: 'string' },
@daffl
daffl / tap.py
Created December 12, 2021 06:08
TapSDK MIDI mapper
from logging import NullHandler
from tapsdk import TapSDK, TapInputMode
from tapsdk.models import AirGestures
import time
import rtmidi
import asyncio
midiout = rtmidi.MidiOut()
available_ports = midiout.get_ports()
@daffl
daffl / authentication.js
Last active February 9, 2024 15:35
Multi client oAuth redirect
const querystring = require('qs');
class MultiClientOauth extends OAuthStrategy {
async getRedirect (data, params) {
const redirectUrl = (params && params.redirect) || '/';
const { redirect } = this.authentication.configuration.oauth;
if (!redirect) {
return null;
}
@daffl
daffl / client.js
Created October 5, 2020 01:03
Initializing feathers-batch on the client
// If your module loader supports the `browser` package.json field
import { batchClient } from 'feathers-batch';
// Alternatively
import { batchClient } from 'feathers-batch/client';
const client = feathers();
// configure Feathers client here
// `batchClient` should be configured *after*
// any other application level hooks
@daffl
daffl / index.js
Last active October 5, 2020 00:47
Using the feathers-batch service in a generated application
// Add to src/services/index.js
const { BatchService } = require('feathers-batch');
module.exports = function (app) {
// ...
app.use('/batch', new BatchService(app));
}
@daffl
daffl / queue.js
Last active August 5, 2020 22:35
Bull queue example for adding a chat message every 2 seconds
const Queue = require('bull');
const app = require('./app');
const redisUrl = 'redis://localhost:6379';
const messageQueue = new Queue('add-message', redisUrl, {
defaultJobOptions: {
removeOnComplete: true
}
});
@daffl
daffl / op.js
Created May 13, 2020 18:19
Using the 1Password CLI in NodeJS
const runOp = args => {
const cmd = 'op';
const proc = spawn(cmd, args, {
stdio: [
'inherit',
'pipe',
'inherit'
]
});
@daffl
daffl / package.json
Created April 14, 2020 18:30
GitHub action that updates all dependencies once a week
{
"scripts": {
"update-dependencies": "ncu -u"
},
"devDependencies": {
"npm-check-updates": "^4.1.2"
}
}