MISCONF Redis is configured to save RDB snapshots

echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
10 января 2017, 16:00

Change gitlab url

vi /etc/gitlab/gitlab.rb
 external_url 'http://gitlab.example.com/'
sudo gitlab-ctl reconfigure 
sudo gitlab-ctl restart
14 декабря 2016, 14:37

Постим картинки на стену сообщества vkontakte

vk
<?php
$token = '**************************************';
$group_id = '1111111';
$vk = new Vk($token);

$image_path = 'image.png';
copy('https://www.google.ru/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', 'image.png');

$upload_server = $vk->photosGetWallUploadServer($group_id);

$upload = $vk->uploadFile($upload_server['upload_url'], $image_path);

$save = $vk->photosSaveWallPhoto([
        'group_id' => $group_id,
        'photo' => $upload['photo'],
        'server' => $upload['server'],
        'hash' => $upload['hash']
    ]
);

$attachments = sprintf('photo%s_%s', $save[0]['owner_id'], $save[0]['id']);


$post = $vk->wallPost([
    'owner_id' => "-$group_id",
    'from_group' => 1,
    'message' => "блаблабла",
    'attachments' => $attachments
]);


class Vk
{
    private $token;
    private $v = '5.37';

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function wallPost($data)
    {
        return $this->request('wall.post', $data);
    }

    public function photosGetWallUploadServer($group_id)
    {
        $params = [
            'group_id' => $group_id,
        ];
        return $this->request('photos.getWallUploadServer', $params);
    }

    /**
     * @param $params [user_id, group_id, photo, server, hash]
     * @return mixed
     * @throws \Exception
     */
    public function photosSaveWallPhoto($params)
    {
        return $this->request('photos.saveWallPhoto', $params);
    }

    public function uploadFile($url, $path)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);

        if (class_exists('\CURLFile')) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, ['file1' => new \CURLFile($path)]);
        } else {
            curl_setopt($ch, CURLOPT_POSTFIELDS, ['file1' => "@$path"]);
        }

        $data = curl_exec($ch);
        curl_close($ch);
        return json_decode($data, true);
    }

    private function request($method, array $params)
    {
        $params['v'] = $this->v;

        $ch = curl_init('https://api.vk.com/method/' . $method . '?access_token=' . $this->token);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        $data = curl_exec($ch);
        curl_close($ch);
        $json = json_decode($data, true);
        if (!isset($json['response'])) {
            throw new \Exception($data);
        }
        usleep(mt_rand(1000000, 2000000));
        return $json['response'];
    }
}
14 декабря 2016, 00:31

Idea PhpStorm licence key (nov 2016)

43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWdu
ZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBl
ZHVjYXRpb25hbCB1c2Ugb25seSIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3Rz
IjpbeyJjb2RlIjoiSUkiLCJwYWlkVXBUbyI6IjIwMTctMDItMjUifSx7ImNvZGUiOiJBQyIsInBh
aWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IkRQTiIsInBhaWRVcFRvIjoiMjAxNy0wMi0y
NSJ9LHsiY29kZSI6IlBTIiwicGFpZFVwVG8iOiIyMDE3LTAyLTI1In0seyJjb2RlIjoiRE0iLCJw
YWlkVXBUbyI6IjIwMTctMDItMjUifSx7ImNvZGUiOiJDTCIsInBhaWRVcFRvIjoiMjAxNy0wMi0y
NSJ9LHsiY29kZSI6IlJTMCIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IlJDIiwi
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D+PTAsWGu9GyLmhti2EnVwGybSD
2Dxmhxk3IPCkhKAK+pl0eWYGZWG3tJ9mZ7SowcXLWDFAk0lRJnKGFMTggrWjV8GYpw5bq23VmIqq
DLgkNzuoog==
18 ноября 2016, 14:37

Удаление всех аудиодорожек из видео файла

ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4
11 сентября 2016, 14:26

Как залить на яндекс диск через CURL

curl --user USER:PASSWORD -T "/path/to/file" https://webdav.yandex.ru/
23 августа 2016, 16:49

Как узнать что занимает порт в FreeBSD

sockstat -4 -l | grep :80
23 августа 2016, 16:37

Проверка диска на bad blocks

dd_rescue -v -l /var/log/mfid1_error.log -o /var/log/mfid1_bad.log /dev/mfid1 /dev/null
6 августа 2016, 11:56

Определение серийного номера диска в raid

Для рейдов типа twaX или daX смотрим в dmesg.boot:
cat /var/run/dmesg.boot
Вывод будет примерно такой
da18 at twa1 bus 0 scbus1 target 6 lun 0
da18: <AMCC 9650SE-12M DISK 4.10> Fixed Direct Access SCSI-5 device 
da18: Serial Number W1E1T3RX000000000000
da18: 100.000MB/s transfers
da18: 1907729MB (3907029168 512 byte sectors: 255H 63S/T 243201C)
26 апреля 2016, 19:40

