Tuesday, November 16, 2010
Automapper Datatable to List
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
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
and yes the code that it wraps has some issues....
Monday, March 2, 2009
jqueryUI effect error with Google Chrome and Safari
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).css("background-image", "url(some_image.png)");
$(this).css("background-repeat", "no-repeat");
$(this).effect("highlight");
Sunday, October 19, 2008
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
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, ...
.
Monday, March 3, 2008
'vincent-vega' is now 'The Tarantino Project'
Saturday, February 16, 2008
Rails like migrations in the .NET world
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
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
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
- Download the SyntaxHighlighter javascript and css files from http://code.google.com/p/syntaxhighlighter/
- Upload those to my googlepage website, if you don't have one go to https://www.google.com/accounts/ManageAccount and click on the 'Page Creator' link
- Edit the blog template -> Layout -> Edit Html
- Add the references to the css and javascript files in the head section
- Add the initialization javascript calls right before the /body tag at the end of the html template
- see http://morten.lyhr.dk/2007/12/how-to-get-syntax-highlighting-in.html
- then use pre tags like this around your code pre class="c-sharp" name="code"
- see http://code.google.com/p/syntaxhighlighter/wiki/Usage
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
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
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
Sunday, October 14, 2007
Assembla is cool
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
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
notes and links for future reference
Books
Ruby and Rails resources
- Rails Casts
- Active Scaffold
- Ruby Rools
- Ruby Forum
- Rails Plugin Tutorial
- Active Scaffold Tutorial
- Jay Fields Thoughts
- O'Reilly Ruby and Rails articles
- Migration Cheat Sheet
IDE and text editors for Windows
Some notes and code stuff
Ruby Notes - part 1 - dynamic object creation
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


