Wednesday, December 30, 2009

Programming and Software Development Quotes

Some of my favorites from some of his favorites:

“Good design adds value faster than it adds cost.”
- Thomas C. Gale

“Better train people and risk they leave – than do nothing and risk they stay.”
- Unknown

“Think twice before you start programming or you will program twice before you start thinking.”
- Unknown

“Debugging is like farting – it’s not so bad when it’s your own code.”
- Unknown

“Confidence, n.: The feeling you have before you understand the situation”
- Unknown

“Good judgement is the result of experience … Experience is the result of bad judgement.”
- Fred Brooks

“Your code is both good and original. Unfortunately the parts that are good are not original, and the parts that are original are not good.”
- Unknown

“Now I’m a pretty lazy person and am prepared to work quite hard in order to avoid work.”
- Martin Fowler

And the last one is actually someone I work with!!! Well, its a guy with the same name as the guy I work with and who is often mistaken for the great Martin Fowler!

http://daipratt.co.uk/programming-and-it-quotes/

Friday, November 20, 2009

fixed and smoothed my fonts in Firefox on Windows XP

I use Windows Vista at work, and although I'm about to upgrade to Windows 7 (yay!!!) I wasn't sure how to smooth the fonts in Firefox given screenshots of a website in Firefox 3.5.5 and IE 8. The client pointed out that the fonts looked better in IE than in Firefox. What?! This never happens! So with a little searching, I discovered that Firefox displays fonts based on the user's operating system settings. There's a display setting called ClearType that you can get to from desktop Properties -> Appearance -> Effects. In Windows XP, the default is Standard, not ClearType. In Windows Vista (and I assume Windows 7) the default is ClearType.

How to make font render smoothly in firefox just like safari and IE7

How to evaluate and change Windows font smoothing or ClearType

(although I'm sure this is condemned as browser hijack)

[DllImport("user32.dll", SetLastError = true)]
static extern bool
SystemParametersInfo(uint uiAction, uint uiParam,
ref int pvParam, uint fWinIni);

/* Constants used for User32 calls. */
const uint SPI_GETFONTSMOOTHING = 74;
const uint SPI_SETFONTSMOOTHING = 75;
const unit SPI_UPDATEINI = 0x1;

private Boolean GetFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to get the font smoothing value. */
iResult =
SystemParametersInfo(SPI_GETFONTSMOOTHING, 0,
ref pv, 0);
if (pv > 0)
{
//pv > 0 means font smoothing is on.
return true;
}
else
{
//pv == 0 means font smoothing is off.
return false;
}
}

private void DisableFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to set the font smoothing value. */
iResult =
SystemParametersInfo(SPI_SETFONTSMOOTHING, 0,
ref pv, SPIF_UPDATEINIFILE);
}

private void EnableFontSmoothing()
{
bool iResult;
int pv = 0;
/* Call to systemparametersinfo
to set the font smoothing value. */
iResult =
SystemParametersInfo(SPI_SETFONTSMOOTHING, 1,
ref pv, SPIF_UPDATEINIFILE);
}


More on ClearType:
Microsoft Typography
Microsoft ClearType FAQ
Technical Overview of ClearType Filtering

Thursday, November 19, 2009

How to: Register HTTP Handlers

To register an HTTP handler for IIS 7.0 running in Integrated Mode

The following example shows how to map all HTTP requests to files with the file name extension ".SampleFileExtension" to the SampleHandler2 HTTP handler class. In this case, the handler code is in the App_Code folder, so you do not have to specify an assembly.

<configuration>
   <system.webServer>
      <handlers>
         <add name="SampleHandler" verb="*" path="SampleHandler.new" type="SampleHandler, SampleHandlerAssembly" resourceType="Unspecified" />
      </handlers>
   <system.webServer>
</configuration>

Wednesday, November 18, 2009

fixed my content disappearing in Firefox print preview

Problem

You wrote a web page which the customer will want to print out, which takes 2 or more pages of paper to print. Everything works fine in IE6, but when you go to print it in Firefox, only the first page comes out! The rest of the web page is simply missing from the printer.

Solution

Do you ever get the feeling that these Problem/Solution tricks I write about are from my own experiences as a web developer? You bet! This one took me quite some time to figure out.

The problem was in the style settings of the container of the web page content.

I was using a DIV tag to surround the entire body of the text of the web page to be printed. That DIV tag referenced a CLASS within my CSS that happened to have the element:

overflow: auto;

Removing that little bit from the DIV tag's CSS class completely solved the problem.

