Skip to content

Instantly share code, notes, and snippets.

@kovid-rathee
kovid-rathee / static_server.js
Created February 3, 2017 10:39 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@kovid-rathee
kovid-rathee / etl_mysql_redshift.sh
Last active February 3, 2017 11:15
Script to Load a table from MySQL to Amazon Redshift with Alerting.
#!/bin/sh
credentials()
{
username=loader
password=L0#De&1234
hostname=127.0.0.1
database=yourdatabasename
postgres_user=postgresusr
@kovid-rathee
kovid-rathee / pandas_scatterplot_pyplot.py
Created January 25, 2017 20:11
Create a basic scatter plot using matplotlib on random data set generated by NumPy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# if you want a list of integers as your random data set
df = pd.DataFrame(np.random.randint(0,20,size=(20, 2)), columns=list('PQ'))
# if you want a list of random decimal numbers as your random data set
df = pd.DataFrame(np.random.randn(20,2), columns=list('PQ'))
# plot the data
plt.scatter(df.P,df.Q, alpha=0.5)
# plt.show()
@kovid-rathee
kovid-rathee / pandas_mysql_dataframe.py
Created January 25, 2017 19:05
Script to connect to a MySQL source, fetch data and print loosely formatted data using pandas DataFrame
import MySQLdb as mdb
import pandas as pd
con = mdb.connect(‘127.0.0.1’, ‘root’, ‘password’, ‘database_name’);
with con:
cur = con.cursor()
cur.execute(“select random_number_one, random_number_two, random_number_three from randomness.a_random_table”)
rows = cur.fetchall()
df = pd.DataFrame( [[ij for ij in i] for i in rows] )
df.rename(columns={0: ‘Random Number One’, 1: ‘Random Number Two’, 2: ‘Random Number Three’}, inplace=True);
print(df.head(20))