Saturday, January 25, 2014

Very Basic Configuration Tips with Windows Git SSH

Like most of us you probably started using Git (GitHub most likely) on Windows and found this notion of SSH a bit challenging especially on Windows where Unix like OS manners are imposed on Windows OS and if you do not have exposure to Unix it will be really confusing.

As a programmer, though you think you can go fancy, perhaps even feeling more secure and you do not follow any of the instructions in the book and create directories and name key files the way you want them.

For this, that's where the problem starts to happen. Many Unix based systems for which Git is based on rely on the configurations in default ways. Experts know how to override them in a fairly complex ways like environmental variables or config file edits if you know which ones to manipulate.

You will learn about those as you go... But if you are starting out, don't go fancy, just use the default values as described in the documents and also store the files in the default places where the system expects them to be.

For example, when you run ssh-keygen it outputs id_rsa for the public key and id_rsa.ppk for the private key. Please do note that id_rsa is a file name not a directory. Or maybe you used another SSH key generator where id. RSA could come first with in which case you do need to remove .pub or the rest of the system by default won't recognize it. By the way, the easiest and fastest way is to just use ssh-keygen from the bash command line.

There files should be stored in where the Bash wants them to be. That's ~/.ssh  Do not put them anywhere else. Of course you may be wondering where is ~/.ssh is.

When transacting with files with bash, always use bash and do not use Windows CMD shell. Since Windows command shell does not like file or directory names that starts with a period.

Having said that, for example my user name is stokemaster then the ~ directory is at C:\Users\stokemaster so the .ssh would go to C:\Users\stokemaster\.ssh

Lastly, for the passwords don't go too fancy with it at first either! I had a % sign in my password and ssk-keygen did not like it at all. Don't waste too much time, just try a password consisting of just numbers, upper and lower case letters to make it easy.

Again, I have to stress that don't go too fancy.

Next, you would not want to type in user name and password every time you use Git. There is a script to help you do this as described on this page.

You might be wondering how to make .profile file or .bashrc file. Here is how;

  • Start with the MsysGit bash window (not DOS command window), 
  • type in: cd ~ [ENTER] to go to the home directory. (Enter is the single Enter key I am talking about.)
  • type in: touch .profile [ENTER] (or .bashrc) which will create an empty file.

Now you can use notepad or Notepad++ (recommended) to edit this file, just copy and paste the text in the box (no modification needed)

Friday, January 17, 2014

Windows PowerShell Script to Restart Memory Leaking Services


You have a service or two that has a modest memory leak and you would want to restart right when it has consumed a certain amount of memory.

This approach has an advantage over scheduled restarts because it will restart the service right when it is needed, or otherwise it leaves "it" alone.

This requires the use of Microsoft PowerShell which is available for XP (as download) and built-in on Windows Vista/7 and Server 2003 or later.

First time you try to run it, it is very likely that it won't run the script locally because out of the box, the script file is disabled. You will need to manually type in after manually opening PowerShell

Set-ExecutionPolicy RemoteSigned

From that point on it should permit running.

# This script detects the memory usage threshold and then restarts a service named in this script. You can
# run this script periodically in Scheduled Task to restart memory leaking service.
# Remember to do 
# Set-ExecutionPolicy RemoteSigned 
# so that this script can run
# To run this script from a BAT, 
# powershell -File RestartService.ps1
# First comment out the following two lines so that you can get the basic idea of the content of this stuff by
# looking at the proc.txt output file in your editor to hunt for the process name etc.
# Then it's easier to figure out the filtering for the name and the threshold.
#$Processes = Get-WmiObject -ComputerName "localhost" -Class Win32_PerfFormattedData_PerfProc_Process
#echo $Processes > C:\temp\proc.txt
# First do the Task Manager then find the EXE that is hosting the process or its subprocess then take the .exe out of that name
# If the task manager is showing *32, do not include that either.
# This is the name of the service to restart, this is the 'short' service name you can find in the Service's property
# This is the working set threshold. For example, 3,500,000,000 would be 3.5 GB
#$Threshold = 3500000000
$Threshold = 500000000
# Real Meat of this program
$Process = Get-WmiObject -ComputerName "localhost" -Class Win32_PerfFormattedData_PerfProc_Process -Filter "Name='$ServiceExe'"
$wsm = $Process.WorkingSet /1024/1024/1024;
$thgb = $Threshold/1024/1024/1024
# Format the numbers so they are easier to read in GB units and round up to a
# decimal places.
$Fwsm = $("{0:0.000}" -f $wsm);
$Fthgb =$("{0:0.000}" -f $thg


cho $("Worksing Set is "+ $Fwsm + " gb and threshold is " + $Fthgb  + " gb");
if($Process.workingset -gt $Threshold)
    Restart-Service $Service; 
    echo "Restarted


    $delta = $("{0:0.000}" -f ($thgb - $wsm));
    echo $("Still " + $delta + " gb left. Did not restart"


eep 10

Tuesday, January 07, 2014

Script to Locate A Column Name in the Entire Database

Happy 2014.

Hope you will have a productive software career with some advancements too.

This is my first post of 2014. As always I have been doing, I will continue to write "The Answers to Questions Experts Don't Know How To Answer." And also these are notes to myself as I tend to forget I have done in the past unless I document them somewhere.


I had to figure out someone else's database work as I cannot ask this "someone" a question. I am sure you may be brought into a gig that would require figuring out other people's work without asking them the questions (often you cannot.)

In this case I needed to figure out in every table and view of the SQL Server database that contained the word "Price." Then reconstruct their relationship.

Of all the answers I found the following query worked the best for me so give this a try.

SELECT AS table_name, SCHEMA_NAME(schema_id) AS schema_name, AS column_name
 FROM sys.tables AS t
WHERE LIKE '%Price%'
ORDER BY schema_name, table_name;