start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| start [2013/12/22 20:31] – [How to enable Service Tracing] stephen | start [2024/08/24 01:22] (current) – [Running with Rubix] stephen | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| This is a collection of random stuff I want to record for future reference. Probably not much use to anyone else. | This is a collection of random stuff I want to record for future reference. Probably not much use to anyone else. | ||
| + | ===== .NET Logging Levels ===== | ||
| + | |||
| + | Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6. | ||
| + | |||
| + | ===== Running with Rubix ===== | ||
| + | |||
| + | 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. | ||
| + | |||
| + | ===== Restart Garmin Forerunner 235 ===== | ||
| + | |||
| + | Hold down the ☀️ button for ages. Watch will power off. Press it again to power on. Settings etc. are not lost. | ||
| + | |||
| + | ===== Set Environment Variable in Unit Test ===== | ||
| + | |||
| + | Create a '' | ||
| + | |||
| + | <code xml> | ||
| + | <?xml version=" | ||
| + | <!-- File name extension must be .runsettings --> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <!-- List of environment variables we want to set--> | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Getting Visual Studio to use the file is a bit tricky. Try Test -> Configure Test Settings. You may need the ' | ||
| + | |||
| + | To test, debug and stop at a breakpoint. Run '' | ||
| + | |||
| + | ===== Direct Object Creation with Ninject ===== | ||
| + | |||
| + | This will only work inside an ASP.NET project. | ||
| + | |||
| + | <code c#> | ||
| + | using System.Web.Mvc; | ||
| + | |||
| + | private ILog _log; | ||
| + | private ILog Log => _log ?? (_log = (ILog)DependencyResolver.Current.GetService(typeof(ILog))); | ||
| + | </ | ||
| + | |||
| + | ===== Azure Virtual Machine Windows Activation Problems ===== | ||
| + | |||
| + | Running this worked on my Azure Dev VM: | ||
| + | |||
| + | <code powershell> | ||
| + | ForEach-Object { Invoke-Expression " | ||
| + | </ | ||
| + | |||
| + | More details at [[https:// | ||
| + | |||
| + | ===== Log all TypeScript functions ===== | ||
| + | |||
| + | Search: ''< | ||
| + | |||
| + | Replace: ''< | ||
| + | |||
| + | ===== Stupid Roslyn Error ===== | ||
| + | |||
| + | < | ||
| + | Could not find a part of the path ' | ||
| + | </ | ||
| + | |||
| + | Run this in the Package Manager Console: | ||
| + | < | ||
| + | Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r | ||
| + | </ | ||
| + | |||
| + | ===== Use PowerShellGet behind a corporate proxy ===== | ||
| + | |||
| + | <code powershell> | ||
| + | notepad $PROFILE | ||
| + | </ | ||
| + | |||
| + | Add this to the top: | ||
| + | <code powershell> | ||
| + | [system.net.webrequest]:: | ||
| + | |||
| + | # To use your current Windows account to log on to the proxy: | ||
| + | [system.net.webrequest]:: | ||
| + | |||
| + | # To use a different Windows account: | ||
| + | $Username=" | ||
| + | $Password=" | ||
| + | [system.net.webrequest]:: | ||
| + | |||
| + | [system.net.webrequest]:: | ||
| + | </ | ||
| + | |||
| + | Restart your PowerShell session. Fix up the repository source: | ||
| + | <code powershell> | ||
| + | Register-PSRepository -Default | ||
| + | </ | ||
| + | |||
| + | Check you have a repository: | ||
| + | <code powershell> | ||
| + | Get-PSRepository | ||
| + | </ | ||
| + | |||
| + | Should get '' | ||
| + | |||
| + | |||
| + | ===== Add the IIS Development certificate to the Trusted Root Certificates ===== | ||
| + | |||
| + | - Open MMC. | ||
| + | - Add the Certificates snap-in for ' | ||
| + | - Console Root > Certificates (Local Computer) > Personal > Certificates. | ||
| + | - localhost (IIS Express Development Certificate) > Right click > Copy. | ||
| + | - Console Root > Certificates (Local Computer) > Trusted Root Certification Authorities > Certificates. | ||
| + | - Actions (right panel) > More Actions > Paste | ||
| + | |||
| + | ===== Kill Chrome instances from automated testing ===== | ||
| + | |||
| + | <code powershell> | ||
| + | (Get-WmiObject Win32_Process -Filter "name = ' | ||
| + | </ | ||
| + | |||
| + | And if you want to get rid of the Chrome driver as well (which is always a good idea): | ||
| + | |||
| + | <code powershell> | ||
| + | (Get-WmiObject Win32_Process -Filter "name = ' | ||
| + | </ | ||
| + | |||
| + | ===== Faking DateTime.Now() ===== | ||
| + | |||
| + | <code c#> | ||
| + | using (ShimsContext.Create()) | ||
| + | { | ||
| + | System.Fakes.ShimDateTime.NowGet = () => new DateTime(2019, | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Chrome Dev Tools - Show only bad network requests ===== | ||
| + | |||
| + | Copy and paste the below into the filter. | ||
| + | |||
| + | '' | ||
| + | |||
| + | ===== Unit testing - test a method on a property is executed ===== | ||
| + | |||
| + | Requires the [[https:// | ||
| + | |||
| + | <code c#> | ||
| + | [TestMethod] | ||
| + | public void MealViewModel_Banana_EatMethodIsCalled_DrinkIsNot() | ||
| + | { | ||
| + | IUtensil spoon = new Spoon(); | ||
| + | var mockBanana = new Mock< | ||
| + | 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 | ||
| + | mockBanana.Verify(banana => banana.Drink(It.IsAny< | ||
| + | // Not sure if an interface will work here -------^^^^^^^^ | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Visual Studio can't open CSHTML files ===== | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | Fix it thusly: | ||
| + | |||
| + | - Close Visual Studio. | ||
| + | - Delete everything in '' | ||
| + | - Open Visual Studio. | ||
| + | |||
| + | ===== Append randomness to start of a filename ===== | ||
| + | |||
| + | <code powershell> | ||
| + | Get-ChildItem *.mp3 | ForEach-Object{Rename-Item $_ -NewName " | ||
| + | </ | ||
| + | |||
| + | ===== Why did Windows wake from sleep? ===== | ||
| + | |||
| + | Run this and find out: | ||
| + | |||
| + | < | ||
| + | |||
| + | ===== HTML Sanitation ===== | ||
| + | |||
| + | Add the ' | ||
| + | |||
| + | <code c#> | ||
| + | var input = " | ||
| + | |||
| + | var output = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(input); | ||
| + | // fjkdlsjf < | ||
| + | </ | ||
| + | |||
| + | ===== Setting up a Database User ===== | ||
| + | |||
| + | - [SQL Server Management] Right click the **server**, Properties. | ||
| + | - [SQL Server Management, Server Properties] Security -> Server Authentication -> SQL Server and Windows Authentication mode | ||
| + | - [SQL Server Management, Server Properties] Ok | ||
| + | - [SQL Server Management] Right click (Server) -> Security -> Logins, New Login... | ||
| + | - [SQL Server Management, Login - New] General -> Fill in details. | ||
| + | - [SQL Server Management, Login - New] Server Roles -> public only. | ||
| + | - [SQL Server Management, Login - New] Ok | ||
| + | - [SQL Server Management] Right click (Server) -> Databases -> (Database) -> Security -> Users, New User... | ||
| + | - [SQL Server Management, Database User - New] General -> Fill in details. | ||
| + | - [SQL Server Management, Database User - New] Membership -> Fill in details. | ||
| + | - [SQL Server Management, Database User - New] Ok. | ||
| + | |||
| + | ===== Reading Event Logs with PowerShell ===== | ||
| + | |||
| + | <code powershell> | ||
| + | # Logs that contain ' | ||
| + | Get-EventLog Application -Source M.pad -newest 20 -message " | ||
| + | |||
| + | # Logs that do not contain ' | ||
| + | Get-EventLog Application -Source M.pad -newest 2000 | Where { $_.Message -notmatch ' | ||
| + | </ | ||
| + | |||
| + | ===== Unit Testing Private Methods ===== | ||
| + | |||
| + | Ignoring the argument as to whether a private method //should// be unit tested... | ||
| + | |||
| + | <code c#> | ||
| + | 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(" | ||
| + | |||
| + | PrivateObject bananaTest2 = new PrivateObject(new Banana()); | ||
| + | int result2 = (int)bananaTest2.Invoke(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Enable external web requests (Win8) ===== | ||
| + | |||
| + | - Open ' | ||
| + | - Add an Inbound Rule | ||
| + | - Local port 80 (and 443 if HTTPS is required). | ||
| + | |||
| + | ===== When HTTPS requests always return 404s ===== | ||
| + | |||
| + | - [IIS Manager] Select the //Default Web Site//. | ||
| + | - [IIS Manager] On the right, under Actions, Edit site, select // | ||
| + | - [IIS Manager, Site Bindings] There should be two entries, http & https. Select //https//, select //Edit...// | ||
| + | - [IIS Manager, Edit Site Binding] SSL certificate should be selected (e.g. PKS1684.corp.ps.co.nz). | ||
| + | |||
| + | ===== Poor Man's Dependency Injection ===== | ||
| + | |||
| + | Chris used an abstract base class. The following should be adapted for an interface, if possible. | ||
| + | |||
| + | <code c#> | ||
| + | /* | ||
| + | < | ||
| + | <add key=" | ||
| + | </ | ||
| + | */ | ||
| + | public abstract class DefinitionService | ||
| + | { | ||
| + | public abstract List< | ||
| + | // ... | ||
| + | |||
| + | public static DefinitionService Current | ||
| + | { | ||
| + | get | ||
| + | { | ||
| + | var activeServiceName = WebConfigurationManager.AppSettings[" | ||
| + | if (string.IsNullOrWhiteSpace(activeServiceName)) | ||
| + | throw new ConfigurationErrorsException(" | ||
| + | |||
| + | var serviceType = typeof(DefinitionService).Assembly.GetType(activeServiceName); | ||
| + | if (serviceType == null || !typeof(DefinitionService).IsAssignableFrom(serviceType)) | ||
| + | throw new ConfigurationErrorsException(" | ||
| + | |||
| + | var defaultConstructor = serviceType.GetConstructor(Type.EmptyTypes); | ||
| + | if (defaultConstructor == null) | ||
| + | throw new ConfigurationErrorsException(" | ||
| + | |||
| + | return (DefinitionService)defaultConstructor.Invoke(null); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== How to view LINQ Generated SQL statements ===== | ||
| + | |||
| + | <code c#> | ||
| + | ((System.Data.Objects.ObjectQuery)myQuery).ToTraceString() | ||
| + | </ | ||
| + | |||
| + | Or, if you want an extension method: | ||
| + | |||
| + | <code c#> | ||
| + | public static class IQueryableExtensions | ||
| + | { | ||
| + | public static string ToTraceString< | ||
| + | { | ||
| + | ObjectQuery< | ||
| + | | ||
| + | return oqt == null ? string.Empty : oqt.ToTraceString(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Windows Azure Regional Response Times ===== | ||
| + | |||
| + | ^ 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 | ||
| + | | West Europe | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | Just use **Australia East**. | ||
| + | ===== Unget Files from TFS ===== | ||
| + | |||
| + | - [Visual Studio] Open Source Control Explorer. | ||
| + | - [Visual Studio - Source Control Explorer] Right click the branch or folder to be ungetted. | ||
| + | - [Visual Studio - Source Control Explorer] Select 'Get Specific Version...' | ||
| + | - [Visual Studio - Get dialogue] Type: Changeset. | ||
| + | - [Visual Studio - Get dialogue] Changeset: 1. | ||
| + | - [Visual Studio - Get dialogue] Click Get. Bye bye local files and the branch / folder is updated correctly in the Source Control Explorer. | ||
| + | |||
| + | ===== Caches along a trail ===== | ||
| + | |||
| + | - Open this page in a **new** browser window. | ||
| + | - Setup a [[http:// | ||
| + | - Create a new or reuse an existing [[http:// | ||
| + | - Create a run-once pocket query based on the route. | ||
| + | - Sort the results by favourites and open each in separate browser tab. | ||
| + | - Send each one to c:geo. | ||
| + | - Bookmark the first one and add it to the list. | ||
| + | - Bookmark all the rest. | ||
| + | - Go back to the [[http:// | ||
| + | - Check lots of boxes and Use the " | ||
| + | - Go to [[http:// | ||
| + | - Wait for email. | ||
| + | - Upload attached GPX file to phone. | ||
| + | - Import caches into Locus. | ||
| + | - Use [[http:// | ||
| + | - Create new map and upload GPX file. | ||
| + | |||
| + | To print: | ||
| + | |||
| + | - Open uMap page in Firefox. | ||
| + | - F11 to full screen. | ||
| + | - Ctrl + PrnScn (or whatever it is). | ||
| + | - Open Paint.NET, paste & print. | ||
| + | - Untick 'Fit picture to frame' | ||
| ===== How to enable Service Tracing ===== | ===== How to enable Service Tracing ===== | ||
| Line 83: | Line 454: | ||
| </ | </ | ||
| - | ===== Nuke the Database ===== | ||
| - | |||
| - | Generates SQL commands to drop everything in the database. Be careful you nuke the correct database... | ||
| - | |||
| - | <code sql> | ||
| - | USE [Database] | ||
| - | |||
| - | SELECT 'DROP PROCEDURE ' + [Schema].name + ' | ||
| - | , 10 AS SortOrder | ||
| - | FROM | ||
| - | JOIN | ||
| - | ON | ||
| - | WHERE StoredProcedure.TYPE = ' | ||
| - | UNION | ||
| - | SELECT 'DROP VIEW ' + sys.objects.name | ||
| - | , 20 | ||
| - | FROM | ||
| - | WHERE sys.objects.TYPE = ' | ||
| - | UNION | ||
| - | SELECT 'ALTER TABLE ' + [ParentTable].Name + ' DROP CONSTRAINT [' + [ForeignKey].name + ' | ||
| - | , 30 | ||
| - | FROM | ||
| - | JOIN | ||
| - | ON | ||
| - | WHERE [ForeignKey].TYPE = ' | ||
| - | UNION | ||
| - | SELECT 'DROP TABLE ' + sys.objects.name | ||
| - | , 40 | ||
| - | FROM | ||
| - | WHERE sys.objects.TYPE = ' | ||
| - | ORDER BY SortOrder | ||
| - | </ | ||
| ===== ASP.NET MVC Security Check List ===== | ===== ASP.NET MVC Security Check List ===== | ||
| Line 160: | Line 499: | ||
| <code powershell> | <code powershell> | ||
| - | Get-Item *.jpg | ForEach-Object { convert $_ " | + | Get-Item *.jpg | ForEach-Object { magick |
| </ | </ | ||
| Line 166: | Line 505: | ||
| <code powershell> | <code powershell> | ||
| - | Get-ChildItem ' | + | Get-ChildItem ' |
| + | </ | ||
| + | |||
| + | For canvas prints through pixelpaint.co.nz, | ||
| + | |||
| + | <code powershell> | ||
| + | Get-ChildItem | Foreach { magick convert $_.FullName -quality 98 " | ||
| </ | </ | ||
| + | For any that are still bigger than 15MB, decrease quality and / or size ('' | ||
| ===== Firefox Command Line Parameters ===== | ===== Firefox Command Line Parameters ===== | ||
start.1387744261.txt.gz · Last modified: 2017/01/01 19:53 (external edit)
