Skip to content

Instantly share code, notes, and snippets.

View panzi's full-sized avatar

Mathias Panzenböck panzi

View GitHub Profile
@panzi
panzi / database-url.ts
Last active August 30, 2022 20:26
Simple parser for common database URLs. (MIT License)
// Copyright 2022 Mathias Panzenböck
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@panzi
panzi / enable_context_menu.js
Created July 22, 2020 21:17
Bookmarklet to re-enable context menus on sites that disable it.
javascript:(function(pd){Event.prototype.preventDefault=function(){if(this.type!=='contextmenu')return%20pd.apply(this,arguments);};})(Event.prototype.preventDefault);void(0)
@panzi
panzi / VideoScreenshot.js
Last active May 7, 2022 10:59
Make a screenshot of a video.
javascript:(function() {
function screenshot(video) {
var canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
context = canvas.getContext('2d');
var now = new Date();
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
var url = canvas.toDataURL('image/png');
var link = document.createElement('a');
@panzi
panzi / jqlog.sh
Created April 6, 2022 21:06
Follow JSON logs formatted using jq. You can also pass jq options after the filename for filtering.
#!/usr/bin/bash
set -eo pipefail
RED=$(echo -e '\033[0;1;31m')
NORMAL=$(echo -e '\033[0m')
if [[ $# -lt 1 ]]; then
echo "usage: $0 <logfile> [jq-options...]">&2
exit 1
fi
logfile=$1
shift
@panzi
panzi / mandelbrot.c
Created November 10, 2013 04:40
gcc -lm -Wall -Werror -Wextra -pedantic -std=c99 -O3 -o mandelbrot mandelbrot.c original: http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python/
#include <stdio.h>
#include <complex.h>
#define dc double complex
dc
Y(dc
V,
dc B,dc c){
return
(cabs (V)<6)?(c?Y(V *V+
B,B,c-1):c):(2+c-4*cpow
@panzi
panzi / saveCanvas.js
Last active November 28, 2021 09:31
JavaScript function to save the contents of canvas element to a file.
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
window.saveAs = window.saveAs || window.webkitSaveAs || window.mozSaveAs || window.msSaveAs;
function saveCanvas (canvas, filename, fileformat) {
if (navigator.msSaveBlob || window.URL || window.saveAs) {
if (canvas.toBlob) {
canvas.toBlob(function (blob) {
saveBlob(blob, filename);
}, fileformat);
}
@panzi
panzi / no_blocking_overlay.js
Last active November 28, 2021 03:00
A bookmarklet that removes these nasty overlays from websites that would work perfectly fine without a login, but still want you to create one. Create a new bookmark and paste the script source as the URL. (Use "Raw" to see only the script source for easy copy-paste.) When on a page with a blocking overlay click the bookmark.
javascript:(()=>{var d=document.documentElement,b=document.body,es=b.querySelectorAll("*"),m=20;for(var i=0;i<es.length;++i){var e=es[i];var s=getComputedStyle(e);if(s.position!=='static'&&s.position!=='relative'){var r=e.getBoundingClientRect();if(r.x<=m&&r.y<=m&&r.right>=window.innerWidth - m&&r.bottom>=window.innerHeight - m){e.remove();}}}var s='\n/**/;position:static!important;overflow:auto!important;width:auto!important;height:auto!important;';d.setAttribute('style',(d.getAttribute('style')||'')+ s);b.setAttribute('style',(b.getAttribute('style')||'')+ s);})();void(0)
@panzi
panzi / 10_object_url.js
Created November 1, 2012 05:02
Save/download data generated in JavaScript (2)
if (BrowserSupportedMimeTypes[mimetype.split(";")[0]] === true) {
  mimetype = "application/octet-stream";
 }
 
 blob = builder.getBlob(mimetype);
 url = URL.createObjectURL(blob);
 window.open(url, '_blank', '');
}
@panzi
panzi / deleteElement.js
Last active November 27, 2021 08:45
Delete an element by clicking it. Save this script as the URL of a bookmark, click the bookmark, and then click the element you want to delete. (Click Raw to get to a page that only shows the script source for easier copy-paste.)
javascript:(function(){var cursor=document.body.style.cursor;var overlay=document.createElement('div');var iframeCatch=document.createElement('div');var style='border:1px solid #3280FF;background-color:rgba(50,128,255,0.5);position:absolute;z-index:2147483647;display:block;box-sizing:border-box;left:0;top:0;width:0;height:0;margin:0;padding:0;';var ev='pointer-events:none;';var tr='transition:width 60ms,height 60ms,left 60ms,top 60ms;';var br='border-radius:0;';style +=ev+'-webkit-'+ev+'-moz-'+ev;style +=tr+'-webkit-'+tr+'-moz-'+tr;style +=br+'-webkit-'+br+'-moz-'+br;overlay.setAttribute('style',style);document.body.appendChild(overlay);style='border:none;position:absolute;z-index:2147483647;display:none;box-sizing:border-box;left:0;top:0;width:0;height:0;margin:0;padding:0;';style +=br+'-webkit-'+br+'-moz-'+br;iframeCatch.setAttribute('style',style);iframeCatch.addEventListener('mouseout',function(event){this.style.display='none';},false);document.body.appendChild(iframeCatch);document.body.style.cursor="cro
@panzi
panzi / detect_svg_support.js
Created July 18, 2013 17:48
Detect SVG browser support.
function supportsSVG() {
return !!document.createElementNS && !!document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGRect;
}