I actually didn't need to remove it, and instead I changed the setting to visible.

http://www.fastechws.com/tricks/web/printing-web-page-has-missing-pages-in-firefox.php

Tuesday, October 27, 2009

Nested Master Pages

I have two master pages, one that uses a two column layout, and one that uses a three column layout. So instead of duplicating the entire file (ASP.NET file tags, XML file tags, script tags, css link tags, header and footer controls, etc) I did some googling and discovered that you can build master pages from a base master page (the derived master pages = nested master pages), much like you can create a base ASPX page and use the content place holder control as a template to vary the content. Yay!

One important detail though, is that the nested master pages need to inherit either from the vanilla master page class or a custom master page class (not the base master page class!!!), and the base master page should inherit from the vanilla master page class or a custom master page class

http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx

This is the parent master file:
<% @ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="Form1" runat="server">
<div>
<h2>Parent Master</h2>
<p style="font:color=red">This is parent master content.</p>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</form>
</body>
</html>

This is the child master file:

<%@ Master Language="C#" MasterPageFile="~/Parent.master"%>
<asp:Content id="Content1" ContentPlaceholderID="MainContent" runat="server">
<asp:panel runat="server" id="panelMain" backcolor="lightyellow">
<h2>Child master</h2>
<asp:panel runat="server" id="panel1" backcolor="lightblue">
<p>This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent1" runat="server" />
</asp:panel>
<asp:panel runat="server" id="panel2" backcolor="pink">
<p>This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent2" runat="server" />
</asp:panel>
<br />
</asp:panel>
</asp:Content>

And finally, regular page that references the child master file:

<%@ Page Language="C#" MasterPageFile="~/Child.master"%>
<asp:Content id="Content1" ContentPlaceholderID="ChildContent1" runat="server">
<asp:Label runat="server" id="Label1"
text="Child label1" font-bold="true" />
<br />
</asp:Content>
<asp:Content id="Content2" ContentPlaceholderID="ChildContent2" runat="server">
<asp:Label runat="server" id="Label2"
text="Child label2" font-bold="true"/>
</asp:Content>

Friday, October 23, 2009

Hipster: The Dead End of Western Civilization

We are a lost generation, desperately clinging to anything that feels real, but too afraid to become it ourselves.

awesomely simple explanation of javascript:void(0)

http://www.tizag.com/javascriptT/javascriptvoid.php

JavaScript Void 0

Hyperlinks like this one entice visitors to click because they know clicking it will lead them to a new page. However, sometimes when you are making a script, you would like to add functionality to your website that lets a hyperlink to be clicked and perform a useful action like update the sums on the webpage, without loading a new page.


It's these types of programming solutions that will utilize the JavaScript Void 0 programming tool. This lesson will teach you some of the reasons to use the JavaScript Void 0programming strategy in your scripts.



Directly Executing JavaScript in a Browser

Web browsers allow you to execute JavaScript statements directly by entering JavaScript code into the browser's URL text field. All you need to do is place a JavaScript: before your code to inform the browser you wish to run JavaScript. You can play around with this right now by typing something like



  • JavaScript:alert("I'm learning at Tizag.com")

into the browser's URL text field and pressing Enter.



This is useful to you, the JavaScript scripter, because you can now set your hyperlinks's href attribute equal to a JavaScript statement! This means you can remove the hyperlink's ability to load a new page and reprogram it to do your "complete some actions directly on this page" bidding.


This practice can be seen in services like Gmail (Google Email) which does a great deal of interaction with hyperlinks, but has very few new pages loading. Here is an example link that does not load a new webpage.



JavaScript Code:

<a href="javascript: alert('News Flash!')">News Flash</a>

Display:

This is interesting to learn, but it isn't much more than a gimmick. The true power of direct URL JavaScript statements is only unleashed when you use it to return a value. This is where void 0 comes into play.



JavaScript Void 0 Explanation

Web browsers will try and take whatever is used as a URL and load it. The only reason we can use a JavaScript Alert statement without loading a new page is because alert is a
function that returns a null value. This means that when the browser attempts to load a new page it sees null and has nothing to load.


The important thing to notice here is that if you ever do use a JavaScript statement as the URL that returns a value, the browser will attempt to load a page. To prevent this unwanted action, you need to use the void function on such statement, which will always return null and never load a new page.



Simple JavaScript Void 0 Simple Example

void is an operator that is used to return a null value so the browser will not be able to load a new page. An important thing to note about the void operator is that it requires a value and cannot be used by itself. Here is a simple way to use void to cancel out the page load.



JavaScript Code:

