The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

The sorting [chat]

13567103

Posts

  • spool32spool32 Contrary Library Registered User, Transition Team regular
    hahaha, muggle is an option?!

    sorry cB hehehehe

  • cB557cB557 voOOP Registered User regular
    edited August 2015
    P10 wrote: »
    cB557 wrote: »
    Waitwait wait
    the OP actually does select a different thing
    I got
    Apothe0sis wrote: »
    MUGGLE.

    You are using the Internet.
    I assumed it didn't actually do anything and it was just Apoth being clever
    disgusting mudblood
    that's not what that means
    how do you not know this
    you're the wizard here
    get your shit together

    cB557 on
  • P10P10 An Idiot With Low IQ Registered User regular
    cB557 wrote: »
    P10 wrote: »
    cB557 wrote: »
    Waitwait wait
    the OP actually does select a different thing
    I got
    Apothe0sis wrote: »
    MUGGLE.

    You are using the Internet.
    I assumed it didn't actually do anything and it was just Apoth being clever
    disgusting mudblood
    that's not what that means
    how do you not know this
    you're the wizard here
    get your shit together
    they don't have a slur for muggles tho

    Shameful pursuits and utterly stupid opinions
  • AresProphetAresProphet Registered User regular
    why does that funny looking hat call me what I can only assume is a hybrid fat/Pokemon slur

    ex9pxyqoxf6e.png
  • simonwolfsimonwolf i can feel a difference today, a differenceRegistered User regular
    abolish the house system

  • Donkey KongDonkey Kong Putting Nintendo out of business with AI nips Registered User regular
    Shivahn wrote: »
    Hey programmy people - I have a question

    I am adding functionality to my IRC dicebot that will allow persistent tracking of individual's experience, money, and items (which I'm calling a character account). The way the bot is set up is that it has a thread listening on a socket for input which uses a queue to pass to a master thread, which handles the input. If the socket input is a private message, it executes the private message handling logic.

    Now, all actual interaction with the character accounts will therefore be in the private message function, as any requests to change around variables will be received there. The problem, then, is that I want an account to persist once opened, because it's being saved to a file and it'd be really stupid to receive "add ten dollars to desc's account" and then open a file, read it all into memory, fiddle with desc's bits, write the changed file, and send the message "you have successfully fiddled with desc's bits." So I would like the first call to have to be either "create" or "open," and calls afterwards all work on an object in memory.

    Is there a way to do this? The main issue is that, since it's inside of a function, I can't really create an object and have it persist. Global variables are not great practice. I guess I could have a thread run on any given account, and use a SEPARATE queue to communicate with the master thread, but that seems extremely poor in terms of design.

    How would you guys do this?

    The code is in Python, by the way.

    Firstly, that's not so stupid of a design. It's a light duty program, it's a hobby project, and computers automatically cache small, commonly opened files, so the open/read/modify/write cycle is going to be a lot faster than you imagine. Like less than 1ms. My first advice is just leave it the way it is. This is a simple and shockingly robust design. In network apps, this is kind of what the file system is for.

    Next, the "more efficient" design, which may in practice not actually be more efficient, is to have a design where you have a user object that contains all their info. This object has a function for writing its self out to disk and loading off of disk. You store all these user objects in a collection in your main thread. When you get a new command, you check the user name and look in your collection for that user. If they aren't found, look on disk for a file. If a file is found, make a new instance of the user class with that file and put it in the collection. If no file is found, initialize a blank user with that name. Next, process the message, modify the class in-memory, and call the write-out to disk function. You could even have another thread where you queue up the write out to disk functions but then you need to worry about locking the user objects so you don't accidentally modify one while it is being written.

    But like I said, this is classic premature optimization.

    Thousands of hot, local singles are waiting to play at bubbulon.com.
  • AresProphetAresProphet Registered User regular
    simonwolf wrote: »
    abolish the house system

    ex9pxyqoxf6e.png
  • SummaryJudgmentSummaryJudgment Grab the hottest iron you can find, stride in the Tower’s front door Registered User regular
    It's not like we didn't go over about Important Lessons about Adult Responsibility

    This writing :biggrin:

  • MortiousMortious The Nightmare Begins Move to New ZealandRegistered User regular
    edited August 2015
    Some other random photos from my phone's camera.

    Graffiti in Singapore:
    TLM92Egm.jpg

    A traditional UK bike:
    tcWFoe3m.jpg

    A traditional UK breakfast:
    qNAAKvHm.jpg

    Mortious on
    Move to New Zealand
    It’s not a very important country most of the time
    http://steamcommunity.com/id/mortious
  • GarthorGarthor Registered User regular
    P10 wrote: »
    Shivahn wrote: »
    it'd be really stupid to receive "add ten dollars to desc's account" and then open a file, read it all into memory, fiddle with desc's bits, write the changed file, and send the message "you have successfully fiddled with desc's bits."
    how slow would this actually be?

    Depends on whether you have one file containing the data for all players (in which case: depends on the number of players) or one file per players (in which case: not very long, unless that file is keeping a log of every single transaction or something).

    My answer would be that the efficiency of the read/write times is not a concern, unless this bot is going to be servicing thousands of people simultaneously. Just typing out "fiddle with dec's bits" takes orders of magnitude longer than fiddling with desc's bits regardless of how you do it, so don't worry about it.

    However, the question "where do I put data I need 'globally' if global variables is bad?" is important. Generally, you'd give the variable to an object, namely the master thread object. If I recall correctly, in Python this should be as simple as using self.ListOfOpenFiles or somesuch, I dunno. I don't like how wishy-washy Python is, honestly.

  • Solomaxwell6Solomaxwell6 Registered User regular
    Shivahn wrote: »
    Shivahn wrote: »
    Hey programmy people - I have a question

    I am adding functionality to my IRC dicebot that will allow persistent tracking of individual's experience, money, and items (which I'm calling a character account). The way the bot is set up is that it has a thread listening on a socket for input which uses a queue to pass to a master thread, which handles the input. If the socket input is a private message, it executes the private message handling logic.

    Now, all actual interaction with the character accounts will therefore be in the private message function, as any requests to change around variables will be received there. The problem, then, is that I want an account to persist once opened, because it's being saved to a file and it'd be really stupid to receive "add ten dollars to desc's account" and then open a file, read it all into memory, fiddle with desc's bits, write the changed file, and send the message "you have successfully fiddled with desc's bits." So I would like the first call to have to be either "create" or "open," and calls afterwards all work on an object in memory.

    Is there a way to do this? The main issue is that, since it's inside of a function, I can't really create an object and have it persist. Global variables are not great practice. I guess I could have a thread run on any given account, and use a SEPARATE queue to communicate with the master thread, but that seems extremely poor in terms of design.

    How would you guys do this?

    The code is in Python, by the way.

    First of all, the typical OO solution to that kind of problem (having an object that persists across multiple calls of a function) would be to wrap the whole thing--or at least most of it--in a class. Then your initialize function would check to see if your file exists, open up the file, and dump the info into a class variable. Since that variable is at the class rather than function scope, it would persist across multiple calls of a function.

    Second of all, for this particular problem, you might want to look into a nosql solution like MongoDB. Depending on what exactly you're doing with your dicebot that might be a bit overkill, but probably worth looking into for future reference anyway.

    The problem with the first thing is that I don't necessarily want to create it, and it seems inelegant to have a massive class with subobjects that I'm maybe not going to use. At that point it's barely different from a global variable, right?

    I will check those in 2. Though yeah, probably total overkill :P

    If it's very complicated, it's probably worthwhile to just do a class that represents characters, and handle individual updates there.

  • ElkiElki get busy Moderator, ClubPA Mod Emeritus
    Everytime I watch this film, I feel sadness at the dearth of politicians and public figures who spend time critically examining their past actions in a way that's not mostly self serving.

    smCQ5WE.jpg
  • ShivahnShivahn Unaware of her barrel shifter privilege Western coastal temptressRegistered User, Moderator mod
    Thanks, DK

    Yeah I suppose it is hella premature optimization, I just don't want to have to rewrite later and also figure this kind of question is something I could see later, and should learn more about. Your post answers that well (as well as pointing out I'm premature in worrying about it) and is appreciated.

  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    spool32 wrote: »
    hahaha, muggle is an option?!

    sorry cB hehehehe

    Has anyone got Hagrid yet?

  • Donkey KongDonkey Kong Putting Nintendo out of business with AI nips Registered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    Thousands of hot, local singles are waiting to play at bubbulon.com.
  • ShivahnShivahn Unaware of her barrel shifter privilege Western coastal temptressRegistered User, Moderator mod
    Shivahn wrote: »
    Shivahn wrote: »
    Hey programmy people - I have a question

    I am adding functionality to my IRC dicebot that will allow persistent tracking of individual's experience, money, and items (which I'm calling a character account). The way the bot is set up is that it has a thread listening on a socket for input which uses a queue to pass to a master thread, which handles the input. If the socket input is a private message, it executes the private message handling logic.

    Now, all actual interaction with the character accounts will therefore be in the private message function, as any requests to change around variables will be received there. The problem, then, is that I want an account to persist once opened, because it's being saved to a file and it'd be really stupid to receive "add ten dollars to desc's account" and then open a file, read it all into memory, fiddle with desc's bits, write the changed file, and send the message "you have successfully fiddled with desc's bits." So I would like the first call to have to be either "create" or "open," and calls afterwards all work on an object in memory.

    Is there a way to do this? The main issue is that, since it's inside of a function, I can't really create an object and have it persist. Global variables are not great practice. I guess I could have a thread run on any given account, and use a SEPARATE queue to communicate with the master thread, but that seems extremely poor in terms of design.

    How would you guys do this?

    The code is in Python, by the way.

    First of all, the typical OO solution to that kind of problem (having an object that persists across multiple calls of a function) would be to wrap the whole thing--or at least most of it--in a class. Then your initialize function would check to see if your file exists, open up the file, and dump the info into a class variable. Since that variable is at the class rather than function scope, it would persist across multiple calls of a function.

    Second of all, for this particular problem, you might want to look into a nosql solution like MongoDB. Depending on what exactly you're doing with your dicebot that might be a bit overkill, but probably worth looking into for future reference anyway.

    The problem with the first thing is that I don't necessarily want to create it, and it seems inelegant to have a massive class with subobjects that I'm maybe not going to use. At that point it's barely different from a global variable, right?

    I will check those in 2. Though yeah, probably total overkill :P

    If it's very complicated, it's probably worthwhile to just do a class that represents characters, and handle individual updates there.

    My idea was to have a class that represents a given game campaign and has a bunch of separate character accounts (which are their own class) in a list, which handles everything, so mostly I would just need to put that in the right spot so it persists. It sounds like, if I don't want to repeatedly open files, I should make a collection of these and put them in the main thread.

  • This content has been removed.

  • PhyphorPhyphor Building Planet Busters Tasting FruitRegistered User regular
    The only real problem with that design up to thousands of accounts and tens of queries per second is that data integrity might be an issue if your power goes out mid-write, and most filesystems will start by truncating the file and overwriting. You'll want to write the modified data out into a new file and then delete/rename

  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    The forums don't even use https

    It gives me the Heebie jeebies

  • ShivahnShivahn Unaware of her barrel shifter privilege Western coastal temptressRegistered User, Moderator mod
    Phyphor wrote: »
    The only real problem with that design up to thousands of accounts and tens of queries per second is that data integrity might be an issue if your power goes out mid-write, and most filesystems will start by truncating the file and overwriting. You'll want to write the modified data out into a new file and then delete/rename

    I was planning on that anyway - to a degree I'm overengineering this on purpose, so that I can learn more while doing it.

    Like the addition of separate threads for handling console and socket input worked well, but it was totally just an excuse to get myself used to designing multithreaded programs.

  • Solomaxwell6Solomaxwell6 Registered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    Yes, but then you'd have to use javascript, so it's still kind of a losing proposition for you.

  • redxredx I(x)=2(x)+1 whole numbersRegistered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    I always wanted to do a dynamic signature, which not only returned the user's IP address would check the current users page to narrow down the possibilities until it could assocate a user with an IP address.

    They moistly come out at night, moistly.
  • Donkey KongDonkey Kong Putting Nintendo out of business with AI nips Registered User regular
    facebook.gif

    Thousands of hot, local singles are waiting to play at bubbulon.com.
  • ElkiElki get busy Moderator, ClubPA Mod Emeritus
    ugggghhhh

    smCQ5WE.jpg
  • NecoNeco In My Restless Dreams Registered User regular
    OMG this John Oliver bit about sex ed

  • MrMisterMrMister Jesus dying on the cross in pain? Morally better than us. One has to go "all in".Registered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    still in gratitude for helping me catch the cheating cheater who cheated

    you were as become death, destroyer of GPAs

  • redxredx I(x)=2(x)+1 whole numbersRegistered User regular
    Elki wrote: »
    ugggghhhh

    I know.

    I can't login either.

    and it's crazy cuse facebook is like never down.

    They moistly come out at night, moistly.
  • descdesc Goretexing to death Registered User regular
    Watching Halo 5 making of videos

    I am not even a Halo guy and yet I want to buy into the hype Just because

  • Hi I'm Vee!Hi I'm Vee! Formerly VH; She/Her; Is an E X P E R I E N C E Registered User regular
    MrMister wrote: »
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    still in gratitude for helping me catch the cheating cheater who cheated

    you were as become death, destroyer of GPAs

    Wait what

    I want to hear this story.

    vRyue2p.png
  • AresProphetAresProphet Registered User regular
    facebook.gif

    seems legit

    ex9pxyqoxf6e.png
  • P10P10 An Idiot With Low IQ Registered User regular
    javascript is a tool for evil

    Shameful pursuits and utterly stupid opinions
  • Apothe0sisApothe0sis Have you ever questioned the nature of your reality? Registered User regular
    MrMister wrote: »
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    still in gratitude for helping me catch the cheating cheater who cheated

    you were as become death, destroyer of GPAs

    Deetaaaails

  • TehSlothTehSloth Hit Or Miss I Guess They Never Miss, HuhRegistered User regular
    Shivahn wrote: »
    Shivahn wrote: »
    Shivahn wrote: »
    Hey programmy people - I have a question

    I am adding functionality to my IRC dicebot that will allow persistent tracking of individual's experience, money, and items (which I'm calling a character account). The way the bot is set up is that it has a thread listening on a socket for input which uses a queue to pass to a master thread, which handles the input. If the socket input is a private message, it executes the private message handling logic.

    Now, all actual interaction with the character accounts will therefore be in the private message function, as any requests to change around variables will be received there. The problem, then, is that I want an account to persist once opened, because it's being saved to a file and it'd be really stupid to receive "add ten dollars to desc's account" and then open a file, read it all into memory, fiddle with desc's bits, write the changed file, and send the message "you have successfully fiddled with desc's bits." So I would like the first call to have to be either "create" or "open," and calls afterwards all work on an object in memory.

    Is there a way to do this? The main issue is that, since it's inside of a function, I can't really create an object and have it persist. Global variables are not great practice. I guess I could have a thread run on any given account, and use a SEPARATE queue to communicate with the master thread, but that seems extremely poor in terms of design.

    How would you guys do this?

    The code is in Python, by the way.

    First of all, the typical OO solution to that kind of problem (having an object that persists across multiple calls of a function) would be to wrap the whole thing--or at least most of it--in a class. Then your initialize function would check to see if your file exists, open up the file, and dump the info into a class variable. Since that variable is at the class rather than function scope, it would persist across multiple calls of a function.

    Second of all, for this particular problem, you might want to look into a nosql solution like MongoDB. Depending on what exactly you're doing with your dicebot that might be a bit overkill, but probably worth looking into for future reference anyway.

    The problem with the first thing is that I don't necessarily want to create it, and it seems inelegant to have a massive class with subobjects that I'm maybe not going to use. At that point it's barely different from a global variable, right?

    I will check those in 2. Though yeah, probably total overkill :P

    If it's very complicated, it's probably worthwhile to just do a class that represents characters, and handle individual updates there.

    My idea was to have a class that represents a given game campaign and has a bunch of separate character accounts (which are their own class) in a list, which handles everything, so mostly I would just need to put that in the right spot so it persists. It sounds like, if I don't want to repeatedly open files, I should make a collection of these and put them in the main thread.

    I would offload actually storing the data to something totally different -- I think that should be outside the scope of your bot. You could offload it to a sqllite server or something like Redis which is pretty much designed for this and is much hipper.

    FC: 1993-7778-8872 PSN: TehSloth Xbox: SlothTeh
    twitch.tv/tehsloth
  • MrMisterMrMister Jesus dying on the cross in pain? Morally better than us. One has to go "all in".Registered User regular
    MrMister wrote: »
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    still in gratitude for helping me catch the cheating cheater who cheated

    you were as become death, destroyer of GPAs

    Wait what

    I want to hear this story.

    Donkey Kong--and this is a real thing that actually happened--looked at a string of garbage characters and said "oh, yeah, I recognize that; it's what you get when you force open a certain type of image file in text-editor"
    neo_matrix_code.jpg?w=650

  • Solomaxwell6Solomaxwell6 Registered User regular
    I would be perfectly fine with going back to totally static webpages if it meant we could get rid of Javascript. We can get rid of CSS, too, I never liked it all that much.

  • MrMisterMrMister Jesus dying on the cross in pain? Morally better than us. One has to go "all in".Registered User regular
    Also, there were other things wrong with the document but that was the real come to jesus moment

  • NecoNeco In My Restless Dreams Registered User regular
  • Donkey KongDonkey Kong Putting Nintendo out of business with AI nips Registered User regular
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    Yes, but then you'd have to use javascript, so it's still kind of a losing proposition for you.

    In javascript, inside anonymous functions, the "this" keyword refers to the object calling the function, not the scope in which it was created.

    In fact, scope is so sketchy in javascript that if you create a collection of anonymous functions inside of a for loop, for example, to process different pieces of data, every single one will process the last piece of data. Because scope only operates at a function-level and so all the anonymous functions share the same variable space owned by the enclosing function.

    I have used javascript long enough that it can no longer hurt me because I am already dead.

    Thousands of hot, local singles are waiting to play at bubbulon.com.
  • ShivahnShivahn Unaware of her barrel shifter privilege Western coastal temptressRegistered User, Moderator mod
    TehSloth I'm watching a thing with Ell but may ask a q later

  • Solomaxwell6Solomaxwell6 Registered User regular
    MrMister wrote: »
    MrMister wrote: »
    If the forums allowed embedding javascript directly into posts, I would be like a god. And have all of your login credentials.

    still in gratitude for helping me catch the cheating cheater who cheated

    you were as become death, destroyer of GPAs

    Wait what

    I want to hear this story.

    Donkey Kong--and this is a real thing that actually happened--looked at a string of garbage characters and said "oh, yeah, I recognize that; it's what you get when you force open a certain type of image file in text-editor"
    neo_matrix_code.jpg?w=650

    Please take my document homework1.docx.exe

This discussion has been closed.