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.

Friday, December 30, 2011

Inspect all jQuery events on an element

Very useful

$("SELECTOR").data("events");


All bound event handlers are stored in the elements data context under the events key
This can be very useful when debugging with tools like FireBug

$("form").submit(function () { alert('submit form'); });
$("form").data("events");
> Object { submit=[1] }


Resources

Friday, December 2, 2011

Get table and column information in postgres

Use the information_schema catalog - http://www.postgresql.org/docs/9.1/static/information-schema.html

Get table and columns from the public schema




This can be useful, maybe you want to auto generate some text that creates foreign keys based on a naming convention - for instance let's say we have a ruby/rails method called make_fk_unless_exists




The 'code' column would render something like

make_fk_unless_exists :projects, :milestone_id, :milestones
make_fk_unless_exists :tasks, :project_id, :projects
...


Saturday, November 12, 2011

Sample Routes and Links with Rails 3 in the console

The content for this post is all from a gist, hopefully someone finds it useful




Resources


Wednesday, November 9, 2011

Postgres: get the number of days in an interval

-- seconds / 60 = minutes / 60 = hours / 24 = days
select (((EXTRACT(EPOCH FROM INTERVAL '2 years') / 60) / 60) / 24)::integer as number_of_days 

good resource - http://stackoverflow.com/questions/952493/how-do-i-convert-an-interval-into-a-number-of-hours-with-postgres

Saturday, October 15, 2011

Generating barcodes with ruby and rails

Recently I had to convert some functionality from an old MS Access system to a Ruby on Rails application. The Access system generated a report that included a barcode; they were using a barcode font installed on the machine running access. I figured generating the barcode server side in the web app was going to be much nicer than installing barcode fonts on the client browsers. And since this is Ruby, I figured...
There must be a gem for that 
Sure enough, the barby gem. It allows you to output your barcode as png, gif, svg, pdf, etc...

In my case I generated png barcodes and included image references to those in my view files.

Sample code




There is no pixel setting, it uses some other type of unit to determine size; using the xdim, margin and height options you can tweak the size, but I found that it was not very precise - for my use case it was good enough.

The generated barcode does not include the value, it is just the image which can be scanned using a barcode scanner, but it would be nice if there was an option to include the value below that. This is somewhat trivial to add in your view using html.

Overall I was really pleased with this gem!

Resources

Sunday, September 18, 2011

Monday, August 22, 2011

CoffeeScript with Rails 2.3 and Rails 3.0

I just uploaded a sample application that uses guard, coffee-script and a rake task to enable use of coffee-script with a rails 2.3 or 3.0 application. Check out the README file on github for details.

https://github.com/house9/with_coffee


Friday, July 8, 2011

Grow vegetables go to jail?

Oak Park resident Julie Bass now faces serious charges for setting up a vegetable garden in her front yard.

Help her out sign the petition here: http://www.thepetitionsite.com/1/oak-park-hates-veggies/


We are requesting that the City of Oak Park, MI cease its prosecution against its resident Julie Bass for the supposed crime of growing vegetables in her front yard. The bylaw they are pursuing criminal charges under is poorly written and does not explicitly state that you cannot grow vegetables. The prosecutor representing the city wants to take this case to trial, and the associated charge carries a maximum sentence of 93 days in jail. It would be a travesty for this mother of six to be sentenced to 93 days in jail for the simple act of growing tomatoes in her front yard.

Details about the case can be found at http://oakparkhatesveggies.wordpress.com/

Friday, June 24, 2011

rails 3.1 and ruby-1.9.2-p180 - rake aborted! stack level too deep

Ran into the following error when running rake with a rails 3.1 (rc4) app on ruby-1.9.2-p180 (RVM)

rake aborted! stack level too deep
Full error stack

$> rake --tasks

/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/application.rb:28: warning: already initialized constant DEFAULT_RAKEFILES
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList
/Users/HOME_DIR/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
rake aborted!
stack level too deep

