Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aautar
aautar / base64-dataurl-to-blob.js
Created October 19, 2019 21:33
Convert a data URL, with base64 encoded data, to a Blob with binary data
const mime = MIMEFromDataURI.getMIMEType(e.data); // using https://github.com/aautar/mime-from-data-uri
const dataB64 = e.data.split(',')[1];
const imageDataStr = window.atob(dataB64);
const imageDataBinaryArr = new Uint8Array(new ArrayBuffer(imageDataStr.length));
for (let i=0; i<imageDataStr.length; i++) {
imageDataBinaryArr[i] = imageDataStr.charCodeAt(i);
}
@aautar
aautar / jest-simulate-dom-event.js
Created November 28, 2018 22:29
Simulate DOM event within a Jest test
// From https://github.com/facebook/react/issues/3249#issuecomment-177750141
var event = document.createEvent("HTMLEvents");
event.initEvent("click", true, true);
var target = $('.about-page-link')[0];
target.dispatchEvent(event);
@aautar
aautar / insertAdjacentElement.js
Created August 13, 2018 15:14
jQuery version of insertAdjacentElement (b/c jsdom doesn't doesn't implement)
Element.prototype.insertAdjacentElement = function(position, elem) {
let _this = this;
switch (position.toLowerCase()) {
case 'beforebegin':
$(_this).before($(elem));
break;
case 'afterbegin':
$(_this).prepend($(elem));
break;
@aautar
aautar / InvisibleUploadInput.css
Created August 1, 2018 17:18
Styling for invisible file input
.invisible-upload-input {
font-size:0; // hide button
cursor: pointer;
opacity:0;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
z-index:100;
function stuffInt64BytesIntoNumber(_arrayBuffer)
{
// get a DataView over the ArrayBuffer
var dv = new DataView(_arrayBuffer);
// read bytes from DataView into array
var bytes = [];
for(let i=0; i<8; i++) {
bytes.push( dv.getUint8(i) );
}
@aautar
aautar / pptx-to-png-with-apache-poi.java
Created April 12, 2017 20:43
PPTX to PNG image using Apache POI
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

Keybase proof

I hereby claim:

  • I am aautar on github.
  • I am aautar (https://keybase.io/aautar) on keybase.
  • I have a public key ASC2aM0g2jk1jjN3YLBGLlc7KUjq1ckJNfMq-HukcmkqGgo

To claim this, I am signing this object: