Skip to content

Instantly share code, notes, and snippets.

@VanTanev
VanTanev / README.md
Created May 2, 2023 13:01
A github workflow to track progress of convertion JavaScript to TypeScript.

A github workflow to track the progress of converting JavaScript to TypeScript.

Last year, we migrated a large project form JS to TS. We did this with ts-migrate, and we renamed all instances of any to $TSFixMe, to differentiate them from real uses of any.

Tracking the convertion over time

In order to see our progress on removing $TSFixMe, we build the a github workflow that adds comments to PRs with our progress, eg:

image

import { XstateInspectLoader } from 'shared/util/XstateInspectLoader'
const App = () => {
<XstateInspectLoader>
// rest of app goes here
</XstateInspectLoader>
}
@VanTanev
VanTanev / preact.config.js
Created November 7, 2020 11:09
Enable CRA-like environment variable passing in preact-cli
import webpack from 'webpack'
export default {
/**
* Function that mutates the original webpack config.
* Supports asynchronous changes when a promise is returned (or it's an async function).
*
* @param {object} config - original webpack config.
* @param {object} env - options passed to the CLI.
* @param {WebpackConfigHelpers} helpers - object with useful helpers for working with the webpack config.
@VanTanev
VanTanev / io-ts-stringify.ts
Last active June 29, 2020 11:39
Extract static type strings from io-ts definitions
import * as t from 'io-ts'
import * as gen from 'io-ts-codegen'
import { NullableType } from 'codecs/util/nullable'
export function stringifyNaive(identifier: string, codec: t.Any): string {
return `type ${identifier} = ${codec.name}`
}
export function stringifyFull(identifier: string, codec: t.Any): string {
return `type ${identifier} = ${gen.printStatic(getType(codec))}`
@VanTanev
VanTanev / .eslintrc.json
Last active August 22, 2019 14:32
base husky + prettier + eslintconfig
{
"extends": [
"react-app",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier",
"prettier/react",
"prettier/@typescript-eslint"
],
"plugins": ["jest"]
import fromPairs from 'lodash/fromPairs'
export type SafeForFormik<T extends { [key in string]: any }> = {
safe: { [keyWithoutDots in string]: T['key in string'] }
originalToSafeKeyDict: { [key in string]: string }
safeToOriginalKeyDict: { [keyWithoutDots in string]: string }
getBySafeKey: (data: T, keyWithoutDots: string) => T['key in string']
}
/**
@VanTanev
VanTanev / romanize.sh
Last active May 21, 2019 10:33
A script to convert filenames with Japanese characters to romanized versions
#!/usr/bin/env bash
set -eu -o pipefail
# set -x
REMOVE_ORIGINALS=${REMOVE_ORIGINALS="0"}
ROMANIZED_DIR=${ROMANIZED_DIR="romanized"}
mkdir -p "$ROMANIZED_DIR"
MIT License
Copyright (c) 2017 Ivan Tanev <van.tanev@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
#!/usr/bin/env bash
# required stuff
yum -y groupinstall "Development Tools"
yum -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison
# maybe?
# yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib-devel openssl-devel libyaml-devel readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick
# ruby p353
@VanTanev
VanTanev / grab.rb
Last active December 22, 2015 01:49
Grab some pony gifs
#!/usr/bin/env ruby
require "optparse"
require "ostruct"
require "nokogiri"
require "uri"
require "open-uri"
require "net/http"
options = OpenStruct.new