Skip to content

Instantly share code, notes, and snippets.

View YavorK's full-sized avatar
🥥

Yavor Kirov YavorK

🥥
View GitHub Profile
@YavorK
YavorK / index.html
Created May 9, 2023 18:58 — forked from edofic/index.html
htmx with a "backend" in service worker
<!DOCTYPE html>
<html>
<head>
<title>Hello Page</title>
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
</head>
<body>
<h1>Hello</h1>
@YavorK
YavorK / htmx.min.js
Created May 6, 2023 16:26
Validate HTMX Form on change without losing fields focus and without extra endpoints.
(function(e,t){if(typeof define==="function"&&define.amd){define([],t)}else if(typeof module==="object"&&module.exports){module.exports=t()}else{e.htmx=e.htmx||t()}})(typeof self!=="undefined"?self:this,function(){return function(){"use strict";var z={onLoad:t,process:Tt,on:le,off:ue,trigger:ie,ajax:dr,find:b,findAll:f,closest:d,values:function(e,t){var r=Jt(e,t||"post");return r.values},remove:B,addClass:j,removeClass:n,toggleClass:U,takeClass:V,defineExtension:yr,removeExtension:br,logAll:F,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,inlineScriptNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blob",disableSelector:"[hx-dis
@YavorK
YavorK / template_engine.php
Last active June 1, 2023 17:21
Template engine with fragments.
<?php
/**
* Use
* <?= fragment_start('this_is_my_fragment') ?>
* Fragment content <?= $with_variables_and_stuff ?>
* <?= fragment_end('this_is_my_fragment') ?>
*/
/**
# Theory
## Vuejs
- Vue Step By Step (up to & including ep. 29) - https://laracasts.com/series/learn-vue-2-step-by-step
## VueX
Vuex is state management for Vue.
- Short intro https://www.youtube.com/watch?v=LW9yIR4GoVU - The example is good to understand how Vuex works. However DO NOT use Vuex to build components with. We only use it to share app-wide data - for example the currently logged in user or the current shop's data (that many components might need). If you are building a component tree, just pass the data as props.
- Docs https://vuex.vuejs.org/
/*
Solution to https://edabit.com/challenge/voZCqTGMSNjCrRhf9
Minesweeper I — Grid
This challenge is based on the game Minesweeper.
Create a function that takes a grid of # and -, where each hash (#) represents a mine and each dash (-) represents a mine-free spot. Return an array where each dash is replaced by a digit indicating the number of mines immediately adjacent to the spot (horizontally, vertically, and diagonally).
Examples
numGrid([
["-", "-", "-", "-", "-"],
["-", "-", "-", "-", "-"],
["-", "-", "#", "-", "-"],
@YavorK
YavorK / sse.html
Last active November 24, 2022 05:45 — forked from Deele/sse.html
Server-Sent Events example, Javascript client-side, PHP server-side
<html>
<body>
<div id="result"></div>
<script>
if (typeof(EventSource) !== 'undefined') {
console.info('Starting connection...');
var source = new EventSource('/stream.php');
source.addEventListener('open', function(e) {
console.info('Connection was opened.');
}, false);
<?php
$combos = [
'paper' => [
'vs_rock' => 'wins',
'vs_scissors' => 'loses',
],
'rock' => [
'vs_paper' => 'loses',
'vs_scissors' => 'wins',
<?php
$percentages = [
'Milk' => 50,
'Coffee' => 30,
'Water' => 20,
];
$percentSum = 0;
foreach ($percentages as $valuePercent) {
$percentSum = $percentSum + $valuePercent;
@YavorK
YavorK / service-workers.md
Created October 3, 2018 14:52 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@YavorK
YavorK / fun math.js
Last active June 1, 2023 17:27
how to get chained methods (builder pattern :3 ) in ES6
class math {
constructor() {
this.current = 0;
}
add(number) {
this.current += number;
return this;
}