Archives

All posts by peter

In the latest version of PrimeFaces they apparently made the regex validation for “allowTypes” more restrictive.

Previously we had allowTypes="/(\.|\/)(gif|jpe?g|png)$/"

This will allow .gif/.jpg/.jpeg/.png files but not allow .GIF/.JPG/.JPEG/.PNG files.

To remove the case sensitivity you just add the i flag, for insensitivity:

allowTypes="/(\.|\/)(gif|jpe?g|png)$/i"

What is particularly bad about PF 7.0 is that it will allow it to run the uploader as it will pass the first step of the client-side validation, but when it sends to the server it will fail the validation and not alert the user that it failed (!!!), thus making a silent error that will cause users a lot of grief.

The Programmer’s Oath by Robert C. Martin (Clean Coder Blog, 2015-11-18)

In order to defend and preserve the honor of the profession of computer programmers,
I Promise that, to the best of my ability and judgement:

I will not produce harmful code.

The code that I produce will always be my best work. I will not knowingly allow code that is defective either in behavior or structure to accumulate.

I will produce, with each release, a quick, sure, and repeatable proof that every element of the code works as it should.

I will make frequent, small, releases so that I do not impede the progress of others.

I will fearlessly and relentlessly improve my creations at every opportunity. I will never degrade them.

I will do all that I can to keep the productivity of myself, and others, as high as possible. I will do nothing that decreases that productivity.

I will continuously ensure that others can cover for me, and that I can cover for them.

I will produce estimates that are honest both in magnitude and precision. I will not make promises without certainty.

I will never stop learning and improving my craft.

It’s shameful to admit it, but I have known that these are the ethics I should live by, but I often let deadlines, expectations, and laziness come in the way. I hope to work in the next few months to uphold this oath. The hardest part is my tendency to people-please, and my low threshold for the “boring” parts of software development — writing tests, and peer reviews.

I know that logically there are no shortcuts; writing bad code to get a product out ASAP ultimately causes more frustrations and time wasted by myself and others. It is hard for me to fully digest that I will have to slow down in order to save time, but I have seen it happen, literally every day on the job, that fixing a problem in hastily developed code ultimately takes much longer than getting it right the first time.
Just got to remember to breathe every now and then.

I stumbled on this when trying to run the new version of STS (Eclipse) on my work computer, which currently does not have Administrative Rights, yet has Windows 10 “Smart Screen” set to prevent running “unrecognized” applications.

If you try to run an application and the Smart Screen is preventing it from running, right click on the application, click Sent to Compressed File (.zip), then Extract the file and run it. Because Windows Smart Screen sees that you created the .zip file, it will assume that you can trust the contents when you extract it. Replace the original file with this file, and you are off to the races.

YMMV, do not do this at home, or on a computer that you are trusted to protect, etc.

Java MongoDB Collation

Since 3.4, MongoDB now supports specifying collation, which basically means that sorting case insensitive can now be done by the DB natively.

Here’s how to do it in an example method:

public static MongoCursor getDatatableIterator(final String collection, final Bson query, Object sort, final Integer skip, final Integer limit) {
if (sort != null && !sort.getClass().equals(Bson.class)) {
sort = makeSortList(sort);
}
Collation caseInsensitive = Collation.builder().collationStrength(CollationStrength.SECONDARY).locale("en").build();
if (query == null) {
return getDocuments(collection).collation(caseInsensitive).sort((Bson)sort).skip(skip).limit(limit).iterator();
}
return getDocuments(collection).collation(caseInsensitive).sort((Bson)sort).filter(query).skip(skip).limit(limit).iterator();
}

 

Don’t want to have to import your root certificates in Firefox in addition to IE? With this setting you can just set Firefox to use Windows’ native certificate store. I seem to need to do this frequently, with all of my reinstalls of Firefox.

Go to Firefox, type about:config in the address bar and hit Enter, agree to the disclaimer, then search for
security.enterprise_roots.enabled and set it to True.

Recently I found myself migrating, again, my cloud hosting provider.  I like to keep a complete backup of all files so that in case I miss something it’s not forever lost in the ether.

This command comes in handy to rsync everything from one host to a backup location, which I can then use to migrate to the new cloud provider. This command skips the docker device mapper along with the other non-FS files in /dev /proc and /sys. Worked for me!

rsync -av --numeric-ids --exclude='/dev' --exclude='/proc' --exclude='/sys' --exclude='/var/lib/docker/devicemapper/' --progress --inplace --rsh='ssh -p22221' / root@host.petertaylor.me:/backups/backupdirectory

Enabling HSTS and SSL Redirection for Tomcat 9.x

This document details how to enable HSTS and SSL redirection (by default port 80 to 443) on a Tomcat 9.x instance. This will not work on 8.x versions of Tomcat because they changed some of the keywords for some reason.

Enable HSTS

Enabling HSTS (to include maxAgeSeconds = 31536000, includeSubDomains, and preload) requires two modifications of the Tomcat’s conf/web.xml file:
1. First, to enable HSTS support, Continue Reading

Merging directories in command line in Linux is a pain because the native mv command will not allow recursive overwriting.  So if we want to merge two directories, a lot of people like to suggest either using cp or rsync to copy over files and then delete the source files. Another way is to use a shell command to recursively run the move operation on each file in the source directory and mv it to the destination directory/subdirectory. I like this approach more because then you can add in arbitrary rules for which files to copy.
Continue Reading

You can use this SQL QUERY to find all the forms for the entities in your CRM database. If you keep having duplicate Quick Create or Information forms come up, you can just look at this and see which forms have duplicate Type forms.

SQL Query:
USE YOURORGHERE_MSCRM
SELECT form.Type, form.ObjectTypeCode, e.Name, form.Name, IsDefault, form.IsCustomizable, form.PublishedOn, form.IntroducedVersion
FROM SystemForm as form
INNER JOIN Entity e ON form.ObjectTypeCode = e.ObjectTypeCode
WHERE FormPresentation = 1 AND FormActivationState = 1 AND Form.CanBeDeleted = 1 AND form.IsManaged = 0 -- just get unmanaged ones
ORDER BY form.ObjectTypeCode DESC