Skip to content

Instantly share code, notes, and snippets.

View andreidmt's full-sized avatar
🖖

Andrei Dumitrescu andreidmt

🖖
View GitHub Profile
@andreidmt
andreidmt / matchObjects.md
Created December 29, 2022 13:21
chatgpt-matchObjects

Q1: Write Jest tests for the following matchObjects function.

Use describe and test as Jest primitives and formulate the test title using the given $CONTEXT, $DO-ACTION should $EXPECT-RESULT pattern.

export type MatchObjects = <T extends Record<string, unknown>>(
  matcher: Partial<T>,
  input: T
) => boolean;
@andreidmt
andreidmt / chatgpt-useCrudState-part1.md
Last active December 29, 2022 09:01
`useCrudState` via ChatGPT - part 1

I have various versions of useCrudState hook around but never published a package of it. I used ChatGPT to see how far I can get and what the experience is by "just dictating".

I needed multiple sessions since at some point ChatGPT got stuck middle-way and stopped outputting. In between sessions, I sometimes reordered or do some cosmetics that I would do faster.

While Functional Programming teaches you to focus on more "what" as oposed to "how", working together with ChatGPT takes this to a different level.

@andreidmt
andreidmt / chatgpt-bash-slugify.md
Last active December 21, 2022 17:40
Slugify in BASH via ChatGPT

Havent worked in a long time and today didnt promise to be any different.

At some point I opened my desktop pc and Firefox was opened at https://chat.openai.com ... so I went for it :)

Kept at it for more than 7 hours, rewriting questions, reverting from tangents etc.

TL;DR

# Slugify a string, with ChatGPTs help
@andreidmt
andreidmt / ts-mapped-types.md
Last active July 6, 2021 06:39
Typescript Mapped Types

[code] Typescript Mapped Types

When you don’t want to repeat yourself, sometimes a type needs to be based on another type.

Mapped types build on the syntax for index signatures, which are used to declare the types of properties which has not been declared ahead of time:

type CalcTotalByFieldType = <T, F extends keyof T>(
@andreidmt
andreidmt / autocorrect.js
Created March 22, 2021 14:26
Functional'ish autocorrect using http://spellchecker.glitch.me
const axios = require("axios")
const { map, pipe, pipeP, reduce, sortWith, read } = require("@asd14/m") // replace with ramda or underscore
const CORRECTIONS_URL = "https://spellchecker.glitch.me/corrections"
const CHECKSPELLING_URL = "https://spellchecker.glitch.me/checkspelling"
/**
* Given a string, return a list of misspelled words and their positions
*
* @param {string} source
@andreidmt
andreidmt / conway.js
Last active September 1, 2020 14:46
Functional'ish Conway's Game of Life - https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
const {
when,
equals,
pipe,
map,
mapMatrix,
join,
read,
converge,
reduce,
#!/usr/bin/fish
# The typematic delay indicates the amount of time (typically in miliseconds)
# a key needs to be pressed and held in order for the repeating process to
# begin. After the repeating process has been triggered, the character will be
# repeated with a certain frequency (usually given in Hz) specified by the
# typematic rate. Note that these settings are configured seperately for Xorg
# and for the virtual console.
xset r rate 170 25
@andreidmt
andreidmt / sample.csv
Created November 29, 2018 16:18
csv to json in SublimeText 3
Find and Replace (with Regular Expressions)
find : ^(.*),(.*),(".*"),(".*"),(".*")$
where : <current file>
replace: {"id": $1, "other_id": $2, "name": $3, "date_updated": $4, "date_created": $5},
const { sep } = require("path")
const { trim, split, push, join, dropLast } = require("@codemachiner/m")
const removeTrailingSlash = source =>
source[source.length - 1] === sep ? source.slice(0, -1) : source
/**
* Rename a file. Removes trailing slashes.
*
* @param {string} newName New file name
const { count, filter } = require("functial-lib")
const todos = [{isDone: true, ...}, {...}]
const todosIsDoneCount = todos
|> filter(todosFilterElm => todosFilterElm.isDone === true)
|> count