(See full trace by running task with --trace)

Steps to replicate, from the command line
  • rails new sample_app
  • cd sample_app
  • rake --tasks
The solution, prefix calls to rake with bundle exec
bundle exec rake --tasks
Resources

Thursday, June 16, 2011

rails 3.1 asset gem

Package up assets into a gem for use in rails 3.1 applications. Example uses javascript files, but the same should work for images and css.

I recommend you click the HD link on the player and view it on Vimeo in full screen mode, this embed version is not so crisp.


Resources

Wednesday, June 1, 2011

robocopy fix for exit code of 2

Sometimes you want to use robocopy from nant, a sql job or another build tool, robocopy will return 2 during a successful run, this gets interpreted as an error, a google search on the issue returned this article Fixing Robocopy for SQL Server Jobs.

Robocopy is now installed by default on Windows7 and Windows Server 2008
http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

here is robocopy_fix.bat based on the code in the "Fixing Robocopy for SQL Server Jobs" article


Sunday, May 29, 2011

rails 3.1 javascript execution

Looking at a few different ways to execute javascript in rails 3.1. By default all javascript is compiled into one file and embedded in anonymous functions which all execute on each page.

We often want to be selective in how our javascript executes, based on controller and actions. We look at 3 different approaches

  • use selectors based on form id
  • use selectors based on css classes on the body
  • namespaced javascript objects

if you know of any other approaches I would love to hear those as well

I recommend you click the HD link on the player and view it on Vimeo in full screen mode, this embed version is not so crisp.


Resources

Thursday, May 26, 2011

rails 3.1 asset pipeline

a quick look at app, lib, vendor and gem assets for rails 3.1 rc1

It is a pretty rough screen cast, but hopefully has some useful information for you

I recommend you click the HD link on the player and view it on Vimeo in full screen mode, this embed version is not so crisp.


Resources:


UPDATE: see "Unholy Rails: External Scripts, jQuery Plugins, and Page-Specific JavaScript" for a detailed look at using the asset pipeline with rails. 

Wednesday, May 25, 2011

Stream Tennis - 2011 Roland Garros

if your ISP supports ESPN3 they have live and replay streams for 2011 Roland Garros

Sunday, May 8, 2011

AT&T site has some serious issues

I went to check on the price of DSL, I've been a long time Comcast customer and getting tired of the high cost. So I went to check it out on AT&T - all I can say is WTF?

Select 'DSL without phone', but then my choices are everything except what I am looking for?
I think they need to go back and do some more QA


Now I get to choose my phone service - WTF: I selected 'without phone service' for a reason

Tuesday, May 3, 2011

Simple.Data and MongoDB

Get really dynamic with Simple.Data and MongoDB

took me awhile to figure out the proper way to establish a connection with Simple.Data.MongoDB




Resources

You can install all of the dlls using Nuget, search for Simple.Data.MongoDB and install that package it will bring in the rest

Some of the errors I received on my journey

From Simple.Data
Message=No valid exports were found that match the constraint '((exportDefinition.ContractName == "Ado") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Simple.Data.Adapter".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.
And from mongo driver when my connection string was not in the correct format, I was using the wrong port
Message=No connection could be made because the target machine actively refused it 127.0.0.1:

Friday, April 22, 2011

Fixing asp.net MVC AuthorizeAttribute

With very little code we can fix asp.net MVC AuthorizeAttribute
What problems does it have? Too much redirection.

  • When making ajax calls a HTTP 401 (Unauthorized) would be better than a redirection
  • If I am already logged in but access a secure resource (controller / action) redirecting to the login page is far from ideal, an access denied view makes more sense
When is the built in redirection appropriate? When making standard HTTP request and the user is not authenticated.

it turns out it is relatively easy to fix these issues
  • inherit AuthorizeAttribute
  • override HandleUnauthorizedRequest
#1: Ajax request should not return redirection / html response

