Skip to content

Instantly share code, notes, and snippets.

View stephenprater's full-sized avatar

Prater stephenprater

View GitHub Profile
x = lambda do |*args|
row, col = *({ :row => nil, :col => nil}.merge(args.first).values rescue args)
end
x.call(4,2) => [4,2]
x.call(row:4, col:2) => [4,2]
x.call(row:4) => [4,nil]
x.call(4) => [4,nil]
x.call(col:2) => [nil,2]
class DebugMachineCache
remove_const :COMMANDS rescue nil#TODO remove this
# assemble format strings for movement commands
movmts = Hash[[:hpa,:vpa,:cup,:home,:setaf].zip(
[`tput hpa`, `tput vpa`, `tput cup`,`tput home`,`tput setaf`].collect do |fmt|
fmt.split(/(%[pPg][\d\w])|(%.)/).each_with_object '' do |i,m|
if i == '%d'
m << '%d'
module BlackMagick
def keys &block
define_method :keys, &block
end
end
class LeThing
extend BlackMagick
end
has_many :user_favorite_markets
:class_name => "UserFavoriteMarket",
:foreign_key => :user_id
has_many :favorite_markets,
:class_name => "FarmersMarket",
:through => :user_favorite_markets
:source => :market
# I think this is the general idea. You have to have an association for the join table as well.
class Factory
class << self
def new_thing name
klass = Class.new(self) do
attr_accessor :name
define_method :initialize do
@name = name
end
end
const_name = name.camelize.intern
module Thing
module Constants
BOO = 2
end
module Methods
extend ActiveSupport::Concern
include Constants
module InstanceMethods
$('#particles > .particle').draggable({
containment: '#mainpage',
helper: 'clone',
appendTo : '#mainpage',
zIndex: 1000,
start: function(){ $(this).toggle(); },
stop: function(){ $(this).toggle(); }
});
@stephenprater
stephenprater / gist:1134427
Created August 9, 2011 15:54
appending logger
function! s:Logger.put(string) dict
if g:ruby_debugger_debug_mode
let string = 'Vim plugin, ' . strftime("%H:%M:%S") . ': ' . a:string
execute('set verbosefile=' . g:RubyDebugger.logger.file)
silent verbose echo substitute(string,'/^\s*/','',"")
execute('set verbosefile=""')
endif
endfunction
<div id="main_image" class="<%= content_for :image_width -%>">
<a href="<%= @product.image_file.downcase %>" rel="popup">
<%= render :layout => false do %>
<% options, itag = medium_image :id => "primary" -%>
<% content_for :image_width do
options[:width] > 362 ? "wide_image" : "narrow_image"
end %>
<%= itag %>
<% end -%>
</a>
class ChangeMenuCategoryToBoolean < ActiveRecord::Migration
def self.up
change_column :categories, :menu_category, :boolean, :default => false
end
def self.down
change_column :categories, :menu_category, :integer
end
end