Posts

IronPython, PetaPoco, and .Net 4 'dynamic'

Recently I was playing around with IronPython and PetaPoco (a .Net micro-ORM). PetaPoco allows the use of the 'dynamic' keyword when querying data. Unfortunately, the dynamic keyword is not available in IronPython. However, since IronPython makes use of the DLR, its types are already dynamic instances. Therefore, all I needed to do was provide a Python type instead of the dynamic keyword (I used 'object'). The end result is an interesting combination of Oracle, PetaPoco, .Net 4, and IronPython. import clr import csv clr.AddReferenceToFile( "Oracle.DataAccess.dll" ) clr.AddReferenceToFile( "PetaPoco.dll" ) import Oracle.DataAccess.Client import PetaPoco conString = "user id=USER;data source=DB;password=PASS" provider = Oracle.DataAccess.Client.OracleClientFactory() db = PetaPoco.Database(conString, provider) query = "select * from my_table" result = db.Fetch[object](query) csvFile = csv.writer(open('out.csv', '

Triple-Boot MacBook Pro

I am now the proud owner of a triple-boot MacBook Pro featuring OSX, Windows XP, and Ubuntu 10.4; One big happy family! I primarily followed the article here: http://fletcherpenney.net/2009/04/create_the_ultimate_triple-boo I already had OSX with Windows XP set up on boot camp. To get the full house, I only needed to add Ubuntu to the mix. I began by shrinking the OSX partition to make room for Ubuntu using OSX's disk utility. I then installed Ubuntu onto the new partition using a single partition (no separate swap partition) being sure to install the grub boot loader to the same partition (not into the MBR). The key to getting all of the OSs to play nicely together is to use a utility called 'rEFIt' which acts as a boot loader as well as syncs the EFI and MBR for you. It is easily installed from OSX and is available here: http://refit.sourceforge.net/ At that point, all seemed well accept for a nice new BSOD when booting into Windows with the error "UNMOUNTABL

Controlling External .Net Processes

I have a project where I wanted to be able to provide my users with a button that would open an external application. The idea is that the interaction would be seamless so that from the users perspective, the external application would seem to be apart of my application. To pull this off, I needed to be able to bring the main window(s) of the external application to the front if I had already launched it but the user clicked the button again. For this implementation, I tried to use the following .Net implementation: _process.WaitForInputIdle(1000); IntPtr mainWindowsHandle = _process.MainWindowHandle; //show the process's window if applicable else inform the user if (!mainWindowsHandle.Equals(IntPtr.Zero)) { //show the process's main window ShowWindow(mainWindowsHandle, 1); SetForegroundWindow(mainWindowsHandle); } Here we get the handle to the main window of the process and we call the win32 ShowWindow and SetForegroundWindow methods to the fro

Embedding IronPython Within C#

IronPython is a Python implementation that runs on the .Net DLR and allows the use of the powerful .Net Framework from Python. While this is very exciting for Python development, there are also great advantages for other .Net languages. Using IronPython, we can run Python code from without a .Net application. More specifically, we can allow a .Net application to be extendable or scriptable with python. In the following example, I will create a basic python 'plugin' framework in C#. Python Code class TestClass(object): def __init__(self): self.A = 5 self.B = 4 def Go(self): return self.A + self.B C# Code public static object Execute(string code) { object result; try { ScriptEngine engine = Python.CreateEngine(); ScriptScope scope = engine.CreateScope(); ScriptSource source = engine.CreateScriptSourceFromString(code); source.Execute(scope); object t = scope.GetVariable("TestClass"); object o = engine.Operatio

.Net Assembly Probing

I have a situation where I need an application to look for assemblies in a subdirectory of the path where the executable resides. For instance, if I have an executable here: C:\MyApp\MyApp.exe The application will normally look for assemblies it depends on here: C:\MyApp\ However, what if you would like to put the assemblies here instead: C:\MyApp\MyAssemblies\ What you can do is add a few lines to your app.config for the application that looks like this. <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="bin1;bin2;bin3"/> </assemblyBinding> </runtime> </configuration> Where the privatePath attribute is a semi-colon delimited list of subdirectories to look in. In this particular case, we would add this: <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="MyAssemblies"/> &l

Windows XP Activation Fix

I ran across a situation where after doing a repair on Windows XP, the system thought the OS had not been activated and that my 30-day grace period was up. In addition, whenever I would click 'yes' I do want to go ahead and activate, the system would reboot itself. It is also not possible to activate from safe mode. I have read that this is something of a common problem with SP3. It turns out that Microsoft has created an application for system administrators and PC makers that allows you to put the system into a 'factory mode'. The result is that you have an unactivated OS with a 30-day grace period to activate again. The tool is called SysPrep which you can download with a set of tools provided in a cab file from Microsoft. Here are the steps to follow: 1.) Boot into safe mode with the command prompt option. 2.) Run 'explorer'. 3.) Export the files from the cab file into some location via 'My Computer'. 4.) Run the sysprep executable. 5.) Choo

Recover deleted files from a jailbroke iPhone (or *nix)

Here I will describe a process that will allow you to recover deleted files from an jailbroken iPhone hard drive. If you do not know what jailbroken means, your device most likely does not fall into this category. This method should also work with virtually any *nix based distribution as well. I will split this up into two parts: create disk image and analyze disk image. You will also find a list of my resources at the end. I suggest reading completely through each section before attempting it. Do not be intimidated by the length of this post. I have tried to provide a lot of information, but this operation boils down to using only 2 commands. CREATE DISK IMAGE The instant you realize that you need to recover a deleted file, stop using the device immediately. The more you continue to use the device, the higher the chance that the files you need will be overwritten. The first thing we need to do is to make a copy of the data on the device's hard drive. The technique we