Jun 21

How can I decode UTF-8 encoded data from a MySQL table with Latin1 character set?

If you have UTF-8 encoded data in a MySQL table that has character set set to Latin1 you can use the following SQL statement to correctly decode it:


Jun 14

How can I remove a virtual directory in the Default Web Site using appcmd.exe?

Use the following command

appcmd delete app /app.name:"Default Web Site"/VDir

where VDir is the name of the virtual directory / application under the Default Web Site.Appcmd.exe can usually be found in the C:\Windows\System32\inetsrv folder.

Nov 23

How can I determine which process occupies a port?

To find out which process uses a certain TCP or UDP port you can use a tool called netstat. Netstat is a command-line tool that displays incoming and outgoing network connections, routing tables, and network statistics.

So to determine which process is listening on port 80, go to command prompt and type

netstat -aon | find ":80"


In the fifth column you get a process ID, from which you can then find a process in the Task Manager (that has to be configured to show PID column).

For more information about netstat see http://en.wikipedia.org/wiki/Netstat.

Nov 15

Book Notes – The Power of Habit: Why We Do What We Do in Life and Business by Charles Duhigg

A couple of weeks ago I read The Power of Habit: Why We Do What We Do in Life and Business, by Charles Duhigg. I really liked it as it describes mechanisms of forming habits and helps us change them. Since there are several “bad” habits I would like to change in my life, the recommendations in the book will come handy.

Here are several quotes from the book that I find especially interesting or useful.

Habit process is a three-step loop.

First there is a cue, a trigger that tells your brain to go into automatic mode and which habit to use. Then there is the routine, which can be physical or mental or emotional. Finally, there is a reward, which helps your brain figure out if this particular loop is worth remembering for the future

Habits can be changed, replaced or ignored. We can choose our habits (no matter how complex) once we know how.

Habits aren’t destiny.

Habit loop is very important.

When a habit emerges, the brain stops fully participating in decision making. It stops working so hard, or diverts focus to other tasks. … unless you find new routines – the pattern will unfold automatically.

Without habit loops, out brains would shut down, overwhelmed by the minutae of daily life.

Advertisers have learned that craving is what makes cues and rewards work so they use it for their own agenda.

Cravings are what drive habits. And figuring out how to spark a craving makes creating a new habit easier.

Habits are created:

by putting together a cue, a routine, and a reward, and then cultivating a craving that drives the loop.

We must recognize which craving is driving the behavior, if we want to overpower the habit.

Only a cue and a reward are not enough if we want to change a habit for good.

Only when your brain starts expecting the reward, … will it become automatic… The cue, in addition to triggering a routine, must also trigger a craving for the reward to come.

Rule for changing a habit seems quite simple.

If you use the same cue, and provide the same reward, you can shift the routine and change the habit.

There is a golden rule of habit change:

You can’t extinguish a bad habit, you can only change it. … USE THE SAME CUE. PROVIDE THE SAME REWARD. CHANGE THE ROUTINE.

Often we need help from other people if we want to permanently change a habit.

For a habit to stay changed, people must believe change is possible. And most often, that belief only emerges with the help of a group.

Changing or maintaining keystone habits can cause larger shifts in our behavior. But

To find them, you have to know where to look. Detecting keystone habits means searching out certain characteristics. Keystone habits offer … “small wins”

A habit cannot be erased, it must be replaced. If we keep the same cue and the same reward, a new routine can be inserted. We need a help from others as well so it is best if we commit to changing a habit as a part of a group.

For a habit to stay changed, people must believe change is possible. And most often, that belief only emerges with the help of a group.

Small wins are very important, because they have an influence disproportionate to the accomplishments of the victories themselves. They are a steady application of a small advantage.

One of the most important habits is willpower. The best way to strengthen it, is to make it a habit. And to make it a habit we need to choose a certain behavior ahead of time, and then follow that new routine, when an inflection point (cue) arrives.

Organizations also have habits. The best time to change an organizational habit is during a crisis.

You never want a serious crisis to go to waste.

Our brain is wired in such a way that it craves familiarity (for example in music; otherwise we might become distracted by all the sounds around us).

… behavioral habits prevent us from becoming overwhelmed by the endless decisions we would otherwise have to make each day.

If you want to sell something new to the people, you need to make it familiar.

If you dress a new something in old habits, it’s easier for the public to accept it.

We are social creatures.

People want to visit places that satisfy their social needs.

Starting a movement is not easy.

