## Why complexity matters

I needed a simple queue class – so I wrote one based on` java.util.Queue`

interface

** * Queue Template Class * @author: Jarek Przygódzki <jarek.przygodzki@gmail.com> * @version 0.1 **/ class Queue(E) { this() { } bool isEmpty() { return length is 0 ; } /** * Retrieves and removes the head of this queue */ E poll(){ auto e = elements[$-1]; elements = elements[0..$-1]; return e; } /** * Retrieves, but does not remove, the head of this queue */ E peek() { return elements[$-1]; } /** * Inserts the specified element into this queue */ Queue!(E) offer(E e) { elements ~= e; return this; } /** * Number of elements in queue */ uint length() { return elements.length; } int opApply(int delegate(ref E e) dg) { foreach(e;elements) dg(e); return 0; } private E[] elements; }

Of course it totally screwed up Edmonds-Karp algorithm complexity. But it worked ;D

## The devil’s offer

The devil visited a lawyer’s office and made her an offer. “I can arrange some things for you, ” the devil said.

“I’ll increase your income five-fold. Your partners will love you; your clients will respect you; you’ll have four months of vacation each year and live to be a hundred. All I require in return is that your husband’s soul, your children’s souls, and their

children’s souls rot in hell for eternity.”

The lawyer thought for a moment. “What’s the catch?” she asked

## Joke

An American visiting in England asked at the hotel for the elevator. The portiere was a bit confused, but then smiled when he realized what the man wanted.

“You must mean the lift,” he said.

“No,” the American responded. “If I ask for the elevator I mean the elevator.”

“Yes, of course,” the portiere answered, “but over here we call them lifts.”

“Now you listen,” the American said, rather irritated, “someone in America invented the elevator!”

“Oh, right you are sir,” the portiere said in a polite tone, “but someone here in England invented the language.”

Found here

## Math Jokes

A physicist, a mathematician and a computer scientist discuss what is better: a wife or a girlfriend.

The physicist: “A girlfriend. You still have freedom to experiment.”

The mathematician: “A wife. You have security.”

The computer scientist: “Both. When I’m not with my wife, she thinks I’m with my girlfriend. With my girlfriend it’s vice versa. And I can be with my computer without anyone disturbing me…”

It is only two weeks into the term that, in a calculus class, a student raises his hand and asks:

“Will we ever need this stuff in real life?”

The professor gently smiles at him and says:

“Of course not – if your real life will consist of flipping hamburgers at MacDonald’s!”

A math professor, a native Texan, was asked by one of his students:

“What is mathematics good for?”

He replied: “This question makes me sick! If you show someone the Grand Canyon for the first time, and he asks you `What’s it good for?’ What would you do? Well, you kick that guy off the cliff!”

A mathematician has spent years trying to prove the Riemann hypothesis – without success. Finally, he decides to sell his soul to the devil in exchange for a proof. The devil promises to deliver a proof within four weeks.

Four weeks pass, but nothing happens. Half a year later, the devil shows up again – in a rather gloomy mood.

“I’m sorry”, he says. “I couldn’t prove the Riemann hypothesis either. But” – and his face lightens up – “I think I found a really interesting lemma…”

Q: Why do mathematicians, after a dinner at a Chinese restaurant, always insist on taking the leftovers home?

A: Because they know the Chinese remainder theorem!

“That math prof’s marriage is falling apart!”

“No wonder! He’s into scientific computing – and she’s incalculable!”

A woman in a bar tries to pick up a mathematician.

“How old, do you think, am I?” she asks coyly.

“Well – 18 by that fire in your eyes, 19 by that glow on your cheeks,

20 by that radiance of your face, and adding that up is something you

can probably do for yourself…”

Q: What is the difference between a mathematician and a philosopher?

A: The mathematician only needs paper, pencil, and a trash bin for his work – the philosopher can do without the trash bin..

Life is complex: it has both real and imaginary components.

New York (CNN). At John F. Kennedy International Airport today, a Caucasian male (later discovered to be a high school mathematics teacher) was arrested trying to board a flight while in possession of a compass, a protractor and a graphical calculator.

According to law enforcement officials, he is believed to have ties to the Al-Gebra network. He will be charged with carrying weapons of math instruction.

After her husband’s death, the elderly lady decided to go back to school and get a degree in mathematics.

A few weeks into the term, she storms into the dean’s office, exclaiming:

“I’ve been silent until now – but I’m not going to take these obscenities anymore!”

“What obscenities are you talking about?”

She reaches into her purse and pulls out a notebook.

“I noted ofall of them. In my presence, professors had the complete lack of

decency to speak of” – she leafs through her notebook – “Bruhat-Tits

spaces, a pumping lemma, and even degenerate colonels!”

“Students nowadays are so clueless”, the math professor complains to a colleague. “Yesterday, a student came to my office hours and wanted to know if General Calculus was a Roman war hero…”

Mother to her daughter: “Why does the tablecloth you just put on the table have the word `truth’ written on it?”

