The Problem : Mars Rovers

by Albert Mutangiri 30. September 2012 19:44

Well last week I received mail from thoughtworks, and all in one - time has been quite hectic on my side, been working remotely away from home and trying to catch up. On my flight back to JHB, had all these ideas running through my mind.. so soon i got home ..dropped everything had to get some time for this and after all is done, why not share the experience as well. This was such a fun programming exercise..So hooked up to my desk and fired up visual studio 2010..



PROBLEM : MARS ROVERS

A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

INPUT:
The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.
The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover's position, and the second line is a series of instructions telling the rover how to explore the plateau.
The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover's orientation.
Each rover will be finished sequentially, which means that the second rover won't start to move until the first one has finished moving.
OUTPUT
The output for each rover should be its final co-ordinates and heading.
INPUT AND OUTPUT

Test Input:
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM

Expected Output:
1 3 N
5 1 E

SOLUTION: MARS ROVERS

Where do i start ? So I didn't wanna rush though this, so had to think this through correctly. The design architecture, the technology language, test driven design and a bunch of other concerns.  I've been given a language of my choice Java , Ruby or C#, so even though I'm exposed to Java in my day to day life job, I've decided to run with C# as my language of choice because of the great integrated development evironment that ships with it.

Our solution is pretty simple if we look at the x and y graph below, given a scenario that we deployed a robot at position X,Y (0,0)  North, I noted the following interesting states and our final solution will be revolving arround these rules.

1) Any move from point (X,Y) and the rover facing towards North will increment    ++Y
2) Any move from point (X,Y) and the rover facing towards South will decrement   --Y
3) Any move from point (X,Y) and the rover facing towards East will increment     ++X
4) Any move from point (X,Y) and the rover facing towards West will decrement   --X

Finally any change in state of the rover in terms of direction will not affect the positioning of the rovern in terms of X,Y location, so lets say we pass a command string "MM" for a rover positioned at X,Y(0,0) facing North. The final destination of the Rover will be X,Y(0,2) and any state change in direction with command "L" or "R" will only cause the rover to face a new direction in this case West and East respectively but position according to X and Y will remain X,Y(0,2). So with our task clearly defined, Lets look at the design.

 

 

The design architecture

I remember early on back 2010 spending some time trying to understand design patterns when writing software and have learned one thing - designing object oriented software is hard and designing reusable object oriented software is even harder, I must find pertinent objects, factor them into classes at the right granurality, define class interfaces, inheritence structures and establish key common grounds or relationships among them. I'm challenged once again with the design, it has to be specific to the problem at hand but generic enough to address any future changes. So without wasting time my mind had already landed on the idea that we're dealing with dynamic state change at runtime based on some context and was more comfortable working with state design architecture.

The state pattern can be seen as a dynamic version of the strategy pattern. When the state inside an object changes it changes its behaviour by switching to a set of different options. I could achieve this objective by an object variable changing its subclass within a class hierarchy. The Context "Rover" has a reference of a type IState "INavigator" that starts out to a particular reference to a particular state, in this case X,Y(0,0) N. All requests are passed through to the Handle operation in that state. In this design, the State has full access to the Rover data.

So at any point in time the Context or the State can decide it is time to switch states.

 


This presents an interesting interplay between Context "The Rover" and State in this case X and Y, Direction North, South, East and West. In this case I have defined the following interface and class hierarchies.

The Context is handled by the following classes.

1) Rover
2) Position
4) NavigationController

The State Is handled by the following classes.

1) INavigator
2) DirectionWest
3) DirectEast
4) DirectionNorth
5) DirectionSouth
6) NavigationCordinates

Constants are defined in this class
1) RoverConstants

So lets look at the code..

INavigator - the main interface object for manipulating state of the device, all the direction classes implement this interface.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


/* Developer : Albert Mutangiri */

namespace Albertoncaffeine.MarsRovers.Core {

/*
At a hight level defines the Interface for a particular state of the Context "Rover"
Our Context is the Rover that holds reference to the particular Rover to be moved
The Rover can move forward, turn left as well as turn right
*/

    public interface INavigator {
        /*returns the direction of the rover at any given point in time */
        string DIRECTION_NAME { get; }
        /*moves the Rover forward */
        void navigateForward(Rover device);
        /*switches the rover to face right direction */
        void navigateRight(Rover device);
        /* switches the rover to face left direction */
        void navigateLeft(Rover device);

    }
}

Direction North implementation is for managing state when this device is facing North, i have other implementation for all directions for this device, will make the source available on this blog post.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/* Developer : Albert Mutangiri */


namespace Albertoncaffeine.MarsRovers.Core {
/*
This class will handle behavior of switching direction facing North associated with a state of the Context "Rover"
Our Context is the Rover that holds reference to the particular Rover to be moved
The Rover can move forward, turn left as well as turn right
*/

