Friday, April 15, 2016

TestDisk - Partition Recovery and File Undelete

I wish I'd known about this a few months ago. I accidentally make a disk unbootable, but eventually, after many hours of struggle, I got it working again. This might have save me those many hours.

TestDisk - Partition Recovery and File Undelete

I found this reading the original Server Fault post on the huge data loss allegedly suffered by someone at a British web hosting company.

Linux command line mistake nukes web boss' biz • The Register

centos7 - Recovering from a rm -rf / - Server Fault

Thursday, March 03, 2016

Cleaning Visual Studio solutions when using Git

Visual Studio has a "Clean Solution" command, of course, but it's conservative in what it cleans and sometimes leaves detritus around that most of the time you want eliminated. It seems to only clean files -- DLL's and PDB's, mostly, but also content configured to be copied to the output folder -- that are created by the current source code and copied references and other files. It also does not eliminate files created at runtime -- for instance error logs -- that your program may have created. One situation in which files are not deleted by the "Clean Solution" or the "Clean Project" command is when you remove an assembly or project reference from a project before you clean it. The removed reference remains in your project's output directory.

Let Git come to the rescue! Assuming that you have a sensible .gitignore file, the following command will delete all bin and obj folders from your project and all subprojects:

Thursday, January 14, 2016

Deleting git index file, a.k.a. more authoritative methods of dealing with Git line ending problems

The classic problem in Windows with line endings in files repeatedly rears its ugly head. I've tried a number of different ways over the years of dealing with them, but I discovered today that the gitattributes documentation actually gives a recipe for dealing with it, which I'll reproduce here:
$ echo "* text=auto" >>.gitattributes
$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"

Meanwhile, the people over at Github have a slightly different approach. (I'm wondering if rm .git/index followed by git reset is the same as git rm --cached -r.) [EDIT: I realize upon studying this that this version will touch all files in the source tree, whereas the version above does not.]
$ echo "* text=auto" >>.gitattributes
$ git rm --cached -r .
$ git reset --hard
$ git add .
$ git commit -m "Normalize all the line endings"
Source: Refreshing a repository after changing line endings (Github)

The potential problem of the Github approach is that it would add files you might not want in your repository if your repository has any extra stuff in it, i.e. if doing a git status before their procedure shows any files not in the repository.

What's very interesting about the Github approach is that it's very similar to my method for removing all files from a repository that you'd actually like to ignore, except that my steps are missing the git reset --hard command:
$ git rm --cached -r .
$ git add .gitignore
$ git add .
$ git commit -m "Remove ignored files."

git reset vs git reset --hard

One thing I'm not sure of is the difference between git reset and git reset --hard in the Github approach. I'll have to think about that another time. :)

Saturday, January 09, 2016

Five advanced Git merge techniques

Some very interesting stuff here.

I knew about (but forgot) #1 -- including "base" in the merge file output -- but some of the other things are pretty interesting as well.

#4 -- git merge-file, which redoes the merge -- looks particularly interesting and powerful and helps out in the classic newlines style situations I often find myself in.

This blog, subtitled "Existential Pontification and Generalized Abstract Digressions," and which I only recently discovered, seems primarily concerned with Haskell but has a huge helping of computer science articles as well. The name of the blog -- "Inside 736-131" -- sounds like the name of a computer science course at MIT. [Edit: now I see that it's apparently Stanford-specific.]

Tuesday, January 05, 2016

Keeping RDP sessions from locking due to inactivity


Create a VBS file with the following contents:
 Set WSHShell = WScript.CreateObject("WScript.Shell")
 WSHShell.SendKeys ("{SCROLLLOCK}")
 Set WSHShell = Nothing
 WScript.Sleep (2*1000)
Save as a VBS and run on whatever machine you want to stay open

Monday, January 04, 2016

Git: removing cruft from a repository that was added without a .gitignore file

I inherited a Visual Studio project, originally in TFS, where the developer before me added files somewhat willy-nilly to the repository without any sort of filter. Thus, NuGet packages, the bin and obj directories, user settings, and even error logs were committed to version control.

Long story short, I scratched my head over how to clean up the repository such that ignored files were excluded from it. I started picking through by location, file type, and so on, but this took too long, was too tedious, and was likely to miss some files.

Finally, the solution hit me, and it's really quite simple. Here are the steps:

Step 1: remove the entire repository or folder.
$ git rm --cached -r .
Step 2 (optional): if it wasn't already present, add the .gitignore folder obtained from, e.g. the gitignore project:
$ git add .gitignore
Step 3: add back the folder
$ git add .
Step 4: commit the whole shebang:
$ git commit -m "Remove ignored files."
Voila! The resulting commit status (or diff) will show all undesired files being removed.

Tuesday, December 29, 2015

pslist not working – solved

I’m a huge fan of Sysinternals tools, and one of my favorites – pslist – suddenly stopped working one day after a reboot. The error message I received was:
Processor performance object not found on PC01
Try running Exctrlst from to repair the performance counters.
The Exctrlst in question is from the Windows Resource Kit. After installing and running the Exctrlst utility, it still didn’t work. Luckily, more Googling led me to running this command:
lodctr /r
Which of course didn’t work either. First I got an error code 5, which I recognized as the old “Access denied” error code, so I ran it again as Administrator. No dice. That just gave me an error code 2.
More Googling until I found the following solution:
C:\> cd C:\Windows\SysWOW64
C:\Windows\SysWOW64> lodctr /r
Info: Successfully rebuilt performance counter setting from system backup store
Yay! And finally:
C:\Windows\SysWOW64> winmgmt.exe /RESYNCPERF
A subsequence pslist worked perfectly.