Skip to content

Instantly share code, notes, and snippets.

View tairov's full-sized avatar

Aydyn Tairov tairov

  • London, UK
View GitHub Profile
@tairov
tairov / gist:6018239
Created July 17, 2013 06:59
get connections from backends
#! /bin/bash
# получить открытые коннекты к mongos на балансере
HOSTS=('pm.back4' 'pm.back5' 'pm.back6')
file_name=$(date +"%F_%H_%M_%S")
for host in ${HOSTS[@]}; do
remote_cmd="sudo -u www-data netstat -ntp 2>/dev/null | grep 27027 | grep ESTABLISHED"
conn=$(ssh -p 60222 atairov@$host $remote_cmd | awk '{print $4, $7}' | sort)
echo "$conn"
@tairov
tairov / gist:6029090
Last active December 19, 2015 22:39
php MongoClient
MongoLog::setLevel(MongoLog::ALL);
MongoLog::setModule(MongoLog::ALL);
MongoLog::setCallback('printLogs');
function printLogs($m, $l, $mesg)
{
echo $m, ' ', $l, ': ', $mesg, "\n";
}
MongoClient::getConnections();
@tairov
tairov / gist:6060575
Last active December 20, 2015 02:59
redis queries
redis-cli -p 6380 SMEMBERS some_set | grep 2046 | xargs -L 1 -I{} redis-cli -p 6380 SISMEMBER some_set {}
@tairov
tairov / gist:6069164
Created July 24, 2013 09:23
shell-script, backup, webdav, yandex.disk
#!/bin/bash
cd /home/cube/backups
for i in *.tar;
do
# username:password - имя пользователя и
# пароль к аккаунту Яндекса
curl -T ${i} --user username:password https://webdav.yandex.ru
rm ${i}
done
@tairov
tairov / gist:6069516
Created July 24, 2013 10:34
get git revision
public static function getGitRev()
{
if (APPLICATION_ENV == 'local') return time();
if (!isset(self::$_gitRev)) {
self::$_gitRev = 0;
self::$_gitRev = trim(@file_get_contents(APPLICATION_PATH . '/../.git/ORIG_HEAD')) ?: md5(time());
}
return self::$_gitRev;
@tairov
tairov / gist:6163628
Created August 6, 2013 11:13
set cookie
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
@tairov
tairov / gist:6191494
Last active December 20, 2015 20:39
sphinx indexer
# initial sync
indexer full_new delta_new && indexer --merge full_new delta_new
5 * * * * indexer delta_new --rotate >> /var/log/delta.new.log 2>&1 && indexer --merge full_new delta_new --rotate >> /var/log/sphinx.full.new.log 2>&1
@tairov
tairov / gist:6208847
Created August 12, 2013 07:34
nginx as transparent proxy
(none):~# cat /etc/nginx/sites-enabled/proxy
server {
resolver 8.8.8.8;
access_log off;
listen [::]:8080;
location / {
proxy_pass $scheme://$host$request_uri;
proxy_set_header Host $http_host;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0k;
@tairov
tairov / gist:6239351
Created August 15, 2013 08:53
mongodb, get jumbo chunks size
var ns = "mydb.mycollection" //the full namespace of the collection
var key = { "su" : 1, "sd" : 1 } //the shard key of the collection
db.getSiblingDB("config").chunks.find({ns : ns}).forEach(function(chunk) {
var ds = db.getSiblingDB(ns.split(".")[0]).runCommand({datasize:chunk.ns,keyPattern:key,min:chunk.min,max:chunk.max});
print("Chunk: "+chunk._id +" has a size of "+ds.size+", and includes "+ds.numObjects+" objects (took "+ds.millis+"ms)")
}
)
@tairov
tairov / gist:6435418
Created September 4, 2013 10:44
sphinx create deb package
apt-get install libexpat1 libexpat1-dev
./configure --sysconfdir=/etc/sphinxsearch
checkinstall