Sunday, January 19, 2014

// // Leave a Comment

Social CSS Snippets and Ideas – Live Editable Examples

We all know the importance of Social networks, almost every website today has some sort of social media share or like button.
In this post, i will share some interesting social CSS code snippets that i have gathered or made myself. You can use them as a starting point to make your own. Some of them are animated using CSS3, others are just buttons or icons. They are easy to customize and you can play with them directly. I hope you will  find them useful and enjoy them as much as i did. let the ideas flow !

CSS Live Editable Examples

All of the examples below are hosted on codepen, feel free to customize them to suit your needs.

Social CSS Snippet – example 1

Social CSS Snippet – example 2

Social CSS Snippet – example 3

Social CSS Snippet – example 4

Social CSS Snippet – example 5

Social CSS Snippet – example 6


Social CSS Snippets and Ideas – Live Editable Examples


If you like those examples -share them !
Read More
// // Leave a Comment

Simple & Cool Live Examples of Image on hover Css effect

We will be playing with Image on hover effects using CSS  and One image only. I’ve created four simple examples that will work in all  browsers and another six cooler ones that will work only on webkit browsers.
They are all hosted on Codepen so you can directly play with the code and learn in the process. I  didn’t  even make any extra div to confuse you – all the images are in their main IMG tag. I’ll try to keep it short and sweet so you can absorb it even if you never touched CSS before.
In all the examples below we use this two simple things :
For CSS
img {here is the code of the initial state of the image}
and
img:hover { here is the code of the hover state of the image}
For HTML
 src="http://link to the image">
This extra div below ↓ is used  to center things on the Screen JUST IGNORE IT
style="text-align:center">
The first four live examples will work in all the modern browsers
box shadow browser support 
Lets get this party started…
Simple & Cool Live Examples of Image on hover Css effect

Shrink Image on hover

In this example we have  :hover  using height and width to change the size of the image, by adding  transition: all 1s ease;  to img we  make that change  from bigger- to smaller look smooth, changing the 1s  to 1,1s will make the transition last longer and setting it to 0,9s will make it last shorter.

Enlarge Image on hover

In this example we just change the  height and width to be bigger rather than smaller. Compare the css with the first example above and you will understand what i mean.

Rotate Image on hover

In this example we have transition again but this time in  :hover instead of the image size we have  transform: rotate(360deg); which does exactly what it says – it rotates the image 360 degrees.

Tilt Image on hover

In this example the  360 is changed to 15 degrees so it just tilts a little bit.
Simple & Cool Live Examples of Image on hover Css effect

Now for the webkit browsers the effects are much more interesting, yet also very simple to create

Blur Image on hover

Again in the img we use the transition but this time in the :hover we have added a filter -webkit-filter: blur(5px); changing the 5px to more or less will change the blur strength.

Decolorize Image on hover

This time the filter is  -webkit-filter: grayscale(100%); again setting the100% to less will change the effect

Darken Image on hover

Here we have  -webkit-filter: brightness(100%); in img again as initial state and than by adding  -webkit-filter: brightness(0%); to :hover we trigger the change. and of course again you can set up the filters % to your needs.

Hue-rotate Image on hover

In this cool example we have added the filter -webkit-filter: hue-rotate(333deg); 


Drop shadow Image on hover

For drop shadow we use -webkit-filter: drop-shadow(10px 7px 1px grey)

Opacity Image on hover

In this last example we have  -webkit-filter: opacity(0.3); as a filter.
And that concludes my Image on hover Css effect article.

I suggest that you bookmark this page and use it as a starting point anytime you wish to practice and experiment.

You can also check some other cool stuff that i have about CSS.
If you like this article please be kind to share it on your favorite social networks below.
Read More

Tuesday, October 22, 2013

// // Leave a Comment

How To (Automatically) Backup Your Website Into Dropbox or Copy.com

As owners of websites, one of the more important things you should do is to regularly backup the website. Most web hosting providers will enable daily or weekly backups, mainly for their disaster recovery purpose only. If you want to personally oversee a backup of your website, you can do it by yourself using the Backup function in hosting control panels like cPanel, Plesk and DirectAdmin. As a webmaster or domain owner, you are responsible for this task.
A good backup should have following criteria:
  • Backup your data as frequently as possible.
  • Give higher priority to critical data like database and web contents. Try to exclude temporary files.
  • Your backup should NOT be saved inside the same server.
  • Your backup should be retrievable and accessible anytime, anywhere.
  • You should get notified for every backup status which has been scheduled.
  • Your backup should be compressed, if disk space or bandwidth is your concern.
