Switching from Git to Mercurial

I’ve decided to make the switch from using git to Mercurial. Git’s syntax to me is much more complicated than it needs to be and Mercurial seems to be more my style. I find it’s much easier to find out how to do things with Mercurial and to be honest, I use about 10% of the functionality in either git or Mercurial.

This also means I’ll be transitioning Snowball to Codeplex I think. I’ll be moving it away from GitHub for sure just not 100% sure where.

Am I finally free?

For the last 3 and half years, I’ve done php programming professionally. I’ve programmed many things from web apps to websites. I’ve worked with a few CMS systems. I was beginning to think I would be stuck in the world of php for a long time.

Last year, I took a job at a different company thinking I was going to start something different. My first day there they informed me I would begin working on a new php project for the company. As of today, they’ve informed me I’ll be moved to a different project, using a different programming language.

Most of my time in php land was spent working with Zend Framework. I can’t say my experiences were all good. Some parts of Zend Framework are great, others are not. Work on Zend Framework v2 began before I took my current job and still isn’t finished. The framework is supposed to be a set of “components” which can be used separate from each other. This is both good and bad. There are some parts where you feel the components are too tightly coupled and there are other parts where you feel the components don’t work well enough together. There is also no built in mechanism for creating a distribution containing the components you need and their dependencies. Without that, what’s the point of programming the framework as a set of loosely coupled components.

I had to work for a little while with the CMS “Contao”, then called “Typolight”. That thing was a monstrosity. Most of the classes were just singletons. They preach that they are an object oriented CMS, but if almost every class in the system is a singleton and everything is so tightly coupled, then what’s the point of having done things object oriented in the first place?

As a whole, I don’t feel like php is a bad language. I think there are a lot of bad code examples out there which makes it easy for new programmers to copy and paste and have that, “Look what I did ma!” feeling. Sure there are some parts of php which make you say WTF, but as long as you learn those points and avoid them the language is fine. I’m glad to be moving on but I can’t say the language is totally terrible.

I don’t know exactly what I’ll be doing next, though I do know it will be a statically compiled language and I will be doing something web related.

Using git-gui with Cygwin on Windows 7

I’ve started using git via cygwin and was running into trouble trying to pin it to my taskbar in Windows 7.

First I created a .bat file in the c:\cygwin folder which launches the app standalone:

@echo off

C:
chdir C:\cygwin\bin

start run.exe git gui

You can change paths accordingly. Now run the batch file and pin the program to the taskbar. You’ll notice after you close the app, the icon changes and it won’t launch again.

Right click on the shortcut while holding shift and choose properties. Change the target to the batch file we wrote. You can change the icon to the git-gui icon by pointing the shortcut icon to “C:\cygwin\usr\share\git-gui\lib\git-gui.ico”.

Now if you click on the icon, the git-gui app should start up. Kill your explorer.exe in task manager and restart. If the icon is still the genie lamp, you’ll need to clear your icon cache to get the icon to look right. Credit for that from here. Kill your explorer.exe again and while explorer is gone, start cmd.exe. From there enter the following commands:

CD /d %userprofile%\AppData\Local

DEL IconCache.db /a

EXIT

After that your icon should be there as you want.

Getting started with SlimDX

Since I tried OpenTK, I decided to give SlimDX a try as well. So, here’s a simple getting started app:

using System;
using System.Drawing;
using System.Windows.Forms;
using SlimDX;
using SlimDX.Direct3D9;
using SlimDX.Windows;

namespace SlimDXApp1
{
	public partial class SlimDXApp1Form : RenderForm
	{
		struct Vertex
		{
			public Vector4 Position;
			public int Color;
		}

		Device device;
		VertexDeclaration vertexDeclaration;

		public SlimDXApp1Form()
			: base("SlimDXApp1")
		{
			this.ClientSize = new Size(800, 600);

			this.device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = this.ClientSize.Width,
                BackBufferHeight = this.ClientSize.Height
            });

			this.vertexDeclaration = new VertexDeclaration(this.device, new[] {
        		new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
        		new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
				VertexElement.VertexDeclarationEnd
        	});
		}

		public void Run()
		{
			MessagePump.Run(this, () =>
			{
				this.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
				this.device.BeginScene();

				this.device.VertexDeclaration = this.vertexDeclaration;

				this.device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, new[] {
					new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f) },
					new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f) },
					new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f) }
				});

				this.device.EndScene();
				this.device.Present();
			});
		}

		[STAThread]
		static void Main()
		{
			SlimDXApp1Form form = new SlimDXApp1Form();
			form.Run();

			// Cleans up COM handles
			foreach(var item in ObjectTable.Objects)
				item.Dispose();
		}
	}
}

Getting started with OpenTK

I started experimenting with OpenTK and I had to look in a few places to put this code together, so I’m posting it here for anyone who might be looking for an easy getting started lesson.

I’ve set up a window similar to what I’ve been used to in Xna (CornflowerBlue 4 life). I’ve also set up a 2D projection matrix and drawn a triangle in a 2D fashion. You’ll need to add a reference to the OpenTK assembly for your project in Visual Studio.

using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace OpenTKApp1
{
	public class AppWindow : GameWindow
	{
		public AppWindow()
		{
			this.Title = "OpenTK App 1";
			this.WindowBorder = WindowBorder.Fixed;
			this.ClientSize = new Size(800, 600);
		}

		protected override void OnRenderFrame(FrameEventArgs e)
		{
			base.OnRenderFrame(e);

			GL.ClearColor(Color.CornflowerBlue);
			GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

			GL.MatrixMode(MatrixMode.Projection);
			GL.LoadIdentity();
			GL.Ortho(0, 800, 600, 0, -1, 1);
			GL.Viewport(0, 0, 800, 600);

			GL.Begin(BeginMode.Triangles);
			GL.Color3(Color.Red);
			GL.Vertex3(400, 150, 0);
			GL.Color3(Color.Green);
			GL.Vertex3(600, 450, 0);
			GL.Color3(Color.Blue);
			GL.Vertex3(200, 450, 0);
			GL.End();

			GL.Flush();
			this.SwapBuffers();
		}

		[STAThread]
		public static void Main()
		{
			AppWindow window = new AppWindow();
			window.Run();
		}
	}
}

Keeping SplitContainer SplitterDistance consistent

If you’re having trouble keeping the SplitterDistance property of a SplitContainer consistent across app sessions, you can set the FixedPanel property of the splitter to FixedPanel.Panel1.

splitter.FixedPanel = FixedPanel.Panel1;

I guess this could also work with FixedPanel.Panel2 as well but I haven’t given it a try. Credit this stackoverflow post.