Cameron Fletcher

Random thoughts and dicussions on the things that interest me
File Transfer via Clipboard Text

I have recently been involved in some work that requires me to program on a Remote Desktop (via RDP over an SSL connection) so there is no development software installed locally. One of the downsides is that due to the restricted nature of the connection only text based copy and paste works, so it is not possible to transfer files onto the development environment. Not only this, but although the local machine has access to the internet, the development environment has none.

The solution? I wrote a console based application called MemCopy to copy files to and from the clipboard as text. It does this by either encoding the file as Base64 then saving it as text on the clipboard, or decoding it from the clipboard.

I'd only written this in one of the environments, so I had to decode it in the other before I could use it - a bit chicken and egg, if you ask me. Anyway, I have attached a link to the encoded text here (you didn't think I was going to give you the solution on a plate did you?)

The code below is all that was required to decode it. I placed the encoding into the resources as a file.

byte[] buffer = Convert.FromBase64String(Resources.Encoding);
FileStream stream = new FileStream("memcopy.zip", FileMode.Create,FileAccess.ReadWrite);
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(buffer);
writer.Close();

For those of you without the technical acumen to decode the above source, I have attached a working copy MemCopy as a zip file here. Simply download and extract MemCopy to a folder of your choosing, copy the contents of the encoded text (above) into memory, then execute MemCopy from the extracted location using the following command:

MemCopy /decode MemCopy.zip

The result? Awesomeness.

Posted: Sep 24 2009, 18:27 by flet0496 | Comments (4) RSS comment feed |
  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET
The [IT] Stig?

Andy Aitken in his normal working attire.

Posted: Sep 07 2009, 12:21 by flet0496 | Comments (0) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
#500 Firewall Error ##

Occasionally I have received the following error when trying to send emails to other organisation from Exchange 2007:

Diagnostic information for administrators:
Generating server: exchange-server.internal.domain.com
enduser@externaldomain.com
external.mail.server.domain.com #500 Firewall Error ##

It turns out that this is actually due to the Cisco router inspecting SMTP traffic. Entering the command below into IOS fixed the issue:

no ip inspect name SDM_LOW esmtp

Posted: Aug 22 2009, 15:11 by flet0496 | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Cisco
Technical Skills Datasheet

I am finding it increasingly hard to illustrate my technical skills on my CV due to the large amount of software I have had exposure to – and I don’t mean just sat next to. So I have created my own technical skills datasheet to accompany my CV a copy of which can be found here.

Evidently, you'll notice that my technical prowess do not extend to creation of well formatted PDF files, as upon resizing or come to print the document the font sizing, spacing, and subsequent readability goes haywire. I blame Adobe.

Posted: Aug 14 2009, 11:51 by flet0496 | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET
Catastrophic Failure

Andy Aitken, a guy I work with, evidently abused his copy of Visual Studio 2008 to breaking point and got this message in return. Hats off.

Andy Aitken's Exception

UPDATE: It turns out that a week later I too rose to the dizzy heights of Aitken's abuse:

Cameron Fletcher's Exception

Posted: Aug 11 2009, 16:20 by flet0496 | Comments (0) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET
Converting a CTE T-SQL statement into Linq2Sql

Below is the SQL statement including the common table expression that I need to re-write using Linq2Sql for an application I’m working on. The query identifies the subset of most up-to-date records using a group by query in a CTE. It then performs a join back to the booking table to return the full list of most up-to-date records.What is noticeable about this particular piece of code is the join between table and CTE making use of the isnull keyword.

with cte (RootBookingID, CreatedTime)
as
(
    select
        isnull(ParentBookingID, BookingID),
        max(CreatedTime) -- get the latset version
    from [system].Booking
    where Deleted = 0
    group by isnull(ParentBookingIDBookingID)
)
select b.*
from [system].Booking b inner join cte
on cte.RootBookingID = isnull(b.ParentBookingID, b.BookingID)
       and cte.CreatedTime = b.CreatedTime;

When rewriting this in C#, we first declare the query for the CTE as its own variable.

//define the cte to use as an anchor
var cte = from b in this.Model.Bookings
          where b.Deleted == false
          group b by b.ParentBookingID ?? b.ID into g
          select new
          {
              BookingID = g.Key,
              CreatedTime = g.Max(b => b.CreatedTime)
          };

We can then reuse this variable within our core query (below). Notice how the join on isnull is created by explicitly defining the name of the anonymous type.

//perform a join on the cte to get the results
var qry = from b in this.Model.Bookings
          joinin cte
                  on new
                  {
                      ID = (b.ParentBookingID ?? b.ID),
                      b.CreatedTime
                  } equals new
                  {
                      ID = c.BookingID,
                      c.CreatedTime
                  }
          order by b.PickUpTime
          select b;

The post here explains the stumbling blocks I encountered:

To join multi-valued keys you need to construct an anonymous type on both sides of the 'equals' that is the same type. The anonymous type initializer expression infers both type and name of members from the expressions that are supplied. Using the name = value syntax in the initializer you can specify the name the compiler uses when creating the type. If all members, types, and names are the same then the anonymous types are the same type.