<a href="javascript: void(0)">I am a useless link</a>

Display:

Simple JavaScript Void 0 Useful Example

This example shows how you would return a value using the void operator. myNum is a variable that we set to the value 10. We then use the same variable myNum in an alertoperation.



JavaScript Code:

<a href="javascript: void(myNum=10);alert('myNum = '+myNum)">
Set myNum Please</a>

Display:

Tuesday, October 20, 2009

Friday, October 16, 2009

fixed my IIS "page not found error"

My local development environment uses IIS7, which has a different interface for managing HTTP handler mappings, and which uses different web.config settings to detect those mappings from IIS6. Some pages on the site require URL path rewriting to load pages that live in a non-root directory, but give the user the ability to navigate to them by creating the illusion that they live in the root directory. But the same site on a staging server using IIS6 was resulting in a page not found error. Because the error was happening before IIS could serve up the custom 404 page, the error was suspected to be a missing or bad setting in IIS.

Although this solution wasn't voted the highest or as "the answer" to the OP's question, it seemed to fix the problem and get rid of the error!

"If I understand the problem correctly, it sounds like you need add a "Wildcard Application Mapping" for your virtual directory. In other words, you want to forward all requests to any file extension to ASP.NET's ISAPI extension.

To do so, open the properties of your virtual directory. On the Virtual Directory tab (Home Directory tab if it's a web site), click the Configuration... button. Click the Insert... button next to the bottom list box in the dialog that shows up. In this dialog, choose "%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" as the executable and make sure to un-check "Verify that file exists" checkbox, since the files to be requested don't live in your virtual directory."

Thursday, October 15, 2009

Things to post about:

Using USPS Web Tools
Learning just enough XQuery to query XML data from a SQL Server database

Thursday, October 8, 2009

ASP.NET Ajax Web Services [ScriptMethod(UseHttpGet = true)]

HTTP POST Is Slower than HTTP GET, but It Is Default in ASP.NET Ajax

ASP.NET Ajax, by default, makes HTTP POST for all web service calls. HTTP POST is more expensive than HTTP GET. It transmits more bytes over the wire, thus taking precious network time, and it also makes ASP.NET do extra processing on the server end. So, you should use HTTP GET as much as possible. However, HTTP GET does not allow you to pass objects as parameters. You can pass numerics, strings and dates only. When you make an HTTP GET call, Atlas builds an encoded URL and makes a hit to that URL. So, you must not pass too much content that makes the URL become larger than 2048 characters. As far as I know, that's the max length of any URL. In order to enable HTTP GET on a web service method, you need to decorate the method with the [ScriptMethod(UseHttpGet=true)] attribute:

[WebMethod] [ScriptMethod(UseHttpGet=true)] 
public string HelloWorld()
{
}

Wednesday, October 7, 2009

DZone The heart of the Java development community

I'm following DZone on Twitter after getting an email today from a grad student at Delaware I worked with as an undergrad the summer I did research. He's contributed a few articles, and even though I don't code in Java on a daily basis, I did come across a different article that raised some good questions about what it means to be a software developer, and specifically, what responsibility comes along with the "developer" part of that, Staying Current: A Software Developer's Responbility. Two questions that he asks (and looks for in potential teammates) really stuck out to me:

* What language(s) that are gaining popularity, but not yet mainstream, have you written Hello World in?
* Do you read books or blogs looking for new ideas at least (on average) once every two weeks?

I've discovered for myself that the idea behind the first question is an essential part of the job, and that discovery on a daily basis is key to learning "Hello World" knowledge about new stuff. Although I haven't actually written Hello World in a new language, there are definitely basic things I've learned everyday about new technologies I didn't/don't know anything about, but which help to nudge the door open and keep it open for them. But I've definitely realized the benefit of examining a problem thoroughly, perhaps even excessively, if there's something in it for me, especially if it concerns something in particular that's in my blind spot as a gap in my knowledge; its crucial that I'm assertive about honing any missing fundamental knowledge, and even more crucial about gaining new knowledge.

Tuesday, September 29, 2009

TWENTY YEARS, only a few tears.

TWENTY YEARS, only a few tears.

helped my "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level..." this morning


It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

Instead of moving my web.config from the sub-directory to the root, I copied it, and thus, there were two of the same file, one in the root, and one in the sub-directory. In my case, deleting the file from the sub-directory solved the problem, but the explanation below is a slightly more abstract explanation of the nature of the error that I found helpful.

Particularly #2:
"2. When you have sub-directories in your application, you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or sessionstate is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point).

Mostly we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we wish to protect the admin pages from unathorized users).

