Skip to content

Instantly share code, notes, and snippets.

View JeffCohen's full-sized avatar

Jeff Cohen JeffCohen

View GitHub Profile
@JeffCohen
JeffCohen / no_pipeline.markdown
Created September 1, 2011 16:19
Notes on how to turn off the Rails 3.1 asset pipeline

This is a draft. I'm still learning, so this information could be completely wrong.

Avoiding the Asset Pipeline

Option 1. Avoiding it in Production Only

  1. Disable assets in production.rb
  2. Create public/stylesheets and public/javascripts folders, and put your css and js files there
  3. Modify application.html.erb to reference your own files instead of the generated "application.css" and "application.js"
  4. (Optional) Specify the --no-assets option when using the scaffold and controller generators
@JeffCohen
JeffCohen / gist:1998347
Created March 8, 2012 03:14
Fun with array mapping
class Array
def method_missing(m, *args)
map_elements(m, args) || super
end
def map_elements(m, *args)
target_method = singular_of(m)
new_array = map do |element|
if element.respond_to?(target_method)
@JeffCohen
JeffCohen / gist:2029246
Created March 13, 2012 14:51
Some code for this sample
def show
slug_id = CGI.escape(params[:id])
@list = List.find_by_slug(slug_id)
@aha = Aha.new
@aha.list = @list
respond_to do |format|
format.html # show.html.erb
format.json { render json: @list }
@JeffCohen
JeffCohen / gist:2333139
Created April 8, 2012 00:33
Some Sample Code
def something
puts "Hello"
end
@JeffCohen
JeffCohen / sample.rb
Created May 11, 2012 16:09
Fun with Ruby classes
# Open up a Rails app that has at least one model
# Create a file named config/initializers/sample.rb
# Paste this code into it
# Open up your console
# Try to figure out how to call these methods
# Try to figure out how they work
class ActiveRecord::Base
def self.sample
@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'
@JeffCohen
JeffCohen / gist:2790389
Created May 25, 2012 20:26
Vending Machine Script
# Vending Project
# Task 1 - Write a vending machine script that will dispence cokes until inventory is 0.
# Task 2 - Try adding the ability to keep track of capacity per brand
class VendingMachine
def initialize(total_inventory)
@coke, @sprite, @root_beer = [total_inventory/3,total_inventory/3,total_inventory/3]
@money = 0
@total_inventory = total_inventory * 50
@JeffCohen
JeffCohen / gist:2881991
Created June 6, 2012 13:54
JS for today
<html>
<head>
</head>
<body>
<script>
function sayWeather() {
alert('It is very nice outside, what are you doing coding in here?');
var e = document.getElementById("jeff");
// e.style.color = "red";
e.style.display = "none";
@JeffCohen
JeffCohen / gist:2888727
Created June 7, 2012 13:12
Some JS for Thursday
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/redmond/jquery-ui.css" type="text/css" media="screen">
<script>
$(function() {
$("#message").datepicker();
$("a").on('click', function() {
@JeffCohen
JeffCohen / gist:2925061
Created June 13, 2012 16:21
Dynamic Ruby
# s = "Can't believe Los Angeles won the Stanley Cup"
#
# a = ["downcase", "reverse", "upcase"]
#
# a.each do |m|
# puts s.send(m)
# end
class Team
def method_missing(m, *args)