Skip to content

Instantly share code, notes, and snippets.

View noahsw's full-sized avatar

Noah S-W noahsw

  • Product, Axon
  • Seattle
View GitHub Profile
@noahsw
noahsw / logger.rb
Created January 3, 2015 22:08
Log4r logger initializer that auto-reloads config and subscribes to Rails notifications
# Uncomment these lines to debug Log4r
# trouble = Log4r::Logger.new('log4r')
# trouble.add Log4r::Outputter.stdout
# assign log4r's logger as rails' logger.
log4r_config = YAML.load_file(File.join(File.dirname(__FILE__), "..", "log4r_#{Rails.env}.yml"))
log_cfg = Log4r::YamlConfigurator
log_cfg["ENV"] = Rails.env
log_cfg["HOST"] = `hostname`.to_s.gsub(/\n$/, "")
log_cfg["APPNAME"] = Rails.application.class.parent_name
@noahsw
noahsw / gist:9bc71582c59cfe224007
Last active August 29, 2015 14:08 — forked from bkimble/gist:1365005
Rake task to list non-expired memcache keys
namespace :memcached do
desc "List valid keys that haven't expired"
task list_valid_keys: [:environment] do
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
# overload so we don't have to worry about unmarshaling
module Marshal
@noahsw
noahsw / backup_mysql
Last active December 28, 2015 09:19
Backup mysql database with individual files per table, all gzipped together at the end.
#!/bin/bash
username="root"
password="root"
mysql="/Applications/MAMP/Library/bin/mysql"
mysqldump="/Applications/MAMP/Library/bin/mysqldump"
date=`date +%Y-%m-%d_%H-%M-%S`
output_folder="$HOME/Projects/mysql_backup"
show_databases="$mysql -u $username -p$password -e 'show databases'"
@noahsw
noahsw / awesome_print.rb
Last active December 23, 2015 21:19 — forked from dougc84/awesome_print.rb
This is a revised gist that allows you to safely leave your awesome_print and awesome_inspect calls in production.
# The following snippet handles any calls to ap or awesome_print hanging out in your code,
# which can be particularly troublesome in a production environment where awesome_print isn't
# included in your Gemfile.
# If you have any inline "ap" or "awesome_print" calls, they will be aliased to
# puts (not using the alias method, that wasn't optimal). The output will also be logged at
# info level (feel free to change this depending on your needs) with the calling file and
# line number so you can find the offending calls.
# You can grep through your log files for "[ AP called from " to find any calls to ap.