View the code on Gist.
Posts Categorized: 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 »
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 »
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 »
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 »
Fighting against an issue with the sendmail queue getting filled with junk I needed a way to delete a folder full of messages, and there were too many for rm to delete. A post on Stack Overflow had the solution. Only thing I added was the -v option to rm so that it displays the… Read more »
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.
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.
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.
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 »