Skip to content

Instantly share code, notes, and snippets.

# Parse out 404's and count them with `head`
grep '" 404' website.apachestyle.log* | cut -d'"' -f2 | sort | uniq -c | sort -nr | head
# Remove `head` to get all results
grep '" 404' website.apachestyle.log* | cut -d'"' -f2 | sort | uniq -c | sort -nr
@joelvh
joelvh / .bash_profile
Last active January 14, 2020 21:04
Install Mac software updates, apps and Homebrew dependencies via command line script
### iTerm ###
# See https://www.iterm2.com/3.3/documentation-scripting-fundamentals.html
function iterm2_print_user_vars() {
iterm2_set_user_var phpVersion $(php -v | awk '/^PHP/ { print $2 }')
iterm2_set_user_var rubyVersion $(ruby -v | awk '{ print $2 }')
iterm2_set_user_var nodeVersion $(node -v)
}
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
@joelvh
joelvh / db.rake
Last active March 18, 2023 12:04 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# Original source: https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
# Merged with: https://gist.github.com/kofronpi/37130f5ed670465b1fe2d170f754f8c6
namespace :db do
desc 'Dumps the database to backups'
task dump: :environment do
dump_fmt = ensure_format(ENV['format'])
dump_sfx = suffix_for_format(dump_fmt)
backup_dir = backup_directory(Rails.env, create: true)
full_path = nil
cmd = nil
#!/bin/bash
# This was used for a Rails app with PostgreSQL database on Heroku.
# It uses the DATABASE_URL as the source and destination.
#
# Usage:
#
# 1) Specify the SRC_APP, DEST_APP and THREADS variables in this script.
# 2) Run: `sh heroku_db_sync_prod_to_staging.sh`
#
@joelvh
joelvh / time_in_time_zone.rb
Created October 10, 2013 18:57
Parse time in time zone in Rails
# parse date/time in detected time zone
time_zone_name = params[:time_zone]
time_zone = ActiveSupport::TimeZone.new(time_zone_name || Time.zone.name)
time_string = "#{params[:date]} #{params[:time]}"
time_in_time_zone = time_zone.parse time_string
@joelvh
joelvh / membership.rb
Last active December 14, 2015 12:39
Generating methods that update an instance or multiple database records the same way
class Membership
###### SCOPES ######
scope :active, where(:is_active => true)
scope :not_active, where{is_active != true}
scope :removed, where(:is_active => false, :unsubscribed_at => nil)
scope :unsubscribed, where{(is_active == false) & (unsubscribed_at != nil)}
scope :admin, active.where(:is_admin => true)
@joelvh
joelvh / email_previews.rb
Last active December 11, 2015 23:58
Easily preview email templates in your browser by adding a route for MailView email previews in your Rails app using this helper class. You can specify which mailers and which email templates to use, as well as what sample data to use.
### CUSTOM CLASS WITH MAILERS TO PREVIEW ###
class EmailPreviews < MailerPreview::Engine
mailer NotificationMailer do
# specify a block that returns the arguments used for this mailer
preview(:new_follower) { User.last }
# make sure I didn't miss any email templates for this mailer
assert_full_coverage!
end
@joelvh
joelvh / flow.json
Created June 3, 2012 17:12
Untitled_0
{
"nodes": [
{
"title": "Postmark Outbound",
"icon": "images/icons/postmark_64.png",
"top": 93,
"left": 357,
"compID": "postmark_send",
"from": "no-reply@elastic.io",
"id": "step_129"
@joelvh
joelvh / main.rb
Created November 5, 2010 03:48 — forked from waynehoover/main.rb
require 'rubygems'
require 'sinatra'
require 'active_support/core_ext'
require "base64"
get '/upload' do
bucket = 'bucket name here'
access_key_id = 'access key id here'
secret_access_key = 'Enter secret access key here'