Skip to content

Instantly share code, notes, and snippets.

@gentoo90
gentoo90 / ask_pass_if_not_saved.py
Created May 26, 2014 19:00
Ask password if not found in keyring
from getpass import getpass
try:
import keyring
def get_passwd(address, username):
passwd = keyring.get_password(address, username)
if passwd is None:
passwd = getpass('Password for %s: ' % address)
keyring.set_password(address, username, passwd)
return passwd
@gentoo90
gentoo90 / colorprompt.sh
Last active December 19, 2015 18:29
Put this file into "/etc/profiles.d/" and get colored prompt: green for users and red for root. Tested on CentOS 6.2 x64. Grabbed from http://bash.cyberciti.biz/guide/Changing_bash_prompt
# bash color prompt
bash_prompt_command() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
#dates
chalange3 = /^(1\d{3}|20(0\d|1[02]))\/(0[1-9]|1[0-2])\/(0[1-9]|[1-2]\d|30)\s([0-1]\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/