Skip to content

Instantly share code, notes, and snippets.

Avatar

Michele Locati mlocati

View GitHub Profile
@mlocati
mlocati / win10colors.cmd
Last active Sep 13, 2022
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 / app.php
Last active Aug 25, 2022
Install concrete5 on Android (Termux)
View app.php
<?php
// Save this file as /application/bootstrap/app.php
if (!function_exists('fnmatch')) {
// Shim for fnmatch
// Code from https://www.php.net/manual/en/function.fnmatch.php#100207
define('FNM_PATHNAME', 1);
define('FNM_NOESCAPE', 2);
define('FNM_PERIOD', 4);
define('FNM_CASEFOLD', 16);
@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 Jul 18, 2022
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
View color-scale.js
// License: MIT - https://opensource.org/licenses/MIT
// Author: Michele Locati <michele@locati.it>
// Source: https://gist.github.com/mlocati/7210513
function perc2color(perc) {
var r, g, b = 0;
if(perc < 50) {
r = 255;
g = Math.round(5.1 * perc);
}
else {
@mlocati
mlocati / main.c
Last active May 12, 2022
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 / compile-php.cmd
Created Oct 7, 2016
Script to compile PHP
View compile-php.cmd
@echo off
setlocal enabledelayedexpansion
rem Reference: https://wiki.php.net/internals/windows/stepbystepbuild
set MY_VSDIR=C:\Path\To\Microsoft Visual Studio 14.0
set PATH=%SystemRoot%\System32
echo # Compiling PHP
@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 / 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}");