Bringing my git-ignore settings with me

Since I’m working a lot of different places, and on quite a few different computers, I need to reconfigure my git-ignore settings every now and then. To manage my settings, I’ve put my git excludes in my Dropbox folder. This gives med the added advantage that all ignore settings are automatically syncronized between computers.

This is the file I have in Dropbox:


bin/
obj/
*.user
*.suo
_ReSharper.*/

And this is how git status looks like if I don’t use the ingore file:

Git notifies me that the Visual Studio build output and local settings are in the repository but are untracked. As my solutions grow, this list can grow to be very big.

I run this statement in git bash, pointing to my dropbox folder on my D: drive. This should work from Windows Command Line too, but then you need to use the Windows path

git config --global core.excludesfile /d/Dropbox/git/excludes

Note that it’s important to use the –global flag to make it valid for all local repositories, as this makes the command store the setting in the .gitconfig in your HOME folder.
When I now run git status, all the local files and settings from Visual Studio is now ignored:


Google+

Warning: this may seem like advertising!

I’ve been hooked on Google+. Probably somewhat because of my geeky nature, but I love how often sharing on G+ turns into conversations. I also love the photo sharing functions with great image viewing functions and image details. Look at this example album: https://plus.google.com/photos/112163012415386550166/albums/5479744893742196977, and remember to click on Actions -> Details under the picture so you can see both the map of the location and the camera details.

I also like how easy I can share things from my phone. The fact that Google+ uses Picasa for picture sharing is an extra plus, I’ve used it for years and would never put an image on Facebook because of their shady privacy policy.

I believe that the worst hype is over, but if you still haven’t gotten an inviation, here is one for you:

https://plus.google.com/_/notifications/ngemlink?path=%2F%3Fgpinv%3DQzg7ugB0SDY%3ATLC7AN5MlTo


An adventure in XCode and Cocoa

Since I haven’t learned a new language in a while, I wanted to try something new. Next stop Cocoa Mac and XCode.

It took quite a while to figure out how the Interface Builder and XCode worked together, but I’ll try to give a quick explanation:
First I created a new Application, and XCode created a XIB-file for me. This was called MainMenu.xib and contained both a system menu and a view. The XIB could be opened in Interface Builder, and I could draw the UI.

I then created a Cocoa class that inherited from NSView. In this class I implemented my properties and methods, which is called Outlets and Actions. Using the correct types is important for the Interface Builder to work when connecting code and UI together.
HelloWorldView.h

#import <Cocoa/Cocoa.h>
@interface HelloWorldView : NSView {
	IBOutlet NSTextField *words;
}
- (IBAction)sayHello:(id)sender;
@end

HelloWorldView.m

#import "HelloWorldView.h"
@implementation HelloWorldView
- (IBAction) sayHello:(id) sender{
	
	NSLog(@"buttonClicked");
	
	[words setStringValue:@"Hello, world"];
	[words setNeedsDisplay:YES];
}
@end

 

Then I hooked this class up to the View using Interface Builder.

Finally I hooked the text fields to the properties and the Buttons to the methods.
IB Bindings
Then I ended up with a working Cocoa mac app


Using my Squeezebox Remote for traffic information

I have a Squeezebox Duet, which is great for playing music. But I knew that the remote control was an embedded system running Linux. It’s sitting in it’s charger right next to me during breakfast, and I’ve been thinking about whether it would be possible to use it to check when my bus is coming. My bus is running along a road with heavy traffic, and it can be quite delayed during rush hours in the morning. And since the local traffic information agency is supplying free real time public transport information, I decided to give it a go.

The result

This is how the application looks right now. It’s currently in a state where it’s usable for me.

imageimageimage

If you have a squeezebox and are really bold, the applet can be dowloaded directly from the remote by adding https://github.com/downloads/perfp/TrafikantenSqueezebox/applets.xml to your squeezebox plugin settings (and remember to enable 3. party plugins)

Also, if you wan’t to check out the source, it’s available on https://github.com/perfp/TrafikantenSqueezebox

 

A few technical notes

The Squeezebox runtime environment is called jive and can be programmed in Lua. Lua is a really simple scripting language with a few interesting features, like first-class functions, dynamic typing, garbage collection and closures. I also uses one specific structure for all state, the table, which is more or less a hash table.

