Skip to content

Commit

Permalink
Merge pull request #25 from milkiyd/order-resources-by-name
Browse files Browse the repository at this point in the history
Sort resources by name
  • Loading branch information
geoffreylgv authored Sep 21, 2023
2 parents 64cb94d + 8922410 commit 31cc153
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 55 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,27 @@ Soon I'll be merging all your changes into the main branch of this project. You
Congrats! You just completed the standard _fork -> clone -> edit -> pull request_ workflow that you'll often encounter as a contributor!

Celebrate your contribution and share it with your friends and followers on Twitter and tag the team.

### Adding resources
- If you added a new resource to an existing `resources.md` or `learning-material.md` file, just run `sort-resources.py` directly.

- If you added a new `resources.md` or `learning-material.md` file, add the path to the file to the RESOURCE_FILE_PATHS list below and then run `sort-resources.py`.

To run this script, open a terminal or command prompt and navigate to the directory that contains this script.

If you're using a Mac or a Linux distribution, you can run this script from the terminal by typing the following command: `python3 sort_resource_links.py`

If you're using Windows, you can run this script from the command prompt by typing the following command:
`python sort_resource_links.py`

Note 1: The links must be in the following format: `- [Link text](link URL)`. If you use a different format, the script will not work.

Note 2: The heading for the sections must use a h4 heading (`####`). If you use a different heading, the script will not work.

Note 3: You must have Python 3 installed on your computer to run this script. If you don't have
Python 3 installed, you can download it from https://www.python.org/downloads/. Make sure you
download the version for your operating system (Windows, Mac, or Linux).

Note 4: This script assumes that it is at the root of the repository. If you move this script to
a different location, you will need to update the RESOURCE_FILE_PATHS list below to include the
correct paths to the resources.md and learning-material.md files.
48 changes: 24 additions & 24 deletions dsa/resources/resources.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#### Courses articles blogs

