tag:blogger.com,1999:blog-83357938381111473152024-03-04T20:09:37.975-08:00Adventures in CodeAdam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.comBlogger30125tag:blogger.com,1999:blog-8335793838111147315.post-25344713913821194992019-06-18T07:56:00.002-07:002019-07-04T06:59:02.743-07:00C++ Pointers and References: Quick Reference<div dir="ltr" style="text-align: left;" trbidi="on">
After watching a few hours of an Intro to C++ series on Pluralsight, this is a succinct aide-memoir for myself for C++ pointers and references.
<br />
<br />
<script src="https://gist.github.com/adamfeather/ef185b54958f4f93d1176e065be49dcb.js"></script>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-18087818409941101492018-10-08T04:16:00.001-07:002018-10-08T04:18:55.807-07:00Impersonation in .NET<div dir="ltr" style="text-align: left;" trbidi="on">
Recently, I had need to programmatically impersonate a Windows account which has elevated permissions. In my case, only one step in a multi-step process required the extended permissions so the impersonation was temporary.<br />
<br />
To do so in .NET a P/Invoke call into unmanaged code is required. The detail of which can be found here: <a href="https://docs.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity.impersonate?view=netframework-4.7.2" target="_blank">WindowsIdentity.Impersonate</a><br />
<br />
A call into unmanaged code is made in order to retrieve a user token. The token is then passed to a framework class which facilitates the impersonation.<br />
<br />
I've written a small class which wraps this functionality and thought it may be of use to other people:<br />
<br />
<script src="https://gist.github.com/adamfeather/5de849b66e3885d1fa37a867547c7c8c.js"></script>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-44754180551781020282018-09-17T08:37:00.001-07:002018-10-02T03:24:49.766-07:00Understanding Streams (in .NET) #2<div dir="ltr" style="text-align: left;" trbidi="on">
In <a href="https://adam-feather.blogspot.com/2018/09/understanding-streams-in-net-1.html">Part 1</a> we looked at streams from a conceptual point of view. We learnt that streams are an abstraction over moving data from point A to point B. A very simple example of reading from a stream can be used to demonstrate this:
<br /><br />
<script src="https://gist.github.com/adamfeather/abc642a7ce64c6bc79ec9d4ecf6ce091.js"></script>
The <b>GetStream()</b> method returns a stream object from which we can read bytes until we are told there are no more bytes to read, which is indicated by -1 being returned. The stream abstraction is already working for us here as we've no idea - and potentially don't care - about where the data is coming from: we can simply keep asking for data until we're told there's no more data to be had.
<br /><br />
To peek behind the curtain a little here is the <b>GetStream()</b> method:
<br /><br />
<script src="https://gist.github.com/adamfeather/c66752885f43b7455e36ed57e0da0e0d.js"></script>
All I'm doing here is converting a string into an byte array where each byte is the ASCII representation of a character in the string. I then create a new <b>MemoryStream</b> object passing the byte array in to the constructor. Through the power of inheritance and the <a href="https://en.wikipedia.org/wiki/Liskov_substitution_principle">Liskov substitution principle</a> we can treat the MemoryStream as it's parent Stream object.<br />
On its own this doesn't seem terribly useful. But the data in the <b>Stream</b> doesn't have to be from an in-memory source. I could change the <b>GetStream()</b> method to the following and still read from it in the same way, even though the data now exists in a file:
<br /><br />
<script src="https://gist.github.com/adamfeather/e5110944cdbbb85b187ace67dae0e426.js"></script>
I could even be reading from a stream whose bytes come over the internet:
<br /><br />
<script src="https://gist.github.com/adamfeather/e9121f142b7346530bc2e1833bd61cef.js"></script>
These examples are a little contrived and not awfully useful as all I do with the byte I've read is write it out to the console and move onto the next one. That being said, bytes are the essential nature of all data, so we have an solid starting point to do more interesting things...
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-24203997881850935172018-09-14T03:29:00.000-07:002018-09-14T03:29:03.351-07:00Understanding Streams (in .NET) #1<div dir="ltr" style="text-align: left;" trbidi="on">
I'm going to attempt to explain streams - with C# as the example language - using the same tiered approach I used to <a href="http://adam-feather.blogspot.co.uk/2017/01/understanding-base64-encoding.html" target="_blank">explain base64 encoding</a> previously. Caveat emptor: this series is, in part, about getting the topic straight in my head, so please don't take anything here as gospel.<br />
<br />
<b><u>Tier 1.</u></b><br />
<u><br /></u>
<b>Current Understanding: </b><br />
<b><br /></b>
You may have heard someone talk about "streaming data" or "writing to a stream" - perhaps you've even used the term(s) yourself - but you're only, at best, dimly aware of what it means.<br />
<br />
<u>N.B.</u> If you have a greater understanding than the above it may make sense for you to skip over this tier.<br />
<br />
<b>Intro:</b><br />
<br />
Moving data about is useful and we do it a lot! You requested the movement of data by asking your browser to display this website: a Blogger server somewhere has this webpage (or knows how to assemble it) and you asked for a copy of that data. Ultimately, that involved the transmission of binary digits (bits) but that's rarely the level at which anyone wishes to work. To avoid doing so we invent higher level models of abstraction to help us reason about and perform such tasks. Streams are one of these such abstractions.<br />
<br />
<b>Terminology & Pre(r)amble:</b><br />
<b><br /></b>
I completely agree that one of the two hard things in computer science is "naming thing". <a href="https://martinfowler.com/bliki/TwoHardThings.html" target="_blank">Two Hard Things</a><br />
<b><br /></b>However... with that said, as an analogy I'm not sure a <i>stream </i>is the best one for thinking about this topic. It's certainly not how I think about it. The term"stream" seems to have been chosen to convey a flow of data - "river", "brook", or "creek" could equally have been used. And to that extent it has utility, however, I'm not sure its explanatory power holds out as one explores the subject further.<br />
<br />
I've occasionally thought a more instructive way of thinking about <i>reading from a stream </i>would be <i>drinking from an unseen cup via a straw.</i> Here, you are sucking up liquid and don't know how much is left until at some point you go to suck up a mouthful and there's no liquid left. This is how reading from a stream works: you don't how much data there is to be read until you go to get the next chunk of data and there is none. Strictly speaking, this isn't <i>always </i>the case - we'll cover that later.<br />
<b><br /></b>
The term "stream" is both a noun and a verb in computing: you can have "a stream" of data; I can "stream data to you"; you might be "streaming data from me".<br />
<br />
<b>Why should I care?</b><br />
<b><br /></b>
Streaming, at it's most fundamental, is about moving data from one place to another; streaming is taking data which exists at A and moving it to B. It's a concept common to all programming languages, and in computing more widely, so understanding it has broad utility.<br />
<br />
So, if you want to move data about as part of your application it may well help to know about streams!<br />
<br />
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-67566680922345273882018-04-25T00:52:00.000-07:002018-04-25T00:55:01.668-07:00PostgreSQL: Script to Tear Down and Recreate Database<div dir="ltr" style="text-align: left;" trbidi="on">
I've used this as either a either PowerShell or Bash script when in a development environment. You'll need the <span style="background-color: #eeeeee;">postgres</span> user's password. The .sql file is the file I keep in order to be able to generate the structure of my database (and seed it) in an empty database.
<div><br /></div>
<div>
It connects as the <span style="background-color: #eeeeee;">postgres</span> user to the <span style="background-color: #eeeeee;">postgres</span> database, drops the specified database, if it exists, creates the new database, connects to the new database, and executes the schema & seed SQL file.</div>
<div><br /><div>
</div>
</div>
</div>
<script src="https://gist.github.com/adamfeather/c44df0455b73e7bbccf4973d98a67817.js"></script>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-51525090004621539722017-05-12T08:35:00.003-07:002017-05-12T08:35:37.193-07:00The Zen of Python - Programming Aphorisms<div dir="ltr" style="text-align: left;" trbidi="on">
I was linked to the below Zen of Python today. And although Python is in the name the aphorisms are good for all languages. Simplicity, Explicitness and Readability are hard to achieve but pay dividends when implemented.<br />
<br />
<i>Beautiful is better than ugly.</i><br />
<i>Explicit is better than implicit.</i><br />
<i>Simple is better than complex.</i><br />
<i>Complex is better than complicated.</i><br />
<i>Flat is better than nested.</i><br />
<i>Sparse is better than dense.</i><br />
<i>Readability counts.</i><br />
<i>Special cases aren't special enough to break the rules.</i><br />
<i>Although practicality beats purity.</i><br />
<i>Errors should never pass silently.</i><br />
<i>Unless explicitly silenced.</i><br />
<i>In the face of ambiguity, refuse the temptation to guess.</i><br />
<i>There should be one-- and preferably only one --obvious way to do it.</i><br />
<i>Although that way may not be obvious at first unless you're Dutch.</i><br />
<i>Now is better than never.</i><br />
<i>Although never is often better than *right* now.</i><br />
<i>If the implementation is hard to explain, it's a bad idea.</i><br />
<i>If the implementation is easy to explain, it may be a good idea.</i><br />
<i>Namespaces are one honking great idea -- let's do more of those!</i><br />
<i><a href="https://www.blogger.com/goog_1466467912"><br /></a></i>
<a href="https://www.python.org/dev/peps/pep-0020/#id3">https://www.python.org/dev/peps/pep-0020/#id3</a><br />
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-56687147241555072992017-04-10T06:15:00.001-07:002017-04-10T06:15:18.337-07:00Visualising and Understanding Recursion<div dir="ltr" style="text-align: left;" trbidi="on">
As someone who learns best visually, recursion (recursive functions in software) can be a bit of a mind-bender and I periodically have to go back and refresh my understanding of it. A great video to do so with is this:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe width="320" height="266" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/Mv9NEXX1VHc/0.jpg" src="https://www.youtube.com/embed/Mv9NEXX1VHc?feature=player_embedded" frameborder="0" allowfullscreen></iframe></div>
<br />
<br />
<a href="https://www.youtube.com/channel/UC9-y-6csu5WGm29I7JiwpnA" target="_blank">Computerphile</a> is a brilliant YouTube channel generally and anyone with an interest in computing should subscribe to it. </div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-14724462395069612102017-02-08T04:27:00.003-08:002017-02-08T04:50:33.429-08:00Understanding Base64 Encoding #5<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Tier 5<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">This tier is aimed at
filling in a few gaps, showing the wider applicability of base64 encoding, and
pointing to further reading.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Padding: The Trailing
Equals Character<o:p></o:p></span></u></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">When I first looked at
the characters used in base64 encoding I noticed there was a cheeky 65<sup>th</sup>
character (‘=’) sometimes appearing once or twice at the end of encoded data.
It’s actually a special character used for when source binary data doesn’t
divide neatly into three byte blocks. A quick example to illustrate.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Imagine I want to
base64 encode the following four 8-bit bytes:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">01000001 01100100
01100001 01101101<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">I take the first three
octets: <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">01000001 01100100
01100001<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Represent them as four
sextets: <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">010000 010110 010001
100001<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And encode using my
encoding key, producing: QWRh<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">But now I have a
lonely, final octet left to encode: 01101101<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">In base64 encoding it’s
simply padded out with trailing zeros until we have another three octets: <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">01101101 00000000
00000000<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And converted it to
sextets as normal:<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">011011 010000 000000
000000<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Any sextet which <i>contains</i> <i>nothing but padded zeros</i> gets represented as ‘=’.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">So the rest of the encoded
data becomes: bQ==.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">The ‘=’ character is a
bit of a courtesy and not every implementation of base64 encoding uses it; it
is possible to recreate the original binary data without using ‘=’ for padding,
it’s is just more explicit to include it. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Other Uses:<o:p></o:p></span></u></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif;"><span style="font-size: 10pt;">Base64 encoding is typically used in scenarios where
representing binary data as a limited set of ASCII characters is desirable.
This could be when using an 8-bit (or greater) character encoding isn’t viable,
or when you wish to </span><span style="font-size: 13.3333px;">embed</span><span style="font-size: 10pt;"> binary data in a </span><span style="font-size: 13.3333px;">explicitly</span><span style="font-size: 10pt;"> text-based medium, or when
sending non-alpha-numeric characters could be an issue. <o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Attachments to emails are base64 encoded, as are the
username and passwords sent for basic HTTP authentication. The specifics of why
base64 encoding is used in these scenarios is beyond this series, but reading
about </span><a href="https://en.wikipedia.org/wiki/8-bit_clean"><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">https://en.wikipedia.org/wiki/8-bit_clean</span></a><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"> and </span><a href="https://en.wikipedia.org/wiki/Email_attachment"><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">https://en.wikipedia.org/wiki/Email_attachment</span></a><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"> gives you a good idea of why this is the case. The
below quote taken from the Email Attachment Wikipedia page gives a good sense
of the history:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<i><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">“Originally Internet SMTP email
was 7-bit ASCII text only, and attaching files was done by manually encoding
8-bit files using uuencode, BinHex or xxencode and pasting the resulting text
into the body of the message.” <o:p></o:p></span></i></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<u><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Further
Resources:<o:p></o:p></span></u></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Once
you grasped the basics of base64 encoding the Wikipedia article actually
becomes useful. To my mind it’s missing a Tier 1 style explanation but it
otherwise quite passable. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">There’s
an Oracle blog post which is also good – again, if you’ve got some base knowledge
to work from.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And
when you want to go full nerd there’s the IETF spec!<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><a href="https://en.wikipedia.org/wiki/Base64">https://en.wikipedia.org/wiki/Base64</a><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><a href="https://blogs.oracle.com/rammenon/entry/base64_explained">https://blogs.oracle.com/rammenon/entry/base64_explained</a><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><a href="https://tools.ietf.org/html/rfc4648">https://tools.ietf.org/html/rfc4648</a></span></div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-55599267193767498412017-02-07T07:49:00.003-08:002017-02-08T04:28:33.542-08:00Understanding Base64 Encoding #4<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Tier 4</b><br />
<br />
For this tier I’m going to start to push the strained and sanitised analogy into the background and, hopefully, bring the hard edges of base64 encoding into focus.<br />
<br />
First, a quick recap on what we’ve established: <br />
<ul style="text-align: left;">
<li>Base64 encoding is a methodology by which we can represent arbitrary binary data (an image, in our example) as a string of ASCII characters.</li>
<li>The 64 characters used when base64 encoding are a subset of the full ASCII character set. In our case: A-Z, a-z, 0-9, +, and /.</li>
<li>64 characters can be neatly represented by a block of 6 bits.</li>
<li>When base64 encoding, the binary source data is broken into 3 octet blocks (24 bits) which is then parsed as 4 sextet blocks (also 24 bits); 24 being the first common multiple of 8 and 6. </li>
</ul>
And our encoding key looked like this:<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLgI5Ks4B6KX3N-ai8B4ij-zz_o8FfpEPqTvd4kh6JvjDv_QVPomP8N2r7BlGUf4h6XWujwzOOKt1ydr4FG5u5JGJfy_0ILTB6CiwhEHVjS1piwsYZcmZ9Z0pKZrsmozfaX4PN_e_SGk/s1600/base64+wiki.png"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtLgI5Ks4B6KX3N-ai8B4ij-zz_o8FfpEPqTvd4kh6JvjDv_QVPomP8N2r7BlGUf4h6XWujwzOOKt1ydr4FG5u5JGJfy_0ILTB6CiwhEHVjS1piwsYZcmZ9Z0pKZrsmozfaX4PN_e_SGk/s320/base64+wiki.png" /></a></div>
<br />
So far we’ve been using a contrived example – a world with no digital communication – in an attempt to remove the contextual complexity of base64 encoding, concentrating on the essence of subject instead. But this only takes us so far. Let’s take a real world example of where base64 encoding could be used: <i>embedding images in XML</i>.<br />
<br />
Occasionally, it may be useful to be able to create an XML document which contains images – not references to images stored elsewhere, but the actual images themselves. I’ve seen this kind of thing done when archiving orders in an e-commerce context: a business wishes to archive orders made over five years ago, however, it also wants some reasonable level of access to that data should a pressing need to retrieve it arise.<br />
<div>
<br />
One approach to take could be to create an XML document for each order, one which contains a complete record of the transaction: top-level order details, items details, invoice address, delivery address, etc. All this is relatively straightforward. But the company may also decide, for completeness sake, that they wish to store a copy of the primary product images alongside the order. This causes a problem for a developer who doesn’t know about something like base64 encoding. For one who does, it’s fairly trivial. It could look something like this:<br />
<br />
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-p7EsXdGxJy_V6KF312VrSA9B5yinSY27Mwcel8mnUgJCM51gRb2tQ0iW_8tA9oX28YG8_XUZOhSipZlPCe_gS7q5yd_wncgZTptN8ZoO-6NUTUs6jgEWm8QOTHCuch1j93-yJxQcsNk/s1600/encodingxml.png"><img border="0" height="115" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-p7EsXdGxJy_V6KF312VrSA9B5yinSY27Mwcel8mnUgJCM51gRb2tQ0iW_8tA9oX28YG8_XUZOhSipZlPCe_gS7q5yd_wncgZTptN8ZoO-6NUTUs6jgEWm8QOTHCuch1j93-yJxQcsNk/s400/encodingxml.png" width="400" /></a></div>
<br />
Here you have co-opted a medium which is designed to carry text to also carry binary data, although it doesn't even necessarily know it! Those characters between the image nodes are just text characters as far as the XML is concerned. But if the reader knows they're base64 encoded binary data, then the images can be retrieved.<br />
<br />
Tier 5 will look to fill in a few of the gaps we've glossed over, briefly give a couple of other examples, and point at some further reading.<br />
<br />
Next <a href="http://adam-feather.blogspot.co.uk/2017/02/understanding-base64-encoding-5.html">Understanding Base64 Encoding #5</a><br />
<br /></div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-71795423891685162002017-02-02T06:30:00.000-08:002017-02-08T00:39:37.271-08:00Understanding Base64 Encoding #3<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Tier 3<o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">In
Tier 2 I found myself with some binary data (a 10 x 10 pixel image) and a
text-based medium (pen and paper) with which to communicate that image to
another computer. The image is about a thousand bytes large and I didn’t fancy
having to write down eight thousand ones and zeros in order to communicate that
image. I’d decided I need to encode the raw data to save myself some pain.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">My
initial instinct to encode the raw data is that I’ll use a character to
represent each possible byte value. This means I can reduce the characters I
have to write out from 8000 to 1000. i.e. instead of having to write the byte
value ‘00000000’, I could instead write ‘A’. As long as the recipient of my
encoded image knows the encoding, e.g. ‘A’ = ‘00000000’, then they can decode
the image. I start to write out my encoding key:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">00
| 00000000 = A<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">01
| 00000001 = B<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">02
| 00000010 = C<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">…<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">24
| 00011000 = Y<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">25
| 00011001 = Z<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">26
| 00011010 = a<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">27
| 00011011 = b<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">…<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">50
| 00110010 = y<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">51
| 00110011 = z<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">52
| 00110100 = 0<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">53
| 00110101 = 1<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">…<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">61
| 00111110 = 9<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">However,
as you might be able to see, by the time I’ve covered byte values 0 to 61 I’ve
run out of standard alpha-numeric characters (A-Z, a-z and 0-9). I’m going to have to start
using some less recognised characters – and/or possibly even fabricating new
ones – in order to get all the way to 256 (the distinct values which can be
represented by an 8-bit byte: 0 to 255). This gives me pause for thought. It
feels like there’s potential for confusion if I start using arcane or made-up
characters.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">I
stop and have a think. I’ve got 62 alphanumeric characters I’m confident any
decoder can easily recognise. I also suspect I could probably be fairly confident using a
handful of other characters, e.g. ‘=’, ‘!’, ‘+’, ‘:’, ‘&’, ‘/’, ‘\’, ‘%’,
etc. But that doesn’t bring me anywhere near to the 256 characters I’d need for
this encoding method.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">While
I’m ruminating on the problem a thought appears: 62, the number of easily
recognised characters I have, is close to the binarily-significant number 64 –
the distinct values which can be represented by 6 bits: 0 to 63 or 000000 to
111111. Perhaps I can use this? If I picked a couple of my additional
characters at random, say ‘+’ and ‘/’ that would bring me up to a encoding set
of 64 easily recognisable characters. I bank the thought.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Then
comes the flash of inspiration! Ultimately, I’m just trying to communicate a
series of ones and zeros from A to B. When thinking about those ones and zeros I’ve
always naturally separated them into 8-bit bytes, but for the purpose of
transmission there’s no inherent reason to do so; as long as the correct
sequence of ones and zeros reaches the other end the interpretation of
that data as 8-bit bytes is the receiving computer’s decision.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">I start to jot down my thinking. Imagine
the first 3 8-bit bytes of my 10 x 10 image are as follows:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">00000010
– 0011011 – 00110100<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">For transmission, I could split those 24 bits any way I like. Into two bit
chunks, for example:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">00
– 00 – 00 – 10 – 00 – 01 – 10 - 11 – 00 – 11 – 01 – 00<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Or
- going back to my previous thinking! – as 6-bit chunks:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">000000
– 100001 – 101100 – 110100<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And
with 6-bit chunks, I can use my recognisable character encoding key!<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">A
– h – s – 0<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif;"><span style="font-size: 10pt;">I could send you "Ahs0" and, as long as you knew the </span><span style="font-size: 13.3333px;">decryption</span><span style="font-size: 10pt;"> key, you could reverse the encryption and retrieve the bits.</span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And
this is the bare bones of base64 encoding. I’ll fill in the gaps and attempt to
extricate the tortured analogy from this explanation, applying the real world, in Tier 4.<o:p></o:p></span><br />
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><br /></span>
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Next >> <a href="http://adam-feather.blogspot.co.uk/2017/02/understanding-base64-encoding-4.html">Understanding Base64 Encoding #4</a></span></div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-51219327341205617862017-01-26T07:38:00.000-08:002017-02-08T00:38:58.817-08:00Understanding Base64 Encoding #2<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><b>Tier 2</b></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">If
Tier 1 is about establishing the scantest familiarity with a subject – hoping
to avoid looking glassy-eyed whenever it’s mentioned – then Tier 2 is about
beginning to understand the topic; perhaps a cursory interest has been kindled
and/or you’d like to be able to do a bit more than just identify the subject by
sight.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">To
that end, one of the first questions I like answered when getting to grips with
a new topic is “why does this thing exist?”. I’m going to begin to attempt to
answer this question for base64 encoding by giving a disingenuous, rather
long-winded, somewhat tortured analogy. I promise I’ll make amends in later tiers.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Imagine
a strange parallel universe in which inter-computer communication has never
happened. The parallel universe’s computers work in the same manner as ours,
just no one ever bothered to invent the technologies which allow computers to
communicate: no Internet, Bluetooth, portable digital devices – no floppy
discs, CDs, DVDs, USB drives, etc. Essentially, each computer is a lonely
digital island. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">In
this reality, if I create a super-cool bitmap image in the alternative
universe’s version of MS Paint, you’d physically have to come over to my house
and look at it on my screen; I have no digital means by which to transmit the
data to you. To add to my misery, you live on the other side of the country and,
despite my enthusiasm and entreatment for you to come visit, you’re not going
decamp for the sake of one bitmap image.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">So,
scratching my head, I begin to think about the problem and in a fit of pique I
come up with my first – and worst – solution to this problem: I’m going to
write the binary code out on pieces of paper and send the code in the post to
you. Every single one and zero. And then when you receive the paper full of
bits you can key them all in at your end and recreate the image. Perfect! <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">However,
I soon find, even if I only wanted to send the small 10 x 10 pixel image from
Tier 1 it’s ~1000 bytes. And given there are 8 bits in a byte that’s ~8000 ones
and zeros I’ll have to transcribe! I’m not so keen on this and imagine you’re
even less keen about having to key 8000 binary digits in at your end. We need a
shortcut. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">I’m
convinced the part about mailing you the code still has merit but I’m also certain
that raw ones and zeros aren’t the answer. What I need is some sort of
shorthand way of representing the same raw binary data; I need to encode it.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif;"><span style="font-size: 10pt;">This
is the essence of the problem base64 encoding looks to solve: how can a
text-based medium, in our case pieces of paper, be </span><span style="font-size: 13.3333px;">re-purposed</span><span style="font-size: 10pt;"> to effectively transmit
binary data.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Tier
3 will, hopefully, begin to straighten this all out…<o:p></o:p></span><br />
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><br /></span>
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Next >> <a href="http://adam-feather.blogspot.co.uk/2017/02/understanding-base64-encoding-3.html">Understanding Base64 Encoding #3</a></span></div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-21833007501901198612017-01-24T08:10:00.000-08:002017-02-10T04:20:34.544-08:00Understanding Base64 Encoding #1<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Disclaimer</span></b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">: I’m writing this blog
post in an attempt to present a tiered approach to learning a new subject. It's also to solidify my understanding of the topic of base64 encoding
as well as to act as an aide-memoire. I’m not presenting this information as
infallible fact.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Preamble</span></b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">: Personally, learning
a new programming concept (or any complex topic for that matter) requires me to
take a very particular approach if I want gain and maintain a comprehensive
understanding of it, and I don’t see resources which represent and facilitate
my learning process very much in evidence. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Learning
for me involves moving from the general to the specific and for my sources of
information to assume as little as possible while establishing context and
purpose quickly. Producing this type of learning resource usually manifests in
tiered levels of explanation. To my mind, Tier 1 is where the biggest shortage
of good resource on a topic generally is. It should be what the opening
paragraph of the Wikipedia topic strives to attain: a succinct and clear
overview of the topic that someone immersed in the relevant field can read and
feel more illuminated right away. Further tiers of explanation should elaborate on what previous tiers have established.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Let
me try presenting the first couple of tiers for <b>base64 encoding</b> in the style I'm talking about.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">What I assume</span></b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">: you have a
programming background and that you’re looking to better understand base64
encoding.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Tier 1: <o:p></o:p></span></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Okay,
Tier 1 explanations might be relevant if you’ve just heard someone say “base64
encode” in a meeting and you’re thinking “I should probably have some idea what
on Earth they’re talking about”; you’re googling about for five minutes to see if you can shed some light on the topic.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Wikipedia’s
Base64 opening salvo is: “<i>Base64 is a
[...] binary-to-text encoding scheme that represent[s] binary data in an ASCII
string format”</i>.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">This
isn’t particularly illuminating on its own but there are a couple of clues in
there: it’s something do with binary data being represented as ASCII
characters. <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Warning: </span></b><span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">rather unhelpfully, it
is possible to immediately jump down the rabbit hole with base64 encoding and
you may be thinking, as I was, “hang on a minute, everything eventually boils
down to binary data - including ASCII characters - so that seems like a bit of
a nonsense”. Or perhaps you have come across an example whereby someone is
showing you how they converted a sentence (one string of characters) into
base64 encoded text (another string of characters) and are thinking “what could
possibly be the value in that!?”. If you’ve done either (or both) of these
things, please, for the moment, put those thoughts on ice – don’t worry, I’m with
you comrade, I feel your pain.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">A
concrete example might help. Imagine I have an 10 x 10 pixel jpeg image (some
binary data) and I want to represent it (for some ungodly reason) as ASCII
characters. Up steps base64 encoding. In fact, here is a base64 encoded 10 x 10
jpeg:<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAAB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABg<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC45AP/bAEMAAQEBAQEBAQEBAQEBAQEB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">Af/bAEMBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAoACgMBIgACEQEDEQH/xAAfAAAB<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">BQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0B<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygp<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">KjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImK<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">kpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJ<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">Cgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGh<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">scEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZ<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">WmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEA<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">AhEDEQA/AP5/fg7rH7M+nWv7EPjn4nfsT/ACH49fsz/D/wDZbvPgR+xr4R+Hf7Qn<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">x1tf+C7/APwvX9o7x3D4p8R+Ivi14A+I3jn4ZeAviB8FbK8Xw/P4K8QeGfil/bn7<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">R3hz4i/sufEfwBqngX4ZaX+xF8FPxB+LFn/Z3xT+Jen/APCN/D/wd9g+IHjKz/4R<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">H4T+Nf8AhZXws8K/ZfEepQf8I58NPiL/AMJ/8V/+E++H+h7P7M8G+Nf+FpfEr/hK<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">vDlrpuu/8J/4x+3/APCRaj6B4A/ax/an+FHws8a/Av4W/tLftAfDX4JfEr/hI/8A<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">hYvwd8AfGT4i+DvhZ4+/4THw5Z+D/F3/AAmvw+8O+I9O8JeKv+Eq8Jadp/hbxH/b<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: xx-small;">ukX/APbnhyws9E1P7VplrBap8/0Af//Z</span><span style="font-size: 8pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Sceptical?
If you copy that text and save it into a new text file (called, say, “encodedJpg.txt”)
and then navigate to the folder the file is saved in from a Windows
command prompt, you can run the following command <i>certutil
-decode encodedJpg.txt 10x10.jpg and </i>you should see the jpg recreated.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBjZjdBbk6JLlUAidDphSS8qiXX-t9ajYaC8l26dZiVzqSkR8mFKOfv8v4YmSwhl1C8TxIbCSxhMKl0qOzY5KAua49FLuHnqkQXe5zakLOo4QJN3qWLQZiJQe8aNYXiH1EH81r8sUEGPo/s1600/example.exe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="40" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBjZjdBbk6JLlUAidDphSS8qiXX-t9ajYaC8l26dZiVzqSkR8mFKOfv8v4YmSwhl1C8TxIbCSxhMKl0qOzY5KAua49FLuHnqkQXe5zakLOo4QJN3qWLQZiJQe8aNYXiH1EH81r8sUEGPo/s400/example.exe.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">You can turn the jpg back in to the text above by running the alternative <i>certutil -encode "input" "output" </i>command.</span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">And
that’s Tier 1. For the moment we’re not going to worry about the mechanics of
the operation, it’s enough to know that base64 encoding changes binary data into text that looks like the above. Why you'd want to do such a thing and how it's achieved are Tier 2 explanations. N.B. the binary data doesn’t
have to be a jpeg image, it could be anything: an executable, a zip file,
a Word document, etc.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: "arial" , sans-serif; font-size: 10.0pt;">Next >> <a href="http://adam-feather.blogspot.co.uk/2017/01/understanding-base64-encoding-2.html">Understanding base64 Encoding #2</a><o:p></o:p></span></div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-44962807491919715582016-11-28T12:00:00.003-08:002016-11-28T12:02:56.297-08:00Visualising Sorting Algorithms <div dir="ltr" style="text-align: left;" trbidi="on">
Stumbled across a few really good videos for visualising sorting algorithms. I've seen a few which show the sorting happening but not the logic behind it. I think these convey both aspects really well.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/aXXWXz5rF64/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/aXXWXz5rF64?feature=player_embedded" width="320"></iframe></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/es2T6KY45cA/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/es2T6KY45cA?feature=player_embedded" width="320"></iframe></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/H5kAcmGOn4Q/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/H5kAcmGOn4Q?feature=player_embedded" width="320"></iframe></div>
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-90255109205097642692016-06-17T06:11:00.000-07:002016-06-17T06:13:28.061-07:00Stack and Heap Refresh<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/W8nNdNZ40EQ/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/W8nNdNZ40EQ?feature=player_embedded" width="320"></iframe></div>
<br />
Brilliant refresher on how the stack and heap are used. Also gives an insight into when and why variables are and are not thread-safe.</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-3525872386623773262016-02-26T04:06:00.002-08:002016-02-26T04:06:29.581-08:00Commenting Code<div dir="ltr" style="text-align: left;" trbidi="on">
My rules-of-thumb for code commenting:<br /><br />
<b>Don't.</b> If you find yourself writing a comment ask yourself "why am I writing this comment?". Most of the times I've found myself writing a comment is because the code isn't self-commenting: the method/class wasn't small enough; naming - at class, function and/or variable level - was poor and obscured intention; I'd written code which could have been written in a more expressive fashion. I was adding a comment to something which should have been extracted to its own method.<br /><br />
<b>Why not What.</b> As far as possible it should be patently obvious <i>what </i>your code is doing, even at a glance. You may not immediately know <i>how </i>it goes about it, but you often won’t need to: a properly named function in a codebase you trust will tell you what it’s doing; a properly name variable will tell you what is it and what it’s being used for. If the domain logic is a bit peculiar, it might be worth documenting <i>why </i>the thing is being done. But be careful and always take a minute to reflect on whether the domain logic truly is peculiar or whether you are just doing something a bit odd.<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-24873104072045548272016-02-01T08:01:00.001-08:002016-02-01T08:01:53.966-08:00Is TDD Dead?<div dir="ltr" style="text-align: left;" trbidi="on">
A brilliant and informative discussion for anyone who's interested in TDD and its utility: <a href="https://www.youtube.com/watch?v=z9quxZsLcfo">https://www.youtube.com/watch?v=z9quxZsLcfo</a></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-46814461493444812432015-12-02T03:24:00.004-08:002015-12-02T05:31:22.905-08:00oAuth2: A Conversation<div dir="ltr" style="text-align: left;" trbidi="on">
I sometimes try to view protocols as conversations between actors in order to aid my comprehension - the anthropomorphising of computer interactions, if you will. I imagine oAuth2 to go something like this (in the context of a web server)...<br />
<br />
The actors:<br />
<ul style="text-align: left;">
<li>You</li>
<li>A Desired Service (ADS) - a service you'd like to use</li>
<li>oAuth2 Implementer (oAI) - a service you've trusted with your details</li>
</ul>
<b>You to ADS</b>: Hello, I'd like to use your service<br />
<br />
<b>ADS</b>: Okay, in order to use the service I provide I need you to create an account. I can make this easier for you if you already have an account with (Google | FB | Twitter | etc.) - someone who already knows the information I need to know.<br />
<br />
<b>You</b>: I have a Google account, we can use that.<br />
<br />
<b>ADS:</b> Cool, in that case I'm going to send you to over to Google to login and they'll send you back to me when you're done.<br />
<br />
<b>ADS to oAI: </b>Hey, Google, it's ADS, I'm sending you someone and I want to know their email address, name and phone number. Send them back to this address when you're done.<br />
<br />
<i> ~ you arrive at the oAI (Google)~</i><br />
<br />
<b>aOI: </b>Okay, so who are you?<br />
<br />
<b>You: </b>I'm me, I'll login to prove it.<br />
<br />
<b>aOI:</b> Hello You. The service that sent you here wants to know your email address, name and phone number, is that cool?<br />
<br />
<b>You:</b> Yes, that's fine.<br />
<br />
<b>aOI: </b>Alright<b>y. </b>When ADS registered with me they specified after people have logged in successfully and agreed to the things it wants access to, there are a predefined list of URLs I can send you back to, of which <a href="https://ads.com/oauth2-return-page">https://ads.com/oauth2-return-page</a>, which arrived alongside you, is one. I'll send you back there with this authorisation code which ADS can exchange for an access token in order to ask me about your email address, name and phone number.<br />
<br />
<i>~ you arrive back at ADS ~ </i><br />
<br />
<b>ADS: </b>Nice to see you again. I can see you've logged in with Google successfully. I'll just use that authorisation code to request an access token which I'll use to request your details, then I'll create you an account.<br />
<i> </i><br />
<b>ADS to oAI: </b>Hey, I've got this authorisation code, can I get the associated access token.<br />
<i></i><br />
<b>oAI to ADS: </b>Sure, here you go.<br />
<br />
<b>ADS to oAI:</b> Hey, I've got this access token. Can you tell me the email address, name and phone number associated with it?<br />
<br />
<b>oAI to ADS:</b> Yup, here you go.<br />
<br />
And that, crudely, is how I understand oAuth2 works when web servers are talking to each other.<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-65530163233371951432015-11-27T03:04:00.001-08:002015-11-27T03:04:29.041-08:00The Why of the Kilobyte (and data sizes generally)<div dir="ltr" style="text-align: left;" trbidi="on">
I am a Computer Science graduate and a developer of ten years. Embarrassingly, it took me until last night to jump down the rabbit hole of the terminology used when describing quantities of data. As usual, I didn't find <i>exactly </i>what I was looking for on the internet, so here are my thoughts:<br />
<br />
I like to think I understand binary, in a rudimentary fashion at least. I can explain that it's a base-2 number system, having two symbols to represent its numbers: "0" and "1". I can show you how to count in a base-2 system and show you why it works that way. I can contrast it with a base-4, base-10 or a base-16 system and show how those works. I can perform basic binary addition. Essentially, I'm trying to establish my credentials as someone who isn't a complete binary dullard.<br />
<br />
I also understand that one bit (Binary digIT) isn't an awful lot of use on its own. It can be on/off, high/low, true/false - however you choose to describe it - but only in context and combination with other bits does it become interesting and useful. And this is where my journey down the rabbit hole began...<br />
<br />
Let me start with good old, recognisable base-10. It has ten symbols to use when representing numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. We - people - have chosen to assign special names to particular, neat representations of quantity in this system:<br />
<br />
1 = one = 10^0<br />
10 = ten = 10^1<br />
100 = hundred = 10^2<br />
1000 = thousand = 10^3<br />
1000000 = million = 10^6<br />
1000000000 = billion = 10^9 (old British billion: 1,000,000,000,000 = 10^12)<br />
<br />
I haven't worked out quite why we decided those particular representations were worthy of their own name; it feels like an addition chain, especially if you go with the old British billion: 0, 1, 2, 3, 6, 9|12.<br />
<br />
With this in mind we approach base-2, where the ground appears to completely shift. We start by giving names to collections of bits, seemingly more interested in the range of numbers a collection of bits can represent than the numbers themselves. So..<br />
<br />
0 = bit = 0 to 1<br />
0000 = nibble | nyble = 0 to 15<br />
0000 0000 = byte = 0 to 255<br />
<br />
You think "okay, well it's a different world, things area different here... maybe a different pattern is used". Once you get your head round it's collections of bits (ranges of numbers) are given names, rather than numbers themselves, then maybe you can work out the pattern. Maybe 16 bits or 32 bits have a special name? Nope. It's all madness from here on in!<br />
<br />
0000 0000 0000 0000 = 2 bytes | 16 bits<br />
0000 0000 0000 0000 0000 0000 0000 0000 = 4 bytes | 32 bits<br />
<br />
What appears to have happened is that someone decided bits are no longer interesting and that... wait for it... quantities of bytes are interesting (completely eschewing the lowly bit) and decide either 1000 or 1024 (depending on your stance) is an interesting quantity of these byte things to be concerned about. I can only imagine being interested in ~1000 of these thing is the spectre of base-10 hovering over the decision making.<br />
<br />
1024 x byte = kilobyte<br />
1024 x kilobyte = megabyte<br />
1024 x megabyte - gigabyte<br />
etc.<br />
<br />
If someone can explain the <i>why </i>behind this thinking I'll be greatly appreciative. I can only imagine that "kilo" and "mega" are impositions from the world of base-10 and that multiples of bytes is interesting because 8 bits can represent a character (as per ASCII or some machine instruction).<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-52587157986650078732015-11-05T06:45:00.004-08:002015-11-05T06:45:46.243-08:00Nomenclature<div dir="ltr" style="text-align: left;" trbidi="on">
I agonise over naming things when it comes to coding; names convey intention and purpose and are one of the first things you rub up against when trying to figure a out new concept or someone else's code - or your own from longer than a few days ago.<br />
<br />
It's in this spirit I want to rename Closures as Captors (or Captures). When you read into it and discover that the term "closure" is used in reference to "closing over variables", I submit you immediately think "what?" and then "I wonder if them mean capture a variable?".<br />
<br />
Thoughts?<br />
<br />
<a href="http://www.blackwasp.co.uk/CSharpClosures.aspx">http://www.blackwasp.co.uk/CSharpClosures.aspx</a></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-35431646620794554842015-10-01T08:49:00.001-07:002019-06-14T04:47:55.278-07:00IT Recruitment Agencies<div dir="ltr" style="text-align: left;" trbidi="on">
I'm unlikely to say anything original in this post. I'm trying to work out what exactly my opinion of recruitment agencies is and whether not they can be bent so as to be useful.<br />
<br />
<b>N.B.</b> I'm a permanent, full-time employee. I always have been. My experiences of recruitment agencies have always been in that context; I've never dealt with recruitment agencies from a contractor's point of view.<br />
<br />
The sheer volume of IT recruitment agencies in Brighton (and surrounding areas) is staggering yet completely understandable: they want a piece of the relatively well paid developer's pie. A recruitment agency introduces you to a prospective employer and typically, providing you pass probation, gets a lump sum (~20% of your first year's salary) for doing so.<br />
<br />
Traditional free market principles do not seem to apply to IT recruitment agencies, that is, myriad agencies do not appear to have created a survival of the fittest situation in which only the leanest, highly-skilled, astute agencies / agents survive. Rather, there's a roiling mass of incompetence and greed from which no front-runners emerge, presumably because there are non to do so.<br />
<br />
I imagine a recruitment agent's job must not feel too dissimilar to that of a 419 scammers: sending innumerable emails off to potential victims (LinkedIn members who wonder was there ever a time giving LinkedIn all your personal work history felt like a good idea...) hoping for that one hit in a thousand to make them rich.<br />
<br />
It feels like mine and my potential agent's interests are fundamentally misaligned: I want the right job; the agent wants me to take any job, preferably one I can only stick out for a year before returning to them to try again.<br />
<br />
This has merely turned into a rant. What are the benefits or a recruitment agent for a full-time, permanent employee? There must be some...<br />
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-20495301465566216312015-09-18T07:27:00.002-07:002015-09-18T07:29:49.310-07:00Creating a SQL Server Managment Studio Add-in<div dir="ltr" style="text-align: left;" trbidi="on">
I've spent the last day or so playing with an idea for a SSMS add-in. It's something I've been thinking about for a while now but will save the details for another post. What I want to document are my experiences so far as well as how convoluted and poorly-resourced the process of producing an add-in to SSMS is. Here are some of the things you should know about before strating on the journey. Hopefully some of this will save you some pain.<br />
<br />
<b>General Points:</b><br />
<ul style="text-align: left;">
<li>As far as I can tell, Microsoft don't really want you to integrate into SSMS - at least they've no interest in supporting the endeavour.</li>
<li>Luckily, due SSMS's similarity to Visual Studio, you can broadly follow the same instructions offered up for extending Visual Studio with add-ins, something MS seem to actively encourage.</li>
<li>There appear to be two ways of skinning this cat: Add-ins and VSExtensions. Add-ins, the route I've taken, are the older of the techniques but are where the majority of the resources are.</li>
</ul>
<div style="text-align: left;">
<br /></div>
<b>SSMS Integration:</b><br />
<ul style="text-align: left;">
<li>In order to load add-ins SSMS looks in folder locations specified here: <i>HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\11.0_Config\AutomationOptions\LookInFolders</i> for XML files giving details of the add-ins.</li>
<li>You can configure things to happen only the first time the add-in is loaded by SSMS or every time the add-in is loaded: ext_ConnectMode.ext_cm_UISetup & ext_ConnectMode.ext_cm_Startup. I've still haven't quite grasped fully how they work.</li>
</ul>
<br />
<b>Menu Generation:</b><br />
<ul style="text-align: left;">
<li>A <i>CommandBar </i><b>can contain a</b> <i>CommandBarPopup </i><b>which needs to contain a </b><i>CommandBar </i>which is <b>where you place</b> <i>CommandBarButton </i>objects <b>produced by</b> Command objects.</li>
<li>A<i> Command</i><i> </i>can exist entirely independently of anything else. They don't have to be attached to <i>CommandBarButton </i>objects.</li>
<li>A <i>Command </i>hangs around. It doesn't disappear after you close SSMS. To have it do so you need to remove it in the <i>OnDisconnection </i>of the <i>IDTExtensibility2 </i>interface.</li>
</ul>
<div>
<b><br /></b>
<b>Resources:</b></div>
<div>
<ul style="text-align: left;">
<li><a href="http://solutioncenter.apexsql.com/the-art-and-science-of-creating-ssms-2012-add-ins-part-1-laying-the-foundation">http://solutioncenter.apexsql.com/the-art-and-science-of-creating-ssms-2012-add-ins-part-1-laying-the-foundation</a><br /></li>
<li><a href="http://www.mztools.com/articles/2005/mz2005003.aspx">http://www.mztools.com/articles/2005/mz2005003.aspx</a><br /></li>
<li><a href="http://www.ssmsboost.com/create-own-ssms-2012-add-in-sample-code-with-download">http://www.ssmsboost.com/create-own-ssms-2012-add-in-sample-code-with-download</a></li>
</ul>
</div>
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-24157461589519049732015-09-10T03:05:00.001-07:002015-09-10T03:06:13.059-07:00Uri.TryCreate C# (Part 2)<div dir="ltr" style="text-align: left;" trbidi="on">
It occurred to the other other day that the .NET core is now open-source so I can actually go see the code involved in the Uri.TryCreate method.<br />
<br />
It transpires that Uri is a partial class and the meat of the functionality is split over the two following files:<br />
<br />
<a href="https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/UriExt.cs">https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/UriExt.cs</a><br />
<br />
<a href="https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/Uri.cs">https://github.com/dotnet/corefx/blob/41e203011152581a6c65bb81ac44ec037140c1bb/src/System.Private.Uri/src/System/Uri.cs</a><br />
<br />
The first thing that stuck me was there's an awful lot of code involved with attempting to create a Uri.<br />
<br />
The <b>TryCreate </b>static methods which lives in the <b>UriExt.cs</b> class are deceptively simple. The <b>TryCreate </b>overload I'm interested in is the most simple of those - it really just passes the work off to a <b>CreateHelper </b>method which in turn passes off the work to a <b>ParseScheme </b>method located in the Uri.cs class.<br />
<br />
<b>ParseScheme </b>appears to do some basic length checking before deferring to <b>ParseSchemeCheckImplicitFile, </b>which is where the main body of work seems to take place. As far as I can glean the following rules are being observed:<br />
<ol style="text-align: left;">
<li>Whitespaces at the start are ignored</li>
<li>A url is valid if it is at least 2 characters, as long as the first of which is not a number, followed by a colon - unless those letters are a scheme you'd recognise (ftp, http, https, etc) at which intuitive validation kicks in.</li>
<li>UNC paths are valid e.g. //foo</li>
</ol>
<div>
<br /></div>
<div>
Given these rules, the following odd strings pass as valid absolute URIs:</div>
<div>
<br /></div>
<div>
"aa:"</div>
<div>
"fo:o"</div>
<div>
" fo:o"</div>
<div>
"javascript:void()"</div>
<div>
<br /></div>
<div>
Maybe there are just so many esoteric schemes out there that robust validation is not viable.</div>
<br />
<br />
<br /></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-13188320280414860262015-09-09T08:38:00.001-07:002015-09-09T08:39:19.362-07:00Licences & Additional Build Agents in TeamCity<div dir="ltr" style="text-align: left;" trbidi="on">
We use a combination of TeamCity and Octopus Deploy to automate our deployment and release process at work. We’ve been using the Professional Server Licence (free version) of TeamCity which allows for 20 build configurations (each configuration delineates one logical group of actions. e.g. pull code; build it; run unit tests) and 3 build agents (in our case Windows services which execute build configurations).<br />
<br />
We recently bumped up against the 20 configuration limit and the boss dusted off the credit card to purchase a Build Agent Licence (£236 for 10 additional build steps and one additional build agent, at the time of writing). I dutifully entered in the licence key and fairly quickly learned a few things:<br />
<br />
<ol style="text-align: left;">
<li>What you purchase are <b>build agent slots</b> not <b>build agents.</b></li>
<li>You need to <b>install build agents</b> into your available build agent slots</li>
<li>The person who set-up our TeamCity build server originally had only installed on build agent (probably due to #4)</li>
<li>Precautions need to be taken when switching from a single build agent to multiple agents</li>
</ol>
<br />
Prior to purchasing the upgrade licence we had only one build agent installed (I assumed that was our limit on the free license) and I expected, rather naively as it turns out, to see another build agent appear when I entered the licence key. What you need to do, in fact, is install additional build agents into your free build agents slots. This is made a little more complicated by the fact you can’t just straightforwardly use the build agent installer (on Windows at least) to install more build agents; each build agent needs some tweaks to be made to its installation configuration files halfway through the installation. It feel like TeamCity have missed a trick here and could make customers’ lives easier by bundling up these config changes as part of the installer.<br />
<br />
Excellent article detailing the process here: <a href="http://www.diaryofaninja.com/blog/2011/07/26/teamcity--when-1-build-agent-isnrsquot-enough">http://www.diaryofaninja.com/blog/2011/07/26/teamcity--when-1-build-agent-isnrsquot-enough</a></div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-58168139013795496062015-08-25T03:28:00.002-07:002015-08-26T04:13:15.663-07:00Clean Code<div dir="ltr" style="text-align: left;" trbidi="on">
I'm re-reading Clean Code by Robert C. Martin and a few quotes from the intro have really stuck out:<br />
<br />
"Quality is the result of a million selfless acts of care - not just of any great method that descends from the heavens".<br />
<br />
I like this quote a lot. I'd take the word "selfless" out of it though. When I'm writing code I'm often thinking about Future Me and trying to make his life as easy as possible. Every act of care, or short-cut not taken, makes Future Me's life that bit easier. I want Future Me to not curse Past Me.<br />
<br />
The idiom "a bad penny always turns up" is cited too. This one rings true. The amount of times a short-cut taken in a fatigued moment has come back to bite me is unnerving!</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0tag:blogger.com,1999:blog-8335793838111147315.post-91018333268796350612015-08-14T04:46:00.002-07:002015-09-10T02:06:37.170-07:00Uri.TryCreate C#<div dir="ltr" style="text-align: left;" trbidi="on">
Came across a strange problem at work yesterday:<br />
<br />
<script src="https://gist.github.com/adamfeather/b1ced64f5b42fb4c2149.js"></script>
was returning true.<br />
<br />
On further investigation strings such as "foo:bar" will also return true. It seems a colon separating a few characters is enough to satisfy TryCreate's criteria of a valid URI being contained in the string. I assume colons are related to the username:password prefixes some URIs contain, but I would have assumed that in itself would not be enough.<br />
<br />
Anyone know why this would be the case?
</div>
Adam Featherhttp://www.blogger.com/profile/15555670072428051605noreply@blogger.com0