Skip to content

Instantly share code, notes, and snippets.

🐹 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
--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`;

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 / 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

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:


K&R Style

  • Required (but not enforced) for JavaScript
  • Required AND enforced for Go
function kr() {
  // foo

Why is this bad?

const something = (params) => value;

TL;DR Because this ISN'T bad


Pyramids of Doom in JavaScript

  • callbacks
  • promises
  • try/catch

solution: await.catch

async function doLotsOfStuff(params) {