Useful Stuff

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


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 p.name AS ParameterName, t.name 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.

SELECT 
    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
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    UsedSpaceKB desc

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

SELECT 
    [TYPE] = A.TYPE_DESC
    ,[FILE_Name] = A.name
    ,[FILEGROUP_NAME] = fg.name
    ,[File_Location] = A.PHYSICAL_NAME
    ,[FILESIZE_MB] = CONVERT(DECIMAL(10,2),A.SIZE/128.0)
    ,[USEDSPACE_MB] = CONVERT(DECIMAL(10,2),A.SIZE/128.0 - ((SIZE/128.0) - CAST(FILEPROPERTY(A.NAME, 'SPACEUSED') AS INT)/128.0))
    ,[FREESPACE_MB] = CONVERT(DECIMAL(10,2),A.SIZE/128.0 - CAST(FILEPROPERTY(A.NAME, 'SPACEUSED') AS INT)/128.0)
    ,[FREESPACE_%] = CONVERT(DECIMAL(10,2),((A.SIZE/128.0 - CAST(FILEPROPERTY(A.NAME, 'SPACEUSED') AS INT)/128.0)/(A.SIZE/128.0))*100)
    ,[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

enquire.com 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

daffy_swinging

bugs_and_daffy

black_lab

Leave a Reply