Skip to content

Instantly share code, notes, and snippets.

View jglodek's full-sized avatar

Jacek Głodek jglodek

  • Iterators
  • Warsaw, Poland
View GitHub Profile
@jglodek
jglodek / gist:b9711c6133950e2385847b6f56ba38e1
Created September 29, 2025 11:52
Copy from Miro to LLM
javascript:(async()=>{const e=await miro.board.getSelection(),t=e=>e?e.replace(/<br\s*\/?>/gi,"\n").replace(/<\/p>\s*<p>/gi,"\n").replace(/<\/?[^>]+(>|$)/g,"").replace(/&[#a-z0-9]+;/gi,"").trim():"",n=e.filter(e=>"connector"!==e.type).map(e=>({id:e.id,type:e.type,text:t(e.content||e.title||""),shape:e.shape,x:e.x,y:e.y})),o=[...n].sort(((e,t)=>e.y-t.y||e.x-t.x)),a=[...n].sort(((e,t)=>e.x-t.x||e.y-t.y)),r=e.filter(e=>"connector"===e.type).map(e=>({from:e.start?.item,to:e.end?.item,arrow:"none"!==e.style?.endStrokeCap})).filter(e=>e.from&&e.to),c={nodes:Object.fromEntries(n.map(e=>[e.id,{text:e.text,type:e.type,shape:e.shape,x:e.x,y:e.y}])),edges:r},l={};for(const e of r)e.arrow&&((l[e.from]=l[e.from]||[]).push(e.to));function d(e,t=new Set){if(t.has(e))return null;t.add(e);const n=c.nodes[e];return n?{id:e,text:n.text,type:n.type,children:(l[e]||[]).map(e=>d(e,t)).filter(Boolean)}:null}const i=new Set(r.filter(e=>e.arrow).map(e=>e.to)),s=n.map(e=>e.id).filter(e=>!i.has(e)),f=s.map(e=>d(e)).filter(Boolean),u=%6
@jglodek
jglodek / gist:825bbc03b83fb2baa701c5416c036a17
Created January 22, 2025 17:19
JsonModel(BaseModel) for pydantic to work with structured tool calls in langchain agents
from pydantic import BaseModel, model_validator, ValidationError
import json
from typing import Any
class JsonModel(BaseModel):
"""
A base model that parses the entire input or specific fields if they contain JSON strings.
"""
@model_validator(mode="before")
#command that says battery low if <8%
ioreg -l |awk 'BEGIN{FS="=";max=0;cur=0;} $1~/CurrentCapacity/{cur=$2} $1~/MaxCapacity/{max=$2} END{if (cur/max*100<8) {"say battery low" | getline result} else {print "battery OK"}}'
#crontab editor
crontab -e
#crontab entry that does this once every 60s
* * * * * ioreg -l |awk 'BEGIN{FS="=";max=0;cur=0;} $1~/CurrentCapacity/{cur=$2} $1~/MaxCapacity/{max=$2} END{if (cur/max*100<8) {"say battery low" | getline result} else {print "battery OK"}}'
@jglodek
jglodek / gist:87f6d040efbddfc2ad293f039d330365
Created December 17, 2020 20:30
Upload any file with copy paste
uploadify() {
echo "echo '"${$(cat $1 | base64)}${$(echo "' | base64 --decode > $1")}
}
#usage uploadify logo.png
#copy + paste on any terminal anywhere in the interwebs
@jglodek
jglodek / gist:f7b8abd552131fc54ed6a60e42c64a44
Last active December 2, 2020 08:36
ICLOUD NODE_MODULES .NOSYNC - Stop synchronizing node_modules Mac Documents
# find icloud files
cd $HOME/Library/Mobile Documents/com~apple~CloudDocs
# test run crontab
find $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs -type d -name node_modules -exec touch {}/.nosync \;
# add crontab with vim so it runs every couple of hours
EDITOR=vim crontab -e
0 */2 * * * find $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs -type d -name node_modules -exec touch {}/.nosync \;
@jglodek
jglodek / NGINX_DEBUG.sh
Last active May 20, 2020 20:00
NGINX REWRITE DEBUG SETUP
#We're creating a nginx + a ECHO SERVER
# in nginx we play around the config
# echo server will show us the WYMIWYG (WHAT YOU MEAN IS WHAT YOU GET) when we do requests to the nginx
# run containers for debug
docker run --detach --name nginx -p 80:80 nginx
docker run --detach --name echo -P jmalloc/echo-server
# enter the server
docker exec -ti nginx bash
# ./p.bin is /opt/docker/p.bin
# 1 is the PID of java
jmap -dump:format=b,file=./p.bin 1
docker cp <containerId>:/file/path/within/container /host/path/target
docker cp <containerId>:/opt/docker/p.bin .
scp -o StrictHostKeyChecking=no -i $(echo $ssh_private_key_location) user@example.com:/home/core/p.bin .
@jglodek
jglodek / gist:ea8e8ff961e1fb780499a93dfb820ba8
Last active August 17, 2018 22:37
getting project version text from package.json file for interpolation
$(cat package.json | grep "version" | sed 's/.*"\(.*\)".*/\1/')
or
$(node -p "require('./package.json').version")
if you have node (not the case for some docker images)
@jglodek
jglodek / gist:fd4f03601739d6567b5a50dbfefdf745
Last active August 18, 2018 11:46
lame getting project version text from build.sbt SBT file for interpolation
$(cat build.sbt | grep '[ \t]*version :=' | sed 's/.*"\(.*\)".*/\1/')
@jglodek
jglodek / gist:fcdda60088e8adad51ef038872a77a1b
Created July 17, 2018 15:08
Recovering files from stopped docker containers | Docker Container Stopped | Rescue | Recovery
list files
docker ps -a
commit data to images
docker commit 91ea7799154c user/test_image1
docker commit e68f87d44923 user/test_image2
docker commit 439177e1f838 user/test_image3
docker commit 1fbf94e114ff user/test_image4