Thursday, June 28, 2012

ActiveRecord::Fixtures.create_fixtures and RI_ConstraintTrigger error

When you run ActiveRecord::Fixtures.create_fixtures with postgresql adapter, it requires the db user (in config/database.yml) to be superuser. So the user is created by 'createuser -S' command, ActiveRecord::Fixtures.create_fixtures will fail with permission denied error related to RI_ConstraintTrigger. There are some useful discussion over here: https://github.com/matthuhiggins/foreigner/issues/61

Thursday, April 12, 2012

Delete Multiple Objects from s3

Deleting s3 objects used to be slow if you have lots of files in a s3 buckets: you have to issue a delete request for each file. On Dec 7, 2011 , Amazon announced Multi-Object Delete, a new API that allows user to delete multiple objects with a single web request.

As this api is relatively new, those popular ruby s3 libraries including rightaws has not supported it. So I wrote a ruby script to do it, the source code is here:
https://gist.github.com/2361625

And it can be used as a command line tool:

$ruby s3_multi_object_delete.rb bucket s3id s3key key1 key2

Or you want to use it in your Rails project, just drop it into 'config/initializers' folder.

It is based on happening, although the code can be ported to rightaws easily. I picked happening as it may archive better performance due to higher concurrency.

Labels:

The 200 billion company that can not fix a simple credit card processing problem

I am talking about Google.

About a month ago I purchased OBI110 device, it is a VOIP device to make free phone call to US&Canada without any fee, thanks to its great integration with Google Voice. It works great for local calls, so great that I cancelled my old landline phone service. But I also have the needs to make international calls, then the problem begins.

While google voice promised free calling within the US and Canada through 2012, international call is at an affordable rates. There is easy button to add '$10' credit to my account through credit card payment. On Mar. 6, I clicked it, then it told me:

Uh oh. There was a Problem
We couldn't complete your purchase because of a technical issue.
Details of the problem below:
We were unable to verify your account information. Please visit wallet.google.com/manage in order to resolve this issue.


I did what it told me, I double checked my information, I tried difference cards, I tried on another day... nothing helps. I tried to contact google, and it turns out they do not have phone # or email for Google voice. The support links on google voice leads me to this forum, and oh my god, lots of people reported this issue since Feb 19, and there is not a single word from Google. From the discussion there you can see people tried different ways, phone calls to general google support, submitting feedbacks etc, none of them helps. It is clear people working at google does not pay attention to this official support forum, and the google voice team is completely out of touch with its users.

On Apr 8, I heard some news about google wallet and it seems to be undergoing some active development. So I gave it another try, but it failed again. But luckily I found a deeply hidden 'Email us' link wile navigating their help page, so I sent an email explaining my problem and mentioned lots of other people having the same issue.

A few hours later, I got an email from Google Wallet Support with an link from the help section, I wrote back saying it is useless. Three days later, I received another email, and my problem was finally resolved.

I love lots of products google builds, but this customer service experience is the worst I have with any big company.

Labels: ,

Monday, April 09, 2012

HTML5 for Desktop Application Development

Thursday, August 11, 2011

Inspect Ruby Process From gdb

If you have been developing in Ruby and Ruby on Rails for any length of time, it is very likely that you have encountered a 'Segmentation fault' from Ruby without any information about where the error is coming from.

Normally, a gem written in C extension is to blame. If pure Ruby code meets an error, a nice stacktrace with a line number will be there to point you in the right direction, but not for code in C extension. You won't find more information about the error unless you fire up gdb.

Assuming the code that crashes is bug.rb, instead of doing 'ruby bug.rb', just do:
$gdb ruby
(gdb) run bug.rb

Once the the crash is reproduced, type:
(gdb) bt

'bt' means 'backtrace'. A C callstack will show up. And you will find some valuable information there. If 'bt' does not give you function name and line# you want, it normally means it can not locate the source code, and you can use the 'dir' command to help gdb locate the source code (Ruby's source code is freely available, just download the one that matches the binary):
(gdb) dir /root/downloaded/ruby-1.8.6-p111

If the program that crashed is a rake task, just do some thing similar. Rake itself is a Ruby script:
$gdb ruby
(gdb) run /usr/bin/rake -T

