Skip to content

Instantly share code, notes, and snippets.

@danielroe
danielroe / fromEntries.ts
Created June 1, 2022 12:40
fromEntries typing
type Entries<T extends Readonly<Array<readonly [string, any]>>> = {
[Index in keyof T]: { [K in T[Index][0]]: T[Index][1] }
}[number]
type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
const fromEntries = <T extends Readonly<Array<readonly [string, any]>>>(entries: T): UnionToIntersection<Entries<T>> =>
Object.fromEntries(entries) as any
@danielroe
danielroe / settings.json
Last active May 4, 2024 08:55
VScode settings for a minimal UI
{
// Disable telemetry
"telemetry.telemetryLevel": "off",
// Zen mode
"zenMode.fullScreen": false,
"zenMode.hideTabs": true,
"zenMode.centerLayout": false,
// Theming
"workbench.iconTheme": "city-lights-icons-vsc",
"editor.fontFamily": "Dank Mono",
// ~/.storybook/webpack.config.js
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const webpackConfig = require('../test/webpack.config.nuxt')
/* eslint-enable */
module.exports = ({ config }) => {
return {
...config,
resolve: {
@danielroe
danielroe / onfetch.ts
Created April 26, 2020 21:43
Lifecycle hook for Nuxt fetch
import Vue from 'vue'
import {
getCurrentInstance,
onServerPrefetch,
onBeforeMount,
} from '@vue/composition-api'
import { ComponentInstance } from '@vue/composition-api/dist/component'
import { normalizeError } from '@nuxt/vue-app'
interface Fetch {
/* eslint-disable @typescript-eslint/no-var-requires */
const { Nuxt, Builder } = require('nuxt')
const config = require('./nuxt.config')
/* eslint-enable */
process.env.DEBUG = 'nuxt:*'
const nuxt = new Nuxt({
...config,
dev: false,
@danielroe
danielroe / endpoint.js
Created October 26, 2019 08:33
Now / Nuxt with serverMiddleware as functions
import express from 'express'
const app = express()
app.use(express.json())
app.post('/endpoint', function(req, res) {
try {
// Do stuff
res.status(200).end()
} catch (e) {
import { CookieAttributes } from 'js-cookie'
interface StorageCookieOptions extends CookieAttributes {
cookie: {
prefix: string
options?: StorageCookieOptions
}
}
interface Storage {
setUniversal(key: string, value: any, isJson?: boolean): string
import { Dictionary } from '@nuxt/vue-app'
import sass from 'node-sass'
const sassUtils = require('node-sass-utils')(sass)
const theme: Dictionary<string> = require('../config/colors.js')
const hexToRGBA = (hex: string) => {
if (!/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
return null
}
@danielroe
danielroe / keybase.md
Last active September 19, 2017 22:38

Keybase proof

I hereby claim:

  • I am danielroe on github.
  • I am danielroe (https://keybase.io/danielroe) on keybase.
  • I have a public key ASA3zsMlYBXMV7BLvWJznIHspfIv-nmWhccADD3slFlb9Qo

To claim this, I am signing this object: