<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Bublik's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 02:19:58 GMT</pubDate>
    <description>DZone Snippets: Bublik's Code Snippets</description>
    <item>
      <title>rake task for restart rails application runed on mod_rails</title>
      <link>http://snippets.dzone.com/posts/show/5543</link>
      <description>&lt;br /&gt;&lt;code&gt;&lt;br /&gt;amespace :passenger do&lt;br /&gt;  desc "Restart Application"&lt;br /&gt;  task :restart do&lt;br /&gt;    puts `touch tmp/restart.txt`&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 27 May 2008 12:26:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5543</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>rename view files  for rails 2.0</title>
      <link>http://snippets.dzone.com/posts/show/5532</link>
      <description>save speed improve + 80% &lt;br /&gt;&lt;br /&gt;Using view.rhtml on rails 2.0&lt;br /&gt;Completed in 1.41661 (0 reqs/sec) | Rendering: 1.40170 (98%) | DB: 0.00000 (0%) | 200 OK [http://rubyclub.com.ua/]  &lt;br /&gt;&lt;br /&gt;Using view.html.erb on rails 2.0&lt;br /&gt;Completed in 0.22283 (4 reqs/sec) | Rendering: 0.21387 (95%) | DB: 0.00000 (0%) | 200 OK [http://rubyclub.com.ua/]  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace 'views' do&lt;br /&gt;  desc 'Renames all .rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder, and .haml to .html.haml'&lt;br /&gt;  task 'rename' do&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rhtml').each do |file|&lt;br /&gt;      puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rxml').each do |file|&lt;br /&gt;      puts `svn mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.rjs').each do |file|&lt;br /&gt;      puts `svn mv #{file} #{file.gsub(/\.rjs$/, '.js.rjs')}`&lt;br /&gt;    end&lt;br /&gt;    Dir.glob('app/views/**/[^_]*.haml').each do |file|&lt;br /&gt;      puts `svn mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 22 May 2008 09:34:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5532</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>create new rails rake task</title>
      <link>http://snippets.dzone.com/posts/show/5185</link>
      <description>Create new task for /unit/helpers/*_test.rb&lt;br /&gt;&lt;br /&gt;Rakefile &lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :test do&lt;br /&gt;  Rake::TestTask.new(:helpers) do |t|&lt;br /&gt;    t.libs &lt;&lt; "test"&lt;br /&gt;    t.pattern = 'test/unit/helper/*_test.rb'&lt;br /&gt;    t.verbose = true&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  Rake::Task['test:helpers'].invoke&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 28 Feb 2008 15:02:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5185</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Save db data to fixture files</title>
      <link>http://snippets.dzone.com/posts/show/4729</link>
      <description>rake db:fixtures:dump_all &lt;br /&gt;&#1086;&#1085; &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1080;&#1090; &#1074;&#1089;&#1077; &#1076;&#1072;&#1085;&#1085;&#1099;&#1077; &#1080;&#1079; &#1074;&#1072;&#1096;&#1080;&#1093; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094; development &#1073;&#1072;&#1079;&#1099; &#1074; &#1103;&#1084;&#1083;&#1099; &#1076;&#1083;&#1103; &#1090;&#1077;&#1089;&#1090;&#1086;&#1074; rake &lt;br /&gt;&lt;br /&gt;db:fixtures:dump_references &lt;br /&gt;["areas","countries"]&lt;br /&gt;&#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1080;&#1090; &#1090;&#1086;&#1083;&#1100;&#1082;&#1086; &#1090;&#1077; &#1090;&#1072;&#1073;&#1083;&#1080;&#1094;&#1099; &#1082;&#1086;&#1090;&#1086;&#1088;&#1099; &#1077;&#1087;&#1088;&#1086;&#1087;&#1080;&#1089;&#1072;&#1085;&#1099; &#1091; &#1085;&#1077;&#1075;&#1086; &#1074; &#1082;&#1086;&#1085;&#1092;&#1080;&#1075;&#1077;, &#1074; &#1076;&#1072;&#1085;&#1085;&#1086;&#1084; &#1089;&#1083;&#1091;&#1095;&#1072;&#1077; &#1101;&#1090;&#1086; &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace :db do&lt;br /&gt;  namespace :fixtures do&lt;br /&gt;&lt;br /&gt;    desc 'Create YAML test fixtures from data in an existing database.&lt;br /&gt;Defaults to development database. Set RAILS_ENV to override.'&lt;br /&gt;    task :dump_all =&gt; :environment do&lt;br /&gt;      sql = "SELECT * FROM %s"&lt;br /&gt;      skip_tables = ["schema_info"]&lt;br /&gt;      ActiveRecord::Base.establish_connection(:development)&lt;br /&gt;      (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|&lt;br /&gt;        i = "000"&lt;br /&gt;        File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|&lt;br /&gt;          data = ActiveRecord::Base.connection.select_all(sql % table_name)&lt;br /&gt;          file.write data.inject({}) { |hash, record|&lt;br /&gt;            hash["#{table_name}_#{i.succ!}"] = record&lt;br /&gt;            hash&lt;br /&gt;          }.to_yaml&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  namespace :fixtures do&lt;br /&gt;    desc 'Create YAML test fixtures for references. Defaults to development database. &lt;br /&gt;    Set RAILS_ENV to override.'&lt;br /&gt;    task :dump_references =&gt; :environment do&lt;br /&gt;      sql = "SELECT * FROM %s"&lt;br /&gt;      dump_tables = ["areas","countries"]&lt;br /&gt;      ActiveRecord::Base.establish_connection(:development)&lt;br /&gt;      dump_tables.each do |table_name|&lt;br /&gt;        i = "000"&lt;br /&gt;        file_name = "#{RAILS_ROOT}/test/fixtures/#{table_name}.yml"&lt;br /&gt;        p "Fixture save for table #{table_name} to #{file_name}"&lt;br /&gt;        File.open(file_name, 'w') do |file|&lt;br /&gt;          data = ActiveRecord::Base.connection.select_all(sql % table_name)&lt;br /&gt;          file.write data.inject({}) { |hash, record|&lt;br /&gt;            hash["#{table_name}_#{i.succ!}"] = record&lt;br /&gt;            hash&lt;br /&gt;          }.to_yaml&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 02 Nov 2007 09:30:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4729</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Customize error_messages_for</title>
      <link>http://snippets.dzone.com/posts/show/4710</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; module ActionView::Helpers::ActiveRecordHelper&lt;br /&gt;   def error_messages_for(object_name, options = {})&lt;br /&gt;    options = options.symbolize_keys&lt;br /&gt;    object = instance_variable_get("@#{object_name}")&lt;br /&gt;    if object &amp;&amp; !object.errors.empty?&lt;br /&gt;      content_tag("div",&lt;br /&gt;      content_tag(&lt;br /&gt;      options[:header_tag] || "h2",&lt;br /&gt;      "&#1042;&#1086;&#1079;&#1085;&#1080;&#1082;&#1083;&#1086; #{object.errors.count} &#1086;&#1096;&#1080;&#1073;&#1086;&#1082; &#1087;&#1088;&#1080; &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1077;&#1085;&#1080;&#1080;"&lt;br /&gt;      ) +&lt;br /&gt;      content_tag("p", "&#1055;&#1088;&#1086;&#1073;&#1083;&#1077;&#1084;&#1084;&#1099; &#1074;&#1086;&#1079;&#1085;&#1080;&#1082;&#1083;&#1080; &#1076;&#1083;&#1103; &#1089;&#1083;&#1077;&#1076;&#1091;&#1102;&#1097;&#1080;&#1093; &#1087;&#1086;&#1083;&#1077;&#1081;:") +&lt;br /&gt;      content_tag("dl", object.errors.full_messages.collect { |msg| content_tag("dt", msg) }),&lt;br /&gt;      "id" =&gt; options[:id] || "errorExplanation", "class" =&gt; options[:class] || "errorExplanation"&lt;br /&gt;      )&lt;br /&gt;    else&lt;br /&gt;      ""&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt; end&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 29 Oct 2007 08:45:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4710</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>clear  directory with svn files</title>
      <link>http://snippets.dzone.com/posts/show/4420</link>
      <description>// description of your code here&lt;br /&gt;It command line clear svn directory&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find d . -name .svn -exec rm -rf '{}' \; -print&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 14 Aug 2007 14:50:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4420</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Check email in html form</title>
      <link>http://snippets.dzone.com/posts/show/4290</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &lt;script type="text/javascript"&gt;&lt;br /&gt;        function check_email(email_id,err_id){&lt;br /&gt;            emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/;&lt;br /&gt;            var err_mail='Email addres incorect!';&lt;br /&gt;            if(emailRegExp.test(document.getElementById(email_id).value)){&lt;br /&gt;                alert('true');&lt;br /&gt;                return true;&lt;br /&gt;            }else{&lt;br /&gt;                document.getElementById(err_id).innerHTML=err_mail;&lt;br /&gt;                alert(err_mail);&lt;br /&gt;                return false;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span id="err_msg" style="color: red;"&gt;&lt;/span&gt;&lt;br /&gt;    &lt;form id="myForm" name="myForm" action="./register.php" method="post" onsubmit="return check_email('email','err_msg');"&gt;&lt;br /&gt;        &lt;input type="text" name="email" id="email"/&gt;&lt;br /&gt;        &lt;input  type="submit" name="send" value="Send" /&gt;&lt;br /&gt;    &lt;/form&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 12 Jul 2007 10:04:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4290</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Convert mail to image (guard mail) from spam</title>
      <link>http://snippets.dzone.com/posts/show/4283</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;if(empty($_GET['sid'])){&lt;br /&gt;	//write html for image&lt;br /&gt;	$mail='example@domain.com';&lt;br /&gt;    $text=base64_encode(serialize($mail));&lt;br /&gt;	echo '&lt;img src="imgmail.php?sid='.$text.'" /&gt;&lt;br/&gt;';&lt;br /&gt;}else{&lt;br /&gt;	//show coded mail image&lt;br /&gt;	$text=$_GET['sid'];&lt;br /&gt;	header("Content-type: image/gif");	&lt;br /&gt;	echo mail_to_image($text);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function mail_to_image($ctext='no mail'){&lt;br /&gt;	$text=unserialize(base64_decode($ctext));&lt;br /&gt;    $size=strlen($text)*8;&lt;br /&gt;    $im = @imagecreate($size, 20) or die("Cannot Initialize new GD image stream");&lt;br /&gt;    $background_color = imagecolorallocate($im, 255, 255, 255);&lt;br /&gt;    $text_color = imagecolorallocate($im, 0, 0, 0);&lt;br /&gt;    imagestring($im,3, 5, 5,  $text , $text_color);&lt;br /&gt;    return imagegif($im);&lt;br /&gt;}&lt;br /&gt;?&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 10 Jul 2007 08:11:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4283</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
    <item>
      <title>Pinging site </title>
      <link>http://snippets.dzone.com/posts/show/4213</link>
      <description>&#1042;&#1086;&#1090; &#1087;&#1088;&#1086;&#1089;&#1090;&#1086;&#1081; &#1087;&#1088;&#1080;&#1084;&#1077;&#1088; &#1082;&#1072;&#1082; &#1087;&#1088;&#1086;&#1087;&#1080;&#1085;&#1075;&#1086;&#1074;&#1099;&#1074;&#1072;&#1090;&#1100; &#1089;&#1072;&#1081;&#1090;&#1099; &#1087;&#1088;&#1080; &#1085;&#1086;&#1074;&#1099;&#1093; &#1087;&#1086;&#1089;&#1090;&#1072;&#1093; &#1073;&#1077;&#1079; &#1074;&#1082;&#1083;&#1102;&#1095;&#1077;&#1085;&#1080;&#1103; &#1076;&#1086;&#1087;&#1086;&#1087;&#1083;&#1085;&#1080;&#1090;&#1077;&#1083;&#1100;&#1085;&#1099;&#1093; &#1087;&#1083;&#1072;&#1075;&#1080;&#1085;&#1086;&#1074; &#1080; &#1084;&#1086;&#1076;&#1091;&#1083;&#1077;&#1081;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;irb(main):032:0&gt;&lt;br /&gt;irb(main):033:0* server = XMLRPC::Client.new("blogsearch.google.com", "/ping/RPC2", 80)&lt;br /&gt;=&gt; #&lt;XMLRPC::Client:0x2aaaaeb222e8 @create=nil, @port=80, @http=#&lt;Net::HTTP blogsearch.google.com:80 open=false&gt;, @proxy_host=nil, @http_last_response=nil, @parser=nil, @timeout=30, @path="/ping/RPC2", @password=nil, @http_header_extra=nil, @use_ssl=false, @host="blogsearch.google.com", @user=nil, @proxy_port=nil, @auth=nil, @cookie=nil&gt;&lt;br /&gt;irb(main):034:0&gt; server.call("weblogUpdates.extendedPing", 'Rubyclub.com.ua new on site','http://rubyclub.com.ua/', 'http://rubyclub.com.ua/messages/rss')&lt;br /&gt;=&gt; {"message"=&gt;"Thanks for the ping.", "flerror"=&gt;false}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 26 Jun 2007 14:17:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4213</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
  </channel>
</rss>