Daughter: “Because I want to turn the table into a truth table!”

A newlywed husband is discouraged by his wife’s obsession with mathematics. Afraid of being second fiddle to her profession, he finally confronts her:

“Do you love math more than me?”

“Of course not, dear – I love you much more!”

Happy, although sceptical, he challenges her: “Well, then prove it!”

Pondering a bit, she responds: “Ok… Let epsilon be greater than zero…”

“So how’s your boyfriend doing, the math student?”

“Don’t mention that crazy pervert to me anymore! We broke up.”

“How can you say such a nasty thing about him? He seemed to be such a nice boy.”

“Imagine! He was restless during the days and couldn’t sleep at

night – always trying to solve his math problems. When he had finally

done it, he wasn’t happy: he would call himself a complete idiot and

throw all his notes into the garbage. One day, I couldn’t take it

anymore, and I told him to drop math. You know what he told me?”

“No.”

“He said, he enjoyed it!!!”

In a speech to a gathering of mathematics professors from throughout the United States, George W. Bush warned the academics not to misuse their position to force their often extremist political views on young Americans.

“It is my understanding”, the president said, “that you are frequently teaching algebra classes in which your students learn how to solve equations with the help of radicals. I can’t say that I approve of that…”

A math professor is talking to her little brother who just started his first year of graduate school in mathematics.

“What’s your favorite thing about mathematics?” the brother wants to know.

“Knot theory.”

“Yeah, me neither.”

The math professor’s six-year-old son knocks at the door of his father’s study.

“Daddy”, he says. “I need help with a math problem I couldn’t do at school.”

“Sure”, the father says and smiles. “Just tell me what’s bothering you.”

“Well, it’s a really hard problem: There are four ducks swimming in a pond, when two more ducks come and join them.

How many ducks are now swimming in the pond?”

The professor stares at his son with disbelief: “You couldn’t do that?! All you need to know is that 4 + 2 = 6!”

“Do you think, I’m stupid?! Of course, I know that 4 + 2 = 6. But what does this have to do with ducks!?”

“What is Pi?”

A mathematician: “Pi is the ratio of the circumference of a circle to its diameter.”

A computer programmer: “Pi is 3.141592653589 in double precision.”

A physicist: “Pi is 3.14159 plus or minus 0.000005.”

An engineer: “Pi is about 22/7.”

A nutritionist: “Pie is a healthy and delicious dessert!”

At a press conference held at the White House, president George W.

Bush accused mathematicians and computer scientists in the U.S. of

misusing classroom authority to promote a Democratic agenda.

“Every math or CS department offers an introduction to AlGore-ithms”,

the president complained. “But not a single one teaches

GeorgeBush-ithms…”

Q: How can you tell that a mathematician is extroverted?

A: When talking to you, he looks at your shoes instead of at his.

Q: What is the fundamental principle of engineering mathematics?

A: Every function has a Taylor series which converges to the function and breaks off after the linear term.

“Wasn’t yesterday your and your wife’s first wedding anniversary? What is it like having being married to a mathematician for a whole year?”

“She just filed for divorce…”

“I don’t believe it! Did you forget about your wedding day?”

