Useful Stuff

Here are some files and other stuff that I have found useful over the years.

Reset branch back to remote

If your working copy has changes and pushes in it that you do not want, and you want to dump all of the changes and reset it back to the branch as it exists on remote, here are the commands. In the second command, you would substitute the branch name you want to reset to instead of branch-name, and depending on your repository, you may need to substitute something in place of origin.

git fetch origin
git reset --hard origin/branch-name

Reset Git password on Mac

If you use Git on a Mac and your password changes, your command line and/or GUI client operations may fail without letting you enter a new password. To fix this situation, run this command in terminal:

git config --global --unset user.password

Get SourceTree to pick up Github branches

If you are using SourceTree on a Mac (and this could go for other Git clients as well, YMMV), and you just cannot get that branch you just created on the Github web site to show up under Branches, go into the Mac Terminal and enter the following commands (parens with comments added, do not enter those):

cd myproject (change to your project home directory)
git branch -a (shows a list of branches, should include something like remotes/origin/versionX)
git checkout versionX (the last param is the branch you want to show up in SourceTree)
git branch (verifies that you are using the branch you need to use)

Finding files by name on a Mac

If you want to find all the files on your Mac that match a particular file name or pattern with wildcards, go into Terminal and enter the following command:

sudo find ./ -name "filename*.ext"

The sudo may require an administrative password, but will likely keep you from seeing a bunch of “Permission denied” errors.

Finding files by contained text on a Mac

If you want to find all the files on your Mac that contain a particular text string, go into Terminal and enter one of the following commands:

grep -r 'TextToFind' .
grep -r 'TextToFind' . --include=*.txt

The first one will recursively search all files starting at the current directory, and the second one will only search the files with a .txt file extension. Also, please keep in mind that the text search is case sensitive.

Removing .svn folders on a Mac

After you open up the Terminal and change to the root directory where the .svn folders start, enter the following command:

find ./ -name ".svn" | xargs rm -Rf

SQL Server queries

This query will return the parameters for a given stored procedure, just in case you do not have sufficient permissions to look at
and edit the stored procedure.

SELECT AS ParameterName, AS ParameterType, p.max_length AS ParameterLength
FROM sys.parameters AS p
JOIN sys.types AS t ON t.user_type_id = p.user_type_id
WHERE object_id = OBJECT_ID('YourProcedureName')

This query will show you the tables in your database, along with disk space information about each of the tables.

    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(SUM(a.total_pages) * 8 / 1024.0, 2) AS NUMERIC(36,2)) AS TotalSpaceMB, 
    CAST(ROUND(SUM(a.total_pages) * 8 / 1024.0 / 1024.0, 2) AS NUMERIC(36,2)) AS TotalSpaceGB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(SUM(a.used_pages) * 8 / 1024.0, 2) AS NUMERIC(36,2)) AS UsedSpaceMB, 
    CAST(ROUND(SUM(a.used_pages) * 8 / 1024.0 / 1024.0, 2) AS NUMERIC(36,2)) AS UsedSpaceGB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
    sys.tables t
    sys.indexes i ON t.OBJECT_ID = i.object_id
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
    sys.allocation_units a ON p.partition_id = a.container_id
    sys.schemas s ON t.schema_id = s.schema_id
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
    t.Name, s.Name, p.Rows
    UsedSpaceKB desc

This query will show you the databases that SQL Server knows about, along with their sizes.

    ,[FILE_Name] =
    ,[File_Location] = A.PHYSICAL_NAME
    ,[AutoGrow] = 'By ' + CASE is_percent_growth WHEN 0 THEN CAST(growth/128 AS VARCHAR(10)) + ' MB -' 
        WHEN 1 THEN CAST(growth AS VARCHAR(10)) + '% -' ELSE '' END 
        + CASE max_size WHEN 0 THEN 'DISABLED' WHEN -1 THEN ' Unrestricted' 
            ELSE ' Restricted to ' + CAST(max_size/(128*1024) AS VARCHAR(10)) + ' GB' END 
        + CASE is_percent_growth WHEN 1 THEN ' [autogrowth by percent, BAD setting!]' ELSE '' END
FROM sys.database_files A LEFT JOIN sys.filegroups fg ON A.data_space_id = fg.data_space_id 
order by A.TYPE desc, A.NAME;

Windows 7 batch file command batch file command — I used this for the longest time in on my 32-bit Windows dev boxes to collect key presses inside of my batch files. Unfortunately, this application does not work on my Windows 7 Ultimate 64-bit OS, so I have to modify all of my batch files to use the choice command instead.

Animated GIFs




Leave a Reply