It is good if you can have your one FTP server to store backup remotely. But, what if the FTP server is down? How can we automate the backup task with limited access to the server? How can you be sure that the availability is always there? Cloud storage is your answer.
Cloud storage is becoming the best way to store files. Popular providers like Amazon S3, Dropbox, iCloud and Box.net are offering these facilities for free with some limitations. But, none of them are supporting FTP as the medium to transfer while almost all of webhosting providers only allow this transfer method.
Here’s where Backup Box/Movers.io comes in. Backup Box helps you securely transfer anything on an FTP server to your Dropbox account. Actually, Backup Box can integrate your FTP account with cloud storage providers like Amazon, GitHub, Box.net and Flickr as well. At this very moment, only Dropbox integration is supported while the others are still under development. It is free to use, with limited features like monthly backup schedule and immediate transfer schedule. In this post, I am focusing on preparing the backup data for weekly backup while running on cPanel server.
Backup Box
We can use this tool with various ways of implementation such as 1, directly copying the web directory using FTP and transferring to Dropbox (compressed or uncompressed) or 2, creating a compressed backup (cPanel backup) and using FTP to fetch the backup to Dropbox.
Before we proceed with the tutorial, ensure that you have following required information:
  • An FTP account which is mapped to your web directory. Get it from your hosting control panel.
  • A Dropbox account. You can register here for free
  • Or A Copy account. You can register here for free. (Recommended)
  • A Backup Box account. You can register here for free or movers account at http://movers.io/.

Web Directory > FTP > Dropbox

Since the database is also important, we need to prepare the database backup and put it into our web directory. If you are running on Linux hosting, you can use a task scheduler called a cron job with some help from mysqldump. In cPanel, it is located under cPanel > Advanced > Cron jobs.
Let’s use the following data as an example:
  1. Web directory path: /home/username/public_html  
  2. cPanel username: mycpanel  
  3. cPanel password: mypass123$  
Create a new weekly cron job and use the following command:
  1. mysqldump --opt -Q -u mycpanel -p'mypass123$' --all-databases > /home/username/public_html/databases.sql  

Here’s An Example:

This will create an SQL backup file which includes all the databases under your cPanel account. Login into Backup Box. On the left panel, login into the FTP account by clicking the ‘gear’ icon. On the right panel, login into your Dropbox account.
You can choose Transfer public_html as a folder in the Transfer Options. This will transfer the whole public_html folder including all files into your Dropbox account. You can now start the immediate transfer by clicking Review. This will transfer the public_html folder to Dropbox. Once done, you can create Monthly schedule to automate this backup task monthly. Just click Monthly > select Date and Time > Finalize and Run. Note: If you want to use weekly or daily backup, you need to upgrade your subscription as stated in the website. Do not forget to change the cron job setting based on when you want the backup schedule to happen

CPanel Backup > FTP > Dropbox

The good thing about cPanel is you can generate your own backup automatically using cPanel API. In this case, we will use PHP script to run on schedule to generate backup. Since the backup location needs to be exclusively for Backup Box, we will need to create an FTP account which is mapped to a new backup folder.
Go to cPanel > FTP and create an FTP account as the screenshot below. Do not create the FTP directory under public_html because it is accessible publicly via web browser (unless you protect the directory with a password):
We need to use PHP with cPanel API to trigger the backup process. Download this file (cpanel-php-backup.zip) and unzip it. You should see 2 files, cpanel-backup.php and xmlapi.php.inc. Change all required information inside cpanel-backup.php as below:
  1. // Credentials for cPanel account  
  2. $source_server_ip = ""; // Server IP or domain name eg: 212.122.3.77 or cpanel.domain.tld  
  3. $cpanel_account = ""; // cPanel username  
  4. $cpanel_password = ""; // cPanel password  
  5.   
  6. // Credentials for FTP to Backup Box  
  7. $ftpacct = ""; // FTP account  
  8. $ftppass = ""; // FTP password  
  9. $email_notify = ''; // Email address for backup notification  
