TristinDavis
TristinDavis
Tristin Davis
11 Snippets
Published
1 Channel
Created
3 Channels
Following
3 points
Reputation
Junior Code Generator
Serious Code Generator
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Senior Autobiographer
Junior Famous Coder
Serious Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by TristinDavis

public by TristinDavis  1411  2  3  0

CI WebDeploy using MSBuild - Creates WebDeployment package and then deploys that package using the given published profile name

CI WebDeploy using MSBuild - Creates WebDeployment package and then deploys that package using the given published profile name: msbuild-webdeploy.commandline.cmd
## Deployment Step ##

```
MSBuild.exe C:\Projects\Class.csproj /P:Configuration=Debug /P:DeployOnBuild=true /P:DeployTarget=Package /P:PublishProfile=ClassOnlineProduction /P:_PackageTempDir=C:\packages /P:CreatePackageOnPublish=True /P:VisualStudioVersion=14.0
```


;

public by TristinDavis  1173  2  4  0

SQL Server View missing indexes

SQL Server View missing indexes: missing_indexes.sql
-- Credit to https://basitaalishan.com/2013/03/13/find-missing-indexes-using-sql-servers-index-related-dmvs/
SELECT CAST(SERVERPROPERTY('ServerName') AS [nvarchar](256)) AS [SQLServer]
    ,db.[database_id] AS [DatabaseID]
    ,db.[name] AS [DatabaseName]
    ,id.[object_id] AS [ObjectID]
    ,id.[statement] AS [FullyQualifiedObjectName]
    ,id.[equality_columns] AS [EqualityColumns]
    ,id.[inequality_columns] AS [InEqualityColumns]
    ,id.[included_columns] AS [IncludedColumns]
    ,gs.[unique_compiles] AS [UniqueCompiles]
    ,gs.[user_seeks] AS [UserSeeks]
    ,gs.[user_scans] AS [UserScans]
    ,gs.[last_user_seek] AS [LastUserSeekTime]
    ,gs.[last_user_scan] AS [LastUserScanTime]
    ,gs.[avg_total_user_cost] AS [AvgTotalUserCost]
    ,gs.[avg_user_impact] AS [AvgUserImpact]
    ,gs.[system_seeks] AS [SystemSeeks]
    ,gs.[system_scans] AS [SystemScans]
    ,gs.[last_system_seek] AS [LastSystemSeekTime]
    ,gs.[last_system_scan] AS [LastSystemScanTime]
    ,gs.[avg_total_system_cost] AS [AvgTotalSystemCost]
    ,gs.[avg_system_impact] AS [AvgSystemImpact]
    ,gs.[user_seeks] * gs.[avg_total_user_cost] * (gs.[avg_user_impact] * 0.01) AS [IndexAdvantage]
    ,'CREATE INDEX [Missing_IXNC_' + OBJECT_NAME(id.[object_id], db.[database_id]) + '_' + REPLACE(REPLACE(REPLACE(ISNULL(id.[equality_columns], ''), ', ', '_'), '[', ''), ']', '') + CASE
        WHEN id.[equality_columns] IS NOT NULL
            AND id.[inequality_columns] IS NOT NULL
            THEN '_'
        ELSE ''
        END + REPLACE(REPLACE(REPLACE(ISNULL(id.[inequality_columns], ''), ', ', '_'), '[', ''), ']', '') + '_' + LEFT(CAST(NEWID() AS [nvarchar](64)), 5) + ']' + ' ON ' + id.[statement] + ' (' + ISNULL(id.[equality_columns], '') + CASE
        WHEN id.[equality_columns] IS NOT NULL
            AND id.[inequality_columns] IS NOT NULL
            THEN ','
        ELSE ''
        END + ISNULL(id.[inequality_columns], '') + ')' + ISNULL(' INCLUDE (' + id.[included_columns] + ')', '') AS [ProposedIndex]
    ,CAST(CURRENT_TIMESTAMP AS [smalldatetime]) AS [CollectionDate]
