Skip to content

Instantly share code, notes, and snippets.

View mikebeaton's full-sized avatar

Mike Beaton mikebeaton

View GitHub Profile
@mikebeaton
mikebeaton / XmlCommentsSchemaFilter_Fix960.cs
Last active January 30, 2019 14:53
Stand-alone implementation of Swashbuckle.AspNetCore pull #960 which fixes the formatting of non-string JSON examples. Can be used with existing distributions until the pull makes it into a public release. See https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1021 for instructions.
using System;
using System.ComponentModel;
using System.Xml.XPath;
using System.Reflection;
using System.Linq;
using Microsoft.OpenApi.Any;
using Newtonsoft.Json.Serialization;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.Mvc;
@mikebeaton
mikebeaton / .bashrc
Created March 1, 2019 08:53
.bashrc ssh-agent script for WSL Ubuntu
# Location where ssh-agent settings are persisted
SSH_ENV="$HOME/.ssh/environment"
# Start ssh-agent and persist its settings
function start_agent {
echo "Initializing new SSH agent..."
touch $SSH_ENV
chmod 600 "${SSH_ENV}"
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
@mikebeaton
mikebeaton / fork.bat
Last active April 11, 2024 16:34
Batch file to activate and restore an existing program if it exists, or start a new instance otherwise (in this case, Fork.exe)
@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal
for /f "tokens=2" %%i in ('tasklist /FI "IMAGENAME eq Fork.exe" ^| find /I "Fork.exe"') do set pid=%%i
if "%pid%" == "" (
%localappdata%\Fork\Fork.exe
) else (
cscript //E:JScript //nologo "%~f0" "%~nx0" "%pid%"
)
@mikebeaton
mikebeaton / MightyGist1.cs
Last active September 3, 2019 15:14
Mighty article: Hydrating dynamic objects
var db = new MightyOrm(connectionString);
var smiths = db.Query("SELECT * FROM Employees WHERE FamilyName = @0", "Smith");
foreach (var employee in smiths)
{
Console.WriteLine($"ID={employee.ID} GivenName={employee.GivenName}");
}
@mikebeaton
mikebeaton / MightyGist2.cs
Last active September 3, 2019 15:14
Mighty article: object as input to DB operation
var db = new MightyOrm(tableName: "Employee", primaryKey: "EmployeeID");
db.Update(new {EmployeeID = 42, Salary = 100000});
@mikebeaton
mikebeaton / MightyGist3.cs
Last active September 3, 2019 15:14
Mighty article: Example #3
// use DynamicModel instead of MightyOrm for original Massive code
var db = new MightyOrm(connectionString);
var smiths = db.Query("SELECT * FROM Employees WHERE FamilyName = @0", "Smith");
foreach (var employee in smiths)
{
Console.WriteLine($"ID={employee.ID} GivenName={employee.GivenName}");
}
@mikebeaton
mikebeaton / MightyGist5.cs
Last active September 3, 2019 19:26
Mighty article: Example #4
var db = new MightyOrm<Employee>(connectionString);
// the rest of the previous code sample stays exactly the same,
// though each employee value will now be strongly typed
var smiths = db.Query("SELECT * FROM Employees WHERE FamilyName = @0", "Smith");
foreach (var employee in smiths)
{
Console.WriteLine($"ID={employee.ID} GivenName={employee.GivenName}");
}
@mikebeaton
mikebeaton / MightyGist6.cs
Last active September 3, 2019 15:15
Mighty article: Stored procedure with named, directional arguments
var db = new MightyOrm(connectionSting);
var results = db.ExecuteProcedure("TestSumProc",
inParams: new { a = 1, b = 2 },
outParams: new { c = 0 });
// passes!
Assert.AreEqual(3, results.c);
@mikebeaton
mikebeaton / MightyGist7.cs
Created September 3, 2019 15:05
Mighty article: Stored procedure with typed null parameter
var results = db.ExecuteProcedure("TestProc",
inParams: new { a = 1, b = 2 },
outParams: new { c = (int?)null });
@mikebeaton
mikebeaton / MightyGist8.cs
Created September 3, 2019 15:12
Mighty article: Passing a cursor parameter between calls in Mighty
// passing a cursor parameter between calls in Mighty
var res1 = db.ExecuteWithParams(
"begin open :p_rc for select * from emp " +
"where deptno = 10; end;",
outParams: new { p_rc = new Cursor() },
connection: conn);
db.ExecuteProcedure(
"cursor_in_out.process_cursor",
inParams: new { p_cursor = res1.p_rc },