Save the file and upload both files into your public_html directory using FTP. You can start to generate a backup by accessing the PHP file directly via browser, which is usuallyhttp://www.yourwebsite.com/cpanel-backup.php .
In order to automate cPanel backup creation, we need to setup a weekly cron job into cPanel and use following command:
  1. php -q /home/username/public_html/cpanel-backup.php  
Here is a sample:
Login into Backup Box. On the left panel, login into the FTP account (use the backup box FTP account) and in the right panel, login into your Dropbox account:
Since we store backup files into a dedicated folder, we can only transfer the contents of it. Select Transfer only the contents of / in the Transfer Options as the transfer method.
You can now start the immediate transfer by clicking Review. This will transfer the public_html folder to Dropbox. Once done, you can create Monthly schedule to automate this backup task monthly. Just click Monthly > select Date and Time > Finalize and Run.
Note: If you want to use weekly or daily backup, you need to upgrade your subscription as stated in the website. If you do, do not forget to change the cron job setting according to your backup schedule. Another thing, the PHP script will delete all previous cPanel backup before it generate new backups. This to make sure your backup will not eat up much disk space.
Read More

Thursday, September 19, 2013

// // Leave a Comment

Convert root filesystem to LVM

I converted root filesystem to lvm since the root partition was huge and I needed more flexibility in managing the partitions. Besides, lvm would also enable for easy backups with lvm snapshots.
I had a sizable swap partition of 2GB which I used to transfer my root files to and rebooted to it, prior to the conversion.
Please know what you are doing prior and make sure to create backups.
  1. This is what the partitions looked like prior to the change:
    # df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             228G  1.4G  215G   1% /
    /dev/sda1              99M   17M   77M  19% /boot
    none                 1014M     0 1014M   0% /dev/shm
    
    # fdisk -l
    Disk /dev/sda: 250.0 GB, 250000000000 bytes
    255 heads, 63 sectors/track, 30394 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          13      104391   83  Linux
    /dev/sda2              14         267     2040255   82  Linux swap
    /dev/sda3             268       30394   241995127+  83  Linux
    
  2. With the current setup, I have a better sized partition, and can further create/resize partitions to add or remove at will:
    # df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg0-lvroot0
                           24G  1.3G   22G   6% /
    /dev/sda1              99M   19M   75M  21% /boot
    none                 1014M     0 1014M   0% /dev/shm
    
    # fdisk -l
    Disk /dev/sda: 250.0 GB, 250000000000 bytes
    255 heads, 63 sectors/track, 30394 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          13      104391   83  Linux
    /dev/sda2              14         267     2040255   83  Linux swap
    /dev/sda3             268       30394   241995127+  8e  Linux LVM
    
  3. I had a sizable swap partition of 2GB, so I turned it off.
    # swapoff -a
  4. Formated the swap partition as ext3 and copied over the root files:
    # mke2fs -j /dev/sda2
    # mount /dev/sda2 /mnt/
    # find / -xdev | cpio -pvmd /mnt
  5. Once the files were transfered. I then edited the "/mnt/etc/fstab" file to reflect the new root.
    /dev/sda2      /    ext3       defaults 1 1
    
  6. Add a grub section to use "/dev/sda2" as the new root.
    title CentOS (2.6.9-55.0.9.ELsmp.sda2)
            root (hd0,0)
            kernel /vmlinuz-2.6.9-55.0.9.ELsmp ro root=/dev/sda2
            initrd /initrd-2.6.9-55.0.9.ELsmp.img
    
  7. After reboot the original root (/dev/sda3) is no longer mounted and is free to work with.
  8. Change the partition type from Linux to LVM (8e).
          # fdisk /dev/sda
          Command (m for help): t
          Partition number (1-4): 3
          Hex code (type L to list codes): 8e
          Changed system type of partition 4 to 8e (Unknown)
          Command (m for help): w
  9. Inform the Operating System for the partition table changes.
          #partprobe
  10. Initialize LVM
          # vgscan
  11. Make the new partition into a Physical Volume.
          # pvcreate /dev/sda3          
  12. Create a new volume group.
          # vgcreate vg0 /dev/sda3
  13. Create a logical volume to hold the new root (/).
          # lvcreate -L 24G -n lvroot0 vg0
  14. Make a filesystem in the logical volume and copy the root files onto it.
          # mke2fs -j /dev/vg0/lvroot0
          # mount /dev/vg0/lvroot0 /mnt
          # yum update kernel
          # find / -xdev | cpio -pvmd /mnt
  15. Additionally, since the new root is now lvm, the initrd image file should have support for it else kernel will not be able to find root on reboot and end up with a kernel panic.
    Note: At this stage, instead of creating a new image, I update the kernel so that the new image supports lvm. LVM support can also be checked via extracting the initrd image file and checking for lvm binary in the bin folder.
    # mkdir -p /tmp/kill/00
    # cd /tmp/kill/00
    # gunzip < /boot/initrd-2.6.9-55.0.9.ELsmp.img | cpio -id
    # ls -al bin/lvm
    -r-x------ 1 root root 1417512 May 24 14:38 bin/lvm
    If image does not have the lvm binary, create and move it to the /boot folder.
    # chroot /mnt
    # mount -t proc /proc /proc
    # mount -t sysfs /sys /sys
    # vgmknodes -v
    # mkinitrd -v initrd-2.6.9-55.0.9.ELsmp.lv.img 2.6.9-55.0.9.ELsmp
  16. Edit "/mnt/etc/fstab" on the new root so that / is mounted on /dev/vg0/lvroot0.
    /dev/vg0/lvroot0       /    ext3       defaults 1 1
    
  17. Add grub section to use "/dev/vg0/lvroot0" to boot to.
    title CentOS (2.6.9-55.0.9.ELsmp.lvroot0)
            root (hd0,0)
            kernel /vmlinuz-2.6.9-55.0.9.ELsmp ro root=/dev/vg0/lvroot0
            initrd /initrd-2.6.9-55.0.9.ELsmp.lv.img
    
  18. Reboot, and enjoy the flexibility of lvm!!
