Skip to content

Commit

Permalink
Add tutorials and fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
simosathan9 committed Aug 1, 2024
1 parent 378ad0f commit a5c28e6
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/blocks/sedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var sedBlock = {
category: 'Text processing',
unix_description: [
{
regPattern: "'s/patt/",
regPattern: "'s/patt ",
singleStr: "'s/str/",
regReplaceText: "str/'",
regex: '-E',
Expand Down
Binary file added public/img/combine_files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/convert_domains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/extract_columns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/filter_rows_and_count_lines.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/remove_duplicate_lines_and_sort.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/js/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ Blockly.Msg['WC_TOOLTIP'] = 'word, line, character, and byte count in a file';
Blockly.Msg['WC_HELPURL'] = 'https://www.google.com/';

Blockly.Msg['XARGS'] = 'Execute following command\n for each item';
Blockly.Msg['XARGS_PLACEHOLDER'] = 'use a palceholder %1';
Blockly.Msg['XARGS_PLACEHOLDER'] = 'use a placeholder %1';
Blockly.Msg['XARGS_TOOLTIP'] =
'Execute the following command for each item of a list or a file';
Blockly.Msg['XARGS_HELPURL'] = 'https://www.google.com/';
Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ app.get('/', (req, res) => {
res.render('homePage', { errorMessages: req.flash('error') || [] });
});

app.get('/tutorials', (req, res) => {
res.render('tutorials', { errorMessages: req.flash('error') || [] });
});

app.get('/blockly_unix', addAuthToken, (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'), {
headers: { 'X-Auth-Token': req.authToken || '' }
Expand Down
2 changes: 1 addition & 1 deletion views/homePage.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<a class="nav-link active" aria-current="page" href="/blockly_unix">Blockly</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Tutorials</a>
<a class="nav-link active" aria-current="page" href="/tutorials">Tutorials</a>
</li>
</ul>
<div class="d-flex align-items-center">
Expand Down
189 changes: 189 additions & 0 deletions views/tutorials.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blockly Unix</title>
<!-- Link to Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Link to custom CSS -->
<link rel="stylesheet" href="homePage.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">

<script>
document.addEventListener('DOMContentLoaded', () => {
fetch('/auth-token')
.then((response) => response.json())
.then((data) => {
const token = data.authToken;
const user = data.user;
if (!token) {
// User is authenticated
document.getElementById('loginHomePageButton').style.display = 'block';
document.getElementById('registerHomePageButton').style.display = 'block';
document.getElementById('registerSecondButtonHomePage').style.display = 'inline-block';
document.getElementById('getStartedButton').style.display = 'inline-block';
console.log('Token:', token);
} else {
document.getElementById('continueWithBlocklyButton').style.display = 'block';
document.getElementById('logoutHomePageButton').style.display = 'block';
document
.getElementById('logoutHomePageButton')
.addEventListener('click', () => {
event.preventDefault();
document.getElementById('logoutForm').submit();
});
}
})
.catch((error) => {
console.error('Error fetching the token:', error);
});
});
</script>
</head>
<body class="d-flex flex-column min-vh-100">

<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<span class="navbar-brand d-flex align-items-center">
<img src="img/blockly_72.png" alt="" class="me-2">
Blockly Unix
</span>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/blockly_unix">Blockly</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="/tutorials">Tutorials</a>
</li>
</ul>
<div class="d-flex align-items-center">
<a href="/login" class="btn btn-primary me-2" id="loginHomePageButton" style="display: none;">Login</a>
<a href="/register" class="btn btn-outline-primary me-2" id="registerHomePageButton" style="display: none;">Register</a>
<!--
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-primary" type="submit">Search</button>
</form>
-->
</div>
<div class="d-flex align-items-center">
<a href="/blockly_unix" class="btn btn-primary me-2" id="continueWithBlocklyButton" style="display: none;">Continue Where You Left Off</a>
<a href="/" class="btn btn-outline-primary me-2" id="logoutHomePageButton" style="display: none;">Logout</a>
<form id="logoutForm" action="/logout" method="DELETE" style="display: none;">
<input type="hidden" name="_method" value="DELETE" />
</form>
</div>
</div>
</div>
</nav>
<section id="faq" class="faq">
<div class="container">

<div class="section-title text-center" data-aos="fade-up">
<h1>Commonly used tasks and Blockly Unix solutions</h1>
</div>

<ul class="faq-list ">

<li>
<div data-bs-toggle="collapse" class="collapsed question" href="#faq1">Filter, Sort, Count, and Save Data Based on Specific Conditions<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq1" class="collapse" data-bs-parent=".faq-list">
<p>
Filter lines from a file based on a specific condition, sort them, count unique occurrences, and save the top results to a new file.
</p>
<div class="image-container">
<img src="img/blockly_photo.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>awk -F';' ' $3 == "empt" ' test.txt | sort -r -k2 | uniq -c | head -n 50 > newFile.txt</strong>
</p>
</div>
</li>
<li>
<div data-bs-toggle="collapse" href="#faq2" class="collapsed question">Removing Duplicate Lines and Sorting<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq2" class="collapse" data-bs-parent=".faq-list">
<p>
Remove duplicate lines from a file and then sort the remaining lines.
</p>
<div class="image-container">
<img src="img/remove_duplicate_lines_and_sort.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>sort inputFile.txt | uniq > outputFile.txt</strong>
</p>
</div>
</li>

<li>
<div data-bs-toggle="collapse" href="#faq3" class="collapsed question"> Filter Rows Based on a Pattern<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq3" class="collapse" data-bs-parent=".faq-list">
<p>
Filter rows containing the word "error" in a log file. Then count the number of lines that contain the word "error."
</p>
<div class="image-container">
<img src="img/filter_rows_and_count_lines.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>grep "error" logFile.txt | wc -l</strong>
</p>
</div>
</li>

<li>
<div data-bs-toggle="collapse" href="#faq4" class="collapsed question">Convert a List of URLs to Their Domain Names<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq4" class="collapse" data-bs-parent=".faq-list">
<p>
Extract and count domain names from a list of URLs and save the top 15 most frequent domains to a new file.
</p>
<div class="image-container">
<img src="img/convert_domains.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>awk -F'/' ' -F'/' {print $3}}' ' urls.txt | sort | uniq -c | sort -r | head -n 15 > topdomains.txt</strong>
</p>
</div>
</li>
<li>
<div data-bs-toggle="collapse" href="#faq5" class="collapsed question">Combining Multiple Files into One<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq5" class="collapse" data-bs-parent=".faq-list">
<p>
Concatenate the contents of multiple files into a single file.
</p>
<div class="image-container">
<img src="img/combine_files.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>cat file1.txt file2.txt file3.txt > combinedFile.txt</strong>
</p>
</div>
</li>
<li>
<div data-bs-toggle="collapse" href="#faq6" class="collapsed question">Extracting Specific Columns from a File and Saving to a New File<i class="bi bi-chevron-down icon-show"></i><i class="bi bi-chevron-up icon-close"></i></div>
<div id="faq6" class="collapse" data-bs-parent=".faq-list">
<p>
Extract columns 1 and 3 from a CSV file and save the output to a new file.
</p>
<div class="image-container">
<img src="img/extract_columns.png" alt="Blockly Unix" class="img-fluid" style="width: 700px; height: auto;">
</div>
<p>
The corresponding Unix command for this task is: <strong>cut -d',' -f'1,3' file.txt > extracted_columns.txt</strong>
</p>
</div>
</li>
</ul>

</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>

0 comments on commit a5c28e6

Please sign in to comment.