Skip to content

Instantly share code, notes, and snippets.

View bbottema's full-sized avatar

Benny Bottema bbottema

View GitHub Profile
@bbottema
bbottema / example.sh
Last active November 27, 2023 21:40
Truncate GIT history
# <commit-rev> = commit you want to reset repo to
# <target-branch> = branch you want to truncate (probably master or develop)
git checkout --orphan temp <commit-rev>
git commit -m "Truncate history or Initial commit"
git rebase --onto temp <commit-rev> <target-branch>
git push --force
@bbottema
bbottema / Express with base64 file upload and read back to client
Last active December 14, 2022 14:34
A complete Express 4 example using multer to read base64 png data and reading the file back to the client as binary data
var express = require('express');
var fs = require('fs');
var multer = require('multer'); // v1.0.5
var app = express();
app.use(express.static('./public'));
var upload = multer(); // for parsing multipart/form-data
app.post('/testFormData', upload.array(), function(req, res) {
<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);
@bbottema
bbottema / PizzaSorter.java
Last active October 26, 2021 17:08
Demonstration of various techniques for sorting based on multiple properties. Also, see: http://www.bennybottema.com/2013/06/21/ways-to-sort-lists-of-objects-in-java-based-on-multiple-fields/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.google.common.collect.ComparisonChain;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ComparatorChain;
import org.apache.commons.lang3.builder.CompareToBuilder;
@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"*/;
@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 / 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 / Read ajax binary response data to base64
Created September 30, 2015 18:19
Complete example using FormData to post a variable and file to a service and parsing the binary result to base64
var formData = new FormData();
formData.append("user", "Mario");
formData.append("testdot", imgData);
createRequest("POST", "some webservice", callback).send(formData);
/*
* SOLUTION 1
*/
function callback(file) {
var reader = new FileReader();
@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 / REST.md
Created March 4, 2019 15:33 — forked from chrisnicola/REST.md
Is REST specific to HTTP?

Davy Brion and Jef Claes were discussing whether or not you can have REST without HTTP. Is this another peanut butter and chocolate thing? I think it's hard to extract REST from HTTP because that is how it is defined. I mean quite literally how it is defined in Fielding's dissertation. REST, the term, is short for "representational state transfer" but it still specifically describes an architectural style of representing state transfer via the HTTP specification.

But what if we didn't let such a little thing like semantics get in our way here and only took REST for it's literal name definition and not as the specification laid out in Fielding's dissertation? What if REST only meant a representation of state transfers? I'm not muc