Welcome to Stephen's wiki. There is lots of really great content here - you just have to search for it.
This is a collection of random stuff I want to record for future reference. Probably not much use to anyone else.
Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6.
Rubix and I did approximately 1,547 runs and covered 16,347kms together. First run was 2015-08-24, last was around 2024-07-24.
Hold down the ☀️ button for ages. Watch will power off. Press it again to power on. Settings etc. are not lost.
Create a something.runsettings
file and put it in the solution directory:
<?xml version="1.0" encoding="utf-8"?> <!-- File name extension must be .runsettings --> <RunSettings> <RunConfiguration> <EnvironmentVariables> <!-- List of environment variables we want to set--> <ENABLE_GOD_MODE>true</ENABLE_GOD_MODE> </EnvironmentVariables> </RunConfiguration> </RunSettings>
Getting Visual Studio to use the file is a bit tricky. Try Test → Configure Test Settings. You may need the 'Select Solution Wide runsettings File'. Eventually the file itself should appear in the menu.
To test, debug and stop at a breakpoint. Run Environment.GetEnvironmentVariables()
in the Immediate Window.
This will only work inside an ASP.NET project.
using System.Web.Mvc; private ILog _log; private ILog Log => _log ?? (_log = (ILog)DependencyResolver.Current.GetService(typeof(ILog)));
Running this worked on my Azure Dev VM:
ForEach-Object { Invoke-Expression "$env:windir\system32\cscript.exe $env:windir\system32\slmgr.vbs /ato" ; start-sleep 5 }
More details at Troubleshoot Azure Windows virtual machine activation problems.
Search: (public|private)( static)?\s*([\w]+)\(.*?\)(:\s*[\w<>]+)?\s*\{
Replace: $0 console.log('Module: $3');
Could not find a part of the path 'C:\Dev\BucketsOfFunds\BucketsOfFunds.Web\bin\roslyn\csc.exe'.
Run this in the Package Manager Console:
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
notepad $PROFILE
Add this to the top:
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://10.104.66.70:80') # To use your current Windows account to log on to the proxy: [system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials # To use a different Windows account: $Username="domain\username" $Password="password" [system.net.webrequest]::defaultwebproxy.credentials = New-Object System.Net.NetworkCredential($Username, $Password) [system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
Restart your PowerShell session. Fix up the repository source:
Register-PSRepository -Default
Check you have a repository:
Get-PSRepository
Should get https://www.powershellgallery.com/api/v2
.
(Get-WmiObject Win32_Process -Filter "name = 'Chrome.exe'" | Where-Object { $_.CommandLine.Contains("--enable-automation") }).Terminate()
And if you want to get rid of the Chrome driver as well (which is always a good idea):
(Get-WmiObject Win32_Process -Filter "name = 'Chrome.exe'" | Where-Object { $_.CommandLine.Contains("--enable-automation") }).Terminate(); (Get-WmiObject Win32_Process -Filter "name = 'chromedriver.exe'").Terminate();
using (ShimsContext.Create()) { System.Fakes.ShimDateTime.NowGet = () => new DateTime(2019, 03, 31); ... }
Copy and paste the below into the filter.
-is:running -status-code:200 -status-code:302 -status-code:204 -status-code:304 -status-code:307
Requires the Moq NuGet package.
[TestMethod] public void MealViewModel_Banana_EatMethodIsCalled_DrinkIsNot() { IUtensil spoon = new Spoon(); var mockBanana = new Mock<BananaViewModel>(); var test = new MealViewModel(); testMeal.Banana = mockBanana.Object; // Calling Eat() on the meal should also call Eat() on the banana. testMeal.Eat(spoon); mockBanana.Verify(banana => banana.Eat (It.IsAny<IUtensil>()), Times.Once, "Banana should be eaten with a utensil."); mockBanana.Verify(banana => banana.Drink(It.IsAny<IUtensil>()), Times.Never, "Banana should not be drunk."); // Not sure if an interface will work here -------^^^^^^^^ }
Fix it thusly:
%LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
Get-ChildItem *.mp3 | ForEach-Object{Rename-Item $_ -NewName "$(Get-Random) $($_.Name).mp3"}
Run this and find out:
powercfg -lastwake
Add the 'AntiXSS' (Microsoft) package from NuGet.
var input = "fjkdlsjf<script></script> <b>klds</b> <a href='fsdfsd.html'>Test</a> <a href='javascript:alert('bugger off')'>HubAdmin</a>"; var output = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(input); // fjkdlsjf <b>klds</b> <a href="fsdfsd.html">Test</a> <a href="">HubAdmin</a>
# Logs that contain 'Sequence contains'. Get-EventLog Application -Source M.pad -newest 20 -message "*Sequence contains*" | Format-Table -autosize -wrap # Logs that do not contain 'FromCommonAuditItem'. Get-EventLog Application -Source M.pad -newest 2000 | Where { $_.Message -notmatch 'FromCommonAuditItem' } | Format-Table -autosize -wrap
Ignoring the argument as to whether a private method should be unit tested…
using Microsoft.VisualStudio.TestTools.UnitTesting; public class Banana { private int _count; private static int Add(int n1, int n2) { return n1 + n2; } private int Inc() { _count = Add(_count, 2); return _count; } } class Program { static void Main(string[] args) { PrivateType bananaTest1 = new PrivateType(typeof(Banana)); int result1 = (int)bananaTest1.InvokeStatic("Add", 12, 34); PrivateObject bananaTest2 = new PrivateObject(new Banana()); int result2 = (int)bananaTest2.Invoke("Inc"); } }
Chris used an abstract base class. The following should be adapted for an interface, if possible.
/* <appSettings> <add key="definitionService" value="EA.ReportingPortal.Services.DbDefinitionService" /> </appSettings> */ public abstract class DefinitionService { public abstract List<CategoryTag> GetAllCategories(); // ... public static DefinitionService Current { get { var activeServiceName = WebConfigurationManager.AppSettings["DefinitionService"]; if (string.IsNullOrWhiteSpace(activeServiceName)) throw new ConfigurationErrorsException("Definition Service type not specified or blank"); var serviceType = typeof(DefinitionService).Assembly.GetType(activeServiceName); if (serviceType == null || !typeof(DefinitionService).IsAssignableFrom(serviceType)) throw new ConfigurationErrorsException("Definition Service type does not exist or does not inherit from DefinitionService"); var defaultConstructor = serviceType.GetConstructor(Type.EmptyTypes); if (defaultConstructor == null) throw new ConfigurationErrorsException("Definition Service type does not have an empty constructor"); return (DefinitionService)defaultConstructor.Invoke(null); } } }
((System.Data.Objects.ObjectQuery)myQuery).ToTraceString()
Or, if you want an extension method:
public static class IQueryableExtensions { public static string ToTraceString<T>(this IQueryable<T> t) { ObjectQuery<T> oqt = t as ObjectQuery<T>; return oqt == null ? string.Empty : oqt.ToTraceString(); } }
Region | Free | Standard | ||
---|---|---|---|---|
Mean | StdDev | Mean | StdDev | |
West US | 160.03 | 23.97 | 155.72 | 12.17 |
East Asia | 163.13 | 22.12 | 159.67 | 13.76 |
North Central US | 205.12 | 11.56 | 207.13 | 15.07 |
East US | 212.42 | 9.47 | 213.05 | 12.15 |
North Europe | 293.83 | 16.72 | 287.96 | 14.76 |
West Europe | 307.37 | 45.31 | 296.47 | 11.05 |
Just use Australia East.
To print:
[DataType(DataType.Date)] [DisplayName("Start date")] [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] [Date(ErrorMessage = "Please enter a start date")] public DateTime StartDate { get; set; }
Visual Studio can sometimes get a bit confused about which TFS workspaces exist and which don't. Sort it out with the Visual Studio Command Prompt.
Figure out what workspaces really exist:
tf workspaces /collection:sourcecontrol.company.co.nz\DefaultCollection
Well and truly delete the motherfucker:
tf workspace /delete workspacename
If tf
starts complaining about “Unable to determine the source control server”, try running the first command again (it seems to magically fix shit up or something):
tf workspaces /collection:sourcecontrol.company.co.nz\DefaultCollection
Library | Conceptual Density | Googles/Hour | Scaling Pain¹ | Rob's Choice |
---|---|---|---|---|
Knockout | Fairly Low | 6 - 8 | 20, 25, 50, 90 | 80% of the time |
Backbone | High | 25 - 30 | 50, 30, 20, 20 | |
Angular | Medium/ High | 10 - 20 | 10, 20, 70, 90 | Simple JS App |
Ember | Extreme | *² | 90, 25, 20, 10 | Big JS App |
¹ Simple, Moderate, Advanced, Enterprise
² Gave up googling, api changes often, lots of out-of-date info on web.
<div @(item.Selected ? string.Empty : "style=display:none")></div>
Note that Razor is quite fussy about the format of the style=display:none
bit. No spaces.
A less nice method that also works is:
<div class="notch" @(Html.Raw(item.Selected ? string.Empty : "style=\"display: none;\""))></div>
On Windows 7 and above:
Steps
or PSR
.NuGet.Tools.vsix
(look for it at nuget.org)NuGet.Tools.vsix
file to install the new version.Search the application event log on the local machine:
LogParser.exe -i:evt -rtp:-1 "SELECT TOP 100 * FROM Application WHERE SourceName like '%Reporting%'" > d:\Temp\Output.txt
Search the standard three event logs on the local machine:
LogParser.exe -i:evt -rtp:-1 "SELECT TOP 100 * FROM System, Application, Security WHERE SourceName like '%Reporting%'" > d:\Temp\Output.txt
Search the application event log on a remote machine (may take a while):
LogParser.exe -i:evt -rtp:-1 "SELECT TOP 100 * FROM \\MachineName\Application WHERE SourceName like '%Reporting%'" > d:\Temp\Output.txt
The -rtp:-1
option suppresses the “Press a key…” prompt.
In a Powershell console:
Get-Item *.jpg | ForEach-Object { magick convert $_ "$($_.basename).png" }
This also works:
Get-ChildItem 'C:\External Drives\Primary Media 2\My Pictures\Fractals\FA (Dual Monitor Wallpaper)' | Foreach { magick convert $_.FullName -resize 3840x1080! -quality 99 $_.Name }
For canvas prints through pixelpaint.co.nz, use 8E series images and convert to JPEG, < 15MB. Copy images from C:\External Drives\Primary Media 2\My Pictures\Fractals\8E (Printing)
to a temp directory. Run this:
Get-ChildItem | Foreach { magick convert $_.FullName -quality 98 "$($_.basename).jpg" }
For any that are still bigger than 15MB, decrease quality and / or size (-resize 80%%
).
-ProfileManager | Starts Firefox with the Firefox Profile Manager. |
-P “Profile Name” | Starts Firefox using the specified profile. |
-safe-mode | Starts Firefox in “Safe Mode” - useful when extensions go awry. |
-no-remote | Permits multiple instances of Firefox using separate profiles. |
about:config
in the address bar.network.automatic-ntlm-auth.trusted-uris
.http://intranet.company.com,http://email.company.lan
How do I fix the following error:
‘dropdownlist1′ has a SelectedValue which is invalid because it does not exist in the list of items
SelectedValue='<%# Bind("LocationId") %>'
Protected Sub EmployeeDetailsFormView_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles EmployeeDetailsFormView.PreRender If EmployeeDetailsFormView.CurrentMode = FormViewMode.Edit Then Dim Location_DropDownList As DropDownList = CType(EmployeeDetailsFormView.FindControl("Location_DropDownList"), DropDownList) Dim rowView As DataRowView = CType(EmployeeDetailsFormView.DataItem, DataRowView) If IsNothing(rowView) Then Return ' Or perhaps throw an exception. Dim locationId As String = rowView("LocationId").ToString() If Not IsNothing(Location_DropDownList.Items.FindByValue(locationId)) Then Location_DropDownList.SelectedValue = locationId Else ' TODO: Set the value to whatever it should be if there is no match. Location_DropDownList.SelectedValue = "0" End If End If End Sub
Protected Sub EmployeeDetailsFormView_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs) Handles EmployeeDetailsFormView.ItemUpdating Dim Location_DropDownList As DropDownList = CType(EmployeeDetailsFormView.FindControl("Location_DropDownList"), DropDownList) e.NewValues("LocationId") = Location_DropDownList.SelectedValue End Sub
…and maintaining version history.
C:\Temp\SuperApp\trunk
C:\Temp\SuperApp\trunk\SuperApp.sln
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "SuperApp.Web", "SuperApp.Web", "{C92B633A-C441-4FB6-904B-EEA604BAAF15}" ProjectSection(WebsiteProperties) = preProject ... ProjectReferences = "{0A231AD6-AF0C-45C1-B441-2AB97BC40975}|SuperApp.DataAccess.dll;{96DC8217-C24D-4851-B4C2-92FBE60727CC}|SuperApp.Business.dll;" ... EndProjectSection EndProject
SuperApp.DataAccess.dll
and SuperApp.Business.dll
.Project
to EndProject
inclusive) and save.C:\Temp\SuperApp\trunk\SuperApp.Web
C:\Dev\SuperApp\trunk
→ C:\Dev\SuperApp\branches\Converting to Web App
C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.sln
C:\Temp\SuperApp\trunk\SuperApp.Web\Properties
→ C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.Web
C:\Temp\SuperApp\trunk\SuperApp.Web\My Project
→ C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.Web
C:\Temp\SuperApp\trunk\SuperApp.Web\SuperApp.Web.csproj
→ C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.Web
C:\Temp\SuperApp\trunk\SuperApp.Web\Web.Debug.config
→ C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.Web
C:\Temp\SuperApp\trunk\SuperApp.Web\Web.Release.config
→ C:\Temp\SuperApp\branches\Converting to Web App\SuperApp.Web
C:\Dev\SuperApp\branches\Converting to Web App\SuperApp.Web\Web.config
C:\Temp\SuperApp\trunk\SuperApp.Web\Web.config
ASPX
file and select Convert To Web Application.<script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(".CollapsibleTrigger").click(function (event) { $(this).next().toggle(); if ($(this).next().is(':visible')) $(this).addClass('Expanded'); else $(this).removeClass('Expanded'); }); }); </script>
<asp:ListView ID="Foo_ListView" runat="server" DataSourceID="Foo_Logic" DataKeyNames="FooID" > <LayoutTemplate> <table class="DataWebControlStyle" cellspacing="0" cellpadding="2" border="1"> <tr class="GridHeader"> <th>Blah</th> ... </tr> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </table> <asp:DataPager runat="server" ID="ContactsDataPager" PageSize="50"> <Fields> <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="true" FirstPageText="|<< " LastPageText=" >>|" NextPageText=" > " PreviousPageText=" < " /> </Fields> </asp:DataPager> </LayoutTemplate> <ItemTemplate> <tr class='<%# String.Format("{0} CollapsibleTrigger", Me.AlternatingGridRowClass()) %>'> <td><asp:Label ID="Foo_Label" runat="server" Text='<%# Eval("Foo") %>' /></td> ... </tr> <tr class="CollapsibleRegion" style="Display: none;"> <td><asp:Label ID="Bar_Label" runat="server" Text='<%# Eval("Bar") %>' /></td> ... </tr> </ItemTemplate> </asp:ListView>
Private _alternateRow As Boolean Protected ReadOnly Property AlternatingGridRowClass() As String Get _alternateRow = Not _alternateRow Return If(_alternateRow, "GridAlternatingRow", "GridRow") End Get End Property
Protected Sub Foo_ObjectDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) _ Handles Foo_ObjectDataSource.Updating Dim iod As IOrderedDictionary = e.InputParameters For Each de As DictionaryEntry In iod System.Diagnostics.debug.print(de.Key & "=" & de.Value) Next End Sub
ASP.NET's UpdatePanel will not work if xhtmlConformance mode is set to Legacy in the Web.config
file:
<xhtmlConformance mode="Legacy" />
Take it out of the Web.config
file - it almost certainly does not need to be in there.
With administrator privileges, edit the C:\Program Files (x86)\VideoLAN\VLC\lua\http\.hosts
file, and set it to:
::/0 0.0.0.0/0
This will probably need to be done every time a new version of VLC is installed.
Probably caused by the Web.config
file. Remove the following, if they exist:
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
Removing these from the Web.config
doesn't seem to matter, but if it does, try adding the relevant DLL files and see if that fixes the problem.