{"id":15157,"date":"2025-06-04T14:26:07","date_gmt":"2025-06-04T19:26:07","guid":{"rendered":"https:\/\/ericsiegmund.com\/fireant\/?p=15157"},"modified":"2025-06-04T14:26:10","modified_gmt":"2025-06-04T19:26:10","slug":"coding-with-ai","status":"publish","type":"post","link":"https:\/\/ericsiegmund.com\/fireant\/2025\/06\/04\/coding-with-ai\/","title":{"rendered":"Coding with AI"},"content":{"rendered":"\n<p>It&#8217;s been a couple of weeks (plus) since I posted anything, and <a href=\"https:\/\/ericsiegmund.com\/fireant\/2025\/05\/16\/just-another-manic-memeday\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Nothing but memes\">the last thing I posted<\/a> was just a series of things I <s>borrowed<\/s> stole from other people. Frankly, it&#8217;s been a miserable month, health-wise, but things have improved vastly &#8212; almost miraculously, in fact &#8212; in just the past couple of days, and I&#8217;m happy to bang away at the keyboard.<\/p>\n\n\n\n<p>Speaking of keyboards&#8230;the header photo merits a brief explanation. We spent a few days in Key West, Florida, and visited the <a href=\"https:\/\/www.hemingwayhome.com\" target=\"_blank\" rel=\"noreferrer noopener\">Hemingway Home &amp; Museum<\/a>. One of the exhibits was a recreation of Ernest Hemingway&#8217;s office, and his Underwood typewriter was on display. We weren&#8217;t allowed inside the office and the typewriter was behind glass across the room, but I couldn&#8217;t resist getting a photo (and then messing with it).<\/p>\n\n\n\n<p>So, this post is pretty geeky and if you have no interest in AI-related material, feel free to skip it. OTOH, if you&#8217;re skeptical about whether ChatGPT and similar chatbots have any practical use beyond helping college students cheat on their essays, I can offer some evidence to the contrary.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Some of you may recall that I did a decade-long stint as a freelance website designer\/developer between assignments as a corporate drone. If you&#8217;re not sure of the difference between designer and developer, think about how an architect and a builder work together to construct a house. The architect should have at least a working knowledge of building materials but he or she doesn&#8217;t need to actually know how to use a mitre saw or a nail gun; the builder&#8217;s crew will handle that work. <\/p>\n\n\n\n<p>As a freelancer, I didn&#8217;t have the luxury of handing off my website designs to a skilled coder to make those designs work. I needed proficiency in the basic building blocks of websites, which at the time &#8212; late Nineties\/early Oughts &#8212; consisted of HTML, <acronym title=\"Cascading Style Sheet\">CSS<\/acronym>, and Javascript.<\/p>\n\n\n\n<p>I was pretty adept at the first two; much less so with Javascript, despite taking an online course. I could troubleshoot an existing Javascript, and if I found one that generally met my needs, I could tweak it to improve its usefulness. But I was incapable of coding one from scratch, and didn&#8217;t have the time or patience to gain that skill. That was part of the reason that I decided to move from web work as a fulltime position. (The main reason was that I was wearied from working long hours for less than minimum wage, even though I was having a lot of fun with the work itself.)<\/p>\n\n\n\n<p>I still enjoy working with websites, and this blog provides plenty of opportunities to exercise what HTML- and CSS-related skills I&#8217;ve retained. But I&#8217;m still deficient in the area of scripting, and I intend to remain that way because I now have an expert coder on my team, and it works for free. I&#8217;m referring to <a href=\"https:\/\/chatgpt.com\" target=\"_blank\" rel=\"noreferrer noopener\">ChatGPT<\/a>.<\/p>\n\n\n\n<p>Up to now, my interactions with ChatGPT and other AI models have been limited to generating images and posing questions that search engines such as Google couldn&#8217;t handle. But as AI has gotten more adept at coding, and as that capability is now readily available to non-professional users like me, I find the possibilities intriguing.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">My test case: A photo &#8220;slider&#8221;<\/h4>\n\n\n\n<p>One of my favorite applications for the Gazette is the use of a &#8220;slider&#8221; to show before-and-after images of the same scene, or some variation thereof. Years ago, I found a preprogrammed slider script and I used it to compare a famous painting by Georges Seurat with an ad for which characters from <em>The Office<\/em> were inserted into Seurat&#8217;s layout. You can see the result <a href=\"https:\/\/ericsiegmund.com\/fireant\/2011\/05\/17\/110517-seuratvstheoffice\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>That slider works perfectly well, but it relies on a third-party library over which I have no control, meaning that it could disappear at any time. It also automatically places a watermark &#8212; seen in the lower right corner of the images &#8212; and I&#8217;m not crazy about that.<\/p>\n\n\n\n<p>After reading an article in the <em>Wall Street Journal<\/em> about using the free version of ChatGPT to generate computer code, I decided to give it a whirl. Here&#8217;s the prompt I used to kick off the project:<\/p>\n\n\n\n<p class=\"quote\">Hello again. I need some help with script coding. I\u2019m looking for a dynamic HTML script (Javascript, CSS, and HTML) that creates a slider on top of a photo that can be dragged to reveal (or conceal) another photo. I would use it as a \u201cbefore and after\u201d application in my blog, so it needs to be a self-contained script that I can drop into a post. Does that make sense, and can you create such a script?<\/p>\n\n\n\n<p>ChatGPT responded immediately&#8230;<\/p>\n\n\n\n<p class=\"quote\">Hello again! Yes, that makes perfect sense, and it\u2019s a great feature for a blog \u2014 especially to show before-and-after images interactively. Below is a self-contained HTML + CSS + JavaScript script that you can drop directly into your blog post. It creates a before\/after image comparison slider that works without any external libraries.<\/p>\n\n\n\n<p>It also provided the script in its entirety &#8212; HTML, CSS, and Javascript &#8212; in a format that I could copy and paste into any blog post. It provided documentation for updating the options to change how the slider worked, depending on the format of the images and whether I wanted the slider to be vertical or horizontal.<\/p>\n\n\n\n<p>The first pass was close to what I was looking for, but not exact, so I provided ChatGPT with more precise instructions. It took a couple of iterations but I finally ended up with what I wanted. I especially like the addition of the labels. Try it out here (drag the yellow line back and forth): <\/p>\n\n\n\n<div style=\"max-width: 640px; margin: auto; position: relative; border: 1px solid black;\">\n  <div class=\"img-compare-container horizontal\">\n    <img decoding=\"async\" src=\"https:\/\/www.ericsiegmund.com\/fireant\/images\/miscphotos2\/landscape20250315.jpg\" alt=\"3\/15\/2025\" class=\"img-compare bottom\">\n    <div class=\"img-compare-overlay\">\n      <img decoding=\"async\" src=\"https:\/\/www.ericsiegmund.com\/fireant\/images\/miscphotos2\/landscape20240315.jpg\" alt=\"3\/15\/2024\" class=\"img-compare top\">\n    <\/div>\n    <div class=\"slider-handle\"><\/div>\n    <div class=\"label before-label\">Before: March 15, 2024<\/div>\n    <div class=\"label after-label\">After: March 15, 2025<\/div>\n  <\/div>\n<\/div>\n<style>\n  .img-compare-container {\n    position: relative;\n    overflow: hidden;\n    width: 100%;\n    aspect-ratio: 3 \/ 2;\n    \n  }\n\n  .img-compare {\n    width: 100%;\n    height: 100%;\n    object-fit: cover;\n    pointer-events: none;\n    user-select: none;\n  }\n\n  .img-compare-overlay {\n    position: absolute;\n    top: 0;\n    left: 0;\n    overflow: hidden;\n    height: 100%;\n  }\n\n  .img-compare-container.horizontal .img-compare-overlay {\n    width: 95%; \/* Initial state *\/\n  }\n\n  .slider-handle {\n    position: absolute;\n    top: 0;\n    left: 95%;\n    width: 8px;\n    height: 100%;\n    background-color: yellow;\n    border-left: 2px solid #000;\n    border-right: 2px solid #000;\n    cursor: ew-resize;\n    z-index: 10;\n  }\n\n  .label {\n    position: absolute;\n    color: white;\n    font-weight: bold;\n    font-family: sans-serif;\n    padding: 4px 8px;\n    background: rgba(0, 0, 0, 0.5);\n    border-radius: 4px;\n    z-index: 20;\n    font-size: 0.9rem;\n    transition: opacity 0.2s ease;\n  }\n\n  .before-label {\n    top: 10px;\n    left: 10px;\n    opacity: 1;\n  }\n\n  .after-label {\n    bottom: 10px;\n    right: 10px;\n    opacity: 0;\n  }\n<\/style>\n<script>\n  (function() {\n    document.querySelectorAll('.img-compare-container').forEach(container => {\n      const overlay = container.querySelector('.img-compare-overlay');\n      const isVertical = container.classList.contains('vertical');\n      const handle = container.querySelector(isVertical ? '.slider-handle-vertical' : '.slider-handle');\n      const beforeLabel = container.querySelector('.before-label');\n      const afterLabel = container.querySelector('.after-label');\n\n      let isDown = false;\n\n      const slide = (x, y) => {\n        const rect = container.getBoundingClientRect();\n        let percent;\n\n        if (isVertical) {\n          let offsetY = y - rect.top;\n          offsetY = Math.max(0, Math.min(offsetY, rect.height));\n          percent = offsetY \/ rect.height;\n          overlay.style.height = offsetY + \"px\";\n          handle.style.top = offsetY + \"px\";\n        } else {\n          let offsetX = x - rect.left;\n          offsetX = Math.max(0, Math.min(offsetX, rect.width));\n          percent = offsetX \/ rect.width;\n          overlay.style.width = offsetX + \"px\";\n          handle.style.left = offsetX + \"px\";\n        }\n\n        \/\/ Toggle label visibility\n        if (percent < 0.35) {\n          beforeLabel.style.opacity = 0;\n          afterLabel.style.opacity = 1;\n        } else {\n          beforeLabel.style.opacity = 1;\n          afterLabel.style.opacity = 0;\n        }\n      };\n\n      const startSlide = (e) => {\n        isDown = true;\n        const touch = e.touches ? e.touches[0] : e;\n        slide(touch.pageX, touch.pageY);\n      };\n\n      const moveSlide = (e) => {\n        if (!isDown) return;\n        const touch = e.touches ? e.touches[0] : e;\n        slide(touch.pageX, touch.pageY);\n      };\n\n      const endSlide = () => {\n        isDown = false;\n      };\n\n      handle.addEventListener('mousedown', startSlide);\n      window.addEventListener('mousemove', moveSlide);\n      window.addEventListener('mouseup', endSlide);\n\n      handle.addEventListener('touchstart', startSlide);\n      window.addEventListener('touchmove', moveSlide);\n      window.addEventListener('touchend', endSlide);\n    });\n  })();\n<\/script>\n\n\n\n<p>The script allows me to customize (or eliminate) the labels and specify when they appear\/disappear. I can also change the look of the slider bar and its initial position.<\/p>\n\n\n\n<p>The interaction with the chatbot was interesting. ChatGPT actually suggested the before and after labels; I hadn&#8217;t thought about that feature. It had a couple of other suggestions that I didn&#8217;t use, but the process reinforced the feeling that it was a collaborative effort.<\/p>\n\n\n\n<p>I don&#8217;t have any additional needs for coding assistance at this time, but it&#8217;s nice to know that the resource is available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I asked ChatGPT to help me with a computer coding issue, and the results were impressive.<\/p>\n","protected":false},"author":1,"featured_media":15191,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[388,18],"tags":[148,509,506],"class_list":["post-15157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-2","category-technology","tag-chatgpt","tag-coding","tag-javascript","entry"],"jetpack_featured_media_url":"https:\/\/ericsiegmund.com\/fireant\/wp-content\/uploads\/2025\/06\/header_underwoodtypewriter.jpg","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/posts\/15157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/comments?post=15157"}],"version-history":[{"count":47,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/posts\/15157\/revisions"}],"predecessor-version":[{"id":15208,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/posts\/15157\/revisions\/15208"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/media\/15191"}],"wp:attachment":[{"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/media?parent=15157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/categories?post=15157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ericsiegmund.com\/fireant\/wp-json\/wp\/v2\/tags?post=15157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}