Skip to content

Instantly share code, notes, and snippets.

Avatar

Fernando Bueno antenando

View GitHub Profile
View pdfcompress.sh
# Usage: pdfcompress [input file] [output file] [screen*|ebook|printer|prepress]
pdfcompress() {
if [ -z "$1" ]||[ -z "$2" ]
then
echo "Usage: pdfcompress [input file] [output file] [screen*|ebook|printer|prepress]"
return 1
else
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/${3:-"printer"} -dCompatibilityLevel=1.4 -sOutputFile="$2" "$1"
fi
}
@antenando
antenando / convert-encoding.sh
Created Aug 14, 2018 — forked from arpith20/convert-encoding.sh
Shell script to convert encoding of files to utf-8.
View convert-encoding.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Usage: "$0" <file_name>"
echo "Convert files to utf-8"
exit
fi
for i in $*
do
@antenando
antenando / coverage.js
Created Feb 28, 2018 — forked from ebidel/coverage.js
CSS/JS code coverage during lifecycle of page load
View coverage.js
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*
* Shows how to use Puppeeteer's code coverage API to measure CSS/JS coverage across
* different points of time during loading. Great for determining if a lazy loading strategy
* is paying off or working correctly.
*
* Install:
* npm i puppeteer chalk cli-table
@antenando
antenando / cloudSettings
Last active Jul 11, 2018
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2018-07-11T02:23:51.479Z","extensionVersion":"v2.9.2"}
View Infrastructure.js
const fetch = (url) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(url)
switch(url.match(/\d[aA-zZ]$/)[0]) {
case "1a":
resolve({name: "Seb"})
// or try this instead:
// reject({error: "something went wrong while fetching " + url})
break;
View Infrastructure.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@antenando
antenando / script-loaded.js
Created Dec 21, 2017 — forked from AllThingsSmitty/script-loaded.js
Check if any given script has loaded
View script-loaded.js
var myScript = document.createElement('script');
myScript.src = 'http://code.jquery.com/jquery-2.1.4.min.js';
myScript.onload = function() {
console.log('jQuery loaded.');
};
document.body.appendChild(myScript);
@antenando
antenando / cache_storage_size.js
Created Dec 15, 2017 — forked from ebidel/sw_caching_size.js
Print service worker cache sizes and overall bytes cached.
View cache_storage_size.js
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*/
// Prints the size of each cache in the Cache Storage API and the overall bytes cached.
async function getCacheStoragesAssetTotalSize() {
// Note: opaque (i.e. cross-domain, without CORS) responses in the cache will return a size of 0.
const cacheNames = await caches.keys();
@antenando
antenando / Frame.js
Created Dec 12, 2017 — forked from robertgonzales/Frame.js
Use React portals to render inside shadow dom and iframes
View Frame.js
class Frame extends Component {
componentDidMount() {
this.iframeHead = this.node.contentDocument.head
this.iframeRoot = this.node.contentDocument.body
this.forceUpdate()
}
render() {
const { children, head, ...rest } = this.props
return (
View FiniteMachine.js
import React, { Component } from "react"
import { Machine } from "xstate"
import * as PropTypes from "prop-types"
class FiniteMachine extends Component {
machine = Machine(this.props.chart)
state = {
data: this.props.reducer(undefined, { type: "@init" }),
machineState: this.machine.getInitialState()