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
@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" />
ERROR: Command errored out with exit status 1:
command: /Users/federicovitale/Developer/Chili/chili-aquaman/acquaman/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/m9/7q3cfhks1tzbf400djhj35cw0000gn/T/pip-install-03kuzaxi/confluent-kafka_b002a784c6954fb897cef23347b69f60/setup.py'"'"'; __file__='"'"'/private/var/folders/m9/7q3cfhks1tzbf400djhj35cw0000gn/T/pip-install-03kuzaxi/confluent-kafka_b002a784c6954fb897cef23347b69f60/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/m9/7q3cfhks1tzbf400djhj35cw0000gn/T/pip-record-h2pvufp1/install-record.txt --single-version-externally-managed --compile --install-headers /Users/federicovitale/Developer/Chili/chili-aquaman/acquaman/include/site/python3.9/confluent-kafka
cwd: /private/var/folders/m9/7q3cfhks1tzbf400djhj35cw0000gn/T/pip-install-03kuzaxi/co
@rawnly
rawnly / isDown.sh
Created March 3, 2021 16:17
downfor.io api
#
# https://downfor.io
# Usage:
# $ isDown google.com
# $ isDown fedevitale.dev
#
function isDown() {
curl "https://api-prod.downfor.cloud/httpcheck/$1" \
--silent \
--fail \