Posted: Jul 21 2009, 13:03 by flet0496 | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET
Flip-flops, beer, and a bottle opener

I bought got my brother to buy some flip-flops at the weekend. Check them out:

And guess what is located on the sole of the them? That’s right, a bottle opener. One per flip-flop:

Now I just need a beer. And a holiday…

Posted: Jul 13 2009, 21:32 by flet0496 | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
Hard drive weight increasing?

Possibly the funniest technical question I've seen posted on a technical message board. Ever. Worth a look and you're guaranteed a laugh. 

http://social.answers.microsoft.com/Forums/en-US/vistahardware/thread/720108ee-0a9c-4090-b62d-bbd5cb1a7605

Posted: Jul 08 2009, 08:43 by flet0496 | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under:
An error was encountered. Please return to the previous page and try again.

If you are trying to use the ASP.NET website administration tool and are getting a web page stating "An error was encountered. Please return to the previous page and try again." it is possible that you have the same error as me (see below). Another symptom is clicking on the "How do I use this tool?" link and being presented with a message stating "Tool Has Timed Out". 

It would appear that Microsoft, in its wisdom, has developed a tool that cannot handle the path of the web application it is designed to administer containing non-standard characters. Or spaces. To fix, simply copy your solution to a path that doesn't contain any non-standard characters. Or spaces.

eg. Changing C:\Will (Not.) Work\see.sln to C:\WillWork\see.sln

It's an easy fix to a problem most likely created by a tool both from, and within, Microsoft. 

Posted: Jun 16 2009, 12:41 by flet0496 | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET
Sentence and Word Analysis #2

This as part two of my post on sentence and word analysis. In part one I discussed my motives for analysing the RSS feed in question. In this post I shall be building upon my initial findings and presenting the C# and SQL code that I used to do so.

I have continued to run the RSS reader periodically and now have 284 job descriptions to analyse. I have run through the initial results and identified the words and sentences that are irrelevant and placed these into a keywords table so that I may strip them from my results. This was quite a lengthy process as there were a significant number of these to exclude - nearly a thousand. Following that, I looked through the results and because of the different permutations of the keywords that I was looking for it was evident that I would need to look within the top 100 words/phrases to identify the ones that I was interested in. I made a decision to leave in keywords that related to job skills in addition to computer languages.

The top 100 keyword/skills results from analysis of 284 job descriptions. The analysis took 9.5 minutes to run.

#  Word Rank   #  Word Rank   #  Word Rank
1   C# 301   35   CSS 29   69   structured 16
2   SQL 206   36   E-commerce 29   70   Unix 16
3   .NET 203   37   ASP 26   71   Website 16
4   Server 173   38   C# .NET 26   72   will work 16
5   ASP.NET 129   39   CRM 26   73   automated 15
6   SQL Server 122   40   Equities 26   74   Datawarehouse 15
7   SharePoint 79   41   RAD 26   75   Derivative 15
8   Office 78   42   SQL Server 2005 26   76   desk 15
9   Test 70   43   VBA 25   77   Equity 15
10   C++ 69   44   Winforms 25   78   International 15
11   banking 63   45   C#. 23   79   MOSS 15
12   Java 59   46   C#.NET 23   80   OLAP 15
13   London 59   47   Fixed Income 23   81   VB6 15
14   Front Office 55   48   framework 23   82   ASAP 14
15   XML 52   49   Quant 22   83   Back End 14
16   Windows 47   50  2 21   84   Basic 14
17   Oracle 45   51   Visual Studio 21   85   business req. 14
18   tools 45   52   GUI 20   86   comm. skills 14
19   database 44   53   VB.NET 20   87   document 14
20   Excel 43   54   Web based 20   88   experienced C# 14
21   FX 43   55   Access 19   89   functional 14
22   MS 41   56   Cash 18   90   VB 14
23   HTML 40   57   digital 18   91   .NET Framework 13
24   C# ASP.NET 39   58   Finance 18   92   .NET 3.5 13
25   life cycle 38   59   AJAX 17   93   ASP.NET C# 13
26   C# Developer 36   60   Biztalk 17   94   ASP.Net Developer 13
27   Reporting 36   61   Excel VBA 17   95   C# ASP.net SQL 13
28   analyst 34   62   media 17   96   degree 13
29   JavaScript 33   63   Security 17   97   MS SQL 13
30  3.5 32   64   ASP.Net SQL 16   98   Rates FX 13
31   agile 31   65   CMS 16   99   Reporting Services 13
32   architecture 31   66   credit derivatives 16   100   Siebel 13
33   communication 31   67   Silverlight 16      
34   .NET developer 29   68   Sophis 16      

A link to a backup of the database may be found here: jobs.zip (392.41 kb)
You will need to restore this into SQL Server before the .NET code (below) will work.

A link to the .NET code (C#) is here: RssReader.zip (3.48 kb)
You will need to modify the App.Config file to point to your RSS feed and database.

To run the analysis on the sentances in the database you'll need to execute the 'analyse' stored procedure. Once that has finished execuiting you'll need to perform a select from the 'analysis_results' view to view the results.

Posted: Jun 09 2009, 14:21 by flet0496 | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .NET