9
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?
I’ve done it once or twice when I planned on trying to help work on the project then just never did ¯\_(ツ)_/¯
Some people/organizations will fork everything they use to ensure that they have a copy of the code that's in their control and can't be changed or removed. I think some places do this strictly as a policy, since having one of your dependencies suddenly disappear can be a disaster.
It could also be a method of effectively pinning repos to a particular version without needing to put a version number or commit hash into the project itself. Always pull from the head of your fork, and then only update the fork from upstream when you want to bring in updates. (I don't think that's a great practice, but it works)
If you just click the fork button on github and the upstream is forcibly removed, your fork will be, too.
If GitHub itself removes it, you mean? Yes, all forks should be removed in that case, since GitHub is saying they don't want to host the code, so the forks wouldn't be allowed either.
If the original owner just deletes the repository or destroys it in some other way like force-pushing over the commit history it won't also delete/break forks though, so that's what you're protecting against.
K, let's say I have a program written in CUDA. I want to make it portable, preferably in vulcan, how would I go about doing that?
I've seen VUDA, but It's a one man operation, so I'm uncertain about using it. I'd like to use NVIDIA libraries, and my impression is that portions of their stuff is open source, so it may be possible to write a home-brew compiler. Thoughts?
What do you mean "in vulkan"? CUDA is a compute API, Vulkan is graphics with some compute bolted on? That said...
edit: also OpenMP offload might work, but don’t expect great performance or any compilers that work for Windows.
The parts that literally have to be open source (e.g., headers) are open-source... beyond that, not so much. There are some "research-y" libraries like Cub or Cutlass that are true open-source.
Most compute operations can be implemented in graphics. (That's a single person operation though, which is probably not stable.)
Anyway, yes I would like to use openCL, but I haven't found any good guides on setting it up. I use both windows 10 and ubuntu, so if you have a suggestion for a guide, I would be happy to try it.
Conda is the easiest way on Ubuntu, I find that PyOpenCL has good guides. Windows is trickier, you likely need a vendor supplied OpenCL runtime (e.g., from your GPU driver, or Intel's Beigenet for integrated). There some additional resources as well:
That said... if those are your only two targets, CUDA works on Windows :P
Do we allow auothotkey questions in here? If so, is there some way of referencing a single section of code multiple times from different hotkeys? For instance, having the same tooltip and timer to remove the tooltip
or having the same menu appear.
I don't think so, but that led me to labels and gosub which might do it. Thanks.
In PostgreSQL, is there a way to have a unique constraint that is dependent on another column? Say I have the table below, I want the
unique_id
column to be unique but only where thef_key
column is the same.This sounds like a regular
UNIQUE
constraint on 2 columns.Oh it's that simple? I'll try it out tomorrow and edit this comment if it worked.
Edit: Seems to be working, thanks again @pvik!
Cheers!
When using the
UNIQUE
constraint in postgres, always be wary ofNULL
values.since
UNIQUE
will allow multiple rows withNULL
in a column even with aUNIQUE
constraint.From postgres documentation:
So it is advisable to tack on a
NOT NULL
constraint as well, if you do not wantNULL
values in those columns.That's good to know! Luckily so far all my usage of unique has also always been not null.
Best tutorial for avocational assembly for an ex perl developer who’s been out of the game for 15 uears?
Reverse engineering for beginners/Understanding assembly language (published separately under both names) is a good one. It spends some time talking about reverse engineering, but is still a great guide for assembly.
Personally, I think x86 assembly is fine (though make sure you use intel syntax; at&t is confusing and useless), but some people say other architectures like MIPS or m68k are more approachable. You mention the 6502; if you want to learn that, you may have luck looking up guides for game consoles that used it, like the NES or the atari 2600; this list looks pretty good.
Do you have a particular project or machine in mind?
Not really. Perhaps the 6502. The desire is born from a challenge I didn’t meet as a young lad.
The reason I ask is that without a machine (real or virtual) to target, one with a screen you can write to, it's going to be hard to even play around. At least that was my experience with a Z80 many years ago.
Unfortunately I don't know much about modern 6502 tools, but maybe I can help anyway!
I see this emulator for 6502 computers, which looks active. I expect putting things on the screen and debugging to be about equally hard on those.
Another option might be to target the NES/Famicom, although from what I've read that's probably going to be harder — see here for an overview. I think there's a pretty active development scene though. In particular I see this repository which has some useful links; and this project, whose author is regularly streaming its development on Twitch!
For completeness I should mention that writing assembly for modern systems is much more straightforward. For instance, you can write a program in RISC-V assembly, compile it with LLVM, and then run it directly on Linux with QEMU. Incidentally, if you do that, I'd recommend the book Computer Organization and Design (Patterson and Hennessy) for more on CPUs. You might find it useful background, depending on your interests.
Sorry, having all of these options probably didn't help much. Hopefully something focused enough to work on piques your interest!
Another option — Ben Eater is producing videos about building a 6502 computer (like from a microprocessor, wires, and resistors), and is selling kits for following along. Either buying the kits or sourcing the parts yourself is going to be expensive, but depending on how much time and energy you want to invest, it might very well be worthwhile!