Skip to content

Instantly share code, notes, and snippets.

View honzabrecka's full-sized avatar
👋

Honza Břečka honzabrecka

👋
View GitHub Profile
class Stack {
constructor() {
this.items = [];
}
// Add an element to the stack
push(element) {
this.items.push(element);
}
(defn ->roman
; https://www.codewars.com/kata/51b62bf6a9c58071c600001b/train/clojure
[n]
(let [rn ["I" "V" "X" "L" "C" "D" "M"]
rn# (partition 3 2 [nil nil] rn)
->rn (fn [x n]
(let [[a b c] (nth rn# x)]
(get {9 [a c]
8 [b a a a]
7 [b a a]
import { nested, nestedFieldSeparator } from '../nested';
type NestedInput = {
name: string;
inputs: NestedInput[];
};
const flatInputs = (inputs: NestedInput[]) => {
const recur = (inputs: NestedInput[], path: string[]) =>
inputs.flatMap(({ name, inputs }) => {
import React, {
useEffect,
useState,
useCallback,
StrictMode,
useSyncExternalStore,
} from 'react';
import { render, waitFor, screen } from '@testing-library/react';
export const strictWrapper = ({ children }: any) => (
const trampoline = (f, ...args) => {
let r = f(...args);
while (typeof r === 'function') r = r();
return r;
};
const f = (x, n) => {
return x < n ? f(x + 1, n) : 'done';
};
import React, { useState, useCallback, useMemo, Suspense } from "react";
const [rejected, resolved, pending] = ["rejected", "resolved", "pending"];
export const wrapAsyncResource = (factory, lazy = true) => {
let promise;
let state = [pending, undefined];
const startPromise = () => {
promise = factory();
const metaProp = Symbol.for("meta");
function withMeta(m, x) {
Object.defineProperty(x, metaProp, {
value: m,
writable: true,
configurable: true,
enumerable: false,
});
return x;
let ix = 0;
const getIx = () => `generated_id/${ix++}`
const useGenerateId = () => {
const [id, setId] = useState(getIx);
const regenerate = useCallback(() => setId(getIx()), []);
return [id, regenerate];
};
  1. způsob
const [token, setToken] = useState(getToken);

useEffect(() => {
  setToken(localStorage.getItem("token");
}, []);
import {
Forms,
useSafeCallback
} from '@pricefx/unity-components';
const {
useForm,
Form,
Field,
error,