12 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?

34 comments

  1. [11]
    Diff
    Link
    What's the best way to explore the capabilities of a browser that has very little documentation left alive? I'm trying to a build something of a web app for my Sony PSP, and all the links to the...

    What's the best way to explore the capabilities of a browser that has very little documentation left alive? I'm trying to a build something of a web app for my Sony PSP, and all the links to the documentation have rotted away in the past 15 years.

    There's enough fragments floating around to know that it supports HTML 4.01, ECMAScript 3, and a good chunk of CSS 1 and 2. Those are old enough that they're difficult enough to find good, reliable documentation on outside of the specifications themselves.

    But this browser has quite a few quirks outside of just the specs. Particularly, there's no XMLHttpRequest, and you're not allowed to mess with the DOM much after it's loaded. CreateElement does nothing and neither does innerHTML.

    What's the best way to figure out all the tools I have available in this extremely constrained environment?

    6 votes
    1. whbboyd
      Link Parent
      I have no advice for documentation on the PSP's browser, but for documentation of old standards, I'd recommend trying to get your hands on some outdated reference books (i.e. printed on paper—if...

      I have no advice for documentation on the PSP's browser, but for documentation of old standards, I'd recommend trying to get your hands on some outdated reference books (i.e. printed on paper—if it's currently functioning at all, your local public library probably has a nice selection, though hitting the right narrow window of outdatedness may take some searching).

      5 votes
    2. [2]
      nothis
      (edited )
      Link Parent
      Is this the official browser on the PSP? It sounds like they've deliberately cut features to make it less prone to hacking. No proper "app" should run on this thing, right? What's the point of...

      Is this the official browser on the PSP? It sounds like they've deliberately cut features to make it less prone to hacking. No proper "app" should run on this thing, right? What's the point of javascript if you can't even change anything on the site?

      Why not just render everything server-side? Or, you know... jailbreak it and look for alternatives?

      3 votes
      1. Diff
        Link Parent
        Yep, the official browser. I don't think they cut features, rather the features were never there in the first place. Games and programs running on the PSP can summon the browser if they need it,...

        Yep, the official browser. I don't think they cut features, rather the features were never there in the first place. Games and programs running on the PSP can summon the browser if they need it, so it's incredibly slim. IIRC it only allows itself 2MB of RAM.

        I am jailbroken; believe it or not, going through the browser is probably the path of least resistance lol. I'm creating an internet radio player. On the PSP, internet radio players are essentially just web pages that are given access to a few extra APIs (that, thankfully, are very well documented) that handle all the heavy lifting as far as the actual streaming and playing.

        5 votes
    3. [4]
      wirelyre
      Link Parent
      But there is JavaScript available? I think a good early goal would be to get some sort of feedback from running JavaScript. Maybe you can dynamically load an image and leak something through the URL?

      But there is JavaScript available?

      I think a good early goal would be to get some sort of feedback from running JavaScript. Maybe you can dynamically load an image and leak something through the URL?

      2 votes
      1. [3]
        Diff
        Link Parent
        There is Javascript, an ancient version, but it exists. I have the normal alert() and a special debug function that dumps text onto the screen, so I imagine those'll come in handy. Thankfully one...

        There is Javascript, an ancient version, but it exists. I have the normal alert() and a special debug function that dumps text onto the screen, so I imagine those'll come in handy. Thankfully one part that's well-documented is the handful of platform-specific Javascript methods.

        4 votes
        1. [2]
          wirelyre
          Link Parent
          Ah, so this isn't an attack on a black box. That's nice. :-) Do you have window.location[.assign], document.write, iframes, or data: URIs? If you do, you can probably inject arbitrary content from...

          Ah, so this isn't an attack on a black box. That's nice. :-)

          Do you have window.location[.assign], document.write, iframes, or data: URIs? If you do, you can probably inject arbitrary content from JavaScript.

          What sort of features are you looking for? If you have enough control over the server, you might only need <div>, display: float, and forms.

          3 votes
          1. Diff
            (edited )
            Link Parent
            Lol definitely not, just trying to listen to some tunes on the go in probably the least efficient way I could think of. Did some poking around, window.location exists and behaves normally....

            Lol definitely not, just trying to listen to some tunes on the go in probably the least efficient way I could think of.

            Did some poking around, window.location exists and behaves normally. document.write only functions while the document stream is open, otherwise it erases the entire page without creating a new document. I have iframes, but changing their src has no effect. However, I can click() a link that has the iframe as its target.

            Oddly, I can access parent.document from the iframe, but there's no contentWindow or contentDocument accessible by the parent. But iframe.firstChild is an HTMLHtmlElement so maybe I can go diving down that. I don't see any methods that would do the heavy lifting of sorting through all the children unfortunately, just children, firstChild, and lastChild.

            In any case, yeah, I think that's enough tools available to keep this in the realm of possibility, at least

            3 votes
    4. [3]
      mftrhu
      Link Parent
      Banal, but - have you checked Archive.org to see if you can recover anything? I have had some degree of success for pages that old.

      and all the links to the documentation have rotted away in the past 15 years.

      Banal, but - have you checked Archive.org to see if you can recover anything? I have had some degree of success for pages that old.

      2 votes
      1. [2]
        Diff
        Link Parent
        Archive.org has saved my butt so many times in different parts of this search, unfortunately it didn't manage to grab the document I'm looking for. Google's cache didn't have it, either, and some...

        Archive.org has saved my butt so many times in different parts of this search, unfortunately it didn't manage to grab the document I'm looking for. Google's cache didn't have it, either, and some extensive searching hasn't turned up any saved copies publicly available on the net.

        Did have a tiny breakthrough this morning though, turns out the Japanese version of the same guidelines is still live on Sony's site. I don't read Japanese, but I can at least recognize these tables of unsupported elements/attributes/properties/methods which is a massive step forward.

        3 votes
        1. cfabbro
          (edited )
          Link Parent
          Is this it? https://cdn.us.playstation.com/pscomauth/groups/public/documents/webasset/web_content-guidelines_3.10-e.pdf Ah, NM... that seems to be PS3 related. :( Although digging around using...

          Is this it? https://cdn.us.playstation.com/pscomauth/groups/public/documents/webasset/web_content-guidelines_3.10-e.pdf

          Ah, NM... that seems to be PS3 related. :( Although digging around using site:playstation.com seems to be getting some old PSP related pdf results, which you may want to check out if you haven't already.

          EDIT: Found at least a partial translation of the Japanese pdf:
          http://forums.qj.net/psp-general-help/131272-internet-browser-content-guideline.html

          1 vote
  2. PetitPrince
    Link
    I'm looking for some pointers on how to properly deploy and manage a Django app. More specifically, how do you manage your dev and prod environment , and how do transfer data and database between...

    I'm looking for some pointers on how to properly deploy and manage a Django app. More specifically, how do you manage your dev and prod environment , and how do transfer data and database between ? (I'm using a cheap digital ocean droplet). There's probably some tools that automate the whole process, but I don't know where to start.

    3 votes
  3. [4]
    mercury
    Link
    What is the best way for git (on, say, github) to handle a software which has different code for multiple platforms? Basically I have two use-cases: A software serves Windows/Mac/Linux versions of...

    What is the best way for git (on, say, github) to handle a software which has different code for multiple platforms? Basically I have two use-cases:

    1. A software serves Windows/Mac/Linux versions of it, each of them have a little quirk in their code to make it compatible with their respective OSes.
    2. A website has a little difference in configuration for the server (production) and for the local (development) branch.

    Is it preferred to make separate branches, or separate projects unto themselves? Which one would prove to be a "cleaner" and hassle-free method in the long run?

    3 votes
    1. [3]
      KilledByAPixel
      Link Parent
      Why not use the exact same project with a some kind of compile time option for deciding which os it is for? You need to move all the os specific code to a platform independent layer.

      Why not use the exact same project with a some kind of compile time option for deciding which os it is for? You need to move all the os specific code to a platform independent layer.

      2 votes
      1. [2]
        mercury
        Link Parent
        I'm sort of new to this so don't understand what you mean by "moving the os specific code to a platform independent layer". How do I implement this?

        I'm sort of new to this so don't understand what you mean by "moving the os specific code to a platform independent layer". How do I implement this?

        2 votes
        1. KilledByAPixel
          Link Parent
          there are different ways to do it. for example you could have a generic base class that you inherit from for each of the different os you want to support. then you just use the one for which os...

          there are different ways to do it. for example you could have a generic base class that you inherit from for each of the different os you want to support. then you just use the one for which os you want to build for. the interface is the same regardless of the os.

          1 vote
  4. [14]
    Gyrfalcon
    Link
    I have yet another "Not really programming but programming related" question. I'm trying to achieve something that's a bit odd. I want to be able to have the same project on a professional facing...

    I have yet another "Not really programming but programming related" question. I'm trying to achieve something that's a bit odd.

    I want to be able to have the same project on a professional facing Github/lab, and on a personal Github/lab, without it being hard to manage, and without either (for lack of a better word) contaminating the other. I'd like to be able to showcase the project without making it super easy for someone who sees the personal page to find my real name and email, or for someone looking at the professional page to find my reddit/tildes/etc.

    The real key, I think, is to have two separate sets of commits, one with the name/email associated with the professional account, the other with the personal name/email. How to manage this I'm not 100% sure. I think I could manage it with like 3 folders of the same code and a bit of shell script, but I don't feel that's really a good solution.

    Anyway, I know this is a bit of a weird thing to want to do, but I was wondering if anyone here had any ideas.

    2 votes
    1. [6]
      musa_totter
      Link Parent
      Wouldn't the fact that the same project is on both profiles make it easy to guess that both are the same person? Or is your goal just to prevent one profile from having information that points to...

      Wouldn't the fact that the same project is on both profiles make it easy to guess that both are the same person? Or is your goal just to prevent one profile from having information that points to the other?

      This isn't a great solution either, but you could use the same "neutral" name/email (such as name: "Commit Author" email: "<project>@example.com") on both profiles

      6 votes
      1. [2]
        bdn
        (edited )
        Link Parent
        You called? (Edit for future readers: I used to use the handle @example.)

        You called?

        (Edit for future readers: I used to use the handle @example.)

        3 votes
        1. cfabbro
          Link Parent
          LOL, this makes me wonder how many notifications you get by accident? I imagine you and @user are probably the most accidentally mentioned on the site. :P

          LOL, this makes me wonder how many notifications you get by accident? I imagine you and @user are probably the most accidentally mentioned on the site. :P

          1 vote
      2. [3]
        Gyrfalcon
        Link Parent
        I mean, yeah I suppose it would make it easier for a determined person to connect the two, but in general I just don't want to make it obvious. The neutral domain/email is an idea. I guess in the...

        I mean, yeah I suppose it would make it easier for a determined person to connect the two, but in general I just don't want to make it obvious. The neutral domain/email is an idea. I guess in the end it probably wouldn't be the end of the world to link to a personal facing one from a professional domain, since someone looking at my project isn't going to be out to reddit and especially not to Tildes stalk me, but it just doesn't feel terribly professional to do it that way.

        2 votes
        1. [2]
          Bop
          Link Parent
          If it's something you intend on showcasing to potential employers in the future, the odds aren't terrible that they'll have someone whose job it is to see what pops up on the internet attached to...

          If it's something you intend on showcasing to potential employers in the future, the odds aren't terrible that they'll have someone whose job it is to see what pops up on the internet attached to that username.

          1. Gyrfalcon
            Link Parent
            That's true, but I don't think my post history is particularly interesting. I think really I'm most concerned with internet randos finding my real name and other information. Anyway, it seems like...

            That's true, but I don't think my post history is particularly interesting. I think really I'm most concerned with internet randos finding my real name and other information. Anyway, it seems like some of the things with Git hooks will suffice for my application.

            2 votes
    2. [2]
      parsley
      Link Parent
      Git commits contain author (and committer) information. You want those fields to show your name or your handle depending on the case. I don't think you can keep both copies in sync trivially. Do...

      Git commits contain author (and committer) information. You want those fields to show your name or your handle depending on the case. I don't think you can keep both copies in sync trivially.

      Do you need commit history in both? In your case i would have two repos, one with the everyday work under your internet handle, and the other with a single branch with squashed commits every now and then showing your professional name, or even better just have one commit with the current version, deleting older stuff as you update it. Remember to update your name if you add it to READMEs or other documentation.

      I would not do this at all if it is important for you to keep your internet names and your actual name independent, though. It is very easy to miss a name in a doc or commit to the wrong repo. You could be accused of plagiarizing yourself too.

      6 votes
      1. Gyrfalcon
        Link Parent
        I hear that. On the other hand, if I make something good enough to show off in one domain, I want to show it off in the other. I certainly am not productive enough to make a two sets of separately...

        I would not do this at all if it is important for you to keep your internet names and your actual name independent, though.

        I hear that. On the other hand, if I make something good enough to show off in one domain, I want to show it off in the other. I certainly am not productive enough to make a two sets of separately cool projects. I think maybe a single project with neutral names and two remotes or just dumping completed files into my professional repo at regular intervals will be doable.

        1 vote
    3. [2]
      streblo
      Link Parent
      If you own the professional site (i.e. you host your own git server) you should be able to use a server-side hook to change the email but your commit hashes won't line up as you will be re-writing...

      If you own the professional site (i.e. you host your own git server) you should be able to use a server-side hook to change the email but your commit hashes won't line up as you will be re-writing history.

      4 votes
      1. Gyrfalcon
        Link Parent
        Unfortunately I don't run the server, it would just be a regular Github account. This is something I would consider doing in the future, but I would probably want to set it up on a VPS (or on a...

        Unfortunately I don't run the server, it would just be a regular Github account. This is something I would consider doing in the future, but I would probably want to set it up on a VPS (or on a home server if my ISP will cooperate?) and I don't think I've got the time for it right now.

        1 vote
    4. [3]
      Deimos
      Link Parent
      It would definitely be weird, but I feel like you could probably do this with a post-commit hook in git. I haven't tried this and have no idea if it would actually work, but the idea would be:...

      It would definitely be weird, but I feel like you could probably do this with a post-commit hook in git.

      I haven't tried this and have no idea if it would actually work, but the idea would be:

      • Have two separate repos (locally these are just two different directories). I'll call them "Real" for the one with your real name and "Fake" for the one using your fake name/nickname.
      • Set up Real so it's effectively a fork of Fake, so that Fake is the "upstream" that you'll pull changes from into Real.
      • Work only in Fake. You shouldn't make any changes manually in Real at all.
      • Set up a post-commit hook in Fake (probably a shell script) that switches over to Real, does a git cherry-pick to get the latest commit from Fake, then does git commit --amend --author="Real Name <email@address.com>" to change the last commit's author to your real info.

      That way the two repos should stay in sync with their own author information, and you could just push them separately to their respective GitHub/GitLab locations. You could probably even use another hook to push them both automatically whenever you push Fake, but I'd probably do it manually first for a while to make sure it's all working as expected.

      If you want to be really safe, you should probably set up pre-push hooks in both repos that check to make sure there aren't any commits that have the "opposite" author info, and cancel the push if it finds anything.

      3 votes
      1. streblo
        Link Parent
        If he runs the git server easier to use a pre-receive hook on the server -- then you just work out of one repo.

        If he runs the git server easier to use a pre-receive hook on the server -- then you just work out of one repo.

        2 votes
      2. Gyrfalcon
        Link Parent
        I think this is along the lines of what I'll do. Something like rsync can easily handle copying the new files from one directory to the other and then some Git magic will handle the rest. Thanks!

        I think this is along the lines of what I'll do. Something like rsync can easily handle copying the new files from one directory to the other and then some Git magic will handle the rest. Thanks!

        2 votes
  5. [4]
    unknown user
    Link
    Is there a way to run build tasks without manually using either an IDE or command line? I've found what may be the most perfect EJS-based website builder for me yet, and I'd like it to be able to...

    Is there a way to run build tasks without manually using either an IDE or command line? I've found what may be the most perfect EJS-based website builder for me yet, and I'd like it to be able to run on a schedule. I want to be able to set it, forget about it, but be able to edit it with ease if I ever change my mind or any other part of the equation.

    2 votes
    1. [2]
      Diff
      Link Parent
      Aren't you describing cron? Pretty much every OS has some equivalent. Linux and macOS have an actual cron daemon that can run stuff on a recurring basis. On Linux, I guess systemd timers can be a...

      Aren't you describing cron? Pretty much every OS has some equivalent. Linux and macOS have an actual cron daemon that can run stuff on a recurring basis. On Linux, I guess systemd timers can be a bit more flexible. On Windows, there's the Task Scheduler app.

      8 votes
      1. unknown user
        Link Parent
        Thank you. Gonna check it out.

        Thank you. Gonna check it out.

        2 votes
    2. Gyrfalcon
      Link Parent
      It looks like your static site generator has an open issue for a watch mode, to rebuild as you make development changes, so if/when that is implemented that may be part of the equation for you....

      It looks like your static site generator has an open issue for a watch mode, to rebuild as you make development changes, so if/when that is implemented that may be part of the equation for you. You could also try git hooks if it's just getting something else to update or run every time you commit or push to a remote or something.

      EDIT: Now that I look at it, maybe git hooks could be helpful for my issue as well...

      1 vote