Skip to content

Instantly share code, notes, and snippets.

@michaelkebe
Created February 1, 2022 20:06
Show Gist options
  • Save michaelkebe/45a0b5d209897f59e619a0a3e671bf8a to your computer and use it in GitHub Desktop.
Save michaelkebe/45a0b5d209897f59e619a0a3e671bf8a to your computer and use it in GitHub Desktop.
/** @param {NS} ns **/
export async function main(ns) {
const delay = ns.args[1]
if (delay) {
await ns.sleep(delay)
}
await ns.hack(ns.args[0])
}
import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
import { PERSONAL_ACCESS_TOKEN } from "token.js"
// Create a token.js with this content
// export const PERSONAL_ACCESS_TOKEN = "ghp_abcdef1234567890"
/** @param {NS} ns **/
export async function main(ns) {
if (ns.args.length == 0) {
ns.tprint("Usage: run gists.js file1 file2 file3 ...")
}
const octokit = new Octokit({ auth: PERSONAL_ACCESS_TOKEN })
//await octokit.rest.users.getAuthenticated()
const files = {}
for (const filename of ns.args) {
const fileContent = await ns.read(filename)
if (fileContent !== "") {
files[filename.replaceAll("/", "_")] = {
"content": fileContent
}
} else {
ns.tprint(`ERROR: Could not read ${filename}`)
ns.exit()
}
}
ns.tprint(files)
ns.tprint("Creating gist...")
const response = await octokit.rest.gists.create({
public: true,
files: files
})
ns.tprintf(`Gist created. URL: ${response.data.html_url}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment