Skip to content

Instantly share code, notes, and snippets.

View rawnly's full-sized avatar
🧨
fixing my printer

Federico rawnly

🧨
fixing my printer
View GitHub Profile
import produce from 'immer';
import { Action, useRegisterActions } from 'kbar';
import { FC, useMemo, useState } from "react";
interface IDemoProps { }
const Demo: FC<IDemoProps> = () => {
const [counter, setCounter] = useState( 0 )
const [recentActions, setRecentActions] = useState<Record<string, number>>( {} )
import createStore from 'zustand'
type HistoryStore<T> = {
present: T
past: T[]
future: T[]
undo: () => void
redo: () => void
reset: (present: T | ((data: T) => T)) => void
@rawnly
rawnly / array-util.ts
Last active September 28, 2021 10:08
import { match, Pattern } from 'ts-pattern'
/**
* Returns an element of the array matching given pattern or `null`
*/
export const find = <T>(data: T[], query: Pattern<T>): T | undefined =>
data
.find(item =>
match(item)
.with(query, () => true)
import { useEffect, useState } from 'react';
const useHistory = <T>( initialValue: T[] = [] ) => {
const [isDirty, setIsDirty] = useState( false );
const [step, setStep] = useState( 0 );
const [history, setHistory] = useState<T[]>( initialValue );
useEffect( () => {
console.log( {
isDirty,
@rawnly
rawnly / show-password.js
Created July 3, 2021 18:08
Sometimes it works, sometimes not. Better than nothing :)
const genericButton = document.querySelector('[type="submit"]')
const password_input = document.querySelector('[type="password"]')
const button = document.createElement('button')
button.setAttribute('type', 'button')
button.innerText = 'Show Password'
button.style = "margin-top: 5px;"
if ( genericButton ) {
button.setAttribute('class', genericButton.getAttribute('class'))
#!/bin/zsh
TEXT_DIM="\e[2m"
TEXT_BOLD="\e[1m"
TEXT_UNDERLINE="\e[4m"
TEXT_RED="\e[91m"
TEXT_BLACK="\e[30m"
TEXT_DEFAULT="\e[39m"
TEXT_RESET="\e[0m"
TEXT_YELLOW="\e[33m"
name: Docker CI
on:
push:
branches:
- 'master'
- 'develop'
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
@rawnly
rawnly / Switch.tsx
Created April 1, 2021 15:31
Super simple Switch case as React Functional Component
// Super simple Switch case as React Functional Component
import React, { FC, Children, ReactElement } from "react";
const Case: FC<{ value: SwitchValue } | { default: true }> = ( { children } ) =>
<>{children}</>;
const checkCondition = ( condition, value ) => {
if ( condition instanceof Function && condition( value ) ) return true;
return condition === value;
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Dwminit" />
<EventID Qualifiers="32770">0</EventID>
<Version>0</Version>
<Level>3</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2021-03-24T22:25:17.9398436Z" />