суббота, 29 августа 2009 г.

Rails Code Snippets



Hi,

In my rails application I usually copy some usefull scripts from my previous project.
May be it's very interesting for you.

def stylesheet(*args)
content_for(:header) { stylesheet_link_tag(*args.map(&:to_s)) }
end

def javascript(*args)
args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
content_for(:header) { javascript_include_tag(*args) }
end

def script(&block)
content = capture(&block)
concat("", block.binding)
end

def content_for_script(place = :header, &block)
content = capture(&block)
content_for place do
script(&block)
end
end

def google_analytics(code)
%(
script type='text/javascript'
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
var pageTracker = _gat._getTracker("#{code}");
pageTracker._trackPageview();
} catch(err){}
/script

)
end


class String
def self.random_alphanumeric(size=64)
s = ""
size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
s
end
end



See you.

пятница, 28 августа 2009 г.

sudo with default path

Not for a long time I have some troubles with running commands by sudo in Ubuntu.
I found decision and it's very simple:

# you have to add this line to ~/.bashrc

alias sudo='sudo env PATH=$PATH'

# And now it's gonna be alright.

See you.

четверг, 27 августа 2009 г.

Nginx https configuration

Now I am working in one project that was written by another developer. And in production server my website weas only working via https. It was very strange because I was searching in nginx configuration any lines such as:


location ~* ^/(orders|offers)/ {
rewrite ^/(.*)$ https://testname.com/$1 redirect;
}


but nothing to find. As you can see this sources it's only simple rewrite rule for nginx configuration. After 3 hours in my rails application I didn't find anything codes connecting with https. I read nginx docs and found one funny line that was previous developer used in nginx.conf:

proxy_set_header X-FORWARDED_PROTO https;

That's all.

вторник, 25 августа 2009 г.

Freelance Life

Not far a long time I have just started to work via internet in my free time. But It's very difficult and reading my one post doesn't make sense for understanding me.
My first work was started about 0.75 year and it's great but I didn't give money.
(http://aksent.heroku.com/). Still I was trying to sell this website for one company.