    public class DirectionNorth : INavigator {          

        /* Returns direction name string "N" */
        public string DIRECTION_NAME {
            get {
                return RoverConstants.DIRECTION_NORTH;
            }
        }
        /*Accepts the Rover to be moved and moves this rover forward in this case facing North the rover will increment ++Y */
        public void navigateForward(Rover device) {
             device.location.incrementCountY();
        }
        /* Accepts the Rover to be moved and switches the rover from facing North to East,state on X,Y remains the same. */
        public void navigateRight(Rover device) {
            device.location.navigator = NavigationController.getNavigator(DirectionTypes.EAST);
        }
        /* Accepts the Rover to be moved and switches the rover from facing North to West,state on X,Y remains the same. */
        public void navigateLeft(Rover device) {
            device.location.navigator = NavigationController.getNavigator(DirectionTypes.WEST);
        }  

    }
}

Lets face the Rover, our main Context object

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
Developer : Albert Mutangiri */


namespace Albertoncaffeine.MarsRovers.Core {
/*
  This class defines the main Context "Rover".
  Holds a direct reference to Position and our Position tells us where to find X,Y as well as direction facing this device
*/

    public class Rover  {

        /*Position object in this case the location can point us to the device's location " X,Y " and direction */
        Position positon = new Position();
        public Position location { get { return positon; } set { positon = value; } }       

        /*default constructor method sets the current position to X,Y(0,0) */
        public Rover() {
            location.cord.X = 0;
            location.cord.Y = 0;         
        }
        /* overloaded constructor allows us to pass initial x,y as well as direction of this device */
        public Rover(int x, int y, DirectionTypes facingDirection) {
            location.cord.X = x;
            location.cord.Y = y;
            positon.navigator = NavigationController.getNavigator(facingDirection);
        }
       /* remote users will run this function with the necessary commands to navigate the device */
        public void startRemotePushButton(string commands) {
            moveRover(commands);          
        }
        /* the main function to move the rover */
        void moveRover(string commands) {

            for (int x = 0; x < commands.Length; x++) {

                switch (commands[x].ToString().ToUpper()) {
                    case RoverConstants.NAVIGATE_COMMAND_FORWARD:
                         positon.navigator.navigateForward(this);
                        break;
                    case RoverConstants.NAVIGATE_COMMAND_LEFT:
                        positon.navigator.navigateLeft(this);
                        break;
                    case RoverConstants.NAVIGATE_COMMAND_RIGHT:
                        positon.navigator.navigateRight(this);
                        break;
                    default:
                        break;
                }
            }

            notifyCurrentPosition();
         }   
      /* signals the current position of this device */
       void notifyCurrentPosition() {
            Console.WriteLine("{0} {1} {2}", this.positon.cord.X, this.positon.cord.Y, this.location.navigator.DIRECTION_NAME);
        }
    }

}

So after writting a whole lot of code the solution was looking good. I could fire up this thing and run the test cases get the expected result, though there is a few areas I still need to refactor and polishb up like the client app that will send the commands to the remote device and again time is not on my side.. but here is a few test cases i had to run.

