Thursday, November 17, 2011

Impressions from the Riak & Haskell Meetup at Bump Technologies - http://bit.ly/vIp0Oq

  • Folks use noSQL because databases eventually become a key-value datastore.
  • When carefully tuned, SQL database still perform exceedingly well and scale nicely.
  • However, companies that can't afford the time and resources of tweaking SQL databases can benefit from using noSQL where you can just throw machines at the problem.
  • From prior presentations, I learned that performing a re-schema on SQL databases, especially when there are lots of records, can be painful. As in hours. Whereas for noSQL, it's a no-op.
  • Riak is a noSQL database that offers heavy writes. In contrast, MongoDB offers heavy reads.
  • Riak has this concept of a Resolution Schema that I don't quite understand. And hope never have to.


Thursday, January 27, 2011

bug fix for ctran-annotate

I use ctran-annotate to annotate my Rails models. It's a nifty little gem that adds the database schema for a model to the top of your Model, spec/test, and fixture files. Unfortuately, it has a little pathing bug that keeps it working properly with rvm.

The fix is in a fork by James2M. Unfortunately, it too has a typo; just read the comment on that page.

Thursday, December 09, 2010

rvm on Ubuntu 10.04.1 Desktop

Packages needed to install rvm on Ubuntu 10.04.1 Desktop:

  • build-essential
  • git-core
  • zlib1g-dev
  • libssl-dev
  • libreadline6-dev


Monday, October 04, 2010

`require': no such file to load -- readline (LoadError)

Compiling Ruby from source may cause this error to fire when trying to script/console:

`require': no such file to load -- readline (LoadError)
This snippet tells you the simple commands to fix it. Unfortunately, on my Ubuntu installation, the libreadline5-dev package was not installed, so "ruby extconf.rb" failed. After installing libreadline5-dev according to this article, the snippet then worked.

Friday, April 09, 2010

Installing MySQL for Rails on Snow Leopard

Download the 64-bit .DMG version of MySQL Community Server. Note that the .DMG package installs the MySQL directory at /usr/local/mysql so it will help to add /usr/local/mysql/bin to your path.

Install the mysql gem with the following commands:

  1. export ARCHFLAGS="-arch x86_64"
  2. gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

According to this forum post, using version 2.7 (instead of the latest) of the mysql gem will make it work. However, I find that version 2.8.1 works fine.

Tuesday, January 19, 2010

Rails Counter Cache requires evil hack

Rails Counter Cache, when it first came out, probably didn't seem to need this hack (see http://railscasts.com/episodes/23-counter-cache-column and http://snipplr.com/view/3283/counter-cache-column/). However, as of 2.3.4, I need to make the counter cache attribute non-readonly; otherwise, the up migration does not set its value properly.

Tuesday, October 13, 2009

Setting MySQL permissions for a Rails project

Enter mysql as root:
  • mysql -u root -p
Grant permissions for each dev, test, & prod databases:
  • GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON rails_project_development.* TO 'username'@'localhost' IDENTIFIED BY 'password';
  • GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON rails_project_test.* TO 'username'@'localhost' IDENTIFIED BY 'password';
  • GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON rails_project_production.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Labels: ,

Tuesday, May 05, 2009

git archive the current directory into a zip file


Labels:

Friday, May 01, 2009

Rails DB Migration on production

rake db:migrate RAILS_ENV="production"
That command will run all the Migrations it finds under db/migrate until it's at the highest version number. You can override the version number by appending VERSION=x after the command. - i.e., pass RAILS_ENV="test to force the migration to run on the test.

Monday, April 27, 2009

Using Ruby oauth gem to access Netflix

The example at Mandarin Soda didn't work for the latest version of the Ruby oauth gem (version 0.3.2.2 as of this writing). Took me a day to work out all the differences. The slightly alter code is a gist on GitHub (and reproduced here). The differences are:
  • :request_token_url is http instead of https
  • access_token.response is a subclass of Net::HTTPResponse so there's no access_token.response[:user_id]; rather, you get the user ID with access_token.params[:user_id]
  • using access_token.get(url) instead of consumer.request(:get, url, access_token, {:scheme => :query_string}) but I think they're the same (and the latter still works)
