Skip to content

Instantly share code, notes, and snippets.

@metatarz
metatarz / posoco.tpl.md
Created March 13, 2023 12:36
POSOCO template

Tags

posoco tags separated by comma

tag1,tag2,tag3

Problem

State your problem, issue you are facing, expected output... in few words

Solution

@metatarz
metatarz / posoco.md
Last active March 13, 2023 12:22
jq filtering with arguments, variables and keeping the result as an array

Tags

jq,jq-with-arguments,jq-filter-from-array-to-array,jq-with-variables

Problem statement

I want to be able to select a random peak object with a given 'peak.type' argument from the peaks array data with jq.

Solution

  1. Filter peaks data with '.peaks[] | select(.type == $p)'
  2. Surround the expression with [] to keep it as an array
  3. Get the length of the new array and assign the value to the $k variable
  4. Convert the $i argument and get the modulus with the $k variable to keep the random index within the range
@metatarz
metatarz / index.html
Last active December 13, 2020 18:24
Lazy loading intercom js web library
<body>
<div class="contact-us">
<div class="phone-icon"></div>
</div>
</body>
@metatarz
metatarz / index.html
Last active October 26, 2020 16:41
CSS reactive animations
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reactive CSS Animations </title>
<style>
.long{
background-color: #137b85;
height: 100vh;
width: 100vw;
@metatarz
metatarz / InteractiveMap.vue
Created October 24, 2020 07:59
How to use Vue 3 directives inside a popup content like in Mapbox
<template>
<div id="map"></div>
<popup :key="componentKey"></popup>
</template>
<script>
import PopupContent from './PopupContent.vue'
export default{
name:'InteractiveMap',
data(){
@metatarz
metatarz / compress.js
Created October 11, 2020 09:18
Client-side file upload compression with CompressionStream
const fileEl = document.getElementById('upload-js')
fileEl.addEventListener('change', async ()=>{
const uploadedFile = fileEl.files[0]
const format = 'gzip'
const compressedFile = await compressStream(uploadedFile, format)
console.log(compressedFile)
})