Skip to content

Instantly share code, notes, and snippets.

Avatar

Randle csharpforevermore

View GitHub Profile
@csharpforevermore
csharpforevermore / commands.txt
Created Sep 21, 2022
Encoding mp4 videos using FFMPEG
View commands.txt
FFMPEG is used to reduce size of videos and compress
To reduce size
• ffmpeg -i .\inputvideo.mp4 -vcodec libx265 -crf 28 outputvideo.mp4
To compress audio
• ffmpeg -i .\2.mp4 -filter_complex "[0]dynaudnorm[a]" -map 0:v -map "[a]" -map 0:a -c:v copy -c:a:1 copy 3.mp4
@csharpforevermore
csharpforevermore / JsonConvertExtension.cs
Last active Mar 29, 2022
Newtonsoft.Json's JsonConvert TryParse extension method - as per Stack Overflow article https://stackoverflow.com/questions/23906220/deserialize-json-in-a-tryparse-way
View JsonConvertExtension.cs
using Newtonsoft.Json;
public static class JsonConvertHelper
{
public static bool TryParseJson<T>(this string @this, out T result)
{
bool success = true;
var settings = new JsonSerializerSettings
{
Error = (sender, args) => { success = false; args.ErrorContext.Handled = true; },
@csharpforevermore
csharpforevermore / Index.cshtml
Created Sep 26, 2021
Example of JavaScript plugin jQuery connecting to MVC ApiController
View Index.cshtml
@using MyWebAPjQuery.WebAPI.Controllers
<div class="jumbotron">
<h1>ASP.NET jQuery to Web API AJAX call</h1>
<p class="lead">This sentence has a class that denotes it as a lead phrase.</p>
</div>
<div class="row">
<div class="col-md-4">
<h2>My MVC API AJAX Call</h2>
<form id="form1">
Name :- <input type="text" name="name" id="name" value="Chris" />
@csharpforevermore
csharpforevermore / test_connection.ps1
Created Aug 30, 2021
How to test your connection string using Powershell
View test_connection.ps1
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=(local);Database=Sample;Integrated Security=True;"
$conn.Open()
$conn.Close()
@csharpforevermore
csharpforevermore / gist:383c91e37d5ad030c9dae7ae1834d878
Created Aug 30, 2021
How to test your connection string using Powershell
View gist:383c91e37d5ad030c9dae7ae1834d878
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=(local)\SQLEXPRESS;Database=SampleDatabase;Integrated Security=True;"
$conn.Open()
$conn.Close()
@csharpforevermore
csharpforevermore / EnterInteger.cs
Created Aug 28, 2021
User input for an integer
View EnterInteger.cs
int X;
String Result = Console.ReadLine();
while(!Int32.TryParse(Result, out X))
{
Console.WriteLine("Not a valid number, try again.");
Result = Console.ReadLine();
}
@csharpforevermore
csharpforevermore / ClassParser.cs
Created Jul 22, 2021
Lists out the methods of the class Student
View ClassParser.cs
public void GetMethodsUsingReflection()
{
MethodInfo[] methodInfos = typeof(Student).GetMethods();
foreach (MethodInfo methodInfo in methodInfos)
{
Response.Write(Environment.NewLine + methodInfo.Name);
}
}
@csharpforevermore
csharpforevermore / AssertionExamples.cs
Last active Jun 25, 2021
Examples of NUnit and Moq assertions
View AssertionExamples.cs
[SetUp]
public void SetUp()
{
_MockRepository = new MockRepository(MockBehavior.Strict);
_MockLogger = _MockRepository.Create<ILogger<TagController>>();
_MockTagManager = _MockRepository.Create<ITagManager>();
_MockApplicationConfigManager = _MockRepository.Create<IApplicationConfigManager>();
}
View changeindex.js
function detach(element) {
return element.parentElement.removeChild(element);
}
function move(src, dest, isBefore) {
dest.insertAdjacentElement(isBefore ? 'beforebegin' : 'afterend', detach(src));
}
function children(element, selector) {
return element.querySelectorAll(selector);
@csharpforevermore
csharpforevermore / TableToPoco.sql
Created May 20, 2021
Stored Procedure that generates a POCO from SQL
View TableToPoco.sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Chris Randle
-- Create date: 17/02/2021
-- Description: Converts a SQL table into a basic CLR object (a "POCO" or "plain old CLR object")
-- =============================================
ALTER PROCEDURE [dbo].[TableToPoco]