A movement starts because of the social habits of friendship and the strong ties between close acquaintances. It grows because of the habits of the community, and the weak ties that hold neighborhoods and clans together. And it endures because a movement’s leaders give participants new habits that create a fresh sense of identity and a feeling of ownership.

Changing a habit is not easy.

… to modify a habit, you must decide to change it. You must consciously accept the hard work of identifying the cues and rewards that drive the habits’ routines and find alternatives. You must know you have control and be self-conscious enough to use it.

And once you realize that habits can change,

you have the freedom – and the responsibility – to remake them.

If you believe you can change, the change becomes real.

The framework for changing a habit has several steps:

  • identify the routine

To understand your own habits, you need to identify the components of your loops. Once you have diagnosed the habit loop of a particular behavior, you can look for ways to supplant old vices with new routines.

  • Experiment with rewards

To figure out which cravings are driving particular habits, it’s useful to experiment with different rewards. This might take a few days, or a week, or longer. During that period you should not feel any pressure to make a real change

  • Isolate the cue

The reason why it is so hard to identify the cues that trigger our habits is because there is too much information bombarding us

Almost all cues fit into one of five categories: location, time, emotional state, other people, immediately preceding action. So if you are trying to figure out a cue, answer five questions the moment the urge hits:

  1. Where are you?
  2. What time is it?
  3. What is your emotional state?
  4. Who else is around?
  5. What action preceded the urge?
  • Have a plan

A habit is a formula our brain automatically follows: When I see a CUE, I will do ROUTINE in order to get a REWARD. To reengineer that formula we need to begin making choices again. And the easiest way to do this … is to have a plan.

Write down what you intend to do when you feel the urge.

Oct 05

How can I quickly sort characters in a string?

string word = "cab";
string sorted = string.Concat(word.OrderBy(c => c));

Jan 16

How can I disable a plugin in Google Chrome?

To disable a plugin in Google Chrome type chrome://plugins/ in the address bar (sometimes also called omnibox). A page with all plugins will be displayed and you can disable them easily by just clicking the “Disable” link.

Google Chrome Plugins

Jan 08

Spell Checker in Axosoft OnTime

It seems that Axosoft does not intend to implement spell checker in the Windows client for OnTime Scrum Project Management Software. There is however a solution for the problem: AutoHotkey and "AutoCorrect for English" script.

  1. Download AutoHotkey from http://www.autohotkey.com/
  2. Download "AutoCorrect for English" script for AutoHotkey from http://www.autohotkey.com/download/OtherDownloads.htm.
  3. Install AutoHotkey.
  4. Double click AutoCorrect.ahk file in the file manager of your choice to run the script.
  5. You will get a small H icon in the Windows Tray area. If you right click it you will get a popup menu that allows you to edit or reload the script, suspend hotkeys, etc.
  6. Open OnTime if it is not running yet and start typing. If you make a mistake the AutoCorrect script will automatically fix it for you.

The "AutoCorrect for English" script corrects about 4700 common English misspellings on-the-fly (wherever you type them) via hotstrings. It also includes a Win+H hotkey to make it easy to add more corrections for misspellings (see the screenshot below). Of course you can also edit the script manually with a regular text editor. The good thing is that the script will also work in other applications (Notepad, etc.).


I cannot recommend using AutoHotKey enough for other purposes also because it is truly very powerful and useful tool that can save you lots of keystrokes and mouse clicks.

Jan 06

How can I get information about digital signatures of all files in the folder?

The following PowerShell code snippet allows you to get information about digital signatures of all files in a specific folder:

Get-ChildItem *.* | foreach-object {Get-AuthenticodeSignature $_}

All you have to do is start PowerShell, go to the folder you want to check and run the command.

Oct 12

How can I delete records from MS SQL Server database using Python?

The following code will delete all records from table in database on server.

import win32com.client

connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=database;Data Source=server;"
query = "delete from table;"
con = win32com.client.Dispatch('ADODB.Connection')
con.Close( )

Note: This code works on Windows only. You will also need to install excellent Python for Windows extensions (pywin32) by Mark Hammond from http://sourceforge.net/projects/pywin32/.

Sep 28

How can I restart Windows service with Python?

First you need to install excellent Python for Windows extensions (pywin32) by Mark Hammond from http://sourceforge.net/projects/pywin32/.

Then you can use the following code (that will restart the Print Spooler service).

import win32serviceutil

serviceName = "spooler"


Note: this code was tested with Python 2.7 and version 216 of the pywin32 extensions.

Older posts «