Skip to content

Instantly share code, notes, and snippets.

View mlocati's full-sized avatar

Michele Locati mlocati

View GitHub Profile
@mlocati
mlocati / color-scale.js
Last active October 25, 2024 13:11
Javascript color scale from 0% to 100%, rendering it from red to yellow to green
// License: MIT - https://opensource.org/licenses/MIT
// Author: Michele Locati <[email protected]>
// 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 / remove-old-kernel-versions.php
Last active August 29, 2015 14:03
Remove old kernel versions, by keeping only the active one and the latest one
#!/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 June 16, 2016 09:57
Translate Country names for Webogram
/* 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 <[email protected]>
* @licence: MIT
*/
try {
var fs = require('fs'), path = require('path');
@mlocati
mlocati / concrete5.md
Created December 24, 2015 11:03
concrete5 under nginx

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 September 24, 2024 13:45
ANSI Colors in standard Windows 10 shell
@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 June 28, 2019 14:25
Correct wrong email and name in all git commits
#!/bin/bash
WRONG_EMAIL="[email protected]"
CORRECT_EMAIL="[email protected]"
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 December 20, 2019 14:46
Convert SVN repository to GIT
#!/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 January 19, 2024 14:10
Enable/disable/check color support for Windows (ENABLE_VIRTUAL_TERMINAL_PROCESSING flag)
#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 October 7, 2016 08:10
Script to compile PHP
@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 November 8, 2016 20:12
Call php-cs-fixer by automatically locating the configuration file
@echo off
setlocal enabledelayedexpansion
if "%~1" equ "" (
echo Missing file name>&2
goto :eof
)
if "%~2" neq "" (