11/17/2009 03:40 AM -
i've been messing around with the dynamic typing features in c# 4.0. it took a little while before i actually came up with a good use for them, but i finally found one. i had a situation that seemed like it should have a small custom class with two properties: a string and an int, representing the number of hits of that string within a list<string>. that seemed like overkill. best practices tell me this puny little class would expect its own .cs file, and i just wasn't ready to write a whole .cs file for two variables. i may be leaning toward the whole enterprise architecture mentality, but not that much :) i tried a dictionary<string,int>, but that didn't work as it doesn't provide an iterator. so i have a problem whereas i want to create a complex duplicate filter based on a list<string>. well, not really a duplicate filter so much as a "nearly duplicate" filter. that is, i want to remove any instances from the list if they contain a word that occurs in multiple items in the list, except short and common words. oh sure, it sounds simple. but i wanted to do it a new way. at first i thought i might be able to use anonymous types and stick them into a list of their own type. list <(new { word = "", instances = 0 }).gettype()> words2 = new list<(new { word = "", instances = 0 }).gettype()>(); obviously, that didn't work. i got tons of compiler errors like using the generic type 'system.collections.generic.list<t>' requires 1 type arguments and argument 1: cannot convert from 'anonymoustype#1' to 'int'. but i was passing in a type... bah, that's not going to work. my figuring is that i just ran into a contravariance issue whereas the compiler tried to find the most suitable overload for the list<type> constructor and thought list<int> was the closest match, possibly because my anonymous type had an int property and the int constructor comes before the string constructor in the framework assembly. what i needed was a way to force it to use the list<object> constructor without having to box the variable. why avoid boxing? while object is the only type you can cast an anonymous type to, for some reason they don't like being cast back from objects into anonymous types, so unboxing would have been impossible. so then i remembered i was working in .net 4.0, and thus i could use the new dynamic keyword as a type. that made it simpler. i'd still use anonymous types, but the anonymous type itself would be the dynamic type in my generic. dynamic directly extends object, so the compiler should see that constructor overload first and go directly there based on base class inferrence. my brain goes into recursion just thinking about how this resolves at runtime :) private static list<string> complexduplicatefilter(list<string> input) { if (input == null || input.count == 0) return input; input = input.distinct().tolist(); // build a list of words and how many times they occur in the overall list list<dynamic> words2 = new list<dynamic>(); foreach (string line in input) foreach (string word in line.split(new char[] { ' ', ',', ';', '\\', '/', ':', '\r', '\n' })) { if (string.isnullorempty(word)) continue; else if (existsinlist(word, words2)) foreach (dynamic dyn in words2) { if (dyn.word == word) dyn.instances++; } else words2.add(new { word = word, instances = 0 }); } // remove extraneous entries for common word permutations list<string> output = new list<string>(); foreach (dynamic dyn in words2) if ((dyn.iterations > 5 && !output.contains(dyn.word)) || dyn.iterations <= 5) output.add(dyn.word); return output; } private static bool existsinlist(string word, list<dynamic>
Post.aspx?Title=C%23+4.0%3a+Complex+String+Duplicate+Filter+using+Dynamic+Typing
11/09/2009 03:48 PM -
a couple of my domains will be expiring soon, and i don't think i'm going to bother renewing them. these domains will be expiring soon:zi255.com - blog websitezindex255.com - blog website (dupe)these domains aren't expiring soon but i probably won't bother renewing them when they come up:damnednice.com - name wasn't as "cool" as i thought it was when i bought itmultimononline.com - dupe of manymon.com; doesn't work with windows live idgooglejuicer.com - another one of my great ideas that i didn't bother doing anything with. was going to be an seo service.so, going forward, these are the only domains i plan to keep and make use of:kconnolly.net - portfolio and blog (public-friendly)manymon.com - multi-monitor enthusiast site. still plan to do this someday :)i'm not planning to cancel them; just let them expire naturally. anyone wanna buy some of these domain names before the domain farmers gobble them up? keep in mind, in addition to buying a domain, you still have to renew it. if i get a good offer, i'll sell it off early (i.e. googlejuicer is a great name for an seo service). expiration dates:damnednice.com: 12/12/2011googlejuicer.com: 01/01/2012multimononline.com: 07/12/2010zi255.com: 11/25/2009zindex255.com: 11/25/2009i've turned off automatic renewal on these domains. the other domains (which i'm keeping) don't expire for a couple years. anyhow, i'll be taking them all offline for the big move sometime around nov 20-30th and will remain offline for a still-unknown timeframe. when the blog goes back up at kconnolly.net, i plan to have a shiny new interface - version 7. why not, i have free time now. incidentally, if anyone is using one of these domains to send me e-mail (i.e. kevin@zi255.com), these addresses will become defunct when the domains expire. i suggest you use kevin@kconnolly.net - i plan to keep that domain for a long time.
Post.aspx?Title=Domains+Expiring
11/03/2009 10:54 AM -
i'm just about sick of the way applications traditionally update themselves. every fairly-savvy computer user who's ever installed an app like java or anything from adobe is aware of this by now. the app will insist on updating itself as soon as possible, usually by calling home every day or so. usually this has been done by installing an applet that runs at startup and keeps running as long as the computer is running. as a result, you end up with all kinds of useless adobeupdaters and googleupdaters. some of us have let them live; some of us have killed them manually when we see them; but the paranoid and savvy among us generally disable them altogether. surely you'll recognize this screen: see all that crap that was loading at startup? google, steam, etc. only google is an updater in this case (though i disable crap i don't need anyway). i don't have adobe reader installed or you'd see them in the list as well; and i'm fairly certain i've seen adobe flash in here at some point. you'll probably never see a sun/java product installed on one of my systems ever again. i've always checked here, in the registry under windows/currentversion/run, and in the startup folder in the start menu. today i discovered another place they live, and it explains how things have been hiding from me. the windows task scheduler? great. google, you don't need to check for updates every fucking hour. there is another way: paint.net checks for updates when you load it, and this option can be disabled. you can install the update now, when you exit the app, or never. this way is less annoying, but we can still do better. i propose this: windows/microsoft update should be extended to allow updates for non-microsoft products. they already do this for driver updates, so why not extend this functionality to trusted partners like google and adobe? even other parts of microsoft? i have no problem with adobe and google checking for updates; but they don't need a seperate update checker for every app/company, and they don't need to check 24 times a day. windows update lets me set the schedule and inspect updates before installing them. it lets me do all this from one central place. this should be the accepted standard paradigm, and all updates should be done from one place. when this happens someday, i will allow useless updates to my pdf reader and flash player. until then, you're out of luck.
Post.aspx?Title=Evil+Update+Processes
11/01/2009 05:23 AM -
via stanford course cs106x blog: youtube link lyrics: code monkey by jonathan coulton code monkey get up, get coffee code monkey go to job code monkey have boring meeting with boring manager rob rob say code monkey very diligent but his output stink his code not functional or elegant what do code monkey think? code monkey think maybe manager want to write goddamn login page himself code monkey not say it out loud code monkey not crazy, just proud code monkey like fritos code monkey like tab and mountain dew code monkey very simple man big, warm, fuzzy, secret heart code monkey like you code monkey like you code monkey hang around at front desk tell you sweater look nice code monkey offer buy you soda bring you cup, bring you ice you say no thank you for the soda, cuz soda make you fat anyway you busy with the telephone no time for chat code monkey have long walk back to cubicle he sit down pretend to work code monkey not thinking so straight code monkey not feeling so great code monkey like fritos code monkey like tab and mountain dew code monkey very simple man big, warm, fuzzy, secret heart code monkey like you code monkey like you... a lot code monkey have every reason to get out this place code monkey just keep on working see a soft pretty face much rather wake up eat a coffee cake take bath, take nap this job fulfilling in creative way such a load of crap code monkey think some day he have everything, even pretty girl like you code monkey just waiting for now code monkey say someday, somehow... code monkey like fritos code monkey like tab and mountain dew code monkey very simple man big, warm, fuzzy, secret heart code monkey like you code monkey like you
Post.aspx?Title=Song%3a+Code+Monkey