CSS3 Rounded corners

.class {
 border-radius: 6px;
 -webkit-border-radius: 6px;
 -moz-border-radius: 6px;
}

source

Letterpress

color: #222;
text-shadow: 0px 2px 3px #555;

source

iOs device favicon

<link rel="apple-touch-icon-precomposed" media="screen and (resolution: 163dpi)" href="/link/to/iOS-57px.png" />

<link rel="apple-touch-icon-precomposed" media="screen and (resolution: 132dpi)" href="/link/to/iOS-72px.png" />

<link rel="apple-touch-icon-precomposed" media="screen and (resolution: 326dpi)" href="/link/to/iOS-114px.png" />

source

Simple XHTML Form with CSS

-----------CSS-----------------

label {
  width: 4em;
  float: left;
  text-align: right;
  margin-right: 0.5em;
  display: block;
}

.submit input {
  margin-left: 4.5em;
}
#form input:hover, #form textarea:hover{
	background-color: lightyellow;
}
input:focus, textarea:focus{
background-color: lightyellow;
}

-----------Form----------------

<form action="#">
<p><label for="name">Name</label> <input type="text" id="name" /></p>
<p><label for="e-mail">E-mail</label> <input type="text" id="e-mail" /></p>
<p class="submit"><input type="submit" value="Submit" /></p>
</form>

source

objects into array

function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
    $arrData = array();
   
    // if input is object, convert into array
    if (is_object($arrObjData)) {
        $arrObjData = get_object_vars($arrObjData);
    }
   
    if (is_array($arrObjData)) {
        foreach ($arrObjData as $index => $value) {
            if (is_object($value) || is_array($value)) {
                $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
            }
            if (in_array($index, $arrSkipIndices)) {
                continue;
            }
            $arrData[$index] = $value;
        }
    }
    return $arrData;
}

source

Store/retrieve object in session

//On Login page
User currentUser = <get the User entity here, including relations to UserRights>;
Session.Add("CurrentUser", currentUser);

//On another page
User restoredUser = Session["CurrentUser"] as User;
if (restoredUser != null)
{
	//use the User entity here to check user's rights
}

source

Require a checkbox to be checked:

<asp:CustomValidator runat="server" ID="rfvMember" OnServerValidate="cbMember_Validate" ValidateEmptyText="true" ErrorMessage="Member coverage is required." Display="None"></asp:CustomValidator>


protected void cbMember_Validate(object sender, ServerValidateEventArgs e)
	{
		e.IsValid = cbMember.Checked;
	}

source

Assure a valid email that .Net can actually send an email to is passed.

protected void ValidEmail(object source, ServerValidateEventArgs args)
		{
			try
			{
				var a = new MailAddress(args.Value);
			}
			catch (Exception ex)
			{
				args.IsValid = false;
				return;
			}
			args.IsValid = true;
		}

source

Format a date as desired in a LINQ query assigned object

Created = String.Format("{0:M/d/yyyy}", cn.Created)

source

Python log setup

def setupLogger(self, log_dir):
                if not isdir(log_dir):
                        os.mkdir(log_dir)

                # create logger
                log_file = join(log_dir, time.strftime('%Y_%m_%d') + '.log')
                logger = logging.getLogger(log_file)
                logger.setLevel(logging.INFO)

                # create console handler and set level to debug
                ch = logging.FileHandler(log_file)
                ch.setLevel(logging.INFO)

                # create formatter
                formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")

                # add formatter to ch
                ch.setFormatter(formatter)

                # add ch to logger
                logger.addHandler(ch)

                return logger

source