Thursday, May 26, 2016

The old 'TFS Repository can not be root and must start with "$/"' error

When using git-tfs to clone a repository using the bash shell, this error is common:
$ git tfs clone https://tfsserver/tfs/DefaultProjectCollection/ "$/path/to/tfs/project"
TFS repository can not be root and must start with "$/".
You may be able to resolve this problem.
The solution? Prepend MSYS_NO_PATHCONV=1 to the command, e.g.:
$ MSYS_NO_PATHCONV=1 git tfs clone https://tfsserver/tfs/DefaultProjectCollection/ "$/path/to/tfs/project"
Initialized empty Git repository in C:/Projects/path/to/tfs/project/.git/
Fetching from TFS remote 'default'...
C6782 = 81584efc08348f7dc4c81297e4e82115789a1e3d
C6784 = 6a6a8bd55111286b24c7acd4825e4ef79030d693
C6863 = 60e8369f34b16a6123d7ed22bf60e59db46ee2e9
etc.

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"
Source: http://git-scm.com/docs/gitattributes#_end_of_line_conversion

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.

http://blog.ezyang.com/2010/01/advanced-git-merge/

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

YMMV.

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


5/26/16 Edit: here's a better version that does not toggle the ScrollLock key and also increases the delay to minimize disruption:
Do
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  WSHShell.SendKeys ("{SCROLLLOCK}{SCROLLLOCK}")
  Set WSHShell = Nothing
  WScript.Sleep (60*1000)
Loop

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.


[5/26/16 Edit: here are all the lines of code together:
]

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 microsoft.com 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
C:\Windows\SysWOW64>
A subsequence pslist worked perfectly.

Tuesday, December 22, 2015

Bootstrap horizontal scrollbar mystery solved

Sometimes when creating a Bootstrap-based site, I've had a pesky problem with a horizontal scrollbar that appears and just won't go away. It turns out the root cause -- and the solution – are simple.
Essentially, make sure any “row” div is inside a “container” div, e.g.:
Wrong
<div class="row">
    <div class=”col-md-12”>This is some content inside the column</div>
</div>
Right
<div class=”container”>
    <div class="row">
        <div class=”col-md-12”>This is some content inside the column</div>
    </div>
</div>

Tuesday, December 01, 2015

Git TFS with Git 2.5 and above - Solved!

I experienced the same issues as the OP here: https://github.com/git-tfs/git-tfs/issues/845

In my case:
$ git tfs clone https://me.visualstudio.com/DefaultCollection/_versionControl $/MyProject
TFS repository can not be root and must start with "$/".
You may be able to resolve this problem.
- Try using $/C:/Program Files/Git/MyProject
The solution, courtesy of dscho: an msys2 flag that looks like the most bastardized bash syntax in the world, but apparently works. (Is this valid bash or a special msys2 thing?)
$ MSYS_NO_PATHCONV=1 git tfs clone https://me.visualstudio.com/DefaultCollection/ $/MyProject
Initialized empty Git repository in C:/Projects/MyProject/.git/
This is documented in the release notes here: https://github.com/git-for-windows/build-extra/blob/master/installer/ReleaseNotes.md#known-issues

EDIT:

You can also double up the initial quote after the $, e.g.:
$ git tfs clone https://me.visualstudio.com/DefaultCollection/ $//MyProject
Initialized empty Git repository in C:/Projects/MyProject/.git/


Tuesday, January 27, 2015

Doug Crockford on Monads and JavaScript

He's not the father of JavaScript, he's more the strongly opinionated caretaker.

Here is his fascinating YouTube video on JavaScript and Monads.

Here is the sourcecode: https://github.com/douglascrockford/monad

He covers four monads in the talk:

  • The Identity Monad
  • The Ajax Monad
  • The Maybe Monad, which eliminates the possibility of a null -- very cool!
  • The Promise Monad, which apparently is not agreed upon by all to be a monad

Two links he mentions

Carl Hewitt, inventor of the Actor Model

Mark Miller, Secure Distributed Programming with Object-capabilities in JavaScript

How to Page in ASP.NET Web API

Great article. There are several ways of doing it, including the Twitter way, which handles infinite feeds in real-time scenarios using cursors.

Paging in ASP.NET Web API: Introduction | Jerrie Pelser

Cool Visual Studio Extensions From Mads Kristensen

Mads, the author of the essential Web Essentials extension for Visual Studio, has created a number of other plugins and extensions as well. Here's a link to two blog posts by him describing these extensions.

New handy Visual Studio extensions
New handy Visual Studio extensions - part 2

Monday, January 26, 2015

Learn F# or Haskell?

Here's a side-by-side comparison of ML dialects, of which F# is one, with Haskell:
ML Dialects and Haskell: SML, OCaml, F#, Haskell - Hyperpolyglot

Then there are the various "99 Bottles" F# implementations. Interestingly, Don Syme's is one of the longer version. He is the creator of F# and arguably knows it the best.
99 Bottles of Beer | Language F#

Here's the Haskell version:
99 Bottles of Beer | Language Haskell

Friday, January 23, 2015

ASP.NET - don't minimize files if you're bundling!

If you've got bundling turned on, the ASP.NET bundling library will choose the already minimized instead of minimizing it at runtime. This can cause problems if you have updated the the source file -- file.js or file.css -- and you haven't remimized it.

So don't minimize the file in the IDE. Alternatively, set up some sort of automation that will automatically minimize the file or your minimized CSS and JavaScript files will be out of sync and your won't know why.

See this StackOverflow question: ASP.NET Bundling - Bundle not updating after included file has changed (returns 304 not modified)

Thursday, January 22, 2015

Adding only non-whitespace changes in Git.

Sometimes it's useful to add only the non-whitespace changes because typically they'll be the meaningful content. This StackOverflow question show how to do that.

Here's the command to add everything, ignoring whitespace-only changes:

git diff -w | git apply --cached --ignore-whitespace


Link here: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes

Wednesday, December 10, 2014

Properly serving SVG files in IISExpress

If you just edit your web.config file it will actually break your website under IISExpress. Instead, follow the instructions found here: http://tomasmcguinness.com/2011/07/06/adding-support-for-svg-to-iis-express/
  • Open a console application with administrator privileges.
  • Navigation to the IIS Express directory. This lives under Program Files or Program Files (x86)
  • Run the command appcmd set config /section:staticContent /+[fileExtension=’svg’,mimeType=’image/svg+xml’]



Wednesday, November 05, 2014

Git line ending fixups revisited

I blogged about this a few years ago. I discovered how to do this when using .gitattributes, which is automatically created when you use Visual Studio to create a project that uses git as its version control system.

I have a .gitattributes file that contains (among other things) this line at the top:
The sequence of commands is the following:

First, add all changed files: Then, edit the .gitattributes file to comment out the "text=auto" line and save this file: Then issue this command to un-stage all the files. It doesn't matter whether some of the files have meaningful changes. You're not resetting or undoing any file edits, you're merely removing them from the index: Finally, restore the "text=auto" line in your .gitattributes file and save that file: You should be all set. If you issue a git status command again you should see only the files that have meaningful changes, if any.