Categories
Tags
Category Archives: Snippets
Ternary Conditional Syntax in PHP
The below two statements are equivalent. The first uses the ternary syntax and the second uses the more traditional verbose syntax. The condition should be a statement or variable that evaluates to true or false. true will be executed if the condition is met. false is executed if the condition fails. You could argue that […]
Calculating Median and Average w/ PHP
Here’s some handy functions for calculating the median or average of an array of numbers. The median is the number in the middle of an array of numbers, or when the number of items in the array is even, the median is the average of the two numbers that straddle the middle. The below was […]
All About $PATH
When issuing commands from a shell, the system will check for programs in the directories listed in your $PATH variable. Multiple paths are the norm, and each should be divided with a colon. Earlier directories will be searched before whatever follows. Here’s an example $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin To see what’s currently in your $PATH variable Adding […]
Multi-Dimensional Array/Object Sort
I can never remember exactly how to accomplish this yet I need it all the time. This makes use of usort and a custom comparison function
Combine commits with Rebase – squashed!
If you commit often while deep inside a coding tornado, that’s great, but you should clean up after the whirlwind so that your commits tell a better story. Use an interactive rebase to combine multiple smaller incremental commits into larger ones. This helps swab out the dumb “forgot something” or “code cleanup” commits, and enables […]
MySQL command line cheat sheet
Selecting a database Listing databases Listing tables in a db Describing the format of a table Creating a database Creating a table Inserting one row at a time Retrieving information (general) Fixing all records with a certain value Retrieving unique output records Sorting Date calculations MONTH(some_date) extracts the month value and DAYOFMONTH() extracts day. Pattern […]