From 8bd574b39c087b5e565bb4a8b91056548dc85f89 Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Thu, 24 Jan 2019 18:20:10 -0700 Subject: [PATCH] More documentation. A blog article! --- Blog/Mysql-reset-password.md | 74 +++++++++++++++++++ Codecademy.md | 61 ++++++++++++++- .../{ex7_ch5?.py => ex7_ch3,L1?.py} | 0 Codecadmey Projects/gradebook-ch4.py | 9 +++ .../{lens-pizza.py => lens-pizza-ch4.py} | 0 ex11.py | 11 +++ infinite.py | 4 + 7 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 Blog/Mysql-reset-password.md rename Codecadmey Projects/{ex7_ch5?.py => ex7_ch3,L1?.py} (100%) create mode 100644 Codecadmey Projects/gradebook-ch4.py rename Codecadmey Projects/{lens-pizza.py => lens-pizza-ch4.py} (100%) create mode 100644 ex11.py create mode 100644 infinite.py diff --git a/Blog/Mysql-reset-password.md b/Blog/Mysql-reset-password.md new file mode 100644 index 0000000..28716c9 --- /dev/null +++ b/Blog/Mysql-reset-password.md @@ -0,0 +1,74 @@ +# Set/Reset MySQL Root Password on MySQL 14.14 + +I was trying to setup MySQL that I installed using `sudo apt install MySql` and couldn't remember how to set the root password. I found many different instructions on how to stop MySQL, boot into safe mode and reset the root password. + +*None of them worked.* + +This did: + +Run: `sudo mysql_secure_installation` + +You will see something like this: + +``` +Securing the MySQL server deployment. + +Enter password for user root: +``` + +You can setup a password strength validation plugin if you wish in the next step: + +``` +VALIDATE PASSWORD PLUGIN can be used to test passwords +and improve security. It checks the strength of password +and allows the users to set only those passwords which are +secure enough. Would you like to setup VALIDATE PASSWORD plugin? + +Press y|Y for Yes, any other key for No: +``` + +Next, it will give you an option to disable anonymous users. Do it. It is a security liability if you don't. + +``` +By default, a MySQL installation has an anonymous user, +allowing anyone to log into MySQL without having to have +a user account created for them. This is intended only for +testing, and to make the installation go a bit smoother. +You should remove them before moving into a production +environment. + +Remove anonymous users? (Press y|Y for Yes, any other key for No) : +``` + +Remote root login to MySQL is generally not a good thing. I recommend disabling it: + +``` +Normally, root should only be allowed to connect from +'localhost'. This ensures that someone cannot guess at +the root password from the network. + +Disallow root login remotely? (Press y|Y for Yes, any other key for No) : +``` + +Delete the test database to reduce the attack surface for hackers: + +``` +By default, MySQL comes with a database named 'test' that +anyone can access. This is also intended only for testing, +and should be removed before moving into a production +environment. + + +Remove test database and access to it? (Press y|Y for Yes, any other key for No) : +``` + +Reload privilege tables now, unless you need MySQL working for this precise instant. It only takes a second. + +``` +Reloading the privilege tables will ensure that all changes +made so far will take effect immediately. + +Reload privilege tables now? (Press y|Y for Yes, any other key for No) : +``` + +And you're done! diff --git a/Codecademy.md b/Codecademy.md index e521594..a7d9e34 100644 --- a/Codecademy.md +++ b/Codecademy.md @@ -286,7 +286,7 @@ You can add lists like this: `['list1', 'stuff'] + ['list2', 'stuff']` but need You can get a range of numbers using `range()` -It will give you all numbers under the number you input. For example, `range(8)` would give you 0-7, `range(1, 8)` would give you 1-7, and `range(1, 8, 2)` would give you 1,3,5,7 (2 is the interval) Use `print(list(var))` when printing. +It will give you all numbers under the number you input. For example, `range(8)` would give you 0-7, `range(1, 8)` would give you 1-7, and `range(1, 8, 2)` would give you 1,3,5,7 (2 is the interval and needs no padding) Use `print(list(var))` when printing. ## length @@ -417,6 +417,65 @@ to produce a new list with sorted contents without changing the original variabl print("Nice little message to user.") ``` +# Loops +The following assigns an arbitrary name to a temporary variable (tempvar) to the number of elements in `sport_games` For every element in `sport_games`, it will print `print(tempvar)` + +``` +for tempvar in sport_games: + print(tempvar) +``` + +You can use `range()` to get lists of arbitrary lengths. + +You can also add lists like this: + +``` +students_period_A = ["Alex", "Briana", "Cheri", "Daniele"] +students_period_B = ["Dora", "Minerva", "Alexa", "Obie"] + +for student in students_period_A: + students_period_B.append(student) +``` + +## Iterating until we find something + +``` +for thing in stuff: + if thing == thing_I_want: + print("Found it!") + break # Stops the loop, executes code outside. +``` + +## Skip a value in a list. + + Ex.5 + + ``` + for age in ages: + if age < 21: + continue + else: + print(age) + ``` + +## Move from list to list +Ex.7 +``` +while len(students_in_poetry) < 6: + student = all_students.pop(-1) # Remove last element + students_in_poetry.append(student) # Add it to students_in_poetry + +print(students_in_poetry) +``` + +# Nested Loops + +``` +for location in sales_data: + print(location) + for sub in location: + scoops_sold += sub +``` # Fun Projects diff --git a/Codecadmey Projects/ex7_ch5?.py b/Codecadmey Projects/ex7_ch3,L1?.py similarity index 100% rename from Codecadmey Projects/ex7_ch5?.py rename to Codecadmey Projects/ex7_ch3,L1?.py diff --git a/Codecadmey Projects/gradebook-ch4.py b/Codecadmey Projects/gradebook-ch4.py new file mode 100644 index 0000000..8565094 --- /dev/null +++ b/Codecadmey Projects/gradebook-ch4.py @@ -0,0 +1,9 @@ +last_semester_gradebook = [("politics", 80), ("latin", 96), ("dance", 97), ("architecture", 65)] +subjects = ['physics', 'calculus', 'poetry', 'history'] +grades = ['98', '97', '85', '88'] +subjects.append('computer science') +grades.append('100') +gradebook = list(zip(subjects, grades)) +gradebook.append(['visual arts', 93]) +full_gradebook = gradebook + last_semester_gradebook +print(full_gradebook) diff --git a/Codecadmey Projects/lens-pizza.py b/Codecadmey Projects/lens-pizza-ch4.py similarity index 100% rename from Codecadmey Projects/lens-pizza.py rename to Codecadmey Projects/lens-pizza-ch4.py diff --git a/ex11.py b/ex11.py new file mode 100644 index 0000000..2b23c20 --- /dev/null +++ b/ex11.py @@ -0,0 +1,11 @@ +#Write your function here + +def every_three_nums(start): + if start > 100: + return [] + + everythree = range(start, 101, 3) + return list(everythree) + +#Uncomment the line below when your function is done +print(every_three_nums(91)) diff --git a/infinite.py b/infinite.py new file mode 100644 index 0000000..c008127 --- /dev/null +++ b/infinite.py @@ -0,0 +1,4 @@ +a = 1 + +while a == a: + print("hi")