“No. Actually, on my way back home from work, I stopped at a flower store and bought a bouquet of red roses for my wife. When I came home, I gave her the roses and said: `I love you.'”

“So, what happened?!”

“Well, she took the roses, slapped them around my face, kicked me in the groin, and threw me out of our apartment…”

“What a bitch!”

“No, no… it’s all my fault… I should have said: `I love you and only you.’.”

Q: Do you already know the latest stats joke?

A: Probably…

A mathematician gives a talk intended for a general audience. The talk is announced in the local newspaper, but he expects few people to show up because nobody who is not a mathematician will be able to make any

sense of the title: Convex sets and inequalities. To his surprise, the auditorium is crammed when his talk begins. After he has finished, someone in the audience raises his hand.

“But you said nothing about the actual topic of your talk!”

“What topic to you mean?”

“Well, the one that was announced in the paper: Convicts, sex, and inequality.”

At the end of his course on mathematical methods in optimization, the professor sternly looks at his students and says:

“There is one final piece of advice I’m going to give you now: Whatever you have learned in my course – never ever try to apply it to your personal lives!”

“Why?” the students ask.

“Well, some years ago, I observed my wife preparing breakfast, and I noticed that she wasted a lot of time walking back and forth in the kitchen. So, I went to work, optimized the whole procedure, and told my wife about it.”

“And what happened?!”

“Before I applied my expert knowledge, my wife needed about half an hour to prepare breakfast for the two of us. And now, it takes me less than fifteen minutes…”

“My life is all arithmetic”, the young businesswoman explains. “I try to add to my income, subtract from my weight, divide my time, and avoid multiplying…”

A father who is very much concerned about his son’s bad grades in math decides to register him at a catholic school.

After his first term there, the son brings home his report card: He’s getting “A”s in math.

The father is, of course, pleased, but wants to know:

“Why are your math grades suddenly so good?”

“You know”, the son explains, “when I walked into the classroom the first day, and I saw that guy on the wall nailed to a plus sign, I knew one thing: This place means business!”

At a conference, a mathematician proves a theorem.

Someone in the audience interrupts him: “That proof must be wrong – I have a counterexample to your theorem.”

The speaker replies: “I don’t care – I have another proof for it.”

Psychologists subject an engineer, a physicist, and a mathematician- a topologist, by the way – to an experiment: Each of them is locked in a room for a day – hungry, with a can of food, but without an opener; all they have is pencil and paper.

At the end of the day, the psychologists open the engineer’s room first. Pencil and paper are unused, but the walls of the room are covered

with dents. The engineer is sitting on the floor and eating from the open can: He threw it against the walls until it cracked open.

The physicist is next. The paper is covered with formulas, there is one dent in the wall, and the physicist is eating, too: He calculated how

exactly to throw the can against the wall, so that it would crack open.

When the psychologists open the mathematician’s room, the paper is also full of formulas, the can is still closed, and the mathematician

has disappeared. But there are strange noises coming from inside the can…

Someone gets an opener and opens the can. The mathematician crawls out. “Damn! I got a sign wrong…”

“What happened to your girlfriend, that really cute math student?”

“She no longer is my girlfriend. I caught her cheating on me.”

“I don’t believe that she cheated on you!”

“Well, a couple of nights ago I called her on the phone, and she told me that she was in bed wrestling with three unknowns…”

In the old days of the cold war, when it was very hard for Westerners to visit the Soviet Union, a British mathematician travels to Moscow to speak in the seminar of a famous Russian professor.

He starts his talk writing a theorem on the board. When he wants to prove it, the professor interrupts him:

“This theorem is clear!”

The speaker is, of course, annoyed, but manages to conceal it. He continues his talk with a second theorem,but, again, when he wants to start with the proof, he is interrupted by his host:

“This theorem is also clear!”

With a stern face, he writes a third theorem on the board and asks:

“Is this theorem clear, too?!”

His host nods.

The visitor grins and says: “This theorem – is false…”

## Math Definitions

Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination.

An engineer thinks that his equations are an approximation to reality.A physicist thinks reality is an approximation to his equations. A mathematician doesn’t care.

Old mathematicians never die; they just lose some of their functions.

Mathematics is the art of giving the same name to different things.– J. H. Poincare

What is a rigorous definition of rigor?

