The blog has moved to http://jessehouse.com/ ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Wednesday, November 17, 2010

ASP MVC Razor templates with nested layout and sections

Using ASP MVC 3 with Razor views.

Ran into an issue with nested layouts and wanting to render a section in a top level layout, but define it in the view which uses a 'child' layout (master) page. This was generating a runtime error of:

The following sections have been defined but have not been rendered for the layout page... 

I posted some code to the asp.net forum and github. A nice workaround was supplied by 'Imran Baloch'


Tuesday, November 16, 2010

Automapper Datatable to List

I did a few Google searches for "c# automapper datatable to list" but nothing good showed up right away, maybe this post will help someone in the future?

The solution showed up on stackoverflow here is the link

http://stackoverflow.com/questions/2429194/automapper-mapping-ienumerable-to-datareader-issue

and here is a code snippet



Note that we are actually mapping IDataReader to a list, and DataTable has convenience method to do that for us 'CreateDataReader'


Friday, November 5, 2010

Get the date of the beginning and end of a month using Ruby

Sometimes Ruby blows my mind, I needed to get the start date and end date of the previous month. Guess what Ruby just happens to have methods to handle this - beginning_of_month, end_of_month, there is even beginning_of_quarter and end_of_quarter if you need them!




Friday, October 29, 2010

Remote desktop mac OSX to Ubuntu

There is a good program (free) for remote connections between mac OSX and Ubuntu. It is called Chicken of the VNC - in my case I needed to remote into an Ubuntu (9.04) desktop from my mac.

First step - allow remote access on the Ubuntu machine



Install Chicken of the VNC




Then open the program and type in the IP address of the machine you wish to connect to.
Done - you are now remoted!

The best overload for 'RenderSection' does not have a parameter named 'optional'

I've been taking a look at asp.net mvc 3 beta with razor view templates.

some of the examples on the net are from previous releases and things have changed; one that I came across was the RenderSection method which can be used in layout (master) files

@RenderSection("Header", optional:true)
will throw an exception

The best overload for 'RenderSection' does not have a parameter named 'optional'
the newer syntax for rendering an optional section appears to be

@RenderSection("Header", false) 

Friday, October 22, 2010

jQuery iframe auto height plugin

This week I needed to automatically size the height of an iframe to the height of its contents. After a bunch of Google searches I came across this post from Nathan Smith here; It used jquery but applied the auto height to every iframe on the page, I could not use the code out of the box and so the 'jQuery iframe auto height plugin' was born. I made a few slight changes to the original code and wrapped it in a jquery plugin.

Download from github

http://github.com/house9/jquery-iframe-auto-height

see the README file for usage

Wednesday, October 13, 2010

Geek Desk in Action!

My Geek Desk showed up last week!

I work standing up most of the time, but I do like to sit down a few times through out the day. In the past I used a "Drafting Chair", but they create a funky angle for your legs as your feet must sit on the bottom ring. So far I am really loving the Geek Desk! - check them out at http://www.geekdesk.com/

here is a short vid of the adjustable height desk in operation


and some pics









Thursday, September 30, 2010

VirutalBox - Increase the memory on an existing guest machine

I use VirtualBox to run a guest Windows XP machine on my Mac. When I set up the virtual guest I set it to use 512MB of memory. And of course now I decide I want to bump it to 1GB. I could not find anyway to do this using the GUI but it can be done from the Terminal.

When the virtual machine is not running execute this command
VBoxManage modifyvm XP1 --memory 1024
XP1 is the name of my guest machine, so replace with yours. The memory parameter takes the amount in MB, in this case 1GB

The first time I ran it I received the following error message

ERROR: The machine is not mutable (state is Saved)

Last time I turned off the guest machine I had selected the save state option. You need to Power the virtual machine down before you can run this command.

Wednesday, September 29, 2010

Textmate Go to File now available in Visual Studio 2010

Finally! Visual Studio has a feature similar to Textmates "Go to File" (Command key + T), I love this feature. It means that you rarely need to look around in the project tree for a file, just type part of the file name and bam!



In visual studio it is called "Navigate to" (Ctrl + ,) it takes it one step further and even brings up methods matching the name, not sure if that is a good thing or not, so far so good.



Found out about it here. Guess it has been around for awhile

A code smell - try catch that swallows an exception

Came across a code smell this week - try catch that swallows an exception

and yes the code that it wraps has some issues....

Thursday, September 9, 2010

NFL Live Stream Thursday and Sunday night on NBC

Awesome!

does not seem like NBC or NFL is doing a lot to advertise the official free stream, but here we go!

http://nbcsports.msnbc.com/id/26393211

Saturday, September 4, 2010

2010 US Open live high quality stream

US Open has their high quality stream going again this year!

http://www.usopen.org/en_US/interactive/video/live.html?promo=slamtracker

Friday, September 3, 2010

You have got to be kidding

Just did a search and ended up on msdn


