Skip to content

Instantly share code, notes, and snippets.

View aalfson's full-sized avatar
💭

Aaron Alfson aalfson

💭
View GitHub Profile
@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2024 18:30
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@david-torres
david-torres / db_exists.js
Last active July 7, 2023 16:26
[mongo db_exists command] MongoDB command to check if a database exists. I use it with a puppet script to conditionally load up a database dump if one isn't detected. Useful for provisioning Vagrant. Returns with exit code zero if the database was found. #mongodb
function db_exists(db_name) {
db = db.getSiblingDB('admin');
db.runCommand('listDatabases').databases.forEach(function(db_entry){
if (db_entry.name == db_name) {
// quit with exit code zero if we found our db
quit(0);
}
});
// quit with exit code 1 if db was not found
upstream myapp {
server unix:///myapp/tmp/puma.sock;
}
server {
listen 80;
server_name myapp.com;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in