FROM [sys].[dm_db_missing_index_group_stats] gs WITH (NOLOCK)
INNER JOIN [sys].[dm_db_missing_index_groups] ig WITH (NOLOCK)
    ON gs.[group_handle] = ig.[index_group_handle]
INNER JOIN [sys].[dm_db_missing_index_details] id WITH (NOLOCK)
    ON ig.[index_handle] = id.[index_handle]
INNER JOIN [sys].[databases] db WITH (NOLOCK)
    ON db.[database_id] = id.[database_id]
WHERE db.[name] LIKE 'ClassOnlineAssessmentDev' -- Remove this to see for entire instance
ORDER BY [IndexAdvantage] DESC
OPTION (RECOMPILE);

;

public by TristinDavis  1233  0  4  0

Class to do Unit Test with TypeScript and TSTestAdapter

Class to do Unit Test with TypeScript and TSTestAdapter: UnitTest.ts
class Assert
{
    public static AreEqual<T>(expected: T, actual: T, message: string = ""): void
    {
        if (expected !== actual)
        {
            throw "Assert.AreEqual failed. "
                + "Expected: <" + expected + ">. "
                + "Actual: <" + actual + ">. "
                + message;
        }
    }

    public static AreNotEqual<T>(notExpected: T, actual: T, message: string = ""): void
    {
        if (notExpected === actual)
        {
            throw "Assert.AreNotEqual failed. "
                + "Expected any value except: <" + notExpected + ">. "
                + "Actual: <" + actual + ">. "
                + message;
        }
    }

    public static AreNotSame<T>(notExpected: T, actual: T, message: string = ""): void
    {
        if (typeof (notExpected) !== "object"
            || typeof (actual) !== "object")
        {
            throw "Assert.AreSame failed. Do not pass value types to AreSame(). Consider using AreEqual()."
        }

        if (notExpected === actual)
        {
            throw "Assert.AreNotSame failed. " + message;
        }
    }

    public static AreSequenceEqual<T>(expected: T[], actual: T[], equals?: (x, y) => boolean, message: string = ""): void
    {
        if (expected === null || actual === null)
        {
            throw "Assert.AreSequenceEqual failed. Do not pass null values to arrays. " + message;
        }

        if (expected === actual)
        {
            return;
        }

        if (expected.length !== actual.length)
        {
            throw "Assert.AreSequenceEqual failed. Length mismatch. "
                + "Expected: <" + expected.length + ">. "
                + "Actual: <" + actual.length + ">. "
                + message;
        }

        if (!equals)
            equals = (x, y) => x == y;

        for (var i = 0, n = expected.length; i < n; i++)
        {
            if (!equals(expected[i], actual[i]))
            {
                throw "Assert.AreSequenceEqual failed. "
                    + "Expected: <" + expected[i] + ">. Actual: <" + actual[i] + ">."
                    + message;
            }
        }
    }

    public static Fail(message: string = ""): void
    {
        throw "Assert.Fail failed. " + message;
    }

    // TODO: Implementation
    public static Inconclusive(message: string = ""): void
    {
        throw "NotImplementedException";
    }

    public static IsFalse(actual: boolean, message: string = ""): void
    {
        if (actual !== false)
        {
            throw "Assert.IsFalse failed. " + message;
        }
    }

