Skip to content

Instantly share code, notes, and snippets.

View euge's full-sized avatar

Eugene Gimelberg euge

  • SecureDocs
  • Santa Barbara
View GitHub Profile
module Decorator
def decorate(decorator_name, &block)
(class << self; self; end).class_eval do
define_method(decorator_name) do |method_name_to_decorate|
with_feature = "#{method_name_to_decorate}_with_#{decorator_name}"
without_feature = "#{method_name_to_decorate}_without_#{decorator_name}"
define_method with_feature do
# call decorator code passing argument of a proc that will call original method
#!/usr/bin/env ruby
#
# Assignment block tidier, version 0.1.
#
# Copyright Chris Poirier 2006.
# Licensed under the Academic Free License version 3.0.
#
# This script can be used as a command for TextMate to align all
# of the equal signs within a block of text. When using it with
# TextMate, set the command input to "Selected Text" or "Document",
sadasdasd
@euge
euge / content_tag.html.erb
Created December 28, 2011 04:16
content_tag performance
<% if params[:slow].present? %>
<% 100.times do %>
<% content_tag :div do %>
Something here!!
<% end -%>
<% end -%>
<% else %>
<% 100.times do %>
<%= content_tag :div, "Something here!!" %>
<% end -%>

If one was inclined to use the acts_as_yaffle pattern, they would probably use the second one, rather than the heavily cargo-culted first one.

.DS_Store
*.log
@euge
euge / snippet.rb
Created June 4, 2010 05:27
mysql locking
=begin
FOR UPDATE
- no one else can SELECT ... FOR UPDATE the row
- no one else can update/delete the row
LOCK IN SHARE MODE
- others may SELECT ... LOCK IN SHARE MODE
- no one else can update/delete the row
=end
require 'rubygems'
@euge
euge / IE8 opacity
Created May 29, 2010 00:13
IE8 Opacity
16. Fix opacity on IE8
view source
print?
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
Internet Explorer 8 is a bit peculiar when it comes to support CSS opacity. It still doesn’t support the ‘opacity’ property like any other browser, but also breaks support for ‘filter: alpha(opacity=XX)’, which worked fine in IE6 and IE7. To work around this, insert above meta element in the HEAD section of the HTML.
(from http://mir.aculo.us/2010/04/30/build-a-flash-like-game-with-scripty2/)
@euge
euge / url_dsl.rb
Created December 24, 2009 04:21 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json