Skip to content

Instantly share code, notes, and snippets.

View bizley's full-sized avatar
🖤
Kurald Galain user

Bizley bizley

🖤
Kurald Galain user
View GitHub Profile
@bizley
bizley / yii-index.php
Created September 2, 2014 11:23
Yii 1.1 index.php file with output buffering
<?php
$yii = dirname(__FILE__) . '/framework/yii.php';
$config = dirname(__FILE__) . '/protected/config/main.php';
if (isset($_SERVER['REMOTE_ADDR']) && in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1'))) {
defined('YII_DEBUG') or define('YII_DEBUG', true);
ini_set('display_errors', 'on');
error_reporting(E_ALL);
}
@bizley
bizley / polish-countries.php
Last active August 29, 2015 14:07
Polish names of countries of the world (ISO 3166-1 alfa-2)
<?php
// ISO 3166-1 alfa-2
// Polish names of countries of the world
// Polskie nazwy krajów świata
$countries = [
'AF' => 'Afganistan',
'AL' => 'Albania',
'DZ' => 'Algieria',
'AD' => 'Andora',
'AO' => 'Angola',
@bizley
bizley / timezones.php
Last active August 29, 2015 14:17
Timezones supported by PHP
<?php
return [
'Africa/Abidjan',
'Africa/Accra',
'Africa/Addis_Ababa',
'Africa/Algiers',
'Africa/Asmara',
'Africa/Asmera',
'Africa/Bamako',
@bizley
bizley / CsNumberValidator.php
Created February 17, 2015 20:31
Yii 1.1 number validator that allows comma before decimals.
<?php
/**
* CsNumberValidator class file.
* @copyright 2014 Paweł Bizley Brzozowski
*/
/**
* CsNumberValidator is the same as CNumberValidator but allows comma instead of dot before decimals.
* So now 123,45 is valid number.
@bizley
bizley / multiimplode.php
Last active March 22, 2016 19:19
Multidimensional array implode (PHP >= 5.4)
/**
* Join array elements with a string.
* This method works with multidimensional arrays.
*
* @param string|array $glue the string for the array to be joined with or
* the array itself if $array is null
* @param array|null $array array to implode or null if array is provided as
* first parameter.
* @return string imploded array
* @throws \yii\base\InvalidParamException
@bizley
bizley / countries-iso.php
Created May 27, 2016 17:57
Contries ISO codes
<?php
$countries = [
'AF' => Yii::t('app/countries', 'Afghanistan'),
'AL' => Yii::t('app/countries', 'Albania'),
'DZ' => Yii::t('app/countries', 'Algeria'),
'AS' => Yii::t('app/countries', 'American Samoa'),
'AD' => Yii::t('app/countries', 'Andorra'),
'AO' => Yii::t('app/countries', 'Angola'),
'AI' => Yii::t('app/countries', 'Anguilla'),
@bizley
bizley / Sort by dependency
Last active July 4, 2019 07:50
Sorts array by elements dependency [item => [items item depends on]].
<?php
function sortByDependency($input)
{
$output = [];
$checkList = [];
$inputCount = count($input);
// while not all items are resolved:
@bizley
bizley / Postman-pre-request.js
Created September 13, 2019 12:03
Pre-request for Postman to check if OAuth2 token expired and if so to refresh it.
let currentTime = Math.floor(Date.now() / 1000);
let tokenExpiration = pm.environment.get("token_expiration");
if (tokenExpiration && tokenExpiration <= currentTime) {
let apiUrl = pm.environment.get("api_url");
let refreshToken = pm.environment.get("refresh_token");
if (refreshToken) {
pm.sendRequest(
{
url: 'http://' + apiUrl + '/oauth/v2/token',
method: 'POST',
version: '3.7'
services:
reverse-proxy:
restart: always
networks:
- dev
container_name: traefik
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
@bizley
bizley / Ocramius_PhpCache.php
Created October 31, 2019 21:37 — forked from Ocramius/Ocramius_PhpCache.php
Simple cache adapter based on var_export and include.
<?php
/**
* Simple php cache using var_export generated files
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class Ocramius_PhpCache {
const DEFAULT_TTL = 3600;