Skip to content

Instantly share code, notes, and snippets.

View MorganConrad's full-sized avatar

Morgan Conrad MorganConrad

View GitHub Profile
@MorganConrad
MorganConrad / glob_utils.js
Created March 25, 2024 14:27
Utilities for working with Svelte / Vite globs
/* TODO Must be hard-coded, change to fit your project */
const IMPORT_META_GLOB = import.meta.glob("/src/content/*/*.md");
const CONTENT_DIR = "/src/content"; // TPDP move to a config
const = CONTENT_DIR + "/*/*.md";
const INDEX = "/index.md";
export async function filterGlob(regexOrString) {
let regex = (regexOrString instanceof RegExp) ? regexOrString : new RegExp(regexOrString);
@MorganConrad
MorganConrad / glue.js
Created January 17, 2018 00:06
ES6 Import
import {add, subtract} from './modules/supermath.js';
window.glue = {
doMath :function doSomething1(ida, idb, idop, idresult) {
let a = Number(document.getElementById(ida).value);
let b = Number(document.getElementById(idb).value);
let op = document.getElementById(idop).value;
let result = (op === '+') ? add(a,b) : subtract(a,b);
document.getElementById(idresult).value = result;
@MorganConrad
MorganConrad / mapy.js
Created November 18, 2017 19:54
Treat ordinary object as Map: `keys(), values(), entries())`
function mapy(object, andPrototype, andAssign) {
const _object = object;
let _mapy = {
keys() { return Object.keys(_object); },
values() { return _it(true); },
entries() { return _it(false); }
}
if (andPrototype)
Object.setPrototypeOf(_mapy, object);
package com.flyingspaniel.xen;
import java.util.Arrays;
import java.util.Comparator;
/**
* @author Morgan Conrad
* @see <a href="http://opensource.org/licenses/MIT">This software is released under the MIT License</a>
* @since Copyright (c) 2014 by Morgan Conrad
*/
var Request = require('request/request.js'); // IMPORTANT - specify request.js, don't get index.js!!!
var querystring = require('querystring');
MyRequest.prototype = Object.create(Request.prototype);
MyRequest.prototype.constructor = MyRequest;
function MyRequest(options, callbackfn) {
"use strict";
if (callbackfn)
options.callback = callbackfn;
@MorganConrad
MorganConrad / classical1.js
Created November 15, 2013 17:02
Example of "classical" style JavaScript
module.exports = Foo; // just one line to get all of this code.
// Now how much would you pay?
/** constructor capital first letter to remind callers**/
function Foo(args) {
if (!this instanceof Foo) // but callers do screw up...
return new Foo(args) // or, if you wish, throw something
this.useSoap = args.useSoap ; // define instance vars here