After playing a bit with Lua, I started looking at creating Applets for Squeezebox. At first this seemed like a simple task, since Logitech has been kind enough to supply both development guide in their wiki and SqueezePlay, a Windows/Linux/Mac version of the remote control software.

But the documentation is really poor. And they are using a patched version of the interpreter that uses a different syntax from the standard Lua parser. This means that you cannot use the lua parser to unit test your functions.

Another issue is that there is no apparent way to address the file system to reference modules. This is a problem because the relative file structure in squeezeplay on windows is different from the actual hardware, so relative references won’t work.

There is no date/time functions available in the runtime, and the only decent library I could find did not work on the squeezebox, unfortunately.

I still had a lot of fun exploring this platform and learning a new language.


Installing Oracle Client on Windows 7

During the install of Oracle Client on my brand new Windows 7 machine, I got the following error:

This seemed like a showstopper to me, but was actually just bad usability from Oracle (surprise!):

Checking the checkbox changes the status from “Error” to “User verified”, and allows me to continue installing…

Great!

What I really wanted was the 64-bit versjon, but that’s another story…


Using Visual Studio Find and Replace for language transformations

Sometimes I need to create code from data, normally to create scripts for deployment to multiple environments. Since this often is a one time job, it makes no sense to make or buy a tool for doing this.
Being a former Perl-programmer, I have a powerful tool in my toolbelt: regex.
This is a real example from a recent project.

I had quite a few sql-statements like this:
update maparea set extentx1=100616, extentx2=6654051,extenty1=139033,extenty2=6700901 where id = 110;

I wanted to create migration code for FluentMigrations, which should look like this:
Update.Table("maparea").Set(new {extentx1=179073, extentx2=7001157,extenty1=202727,extenty2=7012535}).Where(new {id= 390});
I pasted the sql statements into visual studio, and used Find and Replace to convert the statements.
Find what:
update {:w} set {.+} where {:w= :z}.+
Replace with:
Update.Table("\1").Set(new {\2}).Where(new {\3});

The trick is using {groups}to match the part of the expression I want to reuse in my new code, and group references, \1, \2 etc., to insert it in the right place.

After that I just press Replace All : )


Oracle and HTTP_PROXY

I’ve been working with Oracle lately. I’ve installed a local instance of Oracle XE to use while developing to make it easier for me to test NHibernate Mappings and Fluent Migrator (which is a really nice product, there will be a blog post about it someday).

Anyway, I’ve had all sorts of strange errors happen to me, and the strange thing was that none of these happened at home, only at work:

Immediately after install, http://localhost:8080/apex wasn’t working. Checking the logs gave me no useful information, they looked like this:
2010-11-23 16:08:35.574: [ CSSCLNT][3364]clsssinit: error(33 ) in OCR initialization
[ OCRUTL][6304]u_set_comp_error: Parameter was NULL
[ OCRUTL][6304]u_set_ocr_error: Parameter was NULL
2010-11-26 12:17:41.822: [ OCROSD][6304]utgdv:1:could not open registry key SOFTWARE\Oracle\ocr os error The system could not find the environment option that was entered.
[ OCRUTL][6304]u_set_gbl_comp_error: Parameter was NULL
[ OCRUTL][6304]u_set_gbl_comp_error: Parameter was NULL
2010-11-26 12:17:41.822: [ OCRRAW][6304]proprinit: Could not open raw device
2010-11-26 12:17:41.822: [ default][6304]a_init:7!: Backend init unsuccessful : [33]
[ OCRUTL][6304]u_set_ocr_error: Parameter was NULL

All suggestions i found on the net pointed to using SQL*plus to update and check system variables. But SQL*plus gave me this:

Error 46 initializing SQL*Plus
HTTP proxy setting has incorrect value
SP2-1502: The HTTP proxy server specified by http_proxy is not accessible

 
OK, thats a hint: remove the HTTP_PROXY system variable (which I’ve set to be able to use cygwin, maven and other command line tools that needs to download stuff from the web). That fixed SQL*plus, but surprisingly also fixed Apex ??! And not because the browser was using HTTP_PROXY, I tried using telnet to port 8080. It the port is open and accepts input, but after typing the usual:

GET /apex HTTP/1.1
Location: locahost

