Skip to content

Instantly share code, notes, and snippets.

View kuharan's full-sized avatar
🎯
Focusing

KUHARAN BHOWMIK kuharan

🎯
Focusing
View GitHub Profile
@kuharan
kuharan / gen_pass.py
Created March 4, 2018 18:48
A Simple Password Generator in Python
from random import *
import string
min = 10
max = 20
combination = string.ascii_letters + string.digits + string.punctuation
var_pass = "".join(choice(combination) for x in range(randint(min, max)))
print("Random Password String: ", var_pass)
//double quotes test
val pattern = """(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s*(-)\s*(-)\s*(\[.+?\])\s*"(.+?)\s(.+?)\s(.+?)"\s*(\d{1,3})\s*(\d{1,10})\s*"(.+?)"\s*"(.+?)"\s*"(.+?)"""".r;
val input = """174.371.196.220 - - [07/Sep/2017:00:06:00 +0000] "GET /cs/v1/points/bal?memberId=2164699082&accountType=10 HTTP/1.1" 200 4263 "-" "Mozilla/5.0 (Windows NT 6.0; rv:34.0) Gecko/20100101 Firefox/34.0" "-"""";
val res = input match {
case pattern(ip, username1, logname2, time, requestType, requestURL, requestMethod, status, bytes, referer, userAgent, filename ) => s"IP=$ip\nUsername=$username1\nLogname=$logname2\nTime=$time\nRequestType=$requestType\nRequestURL=$requestURL\nRequestMethod=$requestMethod\nStatus=$status\nBytes=$bytes\nReferer=$referer\nUserAgent=$userAgent\nFilename=$filename"
case _ => "NONE"
}
print(res)
@kuharan
kuharan / One Hot Encoding Example.ipynb
Last active January 14, 2019 06:17
This gist provides sample code to generate random car data and use one hot encoding and re arrange the data frame so that the target remains in the end.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kuharan
kuharan / converter.js
Last active January 18, 2019 06:46
Draw dynamic Canvas with Js
function hexToRgb(hex) {
r = hex.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
if (r) {
return r.slice(1, 4).map(function(x) {
return parseInt(x, 16);
});
}
return null;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kuharan
kuharan / send_email.py
Created February 14, 2021 05:35
Send emails in AWSlambda
from botocore.exceptions import ClientError
from botocore.vendored import requests
def send_email(sender, recipient, aws_region, subject):
# This address must be verified with Amazon SES.
SENDER = sender
# If your account is still in the sandbox, this address must be verified.
RECIPIENT = recipient
# Specify a configuration set. If you do not want to use a configuration
@kuharan
kuharan / send_email_with_attachments.py
Created February 14, 2021 05:37
Send email with attachments in AWS lambda
def send_email(sender, recipient, aws_region, subject, file_name):
# The email body for recipients with non-HTML email clients.
BODY_TEXT = "Hello,\r\nPlease find the attached file."
# The HTML body of the email.
BODY_HTML = """\
<html>
<head></head>
<body>
<h1>Hello!</h1>
<p>Please find the attached file.</p>
@kuharan
kuharan / json2csv.py
Last active February 15, 2021 18:03
JSON to CSV
def json_to_csv(path, fileInput, fileOutput):
inputFile = open(path + fileInput)
data = json.load(inputFile)
inputFile.close()
with open(os.path.join(path,fileOutput), 'w') as fp:
output = csv.writer(fp)
output.writerow(data[0].keys())
for row in data:
output.writerow(row.values())
@kuharan
kuharan / lambda_function.py
Last active February 25, 2021 17:04
AWS Lambda Function to automate DP APIs
import json
import requests
import time
from pytz import timezone
import datetime
status_dict = {'0':'Running','1':'Running with Errors','12':'Running with Failures','15':'Queueing with Failures'}
session_type_dict = {'0':'Backup'}