Bash loop through folders recursively and lower case files

This script will loop through all files and folders recursively and make them lower case. Please do not just blindly run this against your intended directory. The echo is there for testing and once you know that works then use the mv command

You can perform any command you’d like after the tr. In my case it’s replace all upper case letters with lower case ones.

If you don’t include the if statement, you’ll get a warning message if it tries to rename to the same case, so that keeps the console clean.

find /home/buschm3/bananas -depth -name '*' -print0 |
while IFS= read -r -d '' src; do
    dst=`dirname "${src}"`/`basename "${src}" | tr '[A-Z]' '[a-z]'`
    echo "$src"
    echo "$dst"
    if [ "${src}" != "${dst}" ]
    then
        #mv "$src" "$dst"
    fi
done

read more

Current request is not of type HttpServletRequest

Ran into this error this week

There was an unexpected error (type=Internal Server Error, status=500). Current request is not of type [org.apache.catalina.servlet4preview.http.HttpServletRequest]: ServletWebRequest: uri=/my/url/

Make sure you imported the correct HttpServletRequest import. I wanted import javax.servlet.http.HttpServletRequest;

read more

Filtering FiveThirtyEight's NFL Forecasting Leaderboard

A group of friends and I have a contest going on FiveThirtyEight’s NFL Forecasting Game Leaderboard and they don’t allow group functionality, so at the end of each week I Ctrl + F on the page to find each of our name’s and update a spreadsheet. Instead of spending 3 minutes once a week I decided to spend 15 minutes and write something that will do it for me.

Just replace the names array with a list of the names in your group

var table = document.getElementById('leaderboard-table-wrap').getElementsByTagName('tr');
Array.from(table).forEach(function(item) {
  var names = ['Matt Busche', 'Random Dude'];
  if (names.indexOf(item.getElementsByClassName('name')[0].textContent) === -1) {
    item.closest('tr').remove();
  }
});

As always you can use a Bookmarklet Creator to add this as a “bookmark” on your address bar to make filtering super easy.

Note: If you can’t find a person, each person needs to acknowledge that they want to publically post their score by visiting the leaderboard page and clicking a link.

read more

Finding md5 hash of file

Fun tip I learned today. If you need to find the md5 hash of a file you can simply user the following command.

certutil -hashfile {path+filename} md5 

certutil is included in windows by default, so you aren’t required to have anything additional installed.

read more

Angular Loading JavaScript file in different environments

If you ever need to load two different files in production vs test, you can add some code to your main.ts file in your Angular project. The existing code includes the if statement and enableProdMode(), but you can easily add in the else to conditionally load a different file. In my case I don’t want google analytics posting to my production account.

import { environment } from './environments/environment';

//create a new element
const script = document.createElement('script');
if (environment.production) {
    enableProdMode();
    script.src = 'analytics.js';
} else {
    script.src = 'test-analytics.js';
}
//append that element into the dom
document.head.appendChild(script);

read more