tuxninja

Tuxninja aka Jason Riedel has worked as a Systems & Network Administrator and Code Hacker since 1999. Since 2005 he has worked for PayPal with a focus on Operations Architecture. He is also CEO of Tuxlabs LLC where he dedicates his time to the experimentation and close study of new technologies and programming languages.

How To Build An Ansible Clone

Today marks an important milestone, I have released my very first course that teaches you how to build Commander, a parallel SSH / SCP utility, similar to the core that powers Ansible, Rundeck and other DevOps tools. If you are interested in learning how to SSH using Python this is a great course to checkout, also if you just want a cool Python project, I think you found the one! If you have any questions contact me on Twitter or via jason@tuxlabs.com.

Buy on

How To Build An Ansible Clone Read More »

Convert Google Sheet/Excel to SQL

Have a lot of data you want to populate into a SQL database? Most likely you have that data in a spreadsheet or can easily put it in one. In this case use the following script I wrote to convert your Spreadsheet data to SQL statements and then import them to your SQL database of choice. All that is required is putting your data in the spreadsheet with headers, exporting to TSV and then updating the script for file names and running it.

Here is the code. Enjoy!

#!/usr/bin/env python3
# Generates SQL from TSV 
# Author: Jason Riedel ( Follow me on twitter - jasonriedel.com )
import pandas
import numpy as np


def parse_tsv_to_df(path):
    df = pandas.read_csv(path, header=0, sep="\t", dtype=object)

    # replace NaN's with empty string
    df_new = df.replace(np.nan, "", regex=True)

    return df_new.replace("'", "''", regex=True)


def print_sql(table_name, fname, df):
    with open(fname, "w") as f:
        row_values = df.values.tolist()
        headers = list(df.columns)
        cols = ", ".join(headers)
        for row in row_values:
            values = ", ".join("'{0}'".format(col) for col in row)
            sql = f"INSERT INTO {table_name} ({cols}) VALUES ({values});\n"
            f.write(sql)


if __name__ == "__main__":
    df = parse_tsv_to_df("tsv/my_table.tsv")
    print_sql("my_table", "sql/my_table_seed.sql", df)

Convert Google Sheet/Excel to SQL Read More »

How to setup Flask and Apache on an Ubuntu VM in DigitalOcean with a Custom Domain

In this video I show how setup Flask and Apache on an Ubuntu VM in Digital Ocean with a custom domain. This was made after someone in the comments on my other DigitalOcean video requested it. If there is something else anyone would like to see, please just let me know I am happy to provide these walk through’s.

Note: I hit a number of challenges with DNS in this one, I think it’s fun to watch me struggle. Enjoy!

How to setup Flask and Apache on an Ubuntu VM in DigitalOcean with a Custom Domain Read More »