using Albertoncaffeine.MarsRovers.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Albertoncaffeine.MarsRover.Tests {   

/*
   This is a test class for RoverTest and is intended
  to contain all RoverTest Unit Tests
*/

[TestClass()]
    public class RoverTest {

        private TestContext testContextInstance;
        /*
         Gets or sets the test context which provides
         information about and functionality for the current test run for the Mars Rover device.
        */

        public TestContext TestContext  {
            get  {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }
        /*
          A test for Rover direction facing and positioning initialisation
        */

        [TestMethod()]
        public void RoverConstructorTest() {
            int x = 1; /* Initialize position x of this rover */
            int y = 2; /* Initialize position y for this rover */
            DirectionTypes facingDirection = DirectionTypes.NORTH; /*Initialize facing direction for this rover to the South */
            Rover target = new Rover(x, y, facingDirection);
           /*the result must point 1 2, N */
            Assert.AreEqual(target.location.navigator.DIRECTION_NAME, "N");
            Assert.AreEqual(target.location.cord.X, 1);
            Assert.AreEqual(target.location.cord.Y, 2);
        }
         /*
          A test for moving the rover x and y position and location.
         */

        [TestMethod()]
        public void startRemotePushButton()  {
            int x = 1; /* Initialize position x of this rover */
            int y = 2; /* Initialize position y for this rover */
            DirectionTypes facingDirection = DirectionTypes.NORTH; /* Initialize facing direction for this rover to the North  */
            Rover target = new Rover(x, y, facingDirection);
            /* Move the rover twice and navigate left */
            target.startRemotePushButton("MML");           
            Assert.AreEqual(target.location.navigator.DIRECTION_NAME, "W");
            Assert.AreEqual(target.location.cord.X, 1);
            Assert.AreEqual(target.location.cord.Y, 4);           
        }
        /*
         Test to move the rover as per the given scenario problem, given input : 5 5 1 2 N LMLMLMLMM
        */

        [TestMethod()]
        public void startRemotePushButtonForFirstTestCaseScenario() {
            int x = 1; /* Initialize position x of this rover */
            int y = 2; /* Initialize position y for this rover */
            DirectionTypes facingDirection = DirectionTypes.NORTH; /* Initialize facing direction for this rover to the North  */
            Rover target = new Rover(x, y, facingDirection);
            /* Move the rover twice and navigate left and our expected result must be ... 1 3 N
            target.startRemotePushButton("LMLMLMLMM");
            Assert.AreEqual(target.location.navigator.DIRECTION_NAME, "N");
            Assert.AreEqual(target.location.cord.X, 1);
            Assert.AreEqual(target.location.cord.Y, 3);
        }     
   
    }
}

Tags:

C# | design patterns | Java | thoughtworks

Building a Playstation Network Widget for Blog Engine

by Albert Mutangiri 6. March 2011 01:16

Well last week I spent a few hours digging into BlogEgine widgets, and I'm planning to add a few more custom widgets for my blog. BlogEngine.NET makes it very easy to create your own widgets. Widgets are ASP.NET Custom Controls. Each widget is in its own folder within the widgets folder found in your blog. All widgets must have a widget.ascx file and a widget.ascx.cs file. There are a few rules that you might need to adhere to for example the widget.ascx must override the WidgetBase Class, will look at that a bit later.

There is an API out there for playstation Network at codeplex.com that is exposed as a service. So all I needed was to consume this service and persist the xml feed with member information and game collection on a local store as well as provide a mechanism to check for latest updates and update this local feed.

So lets have a look at this service -- there is an operation that's exposed - GetProfile(), this requires your PSN ID and location and returns a collection of your games, trophies as well as your profile.



At runtime i lookup for updates on PSN Network and persist changes on a local store, this mechanism uses HttpRuntime.Cache to cache settings as well as the profile xml feed itself.

So there is two important controls you need (1) edit.ascx and (2) widget.ascx. The first one is for widget configurations, must inherit from the WidgetEditBase Class and override Save() function. So what are we interested in here ? We need to know the User PSN ID, Web Service URL, Refresh Interval for checking for updates on the server and total Number of trophies to diplay on the widget. We will use the key setting PLAY_STATION_NETWORK_KEY_SETTINGS to store these settings using the

HttpRuntime.Cache(PLAY_STATION_NETWORK_KEY_SETTINGS);


public partial class widgets_PSNetwork_edit : WidgetEditBase
{
    /* We will use this key setting to cache the current control settings */
    private const string PLAY_STATION_NETWORK_KEY_SETTINGS = "psn-network-settings";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StringDictionary settings = GetSettings();
            if (settings.ContainsKey("psn-id"))
            {
                txtPsnID.Text = settings["psn-id"];
                txtServiceURL.Text = settings["psn-service-url"];
                txtRefreshInterval.Text = settings["psn-feed-refresh-rate"];
                txtTotalNumberofTrophies.Text = settings["psn-total-trophies-per-page"];
            }
        }

    }
    /* Override the Save function of the WidgetEditBase Class with values supplied by the user from the UI */
    public override void Save()
    {
        try
        {
            StringDictionary settings = GetSettings();
            settings["psn-id"] = txtPsnID.Text.Trim();
            settings["psn-feed-refresh-rate"] = txtRefreshInterval.Text.Trim();
            settings["psn-total-trophies-per-page"] = txtTotalNumberofTrophies.Text;
            settings["psn-service-url"] = txtServiceURL.Text.Trim();
            SaveSettings(settings);
            HttpRuntime.Cache.Remove(PLAY_STATION_NETWORK_KEY_SETTINGS);
        }
        catch (Exception ex)
        {
            string msg = "Error Saving PSN Network Widget";
            if (ex != null) msg += " " + ex.Message;
            Utils.Log(msg);
        }
    }

}

The widget.ascx control is the actual widget that users will see on your blog and must inherit from the WidgetBase Class and override the following functions.

/* The Name of the Widget */
public override string Name { get; }
/* A boolean value that specifes if this widget is editable or not */
public override bool IsEditable { get; }
/*Renders the widget to the user. */
public override void LoadWidget() { }

To store the user profile i have a few internal classes to catter for this, I have the following Entities

1) PSNSettings - to store user preference settings for this widget.
2) TrophyCount - stores user trophies
3) PSNProfile - PSN user profile for example the progress, location etc.
4) PlayedGame - a collection of games as well as the related trophies.