    public static IsInstanceOfType(actual: any, expectedType: Function, message: string = ""): void
    {
        if (!(actual instanceof expectedType))
        {
            var expectedTypeName = /^function\s*([^(]*)/i.exec(expectedType + "")[1].toLocaleLowerCase();
            var actualTypeName = /^function\s*([^(]*)/i.exec(actual.constructor + "")[1].toLocaleLowerCase();

            throw "Assert.IsInstanceOfType failed. "
                + "Expected type: <" + expectedTypeName + ">. "
                + "Actual type: <" + actualTypeName + ">. "
                + message;
        }
    }

    public static IsNotInstanceOfType(actual: any, wrongType: Function, message: string = ""): void
    {
        if (actual instanceof wrongType)
        {
            var wrongTypeName = /^function\s*([^(]*)/i.exec(wrongType + "")[1].toLocaleLowerCase();
            var actualTypeName = /^function\s*([^(]*)/i.exec(actual.constructor + "")[1].toLocaleLowerCase();
            
            throw "Assert.IsNotInstanceOfType failed. "
                + "Expected any type except: <" + wrongTypeName + ">. "
                + "Actual type: <" + actualTypeName + ">. "
                + message;
        }
    }

    public static IsNotNull(actual: boolean, message: string = ""): void
    {
        if (actual === null)
        {
            throw "Assert.IsNotNull failed. " + message;
        }
    }

    public static IsNull(actual: boolean, message: string = ""): void
    {
        if (actual !== null)
        {
            throw "Assert.IsNull failed. " + message;
        }
    }

    public static IsTrue(actual: boolean, message: string = ""): void
    {
        if (actual !== true)
        {
            throw "Assert.IsTrue failed. " + message;
        }
    }

    public static Throws(fn: () => void, message: string = ""): void
    {
        var result = false;

        try
        {
            fn();
        }
        catch (ex)
        {
            result = true;
        }

        if (!result)
            throw "Assert.Throws failed. " + message;
    }
}

;

public by Arslanbekov  1053  1  4  0

My Sublime Text 3 setup.

My Sublime Text 3 setup.: sublime-text-3-setup.md
# Sublime Text 3 Setup

## Install Package Control

Install [Package Control](https://sublime.wbond.net/installation) for easy package management. 

1. Open the console with `` Ctrl+` ``
2. Paste in the following:

````
import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
````

From here on out, use [Package Control](https://sublime.wbond.net/browse) to install **everything**. `⌘`+`Shift`+`P`, then type `Install` to get a list of installable packages you can livesearch through. Watch the Status Bar for installation progress.

## Add Some Style

Install [Soda Theme](http://buymeasoda.github.io/soda-theme/) for some UI customisations. You'll need to restart Sublime after installation for the changes to take effect.

I prefer the classic tab styles and install [the Expresso Soda and Monokai Soda colour schemes](http://buymeasoda.github.com/soda-theme/extras/colour-schemes.zip).

## Add Some Useful Packages

All installed with Package Manager. `⌘`+`Shift`+`P` and type `install`. Then start typing the name of the extension you want to install.

### General 

- [SideBarEnhancements](https://github.com/titoBouzout/SideBarEnhancements/tree/st3) Provides enhancements to the operations on Sidebar of Files and Folders.
- [SublimeCodeIntel](https://sublime.wbond.net/packages/SublimeCodeIntel) - Full-featured code intelligence and smart autocomplete engine.
- [AdvancedNewFile](https://sublime.wbond.net/packages/AdvancedNewFile) - Fast file creation within a project.
- [Nettuts+ Fetch](https://sublime.wbond.net/packages/Nettuts%2B%20Fetch) - Fetch the latest version of remote files and zip packages.
- [Gist](https://sublime.wbond.net/packages/Gist) - Gist management.Create, read, update, and delete gists from within Sublime. 
- [ApplySyntax](Provides a real-time Word Count and character count in the status-bar) - Better syntax detection.
- [Alignment](https://sublime.wbond.net/packages/Alignment) - Easy alignment of multiple selections and multi-line selections.
- [DocBlockr](https://sublime.wbond.net/packages/DocBlockr) - Simplifies writing DocBlock comments in Javascript, PHP, CoffeeScript, Actionscript, C & C++.

### HTML, CSS & JS
- [Emmet](https://sublime.wbond.net/packages/Emmet) - (Formerly Zen Coding) For lightning fast coding.
- [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter3#sublimelinter3) - Coming soon. Code linting & hinting for HTML/CSS/JS.
- [Sass](https://sublime.wbond.net/packages/Sass) - Adds syntax highlighting and tab/code completion for Sass and SCSS files. Also features Emmet shortcuts for many CSS properties.

### Git
- [GitGutter](https://github.com/jisaacks/GitGutter) tracks line changes in the gutter.
- [Modific](https://sublime.wbond.net/packages/Modific) - Highlight lines changed since the last commit.

### Markdown
- [MarkdownEditing](https://sublime.wbond.net/packages/MarkdownEditing) - Better Markdown editing from within Sublime.
- [Markdown Preview](https://sublime.wbond.net/packages/Markdown%20Preview) - Preview and build your markdown files quickly in your web browser from sublime text 2/3.
- [SmartMarkdown](https://sublime.wbond.net/packages/SmartMarkdown) - Some useful shortcuts for working with Markdown in Sublime. Brings better integration with Pandoc.
- [WordCount](https://sublime.wbond.net/packages/WordCount) - Provides a real-time Word Count and character count in the status-bar.

### Laravel 

- [Laravel 4 Facades](https://sublime.wbond.net/packages/Laravel%204%20Facades) - Easy access to the Laravel 4 Facades.

### ExpressionEngine

- [ExpressionEngine Add-on Builder](https://sublime.wbond.net/packages/ExpressionEngine%20Add-On%20Builder) - *(Waiting on ST3 support)* - Quick scaffold for EE addon development.

### Apache Conf

- [ApacheConf](https://sublime.wbond.net/packages/ApacheConf.tmLanguage) - For editing .htaccess and .conf files.

## Add Some Colour

- [Dayle Rees Color Schemes](https://github.com/daylerees/colour-schemes) - A collection of high quality colour schemes.
- [Github Color Theme](https://sublime.wbond.net/packages/Github%20Color%20Theme) - Simple github colour scheme.
- [Solarized Toggle](https://sublime.wbond.net/packages/Solarized%20Toggle) - A very simple plugin that lets you toggle between the dark and light default Solarized colour schemes.

## Settings - User

Accessible via: `SublimeText` &rarr; `Preferences` &rarr; `Settings – User`, or with `⌘`+`,'.'

This is a JSON file of custom user configuration settings. Kept in alphabetical order for easy reference.

**Note:** *As a JSON file no comments can be included. Any you add will be stripped out on saving.*

```json
{
    "auto_complete": true,
    "auto_complete_commit_on_tab": true,
    "auto_complete_with_fields": true,
    "bold_folder_labels": false,
    "color_scheme": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme",
    "default_encoding": "UTF-8",
    "detect_indentation": true,
    "font_face": "Menlo",
    "folder_exclude_patterns":
        [
            ".git",
            ".bundle",
            ".sass-cache"
        ],
    "font_options":
        [
            "subpixel_antialias"
        ],
    "font_size": 12.0,
    "highlight_line": true,
    "highlight_modified_tabs": true,
    "ignored_packages":
        [
            "Vintage"
        ],
    "line_padding_bottom": 1,
    "line_padding_top": 1,
    "soda_classic_tabs": true,
    "soda_folder_icons": false,
    "tab_size": 4,
    "theme": "Soda Light 3.sublime-theme",
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true,
    "word_wrap": true,
}
```

A complete list of Settings can be referenced in `SublimeText` &rarr; `Preferences` &rarr; `Settings – Default`. 

Override any which aren't to your taste.

## Key Bindings - User

Accessible via: `SublimeText` &rarr; `Preferences` &rarr; `Key Bindings – User`. 

Key bindings are the productivity engine which allow you to become one with your text editor. I try to stick with all the defaults to make for an easy install and less chance of potential future clashes. The following are a few small edits I make along with some package specific controls:

```
[
    // Reveal the currently open file in the sidebar
    { "keys": ["ctrl+super+r"], "command": "reveal_in_side_bar" },

    // AdvancedNewFile
    { "keys": ["ctrl+alt+n"], "command": "advanced_new_file_new" },

    // Create a new snippet [Jeffrey Way]
    { "keys": ["alt+super+n"], "command": "new_snippet" },

    // Open iTerm
    { "keys": ["ctrl+alt+t"], "command": "open_terminal" },

    // Select (or type) the syntax to apply to the current view.
    { "keys": ["ctrl+shift+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Set Syntax: "} },

    // swap the keybindings for paste and paste_and_indent
    { "keys": ["super+v"], "command": "paste_and_indent" },
    { "keys": ["super+shift+v"], "command": "paste" },

    // [HTMLPrettify] Format your HTML, CSS, and JS
    { "keys": ["super+shift+h"], "command": "htmlprettify" },

    // Close tag
    { "keys": ["super+."], "command": "close_tag" },

    // Alignment
    { "keys": ["super+shift+a"], "command": "alignment" },

    // Wrap selection in tag
    {
        "keys"      :   ["alt+shift+t"],
        "command"   :   "insert_snippet",
        "args": {
            "contents": "<${1:p}>${0:$SELECTION}</${1}>"
        }
    },

]
```

More info on Key Bindings can be found in the [unofficial docs](http://docs.sublimetext.info/en/latest/reference/key_bindings.html).

## Sublime from the Command Line

Sublime Text includes a command line tool which you just need to symlink up so that it's in your PATH file. In Sublime Text 3 simply copy this into a terminal session:

    ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Then you can open files in Sublime Text from the command line with:

    subl my_file.txt

Replacing `my_file.text` with the name of the file or folder you wish to open in Sublime Text.

## Sublime Text Dropbox Sync

If you switch between Macs at home and work then syncing via Dropbox is a huge time saver. To do this you only need to symlink your `Packages` and `Installed Packages` directories to a location in your Dropbox. Then symlink on the device your setting up to sync with those folders on Dropbox.

**Always make sure you backup your `Packages` and `Installed Packages` folders first - just in case anything goes wrong.**

So, once I have Sublime Text 3 installed on my MacBook Pro, I just need to create a symlink for both my `Packages` and `Installed Packages` directories in my Dropbox folder:

    ln -s ~/Library/Application\ Support/Sublime\ Text\ 3/Packages ~/Dropbox/Sync/Sublime\ Text\ 3/Packages

    ln -s ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages ~/Dropbox/Sync/Sublime\ Text\ 3/Installed\ Packages

Then on my MacBook Air I just need to install Sublime Text 3 (basic install with none of the above) and tell it to look in Dropbox for the Package information:

    ln -s ~/Dropbox/Sync/Sublime\ Text\ 3/Packages ~/Library/Application\ Support/Sublime\ Text\ 3/Packages

    ln -s ~/Dropbox/Sync/Sublime\ Text\ 3/Installed\ Packages ~/Library/Application\ Support/Sublime\ Text\ 3/Installed\ Packages

Now whenever you tweak any settings or install any new packages the changes will be applied to all shared computers.

## Useful Shortcuts

Follow my other gist for useful Sublime Text shortcuts (on a Mac). Commit these to muscle memory and you'll amaze and scare your friends and colleagues with your crazy text editor wizardry. 

## Learn the Basics

Make sure you get familiar with the extremely useful _[Find in Files](http://www.macdrifter.com/2012/07/a-couple-of-sublime-text-tips.html)_ feature along with _[Fuzzy searches](http://docs.sublimetext.info/en/latest/file_management/file_management.html)_.



;

public by Piers Mainwaring  1197  0  4  0

Atom autocomplete suggestions on tab

Atom autocomplete suggestions on tab: tab-completion.coffee
{Point} = require 'atom'

atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
  editor = atom.workspace.getActiveTextEditor()
  cursor = editor.getLastCursor()

  {row, column} = cursor.getBufferPosition()
  precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])

  if /\S/.test(precedingCharacter)
    autocomplete = atom.packages.getActivePackage('autocomplete-plus')
    return unless autocomplete?

    manager = autocomplete.mainModule.activate()
    manager.shouldDisplaySuggestions = true
    manager.findSuggestions(true)
  else
    e.abortKeyBinding()


;