Quick Tips

Automating MySQL Database Backups on the Command Line via mysqldump

Are you tired of manually running backups when you remember to?

If you are running your own server, or have access to the shell and cron jobs this tip is for you!

First off for a better understanding of mysqldump check out the MySQL reference manual. All mysqldump really does is output the necessary queries to rebuild your database to the current state it is at when run.

First I’m going to create a test database and some tables as examples:

› Continue reading

Tags: , , , , ,

Apache: How to redirect all root domain traffic to www subdomain

Problem: Traffic comes to http://aknosis.com/something/ but they really need to go to http://www.aknosis.com/something/.

Solution: 301 Redirect via Apache with mod_rewrite.

Simple easy addition to your httpd.conf or .htaccess, I placed mine right above my wordpress mod_rewrite rules. If you are using .htaccess just dump it in that file above the wordpress redirect, if you having your rewrite rules in your httpd.conf then it needs to go inside the container:

<Directory /www/mydir/>
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www\.aknosis\.com$ [NC]
        RewriteRule ^(.*)$ http://www.aknosis.com/$1 [R=301,L]
#Wordpress Here
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
</Directory>

Breakdown:

RewriteCond %{HTTP_HOST} !^www\.aknosis\.com$ [NC]
If the HTTP_HOST header doesn't equal www.aknosis.com then :
RewriteRule ^(.*)$ http://www.aknosis.com/$1 [R=301,L]
Use the rewrite rule to push the request to http://www.aknosis.com/
^ - Beginning of request uri
() - Means group this into $1
$ - End of request uri
http://www.aknosis.com/$1 - Rewrite to this ($1 = the request uri)
[R=301 - Use a 301 Redirect
,L] - Make this the final rewrite rule and go

Try it out, go here (http://aknosis.com/) and you end up here (http://www.aknosis.com/). You can see the actual redirect in firebug’s net tab:

firebug-redirect

Tags: ,

Thursday, October 22nd, 2009 Apache, Linux, Quick Tips, System Administration No Comments

Fun with jQuery – Checkboxes!!!

Another day with jQuery, this time we are talking about checkboxes. Just like I stated in my previous post about select boxes, jQuery and checkbox integration, if you will, isn't cut and dry but damn near close. So how can jQuery assist with checkboxes? Lots of ways, here are a few examples to keep you entertained. Try and manually select a checkbox and it will still toggle them correctly (turn them off it they are on and vice versa). [inline] [/inline]

jQuery selector for checkboxes

Just like any input you can choose your checkbox(es) with any standard selector.
  • By Class
    //Selector
    $('.cb_class')
    
    <!-- Input Html -->
    <input type="checkbox" class="cb_class" />
    
  • By Id
    //Selector
    $('#cb')
    
    <!-- Input Html -->
    <input type="checkbox" id="cb" />
    
  • By tag and attribute
    //Selector
     $('input[type=checkbox]')
    //Note: This would select all checkboxes
    //(same code in the Toggle Checks button above)
    
    <!-- Input Html -->
    <input type="checkbox" />
    
  • By tag and attribute
    //Selector
    $('input[name=checkBoxname]')
    
    <!-- Input Html -->
    <input type="checkbox" name="checkBoxname" />
    
› Continue reading

Tags: , ,

Saturday, October 17th, 2009 JavaScript, Programming, Quick Tips, jQuery No Comments

More jQuery Fun – Auto Populating a Select Box

Problem: You want to dynamically populate a select box and you don't know how. Solution: Easy, I will show you. First off, I lied there is no built in way in jQuery (why?, I don't know) to automatically populate a select box. But it actually is very easy. There are plenty of methods to accomplish this but I like to do it this was because utilizes the Option object and it doesn't require html string concatenation.

The basics

Example 1: Here is the code for the onlick event of that button: › Continue reading

Tags: ,

Thursday, October 15th, 2009 JavaScript, Programming, Quick Tips, jQuery 3 Comments

Fun with jQuery – toggle() – Easy tips to visually enhance your website

Here's a quick tip to add some cool effects with jQuery that require very little code to implement. In this example I'm going to so how use of the toggle function can make the simplest functionality and jazz it up.

.toggle()

In a nutshell, the toggle function will call the show() function if your element isn't visible and the hide() function if it is.
  • Hamburger
  • Philly Cheese Steak
  • Taco
  • Pizza
  • Something else greasy and unhealthy
<input onclick="$('#preview1').toggle();" type="button" value="Toggle My Menu" />
So as expected, clicking the button will toggle the menu. Now lets get a little more flashy: › Continue reading

Tags: ,

Wednesday, October 14th, 2009 JavaScript, Programming, Quick Tips, jQuery 1 Comment

Optimizing Website Peformance with a CDN (jQuery)

If you want to increase load times for your site a good way is to serve your resources (js/images/css) from different hosts. Even better is to use a CDN (Content Delivery Network) that has edge locations, see Amazon's CloudFront,  that will serve those resources from hosts that are nearest to your viewers.  If it is logistcally possibly for your needs and its free is there any reason not to? Yes. Specifically if you use jQuery on any of your sites more than likely you serve it with every page on your site, so if you want to have one less request for every page just use a free CDN to host it:  GoogleMicrosoft A recent blog post @ elijahmanor.com explains more why you would want to do such a thing. However, a commenter on that blog post has a good point... If I point my jquery resource at one of these cdn's how do I know that the files are being served since it is all client side? What's worse is how much functionality is broken if jquery is 404'd from that CDN? Well here's a little trick that you can use verify that jQuery is loaded and how to handle it if not: › Continue reading

Tags: ,

Friday, October 2nd, 2009 JavaScript, Programming, Quick Tips No Comments

Quick Tip: Managing Linux Processes

Quick tip on managing linux processes, I always end up asking myself this and having to research how to do such things. So here are some quick tips to help you manage your linux processes. This is all done in bash, I'm not sure what is different with the other shells so ymmv. Here is my sample script, just something that doesn't end right away so I can use it for proof of concept:
#!/bin/bash
while [ 1 ]
do
        date
        echo "Sleeping 5 seconds"
        sleep 5
done

Sending a process to the background

› Continue reading

Tags:

Thursday, May 14th, 2009 Linux, Quick Tips, System Administration No Comments

Powered by Twitter Tools