I use Google Chrome for most of my web browsing - the msdn site pops up this 'Ad' to 'upgrade' to IE 8 - LOL!!!



Friday, August 20, 2010

ruby 1.9.2 and rails 3rc with rvm

Get up and running with rails 3 release candidate on ruby 1.9.2

First step install rvm (ruby version manager) - note that rvm does not work on windows, for windows try pik

You will need to wait between each step as installation times will vary

# install 1.9.2 using rvm
 rvm install 1.9.2  
# this installed the official release 1.9.2-p0

# switch to 1.9.2
 rvm 1.9.2 
# gem install rails rc
 gem install rails --pre 

# create a new rails app, in this case 'sample-r3', this differs from older versions of rails; new is a required arg 
 rails new sample-r3 
# navigate to the root of your new rails app
 cd sample-r3 
# install the app dependencies - in this case sqlite3, see Gemfile in the root dir
 bundle install 

# generate a user scaffold, note g is shortcut for generate
 rails g scaffold User name:string email:string 
# create the database table users
 rake db:migrate 
# start up the rails server, note s is shortcut for server
 rails s 

Browse to http://localhost:3000/users and we are up and running and yes the scaffold pages still have the same old look and feel






In the past I have tried installing and running rails3 beta and rc on different versions of ruby and ran into some serious difficulties; but it has been painless on the official release of ruby 1.9.2

As a final step we want to add a .rvmrc file to the root of the rails project, this will force rvm to load the correct ruby version when we are in this directory. This can be quite handy, if we were on a different version of ruby running 'rails s' would create a new rails app directory named 's' instead of running the server; from the terminal run

 echo "rvm 1.9.2" > .rvmrc 

I learned about the .rvmrc file from this post

Thursday, August 19, 2010

Updated Look!

Just switched to a different Blogger Template - much wider and mo better!

Also consolidated my posting, I had 20+ code samples on another blog. Used the Blogger import / export tool which was pretty seamless; needed to move a few code blocks over to gists to get proper formatting but that was it!

Wednesday, August 18, 2010

valid? vs errors.any? in rails

Recently got bit by checking valid? in some rails code, thought I would share.

In this situation I was manually adding to the errors collection of an ActiveRecord object and then calling valid? to see if the object was ok; this is not the normal style of validation on ActiveRecord objects, if I had been playing by the rules valid? would have done what I needed; it would check the current state of my objects attributes and 're-validate' the object.

This screen shot of an irb console session shows the issue I was running into


valid-v-errors-any

Taking a look at the source code for valid? it becomes obvious why the manually added errors get cleared, just not what I expected to happen


valid-source

Wednesday, July 28, 2010

Adjustable Height Desks

Both of these look like pretty sweet adjustable height desks;

- Geek Desk electronic and runs $750 to $800

or

- Airtouch uses air and no electronics - twice the price at $1500

hopefully I'll be able to try one of these out soon

Friday, June 18, 2010

Tuesday, June 1, 2010

Pomodoro Timer application

After reading an article on infoQ, I started using the Pomodoro technique. It works pretty good, but I do still strugle with making my self take a break after the 25 minutes is up.

I recently spent a few days and created a simple timer application to monitor my pomodoros, it is pretty rough around the edges, but good enough for a first release.

I wanted to check out Appcelerator and their Titanium framework, this seemed like a simple enough app to get started with. Titanium allows you to build an app using html, css and javascript then the Titanium framework will 'compile' your code into a desktop application that targets all major operating systems; Windows, Mac and Linux.

In the end I did not really use any of the Titanium Api in my code, just jquery, css and html.


or download the binaries here:

Thursday, May 27, 2010

jsfiddle is awesome!



I had seen some blog posts on jsfiddle before, but just checked it out for the first time, a great way to experiment with javascript code, comes built in with jquery, mootools and more






Monday, May 24, 2010

Snag-it for the Mac

I have used Snag-it on Windows for many years - it is a great product!

During the last year I have been using Ubuntu and Mac and been missing Snag-it; Shutter on Ubuntu is 'ok', but not quite on the same level as Snag-it

I was happy to discover that there was a beta of Snag-it for the Mac


Free right now, been using it for the last month - it seems even better than the version for windows!

Tuesday, April 20, 2010

Need to find real estate comps? www.redfin.com

Need to find real estate comps? www.redfin.com is a sweet site. Not only can you search for new homes on the MLS listings but you can also search previous Sale Records. I don't know of any other site that offers the same functionality. Click the 'More Options' link by the 'Search Listings' button.

Another really nice feature, If you find a bunch of homes for sale in a viewable area on the map, click the 'DOWNLOAD' link to get all of the info in excel (csv).

Uptime and performance monitoring made easy - pingdom.com

This is a nice service - http://pingdom.com/

Get an email or SMS alert if your site is not responding. They ping your site from multiple servers in both North America and Europe.

They offer one free account where you can ping a single url or get one of their payed monthly plans if you have additional sites to monitor.

Wednesday, April 14, 2010

GIMP install on MAC

