Skip to content

Instantly share code, notes, and snippets.

View yurydelendik's full-sized avatar

Yury Delendik yurydelendik

View GitHub Profile
@yurydelendik
yurydelendik / config
Created March 3, 2014 13:52
github try branch alias
[alias]
try = !sh -c 'IFS=\":\" read -ra ARGS <<< \"$0\" && git fetch https://github.com/${ARGS[0]}/pdf.js.git ${ARGS[1]} && git checkout FETCH_HEAD'
// http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
var W = new Int32Array(80);
function sha1(s) {
// 6.1.1 SHA-1 Preprocessing
var H = new Int32Array([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]);
// 5.1 Padding the Message
var sLength = s.length, sLength8 = sLength << 3;
var length = (((sLength8 + 64) | 511) + 1) >> 3;
var m = new Uint8Array(length);
for (var i = 0; i < sLength; i++) {
@yurydelendik
yurydelendik / badfillrule.html
Created February 18, 2014 17:00
Minimal test case to replicate linux firefox 27 bug
<canvas id="c"></canvas>
<script>
var c = document.getElementById('c');
var ctx = c.getContext('2d');
ctx.transform(10, 0, 0, 10, 0, 0);
ctx.rect(10, 5, 1, 1);
ctx.fillStyle = 'red';
// ctx.mozFillRule = 'evenodd'; // also bad
// ctx.fill(); // okay
ctx.fill('evenodd');
@yurydelendik
yurydelendik / gist:8787043
Created February 3, 2014 16:24
Parse network monitor cap file
var sourceAddress = [192,168,1,2];
var targetAddress = [192,168,1,1];
function readCapFile() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'test.cap');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
var file = new Uint8Array(xhr.response);
if (file[0] !== 0x47 || file[1] !== 0x4D) throw new Error('invalid cap file');
@yurydelendik
yurydelendik / gist:8117617
Created December 24, 2013 20:38
Getting the native DPI
function getDPI() {
var native = document.createElement('div');
native.setAttribute('style', 'width:0px; width:100mozmm; position: fixed;');
document.body.appendChild(native);
var standard = document.createElement('div');
standard.setAttribute('style', 'width:100mm; position: fixed;');
document.body.appendChild(standard);
var dpi = Math.round(native.offsetWidth / standard.offsetWidth * 96);
native.remove();
standard.remove();
@yurydelendik
yurydelendik / gist:6195643
Last active December 20, 2015 21:09
Checking if DOM element is in view
function isInView(element) {
// set initial bounds
var bounds = element.getBoundingClientRect();
var left = bounds.left, top = bounds.top;
var right = bounds.right, bottom = bounds.bottom;
var currentElement = element;
while (true) {
if (!currentElement.offsetParent) {
return false; // 'display: none;' not visible
}
@yurydelendik
yurydelendik / pdfinfo.js
Last active December 20, 2015 09:38
Utility to extract PDF info
fs = require('fs');
function fromPdfString(s) {
var t = '';
for (var i = 0; i < s.length; i++) {
if (s[i] != '\\') {
t += s[i];
continue;
}
if (s[i + 1] < "A") {
@yurydelendik
yurydelendik / droidscreen.html
Created July 17, 2013 18:49
poor man droid screencast
<canvas id="screencap" onclick="turn()"></canvas>
<script>
var angle = 0;
function turn() {
angle = (angle + 90) % 360;
}
function readImage() {
var img = new Image();
img.onload = function () {
@yurydelendik
yurydelendik / gist:5953383
Created July 8, 2013 23:31
Making simple barcode scanner for Firefox OS
$ python stats/statcmp.py sp2_orig.stat sp2_ref.stat
-- Grouped By browser, stat --
browser | stat | Baseline(ms) | Current(ms) | +/- | % | Result(P<.05)
---------------------------------------------------------------------------------
firefox | Font Loading | 1 | 1 | -0 | -6.63 | slower
firefox | Overall | 78 | 75 | 3 | 3.37 | faster
firefox | Page Request | 21 | 17 | 4 | 17.59 | faster
firefox | Rendering | 55 | 56 | -1 | -1.66 | slower
-- Grouped By browser, pdf, stat --