Pages

Sunday, November 28, 2010

css nav

Style the Navigation list


A list is used for navigation because it is good semantics.

The list is wrapped with a div with appropriate id:


Style the list, first remove the default style (bullets)

#nav ul{

list-style:none;

}

then give the list items a bottom border

#nav li{

border-bottom: 1px dotted #B2BCC6;

}

then style the link as display:block (instead of the default inline, see ).

#nav a{

display:block;

}

CSS layout

  • To make the container div at the center of the page:
  1. give it width (otherwise it will be Auto or 100%)
  2. margin-left:auto;
    margin-right:auto;
  • 3 columns layout div:
  1. header div is normal with width (or optional width if you use a wrapper div)
  2. left div has (float:left) (should has width)
  3. main div (float:left) (should has width)
  4. right div (float:right) (should has width)
  5. bottom div has clear both (should have height)
Tip: positioning with float, need the elements be in the right order (2,3 can be swapped)

Wednesday, October 6, 2010

OOP Javascript Inheritance


// Inheritance
function RunSampleE() {

var Dog = function (id, name, age, color) {
Dog.prototype.Color = color;
Dog.prototype.Age = age;
Dog.prototype.ID = id;
Dog.prototype.Name = name;
Dog.prototype.toString = function () {
return this.ID + '; ' + this.Name + '; ' + this.Age + '; ' + this.Color;
}
Dog.prototype.Bark = function () { alert('Hoow, Hoow'); }
}

// var buddy = new Dog(1, 'Buddy', 3, 'White');
var buddy = new Dog.prototype.constructor(1, 'Buddy', 3, 'White');
alert(buddy);
buddy.Bark();
Dog.prototype.New = function () { alert('Say new'); }
buddy.New();
}

OOP Javascript (Hints)

Hints
  • Use Visual studio 2010, for writing all the code, it support intellisense
  • Use /// , inside the Javascript file to reference other just to support intellisense
  • when you define function as class, like
    var Dog = function (id, name, age, color) {
    this.Color = color;
    this.Age = age;
    this.ID = id;} //you cannot use Dog.Color [Wrong]

    you have to initiate the object first like

    var buddy = new Dog(1, 'Buddy', 3, 'White');
    then you will call buddy.Color.

Sunday, September 26, 2010

JQuery basic code

//Hook change for each option to an event
<asp:Content ContentPlaceHolderID="ScriptPlaceHolder" ID="Scripts" runat="server">
   <script type="text/jscript" language="javascript">

$(document).ready(function () {
$("#listSamples").change(function (event) {

if (this.value == 'RunSampleA') {
RunSampleA();
return;
}

if (this.value == 'RunSampleB') {
RunSampleB();
return;
}
if (this.value == 'RunSampleC') {
RunSampleC();
return;
}
if (this.value == 'RunSampleD') {
RunSampleD();
return;
}
}
)
}
);
script>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="div_content">
content;
<select id="listSamples">
<option value='NULL'>Choose Sampleoption>
<option value='RunSampleA'>Run Sample Aoption>
<option value='RunSampleB'>Run Sample Boption>
<option value='RunSampleC'>Run Sample Coption>
<option value='RunSampleD'>Run Sample Doption>
select>
div>
asp:Content>

Sunday, September 19, 2010

JQuery basic code

$(document).ready(function(){ $("a").click(function(event){ alert("Thanks for visiting!"); }); });

Anonymous Methods 2

using System;


namespace DeligateTests.GenericDelegate
{

class GenericDelegateTest2 : IProgramTest
{
public string Name
{
get { return "Test Func method"; }
}

public string Description
{
get { return Name; }
}

public void Run()
{
var cus = new Customer {ID = 1, Name = "Jan, Joseph", BirthDate = DateTime.Parse("18/12/1971")};
Console.WriteLine(cus.ToString(c => c.Name + ", " + c.ID.ToString()));
Console.WriteLine(cus.ToString(c => c.BirthDate.ToShortDateString()));
// old way
Console.WriteLine(cus.ToString(delegate(Customer c) { return c.Name;}));


}
}

public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime BirthDate { get; set; }
public string ToString(Func<Customer,string> predicate)
{
return predicate(this);
}
}
}

Saturday, September 18, 2010

