This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { renderToStream } from "@react-pdf/renderer"; | |
| import ReactDOMServer from "react-dom/server"; | |
| import { EntryContext, Headers, RemixServer, Request, Response } from "remix"; | |
| import PDF, { loader } from "./pdfs/my-pdf.server"; | |
| async function handlePDFRequest(request: Request, headers: Headers) { | |
| // get the data for the PDF | |
| let response = await loader({ request, context: {}, params: {} }); | |
| // if it's a response return it, this means we redirected | |
| if (response instanceof Response) return response; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint-disable unicorn/prefer-module */ | |
| module.exports = { | |
| root: true, | |
| parser: "@typescript-eslint/parser", | |
| plugins: [ | |
| "@typescript-eslint", | |
| "unicorn", | |
| "import", | |
| "react", | |
| "prettier", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create a session storage instance | |
| let sessionStorage = createCookieSessionStorage(); | |
| // create authenticator instance | |
| let authenticator = new Authenticator<User>( | |
| sessionStorage | |
| ); | |
| // configure the authenticator to use the Auth0 strategy for sign-in | |
| authenticator.use( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { randomBytes } from 'crypto'; | |
| import * as React from 'react'; | |
| import { Request, Session } from 'remix'; | |
| import { parseBody, parseParams } from './parse-body'; | |
| /** | |
| * An error that is thrown when a CSRF token is missing or invalid. | |
| * @example | |
| * throw new InvalidAuthenticityToken("Can't verify CSRF token authenticity."); | |
| * @example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| const FeatureFlags = React.createContext(null); | |
| export function FeatureProvider({ features = null, children }) { | |
| if (features === null || typeof features !== "object") { | |
| throw new TypeError("The features prop must be an object or an array."); | |
| } | |
| return ( | |
| <FeatureFlags.Provider value={features}>{children}</FeatureFlags.Provider> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const messages = { | |
| year: { singular: 'year', plural: 'years', denominator: 365, inSeconds: 31536000 }, | |
| day: { singular: 'day', plural: 'days', denominator: 24, inSeconds: 86400 }, | |
| hour: { singular: 'hour', plural: 'hours', denominator: 60, inSeconds: 3600 }, | |
| minute: { singular: 'minute', plural: 'minutes', denominator: 60, inSeconds: 60 }, | |
| second: { singular: 'second', plural: 'seconds', inSeconds: 1 } | |
| } | |
| function pluralize(value, unit) { | |
| if (value === 1) return messages[unit].singular; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const regEx = /<a.*href=\"(https?\:\/\/gist\.github\.com\/\w*\/\w*)".*>.*<\/a>/gi; | |
| const html = 'hola <a href="https://gist.github.com/sergiodxa/478eb21b6eb27d77e44bdd7d9732a46f" target="_blank" rel="nofollow">https://gist.github.com/sergiodxa/478eb21b6eb27d77e44bdd7d9732a46f</a> mundo'; | |
| const finalHTML = html.replace(regEx, '<script src="$1.js"></script><noscript>Github Gist <a href="$1" target="_blank" rel="nofollow">$1</a></noscript>'); | |
| document.write(finalHTML); | |
| // result | |
| // hola <script src="https://gist.github.com/sergiodxa/478eb21b6eb27d77e44bdd7d9732a46f.js"></script><noscript>Github Gist <a href="https://gist.github.com/sergiodxa/478eb21b6eb27d77e44bdd7d9732a46f" target="_blank" rel="nofollow">https://gist.github.com/sergiodxa/478eb21b6eb27d77e44bdd7d9732a46f</a></noscript> mundo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const vkeys = { | |
| 0: 'unk', | |
| 1: 'mouse1', | |
| 2: 'mouse2', | |
| 3: 'break', | |
| 4: 'mouse3', | |
| 5: 'mouse4', | |
| 6: 'mouse5', | |
| 8: 'backspace', | |
| 9: 'tab', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function asyncThread(fn, ...args) { | |
| if (!window.Worker) throw Promise.reject( | |
| new ReferenceError(`WebWorkers aren't available.`) | |
| ); | |
| const fnWorker = ` | |
| self.onmessage = function(message) { | |
| (${fn.toString()}) | |
| .apply(null, message.data) | |
| .then(result => self.postMessage(result)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function asyncToReact(fn) { | |
| class PromiseComponent extends React.Component { | |
| state = { waiting: true, result: null }; | |
| componentDidMount() { | |
| fn(...this.props.args).then(result => this.setState({ waiting: false, result })); | |
| } | |
| componentDidUpdate() { | |
| fn(...this.props.args).then(result => this.setState({ waiting: false, result })); | |
| } | |
| shouldComponentUpdate(newProps) { |
NewerOlder