Skip to content

Instantly share code, notes, and snippets.

panzi / portable_endian.h
Last active Aug 19, 2020
This provides the endian conversion functions form endian.h on Windows, Linux, *BSD, and Mac OS X. You still need to use -std=gnu99 instead of -std=c99 for gcc. The functions might actually be macros. Functions: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh. License: I hereby put "port…
View portable_endian.h
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
panzi / VideoScreenshot.js
Last active Aug 11, 2020
Make a screenshot of a video.
View VideoScreenshot.js
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');
View YouTubeThumbs.js
(function() {
"use strict";
function padd(x) {
var x = String(x);
return x.length < 2 ? '0' + x : x;
var duration = +document.querySelector("video").duration;
var playerData = document.querySelector("ytd-watch-flexy").__data.playerData;
panzi / enable_context_menu.js
Created Jul 22, 2020
Bookmarklet to re-enable context menus on sites that disable it.
View enable_context_menu.js
panzi / 10_object_url.js
Created Nov 1, 2012
Save/download data generated in JavaScript (2)
View 10_object_url.js
if (BrowserSupportedMimeTypes[mimetype.split(";")[0]] === true) {
  mimetype = "application/octet-stream";
 blob = builder.getBlob(mimetype);
 url = URL.createObjectURL(blob);, '_blank', '');
panzi / gist:7551381
Created Nov 19, 2013
Download currently playing HTML5 audio/video bookmarklet.
View gist:7551381
Create a new bookmark and set it's URL to this:
When media is playing using HTML5 audio/video you can click this bookmark to open a new tab/window with the media. Then to download it use the context menu action "Save As..." (right mouse button -> Save As...).
If you use Chrome/Safari/recent Opera (WebKit/Blink) you can do better(!) and immediately download the file using this bookmarklet instead:
panzi / escapeXml.js
Created Feb 18, 2012 — forked from atesgoral/escapeXml.js
Escape XML in JavaScript.
View escapeXml.js
var XML_CHAR_MAP = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;',
"'": '&apos;'
function escapeXml (s) {
return s.replace(/[<>&"']/g, function (ch) {
panzi / getMedium.js
Last active Jan 14, 2020
Open clicked medium (image, video, audio, svg, ...) in a new tab. This handles transparent elements covering images or images via CSS background-image.
View getMedium.js
javascript:void(!function(){function e(e){for(var t=null,n=null,r=null,l=0;l<e.length;++l){var i=e[l].srcset;if(i){i=i.split(",");for(var a=0;a<i.length;++a){var o=i[a].trim().split(/\s+/g),u=o[1];if(u){var c=/^(\d+(?:\.\d*)?)([a-z])$/i.exec(u),s=c[2],d=+c[1];(s!==t||d>n)&&(t=s,n=d,r=o[0])}else r||(r=o[0],n=t=null)}}}return r?{url:r}:null}function t(t){switch(t.tagName.toUpperCase()){case"IMG":return e([t])||(t.currentSrc?{url:t.currentSrc}:t.src?{url:t.src}:null);case"CANVAS":return{url:t.toDataURL(),html:'<img src="'+t.toDataURL()+'"/>'};case"VIDEO":case"AUDIO":return t.currentSrc?{url:t.currentSrc}:null;case"SVG":var n=t.outerHTML.replace(/^<svg\b/i,e=>e+' xmlns=""');return{html:n,url:"data:image/svg+xml,"+encodeURIComponent(n)};case"IFRAME":if(t.src&&"about:blank"!==t.src)return{url:t.src};case"PICTURE":return e(t.querySelectorAll("source"));case"IMAGE":if(""===t.namespaceURI)return{url:t.href.baseVal};default:var r=getComputedStyle(t,null).backgroundIma
panzi /
Created Oct 2, 2019
convert a video into a GIF with optimal palette
panzi / bitfield.js
Created Oct 4, 2014
JavaScript bit field class with Base64 serialization.
View bitfield.js
var BitField = (function () {
"use strict";
function BitField (bits) {
if (Array.isArray(bits)) {
return BitField.fromJSON(bits);
else if (typeof bits === "string") {
return BitField.fromBase64(bits);
You can’t perform that action at this time.