Jesse's profileBoring, Possibly TediousPhotosBlogListsMore ![]() | Help |
|
10/31/2008 HttpWebRequest to the un-rescue!I played Nick Burns today and helped a friend with a "simple" programming challenge. However, I forgot to yell, "YOU'RE WEEEEEEEELCOME!!" afterward ;) In a nutshell, he needed to authenticate an enormous number of users against a web application that was secured by the basic authentication dialog, and his load testing software couldn't do it. The authentication causes the web app to generate unique identifiers that the web app administrators need to customize people's profiles. He was looking at spending a day manually logging in as hundreds of different accounts, but I assured him we could knock it out in about 10 minutes. HttpWebRequest to the rescue! System.Net.HttpWebRequest is a really handy if your app just needs to open a connection once or twice and then destroy the object. If you need to open connections sequentially or in a tight loop, HttpWebRequest becomes a giant pain in the ass. You create a request object for a specific URL, then customize protocol headers and supply credentials. To complete the request, you use HttpWebRequest.GetResponse() to get a WebResponse from the URL. It couldn't be more simple, right up until it couldn't be more confusing. Back to sequential access: I obviously needed to open several hundred connections sequentially. When I tried this, the GetResponse() method would timeout after the third attempt with no information on what was wrong. DUMB! This was on separate objects, so some sort of hidden resource pooling was going on in the background as well. DUMB x5!! Yet another "managed" resource that isn't really managed, so I learn that I have to manually close the WebResponse objects I get back from GetResponse(). Fine, I did that. Problem #2: Now GetResponse() no longer throws WebExceptions, timeout-related or otherwise, so e.g. bad credentials in the middle of the loop still appear to make a legitimate connection. Double-you-tee-eff, as the kids say. After staring at the code and making sure I wasn't suffering a stroke, I started studying the HttpWebRequest members. After farting a bit, I got lucky and threw a call to HttpWebRequest.Abort() into the mix and that seemed to solve all my problems. No, this isn't documented anywhere. All the blog entries I could find related to HttpWebRequest were people failing to read the docs about WebResponse.Close(), so as far as I know, this isn't published anywhere. Here's the code I ended up using: private void Connect(string url, string userName, string password) { // Throw app exception if url or user is empty if (url == string.Empty || userName == string.Empty) { throw new ApplicationException("meaningful information"); } // Create the request and apply credentials HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Credentials = new NetworkCredential(userName, password); req.Timeout = 2000; // Create uninitialized response object for 'finally' structure WebResponse response = null; try { response = req.GetResponse(); } catch (WebException ex) { throw new ApplicationException("meaningful information"); } finally { // If you don't abort and then close the response, bad craziness will occur. req.Abort(); if (response != null) response.Close(); } }Note that the purpose of my app was to repeatedly call Connect() just to perform authentication. I handle the app exceptions to capture failed authentications or bad data from the CSV file processor, but I don't return or analyze the response in any way. Enjoy! 昨日、日本語の15課のしけんがあた。私はよかっただと思う!昨日、日本語のしけんをとった。今週に三日友達と「げんき」の教科書を勉強したから、私はよかっただと思う。友達の名前はモリーさん。モリさんはとてもきれいで、おもしおくて、楽しい女の人。私たちはすしのレストランで勉強するのが好きだ。ヂンキタオンのレストランの中で「あずきすし」が一番食べて勉強したが好きだ。毎週、モリーさんと勉強を楽しみにしている。 10/20/2008 Open letter to all of the women in my lifeDear ladies, When you tell me about your problems, whether they're old ones or new ones, something is going on in my head. First and foremost, I am listening intently; however, I'm also strategizing the entire time about what you should do and steps you might have taken to prevent the problem in the first place. Unfortunately for you, I'm relatively good at maintaining conversational engagement. You've seen me nodding, offering verbal encouragement, et cetera. I can't help it; I was taught these cues at a very early age and it's second nature. I realize that my polite conversational style leaves you totally unprepared for the onslaught/interrogation which inevitably follows, and it is partially for this reason that I have written this letter. A smarter, more self-aware man than me would learn not to open his yap at the end of one of your stories, proceed to let you how you screwed up, and then deliver a PowerPoint presentation on how you could have avoided the problem and how you might still fix it. I am not that smarter man. I'm only smart enough to remember that this is a problem I have for the few days after the most recent time I've perpetrated it. After that, the anger and tears and frustration are all forgotten until the next time I make a giant ass out of myself instead of listening to your problems and just empathizing. I apologize. On the plus side, you have my permission to say, "Dude, STFU, it's not that kind of story," and I promise I'll pipe down right away. If you don't cut me off early though, it'll probably be too late to prevent any of the really serious damage I'm able to inflict with all my "help". I'm sorry for the next time I do this. 10/14/2008 USDA allows 'split status' for bovine TB in MNMN's bovine TB status was recently downgraded "after a new case of the highly contagious pulmonary disease surfaced in northwestern Minnesota". The cattle producer's solution? They just transported their cattle out of state to avoid testing for TB. The toothless USDA solution? In an acknowledgment of their perpetual inability to do anything but issue declarations from DC, the USDA established a "split state" policy in MN so that only certain areas of the state are subject to testing. The USDA tells us they're doing this because they want to reduce costs for unaffected farmers, but in reality, they're doing it instead of using their statutory power to prevent cattle in a downgraded state from being transported out. If the whole state was downgraded, how on EARTH was it legal or ethical for cattle producers to just march their animals out of state?? The USDA clearly has no ability to enact meaningful controls to safeguard our food supply. Here's hoping your next burger doesn't have any infectious goo in it. USDA allows 'split status' for bovine TB in Minn. - MSNBC Wire Services - msnbc.com 10/10/2008 If you can't [boo] the one you [hate] honey, [boo] the one you're with!(With apologies to Stephen Stills) Short story: McCain got booed at tonight when he tried to reassure some Minnesotans that we need not fear the spectre of an Obama presidency, and that Obama is actually a decent human being whose accomplishments he admires. Booed. Congrats you backwoods Lakeville assholes, I'm embarrassed to live in "your" state tonight. Long story: What the hell happened to politics in this country? It's not enough that you love the one you vote for, you have to HATE the one you vote against? There's a great argument for a multiparty system: it takes a lot more energy (probably more than it's worth) to hate on a whole bunch of different people for a whole bunch of different reasons all the time. So I was listening to NPR on the way to the airport tonight, and one of our fine Minnesotan Palin sound-alikes was venting her frustration at the McCain rally in Lakeville. In particular she seemed to think that McCain should be busting heads a lot harder than he has been, and that Minnesotan's want to see a fight. WTF? Really? The McCain-Palin rallies the last couple of weeks are getting downright medieval--one dude shouted "off with his head!" My point is that McCain and Palin have been letting some shit go unchallenged from their supporters mouths that I *know* those slick willies don't believe. What happened? This was a guy who was once so principled and heartfelt. I would have gladly voted for the McCain who was running during the 2000 primary. He called the fundies "agents of intolerance" and generally told the GOP hate machine to go screw itself. Oh how things have changed! Anyone who heard a single word out of Limbaugh, Coulter, or Hannity during the GOP primary knows the extreme right had no use for him--Coulter told Hannity that she'd campaign for Hillary if Johnny Mac won the nomination for crying out loud. Since he won it, every lefty who paid any attention in 2000 has been talking about how McCain has gone on the attack in ways he always promised never to do. I think we can all see what happened. Personally, I think McCain is a decent guy who sold his ass to the GOP hate machine so they'd give him a real shot at the presidency. What that means is that he sowed the boos he's reaping right now. I still say good luck to him, but putting this particular hateful toothpaste back in the tube will only surely lose him the election at this point. What's worse, Norm Coleman wouldn't appear with him tonight because of all the negativity and announced that he's unilaterally disarming--stopping all attack ads. Based on the boos and Obama's sudden lead in Minnesota, it was probably a really smart political decision. If a career non-maverick like Coleman is disarming, then "change we can believe in" really must be in the air ;) This little gem from the end of the Yahoo article sums up what's going on pretty well:
McCain booed after trying to calm anti-Obama crowd - Yahoo! News 10/6/2008 2008 Official Bike Equipment Fail Whale AwardHoly crapadesu, as they (might conceivably) say in Japan. I bought this set of Green Slime tire liners on the say-so of the repair manager at my local REI, who swears by these things. While I will admit they resisted punctures for the entire 100 miles I had them installed, they destroyed two tubes by causing massive pinch flats both times I got my bike going fast. The first happened within 50 miles of installation. I had a tailwind on a local street during my commute, and I edged over 30mph to make a light. As I slowed, I realized my rear tire (almost never a problem) was flat. Pulled off to check it out and found the mother of all pinch flats along the point where the liner overlaps itself inside the tire. I'm talking 3 inches long, worn right through. Not only that, but the tube had slipped over the valve inside the tire along the direction of rotation, folding over about 4" of length. I didn't think that was even possible, particular because I adjust the tire pressure almost daily.
None of this seemed like a good thing, and I need to actually USE my bike, so I didn't reinstall the liner after replacing the tube. 50 miles later, I'm riding across a bridge this weekend with a wicked fast downhill slope, going almost 35mph, and the same fricken thing happens to the FRONT tire. Eff!! It was the middle of the night, AND cold, AND I wasn't home yet. I rolled it a 1/2 mile and got a lift the rest of the way from my SO. Same twanked fold over the valve, same wicked pinch flat.
Green Slime tire liners are absolute pieces of shit and I wouldn't wish them on my worst enemy. They win the bike equipment fail whale award of 2008. I did some internet searching (post-purchase, unfortunately), and found a bunch of other stories from people who put their faith in various liners (Green Slime was frequently referenced by name) only to be stuck in the muck by a busy road fixing a flat anyway. I wish I didn't have to commute 80 miles a week through a veritable anti-bike tire warzone, but thems the breaks. On the plus side, I'm becoming really good at repairing flats, but it still sucks to have to do it.
I'm still on the lookout for puncture-resistant tech, but I'm focusing on standard parts like better tires and tubes and more careful post-ride inspections, instead of weird add-on crap.
PS
I also figured out my pannier situation: I remounted my rack 1/2 closer to the rear and found an awesome old bike bag in the mother-in-law's basement that MJ bought like ten years ago. It has the same danger clips that my old bags have, so it's quite capable of ejection, but it has a tight, adjustable frame fastener. Bonus: it's big enough to hold my pack, laptop, and textbooks. Needless to say, I returned all that shit I bought to REI and yelled at them for selling crappy panniers (that manager would have gotten an earful about the slime liners, too, but he wasn't there that day). ミネソタ大学の日本語のじゅぎょうはすごくむずかしいだよ!私は二年生だ。こんがっきの五週だけだ。しかし、一種間に二回だけじゅぎょうを行くが、毎日に三時間しゅくだいをしなくてはいけないよ!二年生はもっと大変だと思った。でも、がんばらなくてはいけない!
ージェシー |
|
|