Skip to content

Instantly share code, notes, and snippets.

View ltpitt's full-sized avatar
🥋
A black belt is a white belt that never quit.

Davide Nastri ltpitt

🥋
A black belt is a white belt that never quit.
View GitHub Profile
@ltpitt
ltpitt / download-latest-code-from-git.sh
Last active February 27, 2017 12:59
Git commands to download latest version of your code from repository
# Reset current HEAD to the specified HEAD state
git reset --hard HEAD
# Fetch from the remote repository and integrate with local branch
git pull
@ltpitt
ltpitt / countOccurrenciesInString.js
Last active February 27, 2017 13:09
Javascript function that counts occurrencies of a substring in a string
/** Function that counts occurrencies of a substring in a string;
* @param {String} string The string
* @param {String} subString The sub string to search for
* @param {Boolean} [allowOverlapping] Optional. (Default:false)
* @return {Integer} Total count of occurrencies
*/
function occurrencesCount(string, subString, allowOverlapping) {
string += "";
subString += "";
if (subString.length <= 0) return (string.length + 1);
@ltpitt
ltpitt / calculateDatetimeDeltaHours.js
Last active February 27, 2017 13:11
Javascript function that calculates the difference between two datetime in hours
/**
* Calculates the difference between two datetime in hours
* @param {String} Current datetime (any format compatible with Date)
* @param {String} Start datetime (any format compatible with Date)
* @return {Integer} The difference between Current datetime and Start datetime in hours
*/
function calculateDatetimeDeltaHours(datetimeCurrent, datetimeStart) {
var datetimeCurrent = new Date(datetimeCurrent);
var datetimeStart = new Date(datetimeStart);
var deltaHours = Math.abs(datetimeCurrent - datetimeStart) / 36e5
// Password change timestamp
var int_pass_rotation = "2017-03-06";
var lastPasswordUpdateDate = new Date(int_pass_rotation);
console.log(lastPasswordUpdateDate);
// GET CURRENT DATE
var now = new Date();
console.log(now);
@ltpitt
ltpitt / create-python-cli-tool.sh
Created April 24, 2017 12:50
Easily create python command line tools using cookie cutter templates
# You need pipsi or pip to proceed. Once that is sorted...
pip install cookiecutter.
# Go in preferred folder
cd ~/Desktop
# Start cookiecutter using python cli tool template
cookiecutter https://github.com/ltpitt/cookiecutter-python-cli
@ltpitt
ltpitt / check-os.sh
Created April 24, 2017 12:55
Function to check Distribution and Version of *nix Operating Systems
# OS check function
os_check ()
{
OS=`uname -rs`
if [ "`uname -rs | grep 'Linux 2.6.9'`" ]
then
OS=RHEL_4
elif [ "`uname -rs | grep 'Linux 2.6.18'`" ]
then
@ltpitt
ltpitt / pip-reinstall.sh
Created April 26, 2017 13:49
Force pip reinstall of a specified tool
# Reinstall Python package present in the current folder
sudo pip install . --upgrade --force-reinstall
@ltpitt
ltpitt / freeze.sh
Created May 31, 2017 21:55
How to freeze Python application requirements
# How to freeze pip requirements
pip freeze > requirements.txt
@ltpitt
ltpitt / runguiapp.sh
Last active June 1, 2017 17:06
Run a GUI application when you connect to a Linux computer from ssh
DISPLAY=:0 firefox http://www.google.com
@ltpitt
ltpitt / reverse_tunnel_ssh.sh
Last active June 27, 2017 07:33
Reverse tunnel ssh on Linux
#!/bin/sh
# Forward only to loopback interface of the server
ssh -fN -R 10022:CLIENTIPTOFORWARD:22 SERVER
# Forward to all interfaces
# In this case it is mandatory to add
# GatewayPorts yes
# to /etc/ssh/sshd_config
ssh -R \*:3389:WINDOWSCLIENT:3389 -N root@yourserver.com