Skip to content

Instantly share code, notes, and snippets.

@bbottema
bbottema / MimeType.java
Last active July 20, 2019 20:10
Mimetypes compiled from two big public lists
class MimeType {
private static final MimetypesFileTypeMap MIMETYPES_FILE_TYPE_MAP = createMap();
/**
* @return a vastly improved mimetype map
*/
private static MimetypesFileTypeMap createMap() {
try (InputStream is = MimeType.class.getClassLoader().getResourceAsStream("mimetypes.txt")) {
return new MimetypesFileTypeMap(is);
@bbottema
bbottema / openssl-cheat.sh
Created June 25, 2019 11:59 — forked from alvarow/openssl-cheat.sh
OpenSSL and Keytool cheat sheet
# Generate a new key
openssl genrsa -out server.key 2048
# Generate a new CSR
openssl req -sha256 -new -key server.key -out server.csr
# Check certificate against CA
openssl verify -verbose -CApath ./CA/ -CAfile ./CA/cacert.pem cert.pem
# Self Signed
@bbottema
bbottema / test-lossy-webp-support.js
Created December 27, 2019 10:32
Ways of detecting webp browser support
// works for all browsers
async function supportsWebp():Promise<boolean> {
const img = new Image();
return new Promise(resolve => {
img.onload = function () {resolve((img.width > 0) && (img.height > 0));};
img.onerror = function () {resolve(false);};
img.src = "data:image/webp;base64," + "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA";
});
}
@bbottema
bbottema / KeyStoreInfo.java
Last active July 5, 2020 11:52
Utility code for creating SSLSocketFactory for sending email
package org.simplejavamail.sslhelper;
import org.simplejavamail.internal.util.MiscUtil;
@SuppressWarnings("SameParameterValue")
public class KeyStoreInfo {
private final String keyStorePath;
private final String password;
private final String type /*= "JKS"*/;
<script>
document.addEventListener("DOMContentLoaded", function() {
sortChildnodes(document.documentElement);
function sortChildnodes(ele) {
if (ele.append) {
ele.childNodes.forEach(sortChildnodes);
var allList = [...ele.childNodes];
var sortList = allList.filter(checkSortCondition);