Skip to content

Instantly share code, notes, and snippets.

ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR =
"#{ActionView::Helpers::AssetTagHelper::ASSETS_DIR}/javascriptx"
ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR =
"#{ActionView::Helpers::AssetTagHelper::ASSETS_DIR}/stylesheetx"
def self.make_zip_io
cmd = "sh -c 'cd /somewhere && zip -r - stuff'"
IO.popen(cmd)
end
def zip
io = self.class.make_zip_io
send_data(io.read, :filename => 'filename.zip', :type => 'application/zip')
end
# modifications from standard capistrano deploy as taken from:
# http://devthatweb.com/view/deploy-any-project-using-capistrano-2
set :application, "name removed"
set :repository, "url to trunk of repo"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/var/www/#{application}"
sql = 'a big honking sql statement'
conditions = conditions_for_doodad
order = "#{params[:order_by]} #{params[:order]}"
Doodad.send(:add_conditions!, sql, conditions)
Doodad.send(:add_order!, sql, order)
@rs = ActiveRecord::Base.connection.select_all(sql)
# Returns hierarchical data structure rooted at this node. When converting to
# json make sure to remove :parent to avoid circular reference:
# message.full_hierarchy.to_json(:only => [:id, :subject, :children, ...])
def full_hierarchy
the_full_set = full_set
ancestry = [build_node(the_full_set.shift)]
while !the_full_set.empty?
next_node = build_node(the_full_set.shift)
while next_node[:level] <= ancestry.last[:level]
ancestry.pop
class Message < ActiveRecord::Base
acts_as_nested_set :scope => 'discussable_id = #{discussable_id} AND discussable_type = \'#{discussable_type}\''
belongs_to :discussable, :polymorphic => true
# ...
end
class Foo < ActiveRecord::Base
mysqldump -u user_name -p database_name > dump.sql
cat dump.sql | mysql -u user_name -p database_name
ssh some.server 'mysqldump -u user_name -p remote_database_name' | mysql -u user_name -p local_database_name
#!/usr/bin/env bash
if [ $# -eq 2 ]; then
user=$1
dbname=$2
basecmd="mysql -u ${user} -D ${dbname}"
elif [ $# -eq 3 ]; then
user=$1
PASS=$2
dbname=$3