Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zhengran Jiang's changes #110

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions challenges/database_challenges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Headstorm database challenges Zhengran Jiang
Here are my codes for the database challenge. I use MySQL as the relational database language and python to display these commands.
There are test data generated by python and they are in the form of a list of dictionaries. The generate_test_data function generate a test file of size size.
I did not print the create database and tables statement in console since it did not specifically say so. However, these create statements are in the database.py file starting at line 49. To print them, uncomment line 80.

The data visualization is in the form of an ER diagram in relational data model visualization.png
109 changes: 109 additions & 0 deletions challenges/database_challenges/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import json
import random
import string

def generate_phone_number():
phone = ''.join(str(random.randint(0, 9)) for i in range(3))
phone += "."+ ''.join(str(random.randint(0, 9)) for i in range(3))
phone += "."+ ''.join(str(random.randint(0, 9)) for i in range(4))
return phone


def generate_test_data(size):
nosql_data =[]
letters = string.ascii_lowercase


for i in range(1,size+1):
name = ''.join(random.choice(letters) for i in range(5)) + " " +''.join(random.choice(letters) for i in range(5))
cellphone = generate_phone_number()
workphone = generate_phone_number()
email = name.replace(" ","")+ "@gmail.com"
address = ''.join(str(random.randint(0, 9)) for i in range(3)) + " Test Way, Dallas TX 75205"
basic_widget_order = random.randint(1, 100)
advanced_widget_order = random.randint(1, 100)
if random.randint(0,1)==0:
protection=False
else:
protection=True
pydict = {
"Record ID": i,
"Name": name,
"Cell Phone":cellphone,
"Work Phone": workphone,
"Email": email,
"Address":address,
"Basic Widget Order": basic_widget_order,
"Advanced Widget Order": advanced_widget_order,
"Protection": protection
}
nosql_data.append(pydict)
with open ("test.json","w") as outfile:
json.dump(nosql_data, outfile,indent=4)

if __name__ =="__main__":
# generate_test_data(10)
with open ("test.json") as test:
test_data = json.load(test)
# print(json.dumps(test_data,indent=4))
create_stmt = """
create database if not exists headstorm_backend;
use headstorm_backend;
create table if not exists application_user (
record_id Int auto_increment primary key,
username varchar(255) not null,
email varchar(255),
address varchar(255)
);
create table if not exists application_phone_number(
phone_id Int auto_increment primary key,
record_id Int,
isWork tinyint(1) not null default 0,
contact varchar(15) not null,
foreign key (record_id) references application_user(record_id)
on update restrict
on delete cascade
);

create table if not exists application_order(
order_id int auto_increment primary key,
record_id int,
basic_widget_order int not null,
advanced_widget_order int not null,
protection tinyint(1) not null default 0,
foreign key (record_id) references application_user(record_id)
on update restrict
on delete cascade
);
show tables;
"""
# print(create_stmt)

for element in test_data:
insert_stmt_user = """
insert into application_user(
record_id, username, email, address
)
Values({0},\"{1}\",\"{2}\", \"{3}\");
"""
print(insert_stmt_user.format(element["Record ID"], element["Name"], element["Email"],element["Address"]))
insert_stmt_phone_number ="""
insert into application_phone_number(
record_id, isWork,contact
)
Values({0},{1},\"{2}\");
"""
if element["Cell Phone"]!="":
print(insert_stmt_phone_number.format(element["Record ID"], 0, element["Cell Phone"]))
if element["Work Phone"]!="":
print(insert_stmt_phone_number.format(element["Record ID"], 1, element["Work Phone"]))
insert_stmt_order ="""
insert into application_order (
record_id, basic_widget_order, advanced_widget_order,protection)
Values({0},{1},{2},{3});
"""
if element["Protection"]:
protected =1
else:
protected =0
print(insert_stmt_order.format(element["Record ID"], element["Basic Widget Order"], element["Advanced Widget Order"],protected))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions challenges/database_challenges/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"Record ID": 1,
"Name": "nsphw kwgck",
"Cell Phone": "893.236.4843",
"Work Phone": "604.794.5320",
"Email": "[email protected]",
"Address": "564 Test Way, Dallas TX 75205",
"Basic Widget Order": 11,
"Advanced Widget Order": 83,
"Protection": true
},
{
"Record ID": 2,
"Name": "gixwk muaoc",
"Cell Phone": "199.564.9387",
"Work Phone": "360.421.3433",
"Email": "[email protected]",
"Address": "516 Test Way, Dallas TX 75205",
"Basic Widget Order": 3,
"Advanced Widget Order": 38,
"Protection": true
},
{
"Record ID": 3,
"Name": "suzmv netbp",
"Cell Phone": "980.497.8755",
"Work Phone": "245.891.6646",
"Email": "[email protected]",
"Address": "394 Test Way, Dallas TX 75205",
"Basic Widget Order": 48,
"Advanced Widget Order": 12,
"Protection": false
},
{
"Record ID": 4,
"Name": "utenq sobmx",
"Cell Phone": "388.717.0782",
"Work Phone": "726.228.4275",
"Email": "[email protected]",
"Address": "631 Test Way, Dallas TX 75205",
"Basic Widget Order": 53,
"Advanced Widget Order": 56,
"Protection": false
},
{
"Record ID": 5,
"Name": "kcddl qachd",
"Cell Phone": "362.386.2664",
"Work Phone": "682.940.5507",
"Email": "[email protected]",
"Address": "046 Test Way, Dallas TX 75205",
"Basic Widget Order": 28,
"Advanced Widget Order": 58,
"Protection": false
},
{
"Record ID": 6,
"Name": "encoi nukxg",
"Cell Phone": "769.157.2534",
"Work Phone": "143.782.2238",
"Email": "[email protected]",
"Address": "440 Test Way, Dallas TX 75205",
"Basic Widget Order": 94,
"Advanced Widget Order": 44,
"Protection": true
},
{
"Record ID": 7,
"Name": "fiohg ugulh",
"Cell Phone": "566.452.2541",
"Work Phone": "799.030.0851",
"Email": "[email protected]",
"Address": "566 Test Way, Dallas TX 75205",
"Basic Widget Order": 50,
"Advanced Widget Order": 79,
"Protection": false
},
{
"Record ID": 8,
"Name": "wbybs ytaoq",
"Cell Phone": "567.719.7844",
"Work Phone": "754.769.2508",
"Email": "[email protected]",
"Address": "086 Test Way, Dallas TX 75205",
"Basic Widget Order": 51,
"Advanced Widget Order": 41,
"Protection": false
},
{
"Record ID": 9,
"Name": "huzwc krusv",
"Cell Phone": "967.533.6333",
"Work Phone": "510.833.4167",
"Email": "[email protected]",
"Address": "721 Test Way, Dallas TX 75205",
"Basic Widget Order": 25,
"Advanced Widget Order": 93,
"Protection": false
},
{
"Record ID": 10,
"Name": "ysrkm btdex",
"Cell Phone": "244.662.6300",
"Work Phone": "005.947.4162",
"Email": "[email protected]",
"Address": "351 Test Way, Dallas TX 75205",
"Basic Widget Order": 42,
"Advanced Widget Order": 47,
"Protection": true
}
]
5 changes: 5 additions & 0 deletions challenges/frontend_challenges/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Headstorm frontend challenges (Zhengran Jiang)
Here are my codes for the frontend challenges. Since it states to build a webiste quickly, I did not use any external JavaScript libraries like jQueries or React and keep my code minimal.

