Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Snippets-C++] Added two snippets from #209 #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
majvax merged 24 commits into quicksnip-dev:main from majvax:snippets-c++
Jan 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e93bcac
[C++] added snippet
majvax Jan 1, 2025
2a6b1e2
Merge remote-tracking branch 'origin/snippets-c++' into snippets-c++
majvax Jan 1, 2025
aad3f79
[C++] added 3 snippets for string.
majvax Jan 1, 2025
f472a29
Added missing chrono header
majvax Jan 2, 2025
31b43b5
fixed tags
majvax Jan 2, 2025
29112d8
Merge remote-tracking branch 'origin/snippets-c++' into snippets-c++
majvax Jan 2, 2025
4638879
fixed exemple needing std=c++20
majvax Jan 2, 2025
98ddffc
Fixed Usage to accommodate to new guidelines
majvax Jan 2, 2025
aebefde
Fixed all tags + type
majvax Jan 3, 2025
d76dbfd
Revert "Fixed all tags + type"
majvax Jan 3, 2025
c188670
Merge remote-tracking branch 'upstream/main' into snippets-c++
majvax Jan 3, 2025
9364abb
Fixed type and all tags
majvax Jan 3, 2025
3a99176
fixed gh check failing
majvax Jan 3, 2025
c0d6f04
Update consolidated snippets
actions-user Jan 3, 2025
1dd6a8f
Merge branch 'dostonnabotov:main' into snippets-c++
majvax Jan 3, 2025
fce087f
Update consolidated snippets
actions-user Jan 3, 2025
a959e95
Update consolidated snippets
actions-user Jan 3, 2025
4708bd9
Merge remote-tracking branch 'origin/main' into snippets-c++
majvax Jan 4, 2025
112302e
Revert "Merge remote-tracking branch 'origin/main' into snippets-c++"
majvax Jan 6, 2025
60496ec
Merge remote-tracking branch 'origin/main' into snippets-c++
majvax Jan 6, 2025
812842f
Update consolidated snippets
actions-user Jan 6, 2025
1fbaec8
Merge remote-tracking branch 'origin/main' into snippets-c++
majvax Jan 10, 2025
7c0ca05
added two snippets from #209
majvax Jan 10, 2025
da7b75c
resolve check not passing
majvax Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Merge remote-tracking branch 'origin/main' into snippets-c++"
This reverts commit 4708bd9, reversing
changes made to a959e95.
  • Loading branch information
majvax committed Jan 6, 2025
commit 112302e456d8b7d871d619d6b6ca5dd124675b0c
41 changes: 41 additions & 0 deletions public/consolidated/cpp.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,47 @@
}
]
},
{
"categoryName": "File Handling",
"snippets": [
{
"title": "Find files recursively",
"description": "Find all the files in a directory and subdirectories using a predicate function.",
"author": "majvax",
"tags": [
"filesystem",
"file_search",
"c++17"
],
"contributors": [],
"code": "#include <filesystem>\n#include <vector>\n#include <string>\n\ntemplate <typename P>\nstd::vector<std::filesystem::path> find_files_recursive(const std::string& path, P&& predicate) {\n std::vector<std::filesystem::path> files;\n std::error_code ec;\n\n if (!std::filesystem::exists(path, ec) || ec)\n return files;\n if (!std::filesystem::is_directory(path, ec) || ec)\n return files;\n\n auto it = std::filesystem::recursive_directory_iterator(path, ec);\n if (ec)\n return files;\n\n for (const auto& entry : it)\n if (!std::filesystem::is_directory(entry) && predicate(entry.path()))\n files.push_back(entry.path());\n\n return files;\n}\n\n\n\n// Usage:\n\n// Find all files with size greater than 10MB\nauto files = find_files_recursive(\"Path\", [](const auto& p) {\n return std::filesystem::file_size(p) > 10 * 1024 * 1024;\n});\n\n// Find all files with \".pdf\" as extension\nauto files = find_files_recursive(\"Path\", [](const auto& p) {\n return p.extension() == \".pdf\";\n});\n\n// Find all files writed after The New Year\n#include <chrono>\n// need std=c++20\nauto jan_1_2025 = std::filesystem::file_time_type::clock::from_sys(\n std::chrono::sys_days{std::chrono::year{2025}/std::chrono::month{1}/std::chrono::day{1}}\n);\nauto files = find_files_recursive(\"Path\", [jan_1_2025](const auto& p) {\n return std::filesystem::last_write_time(p) > jan_1_2025;\n}),\n"
},
{
"title": "Find files",
"description": "Find all the files in a directory using a predicate function.",
"author": "majvax",
"tags": [
"filesystem",
"file_search",
"c++17"
],
"contributors": [],
"code": "#include <filesystem>\n#include <vector>\n#include <string>\n\ntemplate <typename P>\nstd::vector<std::filesystem::path> find_files(const std::string& path, P&& predicate) {\n std::vector<std::filesystem::path> files;\n std::error_code ec;\n\n if (!std::filesystem::exists(path, ec) || ec)\n return files;\n if (!std::filesystem::is_directory(path, ec) || ec)\n return files;\n\n auto it = std::filesystem::directory_iterator(path, ec);\n if (ec)\n return files;\n\n for (const auto& entry : it)\n if (!std::filesystem::is_directory(entry) && predicate(entry.path()))\n files.push_back(entry.path());\n\n return files;\n}\n\n\n\n// Usage:\n\n// Find all files with size greater than 10MB\nauto files = find_files(\"Path\", [](const auto& p) {\n return std::filesystem::file_size(p) > 10 * 1024 * 1024;\n});\n\n// Find all files with \".pdf\" as extension\nauto files = find_files(\"Path\", [](const auto& p) {\n return p.extension() == \".pdf\";\n});\n\n// Find all files writed after The New Year\n#include <chrono>\n// need std=c++20\nauto jan_1_2025 = std::filesystem::file_time_type::clock::from_sys(\n std::chrono::sys_days{std::chrono::year{2025}/std::chrono::month{1}/std::chrono::day{1}}\n);\nauto files = find_files(\"Path\", [jan_1_2025](const auto& p) {\n return std::filesystem::last_write_time(p) > jan_1_2025;\n}),\n"
},
{
"title": "List Directories",
"description": "Lists all the directories in a path.",
"author": "majvax",
"tags": [
"filesystem",
"directories",
"c++17"
],
"contributors": [],
"code": "#include <filesystem>\n#include <vector>\n#include <string>\n\nstd::vector<std::filesystem::path> list_directories(const std::string& path) {\n std::vector<std::filesystem::path> files;\n std::error_code ec;\n\n if (!std::filesystem::exists(path, ec) || ec)\n return files;\n if (!std::filesystem::is_directory(path, ec) || ec)\n return files;\n\n auto it = std::filesystem::directory_iterator(path, ec);\n if (ec)\n return files;\n\n for (const auto& entry : it)\n if (std::filesystem::is_directory(entry))\n files.push_back(entry.path());\n\n return files;\n}\n\n\n\n// Usage:\nauto directories = list_directories(\"Path\");\n"
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
Expand Down

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /