bxSlider "The Responsive jQuery Content Slider"

  • Fully responsive - will adapt to any device
  • Horizontal, vertical, and fade modes
  • Slides can contain images, video, or HTML content
  • Advanced touch / swipe support built-in
  • Uses CSS transitions for slide animation (native hardware acceleration!)
  • Full callback API and public methods
  • Small file size, fully themed, simple to implement
  • Browser support: Firefox, Chrome, Safari, iOS, Android, IE7+
  • Tons of configuration options
I'm creating a new design for my site. I found this great slider for web. It's really cool script.

When To Use Indexes In MySQL

 This comes up in discussions almost every new project I work on, because it's a very important thing to consider when designing a database.

When deciding when and how to create an index in your MySQL database, it's important to consider how the data is being used.

Let's say you have a database of employees. We will create it like this:

CREATE TABLE employees (
ID INT,
name VARCHAR(60),
salary decimal(10,2),
date hired(date)
)

So you will notice that this table is pretty simplistic, and doesn't really contain all the info you would need to actually manage employees, but its just for the sake of demonstration, and you could always add more later, or even make another table and use joins if you had really complex needs.

For now we will go over these real quick.

The ID is basically just a number (INT) which can hold a very large number. If this were real world I would probably make it unsigned, since you will never have a negative employee ID – but either way, you will never reach the number of employees it would take to get to the number that would fill up an INT.

Even unsigned int will hold values up to 2,147,483,647. So if you have 2 billion employees, you would probably not be a developer anymore ;-).

You might want to consider making the field an auto increment, and primary key, the auto increment depending on how data will be entered into this database.

Name is a simple varchar(60) which should cover most people's names.

Salary is a decimal with 10 total digits, two on the right hand side of the decimal point. This would handle a salary of up to 99,999,999.99 – again, you're not likely to hit this limit.

Date hired will be a date in this format 2010-05-06. YYYY-MM-DD.

So when considering this simple table, where would you expect to need an index?
If we assign ID as a primary key, we don't need one there.

Indexes are best used on columns that are frequently used in where clauses, and in any kind of sorting, such as "order by".

You should also pay attention to whether or not this information will change frequently, because it will slow down your updates and inserts. Since you wont frequently be adding employees, you don't have to worry about the inserts.

Let's say that you will be looking up the employees with a php web interface and the end user will be typing in the employees name to find them, since remembering the employee ID's would be cumbersome.

It sounds like this situation would be good to use an index.

A – You won't be updating the employee's name very often, so you don't have to worry about a performance hit there.

B – You WILL be using the employee in where clauses like this:

select * from employees where name ='smith';

C – You WILL be generating reports, which will probably be alphabetic, like this:

select * from employees order by name asc;

So in this simple example it's easy to see when it would be important to use indexes.

So, you could do it like this:

create index name_index on employees (name);

You might be working on a more complex database, so it's good to remember a few simple rules.

- Indexes slow down inserts and updates, so you want to use them carefully on columns that are FREQUENTLY updated.

- Indexes speed up where clauses and order by.

Remember to think about HOW your data is going to be used when building your tables.

There are a few other things to remember. If your table is very small, i.e., only a few employees, it's worse to use an index than to leave it out and just let it do a table scan. Indexes really only come in handy with tables that have a lot of rows.

So, if Joe’s Pet Shop was using this database, they would probably be able to leave the index off the "name" column.

If Microsoft was using this database (hah!) they might want to throw and index in there.

Another thing to remember, that is a con in the situation of our employees database, is that if the column is a variable length, indexes (as well as most of MySQL) perform much less efficiently.

As you can see there are many things to consider with indexes, even with a very simple table as this.

I would suggest looking at the explain command in MySQL, which I will be writing about in the future.

http://www.tsmonaghan.com

Minify of CSS and javascript files with php

First method:

Using .htaccess and RewriteRule for Minify

I used the following within .htaccess to minify all .js and .css on my WordPress MU site:

# .htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(.*\.(css|js))$ min/index.php?f=$1&debug=0 [L,NC]

# Note &debug=0 is not needed but I set it to 1 when needed
# (when $min_allowDebugFlag = true; is set within config.php)

I found this works great as I used this method in minify v1.0 but appears to break css background images.

/*wp-content/themes/mytheme/style.css*/

#someid {
    background
: #6E6A66 url('pics/mygif.gif') repeat-x top;
}

 becomes  (According to my Firebug output)

