Suppose you have to change some PHP settings for specific projects or directories. Well, you can do so using four useful Apache directives, directly in your Apache configuration files, or even in .htaccess files. To change the value of a boolean directive use the following Apache directive:
php_flag [directive_name] on|off
To set the value of a non-boolean directive you can use the following Apache directive:
php_value [directive_name] [value]
Last, you can also use the two following directives, which behaves like the previous two directives, respectively, with a small difference. When you set a value using these directives, you can’t override it in the .htaccess file. And obviously, you can’t use them in that file.
php_admin_flag [directive_name] on|off php_admin_value [directive_name] [value]
For example, if you want to alter the error reporting rules for a specific virtual host, just use something like this in the virtual host configuration:
php_flag display_errors on # Equal to "E_ALL | E_DEPRECATED" php_value error_reporting 30719
Finally, remember that you cannot use the various PHP constants. You must use the numerical codes in place of them. E.g. E_DEPRECATED is 8192. Note that you can’t add comments in the same line of the directive: put it before or after! Otherwise Apache will not start up!
For computing the value of the combination of two or more constants (like in the example above), you can use a PHP script like the following one:
<?php echo (E_ALL | E_DEPRECATED); # Prints 30719
Enjoy!
Delete recursively all .svn files and folders.
rm -rf `find . -type d -name .svn`
As specified from the RFC4627 the correct header is application/json and not text/json.
In PHP you can use:
header('Content-type: application/json');
If you need not cache the output, a common problem with GET requests on IE, you can use these lines of code:
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
In some IDE (like IDEA) graphic representation of your Grails domain classes is built-in. But if you use another IDE, eg. SpringSource Tool Suite (like me), you can supply this lack with the Class Diagram plugin.
Installation is really simple: first, check that in your system is installed Graphviz (under Debian/Ubuntu
sudo apt-get install graphviz
) than into your app folder type
grails install-plugin class-diagram
Re-run your app and at http://localhost:8080/<your_app>/classDiagram you can see the class diagram generated. The result could look like the following:
IE6 and IE7 in quirks mode don’t support :hover pseudoclass for non-anchor (<a>) elements.
This little css trick can workaround the problem (example on a <tr> element):
tr { background: #ffffff; hover:expression(this.onmouseover=new Function("this.style.background='#ff0000';"),this.onmouseout=new Function("this.style.background='#ffffff';")); }
tr:hover { background:#ff0000; }
First line define background color for generic <tr> element and implement hover behaviour for IE, second line catch hover for standard-compliant browsers.
A small cheat sheet of wp’s database functions.
In your own functions put this line of code to be able to use wp’s db:
global $wpdb;
Get a field
$field = $wpdb->get_var($sql);
Get a single row
$row = $wpdb->get_row($sql);
Get some rows
$rows = $wpdb->get_results($sql);
Escape an input
$value = $wpdb->get_escape($input);
Perform a query
$n = $wpdb->query($sql);
WP Tables’ name
You can use
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N);
Return format
In get_row and get_results you can specify in the second argument the format
More info
Function Reference/wpdb Class « WordPress Codex.
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N);
You can move a wordpress website to a new domain with the following two steps:
1. Change all post’s URLs
UPDATE wp_posts SET guid = REPLACE ( guid, 'http://exampleoldsiteurl.com', 'http://examplenewsiteurl.com');
2. Replace the values of ’siteurl’ and ‘home’ in the wp_options table.
You can do it directly by phpMyAdmin or simply putting this lines of code in the functions.php of the theme:
update_option('siteurl','http://example.com/blog');
update_option('home','http://example.com/blog');
It is important to execute the previuos code once, then you have to delete this lines.
The official guide is here: Changing The Site URL « WordPress Codex.
PHP offers us the perfect solution to force the download of a file and propose to the user a filename:
$file ='monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header'Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '. filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
The method you can use to count the element’s of a jQuery selection is “size()”
$("div.class").size();
So you are able to do
if ($("div.class").size() > 0)
// Do something
else
// Another thing
or whatever you want to do