Skip to content

Instantly share code, notes, and snippets.

@Lexx918
Lexx918 / geo-hash.php
Created June 10, 2015 14:30
geo-hash
<?php
// geo-hash
function ghEncode($lt, $lg)
{
$ltTop = 90;
$ltBottom = -90;
$lgLeft = -180;
$lgRight = 180;
$chars = "0123456789bcdefghjkmnpqrstuvwxyz";
@Lexx918
Lexx918 / distance.php
Created June 10, 2015 14:36
distance
<?php
/**
* author: domino, 28 апр 2008
* http://phpclub.ru/talk/members/domino.521/
* http://phpclub.ru/talk/threads/%D1%80%D0%B0%D1%81%D1%81%D1%82%D0%BE%D1%8F%D0%BD%D0%B8%D0%B5-%D0%BC%D0%B5%D0%B6%D0%B4%D1%83-%D0%B4%D0%B2%D1%83%D0%BC%D1%8F-%D1%82%D0%BE%D1%87%D0%BA%D0%B0%D0%BC%D0%B8-%D0%B7%D0%B5%D0%BC%D0%BB%D0%B8-%D0%B2-gps-%D0%BA%D0%BE%D0%BE%D1%80%D0%B4%D0%B8%D0%BD%D0%B0%D1%82%D0%B0%D1%85-%D1%81%D1%82%D0%B0%D0%BD%D0%B4%D0%B0%D1%80%D1%82%D0%B0-wgs84.54170/
*
* $gps_1['lat'] - latitude (широта)
* $gps_1['lon'] - longitude (долгота)
* $gps_1['point_elevation'] (высота точки) // == 0 if this is sea. but must be defined!
*/
@Lexx918
Lexx918 / js.loader.html
Created September 8, 2015 10:59
JS.Loader
<!DOCTYPE html>
<html>
<head>
<!--
DEMO: http://lexx918.ru/files/js.loader.html
-->
<meta charset="utf-8">
<title>loader</title>
@Lexx918
Lexx918 / sun.js
Created April 18, 2016 16:52
Sun, azimuth and altitude
/**
* http://stjarnhimlen.se/comp/tutorial.html
* http://www.planetcalc.ru/320/
*/
// day
var year = 2016;
var month = 4;
var day = 18;
@Lexx918
Lexx918 / combinator-iterator.php
Created July 1, 2016 11:26
Перебор комбинаций алгоритмом Нарайаны
/**
* Алгоритм Нарайаны
* https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%9D%D0%B0%D1%80%D0%B0%D0%B9%D0%B0%D0%BD%D1%8B
* @param array $arr
* @return array
*/
function getNext(array $arr)
{
// step 1
// [4,4,6,5] -> j=1 (4 > 6)
@Lexx918
Lexx918 / boxes.php
Last active July 1, 2016 11:55
Распределение камней по карманам
<?php
/*
* Есть n камней. 0 < n < 21. Их вес колеблется от 1 до 100 000.
* Нужно разложить их в две сумки, что бы разница веса между сумками была минимальная.
*/
$rocksCount = 20;
$rocks = [];
for ($i = 0; $i < $rocksCount; $i++) {
@Lexx918
Lexx918 / emoji.php
Last active November 26, 2016 15:58
Emoji+
<?php
// http://unicode.org/emoji/charts-beta/full-emoji-list.html
$src = __DIR__ . "/emoji.html";
$dest = __DIR__ . "/emoji+.html";
$f = fopen($dest, "w");
fwrite($f, "<html><head></head><body><table>");
fwrite($f, "<tr>
<th>#</th>
@Lexx918
Lexx918 / find-sub-image.php
Created November 22, 2016 21:13
Find small sub-image on big image
<?php
$size = 'big';
$cut = __DIR__ . "/{$size}/2.png";
list($cutWidth, $cutHeight) = getimagesize($cut);
$cutImg = imagecreatefrompng($cut);
$cutColorList = [];
for ($y = 0; $y < $cutHeight; $y++) {
for ($x = 0; $x < $cutWidth; $x++) {
$color = imagecolorat($cutImg, $x, $y);
@Lexx918
Lexx918 / php-proxy.php
Created December 6, 2016 07:04
PHP Proxy
<?php
//$request = "CONNECT foo HTTP/1.1
//bar
//Host: foo1
//
//";
//$pattern = '/(?P<url>(GET|PUT|DELETE|POST|CONNECT)\s+[^\s]+)\s+HTTP\/[0-9.]+.+?Host:\s+(?P<host>[^:\s]+)(:(?P<port>\d+))?\s+/s';
//if (preg_match($pattern, $request, $matches) === 1) {
// var_dump($matches);
@Lexx918
Lexx918 / js.zipper.php
Last active June 9, 2019 07:08
js.zipper.php
<?php
$str = trim(file_get_contents(__DIR__.'/tetris.min.js'));
$str = str_replace('"', "'", $str);
// $str = str_replace('function', '', $str);
$origLen = strlen($str);
echo "orig len: {$origLen}\n";
$dictionary = str_split(