Unlock the Power of ChatGPT – A Short Guide For Enhancing Your Code

ChatGPT is a new AI service offered by OpenAI. Practically, ChatGPT is a chat where you can communicate with the AI. Is much more powerful than any other AI language model(🤖).  It can answer most questions using the information in its knowledge database.  If you didn’t test it yet, you could check it.

I started using ChatGPT for my daily tasks. It is so smart. It’s like a personal assistant that can solve anything. I give him some specifications, and it can give me what I need in a matter of seconds.

Currently, ChatGPT is free, but it also has a subscription at $42. You can also use the API that, for code, the AI generator tool is currently free. Also, you can buy tokens. One thousand Davinci tokens cost two cents. You can generate around 750 words using 1000 tokens.  The Davinci model is the most expensive base model, but you can use alternatives cheaper than it.

How to use ChatGPT as a programmer

You can use ChatGPT for almost everything. ChatGPT is using the Codex Model(code-davinci-002 or code-cushman) for code generation. You can check the OpenAI playground and use these models for free (currently in BETA).

The Codex model can be used for many programming languages, including Python, JavaScript, SQL, PHP, GO, and many more.

In my opinion, ChatGPT can be a suitable replacement for most searches on StackOverflow. Below are examples of using AI in your day-to-day programming job.

ChatGPT can fix your errors for you


ChatGPT shows how to fix the OverflowException

Create and Improve SQL scripts using ChatGPT

You can improve your current SQL scripts by asking ChatGPT:

ChatGPT improving a SQL Procedure

Write JavaScript functions

As a backend developer, I am not proficient in JavaScript. So, I started using the Codex model to get small JavaScript functions for different tasks quickly.

ChatGPT writing a JavaScript function that remove accents of a text

For any JavaScript function, I ask ChatGPT first. StackOverflow will not die because there are still specific situations where ChatGPT cannot give a good answer. Also, the models have information until 2021. So a client library that appeared after this year is unknown for ChatGPT.

Convert jQuery into Vanilla JavaScript

After I tried some queries, I wondered if ChatGPT could convert my jQuery code into Vanilla JavaScript. The answer is YES. It does such a great job with the conversion.

// jQuerry
function ConvertAjax() {
        var text = $("#Diacritics").val();
        if (!isNullOrWhitespace(text)) {
                type: 'POST',
                data: JSON.stringify({ text: text }),
                contentType: 'application/json'
                .done(function (data) {
                .fail(function (error) {

// Vanilla JavaScript
function ConvertAjax() {
    var text = document.getElementById("Diacritics").value;
    if (!isNullOrWhitespace(text)) {
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "", true);
        xhr.setRequestHeader("Content-Type", "application/json");
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var data = JSON.parse(xhr.responseText);
                document.getElementById("Text").value = data;
            } else if (xhr.readyState === 4) {
                document.getElementById("Text").value = "Error";
        xhr.send(JSON.stringify({ text: text }));

Using the OpenAI service, you can convert all jQuery code into JavaScript. In this way, you can improve the performance of your website. You will not need to include the jQuery library so that the client will make fewer requests.  Using this trick, I improve the page speed of my websites from 76 to 99 on mobile devices.

This is just an example. You can convert code from one programming language to another or even from a library.

Generating Dummy Data

ChatGPT helps generate mockups and dummy data for your needs. If you have a table or a class, you can ask the AI to generate some inserts.

ChatGPT generating insert with dummy data
It doesn’t matter if you need the data for your Excel file. Just show the ChatGPT what you want, give some examples, and take a step back. This AI is so powerful (😈).

Generating Regex

You can use the OpenAI Codex service or ChatGPT for generating Regular Expressions.
ChatGPT provide the Regex for validating an email

HTML and CSS Generation

If you are like me, a person that doesn’t master HTML and CSS, I highly recommend you use Codex to generate what you need. Look, for example, how easy it was to generate a mobile-friendly form for 3 fields:

ChatGPT Generating HTML and CSS

You can use it to generate different layouts, elements, and controls like:

  • Navbar
  • Cards
  • Carousel
  • Many other controls

If you use a library like Bootstrap, you can specify that you want to generate these elements using the library.

Conclusion about ChatGPT and OpenAI services

ChatGPT is still in beta and doesn’t always give the best answer, but it’s a powerful tool that any programmer should use. Don’t expect to solve anything with OpenAI services, but it will help you so much.

Be careful when you use ChatGPT. Not every time you will receive a good answer.

I only gave you some ideas for using ChatGPT to enhance your code and productivity. If you want to see more ways how ChatGPT can leverage your productivity in programming, check this video of Mosh Hamedani:

Leave a Comment