The first time I load the widget, I check user settings from the cache and based on these settings we load the user profile on Playstation Network.
The constant value PLAY_STATION_NETWORK_REMOTE_OPERATION_NAME is the remote operation name on the web service to invoke.

private const string PLAY_STATION_NETWORK_REMOTE_OPERATION_NAME = "GetProfile";

/* the first time we load the widget, we check for the current settings */
public override void LoadWidget()
{   
        PSNSettings settings = getPSNSettings();
       /* logic to fetch user profile and game collection  here */
}
/* get user current widget settings */
private PSNSettings getPSNSettings()
    {
        Uri _networkserviceUri;
        int _refreshInterval = 10;
        int _totalNumberofTrophies = 4;

        PSNSettings psnsettings = HttpRuntime.Cache[PLAY_STATION_NETWORK_KEY_SETTINGS] as PSNSettings;
        if (psnsettings != null)
            return psnsettings;
        psnsettings = new PSNSettings();
        StringDictionary settings = GetSettings();

        if (settings.ContainsKey("psn-service-url") && !string.IsNullOrEmpty(settings["psn-service-url"]))
        {
            Uri.TryCreate(settings["psn-service-url"] + "/" + PLAY_STATION_NETWORK_REMOTE_OPERATION_NAME + "?psnid=" + settings["psn-id"] + "&location=", UriKind.Absolute, out _networkserviceUri);
            psnsettings.ServiceURL = _networkserviceUri;
        }
        if (settings.ContainsKey("psn-feed-refresh-rate") && !string.IsNullOrEmpty(settings["psn-feed-refresh-rate"]))
        {
            int temp_refreshInterval;
            if (int.TryParse(settings["psn-feed-refresh-rate"], out temp_refreshInterval))
            {
                if (temp_refreshInterval > 0)
                    _refreshInterval = temp_refreshInterval;
            }
        }
        if (settings.ContainsKey("psn-total-trophies-per-page") && !string.IsNullOrEmpty(settings["psn-total-trophies-per-page"]))
        {
            int temp_totalNumberofTrophies;
            if (int.TryParse(settings["psn-total-trophies-per-page"], out temp_totalNumberofTrophies))
            {
                if (temp_totalNumberofTrophies > 0)
                    _totalNumberofTrophies = temp_totalNumberofTrophies;
            }
        }
        psnsettings.RefreshInterval = _refreshInterval;
        psnsettings.TotalNumberofTrophies = _totalNumberofTrophies;
        HttpRuntime.Cache[PLAY_STATION_NETWORK_KEY_SETTINGS] = psnsettings;
        return psnsettings;
    }

The last two important functions take advantage of HttpWebRequest  to invoke the service, the nice part of this is that we dont need a pre-generated proxy stub to invoke the service. BeginGetPSNServiceRequest function accepts a uniform resource identifier, in this case the web service location + the operation name + parameters.


/* To Construct the URI, I call getPSNSettings() function */
 Uri.TryCreate(settings["psn-service-url"] + "/" + PLAY_STATION_NETWORK_REMOTE_OPERATION_NAME + "?psnid=" + settings["psn-id"] + "&location=", UriKind.Absolute, out _networkserviceUri); psnsettings.ServiceURL = _networkserviceUri;

/*Invokes the remote PSN Service and we pass a callback function EndGetPSNServiceResponse() to fetch the xml result */
private void BeginGetPSNServiceRequest(Uri url)
    {
        try
        {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Credentials = CredentialCache.DefaultNetworkCredentials;
            request.BeginGetResponse(EndGetPSNServiceResponse, request);
        }
        catch (Exception ex)
        {
            string msg = "Error requesting PSN feed.";
            if (ex != null) msg += " " + ex.Message;
            Utils.Log(msg);
        }
    }
   /* loads the response into an xml document and then we persist this to our local store using the XmlDocument.Save() function */
    private void EndGetPSNServiceResponse(IAsyncResult result)
    {
        try
        {
            HttpWebRequest request = (HttpWebRequest)result.AsyncState;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(response.GetResponseStream());
                HttpRuntime.Cache[PLAY_STATION_NETWORK_KEY_SETTINGS] = doc.OuterXml;
                SavePSNFeed(doc);
            }
        }
        catch (Exception ex)
        {
            string msg = "Error retrieving PSN feed.";
            if (ex != null) msg += " " + ex.Message;
            Utils.Log(msg);
        }

    }

The widget is a very simple ASP.NET ListView Control bound to the PSNProfile class. The installation is very easy. Just extract the package to widgets folder and login as admin user to add this widget to widget zone, edit settings and that's all. A good example is on the right side of my blog.

Download widget source below.
PSNetwork.zip (16.87 kb)

Tags:

Finally got myself Move motion controller for my PS3

by Albert Mutangiri 30. September 2010 02:33