if the user cannot authorize an action and the request is made via ajax we don't want 200 or 302 response codes

we do want 401 Unauthorized, but we have to settle for a 403 Forbidden

The code to fix this

#2: Authenticated users should not redirect to the login page, they should get an Access Denied page
The code to fix this

Turns out very little code is needed - but seems like some of this should just be built in? Using the 401 response won't work because the asp mvc framework must be picking that up later on and forcing the redirection to the login page, the 403 is not ideal but it is effective.

The code for our class - AuthorizeFor


Usage of our AuthorizeFor attribute


Resources

Friday, April 15, 2011

Log: Wildlife sightings summer 2010

Came across some notes from my vacation last summer, figured I might as well post them on the net (better late then never). Not in any order and contains both spelling and grammer errors, enjoy:


2010-06-27 UT,AZ,ID:
Swainsons Hawk
Black Throated Sparrow

2010-06-30 Zion
Rocky Mountain Bighorn Sheep

2010-07-01 Uinta, UT:
Tanager
Kestrel
Robins

2010-07-01 Near Yellowstone:
Bald Eagle
Osprey

2010-07-01 - 2010-07-04 Yellowstone:
Grizzley Bear + 2 cubs
Girizley Bear + 3 cubs
Red Tail
Gray Jay
Mtn Blue Bird
Mule Deer
Cyotes
Otters
Junco
Common Muskrat
Deer Mouse
Chipping Sparrow
Cassins Finch
Cliff Swallow
Brewers Blackbird
Cowbird

2010-07-04 Leaving Yellowstone -> Cody, WY:
Black Bears
Sandhill Cranes
2 Coopers Hawks
2 Golden Eagles
Harrier (Male)
Waxwings
Terns

2010-07-06 Big Horn National Forest, WY:
Moose
Marmots

we went on to the Black Hills of South Dakota, Montana, and Alberta after this, but I must have stopped keeping track of sightings, there were plenty more...

Saturday, April 9, 2011

Notes - TeamCity setup on Ubuntu

Notes from setting up TeamCity on Ubuntu

TeamCity on Ubuntu
==================================================================
Go to http://www.jetbrains.com/teamcity/download/ and download the linux distribution

set JAVA_HOME : update .bashrc add the following lines
--------------------------
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk/bin/java
export PATH=$PATH:/usr/lib/jvm/java-1.6.0-openjdk/bin

tar xfz TeamCity-6.0.3.tar.gz
put extracted TeamCity directory under ~/TeamCity

open terminal and run bin/runAll.sh start from the ~/TeamCity directory

install tcWebHook plugin
==================================================================
http://tcplugins.sourceforge.net/files/tcWebHooks
- http://sourceforge.net/apps/trac/tcplugins/wiki/TcWebHooks

create directory at ~/.BuildServer/plugins - tcWebHooks
put the jar file in that directory
restart the teamcity server
there should be a new tab 'web hooks' on the build results, not in the admin section

Some notes - Ubuntu install rails 3 environment

Had this on my desktop, notes to set up Ubuntu install rails 3 environment

Ubuntu install rails 3 environment
================================================

1) Get RVM installed with ruby 1.9.2
 - http://www.christopherirish.com/2010/08/25/how-to-install-rvm-on-ubuntu-10-04/

2) Install Rails 3 gem
 - gem install rails --no-rdoc --no-ri
 - .... Successfully installed rails-3.0.5 ... 23 gems installed

