programming


16
Feb 10

How to fix the Windows desktop context menu after installing Samsung MagicRotation

With the new computer setup I have at work, I needed to have one of my monitors rotated 90° so it would fit until a better solution was attempted. The desktop wasn’t rotating though because I hadn’t installed Samsung’s MagicRotation software. So I did.

After doing so, I noticed that the context menu on my desktop was way screwed up. All the text had shifted over to the right and was unreadable.

Continue reading →


26
Oct 09

how to think of “git diff” using branch names

This post is more of a note to myself to remember how to think of certain git diff commands but it might be useful to other newbie-ish users of git. This is from my own experimentation, since I couldn’t find a good newbie-understandable explanation of this on the Interwebs.

git diff <branch name> – means what would change if we applied the current working HEAD of the branch we are on, including all unstaged/uncommitted changes, to the named branch.

git diff <branch 1> <branch 2> – means what would change if we applied <branch 2> onto <branch 1>


4
Jul 09

jQuery Tools’ Scrollable as a circular carousel

jQuery Tools - Scrollable
I recently discovered a new jQuery effect library named jQuery Tools. It’s like jQuery UI but more focused on the core items that can improve the usefulness of a website. Tabs, tooltips, scrollables, overlays, and a few more. I began using it this week to replace a carousel on my website at work. My website uses several different javascript libraries for these very same techniques but they’re all from different authors. I like the idea of having a single library instead of tracking several so I’ve started converting those libraries over to jQuery Tools. The first to go was the homepage carousel.

After replacing the old carousel with the new one, I discovered that the new code didn’t provide a way to do circular carousels. It had a fixed beginning and an end. You could program it to loop but when you got to the end and told it to move to the right again it would actually scroll really fast to the left until the first item was back on the left edge. In a circular carousel, if you’re on the last item, you want the first item to show up to the right of the last item if you move past the end, looping forever.

So, with the code being released under the GPL opensource license, I did what any self-respecting developer would do. I patched the code to make it circular when you told it you wanted it to loop. This is a change from the old way it worked so people using this library and expecting the old functionality should be warned. I could have added a “loopmethod” config variable but I didn’t want to introduce any new configuration variables without approval from the true author. As it is, I only added one new method – a way to move a specific item to the left most item using an unnoticeable jump, instead of the default scroll. This is part of the magic that makes it able to simulate a circular loop. Compressed with the YUI Javascript Compressor, it only adds 600-ish bytes to the code. Even less, when you finally gzip it. Acceptable for the return in functionality, IMNSHO.

I haven’t tested it 100%, notably the code where you are using the custom API methods, but it SHOULD be good to go by just replacing your old version. YMMV. I will be submitting this to the author of jQuery Tools so he can evaluate it for the next revision of Scrollable. In the mean time, test it, use it, let me know what you think.

Download the Scrollable javascript

UPDATE 7/6 – Added autoscroll pausing when hovering over the specific page nav links, just like when hovering over the “next” and “previous” links.

UPDATE 7/6 #2 – Fixed a problem with the “disabledClass” on prev/next/prevPage/nextPage when looping. Those elements should always appear when looping and you have them in the html.

UPDATE 7/7 – I’ve pushed my updated version of the code to my employer’s website so you can see the circular ability in action. Visit http://www.ruckuswireless.com. The homepage has the page nav links underneath while the “Solutions”, “Verticals”, “TechTalk”, “Products”, “Ruck(us)” and “Management” page – under Ruck(us) – do not use the page nav links. Note that on the “Ruck(us)” page, the “next” and “previous” links are automatically hidden because there aren’t more items than are already displayed.


9
Apr 09

Fixing Snarl and autotest_menu in windows

I’ve been trying to get ZenSpider autotest and Windows to play nice for a while. First, I had the problem where autotest would only run once and not stick around waiting for updates to my code. That was fixed by Luke Pearce. He commented on a previous post with his fix and I can confirm that it works. Thanx Luke!

I encountered another problem now. When I ran my autotest but tried to shut it down by hitting Control-C twice in a row, the tests would just reset and run again. Double Control-C is supposed to interrupt the process and allow me to shut it down. This it did not do.
Continue reading →


6
Apr 09

Turning off the Rails 2.3.2 BacktraceCleaner

I had a situation today where, when running some functional tests, the error backtrace being displayed was not helpful at ALL. I was defining a layout for a controller as a symbol instead of a string like I should have been using. You use a string when you are just saying “Use this layout” and you use a symbol when you have a method to call that responds with the layout to use. The error I was getting was …

NoMethodError: undefined method `admin' for #<Admin::RegistrationsController>

but what was the first line that came up in the backtrace?

app/controllers/admin/registrations_controller.rb:18:in `show'

This was giving me fits. There’s no call to ‘admin’ in the ’show’ method. I knew there had to be something else so I searched for how to see more of the backtrace.

The BacktraceCleaner introduced in Rails 2.3.2 cleans out backtrace lines coming from the Rails framework (Railties, etc). This is usually what you want. However, I was sure that my error was coming from somewhere in the framework. Turns out it’s really simple to turn off the backtrace cleaner. Add this line in a ’setup’ method in your test_helper.rb file.

