This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Subject { | |
hidden [System.Collections.ArrayList]$observers | |
Subject() { | |
$this.observers = New-Object System.Collections.ArrayList | |
} | |
Attach([Observer]$o) { $this.observers.Add($o) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Logger { | |
log($message) { # Define a method called "log" that takes a message as input | |
$message | Out-Host # Output the message to the console | |
} | |
} | |
class TimeStampingLogger : Logger { # Define a class called "TimeStampingLogger" that inherits from "Logger" | |
$logger # Declare a variable called "logger" | |
TimeStampingLogger($logger) { # Define a constructor that takes a "logger" as input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Command { | |
execute() { | |
"[$(get-date)] Logging execute of command [$this]" | Out-Host # Logs the execution of the command | |
} | |
} | |
class Loony : Command { | |
execute() { | |
([Command]$this).execute() # Calls the execute method of the base class (Command) | |
"You're a loony." | Out-Host # Outputs "You're a loony." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CPU { | |
freeze() { "$this freezing" | Out-Host } | |
jump($position) { "$this jump to $position" | Out-Host } | |
execute() { "$this execute" | Out-Host } | |
} | |
class Memory { | |
load($position, $data) { | |
"$this load $position $data" | Out-Host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Define an object that encapsulates how a set of objects interact. | |
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. | |
#> | |
class ChatMediator { | |
$users | |
ChatMediator() { | |
$this.users = New-Object System.Collections.ArrayList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Singleton | |
class Product { | |
$Name | |
Product($name) { | |
$this.Name = $name | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var clientSettings = new MongoClientSettings(); | |
var traceSource = new TraceSource("MongoDB-CMAP-SDAM", SourceLevels.All); | |
traceSource.Listeners.Clear(); // remove the default listener | |
var logFileName = "<should be updated on the real path to a log file>"; | |
var listener = new TextWriterTraceListener(new FileStream(logFileName, FileMode.Append)); | |
listener.TraceOutputOptions = TraceOptions.DateTime; | |
traceSource.Listeners.Add(listener); | |
var eventSubscriber = new TraceSourceEventSubscriber(traceSource); | |
Action<ClusterBuilder> clusterConfigurator = builder => builder.Subscribe(eventSubscriber); // if you don't use a MongoClient as singletone, it's better to share the same instance(so object.ReferenceEquals for them should return true) of this configurator, between all mongo clients | |
clientSettings.ClusterConfigurator = clusterConfigurator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while($true) { cls ; '' ; ps | sort cpu -Descending | select -first 20 | ft -auto; Start-Sleep -Milliseconds 1000 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"background": "#1B1D1E", | |
"black": "#222D3F", | |
"blue": "#3167AC", | |
"brightBlack": "#a4eeb7", | |
"brightBlue": "#3C7DD2", | |
"brightCyan": "#35B387", | |
"brightGreen": "#2D9440", | |
"brightPurple": "#8230A7", | |
"brightRed": "#D4312E", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If $value is not $null or 0 or $false or an empty string | |
if ($null -ne $value -and $value -ne 0 -and $value -ne '' -and $value -ne $false ){ | |
:do | |
} |
NewerOlder