Skip to content

Instantly share code, notes, and snippets.

@justinnaldzin
justinnaldzin / timeout_and_retry_function.py
Last active March 7, 2017 18:24
Python 'Timeout' class that will raise an exception after the containing code does not finish within a specified number of seconds. Use the 'retry' decorator to retry the function a specified number of times after the timeout. NOTE: this works for Unix only. Additionally, signal only works in main thread.
import time
import signal
from retrying import retry
class Timeout:
def __init__(self, seconds=1, error_message='Timeout'):
self.seconds = seconds
self.error_message = error_message
@justinnaldzin
justinnaldzin / install_apache_maven.sh
Created February 20, 2017 17:54
Install Apache Maven
# Install Apache Maven
cd /opt
wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
tar xzf apache-maven-3.3.9-bin.tar.gz
ln -s apache-maven-3.3.9 maven
echo 'export M2_HOME=/opt/maven' >> /etc/profile.d/maven.sh
echo 'PATH=${M2_HOME}/bin:${PATH}' >> /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
@justinnaldzin
justinnaldzin / sql_server_bulk_insert
Created February 20, 2017 17:45
Create tables and insert data into SQL Server 2014 from all CSV files in a directory
#!/usr/bin/env python3
# Create tables and insert data into SQL Server 2014 from all CSV files in a directory. The process involves:
# - Read all CSV files in a directory
# - Ensure all headers are the same
# - Generate DTS (Data Transformation Service) files for all CSV files
# - Execute all .dtsx files to bulk insert the CSV
import os
@justinnaldzin
justinnaldzin / database.py
Created February 17, 2017 20:40
python class for SQLAlchemy Databases
import sys
import logging
'''Usage:
from database import Database
db = Database(attributes)
db.connect()
sql = "SELECT * FROM TABLE"
dataframe = pandas.read_sql(sql, db.connection)