This is fixed by using a previous mentioned option within config.php and switching the css URI rewrite option off.

$min_serveOptions['rewriteCssUris'] = false;

I hope this helps anyone attempting to do the same.




Second method:

MagicMin DOES however, NOT suck, performs flawless (so far) minification of CSS and javascript files, allows you to automatically write the compressed file with gzip headers and  a php extension, defaults to using the Google Closure API for javascript minification, will base64_encode images (reasonably sized please) directly INTO your stylesheets, AND will serve the compressed, gzipped, minified, and awesome files in style until you update any of the source files included in the minified stylesheet or javascript file! (phew- long sentence with random bold!)

Check out the source code of this site! You’ll see 2 meager files included: 1 stylesheet, and 1 javascript file. If you use your web inspector, you’ll also see that they have defined caching periods, and are gzipped. All of this is automatic!

“But why go to all this trouble?” you ask?  Couple big reasons!

  1. I’ve been thrown 50,000 character long single-line strings of minified filth waaaaaay too many times.  Which I then have to run through a beautifier, only to re-minify, then repeat with the inevitable change (NOOOOOO)
  2. Performance and the ability to follow normal development workflows.  You know- the kind that aren’t mashed into a unusable non-editable nightmare of singlelinedness.
  3. The ability to do #2 above, and have something smart enough to go, “Oh hey- he just added a line to one of the 18 CSS files included in the ->merge command, let’s make a new beautiful updated file!” without me having to tell it, and without having to do anything (ANYTHING) manually

To preemptively answer the forthcoming questions:

  • Yes, I am aware that other javascript and css minification/packing libraries, classes, and functions exist
  • Yes, I am aware that older versions of IE do not like base64_encoded images
  • and, Yes- I am still aware that other javascript and css minification libraries exist

And to preemptively answer the next question (“So, why then?”):

  • For fun
  • Because I can
  • Because mine is more awesome (because it’s mine)

Before you waste time reading ANY further, I feel I should demonstrate.

Include the magicmin class and initialize it
1
2
3
4
require( 'class.magic-min.php' );
 
//Default usage will echo from function calls and leave images untouched
$minified = new Minifier();

Now all you need to do is replace the normal references in your script the stylesheet includes…

Actual usage
1
2
3
4
5
//This will output a newly minified file called "style.min.css"
<link href="<?php $minified->minify( 'css/style.css' ); ?>" rel="stylesheet" />
 
//This will output a newly minified js file called "jquery-awesome.min.js"
<script type="text/javascript" src="<?php $minified->minify( 'js/jquery.js', 'js/jquery-awesome.min.js' ); ?>"></script>

But now you’re all like, “But, but, but- there are 19 css files in my /css directory and I only want to include 3 of them!”. GOOD.

Grab a bunch, minify, merge, awesome
1
2
<?php $include_only = array( 'css/base/jquery.ui.all.css', 'css/base/jquery.ui.base.css', 'css/base/jquery.ui.spinner.css' ); ?>
<link href="<?php $minified->merge( 'css/base/specified-files.css', 'css/base', $include_only ); ?>" rel="stylesheet" />

Satisfied? Good. Continue!

Enter PHP Minification  for Javascript and CSS

That’s right.  I said MAGIC.  And I meant it.

MagicMin (lame name, yes, descriptive, yes) has four primary functions (lots of bullet points today because I said so!):

  1. Minification of single javascript, or CSS files via the ->minify( ‘source-file’, ‘output-filename [optional]‘, ‘version [also optional]‘ ); command
  2. Merging AND minification of groups of files via the ->merge( ‘params below on this page’ ) command with some awesome stuff:
    1. Files must be the same type (css or js)
    2. Happily glob’s it’s way through any specified directory, grabbing and minifying any and all files of matched types
    3. Allows you to glob your way through a directory, excluding any files you deem unworthy
    4. Allows you to specify an order of the files, and this is only necessary for the files that need to be ordered- all others will be glob’d in after the order parameters have been met
    5. And last but CERTAINLY not least, allow you to specify ONLY an array of files to include (they really should be the same css or js type if you have any desire for your scripts or stylesheets to work)
  3. Base64_encoding images into stylesheets to enable all assets to be loaded in a single request (small files [think icons and slivers of backgrounds])
  4. Providing generated assets using gzip with specified cache control
    1. zlib Must exist and be enabled, otherwise no gzip will be used
    2. Default expires set to 30 days (60 x 60 x 24 x 31)

