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.
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

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'


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....

Monday, March 2, 2009

jqueryUI effect error with Google Chrome and Safari

Ran into a strange issue using jqueryUI highlight effect, the issue only occurred with Webkit browsers (Google Chrome and Safari) and only when I was manipulating the background property of the element that was being highlighted.

Using a slightly modified version of the demo. I tweak the background image before applying the highlight effect

$("#highlight").click(function() {
$(this).css("background", "url(some_image.png) no-repeat");
$(this).effect("highlight");
});
This resulted in the highlight appearing but not going away. Then checking it in the debugger the following javascript error was being generated - "Uncaught TypeError: Cannot read property '0' of undefined," Changing the background manipulation to the following fixed the issue.

$(this).css("background-image", "url(some_image.png)");
$(this).css("background-repeat", "no-repeat");
$(this).effect("highlight");

Update 2009-03-06: You also need to make sure that if there is an existing style on the element being highlighted it is using the more verbose style tags of background-image and background-repeat or the same error will be encountered

Sunday, October 19, 2008

Assembla to start charging for all private services

well I guess it had to happen sooner or later - Assembla to start charging for all private services

they do offer a great service and the fact that it has been free up until now has been really great!
I can understand why they need to start charging and it still seems very reasonable,
but it would be nicer if it was based purely on disk space instead of per project

read more here

Saturday, May 10, 2008

Python MVC web framework - web2py

Recently I did a google search for a Python MVC web framework. I have never done any coding in Python but it seems to be one of the primary languages used at Google and currently the only language supported on the Google App Engine so it seemed worth getting familiar with.

Django seems to be one of the most robust python mvc frameworks around at this time and I was going to dive in and create a small toy application with it, but then I stumbled across a comment on some blog that talked about the web2py MVC framework, still in it's infancy, development is very active on the project. It seems very easy to get up to speed with the framework and even someone who does not know Python can get a simple site up and running.

I love this graphic from one of the pdfs on the site

The feature list taken directly from the site
  • No installation, no configuration, no dependencies. All in one package. You can run it off a USB drive
  • Runs on Windows, OSX, Unix/Linux, and Windows CE phones.
  • Allows development, debugging, testing, deployment, maintenance and administration, including database administration, via the provided web interface.
  • Enforces good Software Engineer practices, like the Model-View-Controller design, validation and self-submission of forms.
  • Strong on security. Prevents the most common types of vulnerabilities: Cross Site Scripting, Injection Flaws, and Malicious File Execution.
  • Talks HTML, XML, RSS, ATOM, AJAX, JSON, RTF, CSV, WIKI, XML-RPC, REST, Flash, etc.
  • Dynamically and transparently generates SQL queries for you for SQLite, MySQL, PostgreSQL and Oracle. Even creates and alters tables for you when required. Performs automatic transactions.
  • Allows you to create apps easily, byte-code compile them, and distribute them in open or closed source under any license you like.
  • Faster then the competition, designed for small as well as large projects, includes the ability to upload/download/stream large files, internationalization support, distributed transactions, ...
Web2py is worth checking out!

.

Monday, March 3, 2008

'vincent-vega' is now 'The Tarantino Project'

The vincent-vega database change management project has been consolidated into the Tarantino project. code is available at http://code.google.com/p/tarantino/ I can't wait to check it out!

Saturday, February 16, 2008

Rails like migrations in the .NET world

I have done a few very small projects with rails; one of the really nice features with rails is database migrations

