Skip to content

Posts by Patrick

26
Jul

KMZ test

Here is the track:


26
Mar

Building a simple MVC framework

Introduction

I don’t know about you, but it took me a while to fully grasp the concepts of MVCs. I mean sure, it’s a Model View Controller framework and the model manages the raw data and links it to the database, the controller manages the requests to a specific module and is the translator between “Model-talk” and “View-talk” – which should be mute btw – and the View displays what the controller says to display.

I’ll let you check wikipedia for all the theoretical details and the thousand related frameworks.

Courtesy of the Symfony project

Meanwhile, we have tons of schema explaining to you how they work, like this one, from the Symfony framework. We’ve all seen those, but they don’t really demystify the “How do they work?“. When you look at the code, it’s MASSIVE. And it seems working like magic.

This is a humble attempt to explain the basis of how all those frameworks work for the curious programmer. I’ve been strongly inspired to create this by the Zend framework, Symfony, Yii and a great tutorial found here.

I strongly discourage you from writing your own MVC for production purposes. Use one of the above, take time to learn it and run with it. I personally have a preference for Symfony because it uses Doctrine, which is one of my favorite PHP software ever. It’s an amazing ORM.

That being said…I strongly encourage you to write your own MVC to satisfy your curiosity :)

I don’t really know where I’m going to go with this but if it proves popular, I probably will expand the whole thing, bits by bits, just for fun! If i do though, be prepared for a lot of refactoring though, since there will be many problems. I kept this as simple and straight forward as possible to keep the code distraction free.

This part is all about the dispatcher. How do we fetch the right controller, output the right data. Oh, and one more thing before we get started: we know nowadays SEO is the bread and butter of the web. Therefore, we will directly code for plain text URLs. We will go down the rabbit hole as a request hitting the web server, and see, step by step, what’s going on and how is it working.

Let’s begin!

Read moreRead more

21
Jun

Managing multiple threads in C# with a GUI

Objective: manage multiple threads from C# with a responsive GUI
Description:: In this example, I simulate encoding from a source that is splittable in segments. It could be the b-frames between I-frames in a video or even some sort of audio codec. To simulate the workload, I use Thread.Sleep(TimeInMs).

bggui

For this code, I have 4 threads working on a source to encode of 10 segments. Each threads will take a slice to encode, process it and reassemble the end result in an array, that can be utilized by another process to unify the encoded version, for example.

A word of caution though: although working with threads can be useful in some cases it also complicates the code quite a bit, especially at debugging. It’s much harder to keep track of what is going on.

Here is the code in the windows form (download the whole project in VS2008 at the end):

Read moreRead more

19
Apr

C# Crash report – How to handle remote crash report with HTTP POST

Objective: Make your applications report any unhandled crash to a database on a remote server.
Description:You have a Reporter class that will send the values to page accepting POST data. The application main entry point will be surrounded by a Try Catch block (effectively catching every possible unhandled errors in the application). It will then try to send the stack trace of the error to the webpage. If it can’t (ie. no internet connection, server down) it won’t do anything and the application quits.

It can be very useful to catch those bugs you didn’t see or thought possible without mass testing and QA…which, let’s face it, you can’t afford as a self programmer. Your users are your testers! :P
A word of caution though, you might want to warn your users you’re sending data, and what kind of data you’re sending before using this. In this example, it doesn’t warn the end user.

On to the code below the break!

Read moreRead more

17
Nov

Hello world!

I’m revamping this site!