Skip to content

Instantly share code, notes, and snippets.

View pie6k's full-sized avatar

Adam Pietrasiak pie6k

View GitHub Profile
@pie6k
pie6k / svgSquirclePath.ts
Created June 26, 2024 07:59
Get SVG Squircle Path
const iOSPreset = {
r1: 0.0586,
r2: 0.332,
};
function getSmoothSquirclePath(w: number, h: number, r1: number, r2: number) {
r1 = Math.min(r1, r2);
return `
M 0,${r2}
@pie6k
pie6k / widget.js
Created January 3, 2023 23:37
Scriptable widget showing app revenue
// Copy this code and paste it into Scriptable code editor on your phone
async function loadStats() {
const request = new Request("https://your-endpoint-giving-you-revenue-data.com");
const { todayUSD, todayOrders, revenue30USD, orders30 } = await request.loadJSON();
return { todayUSD, todayOrders, revenue30USD, orders30 };
}
const usdFormatter = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });
@pie6k
pie6k / nodeview.tsx
Created July 5, 2020 17:24
React Node View
import { Node, NodeSpec, AttributeSpec, ParseRule, Fragment, NodeType } from 'prosemirror-model';
import { EditorState, Plugin } from 'prosemirror-state';
import { Decoration, EditorView, NodeView } from 'prosemirror-view';
import { ComponentType } from 'react';
import ReactDOM from 'react-dom';
import { createGlobalStyle, css } from 'styled-components';
/**
* Props for react component responsible for rendering node view
*/
@pie6k
pie6k / package.json
Created January 28, 2020 05:24
Timpler package.json
{
"name": "Timpler",
"version": "0.0.1",
"private": true,
"scripts": {
"a": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug",
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
@pie6k
pie6k / t
Created November 3, 2019 09:14
Test na mamę
"Test na mamę"
syn rozmawia z mamą o swojej aplikacji.
2 przykłady tej rozmowy, jedna w której syn oblewa "test na mamę" i druga w której zalicza.
W nawiasach są komentarza autora książki do tego co rozmawiają
syn: mamo, mam pomysł na biznes, mogę Ci o tym opowiedzieć? (mama myśli pewnie - o, mój synek! nie chce go urazić!)
@pie6k
pie6k / useSuspend.tsx
Created October 29, 2019 19:37
useSuspend without waterfall
import { useRef } from 'react';
const noValueSymbol = Symbol();
function didBitsChange(oldBits: any[], newBits: any) {
return oldBits.some((oldBit, index) => !Object.is(oldBit, newBits[index]));
}
export function useSuspend<T>(
fetcher: () => Promise<T>,
@pie6k
pie6k / rfc.jsx
Last active October 28, 2021 18:57
<Freeze /> React Component
/**
* Goal:
*
* Being able to freeze some part of react tree and stop all updates from 'react word' for part of the tree for some period of time.
* It would prevent ui from updating in any way (props change, state change, hooks change etc)
*
* Use case:
*
* Let's say there is tab based react-native app.
* All of the screens are rendered all the time, and by using some store (redux etc)
@pie6k
pie6k / useShareForwardedRef.tsx
Created October 23, 2019 10:02
forwardRef hook
import React, { useRef, forwardRef, Ref, useEffect } from 'react';
import { TextInputProps, TextInput } from 'react-native';
import styled from 'styled-components/native';
interface Props extends TextInputProps {
showEditLabel?: boolean;
}
const Input = styled.TextInput``;
@pie6k
pie6k / suspensify-promise.ts
Last active September 18, 2019 07:50
Suspensify Promise Typescript
type AllowedArg = number | string | boolean | null | undefined;
function stringifyArg(arg: AllowedArg) {
return `${arg}`;
}
function serializeArgs(args: AllowedArg[]) {
const argsLimiter = "<<<<***>>>>";
if (args.length === 0) {
import { useEffect, useRef } from 'react';
export function useUnmountEffect(callback: () => void) {
const callbackRef = useRef(callback);
callbackRef.current = callback;
useEffect(() => {
return () => {
const callbackFunction = callbackRef.current;