3) Install redcar 'ruby ide'
 - check out
 - http://azazeal.xelixis.net/post/How-to-install-Redcar-editor-under-Ubuntu-1010-with-RVM.aspx
 - for my situation I am only installing it on ruby 1.9.2, if you plan to run multiple versions of ruby this probably will not work when you have your rvm switched to another version
  - gem install redcar --no-rdoc --no-ri
  - redcar install
 - now you should be able to type redcar at the terminal to launch the gui
 - lets make a desktop shortcut
  - right click on the desktop : Create Launcher
   - Type: Application
   - Name: Redcar
   - Command: /home/YOUR_USER_NAME/.rvm/gems/ruby-1.9.2-head/gems/redcar-0.11/bin/redcar
   - Comment: Ruby IDE
  - need a tight icon for our launcher
   - right click > Properties > click the emblem icon
   - Path: /home/YOUR_USER_NAME/.rvm/gems/ruby-1.9.2-head/gems/redcar-0.11/share/icons/redcar-icon-beta.png
  - drag the desktop icon up to the launcher bar if you want one there as well
   - need to set the icon path again for that one

4) Create a rails application 
 - mkdir projects; cd projects
 - rails new sample_app_01; cd sample_app_01
 - in redcar > File > Open Directory > projects/sample_app_01
  - ctrl+T > type Gem > open Gemfile
  - verify line : gem 'sqlite3'
 - back to the terminal
  - bundle 
  - rails g scaffold post title:string body:text
  - rake db:migrate
  - rails s
 - in a browser go to http://localhost:3000/posts


Sorry the links above are not hot, just cut and paste from my notes into a pre tag - quick and dirty

Friday, April 8, 2011

Could not find generator delayed_job_migration.

Maybe this post will help somebody? just installed delayed_job on a rails 3 application. The readme for delayed_job is for the older version, here is a link to the newer docs.

Running this command
rails g delayed_job_migration
Returned this error
Could not find generator delayed_job_migration.
With rails 3 the command should be
rails g delayed_job

Thursday, April 7, 2011

Ping Guest OS from Host OS with VirtualBox

I am running a host Windows 7 machine with a Guest Windows Server 2008 RC2. The guest machine is hosted inside of VirtualBox. It appears that this issue can occur with any number of OS host or guest machines.

From the guest machine I could access the internet and access the host machine, but I could not ping or access the guest machine from the host. Turns out there is a network setting that needs to be changed.

On the guests 'container' go to Devices > Network Adapters


Then change 'Attached to' from 'NAT' to 'Bridged Adapter'


at that point you should be good to go

Resources

Tuesday, March 29, 2011

Add tf.exe and other .net command line tools to your powershell path

I really don't like cmd.exe, it is difficult to work with. PowerShell ISE is much nicer and the bonus is you can run non powershell programs from this environment as well.

I needed to run some TFS commands, adding the ide directory to the path is easy
$env:path += ";C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
another directory you might want to add if you are messing about with IIS7

$env:path += ";C:\Windows\System32\inetsrv" 
now you can do things like recycle all of the AppPools on your machine

appcmd list apppool /xml | appcmd recycle apppool /in

Rows and Columns with CSS

here is a code snippet for creating rows and columns with css - I guess you could say this is a table?




Resources

Tuesday, March 15, 2011

asp mvc jquery from cdn with fallback to localhost

Paul Irish has some nice code for loading jquery from cdn but then falling back to localhost if it cannot be loaded from cdn. Check it out here.

For asp mvc you usually also want jquery.valdiater and possibly unobtrusive validation as well. Here is an html helper to generate html mark up that handles loading these via cdn with fallback

The helper



Usage, most likely from your layout file



And the rendered html

Monday, March 14, 2011

Powershell script to generate a TODO report

You can use this from your CI build process, help keep the code base clean. I am a big fan of the TODO: comment, but you don't want too many building up in the code base at some point you either need 'TO DO IT' or else forget about it.




the above script is excluding all files found under lib or Test directories, and selecting only a subset of file types. Modify to your needs

Friday, March 11, 2011

MSTest output result to HTML

MSTest generates trx (xml) files which can be viewed in Visual Studio. But often you will be executing MSTest from the command line via your Continuous Integration (CI) server and you will want to view them in an html format outside Visual Studio.

trx2html to the rescue!

  • download the zip file here - http://trx2html.codeplex.com/
  • unzip and put the files somewhere
    • I choose C:\Program Files (x86)\trx2html
  • execute it from the command line 