But actually, this can be achieved in the web.config at the application's root level itself, by specifing the location path tags and authorization, as follows:-

<location path="Admin">
   <system.web>
      <authorization>
         <allow roles="administrators" />
         <deny users="*" />
      </authorization>
   </system.web>
</location>

However, if you wish to have a web.config at the sub-directory level and protect the sub-directory, you can just specify the Authorization mode as follows:-

<configuration>
   <system.web>
      <authorization>
         <allow roles="administrators" />
         <deny users="*" />
      </authorization>
   </system.web>
</configuration>

Thus you can protect the sub-directory from unauthorized access."

helped my HTTP Error 500.22 this morning

Breaking Changes for ASP.NET 2.0 applications running in Integrated mode on IIS 7.0

AppCmd Migrate Config and HTTP Error 500.22

Wednesday, July 1, 2009

Free

Shamelessly following this Anderson, Gladwell, Godin debate, I think Mitch Ratcliffe actually got it right, taken from booksahead:

"In a constantly churning market, “Free” is just a way to destroy your competitor, but it doesn’t make a business sustainable."

and so does Mark Cuban, taken from Blog Maverick:

"We give you something free, you give us something that costs you nothing.

The music is often free, but it is NEVER freely distributed.

The TV and Movie business are realizing this is the case. Hence TV Anywhere. They will give you access to content for free if you are already a customer of their distributors. And before you IT ALL HAS TO BE FREE BIGOTS EXPLODE, even google requires you have internet access of some kind, which costs you in subscription fees , taxes or coffee.

Newspapers are catching flack for saying there should be copyrights on their news reports and the summaries. They are right. Their work, their ability to control it. They should have the right to control where it appears. If, as Chris Anderson and others suggest, there will be plenty of content creators and the quality of the work is sufficient for consumers of that content, then there will be plenty of open source content and it shouldnt matter what the newspapers request for protection. The market will decide.

Newspapers are also catching flack for saying they dont want their content openly distributed. On this point, they are correct again. They should have complete control over where it is distributed. They should have the ability to choose where it is offered for free.

Not only should they have this control, taking back this control is the exact right business move. Im not saying it will save newspapers or magazines, it wont. But it will make their website offerings stronger in the long run. If Im them, I take the risk that the “printed” content business follows the path of the music industry.

In other words, you take on the role of identifying the best in breed for your business and use your resources to help those talented people figure out how to make money for themselves and for you. You provide your resources and knowledge to make them smarter and then you go and compete against the masses.

In the long run, printed content producers should have a brand, and use their institutional knowledge, their core competencies and ability to procure, improve and market to maximize the value of their brands and the perceived value of their content. Whether its on a central website, a co produced website, in print or on a hologram in the evening sky, I should go to the NY Times because they have demonstrated to me that they have the very best articles on the subjects I am looking for. That they are the best source for breaking news about the topics I care about. THEY NEED TO MAKE SURE I DONT HAVE THE CHOICE OF GETTING IT ANYWHERE ELSE BUT WHERE THEY DICTATE. If they cant make their content stand out from the open source masses and convince enough people to transact with them in a way that makes them money they dont deserve to exist.

They should distribute their content for Free where they believe it maximizes return, but should do everything possible to keep it from being distributed Freely."

Tuesday, June 30, 2009

advice

Kind of incredible advice, really:

When I started high school my mother told me "Use your best judgment, and remember, nobody likes a prude."

Never leave your house without enough money to get back by yourself. (advice given when I started dating. I view it as a call to independence to this day.)

Tuesday, June 23, 2009

before your ovaries fall out

This summary is not available. Please click here to view the post.

fluent helpers

Fluent C Sharp Language Extension Helpers - Part 1

So, I found myself doing a lot of for( int i = 0; i < n; i++ ){} stuff lately. So, I've decided to try something new. I've started a small collection of "Fluent Helpers" that alleviate a lot of the verbosity in C#.

About 28 characters (including spaces) for a simple for loop to do some constant iteration.

