Skip to content

Instantly share code, notes, and snippets.

View p182's full-sized avatar

p182

  • Донецьк, Україна
  • 19:16 (UTC +03:00)
View GitHub Profile
@p182
p182 / mirrors.php
Last active December 19, 2023 20:54
Generate advanced apt mirror.txt file for sources.list, supports different mirrorlist sources (from different locations, etc.) and host/path filtering
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$locations = ['mirrors', 'SE', 'FI']; //locations to download lists for, mirrors is for local mirrors.txt by GeoIP, not always fastest servers
$substrings = ["truenetwork.ru", "linux-ia64.org", "powernet.com.ru", "timeweb.ru", "yandex", "hyperdedic.ru"]; //substrings of mirror URLs to exclude
$filteredLines = ["http://mirrors.linode.com/ubuntu/".PHP_EOL,"http://mirrors.digitalocean.com/ubuntu/".PHP_EOL]; //array definition to add mirrors to output
foreach ($locations as $location){
$url = 'http://mirrors.ubuntu.com/'.$location.'.txt';
$cache_file = '/tmp/mirrors_'.$location;
@p182
p182 / youtube_formats.md
Created November 9, 2023 00:02 — forked from AgentOak/youtube_formats.md
Youtube Format IDs

Last updated: April 2021

Also known as itag or format codes and way back they could be specified with the fmt parameter (e.g. &fmt=22). Depending on the age and/or popularity of the video, not all formats will be available.

DASH video

Resolution AV1 HFR High AV1 HFR AV1 VP9.2 HDR HFR VP9 HFR VP9 H.264 HFR H.264
MP4 MP4 MP4 WebM WebM WebM MP4 MP4
#include <stdio.h>
#include <stdlib.h> //Бібліотека з функціями rand і srand
#include <time.h> //Для генерації "солі", функції rand(srand)
int main () {
int arr[1024]; //ініціалізація масиву в пам'яті
int i,n=10,c=0;
srand(time(NULL)); //ініціалізація "солі"
@p182
p182 / copy.php
Created November 4, 2021 23:55
Copy snippet
<?php
/*Below a code snippet for downloading a file from a web server to a local file.
It demonstrates useful customizations of the request (such as setting a User-Agent and Referrer, often required by web sites), and how to download only files if the copy on the web site is newer than the local copy.
It further demonstrates the processing of response headers (if set by server) to determine the timestamp and file name. The file type is checked because some servers return a 200 OK return code with a textual "not found" page, instead of a proper 404 return code.
*/
// $fURI: URL to a file located on a web server
// $target_file: Path to a local file
@p182
p182 / import.php
Last active July 20, 2023 14:35
Импортирование файла с проверкой на расширение и автоматическим перенаправлением
<?php
header('Content-Type: text/html; charset=utf-8'); //Заголовок с типом HTML и кодировкой UTF-8
$url = $_GET['url']; //Переменная с адресом загрузки
$name = $_GET['name']; //Переменная с именем файла в папке назначения
$source = $_GET['source'];
if(preg_match('/^.*\.(\S*)$/', $name, $res)){//Выделение расширения (последней части, после точки в имени файла $name)
if (in_array($res[1], array("jar", "zip"))){//Проверка, что расширение в списке разрешённых
$arrRequestHeaders = array(//установка заголовка GET запроса с referrer и поддержкой перенаправлений
'http'=>array(
'method' =>'GET',
@p182
p182 / hellobot.php
Created January 14, 2021 14:55
Hello Telegram bot example in PHP
<?php
define('BOT_TOKEN', 'ТОКЕН БОТА'); //СЕКРЕТНЫЙ КЛЮЧ, получить в @BotFather
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
function apiRequestWebhook($method, $parameters) {
if (!is_string($method)) {
error_log("Method name must be a string\n");
return false;
}
[
{
"value": 1,
"first": "bar",
"second": "bar",
"third": "bar"
},
{
"value": 2,
"first": "grape",
@p182
p182 / proxy.php
Created January 29, 2019 18:43 — forked from codedokode/proxy.php
Простой прокси-сервер на PHP для изучения и модификации данных, передаваемых между браузером и сторонним сервером
<?php
/**
* Простой прокси-сервер на PHP для изучения и модификации данных,
* передаваемых между браузером и сторонним сервером.
*
* Запуск:
*
* указать URL сайта в $base
* php -S 127.0.0.1:9001 proxy.php
*