Also, the frontend challenge states to use Google recaptcha v3 but the link directs to v2, so I assume that recaptcha v2 is the one that I should be using.

1 change: 1 addition & 0 deletions challenges/frontend_challenges/images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Here is the favicon image.
Binary file added challenges/frontend_challenges/images/favicon.ico
Binary file not shown.
73 changes: 73 additions & 0 deletions challenges/frontend_challenges/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<link rel = "stylesheet" href ="style.css"/>
</head>
<body>
<h1 class="companyName" >Headstorm </h1>
<form id="myform">
<label for="fname" class="label" style="top: 20%;left: 49%;">Full Name:</label><br>
<input type="text" id="fname" name="fname" class = "input" style="top: 25%;"><br>

<label for="email" class="label" style="top:30%;left: 50%; ">Email:</label><br>
<input type="email" id="email" name="email" class = "input" style="top:35%;"><br>

<label for="phone" class="label" style="top: 40%;left: 48%;">Phone Number:</label><br>
<input type="tel" id="phone" name="phone" name="email" class = "input" style="top:45%;"><br>

<label for="message" class="label" style="top: 50%;left: 49.5%;">Message:</label><br>
<textarea for="message" name="message" id="message" rows ="4" cols="50" class = "inputTextarea" ></textarea>

<div class="g-recaptcha gverify" data-sitekey="6LcVJLQeAAAAAHIGNTmpAEOue_X-zEt1JlxSChR7"></div>
<input type="submit" name="submit" value="Submit" id="submit" class="submitButton" />

</form>
<script>
var form = document.getElementById("myform");
function handleForm(event){
event.preventDefault();
var response = grecaptcha.getResponse();
if(response.length ==0){
alert("Please verify the recaptcha box");
return;
}
let fname = document.getElementById("fname").value;
let email = document.getElementById("email").value;
let phone = document.getElementById("phone").value;
let message = document.getElementById("message").value;
if(fname.trim().length ==0){
console.log("first name is empty");
}
else{
console.log(fname);
}
if(email.trim().length==0){
console.log("email is empty");
}
else{
console.log(email);
}
if(phone.trim().length==0){
console.log("phone number is empty");
}
else{
console.log(phone);
}
if(message.trim().length==0){
console.log("message is empty ");
}
else{
console.log(message);
}
grecaptcha.reset();
}
form.addEventListener('submit', handleForm);
</script>
</body>
</html>
43 changes: 43 additions & 0 deletions challenges/frontend_challenges/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.companyName{
position: fixed;
text-align: center;
left: 45%;
top:5%;
margin-left: auto;
margin-right: auto;
}
.label{
position: fixed;
text-align: center;
margin-left: auto;
margin-right: auto ;
}

.input{
position: fixed;
text-align: center;
left: 45%;
margin-left: auto;
margin-right: auto ;
}

.inputTextarea{
top:55%;
position: fixed;
width: 30%;
left: 38%;
margin-left: auto;
margin-right: auto ;
}

.submitButton{
top:90%;
position: fixed;
left: 50%;
}

.gverify{
top: 70%;
position: fixed;
left: 40%;
}