Skip to content

Instantly share code, notes, and snippets.

View scottweisman's full-sized avatar

Scott Weisman scottweisman

View GitHub Profile
# Gemfile
source 'http://rubygems.org'
gem 'rails'
group :test do
gem 'capybara'
gem 'launchy'
end
@henkm
henkm / gist:952240
Created May 2, 2011 19:55
Add new items via JQuery TokenInput / Ruby on Rails
#model (idea 100% stolen from ryanb)
def author_tokens=(ids)
ids.gsub!(/CREATE_(.+?)_END/) do
Author.create!(:name => $1).id
end
self.author_ids = ids.split(",")
end
# jquery.tokeninput.js
@ahamid
ahamid / ImageUploader
Created May 27, 2011 16:51
CarrierWave mixed content upload processing
require 'carrierwave/processing/mini_magick'
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
IMAGE_EXTENSIONS = %w(jpg jpeg gif png)
DOCUMENT_EXTENSIONS = %w(exe pdf doc docm xls)
def store_dir
"files/#{model.id}"
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@RandomEtc
RandomEtc / 1-make-key
Created September 16, 2011 16:35
generating SSL keys and Certificate Signing Requests for Heroku / Nginx / RapidSSL
Key was generated using:
tom% openssl genrsa -des3 -out example.com.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
..........................................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for example.com.key:
Verifying - Enter pass phrase for example.com.key:
%tom
@potomak
potomak / _flash.html.erb
Created January 12, 2012 14:35
Rails flash messages using Twitter bootstrap
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
@twosixcode
twosixcode / gist:1988097
Created March 6, 2012 18:40
Make "Paste and Indent" the default paste in Sublime Text 2
// swap the keybindings for paste and paste_and_indent
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" }
@trevorturk
trevorturk / current.rb
Created May 7, 2012 20:27 — forked from scottweisman/current.rb
Using current_kase method in views
# concerns#current
module Current
extend ActiveSupport::Concern
...
def current_kase
@current_kase ||= Kase.find_by_id(params[:kase_id])
end
# To include methods in views
@andynu
andynu / generate_glyphicons_pro_css.rb
Created May 14, 2012 15:28
Generate css for Glyphicons Pro.
#!/usr/bin/env ruby
#
# Generate css for the pro glyphicons.
# Run this script in the glyphicons_pro/glyphicons/png folder
# from the purchased zip file.
#
# see http://glyphicons.com/ for purchase/license information.
#
render = (ARGV.include? "--html") ? :html : :css
@JeffCohen
JeffCohen / gist:2782207
Created May 24, 2012 15:22
Vending Machine Fun
# Try adding the ability to keep track of capacity per brand
# And push the buttons until the entire machine is empty
class VendingMachine
# attr_accessor :money
def initialize(number_of_cans)
@cans = []
number_of_cans.times do
@cans << 'Coke'