Skip to content

Instantly share code, notes, and snippets.

View bbottema's full-sized avatar

Benny Bottema bbottema

View GitHub Profile
@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 / jquery-css.js
Last active May 28, 2018 13:48
jquery plugin that triggers event when a css style property is being changed
/*
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 September 30, 2015 19:20
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
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);
@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) {
@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();