Skip to content

Instantly share code, notes, and snippets.

View bpacholek's full-sized avatar

Bartosz Pachołek bpacholek

View GitHub Profile
@bpacholek
bpacholek / wykoptagstat.php
Created August 26, 2018 18:59
Lists stats for major cities on Wykop.pl
<?php
$data = file_get_contents('https://stat.gov.pl/statystyka-regionalna/rankingi-statystyczne/miasta-najwieksze-pod-wzgledem-liczby-ludnosci/');
$matches = [];
preg_match_all('/<td style="text-align: left;">(M\.st\.){0,1}(.*?)(&nbsp;){0,1}<\/td>/is', $data, $matches);
$tags = [];
$cityRank = [];
$i = 0;
foreach ($matches[2] as $city) {
$cityname = strtolower(iconv('utf8', 'ascii//TRANSLIT', str_replace([' ', '-'], ['', ''], $city)));
$cityRank[$cityname] = ++$i;
<?php
/**
* Simple method which performs a login operation to Polish reddit-like "wykop.pl"
* and fetches the number of notifications.
*
* @todo This is made just for fun! My activity on the websites was too low to
* be granted access to Wykop API.
*
* @param string $operation token, login, notifs
* @param string $username
function getStatus($num) {
$query = "curl 'https://tracking.inpost.pl/api/v1/history/package\[0\]=".$num."?_=".time()."' -H 'Origin: https://twoj.inpost.pl' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36' -H 'Accept: */*' -H 'Referer: https://twoj.inpost.pl/pl/znajdz-przesylke?parcel=".$num."' -H 'Connection: keep-alive' --compressed 2>/dev/null";
$data = shell_exec($query);
return json_decode($data, true);
}
function reportPackageInfo($num) {
$status = getStatus($num);
if (!$status || $status == 'Error') {
echo $num . ' -- brak' . PHP_EOL;
@bpacholek
bpacholek / leibniz.php
Created March 14, 2017 13:22
Leibniz formula for Pi calculation implementation
<?php
$complexity = 1000000;
$decimals = 50;
bcscale($decimals);
$num = 0;
for ($i =0; $i < $complexity; $i++) {
$num = bcadd($num, bcdiv(pow(-1, $i), bcadd(1, bcmul(2, $i) )));
}
echo bcmul(4, $num);
<?php
const BUMPER_FR = 23;
const BUMPER_FL = 24;
const BUMPER_RR = 22;
const BUMPER_RL = 25;
const E_R_F = 4;
const E_R_B = 1;
const E_L_F = 5;
<?php
const BUMPER_FR = 23;
const BUMPER_FL = 24;
const BUMPER_RR = 22;
const BUMPER_RL = 25;
const E_R_F = 4;
const E_R_B = 1;
const E_L_F = 5;
@bpacholek
bpacholek / Downloader.php
Created November 24, 2015 09:56
download
<?php
namespace Casadatos\Component\Downloader;
use Casadatos\Component\Downloader\Exception\HttpException;
use Zend\Http\Client;
use Zend\Http\Headers;
use Zend\Http\Request;
use Zend\Http\Response;
use Melihucar\FtpClient\FtpClient;
<?php
include "vendor/autoload.php";
include "Exception/HttpException.php";
include "Downloader.php";
$downloader = new Casadatos\Component\Downloader\Downloader();
$headers = new Zend\Http\Headers();
$headers->addHeaderLine("Accept-Encoding", "gzip")
->addHeaderLine("Content-Encoding", "gzip")
#include <iostream>
using namespace std;
void echotest() {
cout << "echo out of class\r\n";
}
class with_method_inside {
public:
<?php
function gen_one_to_three() {
for ($i = 1; $i <= 3; $i++) {
// Note that $i is preserved between yields.
echo "yielded $i\n";
yield $i;
}
}
$generator = gen_one_to_three();