Category: Uncategorized

Aug 08 2018

The proper way to use HttpClient

Most people are mostly using .net HttpClient the wrong way.  This is because HttpClient implements IDisposable which makes people think they should wrap it in a using statement.  Also, most code example on the interwebs show that usage including a lot of documentation from Microsoft.

Wrong. Wrong. Wrong.

Here is a great Code Project article on it.  It takes a “recipes” approach which makes it even better…


Oct 27 2017

To map each bit in a single byte to individual bools do this (using c#)

Implemented as two extension methods in this example. Using an enum to get the bit your looking for.

public enum Weekday

public static bool GetBitwiseBool(this byte bits, Weekday weekday)
	return (bits & (1 << (int)weekday - 1)) != 0; 

public static bool GetBitwiseBool(this string bits, Weekday weekday) 
    if (!bits.All(c=>"01".Contains(c)))
		bits = "11111111";
	//8 character or less
	if (bits.Length>8)
		bits = bits.PadLeft(8,'0');

	var myByte = Convert.ToByte(bits, 2);
	return myByte.GetBitwiseBool(weekday);

Aug 30 2017

Comment by Seth Spearman on Understanding the recursive CTE termination check

I'll have to check out that dense_rank() function. But thanks...awesome solution.
Aug 30 2017

Comment by Seth Spearman on Understanding the recursive CTE termination check

@scsimon, thanks for your answer. My question lacked context. I have edited the answer to provide some context. I intentionally left my sqlfiddle very simple so that the recursion question could be addressed. My real query actually does have some depth to it.
Jun 23 2017

Comment by Seth Spearman on Does Mirth Open-Source support channels that work over https (using ssl)

Can you point me to a URL that explains the workaround?
Apr 19 2017

Answer by Seth Spearman for MS Access tabbed form multiple OnCurrent firings

I believe the proper way to do this is to not dynamically change the rowsource of the combobox. Instead, set the rowsource to a query using the query designer and have the query read the value from the "main form" just as is shown in your sample code...Forms![products main form]!ProductNumber.

Then I would trigger the refresh of the combo box using the MAIN FORMs AfterUpdate event. It will be something like MainForm!MySubForm.Form("mycombobox").requery. (I may not have that syntax exactly access syntax is rusty.)

BTW, I don't like my own answer. The reason is that you are hard-coding a dependency between the subform and its parent. That might be fine if you will NEVER use that subform anywhere else. To get around this some Access Developers use a hidden form that has textboxes that you set from the Main Form's After Update event. Then the query is updated to refer to the the hidden form's textbox that you created for this form.

There are other ways to do this, too (public functions for example). But sorry, that is not really what you were asking for. My first method will work. But first time you need to re-use that subform you will need to refactor and the hidden form solution works pretty well.

Feb 22 2017

If you need to make a bootable USB drive using an ISO…

…use Rufus

Nov 09 2016

Comment by on Is there a way to aggregate a variable range of dates in SQL using a SET operation

Wow...this totally worked! I love the simplicity. No need to avoid holidays so I am giving you the answer.
Nov 08 2016

Comment by on Is there a way to aggregate a variable range of dates in SQL using a SET operation

@Hogan I see your point.
Oct 18 2016

Does SQL short-circuit the evaluation of an OR in the WHERE CLAUSE?

Looking at other questions here on SO and google seems to indicate MS Sql Server does not guarantee to short circuit the expressions in the WHERE clause.

Does that mean that a WHERE expression like this this one cannot be trusted to work...?

... WHERE (@include_voided = 1 OR mytable.void = 0) AND ... 

I frequently use this kind of expression in my stored procedures. Having researched short-circuiting for another reason I am now wondering if this should be replaced with ...

... WHERE mytable.void = case when @include_voided=1 then mytable.void else 0 END all of the articles seem to indicate that CASE statements are the only ones guaranteed to short-circuit.

I am hoping that the first expression is fine just because it is more readable and easier to type.