Skip to content

Instantly share code, notes, and snippets.

View lacikawiz's full-sized avatar
🏠
Working from home

Laszlo Szenes lacikawiz

🏠
Working from home
View GitHub Profile
@lacikawiz
lacikawiz / README.md
Last active March 20, 2023 20:14
SolidJS with Vite: preventing multiple instances of code running and HTML generated when modules are hot reloaded

I've started using SolidJS maybe 2 months ago, and I like it very much. It has solutions to problems I encountered with Svelte while building a large Apps. But there's one annoyance that comes up during the development mode which bugged me until I found a solution.

If you have been working with SolidJS using the developer mode (npm run dev) then you probably noticed the annoyance which happens when you modify a file, Vite reloads it but parts of the old code is still active (namely the reactive effects), so the HTML can have duplicates, old errors that you fixed cropping up, etc. Beyond annoyance it can waste a lot of developer time to try to figure why something is still malfunctioning after fixing it.

I've run into this myself quite a bit so I decided to dig deeper. After extensive Google-ing I couldn't find the mention of this issue or any solution. It's sure to exist because it happens even when I use SolidJS' standard starter template with a very simple application.

Anyways, problem lies in the fac

@lacikawiz
lacikawiz / Svelte Components Collection.md
Last active April 8, 2021 14:47
Svelte Components Collection
@lacikawiz
lacikawiz / google-translate.js
Last active November 19, 2019 09:34
Calling Google Translate from JS, no API Key needed
/*
Calling of simple Google API to translate short pieces of text.
Requires no API key :)
WARNING: This call has a severe rate limitation. Frequent calls will result in a temporary block for your IP address for a few hours.
INPUT:
- source language code, eg: "ru"
- target language code, eg: "en"
- text to be translated
@lacikawiz
lacikawiz / *Calculate Circle from Points.md
Created January 13, 2019 18:16
Calculate center coordinates and radius of circle based on the coordinates of 3 points on the circumference

#How to find the parameters of a circle based on 3 points on circumference

I spent some hours with WolframAlpha, paper and a text editor to distill the mathematical formula to find the center coordinates of a circle and its radius. I tested it with a few random coordinates and it returned precise results each time.

I provide here a Go code for my testing. It's very trivial to convert it into any other language.

Laszlo

@lacikawiz
lacikawiz / *Vanilla JS Wait for elements to appear in DOM.md
Created January 6, 2019 23:23
Vanilla JS Wait for elements to appear in DOM

Run JS code on DOM elements as soon as they appear

This code is written to handle cases when the DOM is being generated, like Angular, Ractive or Svelte, etc. It does a quick (100ms) repeated check for the existence of the DOM elements and when they appear it runs the given function on each elements.

@lacikawiz
lacikawiz / *<InputBlock> Svelte Component: A block to display all necessary elements to an input.md
Last active November 10, 2018 14:33
<InputBlock> Svelte Component: A block to display all necessary elements to an input

<InputBlock> component

An <InputBlock> is a unit that contains all the necessary elements for a form input element.

  • The label (with indication whether it's a required field)
  • The input component itself
  • The Explanation (short note or explanantion on the what needs to be inputted)

It also handles the validation (as given by a parameter) and displaying an error message if there's one.

@lacikawiz
lacikawiz / *<FixedBottom> Svelte Component.md
Last active November 9, 2018 19:57
<FixedBottom> Svelte Component: Generates an always visible content on the bottom of the page
@lacikawiz
lacikawiz / *Svelte Component: <Section> (styled).md
Last active November 9, 2018 14:57
A styled `Section` with slots for Title, Header, Content & Footer
@lacikawiz
lacikawiz / *<Money> Svelte Component: auto-formatting number input for number entering.md
Last active May 23, 2021 19:58
<Money> Svelte Component: auto-formatting number input for number entering
@lacikawiz
lacikawiz / *<Modal> Svelte Module: Modal Window with content insertion.md
Last active November 9, 2018 14:48
<Modal> Svelte Module: Modal Window with content insertion