I think the real goal isn't reducing the total number of lines but making the code more readable and reducing duplication. You can do this by refactoring codes into methods and other classes or using frameworks. I'd caution against reducing code for reducing's sake. I've seen some really unintelligible ternary operator statements that were written on a single line. I would often take these out for a more readable two or three line if statement or whatever. I'm a big fan of using frameworks. For instance, I use a lot of jQuery and I love the CSS selectors (bear with me if you have no interest or use for my example). I started a project where I need to do scraping of a website. Fine, using WebRequest and such I get a single string object with all the HTML. To get specific parts of data from the html string most examples on the web start diving into complex and ugly string manipulation functions and some smarter ones use Regex. Better yet others start making use of HtmlAgilityPack. But this returns an XmlNode tree and forces me to use XPath if I want to select specific portions of data. I'm not against XPath and I've used it in other areas but I really like CSS selectors and I'm pretty much a master at them. So, I found Sharp-Query. This is an awesome framework that lets me do exactly what I want. I deliver it the html string and pass a CSS selector query to get, say, all the table rows that have a specific value in one of the columns. I replaced dozens of ugly lines of code with one readable line. Sure, I added a framework which added hundreds of lines of code in total. But it makes my app much more readable and much more stable.
MattPenner
Posts
-
How do you write fewer lines of code? -
Decent Open Source business dashboard system/framework?Thanks for the tip Richard, I'll take a look at that site. I was really trying to figure out which forum because it seems that it could fall into several and I didn't want to cross-post. If you can suggest where it should be I'd be happy to move it. Thanks!
-
Decent Open Source business dashboard system/framework?We are looking at setting up a web-based dashboard for our school district. I've had a hard time finding a decent product for our needs and I'm asking for suggestions. We are not against purchasing something but we have had several vendor solutions in the past for various things (not dashboards) that are too closed, not customizable and expensive. With in-house development staff we have no problem customizing solutions and actually prefer the ability to do so. We are looking at possibly developing our own solution but I’d hate to reinvent the wheel if something else is already out there that does a great job. It would be more professional and help us deliver a solution faster. Here are the requirements we have: • Must work on iPads (no Flash, Silverlight, Java, etc) This is a must. All our adman staff have iPads and will be making use of them. The solution must be compatible. • Must allow adding our own data. 90% of our data is in SQL and the other 10% we can get into SQL if that is the only way it takes data. • Should be somewhat usable by office staff if they want to add their own KPIs and charts/graphs. Not really a requirement but it’s something I would expect from any commercial solution. • Must run on Windows server. No Linux solutions please. • Preferably a .Net MVC based solution (C#, VB) but not a requirement. I’m sure there are many good WebForms or PHP ones out there. • Preferably integrates with Active Directory so that we can manage all our user permissions easily and not have separate sign ons for our staff. The dashboard should be "fluid" rather than the static limitations of reporting software like SSRS. What I mean is this. Many dashboards these days allow you to dynamically filter items or click on individual data bars and such to drill down into details. From my experience with SSRS 2005 charts/graphs did not give you the option to click on individual elements. You could create sub-reports that linked to detail reports but creating these were a lengthy manual process and didn’t lend too well to ad-hoc creation or dynamic data records that you may not know you are receiving at run-time. Most of these issues are easily solved in website solutions with programming on the backend and JavaScript on the front end. In these cases my fear is just that SSRS is “too closed” to customization. I’d be happy to be proven wrong if you, or someone else, has great experience with SSRS 2008 and know that some of these features are available. Thank you!
-
Calculators99% of the time I'm already at my computer and most calculations I would have to do for my work are non-complex. In that case I just tap my Windows key and type "calc" and hit enter. Faster than physically moving (boy that sounded lazy huh? :laugh: ) and doesn't clutter up my desk with "ancient" tech. Win7 or some other keyboard shortcut utilities will do that for you.
-
Coding file paths to a server or network shareYou could use DNS aliases for the network shares. This way, you can use the DNS name however you wish. If the server or share ever changes you just update the DNS entry and all the apps don't know the difference. This also allows you to create DNS entries with names based on the roles or services not the server it's on at the time. Here's some info on it: http://serverfault.com/questions/23823/how-to-configure-windows-machine-to-allow-file-sharing-with-dns-alias[^] Or you can Google dns-alias network share
-
Powerrrrrrrrrrr!I had the same problem with my main work desk on a wall in my home office that had only two 2x wall plates. What's worse is one of the wall plates had an outlet that was on a light switch for a floor lamp. That left me with only three usable outlets and a myriad of equipment. I ended up plugging in two surge strips, one that had 6 outlets and another that had like 10. These were both tucked pretty far under my desk but still accessible when I needed to get to them. I love my pTouch labeler so I like to label everything. :) I labeled every one of my cables right at the base so I knew what each plug was, such as Monitor-1, Monitor-2, Vonage adapter, Router, etc. Worked out pretty well and I still had a few outlets left for the daily temporary item.
-
This is one of my concerns with HTML 5The fact that they manipulated the code in HTML5's localStorage is not the issue at all. In fact, before online games, all software configs were stored on the local drive. That's how people have been hacking into games and unlocking password protection for years. HTML5 didn't make this type of "attack" something new, it's been around since the beginning of computers. HTML5 just gave a new publishing platform for developers to shoot themselves in the foot. It's the developers fault that they made this accessible on the local machine and didn't secure it in any fashion. It would be like as if Microsoft had a config file for Office on the local machine and you only had to change a few lines to unlock it for free. What they should have done is stored the sensitive data on the server or encrypted/protected the sensitive data in the local storage.
-
Netbook recommendationsFirst of all, I have to say you have the perfect expectation of a netbook. Too many people purchase a portable unit (netbook, iPad, tablet, etc) ultimately trying to replace a desktop or more powerful laptop. Our org has purchased 100+ HP Pavilion dm1-2010nr netbooks. They have the option of a built-in Verizon broadband if you want it. I take it with me when I am at a conference or a 2-day training session that I attend once a month. It has Win7 and is surprisingly fast for general use, such as Office 2010 documents, email, web browsing, etc. The screen is a great size and crisp. I tend to make my menu bars as minimal as comfortable to maximize the work area. During a conference I typically have about 5 Word documents open at a time, Internet with 5+ tabs open at a time and email. This netbook easily handles all these tasks at one time and I can quickly alt-tab between whatever I need with no delays. With this type of usage I usually get about 6-7 hours of constant use without having to plug it in. If I were to use it less or let it go into powersave I'd probably get more, but usually I'm near a power outlet within this amount of time.
-
I Hate Clever Javascript Programmers [modified]As others have said there is nothing demented or intentionally spiteful about this at all. They simply used an optimization tool (minifier), which removes all white space and uses the minimum amount of characters for variables. It compresses JavaScript quite a bit for downloading. It is a highly common, and very recommended, practice. The actual source code with all comments and descriptive variable names is on the project site.
-
Watch out for the Master Control ProgramI was only 6 when it hit the theaters so I didn't see it until it was released on VHS, however, I loved the movie and was instantly addicted. As one who was a part of the Tron generation it was quite good. I really don't know how I would react if I watched it for the first time among today's generation of movies. Many hot lazy summer days were spent watching it when it was 110+ outside. As many have pointed out most of the computer users at the time were early business professionals, academia or the developers themselves, so the initial target audience of geeks was very small. It did appeal to a wide range of Sci-Fi fans though. The effects were simply amazing at the time. If you watch the making of the movie, which is on the DVD, it's quite extraordinary how they did the effects. Some have pointed out the inaccuracies in the movie, however, I'm hard pressed to even think of one movie that was based on computers (or even attributed them) that didn't have inaccuracies. This one, being a complete fantasy world imagined inside the computer realm, I give it a high amount of artistic license. Given the absolute imagination of the movie and the story I pretty much let go any restrictions and just get totally engrossed into the film. Whereas romantic comedies I watch with my wife absolutely drive me nuts when some "nice guy" calls the leading lady on the phone, suddenly out of no where rains rose petals on her work computer screen and she thinks, "Oh, how cute!".
-
F1 for help in VSThanks for the clear and quick tip! For those interested I just added an alternate version at the end of the tip in the link. My alternate version opens the search outside of Visual Studio in the user's default browser. It also searches on the word the text cursor is on if there is no selection, much like the original F1 functioned. I'm lazy and I don't like to have to select the entire word just to search on it. :) Oh, also, 95% of the time the result I want is in the first hit. For instance, when searching Google for "msdn ActionResult" the MSDN page for the ActionResult Class is the first one on the list. So, my new version also allows you to hit Shift+F1 (or whatever you map it to) to go directly to the first result, much like the I'm Feeling Lucky button on Google.
modified on Friday, February 11, 2011 3:12 PM
-
F1 for help in VSThanks Hans! For those interested I just added an alternate version at the end of the tip Hans posted the link to. My alternate version opens the search outside of Visual Studio in the user's default browser. It also searches on the word the text cursor is on if there is no selection, much like the original F1 functioned. I'm lazy and I don't like to have to select the entire word just to search on it. :) Have fun!
-
F1 for help in VSThis is exactly what I do but the manual way. I don't have a macro set up. What did you do to set this up? Is this set up in Visual Studio itself or some other macro app? I'd really like to do the same. Thanks!
-
When do you blog? [modified]Ah, forgot that piece of info! :) I've updated my original question with my blog info. I have a technical blog at http://MattPenner.info that is mainly about C# development but delves into occasional articles on Usability, SQL, GIS and some other fun or related technologies.
-
When do you blog? [modified]I'm fairly busy with a load of tasks at work, but often I use a fun technology or enhance my learning when I can't find a solution on Google and I think these would make good blog posts. The problem is finding the time to actually do it. Writing a blog post (at least for me) is often more than just typing for a few minutes. It involves code samples, occasional screen shots, previewing and making corrections and then finally posting. For a somewhat in-depth post this can take an hour or several. I have a running set of potential posts I would like to write but my list is getting longer and longer without much actually happening. So, here's my question. If you blog on a fairly regular basis (every week or a few times a month) and your posts are mostly instructional when do you do it? Do you have a few hours a week (like Friday after lunch) set aside to do this? Do you do it at 2am when the family is sleeping? Does your employer frown on you blogging on work time or do they actually promote it? For me, my employer doesn't really know that I do it but they do occasionally see a post or two. I just discipline myself not to take too much work time to do it. Do you have any tips that you have discovered that make the process a little smoother? Do you have an assistant? :-D I'm serious on this one. A lot of my time is spent on correcting errors, re-wording sections and fiddling with format. If I was a professional blogger I'd probably do like movie composers do. I'd write the content, throw it together and then throw it over the wall. Let my assistant clean it up and rephrase complicated sections. Then I'd proof it and post it. I'm sure many professional bloggers have a similar set up. Any services that are somewhat reasonable that you use and would recommend? Maybe this is a market that is yet untapped. :) Oh, btw, if you want to drop by my technical blog and personal info is at http://MattPenner.info. Thanks! Matt Penner
modified on Wednesday, February 9, 2011 2:01 PM
-
They should really warn youYeah, no kidding! :wtf: My wife and I loved the movie but it was a good thing we rented it on DVD. We started watching it with the kids (6 yrs and younger). As the movie progressively got more "scary and dark" we started skipping chapters. They got the 45 minute version (and my middle son was still a little scared in my lap). After they went to bed my wife and I watched the whole thing ourselves. It was great, but I would exactly call it suitable for young children. After all, while the characters are probably no meaner than other villains in child movies, I don't need my kids afraid that their toys are going to wake up in the middle of the night and start imprisoning/torturing each other. Cute baby dolls turning bad is just evil in the minds of kids. What gets me is they still sell the purple bear as a smiling toy. Uh, yeah, that's what I want to buy my kids. X|
-
Napping At Work [modified]I don't have time for naps. I love them during the weekend but I have a wife and kids at home. When I was single and an independent consultant in the off hours I would often get only 4 hours of sleep or pull occasional all-nighters. Now I like to work my standard work day and get home. I'm in my early thirties so I'm not "old" yet. However, my priorities have changed. I typically put in about 8-9 hours at work and then go home. I don't have time to take a nap at work because that would extend my work day. I also work for a more traditional organization so, while my hours are flexible, I'm still expected to put in 8 hours of work, not a few hours plus some sleep as long as the job gets done. One other thing that may cause me to not have time for a nap is I never feel rested unless I actually fall deep asleep. Depending on how tired I am it can take me 15-20 minutes or more to fall deep asleep and then I have to sleep for an hour or two. I can't do 20 minute power naps. If I don't fall completely asleep I don't feel anymore rested than had I not slept at all. If I fall deep asleep but am interrupted (such as by an alarm) before my body is ready I am groggy and unfocused. So, I tend to avoid naps unless I have several hours of down time on the weekend. As an alternative, what I do is I take various mental breaks through the day. I may read an article or two on Code Project (or other websites/blogs) or listen to a podcast. I wish I had a ping-pong table. :) The weather isn't always conducive so I don't go outside much. What really works is if I get a real mental burst from something like a fun puzzle or a really great article/podcast on something I enjoy. Something that really sparks my brain. Then I'm good to go for the rest of the day.
-
LogMeInThis is correct. When we log in to our server it prompts us asking if we want it to log in for us. However, this only works if your LogMeIn password for the machine is the same as the password of the machine itself.
-
Routers & dual zonesI call your two routers "private" and "public" just to keep things straight. I am assuming both wireless routers are standard modern routers that have DHCP and NAS. What I mean by that is they have multiple LAN ports, they get their own address from wahtever is plugged into the WAN port and then hand out local addresses (such as 192.168.x.x) to whatever machines are plugged into the LAN ports. My suggestion will not work with simple hubs as they do not do any sort of routing or NAS. Since your cable modem only has one local port what you will want to do is plug the WAN connection your "public" router into that and move your current "private" wireless router 1's WAN port to a LAN port on the "public" router. Much like this: Simple Public/Private Wireless Diagram[^] What this effectively does is put your public wireless router first in line off of your cable modem. Since your routers don't allow any unsolicited traffic from the outside world into your network (unless you have opened ports such as for putting a web server online or a gaming server) there is no way for the first router in the line to talk to the second. I had the exact same setup at my house for a while and it worked great. There is no need for you to actually change the subnet addresses. It's OK if they are both 192.168.0.x. The value of having, say, the public router being on 192.168.1.x and the private one on 192.168.2.x is that anyone on the private router can still reach any machines on the public router. This allows you to admin your public router from any machine plugged into the private one. Otherwise, if they are the same subnet, you will need to physically plug a machine into the public router (or have your laptop join the public wireless) to log into it. Bear in mind that if you want to make any other resources available to the public clients, such as a printer, you will need to move that device to the public router. Good luck!
-
VCR woes - potential solutionCheck this one out. It doesn't have a tuner, which from your previous post I thought wasn't an issue. If you're doing over the air then you'll need one, but if you have a cable box then you don't. http://www.amazon.com/Magnavox-ZV427MG9-Recorder-Recording-Refurbished/dp/B0032RR08S/ref=sr_1_6?ie=UTF8&qid=1294422610&sr=8-6[^] The price is great and it's not something you'll worry about losing if it dies after a year. It's similar to mine but our VCR portion is now eating tapes after a couple of years. For your situation you could just record on DVD-RW discs and not worry about the tape function. Good luck!