The Geeks Daily

OP
sygeek

sygeek

Technomancer
Did You Hear We Got Osama?
By Roshan Choxi​
I think I got my first computer in 2004 when I went to a boarding school in Illinois. The thing that really blew my mind about it was the unlimited amount of information that I just wished I could absorb into my brain. ”I’m going to know everything there is to know,” I told myself as I subscribed to The New York Times, The Economist, Wall Street Journal, Wired, and at least a dozen other blogs on Google Reader. Politics, economics, science, whatever your choice of topic was I would never be caught uninformed.

It’s only in hindsight that I see what felt like self improvement at the time was actually the beginning of a terrible addiction. It got overwhelming really fast. I added filters, I tried a dozen different RSS readers, I even learned to speed read over the course of a few years just to keep pace with my reader. This was serious business. How would I keep up to date with the Human Genome Project and Bush’s latest folly if I started slacking on my Reader queue? Over time, I’d get better at reading quickly to the point where I was just skimming headlines. Technology would improve so I could consume news within a 140 character limit and stash the important items to “Read it Later”.

*roshfu.com/images/ConsumerWhore.jpg​
(Image from Don Hertzfeldt's "Rejected")​

My freshman year of college, Obama was running for president and the murmurings of the debt crisis had begun. Despite the 20-30 articles I consumed every day and the catch phrases I learned to repeat in front of my friends to sound knowledgable, I still had no idea what was actually going on.

I turned 18 and chose not to vote that year. I got less and less vocal about my political opinions. And, most importantly, I phased out the majority of my RSS reader. Goodbye to Wired, The Wall Street Journal, The New York Times, The Economist, and Google News. I was ready to see what would happen if I turned it all off and embraced not knowing anything about current events and the world at large.

What followed were the most productive three years of my life.

That’s when I learned an important truth about news. Whether it’s TechCrunch, The New York Times, Wired, or Fox News: their job isn’t to educate or inform you, it’s to entertain you. You’re not reading them because you think you’ll be more knowledgable and informed, you’re reading them because you want to be distracted – because consuming has a more immediate reward than creating.

Did you guys hear about the Path scandal? Did you know Kickstarter is completely changing the fundraising landscape? “That’s just tech gossip, I don’t read the gossip,” you might say. Well what about the 30 articles that come up each day about how to do do X better? It doesn’t even matter if each of those posts had a fantastic message, do you really think your reading an article can replace the deliberate effort it takes to do anything better?

Say that you somehow didn’t know we found and killed Osama Bin Laden last year, I claim that your life would be virtually the same if you did. What if you didn’t even know who the current president was? Besides for the social embarassment, would your day-to-day be any different? If you followed the news daily, when it came time to cast your ballot could you convince yourself that you’re making an informed vote and not just one based on questionable media factoids and the dogma of your closest social circle?

But this post isn’t about politics, it’s about noise
. I realize there’s some irony in the medium of this message being a blog post. I’m not advocating that you pack up canned beans and a Snuggie and go off the grid, just turn down the noise in your life. I’ve gotten my sources of consumption (I don’t even call it “news” anymore) down to just HackerNews, and I probably check it twice a day on average and only read one or two posts. You may not be impressed, but for me chopping my consumption down from 50 tweets, 10 blog posts, 15 news articles, and a couple dozen Facebook posts to just two HackerNews posts took effort and time.

Give it a try. You’ll be surprised how much of the world you can tune out with no negative side effects.
 

aaruni

The Linux Guy
Recently, after being awake for longer than I should have, I started thinking about methods of remembering the number of days in each month of the year. There is a rhyme for it, and a way to count on your knuckles, but these didn’t satisfy me. I wondered if there was a mathematical formula for the problem, and upon not immediately finding one, I challenged myself to create one.

Put more formally In other words, the challenge was this: find a function f, such that f(x) is equal to the number of days in month x, represented by the integers 1 through 12. Or, as a table of values:[SUP]1[/SUP]

Saw that on reddit sometime back. Didn't have the time to read it full. You have the link to the solution ?
 

Vyom

The Power of x480
Staff member
Admin
Insert number of month in A1 in excel sheet and this formula in any other cell:
Code:
=28+MOD((A1+FLOOR(A1,8)),2)+MOD(2,A1)+2*FLOOR(1,A1)

Source: A Formula for the Number of Days in Each Month · Curtis McEnroe
 
OP
sygeek

sygeek

Technomancer
Saw that on reddit sometime back. Didn't have the time to read it full. You have the link to the solution ?
oops, sorry. I accidentally posted it. Post is still in draft.

- - - Updated - - -

A Formula for the Number of Days in Each Month
Curtis McEnroe​
Recently, after being awake for longer than I should have, I started thinking about methods of remembering the number of days in each month of the year. There is a rhyme for it, and a way to count on your knuckles, but these didn’t satisfy me. I wondered if there was a mathematical formula for the problem, and upon not immediately finding one, I challenged myself to create one.

Put more formally In other words, the challenge was this: find a function f, such that f(x) is equal to the number of days in month x, represented by the integers 1 through 12. Or, as a table of values:[SUP]1[/SUP]
x123456789101112
f(x)312831303130313130313031

If you want to give this challenge a go before reading my solution, now is your chance. If you’d rather see my complete solution right away, scroll to the bottom of the page. What follows is my process for solving the problem.

The Tools
Firstly, here’s a quick refresher on two operations I found vital to solving the problem: floor division and modulo.

Floor division is the operation performed by many programming languages when dividing two integer numbers, that is, the result of the division is truncated to the integer part. I will represent floor division as ⌊[SUP]a[/SUP]⁄[SUB]b[/SUB]⌋, for example:
⌊[SUP]5[/SUP]⁄[SUB]3[/SUB]⌋ = 1

Modulo is an operation that results in the remainder of a division. It is represented in many programming languages with the % operator. I will represent it as a mod b, for example:

3 mod 2 = 1

Note that modulo has the same precedence as division.

The Basics
With those tools in mind, let’s get a basic pattern going.2 Months usually alternate between lengths of 30 and 31 days. We can use x mod 2 to get an alternating pattern of 1 and 0, then just add our constant base number of days:

f(x) = 30 + x mod 2

x123456789101112
f(x)313031303130313031303130

That’s a pretty good start! We’ve already got January and March through July done. February is its own special problem we’ll deal with later. The problem after July is that the pattern should skip one, and the rest of the months should follow the alternating pattern inversely.

To obtain an inverse pattern of alternating 0 and 1, we can add 1 to our dividend:

f(x) = 30 + (x + 1) mod 2

x123456789101112
f(x)303130313031303130313031
Now we have August through December right, but the rest of the year is wrong as expected. Let’s see how we can combine combine our two formulas.

Masking
What we need here is basically a piece-wise function, but that’s just no fun. This got me thinking of other ways to use a part of a function only over a certain domain.

I figured the easiest way to do this would be to find an expression equal to 1 over the desired domain and 0 otherwise. Multiplying a term by this expression will result in the term being cancelled out outside its domain. I’ve called this “masking,” since it involves creating a sort of bit-mask.

To mask the latter piece of our function, we need an expression equal to 1 where 8 ≤ x ≤ 12. Floor division by 8 is perfect for this, since all our values are less than 16

x123456789101112
⌊[SUP]x[/SUP]⁄[SUB]8[/SUB]⌋000000011111
Now if we substitute this expression in our x + 1 dividend, we can invert the pattern using our mask:

f(x) = 30 + (x + ⌊[SUP]x[/SUP]⁄[SUB]8[/SUB]⌋) mod 2

x123456789101112
f(x)313031303130313130313031
Woot! Everything is correct except February. What a surprise.

February
Every month has either 30 or 31 days, but February has 28 (leap years are out of scope).[SUP]3[/SUP] February currently has 30 days according to our formula, so an expression equal to 2 when x = 2 would be ideal for subtraction.

The best I could come up with was 2 mod x, which gives us a sort of mask over every month after February.

x123456789101112
2 mod x002222222222
With this, we’ll need to change our base constant to 28 so that adding 2 to the rest of the months will still be correct.

f(x) = 28 + (x + ⌊[SUP]x[/SUP]⁄[SUB]8[/SUB]⌋) mod 2 + 2 mod x

x123456789101112
f(x)293031303130313130313031

Unfortunately, January is now 2 days short. Luckily, finding an expression that will apply to only the first month is easy: floored inverse of x. Now just multiply that by 2 and we get the final formula:

f(x) = 28 + (x + ⌊[SUP]x[/SUP]⁄[SUB]8[/SUB]⌋) mod 2 + 2 mod x + 2 ⌊1⁄x⌋

x123456789101112
f(x)312831303130313130313031

Conclusion
2014-12-06: Hello, Internet. This is tongue-in-cheek. Why would anyone use this?

There you have it, a formula for the number of days in each month using simple arithmetic. So next time you find yourself wondering how many days are in September, just remember to apply f(9). For ease of use, here’s a JavaScript one-liner:

Code:
function f(x) { return 28 + (x + Math.floor(x/8)) % 2 + 2 % x + 2 * Math.floor(1/x); }
 
Last edited:

Vyom

The Power of x480
Staff member
Admin
^^ OMG. We thought Sygeek is actually trying to find the formula. So I googled and came up with the exact article, that Sygeek was intended to post initially! :D
 
OP
sygeek

sygeek

Technomancer
^^ OMG. We thought Sygeek is actually trying to find the formula. So I googled and came up with the exact article, that Sygeek was intended to post initially! :D
Nah, I tried finding a solution but I just wanted to post the article first.
 

Vyom

The Power of x480
Staff member
Admin
Wow! Much Awesome Articles! Linked on One Page!
Most Popular Features and Essays of 2014
 
OP
sygeek

sygeek

Technomancer
Your statement is 100% correct but misses the entire point

Jussi
Let's assume that there is a discussion going on on the Internet about programming languages. One of the design points that come up is a garbage collector. One participant mentions the advantages of garbage collection with something like this:
Garbage collectors are nice and save a lot of work. If your application does not have strict latency requirements, not having to care about memory management is liberating and can improve developer efficiency by a lot.
This is a fairly neutral statement that most people would agree with, even if they work on code that has strict real time requirements. Yet, inevitably, someone will present this counterpoint.
No! If you have dangling references memory is never freed and you have to fix that by doing manual memory management anyway. Garbage collectors do not magically fix all bugs.
If you read through the sentences carefully you'll notice that every asserted statement in it is true. That is what makes it so frustrating to argue against. Most people with engineering backgrounds are quite willing to admit they are wrong when presented with evidence that their statements are not correct. This does not cover everyone, of course, as some people are quite willing to violently disagree with any and all facts that are in conflict with their pre-held beliefs. We'll ignore those people for the purpose of this post.

While true, that single sentence ignores all of the larger context of the issue, which contains points like the following:

  • Dangling reference out of memory errors are rare (maybe 1 in 10 programs?) whereas regular memory bugs like use-after-free, double free, off by one errors etc are very common (100-1000 in every program).
  • Modern GCs have very good profilers, finding dangling references is a lot easier than debugging stack corruptions.
  • Being able create things on a whim and just drop them to the floor makes programmers a lot more productive than forcing them to micromanage the complete life cycle of every single resource.
  • Even if you encounter a dangling reference issue, fixing it probably takes less time than would have gone to fixing memory corruption issues in a GCless version of the same app.
In brief, the actual sentence is true but misses the entire point of the comment they are replying to. This is sadly common on Internet debates. Let's see some examples.

Computer security
A statement like this:
Using HTTPS on all web traffic is good for security and anonymity.
might be countered with something like this:
That provides no real security, if the NSA want your data they will break into your apartment and get it.
This statement is again absolutely true. On the other hand if you are not the leader of a nation state or do regular business with international drug cartels, you are unlikely to be the target of a directed NSA offensive.

If you think that this is a stupid point that nobody would ever make, I agree with you completely. I have also seen it used in the real world. I wish I hadn't.

Bugs are caused by incompetents
High level programming languages are nice.
Programming languages that guard against buffer overruns is great for security and ease of development.
But not for everyone.
You can achieve the exact same thing in C, you just have to be careful.
This is again true. If every single developer on a code base is being 100% focused and 100% careful 100% of the time, then bug free code is possible. Reality has shown time and time again that it is not possible, human beings are simply not capable of operating flawlessly for extended periods of time.

Yagni? What Yagni?
There's the simple.
Processing text files with Python is really nice and simple.
And not so simple.
Python is a complete joke, it will fail hard when you need to process ten million files a second on an embedded microcontroller using at most 2 k of RAM.
Yes. Yes it does. In that use case it would be the wrong choice. You are absolutely correct. Thank you for your insight, good sir, here is a shiny solid gold medal to commemorate your important contribution to this discussion.

What could be the cause of this?
The one thing that school trains you for is that being right is what matters. If you get the answers right in your test, then you get a good grade. Get them wrong and you don't. Maybe this frame of mind "sticks on" once you leave school, especially given that most people who post these kinds of comments seem to be from the "smarter" end of the spectrum (personal opinion, not based on any actual research). In the real world being right is not a merit by itself. In any debate being right is important, of course, but the much more important feature is being relevant. That requires understanding the wider context and possibly admitting that something that is the most important thing in the world to you personally, might be completely irrelevant for the issue at hand.

Being right is easy. Being relevant is extremely difficult.
 
OP
sygeek

sygeek

Technomancer
The Cylops Child
Fredric Neuman M.D.
Probably every physician can think of one patient who affected him more than any other. The patient who has haunted me through the years was a child that I saw for only a little time at the very beginning of my career. I was an intern at a Catholic institution. I mention that because it seems to me relevant to the ethical considerations that swirled about the care of this infant. When this child was born, the obstetrician looking at it was horrified. It was a “monster.” That was the medical term used to describe a grossly misshapen baby. The doctor was concerned, then, first of all, about the effect on its mother of seeing the child. Therefore, he told the parents that it was born dead; and that the body had been disposed of. But the child was alive. This particular “monster” had deformities that were not consistent with it living for any length of time. The obstetrician must have recognized that immediately and chose to spare the parents the special anguish of looking at and knowing about this abnormal birth. But did he have the right to tell them a lie about such a critical matter? I’m not sure that there is a law to deal with such a strange situation, but I am sure the obstetrician violated medical canons. He short-circuited the parents’ wishes and concerns. Plainly, they had the right to know the truth. If a medical malpractice action had been instituted, the doctor would have been liable. By telling this lie, he was risking his career. The other people in the delivery suite were also complicit and also liable. As far as I was concerned, however, he had done the right thing.​
There are ethical rules that govern our behavior. Sometimes, they are unspoken. They go without saying. Thou shalt not lie. Thou shalt not murder. Even those peoples who have not heard of the Ten Commandments know these rules. But there are not just ten rules or commandments. As social situations change and develop, so do these rules. There are rules, sometimes codified, sometimes not, that govern how we deal with fellow-workers, elderly parents, strangers, people we communicate with over the internet, and so on. In an important sense, all the rules of courtesy are ethical rules. They grow out of a fundamental idea: that we are responsible for and answerable to other people. There are some, of course, who regard these rules as God-given and embodied in various religious texts such as the Bible or the Koran. But even those who have no religious beliefs would find themselves usually in agreement with the ethical rules embodied in these texts. Not without exception, but for the most part.​
In my opinion, these ethical rules sum to one principle: unethical behavior is behavior that hurts, or has the potential to hurt, other people. There is only one good: kindness, and one evil, cruelty. Ordinarily one does not lie, for instance, but might ethically do so if it served the purpose of helping someone, rather than hurting someone as it usually does. By this admittedly vague criterion any particular act, thievery, deceit, even murder, could be ethical. There are extraordinary circumstances when rules break down, and even the rules that govern when it is proper to break other rules, break down. At such times, an ethically driven person might entertain the idea of doing something that in almost all circumstances is forbidden. He does it usually by himself. He presumes to act even though he knows other people might condemn his actions. Doctors confront these situations sometimes. For instance, a different obstetrician, finding himself delivering a baby such as the one described above, might smother the baby before anyone had the chance to see it. Such things happen. They are not publicized because it is important to keep the rules in place. No woman wants to deliver a child thinking that the obstetrician, on his own initiative, might choose to kill the child. Most people like to think that there are no exceptions to these rules, but they are people who have not had to confront these choices themselves. It suits them to be definite. They think, what’s to stop some arrogant and idiotic person from taking it upon himself to do awful things? In that respect, they are right. I like to think that there are some who have the courage to make wise and selfless decisions, but there are others who take it upon themselves to violate these rules for no reason at all.​
For instance, earlier that same year I was making evening rounds and discovered that one woman, who was 70 years old, had not eaten or been given fluids for two days. I had a pleasant conversation with her, and then I started an I.V. The woman was a private patient of one of the attending physicians. He called me in a huff the following morning.​
“Why did you give that woman fluids? I hadn’t ordered anything.”​
“She hadn’t had anything in two days.”​
“She’s 70 years old, for God’s sake. It’s time for her to go!”​
I knew, of course, of doctors who hastened the demise of painfully, and fatally, ill patients; but this woman was not suffering. She was not senile, and she didn’t even have a fatal illness. This guy decided for whatever reason that she was old enough to die!​
When I was in medical school, the medical service at Bellevue Hospital would fill up with elderly patients who could not, for one reason or another, be placed in nursing homes promptly. They took up space that sicker patients, and more instructive patients, could be using. Mondays, following weekends when a particular resident was on call, it was sometimes discovered that one or more of these patients had died. The medical staff joked that this resident had conducted “death rounds,” meaning that he had killed them. I have no reason to believe that was so, but the fact that it could be the subject of a joke indicated that no one thought it was impossible.​
But, these situations, thankfully, are rare. How to handle them cannot be squeezed into a comfortable formula. These are situations when the conventional thing is to do one thing, and the morally correct thing is to do something different. I can tell you from personal experience that at such times the person deciding these matters feels he is the wise and enlightened person described above, and not the arbitrary and arrogant person that someone else might be.​
Let me describe the Cyclops child. It had a single fused eye in the middle of its forehead. The irises pointed to the sides. There seemed to be four lids surrounding the eye like a box. It was blind, of course. A large part of the brain and head were missing. There was no nose. On investigation, it turned out that the baby’s esophagus and trachea had not separated, so that feeding the child was impossible. The food would go directly into the lungs. Also, the child had extra fingers. It did not look like a baby. It did not even look like a doll. It was unworldly. Alien. It was, someone said, “one of God’s little jokes.”​
As an intern, I was very busy; but I looked in briefly to see this very unusual child before it died, Everyone expected its death to be imminent. In the meantime it existed in some kind of legal limbo, no name, no family. As far as the hospital went, it did not exist. But there it was.​
I rotated onto pediatrics a few days later, and the baby was still there. Still alive. Because it did not look like a human being, most of the time no one was disturbed by it; until it cried! Then it sounded like any other baby. It was hungry, and it could not be fed. Picking it up would not stop the crying. After a while, the staff spent as much time as possible on the other end of the ward. It was agonizing to me. Human beings are not constructed to listen to a crying baby and do nothing. And I felt sorry for the nurses and the rest of the staff. As the days went by without the baby dying, I began to wonder, just how long can a baby live without being fed? I did not know. Every day, when I went to the ward I hoped the baby would be dead, but it lived on.​
The resident told me during rounds that he wanted me to treat the baby’s extra fingers.​
“Why?” I said. “The baby is going to die.”​
“Well, you might as well use this opportunity as a learning experience.”​
That sort of made sense to me. I was planning to be a psychiatrist, and I did not envision ever having to treat someone’s extra fingers; but much of what I did as an intern had very little to do with psychiatry.​
The way you treat a baby’s extra fingers is to tie a ligature, a string, as tight as you can around the base of the finger. The blood supply is cut off, and after a while the finger falls off.​
When I went over to the baby, it was lying quietly in its bed. It did not object when I picked up its hand. But when I tied the ligature around its finger and pulled tightly, it screamed.​
My God, what was I doing, I suddenly thought. My hands began to shake. The kid was in pain. It could feel pain. I should have realized that, but somehow I did not. It was because the baby did not really look like a baby, I thought. I put the child down and retreated out of earshot.​
Later that day, I went to the library to look up this particular kind of birth defect. To my surprise, a number of cases had been reported previously. Most of them died within a relatively short period of time, but one Cyclops child lived for a year! I knew this baby wasn’t going to live for a year without being fed; but it was possible somebody might decide to pass a stomach tube, for the same reason I was asked to amputate its finger, for the experience. I found myself suddenly in a rage. What was the point of taking care of this baby? There was a price to be paid. Dying though it might be, the staff still had to tend to it, to change it, to clean it, to hold it in repeated attempts to comfort it. The baby was suffering, and so was everyone else. Earlier, I had caught an aide crying. A couple of nurses had stayed home that day. It was at that point that I began to think about killing the baby.​
I realized right away that there were some problems involved in killing someone, some practical problems and some psychological problems. The practical problems, in this case, involved finding a way to be alone with the child. It lay in some kind of crib off to one side on the ward, where visiting parents were not likely to see it. But it was always in plain view of the nursing station. Some of the nurses were nuns. I thought they might object on principle to my killing one of the patients. My best opportunity would have been when I was amputating his finger, but the thought did not occur to me then.​
The psychological difficulties were obvious. I did not know how anyone managed to kill anyone else. I was always afraid of hurting my patients. For that reason, I had trouble drawing blood or passing tubes. The only way I could imagine killing this baby was by putting my hand over its mouth and smothering it. Could I possibly do that? Besides, smothering leaves tell-tall signs, small petechial hemorrhages on the skin and ruptured blood vessels in the eyes, or eye. I could not imagine anyone doing a pathological examination on this baby; but I definitely did not want to put myself at risk to save the staff from having a bad time for another indeterminate period of time. Still, they were having a really bad time.​
I went to the ward that night even though I was feeling a little sick and discovered that the baby had died. It was gone. Someone had beat me to it, I thought. But that was unlikely. Probably the baby starved to death, like it was supposed to.​
The next few days, I found myself thinking obsessively about how I would have placed my hand on the baby’s mouth. Could I have really done that? Probably not. But maybe. The scene played out in my mind over and over.​
Over all the years that followed, I found myself thinking from time to time of that picture, my hand over the baby’s mouth. I knew then, and I still think now, that the right thing to do would have been to kill that baby. It wasn’t really a baby; it just sounded like a baby—that's what I tell myself. But I would like to stop thinking about it. After all, the whole thing happened over fifty years ago.(c) Fredric Neuman 2012 Follow Dr. Neuman's blog at fredricneumanmd.com/blog​
 
Top Bottom