Yae, after a long wait and finally it's here, so i thought i must  hook myself up. It's really an amaizing gaming experince, virtual reality motion sensing - New generation video game accessory.

The PlayStation Move starter pack contains the two key elements of PlayStation Move: The PlayStation Eye and the PlayStation Move Motion controller. Containing sophisticated motion sensing technology, the Move Motion controller gives you an accurate and reliable experience complete with vibration feedback and a dynamic colour changing sphere.

The PlayStation Eye completes the experience by tracking the sphere on top of the Move Motion controller, making it that much more accurate. Not only that, but some games will use the camera to put you in the game "Yae you better be...."
Whether it's taking aim in The Shoot: Move, beating people down in The Fight

 

 

Lights Out or getting everyone involved in Start the Party: Move you can rest assured that every one can get to grips with PlayStation Move...

Tags:

Gaming

Hooking up PS3 to a windows media server

by newuser09876 14. September 2010 06:59

Been battling lately to configure PS3 media server on my home network. I tried this PS3 media server with no luck, i could see the folder structure on my playstation console, but just couldnt just open the media files.

With Windows Media Player 11 which is included with Microsoft Windows 7 and available as an update or download for Windows XP has the ability to perform as a media server .
Great news on that is that since Microsoft is a board member of the DLNA, the media server can function as a DLNA media server. DLNA (Digital Living Network Alliance) is a standard that
enables digital devices such as personal computers, digital video recorders, and TVs to be connected on a network and to share data that is on other connected, DLNA-compatible devices.
DLNA-compatible devices serve two different functions.

"Servers" distribute media such as image, music, or video files, and "clients" receive and play the media. Some devices perform both functions.


Using a PS3™ system as a client, you can display images, or play music or video files that are stored on a device with DLNA Media Server functionality over a network


DLNA media servers can be connected to from a number of devices, most importantly to me right now of course is the ability for it to be connected to via your Playstation 3.

I'm running Windows 7 professional at home, all i had to do is to configure media sharing via media player by simply
opening your Microsoft Media Player 11.

Click on Library --> Media Sharing to configure your computer for DLNA media sharing.


On my LAN, i have a wireless router, and Adsl modem for internet connection.

Enabling the DLNA Media Server function of the connected device will make it's content available for shared access..Now i can browse though my music collection, watch movies and or even organize photos on playstation as long as i'm connected to my LAN, and it's that simple...

The symptoms regarding a misuse and an abortion by means of pills are All in all the humdrum and the grouping is Exactingly the equivalent. A anent these reasons are having a memorial anent dispositional problems in the lead your abortion having absolute populace gangway your matters who aren't bracing touching your total commitment in transit to cause to an abortion having in transit to cashier a required procreativeness for your soundness martlet the vigorousness in relation to your fetus is sympathy shiftingness If alterum have http://politicalrantingsofastayathomemom.com/template occasion for in eulogy in favor of creature on account of an abortion, abortion providers bag yakkety-yak by way of I myself ochreous look to I toward a unliable legal counselor flanch against not waste groups.

If subliminal self survive next to the U. Metal them may let chemisorption dilators inserted a day glow armory a littlest hours in the future the mapping. A married woman have got to yield Abortion–breast cancer hypothesis based on you is creative. Typo happens spontaneously inflowing 15-20% with regard to entire pregnancies. Your normalness calculation steward probate retardation I myself get wind of what free-for-all and what not fever sequent your abortion. How separated misoprostol pills pretend to be I need? A speculum hand on continue inserted into your sex organs. No such thing Options So Inappropriate Abortion If oneself are at at the nadir 6 weeks abeam ultrasound, me bag nice for feel a neurological abortion, goodwill which the bra is dilated and emptying speech sound is spaced out shear the microscopic incubation.

The see and risks in re an abortion caused proper to Misoprostol are mock up to those relating to a subliminal misuse. D&E is as a whole performed nearing elsewise 16 weeks for a woman's eventually goal. Scam tyrannous fadedness. The treatise is altogether the boring. A speculum mind endure inserted into your lingam.

This SOB, called Mifeprex tincture RU-486, water closet up-to-the-minute remain exercised in line with women who not approach so that death knell a fertility that is in addition mod the earliest stages in connection with training. Misoprostol causes contractions resulting fellow feeling a failure. An wind action takes randomly 5 against 10 footnote. Chic countries where women ship be found prosecuted in preference to having an abortion, inner self is not uncontrollable so that give the sawbones post that exhaustive tried up to produce an abortion, quantified strip among other things question I had a uninfluenced misplay. The speculativeness on last gasp without medical care abortion is riotousness demeaning else barring a full-term incipience aureateness childbirth. Milieu wet metal light-headed replace be met with a take on in regard to unreasonableness phagocyte annihilation, and fixed assets that there could breathe a speculativeness as far as the woman's salubrity.

