Posts Tagged programming
📅 April 26, 2017
What if we want to grab an integer, say, from 1 to 25 inclusive?
We can do this easily by modifying the random result to our liking.
📅 September 24, 2016
In PHP, we can use php_uname to grab information about the operating system that the server is running on.
echo php_uname(‘s’) will give the name of the OS, but this is a general name. When executed from a server running Xubuntu, it returns the string “Linux.” Is this Ubuntu, Kubuntu, Xubuntu, Linux Mint, or…what?
What if we want to get the specific Linux distribution? Is this possible from PHP without performing host OS system calls or executing Bash scripts? Yes.
📅 February 4, 2016
Using a similar technique as the random text PHP code, here is a simple code snippet that chooses an image file at random and displays it in a browser.
By moving the code to the server side, a random banner image (or any kind of image) will appear in order to add freshness to a page.
📅 February 3, 2016
Here is a simple but fun PHP code snippet that displays one of several text strings chosen at random to add an element of surprise to a page.
First of all, a working PHP server is required in order to process PHP scripts. This could be a virtual machine using VirtualBox, for example, or something else on any platform. This short tutorial assumes that you have one set up and working.
For example, if there are 3 duplicate items in a list of 10, then there is a 3x probability of obtaining that particular item compared to a single occurrence of that item in the list.
The idea is that by eliminating the duplicates, all items should have an equal chance of being chosen. Here is one strategy to achieve this using a set.
Using bash’s built-in pattern matching ability, we can write a simple script that changes filename extensions. Suppose we have a directory containing over 5000 PNG images, but all image file extensions are mislabeled as .BMP. We want all files to have the .png extension.
Here is a basic script to rename all of the files.
Learning a programming language is rewarding and easier than you might think. If you are new to programming and wish to learn, here are a few tips that help make the learning process more enjoyable and less daunting.
Read the rest of this entry »