Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / TestAssociation.cs
Last active December 15, 2015 00:59
Simple attribute and reporting for what tests are related to which work items (such as PBI's, QA Testcases, Tasks etc.... whatever you want really). Nothing magic, you just mark your test class or method with the attribute and put in the dataz.
void Main()
{
WorkItemReporter.GetTestCoverageReport(typeof(MyTest).Assembly).Dump();
}
// Define other methods and classes here
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class WorkItemAttribute : Attribute
{
public WorkItemAttribute(WorkItemType workItemType, string id)
@RhysC
RhysC / GetInstalledApps.ps1
Created April 7, 2013 01:41
Get all installed apps on current machine
#32 bit path - "hklm:\software\microsoft\windows\currentversion\uninstall"
$regInstallPath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
$installed = gci $regInstallPath |
foreach { gp $_.PSPath } |
select DisplayVersion,InstallDate,ModifyPath,Publisher,UninstallString,Language,DisplayName |
where { ($_.DisplayName -ne $null) -and ($_.DisplayName -ne "") }
@RhysC
RhysC / DateSelector.js
Last active December 18, 2015 04:48
Knockout bindable date selector view model using moment to assist with date parameter and ensuring valid dates are shown. This code only shows valid dates in the date range supplied. Dependencies : knockout, moment
/// <reference path="~/Scripts/ThirdParty/knockout-2.1.0.debug.js" />
/// <reference path="~/Scripts/ThirdParty/moment.js" />
function YearSelector(earliestDate, latestDate) {
var self = this;
self.earliestDate = earliestDate;
self.latestDate = latestDate;
var getYears = function () {
var years = [];
@RhysC
RhysC / SendMessage.cshtml
Created June 12, 2013 00:45
Azure storage queue (not service bus) demo using mvc and worker role
@using (Html.BeginForm())
{
@Html.TextArea("content")
<input type="submit" value="Send it!" />
}
@if (ViewBag.SentMessage != null)
{
public class FakeControllerContext : ControllerContext
{
public FakeControllerContext(IController controller)
: this(controller, null, null, null, null, null, null)
{
}
public FakeControllerContext(IController controller, HttpCookieCollection cookies)
: this(controller, null, null, null, null, cookies, null)
{
@RhysC
RhysC / PollWebsite.ps1
Created July 5, 2013 01:43
Poll URL to see if it is up.
function Poll-Website([string]$uri){
$status = ""
$retryCount = 0;
while($status -ne "OK" -and $retryCount -le 5){
try{
$status = (Invoke-WebRequest -Uri $uri).StatusDescription
Write-Host $status
}
catch
{
@RhysC
RhysC / AnonUsersInAsp.cs
Created July 9, 2013 04:17
Handling Anon users in ASP.Net. You can use the Anon module (include it in your web config and the anon users will get a unique token (cookie) that can be used to track them. On authentication we can handle the event of changing from anon => auth and clear the token http://brockallen.com/2012/04/07/think-twice-about-using-session-state/ http://m…
using System.Web.Mvc;
public class HomeController : Controller
{
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
ViewBag.Message = "User = " + User.Identity.Name;
else
ViewBag.Message = "AnonymousID = " + Request.AnonymousID;
@RhysC
RhysC / gist:6006795
Created July 16, 2013 08:15
Make visual studio command prompt available in powershell : just jam this into your profile (http://stackoverflow.com/questions/2124753/how-i-can-use-powershell-with-the-visual-studio-command-prompt)
#Set environment variables for Visual Studio Command Prompt
pushd 'c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC'
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
write-host "`nVisual Studio 2012 Command Prompt variables set." -ForegroundColor Yellow
@RhysC
RhysC / WarmUpForGithub.ps1
Last active December 22, 2015 03:28
WarmuP equivalent via power shell, using Github. Will take a zip from a given Git-hub location (https://github.com/{OrgOrUserName}/{Project} and pull it down and swap out the old project name for a new project name. You can now push this to a new origin or do what you will.
function Select-UniqueChildrenWithStringPattern {
param($path, $pattern)
Get-ChildItem $path -Recurse -exclude *.exe,*.dll,*.pdb,*.jpg,*.png,*.gif,*.mst,*.msi,*.msm,*.gitignore,*.idx,*.pack,*.suo,*.ico,*.nupkg,*.zip,*.7z |
Select-String -Pattern $pattern |
Where-Object { $_ -ne $null } |
Select-Object Path -Unique
}
function String-ReplaceRecursive {
param($path, $pattern, $replaceValue)
@RhysC
RhysC / ResponseCodesToEnumValues.cs
Created September 19, 2013 03:43
Turn external response codes into an enum - we are suing this for SMS central (see page 28 for an example http://www.smscentral.com.au/wp-content/uploads/SMS-Central-API-Reference-May-2013.pdf)
void Main()
{
//turn response codes into enum values
var things = GetData().Select (x =>{
var id = GetNumberFromStart(x);
var name = ConvertToVariable(x.Replace(id.ToString(),string.Empty));
return string.Format("{0} = {1},",id,name);
} );
things.Dump();
}