Skip to content

Instantly share code, notes, and snippets.

View timdown's full-sized avatar

Tim Down timdown

  • UK
View GitHub Profile
@timdown
timdown / print_pdf.js
Last active June 5, 2024 13:45
Print PDF
/**
* Prints a PDF in a browser using a hidden iframe. Works in recent versions of Firefox, Chrome, Safari and Edge. Does
* not work in IE 11 and instead attempts to open the PDF in a new tab.
*
* Note that the PDF URL must come from the same domain as the page including this file because of the same-origin
* policy.
*
* Usage: printPdf(url)
*/
var printPdf = (function() {
@timdown
timdown / range_selection_save_restore.js
Last active July 4, 2024 09:50
Range and selection marker-element-based save and restore
/**
* This is ported from Rangy's selection save and restore module and has no dependencies.
* Copyright 2019, Tim Down
* Licensed under the MIT license.
*
* Documentation: https://github.com/timdown/rangy/wiki/Selection-Save-Restore-Module
* Use "rangeSelectionSaveRestore" instead of "rangy"
*/
var rangeSelectionSaveRestore = (function() {
var markerTextChar = "\ufeff";
@timdown
timdown / trim_canvas.js
Created July 26, 2017 16:15
Returns a copy of a canvas element with surrounding transparent space removed
var trimCanvas = (function() {
function rowBlank(imageData, width, y) {
for (var x = 0; x < width; ++x) {
if (imageData.data[y * width * 4 + x * 4 + 3] !== 0) return false;
}
return true;
}
function columnBlank(imageData, width, x, top, bottom) {
for (var y = top; y < bottom; ++y) {

Keybase proof

I hereby claim:

  • I am timdown on github.
  • I am timdown (https://keybase.io/timdown) on keybase.
  • I have a public key whose fingerprint is D48F D84D 2AA1 572A 1E6B 965A 0E1C 5774 5110 6790

To claim this, I am signing this object:

/**
* Class Applier module for Rangy.
* Adds, removes and toggles classes on Ranges and Selections
*
* Part of Rangy, a cross-browser JavaScript range and selection library
* https://github.com/timdown/rangy
*
* Depends on Rangy core.
*
* Copyright 2015, Tim Down
/**
* Rough FileAppender implementation for log4javascript 1.4.
*
* Copyright 2013 Tim Down.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0