Skip to content

Instantly share code, notes, and snippets.

@polotek
Last active October 16, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polotek/3650c93859d95425c9aeaae88161067f to your computer and use it in GitHub Desktop.
Save polotek/3650c93859d95425c9aeaae88161067f to your computer and use it in GitHub Desktop.

This gist is meant to go along with a twitter thread. You can find that thread here.

I spent some time discussing my experience with Github Copilot. I talked about some of the social implications of this tech. But I also wanted to show examples of how it worked. In some cases, the experience was pretty surprising.

Because the code screenshots on twitter are not very accessible, I've created this gist to capture the code samples. And I've included some of my commentary in code comments.

/*
Some other functions produced entirely by copilot just based on the name and context.
These are mostly correct, but buggy. For example, in the dm function, you definitely
need to put quotes around the message so it’s treated as a single token.
*/
function muteTwitterUser(user) {
return new Promise((resolve, reject) => {
$p(`t mute ${user}`).data(function (stderr, stdout) {
resolve(stdout);
});
});
}
function sendTwitterDM(user, message) {
return new Promise((resolve, reject) => {
$p(`t dm ${user} ${message}`).data(function (stderr, stdout) {
resolve(stdout);
});
});
}
/*
In other cases, you can see the limitations of copilot trying to guess context.
This is adding a user to a twitter list. Copilot doesn’t understand that you also
need to specify the list as an argument. e.g. `t list add LIST USER`
*/
function addUsersToTwitterList(users) {
return new Promise((resolve, reject) => {
$p(`t list add ${users.join(' ')}`).data(function (stderr, stdout) {
resolve(stdout);
});
});
}
/*
This is code produced by copilot in a "fresh" project. There is no
custom code. Only the basic files added by Angular. Copilot doesn't
have much context to work wtih, so it doesn't produce anything.
*/
function getTwitterUsers() {
return new Promise((resolve, reject) => {
// do something
});
}
/*
This is code sample produced entirely by copilot. This time in a project that
already has some of my own code in it. Copilot produces a full function that
also uses my custom library. And is mostly correct.
*/
function getTwitterUsers(userIds) {
return new Promise((resolve, reject) => {
const data = `user_id=${userIds.join(",")}`;
const cmd = `twurl -d "${data}" "/1.1/users/lookup.json"`;
console.log("getting users:", userIds);
console.log(cmd);
const users = $p(cmd)
// .out()
.data((err, stdout, stderr) => {
if (err) {
return reject(err);
}
try {
const users = JSON.parse(stdout);
resolve(users);
} catch (e) {
reject(e);
}
});
});
}
/*
This is a smample of code that I wrote entirely on my own. It also uses a custom
library that I wrote. The library is not popular at all and hasn't been touched
in 10 years! Copilot senses this code and produces code that looks similar.
*/
async function unfollow(followings, config) {
const batch = followings.slice(config.index, config.index + BATCH_SIZE);
const cmd = `t unfollow ${batch.join(" ")}`;
console.log("executing:", cmd);
return new Promise((resolve, reject) => {
$p(cmd)
.out()
.data((err, stdout, stderr) => {
if (err) {
return reject(err);
}
config.index = config.index + BATCH_SIZE;
console.log("writing config:", config);
fs.writeFileSync("./.unfollow-config", JSON.stringify(config));
resolve([stdout, stderr]);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment