Skip to content

Instantly share code, notes, and snippets.

@daz
daz / backup.sh
Created Apr 26, 2010
My Ubuntu web server rsync backup scripts
View backup.sh
#!/bin/sh
user="mysqluser"
pass="mysqlpass"
dir="/tmp/backup"
for i in /var/lib/mysql/*/; do
dbname=`basename $i`
if [ $dbname != "mysql" ]; then
mysqldump -u$user -p$pass $dbname > $dir/db/$dbname.sql
@daz
daz / Mellow Black.terminal
Created May 6, 2010
Mellow Black OS X Terminal theme. Save this file as "Mellow Black.terminal" and open it, then set it to default if you like it. Screenshot http://imgur.com/alhUa.png
View Mellow Black.terminal
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OViRjbGFzc1xOU0NvbG9yU3BhY2VVTlNSR0KAAhAB
TxARMCAwIDAgMC44OTk5OTk5OADSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
View Rakefile
ssh_user = "user@domain.com" # for rsync deployment
remote_root = "~/path/to/remote/" # for rsync deployment
namespace :styles do
desc "Clear styles"
task :clear do
puts "*** Clearing styles ***"
system "rm -Rfv css/*"
end
desc "Generate styles"
@daz
daz / f1-results.rb
Created May 30, 2010
Formula 1 results scraper using Mechanize
View f1-results.rb
# Gets race and quali info from f1.com and returns an array table with Position, Driver, Team, Time/Retired, Laps
#
# Eg
# [
# ["1", "Jenson Button", "McLaren-Mercedes", "1:34:09.565", "58"],
# ["2", "Sebastian Vettel", "Red Bull Racing-Renault", "+2.1 secs", "58"],
# ["3", "Lewis Hamilton", "McLaren-Mercedes", "+4.0 secs", "58"],
# ...
require 'rubygems'
@daz
daz / skype_status.rb
Created Dec 16, 2010
Skype status checker for Ruby
View skype_status.rb
# Check Skype status. You need to enable 'Show my status on the web' in Skype prefs
#
# skype = SkypeStatus.new('some.username')
# skype.online?
# => true
require 'net/http'
require 'uri'
class SkypeStatus
@daz
daz / gist:818065
Last active Sep 24, 2015
Google Analytics Rails helper
View gist:818065
# <%= google_analytics 'UA-XXXXXX-XX' %>
# </body>
# application_helper.rb
module ApplicationHelper
def google_analytics(id)
content_tag :script, :type => 'text/javascript' do
"var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{id}']);
View gist:879260
status = "Text message you don't want from Telstra when you're overseas: YOU HAVE USED 60MB ON INTERNATIONAL ROAMING AT A COST OF UP TO $15.00 PER MB... Oooops :("
status.length.to_f / 1024 / 1024 * 15 * 100
=> 0.217437744140625
View 3.1.0.rc1.html
<form accept-charset="UTF-8" action="/suppliers/6/products/38" class="edit_product" data-remote="true" id="edit_product_38" method="post" name="edit_product_38">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&acirc;&oelig;&ldquo;"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="K5dKVuoTllzbCT5uJkWuHAoUsayE4Z5irFjXcuP2dME=">
</div>
<p><label for="product_name">Name</label> <input id="product_name" name="product[name]" size="30" type="text" value="Bacon Streaky Precooked"></p>
<p><label for="product_item_number">Item number</label> <input id="product_item_number" name="product[item_number]" size="30" type="text" value="40656"></p>
<p><label for="product_carton_quantity">Carton quantity</label> <input id="product_carton_quantity" name="product[carton_quantity]" size="30" type="text" value="4x1kg"></p>
<p><label for="product_uom">UOM</label> <input id="product_uom" name="product[uom]" si
@daz
daz / gist:1136395
Created Aug 10, 2011
Using Ruby to schedule jobs with UNIX `at` command
View gist:1136395
time = Time.now + 60
queue_command = <<-CMD
at -t #{time.strftime('%Y%m%d%H%M')} <<-AT
echo "ran at #{time}" > output.txt
CMD
system queue_command
@daz
daz / php-cgi.rb
Created Sep 24, 2011 — forked from ambethia/php-cgi.rb
Homebrew Formula for PHP 5.2.17 as php-cgi (for nginx, etc.)
View php-cgi.rb
# Homebrew Formula for PHP 5.2.17 as php-cgi (for nginx, etc.)
require 'formula'
class PhpCgi <Formula
@url='http://www.php.net/get/php-5.2.17.tar.bz2/from/a/mirror'
@version='5.2.17'
@homepage='http://php.net/'
@md5='575551f5df56b9311e932b3a098c2e7a'