Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/post-leetcode-potd-to-discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: ./.github/workflows/set-up-everything

- name: Prepare secrets
run: (cd workspaces/post-leetcode-potd-to-discord && echo "$SECRETS_FILE" > secrets_DO_NOT_COMMIT_OR_SHARE.json)
run: echo "$SECRETS_FILE" > workspaces/post-leetcode-potd-to-discord/secrets_DO_NOT_COMMIT_OR_SHARE.json
env:
SECRETS_FILE: ${{ secrets.SECRETS_FILE }}

Expand Down
21 changes: 21 additions & 0 deletions .yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/nullthrows.d.ts b/nullthrows.d.ts
index d4953f2f47b79701e5f125b9c041fb185668dd53..a39a37b30cd206e037ecbbb66bc90dacd6adb3af 100644
--- a/nullthrows.d.ts
+++ b/nullthrows.d.ts
@@ -1,5 +1,15 @@
/**
* Throws if value is null or undefined, otherwise returns value.
*/
+declare function nullthrows<T>(
+ value?: T | null,
+ message?: string,
+): NonNullable<T>;
+
+// Patched based on https://github.com/microsoft/TypeScript/issues/46770#issuecomment-1039459991 and https://github.com/zertosh/nullthrows/pull/15
+
+declare namespace nullthrows {
+ export { nullthrows as default };
+}
+export = nullthrows;