Read More

Wednesday, September 11, 2013

// // Leave a Comment

The Ultimate Wget Download Guide With 15 Awesome Examples

wget utility is the best option to download files from internet. wget can pretty much handle all complex download situations including large file downloads, recursive downloads, non-interactive downloads, multiple file downloads etc.,
In this article let us review how to use wgetfor various download scenarios using 15 awesome wget examples.

1. Download Single File with wget

The following example downloads a single file from internet and stores in the current directory.
$ wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
While downloading it will show a progress bar with the following information:
  • %age of download completion (for e.g. 31% as shown below)
  • Total amount of bytes downloaded so far (for e.g. 1,213,592 bytes as shown below)
  • Current download speed (for e.g. 68.2K/s as shown below)
  • Remaining time to download (for e.g. eta 34 seconds as shown below)
Download in progress:
$ wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
Saving to: `strx25-0.9.2.1.tar.bz2.1'

31% [=================> 1,213,592   68.2K/s  eta 34s
Download complete
$ wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
Saving to: `strx25-0.9.2.1.tar.bz2'

100%[======================>] 3,852,374   76.8K/s   in 55s    

2009-09-25 11:15:30 (68.7 KB/s) - `strx25-0.9.2.1.tar.bz2' saved [3852374/3852374]

2. Download and Store With a Different File name Using wget -O

By default wget will pick the filename from the last word after last forward slash, which may not be appropriate always.
Wrong: Following example will download and store the file with name: download_script.php?src_id=7701
$ wget http://www.vim.org/scripts/download_script.php?src_id=7701
Even though the downloaded file is in zip format, it will get stored in the file as shown below.
$ ls
download_script.php?src_id=7701
Correct: To correct this issue, we can specify the output file name using the -O option as:
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

3. Specify Download Speed / Download Rate Using wget –limit-rate

While executing the wget, by default it will try to occupy full possible bandwidth. This might not be acceptable when you are downloading huge files on production servers. So, to avoid that we can limit the download speed using the –limit-rate as shown below.
In the following example, the download speed is limited to 200k
$ wget --limit-rate=200k http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

4. Continue the Incomplete Download Using wget -c

Restart a download which got stopped in the middle using wget -c option as shown below.
$ wget -c http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
This is very helpful when you have initiated a very big file download which got interrupted in the middle. Instead of starting the whole download again, you can start the download from where it got interrupted using option -c
Note: If a download is stopped in middle, when you restart the download again without the option -c, wget will append .1 to the filename automatically as a file with the previous name already exist. If a file with .1 already exist, it will download the file with .2 at the end.

5. Download in the Background Using wget -b

For a huge download, put the download in background using wget option -b as shown below.
$ wget -b http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2
Continuing in background, pid 1984.
Output will be written to `wget-log'.
It will initiate the download and gives back the shell prompt to you. You can always check the status of the download using tail -f as shown below.
$ tail -f wget-log
Saving to: `strx25-0.9.2.1.tar.bz2.4'

     0K .......... .......... .......... .......... ..........  1% 65.5K 57s
    50K .......... .......... .......... .......... ..........  2% 85.9K 49s
   100K .......... .......... .......... .......... ..........  3% 83.3K 47s
   150K .......... .......... .......... .......... ..........  5% 86.6K 45s
   200K .......... .......... .......... .......... ..........  6% 33.9K 56s
   250K .......... .......... .......... .......... ..........  7%  182M 46s
   300K .......... .......... .......... .......... ..........  9% 57.9K 47s
Also, make sure to review our previous multitail article on how to use tail command effectively to view multiple files.

6. Mask User Agent and Display wget like Browser Using wget –user-agent

Some websites can disallow you to download its page by identifying that the user agent is not a browser. So you can mask the user agent by using –user-agent options and show wget like a browser as shown below.
$ wget --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" URL-TO-DOWNLOAD

7. Test Download URL Using wget –spider

When you are going to do scheduled download, you should check whether download will happen fine or not at scheduled time. To do so, copy the line exactly from the schedule, and then add –spider option to check.
$ wget --spider DOWNLOAD-URL
If the URL given is correct, it will say
$ wget --spider download-url
Spider mode enabled. Check if remote file exists.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.
This ensures that the downloading will get success at the scheduled time. But when you had give a wrong URL, you will get the following error.
$ wget --spider download-url
Spider mode enabled. Check if remote file exists.
HTTP request sent, awaiting response... 404 Not Found
Remote file does not exist -- broken link!!!
You can use the spider option under following scenarios:
  • Check before scheduling a download.
  • Monitoring whether a website is available or not at certain intervals.
  • Check a list of pages from your bookmark, and find out which pages are still exists.

8. Increase Total Number of Retry Attempts Using wget –tries

If the internet connection has problem, and if the download file is large there is a chance of failures in the download. By default wget retries 20 times to make the download successful.
If needed, you can increase retry attempts using –tries option as shown below.
$ wget --tries=75 DOWNLOAD-URL

9. Download Multiple Files / URLs Using Wget -i

First, store all the download files or URLs in a text file as:
$ cat > download-file-list.txt
URL1
URL2
URL3
URL4
Next, give the download-file-list.txt as argument to wget using -i option as shown below.
$ wget -i download-file-list.txt

10. Download a Full Website Using wget –mirror

Following is the command line which you want to execute when you want to download a full website and made available for local viewing.
$ wget --mirror -p --convert-links -P ./LOCAL-DIR WEBSITE-URL
  • –mirror : turn on options suitable for mirroring.
  • -p : download all files that are necessary to properly display a given HTML page.
  • –convert-links : after the download, convert the links in document for local viewing.
  • -P ./LOCAL-DIR : save all the files and directories to the specified directory.

11. Reject Certain File Types while Downloading Using wget –reject

You have found a website which is useful, but don’t want to download the images you can specify the following.
$ wget --reject=gif WEBSITE-TO-BE-DOWNLOADED

12. Log messages to a log file instead of stderr Using wget -o

When you wanted the log to be redirected to a log file instead of the terminal.
$ wget -o download.log DOWNLOAD-URL

13. Quit Downloading When it Exceeds Certain Size Using wget -Q

When you want to stop download when it crosses 5 MB you can use the following wget command line.
$ wget -Q5m -i FILE-WHICH-HAS-URLS
Note: This quota will not get effect when you do a download a single URL. That is irrespective of the quota size everything will get downloaded when you specify a single file. This quota is applicable only for recursive downloads.

14. Download Only Certain File Types Using wget -r -A

You can use this under following situations:
  • Download all images from a website
  • Download all videos from a website
  • Download all PDF files from a website
$ wget -r -A.pdf http://url-to-webpage-with-pdfs/

15. FTP Download With wget

You can use wget to perform FTP download as shown below.
Anonymous FTP download using Wget
$ wget ftp-url
FTP download using wget with username and password authentication.
$ wget --ftp-user=USERNAME --ftp-password=PASSWORD DOWNLOAD-URL
If you liked this article, please bookmark it with delicious or Stumble.
Read More