Posts Tagged ‘Trips’

Minimizes and organizes your CSS

Thursday, September 10th, 2009

Barry van Oudtshoorn, has developed a compactor CSS also allows us to alphabetize our CSS attributes.
It has therefore followed the specifications proposed in Google Payload Size Minimize making our CSS is smaller and, consequently, less late in coming to the end user.

What do you do?

Using a basic CSS file are applied to a series of transformations to obtain a new CSS file supplement packed.

  • Eliminate all comments
  • Sort all the properties for each selector alphabetically
  • Sort all values of each property alphabetically
  • Eliminate all unnecessary space.

Comparison with YUI Compressor

CSS_Compress_090909

The compaction is equal to that offered by YUI Compressor, but only the above (and little) in cases with gzipped CSS.
YUI_Comparison_090909

PHP Version

Taking advantage of this holiday and I’ll be okay for a project I’m developing, I ported to PHP function to use it without using Java.

<?php
class cssCompressor {
 private $cssFileName;
 private $selectors = array();
 
 function cssConstruct($cssContent = '', $deleteComments = true){
 $this->cssFileName = $cssContent;
 
 // Delete comments
 if ($deleteComments)
 $this->cssFileName = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $this->cssFileName);
 
 $selectors = array();
 // We get all the selectors
 $parties = explode("}", $this->cssFileName);
 
 foreach($parties as $part) {
 if (!empty($part))
 array_push($this->selectors, new SelectorCSS($part."}"));
 }
 }
 
 function get($cleanSpaces = true){
 $output = '';
 foreach($this->selectors as $selector) {
 $output .= $selector->get($cleanSpaces)."\n";
 }
 // Delete line breaks, spaces, ...
 if ($cleanSpaces)
 $output = str_replace(array("\t", "\n", "\r"), '', $output);
 
 return $output;
 }
}
 
/*
 SelectorCSS
*/
class SelectorCSS{
 private $properties = array();
 private $selector;
 
 function cssConstruct($selector = ''){
 $parts = explode("{", $selector);
 if (count($parts) < 2) {
 die("Selector " + selector +" incomplete");
 }
 $this->selector = trim($parts[0]);
 $contents = trim($parts[1]);
 if (strlen($contents) == 0) {
 die("Selector " + selector + "empty");
 }
 
 if (substr($contents,strlen($contents) -1 ,1) != '}'){
 die("Selector "+selector+" is wrong");
 }
 
 $contents = substr($contents, 0, $contents - 2);
 
 $this->properties = explode(';', $contents);
 }
 
 function get(){
 $str = $this->selector.'{';
 natcasesort($this->properties);
 foreach($this->properties as $property) {
 if (!empty($property))
 $str .= $property.";";
 }
 $str .= '}';
 return $str;
 }
 
}
?>

To use is simple, we simply must indicate the file’s contents. Css we want to compact and manage their properties. Upon receiving the contents of the file we can send one or more file concatenating the contents thereof.

// StyleSheet.css file content
 $fileName = file_get_contents('StyleSheet.css');
 
 // We create an object that we pass the contents of parameter
 $styleSheet = new cssCompressor($fileName);
 /* Parameters:
     1: (String) content of the file
     2: (Bool) Clear comments (default: true)
 */
 // We get the CSS content
 echo $styleSheet->get(false);
 /*    Parameters:
      1: (Bool) Delete lines (default: true)
 */

The object has a method get() that returns the contents compacted and orderly, this content can cache in a static file or display it directly.

Over 22 Links To LINQ

Tuesday, March 24th, 2009

LINQ Index

Charlie Calvert’s Blog- Links to LINQ: Click Here..
The Server Side – LINQ/C# Learning Guide: Click Here..

LINQ Bloggers

Troy Magennis – LINQed IN: Click Here..
Charlie Calvert’s Community Blog: Click Here..
LINQ- The Wandering Glitch: Click Here…
OakLeaf Systems: Click Here..

LINQ Websites

LINQDev:
LINQ in Action:

LINQ Videos

LINQ Video:
Luke Hoban: Orcas – Compiling LINQ, C# Futures, Intellisense

LINQ Books

Amazon.com: Pro LINQ: Language Integrated Query in C# 2008 (Windows.Net) (Paperback)
Amazon.com: LINQ for Visual C# 2005 (Paperback)
Amazon.com: LINQ for VB 2005 (Paperback)

LINQ Articles

SingingEels: Improving Performance With LINQ
Next-Generation Data Access: Making the Conceptual Level Real
LINQ ASP.NET Sitemap
LINQ Lazy Evaluation
Query Windows Forms Controls in LINQ
Enumerable.Range in C#
ToDictionary Method in C#

From Microsoft

LINQ Project General
LINQ 101 Samples

Some other books for ASP.NET MVC, LINQ, Silverlight, ASP.NET 3.5, Sharepoint Server. Click Here..

Mapping .html file to ASP.NET

Tuesday, February 24th, 2009

Step one: Open IIS, in your site to set up virtual directory property page tab, click on the “Application Settings (Application Settings)” under the “configuration (Configuration..)” Button, open the “application configuration (Application Configuration ) “window” App Mappings (App Mappings) “Tab page, click on the” Add (Add..) “button, the pop-up” Add / Edit Application Mapping suffix (Add / Edit Application Extension Mapping ) “window, in the” executable program (Executable) “the right of the text box, type C: \ WINNT \ Microsoft.NET \ Framework \ v1.1.4322 \ aspnet_isapi.dll (file path will be. net framework version of the different different for the sake of safety, you can in the “App Mappings (App Mappings)” tab under the list of double-mapping “. aspx”, in the pop-up window to select its “executable program (Executable)” text Copy the text box and then out), in the “name suffix (Extension)” text box you want to add the suffix of “. html”, then click OK to save all open windows to complete the property settings in IIS; 

Step two: open you want to configure the site or virtual directory under the root directory of the web.config file, configuration section in <system.web> add the following configuration sections: 

<httphandlers>
<add verb=”*”
path=”*.html”
type=”System.Web.UI.PageHandlerFactory” />
</httphandlers>


Save web.config file, Now we are set !!! :-)