for( int i = 0; i < n, i++){

About 18 characters to do this (no pun intended):

Do.This( 5, () =>{

Here's an example:


Do.This( 5,() =>
{
Console.Write( "Hello " );
Console.WriteLine( "World!" );
}
);


Prints:

Hello World!
Hello World!
Hello World!
Hello World!
Hello World!

Now that feels much better on my hands, and looks much cleaner too, IMHO. Here's the simple implementation for Do.This:


public static class Do {

public static void This(int times, Action what)
{
for( int i = 0; i < times; i++ )
what();
}
}


I've already started a little library of these small syntax helpers I've collected. If you have any suggestions, please share! cool0003.gif

-Brian Chavez

Wednesday, May 27, 2009

recession blog comments

from Decorno

"I think most of the foreclosures from people biting off more than they could chew are gone. Now it's a second wave people who actually bought houses they could afford but lost jobs." :(

Tuesday, May 26, 2009

inspired by Eva: 3 or so things I'm grateful for today:

1. Partly walking with my neighbor to work today.

Today is one of the first days in over a week that I haven't left early to bike to Cafe Rustica to sit and have some morning coffee (black!) and read. I was annoyed at myself for wasting what would've otherwise been ~40mins to relax at the cafe, and instead mindlessly surfed the internet, which would also probably result in getting to work late. But when she remarked to me how it was a little cooler than expected, to which I wholly agreed being also fooled by the delicious rays of sun pouring into my room and presuming their warmth, I actually felt kind of lucky to be exactly where I was in that moment, sharing this deceptive summer morning together. We continued walking together and she said her son begged her to use the car to drive to school this morning and she was on her way to the bank, but since it was this cold, that she decided only to the bank, and then straight home. As we walked she saw someone drive past and waved him down, who I assumed to be her son as she ran over to the car. She abruptly stopped by the door and turned, waved at me and said, you, too, you want a ride? It was actually a friend she knew and not her son, although I changed my mind after seeing him up close anyways. So we, all three of us, drove to Porter Square together. He dropped us off at the intersection across from the T. I asked her if that was her son, and she said, no, just a friend, "from her country."

I asked her what country, but she was already walking toward the bank in the other direction. I think she was the woman who's kids I asked directions for how to get to the park a few blocks from my house, and myself already running late that day, all proceeded to ask me about a million questions about where I was going and what I was doing, so I stopped and talked with her kids, since I was already late, and the woman sitting on the porch smiled at my dilemma, even though I was pretty happy to bask in my kingdom of their wonder. I swear maybe she was that woman outside watching them. I really hope I see her again.

2. Bekah ordering 7 quarts of ice cream, hot fudge, caramel, and tons of toppings at work today, including chocolate covered espresso beans, in celebration of Memorial Day weekend.

3. Today being my first free night in over three weeks. I'm euphoric at the idea of really having time to myself.

okay, one more...

4. The afterglow. It gives me this intoxicating restless adrenaline and this feeling of connectedness. I swing my hips a little more. I look people in the eye. I wonder. It makes me tireless of the smallest and simplest things and connected to the beauty in them and around me.

umm, and another!

5. T-station musicians.

Thursday, April 9, 2009

explicitly stated usages of Google Maps APIs

I guess they felt they needed to...

"There are some uses of the API that we just don't want to see. For instance, we do not want to see maps that identify the places to buy illegal drugs in a city, or any similar illegal activity..."

AddThis

AddThis is a really great sharing tool for social networking.

ViewState, Twins, and Triplets!

This is a great article on ViewState and how it works that I found after a co-worker made a comment about optimizing our project by disabling the ViewState property on some of our project's web page controls.

public string NavigateUrl
{
get
{
string text = (string) ViewState["NavigateUrl"];
if (text != null)
return text;
else
return string.Empty;
}
set
{
ViewState["NavigateUrl"] = value;
}
}

(You can view the decompiled source code for a .NET assembly by using a tool like Reflector.)

So when a page control's properties are accessed, as is the case with a HyperLink's NavigateUrl property, the ViewState is actually what gets checked because it saves a snapshot of each control's persisting data. The ViewState is of type System.Web.UI.StateBag, and it stores name-value pairs for all of the page's controls, and can be accessed syntactically the same way in which a Hashtable would.

The article also highlighted two (detestably adorable) classes, the Pair and Triplet classes!

"The Pair and Triplet are two classes found in the System.Web.UI namespace, and provide a single class to store either two or three objects. The Pair class has properties First and Second to access its two elements, while Triplet has First, Second, and Third as properties."

Although I personally would have named the Pair class as the Twin class instead. Oh well.

Thursday, April 2, 2009

incomparably simple compare to example because I can never remember


using System;

class Program
{
static void Main()
{
string a = "a"; // 1
string b = "b"; // 2

int c = 0;

// When a is SMALLER than b
c = a.CompareTo(b);
Console.WriteLine(c);
// -1

// When b is BIGGER than a
c = b.CompareTo(a);
Console.WriteLine(c);
// 1
}
}