Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
N

NickHighIQ

@NickHighIQ
About
Posts
14
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Job Application Test from Hell
    N NickHighIQ

    First thing's first, the order. It appears to be grouped by Region, the groups are ordered by MIN(Contact) (assuming MIN/MAX works in the way I expect, i.e. SELECT MAX('a', 'z') would return 'z' - never had to do an aggregate over varchar fields, thank GOD) and then ordered by Contact ascending. Thought process: Durban, JBurg, Cape Town - no obvious ordering there, but they're grouped... John, Mary - alphabetical Anna, Fred, Joe - alphabetical John, Frank, Anna - alphabetical (desc), so the earliest name in the alphabet in each region is used to order the regions... So, here's the SQL (SQL Server 2008):

    SELECT
    Region, Contact
    FROM
    TheStupidestTableEver
    ORDER BY
    MIN(Contact) OVER(PARTITION BY Region) desc, Contact

    Results:

    Region Contact

    Durban John
    Durban Mary
    Johannesburg Frank
    Cape Town Anna
    Cape Town Fred
    Cape Town Joe

    So, do I win a prize? ;P In fact, I don't need one, that was a satisfying problem to solve :-D

    The Lounge database question career

  • Convert Word doc to Byte
    N NickHighIQ

    I thank you for your advice, but the number of answers someone has posted on an arbitrary forum has no bearing on their ability to be helpful. The fact that you, also a prolific poster, called the OP an idiot makes me doubt even more the validity of the equation of contribution to helpfulness. All I'm saying is be helpful rather than treat him like a fool, something I've seen Luc do on more than one occasion, so I'm guessing it's not just that he's had a bad day. I've had the joy of working for programmers of many years' experience who took delight, it seemed, in making me feel like an invalid when I didn't know, or was unaware of, some dark corner of the world of software engineering - I know how it feels. It's not a good feeling. I will admit I did get a bit hot under the collar, and I apologise for this - I've just seen this so many times (especially considering my whopping 3 years of commercial experience) that I have trouble letting it lie.

    C# html data-structures question

  • Convert Word doc to Byte
    N NickHighIQ

    Well, this is what I take objection to:

    "That is completely wrong. Do you have any idea what Base64 is?"

    And after a completely dignified and calm response (which I wouldn't have afforded you):

    "No. You are not using it in the wrong way. It is wrong for you to use base64 at all."

    I don't know about you, but where I'm from that's very belittling and seems like someone trying to assert to everyone just how clever and knowledgeable they are. Apologies if that was not your intention, but it seems very much that way to me. Regardless, why not point him to the documentation? Not everything is "elementary knowledge", and that includes the labyrinth of MSDN. Also, Google is not very helpful if you don't know what you're after. If you are so frustrated with people not providing enough information for you to correctly answer their question, better you not reply at all then make them feel stupid. I suggest you read the sticky post "HOW TO ANSWER A QUESTION" (although, given your knowledge of systems 30+ years old, I should think you would know how to answer a question): "If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome." I believe that includes sideline insults, like yours - while not directly calling him an idiot you might as well have.

    C# html data-structures question

  • Convert Word doc to Byte
    N NickHighIQ

    Base64 is a number system - normal numbers like 1, 2, 3 are decimal or Base10, binary is Base2 etc.

    Byte[] b = Convert.FromBase64String(attach.Body);

    This would make sense IF "attach.Body" was in fact a Base64 string. Base64 still confuses me dude, so don't let Luc Pattyn make you feel bad for not being born with the intrinsic knowledge of Base64 and its use, as he must have been in order to provide him the right to speak to someone like that (I think a swing at his demeaning tone is fair enough, don't you ;) ). What type is the attach.Body property, is it a just a basic System.String? If you want to convert a string into a byte array, there are plenty of ways to do it, and it's something that comes up often (and I can NEVER remember how to do it). It also depends on the type of encoding you want. In the System.Text namespace there are several Encoding classes: I usually use ASCIIEncoding:

    string myText = "Hello world!";
    ASCIIEncoding enc = new ASCIIEncoding();
    byte[] dataBuffer = enc.GetBytes(myText);

    There is also the UTF8Encoding class I can think of off the top of my head. The type of encoding you use does matter! Having said all this, it seems like you're doing something odd. Can you explain to me what your actual intention is with "converting the html formatted word document into a Byte array"? What do you want to do that for? And then you said later that you wanted to save these files out to a directory. If I was you, I would do something like this:

    using (var fileStream = new FileStream("theNewFileName.txt", FileMode.Create)
    {
    using (var streamWriter = new StreamWriter(fileStream)
    {
    streamWriter.Write(attach.Body);
    }
    }

    Using the StreamWriter class, you can interact at a higher level and use strings rather than byte arrays - much clearer and simpler code IMHO. Does this help?

    C# html data-structures question

  • generating random number
    N NickHighIQ

    However, remember that there's no such thing as bad questions, only bad answers, and everyone's prone to giving them. No need to be upset or insult someone when they don't understand you, simply ask how you can help to further explain yourself :) Keep in mind there's not much resolution when it comes to voting on answers, it's either "good" or "bad", no in-between. There should be another button "I don't get it", "please explain" or simply "Pauline Hanson" (Australian political reference).

    Algorithms tutorial question lounge

  • generating random number
    N NickHighIQ

    I don't understand what you mean, Luc. Could you explain your comment?

    Algorithms tutorial question lounge

  • generating random number
    N NickHighIQ

    No worries mate, you could extend option B to do this every 1000, 5000, 10000 etc. iterations. Just as long as you can divide up your selectors wholly between each group, you're home and hosed! Hope I helped, again, if you would like more explanation or an example, just email me or post again :)

    Algorithms tutorial question lounge

  • generating random number
    N NickHighIQ

    Sorry mate, I replied under Luc's post - come check out the page, I've answered your question (I hope!) :)

    Algorithms tutorial question lounge

  • generating random number
    N NickHighIQ

    "option b is impossible, unless the number of runs is a multiple of 10" - then it's not really impossible, is it? :laugh: @fzml Option A: Ok, for Option A, Luc's solution is what I'd go with (in fact I can't think of another way off the top of my head, at least one that's not contrived). Assume we have two sets of numbers, A and B. We want 30% chance of selecting something from A, and 70% chance of selecting something from B: in pseudo-C#, something like:

    Random rnd = new Random();

    int selector = rnd.Next(1, 10);

    if (selector <= 3) { // select something from the A group }
    else { // select something from the B group }

    As you can see, the rnd.Next has 10 possible outputs (1, 2, 3 ... 10) - we assign 30% of those, i.e. 1 through 3, to our 30% group. The rest make up the 70% for the other group. If we wanted 3 groups with (A: 20%, B: 50%, C: 30%):

    Random rnd = new Random();

    int selector = rnd.Next(1, 10);

    if (selector in {1, 2}) { // select something from the A group }
    else if (selector in {3, 4, 5, 6, 7}) { // select something from the B group
    else { // select something from the C group }

    By splitting a known number of outcomes up like this, you can have "pre-determined probabilities". Of course, this all relies on the soundness of the Random generator you're using. If you would like to write your own, there's heaps of literature out there on the web about RNGs (check out the Mersenne Twister). Option B: Well, Option B (forgive me if I get the wrong terminology here) is about creating a pseudo-random number generator, with period of x, that selects members randomly from different sets based on enforced probabilities. Ok, well let's say you have two sets A and B:

    A = { 1, 2, 3, 4 } // we want EXACTLY 30% of our answers to come from here
    B = { 5, 6, 7, 8 } // we want EXACTLY 70% of our answers to come from here

    You need to set a "period", that is, what number of interations will satisfy the exactness of our probabilities (for example, up until now we have assumed 100 iterations will satisfay the probabilities). So, let's say we pick 100 - that means every 100 iterations, we can look at our results and say for sure that 30% of these will be from A and the rest from B. A very simple way, based on Option A, would be (pseudo-code):

    Algorithms tutorial question lounge

  • Goal finding: I just need the name of an algorithm
    N NickHighIQ

    I'm sure A* would work - all it requires is to know if a neighbouring tile is walkable or not, and then a cost for moving there. (Sidenote: you could substitute this for simply assigning a cost to moving across each tile and make impassable obstacles have infinite cost?) Anyway, here's a good A* link: http://www.policyalmanac.org/games/aStarTutorial.htm This is 8-directional, but it will work exactly the same in 4-directional.

    Algorithms algorithms help question

  • generating random number
    N NickHighIQ

    Ok, someone has already asked this question of you, but I need some clarification. When you say "generate a number which is in group A for 30% of time", do you mean: a. Every iteration there is a 30% chance that the number will come from group A b. If I do 100 iterations, 30 of these numbers will definitely be from group A These two interpretations are very different and will require different solutions, so I need some clarification before helping you further. :cool:

    Algorithms tutorial question lounge

  • Corruption of 'English' as she is spoke
    N NickHighIQ

    'then/than' - "12 is bigger THEN 10." (:mad:) "I don't recall having seen a native speaker make that mistake" ( :laugh: ) You're joking, right? Then/than, here/hear, your/you're, there/their/they're, "I would of" vs. "I would have" and misuse of possessive apostrophes are my biggest pet hates, and it is very surprising, irrespective of age, how many people just have no clue whatsoever about these things. I correct people's ineffective use of English way too often. A self-certified grammar Nazi, that's me :) I don't understand how people can simply not care about incorrect spellings, conjugations or poor use of grammar. It drives me nuts, but most people couldn't care less. Another thing we can blame on Microsoft - spell-checker. :laugh:

    The Lounge csharp design question

  • Corruption of 'English' as she is spoke
    N NickHighIQ

    Haha, damn! You beat me to it! I was like, totally just about to do that. :laugh:

    The Lounge csharp design question

  • Kids I've Got Some News For You...
    N NickHighIQ

    I'm sorry, I understood almost none of that due to your revolting use of the English language. Please learn a language before you decide to slaughter it on an international stage. Oh, and maybe it might pay to share your deepest feelings with someone you know and trust - talk about 'real stuff' with real people (not that the people on the Internet aren't real, it's just that most of our communication is achieved through speech and body-language; words aren't always enough, and to beat my ol' war drum again, that's why your written word must be excellent - that way giving you the highest chance of being understood). As you said yourself, a half-decent slab of AI could reproduce this forum. I would think that by making that statement you invalidate your own purpose in being here or ranting in the first place. Appealing to a computer to share its knowledge and talk about won't get you very far. "That's the stuff that made us all closer." Although mateship and empathy for the losses of others is a noble trait, that's creepy Internet-stalker shit. I don't know who you are, you don't know who I am, our parents have never met nor have I or you been in the other's house - even a 4 year old could tell you that means you're a stranger. You don't share personal information with strangers! "I loved reading about Shogs trips through the mid-west to visit family." Again, others' stories can provide useful insight into unknown territories, but stories don't last forever. Why not go make some of your own? My point is that the world might as well be infinitely large when juxtaposed with the scope of an average human life. Go and explore some of that instead of sitting around the 'poisoned waterhole' drinking yourself to death and whining about it the whole fucking time! I hate it when people whine about their own predicament when they're the one best suited to changing it. P.S. I quite enjoy CodeProject, personally. P.P.S. This time, the OP did come off as a total dick P.P.P.S. Have a great day! :-D

    The Lounge question graphics json discussion announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups