For quite a long time I just couldn’t get my TreePanel (ExtJS) to work. It would just display nothing at all, and Firebug’s output was Node cannot be inserted at the specified point in the hierarchy” code: “3. After a bit of searching around, I found this nice forum post warning about the danger of the el property when creating a new TreePanel… I deleted it and it worked fine! =)
Playing with Rails partials and recursion
Wednesday, March 18, 2009I was wondering if there was a way to render partials from another controller’s directory, different from the one my action’s view is located. My beloved brother opened my eyes! Quite simple to do, but somehow hard to find how on the net… Just add the controller’s name and a slash sign before the partial’s name in the render call:
<%= render(:partial => 'controller_s_directory/partial', :locals => {...}) %>
Another very interesting thing I found out (perhaps quite obvious, but I was delighted): partials can functions as methods, and can be used for recursion! You can call the partial from inside itself! =) This was extremely helpful for me, I hope it will also be for somebody else…! And one last thing, most certainly obvious as well, but always good to be reminded: the render command, when used inside a view, *has* to come surrounded by <%= %>. The equal sign is extremely important! You can’t, for instance, have some ruby code inside <% %> and call render there. You have to close the block and open a new <%= %>… =)
Solutions for sound problems in Ubuntu and Skype
Wednesday, March 18, 2009I’ve just installed Ubuntu 8.10 Intrepid and I was having trouble with sound in several applications, specially Skype and Firefox, to name some… The startup sound played alright, but no other sounds would play. While some page which used sound was loaded in Firefox, or when I was trying to call somene in Skype, the test function in Ubuntu’s sound preferences would give me an error, in all other situations it would play normally. I found the exact perfect solution for my problem here… Install PulseAudio and some other packages, set up sound devices… just follow exactly what the post says. And everything was working again, or *almost* everything… In Skype calls, the other person would hear me with an ever growing delay (lag), and I would hear him/her in real time, instantly. After some googling, I found a good solution here and here. Quite simple… you just have to set Sound In in Skype’s options (sound devices’ tab) to one of the hw or plughw devices available. I did it using the trial and error technique. Voilà! =)
How to add a user to Ubuntu’s “root” groups
Tuesday, March 10, 2009The commands are extremely simple, and perhaps there’s even an easier way to accomplish the task (I’m sure!), but this is one that worked quite alright for me, and I think it might spare some beginner users (and other non-beginners as well, maybe) a lot of time searching for answers out there in the Net… In the code below, user1 is the one created when Ubuntu is first installed, and user2 was created afterwards. What I wanted was that user2 had exactly the same privileges as user1.
$ id user1 uid=1000(user1) gid=1000(user1) groups=1000(user1),\ 4(adm),20(dialout),24(cdrom),25(floppy),29(audio),\ 30(dip),44(video),46(plugdev),104(scanner),\ 108(lpadmin),109(admin),115(netdev),117(powerdev) $ sudo usermod -aG adm,dialout,cdrom,floppy,audio,\ dip,video,plugdev,scanner,lpadmin,admin,netdev,\ powerdev user2
Finding HD device files in Ubuntu and formatting a partition as NTFS
Thursday, January 29, 2009A friend of mine wanted to erase all partitions from a HD and create a new one, formatted with NTFS (reasons unknown). I plugged it in a Ubuntu box, and I couldn’t figure out which device I was supposed to issue the fdisk command with. After a bit of googling, I found this and thru /dev/disk/by-label I found /dev/sdb easily… The next “challenge” was to format the newly-created partition as NTFS… Here I found how:
$ sudo apt-get install ntfsprogs $ sudo mkntfs /dev/sdb1
Error installing mysql gem
Tuesday, January 27, 2009I was getting the following error when trying to install the mysql gem, so I could get access to my non-default database from Rails… (using Kubuntu Hardy)
$ sudo gem install mysql
[sudo] password for user:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Solution? I found in Ubuntu Forums, and it solved the problem.
sudo apt-get install libmysqlclient15-dev
Using an SSH tunnel with Firefox
Friday, December 5, 2008I found a great post after very little googling around, very well written and straight to the point. Basically you run:
$ ssh -D localhost:PORT user@remote_host
Then you edit Firefox proxy settings (Edit menu, Preferences, Advanced, Network, Configure how Firefox conects to the internet (Settings…), Manual proxy configuration) and add localhost to SOCKS host, and the PORT you passed to your ssh command. To tunnel DNS traffic as well, set network.proxy.socks_remote_dns property in about:config to true. =)
Counting lines of code in a RoR project
Wednesday, December 3, 2008Today I bumped into an unusual task: to get the total lines of code for the Ruby on Rails project I work in. I already knew a tool called JavaNCSS, a source measurement suite, that apparently does a whole bunch of stuff, besides what I needed. I wanted to find an equivalent tool for ruby. Googling for ruby source lines code, I found this, which wasn’t exactly what I was looking for, but it contained it. Just one single command solved all my problems… =)
lucas@bonito:~/my_rails_proj$ rake stats (in /home/lucas/my_rails_proj) +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 1687 | 1306 | 13 | 108 | 8 | 10 | | Helpers | 244 | 223 | 0 | 13 | 0 | 15 | | Models | 682 | 550 | 12 | 34 | 2 | 14 | | Libraries | 0 | 0 | 0 | 0 | 0 | 0 | | Components | 0 | 0 | 0 | 0 | 0 | 0 | | Integration tests | 0 | 0 | 0 | 0 | 0 | 0 | | Functional tests | 364 | 262 | 24 | 50 | 2 | 3 | | Unit tests | 120 | 84 | 12 | 12 | 1 | 5 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 3097 | 2425 | 61 | 217 | 3 | 9 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 2079 Test LOC: 346 Code to Test Ratio: 1:0.2
And you can see very easily that my testing skills need to improve a lot… Quite a lot! =P And by the way, Google’s Search History can be amazingly useful… =)
Longs URLs in Chart Director requests
Monday, December 1, 2008I use the ChartDirector library to produce wonderful charts, and I highly recommend it. Thing is, from time to time I was getting a very weird error (in the picture): “Error 800 accessing server: Partial update returns invalid data”.
I had absolutely no idea what it meant, besides the obvious, which didn’t help me to solve the problem. I tried checking error logs, forums, etc. The weirdest thing was that it apparently had no pattern, it looked very random. I could use my app for entire weeks and nothing would go wrong, then all of a sudden, there it was…
I’ve installed LiveHTTPHeaders to better analyze what was being sent to server in the requests, and what exactly I was getting back as a response. Peter Kwan, from ASE, always very very helpful, pointed out a few things to me: that CD uses some parameters of its own to process AJAX updates, for instance zooming, moving, etc. To prevent the URL from getting too long, it limits the length of user parameters. The problem was that sometimes CD was cutting the URL right after a “%“, which is a escape character. With normal text after it (CD’s parameters) rather than a sequence to be escaped, Mongrel (I use Ruby on Rails) returns an error (“HTTP parse error, malformed request” and “HttpParserError: Invalid HTTP format, parsing fails.”). Most web servers would just ignore the incorrect escape sequence, but Mongrel is designed not to tolerate any invalid URL.
Solution: make my URL shorter, replacing parameter names like timestamp by t, for instance, or group many parameters in one, separating them with comma or something like it. Another one is to add the line:
query = query[0..240] + "00"
to file chartdirector.rb, right below line 1569, which should be:
path, query = @request.request_uri.split('?', 2)
This prevents invalid escaped sequences from being sent as a request, adding “00″ to the end of the “cut”… And everything works fine! Thanks once again for great and always helpful Peter Kwan, who makes using ChartDirector and solving problems a kind of pleasent task… =)
