Saturday, November 01, 2008

Sending Tweets from your Rails app

Since I'm on the road, I'll have to make this short.
  • 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:
    gem unpack twitter4r
  • Add Chris' code to the Rails::Initializer.run block in your config/environment.rb:
    config.load_paths += Dir["#{RAILS_ROOT}/vendor/gems/**"].map do dir
      File.directory?(lib = "#{dir}/lib") ? lib : dir
    end
  • Add this line of code under the Rails::Initializer.run block in your config/environment.rb:
    [Ok, I forgot the exact syntax of this line, but it tells Rails 2.1 that the "twitter" gem is found in "twitter4r.rb"]
  • Using the following code snippet, you should be able to send a tweet. However, on the Twitter page, that tweet will say it's coming from Twitter4R. To change that, you'll have to register your app with Twitter (more details to come). And add a init file that alters the Twitter "source" token that Twitter sends you once you register. Don't bother grepping for Twitter4R and changing URLs randomly. It won't work. I promise.

The following code snippets are off the top of my head and may not be absolutely correct.

Authorizing

#return whether username/password is a valid Twitter account
def twitter_auth(username,password)
  c = Twitter::Client.new
  c.authorize(username, password)
end

Sending a tweet

# Send a tweet from username/password. Throws exception if username/password
# is not valid
def send_tweet(username, password, tweet)
  c = Twitter::Client.new(:login => username, :password => password)
  c.status(:post, tweet)
end

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
    • walk to the audience
    • ask a question
    • use props
  • Never
    • after lunch
    • read your slides
    • cover up parts of your slides
    • fiddle with the slide

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?