Firewall on iptables

iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -i eth0 -p udp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p udp --dport 443 -j ACCEPT
iptables -A INPUT -i eth0 -j DROP
26 апреля 2016, 10:19

Использование input value в angular

Для input
.directive('useFormData', function ($parse) {
    return {
      link: function (scope, element, attrs) {
        if (attrs.ngModel && attrs.value) {
          $parse(attrs.ngModel).assign(scope, attrs.value);
        }
      }
    };
});
<input type="text" ng-model="title" value="default value" use-form-data />
Для textarea
.directive('useFormData', function ($parse) {
 return {
  link: function (scope, element, attrs) {
   if (attrs.ngModel && element[0].defaultValue) {
    $parse(attrs.ngModel).assign(scope, element[0].defaultValue);
   }
  }
 };
});
20 марта 2016, 20:58

Число прописью при помощи php_intl

<?php
$result = (new \MessageFormatter('ru-RU', '{n, spellout}'))->format(['n' => 321]);
echo $result;  // триста двадцать один

$result = (new \MessageFormatter('ru-RU', '{n, spellout,%spellout-cardinal-feminine}'))->format(['n' => 321]);
echo $result; // триста двадцать одна
16 марта 2016, 20:52

Подключение к mongodb через ssh туннель

ssh -fN -L 6666:localhost:27017 user@host
Теперь можно подключаться к удаленной базе через 127.0.0.1 по порту 6666
21 февраля 2016, 15:13

Установка Java в Firefox на Ubuntu

sudo apt-get install openjdk*  
sudo apt-get install icedtea-plugin
21 февраля 2016, 13:55

3 способа удалить данные из таблицы, которых нет в другой таблице

1. LEFT JOIN/IS NULL
DELETE b FROM tbl
  LEFT JOIN rel ON rel.id = tbl.fileid 
      WHERE rel.id IS NULL
2. NOT EXISTS
DELETE FROM tbl 
 WHERE NOT EXISTS(SELECT NULL
                    FROM rel
                   WHERE rel.id = tbl.fileid)
3. NOT IN
DELETE FROM tbl
 WHERE tbl.fileid NOT IN (SELECT rel.id 
                        FROM rel)
27 января 2016, 22:37

Полезные команды SKYPE

/showplaces      показывает с каких устройств вы подключены
/remotelogout    выход со всех устройств кроме текущего (push уведомления тоже отключаются)
25 января 2016, 13:39

Какой aac библиотекой лучше пользоваться при перекодировании видео?

Ответ в FAQ
libfdk_aac > libfaac > libvo_aacenc
24 января 2016, 00:34

Установка intl на FreeBSD

pkg install pecl-intl
21 января 2016, 22:36

Формат даты на русском в родительном падеже

<?php
$formatter = new IntlDateFormatter('ru_RU', IntlDateFormatter::FULL, IntlDateFormatter::FULL);
$formatter->setPattern('d MMMM YYYY, HH:mm');
echo $formatter->format(new DateTime('2015-01-01 01:01:01')); //1 января 2015, 01:01
19 января 2016, 12:52

Шпаргалка MegaCli

# flash bios
MegaCli -adpfwflash -f /scripts/firmware/lsi_imr_fw.rom -aALL
MegaCli -adpfwflash -f imr_fw.rom -NoVerChk -aAll
MegaCli -adpfacdefset -aALL # reset to factory default

# controller info
MegaCli -AdpAllinfo -aALL
MegaCli -PDGetNum -a0 # nubmer of discs
MegaCli -PDInfo -PhysDrv [64:0] -aALL
MegaCli -PDMakeJBOD -PhysDrv[64:4]

# clear controller config to defaults
MegaCli -CfgClr -aALL

# delete all
MegaCli -CfgLdDel -LALL -aALL

# create raid
MegaCli -CfgLdAdd -r5 [64:0, 64:1, 64:2, 64:3] -a0
MegaCli -CfgLdAdd -r0 [64:4,64:5,64:6,64:7] -a0

# get free devices
MegaCli -PDList -a0 | grep -e '^Enclosure Device ID:' -e '^Slot Number:'

