Skip to content

Instantly share code, notes, and snippets.

View Marcisbee's full-sized avatar
:octocat:
Current jam: TS, Graphql, Deno, Go

Marcis Bergmanis Marcisbee

:octocat:
Current jam: TS, Graphql, Deno, Go
View GitHub Profile
@jacob-ebey
jacob-ebey / inline-css-middleware.js
Created July 2, 2022 06:41
Inline CSS for Remix express applications
let fs = require("fs");
// TODO: Make it configurable based on publicPath and assetsBuildDirectory
function inlineCssMiddleware() {
/**
*
* @param {import("express").Request} req
* @param {import("express").Response} res
* @param {import("express").NextFunction} next
*/
@DavidWells
DavidWells / javascript-proxy-as-rest-client.js
Last active May 12, 2024 14:24
Using a javascript proxy as low code REST client
/* Using a JavaScript proxy for a super low code REST client */
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3
// also see https://github.com/fastify/manifetch
// also see https://github.com/flash-oss/allserver
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb
const createApi = (url) => {
return new Proxy({}, {
get(target, key) {
@jonathantneal
jonathantneal / command.js
Last active October 26, 2022 07:20
Executable JavaScript Modules
":" //#;exec /usr/bin/env node --input-type=module - $@<$0
import process from 'process'
const { argv } = process
console.log(argv)
<link rel="shortcut icon" width=32px>
<canvas style="display: none" id="loader" width="16" height="16"></canvas>
<script>
class Loader {
constructor(link, canvas) {
this.link = link;
this.canvas = canvas;
this.context = canvas.getContext('2d');
this.context.lineWidth = 2;

assert() (sometimes called invariant())

Instead of checks like:

if (value === null) {
  throw new Error("missing value")
}
doSomethingThatNeedsValue(value)
@webdeb
webdeb / Mailgun.ts
Created November 5, 2020 23:51
Simple deno mailgun client
export default class MailgunClient {
apiKey: string;
domain: string;
defaults?: {
from?: string;
subject?: string;
};
constructor(apiKey: string, domain: string, defaults?: Record<string, any>) {
this.apiKey = apiKey;
@m3g4p0p
m3g4p0p / validate_email.js
Created April 26, 2020 19:30
Test if a string is a valid email address using the constraint validation API
/**
* Test if a string is a valid email address
* using the constraint validation API, rather
* than unwieldy regular expressions
*
* @param {string} value
* @returns {boolean}
*/
const validateEmail = value => Object.assign(
document.createElement('input'),
function setFocusIfFocusable(node) {
if (node.nodeType !== Node.ELEMENT_NODE) {
// Text and comment nodes aren't focusable.
return false;
}
if (node.disabled === true) {
// Disabled elements can't be focused.
return false;
}
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
@sketchpunk
sketchpunk / WebCom.js
Created November 5, 2019 16:52
Web Components and CustomEvents on IE11 with polyfills and plain javascript
//########################################################################################
var WebCom = {};
////////////////////////////////////////////////////////
// Initialize Web Component and Create an Instance
////////////////////////////////////////////////////////
// Need when creating an instance of a Web Component while using the polyfill
WebCom.instance = function( fn, self ){ return (( Object.getPrototypeOf )? Object.getPrototypeOf( fn ) : fn.__proto__).call( self ); }