Skip to content

Instantly share code, notes, and snippets.

View clayadavis's full-sized avatar

Clayton A Davis clayadavis

View GitHub Profile
@clayadavis
clayadavis / clip_magic.py
Last active September 16, 2015 19:50 — forked from nova77/clip_magic.py
copy to clipboard ipython magic
"""
Add copy to clipboard from IPython!
To install, just copy it to your profile/startup directory, typically:
~/.ipython/profile_default/startup/
Example usage:
%clip hello world
# will store "hello world"
@clayadavis
clayadavis / gist:8a2b025b24fdd4b6016d
Last active January 22, 2016 17:15 — forked from yurydelendik/gist:f2b846dae7cb29c86d23
PDF.js get/show hightlight (for Chromium)
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = Array.apply(this, window.getSelection().getRangeAt(0).getClientRects());
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.left, r.top - pageRect.top).concat(
viewport.convertToPdfPoint(r.right - pageRect.left, r.bottom - pageRect.top));
});