Become A Programmer in 9 Weeks

18. April 2013 19:39

 

Visit our new project at www.codercamps.com today!


Elite Developers

29. January 2013 14:19



I use the term "elite developer" a lot when describing the people I want (and have) at our company.  I realized however that I need to define that very specifically or we would be inadvertantly hiring the wrong people. 

Here is what I think being an "elite" developer means:


  1. No excuses.  If it's in your core technology expertise (.Net, Java, iOS), you shouldn't have to make excuses for lackluster code or missing deadlines.  Elite developers do it the right way, the first time.
  2. Driven to exceptionalism. Clocking in at 9 and leaving at 5 is certainly a framework, but it shouldn't have to be pointed out that a milestone for your project is approaching.  You should be overwhelmed with a sense of urgency when that deadline is approaching and rallying the team behind a concerted effort to bring all elements in line to reach the common goals.
  3. Predicting Problems. Knowing what you don't know and predicting issues that are coming are one part, but making sure the decision makers on the projects know what is needed and that there's a problem is another part.  You should be good enough at what you do to know that a problem is coming before it becomes one.
  4. Technology is a tool. Elite developers don't fall in love with one framework or technology.  Devs that do will regret it.  You should be smart enough to realize that we have been solving the same problems for decades using different tools.   Yes, some things have become easier using new tools, but there are still a number of ways to solve a problem.  An elite developer should use the best tool to solve the business problem, not the favorite, fad of the moment (example: Silverlight).
  5. Attitude. We wake up every day with only one thing that we can certainly control - ourselves.  Your attitude is your responsibility and your team is counting on you to perform as a functional piece of the team.   If you aren't loving your job, quit.  You aren't doing anyone any favors by being in a bad mood.
  6. Versatility. Smart people that can get the job done right - irrespective of the framework, platform, etc. (See #4).  You should be very accustomed to picking up new ways to solve the same problems.  If you are stuck in one technology, you aren't an asset that we need on our team and I am sure you will limit your options in the job market as a whole.  You must adapt to survive.

 


Windows Azure - SQL Server Default Instance

20. April 2011 05:11

It may be necessary to change the SQL Server instance that your Windows Azure Storage account uses if you aren't using SQL Server Express.  The error you will see is this:

 

the SQL Server instance ‘localhost\SQLExpress’ could not be found.   Please configure the SQL Server instance for Development Storage using the ‘DSInit’ utility in the Windows Azure SDK.

 

From the start menu find the Windows Azure SDK Command Prompt like this:

 

 

 

 

Then once the command prompt starts, you need to run the dsinit app.  In the picture below is for the Default Instance. The "/sqlinstance:." can be replaced with your specific instance name, so if your instance is "ENTERPRISE", you would put "/sqlinstance:ENTERPRISE".

 

 

 

 

Please note that this does not work on other computers.  Your sql server instance must be local to your current machine.  A development nightmare, yes, but a nessary evil at this time.

 


Multiple E-Commerce Storefronts - One Really Amazing Application

14. April 2011 04:39

We have been working hard on our newest addition to the product family, Spectrum Storefront.  I know some of you have been waiting for this and are as excited as we are.  The basics are outlined in the attached files.  We are looking forward to issuing beta licenses at the end of May.  Keep checking in with us and for more information, look at www.spectrumstorefront.com very soon.

 

Spectrum SCM - Catalog Inheritance.pdf (151.95 kb)

Spectrum Storefront - Catalog Management.pdf (132.55 kb)


New Control! Silverlight AutoScrollViewer.

17. March 2011 18:35

I was inspired by the Zune's quickstart page and came up with this really handy control.  Let me know what you think!

 

http://www.coderforrent.com/Products/SilverlightAutoScrollViewer


C# Shallow Copy / Downcasting

15. March 2011 09:56

Today I found that the child class can't be passed over a WCF service as the base class.  I tried using the KnownType and ServiceKnownType attributes, which did allow the transfer, but then EntityFramework didn't like the child class.  My solution was to write a quick shallow copy function.  Enjoy!

 

public static class Copy
    {
        public static T Shallow< T>(this object source)
        {
            return Shallow< T>(source, (T)Activator.CreateInstance(typeof(T)));
        }
        public static T Shallow<T>(this object source, T target)
        {
            foreach (PropertyInfo pi in typeof(T).GetProperties())
            {
             var prop =  source.GetType().GetProperty(pi.Name);
                    
                if(prop != null)
                    prop.SetValue(target, pi.GetValue(source, null), null);
            }
            return target;
        }


    }

Binary Difference

16. January 2011 16:49

I wanted a way to get the difference between two images, so that I can transfer only the changes between client/servers.  Here's what I came up with... thoughts?

 

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


namespace CFR.BinaryDifference
{
    public class Diff
    {
        public int Position { get; set; }
        public byte[] Bytes { get; set; }

        public Diff()
        {

        }

        public static List<Diff> Compare(byte[] original, byte[] comp)
        {
            return Compare(original, comp, 1, 0);
        }
        public static List<Diff> Compare(byte[] original, byte[] comp, int inc, int start)
        {
            if (original.Length != comp.Length)
                throw new NotSupportedException("Parameters \"original\" and \"comp\" must be of the same length");

            List<Diff> results = new List<Diff>();
            //bool skipBack = false;

            for (int i = start; i < original.Length; i += inc)
            {
                if (original[i] != comp[i])
                {
                    Diff d = new Diff();
                    int length = 0;

                    int pos = i;
                    for (int j = Math.Max(i - inc + 1, 0); j < original.Length; j++)
                    {
                        if (original[j] != comp[j])
                        {
                            if (length == 0)
                                pos = j;

                            length++;
                        }
                        else if (length > 0 && j < i)
                        {
                            length++;
                        }
                        else if (length > 0 && j >= i)
                            break;
                    }

                    d.Position = pos;
                    d.Bytes = new byte[length];
                    Array.Copy(comp, pos, d.Bytes, 0, length);

                    results.Add(d);

                    i = pos + length;

                }

            }

            return results;
        }
        public static byte?[] Combine(List<Diff> differences)
        {
            return Combine(differences, 0);
        }
        public static byte?[] Combine(List<Diff> differences, byte defaultValue)
        {
            if (differences.Count == 0)
                return new byte?[0];

            byte?[] bytes = new byte?[differences.Max(d => d.Position + d.Bytes.Length)];
            for (int i = 0; i < differences.Count; i++)
            {
                Diff d = differences[i];
                for (int j = d.Position; j < d.Bytes.Length + d.Position; j++)
                {
                    bytes[j] = d.Bytes[j - d.Position];
                }
            }

            return bytes;
        }
        public static byte[] Merge(byte[] target, List<Diff> differences)
        {
            for (int i = 0; i < differences.Count; i++)
            {
                Diff d = differences[i];

                for (int j = 0; j < d.Bytes.Length; j++)
                {
                    target[d.Position + j] = d.Bytes[j];
                }
            }

            return target;
        }
    }
}

WCF in a Windows Service using Entity Framework

11. November 2010 18:40

Tried sending an enitity over a WCF service... got this....  

An error occurred while receiving the HTTP response to http://localhost:1337/MyService/service. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

 

So, to fix it I used the Microsoft Trace Viewer on the service side to get to this error:

 

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

 

The problem was that I was using a using statement around my DataEntities context and the service was trying to call out to the context before serializing but it found that it was disposed of already.  Removing the using{} clause fixed the problem.


Fill a DataSet from delimited file

24. October 2010 15:32

Explains how to fill a dataset with the information stored in a delimited text file
Introduction
This code allows you to take data stored in a text file and populate a DataSet with it. It contains one static function that:

- Opens the file
- Makes a DataSet with a DataTable of the given name
- Populates the DataTable with the correct columns (pulled from the first line of the text file)
- Populates the DataTable with data and returns the DataSet.

Background
Anyone who works in business knows that while the delimited text file is the lowest common denominator of data transfers, the process of handling that data can be a pain. This class is an attempt to make handling these files as easy as possible.

Using the code
Using this code is simple. Include it in your project and call it like this:

 

DataSet ds = TextToDataSet.Convert("c:\test.txt", "MyNewTable", "\t");

 

It is necessary to give the full path to the file, so if you use this class in an ASP.NET application, the code may look something like this:

DataSet ds = TextToDataSet.Convert(Server.MapPath("test.txt"), "MyNewTable", "\t");

The last parameter is the delimiter parameter. This is what separates each column from the next. In the case shown we pass it the escape sequence for a horizontal tab, but you can pass any string such as a space (" ") or a semi-colon(;). You may find this list helpful:
Escape Sequences for Formatting
Escape Sequence
 Purpose
 
\a
 bell (alert)
 
\b
 backspace
 
\f
 form feed
 
\n
 new line
 
\r
 carriage return
 
\t
 horizontal tab
 
\v
 vertical tab
 
\'
 single quotation mark
 
\"
 double quotation mark
 
\\
 backslash
 
\?
 literal question mark
 
\ooo
 ASCII character shown in octal notation
 
\xhh
 ASCII character shown in hexadecimal notation
 
\xhhhh
 -UNICODE character shown in hexadecimal notation when this escape sequence is used in a wide-character constant or a UNICODE string literal
 

 

There are many more but these are the most common.

I guess now all that is left is to give you the code, so here it is:

 

using System;
using System.Data;
using System.IO;
namespace TestTextToDataSet
{
  public class TextToDataSet
  {
    public TextToDataSet()
    {  }
  
   /// <summary>
    /// Converts a given delimited file into a dataset. 
    /// Assumes that the first line    
  /// of the text file contains the column names.
  /// </summary>
    /// <param name="File">The name of the file to open</param>    
  /// <param name="TableName">The name of the 
  /// Table to be made within the DataSet returned</param>
    /// <param name="delimiter">The string to delimit by</param>
   /// <returns></returns>  
  public static DataSet Convert(string File, 
   string TableName, string delimiter)
    {   
    //The DataSet to Return
    DataSet result = new DataSet();
    
    //Open the file in a stream reader.
      StreamReader s = new StreamReader(File);
        
    //Split the first line into the columns       
     string[] columns = s.ReadLine().Split(delimiter.ToCharArray());
  
    //Add the new DataTable to the RecordSet
      result.Tables.Add(TableName);
    
    //Cycle the colums, adding those that don't exist yet 
    //and sequencing the one that do.
      foreach(string col in columns)
      {
        bool added = false;
        string next = "";
      int i = 0;
      while(!added)        
      {
        //Build the column name and remove any unwanted characters.
        string columnname = col + next;
         columnname = columnname.Replace("#","");
          columnname = columnname.Replace("'","");
          columnname = columnname.Replace("&","");
        
        //See if the column already exists
        if(!result.Tables[TableName].Columns.Contains(columnname))
          {
          //if it doesn't then we add it here and mark it as added
            result.Tables[TableName].Columns.Add(columnname);
            added = true;
          }
          else
        {
          //if it did exist then we increment the sequencer and try again.
            i++;  
          next = "_" + i.ToString();
          }         
      }
    }
    
    //Read the rest of the data in the file.        
     string AllData = s.ReadToEnd();
    
    //Split off each row at the Carriage Return/Line Feed
    //Default line ending in most windows exports.  
    //You may have to edit this to match your particular file.
    //This will work for Excel, Access, etc. default exports.
    string[] rows = AllData.Split("\r\n".ToCharArray());
      //Now add each row to the DataSet        
    foreach(string r in rows)
      {
      //Split the row at the delimiter.
        string[] items = r.Split(delimiter.ToCharArray());
      
      //Add the item
       result.Tables[TableName].Rows.Add(items);  
      }
    
    //Return the imported data.        
    return result;
    }
  }
}

 

Points of Interest
You can overrload this function many different ways to fit your project's needs. This is just one way that I do it. If there is a desire for more options I will post some of them. Enjoy the code!


Mouse Wheel and the ScrollViewer

22. October 2010 03:40

Today I had a problem where the ScrollViewer in my user control would not scroll using the mouse wheel unless it was over a control like a textbox or label... anything other than the grid that is LayoutRoot.  It went something like this:


 <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="1" BorderThickness="0" >

<Grid x:Name="LayoutRoot" >

 

After much trial and error, I figured out that all is needed is a background... it can even be set to Transparent. So, I did this:

 


   <ScrollViewer Grid.Row="0"  VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="1" BorderThickness="0" >
                <Border Background="Transparent">
                    <Grid x:Name="LayoutRoot"  >

 

I know it is simple and probably makes me look like igmo, but I thought it might help somebody else one day. :)


Learn Programming in 9 Weeks

Coder Camps is innovating programming by giving people the option to skip 4 years of college to start a new career in programming in only 9 weeks - GUARANTEED.

www.codercamps.com

Custom Development

ALL USA BASED DEVELOPERS

 

 

 

Coder For Rent is a one-stop shop for all your .Net programming needs.  We can make project-based fixed bids as well as hourly/weekly/monthly quotes.  Our goal is to meet your needs the first time, saving you time and money.

 

Call to speak with an account manager. We take projects of all sizes.

 

713-340-2001