Skip to content

Instantly share code, notes, and snippets.

@exAspArk
exAspArk / prisma-context.ts
Last active December 20, 2023 16:38
Prisma Extension with Express.js HTTP Request Context
import { Request, Response, NextFunction } from "express";
import { AsyncLocalStorage } from "node:async_hooks";
import { PrismaClient } from '@prisma/client';
const ASYNC_LOCAL_STORAGE = new AsyncLocalStorage();
export const setContext = (callback: (req: Request) => any) => {
return (req: Request, _res: Response, next: NextFunction) => {
const context = callback(req);
@exAspArk
exAspArk / vim-heroku.sh
Created August 3, 2020 13:30 — forked from dvdbng/vim-heroku.sh
Run vim in heroku updated 2017
mkdir ~/vim
cd ~/vim
# Staically linked vim version compiled from https://github.com/ericpruitt/static-vim
# Compiled on Jul 20 2017
curl 'https://s3.amazonaws.com/bengoa/vim-static.tar.gz' | tar -xz
export VIMRUNTIME="$HOME/vim/runtime"
export PATH="$HOME/vim:$PATH"
cd -
@exAspArk
exAspArk / macos+ntfs.sh
Last active December 23, 2019 13:49
Mount writable NTFS disk with osxfuse + ntfs-3g
# brew install ntfs-3g
sudo mkdir /Volumes/NTFS
diskutil list
sudo ntfs-3g /dev/disk2s1 /Volumes/NTFS -olocal -oallow_other
rsync -v --progress ~/Downloads/something /Volumes/NTFS/
sudo umount /Volumes/NTFS
@exAspArk
exAspArk / processes_vs_threads.rb
Created August 24, 2017 15:46
Compare Process vs Thread creation / deletion time
# gem install benchmark-ips
require 'benchmark/ips'
Benchmark.ips do |x|
x.warmup = 0
x.report("threads") do
thread = Thread.new { puts 'thread' }
thread.join
end
defined_indexes = Model.index_specifications.map { |s| s.fields.map(&:to_s) };
existing_indexes = Model.collection.indexes.map { |i| i['key'].keys };
missing_indexes = defined_indexes - existing_indexes
# => []
extra_indexes = existing_indexes - defined_indexes - [['_id']]
# => []
#################################################################################
@exAspArk
exAspArk / curl.sh
Last active April 26, 2023 08:43
Test CORS with cURL
curl -I -X OPTIONS \
-H "Origin: http://EXAMPLE.COM" \
-H 'Access-Control-Request-Method: GET' \
http://EXAMPLE.COM/SOMETHING 2>&1 | grep 'Access-Control-Allow-Origin'
@exAspArk
exAspArk / self-signed-ssl-mongo.sh
Last active April 6, 2024 19:38
Self-signed SSL Certificate with OpenSSL on MacOS | MongoDB
openssl genrsa -out CAroot.key 2048
openssl req -new -key CAroot.key -out CAroot.csr # CN should be different from the certificates below
openssl req -x509 -days 1825 -key CAroot.key -in CAroot.csr -out CAroot.crt
cat CAroot.crt CAroot.key > CAroot.pem
openssl genrsa -out mongod.key 2048
openssl req -new -key mongod.key -out mongod.csr
openssl x509 -req -days 1825 -in mongod.csr -CA CAroot.pem -CAkey CAroot.key -CAcreateserial -out mongod.crt
cat mongod.crt mongod.key > mongod.pem
@exAspArk
exAspArk / web-servers.md
Created May 16, 2017 16:36 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@exAspArk
exAspArk / gpg-import-and-export-instructions.md
Last active October 14, 2023 03:04 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@exAspArk
exAspArk / ansible_vault_merge.sh
Last active March 4, 2021 22:21 — forked from benzado/vault-merge.sh
A shell script for merging encrypted Ansible vault files in a git repository
#!/bin/sh
###############################################################################
# USAGE:
# > ansible_vault_merge.sh [-p PASSWORD_FILE VAULT_YAML_FILE
# This shell script handles conflicts generated by attempts to merge encrypted
# Ansible Vault files. Run this command to attempt a merge on the unencrypted
# versions of the file. If there are conflicts, you will be given a chance to