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 / 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
$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
// )
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
ALTER IGNORE TABLE table_name ADD UNIQUE INDEX unique_index_name(col_1, col_2)
DROP INDEX unique_index_name ON table_name
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"}'
<?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");
@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);