Skip to content

Instantly share code, notes, and snippets.

View bkenny's full-sized avatar
💭
Shipping Products

Brian Kenny bkenny

💭
Shipping Products
View GitHub Profile
@bkenny
bkenny / events.rb
Created December 20, 2010 13:43
Events
def index
@events = Event.all
@events_by_month = Event.find(:all).group_by { |event| event.eventdate.strftime("%B") }
# The answer
@events_by_month = Event.find(:all, :conditions => "live = true").group_by { |event| event.eventdate.strftime("%B") }
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @events }
end
end
@bkenny
bkenny / gist:764744
Created January 4, 2011 13:09
Ordering
@artworks = Artwork.find(:all, :include => :artist, order => "artists.last_name, title")
font:normal normal normal 13px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif;
hda: status error: status=0x58 { DriveReady SeekComplete DataRequest }
hda: status error: error=0x00
hda: drive not ready for command
hda: status error: status=0xd8 { Busy }
hda: status error: error=0x00
hda: drive not ready for command
def show
@event = Event.find(params[:id])
if @event.hits.nil?
@event.hits = 0
else
@event.hits = @event.hits + 1
end
@event.save
respond_to do |format|
@bkenny
bkenny / mysql-backup-script
Created June 1, 2011 10:43
MySQL Backup Script
#!/bin/bash
BACKUP="/backups/db"
DATE=`date +"%Y-%m-%d"`
WEEKAGO=`date --date='week ago' +"%Y-%m-%d"`
DAY=`date +"%a"`
XWEEKSAGO=`date --date='5 weeks ago' +"%Y-%m-%d"`
# Day on which the weekly backup is kept. Should be the 3 char abbreviation
WEEKLY="Sun";
@bkenny
bkenny / gist:1028979
Created June 16, 2011 10:01
Grab last 7 days of load notifications from Hybodus
-- Grab the last 7 days of load notifications
select from_unixtime(notification_history.dts), server.servername, notification_history.message
from server, service, notification_history
where service.server_id = server.server_id
and notification_history.service_id = service.service_id
and notification_history.message like '%Load%'
and from_unixtime(notification_history.dts) >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
order by server.servername desc;
@bkenny
bkenny / Pi-Calc
Created June 29, 2011 10:36
Calculate Pi on a Mac to 5000 places
time echo "scale=5000; 4*a(1)" | bc -l -q
@bkenny
bkenny / ssh-key-port-finder.sh
Created July 12, 2011 09:33
SSH Key Port Scanning
#/bin/sh
# Script to check if port 22 (SSH) is open within the range, secondly if our SSH key is accepted by that server.
# Insert your SSH Key here
KEYPUB="/link/root/.ssh/file";
RANGES="0.0.0.0/0 1.1.1.1/1"
for i in `nmap -sT -n -p 22 -P0 -oG - $RANGES | grep open | awk '{print $2}'`
do
@bkenny
bkenny / Shorten.rb
Created July 19, 2011 21:13
Shorten
require 'rubygems'
require 'yourls'
# For each URL provided in the argument list
# run through it and shorten it.
ARGV.each do|a|
# Create a new Yourls instance with the shortener URL and API key.
yourls = Yourls.new('http://bkenn.me', your_api_key_here)
# Pass it the argument/url provided from the command line to shorten.
tiny = yourls.shorten("#{a}")