Link

Labels: , ,

Sunday, January 25, 2009

Open a Browser from the Command Line (Mac OS X)

In Mac OS X, to open Safari on a file (e.g., README.html) from the command line, use the "open" command with the "-a" switch:
open -a /Applications/Safari.app README.html
Replace Safari with Firefox to use Mozilla Firefox. Why do this at all? I'm working on the command line and it's a pain to "open ." to get a Finder window, and then drag-&-drop the file in question onto the appropriate dock icon. Lastly, add aliases to ~/.bashrc to cut down on the typing even further:

Saturday, November 01, 2008

Sending Tweets from your Rails app

Use the Twitter4R gem. I tried using Twitter, but could never install it properly in the vendor directory - probably my own gem naivete, though, YMMV.

Like Chris Wanstrath says - "vendor everything". Unpack it into your vendor/gem directory. If the gem is already installed, cd to vendor/gem and use this command:

Add Chris' code to the Rails::Initializer.run block in your config/environment.rb:

Add this line of code at the bottom of the Rails::Initializer.run block in your config/environment.rb - it tells Rails that the "twitter" gem is found in "twitter4r.rb":

(Optional) Register your app with Twitter. Otherwise, tweets you send will display on the Twitter home page with a link to twitter4r. Once Twitter registers your app, you'll get an email with a "source token" (usually the name of your app in lowercase). Add an init file (i.e., set_twitter4r_source.rb) to config/initializers/ to initialize twitter4r with that source token. Don't bother grepping for Twitter4R and changing URLs randomly - it won't work (I tried):

Using the following code snippets, you should be able to authenticate and to send a tweet:

Friday, August 15, 2008

quick note: git tag and export

Tag:
git tag -a some_release_name
Export:
git archive --prefix=quikcms/ HEAD > ../quikcms.tar
Since I have to be in the same level as .git, I want to export the tarball one level higher. Moreover, the files inside won't have a dir prefix, so I have to add that on the command line.

Monday, February 25, 2008

gwt-dnd-2.0.7 bugs

This test GWT application demonstrates a few bugs I encountered while using gwt-dnd-2.0.7.jar [1] for drag-and-drop of DIV's inside a FlowPanel [2] wrapped inside a ScrollPanel [3].

The app displays three such ScrollingDropPanel's on the page and allows users to drag-and-drop "strips" within a panel and between panels. Note that the app uses strict mode.

Sources (including Eclipse project files) are in this tarball .

The bugs are:

  1. Clicking on the lower half of a strip (without moving the mouse) performs a drag and swaps it with the strip underneath.
  2. Strips beyond the first page cannot be dragged. Or rather, they can be picked up, but no positioner shows, and when dropped, they return to their original position.
  3. When dragging multiply-selected strips, the drag proxy does not display properly. Some times, it has the correct height, but only the first and last strips show and the strips in the middle are blank. Other times, only two strips are shown and they have the same label. It seems the drag proxy is rendered differently depending on which strip in the multiple selection is used to start the drag.
  4. Once multiply-selected strips have been dragged-and-dropped, clicking on any one of the still selected strips cause the rest to disappear.

References

  1. gwt-dnd-2.0.7.jar
  2. FlowPanel
  3. ScrollPanel

Monday, January 14, 2008

rsync arguments

rsync -a src/ dst/ is too aggresive when backing up files between different file systems - most notably between Samba & Unix. -a is a short hand for -rlptgoD
  • -r recursive
  • -l copy symlinks as symlinks
  • -p preserve permissions
  • -t preserve times
  • -g preserve group
  • -o preserve owner (super-user only)
  • -D same as --devices --specials