If you have a daemon written in Ruby, sometimes you might see that it hangs (does nothing) or uses too many resources (100% cpu usage). To inspect a live process with process id 12345, do this:
$gdb ruby
(gdb) attach 12345
(gdb) bt

For Rails applications, a bug may only happen in the production environment. Before you enter 'run', use this to setup the environment:
(gdb) set environment RAILS_ENV = production

Here are some tips to get more from a C stacktrace.
You can call a C function with a 'call' command under gdb shell -- yep, that makes C feel like an interpreted language. For example, you have a stack trace entry like this:
rb_call0 (klass=47110398570320, recv=47110462241640, id=22977,
oid=, argc=0, argv=0x7fffee0453c8, body=0x2ad8be3946c8,
flags=) at eval.c:5998
You can find out what 'klass' is by using its memory address:
(gdb) call rb_class2name(47110398570320)
Or you can look up a Ruby function's name:
(gdb) call rb_id2name(22977)

This GDB QUICK REFERENCE and Extending Ruby chapter of 'Programming Ruby' book are great references if you want to know more!

Labels:

Monday, January 12, 2009

How to debug or test cron script

If your simple cron script (/etc/cron.daily, etc/cron.hourly etc) does not run as expected, do the following:

1. be sure to have '#!/bin/sh' as the first line
2. make sure the script's name does not contains '.'. for example, you should rename 'yourscript.sh' to 'yourscript'.
3. use absolute path if you need to read/write files in the script
4. try run the script in the shell to make sure there is no obvious problem
5. 'run-parts --test /etc/cron.hourly/' will tell you what scripts will run, you should see your script in the list
6. next try to run it like cron does, for example:
cd / && run-parts --report /etc/cron.hourly
7. cron uses syslog for logging. Check your syslog config file ( /etc/syslog.conf) to see where the log is, and check the log for errors.

Ref:
[1] Why are cron.hourly files not running? SOLVED
https://lists.ubuntu.com/archives/ubuntu-users/2007-July/118973.html

Labels:

Monday, March 24, 2008

Google Summer of Code with Ruby Central

Ruby Central will once again participate the Google Summer of Code in 2008 as a mentoring organization:
http://code.google.com/soc/2008/ruby/about.html

Pat Eyler has put together an idea page, which is a great reference. While every organization may have different policy, Ruby Central has been happy to see students' own ideas in the past, and I believe this year is not an exception. Feel free to submit your own exciting ideas so that the mentors can pick the best ones.

Today is the first day for Google to accept student applications. For student who are interested in participating, my advise is to apply as early as possible: normally students who apply early has a slight advantage because mentors will have more time to read their applications.

And another advise for future GSOC students is: once accepted, please make sure you are well prepared for the program. Google and mentors normally assume you to work near fulltime in the summer, but unfortunately every year we saw 'disappearing' students during the program. If for some reasons you can not make it after being accepted, please communicate with your mentor organization early so that they can make better adjustment.

XRuby license changed to BSD

XRuby had been licensed under GNU General Public License v2. For people who want to create solutions based on XRuby, this means they had to adopt GPL as well, which is not always possible. So since 0.3.3, we changed the license to BSD. Hopefully this will help XRuby gain more acceptance, especially from the corporate world.

Monday, September 24, 2007

XRuby 0.3.1 released

XRuby 0.3.1 is released today and you can download the latest version here:
http://code.google.com/p/xruby/downloads/list

The major changes in this version are:

1. Ruby standard libraries are now pre-compiled and the compilation results (java bytecode) are shipped as part of the xruby.jar. This makes deployment really easy, as there is one jar file to deal with. Pre-compiled libraries means it isn't necessary to compile these code every time by the user which is helpful to performance.

The size of the final jar may cause some concerns: while the number of ruby stdlib supported by the current version of XRuby is still limited, the size of the compiled stdlib has already reached 2,000 KB (the entire xruby-0.3.1.jar is over 4,000 KB). Maybe we will ship ruby stdlib in a separated jar files in the future.

2. Use annotation and code generation to bind Java level method to Ruby level method. We started to make this change in 0.3.0 and finished it in 0.3.1. It helped us to get rid of lots of redundant code. For more information about this change, please read our last announcement and dreamhead's articles(1, 2) on his blogs (in Chinese).

Thank everyone who has contributed to this release.

Labels: