Skip to content

Instantly share code, notes, and snippets.

@marcom04
marcom04 / just_ask.py
Created March 2, 2017 14:35
One more question
def ask(question, answers_type=None, answers=None, menu=None, menu_args=None):
""" Ask a question. (duh!)
Params:
- question: a string representing the question to ask
- answers_type: raw input will be casted to this tipe (if None, answer will be kept as string)
- answers: a list containing the feasible answers (if None, the answer can be any)
- menu: a function that prints a user menu
- menu_args: optional parameters to pass to menu function
@marcom04
marcom04 / authorize_me.sh
Last active October 4, 2016 07:10
Append SSH public key to authorized_keys
#!/bin/bash
# Usage: ./authorize_me.sh <public_key_file>
# Example: ./authorize_me id_rsa.pub
cat <<EOT >> ~/.ssh/authorized_keys
`cat $1`
EOT
@marcom04
marcom04 / menuapp.sh
Created September 29, 2016 06:34
Basic Bash menu
#!/bin/bash
readonly RED='\033[0;41;30m'
readonly STD='\033[0;0;39m'
function show_menu()
{
clear
echo ""
@marcom04
marcom04 / log_to_csv.py
Created September 28, 2016 14:18
Converts a generic log file with separated fields into CSV file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
events = ("warning", "Warning", "error", "Error") # put here strings of interest in log
log_file = sys.argv[1]
log_separator = ':'
@marcom04
marcom04 / bash_spinner.sh
Created September 28, 2016 14:09
Simple spinner for Bash
#!/bin/bash
spinner()
{
local phrase="Doing stuff..."
local pid=$1
local delay=0.5 # Adjust spinner speed
local spinstr='|/-\' # Spinner sequence
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
@marcom04
marcom04 / .python-c-echo
Last active April 20, 2024 18:14
Basic echo between Python client and C server via socket using Python ctypes
Basic echo between Python3 client and C server, and vice versa, via socket using Python ctypes