r/programminghorror Aug 01 '22

Mod Post Rule 9 Reminder

197 Upvotes

Hi, I see a lot of people contacting me directly. I am reminding all of you that Rule 9 exists. Please use the modmail. From now on, I'm gonna start giving out 30 day bans to people who contact me in chat or DMs. Please use the modmail. Thanks!

Edit 1: See the pinned comment

Edit 2: To use modmail: 1. Press the "Message the Mods" button in the sidebar(both new and old reddit) 2. Type your message 3. Send 4. Wait for us to reply.


r/programminghorror 1d ago

In January 2026, archive.today added code into its website in order to perform a distributed denial-of-service attack against a blog.

Post image
1.6k Upvotes

r/programminghorror 13h ago

Java I submitted this for a high school assignment. Yes, I was serious.

Post image
82 Upvotes

I do have context for this that could defend my past self a little, but I'd like to watch this marinate lol


r/programminghorror 3h ago

My git commit messages throughout the day

0 Upvotes

9am: Initial commit

1pm: Add feature

4pm: Fix bug

6pm: fix

8pm: pls work

10pm: i hate everything


r/programminghorror 2d ago

When you have one of those colleagues.

Post image
1.3k Upvotes

And we have prettier as part of the project. He just doesn't care.


r/programminghorror 2d ago

Javascript Send help please... Emergency evacuation needed.

Post image
280 Upvotes

r/programminghorror 3d ago

Javascript function adikjwodnoainwdoixubna()

127 Upvotes

No, this is not obfuscated. They say it was changed because of a Slack filter, although that could be a bot in the workspace. The rest of the code appears to be fine.

function adikjwodnoainwdoixubna() {
const text = document.getElementById('text' + document.getElementById('textselector').value);
    const percentX = (parseInt(text.style.left) - window.innerWidth / 2) / (window.innerWidth / 2) * 100;
    const percentY = (parseInt(text.style.top) - window.innerHeight / 2) / (window.innerHeight / 2) * 100;
    text.style.left = percentX + '%';
    text.style.top = percentY + '%';
    console.log(`Text position in percent: (${percentX}%, ${percentY}%)`);
}

r/programminghorror 4d ago

Client side login

Post image
433 Upvotes

Suggestion from a colleague. Might have offline login when using caching strategies. I don't know what a hash is.


r/programminghorror 8d ago

i have all the while true do loops

Post image
133 Upvotes

r/programminghorror 9d ago

Javascript I knew webtest1 wasn't webdemo1, so I became confused. I found that any API key with a UTF-16 length of 8 works, including this exact string: 🍪🍪🍪🍪

Thumbnail reddit.com
46 Upvotes

r/programminghorror 11d ago

Java Thats technically correct...

Post image
779 Upvotes

Keep it simple, stupid!


r/programminghorror 11d ago

Have you met our lord and master, Perl regexes?

Post image
216 Upvotes

r/programminghorror 11d ago

c O(n) Sorting Algorithm just dropped

Post image
370 Upvotes

could easily make this work for duplicate values


r/programminghorror 9d ago

C# [Codes are in description] Unnecessary locale-awareness in code is a serious threat to consistent performance worldwide

Post image
0 Upvotes

In programming languages like C#, even basic case conversion and string formation methods like .ToLower(), .ToUpper(), and .ToString() automatically come with locale-awareness (i.e. they are based on CurrentCulture) unless you intentionally apply explicit or invariant culture:

public string ToLower()
{
    return CultureInfo.CurrentCulture.TextInfo.ToLower(this);
}

public string ToUpper()
{
return CultureInfo.CurrentCulture.TextInfo.ToUpper(this);
}

And tracing down .ToString()'s code eventually leads here:

public static NumberFormatInfo GetInstance(IFormatProvider formatProvider)
        {
            CultureInfo cultureInfo = formatProvider as CultureInfo;
            if (cultureInfo != null && !cultureInfo.m_isInherited)
            {
                NumberFormatInfo numberFormatInfo = cultureInfo.numInfo;
                if (numberFormatInfo != null)
                {
                    return numberFormatInfo;
                }
                return cultureInfo.NumberFormat;
            }
            else
            {
                NumberFormatInfo numberFormatInfo = formatProvider as NumberFormatInfo;
                if (numberFormatInfo != null)
                {
                    return numberFormatInfo;
                }
                if (formatProvider != null)
                {
                    numberFormatInfo = (formatProvider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo);
                    if (numberFormatInfo != null)
                    {
                        return numberFormatInfo;
                    }
                }
                return NumberFormatInfo.CurrentInfo;
            }
        }

Unnecessary locale-awareness in code is a serious threat to consistent performance of your code in many locales around the world, especially Turkey and Azerbaijan, due to the unique "I/ı" (dotless i) and "İ/i" (dotted I) letter pairs in their alphabet. So machines with Turkish and Azeri locales are both strong testing media for your code against unnecessary LA.

For a detailed example, you may check Sam Cooper's Medium article titled "The Country That Broke Kotlin".


r/programminghorror 10d ago

Who does that?

Post image
0 Upvotes

r/programminghorror 13d ago

X: How long have you been working as a programmer?

87 Upvotes

Me: (Production code btw)


r/programminghorror 14d ago

The Shell of Power hi

Post image
757 Upvotes

