Friday 31 October 2014

Linux: Change permissions recursively of only directories or only files

For directories:

find /path/to/folder -type d -exec chmod 755 {} \;

For files:

find /path/to/folder -type f -exec chmod 644 {} \;

Another way:

find /path/to/base/dir -type d -exec chmod 755 {} +
find /path/to/base/dir -type f -exec chmod 644 {} + 

http://superuser.com/questions/91935/how-to-chmod-755-all-directories-but-no-file-recursively

However, this seems to be the best solution, when you do not need to unset execute permissions on files:


chmod -R u+rwX,go+rX,go-w /path
The important thing to note here is that X acts differently to x - the man page says The execute/search bits if the file is a directory or any of the execute/search bits are set in the original (unmodified) mode. In other words, chmod u+X on a file won't set the execute bit; and g+X will only set it if it's already set for the user.

Tuesday 28 October 2014

Apache Keep Alive Setting

This setting determines if a connection is kept alive after a single file is transferred between the server and the browser.

Default is off

Can be turned on depending on available RAM and traffic patterns:

https://ausweb.com.au/technobabble/2012/07/27/apache-optimization/

Content Negotiation for Languages

http://www.w3.org/blog/2006/02/content-negotiation/

How to configure etags


"remove the iNode portion of Etags. To do this in Apache add the following lines to your configuration file.
<Directory /usr/local/httpd/htdocs>
    FileETag MTime Size
</Directory>" 


Or choose "MTime  Size" for the Etags setting in WHM's Apache configuration

http://www.websiteoptimization.com/speed/tweak/etags-revisited/

Monday 13 October 2014

Jquery multiple selectors

jQuery( "selector1, selector2, selectorN" )

Note that the commas are within the selector.

Jquery iterating over arrays, objects, and array-like objects

http://learn.jquery.com/using-jquery-core/iterating/

var sum = 0;
var arr = [ 1, 2, 3, 4, 5 ];

$.each( arr, function( index, value ){
sum += value;
});

Javascript associative array

Javascript does not feature associative arrays. However, you can create something similar using object arrays.

Example:

arr={'key1': 'value1','key2':'value2'};

This array can be accessed with:

the_value = array['key2']

Values can be added or changes:

arr['key3']='value3';

More info here: http://www.i-programmer.info/programming/javascript/1441-javascript-data-structures-the-associative-array.html

You can iterate over the object array using Jquery:

$.each( arr, function( index, value ){
sum += value;
});