Skip to main content

Posts

ADDPATH NT/DOS command line script

(Yes, We say script now instead of batch ... times are changing). Here is a stupid little batch file that I have written several times. It adds a single argument to the path in your current command-line session (so it is not permanent). @echo off if "%1" == "" goto end_script set path=%path%;%1 :end_script

Iron Languages on DLR

The "Iron" languages that run on the .NET DLR (Dynamic Language Runtime) are making progress. I just noticed that IronRuby has a release on RubyForge . To be honest though, I have moved to Python as my script language of choice, with Perl as the ever-present fallback. Iron Python seems like it is coming along nicely. Iron Python 2 can even host itself . I can't wait for MonoDevelop or SharpDevelop to support IronPython on Windows.

The Castle Project will facilitate native SQL.

I just spotted this on FishEye ... an example native SQL query . You'll need source from SVN or a recent download from the build server - more recent than patch 5551 by mzywitza on 17 February 2009. This is very nice, allowing parameterized SQL without the hacks that I used (you can search here for some of my old blogs on the subject).

Search and Replace in Visual Studio 2005

I usually have to look this up, so I am posting it to my blog. Visual Studio 2005 has a "Regular Expression" option on the "search and replace" dialog. (Previous .Net editions had it as well.) I occasionally want to rewrite several lines of text without writing a macro or wearing out my fingers. Here's what I do ... If I have a file with several lines of DECLARE R1 = VC WITH CONSTANT("TEST1") DECLARE R20 = VC WITH CONSTANT("TEST2") DECLARE R31 = VC WITH CONSTANT("TEST3") DECLARE R42 = VC WITH CONSTANT("TEST4") And I would like to convert these to SET R1 = "TEST1" SET R20 = "TEST2" SET R31 = "TEST3" SET R42 = "TEST4" I would search for "declare [R|r]{.*} = .* with constant\({.*}\)" and replace with "set r\1 = \2" (don't add quotes into the search dialog). This grabs the text in curly braces and assigns it to \1 and \2, so I can re-assemble it as I wish. I...

PdfPoster - a simple fix for Windows

I have tried a couple of times over the last 3 months to use PdfPoster on some Erwin documents. Unfortunately, I am using Windows XP on my work PC. It was clearly documented that I needed to install PyPdf 1.11 or higher, so I did easy_setup to install 1.12. Recently, I tried "C:\test>pdfposter -vvv -s 2.0 SCHEDULING.pdf scheduling_2x.pdf" ... and received a nice traceback (see below). This led me on a wild goose chase, under the assumption that my PyPDF library was not installed correctly. After a while, I decided to start python in immediate mode and just exercise PyPdf. It worked fine, but I noticed that the example opened a file using "rb" mode (read only, binary). So, I opened pdfposter/__init__.py under my site library directory, scrolled down to the bottom and changed the 3rd line of "def main" from "inpdf = PdfFileReader(open(infilename))" to "inpdf = PdfFileReader(open(infilename, "rb" ))". Problem solved!...

Google Chrome and Iron

I'm sure most of you have heard of Google's new WebKit based browser "Chrome" . Well, a German company has released a more privacy friendly version called "Iron" , with the browser usage tracking removed. Their site is written in German, but here is a translation thanks to Google's Language Translation tools. I haven't had a chance to try it out yet, but I'm glad someone is taking advantage of the open source nature of Google's offering.

Python Turtle and Links

I just discovered the Turtle graphics module for Python 2.5 using the Tk graphics library. It is very "kid friendly", and it sets up a screen when you make your first function call. This was very fun, just like when I first played with LOGO on my Commodore 64! >>> from turtle import * >>> clear() >>> down() >>> goto(66,66) >>> for step in range(24): ... right(105) ... forward(100) ... >>> up() >>> goto(0,0) >>> color("red") >>> write("Done!") >>> exit() Seen on the Web in August 2008 Iron Python on ASP.Net http://ironpythonresource.com/post/2008/08/03/Beginning-IronPython-Creating-a-basic-ASPNET-Form-(Part-1).aspx Connecting to a database http://ironpythonresource.com/post/2008/08/09/Connecting-to-a-database-and-using-the-gridview.aspx Creating a class http://ironpythonresource.com/post/2008/08/10/Beginning-IronPython-Creating-a-class.aspx Creating an updat...

The pains of browser page refresh

