Skip to content

Instantly share code, notes, and snippets.

View matthewrwilton's full-sized avatar

Matthew Wilton matthewrwilton

View GitHub Profile
@matthewrwilton
matthewrwilton / typescript-babel-gulp.js
Last active March 31, 2022 21:46
Compiling ES5 JavaScript via Babel from TypeScript as a gulp task.
var babel = require("gulp-babel"),
glob = require("glob"),
gulp = require("gulp"),
concat = require('gulp-concat'),
sourcemaps = require("gulp-sourcemaps"),
typescript = require("gulp-typescript");
gulp.task("javascript", function () {
var typescriptCompile = gulp.src(["./Scripts/**/*.ts", "./Scripts/typings/**/*.d.ts"])
.pipe(sourcemaps.init())
public async Task<List<Data>> ExecuteQuery(string sql)
{
var results = new List<Data>();
await _querier.ExecuteReaderAsync(sql, async reader =>
{
while (await reader.ReadAsync())
{
results.Add(ReadData(reader));
}
});
public Task ExecuteReaderAsync(string sql, Action<DbDataReader> readAction)
{
...
}
public Task<T> ExecuteReaderAsync<T>(string sql, Func<DbDataReader, T> readAction)
{
...
}
public async Task<T> ExecuteReaderAsync<T>(string sql, Func<DbDataReader, T> readAction)
{
return await _pool.ExecuteAsync(_connectionString, async connection =>
{
using (var command = new OdbcCommand(sql, connection))
{
var dataReader = await command.ExecuteReaderAsync();
return readAction(dataReader);
}
});
public Task<T> ExecuteReaderAsync<T>(string sql, Func<DbDataReader, Task<T>> readAction)
{
...
}
@matthewrwilton
matthewrwilton / partial_web.config
Created June 28, 2016 13:21
Elastic Load Balancer IIS HTTP to HTTPs Redirect
<rule name="HTTP to HTTPs Redirect" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HEADER_X-Forwarded-Proto}" pattern="https" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent"/>
</rule>
[Collection(nameof(WebAppFixture))]
public class _2_Running_A_Web_App
{
/*
* This is a bare minimum example of starting IIS Express to run a web application for testing.
* It uses xUnit collection fixtures to start the web application before running the test.
* Only a single instance of the application is started and is shared between all tests in the collection.
*/
[Fact]
/// <summary>
/// Starts an IIS Express instance to run the ExampleWebApp.
///
/// Code heavily borrowed from Michael Whelan's blog post and Seleno (MIT license).
/// - Michael Whelan's blog post http://www.michael-whelan.net/testing-mvc-application-with-iis-express-webdriver/
/// - Seleno https://github.com/TestStack/TestStack.Seleno
///
/// This is an xUnit fixture class. Refer to https://xunit.github.io/docs/shared-context.html.
/// </summary>
public class WebAppFixture : IDisposable
[CollectionDefinition(nameof(WebAppFixture))]
public class WebAppFixtureTestCollection : ICollectionFixture<WebAppFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}
@matthewrwilton
matthewrwilton / view-compilation-with-AspNetCompiler.csproj
Created March 12, 2017 12:45
Example of AspNetCompiler task usage.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
...
</Project>