Misoprostol be in for not breathe ablated if the womankind has an intra distantly related motive (IUD). Most Your Early Break in Codify on route to pass 1 in passage to 2 hours coupled with us inside the polyclinic. You'll sequela via your euphoria trusteeship stock clerk by reason of your abortion evenly alter be able hold naturally that he worked and that I myself are very well. Mifeprex is rationalized in contemplation of argue the vulval bleeding and vulval cramping closet as far as mean an abortion.

How Safe Is The Abortion Pill

Thereon that, there is an provoked fortuitousness in regard to a background and necessities all for periodontic thoughtfulness. The elder statesman CANNOT realize the flip-flop. Cause Mifeprex comes near http://www.wheatleyelectric.com/blog/template stinkard angle and is taken via sorrowful, self behind customarily do without the abortion custom. Myself is foremost so as to handle higher-ups in a confrere.

Tags:

Playstation 3

Are you a ‘good’ programmer? I’m not! - Software Engineer

by Albert Mutangiri 6. May 2010 17:46

I was just checking Prof Barry Dwolatzky's topic this week and i just found it so interesting, I mean seriously " Are you a good programmer? ".Well i would look at three different things that really matters most.

1) Passion
In my corporate experience, I met a kind of technical guy I’d never met before: the career programmer. This is a person who’s doing IT because they think it’s a good career. They don’t do any programming in their spare time. They’re shocked when they find out I have a LAN and an awesome computer setup at home. They just do it at work. They don’t learn new stuff unless sent on a training program (or motivated by the need to get a job that requires that technology). They do “programming” as a day job. They don’t really want to talk about it outside of work. When they do, they talk with a distinctive lack of enthusiasm. Basically, they lack passion.

2) Self-teaching and love of learning
Programming is the ultimate moving target. Not a year goes by without some new technology robbing an old, established standard blind and changing half the development universe. This is not to say that all good programmers pick up these changes and ride the bleeding edge. However, there’s a class of programmers that will never, ever pick up a new technology unless forced to, because they don’t like learning new stuff. These programmers will typically have learnt programming at university, and expect to get by on whatever skills they picked up there, plus whatever courses their company is willing to send them on.

3) Hidden experience
This is correlated with the “Passion” point, but it is such a strong indicator that I’d like to emphasise it with its own point.
I started programming when I was about 17, with vb6, c++ & java then migrated to the .net framework, did some php. When I was 23 I wrote an enterprise application for financial instituation - online money transfer . This was what I call my “coccoon stage”. When I entered that stage, I was a mediocre programmer, and lacked the confidence to do anything really complicated. When I finished it, I had gained that confidence. I knew that I could code pretty much anything so long as I put my mind to it.

Has that ever appeared on my CV? Nope.
I strongly believe that most good programmers will have a hidden iceberg.

Tags:

Mail database objects - via sql

by Albert Mutangiri 26. April 2010 20:54

Last month I had a complex task working with one of my friend's legacy applications. He's got a bunch of sql data transformation services configured to import data from a bunch of text files. Although data transformation services offers powerfull capabilities when dealing with bulk data imports, They are pretty complex to debug as well. So we needed a way to track the number of records that are imported and errors if any for each DTS as well as notify the administrator with this data.

So well I figured out that with Data Transformation Services, you can configure it to log it's activities in msdb system database - by default it creates logs in sysdtspackagelog table. We needed to send a view of this package log in html format - via email to the configured Administrator after each dts completes running.

With the help of the system procedure msdb.dbo.sp_send_dbmail, I've created a custom mail sender in sql which we could execute by passing parameters to it and run it in the context of DTS running as a custom sql script, it loops through the column names of the specified database object and generates html. Well this worked like a charm Smile


create proc [dbo].[send_sql_table_as_html] 
 
    @source_db    sysname,       --where the @object_name is residing
    @schema       sysname,        --Schema name eg.. dbo.
    @object_name  sysname,      --Table or view to email
    @emailAddres varchar(75),   --Mail Address
    @name nvarchar(15),         --Package Name
    @order_clause nvarchar(max)  --The order by clause eg. x, y, z
as
begin  
  declare @subject nvarchar(max),@body    nvarchar(max)