Rails.backtrace_cleaner.remove_silencers!

Very simple, very easy. My name is Chef Tell. :)


2
Apr 09

Rails 2.3.2 and testing with assert_select_email

I upgraded a project to Rails 2.3.2 a while back and have been getting the following error when running some unit tests…

NoMethodError: undefined method `assert_select_email' for #<UserMailerTest>

I posted to the rubyonrails-talk google group but never got a response, and I was not the first to post about this problem to that group. However I found someone else commenting on this in an rspec lighthouse ticket and they’d fixed it for their setup. It was an easy conversion to non-rspec and here’s the line you need to add to your test/test_helper.rb file

include ActionController::Assertions::SelectorAssertions

I’m not sure why it’s broken but it appears to have regressed in one of the Rails 2.3.2 RCs.


24
Nov 08

How I block people from visiting a website

Inspired by the article Block a Website for Everyone But You over at CSS Tricks, I thought I’d post my way of blocking people from accessing my websites while I work on them.

Chris Coyier over at CSS Tricks uses the following code in his .htaccess file to block visitors.

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^71\.225\.113\.171
RewriteCond %{REMOTE_HOST} !^71\.185\.239\.212
RewriteCond %{REMOTE_HOST} !^69\.253\.223\.254
RewriteCond %{REQUEST_URI} !/comingsoon\.html$
RewriteRule .* /comingsoon.html [R=302,L]

What he’s doing there is checking for specific IP addresses that are allowed to see the website but everyone else is sent to the “comingsoon.html” webpage. This is great for people who have specific IP addresses but if you’re behind a proxy like I am at work then everyone else with you behind that proxy can still see the site.

I find it much easier to redirect everyone but check for a custom cookie that I can set using the Webdeveloper Firefox extension. That way I can check to make sure that the redirect to the maintenance page is actually working. Here’s the relevant code that I use (taken from a RoR tutorial of old)

RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteCond %{HTTP_COOKIE} !^.*access_cookie=1.*$
RewriteRule ^.*$ /maintenance.html [L]

where the text “access_cookie” (sans quotes) would be whatever cookie name you want to use. I just create a “session cookie” set to a value of “1″ (or whatever you want to make it) and check for it’s existence.

That gets around the problem of DHCP granted or spoofed IP addresses. Sure a cookie is easy to add but if you make the name and/or value sufficiently difficult to guess, no one is getting in.

Now just add your cookie.

Note in the image that I have set it to be a “session cookie”. This helps when you forget to delete the cookie. Just close your tab (FF) or browser (IE), reopen it and the cookie will be gone.

Oh yeah. The other thing that my .htaccess code does is, on the first line, check for the existence of the “maintenance.html” file. I don’t want to have to add and remove this code everytime I want to take the site down. It’s much easier to just have this code permanently in my .htaccess file and then upload the file that people will see when the site is down. I then delete it when the site is ready to be reopened. This is all performed using a custom Capistrano command that I run when I’m ready to deploy a new version.


3
Oct 08

note to self re: git unpacker error

when you get an unpacker error “unpack failed” and git is being RIDICULOUSLY CRYPTIC (as usual) about it’s error, try this.

git repack remote/origin/master

I’m sick of pulling my hair out over this.


10
Jul 08

log_buddy and Windows

I recently started playing around with the log_buddy gem for Rails and because my development machine is on windows, the “d” method wasn’t playing nice with some paths.  it didn’t like paths that included the drive letter.

this is a sample of a line that would cause log_buddy to barf.  it just so happens to also be the line that causes the error.  :)

c:/ruby/lib/ruby/gems/1.8/gems/log_buddy-0.0.5/lib/log_buddy.rb:98:in `read_line'

the original line looked like this…

file, line_number = frame.split(/:/, 2)

the fix is to replace that line with

file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse

yeah.  ugly, and maybe could be written better but it works for me.

now if only I could get log_buddy to output good inspections of objects I toss to it… like “current_user”.  I’m prolly using it wrong right now, but this isn’t helpful…

current_user = '#<User:0x47143d8>'

just saying.  :)

UPDATE: I monkeypatched log_buddy to fix this functionality. I created a “RAILS_ROOT/lib/log_buddy_extensions.rb” file with the following code.

class LogBuddy

  private

  # Return the calling line
  def self.read_line(frame)
    file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse
    line_number = line_number.to_i
    lines = File.readlines(file)
    lines[line_number - 1]
  end

end

and I figured out that the “current_user” line above shouldn’t be …

d { current_user }

it should be

d { current_user.inspect }

that outputs what I want …

current_user.inspect = '#<User id: 1, login: "matte", email: "matte@localhost", crypted_password: "...", salt: "...", created_at: "2007-08-30 18:23:32", updated_at: "2008-07-08 18:57:45", remember_token: "...", remember_token_expires_at: "2008-07-22 18:57:45", name: "...", password_reset_code: nil, company_id: 2, active: true>'


13
May 08

XSendFile note

I coulda had a V8Note to everyone using Apache and the XSendFile module. If you’ve included the module and are getting 0-byte files, like I was today, make sure you have the following lines in your VirtualHost config

XSendFile on
XSendFileAllowAbove on

The website needs to know you want to use the module. Duh. :)