This class uses filemtime to determine if and when the minified version should be recreated, and will only create a new minified file IF a file selected for inclusion in the minify or merge functions is newer than the previously created minified file, however, files that contain “.min.” in the filename will not have their contents minified, but will still have their contents returned and added to compiled files as normal (as it SHOULD be assumed that those files have already been minified).

Minification of javascript assets is done using either:

  • The Google Closure API (default, however, a bit slow to initially create the minified files at approximately 7 seconds)
    • It’s google.  They’re reliable, the minification is topnotch stuff
  • JShrink
    • JShrink (JShrink.php) is included in the download, however, in the event that it does not exist in the same directory as the class.magic-min.php file, the class will retrieve it from github, write it to a file named JShrink.php in the same directory as the class, and THEN use it.
    • This only applies if the class is initiated with ‘closure’ => false

Want some more?! Good! There’s MORE!

This bad boy can also output to your javascript console via console.log by calling (assuming you’ve initialized the class using $minified = new Minifier(); anyway)

Output the MagicMin processes and timers to console.log
1
<?php $minified->logs(); ?>

For the rest, it’s best if you just read the included documentation, check out the example file (example.php naturally), and add your comments and feature requests below!


Source: http://www.phpdevtips.com/2013/06/magicmin-php-js-and-css-minification-class/


Google page speed test tool

Learn more about web performance tools at Google, including browser extensions and APIs for Insights, PageSpeed Service, and our optimization libraries:

http://developers.google.com/speed/pagespeed/insights/

Optimize images with jpgtran and wesley.pl

wesley.pl (for jpg, png, gif recursively)


# sudo apt-get install libmagickwand-dev imagemagick gifsicle pngcrush libjpeg-progs


jpgtran multiple images shell script:

Installation in Ubuntu

# sudo apt-get install libjpeg-progs

Installation in Ubuntu

# su root
# apt-get install libjpeg-progs

It’s not necessary to be a root all the time to use this tool.

- See more at: http://www.rakeshmondal.info/Image-Compression-in-Ubuntu-Linux-Jpegtran#sthash.A3GX3pqD.dpuf

Installation in Ubuntu

# su root
# apt-get install libjpeg-progs

It’s not necessary to be a root all the time to use this tool.

- See more at: http://www.rakeshmondal.info/Image-Compression-in-Ubuntu-Linux-Jpegtran#sthash.A3GX3pqD.dpuf

http://pastie.org/4566002

 
#! /bin/sh    

EXTENSIONS="jpe?g"

if [ -z "$1" ]; then
    DIR="`pwd`"
else
    DIR="$1"
fi

# Optimize JPEG images
find $DIR -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}.optimized" "{}"

# Rename xxx.jpg.optimized -> xxx.jpg
for file in $(find $DIR -name '*.optimized'); do 
    chown $(stat -c "%U:%G" "${file%.optimized}") "$file"
    chmod $(stat -c "%a" "${file%.optimized}") "$file"
    mv -f "$file" "${file%.optimized}"; 
done


Usage 1:

optimize-images.sh /images/dir 

Usage 2:

cd /images/dir optimize-images.sh  

jEdit is a mature programmer's text editor

Using this text editor find replace in directory function. Great application.

jEdit is a mature programmer's text editor with hundreds (counting the time developing plugins) of person-years of development behind it. To download, install, and set up jEdit as quickly and painlessly as possible, go to the Quick Start page.

While jEdit beats many expensive development tools for features and ease of use, it is released as free software with full source code, provided under the terms of the GPL 2.0.

The jEdit core, together with a large collection of plugins is maintained by a world-wide developer team.

Some of jEdit's features include:

  • Written in Java, so it runs on Mac OS X, OS/2, Unix, VMS and Windows.
  • Built-in macro language; extensible plugin architecture. Hundreds of macros and plugins available.
  • Plugins can be downloaded and installed from within jEdit using the "plugin manager" feature.
  • Auto indent, and syntax highlighting for more than 200 languages.
  • Supports a large number of character encodings including UTF8 and Unicode.
  • Folding for selectively hiding regions of text.
  • Word wrap.
  • Highly configurable and customizable.
  • Every other feature, both basic and advanced, you would expect to find in a text editor. See the Features page for a full list.

