Skip to content

Instantly share code, notes, and snippets.

@D3xx73r
D3xx73r / admin_bootstrap.rake
Last active August 29, 2015 13:58
Rake task to bootstrap admins in a Rails app
# With bash:
# $rake admin:bootstrap[email,first_name,last_name,password]
# With ZSH
# $rake 'admin:bootstrap[email,first_name,last_name,password]'
# or
# $rake admin:bootstrap\[email,first_name,last_name,password\]
namespace :admin do
desc "Add first admin user"
@D3xx73r
D3xx73r / nginx_canvas
Created December 31, 2013 00:32
Configure canvas lms with Nginx
#Nginx configuration file for Canvas LMS
server {
listen 80;
server_name canvas.yourserver.com files.canvas.yourserver.com;
root /path/to/public;
rails_env production; #optionaly specify the rails environment
location / {
rewrite ^(.*)$ https://$http_host$request_uri redirect;
}
@D3xx73r
D3xx73r / WIP: Rails fast deploys(Soon to be a gem)
Created October 11, 2013 01:47
Deployment using Rails + Git + Bash
#Set the rails environment
export RAILS_ENV=environment
#If app directory is present
if [ -d /some/app/directory ]; then
cd /some/app/directory
#Fetch latest changes from origin and update our local branch
git fetch origin
git reset --hard origin/master
load 'deploy/assets'
namespace :deploy do
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, :except => { :no_release => true } do
%x{bundle exec rake assets:precompile}
%x{rsync --recursive --times --rsh=ssh --compress --human-readable --progress public/assets #{user}@#{host}:#{shared_path}}
%x{bundle exec rake assets:clean}
end
@D3xx73r
D3xx73r / restart_torquebox
Created August 13, 2012 16:46
Restart torquebox server
#!/bin/sh
torquebox undeploy
torquebox deploy
torquebox run
@D3xx73r
D3xx73r / uploader.rb
Created June 30, 2012 20:50
Process a thumb version of the image
# This should go in your uploader
version :thumb do
process resize_to_fit: [50, 50]
end
@D3xx73r
D3xx73r / text_field.html.erb
Created June 30, 2012 20:48
text field sample
<%= f.text_field :image %>
@D3xx73r
D3xx73r / replacement_form.html.erb
Created June 30, 2012 20:46
replacement for image upload form
<%= form_for @image, html: { multipart: true } do |f| %>
@D3xx73r
D3xx73r / image_upload.html.erb
Created June 30, 2012 20:46
Image upload form
<%= form_for(@image) do |f| %>
@D3xx73r
D3xx73r / complete_model.rb
Created June 30, 2012 19:36
Complete code for mounted uploader
class Image < ActiveRecord::Base
attr_accessible :description, :image, :title
mount_uploader :image, ImagesUploader
end