Skip to content

Instantly share code, notes, and snippets.

View 64lines's full-sized avatar

Julian Alexander Murillo 64lines

  • Universidad Politécnica de Cartagena
  • Cartagena, Murcia - Spain
View GitHub Profile
alter table {0} rename to {1};
from redshift_utils import Messages
from redshift_utils import ScriptReader
from redshift_utils import RedshiftDataManager
from settings import SCRIPT_PATH
from settings import DB_CONNECTION
def lambda_handler(event, context):
table_name = event.get('table_name')
new_table_name = event.get('new_table_name')
import psycopg2
# Functions for reading scripts
class ScriptReader(object):
@staticmethod
def get_script(path):
return open(path, 'r').read()
# Utils for messages
###############################################
# Script settings and constants.
###############################################
SCRIPT_PATH = 'script.sql'
DB_CONNECTION = {
'db_host': 'myhost.redshift.amazonaws.com',
'db_name': 'somedb',
'db_username': 'user',
'db_password': 'pA$$word'
@64lines
64lines / caesar_encryption.js
Created October 9, 2018 16:28
[JAVASCRIPT] Caesar Encryption
var encrypt = function(plaintext, shiftAmount) {
var ciphertext = "";
for(var i = 0; i < plaintext.length; i++) {
var plainCharacter = plaintext.charCodeAt(i);
if(plainCharacter >= 97 && plainCharacter <= 122) {
ciphertext += String.fromCharCode((plainCharacter - 97 + shiftAmount) % 26 + 97);
} else if(plainCharacter >= 65 && plainCharacter <= 90) {
ciphertext += String.fromCharCode((plainCharacter - 65 + shiftAmount) % 26 + 65);
} else {
ciphertext += String.fromCharCode(plainCharacter);
@64lines
64lines / createDataFrame.py
Last active March 6, 2019 15:06
[PYSPARK] - Create dataframe from scratch
from pyspark.sql import SparkSession
spark = SparkSession.builder.master("local").appName("rel subject").getOrCreate()
columns = ['id', 'referringUrl']
vals = [
(1, 'http://spark.apache.org/docs/2.1.0/api/python/pyspark.sql.html'),
(2, 'https://stackoverflow.com/questions/33224740/best-way-to-get-the-max-value-in-a-spark-dataframe-column'),
(3, 'https://datascience.stackexchange.com/questions/11284/key-parameter-in-max-function-in-pyspark'),
]
@64lines
64lines / example_code.py
Created June 26, 2018 03:44
[PYSPARK] - Example Code
from pyspark.context import SparkContext
spark = SparkSession.builder.master("local").appName("rel subject").getOrCreate()
file_path = 'some_file.csv'
dataframe = spark.read.csv(path=file_path, header=True)
dataframe = dataframe.filter(dataframe['value'] >= 0.5)
@64lines
64lines / philosopher.py
Last active March 2, 2018 04:36
The Philosopher: A program that generates philosophic quotes...
##################################
# The Philosopher: A program that
# generates philosophic quotes...
#################################
import random
R = ["without", "under",
"between", "over", "on",
"after", "by", "because of", "next to", "on top",
"like", "through", "until", "from", "into", "to", "in",
@64lines
64lines / AUC.py
Created November 30, 2017 01:20
[PYTHON][SKLEARN] Area under the ROC curve evaluating model performance.
# Import necessary modules
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import cross_val_score
# Compute predicted probabilities: y_pred_prob
y_pred_prob = logreg.predict_proba(X_test)[:,1]
# Compute and print AUC score
print("AUC: {}".format(roc_auc_score(y_test, y_pred_prob)))
@64lines
64lines / Logistic Regression Plot.py
Created November 30, 2017 00:51
[PYTHON][SKLEARN] Plotting Logistic Regression Raw
# Import necessary modules
from sklearn.metrics import roc_curve
# Compute predicted probabilities: y_pred_prob
y_pred_prob = logreg.predict_proba(X_test)[:,1]
# Generate ROC curve values: fpr, tpr, thresholds
fpr, tpr, thresholds = roc_curve(y_test, y_pred_prob)
# Plot ROC curve