ChatGPTに関するチートシート
はじめに
今回の記事では、ChatGPTの使い方をチートシート形式で簡潔に解説する。
文章を作る
質問とそれに対する応答
日本語:〇〇について教えて
英語:"What is X like?"、あるいは"What does X means?"
Wikipediaのような記事を作成する
日本語:〇〇に関するWikipediaのような記事を作成して
英語:"Please create an article about X like Wikipedia."
Todoリストの作成
日本語:〇〇をタスク化して
英語:"Please create a task for X."
スケジュールの作成
日本語:xx~yyの間にzzをする。その間のスケジュールをmm分刻みで示して
英語:"Between xx and yy, I do zz. Show the schedule in mm minute increments during that time."
要約
日本語:「以下を要約して」と入力し、2回改行した後に要約してほしい文章を入れる。
要約した文章
『ONE PIECE』の世界を治める世界政府によって危険と見做された人物を捜索・拿捕するための足掛かりとして発行されている手配書。
作中世界において大々的に指名手配される犯罪者の大半は海賊であり、その海賊の拿捕は主に海軍の仕事なので、劇中に登場する手配書のほとんどは海軍によって発行されている(そのため海賊の手配書の右下にはほぼ必ず「MARINE」の表記がある)。しかし、指名手配されるのは海賊だけに限らず、山賊や革命軍などの世間的に悪党と見做される人物、特にその中でも一定以上の実力や知名度を持つ人物については大抵懸賞金が掛けられている。
一番上の見出しに大きく「WANTED」、その下に該当する人物の顔写真が特に大きく印刷されており、さらにその下に「DEAD OR ALIVE」(生死問わず)の一文と該当人物の名前、懸賞金額が併記されるデザインが一般的。ただし何らかの理由により一部変更される場合もある。
ちなみに、手配書に書かれる名前は「苗字or二つ名+本名」の形が基本であるようだが、ウソップは当初は「そげキング」、カティ・フラムは「フランキー」名義での手配であり、必ずしも本名での手配に限られるというわけではない様子。
また、レアケースとしてシャムとブチの様に「ニャーバン・ブラザーズ」名義で複数人での手配扱いとなる場合も有る模様。
ごく一部のキャラクターには、「WANTED」ではなく「REWARD」という表記が見られる。現在、「懸賞金10億ベリー以上」「四皇の率いる海賊団の大幹部」「ただし四皇に数えられている本人ではない」人物にのみ見られるが、その詳細や真意、条件等については不明。
また、この「懸賞金が10億ベリーを超える」か否か、特に十数億レベルの賞金が懸けられるというのは特に重要な要素であるらしく、ルフィは懸賞金が15億ベリーに跳ね上がったことで四皇に並ぶ大海賊として認められるようになった。
ちなみに本来「WANTED」は「指名手配」を指し、「REWARD」は「報酬」などを指す言葉である。
手配書が発行されること、そして懸賞金額が設定されることは、海賊としての名が上がって来た事の証明となるため、(主人公のルフィの様に)人物によっては自分が手配されることを好意的に受け止める場合も多い。中には自分の手配書を持ち歩き、あえて自分の危険性を見せつけて横暴に振る舞ったり、自分の手配書を自分で偽造し、虚勢の懸賞金額で相手を威圧するという面倒な人物もいる。一方でより高い実力を持つ海軍の将校や賞金稼ぎなどに狙われる危険性も高まるため、懸賞金額が高くなるほど強い危機感を覚える者もいる。
英語:"Summarize follow sentences."と入力する。後の手順は日本語の場合と同様に行う。
箇条書きを文章化する
日本語:「以下を文章化して」と入力し、2回改行して箇条書きを入れる
英語:"Convert the following bullet points into sentences."と入力する。あとは、日本語の場合と同じ。
英語の場合、リストに副詞を入れるようになっている。(理由は不明)
文章をタスク化する
日本語:「以下をタスク化して」と入力し、2回改行して文章を入れる。
英語:"Convert the following sentences into some tasks."と入力。2回改行して文章を入れる。
ブログ記事のタイトルを出力する
日本語:〇〇に関するブログ記事のタイトルを教えて
英語:"Tell me some example titles of blog post about X."
プログラミング関連
サンプルコードの出力
サンプルコードを出力する方法は数多くあるので、本記事では一例のみを取り上げる。
日本語:Pythonでデコレータのプログラムを表示して
表示された内容
デコレータとは、Pythonの「関数」を「拡張」する仕組みです。デコレータを使用すると、関数に新しい機能を追加したり、既存の機能を変更することができます。
デコレータは、@文法を使用して定義されます。以下は、簡単なデコレータを使用した例です。
@decorator_name
def some_function():
pass
上記の例では、デコレータ名decorator_name
を@記号と一緒に定義しています。このデコレータは、some_function
という名前の関数を「拡張」します。
デコレータを定義するには、以下の構文を使用します。
def decorator_name(func):
def wrapper():
# 具体的な処理を記述
pass
return wrapper
上記の構文では、デコレータ名がdecorator_name
であり、引数として関数を受け取ることを示しています。この関数は、デコレータが「拡張」する元の「関数」を表します。
デコレータは、内部で新しい「ラッパー関数」を定義し、その関数を返します。ラッパー関数は、デコレータが「拡張」する関数を「包括」する役割を果たします。
以下は、デコレータを使用した例です。
# デコレータを定義
def decorator_name(func):
def wrapper():
print("関数が実行されました")
func()
return wrapper
# デコレータを使用
@decorator_name
def some_function():
print("some_functionが実行されました")
# 関数を実行
some_function()
# 実行結果:
# 関数が実行されました
# some_functionが実行されました
英語:"Show me sample code in JavaScript."
表示された内容
Sure, here is an example of a simple JavaScript program that prints "Hello, World!" to the console:
console.log("Hello, World!");
This code uses the console.log
function to print a string to the console. The console
is a global object in JavaScript that provides access to various built-in methods for logging information, such as console.log
for printing messages.
To run this code, you would need to save it to a file with a .js
extension and then run it using a JavaScript runtime environment, such as Node.js. Here is how you would run this code using Node.js from the command line:
$ node my-javascript-program.js
This will execute the code and print "Hello, World!" to the console.
Here is another example that shows how to define and call a function in JavaScript:
// Define a function named "add" that takes two arguments and returns their sum
function add(a, b) {
return a + b;
}
// Call the "add" function with two arguments, 1 and 2, and print the result to the console
console.log(add(1, 2)); // prints 3 to the console
In this code, we define a function named add
that takes two arguments, a
and b
, and returns their sum. We then call this function and pass it the arguments 1 and 2, and print the result to the console using console.log
.
I hope these examples help to give you a better understanding of how JavaScript code works! Let me know if you have any other questions.
コードのドキュメント生成
一例を紹介する。
日本語:「以下のコードのドキュメントをJSDoc形式で出力して」と入力した後、2回改行して該当のコードを貼り付ける。ただし、該当のコードを出力する際に三重の`
で囲うのを忘れないようにする。
表示された内容
以下がJSDocs形式で出力されるドキュメントになります。
/**
* 人間のクラス。
* @class Person
*
* @property {string} name - 名前。
*
* @constructor
* @param {string} name - 名前。
*/
class Person {
constructor(name) {
this.name = name;
}
}
/**
* 社員のクラス。
* @class Employee
* @extends Person
*
* @property {number} empCode - 社員番号。
*
* @constructor
* @param {number} empCode - 社員番号。
* @param {string} name - 名前。
*/
class Employee extends Person {
constructor(empCode, name) {
super(name);
this.empCode = empCode;
}
/**
* 名前を表示する。
*
* @method
*/
displayName() {
console.log("Name = " + this.name + ", Employee Code = " + this.empCode);
}
}
const emp = new Employee(100, "Bill");
emp.displayName(); // Name = Bill, Employee Code = 100
英語:"Output the documentation for the code below in JSDoc format."と入力。後の手順は日本語と同じ。
表示された内容
/**
* Displays the names in the provided array
*
* @template T
* @param {T[]} names - The array of names to display
* @returns {void}
*/
function displayNames<T>(names: T[]): void {
console.log(names.join(", "));
}
To use this function, you can call it like this:
displayNames<string>(["Steve", "Bill"]); // Steve, Bill
The <string>
part is specifying the type of the elements in the names
array, which in this case are strings. This is called a type parameter, and it allows the function to be flexible and work with different types of data. You can use any valid type in place of string
, such as number
or a custom type.
コードの引用:TypeScript Generics
リファクタリング
日本語:「以下のコードをリファクタリングして」と入力し、2回改行した後に該当のコードを貼り付ける。
表示された内容
以下のようにリファクタリングできます。
abstract class Department {
constructor(public name: string) {}
printName(): void {
console.log(`Department name: ${this.name}`);
}
}
interface ReportingDepartment {
generateReports(): void;
}
class AccountingDepartment extends Department implements ReportingDepartment {
constructor() {
super("Accounting and Auditing");
}
printMeeting(): void {
console.log("The Accounting Department meets each Monday at 10 a.m");
}
generateReports(): void {
console.log("Generating accounting reports...");
}
}
以下の点を変更しました。
* `Department`クラスの`printName`メソッド内で文字列を連結する際に、文字列リテラルを使用するようにしました。
* `Department`クラスの`name`プロパティには、デフォルトで public が付与されるため、修飾子を省略するようにしました。
* `ReportingDepartment`インターフェースの `generateReports`メソッドには、デフォルトで`public`が付与されるため、修飾子を省略するようにしました。
英語:"Refactor the following code."と入力する。後の手順は日本語と同じ。
表示された内容
Here is one possible refactoring of the code:
class Department {
constructor(public name: string) {
}
printName(): void {
console.log("Department name: " + this.name);
}
}
interface ReportingDepartment {
generateReports(): void
}
class AccountingDepartment extends Department implements ReportingDepartment {
constructor(name = "Accounting and Auditing") {
super(name);
}
printMeeting(): void {
console.log("The Accounting Department meets each Monday at 10 a.m");
}
generateReports(): void {
console.log("Generating accounting reports...");
}
}
In this refactoring, I removed the abstract keyword from the Department class because it is not used in the code. I also changed the AccountingDepartment constructor to include a default value for the name parameter, which allows you to instantiate the class without providing a value for that parameter. This is a common way to make code more concise and easier to use.
データベースの設計
日本語:〇〇に必要なtable一覧を表示して
英語:"Display the table list required for X."
データベースの操作
一例を示す。
日本語:〇〇で△△するにはどうすればいいのだろうか?
英語:"How do I make data models in MongoDB?"
表示された内容
To create a data model in MongoDB, you will first need to create a MongoDB database and collection. To do this, you can use the use
and db.createCollection()
commands in the MongoDB shell. For example, to create a database named "my_database" and a collection named "my_collection", you could use the following commands:
use my_database
db.createCollection("my_collection")
Once you have a database and collection, you can insert documents into the collection using the db.my_collection.insert()
command. A document is a record in a MongoDB collection and is equivalent to a row in a relational database table. Documents are composed of field-value pairs, similar to a JSON object. Here is an example of inserting a document into the "my_collection" collection:
db.my_collection.insert({
name: "John Doe",
age: 35,
city: "New York"
})
After inserting some documents into your collection, you can use the db.my_collection.find()
command to query the collection and retrieve the documents. This will return all documents in the collection, unless you specify a filter to narrow down the results. For example, you could use the following command to find all documents with an "age" field greater than 30:
db.my_collection.find({ age: { $gt: 30 } })
These are just some basic examples of how to create data models in MongoDB. For more information, I recommend reading the MongoDB documentation, which provides detailed information and tutorials on working with MongoDB.
参考サイト
参考動画
Discussion