Shiva

Puppet syntax for if condition, variable, selector and class

Puppet Site:https://puppet.com/

Puppet Forge :https://forge.puppet.com/

git and puppet https://puppet.com/blog/how-to-use-git-commit-hooks-puppet-enterprise

Puppet variables=A variable hold the value for e.g.  x=1 where x is a variable which holds value 1.

Example that displays how to create and use variable in puppet

class linux{

    $admintools=['git','nano','othersoftware']
    
   package { $admintools:
      ensure=>'installed',
   }
}

 Puppet selectors =A selector assigns one of a set of possible values to a defined variable based on the condition
$ntpservice= variable
$osfamily = one of the fact from puppet

$ntpservice=$osfamily ? {
     'redhat' => 'ntpd',
     'debian' => 'ntp',
     'default' => 'ntp',
}

How to use it?

Replace 
service {'ntpd':
       ensure=>'running',
       enable => true,
}
With
service{$ntpservice:
       ensure => 'running',
       enable =>  true,
}

Class in puppet != Object Oriented Programming (oop) class  in puppet class represent  a named collection of resources declaration such as variable, selector or any other puppet code. It is simply a code container. Class does help to maintain DRY(Don’t repeat yourself principle).

How to create a class in puppet?

class linux{
   package{ 'ntp':
   ensure=> 'installed',
   }
}

How to use/reuse a class?

node 'wiki'{ {class 'linux':} }

node 'wikiexample'{ {class 'linux':} }

Use of If condition in puppet

//checking a condition if osfamily is redhat then install package otherwise skip the block of code
if $osfamily=='redhat'{
  package{'php-xml':
       ensure=>'present',
  }
}

A complete example showing  if condition, variable, selector and class usages in a file init.pp (,pp is the extension for the puppet file)

//define this code under init.pp
class mediawiki{

   $phpmysql=$osfamily ? {
    'redhat' => 'php-mysql'.
    'debian' => 'php5-mysql',
    default  =>  'php-mysql',
  }
  
  package{$phpmysql:
   ensure=>'present',
 }
if $osfamily=='redhat'{
    package{'php-xml':
    ensure=>'present', 
   }
 }
}
//end of code for init.pp

//create nodes.pp file

node 'wiki'{
   class {'mediawiki':}
}

node 'wikiTest'{
   class {'mediawiki':}
}

node 'wikiStage'{
   class {'mediawiki':}
}

node 'wikiProd'{
   class {'mediawiki':}
}
RESOURCE_TYPE { TITLE:
  ATTRIBUTE => VALUE,
  ...
}

Puppet Commands:

List all certificates

puppet cert list --all  # This code will show list of certificates 
puppet cert sing -a  #Sign all certificate

Useful links

http://www.infoq.com/

http://www.dotnetrocks.com/

http://www.theverge.com/

http://thehackernews.com/

http://bitnative.com

http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-and-entity-framework.htm

Automapper

http://cpratt.co/using-automapper-creating-mappings/

http://www.velir.com/blog/index.php/2012/08/27/organizing-automappers-map-configurations-in-mvc/

http://www.codeguru.com/columns/experts/using-automapper-in-your-asp.net-mvc-applications.htm

Repository

http://jasonwatmore.com/post/2015/01/28/Unit-of-Work-Repository-Pattern-in-MVC5-with-Fluent-NHibernate-and-Ninject.aspx

http://rahulrajatsingh.com/2014/06/understanding-repository-and-unit-of-work-pattern-and-implementing-generic-repository-in-asp-net-mvc-using-entity-framework/

http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-and-entity-framework.htm

http://gaui.is/how-to-mock-the-datacontext-entity-framework/

https://medium.com/@severinperez/writing-flexible-code-with-the-single-responsibility-principle-b71c4f3f883f

Zencoding using VS Essential Plugin

Create div with class date

div.date and press tab result  <div class=”date”></div>

Create two div with class date and details

div.date+div.details press tab result

<divclass="date"></div>
<divclass="details"></div>

Learning JavaScript

Creating Object in JavaScript

1) Dot  Notation

var object={}; object.value="This is a value";

2) Square Bracket Notation

var object ={};

object['value']="This is a value";

3) Anonymous Function

function functionWithName(){
 alert("Function with name");
}

var anonymous=function(){
 alert("Function without name");
}

4) Module Pattern

(function () {
  /* module code */
}) ( );

				
								
			

Enabling OData Queries in Web API

Enabling OData Queries in Web API

Add EnableQuery Attribute (Action filter)

Change the IEnumerable return type to IQueryable

Add AsQueryable() to convert the IEnumerable to an IQueryable

[EnableQuery()]

public IQueryable<Product> Get()

{

var productRepository=new ProductRepository();

return productRepositriy.Retrieve().AsQueryable();

}

Refactoring Repository

 First Repo
IpersonRepository repository = new ServiceRepository();
var people =repository.GetPeople();
foreach(var person in people)
{
    personListBox.Items.Add(person);
}
------------------------------------------
Second Repo

IpersonRepository repository = new CSVRepository();
var people =repository.GetPeople();
foreach(var person in people)
{
    personListBox.Items.Add(person);
}

-------------------------------------
ThirdRepo

IpersonRepository repository = new SQLRepositroy();
var people =repository.GetPeople();
foreach(var person in people)
{
    personListBox.Items.Add(person);
}
-------------------------------------------------
Add new class Repository Factory class
----------------------------------------------
public static class RepositoryFactory
{
   public static IPersonRepository GetRepository(string repositoryType)
   {
       IPersonRepository repo =null;
       switch(repositoryType) 
       {
          case RepoType.Service:
             return new ServiceRepository();
            
           case RepoType.CSV:
            return new CSVRepository();
         
          case RepoType.SQL:
           return new SQLRepository();
          
         default:
            throw new ArgumentException("Invalid Repository Type");
          
       }
       return repo;
   }
}
---------------------


public enum RepoType
{
    Service,
    CSV,
    SQL
}
Take Method and Extract to method FetchData Method that takes string argument

private void FetchData(string repositoyType)
{
    IpersonRepositroy repositroy = RepositoryFactory.GetRepository(repositroyTpye);
    var people =repository.GetPeople();
    foreach(var person in people)
   {
     personListBox.Items.Add(person);
   }
}

----------------------------------
Now going back to the each method and replace the code 

FetchData( RepoType.Service);
FetchData( RepoType.CSV);
FetchData( RepoType.SQL);

 

Responsive Typography

Responsive Web Typography  for Modern Web

Measurement and Scale

  • Using max-width to make text readable  @media{ min-width: 100em){p{}}
  • Using EMs(1ems=16px) or REMs =relative ems tide to the root element. For REM need to add poly fill to support older browers.
  • Don’t use pixel.
  • Use real content instead of garbage content.

Clean Up

  • Matching based on oval/ round, wide/tall, thick/thin.
  •  Performance, Progression, Proportion, Polish.

 Selecting Typography for different business

  • Select typeface the suits your business and  project.
  • Look after the pattern that industries follows.

Useful Resources

  • Typecast.com
  • fonts.com
  • webtype.com
  • fontdeck.com
  • typekit.com