FFmpegPHP get thumbnail from external URL

https://github.com/CodeScaleInc/ffmpeg-php

http://stackoverflow.com/questions/12620631/ffmpegphp-get-thumbnail-from-external-url

running code with PHP 5,ffmpeg and CURL with class based structure is as below:

require_once  'PHP_CURFN/ffmpeg-php-master/FFmpegFrame.php';   require_once  'PHP_CURFN/ffmpeg-php-master/FFmpegAutoloader.php';  class MyVideoTest{  private $fh=""; private $size=0; private $ch="";  public function __construct(){                  $video = 'http://[hosturl]/video/41a669911fd635167475d7530bffcc9f.mp4';                 $file = 'PHP_CURFN/cache/tmp_video_' . rand();                   $this->ch = curl_init();                 $this->fh = fopen ($file, 'w+');                 $this->ch = curl_init($video);                  $this->size = 0;                 curl_setopt($this->ch, CURLOPT_URL, $video);                 curl_setopt($this->ch, CURLOPT_HEADER, 0);                   curl_setopt($this->ch, CURLOPT_WRITEFUNCTION, array($this, "myfunction"));                  curl_exec($this->ch);                  fclose($this->fh);                 curl_close($this->ch);                 $movie = new FFmpegMovie($file);                 // Create the thumbnail.                  $thumb = $movie->getFrame(2);                 $thumb->resize(320, 240);                 $image = $thumb->toGDImage();                 imagejpeg($image, 'PHP_CURFN/cache' . $item->getLastInsertIdentifier() . '_' . 320);  } function myfunction($ch, $data)     {         $length = fwrite($this->fh, $data);         $size=&$this->size;          if($length === FALSE) {             return 0;         } else {             $size += $length;         }          // Downloads 1MB.          return $size < 1024 * 1024 *1 ? $length : 0; } }   $MyVideoTest= new MyVideoTest(); pr($MyVideoTest); exit;

How to record a users time on site

Stop loosing visitors! Time on site is one of the most useful metrics. Google website optimizer(GWO) makes it easy to test which design elements yield the highest conversion rate. You can use GWO to see if users spend a certain amount of time on a page, but you can't see which design combinations result in the most time spent on your site or a particular page. To record the time spent on your site you need to:
  1. Use javascript to record the time spent on a page.
  2. Use ajax to send that time to a server-side script the very instance the user leaves that page.
  3. Use a server-side script (like php or asp) to record that result.
To get the time spent on a page you need to use the onbeforeunload event which triggers as soon as the user navigates away from the page. The code to get just the time on a page would look like this:
<script type="text/javascript">
    var startTime = new Date();        //Start the clock!
    window.onbeforeunload = function()        //When the user leaves the page(closes the window/tab, clicks a link)...
    {
        var endTime = new Date();        //Get the current time.
        var timeSpent=(endTime - startTime);        //Find out how long it's been.
        alert(timeSpent);        //Pop up a window with the time spent in microseconds.
    }
</script>
To send that time back to the server you need to make an ajax call with synchronous set to true so that the server doesn't sever the connection when the user actually leaves the page.

<script type="text/javascript">
    var startTime = new Date();        //Start the clock!
    window.onbeforeunload = function()        //When the user leaves the page(closes the window/tab, clicks a link)...
    {
        var endTime = new Date();        //Get the current time.
        var timeSpent = (endTime - startTime);        //Find out how long it's been.
        var xmlhttp;        //Make a variable for a new ajax request.
        if (window.XMLHttpRequest)        //If it's a decent browser...
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();        //Open a new ajax request.
        }
        else        //If it's a bad browser...
        {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");        //Open a different type of ajax call.
        }
        var url = "http://anything.com/time.php?time="+timeSpent;        //Send the time on the page to a php script of your choosing.
        xmlhttp.open("GET",url,false);        //The false at the end tells ajax to use a synchronous call which wont be severed by the user leaving.
        xmlhttp.send(null);        //Send the request and don't wait for a response.
    }
</script>
The php code that takes the time and stores it in the database looks something like this:
<?php
header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
include(
"./connect.php");        //Connect to the database.
mysql_query("INSERT INTO  `your_table_name` (`time`) VALUES ('".$_GET["time"]."');");        //Add them to the db.
?>
In addition to the time spent on a page I also send which version of the page it is as well as the users current session id so I can track their time spent on my site this visit.