jQuery
$.inArray(value, array)
Underscore
_.contains(list, value)
This launches the command $cmd, redirects the command output to $outputfile, and writes the process id to $pidfile.
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
This lets you easily monitor what the process is doing and if it’s still running.
function isRunning($pid){ try{ $result = shell_exec(sprintf("ps %d", $pid)); if( count(preg_split("/\n/", $result)) > 2){ return true; } }catch(Exception $e){} return false; }
Manual:
$user_id = (is_user_logged_in() && !empty($current_user)) ? $current_user->ID : ''; if(empty($user_id)){ $current_user = wp_get_current_user(); if($current_user instanceof WP_User){ $user_id = $current_user->ID; } }
Most people recommend setting up the hostname on a Linux box so that:
1) running ‘hostname‘ returns the short name (i.e. myhost)
2) running ‘hostname -f‘ returns the FQDN (i.e. myhost.prod.example.com)
3) running ‘hostname -d‘ returns the domain name (i.e prod.example.com)
After experimenting a bit and also finding this helpful Server Fault post, here’s what we did to achieve this (we did it via Chef recipes, but it amounts to the same thing):
myhost
(also run ‘hostname myhost‘ at the command line)
10.0.1.10 myhost.prod.example.com myhost myhost.prod
search prod.example.com
grep "Invalid user " /var/log/auth.log | cut -d' ' -f10 | awk '{a[$0]++}END{for(i in a)print i,a[i]}' | sort -k 2 -n -r | head -n 100
grep "Invalid user " /var/log/auth.log | cut -d' ' -f8 | awk '{a[$0]++}END{for(i in a)print i,a[i]}' | sort -k 2 -n -r | head -n 100
<script type="text/javascript" src="/static/js/stacktrace.js"> </script> <script type="text/javascript"> window.onerror = function () { var stackTrace, argData, docData, request; var _doc = {}; _doc.URL = document.URL; docData = encodeURIComponent( JSON.stringify(_doc)); argData = encodeURIComponent( JSON.stringify(arguments)); stackTrace = JSON.stringify(printStackTrace()); console.log(arguments); request = new XMLHttpRequest(); request.open( 'POST', "https://www.yoursite.com/error-logging-url" ); request.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" ); request.onload = function (e) {}; request.send( "docData=" + docData + "&" + "argData=" + argData + "&" + "stackTrace=" + stackTrace); return false; } </script>
Answer yes or no to each.
The Joel Test
/** * Checks if a particular user has a role. * Returns true if a match was found. * * @param string $role Role name. * @param int $user_id (Optional) The ID of a user. Defaults to the current user. * @return bool */ function appthemes_check_user_role( $role, $user_id = null ) { if ( is_numeric( $user_id ) ) $user = get_userdata( $user_id ); else $user = wp_get_current_user(); if ( empty( $user ) ) return false; return in_array( $role, (array) $user->roles ); } // example use for the current user if ( appthemes_check_user_role( 'customer' ) _e( "You've got access dude!", 'appthemes' ); else _e( "Sorry man, no luck.", 'appthemes' ); // example use for a specific user $user_id = 23; if ( appthemes_check_user_role( 'customer', $user_id ) _e( "You've got access dude!", 'appthemes' ); else _e( "Sorry man, no luck.", 'appthemes' );
jQuery(document).ready(function($){ // now you can use jQuery code here with normal $ shortcut formatting });
if(typeof(String.prototype.trim) === "undefined") { String.prototype.trim = function() { return String(this).replace(/^\s+|\s+$/g, ''); }; }
The trim function will now be available as a first-class function on your strings. For example:
" dog".trim() === "dog" //true