None of these options, except for -r, are useful when copying to or from Samba. So invoke rsync this way instead: rsync -Cr --exclude=.DS_Store --size-only src/ dst/
  • -C auto-ignore files in the same way CVS does
  • -r recursive
  • --exclude=.DS_Store don't copy Macintosh directory info
  • --size-only skip files that match in size

Tuesday, December 18, 2007

Firefly Jar Owner's Manual

Inspired by this Firefly Lamp on Etsy, I made my own version. The difference being that the LEDs are held in micro-sockets and thus the owner can change the LED configuration at her discretion. Things to watch out for:
  1. Never let the micro-sockets touch each other. If you do, you will cause a short and though you're using only AA batteries, there's enough current to do serious damage (i.e., melt the metal in the battery holder - I learned this through experience) and maybe even start a fire. Version 3 will probably have an inline fuse.
  2. Insert your LEDs with correct polarity. The longer lead is always positive and must be inserted into the red micro-socket. If for some odd reason, the LED leads are the same length, look at the side of the LED - the negative lead side is flattened. This lead should go into the black micro-socket.
  3. Never let your LED leads touch each other (this is another version of #1). If you have multiple LEDs in the micro-sockets, make sure leads from an LED does not touch the leads on another LED. You can add some Scotch Tape "wings" to the leads to insulate them but that's homework for the reader.
  4. Insert the batteries with correct polarity. Duh. The battery holder has indicators showing which direction the batteries should face.
That's it. I think. Have fun.

Friday, November 30, 2007

Password Generator Bookmarklet

This SuperGenPass bookmarklet, generated from http://supergenpass.com/, should be IE friendly.

Thursday, August 09, 2007

QuickTime Full Screen

Yet another script to make non-Pro QuickTime display a movie in full screen:
(*
Works only as "Drag & Drop" program.

Written by F-3000
*)

on run
 -- if invoked w/o movie, see if quicktime player is running
 tell application "Finder"
  using terms from application "Finder"
   if "QuickTime Player" is in (get name of every process) then
    -- if quicktime player is running, try to maximize a movie
    tell application "QuickTime Player"
     try
      -- if no movies are loaded, the try block degrades graceful
      present front document scale screen
     end try
    end tell
   else
    -- quicktime player is NOT running
    display dialog "Drop a movie on the application icon." buttons {"OK"} ¬
     default button 1 with icon stop
   end if
  end using terms from
 end tell
 
end run

on open (dMovie)
 if (count (dMovie)) > 1 then
  display dialog ¬
   "Try dropping a single movie, if you don't mind." buttons ¬
   {"Quit"} default button 1 with icon stop
 else
  tell application "QuickTime Player"
   activate
   try -- Prevents error when QT is already open.
    close document 1 -- Closes any possibly opening advertises.
   end try
   open dMovie
   present document 1
   play
  end tell
 end if
end open

Monday, June 11, 2007

Giving a Talk

Links:
My Favorite Points:
  • Appetizer, Entree, and Dessert
    • tell your audience what you're going to tell them
    • give your talk
    • tell your audience what you just told them
  • Getting Attention
    • speak clearly
    • walk among your audience
    • walk in front of the projector
    • ask a question
    • use props
  • Never
    • after lunch - post-digestive turpor
    • turn off the lights - your audience will just go to sleep
    • read your slides
    • cover up parts of your slides
    • fiddle with the slide
Other Links

Sunday, March 04, 2007

RPC call to service in common module

This eclipse project archive demonstrates a technique in GWT to call an RPC service, implemented in one module (Common), from another module (Display). Note:
  • Display.gwt.xml has an "inherit" element that makes the Common module available
    inherits name='com.boscomonkey.data.Common'
  • Since Common.gwt.xml is purely a data provider and has no UI component, there's no "entry-point" element in it.
  • Likewise, there are no assets in the "public" directory

Saturday, January 27, 2007

Perl regex to capitalize each word

I always forget how to use Perl regex to capitalize every word in a string buffer. So here it is for future reference:
$buffer =~ s/\b\w/\u\L$&/g;

Friday, January 12, 2007

Empty Firefox Search Bar

In my 1.5.0.9 Windows version of Firefox, all the search sites in the Search Bar disappeared one day. Didn't realized how much I used that Search Bar until it wasn't functional. I tried reinstalling the app, and when that didn't fix anything, I suspected that the problem was in the user specific application data. I deleted the Application Data\Mozilla\Firefox directory and all my settings got cleared.

I've customized my Firefox so much that it was going to be a pain to redo all the settings and so I restored my settings directory from the trash and proceeded to wade through the Profiles directory and removed one file at a time to figure out which caused the Search Bar to come back.

In the end, it was the localstore.rdf file that turned out to be corrupted. When I removed it, my Search Bar returned to normal. Yay!

Monday, January 01, 2007

Synchronizing Time on Windows

Details can be found by following the title link. In short, though WinXP has an "Internet Time" tab on the "Date & Time" control panel, other versions of Win32 doesn't. For all versions, you can sync your Windows machine time by first setting a time server:
net time /setsntp:tick.usno.navy.mil
and then syncing the time:
net time /set
If your time service is not already setup, read the article. The US Naval Observatory has a backup time server named tock.usno.navy.mil; so if tick doesn't work, try tock. A Microsoft web page has a list of time servers that are available on the Internet.

Saturday, December 30, 2006

New Redhat/Fedora/RHEL/CentOS build

My ToDo list for new Redhat-derivative builds:
  • start with minimal package and add
  • change font in /etc/sysconfig/i18n to lat0-08
  • append vga=1 phrase to /boot/grub/grub.conf kernel line
  • remove irda, isdn, pcmcia and similar packages
  • enable yum nightly
  • change httpd, sshd to use non-standard ports (update /etc/sysconfig/iptables accordingly)
  • harden sshd (e.g., no root login, protocol 2, strict modes)
  • revisit chkconfig to make sure services are started (or not) on reboots

Burning DVD ISO in Linux

growisofs -Z /dev/dvd=ISOFILENAME -speed=2
Where ISOFILENAME is CentOS-4.4-i386-binDVD.iso, for instance. Note:
  • -Z closes the DVD from additional sessions (which is the normal case when burning .ISO files).
  • For some reason, under FC4, you can't sudo the command, you must be root.

Thursday, December 14, 2006

Handling non-GWT POSTs in GWT servlets

Posted and answered my own question regarding Google Web Toolkit. The way to handle non-GWT POSTs in GWT servlet is to:
  • Override the service(...) method. If your servlet inherits from GWT's RemoteServiceServlet, you can't override doPost as RemoteServiceServlet has marked it final.
  • Figure out some way to distinguish a GWT POST from a non-GWT POST. The easiest way is to add a hidden field (i.e., ) and check for that parameter value in the service(...) method. If that parameter isn't there, then call super.service(...) so that GWT calls can go through.
  • Declared the servlet in MODULE.gwt.xml like any other servlet (GWT or not).

Since I use Instantiation's GWT Designer, it automatically generates the service's Async interface java file, implementation java file, and servlet entry in the MODULE.gwt.xml file. Thus all I do is add the service(...) method in the implementation file.

Cheers.
boscomonkey wrote:
> In our GWT app, we have a login dialog box that pops up to handle fresh
> users or users whose sessions have timed out. Now we wish to accept
> username/password POSTs from our static web site or even affiliate web
> sites. What are some approaches for handling POSTs from outside the GWT
> app?
> It seems that one simple approach is to write a standard servlet that
> implements doPost, place it in our GWT app's server package space, and
> if users authenticate properly, redirect to our GWT app's URL. In this
> case, do I have to map this servlet in our MODULE.gwt.xml? What's the
> URL to this servlet?

Friday, September 15, 2006

xsltproc on cygwin

Note to self: in order to get xsltproc on cygwin, I need to install the libxml2 and libxslt packages under the Libs category

Thursday, August 24, 2006

Cold Cathode Bicycle Lights

I reassembled my cold cathode bicycle lights (see this or this or this) for BM 2006. While commuting home last night, a woman caught up to me and asked me where I got them. She was disappointed when I told her that I made them. That got me thinking however...

You can buy these lights online for anywhere from $30 to $100. But if you assemble them from readily available parts, they'll cost around $15 (excluding batteries) and you'll have the satisfaction of knowing they're your handiwork.

So here's the part list:

  • Cold Cathode Tubes - used by case-modders to light up the inside of their computer cases. They're basically the backlighting used in laptops. You can buy them locally at CompUSA or a mom & pop computer store. You can get them online at Case-Mod or Xoxide. Skip the black light (ultraviolet) version, they don't emit much visible light (duh - I had to learn the hard way).
  • Battery holder - since a typical battery is at 1.5 volts DC, you'll need 8 of them to get 12 VDC, which is what the inverters for the cold cathode tubes take. (The inverters should be included with your cold cathode tubes.) So get a battery holder that holds 8 batteries. I typically use AA because I have lots of those for my electronics, but you'll get longer burn time if you get C or D batteries. These are available locally at Radio Shack, or online at Jameco & All Electronics.
  • Zip Lock bag - to hold the batteries and holder so they don't get full of playa and corrode. If you have an old under-the-seat bicycle tool bag, that'll work too (that's what I use).
  • Batteries - 8 of them, your choice. I use rechargeables but I also have lots of those.
  • (optional) Velcro straps - using these straps is getting fancy, but allows you to easily take the tubes and inverter off your bike. Not necessary for BM, but may be useful if you have more than 1 bike. You'll need 4 of these - 2 per tube, 1 for the inverter, and 1 for the battery pack. If you use a 2 tube setup (still connected to 1 inverter), you'll need 6 straps.
If you're in a hurry, nothing beats local, but be prepared to pay anywhere from 50% to 100% more.

Wednesday, January 04, 2006

LVM on top of RAID5

I'm turning my old Pentium III 800 MHz box into a Linux RAID5 server. Steps are:
  • Acquired four 200GB IDE drives
  • Acquired Highpoint Rocket133 IDE adapter card because the motherboard does not have enough IDE connectors. I may need another one because the Software RAID HOWTO says that each drive should have its own channel instead of sharing one (master/slave) between two drives (because when a master/slave dies, it may take the correspond slave/master with it).
  • Format each drive with fdisk. Create one full size partition with type FD.
  • Create the RAID5 with mdadm:
  • Make the new /dev/md0 available for LVM use:
    pvcreate /dev/md0
  • From the LVM Tutorial, create LVM volume group named vgdata with 32MB extent:
    vgcreate -s 32M vgdata /dev/md0
  • Create LVM logical volume named lvdata:
    lvcreate -l 17885 -n lvdata vgdata
    17885 is the total number of LVM extents (at 32MB each) in my RAID. Use vgdisplay to find out how many free extents you have.
  • Format logical volume with reiserfs:
    mkreiserfs /dev/vgdata/lvdata
  • mount it:
    mount /dev/vgdata/lvdata /mnt/data
  • Wait a heck of a long time for the RAID to build properly (may take overnight). Check /proc/mdstat/ periodically to see if the recovery has completed. The cat output should look like this:
    Personalities : [raid5]
    md0 : active raid5 hdh1[3] hdg1[2] hdf1[1] hde1[0]
    586075008 blocks level 5, 128k chunk, algorithm 2 [4/4] [UUUU]
    
    unused devices: 
    Do not reboot your machine until the recovery is complete as it'll just start all over again.

Tuesday, December 20, 2005

Ruby MySQL native bindings on Fedora Core

In this article about installing Ruby, and Ruby-on-Rails for Mac OSX, I found that it also works for Fedora Core 2 Linux (and probably other *nuxes). However, if MySQL was installed with RPM, there isn't one root MySQL directory. Thus, the last command that you issue must be modified to point to where the include and lib files are located. So instead of using this command to install the Ruby MySQL native bindings:
  • sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
You need to use this command
  • sudo gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
And by the way, though the lib files are included in the standard mysql RPM distribution, the include files aren't. You'll also need mysql-devel for the include files.

Tuesday, December 13, 2005

Dec 2005 SF Ruby Meetup Notes

The San Francisco Ruby Meetup Group met for the first time in a while on Dec 13, 2005. I did the 1st presentation - Running Ruby and Ruby-on-Rails on the Macintosh - because my colleague who promised to do it had to go on a business trip. It's basically a rehash of the steps in the following articles: When I was installing readline on my Mac, it was at version 5.1 but the instructions in the 1st article was still referring to version 5.0. The instructions have now been updated to 5.1 and the following note (here for historical purpose) can be ignored:
Note that the latest version of readline is 5.1 and you don't have to do the business with sed/mv after running configure (skip these two lines):
sed -e 's/-dynamic/-dynamiclib/' shlib/Makefile > shlib/Makefile.new
mv shlib/Makefile.new shlib/Makefile

Sunday, November 13, 2005

Even Easier del.icio.us Links

In a previous post, I noted that you can use RSS Digest to embed your del.icio.us links into your web page. It turns out that del.icio.us offers its own JavaScript facility to do that - they call it linkrolls. Once you're logged into del.icio.us, go to http://del.icio.us/doc/feeds/js and use the form there to customize the JavaScript that you can embed into your web page. Why do I prefer it over RSS Digest?
  • No logging into RSS Digest
  • No delay in the linkroll output when you update your links

Sunday, November 06, 2005

Mac OSX vertical scrolling w/ Firefox

The 2-finger trackpad scrolling on the new iBook causes vertical scrolling to jump really fast on Firefox. The solution is to use a custom number of lines per scroll rather than the default system number of lines. The changes in about:config are:
  • mousewheel.withnokey.numlines => 3
  • mousewheel.withnokey.sysnumlines => false
Play around with the mousewheel.withnokey.numlines values. To me, 3 seems closest to Safari's behavior but your mileage may vary.

Mac OSX horizontal scrolling w/ Firefox

By default, the horizontal 2-finger scrolling feature on the new iBook trackpad causes Firefox to move backwards and forwards in the history list - quite annoying. This Mac OSX Hints page tells you the Firefox about:config preferences to set to change that. In short:
  • mousewheel.horizscroll.withnokey.action => 0
  • mousewheel.horizscroll.withnokey.sysnumlines => true

Thursday, July 14, 2005

del.icio.us "remember this" popup

del.icio.us has an experimental "remember me" bookmarklet that pops up instead of showing in-page. The advantage is that you can flip back and forth between the page you're bookmarking and the del.icio.us dialog. The only downside I've seen so far is that the post does not occur immediately (and sometimes not at all :-). To try this out, add this bookmark by hand and replace ACCOUNTNAME with your del.icio.us account name:
remember this (popup)
In Mozilla Firefox, you can simply drag the above link to your Bookmarks Toolbar. You may also have to have to increase the height if you have a lot of tags in order to avoid the scroll bar.

Wednesday, July 13, 2005

Burning CD in Linux

First determine what devices are available:
  • cdrecord -scanbus
Then use this cdrecord command line arguments:
  • cdrecord -v dev=0,0,0 driveropts=burnproof -dao -eject DATAFILE.iso
    • leaving out the -speed=X argument will cause cdrecord to query the CD blank for its purported speed
    • -dao option makes it possible to MD5 the result with md5sum -b /dev/cdrom
    • -eject argument will pop the disk. Insert it, unmount if it automounts, and run md5sum
More details at http://www.sun.com/bigadmin/features/articles/burn_iso_images.html

Tuesday, July 12, 2005

del.icio.us on your website

The easiest way to put your del.icio.us links on your web site is via RSS Digest.

Friday, June 24, 2005

Athlon 64 vs. Opteron Processors : What's the difference again?