| BradTrupp.com - Little slices of my life and my projects | BradTrupp.com -- Pages |
| ||
BradTrupp.com -- Pages -- Page 4 - 2007/09/23 - 2007/11/17
Page 4 - 2007/09/23 - 2007/11/17 One Line Template Engine (PHP) (2007/11/17) A One Line Template Engine in PHP This is a really clever example of using a single line of PHP to fill in a HTML template and output a web page. I found the original in the forums at http://www.webmasterworld.com/. The one line engine --
It works by finding any string starting with an opening brace and ending with a closing brace and substituting the php variable with the same name. An example of the template file -- template.tpl -- as used for this example.
This template has three variables defined -- {title}, {header}, and {text}. Using the template engine in its simpliest form.
Elegantly simple? Bash - A Basic Greeting Program. (Bash) (2007/10/31) This is a basic Bash shell program to greet you with short message based on the time of the day.
Save the script as greetings.sh. To run it, you would open a terminal session, change to directory where you saved the scripts, and enter the command as shown below.
Depending on the time of day, you should be greeted with Good Morning, Good Afternoon, or Good Evening. Date Tips The first line to get the hour will seem a little strange.
What is happening is that you are running the date command with the optional format specifier. The format is "date [OPTION]... [+FORMAT]" where date is the command and "%H" means format the results as an hour in 24 hour format. The result of the date command gets saved as the value of the variable hour.
Prevent Automatic Resizing of Images (Firefox) (2007/10/23) Firefox, by default, resizes large images to fit in the browser window. This is usually a good thing but there are a few of use who want to see the image in the correct size the first time. You can test automatic resizing in action by going over to a popular site for wallpapers like InterfaceLift.com and looking at some large sized wallpapers. Entering the New Setting Start Firefox. Click on the address bar or press Ctrl-l to place the cursor on the address bar. Enter about:config and press enter. The configuration settings page displays. Find the browser.enable_automatic_image_resizing parameter and double-click on it to set it to false.
Note that the status field changes from default to user set and the line becomes bolded.
Finally Now restart Firefox and see your images in the original sizes. Boot into Safe Mode (Windows XP) (2007/10/11) Windows XP - Boot into Safe Mode What is Safe Mode Windows Safe Mode is an optional way to boot your Windows operating system to run administrative and diagnostic tasks. In safe mode, the operating system loads only the bare minimum of software that is required for the operating system to work -- including very basic video drivers -- so your programs may look rather different from normal. This mode of operating allows you to troubleshoot and run diagnostics on your computer - for example - to help detect and remove spyware and viruses. Use the System Configuration Utility method Close all open programs and processes. Click Start. Select Run. Enter MSCONFIG in the text box and click OK. The System Configuration Utility will appear, Select the BOOT.INI tab. Check the "/SAFEBOOT" option and then click OK.
![]()
Restart your computer when prompted. You should be automatically booted up into safe mode. When you are done with troubleshooting in safe mode, just repeat the process above but uncheck the "/SAFEBOOT" option instead. If you forget this final step, you will keep rebooting into safe mode over and over again. Use the F8 Key Shut down Windows, and then turn off the power. Wait a few seconds and turn the power back on. Start tapping the F8 key about once per second. The Windows Advanced Options Menu will appear. Some computers display a "keyboard error" message if you begin tapping the F8 key too soon. just restart the computer and try again. Select the safe mode option. Press enter and the Windows should start up in safe mode. When you are done, just shut down Windows as normal. The next time you boot, Windows should restart as normal. The F8 key method also works for other versions of Windows including Windows Vista. Bash - An Introduction to Scripting (Bash) (2007/10/10) Bash is a Unix shell program and is the default shell for Ubuntu, as well as many Linux systems and Mac OS X. A Unix shell, which is commonly called "the command line", provides the traditional user interface for the operating system. You use it by entering commands for the shell to execute, but can also write and execute complex shell programs to do most anything. In Microsoft Windows, this would be equivalent to command.com (or cmd.exe) for the command prompt. A Basic Bash Script It is best to start your Bash script with the "shebang" line -- although it is somewhat optional being the default shell anyway.
Note: The "shebang" (also called a hashbang, hashpling, or pound bang) refers to a pair of characters "#!" that, when used as the first two characters on the first line of a script, causes Unix-like operating systems to execute that script using the interpreter specified by the rest of that line. It is also good practice to end your script with the exit command.
Here is the standard over-used "Hello World" example you see in so many programming languages.
Enter these 3 lines into a file using the text editor of your choice and save it as "helloworld". Bash Comments Comment lines in Bash scripts are similar to other programming languages where a special character, in this case "#" (the hash or pound sign), is used to delimit the start of a comment line.
Make it Executable Until you mark your script as executable, it is nothing more than a text file. The easiest way is to use the chmod command to change the file permissions. Open a terminal session, navigate to the directory that you saved "helloworld" into and enter the command:
Running a Bash Script Once again, open a terminal session, navigate to the directory that you saved "helloworld". If you enter the command
you will likely get an error like "command not found". This is because the default search path for commands does not include the current directory -- so the shell can not find your program. Now enter the command
and your script should run and display the expected "Hello World!" output. The "./" means look in the current directory. You can also fully qualify the script (assuming the script is in freddie's desktop)
and again the script should run. What's Next? Now we are ready to write some useful scripts, but first here are some related web sites.
CSS - A Few Quick Tips (Website Tips) (2007/10/09) Here are a few tips and tricks using CSS or Cascading Style Sheets to put a few special effects on your web pages. Just copy and paste the sample code... Roll-over Color Text Links Your text links will change color as the mouse passes over. Insert this code into the <HEAD> of your document...
Links with no Underline Put this code in the <HEAD> of your document to remove the underline from all links on your page...
Or, remove the underline from individual links like this...
Links with a Line Above and Below This works well as a hover attribute on links, but can also be applied to all of your links. It will show the normal underline plus a line above the link too...
Highlighted Text To highlight important text on your page or just to get words to stand out...
To highlight all links on your page, put this code in the <HEAD> of your document:
Background Images This will create a background image that doesn't repeat...
You can also center the image on the web page...
Disable Blinking Elements (Firefox) (2007/10/05) One of the things that annoys me the most on web pages other than scrolling marquee text is blinking text.
Fortunately, it is a simple change to the Firefox browser configuration to stop the silliness. Entering the New Settings Start Firefox. Click on the address bar or press Ctrl-l to place the cursor on the address bar. Enter about:config and press enter. The configuration settings page displays. Find the entry for browser.blink_allowed and change to false. Fixed! Make the Text Blink!
Now that you know how to make your text blink, please DON'T do it. Thanks. Restore your Database from a Backup (MySql) (2007/09/29) Restore your Database from a Backup
Some time ago, I did an short article on using MYSQLDUMP and CRON to backup databases. Database backups are a good thing to have, but unfortunately someday you might just need do a restore from those backups. Do You Know How? The backups you created using the mysqldump utility earlier simply generate a text file full of SQL commands. For example:
It becomes a simple matter of running MySQL from the terminal session command line and piping the SQL commands into it to recreate the database.
For example:
Test Your Backups Quoting those words from The Hitchhiker's Guide to the Galaxy -- Don't Panic. It is a good idea to try a restore on a test database sometime long before you actually need to do one for real. Nine Random Thoughts on Improving your Web Site. (Website Tips) (2007/09/26) By Brad Trupp (c) 2007 Here are 9 random thoughts on improving your web site --
I hope you find this short list helpful. Feel free to comment below if you are more suggestions on this topic.
Mac Mini HTPC - More Great Software (Apple) (2007/09/23) Mac Mini HTPC - More Great Software
The first 3 parts of this series covered the basics in getting a Mac Mini hooked up and able to play all types of media. There are a number of other features I may get into at a later time, such as TV tuners that plug into the USB port to add PVR functions. However, where I live right now, I get 5 TV stations over the air and none are digital yet, so there is not a lot of value in adding a tuner any time soon. My cable box and a VCR are good enough for now. I also do not know if I want to use iTunes with my music collection or some alternative product like perhaps Song Bird. Players and Content Retrieval
DVD Utilities
Display and Configuration
That other Operating System - Windows Since my Mac Mini sits by my TV and not in my home office, there are a bunch of utilities I use on my XP machine to assist with my media files.
|
|