Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Galvez galvez

View GitHub Profile
View Regarding fastify-request-context.md

I see this snippet:

app.addHook('onRequest', (req, reply, done) => {
  // overwrite the defaults
  req.requestContext.set('user', { id: 'helloUser' });
  done();
});

// this should now get `helloUser` instead of the default `system`
View fastify-issue.txt
```
RangeError: Maximum call stack size exceeded
at exit (/usr/src/app/node_modules/fastify/lib/hooks.js:77:17)
at next (/usr/src/app/node_modules/fastify/lib/hooks.js:93:9)
at hookRunnerApplication (/usr/src/app/node_modules/fastify/lib/hooks.js:75:3)
at next (/usr/src/app/node_modules/fastify/lib/hooks.js:105:7)
at exit (/usr/src/app/node_modules/fastify/lib/hooks.js:82:5)
at next (/usr/src/app/node_modules/fastify/lib/hooks.js:93:9)
at hookRunnerApplication (/usr/src/app/node_modules/fastify/lib/hooks.js:75:3)
at next (/usr/src/app/node_modules/fastify/lib/hooks.js:105:7)
@galvez
galvez / 2010-10-02-14-00-test-migration.py
Created Oct 2, 2010
A minimalist Python migration management script based on Fabric and sqlwitch
View 2010-10-02-14-00-test-migration.py
# 2010-10-02 14h00
# Update created field in user_prefs table
def migrate(db):
with db.select('user_id, created', from_='users'):
all_users = db.fetchall()
for user in all_users:
with db.update('user_prefs') as obj:
obj.created = user['created']
db.where('user_id = %s', user['user_id'])
View white-rose.py
#!/usr/bin/python
from time import sleep
from pygame import mixer
mixer.init()
# Download file from https://freesound.org/people/Koyber/sounds/160483/
mixer.music.load('white-rose.mp3')
mixer.music.play()
View apistore.js
// APIStoreProps are properties that need to be
// ignored when running APIStore.makeStore()
const APIStoreProps = ['use', 'classes', 'constructor', 'init', 'state']
// getMethods returns methods defined
// in a given class' prototype, except init and constructor
const getMethods = (cls) => {
return Object.getOwnPropertyNames(cls.prototype)
.reduce((obj, prop) => {
View pool.js
import os from 'os'
import consola from 'consola'
// Usage:
//
// const handler = (file) => console.log(file)
// const pool = new PromisePool(['file1', 'file2', ...], handler)
// await pool.done()
const failureInterval = 3000
View timing.client.js
import Vue from 'vue'
function componentInject(key, setter) {
const installKey = `__component_inject_${key}`
if (Vue[installKey]) {
return
}
Vue[installKey] = true
const componentKey = `$${key}`
const privateKey = `_${key}`
View BlobImage.vue
<template>
<img ref="img" />
</template>
<script>
export default {
props: ['src'],
data: () => ({ blob: null }),
beforeMount () {
this.$watch('src', this.loadImage)
View module-utils.js
export class ModuleUtils {
static mixin(target) {
for (const member of Object.getOwnPropertyNames(ModuleUtils.prototype)) {
target[member] = ModuleUtils.prototype[member].bind(target)
}
}
resolvePath(...args) {
return resolve(process.cwd(), ...args)
}
View wrapAt.js
function wrapAt (str, max) {
if (str.length > max) {
const parts = str.split(' ')
let i = 0
for (let w = 0; i < parts.length; i++) {
w += parts[i].length
if (w >= max) {
parts[i] = `\n${parts[i]}`
w = 0
}
You can’t perform that action at this time.