Skip to content

Instantly share code, notes, and snippets.

View sirlancelot's full-sized avatar
🍕
Is life without pizza really living?

Matthew Pietz sirlancelot

🍕
Is life without pizza really living?
View GitHub Profile
@sirlancelot
sirlancelot / fetch-weather.js
Last active October 22, 2024 22:22
Obsidian QuickAdd Macro to fetch the weather from OpenWeatherMap
//@ts-check
/**
* Fetch weather data from OpenWeatherMap API
*
* A free OpenWeatherMap API Key is required and can be entered using the Quick
* Add Macro settings dialog.
*
* You should know how to install and use Quick Add Macros before using this.
* See https://quickadd.obsidian.guide/docs/Choices/MacroChoice
*
@sirlancelot
sirlancelot / rollup.js
Last active February 3, 2022 02:01
Use rollup within Bitburner to bundle scripts before copying them to other servers. https://danielyxie.github.io/bitburner/
import { rollup, VERSION } from "https://cdn.jsdelivr.net/npm/rollup/+esm"
const basePath = (path) => {
const index = path.lastIndexOf("/")
return index != -1 ? path.slice(0, index) : ""
}
/** @param {NS} ns */
const bitburnerResolve = (ns) => ({
name: "BitburnerResolve",
@sirlancelot
sirlancelot / util-monkey-patch-method.js
Last active May 20, 2021 18:02
Monkey Patch Method
/**
* Patch a method on an instance. Returns a function which will undo the patch.
*
* Note: The function signature of the provided override does not match the
* original method. This is by design in order to create a more predictable
* function signature.
*
* @param {{ [x: string]: Function }} instance
* @param {keyof instance} method
* @param {(ctx: any, args: IArguments, original: Function) => any} override
@sirlancelot
sirlancelot / frozen-date.js
Last active August 1, 2024 10:30
Create a "frozen" date object
// Date objects frozen with `Object.freeze()` are still mutable due to the way
// JavaScript stores the internal value. You can create a truly immutable,
// "frozen" date object by wrapping it in a proxy which ignores set* functions.
const noop = () => {}
const dateProxyHandler = {
get(target, prop, receiver) {
if (prop === Symbol.toStringTag) return "Date"
if (typeof prop === "string" && prop.startsWith("set")) return noop
@sirlancelot
sirlancelot / try-handlebars.url
Last active December 12, 2017 23:04
Try Handlebars Bookmarklet. Add this url to your bookmarks bar for a quick-and-dirty Handlebars.js template compiler.
data:text/html;base64,PGh0bWwgbGFuZz0iZW4iPgo8aGVhZD4KCTxtZXRhIGNoYXJzZXQ9IlVURi04Ij4KCTx0aXRsZT5UcnkgSGFuZGxlYmFycy5qczwvdGl0bGU+Cgk8bGluayByZWw9InN0eWxlc2hlZXQiIGhyZWY9Imh0dHBzOi8vY2RuanMuY2xvdWRmbGFyZS5jb20vYWpheC9saWJzL25vcm1hbGl6ZS81LjAuMC9ub3JtYWxpemUubWluLmNzcyI+Cgk8bGluayByZWw9J3N0eWxlc2hlZXQgcHJlZmV0Y2gnIGhyZWY9J2h0dHBzOi8vY2RuanMuY2xvdWRmbGFyZS5jb20vYWpheC9saWJzL3R3aXR0ZXItYm9vdHN0cmFwLzQuMC4wLWJldGEuMi9jc3MvYm9vdHN0cmFwLmNzcyc+Cgk8c3R5bGU+CglodG1sLGJvZHksI2FwcCwucm93IHsgaGVpZ2h0OiAxMDAlOyB9Cglib2R5IHsKCQliYWNrZ3JvdW5kLWNvbG9yOiAjMTExMzExOwoJCWNvbG9yOiAjZmZmZmZmOwoJfQoJLmVkaXRvcnMgPiAuZm9ybS1ncm91cCwKCS5wcmV2aWV3ID4gLmZvcm0tZ3JvdXAgewoJCWRpc3BsYXk6IC13ZWJraXQtYm94OwoJCWRpc3BsYXk6IC1tcy1mbGV4Ym94OwoJCWRpc3BsYXk6IGZsZXg7CgkJLXdlYmtpdC1ib3gtb3JpZW50OiB2ZXJ0aWNhbDsKCQktd2Via2l0LWJveC1kaXJlY3Rpb246IG5vcm1hbDsKCQktbXMtZmxleC1kaXJlY3Rpb246IGNvbHVtbjsKCQlmbGV4LWRpcmVjdGlvbjogY29sdW1uOwoJCW1hcmdpbi1ib3R0b206IDA7Cgl9CgkuZWRpdG9ycyA+IC5mb3JtLWdyb3VwID4gLmFjZV9lZGl0b3IsCgkucHJldmlldyA+IC5mb3JtLWdyb3VwID4gLmFjZV
@sirlancelot
sirlancelot / post-checkout
Last active December 9, 2017 01:04
Git hooks for Node.js
#!/bin/bash
# Warn when `package.json` is changed between checkouts.
PREVIOUS_HEAD=$1
NEW_HEAD=$2
BRANCH_SWITCH=$3
if [ $(git diff $PREVIOUS_HEAD..$NEW_HEAD --name-only -- package.json | wc -l) == "1" ]; then
echo "[post-checkout] \`package.json\` changed, running \`npm install --no-optional\`..."
npm install --no-optional
@sirlancelot
sirlancelot / .eslintrc.js
Last active April 8, 2021 18:59
Starter ESLint config
const IS_PROD = process.env.NODE_ENV === "production"
/** @type {import("prettier").Options} */
const prettierRc = {
arrowParens: "always",
endOfLine: "lf",
quoteProps: "consistent",
semi: false,
trailingComma: "es5",
}
@sirlancelot
sirlancelot / nodeBrowserAdaptor.js
Last active August 29, 2015 14:14
Module definition compatible for use in Node.js & Browser environments.
// Defines a module that works in Node & Browsers
(function(global, factory) {
var mock = { exports: {} }
var local = (typeof module === "object" && module.exports) ? module : mock
factory(local, local.exports)
if (local === mock) global["yourNamespaceHere"] = local.exports
}(this, function(module, exports) {
"use strict";
// Add your work to `exports` or `module.exports`
}))
@sirlancelot
sirlancelot / README.md
Last active April 21, 2017 21:47 — forked from anonymous/zzz.js
An experiment to create named parameters in Javascript.
var createNamedParameters = require("./named-parameters")

var fn = createNamedParameters(["greeting", "person"], function(a, b) {
	console.log(a, b)
})

fn.greeting("hello") // set a
fn.person("world")   // set b
fn() // console.log gets run
@sirlancelot
sirlancelot / README.md
Last active April 21, 2017 21:48
An experiment to create named parameters in Javascript