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
# Link to local copy of edge rails
# inside('vendor') { run 'ln -s ~/dev/rails/rails rails' }
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
#run "rm -f public/javascripts/*"
# This is a trivial HTTP proxy server, intended for use as a troubleshooting tool
# ONLY (not for real, actual, production use). I wrote this because I couldn't find
# a simple HTTP proxy that I could use to test HTTP proxy support in Net::SSH.
#
# This code is in the public domain, so do with it what you will!
require 'socket'
server = TCPServer.new('127.0.0.1', 8080)
client = server.accept
#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 / 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"
@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