Skip to content

Instantly share code, notes, and snippets.

View eralston's full-sized avatar
🏠
Working from home

Erik Ralston eralston

🏠
Working from home
View GitHub Profile
@eralston
eralston / axios-sdk.ts
Last active November 11, 2023 19:57
Example class wrapping an Axios instance to provide a basic REST-based repository pattern
// https://www.npmjs.com/package/axios Version 0.19.2
import Axios, { AxiosInstance } from 'axios'
export interface IEntity {
example: string
}
export interface ISdk {
getAllAsync: () => Promise<IEntity[]>
import PublicError from './PublicError';
// Based catch-decorator by Enkot https://github.com/enkot/catch-decorator
// decorator factory function
export default (name: string, message?: string): any => {
return (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor,
// https://webpack.js.org/loaders/raw-loader/
npm install raw-loader --save-dev
// In webpack.config.js
module.exports = {
...
module: {
rules: [
...
@eralston
eralston / JestCheatSheet.js
Last active July 15, 2020 20:11
Jest Cheat Sheet
// package.json
{
...
"scripts": {
"test": "NODE_ENV=test jest --ci --verbose",
},
...
"devDependencies": {
"@types/jest": "^26.0.3",
"babel-jest": "^26.1.0",
@eralston
eralston / ESLintCheatSheet.js
Last active October 3, 2022 16:58
ESLint Cheat Sheet
// Learn more about Standard JS: https://standardjs.com/index.html
// package.json
{
...
"scripts": {
"validate:ci": "tsc --noEmit && eslint . --fix",
}
...
"devDependencies": {
@eralston
eralston / AddBindings
Created August 27, 2019 17:15
Adds assembly redirects to current config file for the project
Get-Project –All | Add-BindingRedirect
@eralston
eralston / List Indices.sql
Created June 14, 2018 16:41
A Query for listing all indices in a SQL database with their
SELECT
TableName = t.name,
IndexName = ind.name,
IndexId = ind.index_id,
ColumnId = ic.index_column_id,
ColumnName = col.name,
ind.*,
ic.*,
col.*
FROM
@eralston
eralston / Missing Index.sql
Last active June 14, 2018 18:03
A query for asking SQL Server about performance recommendations AKA "Missing Indices"
-- Missing Index Script
-- Original Author: Pinal Dave
SELECT TOP 25
dm_mid.database_id AS DatabaseID,
dm_migs.avg_user_impact*(dm_migs.user_seeks+dm_migs.user_scans) Avg_Estimated_Impact,
dm_migs.last_user_seek AS Last_User_Seek,
OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) AS [TableName],
'CREATE INDEX [PERF_' + OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) + '_'
+ REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.equality_columns,''),', ','_'),'[',''),']','')
+ CASE
@eralston
eralston / Initialize.cs
Created November 18, 2016 01:10
Boilerplate for an assembly initialization class to map the datadirectory and reset the local db for unit testing in C# using Entity Framework
[TestClass]
public class Initalize
{
[AssemblyInitialize]
public static void InitializeDbContext(TestContext context)
{
// Connection string in app.config should use LocalDb, EG:
// <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\DefaultConnection.mdf;Initial Catalog=DefaultConnection;Integrated Security=True" providerName="System.Data.SqlClient" />
AppDomain.CurrentDomain.SetData("DataDirectory", context.TestDeploymentDir);
Database.SetInitializer(new DropCreateDatabaseAlways<ApplicationDbContext>());
@eralston
eralston / ControllerExtensions.cs
Last active August 9, 2020 10:40
A set of helpers to enable ASP.Net MVC Controllers to render their views and send them as e-mail
/// <summary>
/// Extension methods for the system MVC controller and related classes
/// </summary>
public static class ControllerExtensions
{
/// <summary>
/// Renders a view to string using the given model
/// </summary>
/// <param name="controller"></param>
/// <param name="viewName"></param>