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
Scripting methods to sum numbers in a file: | |
------------------------------------------- | |
- awk '{s+=$1} END {print s}' number-list-file | |
- paste -s -d+ number-list-file|bc | |
- sum=0; while read num ; do sum=$(($sum + $num)); done < number-list-file ; echo $sum | |
- php -r '$sum=0;foreach(file("number-list-file") as $line) $sum+=$line;echo $sum.PHP_EOL;'; |
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 member(s) from alias(es). | |
* @param mixed (string|array) member(s) | |
* @param mixed (string|array) alias(es) | |
* @return bool | |
*/ | |
public function removeMemberFromAlias($member,$alias=null) | |
{ | |
if(is_string($member)) | |
$member=array($member); |
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
grep -rl "'filter'=>FrontEnd::createPhInputField" * | grep -v ".svn" | xargs -l sed -i "s/filter'=>FrontEnd::createPhInputField(\(.*\),\(.*\))/filter'=>FrontEnd::createPhInputField(\1,\2,\$filtersForm)/g" |
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
// Source: http://www.highonphp.com/fixing-soap-exception-no-xml | |
class SoapClientNG extends \SoapClient{ | |
public function __doRequest($req, $location, $action, $version = SOAP_1_1){ | |
$xml = explode("\r\n", parent::__doRequest($req, $location, $action, $version)); | |
$response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $xml[0] ); |
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
# Source: http://blog.x-if.com/2010/12/find-utf-8-files-with-bom/ | |
# http://stackoverflow.com/questions/204765/elegant-way-to-search-for-utf-8-files-with-bom | |
find -type f|while read file;do [ "`head -c3 -- "$file"`" == $'xefxbbxbf' ] && echo "found BOM in: $file";done | |
grep -orHbm1 "^`echo -ne 'xefxbbxbf'`" . | sed '/:0:/!d;s/:0:.*//' | |
# most efficient way: | |
find . -type f -print0 | xargs -0r awk '/^xEFxBBxBF/ {print FILENAME} {nextfile}' |
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
// source: http://www.php.net/manual/en/function.ldap-delete.php | |
function myldap_delete($ds,$dn,$recursive=false){ | |
if($recursive == false){ | |
return(ldap_delete($ds,$dn)); | |
}else{ | |
//searching for sub entries | |
$sr=ldap_list($ds,$dn,"ObjectClass=*",array("")); | |
$info = ldap_get_entries($ds, $sr); | |
for($i=0;$i<$info['count'];$i++){ |
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 | |
/** | |
* Class Lock | |
* Script locking mechanism for one-time-running scripts. | |
*/ | |
class Lock | |
{ | |
private $fp; | |
function __construct() |
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
/** | |
* function ldap_escape | |
* @source http://stackoverflow.com/questions/8560874/php-ldap-add-function-to-escape-ldap-special-characters-in-dn-syntax#answer-8561604 | |
* @author Chris Wright | |
* @version 2.0 | |
* @param string $subject The subject string | |
* @param bool $dn Treat subject as a DN if TRUE | |
* @param string|array $ignore Set of characters to leave untouched | |
* @return string The escaped string | |
*/ |
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
# ES version: 0.90.5 | |
# /etc/init.d/elasticsearch | |
ES_HEAP_SIZE=4g |