Don't bother installing GIMP using MacPorts; I started this process and it ran for over an hour before I stopped the install. It has alot of dependencies and MacPorts was busy installing all of them.

Just go to http://gimp.lisanet.de/Website/Download.html and download the package for your OS version

around 75mb download but installed in minutes :)

Tuesday, March 23, 2010

sorting rails view with will_paginate plugin

This solution for sorting data on rails index actions does NOT use ajax. Sometimes sorting with ajax is nice but often it is not actually as user friendly; breaking the browser back button, etc...

Disclaimer 1: this code is probably using all kinds of ruby anti-patterns :) - but it is a very simple implementation and so I just went with it...

Disclaimer 2: the title of the post might be a little miss leading as you can use this with or without the will_paginate plugin. In my case I am using it with the will_paginate plugin - and I highly recommend it!

put this file in your rails lib directory /lib/sort_index.rb

in your controller code, set up the SortIndex::Config (you can have more than one if you have multiple actions that need to support sorting

then in your view code render your table headers using the sort object

Does not support the following:
  • additional attributes on the anchor tags
  • additional attributes on the table header tags
  • additional query string parameters - might add this later, would be nice for search results

Monday, March 15, 2010

Digg style css for will_paginate plugin

Just started using the will_paginate plugin for my rails application. I wanted a Flickr or Digg style applied to the paging controls, did not find anything that came 'out 0f the box'. After a few google searches I came across this link which had an example - apparently from an older version of the README file.

here is that css for reference

.

Thursday, March 11, 2010

exclude .svn results with egrep recursive search

The exclude-dir option works nicely, I was previously was using --exclude and it would include some sub-dir .svn files
egrep --exclude-dir=\.svn -r -n {search-criteria} {directory}
i.e. find all TODO comments in the current directory and all sub directories
egrep --exclude-dir=\.svn -r -n TODO .

Found this in the comments on this post - http://antoniolorusso.com/2008/05/12/grep-excluding-svn-dirs/

.

Friday, March 5, 2010

cut back on the blog reading

I had 200+ subscriptions in my rss reader - way too many
I just cut it back to a short list. No doubt the list will start to grow again...




Thursday, March 4, 2010

"Impossible to connect to file" error opening dBase file with open office on ubuntu

Turns out the ubuntu distribution of Open Office does not include the 'Database' product by default, it tries to open the file with the spread sheet program which can not handle it and errors with "Impossible to connect to file". The fix is to install the database product
System -> Administration -> Synaptic Package Manager
install openoffice.org-base
After installing you should see the 'Open Office.org Database' under Applications menu



Found the answer from this post.

Wednesday, February 17, 2010

rails send_data fails on IE when SSL enabled

Came across a nasty issue using rails send_data with IE. Everything worked fine until the pages were running under SSL / HTTPS. Turns out the issue is with file download over SSL when the Cache-Control and Pragma html headers are set to no-cache.

The error message from IE
Internet Explorer was unable to open this site. The requested site is either unavailable or cannot be found. Please try again later.
The fix...
# before calling send_data
response.headers.delete("Pragma")
response.headers.delete('Cache-Control')
This issue is not restricted to rails, any server side code that sets no-cache is subject to the same issue. Glad I was able to find this post.

see also kb-316431

Tuesday, February 16, 2010

Google Webmaster Tools Sitemap.xml issues

After uploading my sitemap.xml file to Google Webmaster Tools I received the following error message and no additional error details were included:

Error: The last attempt at downloading the Sitemap failed. The details below are representative of the last successful download.

I searched around a bit and found a forum post where someone said they get this error 'sometimes', but after switching to use a gzip formatted sitemap.xml file the error went away

on ubuntu

gzip ./sitemap.xml

compresses the file to ./sitemap.xml.gz and deletes the sitemap.xml file by default

after uploading Google was able to process without issue

Tuesday, January 26, 2010

install older version of rails and without the docs

I always forget these

sudo gem install --no-rdoc --no-ri --version 2.3.4 rails

Monday, January 18, 2010

Neat site to generate graphics

I needed to generate a sign up button - this site is so much easier than opening photoshop


Thanks cooltext!

Wednesday, January 6, 2010

Ruby Http Get with Net::HTTP


Resources



require 'net/http'
require 'uri'

def get_html_content(requested_url)
url = URI.parse(requested_url)
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
the_request = Net::HTTP::Get.new(full_path)

the_response = Net::HTTP.start(url.host, url.port) { |http|
http.request(the_request)
}

raise "Response was not 200, response was #{the_response.code}" if the_response.code != "200"
return the_response.body
end

# this will fail with ArgumentError: HTTP request path is empty
s = get_html_content("http://www.google.com")
# these should be fine
s = get_html_content("http://www.google.com/")
s = get_html_content("http://github.com/search?q=http")
# above code does not handle redirects but raises exception for non-200
s = get_html_content("http://www.yahoo.com/") # http 302

Ruby Regex to remove script tags


Resources