Skip to content

Instantly share code, notes, and snippets.

@dbl4ck
dbl4ck / ArgumentMessageBuilder.vb
Last active February 26, 2019 23:53
ArgumentMessageBuilder
<System.Reflection.DefaultMember("DefaultReturn")>
Public Class ArgumentMessageBuilder(Of T As Class)
Private Const MESSAGE_SEPARATOR As String = " "
Private Const PROPERTY_SEPARATOR As String = ", "
Private Const PAIR_SEPARATOR As String = "="
Private Const SURROUND As String = "({0})"
Private m_message As String
Private m_object As T
@dbl4ck
dbl4ck / caesarforcer.cs
Last active March 2, 2019 12:19
Caesar Cipher Brute Force
void Main()
{
var encrypted = "VAGREPRCG GNETRG VA FUNATUNV";
char[] alphabet = GenerateUppercaseAlphabet();
for(var adj = (1-alphabet.Length); adj <= (alphabet.Length-1); adj++)
{
var output = "";
encrypted.
@dbl4ck
dbl4ck / LogNation.ps1
Last active March 13, 2019 22:16
Using NLog + Logz.IO in Powershell (using Logzio.DotNet.NLog)
$scriptPath = $MyInvocation.MyCommand.Path
$scriptPath = Split-Path $scriptPath
[Reflection.Assembly]::LoadFile("$scriptPath\NLog.dll") | Out-Null
# Load Logzio.DotNet.NLog and it's dependencies.
[Reflection.Assembly]::LoadFile("$scriptPath\Logzio.DotNet.NLog.dll") | Out-Null
[Reflection.Assembly]::LoadFile("$scriptPath\Logzio.DotNet.Core.dll") | Out-Null
[Reflection.Assembly]::LoadFile("$scriptPath\Newtonsoft.Json.dll") | Out-Null
@dbl4ck
dbl4ck / delete-logs.ps1
Created March 15, 2019 00:09
Recursively Delete Log Files Over N Days Old (Based on LastWriteTime)
$path = "C:\inetpub\logs\LogFiles"
$retentionDays = 10
$filter = "*.log"
$path `
| Get-ChildItem -Recurse -File -Filter $filter `
| ? { ([datetime]$_.LastWriteTime) -lt [System.DateTime]::Now.AddDays(-$retentionDays) } `
| Remove-Item -Force -Verbose
@dbl4ck
dbl4ck / EnumToList.cs
Last active March 16, 2019 13:52
Convert Enum to List (C#)
using System;
using System.Collections.Generic;
namespace XXXXXXX
{
public class EnumToList<T> where T: Enum
{
public List<T> Convert()
{
var list = new List<T>();
@dbl4ck
dbl4ck / Setup SFTP Server
Last active May 29, 2019 19:36
useful raspberry pi commands
sudo apt-get update
sudo apt-get install vsftpd
sudo nano /etc/vsftpd.conf
uncomment/add following lines:
anonymous_enable=NO
local_enable=YES
write_enable=YES
@dbl4ck
dbl4ck / AwesomeSettings.cs
Last active June 4, 2019 21:38
Using Custom Configuration Sections (.net 4.7 c#)
using System.Configuration;
namespace CustomConfigSectionApp
{
public class AwesomeSettings : ConfigurationSection, IAwesomeSettings
{
#region "accessor"
public static AwesomeSettings Settings { get; } =
ConfigurationManager.GetSection(typeof(AwesomeSettings).Name) as AwesomeSettings;
@dbl4ck
dbl4ck / AutomaticVersion.tt
Created January 21, 2020 20:55
Automatic Project Assembly Version T4 Template (C#)
<#@ template language="C#" #>
using System.Reflection;
[assembly: AssemblyVersion("1.0.<#= this.rev #>.<#= this.build #>")]
[assembly: AssemblyFileVersion("1.0.<#= this.rev #>.<#= this.build #>")]
<#+
int rev = (int)(DateTime.UtcNow - new DateTime(2020, 1, 1)).TotalDays;
int build = (int)DateTime.Now.TimeOfDay.TotalMinutes;
#>
@dbl4ck
dbl4ck / Set-ComPlusRSN.ps1
Last active February 5, 2021 13:18
Powershell Script to set the Remote Server Name (RSN) property on a COM+ Application
# Change a COM+ Proxy App Remote Server Name (RSN).
$appName = "<app name>"
$propertyValue = "<server name>"
$propertyName = "ApplicationProxyServerName"
$collectionName = "Applications"
$catalog = New-Object -ComObject COMAdmin.COMAdminCatalog
$collection = $catalog.GetCollection($collectionName)
@dbl4ck
dbl4ck / TrimMean.cs
Created May 10, 2021 12:17
TrimMean example. order values, remove percentage of elements, apply mean
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
public class TrimMean
{
private const string E_PERCENTAGE_OUT_OF_RANGE =
"Percentage argument should be in the range 0.0 - 1.0 (inclusive)";