tag:blogger.com,1999:blog-58388222092154200212024-03-13T07:53:24.922-07:00NeptunePhoenixUnknownnoreply@blogger.comBlogger9125tag:blogger.com,1999:blog-5838822209215420021.post-55728317958745271812010-09-28T06:39:00.000-07:002010-09-28T07:28:26.291-07:00Rails respond_to and IE File Download Security WarningAs discussed in my earlier post, I am working on a WEB API integration project involving Radiant. This is a public facing website and requires full support of Internet Explorer. So far, IE has proved to be a great pain. I have got an IFRAME rendering pages from another web application. Now, this application had a controller code with respond_to block.<br /><pre class='ruby' name='code'><br />def method_name<br /> #some RUBY code<br /> respond_to do |format|<br /> format.js {#render some JSON}<br /> format.html {#redirect to somewhere}<br /> end<br />end<br /></pre><br />Now, everything seemed to be working good on FireFox and Chrome. Next was the turn of IE. As expected, MORE PROBLEMS.....!! It didn't work!!! It started showing File Download Security Warning Dialog. I had no clue what it was doing. I was totally stumped. Finally, after a bit of googling I came across this <a href="http://agilerails.wordpress.com/2009/05/27/ie-throws-file-download-security-warning-on-form-submit/">post</a>. It saved my day. <br /><br />As mentioned in the post, I tried printing the <span style="font-weight:bold; color: rgb(255, 0, 0);">request.format for normal HTML request</span>. To my surprise, <span style="font-weight:bold; color: rgb(255, 0, 0);">IE</span> was registering the Mime::Type to be <span style="font-weight:bold; color: rgb(255, 0, 0);">"image/gif"</span>. Also, format.html? was nil. <br /><br />I tried accessing the same action from FireFox. This time, the request format was set correctly to be "text/html". <br /><br />Now, there is <span style="font-weight:bold; color: rgb(255, 0, 0);">no Mime::Type registered</span> for "image/gif". Hence, <span style="font-weight:bold; color: rgb(255, 0, 0);">first accept</span> type was taking preference. The solution (moving format.html before format.js) mentioned in the post worked for me.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-87467669593115550452010-08-11T05:46:00.000-07:002010-08-11T06:05:13.550-07:00undefined method `rewrite' for <#String: URL_STRING>Currently, I am working on a WEB API integration project for a leading tourism company in Australia. I am using RADIANT, MySQL, Ruby 1.8.7 and Rails 2.3.8. While working on an issue, I ran into a weird error: <span style="font-weight:bold;">undefined method `rewrite' for <#String URL_STRING></span>. <br /><br />I was defining an instance variable @url in the controller. Also, I was using a simple form_for tag in the view.<br /><br /><span style="font-weight:bold;">CONTROLLER:</span><br /><pre name='code' class='ruby'><br />class SomeController < ApplicationController<br /> def some_method<br /> #some logic<br /> @url = URL_STRING<br /> end<br />end<br /></pre><br /><br /><span style="font-weight:bold;">VIEW:</span><br /><pre name='code' class='ruby'><br />- form_for :some_object, :url => @url do |f|<br /> - #some form fields<br /> = submit_tag 'submit'<br /></pre><br /><br />Everything seemed normal. But, I started getting this weird error. After a bit of search, I came to know that link_to, url_for and similar method uses ActionController::Base @url instance variable to generate URLs. So, make sure that you don't use/define @url anywhere in your controllers/helpers.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-87251010362565144762010-07-26T04:37:00.000-07:002014-01-10T17:34:17.833-08:00Commands...I always forget<div dir="ltr" style="text-align: left;" trbidi="on">
<ul><br />
<li>Locating a file: <span style="font-weight: bold;">sudo find / -name my-large.cnf -print</span></li>
<li>Disk usage: <b>df -kh</b></li>
</ul>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-35942534887052852332010-07-26T03:26:00.000-07:002010-07-26T04:15:22.195-07:00MySQL gem installation problem (Mac OS X - 10.5.8, RVM, Ruby 1.9.1)As mentioned in my previous post, I have been working with RVM on Mac OS X. I have had real troubles installing MySQL gem with ruby-1.9.1p378 on RVM. I tried different things:<br /><pre name="code" class="ruby" style="width:600px; overflow:auto;"><br /><ul><br /><li>Removed RVM setup using rvm implode</li><br /><li>env ARCHFLAGS="-arch x86_64" gem install mysql --verbose -- --with-mysql-config=/usr/local/mysql/bin/mysql_config</li><br /><li>Re-installed <a href="http://dev.mysql.com/downloads/mysql/">MySQL through DMG archive</a></li><br /><li>Tried building MySQL gem on my machine</li><br /></ul><br /></pre><br />Every single time I was let down. I got the same error every single time:<br /><br /><div style ="height:300px;width:600px; overflow:auto;"> <br /><pre name='code'><br />ERROR: Error installing mysql:<br /> ERROR: Failed to build gem native extension.<br /><br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config<br />checking for mysql_ssl_set()... yes<br />checking for rb_str_set_len()... no<br />checking for rb_thread_start_timer()... no<br />checking for mysql.h... yes<br />creating Makefile<br /><br />make<br />gcc -I. -I/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/i386-darwin9.8.0 -I/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/backward -I/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/usr/local/mysql/include -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common -O2 -g -Wall -Wno-parentheses -fno-common -pipe -fno-common -o mysql.o -c mysql.c<br />In file included from /Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby.h:32,<br /> from mysql.c:5:<br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/ruby.h: In function 'INT2NUM':<br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type<br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type<br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/ruby.h: In function 'UINT2NUM':<br />/Users/BLAH/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/ruby.h:472: warning: comparison is always true due to limited range of data type<br />mysql.c: In function 'escape_string':<br />mysql.c:290: error: lvalue required as left operand of assignment<br />mysql.c:290: error: lvalue required as left operand of assignment<br />mysql.c: In function 'real_escape_string':<br />mysql.c:434: error: lvalue required as left operand of assignment<br />mysql.c:434: error: lvalue required as left operand of assignment<br />make: *** [mysql.o] Error 1<br /></pre><br /></div><br /><br />Finally, I consulted a colleague (David) at work. He suggested me to install MySQL via ports. Guess what???!!! He was spot on....!! <br /><br /><span style="font-weight:bold;">SOLUTION:</span><br />All I had to do was:<br /><pre name="code" class="ruby" style="width:600px; overflow:auto;"><br /><ul><br /><li>Install MySQL via ports</li><br /><li>env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5</li><br /></ul><br /></pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-85941072493536261412010-04-19T06:04:00.000-07:002010-04-19T06:53:38.527-07:00Efficient multiple SQL inserts in RAILS - AR ExtensionsRecently, I was required to generate multiple inserts in a RAILS project. I went with traditional way of looping through and creating AR objects.<br /><br /><pre name='code' class='ruby'><br />#class definition<br />class CartoonCharacter < ActiveRecord::Base<br />end<br /><br />#values for NEW objects<br />names = ["Tom", "Jerry", "Donald"]<br /><br />#loop thru and create objects<br />names.each do |name|<br /> CartoonCharacter.create!(:name => name)<br />end<br /></pre><br /><br />It's not as bigger problem if you're just creating 2 or 3 records. Imagine you want to create 70,000 records. I was required to do the same. This approach killed my machine and it just took ages. I couldn't wait after 5 minutes and killed the process.<br /><br />I started looking out for other options. I came across <a href="http://github.com/zdennis/ar-extensions">ar-extensions</a>.<br /><br />It is a nice gem for mass import and conversion of data to CSV. It also incorporates better finder support. All I've used is its mass import functionality.<br /><br />Usage:<br /><pre name='code' class='ruby'><br />column_names = [:name, :age, :country]<br />values = []<br /><br />#build up values<br />15000.times do<br /> values << ["Tom", "65", "AU"]<br />end<br /><br />#import<br />CartoonCharacter.import column_names, values<br /></pre><br /><br />That's it. It worked like a charm. Yes, please don't forget to include adapter specific functionality.<br /><br /><pre name='code' class='ruby'><br />require 'ar-extensions/adapters/mysql'<br />require 'ar-extensions/import/mysql'<br /></pre><br />Recently, some work has been done to extract the import functionality of ar-extenstions into activerecord-import. <br /><br />More information available at: <a href="http://continuousthinking.com/tags/arext">http://continuousthinking.com/tags/arext</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-20910043020377735522009-12-03T05:39:00.000-08:002009-12-03T06:09:38.186-08:00Java ME Early Access to rescue Mac J2ME Developers<span style="font-size:100%;">Finally, we have an IDE for MAC J2ME developers. Most of the Mac users use MPowerPlayer SDK(mpp-sdk) to develop J2ME applications. It was hell of a pain to use it with NetBeans. It also lacked the Bluetooth API support.<br /><br />Last month, Sun announced the launch of most awaited JAVA ME SDK 3.0. This can be downloaded at <a href="http://java.sun.com/javame/downloads/sdk30_mac.jsp">http://java.sun.com/javame/downloads/sdk30_mac.jsp</a>. Please note, it is an Early Access release(not beta). So, it is expected to have some issues. Couple of issues I am aware of are:<br /></span><ul><li><span style="font-size:100%;">Exceptions when launching JAVA ME SDK (Just ignore all the exceptions hitting 'Cancel')</span></li><li><span style="font-size:100%;">Also, it runs out of memory after every 4-8 runs and will require Mac reboot(YES, mac reboot).</span></li></ul><span style="font-size:100%;">You might have to restart your Mac immediately after JAVA ME SDK installation.<br /><br />Apart from these issues, it works like a MAGIC. It has got a nice environment based on NetBeans platform. I have tried mpp-sdk and Java WTK within Sun's Virtual Box, but I find JAVA ME EA to be the best.<br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-60976835405548496742009-11-29T00:11:00.000-08:002010-11-03T05:44:03.855-07:00Frequently used git commandsIgnoring all the local uncommitted changes<br /><span style="font-style: italic; color: rgb(255, 0, 0);font-size:100%;" ><span style="font-family:monospace;">$ git reset --hard</span></span><br /><br /><br />Ignoring changes to individual files<br /><span style="font-style: italic;font-size:100%;" ><span style="font-family:monospace;"></span></span><span style="font-style: italic; color: rgb(255, 0, 0);font-size:100%;" ><span style="font-family:monospace;">$ git checkout path_to_file</span></span><br /><br /><br />Tracking a remote branch (Creates a new local branch based on remote branch and switches to that branch)<span style="font-style: italic;"><br /></span><span style="font-style: italic;font-size:100%;" ><span style="font-family:monospace;"><span style="color: rgb(255, 0, 0);">$ git checkout --track -b local_name origin/remote_name</span><br /><br /></span></span><br />Deleting remote branch/tag<br /><code style="font-style: italic; color: rgb(255, 0, 0);">$ git push origin :heads/branch_name<br /></code><code><span style="font-style: italic; color: rgb(255, 0, 0);">$ git push origin :branch_name</span> <span style="font-style: italic; color: rgb(255, 0, 0);"><br />$ git push origin :tag_name</span> <span style="font-style: italic;"><span style="color: rgb(255, 0, 0);"><br />$ git push origin :refs/tags/tag_name</span><br /><br /></span></code><br />Deleting local tag<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git tag -d tag_name</span></code><br /><br /><br />Deleting local branch (already merged)<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git branch -d branch_name</span></code><br /><br /><br />Deleting local branch (unmerged)<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git branch -D branch_name</span></code><br /><br /><br />Merging with desired merge tool<br /><code><span style="font-style: italic;"><span style="color: rgb(255, 0, 0);">$ git mergetool --tool=tool_name</span><br /><br /></span></code><br />Clearing stash<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git stash clear</span></code><code><span style="font-style: italic;"><br /></span></code><br /><br />Reverting a commit<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git revert HASH</span></code><code><span style="font-style: italic;"><br /></span></code><br /><br />Deleting untracked files<br /><code style="color: rgb(255, 0, 0);"><span style="font-style: italic;">$ git clean -n(for dry-run) -f(for forceful clean)</span></code><br /><span style="font-style: italic;font-size:100%;" ><span style="font-family:monospace;"><span style="font-family:Georgia,serif;"><br /></span></span></span>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-5838822209215420021.post-9016325453401731612009-09-24T17:06:00.000-07:002010-07-26T04:37:27.261-07:00Starting and stopping MySQL on Mac OS X Leopard<pre><span style="font-size:100%;"><span style="font-family:arial;">sudo /Library/StartupItems/MySQLCOM/MySQLCOM start</span><br /><span style="font-family:arial;">sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop</span><br /><br /><span style="font-family:arial;">Reference: </span><a style="font-family: arial;" href="http://www.simplisticcomplexity.com/2007/10/27/start-and-stop-mysql-in-mac-os-x-105-leopard/">Simplistic Complexity</a><br /></span><br /></pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5838822209215420021.post-31608441000498632132009-09-24T15:23:00.000-07:002009-10-10T07:25:23.788-07:00Long running processesIn our application, we've got number of long running processes. These processes are meant to run in background without affecting the application response time. We are using the <a href="http://railscasts.com/episodes/128-starling-and-workling">combination of starling and workling</a>.<br /><br />For installing starling-starling:<br />gem sources -a http://gems.github.com/ <br />gem install starling-starling<br /><br /><br />Unknownnoreply@blogger.com0