Skip to content

Instantly share code, notes, and snippets.

@aheld
aheld / query as app_user
Created February 12, 2024 16:16
Row level security example
begin;
set local jwt.sub = '[email protected]';
show jwt.sub;
select listing_id, listing_name, listing_desc from farmers_markets_pa;
-- allowed to update
update farmers_markets_pa set listing_desc = 'updated @ ' || current_time where listing_id = 301498 returning listing_id;
-- not allowed to update
update farmers_markets_pa set listing_desc = 'updated @ ' || current_time where listing_id = 300430 returning listing_id;
select listing_id, listing_name, listing_desc from farmers_markets_pa;
@aheld
aheld / azsub
Created September 8, 2023 13:47
Azure subscription selector using fuzzy finder fzf
azsub() {
az account set --subscription $(az account list --all --query '[].[id, name]' --out tsv | fzf | awk '{print $1}')
}
@aheld
aheld / starship.toml
Last active July 7, 2023 19:13
Startship config for mac ~/.config/starship.toml https://starship.rs/
# Get editor completions based on the config schema
"$schema" = 'https://starship.rs/config-schema.json'
palette = 'osx'
format = """
[](bold green)\
$os\
$username\
$directory\
const { EventHubProducerClient } = require("@azure/event-hubs")
const { chunkPromise, PromiseFlavor } = require('chunk-promise')
var now = require("performance-now")
var sp = require('streaming-percentiles')
var epsilon = 0.1;
var g = new sp.GK(epsilon);
const TestCases = require("../events/test_cases.js")
const impression = TestCases[0].expected.outputClientImpressionMessage[0]
@aheld
aheld / batcher.js
Created April 14, 2022 17:08
simple demo to batch promises as opposed to promise.all
job = (input, batchNumber) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Running batch ',batchNumber, 'processing ', input)
resolve('completed ' + input)
}, 1000)
})
}
async function batcher(inputArray, fn, batchSize) {
@aheld
aheld / updateSproc.js
Last active January 17, 2022 18:34
companion to tutorial on aaronheld.com
/** some examples for using and testing sprocs
Needs the key in the env var: export cosmos_key="q2Mk.....
npm i -s @azure/cosmos
npm i -s uuid
runHello will create a simple sproc, update it to the collection, and then test it
runSprocCase will create a sproc that does a server-side update for atomic updates, pushes it to the collection, tests it
@aheld
aheld / githublink
Last active August 17, 2021 13:03
bash function to open the github url for a given file
const assert = require('assert')
function makeDeposits (deposits) {
return 0
}
const deposits = [0, 100, 100, 100]
const expected = 300
const balance = makeDeposits(deposits)
@aheld
aheld / catCodeReplace.js
Created October 29, 2018 12:56
Given a csv file with a column called "Category IDs" add a column called 'Category Names' with the name based on a lookup and write it out
const csv = require('csv')
const fs = require('fs')
const path = require('path')
const devnull = require('dev-null')
const catData = require('./catData')
const inputs = ['Members_49827_14.csv', 'Contacts Combined-3-Files.csv']
inputs.forEach(processCSV)
#!/bin/bash
REGION="us-east-1"
PROFILE="prod"
get_ecl_ip(){
aws ec2 describe-instances \
--profile $PROFILE \
--filters Name=tag:Name,Values=enrollecl \
--query "Reservations[].Instances[].PrivateIpAddress" \