Skip to content

Instantly share code, notes, and snippets.

View mrpotatoes's full-sized avatar

Andric LibreSinn mrpotatoes

View GitHub Profile

This pseudo code

section.solutions.flex-columns>.row>.column*2

Will become this code

<section class="solutions flex-columns">
    <div class="row">
 
@mrpotatoes
mrpotatoes / functional-help.js
Last active December 9, 2022 21:48
functional-help.js
console.clear()
const { matchPath } = require('react-router-dom');
const { isNil, trim, flow, identity } = require('lodash');
const patterns = [
{ path: '/' },
{ path: '/new' },
{ path: '/dashboard' },
{ path: '/details/:claimId' },
@mrpotatoes
mrpotatoes / hash.js
Last active July 23, 2022 13:23
A cheap hash function
console.clear()
// https://www.codegrepper.com/code-examples/javascript/javascript+generate+unique+hash
const hash = (len) => '_' + Math.random().toString(len).substr(2, 9)
const hashes = (amount = 5, hashLength = 36) => new Array(amount).fill().map(e => hash(hashLength))
console.log(hashes(100))
@mrpotatoes
mrpotatoes / thingy.js
Created May 31, 2022 13:51
my ramda confusion
console.clear()
const R = require('ramda')
const person = require('../data/lenses.arrays')
// Not correct --------------------------------------------------------
const getThirdFriend_incorrect = R.pipe(
R.lensProp('friends'),
R.lensIndex(2)
)
const result_incorrect = R.view(getThirdFriend_incorrect, person)
console.clear()
const R = require('ramda')
const cart = [
{ name: 'apples', price: 2.49 },
{ name: 'soap', price: 1.99 },
{ name: 'milk', price: 2.99 },
{ name: 'eggs', price: 3.99 },
{ name: 'carrots', price: 2.99 },
/* eslint-disable no-prototype-builtins */
import Overrides from './overrides';
import Themed from './theme';
import Main from './default';
const handler = {
get: (target: any, name: string): any => (target.hasOwnProperty(name) ? target[name] : Main),
};
const mapping = {
console.clear()
// trampoline
const Bounce = (f, x) => ({ isBounce: true, f, x })
const Done = x => ({ isBounce: false, x })
const trampoline = ({ isBounce, f, x }) => {
while (isBounce)
({ isBounce, f, x } = f(x))
return x
@mrpotatoes
mrpotatoes / git.sh
Created November 2, 2020 15:17
Common git stuff I always forget about with git
# Revert to an old commit
git revert --no-commit 0766c053..HEAD
@mrpotatoes
mrpotatoes / generics-help.md
Last active October 16, 2020 17:17
Complex generic + type explained

Understanding TS Generics better

I can't tell others how to write their libraries so that I can understand them easier. That's a given. That's also nonsense. I can do this with code at work though (which I do all the time). What I can do is learn how to read these things better. So I can decipher how others write their code.

But if you read the docs or take a bunch of courses you might not come away with a better understanding. I think it's just fine if your use cases are regular imperative code. When things are curried and you can write a signature for a function as a type within a type that's when things get more difficult.

And honestly, that's where I like to live. So it's time to do a little learning.

Problem statement

I was having issues with complex TypeScript generics/types. I wanted to figure out what was going on with the following function signature. I'm not used to generics espcially complicated ones. I'm fully aware that there are even more complicated ones but this isn't a dick measuring

https://gyandeeps.com/console-stubbing/