Skip to content

Instantly share code, notes, and snippets.

View alvfig's full-sized avatar
😀
tackling side projects in the off-hours

Alvaro Figueiredo alvfig

😀
tackling side projects in the off-hours
View GitHub Profile
@alvfig
alvfig / auto_cleanup.sh
Last active October 16, 2018 17:37
A very simple lock system to avoid multiple instances of the same process
#!/bin/bash
# auto_cleanup.sh - simple lock system
LOCKFILE="auto_cleanup.pid"
# Check for another instance
if [[ -e "$LOCKFILE" ]] && pgrep -F "$LOCKFILE" > /dev/null; then
echo "there is another active instance" 1>&2
exit 1
fi
@alvfig
alvfig / easter.js
Created August 17, 2018 03:36
Evaluation of the Easter day
// easter.js
// Gauss Algorithm
// https://pt.m.wikipedia.org/wiki/Cálculo_da_Páscoa
//
exports.easterSunday = function(year) {
var X=0;
var Y=0;
if (year>=1582 && year<=1699){X = 22; Y = 2;}
if (year>=1700 && year<=1799){X = 23; Y = 3;}
@alvfig
alvfig / cactorial.c
Last active October 22, 2018 03:05
Factorial snippets
/* cactorial.c - evaluates factorial */
#include <stdio.h>
#include <stdlib.h>
double recursive_factorial(int n) {
if (n <= 0)
return 0;
if (1 == n)
return 1;
@alvfig
alvfig / fibonacci.py
Last active August 16, 2018 06:43
Fibonacci sequence snippets
#!/bin/python
"""Fibonacci sequence snippets"""
# Python 2 compatibility
from __future__ import division, print_function
import argparse
import math
@alvfig
alvfig / oldest_file.sh
Last active May 6, 2019 03:18
Shell script routine to pick the oldest file on a directory tree
#!/bin/sh
oldest_file()
{
local dir="$1"
[ -d "$dir" ] || dir="."
find "$dir" -type f -printf '%T+ %p\n' | sort | awk '{print $2; exit}'
}
oldest_file "$@"
@alvfig
alvfig / date_arithmetic.sh
Last active September 30, 2017 23:07
Shell routines for date arithmetic
#!/bin/sh
# shell date arithmetic
secs()
{
TZ=UTC date --date="$1" '+%s'
}
date_diff()
{