<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='/path/to/your/jquery' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Thursday, November 15, 2012
Use jQuery CDN with fallback
Use jQuery from CDN, because it is usually cached.
Always use fallback (Sometimes Google fails).
Wednesday, November 14, 2012
Adding Apache modules
The following may work to enable modules without editing any files:
a2enmod modulename
For example, this module is used for Clean URLs(Good for Drupal):
a2enmod rewrite
Remember to restart Apache:
service apache2 restart
Simple Menu with HTML, CSS & jQuery
Here we have a simple menu and CSS Sprite styling example.
HTML:
CSS:
/* Custom Menu */ ul { list-style-type: none; } ul#nav li, ul#nav li a { background: url('../images/oldmenuexamplesprite.png') no-repeat left top; height: 31px; } /* We give the
and the sprite as the background and set the button dimensions */ ul#nav li { float: left; border: 0px solid #243e3b; border-left: none; } ul#nav li a { display: block; text-indent: -9999px; } ul#nav li.info a { width: 93px; } /* Here we set the button widths. */ ul#nav li.updates a { width: 111px; } ul#nav li.media a { width: 83px; } ul#nav li.downloads a { width: 138px; } ul#nav li.forums a { width: 140px; } ul#nav li.info a { background-position: 0px 0px; } /* Here we set the background/sprite position */ ul#nav li.updates a { background-position: -93px 0px; } ul#nav li.media a { background-position: -204px 0px; } ul#nav li.downloads a { background-position: -287px 0px; } ul#nav li.forums a { background-position: -425px 0px; } ul#nav li.info a:hover { background-position: 0px -34px; } /* And now the hover background-position position */ ul#nav li.updates a:hover { background-position: -93px -34px; } ul#nav li.media a:hover { background-position: -204px -34px; } ul#nav li.downloads a:hover { background-position: -287px -34px; } ul#nav li.forums a:hover { background-position: -425px -34px; }
jQuery:
(function ($) { /* Needed for Drupal 7 */
$(document).ready(function(){
//Set the anchor link opacity to 0 and begin hover function
$("ul#nav li a").css({"opacity" : 0}).hover(function(){
//Fade to an opacity of 1 at a speed of 200ms
$(this).stop().animate({"opacity" : 1}, 200);
//On mouse-off
}, function(){
//Fade to an opacity of 0 at a speed of 100ms
$(this).stop().animate({"opacity" : 0}, 100);
});
//Add more jQuery functionality here...
});
})(jQuery); /* Needed for Drupal 7 */
How to center an image with CSS
How to center an image with CSS:
img.center {
display: block;
margin-left: auto;
margin-right: auto;
}
Adding per-user web directories with Apache
Open Apache2 config file:
sudo nano /etc/apache2/apache2.conf
Add these lines in the end, change *your_username* to yours:
# UserDir #
UserDir public_html
UserDir disabled
UserDir enabled *your_username*
Options Indexes FollowSymLinks -MultiViews AllowOverride None Order allow,deny Allow from all
Make symbolic links for mod_userdir to enable it:
cd /etc/apache2/mods-available/
sudo ln -s ../mods-available/userdir.conf
sudo ln -s ../mods-available/userdir.load
Or enable the module without editing any files:
a2enmod userdir
Remember to restart Apache:
service apache2 restart
Sunday, November 11, 2012
Linux permissions for www-pub group
Create a new group (www-pub) and add the users to that group:
groupadd www-pub
usermod -a -G www-pub usera ## must use -a to append to existing groups
usermod -a -G www-pub userb
groups usera ## display groups for user
Change the ownership of everything under /var/www to root:www-pub
chown -R root:www-pub /var/www ## -R for recursive
Change the permissions of all the folders to 2775
chmod 2775 /var/www ## 2=set group id, 7=rwx for owner (root), 7=rwx for group (www-pub), 5=rx for world (including apache www-data user)
Set group ID (SETGID) bit (2) causes the group (www-pub) to be copied to all new files/folders created in that folder. Other options are SETUID (4) to copy the user id, and STICKY (1) which I think lets only the owner delete files.
There's a -R recursive option, but that won't discriminate between files and folders, so you have to use find, like so:
find /var/www -type d -exec chmod 2775 {} +
Change all the files to 0664
find /var/www -type f -exec chmod 0664 {} +
Change the umask for your users to 0002
The umask controls the default file creation permissions, 0002 means files will have 664 and directories 775. Setting this (by editing the umask line at the bottom of /etc/profile in my case) means files created by one user will be writable by other users in the www-group without needing to chmod them.
Test all this by creating a file and directory and verifying the owner, group and permissions with ls -l.
Note: You'll need to logout/in for changes to your groups to take effect!
Note: Add the following line to /etc/pam.d/login to set the user specific
umask at login:
session optional pam_umask.so umask=0022
Disable SSH Reverse DNS Lookup
If not disabled, SSH server will try to do a slow reverse lookup of the IP address of the client causing for an unnecessary delay during authentication. I often have this case after installing Linux.
To disable it, in the file /etc/ssh/sshd_config add the line below:
To disable it, in the file /etc/ssh/sshd_config add the line below:
UseDNS no
Subscribe to:
Posts (Atom)