There are a few ports of rails migrations to the .NET world (that's where I spend alot of my time). I have not used any of these for 'real' but I have 'sampled' them. They all look promising but it seems like there is not very much activity on these projects.

Migratordotnet
http://code.google.com/p/migratordotnet/

RikMigrations
http://www.rikware.com/RikMigrations.html

SubSonic Migrations
I don't know if they ever did incorporate this into the official release of sub sonic? maybe it will come in a future release
http://blog.wekeroad.com/2007/10/03/subsonic-migrate-me/

I recently stumbled across vincent-vega and have begun using it on a small project and am planning to incorporate it into some of our larger applications. It is an Nant task that handles database versioning. It is not a migration in the same way as the other solutions as it uses actual sql scripts for all schema changes instead of c# code, which makes sense to me!

Vincent-Vega
[update 2008/10/14]
vincent-vega is now part of the tarantino project.
http://code.google.com/p/tarantino/
Thanks for the heads up Dan!
[/update]

 

Rhino.Mocks basics

Rhino.Mocks basics - I just threw this together real quick; personal reference material
http://house9-code-samples.blogspot.com/2008/02/rhinomocks-basics.html

The official Rhino Mocks Documentation is very good and available here
http://www.ayende.com/Wiki/(S(33lpuuuz4itdtnjwlncidy55))/Default.aspx?Page=Rhino+Mocks+Documentation

Rhino.Mocks - the basics

Started using Rhino.Mocks recently (Awesome!!!) - just wanted to list a few of the basics; the official Rhino Mocks Documentation is very good and available here. These examples are a bit rough, they have not been compiled; there may be typos.

using
using Rhino.Mocks;

The mock repository
// use the mock repository to create the mocked objects
MockRepository mocks = new Rhino.Mocks.MockRepository();
// example
System.Object someObject = mocks.CreateMock();
// set up the behaviour you want from calls to your mocked object 
Rhino.Mocks.Expect.Call(someObject.Equals(someParameter)).Return(false);
// then don't forget
mocks.ReplayAll();
// now do stuff that calls your mocked object Equals method
...

Mock a call to the db
// create our mocked repository object - IProductRepository, the real one calls the db
IProductRepository repository = mocks.CreateMock();
// tell rhino.mocks when we call the method GetProduct with the argument 33 to return null
Rhino.Mocks.Expect.Call(repository.GetProduct(33)).Return(null);
// get the mocking ready
mocks.ReplayAll();
// pass our mock to our product service layer
ProductService service = new ProductService(repository);
// service.GetProduct makes a call to the mocked repository.GetProduct which will return null
IProduct product = service.GetProduct(33);
// should be null
Assert.IsNull(product);

Ignore any arguments
// any call to GetProduct will return null no matter the value of the arg
Rhino.Mocks.Expect.Call(repository.GetProduct(null)).Return(null).IgnoreArguments();

mock a method that returns void
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// this void call will handle our product 003092
Rhino.Mocks.Expect.Call(delegate { repository.Save(product); });
// this void call will handle any argument
Rhino.Mocks.Expect.Call(delegate { repository.Save(null); }).IgnoreArguments();

Handle multiple calls to the same method
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// note the .Repeat.Any()
Rhino.Mocks.Expect.Call(repository.GetProduct("003092")).Return(product).Repeat.Any();
// send the mock to our product service object
ProductService service = new ProductService(repository);
// find by sku calls GetProduct on the mocked Product repository
IProduct beer = service.FindBySku("003092");
// find decent beer calls GetProduct on the mocked Product repository also
IProduct decentBeer = service.FindDecentBeer();

Partial Mock
// create a partial mock with constructor args (our product repository again)
IProductService service = mocks.PartialMock(repository);
// our test case data
IUser loggedOnUser = new User("John", "Doe", CustomerType.Gold);
// mock product service calls to GetLoggedOnUser
Rhino.Mocks.Expect.Call(service.GetLoggedOnUser()).Return(loggedOnUser);
// get the mocking ready
mocks.ReplayAll();
// now GetDiscount is not a mocked method but it does call the mocked GetLoggedOnUser method
decimal discount = service.GetDiscount();
// assert the result
Assert.AreSame(44.4M, discount, "Gold customer discount not correct?");
// NOTE: this will not work (compile) unless the mocked method GetLoggedOnUser is public

SyntaxHighlighter and Google Blogger

Just started using the SyntaxHighlighter on my code samples blog - here is some quick notes on what I had to do

One issue I ran into was that the google blogger automatically adds br tags where newlines appear in any content - makes the code pretty much unreadable, but the fix is well documented and easy to implement - http://code.google.com/p/syntaxhighlighter/wiki/BloggerMode

Saturday, December 8, 2007

mysql migration toolkit

I am using the mysql migration toolkit to transfer a database from MSSQL 2005 over to MySQL database. Ran into an issue with the port, by default the tool wants to use 1433 (MSSQL 2000 default), but it looks like 2005 uses a default port of 1434 (well it is more complicated then that http://technet.microsoft.com/en-us/library/ms165724.aspx) - you can use the stored procedure xp_readerrorlog to verify the port your database is listening on - one of the rows in the text column of the result should be something like 'Server is listening on [ 127.0.0.1 1434].'

anyhow after changing the port number everything else was smooth sailing, yeah right...
once I got to the reverse engineer stage then this java stack came up, looks like it still doesn't like the connection string, even though I have already authenticated with it?

Initializing JDBC driver ...
Driver class MS SQL JDBC Driver
Opening connection ...
Connection jdbc:jtds:sqlserver://127.0.0.1:1434/databasename;user=sa;password=;charset=utf-8;
Initializing JDBC driver ...
Driver class MS SQL JDBC Driver
Opening connection ...
Connection jdbc:jtds:sqlserver://127.0.0.1:1434/databasename;user=sa;password=;charset=utf-8;
The schema could not be reverse engineered (error: 0).
ReverseEngineeringMssql.reverseEngineer :I/O Error: Connection reset
Details:
net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2277)
net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:599)
net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:331)net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50)
net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:178)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)com.mysql.grt.modules.ReverseEngineeringGeneric.establishConnection(ReverseEngineeringGeneric.java:141)com.mysql.grt.modules.ReverseEngineeringGeneric.getVersion(ReverseEngineeringGeneric.java:161)com.mysql.grt.modules.ReverseEngineeringMssql.reverseEngineer(ReverseEngineeringMssql.java:164)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.mysql.grt.Grt.callModuleFunction(Unknown Source)

