start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| start [2014/03/19 04:32] – [Poor Man's Dependency Injection] stephen | start [2024/08/24 01:22] (current) – [Running with Rubix] stephen | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| 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 ===== | ===== When HTTPS requests always return 404s ===== | ||
| Line 83: | Line 340: | ||
| | West Europe | | West Europe | ||
| + | [[http:// | ||
| + | |||
| + | Just use **Australia East**. | ||
| ===== Unget Files from TFS ===== | ===== Unget Files from TFS ===== | ||
| Line 194: | 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 271: | Line 499: | ||
| <code powershell> | <code powershell> | ||
| - | Get-Item *.jpg | ForEach-Object { convert $_ " | + | Get-Item *.jpg | ForEach-Object { magick |
| </ | </ | ||
| Line 277: | Line 505: | ||
| <code powershell> | <code powershell> | ||
| - | Get-ChildItem ' | + | Get-ChildItem ' |
| </ | </ | ||
| Line 283: | Line 511: | ||
| <code powershell> | <code powershell> | ||
| - | Get-ChildItem | Foreach { convert $_.FullName -quality 98 " | + | Get-ChildItem | Foreach { magick |
| </ | </ | ||
start.1395203551.txt.gz · Last modified: 2017/01/01 19:53 (external edit)
