Skip to content

Instantly share code, notes, and snippets.

@craigtp
craigtp / AdvancedDistributedSystemDesignCourseNotes.md
Created May 1, 2020 19:38
Notes on Udi Dahan's Advanced Distributed System Design Course

Advanced Distributed System Design Course - Udi Dahan

Notes by Craig Phillips

Fallacies of Distributed Computing

  • There are 11 fallacies of Distributed Computing:
    1. The network is reliable
    2. Latency isn’t a problem
    3. Bandwidth isn’t a problem
    4. The network is secure
  1. The topology won’t change
@craigtp
craigtp / GetWindowsProductKey.vbs
Created May 30, 2016 18:10
Retrieve Windows Product Key
Option Explicit
Dim objshell,path,DigitalID, Result
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
@craigtp
craigtp / LargestDBs
Last active November 16, 2023 15:41
List the largest databases on a SQL Server instance
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024 SizeMB
FROM sys.master_files
ORDER BY SizeMB DESC
@craigtp
craigtp / SQLRandom.sql
Created February 7, 2013 14:38
SQL Server Random Numbers And Other Things!
-- Create a temporary table in an in-memory variable simply to allow the
-- select statement to output multiple rows.
DECLARE @TestTable TABLE (uniqueID int)
INSERT INTO @TestTable
SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL
SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
-- The main Select statement that shows different correct (and incorrect) ways to generate
-- "random" things in a set-based select statement.
SELECT
@craigtp
craigtp / LineCount.ps1
Last active March 14, 2022 18:24
Count number of non-blank lines in files with PowerShell
(dir -include *.cs -recurse | select-string .).Count
@craigtp
craigtp / CleanUpTemporaryASPNETFiles.ps1
Last active April 7, 2021 22:44
Clean Up Temporary ASP.NET Files with Powershell
# Run this as Administrator
net stop w3svc
Get-ChildItem "C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files" -Recurse | Remove-Item -Recurse -Force
net start w3svc
@craigtp
craigtp / ShortCodes.cs
Last active March 30, 2020 07:32
Short code generator.Converts a long integer to a "short code" (a seemingly random string of characters - as seen on many popular URL Shortener utilities.) and vice-versa.See: http://stackoverflow.com/a/529852/57477
using System;
namespace ShortCodes
{
public static class ShortCodes
{
// You may change the "shortcode_Keyspace" variable to contain as many or as few characters as you
// please. The more characters that are included in the "shortcode_Keyspace" constant, the shorter
// the codes you can produce for a given long.
private static string shortcodeKeyspace = "abcdefghijklmnopqrstuvwxyz0123456789";
@craigtp
craigtp / ProbabilityKata2
Last active May 28, 2019 07:52 — forked from gregoryyoung/ProbabilityKata2
Probability Kata part 2
OK so now you have implemented the kata. Your tests should look something like this:
We can say that the tests define the object "in a calculus of itself".
They are not state based tests, they define how the behaviours of the object interact with each other.
To see the real value of this let's introduce some change ... I hear real system's do this occasionally.
Because this is a high performance system decimal math is too slow. You now need to use floats instead.
Need help on floating point math? Check out: http://www-users.math.umd.edu/~jkolesar/mait613/floating_point_math.pdf
@craigtp
craigtp / ProbabilityKata
Created May 27, 2019 16:57 — forked from gregoryyoung/ProbabilityKata
Greg Young's Probability Kata
Value objects are an important concept in DDD. This kata is made both to learn value objects and to learn better ways of testing.
Write a probability value object. It should contain the following methods:
Probability CombinedWith(Probability)
Probability InverseOf()
Probability Either(Probability)
if you forget your probability math:
Either:P(A) + P(B) - P(A)P(B)
CombinedWith: P(A)P(B)
@craigtp
craigtp / BetterRandom.cs
Last active June 13, 2018 22:51
BetterRandom - A C# class to produce random numbers which inherits from the .NET framework's System.Random class and so can be a drop-in replacement for usages of the standard Random class, but which uses the RNGCryptoServiceProvider to generate better (and cryptographically secure) random numbers.
using System;
using System.Security.Cryptography;
namespace BetterRandomNumbers
{
// BetterRandom.cs
// This class implements a random number generator that is based off the Windows "Next Generation" cryptographically secure
// random number generator. It inherits from the base Random class, so can be used as a "drop-in" replacement for the
// built-in .NET System.Security.Random class, but providing a superior quality of random numbers.
public class BetterRandom : Random, IDisposable