<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://gohugo.io/" version="0.124.1">Hugo</generator><title>Programming Hints</title><link href="https://programming-hints.com/" rel="alternate" type="text/html" title="html"/><link href="https://programming-hints.com/feed.xml" rel="self" type="application/atom+xml" title="atom"/><updated>2026-05-22T04:11:28+00:00</updated><id>https://programming-hints.com/</id><entry><title>Microsoft_vc_redist</title><link href="https://programming-hints.com/posts/microsoft_vc_redist_error/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/microsoft_vc_redist_error/</id><published>2025-01-17T13:25:09-08:00</published><updated>2025-01-17T13:25:09-08:00</updated><content type="html">
&lt;p>Not really a post about programming but an annoying thing from my own Windows machine.&lt;/p>
&lt;p>I was getting an error about a missing Microsoft Visual C++ Runtime. It happened every time I launched a game and was also preventing me from installing different versions of the runtime. Said version appeared in the installed programs list but the installer wasn&amp;rsquo;t there and it couldn&amp;rsquo;t be uninstalled or repaired either.&lt;/p>
&lt;p>Here&amp;rsquo;s the error message:&lt;/p>
&lt;blockquote>
&lt;p>The feature you are trying to use is on a network resource that is unavaible.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;img
src="vcredisterror.png"
alt="Screenshot of the error - different version but it&amp;amp;rsquo;s the same error"
/>&lt;/p>
&lt;p>The fix is to find and download the correct version from &lt;a
class="gblog-markdown__link"
href="https://my.visualstudio.com/Downloads?q=visual%20studio%202019&amp;amp;wt.mc_id=o~msft~vscom~older-downloads"
>Visualstudio.com&lt;/a>. You&amp;rsquo;ll need to create a free account to get access. The link is also on &lt;a
class="gblog-markdown__link"
href="https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-160"
>this knowledge base page&lt;/a>&lt;/p>
&lt;p>Once on my.visualstudio.com the version column in the search results unfortunately doesn&amp;rsquo;t match the version listed in the installer. In my case the installer was complaining about version 14.24.28127 being missing and this was visual C++ 2019 16.4 x86. Infurating that the version in the search results isn&amp;rsquo;t the actual version.&lt;/p></content></entry><entry><title>Writing</title><link href="https://programming-hints.com/posts/writing/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/writing/</id><published>2022-03-12T10:14:46-08:00</published><updated>2022-03-12T10:14:46-08:00</updated><content type="html">
&lt;p>&lt;a
class="gblog-markdown__link"
href="https://stackoverflow.blog/2021/08/09/how-writing-can-advance-your-career-as-a-developer/"
>Today&amp;rsquo;s article is all about the importance of writing and its usefulness in advancing your career&lt;/a>. Clear writing in a work context is even more important now for those who are working remotely.&lt;/p>
&lt;p>It might be time for me to start making updates to this blog again - out of self-interest if for no other reason. I have been collecting topics and ideas to write about, I&amp;rsquo;ve just lacked motivation to put hands to keyboard.&lt;/p></content><category scheme="https://programming-hints.com/tags/article" term="article" label="article"/></entry><entry><title>If You Need a Laugh</title><link href="https://programming-hints.com/posts/if-you-need-a-laugh/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/if-you-need-a-laugh/</id><published>2020-05-13T04:00:00+00:00</published><updated>2020-05-13T04:00:00+00:00</updated><content type="html">
&lt;p>&lt;a
class="gblog-markdown__link"
href="https://saagarjha.com/blog/2020/05/10/why-we-at-famous-company-switched-to-hyped-technology/"
>This is an accurate and humorous take on most technology blogs&lt;/a>. Except for this fine website.&lt;/p></content><category scheme="https://programming-hints.com/tags/humour" term="humour" label="humour"/></entry><entry><title>We're Back</title><link href="https://programming-hints.com/posts/were-back/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/were-back/</id><published>2018-03-27T19:22:00+00:00</published><updated>2018-03-27T19:22:00+00:00</updated><content type="html">
&lt;p>My hosting provider decided to migrate my account to a new machine. Something got mucked up in the migration causing this blog to no longer work properly. I guess the lesson here is to always test your deployments, even if it&amp;rsquo;s someone else making the deployment on your behalf.&lt;/p></content><category scheme="https://programming-hints.com/tags/testing" term="testing" label="testing"/></entry><entry><title>Software Developer Interviews Suck</title><link href="https://programming-hints.com/posts/software-developer-interviews-suck/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/software-developer-interviews-suck/</id><published>2017-02-27T00:18:00+00:00</published><updated>2017-02-27T00:18:00+00:00</updated><content type="html">
&lt;p>Interviewing for a software engineering role is more onerous than interviewing for any other profession. Interviewing for most non-software professional jobs typically consists of a phone screen and one to two interviews on site, where you talk about what you did in previous jobs. At no point during are you asked to demonstrate any skills, you&amp;rsquo;re trusted as an adult that you&amp;rsquo;re telling the truth about your experience and qualifications.&lt;/p>
&lt;p>Interviewing for a software job typically involves 1 phone screen with HR or the recruiter, 1 technical phone screen and possibly a programming task to complete in 1-4 hours of your own time. If successful at all of the above then you can go onsite for a whole day of interviews - yes, you will need to use annual leave at your current job. During some of the onsite interview rounds you solve esoteric coding problems on the whiteboard. In the other rounds you will be expected to design scalable software systems in 45 minutes that are similar to ones that the company has literally spent hundreds or thousands of developer hours iterating on the design.&lt;/p>
&lt;p>&lt;a
class="gblog-markdown__link"
href="https://youtu.be/hE_LTbWzhEA"
>This video expresses my frustration with the interview process as a software developer&lt;/a>.&lt;/p></content><category scheme="https://programming-hints.com/tags/interviewing" term="interviewing" label="interviewing"/><category scheme="https://programming-hints.com/tags/career" term="career" label="career"/><category scheme="https://programming-hints.com/tags/business" term="business" label="business"/></entry><entry><title>User Data</title><link href="https://programming-hints.com/posts/user-data/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/user-data/</id><published>2016-05-17T05:47:00+00:00</published><updated>2016-05-17T05:47:00+00:00</updated><content type="html">
&lt;p>Here&amp;rsquo;s a talk that I watched recently and found deeply troubling and thought provoking: &lt;a
class="gblog-markdown__link"
href="https://www.youtube.com/watch?v=GAXLHM-1Psk"
>Haunted by Data - Maciej Ceglowski&lt;/a> &lt;a
class="gblog-markdown__link"
href="http://idlewords.com/talks/haunted_by_data.htm"
>(text/image version)&lt;/a>. The speaker raises the ethical dilemmas with user data collection, retention, governance and overuse that is prevalent throughout the computing industry. The challenge is to end our addiction to collecting and storing user data.&lt;/p>
&lt;p>Here&amp;rsquo;s another post on the related topic of &lt;a
class="gblog-markdown__link"
href="https://news.ycombinator.com/item?id=7485773"
>the web being &amp;ldquo;subsidized&amp;rdquo; by advertising&lt;/a>. It&amp;rsquo;s related because internet advertising relies on the user data harvested when we do anything online. Also worth reading and thinking about.&lt;/p></content><category scheme="https://programming-hints.com/tags/bigdata" term="bigdata" label="bigdata"/><category scheme="https://programming-hints.com/tags/ehtics" term="ehtics" label="ehtics"/><category scheme="https://programming-hints.com/tags/userdata" term="userdata" label="userdata"/></entry><entry><title>Scala's Expressive Power</title><link href="https://programming-hints.com/posts/scalas-expressive-power/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/scalas-expressive-power/</id><published>2016-02-20T05:57:00+00:00</published><updated>2016-02-20T05:57:00+00:00</updated><content type="html">
&lt;p>I saw the following puzzle the other day. Given a set of rings, can you place the numbers 1 through 9 inside each closed area so that the sum of the numbers in each circle is the same?&lt;/p>
&lt;p>&lt;img
src="olympicring.png"
alt="Olympic Rings Puzzle"
title="Olympic Rings Puzzle"
/>&lt;/p>
&lt;p>The 1 was already placed for you.&lt;/p>
&lt;p>Because I&amp;rsquo;m trying to learn Scala, I thought writing a program to solve this would be good practice for me. I assume that the numbers in each closed area are stored in an &lt;code>Array&lt;/code> with elements in the array corresponding to the closed areas from left to right.&lt;/p>
&lt;pre tabindex="0">&lt;code>def isValid(values: IndexedSeq[Int]) = {
val target = values.take(2).sum
values.slice(1, 4).sum == target &amp;amp;&amp;amp;
values.slice(3, 6).sum == target &amp;amp;&amp;amp;
values.slice(5, 8).sum == target &amp;amp;&amp;amp;
values.slice(7, 9).sum == target
}
&lt;/code>&lt;/pre>&lt;p>This was dead easy to write. It&amp;rsquo;s just encoding the solved condition from the question. Next was the tricky part &amp;ndash; going through all permutations of 2 to 9 with 1 in a fixed place until we arrived at an answer. I remember writing code to generate all permutations once as an interview question and it isn&amp;rsquo;t easy. You have to write a complicated recursive function to generate the permutations.&lt;/p>
&lt;p>Thankfully a few minutes spent in the ScalaDoc allowed me to use some of the powerful functions provided by Scala out of the box. Here&amp;rsquo;s code to solve the problem in a handful of lines.&lt;/p>
&lt;pre tabindex="0">&lt;code>val available = 2 to 9
for (perm &amp;lt;- available.permutations) {
val values = (perm.take(3) :+ 1) ++: perm.drop(3)
if (isValid(values)) {
println(&amp;#34;Winner:&amp;#34;)
println(values.mkString(&amp;#34;, &amp;#34;))
}
}
&lt;/code>&lt;/pre>&lt;p>Yes, there&amp;rsquo;s a function to give you all permutations of a sequence. The &lt;code>:+&lt;/code> and &lt;code>++:&lt;/code> are operators that join an element to a sequence and join two sequences respectively.&lt;/p>
&lt;p>If you want the answer you&amp;rsquo;ll have to download Scala and run the above program. Or you can try solving it yourself in the language of your choice.&lt;/p></content><category scheme="https://programming-hints.com/tags/puzzles" term="puzzles" label="puzzles"/><category scheme="https://programming-hints.com/tags/scala" term="scala" label="scala"/></entry><entry><title>Best Firefox Addons</title><link href="https://programming-hints.com/posts/best-firefox-addons/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/best-firefox-addons/</id><published>2015-10-10T03:46:00+00:00</published><updated>2015-10-10T03:46:00+00:00</updated><content type="html">
&lt;p>Long time, no post. I&amp;rsquo;ve had plenty of ideas for topics to write about, but for one reason or another I&amp;rsquo;ve always put off actually sitting down and writing the post. Call it procrastination, call it finding better things to do with my spare time - whatever the excuse I&amp;rsquo;ve made them all.&lt;/p>
&lt;p>Seeing as I&amp;rsquo;m paying for the domain name and hosting, I might as well post occasionally. Will this be a one off or will I get into a regular cadence of updates? Only time will tell.&lt;/p>
&lt;p>The actual topic of the post is my favourite Firefox add-ons. I was prompted to list them here because I recently reset my Firefox install and it took me a while to find the best add-on.&lt;/p>
&lt;p>Here is my must-have list:&lt;/p>
&lt;ol>
&lt;li>&lt;a
class="gblog-markdown__link"
href="https://addons.mozilla.org/en-US/firefox/addon/tree-style-tab/"
>Tree Style Tab&lt;/a> - this is the best add-on ever. It arranges your tabs down the left hand side of the browser and nests them like the old tree view in windows explorer. This is surprisingly impossible to find with Firefox&amp;rsquo;s add-ons search even if you type the exact name.&lt;/li>
&lt;li>&lt;a
class="gblog-markdown__link"
href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/"
>ublock origin&lt;/a> - ad blocking. The web is so much more pleasant to read without popup ads everywhere and blinking gifs on the side of your article. I previously used Adblock Edge but support for that has been discontinued.&lt;/li>
&lt;li>&lt;a
class="gblog-markdown__link"
href="https://addons.mozilla.org/en-US/firefox/addon/lastpass-password-manager/"
>LastPass&lt;/a> - I can&amp;rsquo;t do without my password manager. If LastPass isn&amp;rsquo;t right for you then find one that is, but in 2015 you should be using one of these.&lt;/li>
&lt;li>&lt;a
class="gblog-markdown__link"
href="https://addons.mozilla.org/en-US/firefox/language-tools/"
>Add Dictionaries&lt;/a> - unless you&amp;rsquo;re happy with the default en-US of course.&lt;/li>
&lt;/ol>
&lt;div class="flex align-center gblog-post__anchorwrap">
&lt;h3 id="2022-update"
>
2022 Update
&lt;/h3>
&lt;a data-clipboard-text="https://programming-hints.com/posts/best-firefox-addons/#2022-update" class="gblog-post__anchor clip flex align-center" aria-label="Anchor 2022 Update" href="#2022-update">
&lt;svg class="gblog-icon gblog_link">&lt;use xlink:href="#gblog_link">&lt;/use>&lt;/svg>
&lt;/a>
&lt;/div>
&lt;p>Firebug (a great website debuging tool in the early 2010s) was on the original list in 2015 but it looks like it no longer exists. The inbuilt Firefox developer tools are really good these days.&lt;/p>
&lt;p>This is my only post that ever got a non-spam comment on the old Wordpress programming-hints. A poster called Daniel wrote:&lt;/p>
&lt;blockquote>
&lt;p>Oh, you forgot &amp;ldquo;I don&amp;rsquo;t care about cookies&amp;rdquo; addon which removes EU cookie warnings. Must have.&lt;/p>
&lt;/blockquote>
&lt;p>I&amp;rsquo;m not sure I agree though. I usually don&amp;rsquo;t click accept and instead find the option that downloads the least cookies when presented with the cookie annoying popups.&lt;/p></content><category scheme="https://programming-hints.com/tags/firefox" term="firefox" label="firefox"/></entry><entry><title>Arduino - Loading Strings from Flash Memory</title><link href="https://programming-hints.com/posts/arduino-loading-strings-from-flash-memory/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/arduino-loading-strings-from-flash-memory/</id><published>2014-12-22T06:42:00+00:00</published><updated>2014-12-22T06:42:00+00:00</updated><content type="html">
&lt;p>I got out my &lt;a
class="gblog-markdown__link"
href="http://www.arduino.cc/"
>Arduino&lt;/a> board for the first time in a while for a Christmas themed project. More on that in another post. This post is about loading strings from the Arduino&amp;rsquo;s flash memory, aka program memory, aka &lt;a
class="gblog-markdown__link"
href="http://www.arduino.cc/en/Reference/PROGMEM"
>PROGMEM&lt;/a>.&lt;/p>
&lt;p>There is an example in the PROGMEM link above, but it&amp;rsquo;s kinda ugly. Here&amp;rsquo;s the main points from their example code:&lt;/p>
&lt;pre tabindex="0">&lt;code>// set up strings
prog_char string_0[] PROGMEM = &amp;#34;String 0&amp;#34;; // &amp;#34;String 0&amp;#34; etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = &amp;#34;String 1&amp;#34;;
// Then set up a table to refer to your strings.
PROGMEM const char *string_table[] = // change &amp;#34;string_table&amp;#34; name to suit
{
string_0,
string_1
};
// loading string
strcpy_P(buffer, (char*)pgm_read_word(&amp;amp;(string_table[i]))); // Necessary casts and dereferencing, just copy.
&lt;/code>&lt;/pre>&lt;p>I don&amp;rsquo;t like the fact that they create global variables called string_N then load them in an array of a different type and reference the variables by array index later. It all seems rather unnecessary.&lt;/p>
&lt;p>It seemed like there should be a more straight-forward way of doing things and after reading the header file and playing around for a few minutes, here&amp;rsquo;s what I came up with:&lt;/p>
&lt;pre tabindex="0">&lt;code>// create strings in flash memory
const prog_char STRING_WISH[] PROGMEM = &amp;#34;Have&amp;#34;;
const prog_char STRING_YOU[] PROGMEM = &amp;#34; a&amp;#34;;
const prog_char STRING_MERRY[] PROGMEM = &amp;#34;Merry&amp;#34;;
const prog_char STRING_XMAS[] PROGMEM = &amp;#34;Xmas!&amp;#34;;
// example reading strings
char firstLine[6];
char secondLine[6];
char thirdLine[6];
char fourthLine[6];
strcpy_P(firstLine, STRING_WISH);
strcpy_P(secondLine, STRING_YOU);
strcpy_P(thirdLine, STRING_MERRY);
strcpy_P(fourthLine, STRING_XMAS);
&lt;/code>&lt;/pre>&lt;p>Unfortunately global variables are still required. At least I&amp;rsquo;ve given them sensible names (STRING_WISH was initially the word &amp;lsquo;wish&amp;rsquo; but I later decided &amp;lsquo;have&amp;rsquo; sounded better). Loading the strings from program memory into RAM doesn&amp;rsquo;t require any manipulation of the arguments. No need to remember &amp;ldquo;magic&amp;rdquo; array indices or for type casting or unnecessary calls to &lt;code>pgm_read_word&lt;/code>.&lt;/p></content><category scheme="https://programming-hints.com/tags/arduino" term="arduino" label="arduino"/><category scheme="https://programming-hints.com/tags/C" term="C" label="C"/><category scheme="https://programming-hints.com/tags/Christmas" term="Christmas" label="Christmas"/><category scheme="https://programming-hints.com/tags/progmem" term="progmem" label="progmem"/></entry><entry><title>A more organic approach to Object-Oriented design</title><link href="https://programming-hints.com/posts/a-more-organic-approach-to-oo-design/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/a-more-organic-approach-to-oo-design/</id><published>2014-11-23T10:43:00+00:00</published><updated>2014-11-23T10:43:00+00:00</updated><content type="html">
&lt;p>Today&amp;rsquo;s article I&amp;rsquo;d like to share with you is: &lt;a
class="gblog-markdown__link"
href="https://caseymuratori.com/blog_0015"
>Semantic Compression&lt;/a>.&lt;/p>
&lt;p>The title doesn&amp;rsquo;t say much about the content of the article to someone who hasn&amp;rsquo;t read it, so I&amp;rsquo;ll give a brief overview.&lt;/p>
&lt;p>The author demonstrates his approach to object-oriented design through a very detailed programming example. Instead of starting with a design based on real world entities, he argues that you should start by adding the features you need in procedural style code. Every time you start repeating yourself, you&amp;rsquo;ll be able to see what the repetition has in common. It&amp;rsquo;s only when you have two or more concrete examples of repetition hat you can then make design choices about re-use through classes and functions.&lt;/p>
&lt;p>By programming in this manner you avoid designing too much flexibility too soon. You create just the abstractions you need instead of over-engineering your code based on a design that doesn&amp;rsquo;t match the goals of your program. Having worked on a recent project in a similar manner, I can say that I&amp;rsquo;m in agreement with the author. This approach to programming seems to be quite effective.&lt;/p></content><category scheme="https://programming-hints.com/tags/article" term="article" label="article"/><category scheme="https://programming-hints.com/tags/object-oriented-design" term="object-oriented-design" label="object oriented design"/><category scheme="https://programming-hints.com/tags/design" term="design" label="design"/></entry><entry><title>Python Config Files with Lists and Dictionaries</title><link href="https://programming-hints.com/posts/python-config-files-with-lists-and-dictionaries/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/python-config-files-with-lists-and-dictionaries/</id><published>2014-11-16T01:25:00+00:00</published><updated>2014-11-16T01:25:00+00:00</updated><content type="html">
&lt;p>A common problem with configuration files is that they only allow simple values like strings, integers, doubles. It&amp;rsquo;s not uncommon to want to include more complex values such as a list or dictionary in your config.&lt;/p>
&lt;p>The most elegant approach I&amp;rsquo;ve seen for doing this in python is to make use of the json library to parse the values. First I&amp;rsquo;ll load an example config file using python&amp;rsquo;s &lt;a
class="gblog-markdown__link"
href="https://docs.python.org/3/library/configparser.html"
>SafeConfigParser&lt;/a>. Typically your config would be in a separate file, however for the purposes of this blog post I&amp;rsquo;ll use a multi-line string.&lt;/p>
&lt;pre tabindex="0">&lt;code>&amp;gt;&amp;gt;&amp;gt; from configparser import SafeConfigParser
&amp;gt;&amp;gt;&amp;gt; import json
&amp;gt;&amp;gt;&amp;gt; config_text = &amp;#34;&amp;#34;&amp;#34;
[examples]
list_example=[1,2,3,4]
dict_example={&amp;#34;foo&amp;#34;:1, &amp;#34;bar&amp;#34;:2}
&amp;#34;&amp;#34;&amp;#34;
&amp;gt;&amp;gt;&amp;gt; parser = SafeConfigParser()
&amp;gt;&amp;gt;&amp;gt; parser.read_string(config_text)
&amp;gt;&amp;gt;&amp;gt; parser.items(&amp;#34;examples&amp;#34;)
[(&amp;#39;list_sample&amp;#39;, &amp;#39;[1,2,3,4]&amp;#39;), (&amp;#39;map_example&amp;#39;, &amp;#39;{&amp;#34;foo&amp;#34;:1, &amp;#34;bar&amp;#34;:2}&amp;#39;)]
&lt;/code>&lt;/pre>&lt;p>The list of tuples returned by &lt;code>ConfigParser.items(section)&lt;/code> can be tricky to work with, unless you were planning to iterate through all values in the config file. I find it easier to convert the list into a dictionary, which is simple in python:&lt;/p>
&lt;p>&lt;code>config = dict(parser.items(&amp;quot;examples&amp;quot;))&lt;/code>&lt;/p>
&lt;p>Now that we have a dictionary which maps keys in the config file to their values, you can use &lt;code>json.loads(str)&lt;/code> to convert values from strings to a list or dictionary. The operations after calling &lt;code>json.loads&lt;/code> in the next part of my interpreter session are to demonstrate that these objects are actually a real python list and dictionary.&lt;/p>
&lt;pre tabindex="0">&lt;code>&amp;gt;&amp;gt;&amp;gt; config
{&amp;#39;list_example&amp;#39;: &amp;#39;[1,2,3,4]&amp;#39;, &amp;#39;dict_example&amp;#39;: &amp;#39;{&amp;#34;foo&amp;#34;:1, &amp;#34;bar&amp;#34;:2}&amp;#39;}
&amp;gt;&amp;gt;&amp;gt; list_example = json.loads(config[&amp;#39;list_example&amp;#39;])
&amp;gt;&amp;gt;&amp;gt; list_example
[1, 2, 3, 4]
&amp;gt;&amp;gt;&amp;gt; list_example[2]
3
&amp;gt;&amp;gt;&amp;gt; list_example[:3]
[1, 2, 3]
&amp;gt;&amp;gt;&amp;gt; 5 in list_example
False
&amp;gt;&amp;gt;&amp;gt; dict_example = json.loads(config[&amp;#39;dict_example&amp;#39;])
&amp;gt;&amp;gt;&amp;gt; dict_example
{&amp;#39;bar&amp;#39;: 2, &amp;#39;foo&amp;#39;: 1}
&amp;gt;&amp;gt;&amp;gt; dict_example[&amp;#39;foo&amp;#39;]
1
&amp;gt;&amp;gt;&amp;gt; &amp;#39;bar&amp;#39; in dict_example
True
&lt;/code>&lt;/pre></content><category scheme="https://programming-hints.com/tags/config" term="config" label="config"/><category scheme="https://programming-hints.com/tags/json" term="json" label="json"/><category scheme="https://programming-hints.com/tags/python" term="python" label="python"/></entry><entry><title>Postgres Full Text Search Tutorial</title><link href="https://programming-hints.com/posts/postgres-full-text-search-tutorial/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/postgres-full-text-search-tutorial/</id><published>2014-10-21T00:39:00+00:00</published><updated>2014-10-21T00:39:00+00:00</updated><content type="html">
&lt;p>Today&amp;rsquo;s linked article gives a very in depth introduction to doing &lt;a
class="gblog-markdown__link"
href="http://web.archive.org/web/20141219082121/http://blog.lostpropertyhq.com/postgres-full-text-search-is-good-enough/"
>full text search in Postgres&lt;/a>. The author demonstrates everything with numerous code examples. Their assertion is that for smaller projects, postgres provides all the features you need and you won&amp;rsquo;t require a more specialized search system.&lt;/p>
&lt;p>February 2022 updated: I replaced the original link with the Wayback Machine due to the original website no longer existing.&lt;/p></content><category scheme="https://programming-hints.com/tags/article" term="article" label="article"/><category scheme="https://programming-hints.com/tags/database" term="database" label="database"/><category scheme="https://programming-hints.com/tags/postgres" term="postgres" label="postgres"/></entry><entry><title>NUnit &amp; Parameterized Tests</title><link href="https://programming-hints.com/posts/nunit-parameterized-tests/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/nunit-parameterized-tests/</id><published>2014-10-15T03:16:00+00:00</published><updated>2014-10-15T03:16:00+00:00</updated><content type="html">
&lt;div class="flex align-center gblog-post__anchorwrap">
&lt;h2 id="what-is-nunit-and-why-use-it"
>
What is NUnit and why use it?
&lt;/h2>
&lt;a data-clipboard-text="https://programming-hints.com/posts/nunit-parameterized-tests/#what-is-nunit-and-why-use-it" class="gblog-post__anchor clip flex align-center" aria-label="Anchor What is NUnit and why use it?" href="#what-is-nunit-and-why-use-it">
&lt;svg class="gblog-icon gblog_link">&lt;use xlink:href="#gblog_link">&lt;/use>&lt;/svg>
&lt;/a>
&lt;/div>
&lt;p>NUnit is a .NET port of the popular JUnit test library for Java. It has several advantages that Microsoft&amp;rsquo;s test framework doesn&amp;rsquo;t.&lt;/p>
&lt;p>If you run MS Tests or NUnit tests in visual studio then all your tests appear as a flat list in the test explorer. You only get the method names. If you use the NUnit runner you get the full namespace/class/method hierarchy as seen in the screenshot below.&lt;/p>
&lt;p>&lt;img
src="nunit.png"
alt="NUnit screenshot showing parameterized tests"
title="Nunit screenshot showing parameterized tests"
/>&lt;/p>
&lt;p>An extension is required to run NUnit tests in Visual Studio. Go to Tools → Extensions and Updates, then search for &amp;ldquo;NUnit Test Adapter&amp;rdquo; and install it.&lt;/p>
&lt;p>The final difference to MS Tests is that you can write your tests in the same assembly as your production code. Microsoft enforces separating tests into a different library. Naturally, you can always put your NUnit tests in a separate test dll if you prefer that separation.&lt;/p>
&lt;div class="flex align-center gblog-post__anchorwrap">
&lt;h2 id="parameterized-tests"
>
Parameterized Tests
&lt;/h2>
&lt;a data-clipboard-text="https://programming-hints.com/posts/nunit-parameterized-tests/#parameterized-tests" class="gblog-post__anchor clip flex align-center" aria-label="Anchor Parameterized Tests" href="#parameterized-tests">
&lt;svg class="gblog-icon gblog_link">&lt;use xlink:href="#gblog_link">&lt;/use>&lt;/svg>
&lt;/a>
&lt;/div>
&lt;p>One useful feature in NUnit is the ability to easily add parameters to a test case. This lets you write a single test and call it with a several sets of input data. Probably the best way to demonstrate this is with a (contrived) example.&lt;/p>
&lt;p>Say you have a &lt;code>Calculator&lt;/code> class that you&amp;rsquo;re wanting to test. The usual way of testing the &lt;code>Add&lt;/code> function would be to write a number of test cases which call &lt;code>Add&lt;/code> with different values:&lt;/p>
&lt;pre tabindex="0">&lt;code>[Test]
public void TestAddOneAndOne()
{
Assert.AreEqual(2, calculator.Add(1, 1));
}
// ... more [Test] methods follow for different arguments.
&lt;/code>&lt;/pre>&lt;p>Parameterized tests with the &lt;code>TestCase&lt;/code> attribute allow you to write all the different argument combinations concisely:&lt;/p>
&lt;pre tabindex="0">&lt;code>[TestCase(1, 1, 2)]
[TestCase(2, 3, 5)]
[TestCase(-10, 24, 14)]
public void TestAdd(int arg1, int arg2, int expectedResult)
{
Assert.AreEqual(expectedResult, calculator.Add(arg1, arg2));
}
&lt;/code>&lt;/pre>&lt;p>Each &lt;code>TestCase&lt;/code> runs this method once, passing in the arguments specified. See the previous NUnit runner screenshot for how these test cases appear when run. See the &lt;a
class="gblog-markdown__link"
href="http://www.nunit.org/index.php?p=testCase&amp;amp;r=2.6.3"
>TestCase documentation&lt;/a> for more information.&lt;/p>
&lt;div class="flex align-center gblog-post__anchorwrap">
&lt;h2 id="parameterized-tests-in-junit"
>
Parameterized tests in JUnit
&lt;/h2>
&lt;a data-clipboard-text="https://programming-hints.com/posts/nunit-parameterized-tests/#parameterized-tests-in-junit" class="gblog-post__anchor clip flex align-center" aria-label="Anchor Parameterized tests in JUnit" href="#parameterized-tests-in-junit">
&lt;svg class="gblog-icon gblog_link">&lt;use xlink:href="#gblog_link">&lt;/use>&lt;/svg>
&lt;/a>
&lt;/div>
&lt;p>When I started writing this post, I was originally planning to say that parameterized tests are something NUnit has that JUnit doesn&amp;rsquo;t, but a quick search showed that &lt;a
class="gblog-markdown__link"
href="https://github.com/junit-team/junit/wiki/Parameterized-tests"
>JUnit also has parameterized tests&lt;/a>. The real difference between the NUnit and JUnit implementation is that the syntax is quite messy in JUnit. I&amp;rsquo;ve never seen any parameterized tests in any JUnit code I&amp;rsquo;ve worked on. In contrast, the NUnit syntax is clean and much easier to remember and I have made use of it in a few projects now.&lt;/p></content><category scheme="https://programming-hints.com/tags/.NET" term=".NET" label=".NET"/><category scheme="https://programming-hints.com/tags/C" term="C" label="C#"/><category scheme="https://programming-hints.com/tags/JUnit" term="JUnit" label="JUnit"/><category scheme="https://programming-hints.com/tags/NUnit" term="NUnit" label="NUnit"/><category scheme="https://programming-hints.com/tags/testing" term="testing" label="testing"/></entry><entry><title>Development Process</title><link href="https://programming-hints.com/posts/development-process/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/development-process/</id><published>2014-10-10T19:11:00+00:00</published><updated>2014-10-10T19:11:00+00:00</updated><content type="html">
&lt;p>I highly recommend having a read through this talk: &lt;a
class="gblog-markdown__link"
href="http://zachholman.com/talk/move-fast-break-nothing/"
>Move Fast and Break Nothing&lt;/a>. There are some great ideas in it on continuous development, testing, communication and learning/teaching on the job. Well worth the time to read through and think about whether you can apply some of the points in it to your work.&lt;/p>
&lt;p>A note about this blog: I&amp;rsquo;m going to try and get into a more regular cadence of posts. If you see the gap in the history from May to August it&amp;rsquo;s because I was in the process of moving overseas. I&amp;rsquo;m well and truly settled into my new home now so I have no excuse for sporadic updates [Ed (2022): this didn&amp;rsquo;t happen].&lt;/p></content><category scheme="https://programming-hints.com/tags/article" term="article" label="article"/><category scheme="https://programming-hints.com/tags/meta" term="meta" label="meta"/><category scheme="https://programming-hints.com/tags/process" term="process" label="process"/></entry><entry><title>Tailing Logs with less</title><link href="https://programming-hints.com/posts/tailing-logs-with-less/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/tailing-logs-with-less/</id><published>2014-09-22T05:46:00+00:00</published><updated>2014-09-22T05:46:00+00:00</updated><content type="html">
&lt;p>&lt;code>less&lt;/code> is already an incredibly useful command in linux (GNU/linux for the purists). It&amp;rsquo;s a better version of &lt;code>more&lt;/code>, for paging through files. One not so well known switch for &lt;code>less&lt;/code> is the following:&lt;/p>
&lt;blockquote>
&lt;p>less +F [file]&lt;/p>
&lt;/blockquote>
&lt;p>The &lt;code>+F&lt;/code> option tails the end of the log. Updating when the log changes is buffered, so depending on how noisy your log file is there may be some delay in seeing updates.&lt;/p>
&lt;p>At any time when &lt;code>less&lt;/code> is in tailing mode you can hit &lt;code>CTRL+C&lt;/code> to return to regular less. The status bar reminds you of this with a message like &lt;code>interrupt to abort&lt;/code>. This feature is incredibly powerful, for example if something at the bottom of the log catches your eye and you want to stop tailing for a moment so you can check the logs around it.&lt;/p>
&lt;p>In regular-mode &lt;code>less&lt;/code>, pressing &lt;code>shift+F&lt;/code> will put you into tailing mode. This is true even if you started &lt;code>less&lt;/code> without the &lt;code>+F&lt;/code> option.&lt;/p></content><category scheme="https://programming-hints.com/tags/linux" term="linux" label="linux"/><category scheme="https://programming-hints.com/tags/shell" term="shell" label="shell"/><category scheme="https://programming-hints.com/tags/less" term="less" label="less"/></entry><entry><title>Setting the time zone in C#.NET</title><link href="https://programming-hints.com/posts/setting-the-time-zone-in-c-net/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/setting-the-time-zone-in-c-net/</id><published>2014-04-03T21:31:00+00:00</published><updated>2014-04-03T21:31:00+00:00</updated><content type="html">
&lt;p>DateTimes in .NET are always in one of two timezones - UTC or local time. This advice will make your life easier:&lt;/p>
&lt;blockquote>
&lt;p>Always store DateTimes in UTC.&lt;/p>
&lt;/blockquote>
&lt;p>Unfortunately sometimes we need to deal with timezones stored in a timezone other than UTC. Maybe we&amp;rsquo;ve inherited a system or we&amp;rsquo;re integrating with another system which doesn&amp;rsquo;t save as UTC. If your web server and database server are both in the same timezone and the DateTime is stored in the server&amp;rsquo;s local timezone then everything is still OK. You can easily convert back to UTC or if the users are in the same timezone you don&amp;rsquo;t need to do any conversion.&lt;/p>
&lt;p>What happens when the DateTime stored in the database isn&amp;rsquo;t in UTC or the server&amp;rsquo;s local timezone? If you know the timezone then you can convert the DateTime to UTC using code similar to the following. Once you&amp;rsquo;ve converted to UTC then you can work with it as usual.&lt;/p>
&lt;pre tabindex="0">&lt;code> /// &amp;lt;summary&amp;gt;
/// Convert a DateTime in a specified timezone to UTC.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;#34;timeZoneId&amp;#34;&amp;gt;
/// For valid IDs see: http://msdn.microsoft.com/en-us/library/cc749073.aspx
///&amp;lt;/param&amp;gt;
private DateTime GetUtcDateTimeForTimezone(DateTime dateTime, string timeZoneId)
{
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
DateTimeOffset dto = new DateTimeOffset(dateTime, tzi.GetUtcOffset(dateTime));
return new DateTime(dto.ToUniversalTime().DateTime.Ticks, DateTimeKind.Utc);
}
&lt;/code>&lt;/pre>&lt;p>As the comment in the above code mentions, &lt;a
class="gblog-markdown__link"
href="http://msdn.microsoft.com/en-us/library/cc749073.aspx"
>a list of all available time zones can be found here&lt;/a>.&lt;/p></content><category scheme="https://programming-hints.com/tags/.NET" term=".NET" label=".NET"/><category scheme="https://programming-hints.com/tags/C" term="C" label="C#"/><category scheme="https://programming-hints.com/tags/Database" term="Database" label="Database"/><category scheme="https://programming-hints.com/tags/DateTime" term="DateTime" label="DateTime"/><category scheme="https://programming-hints.com/tags/Timezone" term="Timezone" label="Timezone"/><category scheme="https://programming-hints.com/tags/UTC" term="UTC" label="UTC"/></entry><entry><title>Error Logging with log4net</title><link href="https://programming-hints.com/posts/error-logging-with-log4net/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/error-logging-with-log4net/</id><published>2014-03-21T11:44:00+00:00</published><updated>2014-03-21T11:44:00+00:00</updated><content type="html">
&lt;p>When handling errors you want to do one of the following:&lt;/p>
&lt;ul>
&lt;li>Crash the program.&lt;/li>
&lt;li>Ignore the error.&lt;/li>
&lt;li>Try to fix the error and continue.&lt;/li>
&lt;/ul>
&lt;p>The correct approach depends on a number of factors. What is your application? Do you have enough information available to try and recover or infer what the user wanted to do? Is the error going to impact other operations later on? No matter which approach you choose for handling the error, you ought to use logging!&lt;/p>
&lt;p>At my current job there are two fairly complicated systems I&amp;rsquo;m responsible for maintaining. The older of the two has no logging. When something goes wrong it is hard to find out what happened and sometimes it has been downright impossible! I should note that I didn&amp;rsquo;t write this system although I have become familiar with the code.&lt;/p>
&lt;p>The newer system, which I wrote, has excellent logging thanks to log4net. A quick scan of the log file allows me to pinpoint the cause of errors. It also enables me to display a generic error message to users (it&amp;rsquo;s a web application) and keep the stack traces and unfriendly developer jargon away from them.&lt;/p>
&lt;p>Now that I&amp;rsquo;ve explained the need for logging and the benefits to using it, let&amp;rsquo;s look at how I you can do the same with log4net.&lt;/p>
&lt;p>Firstly you import the log4net dependency with NuGet. Once imported, copy and paste the following line into the top of any classes which you want to add logging to. N.B. I&amp;rsquo;ve split it into two for readability here.&lt;/p>
&lt;pre tabindex="0">&lt;code>private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
&lt;/code>&lt;/pre>&lt;p>This line is exactly the same in each file. The magic is using reflection to get the name of the current class. In the original log4j you have to copy, paste then remember to update the type name in each file.&lt;/p>
&lt;p>Once you have a log variable defined, writing log output is as simple as calling one of the logging methods. log4net supports 4 levels of logging: Error, Warn, Info, Debug. For each level there are several overloads. There is also a &lt;code>*Format&lt;/code> version which allows for formatted parameters similar to &lt;code>String.Format&lt;/code>. Here is an example of error logging from an MVC application. I&amp;rsquo;m overriding the default error handler so any uncaught exceptions in my application are logged with log4net.&lt;/p>
&lt;pre tabindex="0">&lt;code> /// &amp;lt;summary&amp;gt;
/// Override of the default MVC HandleErrorAttribute which writes the exception message to log4net.
/// &amp;lt;/summary&amp;gt;
public class MyHandleErrorAttribute : HandleErrorAttribute
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public override void OnException(ExceptionContext filterContext)
{
log.Error(&amp;#34;An uncaught exception has occurred&amp;#34;, filterContext.Exception);
if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{
log.ErrorFormat(&amp;#34;The currently logged in user is &amp;#39;{0}&amp;#39;&amp;#34;, filterContext.HttpContext.User.Identity.Name);
}
base.OnException(filterContext);
}
}
&lt;/code>&lt;/pre>&lt;p>Choosing where to write your logs is achieved by adding a few lines to your &lt;code>(App|Web).config&lt;/code> file. You can define any number of &lt;code>appenders&lt;/code> and log4net has support for many different places to output your logs. In the example below I&amp;rsquo;m writing the log output to a file which changes daily and to the debug stream - great when developing because it appears in my IDE.&lt;/p>
&lt;pre tabindex="0">&lt;code> &amp;lt;configSections&amp;gt;
&amp;lt;section name=&amp;#34;log4net&amp;#34; type=&amp;#34;log4net.Config.Log4NetConfigurationSectionHandler, log4net&amp;#34; requirePermission=&amp;#34;false&amp;#34; /&amp;gt;
&amp;lt;/configSections&amp;gt;
&amp;lt;log4net&amp;gt;
&amp;lt;appender name=&amp;#34;Debug&amp;#34; type=&amp;#34;log4net.Appender.DebugAppender&amp;#34;&amp;gt;
&amp;lt;layout type=&amp;#34;log4net.Layout.PatternLayout&amp;#34;&amp;gt;
&amp;lt;conversionPattern value=&amp;#34;%date %level %thread %logger - %message%newline&amp;#34; /&amp;gt;
&amp;lt;/layout&amp;gt;
&amp;lt;/appender&amp;gt;
&amp;lt;appender name=&amp;#34;RollingFile&amp;#34; type=&amp;#34;log4net.Appender.RollingFileAppender&amp;#34;&amp;gt;
&amp;lt;file value=&amp;#34;LogFiles\file.log&amp;#34; /&amp;gt;
&amp;lt;appendToFile value=&amp;#34;true&amp;#34; /&amp;gt;
&amp;lt;layout type=&amp;#34;log4net.Layout.PatternLayout&amp;#34;&amp;gt;
&amp;lt;conversionPattern value=&amp;#34;%date %level %thread %logger - %message%newline&amp;#34; /&amp;gt;
&amp;lt;/layout&amp;gt;
&amp;lt;/appender&amp;gt;
&amp;lt;root&amp;gt;
&amp;lt;level value=&amp;#34;DEBUG&amp;#34; /&amp;gt;
&amp;lt;appender-ref ref=&amp;#34;RollingFile&amp;#34; /&amp;gt;
&amp;lt;appender-ref ref=&amp;#34;Debug&amp;#34; /&amp;gt;
&amp;lt;/root&amp;gt;
&amp;lt;/log4net&amp;gt;
&lt;/code>&lt;/pre>&lt;p>Changing the level of logging is as simple as changing the value of the level tag from &lt;code>DEBUG&lt;/code> to &lt;code>WARN&lt;/code>. At the moment I&amp;rsquo;m using &lt;code>DEBUG&lt;/code> for development and testing and using &lt;code>INFO&lt;/code> or &lt;code>WARN&lt;/code> in the production environment. The advantage of having this in a config file is that you can change the logging output and level while the application is running.&lt;/p>
&lt;p>Obviously this post is only an introduction. Great documentation and more examples can be found at &lt;a
class="gblog-markdown__link"
href="http://logging.apache.org/log4net/"
>the official log4net website&lt;/a>.&lt;/p></content><category scheme="https://programming-hints.com/tags/.NET" term=".NET" label=".NET"/><category scheme="https://programming-hints.com/tags/C" term="C" label="C#"/><category scheme="https://programming-hints.com/tags/error-handling" term="error-handling" label="error handling"/><category scheme="https://programming-hints.com/tags/logging" term="logging" label="logging"/></entry><entry><title>Hello World</title><link href="https://programming-hints.com/posts/hello-world-2/" rel="alternate" type="text/html" hreflang="en"/><id>https://programming-hints.com/posts/hello-world-2/</id><published>2014-03-07T06:32:00+00:00</published><updated>2014-03-07T06:32:00+00:00</updated><content type="html">
&lt;p>To introduce my blog, I present to you the simplest hello world program of all.&lt;/p>
&lt;p>&lt;code>print(&amp;quot;hello, world&amp;quot;)&lt;/code>&lt;/p></content><category scheme="https://programming-hints.com/tags/python" term="python" label="python"/></entry></feed>