Skip to content

Instantly share code, notes, and snippets.

View romgrk's full-sized avatar
♥️
hey

Rom Grk romgrk

♥️
hey
View GitHub Profile
/*
* Check if there are files to process.
*/
var files = listFiles(get('global.in'))
var config = readJSON(join(get('global.work'), 'config.json'))
/*
* MetaData API
* Copyright (C) 2016 romgrk <romgrk@Romgrk-ARCH>
*
* Distributed under terms of the MIT license.
*/
/**
Usage:
/*
* MaskedInput.js
* Shamelessly copied from: https://github.com/insin/react-maskedinput (MIT License)
*
* Usage:
* <MaskedInput mask='11/11/1111' onChange={value => console.log(value)} value={myValue} />
*/
import React from 'react';
window.onerror = function(error, filename, line, col) {
'use strict';
var infos = JSON.stringify([].slice.call(arguments))
var source = document.documentElement.innerHTML
.split('\n')
.slice(line - 5, line + 2)
.join('\n');
alert(infos + '\n' + source)
}
// Style guide
// Wrong, a function that calls a function is pointless
document.addEventListener('click', function() {
doSomething()
}
// Right, pass the function itself as a callback
document.addEventListener('click', doSomething)
const image = {
name: 'image.jpg',
src: 'blob:http://...'
}
getBase64FromUrl(image.src)
.then(data => fetch(`${window.SERVER_URL}/image`, { // see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
method: 'POST',
body: objectToFormData({
/*
* multiply.js
* Author: Romain Gregoire, 2017
*/
var inputFile = Watch.getJobFileName()
var outputFile = 'c:/users/gregoirr/tmp/output.pdf'
var numberOfCopies = 3 // get('numberOfCopies')
var numberOfPages = countPages(inputFile)
var path = get('global.workPath')
var files = listFiles(path + '/') // Be sure the path ends with '/'
log(files.length)
/*
* Helpers
*/
@romgrk
romgrk / svg-to-png.js
Last active July 20, 2017 14:16
Convert SVG to PNG in the browser
function svgToPNG(svg, cb) {
var img = document.createElement('img')
var canvas = document.createElement('canvas')
img.onload = function() {
canvas.width = img.width
canvas.height = img.height
canvas.getContext('2d').drawImage(img, 0, 0)
cb(canvas.toDataURL('image/png', 1))
}
/* Usage:
*
* var objects = readExcel('c:/users/gregoirr/tmp/file.xlsx')
* var json = JSON.stringify(objects)
*/
function readExcel(path, sheetNumber) {