Skip to content

Instantly share code, notes, and snippets.

View inem's full-sized avatar
🌰
In progress

Ivan Nemytchenko inem

🌰
In progress
View GitHub Profile
@inem
inem / gist:60711
Created February 9, 2009 08:05 — forked from pauldix/gist:57285
require 'feedzirra'
# fetching a single feed
feed = Feedzirra::Feed.fetch_and_parse("http://feeds.feedburner.com/PaulDixExplainsNothing")
# feed and entries accessors
feed.title # => "Paul Dix Explains Nothing"
feed.url # => "http://www.pauldix.net"
feed.feed_url # => "http://feeds.feedburner.com/PaulDixExplainsNothing"
feed.etag # => "GunxqnEP4NeYhrqq9TyVKTuDnh0"
#Rails 2.3 features
User.admins.first.try(:address).try(:reset)
#--------------------------------------------
render :partial => 'articles/article', :locals => { :article => @article }
#--->
render @article
#-------------------------------------------
default_scope :order => 'created_at DESC'
@inem
inem / bloat.rb
Created February 10, 2009 13:09 — forked from nakajima/bloat.rb
# Measure the amount bloat you're adding by requiring libraries.
#
# Usage:
#
# Bloat.measure do
# require 'rubygems'
# require 'activesupport'
# end
#
# A report will be printed that tells you how many methods were
You can use {TagsAsClasses} and tranform a tag in a CSS class:
A little example:
<div class="{TagsAsClasses}">....</div>
Add the tag test123 to a post and the relative output code will be:
<div class="test123">...</div>
@inem
inem / gist:93944
Created April 12, 2009 10:07
adding to_json method to ostruct
class OpenStruct
def to_json
table.to_json
end
end
o = OpenStruct.new
o.foo = "foo"
o.bar = 1
o.to_json
@inem
inem / gist:93947
Created April 12, 2009 10:19
I wish I could do something like this
class User
def fullname(first, second)
"#{this.firstname} #{first} whatever"
end
def address(options)
"#{street} #{options[:hash_key]}"
end
def smth(params)
@inem
inem / gist:93986
Created April 12, 2009 12:56
serialization.rb patch
7a8
> @methods_params_hash = {}
29a31,37
> def methods_with_params
> Array(options[:methods]).inject({}) do |method_attributes, method_array|
> method_attributes.merge!(method_array) if method_array.is_a?(Hash)
> method_attributes
> end
> end
>
class Operation < ActiveRecord::Base
def best
created_at
end
def test(b)
"*#{b}*"
end
end
=trip_points
-include
:item
:profile
:operations
-methods do
:author
current_user
:full_name
:availability_line
def calculate_params(context, method_name, params)
if params.kind_of?(Array)
context.send(method_name, *params)
elsif params.kind_of?(Hash)
context = context.send(method_name)
calculate_params(context, params.keys[0], params.values[0])
elsif params.respond_to?(:to_sym)
context.send(method_name, params)
else raise ArgumentError, "Unknown type of function params"
end