# in YourTestProject\bin\Release
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /testcontainer:YourTestProject.dll /resultsfile:TestResult.trx

"C:\Program Files (x86)\trx2html\0.6\trx2html.exe" TestResult.trx
# outputs TestResult.trx.htm


Wednesday, March 9, 2011

Visual Studio Solution Items in a sub directory

Visual Studio Solutions have the "Add New Solution Folder" option.



I don't know about you but this makes me think it is going to create a physical directory on the hard drive to emulate what is in the solution, but this is not the case.



The thing that really drives me crazy is if you try to add Test1.txt to the SubFolder it will throw an error because it is really trying to write to the root directory. I think solution folders are only really supposed to be used to organize Visual Studio projects.

In my case I want to have a set of files that are not really part of a Visual Studio project but I want them available in the solution. It turns out there is a Project type called "Empty Project".


This is exactly what the doctor ordered!

You will probably want to do one additional step. Set this "Empty Project" to not build, otherwise you will get a compile time error. Right click on the Solution > Properties > Configuration Properties > Configuration, then un-check the "Build" for this project.

Found out about this from this stackoverflow post.

Here is a good link explaining what you would use a solution folder for, besides a ReadMe.txt

Sunday, March 6, 2011

Ergonomic keyboard for the Mac

The keyboards that come with Macs look really nice, the quality seems pretty good, but I just cannot use a flat keyboard, after a few days my wrists and hands started complaining big time.

After some searching I came across the Kinesis Freestyle keyboard, they make one with Windows layout and another with Mac layout. They are not cheap, however I use a keyboard all day, every day so for me it is worth the money.

If you get the Freestyle you also need to get the Freestyle VIP - Keyboard accessories kit, otherwise you basically just have a flat keyboard again
The VIP accessory kit will give you 10 and 15 degree angles, they also have some other accessory kits that will give you up to 90 degree angle, I believe that kit is very expensive, the 15 degree works fine for me, but the Ascent kit looks interesting.

Eight inches of cable between each side of the keyboard, put them where you want

pivot point if you want them close and asymmetrical

10 degree

15 degree



Thursday, March 3, 2011

varchar (MAX) SqlParameter length

I am using log4net and the AdoNetAppender to log all entries to MSSQL server. The exception column by default is 2000, sometimes the stack traces get large. Not wanting to lose any information I changed the DDL to use varchar (MAX) but I also had to update the appender configuration. Using a size of -1 for the @exception parameter seemed to do the trick.



Resources

Friday, February 25, 2011

CQRS with .NET and C#

I've been intrigued with the idea of CQRS for some time; ever since I watched an infoQ presentation by Greg Young on the subject. What is CQRS?
Command-Query Responsibility Segregation
See the links below to for more information from the experts.

Over the last month I've actually had the opportunity to work with CQRS, so far I am really enjoying it. Separating your reads from your writes is truly liberating! Listed below are a bunch of resources related to CQRS:

Informational:

Monday, February 21, 2011

OSHA Safety Software

I've been working on this project off and on for quite sometime. If you are a small to mid size business in California and you need Safety Documents and Safety Management Software check out www.safetysanity.com.

Use this code to save $100 off the setup fees
2011-SAVE-100
We've simplified the process of creating a Safety Program; starting with Safety Document creation through managing Employee Training, Equipment Inspections and Accident Reporting.
www.safetysanity.com
Our software application  generates a Safety Program which is compliant with Cal/OSHA regulations. Every business in California is required by law to not only have a Safety Program, but also prove that they are following their program. Safety Sanity makes it easy! Learn more at www.safetysanity.com.

Sunday, February 20, 2011

LibreOffice - the real Open Office

LibreOffice - http://www.libreoffice.org/
LibreOffice is the free power-packed Open Source personal productivity suite for Windows, Macintosh and Linux
this is basically Open Office, but without the Oracle factor