Skip to content

Commit

Permalink
Merge branch 'main' into chisquare
Browse files Browse the repository at this point in the history
  • Loading branch information
avdhoottt authored Jan 14, 2025
2 parents e7ac025 + e50335b commit 9cf3f89
Show file tree
Hide file tree
Showing 34 changed files with 2,035 additions and 64 deletions.
22 changes: 22 additions & 0 deletions .github/scripts/validate-content-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { readdirSync } = require('node:fs');

let exitCode = 0;

const next = ['concepts', 'terms'];

function checkPath(path, i) {
for (const entry of readdirSync(path)) {
const entryDir = readdirSync(`${path}/${entry}`);
if (!entryDir.includes(`${entry}.md`)) {
console.error(`\n${path}/${entry} should contain a ${entry}.md file\n`);
exitCode = 1;
}
if (i < 2 && entryDir.includes(next[i])) {
checkPath(`${path}/${entry}/${next[i]}`, i + 1);
}
}
}

checkPath('content', 0);

process.exit(exitCode);
3 changes: 1 addition & 2 deletions .github/workflows/post-merge-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
${{ env.urls }}
Please note it may take a little while for changes to become visible.
If you're appearing as anonymous and want to be credited, see [here](https://discuss.codecademy.com/t/my-contribution-is-live-but-im-not-being-shown-as-a-contributor-why-is-this/758036).
If you're appearing as anonymous and want to be credited, visit the [linked accounts](https://www.codecademy.com/account/linked_accts) page and ensure that your GitHub account is linked.
issuesClosed: |
🌸 Thanks for closing this Issue!
Please head over to the [Docs Forum](https://discuss.codecademy.com/c/community/community-docs/2205) if you have any questions about Docs, or reply to the thread on [Possible Content Discussion](https://discuss.codecademy.com/t/find-a-starting-point-possible-content-discussion/745868) to share ideas and collaborate with other contributors, maintainers, or super users to determine good future issues that will help expand Docs!
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
command: ["compile", "format:verify", "lint:js", "lint:md", "test"]
command: ["compile", "format:verify", "lint:js", "lint:md", "test", "validate-content-tree"]

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion bin/concept-of-the-week.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
content/c/concepts/user-input/user-input.md
content/ruby/concepts/sets/sets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
Title: 'Volatile Variables'
Description: 'Ensures variables avoid compiler optimization, allowing correct access when their values may change due to external factors.'
Subjects:
- 'Computer Science'
- 'Code Foundations'
Tags:
- 'Memory'
- 'Variables'
- 'Variable Types'
CatalogContent:
- 'learn-c-plus-plus'
- 'paths/computer-science'
---

**Volatile variables** in C++ are not optimized or cached by the compiler. Marking a variable as volatile is appropriate when its value may be altered by external factors beyond the program's control. This instructs the compiler to read the most recent value from memory instead of a potentially outdated cached version. However, it's important to note that declaring a variable as volatile does not ensure atomicity or synchronize memory between threads; it solely prevents compiler optimization, which is particularly crucial in multithreaded environments.

## Syntax

To declare a variable as volatile, the `volatile` keyword needs to be placed before the variable type:

```pseudo
volatile data_type variable_name;
```

## Example

A volatile variable signals a worker thread to stop running and performing tasks in the following example. The `volatile` keyword prevents the compiler from optimizing away, continuously checking the variable while in the loop. The worker thread will continue until the `isRunning` variable is false.

```cpp
#include <iostream>
#include <thread>
#include <chrono>
class VolatileExample {
private:
// 'volatile' tells the compiler not to optimize this variable, ensuring that each iteration of the following loop fetches the latest value.
volatile bool isRunning = true;
public:
void runTask() {
while (isRunning) {
std::cout << "Task is running..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
std::cout << "Task has stopped." << std::endl;
}
void stopTask() {
isRunning = false; // Changing 'isRunning' to false to stop the task.
}
};
int main() {
VolatileExample example;
std::thread workerThread(&VolatileExample::runTask, &example);
// The task runs for a while before stopping it.
std::this_thread::sleep_for(std::chrono::seconds(5));
example.stopTask(); // Stop the task
workerThread.join(); // Waits for the thread to finish.
return 0;
}
```
4 changes: 2 additions & 2 deletions content/css/concepts/overflow/overflow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Title: 'Overflow'
Description: 'The overflow property controls what happens to content that spills, or overflows, outside its box. The most commonly used values are: - hidden When set to this value, any content that overflows will be hidden from view. - scroll: When set to this value, a scrollbar will be added to the element’s box so that the rest of the content can be viewed by scrolling. - visible: When set to this value, the overflow content will be displayed outside of the containing element. Note, this is the default value. css p {'
Description: 'The overflow property controls what happens to content that spills, or overflows, outside its box.'
Subjects:
- 'Web Development'
- 'Web Design'
Expand All @@ -16,7 +16,7 @@ The `overflow` property controls what happens to content that spills, or overflo

The most commonly used values are:

- `hidden` When set to this value, any content that overflows will be hidden from view.
- `hidden`: When set to this value, any content that overflows will be hidden from view.
- `scroll`: When set to this value, a scrollbar will be added to the element’s box so that the rest of the content can be viewed by scrolling.
- `visible`: When set to this value, the overflow content will be displayed outside of the containing element. Note, this is the default value.

Expand Down
6 changes: 3 additions & 3 deletions content/general/concepts/json/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ More can be learned about JSON by visiting [json.org](https://www.json.org/).
{
"propertyOne": "valueOne",
"propertyTwo": "valueTwo",
"propertyThree": "valueThree",
"propertyThree": "valueThree"
}
```

Expand All @@ -60,12 +60,12 @@ Multiple JSON objects can be collected in an array-like sequence:
{
"propertyOne": "valueOne",
"propertyTwo": "valueTwo",
"propertyThree": "valueThree",
"propertyThree": "valueThree"
},
{
"propertyA": "valueA",
"propertyB": "valueB",
"propertyC": "valueC",
"propertyC": "valueC"
}
]
```
Expand Down
91 changes: 91 additions & 0 deletions content/git/concepts/amend/amend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
Title: 'Amend'
Description: 'Modifies the most recent Git commit without creating a new one.'
Subjects:
- 'Bash/Shell'
- 'Developer Tools'
Tags:
- 'Command Line'
- 'Documentation'
- 'Error Handling'
- 'Git'
CatalogContent:
- 'learn-git'
- 'paths/computer-science'
---

**Amend** is a Git feature that allows developers to modify the most recent commit. It is commonly used to correct mistakes such as adding a missing file, fixing an incorrect commit message, or making minor adjustments without creating an entirely new commit.

This feature is particularly helpful for maintaining a clean and concise commit history, ensuring that changes are logically grouped and easy to understand.

## Syntax

The syntax for using the amend feature in Git is:

```pseudo
git commit --amend
```

To amend both the content of the commit and the commit message, the following would be used:

```pseudo
git commit --amend -m "Your new commit message"
```

## Example 1

Suppose, the developer created and committed a feature, but forgot to include a file:

```shell
# Original commit
echo "Initial code" > feature.txt
echo "Forgotten content" > forgotten-file.txt
git add feature.txt # Dev forgot to add forgotten-file.txt
git commit -m "Add initial code for the feature"
```

Here's the original commit history:

```shell
git log --oneline
abc1234 Add initial code for the feature
```

The developer realized that he hasn't included a file in the original commit. So, he performs the amend operation to both include the file in that commit and change the commit message:

```shell
# Amending the original commit
git add forgotten-file.txt
git commit --amend -m "Add initial code for the feature and forgotten file"
```

Here's the amended commit history:

```shell
git log --oneline
def5678 Add initial code for the feature and forgotten file # Commit abc1234 has been replaced by def5678
```

## Example 2

Suppose, the developer is going through another commit history:

```shell
git log --oneline
abc1234 Original commit message
```

While going through it, the developer didn't like the above commit message. So, he decides to use the amend operation to only change the commit message without touching the contents of the commit:

```shell
git commit --amend -m "Corrected commit message"
```

Here's the amended commit history:

```shell
git log --oneline
abc1234 Corrected commit message
```

> **Note:** Use `git commit --amend` carefully if the commit has already been shared with others, as it rewrites history.
76 changes: 76 additions & 0 deletions content/git/concepts/checkout/checkout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
Title: 'Checkout'
Description: 'The git checkout command switches, creates and restores branches in the working directory to a specific state.'
Subjects:
- 'Bash/Shell'
- 'Developer Tools'
Tags:
- 'Git'
- 'GitHub'
CatalogContent:
- 'learn-git'
- 'learn-the-command-line'
- 'paths/computer-science'
---

The **`git checkout`** command switches, creates and restores branches in the working directory to a specific state. The `git checkout` command also allows switching to a specific commit without changing branches.

## Syntax

Checkout with branches:

```pseudo
git checkout [options] <branch-name>
```

- `<branch-name>` specifies the name of the branch to switch to or create.
- `[options]` optional flags that can be used with the checkout command. Here are some of the most commonly used options:
- `-b` creates a new branch with the specified name and switches to it immediately.
- `-` returns to the previously checked-out branch. This flag does not need the `<branch-name>`.
- `-f` (--force) forces the checkout, discarding any local changes in the working directory.

Checkout to a specific commit:

```pseudo
git checkout <commit-hash>
```

## Switch to an existing branch

The following command will switch to an already existing branch, created previously with the [git branch](https://www.codecademy.com/resources/docs/git/branch) command:

```pseudo
git checkout existing-branch
```

> **Note**: From Git 2.23, the new specific `git switch` command has been introduced to switch branches, making it clearer and safer than `git checkout` because it avoids the ambiguity of the latter's multi-purpose nature.
## Create and switch to a new branch

It is possible to create and switch to a new branch with a single command using the `-b` option:

```pseudo
git checkout -b new-branch
```

## Restore a file from a specific commit

`git checkout` also allows to restore a file from a specific commit using its hash:

```pseudo
git checkout <commit-hash> -- example.txt
```

## Examine a Previous Commit

`git checkout` also allows temporarily moving to a specific commit without changing branches. This state is called **detached `HEAD` state**:

```pseudo
git checkout <commit-hash>
```

The detached `HEAD` state allows to:

- Examine the state of the repository at that specified commit.
- Create new branches if the developer needs to start from that point.
- Any code changes made in this state will not be associated with any existing branch unless a new branch is created.
Loading

0 comments on commit 9cf3f89

Please sign in to comment.