Skip to content

Instantly share code, notes, and snippets.

@bladeofsteel
bladeofsteel / mongo-log-on.php
Created September 29, 2018 21:01
включение логирования в драйвере монги
<?php
error_reporting (E_NOTICE);
MongoLog::setModule( MongoLog::ALL );
MongoLog::setLevel( MongoLog::ALL );
@bladeofsteel
bladeofsteel / docker-run-user.sh
Created May 9, 2018 18:49 — forked from marten-cz/docker-run-user.sh
Run docker with current user
# Run command with the same user ID as current user
# -v $(pwd):/tmp/mount - mount current directory to /tmp/mount/
# --env HOME="/tmp/" - some commands may need to be able to write to your home, se it to temporary folder
docker run -ti --rm -v $(pwd):/tmp/mount —user=$(id -u) --env HOME="/tmp/" debian:jessie
# Mount current users and group and be able to use them
# mount /etc/group and /etc/passwd read only
# set user from $USER
docker run -ti --rm -v $(pwd):/tmp/mount -w /tmp/hx -v /etc/group:/etc/group:ro -v /etc/passwd:/etc/passwd:ro —user=$USER debian:jessie
@bladeofsteel
bladeofsteel / gist:9594f3c216a257e19e2c798fdb1948ab
Last active March 13, 2017 15:52
Условия тестового задания
Нужно разработать библиотеку/сервис для решения следующей задачи:
Имея набор точек, образующих многоугольник, необходимо иметь возможность узнать периметр
многоугольника и расстояние между любыми двумя вершинами многоугольника. Координаты вершин
задаются парами чисел (x,y). Для указания вершин, между которыми надо определить расстояние,
используются индексы этих вершин.
@bladeofsteel
bladeofsteel / gist:394fd66c4882ec7111d8c0cd321c4dfa
Created February 9, 2017 11:44
Force SSH client to use password authentication instead of public key
@bladeofsteel
bladeofsteel / gist:8c9682de9202e8b2b914
Created May 6, 2015 19:43
Upload file with basic auth by file_get_contents
<?php
$boundary = '--------------------------' . microtime(true);
$header = [
sprintf("Authorization: Basic %s", base64_encode($username . ':' . $password)),
"Content-Type: multipart/form-data; boundary=" . $boundary,
];
$file_contents = file_get_contents($file);
@bladeofsteel
bladeofsteel / gist:cf75756b64706c914893
Created April 30, 2015 15:50
File upload with curl and basic auth
<?php
$post = array('ext_param' => $value, 'file_name' => '@' . $file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
@bladeofsteel
bladeofsteel / gist:5a07dc19db119973141b
Created May 10, 2014 11:50
Unicode characters to html entities
<?php
function unicode_escape_sequences($str) {
$working = json_encode($str);
$working = preg_replace('/\\\u([0-9a-z]{4})/', '&#x$1;', $working);
return json_decode($working);
}
@bladeofsteel
bladeofsteel / gist:a99298dd211361f4a0a6
Created May 10, 2014 11:48
Пакетное конвертирование line-ending в linux
find . -name "*.css" -exec vi +':w ++ff=unix' +':q' {} \;
@bladeofsteel
bladeofsteel / gist:8766906
Created February 2, 2014 11:24
Encode and Decode a String using Base64 scheme
<?php
function base64url_encode($plainText)
{
$base64 = base64_encode($plainText);
$base64url = strtr($base64, '+/=', '-_,');
return $base64url;
}
@bladeofsteel
bladeofsteel / gist:8766850
Created February 2, 2014 11:22
Определение IP-адреса посетителя
<?php
function getRealIPAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip=$_SERVER['REMOTE_ADDR'];
}