Skip to content

Instantly share code, notes, and snippets.

View timneutkens's full-sized avatar
👋

Tim Neutkens timneutkens

👋
View GitHub Profile
@timneutkens
timneutkens / gist:1c18c1add7151a3b3821bba6e4298bfe
Last active March 18, 2024 13:07
Turbopack rules that output TypeScript
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
experimental: {
turbo: {
rules: {
'./pages/**/*.tsx': {
loaders: [require.resolve('./test-file-loader.js')],
as: '*.tsx'
@timneutkens
timneutkens / gist:252011d8f6fbd141c77157f796a806dd
Created March 18, 2024 13:01
Turbopack rules that output TypeScript
turbo: {
rules: {
'*.mdx': {
loaders: ['turbopack-mdx-loader'],
as: '*.tsx',
},
},
},
@timneutkens
timneutkens / route.js
Created February 17, 2023 08:39
Streaming example
// https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#convert_async_iterator_to_stream
function iteratorToStream(iterator: any) {
return new ReadableStream({
async pull(controller) {
const { value, done } = await iterator.next()
if (done) {
controller.close()
} else {
controller.enqueue(value)
import {useState, useEffect} from 'react'
function useMounted() {
const [isMounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])
return isMounted
}
// const isMounted = useMounted()
require('dotenv').config();
const withCSS = require('@zeit/next-css');
const path = require('path');
const Dotenv = require('dotenv-webpack');
const withImages = require('next-images');
const withTypescript = require('@zeit/next-typescript');
const withOffline = require('next-offline');
const {PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD} = require('next/constants')
const TOP_PATHS = new Set(
readdirSync(join(__dirname, '..', 'pages'))
.map(f => f.replace(/\.js$/, ''))
.concat(['', 'static', '_next'])
)
function topRoutesMiddleware(req, res, goNext) {
const topPath = req.path.split('/', 2)[1]
export default function importScript(src) {
return new Promise((resolve, reject) => {
const loaded = Boolean(document.querySelector(`script[src="${src}"]`))
if (loaded) return resolve()
const script = document.createElement('script')
script.type = 'text/javascript'
script.src = src
script.async = true
import React from 'react'
import PropTypes from 'prop-types'
import { ApolloProvider, getDataFromTree } from 'react-apollo'
import Head from 'next/head'
import initApollo from './initApollo'
// Gets the display name of a JSX component for dev tools
function getComponentDisplayName (Component) {
return Component.displayName || Component.name || 'Unknown'
}
@timneutkens
timneutkens / index.js
Last active September 9, 2017 09:34
Unique array values
const yourArray = [1,2,1,3,3]
Array.from(new Set(yourArray)) // [1,2,3]