Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Erik Ralston eralston

🏠
Working from home
View GitHub Profile
View environment.d.ts
declare global {
namespace NodeJS {
interface ProcessEnv {
DYNAMODB_TABLE: string
SOCOTRA_INSTANCE_HOST_NAME: string
SOCOTRA_API_BASE_URI: string
SOCOTRA_AUTH_USERNAME: string
SOCOTRA_AUTH_PASSWORD: string
}
}
View StorageValues.ts
/**
* Utility class around window.sessionStorage that simplifies access and provides strong-typing
* */
export default class StorageValue<ValueType> {
private key: string;
private storage: Storage;
constructor(key: string, storage: Storage = sessionStorage) {
this.key = key;
@eralston
eralston / axios-sdk.ts
Last active Aug 7, 2020
Example class wrapping an Axios instance to provide a basic REST-based repository pattern
View axios-sdk.ts
// 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[]>
View ExampleDecorator.ts
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,
View Webpack XML Raw Loader.js
// 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 Jul 15, 2020
Jest Cheat Sheet
View JestCheatSheet.js
// 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 Jul 15, 2020
ESLint Cheat Sheet
View ESLintCheatSheet.js
// Learn more about Standard JS: https://standardjs.com/index.html
// package.json
{
...
"scripts": {
"validate:ci": "tsc --noEmit && eslint . --fix",
}
...
"devDependencies": {
@eralston
eralston / AddBindings
Created Aug 27, 2019
Adds assembly redirects to current config file for the project
View AddBindings
Get-Project –All | Add-BindingRedirect
@eralston
eralston / List Indices.sql
Created Jun 14, 2018
A Query for listing all indices in a SQL database with their
View List Indices.sql
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 Jun 14, 2018
A query for asking SQL Server about performance recommendations AKA "Missing Indices"
View Missing Index.sql
-- 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
You can’t perform that action at this time.