Skip to content

Instantly share code, notes, and snippets.

View egulhan's full-sized avatar
Here we go again...

Erman Gülhan egulhan

Here we go again...
View GitHub Profile
@egulhan
egulhan / ajaxBtnInCButtonCol.php
Last active May 29, 2021 01:26
Usage of ajax button in CButtonColumn in Yii Framework.
<?php
...
array(
'class'=>'CButtonColumn',
'template'=>'{confirm}{delete}',
//'template'=>'{confirm}',
'deleteButtonUrl'=>'Yii::app()->createUrl("/account/disabledAccounts",array("op"=>"delete","id"=>$data["id"]))',
'deleteButtonLabel'=>Yii::t('common','Cancel request'),
'deleteConfirmation'=>Yii::t('warnings','The account will be accessable by this operation. Are you sure you want to do this?'),
@egulhan
egulhan / sumNumbers
Created January 13, 2014 15:00
Scripting methods to sum numbers in a file
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;';
@egulhan
egulhan / deleteOneValFromLdapMultiValAttr.php
Created January 16, 2014 12:06
How to delete one value from a multiple-valued attribute of LDAP by ldap_mode_del() function.
/**
* 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);
@egulhan
egulhan / sed-from-grep.sh
Created January 31, 2014 15:49
how to execute sed command from just files result from grep command
grep -rl "'filter'=>FrontEnd::createPhInputField" * | grep -v ".svn" | xargs -l sed -i "s/filter'=>FrontEnd::createPhInputField(\(.*\),\(.*\))/filter'=>FrontEnd::createPhInputField(\1,\2,\$filtersForm)/g"
@egulhan
egulhan / solution.php
Created March 4, 2014 13:42
Solution of PHP SOAP error: looks like we got no XML document
// 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] );
@egulhan
egulhan / detectAndRemoveFileWithBoom
Created March 4, 2014 14:08
How-to detect file with BOM and remove it
# 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}'
@egulhan
egulhan / recursiveLdapDelete.php
Created March 7, 2014 14:38
Recursive version of ldap_delete
// 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++){
@egulhan
egulhan / Lock.php
Created March 19, 2014 20:02
Script locking mechanism for one-time-running scripts such as cron scripts
<?php
/**
* Class Lock
* Script locking mechanism for one-time-running scripts.
*/
class Lock
{
private $fp;
function __construct()
@egulhan
egulhan / ldap_escape.php
Created March 25, 2014 08:48
ldap_escape() function
/**
* 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
*/
@egulhan
egulhan / set_ES_HEAP_SIZE
Created March 31, 2014 10:56
How-to set ES_HEAP_SIZE variable for Elasticsearch installed as package
# ES version: 0.90.5
# /etc/init.d/elasticsearch
ES_HEAP_SIZE=4g