Check if a string exists in Moodle

Posted by & filed under Code Tips.

For a Moodle plugin I’m writing I needed a way to check if a String exists. Normally, if a string doesn’t exist then Moodle just outputs [[missing_string]] (replace missing_string with whatever you’re calling the string) and moves on. But, in developer or debug mode it also displays a stack trace. What I needed was a… Read more »

List files in Linux by date

Posted by & filed under Code Tips.

Not really code, but still something I need often enough to write it down. This command will list all files in a Linux folder sorted by date with the most recently updated files at the bottom. ls -ltrh From the ls man page, here’s what each of the choices do. -l – Uses a Long… Read more »

Run the same command on every line in a file

Posted by & filed under Code Tips.

This snippet will let you run the same command using each line from a file as a parameter. cat filename.txt | while read in; do echo “$in”; done As written it’ll open up filename.txt and echo out every line. Probably not what you want, so replace echo “$in” with whatever command you want to run…. Read more »

Fake cron on XAMPP

Posted by & filed under Code Tips.

This little batch file came about from needing to run a cron job from within XAMPP. Since it’s Windows I could have used a scheduled task, but I don’t have XAMPP running all the time and I wanted a little more control over when it runs. And on this specific project, I’m working on a… Read more »

Create a random string in JavaScript

Posted by & filed under Code Tips.

Found this one on Stack Overflow needing a quick and easy way to create somewhat random strings. If you visit the entire thread where this code was posted there’s a pretty good discussion of how to create random strings using math and date functions.

Filling ArrayList with one line, sort of

Posted by & filed under Code Tips.

As a follow up to an earlier post on double braces in Java, came up with a short, but ugly way of filling an ArrayList via an array. Of course, at that point you might as well just do this.

Read a file into a String with one line

Posted by & filed under Code Tips.

This is one of those that I never remember, but use a lot whenever I want to pull an entire file into a String quickly. \\A is the start of the file, so Scanner is going to try and split on the beginning of the file. Since there’s only one beginning, there’s only one next.

Sort get_users by last name

Posted by & filed under Code Tips.

Not sure why, but it looks like sorting on last name and first name is not built into the WordPress get_users method. Seems like it would be a pretty basic need, but it’s not there. So, it’s on to PHP to make it happen. This bit of code assumes that $user_list has already been filled… Read more »