# get raid info
MegaCli -LDInfo -Lall -aALL
MegaCli -PDMakeGood -PhysDrv[64:4] -force -aALL > /dev/null
MegaCli -PDMakeGood -PhysDrv[64:5] -force -aALL > /dev/null
MegaCli -PDMakeGood -PhysDrv[64:6] -force -aALL > /dev/null
MegaCli -PDMakeGood -PhysDrv[64:7] -force -aALL > /dev/null
MegaCli -PDMakeJBOD -PhysDrv[64:4,64:5,64:6,64:7] -a0
MegaCli -CfgLdAdd -r0 [64:4,64:5,64:6,64:7] -a0
MegaCli -AdpEventLog -GetEvents -f logfile -aALL # Dump all events from the adapters event log to a file named logfile
MegaCli -PDList -aAll # Dump information about all Phsyical Disks
MegaCli -LDInfo -LAll -aAll # Dump information about all Logical Disks on all adapters
MegaCli -LdPdInfo -aAll # Dump information of all logical and physical disks on all known adapters
MegaCli -AdpSetProp -EnableJBOD 1 -aALL
MegaCli -CfgDsply -aAll

# adapter diagnostic
MegaCli -AdpDiag -a0

Controller information
MegaCli -AdpAllInfo -aALL
MegaCli -CfgDsply -aALL
MegaCli -AdpEventLog -GetEvents -f events.log -aALL && cat events.log

Enclosure information
MegaCli -EncInfo -aALL

Virtual drive information
MegaCli -LDInfo -Lall -aALL

Physical drive information
MegaCli -PDList -aALL
MegaCli -PDInfo -PhysDrv [E:S] -aALL

Battery backup information
MegaCli -AdpBbuCmd -aALL

Controller management

Silence active alarm
MegaCli -AdpSetProp AlarmSilence -aALL

Disable alarm
MegaCli -AdpSetProp AlarmDsbl -aALL

Enable alarm
MegaCli -AdpSetProp AlarmEnbl -aALL

Physical drive management

Set state to offline
MegaCli -PDOffline -PhysDrv [E:S] -aN

Set state to online
MegaCli -PDOnline -PhysDrv [E:S] -aN

Mark as missing
MegaCli -PDMarkMissing -PhysDrv [E:S] -aN

Prepare for removal
MegaCli -PdPrpRmv -PhysDrv [E:S] -aN

Replace missing drive
MegaCli -PdReplaceMissing -PhysDrv [E:S] -ArrayN -rowN -aN

Rebuild drive
MegaCli -PDRbld -Start -PhysDrv [E:S] -aN
MegaCli -PDRbld -Stop -PhysDrv [E:S] -aN
MegaCli -PDRbld -ShowProg -PhysDrv [E:S] -aN

Clear drive
MegaCli -PDClear -Start -PhysDrv [E:S] -aN
MegaCli -PDClear -Stop -PhysDrv [E:S] -aN
MegaCli -PDClear -ShowProg -PhysDrv [E:S] -aN

MegaCli -PDMakeGood -PhysDrv[E:S] -aN
This changes drive in state Unconfigured-Bad to Unconfigured-Good.

Set the drive offline, if it is not already offline due to an error
MegaCli -PDOffline -PhysDrv [E:S] -aN

Mark the drive as missing
MegaCli -PDMarkMissing -PhysDrv [E:S] -aN

Prepare drive for removal
MegaCli -PDPrpRmv -PhysDrv [E:S] -aN

If you’re using hot spares then the replaced drive should become your new hot spare drive:
MegaCli -PDHSP -Set -PhysDrv [E:S] -aN

In case you’re not working with hot spares, you must re-add the new drive to your RAID virtual drive and start the rebuilding
MegaCli -PdReplaceMissing -PhysDrv [E:S] -ArrayN -rowN -aN
MegaCli -PDRbld -Start -PhysDrv [E:S] -aN
MegaCli -CfgLdAdd -r0 [0:1, 0:1] -a0
MegaCli -LDInfo -Lall -aALL
# View all controleler informations
MegaCli -AdpAllInfo -aAll

MegaCli -LDSetProp CachedBadBBU -LALL -aALL
Delete all devices
MegaCli -CfgLdDel -LALL -aALL

MegaCli -CfgLdAdd -r1 [252:0,252:1] -a0

MegaCli -CfgLdAdd -r10 [252:0,252:1,252:2,252:3] -a0

# create RAID5
MegaCli -CfgLdAdd -r5 [64:0,64:1,64:2,64:3] -a0

# create RAID10
MegaCli -CfgSpanAdd -r10 -Array0[64:0,64:1] -Array1[64:2,64:3] -a0

# create RAID10
MegaCli -AdpSetProp -EnableJBOD 1

# Enable disks cache
MegaCli -LDSetProp EnDskCache -LAll -aAll

# Force flash
MegaCli -adpfwflash -f ./12.12.0-0111.rom -NoVerChk -a0

# load controller defauts
MegaCli -adpfacdefset -aALL
13 января 2016, 23:12