Skip to content

Instantly share code, notes, and snippets.

View michelson's full-sized avatar
🏠
Working from home

Miguel Michelson Martinez michelson

🏠
Working from home
View GitHub Profile
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
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"]
<? $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()) {
# 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
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']
#! /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
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
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
# 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?")
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