Live data from Hacker News

Ask HN: What's your "it's not stupid if it works" story?

news.ycombinator.com

71–80 of 510 posts

Re: Ask HN: What's your "it's not stupid if it works" story?

#71
post #60
post #31

Launching a headless browser just to generate some PDFs. Turns out, if you want to turn html+css into pdfs quickly, doing via a browser engine is a "works really well" story.

I wrote a Python package [1] that does something similar! It allows the generation of images from HTML+CSS strings or files (or even other files like SVGs) and could probably handle PDF generation too. It uses the headless version of Chrome/Chromium or Edge behind the scenes. Writing this package made me realize that even big projects (such as Chromium) sometimes have features that just don't work. Edge headless woul…

Yeah it's the same concept, instead of .screenshot you do .pdf in pupetteer.

But with pdfs the money is on getting those headers and footers consistent and on every page, so you do need some handcrafted html and print styling for that (hint: the answer is tables).

Re: Ask HN: What's your "it's not stupid if it works" story?

#72
My favorite one is probably when I was working at a retail Forex where consumers would try to make money on currencies. There were a lot of support calls where they disputed the price they saw and the price their order was entered. My solution was to log the price when they click the trade button. The interesting bit wasn't that I logged the currency pair and price, instead I did a tree walk of all the Java Swing GUI elements in the open trade window and render them into the log file as ASCII using "(o)" for options, "[x]" for checkboxes, "[text_____]" for text fields, etc. I wasn't sure if it would work as the elements were rounded to the closest line, and sometimes just inserted a line between two others if it was close to half a line in-between etc.

The ASCII 'screenshots' came out beautifully. From then on when a call came it, we told them to use the view log menu item, scroll to the trade time, then they'd shut up quick. A picture is worth a 1000 words indeed.

Re: Ask HN: What's your "it's not stupid if it works" story?

#73
One of the first things I built as a developer at the first startup I worked for (circa 1998 or 1999, I was originally hired as a graphic and web designer) was a system I wrote in Allaire ColdFusion that used Macromedia Flash Generator to render and save custom graphic page headers and navigation buttons for e-commerce websites by combining data stored in an Access database with Flash templates for look and feel.

Re: Ask HN: What's your "it's not stupid if it works" story?

#74
TL;DR: Had no database so I made a PHP page with a hardcoded array of 100,000 coupon codes.

---

Made a PHP landing page for a customer where they could redeem a coupon code they were sent via snail mail. About 100,000 codes were sent out via USPS.

Threw together the basic code you might expect, simple PHP page + MySQL database. Worked locally because customer was dragging their feet with getting me login creds to their webhost.

Finally, with the cards in the mail, they get me the login creds at 5PMish. I login and there's no database. Cards are going to be arriving in homes as early as 8AM the next day. How TF am I going to make this work... without a database?

Solution... I just hardcoded all 100,000 codes into a giant MySQL array. Or maybe it was a hash/dict or something. I forget.

Anyway, it performed FINE. The first time you used the page it took about 30 seconds to load. But after that, I guess `mod_php` cached it or something, and it was fine. Lookups returned in 100ms or so. Not spectacular but more than performant enough for what we needed.

Got paid. Or, well, my employer did.

Re: Ask HN: What's your "it's not stupid if it works" story?

#75
Around 16 years ago, Wordpress security was just not up to snuff yet, and my popular Wordpress-based site kept getting hacked by pharmaceutical spammers and the like. After several such incidents, I wrote a "wrapper" that loaded before Wordpress to scrutinize incoming requests before a lick of Wordpress code was executed. It had blacklists, whitelists, automatic temporary IP blocking, and that sort of thing. There was no reason for visitors to upload files, so any non-admin POST request with a file upload was automatically smacked down.

It wasn't pretty, but the hackers never got through again, and that clunky thing is still in service today. I coded it to quarantine all illicit file uploads, and as a consequence I have many thousands of script kiddies' PHP dashboards from over the years.

Re: Ask HN: What's your "it's not stupid if it works" story?