-export default function nullthrows<T>(value?: T | null, message?: string): T;
2 changes: 1 addition & 1 deletion workspaces/adventure-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"dependencies": {
"immutability-helper": "3.1.1",
"invariant": "2.2.4",
"nullthrows": "1.1.1",
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-syntax-highlighter": "15.5.0"
Expand Down
2 changes: 2 additions & 0 deletions workspaces/download-leetcode-submissions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ secrets_DO_NOT_COMMIT_OR_SHARE.json
submissions/
submissions.jsonl
submissions.sha512

dist/
31 changes: 27 additions & 4 deletions workspaces/download-leetcode-submissions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To use:
nano secrets_DO_NOT_COMMIT_OR_SHARE.json
```

2. **Run the script!**
2. **Run the script!** You can run a development version:

```sh
# Install dependencies, if you haven't already:
Expand All @@ -33,7 +33,26 @@ To use:
yarn start
```

Submissions will be downloaded to a directory named `submissions`, grouped by problem and problem number range. Filenames take the form `{yyyymmdd-date}-{submission-id}-{result}.{extension}`, resulting in full paths like `submissions/2101-2200/2163-kth-distinct-string-in-an-array/20240805-1345920313-ac.c` for an accepted C solution submitted on August 5th, 2024.
Or, build and run a distribution version:

```sh
# It's easiest to do this from the package's directory:
cd workspaces/download-leetcode-submissions

# Install dependencies, if you haven't already:
yarn

# Package the script into an executable:
yarn build

# Run it with Node!
node dist/download-leetcode-submissions.cjs

# Or if your system can handle executable files, try running it directly:
./dist/download-leetcode-submissions.cjs
```

Submissions will be downloaded to a directory named `submissions`, grouped by problem and problem number range. Filenames take the form `{yyyymmdd-date}-{submission-id}-{result}.{extension}`, resulting in full paths like `submissions/2101-2200/2163-kth-distinct-string-in-an-array/20240805-1345920313-ac.c` for an accepted C solution submitted on August 5th, 2024.

## Metadata Files

Expand Down Expand Up @@ -79,6 +98,10 @@ As such it's safe to run the script multiple times, without redoing too much wor

Like the rest of the [Code Chronicles Leetcode ecosystem](../../), this package is structured as a Node module, using [Yarn](https://yarnpkg.com/) as the package manager.

You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy.
You can install dependencies by running `yarn`, either in this package's directory, or in the repository root. The usual `yarn format`, `yarn lint`, and `yarn typecheck` scripts are available to aid in development and occasionally to annoy. Read more in the repository's general [development guide](../../DEVELOPMENT.md).

This package supports an additional `package.json` script:

### `yarn build`

See also the repository's general [development guide](../../DEVELOPMENT.md).
Builds a distribution version of this package, in a `dist` directory within the package's workspace.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import config from "@code-chronicles/eslint-config";

export default [...config, { ignores: ["submissions/"] }];
export default [...config, { ignores: ["dist/", "submissions/"] }];
10 changes: 8 additions & 2 deletions workspaces/download-leetcode-submissions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"name": "Miorel-Lucian Palii",
"url": "https://github.com/miorel"
},
"type": "module",
"exports": "./src/main.ts",
"scripts": {
"build": "cross-env NODE_OPTIONS=\"--import tsx\" webpack && chmod +x dist/download-leetcode-submissions.cjs",
"format": "prettier --color --write .",
"lint": "eslint --color --max-warnings=0 .",
"start": "tsx src/main.ts",
Expand All @@ -22,15 +24,19 @@
"dependencies": {
"@code-chronicles/leetcode-api": "workspace:*",
"@code-chronicles/util": "workspace:*",
"nullthrows": "1.1.1",
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
"zod": "3.23.8"
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
"@types/node": "22.5.5",
"cross-env": "7.0.3",
"eslint": "9.10.0",
"prettier": "3.3.3",
"ts-loader": "9.5.1",
"tsx": "4.19.1",
"typescript": "5.6.2"
"typescript": "5.6.2",
"webpack": "5.94.0",
"webpack-cli": "5.1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "node:path";

import type { TransformedSubmission } from "./transformSubmission";
import type { TransformedSubmission } from "./transformSubmission.js";

const PROBLEMS_PER_GROUP = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import nullthrows from "nullthrows";
import { SUBMISSION_STATUS_TO_ABBREVIATION } from "@code-chronicles/leetcode-api";
import { timestampInSecondsToYearMonthDay } from "@code-chronicles/util/timestampInSecondsToYearMonthDay";

import { LANGUAGE_TO_FILE_EXTENSION } from "./constants";
import type { TransformedSubmission } from "./transformSubmission";
import { LANGUAGE_TO_FILE_EXTENSION } from "./constants.js";
import type { TransformedSubmission } from "./transformSubmission.js";

export function getFilenameForSubmission({
id,
Expand Down
14 changes: 7 additions & 7 deletions workspaces/download-leetcode-submissions/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import { promiseAllLimitingConcurrency } from "@code-chronicles/util/promiseAllL
import { sleep } from "@code-chronicles/util/sleep";
import { whileReturnsTrueAsync } from "@code-chronicles/util/whileReturnsTrueAsync";

import { CONCURRENCY_LIMIT } from "./constants";
import { getFilenameForSubmission } from "./getFilenameForSubmission";
import { getDirnameForSubmission } from "./getDirnameForSubmission";
import { readPriorSubmissions } from "./readPriorSubmissions";
import { readSecrets } from "./readSecrets";
import { CONCURRENCY_LIMIT } from "./constants.js";
import { getDirnameForSubmission } from "./getDirnameForSubmission.js";
import { getFilenameForSubmission } from "./getFilenameForSubmission.js";
import { readPriorSubmissions } from "./readPriorSubmissions.js";
import { readSecrets } from "./readSecrets.js";
import {
transformSubmission,
type TransformedSubmission,
} from "./transformSubmission";
import { writeSubmissionsMetadataAndHashes } from "./writeSubmissionsMetadataAndHashes";
} from "./transformSubmission.js";
import { writeSubmissionsMetadataAndHashes } from "./writeSubmissionsMetadataAndHashes.js";

async function main(): Promise<void> {
// TODO: maybe create the file from a template if it doesn't exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fsPromises from "node:fs/promises";

import { getLines } from "@code-chronicles/util/getLines";

import { METADATA_FILE } from "./constants";
import type { TransformedSubmission } from "./transformSubmission";
import { METADATA_FILE } from "./constants.js";
import type { TransformedSubmission } from "./transformSubmission.js";

export async function readPriorSubmissions(): Promise<
Map<string, TransformedSubmission>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { writeFile } from "node:fs/promises";

import { METADATA_FILE, HASHES_FILE } from "./constants";
import { getFilenameForSubmission } from "./getFilenameForSubmission";
import { getDirnameForSubmission } from "./getDirnameForSubmission";
import type { TransformedSubmission } from "./transformSubmission";
import { METADATA_FILE, HASHES_FILE } from "./constants.js";
import { getDirnameForSubmission } from "./getDirnameForSubmission.js";
import { getFilenameForSubmission } from "./getFilenameForSubmission.js";
import type { TransformedSubmission } from "./transformSubmission.js";

export async function writeSubmissionsMetadataAndHashes(
submissionsMap: ReadonlyMap<string, TransformedSubmission>,
Expand Down
68 changes: 68 additions & 0 deletions workspaces/download-leetcode-submissions/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { builtinModules } from "node:module";
import path from "node:path";

import webpack, {
type Configuration,
type ExternalItemFunctionData,
} from "webpack";

import { stripPrefix } from "@code-chronicles/util/stripPrefix";
import { stripPrefixOrThrow } from "@code-chronicles/util/stripPrefixOrThrow";

import packageJson from "./package.json" with { type: "module" };

const config: Configuration = {
target: "node",
entry: path.resolve(__dirname, packageJson.exports),
output: {
filename:
stripPrefixOrThrow(packageJson.name, "@code-chronicles/") + ".cjs",
path: path.resolve(__dirname, "dist"),
},

module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: {
noEmit: false,
},
},
},
],
exclude: /\bnode_modules\b/,
},
],
},

resolve: {
extensions: [".tsx", ".ts", "..."],
extensionAlias: {
".js": [".ts", ".tsx", ".js"],
},
},

externalsType: "commonjs",
externals: ({ request }: ExternalItemFunctionData) =>
Promise.resolve(
request != null &&
(builtinModules.includes(request) ||
builtinModules.includes(stripPrefix(request, "node:")))
? request
: undefined,
),

plugins: [
new webpack.BannerPlugin({
banner: "#!/usr/bin/env node\n",
raw: true,
entryOnly: true,
}),
],
};

export default config;
2 changes: 1 addition & 1 deletion workspaces/generate-health-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@code-chronicles/util": "workspace:*",
"nullthrows": "1.1.1"
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch"
},
"devDependencies": {
"@code-chronicles/eslint-config": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/leetcode-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@code-chronicles/util": "workspace:*",
"invariant": "2.2.4",
"nullthrows": "1.1.1",
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"invariant": "2.2.4",
"nullthrows": "1.1.1",
"nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
21 changes: 16 additions & 5 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading