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[]>
@eralston
eralston / DateFormat.js
Created May 12, 2011 15:52
Date Format 1.2.3 by Steven Levithan <stevenlevithan.com> - A date formatting library for JavaScript
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
@eralston
eralston / NSArray+WeakArray.h
Last active July 5, 2023 09:11
An pair of Objective-C categories on NSArray and NSMutableArray that provides a mechanism for weak referencing any type of Objective-C object. This was created when I found a case, referencing protocols, where NSPointerArray did not work for my needs.
//
// NSMutableArray+WeakArray.h
//
#import <Foundation/Foundation.h>
///
/// Category on NSArray that provides read methods for weak pointers
/// NOTE: These methods may scan the whole array
///
@eralston
eralston / prompt.txt
Created June 22, 2023 14:05
One Prompts to Rule Them All - An AI Chat Prompt to Make AI Chat Prompts
I want you to become my Prompt Creator. Your goal is to help me craft the best possible prompt for my needs. The prompt will be used by you, ChatGPT. You will follow the following process: 1. Your first response will be to ask me what the prompt should be about. I will provide my answer, but we will need to improve it through continual iterations by going through the next steps. 2. Based on my input, you will generate 3 sections. a) Revised prompt (provide your rewritten prompt. it should be clear, concise, and easily understood by you), b) Suggestions (provide suggestions on what details to include in the prompt to improve it), and c) Questions (ask any relevant questions pertaining to what additional information is needed from me to improve the prompt). 3. We will continue this iterative process with me providing additional information to you and you updating the prompt in the Revised prompt section until it's complete.
using Microsoft.Extensions.Logging;
using System;
namespace Masticore
{
/// <summary>
/// Utility class for logging
/// </summary>
public static class LogUtils
{
@eralston
eralston / change-azfun-runtime-version.ps1
Last active January 21, 2023 16:41
Powershell snippets for converting an Azure Function to version 4. Very necessary given the deprecation of version 2.
# Add new settings or configuration changes to Azure Function (Can be done ahead of time):
AzureTranscriptionSettings:Key
AzureTranscriptionSettings:Region = westus
# PowerShell Setup (Can be done ahead of time)
Uninstall-AzureRm
Install-Module -Name Az.Functions -AllowClobber
Install-Module Az.Websites
# Commands to change version
@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 / HttpWebRequestExtensions.cs
Created May 14, 2013 15:44
A simple static class in C# holding extensions for the System.Net.HttpWebRequest class, to make life a little easier when communicating with HTTP interfaces on the web, especially JSON-based REST-style services.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
// Customize this namespace as needed
namespace Utility
{
@eralston
eralston / .bash_profile
Last active August 20, 2021 18:13
Default profile script that adds commands for easy dev workflow
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
alias done="git add . && git commit && git push"
alias nuke="rm -rf node_modules && npm i && npm audit fix"
alias clean="git branch --merged | grep -v \* | xargs git branch -D"
function switch() {
git fetch -pP
git checkout $1
}
@eralston
eralston / Hacks.sh
Created August 19, 2021 22:26
CLI Hacks
# Run only a single description in Jest
npm t -- -t 'can it transact?'