I like to play Chess sometimes, and I like the MKGI Chess Club . It is great for guys like me who do not have time to play a complete game in one sitting. The site uses a "postal chess" model, where I can play a move in several games, then wait for my opponent to move, or go on with my day, and check later or the next day. The site has an unfortunate quirk. It allows you to write notes about the game, but if it is the opponent's turn, the game page has a 30 second refresh. It is <meta http-equiv="refresh" content="30" >. I tried deleting this from the page using Grease Monkey (an HTML rewriting tool for FireFox), but even after I remove the element, the refresh occurs. So finally, I go into FireFox's about:config and type refresh in the finder. There is "accessibility.blockautorefresh"! So now, I get a notice that the page wants to refresh, instead of losing my notes!

Python 2.6 beta 1 and 3.0 beta 1

Python is sticking pretty close to their release schedule for Python 2.6 and 3.0 as documented in PEP 361 . They released Python 2.6 beta 1 and 3.0 beta 1 today. If you&apos're curious about their progress, check the 2.6 release notes . By the way, I noticed that they fixed a problem with one of the rotating log handlers - it was using a simple filename instead of the full file path when deleting old log files. I have been wanting to check my code in both 2.6 and 3.0 latest releases. Now that it is in beta, I should be able to get a pretty good idea of what has changed. All I want is for it to "feel" like python.

Monitoring SQL Server on the cheap

Use WMI with Python . Thanks to Tim Golden , Python on Win32 (I use ActiveState Python ) can use COM to talk to WMI. WMI allows you to run SQL-like queries to determine available memory, free disk space, database size, transaction log size, transaction log space available, when a database was last backed up, ... all of the good stuff. Any DBA knows that databases need free disk space and frequent backups. I don't want to imply that this is the only work a DBA would perform, but I have worked at shops where there really wasn't a DBA in our department. My programs occasionally failed because there was no disk space, and the transaction logs had not been backed up for a few weeks (sure, the database was backed up, but not the logs). If you don't want to use WMI, SqlServerCentral has some great articles for SQL 2000 and 2005. Give them time and they will have 2008 as well. If you want to to check a backup, try this .

Custom Python Logging Handler

Python has some nice basic logging facilities, but I really wanted a rotating logger that would rotate on each execution. I tried the obvious - just specifying class=MyModule.MyClassName, but I received a NameError exception for my trouble. After some hacking on /python25/lib/logging (a big no-no!), I did another google search and discovered that I could just import the class in my application, and set a reference to my custom class. Hard-coding a logging handler doesn't feel very dynamic, but at least I did't have to hack any more. from MyCustomHandlers import SessionRotatingFileHandler logging.SessionRotatingFileHandler = SessionRotatingFileHandler logfile_name = "test.l4p" logging.config.fileConfig(logfile_name) This allows me to place my custom log handler in my application directory. I still need to figure out how to add things to site-packages.

Perl or Python?

Recently at work, we have been discussing the question of Perl versus Python for file copy, ftp, email and other daily, weekly or monthly automation / integration tasks. We considered Perl because some existing tasks had already been written in it, and Perl has a reputation as the System Admin's language of choice. I took a task that needed automated and wrote it in Perl 5.8, then refined it using CPAN (sweet CPAN) for ArgvFile, Log4Perl, Carp, and Date::Calc. I find Perl to be very functional and completely able to meet my needs, but very quirky or perhaps unsettling. You see, I have been an object oriented programmer for a while now, and Perl's class system just feels "bolted on" to me. And I really had to jump through hoops to do a try/catch, but using eval with a return flag and an END block to test the return worked acceptably. I didn't test the exception module, as I did not discover it in time. Next I tried Python 2.5. After a quick brush-up on the...

Moving to NHibernate 2.0

NHibernate 2.0 is not even close to release, but it is shaping up nicely. Oren Eini (His blog is called Ayende @ Rahien) has a list of interesting new features . Dario Quintana has something to say as well . He has contributed some code to the uNHAddins for Active Record Detached Query support . The Castle development team is considering pointing to NHibernate Trunk (which will be released as 2.0 eventually) so they/we can take advantage of the new features. If Castle Active Record uses NHibernate trunk, I would advise you to be diligent wit! your test code, and don't forget to run the Castle test code too. You can track Castle Project changes on FishEye .

Mono and ProMesh.NET

