Skip to content

Instantly share code, notes, and snippets.

@milo
milo / terminal.colors
Created May 13, 2013 21:44
Count of colors supported by terminals
# Created by commands
(for t in `find /lib/terminfo -type f`; do TERM=`basename $t`; echo $TERM `tput colors`; done) > terminfo.tmp
(for t in `find /lib/terminfo -type l`; do TERM=`basename $t`; echo $TERM `tput colors`; done) >> terminfo.tmp
sort terminfo.tmp > terminfo.txt
echo >> terminfo.txt
(for t in `find /usr/share/terminfo -type f`; do TERM=`basename $t`; echo $TERM `tput colors`; done) > terminfo.tmp
(for t in `find /usr/share/terminfo -type l`; do TERM=`basename $t`; echo $TERM `tput colors`; done) >> terminfo.tmp
sort terminfo.tmp >> terminfo.txt
@milo
milo / fid-remove.js
Created April 20, 2017 12:46
Flash message _fid parameter remove.
(function (w, timeout) {
setTimeout(function () {
var url = w.location.toString();
if (w.history && w.history.replaceState && url.indexOf('_fid=') !== -1) {
w.history.replaceState({}, null, /[?&]_fid=[^&]+$/.test(url)
? url.replace(/[?&]_fid=[^&]+/, '')
: url.replace(/([?&])_fid=[^&]+&/, '$1')
);
}
}, timeout || 2000);
@milo
milo / vhost.conf
Created November 22, 2017 11:26
Apache proxy to localhost port with WebSockets
#
# Proxy for local running .NET application on port 5000
#
# a2enmod proxy proxy_http proxy_wstunnel
#
<VirtualHost *:443>
ServerName example.com
ServerAdmin webmaster@example.com
@milo
milo / CsvResponse.php
Last active June 25, 2018 12:06
CSV response for Nette Application
<?php
declare(strict_types=1);
namespace App\Responses;
use Nette\Application;
use Nette\Http;
@milo
milo / ServiceCollectionsExtension.php
Created October 3, 2018 13:56
Nette DI service collections
<?php
declare(strict_types=1);
namespace App;
use Nette\DI\CompilerExtension;
/**
@milo
milo / Crypt.php
Last active January 28, 2019 09:13
Crypt with OpenSSL
<?php
/**
* Copyright (c) 2015 Miloslav Hůla (https://github.com/milo)
*/
namespace Milo;
final class Crypt
@milo
milo / local-composer-deps-bothers.md
Created December 8, 2014 17:12
Why local composer dependencies bothers (sucks)

This is reaction to article Using local packges as composer dependencies.

The described technique bothers for two main things (mentioned on the article end):

  • after every dependency package change (even one single character) you have to commit changes
  • after that you have to call composer update (on big project, you have to wait few seconds for autoload.php is created)

My best technique is:

  • create project by composer with all dependencies
  • drop developed dependencies from composer.json and run composer update (or just delete them in vendor folder)
  • clone all dependencies into project/libs-dev/... subdirecotries (or link them by file system links)
@milo
milo / LatteBackportMacros.php
Created February 14, 2020 15:07
Latte 2.7 macros bacported for Latte 2.6
<?php
/**
* I'm excited from PhpStorm Latte plugin update and support of new {varType} and {templateType} macros prepared for
* a new Latte 2.7 release. But I'm still using Latte 2.6. This class is a temporary backport of this macros before
* I upgrade to 2.7.
*
* About plugin updates: https://forum.nette.org/en/32907-upgrades-in-latte-plugin-for-phpstorm
*/
@milo
milo / github-webhook-handler.php
Last active July 26, 2023 15:29
GitHub Webhook Handler
<?php
/**
* GitHub webhook handler template.
*
* @see https://docs.github.com/webhooks/
* @author Miloslav Hůla (https://github.com/milo)
*/
$hookSecret = 's.e.c.r.e.t'; # set NULL to disable check
@milo
milo / php-oci8-debian.md
Last active April 5, 2024 03:22
PHP Oracle OCI8 extension on Linux Debian

Oracle Instant Client libraries installation

Download Oracle Instant Client libraries (URL may change, already happened few times). Be sure you download correct (x64 or x32) architecture. And correct version.

Last time I used Client 21.5.0.0.0 with Oracle 12c and PHP 8.1 and 8.3.

Before that Instant Client 21.3.0.0.0 with Oracle 12c and compiled with PHP 8.0, 7.4 and 7.3 fine.

Before that Instant Client 10.1.0.5.0 with Oracle 10g, 11g and 12c and PHP 5.6, 7.1, 7.2, 7.3 and 7.4.

Never hit any problem with such setups but my queries are quite simple. One should be fine with the newest version. It should be backward compatible (fingers crossed).