Barry Bakes
I regret to inform everyone that I am slowing down on the posting on this site. I have a few other projects that are taking precedent to this blog. I will still post here at least one day per week. I do not know which day will be the regular posting day.
I am starting a new blog, BarryBakes.com. There will be all kinds of recipes on that site, not just baking; however, the recipes will be predominately baking recipes. Baking is one of my passions, so I hope everyone will enjoy it.
Wipe & Reload Windows Every 6 Months
Most people think a computer runs slower and slower as it ages. This is entirely false. In fact, with updated drivers for your hardware being released, your computer should run slightly faster as it ages. So, why does your computer slow down? There are many reasons:
- Adware
- Viruses
- Startup Programs
- Uninstalled Programs
- Hard disk fragmentation
The list just goes on and on. Any computer tech can tell you that all of these problems can be handled without formatting the hard drive and reinstalling everything from scratch. I agree, so long as you are willing to spend days, possibly weeks, tracking down that illusive virus and running all sorts of programs to clean the registry, defragment, etc.
There is a quicker and easier way. Wipe & Reload. It may sound scary, but in fact it’s not. Doing this will guarantee there is no virus left lurking on your computer. On top of that, you’ll have a fresh backup of all your files, so if a disaster happens, you’re prepared.
NOTE: I recommend having another computer connected to the internet and a jump drive, so you can download the network drivers in case Windows doesn’t install them by default.
Prep
The first step is to back up all your data. I do not mean creating a full backup of your hard drive. 99% of the files you will want are in My Documents. If you backup everything under “C:\Documents and Settings”, you should be well covered. DO NOT backup the “temp” or “Temporary Internet Files”, as viruses live there and you don’t need anything in those folders.
NOTE: I take no responsibility for lost files you forgot to back up!
The second step is to look in “Add/Remove Programs” and write down anything you want to reinstall.
The third step is to locate your Windows key. This is a 25 character code. It is usually written on a sticker on your computer.
Reinstalling Windows
Once all your data is backed up and you have a list of programs to install, slide your Windows XP CD into your computer and restart. Press any key when it tells you to. Now, go through step by step.
- No, you do not want to recover.
- Yes, you agree.
- Delete the partition.
- Install to the “free space”.
- Format using NTFS. NOT QUICK!
- Let it do it’s thing. It will reboot do not press any key when prompted.
- Enter your code when asked.
- Answer any other questions.
That’s it. Windows XP is now reinstalled.
Installing Drivers
Now, to see what drivers need to be installed:
- Right click on My Computer.
- Click on Manage.
- Click on Device Manager.
Anything with a yellow exclamation point needs a driver. Most manufacturers will offer drivers on their website. I recommend going this route instead of installing them off a disc because driver updates are common and you ever knows how old that driver disc is.
Installing Software
- Install your anti-virus software.
- Install all Windows updates available.
- Install any programs you had that you wanted to keep.
The Data
Special attention is required during this step to keep the viruses and other malware off your computer. Put in each backup CD/DVD one at a time for a virus scan. This may take a while, if you have more than 1 disc.
If there is a virus, the software won’t be able to heal/remove/fix it because the CD/DVD is read-only at this point. Make a note of any file containing a virus. Now, just copy over any file that didn’t make the infected list.
OK, your wipe & reload is now complete. Now, do a few more tweaks to get the most performance.
NOTE: I recommend having another computer connected to the internet and a jump drive, so you can download the network driver.
Recycling Your Old Electronics
We all try to be environmentally conscious, but what do you do with that old TV that stopped working? No, there is no recycle symbol on that TV. That doesn’t mean you should put all that plastic, glass, gold, mercury, copper, silicon, etc. in the landfill.
Odds are that there is an electronics recycling day every 6 or 12 months in the closest major city. You can find out by searching the local newspaper’s website. Usually, the TV news will overlook such valuable information. Here in Augusta, GA, there is one on Fort Gordon, an army base, and another downtown at Fort Discovery, a science museum.
They will take TVs, computers, monitors, keyboards, mice, speakers and stereos. Usually, they will not take stoves, ovens, microwaves, refrigerators, or any other large appliances. Make sure to check what they will and won’t take.
Posted by James Date: Wednesday, October 28, 2009
Categories: Tips
Tags: green, old electronics, recycling
MP3 CDs
OK, so you bought a new CD player and looking at the box, you see MP3 CD. What is an MP3 CD, you ask. It’s just a CD with MP3s on it. No, this is not the same as a traditional audio CD. Let’s look at the differences.
| Traditional CD | MP3 CD | |
| Playtime | 80 Minutes Max | 1450 Minutes Max |
| Bitrate | 1200 Kbps | 64-320 Kbps |
| Number of Tracks | 99 | ????? |
| Embedded Track Info | Yes | Yes |
| Audio Format | WAV | MP3 |
| Burnable | Yes | Yes |
| Computer Playable | Yes | Yes |
To burn an MP3 CD, just put the mp3s directly on the cd. In windows, you can drag the files directly to the CD drive in my computer. Then right click on the CD drive and select “Burn these files…”.
jQuery Intro
jQuery is a very useful javascript library. It provides unified methods to assign event handlers, perform ajax requests, change CSS classes, etc. All of these operations, using jQuery, are performed the exact same way no matter what web browser the end user is running.
Selecting DOM Elements
Before you can do almost anything, you’ll need to select an element to work with. Normally, this is done by by using
document.getElementById('some-element')
But jQuery has an easier way.
$('#some-element')
This does the same thing as the previous example. When using a #, you are selecting by id. This is just like a CSS selector.
Keeping with the CSS selectors, using a period (.) at the beginning selects all elements with that class name. Also, putting an element name selectes that element. Separating selectors with a space, denotes a ancestor/descendant relationship. Separating selectors will a comma, elements matching any of the selectors will be selected.
Event Handlers
Assigning an event handler is a lot easier using jQuery. Once you have selected your element(s), run the function mousedown to add a mousedown event handler. For example,
$('td').mousedown(handler);
Adds a mousedown event handler (handler) to all td elements.
In addition to the ease of assignment, the event object passed to the handler is the same across various browsers. There are a few caveats, but the jQuery crew is working to resolve these.
Manipulating Classes
There are several functions for manipulating classes, including removeClass, addClass, and toggleClass. These are fairly self-explanatory. Running removeClass with no arguments removes all classes from the selected element(s).
Ajax
jQuery makes Ajax very simple. To do a post, all you need is:
jQuery.post('/path/to/post',{data1:'hello',data2:'world'})
Gets are even easier:
jQuery.get('/path/to/get').
That’s jQuery in a nutshell. There is much more you can do with jQuery that wasn’t covered. jQuery has a whole set of UI controls available, but these increase the amount of code & CSS that your end user has to download.
For more information, visit http://www.jquery.org/.
10 Step to Becoming a Worse Programmer
- Code without thinking.
- Believe the first answer you get.
- Use an array as a database field type.
- Create a custom database engine.
- Cram all options in one dialog box.
- Validate data w/o feedback.
- Launch with “Implement this” messages.
- Create a custom application framework.
- Work in only one language.
- Have a negative attitude.
Posted by James Date: Friday, October 23, 2009
Categories: Programming, Tips
Tags: 10 steps, programmer
10 Steps to Becoming a Better Programmer
- Document your code.
- Use a Version Control System.
- Admit that you know nothing of design.
- Understand that functionality doesn’t beat ease of use.
- Test! Test! TEST!
- Indent properly.
- Optimize to out perform.
- Hardcode NOTHING.
- Speak with someone who will use the program 30+ hrs/wk
`grep -i -R 'TODO' *`
Posted by James Date: Thursday, October 22, 2009
Categories: Programming, Tips
Tags: 10 steps, programmer
PVR Cron
For about a year now, I’ve been playing around with my digital tuner card. It wasn’t until I turned off the cable that I have a need to use it. Using some cool linux tools, I’ve made a script to record HDTV broadcasts to my computer. It is a work in progress, but here’s what I’ve got so far.
The Tuner Card
The tuner card is DVB based on a Conextant chipset, so the first step was to get my kernel to make the card usable. A quick check will show if the driver is loaded:
dmesg | grep dvb
The Tools Required
- dvb-atsc-tools
- azap
- ffmpeg
Channel Scan
Scan for channels using:
dvbscan /usr/share/dvb/atsc/us-ATSC-center-frequencies-8VSB > ~/.azap/channels.conf
Edit the file ~/.azap/channels.conf to make sure the channel names are correct. Your base frequencies file may be in a different location, but it is usually under /usr/share.
Iteration 1: Crontab Recording
At first, I used only the crontab to record. Here’s an example:
24 12 * * * /usr/bin/azap -c /home/dvr/.azap/channels.conf -r WRDW-HD
25 12 * * * /bin/cat /dev/dvb/adapter0/dvr0 > /data/dvr/young-restless.mpeg
35 13 * * * /usr/bin/pkill cat
36 13 * * * /usr/bin/pkill azap
37 13 * * * /usr/bin/ffmpeg -i /data/dvr/young-restless.mpeg -s 1024x476 -vcodec libxvid -b 1600000 -acodec copy /data/dvr/y-r-friday.avi
This is a very ugly solution with lots of cracks. For instance, if I were running cat from a console when /usr/bin/pkill cat were running, it would die. Heaven forbid another processes is using cat when that runs. Also, I had to change the name of the ffmpeg output file every day.
Iteration 2: Cronable Perl Script
This script does pretty much the same thing as the above 4 lines in the crontab does. This means you don’t have to write 4 lines in the crontab for each recording, just 1 line. Also, the file name is appended with the date in yyyy-mm-dd format.
#!/usr/bin/perl
#Does someone need a reminder?
if ( $#ARGV != 2 ) {
print “Usage:\n”;
print “record.pl \n”;
exit;
}
#Creates a random 16 character (a-z) string
sub randstr {
my @chars=(‘a’..’z');
my $res = “”;
for(my $i=0;$i<16;$i++) {
$res .= $chars[rand($#chars)];
}
return $res;
}
#Grab the command line args
my ( $channel, $length, $finalFileName ) = @ARGV;
#Temporary mpeg filename
my $tempFileName = randstr();
#Add date to final filename
$finalFileName .= “-”.`date +%Y-%m-%d`;
$finalFileName =~ s/\n//;
#Start Azap in the background
print “Starting azap\n”;
system( “/usr/bin/azap -c /home/barry/.azap/channels.conf -r $channel >/dev/null 2>/dev/null &” );
sleep 5;
#Start cat in the background
print “Starting cat\n”;
system( “/bin/cat /dev/dvb/adapter0/dvr0 > /data/dvr/$tempFileName.mpeg &” );
#Sleep the required seconds for the show to record
print “Recording for “.(60*$length).” seconds…\n”;
sleep 60*$length;
#TODO: Remove pkill, as it may cause problems
print “Killing cat and azap.\n”;
`pkill cat`;
`pkill azap`;
#Resize & Encode to XVID using ffmpeg
#ffmpeg sometimes stops working b/c of bad mpeg data
#TODO: Replace with mencoder
print “Encoding…\n”;
`/usr/bin/ffmpeg -i /data/dvr/$tempFileName.mpeg -s 1024×476 -vcodec libxvid -b 1600000 -acodec copy /data/dvr/$finalFileName.avi`;
#Remove the temporary mpeg file
`rm $tempFileName.mpeg`;
print “Done!\n”;
I know it’s not the most elegant of perl scripts, but it gets the job done. Here’s a sample cron:
25 12 * * * /home/dvr/record.pl WRDW-HD 70 young-restless
As you can see from the TODO comments, I continue to tinker with the script. When I make a good development, I’ll post it. If you have any suggestions, feel free to post a comment or contact me.
Cron Jobs
Cron jobs are the Linux/UNIX world’s scheduler. Many people, myself included, have a hard time understanding crons. After all, setting one up is very simple, if you know what you are doing.
The Crontab
“crontab” is the utility you use to setup a cron job. Type “crontab -e” from the command prompt to edit your list of crons. It’s just a textfile with a special format. Each non-blank line is a cron job. The format of each line is 6 space separated fields. Here is what each field defines:
- Minute
- Hour (Military Time)
- Day of the Month
- Month
- Day of the Week (0 is Sunday, 1 is Monday, etc.)
- Program to run w/any arguments (may include spaces)
The Date/Time fields may be a specific number, a “*” meaning anything, a “*/x” meaning every x hours/minutes/etc., or a comma separated list of any or all of the above.
So, if you wanted a certain program to run every 30 minutes, you could say it any of these ways:
*/30 * * * * /path/to/program arg1 arg2 0,30 * * * * /path/to/program arg1 arg2 12,42 * * * * /path/to/program arg1 arg2
Use Absolute Paths
If you are writing a script to run as a cron, you must make sure your script uses full paths or it will throw an error. Yes, the script will execute without error when run from the command line, but the cron will crap out.
Examples
0 2 1 * * /home/apache/rotate-logs.sh
Runs the rotate-logs.sh script the first of every month at 2AM.
0 17 * * * /home/oddjob/send-margarita-time-email.sh
Runs the send-margarita-time-email.sh script at 5PM every day.
0 17 * * 1,2,3,4,5 /home/oddjob/send-margarita-time-email.sh
Runs the send-margarita-time-email.sh script at 5PM Monday – Friday.
0 4 * * 1 /usr/sbin/mysql_dump > /backup/mysql/backup-`date "+%Y-%m-%d"`
Performs a weekly backup of the mysql database Mondays at 4AM.
0 0 1,15 * * /home/accounting/payroll.pl
Runs payroll.pl on the first and fifteenth of every month at 12 midnight.
Points to remember
- Use full paths in scripts
- The crontab is only for the current user
Minify the Web
Most websites are built for high-speed internet connections, even though there are plenty of people still on dial-up. There are many ways to make your site work much faster for all your users, dial-up and high speed alike. When a site is optimized, users are more likely to stay on the site longer and keep coming back for more.
Utilizing the browser’s cache
The browser’s cache can kill a lot of communications between the browser and the web server. To take advantage of the cache, you should limit the amount of data & code in the HTML. When a file is in the cache, the browser asks the server to send the page if it’s been modified since a certain date/time, if the browser does that.
Step 1: Use a stylesheet
Moving the style information into a stylesheet is priority #1. If you have 1500 bytes of style info inside the HTML doc and a user, on average, views 5 pages, that’s 7.5KB (3 seconds on dialup) per visit. Moving that data into a stylesheet means that the user only downloads the stylesheet once.
Step 2: Make javascript external
Just like a stylesheet, doing this will save time by utilizing the browser’s cache. Also, remove any duplicate javascript.
Minifying the javascript file is like compressing it. You can do this by hand or use one of the many tools available for free on the web. Remeber to test the minified code. A warning: DO NOT DELETE YOUR ORIGINALS. If you do, you’ll wish you hadn’t when it comes time to upgrade or fix a bug.
Step 3: Make use of CSS sprites
If you have 15 images that are on every page, that’s 15 files to download or 15 files to check for modification. Merging those 15 images into 1 larger image is fairly easy using GIMP or Photoshop. Once that is done, setting up the CSS sprites can be easy or difficult depending on how your HTML is setup.
A CSS sprite is a CSS background image using the height, width, background and background-position CSS attributes. If the image is a link, you’ll need to make a transparent image to place inside the link.
Step 4: Compress your images
This is, perhaps, the quickest and easiest way to speed up your site. GIMP and Photoshop allow you to set the compression level when saving the jpeg/gif/png. I’d suggest using 75% to 85% quality, but every image is different. You’ll have to play around with the setting a bit.
Step 5: Rework the HTML
Removing excess white space is one way. You can also rename CSS classes and element ids to a single letter, and remove any unneeded attributes altogether. This step is the most time consuming.
Other Considerations
Use only 1, 2 max, domain name(s) (www.example.com) not counting any ads/analytics you have as DNS lookups can be slow. Also, move Google Analytics and any other non-essential javascript to just before the closing body tag, that way your site shows up before the 1-5 seconds wait for that javascript.
YSlow Firefox Extension
IMO, this is the best extension for optimizing a website. It gives you a letter grade and detailed information on how to improve your score. It does require Firebug, so make sure that’s installed first.
Happy Optimizing.