Skip to content

Instantly share code, notes, and snippets.

View cdoremus's full-sized avatar

Craig Doremus cdoremus

View GitHub Profile
@cdoremus
cdoremus / _middleware.ts
Last active February 17, 2024 16:41
Deno Fresh Middleware for setting a session token
/*
Fresh Middleware for setting a random sesssion token that can be picked up by Fresh route handlers.
Adopted from a Discord post by Chris Knight (@cknight): https://discord.com/channels/684898665143206084/991511118524715139/1202394052604215397
Import map set in deno.json:
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.6.5/",
"$std/": "https://deno.land/std@0.216.0/"
},
*/
@cdoremus
cdoremus / markdown.ts
Created September 19, 2023 21:49
Using markdown with Deno
// from Fresh repo at: https://github.com/denoland/fresh/blob/4a8bfc03278068cffb017ed08d3eb891d7509c37/www/utils/markdown.ts#L13
export * as gfm from "https://deno.land/x/gfm@0.2.5/mod.ts";
import "https://esm.sh/prismjs@1.29.0/components/prism-jsx.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-typescript.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-tsx.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-diff.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-json.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-bash.js?no-check";
import "https://esm.sh/prismjs@1.29.0/components/prism-yaml.js?no-check";
@cdoremus
cdoremus / deno-sass-compile.ts
Created January 4, 2023 23:10
Compiling SASS with Deno
/*
Compiling SASS with Deno
deno run --allow-read="test.scss" --allow-env="SASS_PATH" --unstable "test.ts"```
*/
import SassLang from "npm:sass@latest";
@cdoremus
cdoremus / AllComponents.test.ts
Created May 26, 2022 03:49 — forked from coryhouse/AllComponents.test.ts
Enforce tests exist for each component
// This file assures that a Jest test file and Cypress test file exists for each component.
import path from "path";
import fs from "fs";
function getFiles(filepath: string) {
return fs.readdirSync(filepath).filter(function (file) {
return fs.statSync(path.join(filepath, file)).isFile();
});
}
@cdoremus
cdoremus / fast-check.test.ts
Last active March 23, 2023 18:54
How to use the fast-check property-based testing library with Deno
/**
* Running the fast-check property-based testing library in the Deno
* JavaScript/TYpeScript runtime.
* See: https://github.com/dubzzz/fast-check
*
* This file contains all the 'simple' examples from the fast-check
* repo using Deno.test for the test functions and assertions
* from the Deno standard library. I also added some missing type
* annotations.
*
@cdoremus
cdoremus / json-placeholder-data.d.ts
Last active December 30, 2020 17:52
TypeScript type definitions for the JSON-Placeholder sample data API (see https://jsonplaceholder.typicode.com/).
/**
* TypeScript type definitions for the JSON-Placeholder
* sample data API.
* @see https://jsonplaceholder.typicode.com/
*/
export interface User {
id: number;
name: string;
username: string;
email: string;
@cdoremus
cdoremus / dispatching-action-creators.js
Created June 13, 2017 19:17 — forked from markerikson/dispatching-action-creators.js
Dispatching action creators comparison
// approach 1: define action object in the component
this.props.dispatch({
type : "EDIT_ITEM_ATTRIBUTES",
payload : {
item : {itemID, itemType},
newAttributes : newValue,
}
});
// approach 2: use an action creator function
@cdoremus
cdoremus / dispatching-action-creators.js
Created June 13, 2017 19:17 — forked from markerikson/dispatching-action-creators.js
Dispatching action creators comparison
// approach 1: define action object in the component
this.props.dispatch({
type : "EDIT_ITEM_ATTRIBUTES",
payload : {
item : {itemID, itemType},
newAttributes : newValue,
}
});
// approach 2: use an action creator function
import {action1, action2} from "myActions";
import {bindActionCreators} from "redux";
const mapDispatchToProps(dispatch) => {
return {
manuallyBoundAction : (...args) => dispatch(action1(...args)),
autoBoundAction : bindActionCreators(action2, dispatch),
multipleActionsTogether : bindActionCreators({action1, action2}, dispatch)
}
};
@cdoremus
cdoremus / webdriverjs_localstorage.js
Created March 18, 2017 22:13 — forked from remarkablemark/webdriverjs_localstorage.js
Get and set localStorage with WebDriverJS `executeScript` and `executeAsyncScript`.
'use strict';
/**
* Module dependencies.
*/
const webdriver = require('selenium-webdriver');
/**
* Build driver.
*/