Sorting Gridview Control ASP.NET

protected void grdVw_FileList_Sorting(object sender, GridViewSortEventArgs e)
        {

            GridSorting(e.SortExpression, grdVw_FileList);
         
        }

        private void GridSorting(string column, GridView grid)
        {
            // Session["column"] = ""; clear this after ever search/load
string column_ASC = column + " ASC";
            string column_DESC = column + " DESC";

            DataTable dt = (DataTable)Session["fileList"];

            if (Session["column"].ToString().ToUpper() == column_ASC.ToUpper())
            {
                DataView dv = new DataView(dt, "", column_DESC, DataViewRowState.CurrentRows);
                grid.DataSource = dv;
                grid.DataBind();
                Session["column"] = column_DESC;
            }
            else
            {
                DataView dv = new DataView(dt, "", column_ASC, DataViewRowState.CurrentRows);
                grid.DataSource = dv;
                grid.DataBind();
                Session["column"] = column_ASC;
            }

        }

source

Get Weather – Step 4 – Enhancing encapsulation

class WeatherService{

	public function WeatherService(){
		//some initialization...
	}
	
	public function getWeatherInfo($city, $method=""){
		
		$res = shell_exec("./getWdr.sh {$city}");
		
		if ($methos=="CL")
			return convertFrToC($res);
			
		return $res;
	}
	
	public static function convertFrToC($val){
		return (($val+40)*5/9)-40;
	}
	

}


//now it can also be used independently of the rest of the WeatherService 
//functions and main purpose...

$c = WeatherService::convertFrToC(22);

source

st, nd, rd, th to Number

function ordinal($n) {
    $ln = (int) substr($n, -1);
    $sln = (int) substr($n, -2);
    $r = array('st','nd','rd');
    $es = (($sln < 11 || $sln > 19) && $ln > 0 && $ln < 4);
    return $n . ($es ? $r[$ln - 1] : 'th');
  }

source

Cross-browser CSS Gradient

/* FireFox 3.6 */
background-image: -moz-linear-gradient(top, #9FD4FF, #008CFF);
/* Safari4+, Chrome */
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, #008CFF),color-stop(1, #9FD4FF));
/* IE6,IE7 */
filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#9FD4FF', endColorstr='#008CFF');
/* IE8 */
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#9FD4FF', endColorstr='#008CFF')";

source

Compress CSS with PHP

<?php
    ob_start ("ob_gzhandler");
    header("Content-type: text/css; charset: UTF-8");
    header("Cache-Control: must-revalidate");
    $offset = 60 * 60 ;
    $ExpStr = "Expires: " .
    gmdate("D, d M Y H:i:s",
    time() + $offset) . " GMT";
    header($ExpStr);
?>

body { color: red; }

source

thematic theme – add HOME link

function childtheme_menu_args($args) {
    $args = array(
        'show_home' => 'Home',
        'sort_column' => 'menu_order',
        'menu_class' => 'menu',
        'echo' => true
    );
	return $args;
}
add_filter('wp_page_menu_args','childtheme_menu_args');

source

Insert a value into a numerically-ordered array in the correct order

def insert_value_in_order(array_of_values, new_value, update_array = nil)
	value_index = array_of_values.index(new_value)
	index = 0
	if !value_index && array_of_values.last.to_i > new_value
		i = 0
		while array_of_values[i].to_i < new_value do
			i += 1
		end
		index = i
	else
		index = value_index ? value_index : -1
	end
	return update_array == true || update_array == 1 ? array_of_values.insert(index, new_value) : index
end

source

Spark Animated Filter example

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="<a href="http://ns.adobe.com/mxml/2009"" >http://ns.adobe.com/mxml/2009"</a> 
			   xmlns:s="library<a href="://ns.adobe.com/flex/spark"" >://ns.adobe.com/flex/spark"</a> 
			   xmlns:mx="library<a href="://ns.adobe.com/flex/mx"" >://ns.adobe.com/flex/mx"</a> 
			   minWidth="955" minHeight="600"
			   >
	
	
	<fx:Declarations>
	
		<s:BlurFilter
			
			id="blurFilter"
			blurY="0"
			/>
		
		<fx:Vector
			id="motionPathVector"
			type="spark.effects.animation.MotionPath"
			>
			<s:SimpleMotionPath
				
				id="blurXPath"
				property="blurX"
				valueFrom="0"
				valueTo="100"
				/>
		</fx:Vector>
		
		<s:AnimateFilter
			
			id="animFilter"
			target="{buttonGroup}"
			bitmapFilter="{blurFilter}"
			repeatBehavior="reverse"
			repeatCount="0"
			motionPaths="{motionPathVector}"
			/>
			
			
	</fx:Declarations>
	
	<s:HGroup
		
		id="buttonGroup"
		x="20"
		y="60"
		>
		<s:Button label="1" width="40" />
		<s:Button label="2" width="40" />
		<s:Button label="3" width="40" />
		<s:Button label="4" width="40" />
		<s:Button label="5" width="40" />
		<s:Button label="6" width="40" />
		<s:Button label="7" width="40" />
		<s:Button label="8" width="40" />
		<s:Button label="9" width="40" />
		<s:Button label="10" width="40" />
		
	</s:HGroup>
	
	<s:VGroup
		
		x="20"
		y="120"
		>
		
		<s:ToggleButton
			
			id="goBtn"
			label="{goBtn.selected? 'STOP' : 'GO'}"
			click="{goBtn.selected? animFilter.play() : animFilter.stop()}"
			/>
		
		
	</s:VGroup>
	
</s:Application>

source

Community Stats Plugin Custom CSS

/* Adjusts the background and left padding*/

div#bp_community_stats_widget-3.widget ul li {
background:none;
padding-left:20px;
}

