3
votes
Fortnightly Programming Q&A Thread
General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.
Don't forget to format your code using the triple backticks or tildes:
Here is my schema:
```sql
CREATE TABLE article_to_warehouse (
article_id INTEGER
, warehouse_id INTEGER
)
;
```
How do I add a `UNIQUE` constraint?
BTW does anyone know what I can use to call an API endpoint every 24h and cache that response so that it can be consumed by multiple clients (instances) of my app? Preferably for free and with low latency since this is just a hobby project.
I was thinking something off AWS, but I'm not too familiar and I'm sure easier alternatives exist. I did think of using Heroku or some other PaaS but Heroku is notorious for putting their dynos to sleep after a period of inactivity.
Do you have a raspberry pi? That could be another option. That's the type of stuff I use mine for.
Or I think it could be done with GitHub Actions using a scheduled event.
Wow, github actions seems to have come a long way! I'm guessing it could be used in conjunction with some other action to deploy to a server? Thanks for showing me that :)
You could even deploy directly to a git branch or publish artifacts on GitHub. btw GitHub Actions works in private repos too.
Cryptocurrency mining has unfortunately decimated the free tiers of a lot of cloud and VPS platforms. If you can find any free compute, it will suffice for caching a single resource (assuming it's not gigabytes and gigabytes large); if not, the cheapest thing you can buy will also suffice (reliability could be poor, though).
Looking through AWS's list of free stuff, I think you could probably cobble something together with Lambda (to handle the requests and updating the cache) and either DynamoDB or Storage Gateway (to actually store the cached request; note that neither is really intended for this purpose). AFAIK you'll have to custom-write the software that runs in Lambda, though it should be straightforward.
Note that a major downside to using AWS is that there's no usage caps; if you go over the free tier limits, or accidentally use something that's not free, or fail to notice that they changed their minds about what should be free, you will get a bill.
Personally, I would probably try to find a cheap-enough VPS for this purpose. AFAIK, you could just use Squid out of the box, avoiding the need for custom software and the billing pitfalls of AWS. The resources you need for this are pretty much negligible; RamNode's cheapest instance type is $3/month and frankly massive overkill for what you need here.
Ohh thanks for the tip about AWS. I'm a bit wary of using AWS for hobby stuff just because of that!
I did find deta.sh to be quite interesting and really easy to setup/run.
I should've specified that it's a tiny JSON response so this worked quite well. Thanks again!
On any VPS of your choice, set up a cronjob to curl the API and save the response into a file in a directory you serve with nginx or similar.
What VPS do you generally recommend for hobby level stuff? Thanks :)
I’m a fan of Digital Ocean personally, on account of the easy firewall setup and backups, but it’s mostly personal preference - there’s plenty of good competition at the $5/mo mark.
I've been planning a small project for which I will need to do some full stack development. While I've worked on the disparate parts of these things in isolation throughout my career, I've never managed the whole thing myself before. Additionally, the last thing I worked on was a webserver written in a Lisp dialect (for its threading support) so let's say I'm (1) avoiding doing that again and (2) a bit behind the times on more mainstream offerings.
Just curious if anyone has any web frameworks they like in particular, especially any that have come out or had big developments in the past five years or so. Front end too!
I always find Flask to be a delight to work with although it isn't the latest and greatest. But of late I've been dabbling with a combination of Node.js + TailwindCSS + Svelte and it's been a joy to write applications/websites with that stack. If you like svelte, you should check out sveltekit and elderjs!
Thanks so much for bringing attention to TailwindCSS - I'm definitely going to look further into it as it's come recommended twice.
I also already have some experience with Node.js circa a few years ago, so I was already leaning a bit towards a Node.js solution. I will look into Svelte for sure.
if you're considering using svelte and tailwind at the same time, consider replacing tailwind with https://windicss.org
back when i tried it, tailwind with svelte resulted in very long compile times especially for hot reload stuff, while windi is just about drop-in compatible and works in an instant (in my experience, anyway)
Huh, that's interesting. I used Tailwind recently and it has an experimental JIT mode which is pretty near instantaneous so I encourage you to check it out to see if that fixes the long compile times!
I think i tried the JIT, but with how Svelte handles global styles it still took a few seconds to generate the styles. Also, it felt like a big pain to get it down to the "few seconds", whereas Windi just seemed to work pretty much out of the box.
For the frontend, I like Vite or Eleventy depending on what type of project I'm working on. Frontend styling I always do with tailwindcss, styling with that is especially nice if you're more used to the backend side of things.
For the backend, I've worked in C# (ASP) in the past. .NET6 just got released yesterday with it's long term support.
If course the specific stack depends a lot about your specific project. I might recommend something else in various cases.
Yes of course! I was keeping it a bit vague, but I recently met some folks on one of those old-timey browser-based site games and wanted to try out making my own, just for fun and to get more hands-on experience with the ops side of things.
But I also have my own domain which for now just links to my LinkedIn, and I wanted to update it as just a personal site. Which on initial peek looks like it might be a pretty a good use case for Eleventy!
A good example for a personal site: https://github.com/11ty/eleventy-base-blog. This shows how various features can be implemented pretty nicely.
Anyone here use Nim? Just curious
I have, it's fun. The C interop is less magic than it appears but still works well.
I just have problems justifying situations in which to use it - if speed doesn't matter, I'm probably using Python (for its library ecosystem), but if speed does matter, I'll use Rust (especially if it's a big project).
It occupies a weird niche by being a better Python - but Python isn't a bad language, it's just a slow one, and if you're using Python you're probably dependent on some external library.
It's probably a very fun language for embedded programming.
Anyone here an expert on rooting Android devices? I'm trying to work with the unlocked build of Oculus Go to get on device root through Magisk, so play services and all that can be installed, but I'm running into some walls using the latest Canary version in which it will flash and reboot, but doesn't appear to have rooted properly.
"rooting Android devices" is a very large field. i personally know enough to compile patched lineageos builds for the two phone models i owned, but i couldn't give you any advice about oculus go (or any not-regular-phone device) other than "just go on xda".
if you have a "no command" message before or during rebooting, magisk seems to be tracking that issue here, and my quick ddg search didn't say anything about anyone publicly documenting root methods other than the built-in adb root, so i doubt you are alone
(edit: just compared the usernames)
for play services, opengapps or similar packages could be flashed without magisk. it only requires a custom recovery if the oculus go has one.
Thanks, what happens though is that with Play Services, something happens that makes the device loop when it's installed. I suppose we could try sniffing out what is going on now that we have access to logs and kernel panics. And with the Unlocked build, we only have access to flashing new boot and system through the bootloader. Recovery is off limit and there's no VBmeta since it's still on Android 7.1