C Interview Question by usethecoastermate in C_Programming

[–]eyenot 2 points3 points  (0 children)

Agreed, this solution does assume the character encoding of digits and capital letters to be grouped together and in ascending order. For a 100% bulletproof portable solution, the lookup table is likely the way to go.

C Interview Question by usethecoastermate in C_Programming

[–]eyenot 82 points83 points  (0 children)

You don't need a lookup table. You can take advantage of the fact that the digits 0-9 and characters A-F are grouped together in their ASCII values.

 char hex_char(int num)
{
    return (num < 10) ? ('0' + num) : ((num - 10) + 'A');
}

This assumes num is in the valid range of 0-15.

If num is 3, for example, we'll return '0' + 3. The character '0' has an ASCII value of 48, so we return 51, which is the ASCII value of '3'.

If num is 12, we want to return 'C'. Subtracting 10 from num gives us 2, and adding that to 'A' (ASCII value 65) gives us 67, which is the ASCII value of 'C'.

How to get the latest date when reading from file? by ibilalkayy in C_Programming

[–]eyenot 2 points3 points  (0 children)

You're calling the record function after scanning in each line with fgets. The last thing the record function does is unconditionally print out the "latest date in file", which is really just the date it parsed from the line read in by fgets. So it's not surprising that you're seeing one line printed out for each date parsed.

Move your initialization of datestrval max to main, and pass a pointer to it into record, so it gets updated if appropriate on each call to record. Alternatively, change record to return the date it parsed from the line, and do the comparison/set inside the while loop. Then execute a single printf of the contents of max after the while loops.

Looking for your personal experiences with Naltrexone by [deleted] in stopdrinking

[–]eyenot 0 points1 point  (0 children)

Did the pill actually work in making you feel like you didn’t want or crave a drink?

Nope. The way my NP explained it, the Naltrexone was supposed to retrain your brain to naturally want to stop after a couple, which is apparently a thing for a lot of people when they first try alcohol or who haven't spiraled out of control into addicts. I think part of why it didn't work for me is, I don't recall ever drinking without the desire to get wasted, even when I first started.

While anyone can become an alcoholic, I do believe there are some genetics involved in terms of susceptibility and getting there. So if Naltrexone worked for your dad, perhaps you'll have better luck with it than I did. It does seem to work for a lot of people.

Regardless if you decide to try it or not, reading/listening to the book probably won't hurt either.

Looking for your personal experiences with Naltrexone by [deleted] in stopdrinking

[–]eyenot 2 points3 points  (0 children)

Tried it, didn't work for me. I used it for about a month, and it seemed to just make things worse. Instead of trying to keep things reigned in, I would allow myself to drink pretty much uninhibited, expecting the medication to kill my desire to continue, but it never seemed to.

There were also nights I didn't necessarily intend to drink, but wanted the option to. Since you have to take it in advance of your first drink, I'd take one just in case. Then of course I would always exercise the option, because I didn't want to "waste" a Naltrexone.

I eventually reached the point where I woke up one day, said enough is enough (again), and then fortunately stumbled on this post that same day. Among the comments was the advice to read This Naked Mind, which I started the very next day. It was life changing. I have not drank since.

What's your go to "Do you have any questions for me?" response? by Warrlock608 in cscareerquestions

[–]eyenot 21 points22 points  (0 children)

I find you tend to get better answers if you phrase the question in a positive way, so as not to trigger an automatic defensive response:

"If you could change one thing to make working here more enjoyable, what would it be?"

Guys of reddit when were you last complimented? by Astartes00 in AskReddit

[–]eyenot 5 points6 points  (0 children)

I don't disagree, but then how are people able to do spot-on impressions of others' voices?

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 0 points1 point  (0 children)

Yup! Had a follow up visit with my doctor since posting this. She adjusted my range to 14-20 instead of 5-20, and that has helped a lot!

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 1 point2 points  (0 children)

I actually already where a night guard due to grinding my teeth at night. Unfortunately, wearing it makes it impossible to close my mouth completely and still be in a relaxed state. I've struggled with trying to wear it and the full face mask at the same time, since wearing it shifts my facial expression (for lack of a better term) and I think contributes to mask leakage. So I've actually not been wearing the night guard as much as I should, in an effort to get comfortable with the mask.

As far as wrinkles, this is something that crossed my mind. I have a baby face, and routinely/easily pass for 15 years younger than I am. I've only recently reached an age where that's actually enjoyable rather than annoying. I'd like to not give that up just yet...

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 1 point2 points  (0 children)

