Skip to content

Instantly share code, notes, and snippets.

@tmatz
tmatz / UnionDestructurable.ts
Created January 24, 2024 07:58
Make union a type that allows destructuring assignment
/**
* Make union a type that allows destructuring assignment
* @example
* ```
* const props: { a: number } | { b: string } = ...
* const { a, b } = props as UnionDestructurable<typeof props>
* ```
*/
type UnionDestructurable<
Union,
@tmatz
tmatz / vite.config.ts
Created September 28, 2022 06:32
server.proxy via http_proxy with vite.js
import react from '@vitejs/plugin-react'
import ProxyAgent from 'proxy-agent'
import { defineConfig } from 'vite'
// https://vitejs.dev/config/
export default defineConfig({
server: {
open: true,
proxy: {
'/api/': {
@tmatz
tmatz / MergedUnion.ts
Last active January 24, 2024 07:53
toMergedUnion for deconstructing a discriminated union
type UnionAllKeys<U> = U extends infer T ? keyof T : never
type UnionCommonKeys<U> = keyof U
type UnionPartialKeys<U> = Exclude<UnionAllKeys<U>, UnionCommonKeys<U>>
type UnionPartialProperty<U, Key extends string> =
U extends infer T
? Key extends keyof T
? T[Key]
: never
: never
@tmatz
tmatz / CustomError.js
Last active August 20, 2022 16:01
javascript CustomError
export class CustomError extends Error {
get name() {
return this.constructor.name
}
}
@tmatz
tmatz / README.md
Last active March 10, 2021 13:17
Develop application using AIDE and install from Linux on Chromebook(arm64)

Develop Android application on Chromebook(arm64)

  • Build android application using AIDE on Android.
  • Launch 'Install APK' app whick is in Linux folder on desktop.

Setup

  • Enable ADB Debug of Linux.
  • Copy install-apk file into /usr/local/bin/, and exec sudo chmod +x /usr/local/bin/install-apk.
  • Copy install-apk.desktop file into /usr/shere/applications/, and exec sudo update-desktop-database.
@tmatz
tmatz / type_guard.ts
Created December 24, 2020 15:42
typescript type guard
interface A {
a: string
}
interface B extends A {
b: string
}
const isB = <T>(v: T):
v is (T & B) => 'b' in v
@tmatz
tmatz / editorconfig.vim
Created April 15, 2020 16:19
coc.nvim custom source for .editorconfig (put in ~/.vim/autoload/coc/source/)
function! coc#source#editorconfig#init() abort
return {
\ filetypes: [ 'editorconfig' ]
\}
endfunction
function! coc#source#editorconfig#complete(opt, cb) abort
let items = [
\ 'charset',
\ 'end_of_line',
using EnvDTE;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using Task = System.Threading.Tasks.Task;
@tmatz
tmatz / VSIXErrorListPackage.cs
Last active April 6, 2020 12:38
Show item in ErrorList: visual studio extension sample described at https://vsxexperience.net/2010/03/23/writing-to-the-vs-errorlist/
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using Tasks = System.Threading.Tasks;
namespace VSIXProject1
<!DOCTYPE html>
<html>
<head>
<title>single html react app</title>
<script crossorigin src='https://unpkg.com/react/umd/react.development.js'></script>
<script crossorigin src='https://unpkg.com/react-dom/umd/react-dom.development.js'></script>
<script crossorigin src='https://unpkg.com/@babel/standalone/babel.min.js'></script>
</head>
<body>
<div id='root'></div>