Skip to content

Instantly share code, notes, and snippets.

@mediumhust
mediumhust / Recipe-bundling-fonts-with-headless-chrome.md
Created April 29, 2020 03:45 — forked from nat-n/Recipe-bundling-fonts-with-headless-chrome.md
How to build a fontconfig bundle for adding arbitrary fonts to headless chrome independent of the OS. This is specifically useful for deploying headless chrome to AWS lambda where it is necessary to include fonts for rendering CJK (Chinese, Japanese, Korean) characters into the deployed bundle.

Building fontconfig

Start up a lambda-like docker container:

docker run -i -t -v /tmp:/var/task lambci/lambda:build /bin/bash

Install some dependencies inside the container:

yum install gperf freetype-devel libxml2-devel git libtool -y

easy_install pip

self.addEventListener('install', (e) => {
e.waitUntil(
caches.open("precache").then((cache) => cache.add("/broken.png"))
);
});
function isImage(fetchRequest) {
return fetchRequest.method === "GET" && fetchRequest.destination === "image";
}
// unserialize.js v1.0.1
function unserialize(serialize) {
let obj = {};
serialize = serialize.split('&');
for (let i = 0; i < serialize.length; i++) {
thisItem = serialize[i].split('=');
obj[decodeURIComponent(thisItem[0])] = decodeURIComponent(thisItem[1]);
};
return obj;
};
@mediumhust
mediumhust / object-to-form-data.js
Created February 13, 2020 03:50 — forked from ghinda/object-to-form-data.js
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@mediumhust
mediumhust / GitCommitEmoji.md
Created November 2, 2019 06:46 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji