Skip to content

Instantly share code, notes, and snippets.

Benny Bottema bbottema

Block or report user

Report or block bbottema

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bbottema
bbottema / openssl-cheat.sh
Created Jun 25, 2019 — forked from alvarow/openssl-cheat.sh
OpenSSL and Keytool cheat sheet
View openssl-cheat.sh
# 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 / MimeType.java
Last active Jul 20, 2019
Mimetypes compiled from two big public lists
View MimeType.java
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 / REST.md
Created Mar 4, 2019 — forked from chrisnicola/REST.md
Is REST specific to HTTP?
View REST.md

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

@bbottema
bbottema / example.sh
Last active Dec 4, 2018
Truncate GIT history
View example.sh
# <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 / Dijkstra.java
Created Sep 6, 2018
Minimal Dijkstra Java (uses Lombok)
View Dijkstra.java
// cleaned up generics version of Baeldung's Dijkstra (https://www.baeldung.com/java-dijkstra)
public class Dijkstra {
public static <T> void findShortestPathToAllOtherNodes(Node<T> startingPoint) {
startingPoint.setCost(0);
Set<Node<T>> settledNodes = new HashSet<>();
Set<Node<T>> unsettledNodes = new HashSet<>();
unsettledNodes.add(startingPoint);
@bbottema
bbottema / index.html
Created Jun 7, 2018
Console log to HTML
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Log to HTML</title>
<link rel="icon" href="data:;base64,=">
<script>
(function(eleLocator) {
fixLoggingFunc('log');
@bbottema
bbottema / List 2 Pairs
Created Oct 23, 2017 — forked from ktejnora/List 2 Pairs
Java 8 Create list of pairs from List of items. Java does not have Pair and groupBy uses AtomicInteger trick.
View List 2 Pairs
package cz.tejnora.pokusy;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@bbottema
bbottema / PizzaSorter.java
Last active May 23, 2018
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/
View PizzaSorter.java
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 / jquery-css.js
Last active May 28, 2018
jquery plugin that triggers event when a css style property is being changed
View jquery-css.js
/*
Usage:
$ele.on('style', function(e, prop, value) {
if (prop == 'left') {
console.debug('new value for left: ' + value);
}
});
*/
// This plugin also throws events for individual style properties incase the entire 'style' attribute is removed
(function() {
@bbottema
bbottema / Express with multipart-form-data file upload and read back to client
Last active Sep 30, 2015
A complete Express 4 example using multer to read multipart/form-data png file upload and reading the file back to the client as binary data
View Express with multipart-form-data file upload and read back to client
var express = require('express');
var busboy = require('connect-busboy'); // middleware for form/file upload
var fs = require('fs');
var app = express();
app.use(express.static('./public'));
app.use(busboy());
app.post('/testFormDataBinary', function(req, res) {
req.pipe(req.busboy);
You can’t perform that action at this time.