Skip to content

Instantly share code, notes, and snippets.

View DinkDev's full-sized avatar

Dale Thompson DinkDev

View GitHub Profile
@DinkDev
DinkDev / PSFileTransferByClipboard.ps1
Created October 4, 2021 21:10 — forked from ethzero/PSFileTransferByClipboard.ps1
Transferring binary content by way of clipboard via Powershell
## Powershell method of transfering small (< 1 MB) binary files via Clipboard
##
## NB: Unwise to attempt to encode binary files exceeding 1 MB due to excessive memory consumption
## Powershell 5.0>
# On the transmission end:
$Content = Get-Content -Encoding Byte -Path binaryfile.xxx
[System.Convert]::ToBase64String($Content) | Set-Clipboard
# On the receiving end
@DinkDev
DinkDev / levenshtein_algorithm.lua
Created September 23, 2021 01:59 — forked from Badgerati/levenshtein_algorithm.lua
An implementation of the Levenshtein distance algorithm in LUA.
-- Returns the Levenshtein distance between the two given strings
function string.levenshtein(str1, str2)
local len1 = string.len(str1)
local len2 = string.len(str2)
local matrix = {}
local cost = 0
-- quick cut-offs to save time
if (len1 == 0) then
return len2
@DinkDev
DinkDev / ToStringFromPropertyInfos.cs
Created April 28, 2020 16:18
Use reflection to drive ToString overloading for property bag classes!
public class PropertyBag
{
// assume there are a lot of properties in this class
private PropertyInfo[] PropertyInfos { get; set; }
public override string ToString()
{
if (PropertyInfos == null)
{
@DinkDev
DinkDev / StaticReflection.cs
Last active April 23, 2020 10:59
Methods to reflect on simple LINQ expressions to statically discern property and method names in a compile time safe way!
using System;
using System.Linq.Expressions;
/// <summary>
/// StaticReflection class to parse a properties name from a lambda expression.
/// <see cref="http://joelabrahamsson.com/getting-property-and-method-names-using-static-reflection-in-c/"/>
/// </summary>
public static class StaticReflection
{
public static string GetMemberName<T>(
@DinkDev
DinkDev / AutoMapperLearningTests.cs
Created February 20, 2020 19:44
AutoMapper Dictionary to property bag mapping, with some ExpandoObject utilities.
namespace LearningMoreAutoMapper
{
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using AutoMapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class AutoMapperLearningTests
@DinkDev
DinkDev / t.txt
Created February 20, 2020 14:13
Pluralsight Core Python test file - so it won't be blocked.
It was the best of times
it was the worst of times
it was the age of wisdom
it was the age of foolishness
it was the epoch of belief
it was the epoch of incredulity
it was the season of Light
it was the season of Darkness
it was the spring of hope
it was the winter of despair
@DinkDev
DinkDev / BadToBetterCode_2020_02_04.cs
Created February 4, 2020 14:25
An example of some poor code that could easily be done better.
namespace MessyCode
{
/// <summary>
/// The following issues were created in the BadCode() example:
/// • Casting fsResultG.BoxFolderId which is a Nullable<long> (or better, long?) to long is a problem. Be sure to use the .Value property!
/// • The only thing in the first call that needs to be cast, is the result of the result of Deserialize(), everything else is properly typed.
/// • There is a possibility that fsResultG or fsResultG.BoxFolderId is null, this must be checked before the call since only a long value is accepted – this is a hidden crash error!
/// • Please use the null propagating operators (?? And ?.) It’s silly to write code like:
/// o finalizeData2 == null || finalizeData2.FolderFormList == null || finalizeData2.FolderFormList.Count < 1
/// o ReSharper will fix this for you in most cases.
@DinkDev
DinkDev / ObfuscationByConvolution_2019_01_16.cs
Last active January 16, 2020 13:15
CodingHorror-So many bad practices here: private calling public, exception catching method tailored to a single method, swallowed errors without any logging, poor use of type checking, multiple returns, etc. This could be a simnple method passing a lambda to another. (Gotta love that hidden delegate method call too).
public class derived
{
#region dateTimePicker1_ValueChanged Event
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
ControlBase.Arg1ExceptionLogging(DtpValueChangedAction, sender, "dateTimePicker1_ValueChanged", "Date Picker Button");
}
public void DtpValueChangedAction(object sender)
@DinkDev
DinkDev / AppBootstrapper-Caliburn-Autofac-Serilog-and-dotnet-Core-Loggning.cs
Last active January 27, 2020 18:25
Caliburn with Autofac, Serilog and using .NET Core style ILogger.
namespace Vastec.Ocr.Evaluator.Wpf
{
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Extensions.Logging;
using Autofac;
using Caliburn.Micro;
using Serilog;
using AzureImpl.Parsers;
@DinkDev
DinkDev / Untitled-2
Created January 10, 2020 20:54
CodingHorror-AFewTooManyDependencies.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Atalasoft.Annotate;
using Atalasoft.Imaging.WinControls;