/* Adjusts the font size*/

div#bp_community_stats_widget-3.widget ul, .widget div, .widget p {
font-size:15px;
}

/* Adjusts the color of the number count */

span.community-count {
color:#86A225; 
}

source

PHP Country Code to HTML Currency Symbol List

function country_currency( $amount = 0 ) {
    $bc = ''; // Set this to your country
    $currency_before = '';
    $currency_after = '';
    
    if( $bc == 'GB' || $bc == 'IE' || $bc == 'CY' ) $currency_before = '&pound;';
    if( $bc == 'AT' || $bc == 'BE' || $bc == 'FI' || $bc == 'FR' || 
        $bc == 'DE' || $bc == 'GR' || $bc == 'GP' || $bc == 'IT' ||
        $bc == 'LU' || $bc == 'NL' || $bc == 'PT' || $bc == 'SI' ||
        $bc == 'ES') $currency_before = '&euro;';
    if( $bc == 'BR' ) $currency_before = 'R$';
    if( $bc == 'CN' || $bc == 'JP' ) $currency_before = '&yen;';
    if( $bc == 'CR' ) $currency_before = '&cent;';
    if( $bc == 'HR' ) $currency_after = ' kn';
    if( $bc == 'CZ' ) $currency_after = ' kc';
    if( $bc == 'DK' ) $currency_before = 'DKK ';
    if( $bc == 'EE' ) $currency_after = ' EEK';
    if( $bc == 'HK' ) $currency_before = 'HK$';
    if( $bc == 'HU' ) $currency_after = ' Ft';
    if( $bc == 'IS' || $bc == 'SE' ) $currency_after = ' kr';
    if( $bc == 'IN' ) $currency_before = 'Rs. ';
    if( $bc == 'ID' ) $currency_before = 'Rp. ';
    if( $bc == 'IL' ) $currency_after = ' NIS';
    if( $bc == 'LV' ) $currency_before = 'Ls ';
    if( $bc == 'LT' ) $currency_after = ' Lt';
    if( $bc == 'MY' ) $currency_before = 'RM';
    if( $bc == 'MT' ) $currency_before = 'Lm';
    if( $bc == 'NO' ) $currency_before = 'kr ';
    if( $bc == 'PH' ) $currency_before = 'PHP';
    if( $bc == 'PL' ) $currency_after = ' z';
    if( $bc == 'RO' ) $currency_after = ' lei';
    if( $bc == 'RU' ) $currency_before = 'RUB';
    if( $bc == 'SK' ) $currency_after = ' Sk';
    if( $bc == 'ZA' ) $currency_before = 'R ';
    if( $bc == 'KR' ) $currency_before = 'W';
    if( $bc == 'CH' ) $currency_before = 'SFr. ';
    if( $bc == 'SY' ) $currency_after = ' SYP';
    if( $bc == 'TH' ) $currency_after = ' Bt';
    if( $bc == 'TT' ) $currency_before = 'TT$';
    if( $bc == 'TR' ) $currency_after = ' TL';
    if( $bc == 'AE' ) $currency_before = 'Dhs. ';
    if( $bc == 'VE' ) $currency_before = 'Bs. ';
    
    if( $currency_before == '' && $currency_after == '' ) $currency_before = '$';
    
    return $currency_before . number_format( $amount, 2 ) . $currency_after;
}

source