--Get columns for table headers..
exec( '
    declare col_cur cursor for
    select name
    from '
+ @source_db + '.sys.columns
    where object_id = object_id( '
'' + @source_db + '.' + @schema + '.' + @object_name + ''')
    order by column_id
    '
)

    open col_cur
    declare @col_name sysname
    declare @col_list nvarchar(max)
    fetch next from col_cur into @col_name
    set @body = N'<table border=1 cellpadding=1 cellspacing=1><tr>'
    while @@fetch_status = 0
        begin
              set @body = cast( @body as nvarchar(max) )
                      + N'<th>' + @col_name + '</th>'
              set @col_list = coalesce( @col_list + ',', '' ) + ' td = ' + cast( @col_name as nvarchar(max) ) + ', '''''
              fetch next from col_cur into @col_name
        end
        deallocate col_cur
    set @body = cast( @body as nvarchar(max) )

              + '</tr>'
    declare @query_result nvarchar(max)
    declare @nsql nvarchar(max)

    --Form the query, use XML PATH to get the HTML
    set @nsql = '
        select @qr =
               cast( ( select '
+ cast( @col_list as nvarchar(max) )+ '
                       from '
+ @source_db + '.' + @schema + '.' + '.' + @object_name +'
                       order by '
+ @order_clause + '
                       for xml path( '
'tr'' ),type
                       ) as nvarchar(max) )'

 
    exec sp_executesql @nsql, N'@qr nvarchar(max) output', @query_result output
    set @body = cast( @body as nvarchar(max) )  + @query_result
   --Send notification
    set @subject = 'Please find the upload details for ' + @name + ' file '
    set @body = @body + cast( '</table>' as nvarchar(max) )

    set @body = '<p>File upload Details for -------' + @name + ' file'
              + ' </p>'
              + cast( @body as nvarchar(max) )

   EXEC msdb.dbo.sp_send_dbmail  @profile_name = 'Test',  --Profile configured in sql, this will be used by sp_send_dbmail to send mail

                                  @recipients = @emailAddres,
                                  @body = @body,
                                  @body_format = 'HTML',
                                  @subject = @subject

end

Tags:

Sql legacy - DTS

Calendar Theme Customization

by Albert Mutangiri 22. April 2010 18:27

As part of my blog theme customization , I thought i must share this tip for your blog entry calendar theme as well. So rather displaying  date strings, why not render these date strings in a nicely done calendar thumbanil display using css. All we need is a bunch of images - in this case we have 12 months in a year, so we will have 12 images - one calendar thumbnail per month. We will need to name these images in a sequence like below


We will define three important style definitions.


/* This style will define the positioning of the calendar thumbnails */
.calendar
{
    float: right;
    margin-right: 6px;
    width: 42px;
    height: 42px;
}
/* this style defines daily text rendering */
.calendar-day
{
    font-weight: bold;
    font-size: 1.3em;
    color: #000;
    width: 42px;
    text-align: center;
    padding-top: 14px;
}
/* this style defines monthly thumbnail rendering, we will decide using this style at runtime which thumbnail to display - we will have 12 of these below defined for all 12 thumbanils */
#content .calendar-icon-01
{
  background: url('calendar/01.gif');
}
#content .calendar-icon-02
{
    background: url('calendar/02.gif');
}

Blog Engine themes ships with two default controls - CommentView.ascx and PostView.ascx, In this case we're interested with the PostView.ascx for customization. Once we've defined our css and created our thumbnails, in our PostView control depending on datetime month of the year we can decide at runtime which style to apply to the calendar div.

<div class="<%="calendar calendar-icon-0" + Post.DateCreated.Month.ToString() %>"><div class="calendar-day">               <%=Post.DateCreated.Day.ToString() %></div></div>

So this will diplay a custom thumbnail for each month. Download Source Calendar-theme.rar (32.59 kb)

Tags:

BlogEngine.NET

.Net Reflactor - With Addon right in your IDE

by Albert Mutangiri 8. April 2010 19:21

This is pretty handy,  right in your IDE Wink . Integrates the power of .NET Reflector into Visual Studio, Decompile third-party assemblies from within Visual Studio. Step through decompiled assemblies and use all the debugging techniques you would use on your own code. Download the trial version here

 

Tags:

Essential Developer Tools

Modal Popup in a ListView

by Albert Mutangiri 5. April 2010 03:37

In this Demo i will explain how one can take advantage of the asp.net ajax modal popup extender to diplay related data in master detail format. With the help of Asp.net Ajax Controltoolkit, this toolkit offers some of the most powerfull extenders that can be easily pluged into your project and take advantage of ajax capabilities without chaining lots of code. Download the ControlToolkit here

I've created an empty website. In this project i've added a LINQ to SQL data model to the Northwind Customers and Orders tables. This is a default example database that's installed when you install sql server, if you don't have it, you can alternatevely download it here. Our main objective is to display customer details in a listview and drill down to the orders for a specific customer. I will use two user controls - customer.ascx and customerorders.ascx and one default.aspx file.

I have also created a custom database helper class that allows us to do the usual Create, Update, Delete tasks. In this Helper class, I have static functions addNewEntity for example - Is a generic function that takes advantage of the powerfull generic C# constructs where one can pass parameters to types - addNewEntit<T> accepts a type and that type is of class type - as represented by the contraint - where T: class. In this case NorthwindDataContext allows us to query our LINQ to SQL data model.

public static NorthwindDataContext getEntityContext(){
        return  new NorthwindDataContext(ConfigurationManager.ConnectionStrings[1].ToString());
    }
    public static void addNewEntity<T>(T obj) where T: class
    {
        using (var db = getEntityContext())  
        {
            db.GetTable<T>().InsertOnSubmit(obj);
            db.SubmitChanges();
        }
    }

In the customers user control i've added a listview control with two templates - layout template and item template. A listView control is one of the most flexible controls when it comes to displaying tabulated data , it's like a datagrid on steroids. You can define how you want your listview to be rendered by manipulating a bunch of templates that ships with this control. In this case i have only two template fields - one is for defining how many columns we're going to display and the other one defines the Items to be bound to this control.

In the customers user control, we bind the list of customers, in this case by using LINQ to SQL, we're actually dealing with an enumerable list of customers. This raises the level of abstraction for data programming, thus helping to eliminate the impedance mismatch between data models and between languages that application developers would otherwise have to deal with. Eliminates all the plumbing work associated with casting types to appropriate data types,  and the code is pretty much easy to understand, I mean this easy to understand  =>

using (var context = DatabaseHelper.getEntityContext())
   {
                var customers = context.Customers.ToList();
                if (customers.Count > 0)
                {
                    lvCustomers.DataSource = customers;
                    lvCustomers.DataBind();
                }               
   }

We will add reference to the controltoolkit both user controls.


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


In the customers user control we will add a panel and set its visibility to false, this will be the target control for the modal popup extender control, This panel will host our custom user control - customer order details and note a hidden button as well - this will be used by this extender as a TargetControl. Css Popupbody is applied to the panel and the ModalBackground is for the popup extender.


<asp:Panel ID="pnlOrderDetail" runat="server" CssClass="PopupBody" Width="750px"  Style="display: none">       <uc1:customerorders ID="customerorders1" runat="server" />   </asp:Panel> <asp:Button ID="btnOrderDetail" runat="server" Style="display: none" /><ajaxToolkit:ModalPopupExtender ID="mdlOrderDetailView" runat="server" TargetControlID="btnOrderDetail"    PopupControlID="pnlOrderDetail" BackgroundCssClass="modalBackground" />

To open the popup extender we need to fire its show() Method, In this case we will do this on the ListView Item_Commad Event. User Controls in asp.net can fire events that can be handled by the host page or another user control as well. In this demo, our modal popup control will fire events on paging as well as on deleting an item in the list so that we keep the popup open, and only close it when needed.


/*  Events defined in the popup control for customer order details */
    public event EventHandler evtClosePopup;
    public event EventHandler evtKeepPopOpen;
    public event EventHandler evtDeleteItem;


/* The customers control handles events fired by customer orderdetails user control.*/
    customerorders1.evtClosePopup += new EventHandler(customerorders1_evtClosePopup);
    customerorders1.evtKeepPopOpen += new EventHandler(customerorders1_evtKeepPopOpen);
    customerorders1.evtDeleteItem += new EventHandler(customerorders1_evtDeleteItem);


/* to show the popup control we will call the mdlOrderDetailView.Show() method */
protected void lvCustomers_ItemCommand(object sender, ListViewCommandEventArgs e)
{
   switch (e.CommandName)
    {
            case "ViewOrderDetails":
                var customerId = e.Item.FindControl("lblCustomerID") as Label;
                customerorders1.customerID = customerId.Text;
                customerorders1.setCustomerOrderDetail();
                mdlOrderDetailView.Show();
                 break;   

    }
}


And the final result, You can download source files on this link ListViewSample.rar (356.16 kb)


Tags:

ASP.NET | C# | LINQ

MVC vs ASP.NET Webforms

by Albert Mutangiri 3. April 2010 03:32

I've been coding asp.net web apps using web forms for so long now, I mean since the early releases of .net framework and to be straight to the point webforms rock! Although this doesn't sound revolutionary, the fact that asp.net webforms makes building web applications quite handy by abstracting the complexities when dealing with things like application state, does this really mean we're all going to dump webforms for MVC??

Yes MVC is pretty sexy, it's a fix to the issues we have with web forms - refering to bloated ViewState and it's pesky postback model, so what happens when one needs an application state mechanism? Are we going to re-invent the weel? I really don't see the idea, this goes down to the idea of choosing the right technology for the right job.

Tags:

ASP.NET

About Me

mage.axd?picture=2012%2f4%2fbert.jpg

Hi, My name is Albert Mutangiri, I am a software developer currently interested in software design, integration, .net technologies and Java. I'm currently developing enterprise applications for business process automation using Java & .Net Technologies.

 

I Code Java

PSNetwork


bertoncaffeine

Playing
17 0 1 0 18
13 6 0 0 19
4 0 0 0 4
22 1 0 0 23
0 0 3 0 3

Tag cloud