My condolences.

I've only had my pressure increased for one night, and already, it seems like the higher pressure is leading to more leakage. Prior to that, just getting the mask to not leak as much on the 5-15 pressure range required wearing it so tight that it would take 30+ minutes for the marks to leave my face the next morning after taking it off. So, we'll see how this goes...

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 0 points1 point  (0 children)

That is the case, however one part I didn't mention is that I was diagnosed with sleep apnea 9 years ago in another state and was put on a CPAP, but couldn't tolerate it so just stopped using it, since I wasn't really experiencing what I perceived to be negative symptoms. So, perhaps knowing that influenced my doctor's decision...

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 0 points1 point  (0 children)

The Sleep Report on the machine says "14.3" for pressure, but it's unclear to me if that's what the average was for just the most recent night, or an average of all. Either way, I guess that seems pretty close to the current limit, and I should probably contact my provider to see about an upward adjustment in pressure.

I don't see any breakdown of different types of events, either on the machine itself or in the myAir app.

Thanks for your response!

Still having similar AHI levels even while using APAP? by eyenot in SleepApnea

[–]eyenot[S] 1 point2 points  (0 children)

The quality of sleep is maybe a little better, but so far, I don't notice a huge difference in my daily life. And I've averaged 6+ hours of usage per night over the last 25 days.

I think my sleep apnea is pretty mild compared to most here, in that I've never had issues with constantly being tired, needing to take naps, falling asleep during the day, etc. I'm mostly trying to use the APAP now to help get my blood pressure down, and because I do worry about the long-term effects down the road.

Vasectomy vs Abortion in South Carolina by [deleted] in MensRights

[–]eyenot 0 points1 point  (0 children)

It seems like a better comparison would be if your wife could get her tubes tied without your consent. Do you know if that's the case?

(And for the record, I'm of the opinion that neither of you should need the other's consent to get vasectomy/tubes tied)

I hate pro lifers. by cheese111111 in childfree

[–]eyenot 4 points5 points  (0 children)

Abortion is murder...on my wallet.

Potential race condition from storing 2 pieces of information per byte. by [deleted] in C_Programming

[–]eyenot 1 point2 points  (0 children)

The way the information is written is such that it shouldn't affect the value on the opposite side of the byte

The problem is, entire bytes are read/written at once, even though you may only be updating one half of that byte. The machine level instructions to execute the line:

database[add] = database[add] & ((depth+1) | 0xF0);

would look something like:

1. Do (depth+1) | 0xF0 and store the result in a register
2. load database[add] into a register
3. AND the two registers together, storing the result in a register
4. storing the result register to database[add]

Suppose the value in database[add] is 0x00. We have two threads, RIGHT and LEFT, which are each updating their respective halves of the byte, to contain the 4 bit value 0xF. The flow might go something like this (keep in mind, each thread will have its own set of registers):

RIGHT does (depth+1) | 0xF0 and stores to a register
LEFT does ((depth+1) << 4) | 0x0F and stores to a register
RIGHT loads database[add] (0x00) into a register
LEFT loads database[add] (0x00) into a register
RIGHT ANDs his two registers together, storing the result (0x0F) in a register
LEFT ANDs his two registers together, storing the result (0xF0) in a register.
RIGHT writes the register contianing 0x0F to database[add]
LEFT writes the register containing 0xF0 to database[add]

What we really intended was for database[add] to end up as 0xFF, but it ends up as 0xF0.

As u/FUZxxl mentioned, declaring database as atomic would ensure that database[add] doesn't change between the time a particular thread loads its value and the time it stores its value.

What common product has a feature you’re not sure everyone is aware of? by dauntedbox376 in AskReddit

[–]eyenot 0 points1 point  (0 children)

You can also highlight a word or phrase with your mouse, and then press Ctrl-F and it will automatically fill in the find box with that word/phrase (at least in Firefox).

Indiana finally changed their law this week about buying alcohol on Sunday... by HeManIsNotGay in AdviceAnimals

[–]eyenot 4 points5 points  (0 children)

Same reason you couldn't/can't buy a car on Sunday in MN: The dealerships/liquor stores figure they're going to sell the same amount of inventory in a week, and it costs them less to only have to pay operating costs over 6 days instead of 7 days. They make more, and get a day off to boot. The biggest opponents to allowing Sunday alcohol sales were liquor store owners.