- [Data Structure Visualizations - University of San Francisco](https://www.cs.usfca.edu/~galles/visualization/Algorithms.html)
- [Data Structure - Geeks for Geeks](https://www.geeksforgeeks.org/data-structures/)
- [Collection of Data Structure and Algorithms learning material - Google](https://techdevguide.withgoogle.com/paths/data-structures-and-algorithms/)
- [Data Structure and Algorithms - CS50 Havard University](https://cs50.harvard.edu/law/2019/weeks/3/)
- [Data Structure and Algorithms - Freecodecamp](https://www.freecodecamp.org/news/learn-data-structures-and-algorithms/)
- [Data Structure and Algorithms - Tutorialspoint](https://www.tutorialspoint.com/data_structures_algorithms/index.htm)

#### Videos tutorials

- [Algorithms and Data Structures Tutorial - Full Course for Beginners - Freecodecamp](https://www.youtube.com/watch?v=8hly31xKli0) _5hours_
- [Complete Data Structures and Algorithms - Language: C - **Jenny's Lectures CS IT**](https://www.youtube.com/watch?v=AT14lCXuMKI&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU)
- [Programming & Data Structures - Language C - **Neso Academy**](https://www.youtube.com/watch?v=xLetJpcjHS0&list=PLBlnK6fEyqRj9lld8sWIUNwlKfdUoPd1Y)
- [Data Structures - Full Course Using C and C++](https://www.youtube.com/watch?v=B31LgI4Y4DQ&t=8488s) _9hours+_

#### Where to have the assessment ?

- [LeetCode](https://leetcode.com/)
- [CoderByte](https://coderbyte.com/)
- [HankerRank](https://www.hackerrank.com/dashboard)
- [Project Euler](https://projecteuler.net/)
- [Coding game](https://www.codingame.com/)
- [CodeWars](https://www.codewars.com/)
#### Courses articles blogs

- [Collection of Data Structure and Algorithms learning material - Google](https://techdevguide.withgoogle.com/paths/data-structures-and-algorithms/)
- [Data Structure - Geeks for Geeks](https://www.geeksforgeeks.org/data-structures/)
- [Data Structure and Algorithms - CS50 Havard University](https://cs50.harvard.edu/law/2019/weeks/3/)
- [Data Structure and Algorithms - Freecodecamp](https://www.freecodecamp.org/news/learn-data-structures-and-algorithms/)
- [Data Structure and Algorithms - Tutorialspoint](https://www.tutorialspoint.com/data_structures_algorithms/index.htm)
- [Data Structure Visualizations - University of San Francisco](https://www.cs.usfca.edu/~galles/visualization/Algorithms.html)

#### Videos tutorials

- [Algorithms and Data Structures Tutorial - Full Course for Beginners - Freecodecamp](https://www.youtube.com/watch?v=8hly31xKli0)
- [Complete Data Structures and Algorithms - Language: C - **Jenny's Lectures CS IT**](https://www.youtube.com/watch?v=AT14lCXuMKI&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU)
- [Data Structures - Full Course Using C and C++](https://www.youtube.com/watch?v=B31LgI4Y4DQ&t=8488s)
- [Programming & Data Structures - Language C - **Neso Academy**](https://www.youtube.com/watch?v=xLetJpcjHS0&list=PLBlnK6fEyqRj9lld8sWIUNwlKfdUoPd1Y)

#### Where to have the assessment ?

- [CoderByte](https://coderbyte.com/)
- [CodeWars](https://www.codewars.com/)
- [Coding game](https://www.codingame.com/)
- [HankerRank](https://www.hackerrank.com/dashboard)
- [LeetCode](https://leetcode.com/)
- [Project Euler](https://projecteuler.net/)
10 changes: 5 additions & 5 deletions printf/resources.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- [Secret of printf](https://www.academia.edu/10297206/Secrets_of_printf_)
- [C programming: Example of C custom printf() function](https://www.w3resource.com/c-programming-exercises/c-snippets/implementing-custom-printf-function-in-c.php#:~:text=Implementin[…]%20is%20encountered)
- [Creating a Custom printf Function in C: A Step-by-Step Guide by Noran Saber](https://medium.com/@noransaber685/creating-a-custom-printf-function-in-c-a-step-by-step-guide-432fd2ecf48a)
- [ALX Printf Project: The Power of printf in C Programming by Amara Crystal](https://medium.com/@marameref/alx-printf-project-the-power-of-printf-in-c-programming-a-comprehensive-guide-5087f4677234)
- [Easy to read documentation of the printf function](https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm)
- [ALX Printf Project: The Power of printf in C Programming by Amara Crystal](https://medium.com/@marameref/alx-printf-project-the-power-of-printf-in-c-programming-a-comprehensive-guide-5087f4677234)
- [C programming: Example of C custom printf() function](https://www.w3resource.com/c-programming-exercises/c-snippets/implementing-custom-printf-function-in-c.php#:~:text=Implementin[…]%20is%20encountered)
- [Creating a Custom printf Function in C: A Step-by-Step Guide by Noran Saber](https://medium.com/@noransaber685/creating-a-custom-printf-function-in-c-a-step-by-step-guide-432fd2ecf48a)
- [Easy to read documentation of the printf function](https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm)
- [Secret of printf](https://www.academia.edu/10297206/Secrets_of_printf_)
52 changes: 26 additions & 26 deletions simple-shell/learning-material.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
- [Learning the shell](https://linuxcommand.org/lc3_learning_the_shell.php)
- [Implement your own shell step by step by ehoneahobed](https://blog.ehoneahobed.com/building-a-simple-shell-in-c-part-1)
- [Standford University : Shell project](https://www.scs.stanford.edu/21sp-cs111/proj/proj_shell.html)
- [Shell explaned by nickolasteixeira](https://nickolasteixeira.medium.com/want-to-build-a-simple-shell-heres-how-you-do-it-75890647bae8)
- [What happen after pressing enter on ls command by nickolasteixeira](https://nickolasteixeira.medium.com/what-happens-when-you-type-ls-c-and-hit-enter-in-your-shell-a9c789206c55)
- [What's shell part 1 by indradhanush](https://indradhanush.github.io/blog/writing-a-unix-shell-part-1/)
- [What's shell part 2 by indradhanush](https://indradhanush.github.io/blog/writing-a-unix-shell-part-2/)
- [Code your shell in C by santiagobedoa](https://medium.com/@santiagobedoa/coding-a-shell-using-c-1ea939f10e7e)
- [Shell by Linuxhint.com](https://linuxhint.com/create-simple-shell-c/#:~:text=Building%20a%20simple%20shell%20in,and%20the%20Unix%20operating%20system.)
- [Brennan's method to write a shell in C](https://brennan.io/2015/01/16/write-a-shell-in-c/)
- [Shell project step by step by muirujackson](https://medium.com/@muirujackson/shell-project-step-by-step-80aa31a71df0)
- [Understanding important system calls in C by @noransaber](https://medium.com/@noransaber685/understanding-important-system-calls-in-c-fork-open-read-close-chdir-getline-and-access-2836cc761b17)
- [shell, the standard command language interpreter](https://manpages.org/sh)
- [sh, jsh - the standard command interpreter](https://heirloom.sourceforge.net/sh/sh.1.html)
- [Developing a Linux based shell](https://www.geeksforgeeks.org/developing-linux-based-shell/?ref=rp)
- [Let's Build a Linux Shell [Part I]](https://hackernoon.com/lets-build-a-linux-shell-part-i-bz3n3vg1)
- [Shell Program Explained](https://www.youtube.com/watch?v=ubt-UjcQUYg)
- [Unix Processes in C](https://www.youtube.com/watch?v=cex9XrZCU14&list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [System Call Guide](https://youtu.be/2DscbZAdiko?si=cSjEeO3G1skgVdOl)
- [Essential System Calls and Functions](https://medium.com/@noransaber685/essential-system-calls-and-functions-in-c-programming-explained-strtok-isatty-getpid-malloc-and-30f1f923a10d)
- [Detecting Memory Leaks](https://medium.com/@muirujackson/step-by-step-guide-to-detect-specific-memory-leaks-issues-with-valgrind-memcheck-b9aa45b967c5)
- [PLD Session on Simple Shell By Emmanuel Lomotey](https://mega.nz/file/hxB0GSAS#0NU_eKTfWZ-YQGHxIor-CFscP3E6pXeFdzvJKLwlNns)
- [PLD SESSION SHELL PT. 2 By Emmanuel Lomotey](https://mega.nz/file/sp4RXIwI#33FtT6bQpYKpGfkgBMWCGKZ1-nNzIdklNIPbwiH2mm8)
- [Unix Processes in C by CodeVault](https://www.youtube.com/playlist?list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [Unix Processes in C by CodeVault](https://www.youtube.com/playlist?list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [Write Your Own Shell by Jess-Inspired](https://www.youtube.com/playlist?list=PLxIRFba3rzLzxxZMMbrm_-mkI7mV9G0pj)
- [Brennan's method to write a shell in C](https://brennan.io/2015/01/16/write-a-shell-in-c/)
- [Code your shell in C by santiagobedoa](https://medium.com/@santiagobedoa/coding-a-shell-using-c-1ea939f10e7e)
- [Detecting Memory Leaks](https://medium.com/@muirujackson/step-by-step-guide-to-detect-specific-memory-leaks-issues-with-valgrind-memcheck-b9aa45b967c5)
- [Developing a Linux based shell](https://www.geeksforgeeks.org/developing-linux-based-shell/?ref=rp)
- [Essential System Calls and Functions](https://medium.com/@noransaber685/essential-system-calls-and-functions-in-c-programming-explained-strtok-isatty-getpid-malloc-and-30f1f923a10d)
- [Implement your own shell step by step by ehoneahobed](https://blog.ehoneahobed.com/building-a-simple-shell-in-c-part-1)
- [Learning the shell](https://linuxcommand.org/lc3_learning_the_shell.php)
- [Let's Build a Linux Shell [Part I]](https://hackernoon.com/lets-build-a-linux-shell-part-i-bz3n3vg1)
- [PLD Session on Simple Shell By Emmanuel Lomotey](https://mega.nz/file/hxB0GSAS#0NU_eKTfWZ-YQGHxIor-CFscP3E6pXeFdzvJKLwlNns)
- [PLD SESSION SHELL PT. 2 By Emmanuel Lomotey](https://mega.nz/file/sp4RXIwI#33FtT6bQpYKpGfkgBMWCGKZ1-nNzIdklNIPbwiH2mm8)
- [sh, jsh - the standard command interpreter](https://heirloom.sourceforge.net/sh/sh.1.html)
- [Shell by Linuxhint.com](https://linuxhint.com/create-simple-shell-c/#:~:text=Building%20a%20simple%20shell%20in,and%20the%20Unix%20operating%20system.)
- [Shell explaned by nickolasteixeira](https://nickolasteixeira.medium.com/want-to-build-a-simple-shell-heres-how-you-do-it-75890647bae8)
- [Shell Program Explained](https://www.youtube.com/watch?v=ubt-UjcQUYg)
- [Shell project step by step by muirujackson](https://medium.com/@muirujackson/shell-project-step-by-step-80aa31a71df0)
- [shell, the standard command language interpreter](https://manpages.org/sh)
- [Standford University : Shell project](https://www.scs.stanford.edu/21sp-cs111/proj/proj_shell.html)
- [System Call Guide](https://youtu.be/2DscbZAdiko?si=cSjEeO3G1skgVdOl)
- [Understanding important system calls in C by @noransaber](https://medium.com/@noransaber685/understanding-important-system-calls-in-c-fork-open-read-close-chdir-getline-and-access-2836cc761b17)
- [Unix Processes in C](https://www.youtube.com/watch?v=cex9XrZCU14&list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [Unix Processes in C by CodeVault](https://www.youtube.com/playlist?list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [Unix Processes in C by CodeVault](https://www.youtube.com/playlist?list=PLfqABt5AS4FkW5mOn2Tn9ZZLLDwA3kZUY)
- [What happen after pressing enter on ls command by nickolasteixeira](https://nickolasteixeira.medium.com/what-happens-when-you-type-ls-c-and-hit-enter-in-your-shell-a9c789206c55)
- [What's shell part 1 by indradhanush](https://indradhanush.github.io/blog/writing-a-unix-shell-part-1/)
- [What's shell part 2 by indradhanush](https://indradhanush.github.io/blog/writing-a-unix-shell-part-2/)
- [Write Your Own Shell by Jess-Inspired](https://www.youtube.com/playlist?list=PLxIRFba3rzLzxxZMMbrm_-mkI7mV9G0pj)
139 changes: 139 additions & 0 deletions sort-resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import re


class MarkdownLink:
"""Represents a Markdown link with text and a URL.
Attributes:
title (str): The title of the section in which the link appears.
text (str): The text associated with the link.
link (str): The URL to which the link points.
"""

def __init__(self, title, text, link):
"""Initializes a MarkdownLink instance with the provided text and link.
Args:
title (str): The title of the section in which the link appears.
text (str): The text associated with the link.
link (str): The URL to which the link points.
"""

self.title = title
self.text = text
self.link = link

def __str__(self):
"""Returns a user-friendly string representation of the MarkdownLink instance.
Returns:
str: A formatted string in the Markdown link format, e.g., "[text](link)".
"""

return f"{self.title} / [{self.text}]({self.link})"

def __repr__(self):
"""
Returns a formal string representation of the MarkdownLink instance.
Returns:
str: A formatted string that represents the MarkdownLink instance.
"""

return f"- [{self.text}]({self.link})"

def __lt__(self, other):
"""
Compares two MarkdownLink instances based on their title and text attributes for sorting.
Args:
other (MarkdownLink): Another MarkdownLink instance to compare with.
Returns:
bool: True if this instance's text is less than the other instance's text; False otherwise.
"""

return (self.title == other.title and self.text.lower() < other.text.lower())

def extract_links_from_md_file(file_content):
"""
Extracts Markdown links from the provided file content.
Args:
file_content (str): The content of a Markdown file as a string.
Returns:
list of MarkdownLink: A list of MarkdownLink objects representing the links found in the content.
"""

links = []
current_title = None

for line in file_content.splitlines():
title_match = re.match(r"####\s+(.*)", line) # Match titles (assumes #### title format)
if title_match:
current_title = title_match.group(1)
else:
link_match = re.search(r"- \[(.*)\]\((.*)\)", line) # Match lines like "- [text](link)"
if link_match:
text = link_match.group(1)
link = link_match.group(2)
links.append(MarkdownLink(current_title, text, link))

return links

def sort_links_in_md_file(markdown_file_path):
"""
Sorts Markdown links in a Markdown file alphabetically by their link text.
Args:
markdown_file_path (str): The path to the Markdown file to be sorted.
Prints:
str: A success message indicating that the links in the file have been sorted.
"""

try:
with open(markdown_file_path, "r") as f:
file_content = f.read()

# Extract the links from the file content and sort them
links = extract_links_from_md_file(file_content)
links.sort()

# Create the new file content
new_file_content = ""
current_title = None
for link in links:
if link.title != current_title:
if current_title is not None:
new_file_content += "\n"
current_title = link.title
new_file_content += f"#### {current_title}\n\n"
new_file_content += f"{repr(link)}\n"

# Write the new file content to the file
with open(markdown_file_path, "w") as f:
f.write(new_file_content)

print(f"Links in {markdown_file_path} sorted successfully")

# Handle errors
except FileNotFoundError:
print(f"File {markdown_file_path} not found")

except PermissionError:
print(f"Permission denied to open {markdown_file_path}")

except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":
RESOURCE_FILE_PATHS = [
"printf/resources.md",
"simple-shell/learning-material.md",
"dsa/resources/resources.md",
]

for resource_file_path in RESOURCE_FILE_PATHS:
sort_links_in_md_file(resource_file_path)

0 comments on commit 31cc153

Please sign in to comment.