Skip to content

Instantly share code, notes, and snippets.

@pgwillia
pgwillia / benchmark.sh
Last active August 29, 2015 13:55
calculates average qtime and counts errors from a Tomcat log file
#!/bin/bash
# calculates average qtime and counts errors from a Tomcat log file ($CATALINA_HOME/logs/catalina.out)
if [ -z "$1" ] ; then
echo "requires a Tomcat log path"
exit 1
fi
grep -v "^map entry" $1 | paste - - |
awk -v start="$2" -v end="$3" 'BEGIN{
@pgwillia
pgwillia / netstat.sh
Last active August 29, 2015 13:58
Active Internet connections (servers and established) and Active UNIX domain sockets (servers and established)
netstat -ano #general for linux and windows
sudo netstat -anop #linux gets PID/Program name
netstat -anob #windows gets PID
@pgwillia
pgwillia / book.rb
Last active August 29, 2015 13:58
#projecthydra 'uninitialized constant Book::BookMetadata error' seems to be caused by change is Rails class loading
# corrected app/models/book.rb
class Book < ActiveFedora::Base
has_metadata 'descMetadata', type: Datastreams::BookMetadata
has_attributes :title, datastream: 'descMetadata', multiple: false
has_attributes :author, datastream: 'descMetadata', multiple: false
# within app/models/book.rb
has_many :pages, :property=> :is_part_of
end
@pgwillia
pgwillia / silence.sh
Created April 11, 2014 16:53
Append all stdout and stderr to file
execute_program &> /dev/null > file.log 2>&1
@pgwillia
pgwillia / simplehttpserver.sh
Created June 5, 2014 20:01
start simple http server
python -m SimpleHTTPServer
@pgwillia
pgwillia / crawl.sh
Last active August 29, 2015 14:05
crawl a site's links and report on responses in file
# --spider only do HEAD request
# --no-verbose gives minimal output (~1/4 the lines)
# -o send output to file
# -e robots=off ignores robots.txt (but you should play nice -- so don't use this)
# -w 1 waits for a second between requests
# --random-wait uses -w to vary between 0.5 and 1.5 * wait seconds
# -r recursive (this is the crawler part)
# -nd don't create a hierarchy of directories when retrieving recursively (prevent inode issues)
# -p all page requisites
@pgwillia
pgwillia / who_holds_deleted_file.sh
Last active August 29, 2015 14:06
Some suggestions if du and df don't line up. There is probably a deleted file that wasn't released by a process.
# lsof lists open files (with user and size)
sudo lsof -s | grep deleted
# files that belong to users, processes
fuser -uvcf .
@pgwillia
pgwillia / get_models.rb
Created October 24, 2014 22:42
List all the models in your Rails app from rails console. Doesn't work for 4.1.4)
def load_models_in_development
if Rails.env == "development"
load_models_for(Rails.root)
Rails.application.railties.engines.each do |r|
load_models_for(r.root)
end
end
end
def load_models_for(root)
@pgwillia
pgwillia / resque_cheatsheet.rb
Last active August 29, 2015 14:10
Resque cheatsheet
## Status
Resque.info
Resque.queues
Resque.redis
Resque.size(queue_name)
# check out what's coming next in the queue
# Resque.peek(archive_queue)
# Resque.peek(archive_queue, 1, 5)
@pgwillia
pgwillia / sufia_fedora_4.sh
Last active August 29, 2015 14:10
take Sufia for a spin
#! /bin/sh -x
yum install -y sqlite-devel
rm -Rf sufia
git clone https://github.com/projecthydra/sufia.git
cd sufia
git checkout -t origin/v6.1.0
service redis_6379 restart
rm -Rf spec/internal # removes any existing test app
bundle update
killall java # kill any running jetties