Skip to content

Instantly share code, notes, and snippets.

View vezaynk's full-sized avatar
🤔

Slava Knyazev vezaynk

🤔
View GitHub Profile
@vezaynk
vezaynk / debug rust vscode.md
Created April 21, 2019 00:05
Simple setup for debugging rust in VSCode

It appears that as of the time of writing this, there is no official rust debugger. Luckily, there are two generic debuggers which seem to do the job alright: GDB, LLDB. Setting up both of them is basically the same process. So far, I had a nicer experience with LLDB so that will be the focus.

There are a few LLDB debuggers available for VSCode. The one I decided to use was CodeLLDB (vadimcn.vscode-lldb), but once again all of them should work almost the same way.

Here is the .vscode/launch.json:

{
    "version": "0.2.0",
 "configurations": [
@vezaynk
vezaynk / useTitle.test.tsx
Last active September 13, 2021 22:57
A useTitle hook for React
/**
* @jest-environment jsdom
*/
import React, { useState } from 'react';
import { renderHook, cleanup } from '@testing-library/react-hooks';
import { act, fireEvent, render } from '@testing-library/react';
import useTitle from './useTitle';
import * as LayoutWrappedElement from ':hyperloop/src/layout/getLayoutWrappedElement';
interface SpacingProps {
__typename: string,
property1: {
__typename: string;
a: 2;
nested: {
__typename: string,
x: 3
}
},
interface StringDigitToNumber {
'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
@vezaynk
vezaynk / MinusOne.ts
Created July 12, 2022 19:11
MinusOne.ts
// Lookup table to seed the counting array
// Skips to length of 10, 100, 1000 instead of counting
// Allows going up to 1998 instead of 999!
// With some work, this technique can be pushed further for higher numbers
interface InitialLengths {
'2': [0, 0, 0, 0, 0,
0, 0, 0, 0, 0],
'3': [...InitialLengths[2], ...InitialLengths[2], ...InitialLengths[2], ...InitialLengths[2], ...InitialLengths[2],
...InitialLengths[2],...InitialLengths[2], ...InitialLengths[2], ...InitialLengths[2], ...InitialLengths[2]],
'4': [...InitialLengths[3], ...InitialLengths[3], ...InitialLengths[3], ...InitialLengths[3], ...InitialLengths[3],
@vezaynk
vezaynk / VueSimple.ts
Created July 13, 2022 03:50
Solution to Simple Vue by Anthony Fu (@antfu) from typescript-challenge
type ToGetter<T> = {
[P in keyof T]: T[P] extends (...args: any) => any ? ReturnType<T[P]> : never;
}
interface VueOptions<D, C, M> {
data: () => D;
computed: C;
methods: M;
}
@vezaynk
vezaynk / .eslintrc
Created August 21, 2022 18:57
My eslint
{
"env": {
"es2021": true,
"jest/globals": true,
"browser": true
},
"extends": [
"airbnb",
"airbnb-typescript",
"airbnb/hooks",
@vezaynk
vezaynk / stats.sh
Created September 29, 2022 16:55
TypeScript adoption over time
#!/bin/bash
# Generate TypeScript adoption data
# Google Docs Spreadsheet:
# https://docs.google.com/spreadsheets/d/13iDFWEhGbE8ZGu1LoXmRINy1ZSLd227mAFj99Evl6fc
# Usage:
# bash ./stats.sh > results.tsv
# Copy paste data into sheet
DATE="2022-07-01" # Tune this file to set start date of adoption
@vezaynk
vezaynk / hocfromhook.tsx
Created December 7, 2022 04:28
Create HOC from Hook
import React, { useContext, createContext } from "react";
function createHOCFromHook<T,>(cb: () => T) {
const Context = createContext<T>(null as T);
const withProvider = <T,>(Component: React.ComponentType<T>) =>
function (props: T & JSX.IntrinsicAttributes) {
return (
<Context.Provider value={cb()}>
<Component {...props} />
</Context.Provider>
@vezaynk
vezaynk / HOC.ts
Created February 1, 2023 23:35
HOC helpers. reduceHOCs and applyHOCs.
interface HOC<T> {
(Component: React.ComponentType<T>): (props: T) => JSX.Element
}
const reduceHOCs = <T>(...hocs: HOC<T>[]): HOC<T> => hocs
.reduce((reduced, next) => (c) => next(reduced(c)));
const applyHOCs = <T>(...hocs: HOC<T>[]) {
const reducedHoc = reduceHOCs(...hocs);