Skip to content

Instantly share code, notes, and snippets.

View vakata's full-sized avatar

Ivan Bozhanov vakata

View GitHub Profile
@vakata
vakata / GoogleCloudStorage.php
Last active March 17, 2023 10:13
Google Cloud Storage mini-class
<?php
// depends on vakata/jwt (any other jwt should work too)
// composer require vakata/jwt
/*
// auth.json contains ServiceAccountCredentials
// the only required fields are client_email and private_key
$uploader = GoogleCloudStorage::fromFile('auth.json', '<bucket-name>');
var_dump($uploader->listBucket());
@vakata
vakata / middleware.php
Last active December 3, 2021 13:18
middleware callable dispatchers
<?php
// class for a stack of callables
class Dispatcher
{
protected array $stack;
public function __construct(array &$stack)
{
$this->stack = $stack;
}
public function __invoke(RequestInterface $req)
<?php
namsepace vakata\zip;
class Zip
{
protected $compression = false;
protected $data = [];
protected $ctrl = [];
protected $offset = 0;
/*
1) Open your calendar on trainerroad
2) Press F12 to open developer tools, select console and paste the script below
3) OPTIONAL - modify the two dates (beg & end) to suit your needs
4) Copy the result of the execution (something like TRData = ...)
*/
(function () {
var beg = '2021-01-01';
var end = '2022-01-01';
function normalizeDate(dat) {
@vakata
vakata / strtotime
Created August 5, 2018 07:21
strtotime in js
function strtotime (text, now) {
var parsed, match, today, year, date, days, ranges, len, times, regex, i;
if (!text) {
return false;
}
// Unecessary spaces
text = text.replace(/^\s+|\s+$/g, '')
.replace(/\s{2,}/g, ' ')
@vakata
vakata / kzp
Last active August 29, 2015 14:11
Проверка в КЗП на мейл / масив от мейли
<?php
function kzp($emails) {
if(!is_array($emails)) { $emails = [ (string)$emails ]; }
if(false === ($hashes = @file('http://www.kzp.bg/download.php?mode=fileDownload&p_attached_file_id=4956'))) {
throw new Exception('Could not load KZP hashes');
}
array_walk($hashes, function (&$hash) { $hash = substr(strtoupper(trim($hash)),0,32); });
return array_filter(array_unique($emails), function ($mail) use ($hashes) {
$mail = mb_strtolower(trim($mail),'utf-8');
return filter_var($mail, FILTER_VALIDATE_EMAIL) && !in_array(strtoupper(md5(explode('@', $mail)[1])), $hashes) && !in_array(strtoupper(md5($mail)), $hashes);
@vakata
vakata / gist:6593424
Created September 17, 2013 12:02
import Filezilla to KeePass
$xml = simplexml_load_file('FileZilla.xml');
$csv = fopen('FileZilla.csv','w');
fputcsv($csv, ["Account","Login Name","Password","Web Site","Comments"]);
foreach($xml->xpath('//Server') as $server) {
fputcsv($csv, [(string)$server->Name, (string)$server->User, (string)$server->Pass, ((int)$server->Protocol ? 'sftp://' : 'ftp://' ) . (string)$server->Host.':'.(string)$server->Port, (string)$server->Comments]);
}
fclose($csv);