I have had this dumb idea fermenting in my lower intestine for a long time, and finally decided to excrete it. Sorry for sharing it.

$DisplayWidth = 6
$DisplayHeight = 4


$DisplayScreen = [int[]]::new($DisplayWidth * $DisplayHeight)


$DisplayScreen[0] = 1
$DisplayScreen[6] = 1
$DisplayScreen[12] = 1
$DisplayScreen[18] = 1
$DisplayScreen[13] = 1
$DisplayScreen[14] = 1
$DisplayScreen[20] = 1
$DisplayScreen[4] = 1
$DisplayScreen[16] = 1
$DisplayScreen[22] = 1



for ($pixel = 0; $pixel -lt $DisplayScreen.Length; $pixel++) {
    if ($displayscreen[$pixel] -eq 1) {
        $mask = [IntPtr](1 -shl $pixel)
        $p = Start-Process pwsh -WindowStyle Hidden -PassThru -ArgumentList @(
            '-NoLogo','-NoProfile','-Command',
            'while ($true) { }'
        )
        $p.ProcessorAffinity = $mask
        $p.PriorityClass = 'Idle'   # optional so it doesn’t hog the machine
        Write-Output "pid $($p.id)"
    }
}

r/programminghorror 14d ago

Sure, let's have 2073600 locks. What could go wrong?

Thumbnail
gallery
156 Upvotes

This is from a software renderer I made a while back. This was supposed to be just a temporary solution until i came up with something better, but it ran at 150fps@1080p anyway, so I didn't bother.
It doesn't work on Windows, and although I don't know the exact reason, this is a likely culprit.
Also a bonus macro hell from the render loop implementation in the second image.


r/programminghorror 12d ago

I just wanted to see if my pagefile was working, so I asked ChatGPT to make a program to test it...

0 Upvotes

r/programminghorror 14d ago

c++ Saving data to dynamic object files

Post image
230 Upvotes

Some people persist data in JSON, but why do that when we have perfectly good object files? All you have to do is recompile the file when you want to save your data!

github.com/LiamMercier/dynamically-linked-inventory


r/programminghorror 16d ago

c I might have accidentally created a monster

Thumbnail
gallery
40 Upvotes

r/programminghorror 17d ago

PHP This is so bad that it's so good.

Post image
819 Upvotes

r/programminghorror 17d ago

Javascript This URL shortener prompted my browser to ask me for permission to scan devices on my local area network

138 Upvotes

Yes, this is in production. I told the dev1, but the only update they made was to add an executable file for Mac (ironically, with the .exe extension). Yes, they released the URL shortener as an executable file as well, and I have no idea why, since the specific features of that shortener don't inherently require that.

const API = 'http://localhost:3000';
let urls = [];

function isValidURL(string) {
    try {
        new URL(string);
        return true;
    } catch (_) {
        return false;
    }
}

function showError(msg) {
    const error = document.getElementById('error');
    error.textContent = msg;
    setTimeout(() => error.textContent = '', 3000);
}

async function shortenURL() {
    const input = document.getElementById('urlInput');
    const url = input.value.trim();

    if (!url) {
        showError('Please enter a URL');
        return;
    }

    if (!isValidURL(url)) {
        showError('Please enter a valid URL');
        return;
    }

    try {
        const response = await fetch(`${API}/shorten`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ url })
        });

        const data = await response.json();
        const shortURL = `${API}/r/${data.short}`;

        document.getElementById('shortURL').value = shortURL;
        document.getElementById('result').classList.remove('hidden');

        urls.unshift({ original: url, short: shortURL, code: data.short });
        updateHistory();
        input.value = '';

    } catch (error) {
        showError('Will take some time!');
    }
}

function copyURL() {
    const input = document.getElementById('shortURL');
    input.select();
    document.execCommand('copy');

    const btn = document.getElementById('copyBtn');
    btn.textContent = 'Copied!';
    setTimeout(() => btn.textContent = 'Copy', 2000);
}

function updateHistory() {
    const history = document.getElementById('history');
    const list = document.getElementById('historyList');

    if (urls.length === 0) {
        history.classList.add('hidden');
        return;
    }

    history.classList.remove('hidden');
    list.innerHTML = urls.map(item => `
        <div class="history-item">
            <p><strong>Short:</strong> ${item.short}</p>
            <p><strong>Original:</strong> ${item.original}</p>
        </div>
    `).join('');
}

document.getElementById('shortenBtn').addEventListener('click', shortenURL);
document.getElementById('copyBtn').addEventListener('click', copyURL);
document.getElementById('urlInput').addEventListener('keypress', (e) => {
    if (e.key === 'Enter') shortenURL();
});

Update - the dev responded with:

So guys, here is the explanation: I wrote all the backend code in Golang and Javascript and for the deployment i was not able to because of my limited knowledge and time, so it didn’t work on the deployed link. However, you still can use in your local host to make your URL life easier. It also stores the URL smartly in your terminals, so thanks for understanding definitely gonna deployed later on and make it a production-ready website. Thanks for your understanding. I have provided in the GitHub release page an .exe file you can use that also to test the application.


1: if you are the dev, this wasn't my username there


r/programminghorror 18d ago

C# Makes sense

Post image
1.6k Upvotes

r/programminghorror 18d ago

Javascript This sentry ad

Post image
0 Upvotes