Skip to content

Instantly share code, notes, and snippets.

Avatar

Michele Locati mlocati

View GitHub Profile
@mlocati
mlocati / color-scale.js
Last active Nov 24, 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 / remove-old-kernel-versions.php
Last active Aug 29, 2015
Remove old kernel versions, by keeping only the active one and the latest one
View remove-old-kernel-versions.php
#!/usr/bin/php
<?php
try {
$doEcho = true;
$action = 'view';
if(isset($argv) && is_array($argv) && (count($argv) == 2)) {
$action = strtolower($argv[1]);
switch($action) {
case 'view':
case 'simulate':
@mlocati
mlocati / translate-countries.js
Last active Jun 16, 2016
Translate Country names for Webogram
View translate-countries.js
/* A little utility to translate Country names for Webogram.
* You need to install nodejs.
* Usage: node <thisfile> <languageCode> <inputFile> [outputFile]
* If outputFile is not specified, inputFile will be overwritten.
*
* @author: Michele Locati <mlocati@gmail.com>
* @licence: MIT
*/
try {
var fs = require('fs'), path = require('path');
@mlocati
mlocati / concrete5.md
Created Dec 24, 2015
concrete5 under nginx
View concrete5.md

Here's a very basic nginx configuration for a website running concrete5:

# Define the server configuration
server {
	# Define the ports the server is listening to
	# In case this is the default website, you can add default_server before the semicolon
	listen 80;
	listen [::]:80 ipv6only=on;
@mlocati
mlocati / win10colors.cmd
Last active Nov 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 / fix-git-authors.sh
Last active Jun 28, 2019
Correct wrong email and name in all git commits
View fix-git-authors.sh
#!/bin/bash
WRONG_EMAIL="wrong@email.address"
CORRECT_EMAIL="correct@email.address"
CORRECT_NAME="Correct Name"
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]; then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]; then
@mlocati
mlocati / svn2git.sh
Last active Dec 20, 2019
Convert SVN repository to GIT
View svn2git.sh
#!/bin/bash
# This script was written for Ubuntu 14.04 and 16.04
# Other operating systems may need a few changes
WORK_DIR=~/svn2git
AUTHORS_FILE=$WORK_DIR/authors.txt
GITDIR_DIRTY=$WORK_DIR/dirty
GITDIR_FINAL=$WORK_DIR/final
@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 / 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 / php-cs-fixer.cmd
Created Nov 8, 2016
Call php-cs-fixer by automatically locating the configuration file
View php-cs-fixer.cmd
@echo off
setlocal enabledelayedexpansion
if "%~1" equ "" (
echo Missing file name>&2
goto :eof
)
if "%~2" neq "" (