This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Removes items from an array where key information is missing. Useful in | |
* dynamic add situations. | |
*/ | |
$this->data['Date'] = Set::extract( '/Date[start=/\S+/][end=/\S+/]/.', $this->data ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$l = array( 'a apple is a fruit', 'a banana is also a fruit' ); | |
foreach( $l as $s ) { | |
$s = preg_replace( '/(^| )a ([aeiouAEIOU])/', '$1an $2', $s ); | |
echo $s . "\n"; | |
} | |
# outputs | |
an apple is a fruit | |
a banana is also a fruit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<?php $c_schools = count( $district['School'] ) ?> | |
<?php foreach( $district['Plan'] as $i => $plan ): ?> | |
<?php $classes = array( $i % 2 == 0 ? 'odd' : 'even' ) # Adjusted for 0-based indexing ?> | |
<?php array_push( $classes, $i == 0 ? 'first' : false ) ?> | |
<?php array_push( $classes, $i == $c_schools - 1 ? 'last' : false )?> | |
<li class="<?php echo join( ' ', array_filter( $classes ) ) ?>"> | |
PLAN NAME HERE | |
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Model constructor. | |
*/ | |
public function __construct( $id = false, $table = null, $ds = null ) { | |
parent::__construct( $id, $table, $ds ); | |
# Generate a whitelist that doesn't require me to make an update every time | |
# I add a property...unless I don't want that property to be batch updated. | |
# For me, this is usually the exception rather than the rule. | |
$this->whitelist = array_diff( array_keys( $this->schema() ), array( 'id', 'admin', 'last_login', 'active', 'created', 'modified' ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( !in_array( false, Set::flatten( $this->Model->saveAll( $this->data['Model'], array( 'atomic' => false ) ) ) ) { | |
# Success code | |
} | |
else { | |
# Fail code | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Populate the dropdown | |
$activities = $this->ActivityLog->Activity->find( | |
'all', | |
array( | |
'order' => array( 'Activity.display_order' ), | |
) | |
); | |
$activities = Set::combine( $activities, '{n}.Activity.id', '{n}.Activity.name', '{n}.Activity.type' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Computes the distance in miles between two sets of coordinates. | |
* | |
* @param object from object containing longitude and latitude members | |
* @param object to object containing longitude and latitude members | |
* @return number | |
*/ | |
exports.distance = function( from, to ) { | |
// approx. dist in miles, nothern hemisphere | |
// http://www.meridianworlddata.com/Distance-Calculation.asp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# As seen at http://www.totallyphp.co.uk/count-the-number-of-lines-in-a-text-file | |
$file = 'somefile.txt'; | |
$lines = count( file( $file ) ); | |
printf( 'There are %d line(s) in %s', $lines, $file ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The selection is cleared by the mouseup event | |
// for some stupid reason. | |
$( '#my-text-field' ) | |
.mouseup( function( e ) { | |
e.preventDefault(); | |
}) | |
.focus( function( e ) { | |
$(this).select(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows an administrator to create a new user. | |
* | |
* @param uuid id A user id. | |
* @access public | |
*/ | |
public function admin_edit( $id ) { | |
$this->User->id = $id; | |
if( !empty( $this->data ) ) { |
OlderNewer