There is no logical foundation of mathematics, and Gödel has proved it!

A topologist is a person who doesn’t know the difference between a coffee cup and a doughnut.

A statistician is someone who is good with numbers but lacks the personality to be an accountant.

Classification of mathematical problems as linear and nonlinear is like classification of the Universe as bananas and non-bananas.

A law of conservation of difficulties: there is no easy way to prove a deep result.

A tragedy of mathematics is a beautiful conjecture ruined by an ugly fact.

Algebraic symbols are used when you do not know what you are talking about.

Philosophy is a game with objectives and no rules. Mathematics is a game with rules and no objectives.

Math is like love; a simple idea, but it can get complicated.

Mathematics is like checkers in being suitable for the young, not too difficult, amusing, and without peril to the state. (Plato)

Math is the language God used to write the universe.

God is real, unless proclaimed integer.

Medicine makes people ill, mathematics make them sad and theology makes them sinful. (Martin Luther)

The good Christian should beware of mathematicians and all those who make empty prophecies. The danger already exists that mathematicians have made a covenant with the devil to darken the spirit and confine man in the bonds of Hell. (St. Augustine)

He who can properly define and divide is to be considered a god. (Plato)

“A mathematician is a device for turning coffee into theorems” (P. Erdos)

“God geometrizes” says Plato. And here is the analytical continuation of this saying:

- Biologists think they are biochemists,
- Biochemists think they are Physical Chemists,
- Physical Chemists think they are Physicists,
- Physicists think they are Gods,
- And God thinks he is a Mathematician.

## Howto Get Direct YouTube Video (FLV) URL

This post is based on **paulg’s** description of Youtube video url protocol . Time is precious, so let’s get straight to the point – here’s the Python implementation

import httplib,urllib video_id = 'PB8pWjMlxxE' eurl = 'https://geniusofevil.wordpress.com/' # params = urllib.urlencode({'video_id':video_id, 'eurl':eurl}) conn = httplib.HTTPConnection("www.youtube.com") conn.request("GET","/get_video_info?&%s"%params) response = conn.getresponse() status,reason = response.status, response.reason data = response.read() video_info = dict((k,urllib.unquote_plus(v)) for k,v in (nvp.split('=') for nvp in data.split('&')))

Now video_info is a dictionary containing a lot of information about video ( author, length,title, etc) – but we still don’t have direct video URL.

conn.request('GET','/get_video?video_id=%s&t=%s' % ( video_info['video_id'],video_info['token'])) response = conn.getresponse()

YouTube will respond with **HTTP 303 See Other**

direct_url = response.getheader('location')

## Final Solution

# #!/usr/bin/env python # # -*- coding: utf-8 -*- import httplib,urllib __author__ = 'Jarosław Przygódzki' __copyright__ = 'Copyright (c) 2009 Jarosław Przygódzki' __date__ = '30.04.2009' __license__ = 'GPL' __version__ = '0.1.1' def GetYoutubeVideoInfo(videoID,eurl=None): ''' Return direct URL to video and dictionary containing additional info >> url,info = GetYoutubeVideoInfo("tmFbteHdiSw") >> ''' if not eurl: params = urllib.urlencode({'video_id':videoID}) else : params = urllib.urlencode({'video_id':videoID, 'eurl':eurl}) conn = httplib.HTTPConnection("www.youtube.com") conn.request("GET","/get_video_info?&%s"%params) response = conn.getresponse() data = response.read() video_info = dict((k,urllib.unquote_plus(v)) for k,v in (nvp.split('=') for nvp in data.split('&'))) conn.request('GET','/get_video?video_id=%s&t=%s' % ( video_info['video_id'],video_info['token'])) response = conn.getresponse() direct_url = response.getheader('location') return direct_url,video_info

## Exception handling in constructor’s initialization list

There are some aspects of C++ syntax that still amaze me… The syntax for catching an exception in an initialization list is one of them.It’s totally awkward

class MyClass { public: MyClass() try : <initialization list> { } catch ( ... ) { } };

But even if you catch the exception, you are pretty much screw because it cannot be guaranteed that object being created is in a valid state.There’s nothing much you can do besides rethrowing the exception.