Galaxy.ai Logo

27 ChatGPT Prompts for Writing Code (Ruby's Red Hot)

·

📖15 min read

Cover Image for 27 ChatGPT Prompts for Writing Code (Ruby's Red Hot)

ChatGPT is changing the way we code.

From creating code snippets to debugging, reviewing code, and even enhancing team discussions—its use is truly transformative.

But with so many options, it's tough to decide the starting point.

That's why this guide exists.

In this guide, using real coding situations and numerous hours spent with ChatGPT, I'll provide proven ChatGPT prompts for writing code.

Let's get started.

ChatGPT Prompts for Writing Code

Write a function in Python to reverse a string

Even seasoned coders can sometimes struggle with string manipulation.

However, with Python, you can reverse a string quite easily.

Write a function that accepts a string as an argument and returns the reversed string.

Use slicing, a Python technique for extracting parts of a sequence, to reverse the string.

ChatGPT Prompt:

As an experienced Python developer, write a function that accepts a string as an argument and returns the reversed string.

Use the slicing technique to reverse the string, and remember, your solution must be easy to understand and efficient.

Develop a Java method to find the largest number in an array

ChatGPT can help you draft a Java method that can be used to find the largest number in an array.

The method involves iterating through the array and comparing each number with a variable initially set to the smallest possible value.

The variable will be updated if a larger number is found.

ChatGPT Prompt:

Create a Java method to find the largest number in an array.

Remember to initialize a variable with the smallest possible integer value to compare each array element against.

Update this variable whenever a larger number is found during the iteration.

Create a JavaScript function to animate a webpage element

When you're stuck on how to animate a webpage element using JavaScript, ChatGPT can assist.

You can ask it to generate a JavaScript function that enables animation effects on a certain element of a webpage.

Provide the specifics such as the type of animation, the element you want to animate, and the duration.

ChatGPT Prompt:

As an experienced JavaScript developer, please write a function to animate a div element on a webpage.

The animation should make the element move from the left of the screen to the right over a span of 5 seconds.

Debug a piece of code with syntax errors

Even the most experienced programmers occasionally write code with syntax errors.

For that reason, you can ask ChatGPT to debug a piece of code with such issues.

Just feed the AI with the erroneous code snippet and ask it to identify and correct the syntax errors.

ChatGPT Prompt:

As an experienced programmer, identify and correct the syntax errors in the following piece of code:

Write a Python script to scrape data from a website

ChatGPT is a versatile tool that can assist you in understanding the logic behind web scraping code.

You can input a URL and specific elements you want to scrape, and ChatGPT can help you write a Python script using libraries like BeautifulSoup and requests.

It can even guide you on handling data parsing, making HTTP requests, and dealing with exceptions.

ChatGPT Prompt:

As a Python developer with extensive experience in web scraping, help me write a script to extract data from a website.

I want to scrape the latest news headlines from 'https://www.newswebsite.com'.

We'll be using Python's BeautifulSoup and requests libraries for this task.

Develop a simple calculator in C++

ChatGPT can assist by providing the necessary steps to develop a simple calculator in C++.

This can include instructions on setting up the environment, writing the code, and even debugging errors.

For example, you can ask ChatGPT to provide the entire code for a simple calculator or assist in writing it step by step.

ChatGPT Prompt:

Act as a skilled C++ developer and help me create a simple calculator.

The calculator should be able to perform operations like addition, subtraction, multiplication, and division.

Provide me with the necessary code and steps to follow.

Write a PHP function to connect to a database

ChatGPT can assist in writing a PHP function for connecting to a database by generating the required code.

Provide it with the necessary parameters such as server name, username, password, and database name, and it will create a function using MySQLi or PDO extension for PHP.

Here's a sample prompt to get you started:

ChatGPT Prompt:

As an experienced PHP developer, write a PHP function to connect to a MySQL database using the MySQLi extension.

The function should accept the following parameters:

- server name: localhost

- username: root

- password: password

- database name: mydatabase

Develop a REST API in Node.js

ChatGPT can assist you in developing a REST API using Node.js by providing examples and explaining the code structure.

You can supply an idea or a specific requirement, and ChatGPT will provide a relevant code snippet or explain the logic behind it.

For example, you can ask for guidance on how to create an API endpoint, or how to implement JWT authentication.

ChatGPT Prompt:

Act as an experienced software developer and guide me to develop a REST API in Node.js.

I want to create a GET endpoint that fetches user data from a MongoDB database.

How should I go about it?

Create a simple login form using HTML and CSS

Creating a simple login form with HTML and CSS can be quite straightforward.

First, use HTML to create the structure of the form, including fields for username and password.

Then, with CSS, you can style the form, adding colors, borders, and fonts.

ChatGPT Prompt:

Act as an experienced web developer tasked with creating a simple login form.

The form should include fields for the username and password, and a submit button.

Use HTML for the structure of the form, and CSS for styling it.

Here is the basic structure to get started:

Implement a binary search algorithm in C

Binary search is a quick and efficient algorithm used to find elements in a sorted list.

You can implement this in C to enhance your program's search functionality.

ChatGPT can provide step-by-step guidance on how to write this algorithm, from initializing your variables to the final loop for the search.

ChatGPT Prompt:

As an experienced programmer, write the code in C for implementing a binary search algorithm.

This will include setting up the function, initializing the necessary variables such as 'start', 'end', and 'mid', and finally the loop that carries out the binary search.

Develop a simple game in JavaScript

Use ChatGPT to get the basic structure and elements of a simple JavaScript game.

This could include setting up the game environment, creating characters and objects, and defining basic game logic.

You can ask ChatGPT for code snippets or explanations on how to implement certain features or mechanics in your game.

ChatGPT Prompt:

I am trying to create a simple game in JavaScript.

The game is a basic clicker game where a user clicks on an object to gain points.

Can you help me draft a simple outline of the code that I would need to implement?

Write a Python script for automating a task

You can use ChatGPT to help you create a Python script to automate a common task.

For instance, you might need to automate the process of reading data from a CSV file and analyzing it.

ChatGPT could suggest the necessary lines of code, including importing the required libraries, reading the CSV file, and performing basic data analysis.

ChatGPT Prompt:

Act as an experienced Python developer tasked with writing a script to automate data analysis from a CSV file.

The script should import necessary libraries, read the CSV file, and then perform basic data analysis such as finding the maximum, minimum, and average of a specific column.

Develop a Java class to model a bank account

ChatGPT can aid in generating code snippets or full classes, given a specific requirement.

For example, you can ask ChatGPT to help you develop a Java class to model a bank account, specifying methods like deposit, withdrawal, and balance check.

Remember to clarify if the bank account needs to support features like overdraft or interest calculation.

ChatGPT Prompt:

Act as an experienced Java developer tasked with creating a class to model a bank account.

The class should have methods for depositing and withdrawing money, as well as checking the current balance.

Overdraft is not allowed.

Here are some basic requirements to consider:

Create a responsive webpage using CSS flexbox

CSS Flexbox is a fantastic tool for creating responsive, mobile-first web layouts.

ChatGPT can help you understand how to implement it in your code, discussing the various properties, such as flex-direction, justify-content, align-items and flex-wrap.

Just provide your specific requirements or problems you're facing, and ChatGPT can guide you.

ChatGPT Prompt:

Act as an experienced web developer and explain how to create a responsive webpage using CSS flexbox.

I am struggling to align items evenly across the main axis and wrap the items when the space runs out.

Write a Ruby on Rails application

ChatGPT can help you write a simple Ruby on Rails application from scratch.

If you need assistance with building an application, provide a brief of the application's requirements and functionalities.

ChatGPT can generate the necessary code snippets, outline the directory structure, or guide you through the different phases of the application's development.

ChatGPT Prompt:

Act as an experienced Ruby on Rails developer and assist in building a simple blog application.

The application should have basic CRUD functionalities for posts, with title and body fields.

It should also have user authentication.

Provide a step-by-step guide to build this application.

Develop a SQL query to retrieve data from a database

Understanding how to write SQL queries allows you to retrieve specific data from a database, making it an essential skill for developers, data analysts, and anyone working with databases.

ChatGPT can help guide you in creating SQL queries, just give it the details of the data you want to retrieve.

For example, you might need to select certain fields from a table, filter records based on specific criteria, or sort the results in a certain order.

ChatGPT Prompt:

Act as an experienced database manager and help me write a SQL query.

I need to retrieve customer names and their email addresses from the 'Customers' table where the customer's city is 'New York' and sort the results by their name in ascending order.

Write a shell script for file management

Managing files efficiently is crucial when coding, and ChatGPT can assist you by writing a shell script for file management.

Just provide it with the specifics of what you require, like creating directories, moving, renaming, or deleting files.

With this information, ChatGPT can generate a script that simplifies your file management tasks, streamlining your coding process.

ChatGPT Prompt:

Act as a seasoned programmer and assist me in writing a shell script for file management.

The script should create a new directory, move certain files into this directory, rename them according to a specified pattern, and finally delete any duplicates.

Create a React component for a dashboard widget

ChatGPT can help you write clean and efficient code for your projects.

Just provide it with the details of the React component you need and it'll generate the code for you.

For instance, you might need a dashboard widget for displaying coding progress, task status, or any other data point in your project.

ChatGPT can generate a starter code or even more complex components depending on your requirement.

ChatGPT Prompt:

Create a React component for a dashboard widget that displays the progress of a coding project.

The component should include a progress bar, a list of completed tasks, and a list of pending tasks.

Write a Python function for a machine learning algorithm

To tackle complex problems in Machine Learning, you can use Python's powerful libraries like Scikit-Learn.

Let's create a Python function that trains a simple Linear Regression model.

You need to feed it with two parameters: feature and target datasets.

The function will return a trained model that can be used for further predictions.

ChatGPT Prompt:

Write a Python function using Scikit-Learn library for creating a simple Linear Regression machine learning model.

The function should accept two parameters: features dataset and target dataset.

Upon training the model with these datasets, the function should return the trained model.

Develop a C# application to interact with an API

Using ChatGPT, you can code a simple C# application to interact with an API.

To start, provide ChatGPT with the API documentation and specifics about the desired application functionality.

ChatGPT can help you write code for making API requests, processing responses, error handling and more.

ChatGPT Prompt:

Act as an experienced C# developer tasked with creating a console application that interacts with a given API.

The application should be able to make GET and POST requests, handle errors, and process API responses.

Here's the API documentation to get started:

Write a JavaScript function to handle form validation

Writing a JavaScript function for form validation can ensure that users fill out forms in the correct format.

This involves checking the inputted data for errors and inconsistencies before it is submitted.

You can utilize ChatGPT to generate an example of such a function based on certain specifications and requirements.

ChatGPT Prompt:

As an experienced software engineer, write a JavaScript function to handle form validation.

The form has the following fields: Name (required, at least 2 characters), Email (required, valid email format), and Password (required, at least 8 characters with at least one number and one special character).

Develop a Django view for a web application

ChatGPT can assist in creating a Django view for a web application.

You just have to provide the necessary information such as the name of the view, the model it’s associated with, and the actions that will be performed in the view.

ChatGPT will then generate a code snippet that corresponds to the Django view definition.

ChatGPT Prompt:

Act as an experienced Django developer tasked with writing a view for a web application.

The view's name is 'HomePageView', it's associated with the 'Post' model and it retrieves all posts sorted by the date they were created.

Please write the code for this view.

Write a Swift function for an iOS app feature

Creating a Swift function for an iOS application could simplify several tasks.

For instance, if your app needs to perform an operation multiple times, such as validating a user's password, you can use a Swift function to achieve this.

ChatGPT can help you write a Swift function based on your specifications.

Just feed it with the feature requirements, and it will generate a suitable Swift function.

ChatGPT Prompt:

Act as an experienced iOS developer.

Write a Swift function that validates if a user's password meets the following criteria: at least 8 characters long, contains at least one uppercase letter, one lowercase letter, and one number.

Create a simple chatbot using Python and AI libraries

ChatGPT can assist you in constructing a simple chatbot using Python and AI libraries.

Provide ChatGPT with your requirements and it can generate a simple Python code to create a chatbot utilizing libraries such as NLTK, Keras, or TensorFlow.

For example, it can provide you with instructions and code snippets for chatbot creation.

ChatGPT Prompt:

Act as an experienced software engineer and help me build a simple AI chatbot using Python.

The chatbot should be able to answer basic inquiries like What's your name?

and How are you?.

Which AI libraries do you recommend and can you provide a basic code structure to get started?

Develop a secure login system using PHP and MySQL

Designing a secure login system using PHP and MySQL can be a complex task, but ChatGPT can walk you through the process.

It can assist you in designing the database structure, writing PHP scripts for handling user data, and ensuring the security of the system.

For instance, it can guide you on implementing hash functions for password storage and using secure methods for session handling.

ChatGPT Prompt:

Act as an experienced software engineer to develop a secure login system using PHP and MySQL.

Detail the steps needed to design the database, write the PHP scripts, and ensure the security of the system.

Write an algorithm for sorting an array in ascending order

ChatGPT can help you in writing an algorithm for sorting an array in ascending order.

Just feed in the array elements and ask ChatGPT to provide you with the sorted array.

For instance, you can provide the array as input and ask it to sort it using a specific sorting algorithm like bubble sort or quick sort.

ChatGPT Prompt:

As an experienced programmer, write an algorithm for sorting the following array in ascending order using the bubble sort method.

The array is: [8, 5, 2, 9, 5, 6, 3].

Create a microservice architecture using Java and Spring Boot

ChatGPT can assist you in designing a microservice architecture using Java and Spring Boot.

It can provide insights on setting up individual components, integrating them, and ensuring effective communication between them.

For instance, you might ask it to outline the steps involved in creating a Spring Boot application, or how to configure and use the Eureka Server for service discovery.

ChatGPT Prompt:

Act as an experienced software engineer skilled in Java and Spring Boot.

Outline the steps to create a microservice architecture, from setting up individual microservices to ensuring smooth inter-service communication, using Spring Boot and Eureka Server.

 

Conclusion

Wow! We've traversed quite a distance.

From brainstorming code structures to fine-tuning algorithms, writing test cases, and reviewing code, ChatGPT is revolutionizing every aspect of writing code.

It’s your helping hand when you're blocked, your calculator for complex problem-solving, and your brainstorming ally for creative coding.

But keep this in mind:

ChatGPT is a powerful tool, not a substitute for your coding prowess. Combine its abilities with your own expertise to create truly impressive code.

Now it’s your time to shine.

Choose one or two prompts from this guide and experiment with them in your next coding session, project, or team meeting. You might be amazed at how much more efficient—and innovative—you become.

And if you're ready to explore even more powerful tools that surpass ChatGPT, give Galaxy.ai a look.

Housing every AI tool under one roof, it’s the ultimate productivity partner for modern coders.

Happy coding! 🚀

💡 Big on AI? Not Big on Spending?

Galaxy.ai is the world's #1 AI platform with 3000+ AI tools (everything—from chat, images, audio, video, ads) at one place for just $15/mo

💬

ChatGPT, Claude, Gemini, Grok, Llama, Perplexity, DeepSeek

🎨

Midjourney, Nano Banana, GPT-Image, Ideogram, Leonardo, Stable Diffusion, DALL·E 3, Flux

🎬

Veo 3, Sora 2, Luma, Kling, Pika, HeyGen, RunwayML, Hailuo, Minimax, WAN Animate

🎵

ElevenLabs, Lyria, Hedra, CassetteAI

🌐Works seamlessly on web, iOS, and Android

👉Join millions of creatives, businesses, and everyday people who have switched to Galaxy.ai

Try Galaxy.ai Now →