Skip to content

Instantly share code, notes, and snippets.

@danillab
danillab / curl time till first byte.py
Created October 29, 2017 06:48
Getting TTFB (time till first byte) for an HTTP Request
# https://stackoverflow.com/questions/744532/getting-ttfb-time-till-first-byte-for-an-http-request
import pycurl
import sys
import json
WEB_SITES = sys.argv[1]
def main():
c = pycurl.Curl()
c.setopt(pycurl.URL, WEB_SITES) #set url
@danillab
danillab / translit.php
Last active January 19, 2020 12:25
Транслит для Яндекса
<?php
function translit($str) {
$tr = array("а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d","е"=>"e","ё"=>"e","ж"=>"j","з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l","м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r","с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h","ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"shh","ъ"=>"","ы"=>"y","ь"=>"","э"=>"e","ю"=>"u","я"=>"ya","—"=>"-","«"=>"","»"=>"","…"=>""," "=>"-","№"=>"#");
$str = mb_strtolower($str,'utf-8');
// $str = preg_replace("/\s+/",' ',$str);
$str = strtr(trim($str), $tr);
$str = trim(preg_replace("/\-+/",'-',$str),'- ');
$str = preg_replace('~[^a-z0-9/-]~', '', $str);
return $str;
@danillab
danillab / post-m.php
Created February 28, 2013 12:56
post-m
<?php
function post($url, $postdata = 0){
$ch = curl_init($url);
if(!empty ($GLOBALS['_proxy'])){
curl_setopt($ch, CURLOPT_PROXY, $GLOBALS['_proxy']);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
}
if(!empty ($postdata)){
curl_setopt($ch, CURLOPT_POST, true);