The Built-In Generic Delegate Declarations

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace DeligateTests.GenericDelegate
{
class GenericDelegateTest : IProgramTest
{
public string Name
{
get { return "Test Func method"; }
}

public string Description
{
get { return Name; }
}

public void Run()
{
var result = Directory.GetFiles(Environment.CurrentDirectory).Select(s => new { Value = s, Length = s.Length });
var res = GetProjections(new DirectoryInfo(Environment.CurrentDirectory).GetFileSystemInfos(), f => new { FullName = f.FullName, Extension = f.Extension });
}
IEnumerable GetProjections(IEnumerable en, Func selector)
{
var list = new List();
foreach (var obj in en)
{
list.Add(selector(obj));
}
return list.AsEnumerable();
}
}
}

Anonymous Methods

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Net3p5Features.Expression
{
public class AnonymouseMethodTest : IProgramTest
{
public string Name
{
get { return "Anonymouse Sample"; }
}

public string Description
{
get { return Name; }
}

public void Run()
{
var car = new Car
{
Brand = "BMW",
Model = "92",
OnRunning =delegate(object sender,EventArgs e)
{
Console.WriteLine("sender :{0} called from Anynomouse method", sender);
var s = "Hello world";
}
};
car.Run();

var car2 = new Car
{
Brand = "BMW",
Model = "92",
OnRan =
(sender, e) =>
{
Console.WriteLine("sender :{0} called from Anynomouse method", sender);
var s = "Hello world";
}
};
car2.Run();
}
}

public class Car
{
public string Brand { get; set; }
public string Model { get; set; }
public EventHandler OnRunning;
public EventHandler OnRan;

public void Run()
{
if (OnRunning != null) OnRunning(this, EventArgs.Empty);
Console.WriteLine("Model:{0}, Brand:{1}", Model, Brand);
if (OnRan != null) OnRan(this, EventArgs.Empty);

}

}


}

Generics

public delegate bool Filter(T dinfo); protected void TestExtensionWithLambda()
       {

Console.WriteLine("Enter the Min number of nested files:");
var noS = Console.ReadLine();

//IEnumerable directories = GetDirectories().OrderBy(d=>d.GetDirectories().Length);
IEnumerable<DirectoryInfo> directories = from d in GetDirectories()
orderby d.GetFiles().Length descending
select d;


var result = directories.Filter(d => d.GetFiles().Length >= int.Parse(noS));
Console.WriteLine("Original Collection={0}", directories.Count());
foreach (var dInfo in result)
{
Console.WriteLine("Name={0}, Dirctory Count={1}", dInfo.Name, dInfo.GetFiles().Length);

}
}
protected static IEnumerable<DirectoryInfo> GetDirectories()
       {

var dInfo = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
var dInfos = dInfo.GetDirectories("*", SearchOption.AllDirectories);
var list = from d in dInfos
select d;
return list;
}

Friday, September 17, 2010

OOP Javascript

//Simple OOP Sample

// in this Sample
// in this Sample I will Create objects like C# objects
// Hint all this code support Intellisense
function RunSampleA() {
var Car = new Object();
var Bus = new Object();
Bus.Car = Car;
Car.Name = "BMW";
Car.Width = 20;
Car.Size = { Width: 30, Height: 50 }; // like JSON
Car.Height = 50;
Car.Play = function () {
return this.Name + '; ' + this.Width.toString() + '; ' + this.Height.toString();
}
Car.Play2 = function () {
return this.Name + '; ' + this.Size.Width + '; ' + this.Size.Height;
}
alert(Car.Play());
alert(Car.Play2());
alert(Bus.Car.Play());
}

// Initialising and creating nested objects.

function RunSampleB() {
var ServiceManager = { CarService: 'My Car Service', ComputerService: 'My Computer Service',
FoodService: { DesertServices: "my desert service", Dinners: "Dinner Foods", "DoService": function (food) {
alert('Cooking ' + food);
}
}
};

alert(ServiceManager.CarService);
alert(ServiceManager.FoodService.DesertServices);
alert(ServiceManager.FoodService.Dinners);
alert(ServiceManager.FoodService.DoService('Yamme rice'));


}

