Skip to content

Instantly share code, notes, and snippets.

Avatar
😎
🐹 Go 🦀 Rust 📦 Node 🐧 Linux

AJ ONeal coolaj86

😎
🐹 Go 🦀 Rust 📦 Node 🐧 Linux
View GitHub Profile
View intuit-api-quickbooks-pnl.json
{
"Header": {
"Time": "2022-09-14T12:20:17-07:00",
"ReportName": "ProfitAndLoss",
"ReportBasis": "Accrual",
"StartPeriod": "2022-06-01",
"EndPeriod": "2022-09-30",
"SummarizeColumnsBy": "Total",
"Currency": "USD",
"Customer": "1",
View debug-mysql-foreign-key-varchar.sql
SHOW INDEXES FROM `room`;
--ALTER TABLE `room` DROP INDEX room_code_restriction_idx;
--ALTER TABLE `room` DROP INDEX room_user_restriction_idx;
ALTER TABLE `room` DROP FOREIGN KEY room_code_restriction_foreign;
ALTER TABLE `room` DROP FOREIGN KEY room_user_restriction_foreign;
ALTER TABLE `room` DROP COLUMN `code_restriction`;
ALTER TABLE `room` DROP COLUMN `user_restriction`;
View callbacks-semantics.md

JSDoc tsc Function Workaround

There's no documentation for this, but it just so happens that if you use the @callback alias some extra machinery kicks in and you can type functions as you would have expected.

/**
- * @typedef {Function} PersonGreet
+ * @callback PersonGreet
 * @param {String} name - other's name
 * @returns {String} - the greeting
View escape.js
function escapeHtml(str) {
// TODO more
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&lt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;')
;
}
@coolaj86
coolaj86 / js-with-types.js
Last active Aug 31, 2022
AJ's Code Snippets for Thumbnail Backgrounds
View js-with-types.js
// Package-Scoped Types
// Rather than creating class files, you can define types here and annotate them
// elsewhere as needed (including "Declaration Merges" in @types/foo/index.d.ts).
//
// Note:
// - {...} surround types
// - [...] surround optional properties
// - {Record<string, any>} for a untyped object/map/dict
// - {Array<Thing>} for a typed array
View README.md

BogoSort Wins!

The for loop outperforms the binary search.
(well, the forEach did, until we changed the caching in an unrelated function)

And the optimizations have (almost) nothing to do with the algorithms.
(changing any code can massively change the performance of any benchmark)

See the video: https://www.youtube.com/watch?v=0mmi44ZB2C0

View allman-vs-k-r-braces.md

K&R Style

  • Required (but not enforced) for JavaScript
  • Required AND enforced for Go
function kr() {
  // foo
}
View arrow-functions-are-evil.md

Why is this bad?

const something = (params) => value;

TL;DR Because this ISN'T bad

View js-pyramids-of-doom.md

Pyramids of Doom in JavaScript

  • callbacks
  • promises
  • try/catch

solution: await.catch

async function doLotsOfStuff(params) {