Friday, October 15, 2010

Mark Twain quotes

A collection of quotes from Mark Twain (aka Samuel L. Clemens):


  • A man's character may be learned from the adjectives which he habitually uses in conversation.
  • Action speaks louder than words but not nearly as often.
  • All generalizations are false, including this one.
  • All right, then, I'll go to hell.
  • Any emotion, if it is sincere, is involuntary.
  • But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?
  • Buy land, they're not making it anymore.
  • Courage is resistance to fear, mastery of fear - not absence of fear
  • Don't go around saying the world owes you a living; the world owes you nothing; it was here first.
  • Get your facts first, then you can distort them as you please.
  • I was seldom able to see an opportunity until it had ceased to be one.
  • It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so.
  • It is better to deserve honors and not have them than to have them and not to deserve them.
  • It is easier to stay out than get out.
  • It's not the size of the dog in the fight, it's the size of the fight in the dog.
  • Life does not consist mainly, or even largely, of facts and happenings. It consists mainly of the storm of thought that is forever flowing through one's head.
  • Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen.
  • Patriot: the person who can holler the loudest without knowing what he is hollering about.
  • Patriotism is supporting your country all the time, and your government when it deserves it.
  • Substitute "damn" every time you're inclined to write "very"; your editor will delete it and the writing will be just as it should be.
  • The difference between the right word and the almost right word is the difference between lightning and a lightning bug.
  • The human race has only one really effective weapon and that is laughter.
  • The more things are forbidden, the more popular they become.
  • The more you explain it, the more I don't understand it.
  • The most interesting information comes from children, for they tell all they know and then stop.
  • The only way to keep your health is to eat what you don't want, drink what you don't like, and do what you'd rather not.
  • The radical of one century is the conservative of the next. The radical invents the views. When he has worn them out, the conservative adopts them.
  • The secret of getting ahead is getting started. The secret of getting started is breaking your complex overwhelming tasks into small manageable tasks, and then starting on the first one.
  • The trouble ain't that there is too many fools, but that the lightning ain't distributed right.
  • There are basically two types of people. People who accomplish things, and people who claim to have accomplished things. The first group is less crowded.
  • Thunder is good, thunder is impressive; but it is lightning that does all the work.
  • To succeed in life, you need two things: ignorance and confidence.
  • Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover.
  • We have the best government that money can buy.
  • When I was younger I could remember anything, whether it happened or not.
  • When angry, count to four. When very angry, swear.
  • When people do not respect us we are sharply offended; yet in his private heart no man much respects himself.
  • When red-haired people are above a certain social grade their hair is auburn.
  • When you fish for love, bait with your heart, not your brain.

Thursday, January 28, 2010

Simple way to output XML in ASP.NET MVC

Another post to document something that I really don't want to have to look up ever again. I simply wanted to output XML to the browser window using ASP.NET MVC. Sounds easy, simply use:
 
public ContentResult Index() 
{ 
StringWriter writer = new StringWriter();
myXmlDocument.Save(writer); 
return this.Content(writer.ToString(), @"text/xml", writer.Encoding);
} 


But no luck; IE7's CSS would not display the XML since IIS ASP.NET defaults to UTF-16 and the previous page was UTF-8? Yes, both pages were correctly tagged with there encoding and correctly identified by IE as UTF-8 or UTF-16. It just wouldn't process the later. Whats up with that; can't these MS kids get along. So did a search and found a soluiton posted by Robert McLaw using a modified StringWriter that accepted an encoding which would worked very nicely:
 

public class StringWriterWithEncoding : StringWriter 
{ 
Encoding encoding; 
public StringWriterWithEncoding(Encoding encoding)
{ 
 this.encoding = encoding; 
}
public override Encoding Encoding 
{
 get { return encoding; } 
} 
}

To implement, just use the new writer and set it's encoding as desired:
 
public ContentResult Index() 
{ 
StringWriterWithEncoding writer = new StringWriterWithEncoding(Encoding.UTF8); 
myXmlDocument.Save(writer); 
return this.Content(writer.ToString(), @"text/xml", writer.Encoding);
} 

The advantatage of using the StringWriterWithEncoding method over a custom view is that the code can be used in other, non HTML based applications for consistency.

Tuesday, January 5, 2010

Simple method to download Web resource

Had to look this up - again - so writing a quick note for future reference.

public static string Download(string url) 
{ 
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
Stream stream = httpWebResponse.GetResponseStream(); 
StreamReader streamReader = new StreamReader(stream, Encoding.ASCII); 
return streamReader.ReadToEnd(); 
}