ok, so close the migration tool reopen and go through the same process, exact same behaviour, clicking the back button brings me to the original screen where the MSSQL connection information was entered, everything is as it was, try to connect again and this time another java stack trace, the important part was this line - 'I/O Error: DB server closed connection.' - Weird

a google search led me here - http://bugs.mysql.com/bug.php?id=20674
Using the 'SQL Server Configuration Manager' I had to set the 'SQL Server 2005 Network Configuration' -> 'Protocols for MSSQLSERVER' -> TCP/IP to Enabled

doing this set my default port back to 1433 (actually that is the one I used, xp_readerrorlog shows the database listening on both 1433 and 1434), so re-connecting with the migration tool and using the 1433 default port worked and I was on my way...

so every table fails to migrate except 2? well I guess the migration tool could be better, lucky for me I only had 12 tables going here, I had to update the migration code for all of these tables

`is_active` TINYINT NOT NULL DEFAULT (1),
had to be changed to
`is_active` TINYINT NOT NULL DEFAULT 1,


yes removing the () from the default value - now that sure is a pain. It was only occuring on types of tinyint - these were coming from MSSQL bit datatypes, could be an issue only in that one case?

Sunday, November 4, 2007

TFS without Visual Stuido

you can actually install Team Foundation System source control without installing the entire Visual Studio IDE, why you would want to do this I am not sure, but we had some QA peoples who needed access to the source control system, seemed like it would be easier for them not to need to go through the VS IDE just to access the files.

anyhow if you install TFS Source Control Explorer, everything should work ok from the command line, only one registry hack was required - found this on msdn forum somewhere but forgot to bookmark it

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\TeamFoundation\Servers

add a new String Value with the key being the name of your TFS server and the value the uri for the TFS server i.e. MySourceControl=http://mysourcecontrol:8080

or better yet forget all this and save your self a big headache and just use Subversion - it works better and it is free

Sunday, October 21, 2007

Tic Tac Toe on Rails

Ok I finally completed my first rails project. Tic Tac Toe on Rails, you can check it out at http://www.tictactoeonrails.com/. It was a good reminder for me of how long it takes to really get up to speed on new technologies, Rails is really cool but it is definitely not a silver bullet for building web applications, when you get right down to it building software is hard work no matter which technology you choose to use.

Sunday, October 14, 2007

Assembla is cool

Check out - http://www.assembla.com/

right now I am just using it for the 200MB of free svn repository for my first rails projects (always important to have a back up); but they have so much more to offer as well - Job Board, Distributed Team management tools, etc...

Thursday, September 27, 2007

TFS and the pain

We have been using TFS (Microsoft Team Foundation System) at work for Source Control for a few months now; we've run into numerous issues none of which I am going to get into now; this post is really just some notes for my future reference.

if you get into real trouble with TFS the following steps should almost definitely get you back to a fresh place
  • Start -> Programs -> Visual Studio 2005 Tools -> command line
  • tf workspaces
  • - this will show you your workspace name; probably the same as your machine
  • tf workspaces /remove:*
  • - this will remove local system cache of TFS
  • tf workspace /delete /server:{servername} {workspacename}
  • - this will remove from the server
  • - it will prompt you to verify - type in y
  • tf workspace /new /server:{servername} {newworkspacename}
  • - this will launch the GUI to map the server to your local system
  • - server = $/
  • - local = C:\TFS
  • cd C:\TFS
  • tf get
  • - pull down all the files

This maps the root of the TFS server to C:\TFS, you may of course want it mapped to another location on your drive.

Check out tf command on msdn

Saturday, September 1, 2007

Ruby and Rails

Taking a few hours a week to try and learn Ruby and Rails

notes and links for future reference

Books

Ruby and Rails resources

IDE and text editors for Windows

Some notes and code stuff

Ruby Notes - part 1 - dynamic object creation

I am starting to learn Ruby and Rails (just for fun) - took awhile to find a good example of creating an object at runtime given a string representing the objects name; finally came across this post http://www.ruby-forum.com/topic/96222;

in theses 2 examples - given an ActiveRecord object 'Project' and a database table named 'projects', invoke the Project and execute some methods on it

# using eval
def test_dynamic_invoke_with_eval
__object_name = "Project"
__o = eval(object_name)

__p "object name is '" + o.to_s + "'"
__p "object table name is '" + o.table_name + "'"
end



# using Object.const_get
def test_dynamic_invoke_with_object_const_get
__object_name = "Project"
__o = Object.const_get(object_name)

__p "object name is '" + o.to_s + "'"
__p "object table name is '" + o.table_name + "'"
end



Check the ruby forum link above as well - the last entry posted by 'unknown (Guest)'; this is probably the true ruby way to do it? extend the String object with a helper method so you can turn any string into an object? code from that post

# extend String
class String
__def to_class
___Object.const_get(self)
__end__
end