//Object Model Sample with call back methods
function RunSampleC() {
var ServiceManager = new Object();
ServiceManager.CarService = 'My Car Service';
ServiceManager.ComputerService = 'My Computer Service';
ServiceManager.FoodService = new Object();
ServiceManager.FoodService.Dinners = "My Dinner";
ServiceManager.FoodService.DesertServices = "My Desert service";
ServiceManager.FoodService.DoService = function (food) {
alert('Cooking ' + food);
return 1;
}

ServiceManager.FoodService.DoCallbackService = function (food, cb) {
cb(food);
return 1;
}
alert(ServiceManager.CarService);
alert(ServiceManager.FoodService.DesertServices);
alert(ServiceManager.FoodService.Dinners);
// alert(ServiceManager.FoodService.DoService('Yamme rice'));
alert(ServiceManager.FoodService.DoCallbackService('rice', callBack));


}
function callBack(data) {
alert(data + ' was called from call back');


}



// Creatig objects that can be initialised with constructor
function RunSampleD() {

var Dog = function (id, name, age, color) {
this.Color = color;
this.Age = age;
this.ID = id;
this.Name = name;
this.toString = function () {
return this.ID + '; ' + this.Name + '; ' + this.Age + '; ' + this.Color;
}
this.Bark = function () { alert('Hoow, Hoow'); }
}

var buddy = new Dog(1, 'Buddy', 3, 'White');

alert(buddy);
buddy.Bark();

}

Monday, September 6, 2010

ASP.NET 4 & MVC2

Hint replace all $ by %

if the code will be run on the server but not renders
use this format
<$ sever code block ; $>

if the code will render output
use
<$ =sever code block (without;) $>
for encoded Html
<$ :sever code block (without;) $>

Tuesday, July 6, 2010

Force.com

Force.com code snippet.

Thursday, June 24, 2010

Guide lines for creating a Cube structure

Use a Real actual data not a sample data in development time, so if there any error that can be happened due to the quality of data like (logical keys, and computed columns that may generate null values,..) will be caught very quickly in the design time.
  1. Be sure that all foreign keys has values on primary tables, in case of different sources, create name Query and add any missing data from the parent as unknown values using union, or make an outer join and use the isnull() functions to replace the null values with unknown values or default missing values
  2. Use Regular relation (First Option) between the Dimension and the Fact, if the relation in the database is 1 to many (Dimension is one and fact is many)
  3. Create different Hierarchically in the Dimension, so you can browse the dimension with different break down.
  4. Do not change the source data structure, try to make all change in the Analysis server.
  5. Use Fact relation (Second Option) if the Fact and Dimension are the same table
  6. User Many-to many (Third Option)



    relation if you have a Fact want to make a relation with Dimension via another Fact that represented on a Measure group







  7. Use Reference relation



    (Last tricky Option)
    , if you want to link a Fact with Dimensions, that has indirect relation with the Fact dimension, this scenario will happen if you have multiple measure groups but if you have only one Dimension group, you can create a hierarchy in the dimension (in the development time, please untick materialized, with big data)
  8. Always make the Time dimension in the Server not in source database.
  9. Avoid big dimensions, do not try to construct dimension based on transaction tables, and if you did, do it in the group and summary level, not in the transaction level.

Monday, June 14, 2010

SQL 2008

Case
org_type =
CASE org_type
WHEN 'OTHER' THEN 'OTHERS'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE org_type
END


 getting last word has '\'
