Skip to content

Instantly share code, notes, and snippets.

@kylemclaren
kylemclaren / findLongRunningOp.js
Last active April 9, 2024 20:10 — forked from comerford/killLongRunningOps.js
Find and (safely) kill long running MongoDB ops
db.currentOp().inprog.forEach(
function(op) {
if(op.secs_running > 5) printjson(op);
}
)
@kylemclaren
kylemclaren / run.sh
Created October 18, 2023 10:42
whisperX web API on Fly GPUs
#! /bin/bash
export APP_NAME=yourAppName
fly apps create $APP_NAME
fly vol create -s 50 --vm-gpu-kind a100-pcie-40gb -r ord data -y -a $APP_NAME
# Uncomment for access outside Fly private network
# fly ips allocate-v4 --shared -a $APP_NAME
@kylemclaren
kylemclaren / user-data.sh
Created January 21, 2022 09:32 — forked from codeinthehole/user-data.sh
Get the value of an EC2 instance's tag
#!/usr/bin/env bash
#
# Get the value of a tag for a running EC2 instance.
#
# This can be useful within bootstrapping scripts ("user-data").
#
# Note the EC3 instance needs to have an IAM role that lets it read tags. The policy
# JSON for this looks like:
#
# {
@kylemclaren
kylemclaren / har_instructions.md
Created January 19, 2022 16:17 — forked from legrego/har_instructions.md
Kibana HAR Instructions

A HAR archive of the network timings from a compatible browser is extremely useful in pinpointing which issues with Kibana talking to Elasticsearch.

Note on information gathered in a HAR archive

Please note that HAR archives contain sensitive information:

  • content of the pages you downloaded while recording
  • your cookies, which will allow anyone with the HAR file to impersonate your account
  • all the information that you submitted to your browser while recording (i.e., search values, authentication details).
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
// I wanted to know the top five largest collections in my MongoDB database in
// terms of document count. This MongoDB-specific JavaScript gets the job done.
//
// Edit variables in the config section, then execute like so:
//
// mongo --quiet topCollections.js
// config
var dbname = 'FIXME';
@kylemclaren
kylemclaren / terminate_all_ec2.sh
Created November 19, 2020 22:55 — forked from rjurney/terminate_all_ec2.sh
Bash script to disable termination protection and then terminate all instances in all regions :)
for region in `aws ec2 describe-regions | jq -r .Regions[].RegionName`
do
echo "Terminating region $region..."
aws ec2 describe-instances --region $region | \
jq -r .Reservations[].Instances[].InstanceId | \
xargs -L 1 -I {} aws ec2 modify-instance-attribute \
--region $region \
--no-disable-api-termination \
--instance-id {}
aws ec2 describe-instances --region $region | \
🗣 Commented on #1 in kylemclaren/hello-github-actions
❗️ Opened issue #1 in kylemclaren/hello-github-actions
@kylemclaren
kylemclaren / twilio-validation.js
Created April 21, 2020 08:35
Twilio CF Worker request validation
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
});
/* WARNING:
Anything starting with REPLACEABLE_SECRET_VDB12_ shouldn't be renamed,
because they are used in deployment transformations.
Do not remove the comment below,
it is required to timestamp workers on upload.
Sent from npm.
@kylemclaren
kylemclaren / mongodb-find-duplicate-field-values.js
Created March 31, 2020 16:27
mongodb find duplicate field values
m = function () {
emit(this.my_field, 1);
}
r = function (k, vals) {
return Array.sum(vals);
}
res = db.MyCollection.mapReduce(m,r, { out : "my_output" });
db[res.result].find({value: {$gt: 1}});