Skip to content

Instantly share code, notes, and snippets.

View pahaz's full-sized avatar
🛠️
Yo ho ho

Pavel White pahaz

🛠️
Yo ho ho
View GitHub Profile
@pahaz
pahaz / ssh_tunnel_test.py
Created October 31, 2020 12:42
ssh_tunnel_test.py
import logging
import threading
import time
import sshtunnel
from sshtunnel import HandlerSSHTunnelForwarderError, SSHTunnelForwarder
sshtunnel.DEFAULT_LOGLEVEL = 1
logging.basicConfig(filename='example.log', filemode='w', level=sshtunnel.DEFAULT_LOGLEVEL)
logging.warning('Start example! v %s', sshtunnel.__version__)
@pahaz
pahaz / async-local-storage-context-example.js
Last active October 16, 2024 19:38
How to use node.js async thread local context for HTTP and GraphQL
const { AsyncLocalStorage } = require('node:async_hooks')
const get = require('lodash/get')
const httpStorage = new AsyncLocalStorage()
const gqlStorage = new AsyncLocalStorage()
const KEY = Symbol('_context')
// RESOLVERS //
async function resolveAllUsers (context, path) {
@pahaz
pahaz / gptquery.js
Last active November 20, 2024 16:40
// NOTE: based on python version: https://gist.github.com/pahaz/17c66fd6d75b74ff307aca2b6bf942f3
const crypto = require('crypto')
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch') // Import fetch from node-fetch
const DEFAULT_OUTPUT_DIR = 'out'
const GPT_KEY_FILE = path.resolve(process.env.HOME, '.openai.key')
const GPT_CACHE_DIR = path.resolve(process.env.HOME, '.openai.cache')