The Programming Thread

Discussion in 'Technologics' started by Charles, Jan 5, 2012.

  1. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    Every part of this statement qualifies for understatement of the year.
    JoshV, lesslucid and AaronSofaer like this.
  2. MightyMooquack Worked The System

    Well, that depends. Forking has its place. To be particularly pedantic, it's the only way to spawn a subprocess on Unix, but even aside from that, the preforking model for making a server with a number of worker processes has its merits. (I'm not sure what you mean about the compiler doing magic with respect to forking. It's a syscall with reasonably well-defined semantics, the compiler has little to do with it.)

    But for your everyday parallelism problem? Well, it can depend, but forking, threads, and signals (not to mention file descriptors) all interact in their own delightful ways, and it's really easy to make a hash of it. And forking recursively? You've got to have a pretty clear picture of what all the moving parts are doing.
    Elyscape likes this.
  3. AaronSofaer Magister Mundi Elyscape

    It's not the forking that the compiler did magic to; it's the recursion.

    And I actually implemented the thing this morning and it worked ... interestingly, in that it solved the logic puzzles I was trying to solve as long as certain constraints were present, and if they weren't it forkbomb'd my VM into oblivion.
  4. HalibutBarn Armchair Designer

    Location:
    Calgary
    Code (text):
    1. #include <unistd.h>
    2. #include <stdio.h>
    3. #include <sys/types.h>
    4. #include <sys/wait.h>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8.     int x = atoi(argv[1]);
    9.  
    10.     printf("x! = %d\n", factorial(x));
    11.  
    12.     return 0;
    13. }
    14.  
    15. int factorial(int x)
    16. {
    17.     if(x == 1)
    18.         return 1;
    19.     else
    20.     {
    21.         pid_t pid = fork();
    22.         if(pid == 0)
    23.         {
    24.             int y = factorial(x - 1);
    25.             exit(x * y);
    26.         }
    27.         else
    28.         {
    29.             int ex;
    30.             waitpid(pid, &ex, 0);
    31.             return WEXITSTATUS(ex);
    32.         }
    33.     }
    34.  
    35.     return -1;
    36. }
    Alas, due to limitations on exit values, it only works for 'x' up to 5. I don't recommend trying negative values...
    AaronSofaer likes this.
  5. roBurky Despondent Fancybear

    Is this a good place to ask for web dev help?

    I'm updating my webpage template for Unity web games, as I've got a new one I want to put out, and I'm trying to make it look nice when you haven't got the Unity player installed. I haven't done much website coding since I was a teenager, so I'm learning a lot.

    Here's the page so far, but with the Unity player embed code commented out:
    http://roburky.co.uk/play/threebodyproblem/

    The Unity player install button should appear in the centre of the blurred screenshot, and it does in chrome and firefox. But in IE, it appears below it. If I remove the link from the button image, it appears closer to the centre.
    I've been working on this problem all day, and I have run out of ideas about what could be going wrong. Somebody help me. Please.
  6. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    IE9 doesn't like this line:
    Code (text):
    1. <a name="top"/>
    Change it to this and you'll be fine:
    Code (text):
    1. <a name="top"></a>
    To elaborate, for whatever reason it interprets that first <a> tag to be an open tag that doesn't close anywhere. As part of its attempts to handle for that, it wraps the <a> tag around whatever the next element happens to be, in this case your <div class="content"> element. Then, due to some quirk in the rendering engine, it renders the <div class="content"> element again, causing the button to appear below.

    As a side note, if the button ends up hiding behind the image after that fix, drop the following line into your CSS for the <div class="missing"> element:
    Code (text):
    1. z-index: 1000;
    That'll push it on top of pretty much anything else, including the image.
  7. mkozlows Worked The System

    The reason is that it's an open tag that doesn't close anywhere, specifically. HTML isn't XML, even when it's defined as XHTML, unless it's served with a specific application/xhtml+xml datatype. Which you shouldn't do, because it'll work purely worse everywhere. Plus of course nobody uses XHTML anymore because everyone realized it was silly and now we have HTML5.
    roBurky and Elyscape like this.
  8. nlanza Keeper of the Elemental Materials

    Location:
    Pittsburgh
    fork()/exec() is one of those things Unix got wrong. The VMS spawn model is much saner.

    Note also that there are modern systems where forking without an immediate exec is fundamentally unsafe and leads to crazy undefined behavior.

    So yeah, don't do that. But you already knew that.

    Anyway, why the heck not just use threads or task queues or something that isn't abjectly nutty?
  9. roBurky Despondent Fancybear

    Brilliant! Thank you.

    I used the auto-generated Unity web player page as the base for my page, and I notice that had some stuff mentioning xhtml at the top. I don't actually have any clue what xhtml is. Should I change/remove it?

    Code (text):
    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml">
  10. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    You'll want to leave it alone. If you later decide to build a site for something manually, though, use HTML5 instead of XHTML.
  11. AaronSofaer Magister Mundi Elyscape


    Because using forking was hilarious.

    The naive version of the program was something like this:

    1 - Do you have any actions left available? If no, terminate yourself.
    2 - Pick one of the actions.
    3 - Flag it as no longer available.
    4 - Test it for whether it satisfies the constraints.
    5 - If yes, fork to that move. If no, go back to 1.

    When the solution is found, the parent (well, eventually-parent) process is informed and all the forklings terminate.

    This is a terrible terrible idea and I did it only to see how hard it would obliterate my VM. The surprising thing was that for about 2/3 of the constraint sets I handed it it managed it stunningly quickly. For the other third, of course, it forkbombed my VM into oblivion, or perhaps just sometime after the heat-death of the universe.
    Elyscape and nlanza like this.
  12. nlanza Keeper of the Elemental Materials

    Location:
    Pittsburgh
    This reminds me of the perpetual problem in academic computing where all shared shell hosting machines royally suck to use for a week or so when the intro Systems Programming course starts up and dozens of sophomores first attempt to use fork() in anger.
  13. Quackers Magister Mundi Elyscape

    Okay, we got any jquery mobile specialists in here? I've got a form that is all fucked and I have no idea why. It keeps pushing the menu off the screen. If I only have like, three form elements it's fine. But if I add more it gets all fucked up. Looks fine on a regular computer browser (of course!) but on my iPhone it's sucking. And driving me crazy.
    Elyscape likes this.
  14. JoshV Keeper of the Elemental Materials

    Elyscape likes this.
  15. JoshV Keeper of the Elemental Materials

    Ugh, I have a bug that I can 'fix' by doing something that shouldn't fix it. I hate that. Mathematically I shouldn't need to do what I'm doing. So either my understanding of the math is wrong, or the bug is actually farther up the chain in some high level area I know nothing about.
    Elyscape likes this.
  16. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    "A graphics program has an even number of sign errors"
    Elyscape likes this.
  17. JoshV Keeper of the Elemental Materials

    Heh, your correct by the way, it is a sign error. Hit-testing as opposed to graphics though.
    Elyscape likes this.
  18. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    Your computed normals are pointing the wrong way.
  19. JoshV Keeper of the Elemental Materials

    Heh, all hit detection is done in the space of the object, so it's always [0,0,1]. =)
    (It's UI, so all the objects are rectangles, allows for some shortcuts, especially if there aren't any 3D transforms)
  20. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    Your 0,0 is in the lower left rather than upper left.
    Elyscape and AaronSofaer like this.
  21. JoshV Keeper of the Elemental Materials

    Hah, no, it's was bug that had to do with right to left languages (dang you hebrew!), so it was more like some stuff having coordinates on left instead of the right, because the root transform with a negative scale in it wasn't be taken into account, but others transforms were. (the aforementioned odd number of sign errors)
    Elyscape and AaronSofaer like this.
  22. AaronSofaer Magister Mundi Elyscape

    Aw yiss, Hebrew messing up everyone since forever. Le chaim!
    Elyscape likes this.
  23. Adam A Oh, Come On

    Lately I've been using "Herp" and "Derp" to test anything I do with Strings. Helps get me through the workday.
    nixon66, Elyscape and AaronSofaer like this.
  24. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    Speaking of Hebrew and programming, the Zend Engine for PHP (i.e. the primary engine) was developed by Israelis, which is fine except that sometimes the error messages don't make any goddamn sense:
    Code (text):
    1. $ php -r ::
    2. Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
    Now, you might be wondering, "What the shit is T_PAAMAYIM_NEKUDOTAYIM?" Well, "paamayim nekudotayim", or more properly "פעמיים נקודתיים‎", means two colons. So T_PAAMAYIM_NEKUDOTAYIM is this thing: ::

    Yeah.
  25. JoshV Keeper of the Elemental Materials

    Yeah, similar issues with most modeling packages, except it's french.
    Elyscape likes this.
  26. BaconTastesGood Hard Cider Gal

    Location:
    North Carolina
    I want to write a MIDI app for either my iPhone or an android device. As it turns out, the CoreMIDI interface is woefully undocumented/unsupported on the former, and Android basically just doesn't work with MIDI (in/out). There are no MIDI interfaces for Android devices (that I can find). Well played Google.

    And I'm not sure I want to deal with XCode et. al. just to write a simple MIDI thing.

    I hate computers.
    Elyscape likes this.
  27. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    Earlier today, I was doing some Win32 documentation diving and I noticed something about a function called WaitForInputIdle. I saw WaitForIneptitude.
    SpoofyChop and anaqer like this.
  28. AlanT I Pretty Much Live Here

    I saw WaitForInPuddle, but I can't claim much in the way of programming expertise.
    dermot and Elyscape like this.
  29. Aeon221 Despondent Fancybear

    Location:
    G:\HAW HAW HAW
    So for several days now I've been running into all kinds of the same error with my modeling program related to the change from an embedded derby database to a network one. Lots of access errors, lots of stupid shit.

    I even went back to the derby tutorials and worked through them all because, like, clearly I must have fucked up somehow in a huge way. Nope, doing it all right.

    Then I checked my config file for the database:
    <entry key="LOCATION">jdbc:derby://localhost:1527/:derbyDB</entry>
    it's supposed to be
    <entry key="LOCATION">jdbc:derby://localhost:1527/derbyDB</entry>


    [IMG]

    fuck all colons

    edit: also doing stuff with the derby ij language is notbadface. Nice quick way to check if the db be doin thangs and alive and stuff.
    Elyscape and extarbags like this.
  30. Kildorn Beardy Magnificence

    Location:
    Boston, MA
    May as well ask in here as I start this idiocy: anyone dealt with libvirt heavily, or ruby's libvirt bindings? I'm off to experiment with controlling a vcenter server remotely, and I really don't feel like playing with vmware's shitty api documentation directly (as of this writing, half the perl documentation 404s on their site)
  31. chequers Oh, Come On

    Location:
    Sydney
    We use libvirt via python for managing a bunch of qemu/kvm hosts.
  32. XPav Elitist Negative Nancy

    Location:
    Grogaboo hunting
    Doing some OpenGL ES for simple 2D UI right now.

    It's not that bad. I'm amazed. Am I going to hit some suck at some point?
  33. JoshV Keeper of the Elemental Materials

    Is there a term for the color format that isn't pre-multiplied alpha? I keep referencing it as unmultiplied alpha, but I'm curious if there is an actual term for it.
  34. cnahr Worked The System

    RGBA. If the alpha isn't premultiplied it's just another channel.
    Elyscape likes this.
  35. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    There's also BGRA. This (obviously) can cause problems if you mix them up.

    Awesome problems.
    Marcin likes this.
  36. JoshV Keeper of the Elemental Materials

    Yeah, I get that, the RBGA or BGRA or PRBGA or PRGBA. The alpha value stays around, it's not 'baked' away, as it's still used during blend operations. Was just curious if there was a word instead of an acronym to define it.
  37. cnahr Worked The System

    Color? Color with transparency information? There isn't really a single term even for premultiplied alpha since the RGB channels might be in a different order. It's always acronyms if you want to be precise.
    Elyscape likes this.
  38. AaronSofaer Magister Mundi Elyscape

    Are there any Ruby tutorials out there that come particularly recommended?
  39. Elyscape Already Beat BF's New Expansion

    Location:
    San Jose, CA
    For just Ruby, there's Ruby in Twenty Minutes and also RubyLearning.com. If you mean Ruby on Rails, that's a different story.
    AaronSofaer likes this.
  40. bloo Armchair Designer

    I'm taking this online course now and it's time to leave 4004 processor machine code for C. Is there a preferred free solution for newbs compiling and such on a windows desktop or install linux and dualboot?

    (Also, multiplying two numbers in machine code, I hate you. I see how it works but I'd never figure it out on my own in the space permitted).
    Elyscape likes this.