Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd23d61
commit b633543
Showing
2,785 changed files
with
107,472 additions
and
7,940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
|
||
def find_files_with_non_numeric_title(root_dir): | ||
for root, dirs, files in os.walk(root_dir): | ||
for file in files: | ||
if file == "index.ru.md": | ||
file_path = os.path.join(root, file) | ||
with open(file_path, "r") as f: | ||
lines = f.readlines() | ||
if len(lines) >= 2 and lines[1].startswith("title:"): | ||
title = lines[1].strip().split("title:")[1].strip() | ||
# Check if title is not numeric | ||
numeric = title.replace(".", "", 1) | ||
if not numeric[0].isdigit(): | ||
dir_name = os.path.basename(os.path.dirname(file_path)) | ||
title = lines[1].strip().split("title:")[1].strip() | ||
lines[1] = f"title: {dir_name}. {title}\n" | ||
with open(file_path, "w") as f: | ||
f.writelines(lines) | ||
print(f"Updated file: {file_path}") | ||
|
||
|
||
root_dir = "content/tracks/algorithms-101/leetcode/" | ||
find_files_with_non_numeric_title(root_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: tmp_post | ||
seoTitle: tmp_post | ||
description: tmp_post | ||
toc: true | ||
tags: [tmp_post, tmp_post] | ||
categories: [tmp_post, tmp_post, tmp_post] | ||
date: 2024-02-02 | ||
lastMod: 2024-02-02 | ||
featuredImage: https://picsum.photos/700/241?grayscale | ||
weight: 1 | ||
draft: true | ||
--- | ||
|
||
|
||
tmp_post | ||
|
||
## Problem Statement | ||
|
||
tmp_post | ||
|
||
leetcode-grid | ||
|
||
style="display:inline-block" | ||
|
||
<div id="_react_leetcode_grid_" class='bg-tertiary-bg rounded px-3 py-2 my-2 me-2 text-lg'></div> | ||
|
||
{{< reactblock src="<http://localhost:1313/en/p/tmp_post/react/leetcode-grid.jsx?a2>" divRender="_react_leetcode_grid_">}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { useEffect, useState, useRef } from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
|
||
// console.log("leetcodeProblems", window.location.host, leetcodeProblems); | ||
|
||
const divRender = "_react_leetcode_grid_"; // Make sure this matches the ID of your root div element | ||
|
||
const CELL_WIDTH = 50; | ||
|
||
const Matrix = () => { | ||
const size = 3032; // Total numbers | ||
const [columns, setColumns] = useState(10); | ||
const [leetcodeProblems, setLeetcodeProblems] = useState({}); | ||
const matrixRef = useRef(null); // Ref to the matrix container | ||
|
||
useEffect(() => { | ||
const updateColumns = () => { | ||
const matrixWidth = matrixRef.current.offsetWidth; // Get the current width of the matrix container | ||
const cellWidth = CELL_WIDTH + 2; // width + 1px border on each side | ||
const newColumns = Math.floor(matrixWidth / cellWidth); | ||
setColumns(newColumns); // Update the number of columns based on the parent's width | ||
}; | ||
|
||
window.addEventListener("resize", updateColumns); | ||
updateColumns(); // Initial update | ||
|
||
const leetCodeProblemsUrl = | ||
"http://" + window.location.host + "/leetcode-problems.json"; | ||
console.log("leetCodeProblemsUrl", leetCodeProblemsUrl); | ||
fetch(leetCodeProblemsUrl) | ||
.then((response) => response.json()) | ||
.then((data) => setLeetcodeProblems(data)) | ||
.catch((error) => | ||
console.error("Failed to load leetcode problems:", error), | ||
); | ||
|
||
return () => window.removeEventListener("resize", updateColumns); | ||
}, []); | ||
|
||
const getCellStyle = (number) => { | ||
const problemInfo = leetcodeProblems[number.toString()]; | ||
const _cellStyle = { | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "30px", | ||
border: "1px solid #ccc", | ||
width: CELL_WIDTH + "px", | ||
backgroundColor: "#fff", | ||
}; | ||
|
||
if (!problemInfo || !problemInfo.languages[userLang]) { | ||
return _cellStyle; | ||
} | ||
|
||
if (problemInfo && problemInfo.difficulty === "Easy") { | ||
_cellStyle.backgroundColor = "#ffb800"; | ||
return _cellStyle; | ||
} | ||
if (problemInfo && problemInfo.difficulty === "Medium") { | ||
_cellStyle.backgroundColor = "#1cb8b8"; | ||
return _cellStyle; | ||
} | ||
if (problemInfo && problemInfo.difficulty === "Hard") { | ||
_cellStyle.backgroundColor = "#f63636"; | ||
return _cellStyle; | ||
} | ||
return _cellStyle; | ||
}; | ||
|
||
const numbers = Array.from({ length: size }, (_, i) => i + 1); | ||
|
||
return ( | ||
<div | ||
ref={matrixRef} | ||
style={{ | ||
display: "grid", | ||
gridTemplateColumns: `repeat(${columns}, ${CELL_WIDTH}px)`, | ||
gap: "1px", | ||
}} | ||
> | ||
{numbers.map((number, index) => { | ||
const cellStyle = getCellStyle(number); | ||
const problemInfo = leetcodeProblems[number.toString()]; | ||
let cell = <>{number}</>; | ||
if (problemInfo && problemInfo.languages[userLang]) { | ||
cell = ( | ||
<a | ||
href={problemInfo.languages[userLang]} // userLang - global var | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{number} | ||
</a> | ||
); | ||
} | ||
return ( | ||
<div key={index} style={cellStyle}> | ||
{cell} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
const App = () => { | ||
return ( | ||
<div className="App" style={{ width: "100%", margin: "auto" }}> | ||
<Matrix /> | ||
</div> | ||
); | ||
}; | ||
|
||
const container = document.getElementById(divRender); | ||
const root = createRoot(container); // Ensure your HTML has a div with the id 'root' | ||
root.render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.