Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivan Tanev VanTanev

View GitHub Profile
View App.tsx
import { XstateInspectLoader } from 'shared/util/XstateInspectLoader'
const App = () => {
<XstateInspectLoader>
// rest of app goes here
</XstateInspectLoader>
}
@VanTanev
VanTanev / preact.config.js
Created Nov 7, 2020
Enable CRA-like environment variable passing in preact-cli
View preact.config.js
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 Jun 29, 2020
Extract static type strings from io-ts definitions
View io-ts-stringify.ts
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 Aug 22, 2019
base husky + prettier + eslintconfig
View .eslintrc.json
{
"extends": [
"react-app",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier",
"prettier/react",
"prettier/@typescript-eslint"
],
"plugins": ["jest"]
View safeFormik.ts
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
A script to convert filenames with Japanese characters to romanized versions
View romanize.sh
#!/usr/bin/env bash
set -eu -o pipefail
# set -x
REMOVE_ORIGINALS=${REMOVE_ORIGINALS="0"}
ROMANIZED_DIR=${ROMANIZED_DIR="romanized"}
mkdir -p "$ROMANIZED_DIR"
View LICENSE
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:
View ruby.2.0.0-setup.sh
#!/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 Dec 22, 2015
Grab some pony gifs
View grab.rb
#!/usr/bin/env ruby
require "optparse"
require "ostruct"
require "nokogiri"
require "uri"
require "open-uri"
require "net/http"
options = OpenStruct.new
View LSA_03_homework_all_open_files_from_proc
#!/bin/bash
# List all opened files using only the /proc fs.
main() {
pids | file_descriptor_folder | xargs ls -l | remove_ls_total_lines | remove_ls_file_attributes | remove_non_files | less
}
pids() {
# we try all pids from 1 to the pid max and echo out the valid ones
for P in $(seq 1 $(cat /proc/sys/kernel/pid_max)); do