the connection will hang indefinitely with no response.

Conclusion:
You can’t use the HTTP_PROXY system variable when running Oracle on your system!

Update: The subtitle of this blog is continous learning. And so I learn:
If you make sure that your HTTP_PROXY variable is a valid url:http://proxyserver:port/ it will work just fine…


Mass converting video files using powershell and handbrake

Update 26.10.2011: Doug made me aware of some errors in the script, and I’ve updated the script. I’ve also added a section on Power Shell execution policy to allow running this from a ps1-script.

I’ve been recording the life of my family for a few years, and that has resulted in almost 1000 video files. What I really would like to do with those was to watch them on my Xbox or my phone. My video camera creates MPEG2, which supposedly is better for editing than MP4, but I’m not very good with video editing, so I don’t really do that. I’ve been looking for software to convert my videos, but all my attempts so far has resulted in a terrible quality loss. But then I found Handbrake. Handbrake converts my videos to high quality MP4, and reduces the size to about 20% of the original, and optimizes it for progressive play from web.

When you create a conversion task queue in Handbrake, you can choose to save the queue as a batch file for later execution. I did that, and it created a normal bat-file. The file looked like this:

"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe" -i "Z:\M2U00022.MPG" -t 1 -c 1 -o "C:\temp\M2U00022.mp4"
-f mp4 --strict-anamorphic  -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160
-D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1

Using powershell it was easy to  create a mass conversion of all my video files:

[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$files = get-childitem -Recurse -Include "*.mpg"
foreach ($file in $files) {
 $subpath = $file.DirectoryName.Replace([Environment]::CurrentDirectory , "")
 $destname = "C:\temp" + $subpath + "\" + $file.BaseName + ".mp4"
 if (!(test-path $destname)) {
 & "C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe" -i $file -t 1 -c 1 -o $destname  -f mp4 --strict-anamorphic  -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1
 }
}

Since I’m converting about 1000 files that are about 25 GB in total size, I even threw in a check for existing files at the destination so that I easily could break execution and restart it.

If you are running this code from a .PS1-file, you might get this error:
File convert.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.
This is because the policy for executing  powershell scripts is disabled by default. To allow running scripts on a computer, run


Set-ExecutionPolicy RemoteSigned 

from an elevated PowerShell session.


Troubleshooting errors in WCF Service

WCF hides all details of any errors on the server. This is done deliberately, as a security feature, but it makes it a bit harder to troubleshoot when something goes wrong.
Fortunately, Microsoft has provided some good tools for tracing in WCF, so it’s quite easy to see what’s really going on on the server.

What you typically see on the client is this:

   A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
--->; System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
--->; System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
  at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

On Server you must make the following change to the WCF service application config file (web.config if the server is hosted in IIS)

<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "D:\logs\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>

Rerun request, and watch the traces.svclog file appear under logs.

image

The contents of the logfile looks like this:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Transfer">0</SubType><Level>255</Level><TimeCreated SystemTime="2010-08-06T07:01:12.0107773Z" /><Source Name="System.ServiceModel" />

This is very verbose and quite unreadable. But then again, XML was never intended for humans…

Time to find a tool that can parse this. In the Windows SDK that is shipped with Visual Studio there is a tool called Service Trace Viewer.

image

When you start the Service Trace Viewer and load the tracefile that was produced from the WCF Service, you will get a view that looks like this:

image

Now, the errors that occured in the Service is highlighted in big red letters.


Expanding my bootable VHD

I just love booting from VHD in Windows 7. I have a playground for prerelease software, and just now Microsoft is releasing a torrent of them for the coming 2010 wave.

But the other day the VHD I booted from ran full. The disk is dynamic, but had a max size of 25 GB. After booting back to my physical drive, I tried Disk Management, but there was no option to expand the VHD there. The solution was a two step procedure:

1) Use DISKPART to expand the file:

select vdisk file=c:\vm\example.vhd
expand vdisk maximum=20000

2) Attach the VHD. In Disk Management you will see this:
image 
Right-click the volume (F:) and select Extend Volume.

Alternative 2): Complete the process without leaving diskpart. Make sure you you use the correct warning for

attach vdisk
select volume F:
extend filesystem


Follow

Get every new post delivered to your Inbox.

Join 140 other followers