Skip to content

Instantly share code, notes, and snippets.

View coderoffortune's full-sized avatar

Alessandro Garzaro coderoffortune

  • Yoox Net-A-Porter Group
  • Bologna, Italy
View GitHub Profile
@coderoffortune
coderoffortune / Dockerfile
Created March 23, 2019 16:03
Simple Dockerfile for dotnet core
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS builder
WORKDIR /build
COPY dotnetapp.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o out
namespace Extensions
{
public static class TryParseOrElseExtension
{
public static int TryParseOrElse(this string value, int orElse)
{
return int.TryParse(value, out int result) ? result : orElse;
}
}
}
@coderoffortune
coderoffortune / closebranch.ps1
Last active May 3, 2017 07:48
A script to automate branches closure in mercurial
param (
[Parameter(Mandatory=$true)][String[]]$branches
)
# Default catchall branch for closed branches
$closureOldBranchName = "CLOSURE_OLD_BRANCH"
$closedBranches = @()
# Runs a loop on the branches passed as param
@coderoffortune
coderoffortune / keeplatests.sh
Last active April 19, 2017 14:35
Quickly remove old backup files from backup folder to avoid clutter and keep disk space usage at bay
#Explanation:
# ls -t => Lists the files in a folder in decrescent order of modification time, so it will list newer files first
# sed -e '1,50d' => Filters the first Nth (50 in this case) lines leaving only the oldest files
# grep -v "lost+found" => Optional, if you are in a backup disk root you will need this probably, otherwise you can omit it
# awk '{print "/mnt/backup/"$1}' => Prepend the absolute path to the file name so it's easier to run it in a cron job
# xargs -d '\n' rm => Takes every lines from the pipe, strips out the newline char and passes it to the rm command
@coderoffortune
coderoffortune / cleanup.pl
Created December 15, 2014 10:49
A simple script to cleanse injected code in php files, it can use a tweak or two in performances but it does the job.
#!/usr/bin/perl
use Cwd;
use File::Find;
use Getopt::Long;
use strict;
use warnings;
my $dir = cwd() . "/";