Skip to content

Instantly share code, notes, and snippets.

View dannylloyd's full-sized avatar

Danny Lloyd dannylloyd

  • University of Arkansas for Medical Sciences
  • Cabot, Arkansas
View GitHub Profile
@dannylloyd
dannylloyd / WebcamSettings.ps1
Created January 27, 2021 20:10
Webcam settings screen via FFMPEG
#https://superuser.com/a/1511657/71857
ffmpeg -list_devices true -f dshow -i dummy -hide_banner
#[dshow @ 0000022fd7ac8440] DirectShow video devices (some may be both video and audio devices)
#[dshow @ 0000022fd7ac8440] "USB 2.0 CAMERA"
ffmpeg -f dshow -show_video_device_dialog true -i video="USB 2.0 CAMERA"
@dannylloyd
dannylloyd / HashHMAC.cs
Created July 16, 2020 15:44
Hashes string using salt and returns string
private static string CalcHMACSHA256Hash(string plaintext, string salt)
{
string result = "";
var enc = Encoding.Default;
byte[] baText2BeHashed = enc.GetBytes(plaintext),
baSalt = enc.GetBytes(salt);
System.Security.Cryptography.HMACSHA256 hasher = new HMACSHA256(baSalt);
byte[] baHashedText = hasher.ComputeHash(baText2BeHashed);
result = string.Join("", baHashedText.ToList().Select(b => b.ToString("x2")).ToArray());
return result;
@dannylloyd
dannylloyd / PadRightExtension.cs
Created June 24, 2020 20:53
Padding with string instead of char literal
public static class Extensions
{
public static string PadRight(this string input, int totalWidth, string paddingString){
var rep = string.Concat(Enumerable.Repeat(paddingString, totalWidth-input.Length));
return (input + rep);
}
public static string PadLeft(this string input, int totalWidth, string paddingString){
var rep = string.Concat(Enumerable.Repeat(paddingString, totalWidth-input.Length));
return (rep + input);
}
@dannylloyd
dannylloyd / ExampleFile.bat
Created June 22, 2020 18:50
Generate test file with specified file size
#https://stackoverflow.com/a/46571396/618186
fsutil file createnew [filename].[extension] [# of bytes]
fsutil file createnew asdf.pdf 6234214 #6mb
@dannylloyd
dannylloyd / GetLoggedInUsers.ps1
Created June 10, 2020 20:53
Gets all users logged into a machine
query user /server:computername
$(document).ready(function() {
$.get('https://google.com', function(data) {
console.log(data);
});
});
private bool DateWithinSqlParameters(Event model, DateTime? date, PropertyValidatorContext context)
{
var maxDate = DateTime.Today.AddYears(30);
context.Rule.MessageBuilder = c=> $"Invalid date entered for {context.PropertyDescription}. Must be between 1/1/2000 - {maxDate.ToString("M/d/yyyy")}";
return !date.HasValue || (date.Value >= new DateTime(2000,1,1) && date.Value <= maxDate);
}
#FF353C Dark Salmon, red, highlighting
@dannylloyd
dannylloyd / ffmpeg.txt
Last active January 11, 2021 21:54
ffmpeg commands
#Cut/Edit video
# input file start end output file
#ffmpeg -i inputfilename.mp4 -ss 00:00:03 -t 00:00:08 -async 1 outputfilename.mp4
#Combine videos into single file
# pathToVideos
for f in Videos/*; do echo "file '$f'"; done >> files.txt
./ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp4
rm files.
@dannylloyd
dannylloyd / Write to Excel using EPPLUS.cs
Created May 6, 2019 15:26
Write to Excel using EPPLUS
using (var pck = new OfficeOpenXml.ExcelPackage())
{
var ws = pck.Workbook.Worksheets.Add("Sheet1");
ws.Cells.LoadFromCollection(mrns);
pck.SaveAs(new FileInfo(@"C:\Temp\Output.xlsx"));
}