Skip to content

Instantly share code, notes, and snippets.

Avatar
🤗

Daniel Lobato García dLobatog

🤗
View GitHub Profile
@dLobatog
dLobatog / gist:1431933
Created Dec 5, 2011
Refactored create
View gist:1431933
# POST /issues
# POST /issues.xml
def create
@issue = Issue.new(params[:issue])
# A D D N E W C A U S E / E F F E C T
if params[:action_carrier]
# Read in the :type passed with form to recognize whether this is a Cause or Effect
@causality = params[:action_carrier].to_s
@causality_id = params[:id_carrier]
@dLobatog
dLobatog / gist:1431937
Created Dec 5, 2011
Old create method
View gist:1431937
# POST /issues
# POST /issues.xml
def create
@issue = Issue.new(params[:issue])
# A D D N E W C A U S E / E F F E C T
if params[:action_carrier]
# Read in the :type passed with form to recognize whether this is a Cause or Effect
View gist:1856734
<% people = Person.find(
:conditions => ["added_at > ? and deleted = ?", Time.now.utc, false],
:order => "last_name, first_name") %>
<% people.reject { |p| p.address.nil? }.each do |person| %>
<div id="person-<%= person.new_record? ? "new" : person.id %>">
<span class="name">
<%= person.last_name %>, <%= person.first_name %>
</span>
<span class="age">
<%= (Date.today - person.birthdate) / 365 %>
View gist:2070282
<% if user.has_image %>
<td><%= image_tag(user.img, :size => "10x10") %></td>
<% end %>
View gist:2070324
resources :your_model, :id => /[a-z0-9-]*/
View gist:2070328
def img= image
self.has_image = true
AWS::S3.new.buckets[:images_cloudstock].objects[id].write(image.read)
end
def img
AWS::S3.new.buckets[:images_cloudstock].objects[id].url_for(:read) if has_image
end
View gist:2070340
class User < AWS::Record::HashModel
string_attr :id
string_attr :name
integer_attr :age
string_attr :sex
string_attr :city
boolean_attr :has_image, :default => false
View gist:2427588
find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
@dLobatog
dLobatog / gist:2427596
Created Apr 20, 2012
find_all and cached
View gist:2427596
def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[])
cached(key, [name, prefix, partial], details, locals) do
find_templates(name, prefix, partial, details)
end
end
def cached(key, prefix, name, partial)
return yield unless key && caching?
@cached[key][prefix][name][partial] ||= yield
end
View gist:2427600
require "benchmark"
foo = "foo"
bar = "bar"
array = [foo, bar]
hash = {:a => foo, :b => bar}
nested_hash = Hash.new { |h,k| h[k] = {} }
nested_hash[foo][bar] = true