Select RIGHT(UploadPhysicalPath, CHARINDEX ('\',REVERSE (UploadPhysicalPath))-1),UploadPhysicalPath
  FROM [CLProjects].[dbo].[tbl_Projects]

Sunday, June 13, 2010

MDX Queries 2

TOPCOUNT

SELECT TOPCOUNT([DimCreationTime].[Year].[Year], 2,
[Measures].[NQ Download Count]) ON COLUMNS
, NON Empty [NQ Download].[Source].[Source] On ROWS
FROM [LRRDownloadsCube]

--------------------------------------
Cube Calculations {new Name Set}

// No select or dimensions

TOPCOUNT([Customer - Territory].[Name].[Name], 10,
[Measures].[Sub Total])


MDX Queries 1

Using Axis & Dimensions
SELECT NON EMPTY

[Measures].[NQ Learning Resource Publish To Count] ON COLUMNS
, NON EMPTY
([Tbl Status].[STS Value].[STS Value].ALLMEMBERS * [Tbl Copyright].[CPR Label].[CPR Label].ALLMEMBERS ) ON ROWS


FROM [LRRCreationCube]


-----------------------------------
Using tuples

SELECT // select a cell (tuple)
NON Empty
([Measures].[NQ Learning Resource Publish To Count] , [Tbl Status].[STS Value].&[Live],[Tbl Publish To].[PUB Value].&[TaLe]) ON COLUMNS

,
NON Empty [Tbl Copyright].[CPR Label].ALLMEMBERS ON ROWS // This axis is optional
FROM [LRRCreationCube]

note &[TaLe]

------
Using Set

SELECT
NON Empty
{
([Measures].[NQ Learning Resource Publish To Count],[Tbl Status].[STS Value].&[Live],[Tbl Publish To].[PUB Value].&[TaLe])
,
([Measures].[NQ Learning Resource Publish To Count],[Tbl Status].[STS Value].&[Live],[Tbl Publish To].[PUB Value].&[Public])
} ON COLUMNS

,
NON Empty
[DimCreationTime].[Year].ALLMEMBERS ON ROWS

FROM [LRRCreationCube]

------

Calculated member

WITH MEMBER Measures.Count10 AS
[Measures].[NQ Learning Resource Publish To Count]*10

SELECT NON Empty
{[Measures].[NQ Learning Resource Publish To Count],Measures.Count10} on columns
,NON Empty
[Tbl Status].[STS Value].&[Live]* Filter( [Tbl Copyright].[CPR Label].[CPR Label].ALLMEMBERS, Instr( [Tbl Copyright].[CPR Label].currentmember.Properties( 'Member_Caption' ), 'Share' ) > 0 ) ON ROWS

FROM [LRRCreationCube]
--------------------------------------------
Hint: Comma=Tuple, brace {}= Set

----------------------------------------------

Using Where
it is like slicing (adding another non displayed dimension to slice the result)

select Non Empty
[Measures].[NQ Download Count]
on COLUMNS
,
Non Empty

(
[NQ Download].[Source].&[PUBLIC]
,[DimRegionUsersCombined].[Org Type].[Org Type]
,[DimCreationTime].[Year].[Year]

) on ROWS

from [LRRDownloadsCube]

//Remove the &[PUBLIC] member value and added to where condition and will give the same effect, except will not appear


//where [NQ Download].[Source].&[PUBLIC]


--------------------------------------------
Using Filter

  • SELECT NON Empty
[Measures].[NQ Learning Resource Publish To Count] on columns

,[Tbl Status].[STS Value].&[Live]* Filter( [Tbl Copyright].[CPR Label].[CPR Label].ALLMEMBERS, Instr( [Tbl Copyright].[CPR Label].currentmember.Properties( 'Member_Caption' ), 'Share' ) > 0 ) ON ROWS

FROM [LRRCreationCube]


  • SELECT NON Empty
filter([DimCreationTime].[Year].[Year],[Measures].[NQ Download Count]>3000)
on COLUMNS
from [LRRDownloadsCube]



  • SELECT NON Empty
filter(
([NQ Download].[Source].[Source],[DimCreationTime].[Year].[Year],[Measures].[NQ Download Count])

,[Measures].[NQ Download Count]>3000)

on COLUMNS
,Non Empty
[NQ Learning Resource Live].[RES Depositor].ALLMEMBERS on rows
from [LRRDownloadsCube]

SQL 2008 Admin Tasks

SHRINK the LOG
USE [master]
GO
ALTER DATABASE [TestDb] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(TestDbLog, 1)
ALTER DATABASE [TestDb] SET RECOVERY FULL WITH NO_WAIT
GO




samples
USE LRR_PROD
GO
ALTER DATABASE LRR_PROD SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(LRR_Log, 1)
ALTER DATABASE LRR_PROD SET RECOVERY FULL WITH NO_WAIT
GO


USE cliwebservices
GO
ALTER DATABASE cliwebservices SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(cliwebservices_log, 1)
ALTER DATABASE cliwebservices SET RECOVERY FULL WITH NO_WAIT
GO



Backup 
BACKUP DATABASE [db_name] TO DISK = N'\\otfvclicwebuat\webuat\databasesbackup\Web2ServicesPortal.bak' WITH NOFORMAT, NOINIT, NAME = N'CLProjects-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO




Restore
RESTORE DATABASE[db_name] FROM DISK = N'C:\Projects\clic\Dashboard\BI\Others (do not check in)\db\MUM2008_PROD.bak' WITH FILE = 1, MOVE N'MUM08_PROD_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.OTP3222_MSSQL_08\MSSQL\DATA\[db_name].mdf', MOVE N'MUM08_PROD_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.OTP3222_MSSQL_08\MSSQL\DATA\[db_name]_1.ldf', NOUNLOAD, STATS = 10
GO