Skip to content

Instantly share code, notes, and snippets.

View mt3o's full-sized avatar

Teodor Kulej mt3o

View GitHub Profile
@mt3o
mt3o / polymorphic-patterns.ts
Created June 18, 2024 16:34
TS Polyomrphic patterns
// Very bad
const config={
where: "disk"|"redis"
}
if(config.where=="disk"){
//explicit code to save to disk
}else if(config.where=="redis"){
//explicit code to handle redis
@mt3o
mt3o / what-forces-layout.md
Created June 18, 2024 11:37 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class d {
public static void main(String[] args) {
int x = 650;
@mt3o
mt3o / git purge large unwanted file.sh
Created August 16, 2023 09:01
Diagnose & remove large files from git repo
# find large objects
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
cut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
# remove package.tar.xz from repo
@mt3o
mt3o / commandline.bat
Created March 9, 2023 13:21
gource snippet
gource --hide mouse --date-format "%Y-%m-%d" --highlight-dirs --filename-time 2 --multi-sampling --camera-mode overview --file-idle-time 320 --max-user-speed 400 --seconds-per-day 0.05 -o - | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset medium -pix_fmt yuv420p -crf 9 -bf 0 gource.mp4
@mt3o
mt3o / siblings.js
Created December 12, 2022 08:06
Get all siblings of single DOM node
function siblings(el) {
return el.closest('*:not(:scope)').querySelectorAll(':scope > *');
}
@mt3o
mt3o / node.js
Created June 7, 2022 14:54
hack around ts import error unexpected symbol export
//hack around es6 modules incompatibility
//when import fetch from 'node-fetch'; fails
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
@mt3o
mt3o / multiprocessing_queue.py
Created June 16, 2021 16:39
python multiprocessing with intermediate queue
# stolen from: https://stackoverflow.com/questions/6672525/multiprocessing-queue-in-python
import multiprocessing
num_procs = 4
def do_work(message):
print "work",message ,"completed"
def worker():
for item in iter( q.get, None ):
do_work(item)
#Here's some sample code based on the book Learning Python by Mark Lutz that addresses your question:
import sys
temp = sys.stdout # store original stdout object for later
sys.stdout = open('log.txt', 'w') # redirect all prints to this log file
print("testing123") # nothing appears at interactive prompt
print("another line") # again nothing appears. it's written to log file instead
sys.stdout.close() # ordinary file object
sys.stdout = temp # restore print commands to interactive prompt
print("back to normal") # this shows up in the interactive prompt
@mt3o
mt3o / echo-module.php
Created May 10, 2019 18:41
Echo joomla modules with php
<?php
// https://joomla.stackexchange.com/questions/1054/displaying-a-joomla-module-using-php
$modules = JModuleHelper::getModules("dashboard_main");
$document = JFactory::getDocument();
$attribs = array();
$attribs['style'] = 'xhtml';
foreach ($modules as $mod)