I’m writing again! Where have I been?

Written By: John Glasgow

For those of you following my blog, I have not written in some time.  This is because, like many things, time has significantly changed my priorities. I find it fitting that this blog is titled RefactoringSelf, because I have been heavily involved in changing my career and my goals. I recently finished my MBA and got a Business Architecture certification. My family has also expanded to four children, which provide me with much joy.

Photo by Pixabay on Pexels.com

I am still a die-hard fan and participant in software development and programming, but I also am starting to focus on the wider needs of the industry and focusing more on the business end of things.

What does this mean for RefactoringSelf?

I am still committed to providing good content that can help developers, but I will expand my topics to other areas that can improve your role where you work as I delve into different concepts that will round out you as a software developer. After all, you might be the most technically brilliant person in the room, but what good is it if you can’t relate to or understand the problems the business is facing?

New content you say?

Yes, it is my intention to provide content on new subjects such as:

  • business topics
  • soft skills (writing, communication, team building, strategy)
  • enterprise architecture
  • business architecture

I am continuously having experiences and challenges. My hope is that I can provide you with new interesting content that will save you a few steps (or a few missteps).

I am looking forward to continuing to share my journey and with you and hopefully get some great interactions with you in the future.

Advertisement

Great Primer for Threading Basics in .Net

I stumbled across this article from one of my LinkedIn friends,  Threads in C#

It answered one of my questions about thread pooling in a very concise, easy to understand fashion.  It is a short article, but he then goes into the Task Parallel Library, something that I really enjoy.

If you are asking why should I care about this, I use the magic of Async/Await.  These are the fundamental technologies and techniques that they are built upon.

Keep in mind that not many people are experts in highly concurrent systems, I am not one of them either.  But hopefully by reading this article we will all be a little better in how we implement parallelism/concurrency.

Cheers!

SQL Server Performance Tuning For Developers

Chances are if you are reading this, you are a software developer.  Relax, I am one too, as well as a database administrator.  I spend a lot of time helping people to write code that is efficient or get the right results.  I want to share this post on SQL Database Tuning http://www.toptal.com/sql/sql-database-tuning-for-developers by Rodrigo Koch. It provides some really good advice, especially for beginners in the area.

Really hits the nail on the head though, keep it minimalistic. Only return what you need, it takes more time on the server and then the data has to go over the network.  He goes into some detail of how to troubleshoot slow queries and when to create indexes

 

Mocking in Python

An Introduction to Mocking in Python by Naftuli Tzvi Kay

This article is very insightful for covering mocking in Python.  In case you don’t know mocking is a technique for testing where you don’t want to use a particular object or set of objects.  For example, you might want to simulate database functionality while you are writing your test cases.

Hope you all find this useful, have a great day!

 

Powershell – Copyrighting made easy

I recently needed to submit a program I’m working on for a copyright. One of the criteria is the first and last 25 pages of the program need to be submitted. I really didn’t want to go into every source code file and append it to a file manually, I have more important things to do than that. I used my old friend Powershell to get what I needed.

Here is the line:

> ls *.cs -recurse | ?{-not ($_.fullname -match “obj”) -and -not ($_.fullname -match “properties”)} | Get-Content > sourcecode.txt

What this is doing is grabbing all of my C# code from my solution (excluding code in the obj and properties folders) and dumping it to a text file.

From there I was able to upload one file.

Finding All The Logins Not Associated to Database Users

Today I ran into a particular issue, consolidating user accounts. In this particular exercise, I needed to remove old user accounts that were not tied to any databases. Here is a neat trick I did to get a reasonable number of logins to look at for disabling.

CREATE TABLE ##names (NAME SYSNAME);
EXEC sp_msforeachdb ‘insert into ##names (name) select name from [?].sys.sysusers’;

SELECT name,
loginname
FROM sys.syslogins l
WHERE NOT EXISTS ( SELECT *
FROM ##names u
WHERE u.name=l.name )

Using the unsupported sp_msforeachdb stored procedure I could dump all the usernames into a table and compare it to the logins. Simple, quick, dirty…But saved a lot of time!

SQL Server – Searching for Non-Alphanumeric characters Using Like

All I can say is I have never really needed to search for a percent sign or square brackets or a caret in a query until today. GooBling (Googling and Binging) didn’t return any useful results. Of course Kim Tripp, one of the sage SQL Server gurus always recommends checking Books Online first, shame on me for not checking there first but this wasn’t entirely obvious. Check out the details here: http://msdn.microsoft.com/en-us/library/ms179859.aspx

You can specify an escape character using a very, now, obvious escape character. An escape character placed in front of a pattern matching character will force SQL Server to recognize the pattern matching character as a normal character.

For example:

SELECT * FROM table WHERE col1 LIKE ‘%|%%’ ESCAPE ‘|’

The above query will return all rows where col1 contains a percent sign.

SQL Server Delete From vs. Truncate Table

There are some very important distinctions between these that I feel I need to explain.

Delete From
First and foremost delete is used for deleting a limited number of rows from a table. This is not to be used for deleting all rows in a table.

Another important note is that this is a logged process meaning it writes this delete into the transaction log. Which is good if you ever need to recover those rows.

Also deleting rows does not reset or reseed, more technically, any identity columns. So deleting the last row will not decrement the identity column.

Truncate Table
So this function is to delete all rows in the table.

Unlike Delete, this operation is very efficient, mainly because it is not a logged process. Use this for very specific reasons, testing, repeating processes, etc.

Also it will reseed the identity column in your table. So for example, it will delete all the rows in your table and the identity will be reset to its initial value, by default this is the number 1.

Powershell ~ Shorten Shortcut Names

Renaming Files

Here is something I just came up with. It is a really short Powershell one-liner to remove the annoying ‘- Shortcut’ from your shortcuts.

dir “*- Shortcut*” | foreach{ren -Path $_.Name -NewName $_.Name.Replace(” – Shortcut”,””)}

It is a good idea to execute it first with -whatif in the foreach loop.

Note: Be sure to be in the desktop directory when you run this.

Visual Basic 2010 Object and List Initialization

I just found this out and I am really excited about it! The With & From are cooler than ever!

Check this out:

Module Module1
Private Class TestClass
Public Property Subject As String
Public Property Grade As String
Public Property Student As String
End Class
Sub Main()
Dim myTest As New TestClass With {.Grade = "A+", .Student = "Myself", .Subject = "Advanced Chromotography"}

Dim test As New System.Collections.Generic.List(Of TestClass) From {
myTest,
New TestClass With {.Subject = "Math", .Student = "John Bowman", .Grade = "B"}}

End Sub
End Module

The With and From are now part of the declaration statement, saving even more real estate on the screen.