Skip to content

Instantly share code, notes, and snippets.

View Bat-Chat's full-sized avatar

Vladyslav Shestopalov Bat-Chat

View GitHub Profile
@Bat-Chat
Bat-Chat / getCountFiles.php
Last active January 7, 2016 14:55
Get count of files in directory
<?php
$dir = new DirectoryIterator('/directoryPath/');
$count = 0;
foreach($dir as $file) {
$count += ($file->isFile()) ? 1 : 0;
}
print_r($count);
<?php
// show all processes (queries)
$result = mysql_query("show full processlist");
while($row = mysql_fetch_array($result, MYSQL_NUM)) {
print_r($row);
}
// stop process (query) by id
mysql_query("kill 1724864106");
curl 'http://rest/v1/posts/2' -X DELETE -H 'Access-Control-Request-Method: DELETE' -H 'Origin: http://site' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' -H 'Accept: */*' -H 'Referer: http://site/client/' -H 'Connection: keep-alive' -H 'Access-Control-Request-Headers: accept' --compressed
curl http://rest/create -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}'
ALTER IGNORE TABLE table_name ADD UNIQUE INDEX unique_index_name(col_1, col_2)
DROP INDEX unique_index_name ON table_name
find /dir -type f -exec chmod 0644 {} \;
find /dir -type d -exec chmod 0755 {} \;
sudo groupadd wb
sudo usermod -a -G wb www-data
sudo usermod -a -G wb batchat
sudo chgrp -R wb /dir
sudo chmod -R g+rwx /dir
$parts = parse_url('http://example.com/user/22?r=4');
// $parts return:
// Array
// (
// [scheme] => http
// [host] => example.com
// [path] => /user/22
// [query] => r=4&e=key
// )
@Bat-Chat
Bat-Chat / randWithLimitMysql
Last active September 8, 2016 22:38
little random ids with limit in one query
"SELECT b.id, b.title
FROM books AS b
JOIN
(SELECT (RAND() *
(SELECT MAX(id)
FROM books)) AS rid)
AS rid2
JOIN books_genres
ON books_genres.book_id = b.id
WHERE b.id >= rid2.rid AND b.id <> $bookId
$fileHeaders = @get_headers($imgUrl);
if($fileHeaders[0] == 'HTTP/1.1 200 OK') {
echo 'image exists';
}
@Bat-Chat
Bat-Chat / questionMarkInString
Created March 16, 2016 11:28
Когда строка состоит из кириллицы и utf-8 могут отображаться символы - "�". Для вывода или замены строки из кириллицы делать следиущее:
$name = 'Кириллица вместе с utf-8';
$name = iconv("windows-1251", "utf-8", $name);
$name = str_replace('Кириллица', '', $name);
@Bat-Chat
Bat-Chat / gist:a6e967bac4a39c6d5e4cdd9424dd1c02
Last active July 30, 2016 22:07
Get order_payment collection (like)
$conditions = array();
$words = preg_split( "/([ ]+|[-]+|[_]+)/", $value);
foreach( $words as $value ){
$conditions[] = array('like' => "%{$value}%");
}
$paymentTableName = Mage::getSingleton('core/resource')->getTableName('sales/order_payment');
$this->getCollection()->addFieldToFilter(
"{$paymentTableName}.method",
array('like' => "%{$value}%")