I follow the Mono Blog aggregator , and Miguel de Icaza mentioned that a user had tested ProMesh.NET on Mono , and it ran without any changes! That in in itself was cool, but when I took a look at ProMesh.Net , it looked like a well designed framework, perhaps comparable to MonoRail . The framework is ORM agnostic, and the biggest weakness might be it's view templates, but they have a great tutorial , so judge for yourself!

My take on Enums in SQL Server

I am a registered user on SQL Server Central , and I read a good article there on " Enums in SQL Server ". I thought that I would quickly present my own humble solution to this problem, although I do not mean to imply that my way is better - you can decide for yourself. First, the problem to be solved is to represent a limited set of choices, where new choices would typically require a developer's intervention to implement the business logic. An example would be a list of task priorities in a to-do list. CREATE TABLE Priorities( ID tinyint not null identity(1,1) PRIMARY KEY, Code char(3) not null unique, Priority varchar(20) not null ) ; INSERT INTO Priorities (Code, Priority) VALUES ('911', 'Emergency') ; INSERT INTO Priorities (Code, Priority) VALUES ('HIG', 'High') ; INSERT INTO Priorities (Code, Priority) VALUES ('NOR', 'Normal') ; INSERT INTO Priorities (Code, Priority) VALUES ('LOW', 'Low') ; IN...

Auditing a SQL Server database

I do not believe that I have covered this before, but the Active Record Code Generator can also generate audit records for your database tables. The template that I wrote ( SqlAuditTrigger.vm ) adds records to an AuditChanges table, with a related AuditFields table containing the table and field name. I think that this is a fairly compact solution, but I also added code to the trigger to ignore SA (system administrator) changes. This may not be appropriate for your application, but it is easily removed. I also have a "TODO" item to detect related lookup tables (really ENUMs) and translate IDs to Names, so that changes to the FavoriteColor_ID field would look at the FavoriteColor table, and instead of recording FavoriteColor_ID changed from 2 to 5, it would say changed from "Ruby Red" to "Passionate Purple". The reason that I did not actually implement it is that I do not have enough information. My code generation schema does not list all of the f...

I love Bouncy Castle!

Today, I needed to send some private data to another company, and I could not get FTP with SSL to authenticate over our firewall, so I had to sent an encrypted file over FTP. The other company has a GPG public key, so I looked around for a bit on the web (yes, I googled c# gpg encrypt open source) and found a message that mentioned Bouncy Castle on the 4th or 5th page (why was it so far down the list???). I then googled Bouncy Castle to finally find that they have a wonderful c# implementation of GPG encryption (and many others), and their test code includes an example that reads a file and writes an encrypted file. This made integration VERY simple. I did move their test folder into their test project, so I would not be deploying all of the test code to production.

What happened to VS2005 Data Pro Power Tools?

I was reading a blog on MSDN, with a link to some cool Power Toys for Visual Studio 2005 Team Edition for Database Professionals. So today, I had some time to install the VS2005 TE Service Release 1 so I could grab the power toys, but the microsoft link is dead! The developer went on a vacation (literally), so it might be a while until this gets fixed. Oh, by the way, O’Reilly Hacking Visual Studio mentions a cool documentation tool called GhostDoc . It looks slick! Update: Here is the link , thanks to Michael!

NHibernate hbm xml template

Friday, I added an NHibernate mapping.hbm.xml template. I mainly wanted to show that the code generator can be used for other purposes than just Castle ActiveRecord, and NHibernate is an easy target. Jim R. has requested that I add HasMany (aka ManyToOne) mapping properties and attributes. I think this is going to push me to refactor the schema extraction code. Some of my future goals for the application are: 1. Full Model Generation (list of children, whether directly or indirectly through a many-to-many table) 2. User controllable plural-to-singular mapping. 3. Multi-database, using the Database Provider Factory. 4. Refactor code generation into a library (as I do with all projects) 5. Command-line code generation (supply at least a template and a list of tables) 6. Templates for other ORM tools (pure NHibernate, Rocky Lhotka's CSLA Business Objects, etc.)

Improved Model generation in Code Generator

I have improved the Inequality test in the model template, as requested by JimR . This was another case where it worked well for me, only because I followed the convention that primary keys are named ID, and foreign keys are named SingularOfTable_ID. I know that I should really push the Inequality test into the template, but for now, I have corrected it in the DbFieldInfo class.