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 Cache<T> where T : someBaseType | |
{ | |
public readonly TimeSpan LifeSpan; | |
public readonly SemaphoreSlim semaphore; | |
private Dictionary<string, CacheItem<T>> itemDict; | |
public Cache(TimeSpan lifespan) | |
{ | |
this.LifeSpan = lifespan; |
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
const int sensorPin = A0; // the number of the pushbutton pin | |
long lastDebounceTime = 0; // the last time the output pin was toggled | |
long debounceDelay = 150; // the debounce time; increase if the output flickers | |
int sensorValue = 0; | |
int alreadyAlerted = 0; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println(F("Serial is working.... ")); |
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
Install-WindowsFeature -Name Ad-Domain-Services -IncludeManagementTools | |
###local admin password.... | |
$pass = ConvertTo-SecureString "XXXXXXXXXX" -AsPlainText -Force | |
Install-ADDSForest -DomainName "MyNewDomain.local" -SafeModeAdministratorPassword $pass |
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
//The idea here is there's a difference between how the event repeats (Repetition) and when that repetition occurs (When/NotWhen). | |
// Between 9am and 6pm, run every 5 minutes, exactly on minute 0,5,10,etc., except on the last day of the month. | |
// Before 9am and after 6pm, run every 10 minutes, exactly on minute 0,10,20, etc, except on the last day of the month. | |
// On the last day of the month, run every 20 minutes, exactly on minute 0,20,40. | |
var config = ScheduleConfig.EveryMinute(5).OnTheMinute(0).When(Between(Hour(9),Hour(18))).WhenNot(DayOfMonth.Last).Named("DayTime") | |
.AddRepetition(Repetition.EveryMinute(10).OnTheMinute(0).When(Before(Hour(9)), After(Hour(18))).WhenNot(DayOfMonth.Last).Named("NightTime") | |
.AddRepetition(Repetition.EveryMinute(20).OnTheMinute(0).When(DayOfMonth.Last).Named("LastDayOfMonth"); | |
var schedule = new Schedule(scheduleConfig); //This could also be IObservable.... |
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 http = require('http'); | |
var url = require("url"); | |
var path = require("path"); | |
var fs = require('fs'); | |
http.createServer(function(req, res) { | |
var uri = url.parse(req.url).pathname; | |
var filename = path.join(process.cwd(), uri); | |
if (fs.existsSync(filename)) { | |
var stats = fs.lstatSync(filename); |
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
using System; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Text; | |
namespace SandboxThing | |
{ | |
class EncryptedString | |
{ | |
private const int AesBlockSize = 128; |
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
$adapter = Get-NetAdapter -Name "Ethernet" | |
$ipv4 = $adapter | Get-NetIPAddress -AddressFamily IPv4 | |
## Remove IPv6 Address and disable IPv6 binding.... | |
$ipv6 = $adapter | Get-NetIPAddress -AddressFamily IPv6 -ErrorAction SilentlyContinue | |
if ($ipv6) { | |
$ipv6 | Remove-NetIPAddress -Confirm:$false | |
} | |
$binding = (Get-NetAdapterBinding | Where-Object { $_.ComponentID -eq "ms_tcpip6" }) |
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
using System.Management.Automation; | |
//.... | |
public static async Task<string> RunPowershellScript(string scriptName, Dictionary<string,string> parameters) | |
{ | |
using (var ps = PowerShell.Create()) | |
{ | |
var script = string.Format(". \"{0}\" {1}", scriptName, string.Join(" ", parameters.Select(p => "-" + p.Key + " '" + p.Value + "'"))); | |
if (debug) | |
{ | |
log.Debug("Running the following script:\r\n " + script); |
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
function Clear-Memcache($server, $port = 11211) | |
{ | |
$msg = [System.Text.Encoding]::ASCII.GetBytes("flush_all`r`nquit`r`n") | |
$c = New-Object System.Net.Sockets.TcpClient($server, $port) | |
$str = $c.GetStream() | |
$str.Write($msg, 0, $msg.Length) | |
$buf = New-Object System.Byte[] 4096 | |
$count = $str.Read($buf, 0, 4096) | |
[System.Text.Encoding]::ASCII.GetString($buf, 0, $count) | |
$str.Close() |
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
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) { | |
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss"); | |
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret); | |
$sha1 = [System.Security.Cryptography.SHA1]::Create(); | |
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign)); | |
$signature = [System.Convert]::ToBase64String($signedBytes); | |
$sha1.Dispose() | |
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature); | |
} |