#76
I have centralized AC and the wall-mounted control panel is located in a small storage room. I wanted to hack the control panel with an Arduino and a Raspberry pi so I can control it remotely via my Alexa. I ended up buying a switch bot [0] and an IP camera and was done with it.

0: https://www.switch-bot.com/products/switchbot-bot

Re: Ask HN: What's your "it's not stupid if it works" story?

#77
post #65

Earlier quoted context omitted.

Definitely wouldn't work today. Nowadays you need to classify like 30 images of bicycles and 20 fire hydrants and pray to god before they accept your answer...

This is why I don’t have an account with Snapchat/Instagram/etc. I tried signing up and physically couldn’t get past the challenges. I take too long to solve them and then I’m asked to solve more…

Sometimes if they hate your client and ip they put you into a captcha tar pit that you only think you could get out of. Only a bot would keep trying but a human will die in there too even if they have the tenacity of a bot.

Re: Ask HN: What's your "it's not stupid if it works" story?

#78
15+ years ago, I was working on indexing gigabytes of text on a mobile CPU (before smart phones caused massive investment in such CPUs). Word normalization logic (e.g., sky/skies/sky's -> sky) was very slow, so I used a cache, which sped it up immensely. Conceptually the cache looked like {"sky": "sky", "skies": "sky", "sky's": "sky", "cats": "cat", ...}.

I needed cache eviction logic as there was only 1 MB of RAM available to the indexer, and most of that was used by the library that parsed the input format. The initial version of that logic cleared the entire cache when it hit a certain number of entries, just as a placeholder. When I got around to adding some LRU eviction logic, it became faster on our desktop simulator, but far slower on the embedded device (slower than with no word cache at all). I tried several different "smart" eviction strategies. All of them were faster on the desktop and slower on the device. The disconnect came down to CPU cache (not word cache) size / strategy differences between the desktop and mobile CPUs - that was fun to diagnose!

We ended up shipping the "dumb" eviction logic because it was so much faster in practice. The eviction function was only two lines of code plus a large comment explaining all the above and saying something to the effect of "yes, this looks dumb, but test speed on the target device when making it smarter."

Re: Ask HN: What's your "it's not stupid if it works" story?

#79
I implemented an enterprise data migration in javascript, running in end-user's browsers. (So no server-side node.js or such.)

It was a project scheduled for 2-3 months, for a large corporation. The customer wanted a button that a user would click in the old system, requesting a record to be copied over to the new system (Dynamics CRM). Since the systems would be used in parallel for a time, it could be done repeatedly, with later clicks of the button sending updates to the new system.

I designed it to run on an integration server in a dedicated WS, nothing extraordinary. But 3 days before the scheduled end of the project, it became clear that the customer simply will not have the server to run the WS on. They were incapable of provisioning it and configuring the network.

So I came up with a silly solution: hey, the user will already be logged in to both systems, so let's do it in their browser. The user clicked the button in the old system, which invoked a javascript that prepared the data to migrate into a payload (data -> JSON -> Base64 -> URL escape) and GET-ed it in a URL parameter onto a 'New Record' creation form into the new system. That entire record type was just my shim; when its form loaded, it woke another javascript up, which triggered a Save, which triggered a server-side plugin that decoded and parsed the data, which then processed them, triggering like 30 other plugins that were already there - some of them sending data on into a different system.

I coded this over the weekend and handed it in, with the caveat that since it has to be a GET request, it simply will not work if the data payload exceeds the maximum URL length allowed by the server, ha ha. You will not be surprised to learn the payload contained large HTMLs from rich text editors, so it did happen a few times. But it ran successfully for over a year until the old system eventually was fully deprecated.

(Shout out to my boss, who was grateful for the solution and automatically offered to pay for the overtime.)

Re: Ask HN: What's your "it's not stupid if it works" story?

#80
post #14

`sed` text files as a replacement for templating. In the text file you have something you want to template (or "parametrize") from an outside variable, so you name that something like @@VAR@@ and then you can sed that @@VAR@@ :-)

Wait, you're telling me this isn't a Best Practice™?

It totally is.
Post reply on HN