Skip to content

Instantly share code, notes, and snippets.

View yurydelendik's full-sized avatar

Yury Delendik yurydelendik

View GitHub Profile
@yurydelendik
yurydelendik / gist:f2b846dae7cb29c86d23
Last active January 20, 2026 06:37
PDF.js get/show hightlight
function getHightlightCoords() {
var pageIndex = PDFViewerApplication.pdfViewer.currentPageNumber - 1;
var page = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
var pageRect = page.canvas.getClientRects()[0];
var selectionRects = window.getSelection().getRangeAt(0).getClientRects();
var viewport = page.viewport;
var selected = selectionRects.map(function (r) {
return viewport.convertToPdfPoint(r.left - pageRect.x, r.top - pageRect.y).concat(
viewport.convertToPdfPoint(r.right - pageRect.x, r.bottom - pageRect.y));
});
@yurydelendik
yurydelendik / !wasmllvm.md
Last active December 15, 2025 00:33
Using WebAssembly in LLVM

NOTE: the content is out-of-date. All development is moved to the https://github.com/yurydelendik/wasmception

Using WebAssembly in LLVM

Compiling

# locations, e.g.
export WORKDIR=~/llvmwasm; mkdir -p $WORKDIR
export INSTALLDIR=$WORKDIR
@yurydelendik
yurydelendik / gist:2579279
Created May 2, 2012 19:02 — forked from brendandahl/gist:2579276
Change Channel Owner
// Keep the URL the same so the browser sees it as the same.
channel.originalURI = aRequest.URI;
channel.asyncOpen(proxy, aContext);
var securityManager = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
log('got secruity manager!');
var uri = ioService.newURI('resource://pdf.js/web/viewer.html', null, null);
var principal = securityManager.getCodebasePrincipal(uri);
log('created principal!');
channel.owner = principal;
log('hey we changed the owner!');
<!-- inside examples/ folder -->
<!-- run `gulp dist-install` -->
<html>
<head>
<script src="../node_modules/pdfjs-dist/build/pdf.js"></script>
</head>
<body>
<script>
PDFJS.cMapUrl = "../node_modules/pdfjs-dist/cmaps/";
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
var memory;
var env = {
sys: {
@yurydelendik
yurydelendik / from-mq-to-bookmarks.md
Last active November 27, 2024 22:11
Some version control operations

Overview

Provides set of operations to efficiently maintain set of patch for long time and be able to submit those for review.

GIT

Let's say we clone a repo and 'master' is upstream branch and we will keep it up-to-date on regular base.

We can created a branch for a new feature and will try to keep it fresh and with addressed reviews.

@yurydelendik
yurydelendik / getpdftext.js
Last active November 27, 2024 22:08
PDF.js bookmarklet
var next = Promise.resolve();
var content = [];
for (var i = 1; i <= PDFView.pdfDocument.numPages; i++) {
next = next.then(function (pageNum) {
return PDFView.pdfDocument.getPage(pageNum).then(function (page) {
return page.getTextContent().then(function (tc) {
content.push((tc.items || tc).map(function (x) { return x.str; }).join(' '));
});
});
}.bind(null, i));
@yurydelendik
yurydelendik / .htaccess
Last active November 27, 2024 20:08
CORS for pdf.js
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://mozilla.github.io"
</IfModule>
@yurydelendik
yurydelendik / dwarf-wasm.md
Last active April 26, 2024 20:18
DWARF for WebAssembly target
@yurydelendik
yurydelendik / x-scopes.md
Created August 1, 2018 19:30
Experimental "x-scopes" source maps extension

Experimental "x-scopes" source maps extension

This is crude attempt to add DWARF-like information to the existing wasm source maps. It is not intendent to be used as a final solution, but provides overview of the information that can be used by a consumer/debugger of wasm code.

The source maps JSON is extended to add the x-scopes field at the top level that will contains all information generated by LLVM's llvm-dwarfdump command. To reduce burden of parsing at the consumer side, the dump will be converted to the JSON using following rules:

  1. DW_TAG_xxx entity will be converted to a JS object with tag field with xxx value.
  2. If the above entry has nested level of children, the children field will be added and will contain JS array.
  3. DW_AT_yyy attributes will be assigned at fields to the enclosing object with yyy name. Theirs values will be: