Skip to content

Instantly share code, notes, and snippets.

View michalczukm's full-sized avatar

Michał Michalczuk michalczukm

View GitHub Profile
@michalczukm
michalczukm / merge-objects-with-same-shape.ts
Last active March 25, 2022 08:48
How to type safe merge objects which identical types in TypeScript
type IfEquals<T1, T2, IfEqual = T2, Else = never> = (<
Interim
>() => Interim extends T1 ? true : false) extends <
Interim
>() => Interim extends T2 ? true : false
? IfEqual
: Else;
type Entries<T> = {
[K in keyof T]: [K, T[K]];
@michalczukm
michalczukm / move-exercises-to-ts.sh
Created April 12, 2021 17:07
Moves js exercises files to TS - so now you can do the examples in TS
#!/bin/sh
npm install -D typescript @types/node @types/react @types/react-dom @types/jest
echo "{
"compilerOptions": {
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
@michalczukm
michalczukm / move-to-ts.sh
Created April 12, 2021 14:46
Move the ts files to js, and add ts-nocheck
for f in src/exercise/*.js; do sed -i '' '1s/^/\/\/ @ts-nocheck\'$'\n/g' "$f"; mv -- "$f" "${f%.js}.tsx"; done
@michalczukm
michalczukm / git-pushing-multiple.rst
Created April 10, 2021 14:30 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just

@michalczukm
michalczukm / intersection-observer-example.html
Created May 17, 2020 17:57
Example of Intersection Observer usage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.item {
background: #FFF;
@michalczukm
michalczukm / zipRun.ts
Created September 2, 2019 23:32
Zip run commands - on array elements in same order
const zipRun: <T>(items: T[], commands: Array<(item: T) => unknown>) => void = (items, commands) => {
items.forEach((item, index) => commands[index](item));
}
@michalczukm
michalczukm / .gitignore
Created December 7, 2018 00:08
.NET Core apps minimal .gitignore (including publication settings)
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
@michalczukm
michalczukm / value-types.ts
Last active August 9, 2018 23:20
Example of using values as types - with type assertion
const Foo = {
aFoo: 'SomeAfoo' as 'SomeAfoo',
bFoo: 'SomeBfoo' as 'SomeBfoo',
cFoo: 'SomeCfoo' as 'SomeCfoo',
};
type FooValueTypes = (typeof Foo)[keyof typeof Foo];
function doStuff(value: FooValueTypes) {
}
@michalczukm
michalczukm / extensions.json
Last active July 9, 2018 00:07
VS Code recommended workspace extensions for any Angular project (and not only :) )
{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"angular.ng-template",
"mikael.angular-beastcode",
"msjsdiag.debugger-for-chrome",
"ryu1kn.annotator",