Skip to content

Instantly share code, notes, and snippets.

View stevebartholomew's full-sized avatar

Stephen Bartholomew stevebartholomew

View GitHub Profile
@stevebartholomew
stevebartholomew / gist:50180
Created January 21, 2009 20:52
Simple database backup rake task for Rails using mysqldump
namespace :backup do
desc "Backup database"
task :db do
RAILS_ENV = "development" if !defined?(RAILS_ENV)
app_root = File.join(File.dirname(__FILE__), "..", "..")
settings = YAML.load(File.read(File.join(app_root, "config", "database.yml")))[RAILS_ENV]
output_file = File.join(app_root, "..", "backup", "#{settings['database']}-#{Time.now.strftime('%Y%M%d')}.sql")
system("/usr/bin/env mysqldump -u #{settings['username']} -p#{settings['password']} #{settings['database']} > #{output_file}")
namespace :db do
desc "Reset database and load seed data"
task :seed do
Rake::Task["db:migrate:reset"].invoke
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
Dir.glob(File.join(RAILS_ROOT, 'db', 'seed', '*.{yml,csv}')).each do |fixture_file|
Fixtures.create_fixtures('db/seed', File.basename(fixture_file, '.*'))
end
cd ~/Desktop
wget http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip
unzip selenium-remote-control-1.0.1-dist.zip
echo 'Copying in latest selenium'
sudo cp selenium-remote-control-1.0.1/selenium-server-1.0.1/selenium-server.jar /usr/local/lib/ruby/gems/1.8/gems/Selenium-1.1.14/lib/selenium/openqa/selenium-server.jar.txt
echo 'Removing dirs'
/*
** Template.templates.customer_address = "<div class='address'>${name}, ${line1}, ${postcode}</div>"
**
** var address = jQuery.parseJSON('{"name": "Steve", "line1": test}')
** Template.render("customer_address", address)
**
*/
var Template = {
templates : {},
cd my-project
git clone --bare . ../my-project.git
scp -r ../my-project.git user@server:/path/to/git-repositories/
git remote add origin user@server:/path/to/git-repositories/my-project.git
# then you can do:
git push
git pull
etc etc
@stevebartholomew
stevebartholomew / Postgis Test DB Preparation.rb
Created January 4, 2011 12:38
Override Rails's test prepare db task to source in postgis data
namespace :db do
namespace :test do
task :prepare_postgis do
`/usr/local/pgsql/bin/psql dbname -f /usr/local/pgsql-9.0/share/contrib/postgis-1.5/postgis.sql -U postgres`
`/usr/local/pgsql/bin/psql dbname -f /usr/local/pgsql-9.0/share/contrib/postgis-1.5/spatial_ref_sys.sql -U postgres`
end
end
end
Rake::Task["db:test:prepare"].enhance do
@stevebartholomew
stevebartholomew / js_test.rake
Created February 22, 2011 11:30
Quick & Dirty JS test runner
# Quick and dirty JS test runner
#
# Required files:
# {testdir}
# /index.html (rails specific sample below)
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
# "http://www.w3.org/TR/html4/loose.dtd">
# <html>
# <head>
# <link rel="stylesheet" href="<%= JS_TEST_BASE %>/qunit.css" type="text/css" media="screen" />
@stevebartholomew
stevebartholomew / gist:1033077
Created June 18, 2011 12:59
Excluding all but specified files in git
*
!y.php
!x.php
!folder_xy
@stevebartholomew
stevebartholomew / gist:1639128
Created January 19, 2012 09:56
time a block of ruby code
# Example:
# rendered_content = t("rendering layout") do
# layout.render('item' => self, 'contents' => contents)
# end
#
def t(title, &block)
puts "==========="
puts title
beginning_time = Time.now
result = yield
@stevebartholomew
stevebartholomew / gist:1feab9d6fa5128f618c4
Last active June 27, 2020 20:45
Ruby refactoring exercise
class Array
def to_annotated_xml(root)
output = "<#{root}>"
each do |i|
if i.is_a?(Fixnum)
output << "<number>#{i}</number>"
elsif i.is_a?(String)
if i.match(/@/)
output << "<email>#{i}</email>"