From 3ba991bedda7ac3d2e090bfa9bd9d254ee285ae6 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Wed, 9 Jun 2021 19:04:58 -0400 Subject: Added markdown to default mime types --- mimetypes.csv | 3 +- templates/site/tutorials/py-style.html | 0 templates/site/tutorials/python/py-style.html | 27 +++++++------ templates/site/tutorials/python/py-style.md | 58 +++++++++++++-------------- 4 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 templates/site/tutorials/py-style.html diff --git a/mimetypes.csv b/mimetypes.csv index aa3b678..7e867ea 100644 --- a/mimetypes.csv +++ b/mimetypes.csv @@ -89,4 +89,5 @@ .pl,text/plain .R,text/plain .yml,text/plain -.yaml,text/plain \ No newline at end of file +.yaml,text/plain +.md,text/markdown diff --git a/templates/site/tutorials/py-style.html b/templates/site/tutorials/py-style.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/site/tutorials/python/py-style.html b/templates/site/tutorials/python/py-style.html index d766e39..62de1ba 100644 --- a/templates/site/tutorials/python/py-style.html +++ b/templates/site/tutorials/python/py-style.html @@ -5,20 +5,24 @@

That aside, I have the following idiosyncracies:

1) Strings are double-quoted. Keys and chars are single-quoted.

This is really just because I like how C does it. And Cpython’s C-based so why not?

-

Like so: string = "This is a phrase" word = "word" cur_char = 'a' newline = '\n' # note, two characters, but it's still ONE char in output # keys are single-quoted to avoid confusion dictionary = { 'key' : "1245dqw3w431", 'return': newline }

-

The only exception is for strings with quotes in them (anything to avoid escapes, really) quoted_string = ( '"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott' ) That brings me to my next point.

+

Like so: code string = "This is a phrase" word = "word" cur_char = 'a' newline = '\n' # note, two characters, but it's still ONE char in output # keys are single-quoted to avoid confusion dictionary = { 'key' : "1245dqw3w431", 'return': newline }

+

The only exception is for strings with quotes in them (anything to avoid escapes, really) code quoted_string = ( '"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott' ) That brings me to my next point.

2) Long strings belong in parentheses

-

As in: ``` longboi = ( “This is a really long string usefull when making help menus. Be” “sure to leave s space at the end of each line, or add a new line” “when needed.”

-
    "Try your best to keep formatting accurate like this."
-)
-```
+

As in:

+
longboi = (
+    "This is a really long string usefull when making help menus. Be\n"
+    "sure to leave s space at the end of each line, or add a new line\n"
+    "when needed.\n"
+
+    "Try your best to keep formatting accurate like this."
+)

3) Tabs are four spaces and spaces are ALWAYS prefered to tabs

Again, see PEP8.

4) Always add spaces between arithmetic, but never for brackets

-

It’s a pain to read: 1/(2*sqrt(pi))*exp(x**2) Do this 1 / (2 * sqrt(pi)) * exp(x ** 2) The same goes for logic operators true & false ^ true

+

It’s a pain to read: code 1/(2*sqrt(pi))*exp(x**2) Do this code 1 / (2 * sqrt(pi)) * exp(x ** 2) The same goes for logic operators code true & false ^ true

5) EVERYTHING should be snake_case

-

This is python. Unless there’s a compatibility thing (like a library’s code was written that way, or it matches an API variable), snake_case is preferred. ```

-
user_input = int(input()) # variable
+

This is python. Unless there’s a compatibility thing (like a library’s code was written that way, or it matches an API variable), snake_case is preferred.

+
user_input = int(input()) # variable
 MAX_INPUT = 1000 # constant
 def judge_input(_input, _max): # function
     if _max > _input:
@@ -26,6 +30,5 @@ def judge_input(_input, _max): # function
 
 judge_input(user_input, MAX_INPUT
 class Input_Judger: # a class
-    # etc etc
-```
-

Example exception # this doesn't actually work, but you get the idea r = requests.get("www.debian.org") pageSize = r.json()['pageSize'] # camel case ok

+ # etc etc
+

Example exception code # this doesn't actually work, but you get the idea r = requests.get("www.debian.org") pageSize = r.json()['pageSize'] # camel case ok

diff --git a/templates/site/tutorials/python/py-style.md b/templates/site/tutorials/python/py-style.md index 2a68fac..bf96f59 100644 --- a/templates/site/tutorials/python/py-style.md +++ b/templates/site/tutorials/python/py-style.md @@ -20,7 +20,7 @@ This is really just because I like how C does it. And Cpython's C-based so why not? Like so: - ``` + ```code string = "This is a phrase" word = "word" cur_char = 'a' @@ -31,7 +31,7 @@ Like so: The only exception is for strings with quotes in them (anything to avoid escapes, really) - ``` + ```code quoted_string = ( '"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott' ) @@ -41,30 +41,30 @@ That brings me to my next point. ## 2) Long strings belong in parentheses As in: - ``` - longboi = ( - "This is a really long string usefull when making help menus. Be\n" - "sure to leave s space at the end of each line, or add a new line\n" - "when needed.\n" +```code +longboi = ( + "This is a really long string usefull when making help menus. Be\n" + "sure to leave s space at the end of each line, or add a new line\n" + "when needed.\n" - "Try your best to keep formatting accurate like this." - ) - ``` + "Try your best to keep formatting accurate like this." +) +``` ## 3) Tabs are four spaces and spaces are *ALWAYS* prefered to tabs Again, see PEP8. ## 4) Always add spaces between arithmetic, but never for brackets It's a pain to read: - ``` + ```code 1/(2*sqrt(pi))*exp(x**2) ``` Do this - ``` + ```code 1 / (2 * sqrt(pi)) * exp(x ** 2) ``` The same goes for logic operators - ``` + ```code true & false ^ true ``` @@ -72,22 +72,20 @@ The same goes for logic operators This is python. Unless there's a compatibility thing (like a library's code was written that way, or it matches an API variable), snake_case is preferred. - ``` - - user_input = int(input()) # variable - MAX_INPUT = 1000 # constant - def judge_input(_input, _max): # function - if _max > _input: - print("Too big!") - - judge_input(user_input, MAX_INPUT - class Input_Judger: # a class - # etc etc - ``` +```code +user_input = int(input()) # variable +MAX_INPUT = 1000 # constant +def judge_input(_input, _max): # function + if _max > _input: + print("Too big!") + +judge_input(user_input, MAX_INPUT +class Input_Judger: # a class + # etc etc +``` Example exception - ``` - # this doesn't actually work, but you get the idea - r = requests.get("www.debian.org") - pageSize = r.json()['pageSize'] # camel case ok - ``` +```code +# this doesn't actually work, but you get the idea +r = requests.get("www.debian.org") +pageSize = r.json()['pageSize'] # camel case ok``` -- cgit v1.2.3