Skip to content

Instantly share code, notes, and snippets.

Avatar

Michele Locati mlocati

View GitHub Profile
@mlocati
mlocati / win10colors.cmd
Last active Oct 16, 2021
ANSI Colors in standard Windows 10 shell
View win10colors.cmd
@echo off
setlocal
call :setESC
cls
echo %ESC%[101;93m STYLES %ESC%[0m
echo ^<ESC^>[0m %ESC%[0mReset%ESC%[0m
echo ^<ESC^>[1m %ESC%[1mBold%ESC%[0m
echo ^<ESC^>[4m %ESC%[4mUnderline%ESC%[0m
@mlocati
mlocati / exceptions-tree.php
Created Mar 9, 2017
Throwable and Exceptions tree
View exceptions-tree.php
<?php
if (!function_exists('interface_exists')) {
die('PHP version too old');
}
$throwables = listThrowableClasses();
$throwablesPerParent = splitInParents($throwables);
printTree($throwablesPerParent);
if (count($throwablesPerParent) !== 0) {
die('ERROR!!!');
@mlocati
mlocati / color-scale.js
Last active Sep 23, 2021
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
View color-scale.js
function perc2color(perc) {
var r, g, b = 0;
if(perc < 50) {
r = 255;
g = Math.round(5.1 * perc);
}
else {
g = 255;
r = Math.round(510 - 5.10 * perc);
}
@mlocati
mlocati / attach-release-asset.yml
Last active Aug 6, 2021
Attach concrete5/ConcreteCMS package archive to releases
View attach-release-asset.yml
name: Attach release asset
on:
release:
types:
- created
jobs:
attach_release_asset:
name: Attach release asset
@mlocati
mlocati / create-release-asset.sh
Created Aug 6, 2021
Attach concrete5/ConcreteCMS
View create-release-asset.sh
#!/bin/sh
set -o errexit
set -o nounset
printf -- '- cleanup... '
rm -rf ./tmp
mkdir ./tmp
echo 'done.'
@mlocati
mlocati / main.c
Last active May 20, 2021
Enable/disable/check color support for Windows (ENABLE_VIRTUAL_TERMINAL_PROCESSING flag)
View main.c
#define _WIN32_WINNT 0x0600
#include <stdio.h>
#include <windows.h>
#include <fileapi.h>
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
@mlocati
mlocati / list-pecl-versions.php
Created Dec 8, 2020
List all currently defined versions of PECL packages
View list-pecl-versions.php
<?php
set_error_handler(
static function ($errno, $errstr, $errfile, $errline)
{
$message = trim((string) $errstr);
if ($message === '') {
$message = "Unknown error (code: {$errno})";
}
if ($errfile) {
@mlocati
mlocati / fix-ckeditor-eol.php
Last active Nov 10, 2020
Fix CKEditor 4 line endings
View fix-ckeditor-eol.php
#!/usr/bin/env php
<?php
const FIX_EOL = true;
const FIX_BOM = true;
set_error_handler(
static function ($errno, $errmsg, $errfile, $errline)
{
throw new RuntimeException("Error {$errno}: {$errmsg}\nFile: {$errfile}\nLine: {$errline}");
@mlocati
mlocati / Enable-HyperV.ps1
Last active Jul 30, 2020
Enable or disable Hyper-V (to switch between VirtualBox and Docker for Windows, for example)
View Enable-HyperV.ps1
<#
To enable Hyper-V:
Enable-HyperV.ps1 $True
To disable Hyper-V:
Enable-HyperV.ps1 $False
Author: Michele Locati <michele@locati.it>
License: MIT
Source: https://gist.github.com/mlocati/bb146577785511b44412e2fb57f969a6
#>
View concrete5-migrations-checker.php
<?php
declare(strict_types=1);
set_error_handler(
static function ($code, $message, $file, $line): void
{
throw new RuntimeException("{$message}\nFile: {$file}\nLine: {$line}");
},
-1
);