This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def move_to_s3 | |
temp_path = attachment.path | |
temp_file = attachment.to_file # Paperclips way of getting a File object for the attachment | |
# Save it as a regular attachment | |
# this will save to S3 | |
s3_upload = Upload.find(id) # Same db record but we need the S3 version | |
s3_upload.attachment = temp_file # reset the file - it will assume its a new file | |
s3_upload.save! # Paperclip will upload the file on save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
class Attachment | |
class UploadedPath | |
attr_reader :original_filename, :content_type, :size, :path | |
def initialize(uploaded_file) | |
@original_filename = uploaded_file["name"].downcase | |
@content_type = uploaded_file["content_type"].to_s.strip | |
@file_size = uploaded_file["size"].to_i | |
@path = uploaded_file["path"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? $recentPosts = new WP_Query(); | |
$recentPosts->query('offset=1&showposts=5'.'&limit='.$how_many); | |
?> | |
<div class="box"> | |
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> | |
<div class="latest_news latest_news span-12 last append-bottom"> | |
<div class="tiny_box"> | |
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3> | |
<? if (has_post_thumbnail()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# environment.rb | |
config.gem 'mongo_mapper' | |
#initializers/mongo.rb | |
begin YAML.load_file("#{RAILS_ROOT}/config/mongo_config.yml") | |
MONGOCONNECTION = YAML.load_file("#{RAILS_ROOT}/config/mongo_config.yml")[RAILS_ENV] | |
rescue => e | |
puts "WARNING! loading config file mongo_config.yml , #{e}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin YAML.load_file("#{:config}/mongo_config.yml") | |
MONGOCONNECTION = YAML.load_file("#{:config}/mongo_config.yml")[ENV['RACK_ENV']] | |
rescue => e | |
puts "WARNING! loading config file mongo_config.yml , #{e}" | |
end | |
MongoMapper.connection = Mongo::Connection.new(MONGOCONNECTION['ip']) | |
MongoMapper.database = MONGOCONNECTION['db'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: mongodb | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the mongodb data-store | |
# Description: starts mongodb using start-stop-daemon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get install erlang-nox | |
# Get the latest .egg file for your version of python ("python -V"), then run it: # this is only for phyton < 2.6 | |
wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg | |
sh setuptools-0.6c9-py2.5.egg | |
easy_install simplejson | |
cd /root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
One other cause is your :dependent callbacks. | |
class Blog < AR::Base | |
has_many :posts, :dependent => :destroy | |
end | |
This will iterate through every post and call #destroy on it. Use :delete_all if you want to just issue a single delete query. HOWEVER, this won't hit your destroy callbacks on Post. | |
class Blog < AR::Base | |
has_many :posts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app name | |
app_name = @root.split('/').last | |
if yes?("Drop databases?") | |
run "mysqladmin -u root -p drop #{app_name}_development -f" | |
run "mysqladmin -u root -p drop #{app_name}_test -f" | |
run "mysqladmin -u root -p drop #{app_name}_production -f" | |
end | |
if yes?("Create databases?") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WordTruncateHelper | |
def word_truncate(text, *args) | |
options = args.extract_options! | |
unless args.empty? | |
options[:size] = args[0] || 75 | |
options[:omission] = args[1] || "..." | |
end | |
options.reverse_merge!(:size => 75, :omission => "...") | |
text.scan(/(\S+)(\s+)/)[0..options[:size]].flatten.join << options[:omission] if text |