Friday 8 July 2016

Azure AD Step by Step [Part 0] - What can you do with AAD?

Most of people know about the basic Azure AD (AAD), but I have spent a lot time to research about this topic. Today I would like to give you a quick view and step by step from basic to advance.

Azure Active Directory (Azure AD) is Microsoft’s multi-tenant cloud based directory and identity management service.

For application developers, Azure AD lets you focus on building your application by making it fast and simple to integrate with a world class identity management solution used by millions of organizations around the world.

I use Offer Management UI - a Microsoft project that I have done to show you the result.

The AAD was implemented successfully, if users want to use Offer Management UI, they need to be add to Azure directory and Group (in size AD).
They can belong many groups, one of their group should be allowed for the particular Element (Controller/Menu/API).
1. Define access control: This is a demo for access control table, we can list all elements in our tool and set the right access on each group. User must belong at least one group has checking (X) to access to an element.

Current group in our AD
Group
Observer
Editor
Admin
Demo Email
centric.observer
@outlook.com
centric.editor
@outlook.com
centric.Adm
@outlook.com
Control



Home
X
X
X
Help
X
X
X
View



Offer
X
X
X
Inventory

X
X
Offer Type


X
Offer Scenario


X
Model (API)



Offer - Read
X
X
X
Offer - Create

X
X
Offer - Deactive

X
X
Inventory – Read Blob

X
X
Inventory – Upload Blob


X
Inventory – Delete Blob


X
Inventory – Add to Inventory


X
Queue Graph – Load Graph

X
X

2. Easy to use: Developer can easy to set the right access to each group in each element.
-          Controller


-          View
-        
  API
 

3. Demo

Sunday 27 March 2016

Demo App with ModelView Matrix

GL_PROJECTION matrix is used to define the frustum. This frustum determines which objects or portions of objects will be clipped out. Also, it determines how the 3D scene is projected onto the screen. 
OpenGL provides 2 functions for GL_PROJECTION transformation. glFrustum() is to produce a perspective projection, and glOrtho() is to produce a orthographic (parallel) projection. Both functions require 6 parameters to specify 6 clipping planes; leftrightbottomtopnear and far planes. 8 vertices of the viewing frustum are shown in the following image.

OpenGL Perspective Viewing Frustum
The vertices of the far (back) plane can be simply calculated by the ratio of similar triangles, for example, the left of the far plane is;

OpenGL Orthographic Frustum
For orthographic projection, this ratio will be 1, so the leftrightbottomand top values of the far plane will be same as on the near plane.
You may also use gluPerspective() and gluOrtho2D() functions with less number of parameters. gluPerspective() requires only 4 parameters; vertical field of view (FOV), the aspect ratio of width to height and the distances to near and far clipping planes. The equivalent conversion from gluPerspective() to glFrustum() is described in the following code.

// This creates a symmetric frustum.
// It converts to 6 params (l, r, b, t, n, f) for glFrustum()
// from given 4 params (fovy, aspect, near, far)
void makeFrustum(double fovY, double aspectRatio, double front, double back)
{
    const double DEG2RAD = 3.14159265 / 180;

    double tangent = tan(fovY/2 * DEG2RAD);   // tangent of half fovY
    double height = front * tangent;          // half height of near plane
    double width = height * aspectRatio;      // half width of near plane

    // params: left, right, bottom, top, near, far
    glFrustum(-width, width, -height, height, front, back);
}


An example of an asymmetric frustum
However, you have to use glFrustum() directly if you need to create a non-symmetrical viewing volume. For example, if you want to render a wide scene into 2 adjoining screens, you can break down the frustum into 2 asymmetric frustums (left and right). Then, render the scene with each frustum.

Texture Matrix (GL_TEXTURE)

Texture coordinates (strq) are multiplied by GL_TEXTURE matrix before any texture mapping. By default it is the identity, so texture will be mapped to objects exactly where you assigned the texture coordinates. By modifying GL_TEXTURE, you can slide, rotate, stretch, and shrink the texture.

// rotate texture around X-axis
glMatrixMode(GL_TEXTURE);
glRotatef(angle, 1, 0, 0);

Color Matrix (GL_COLOR)

The color components (rgba) are multiplied by GL_COLOR matrix. It can be used for color space conversion and color component swaping. GL_COLOR matrix is not commonly used and is requiredGL_ARB_imaging extension.

Other Matrix Routines

glPushMatrix() : 
push the current matrix into the current matrix stack.
glPopMatrix() : 
pop the current matrix from the current matrix stack.
glLoadIdentity() : 
set the current matrix to the identity matrix.
glLoadMatrix{fd}(m) : 
replace the current matrix with the matrix m.
glLoadTransposeMatrix{fd}(m) : 
replace the current matrix with the row-major ordered matrix m.
glMultMatrix{fd}(m) : 
multiply the current matrix by the matrix m, and update the result to the current matrix.
glMultTransposeMatrix{fd}(m) : 
multiply the current matrix by the row-major ordered matrix m, and update the result to the current matrix.
glGetFloatv(GL_MODELVIEW_MATRIX, m) : 
return 16 values of GL_MODELVIEW matrix to m.

Demo:

Source Code: Download Here

Friday 22 August 2014

Parse JSON String by SQL script

The first question: Why do you need to parse JSON by SQL script? You can do it easily by C# or VB, or any PL.
But I sure that if you search this keyword and reach this post, you already have your own reason.
In my case, I got a task from Chris (my manager) in Microsoft, he want to migrate database, one of those step is parse about 100 k Json string and Insert into new table.
I have tried with C#, it worked, but I don't know how long, because I recognize that it is not a smart way and stop them ( program is running and thinking about C# solution). I try with SQL script.

Thanks 
And then try with script
Select * From
parseJSON
(
       '[{"Text":"YES","Value":"YES","Default":true},
       {"Text":"NO","Value":"NO","Default":false}]'

)

Great because we can get all field we need, but that is not the format we want. We should have table with three field TEXT, VALUE and Defaule.

That's why we need do more a little


  • Use this script to query table from JSON string
Select
       max(case when name='Text' then convert(Varchar(50),StringValue) else '' end) as [Text],
       max(case when name='Value' then convert(Varchar(50),StringValue) else '' end) as [Value],
       max(case when name='Default' then convert(bit,StringValue) else 0 end) as [Default]
From parseJSON
(
       '[{"Text":"YES","Value":"YES","Default":true},
       {"Text":"NO","Value":"NO","Default":false}]'
)
where ValueType = 'string' OR ValueType = 'boolean'
group by parent_ID


And this is result


All things I need are some where here, I hope you too.
If you have some problem with this Function, feel free to comment here.
Thanks

Reference: 
  1. https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/
  2. http://msdn.microsoft.com/en-us/library/ms187928.aspx
  3. http://www.w3schools.com/sql/func_convert.asp

Wednesday 14 August 2013

How to style default Joomla! Pagination with CSS

Most of the sites we design have plenty of fancy elements, but we always end up with a simple or unstyled page navigation list. The PSD always looks unique, but the web version falls short of the designers’ expectations. This is because there are no CSS selectors on the arrows, start, prev, next, end or numbers.
I probably looked at the custom pagination.php 100 times, before realizing how simple it was to add a CSS class to each element.
Ok, time for the good stuff. Here are the simple steps required to add CSS classes to your Joomla! page navigation (pagination) elements:
  1. Create a file named pagination.php in the “html” folder of your template directory. The file structure should be “/templates/yourtemplatename/html/pagination.php”.
  2. Copy the content of this file (pagination.txt) to your newly created pagination.php file.
  3. Open pagination.php and replace this:
    function pagination_item_active(&$item) {
    return "<li><a href=\"".$item->link."\" title=\"".$item->text."\">".$item->text."</a></li>";
    }
    function pagination_item_inactive(&$item) {
    return "<li><span>".$item->text."</span></li>";
    }
    with this:
    function pagination_item_active(&$item) {
    
    //Custom variable created to use as the element class
    $item_class = strtolower($item->text);
    if(is_numeric ($item_class)) {
    $item_class .= " number";
    }
    return "<li class=\"".$item_class."\"><a href=\"".$item->link."\" title=\"".$item->text."\">".$item->text."</a></li>";
    }
    
    function pagination_item_inactive(&$item) {
    
    //Custom variable created to use as the element class
    $item_class = strtolower($item->text);
    if(is_numeric ($item_class)) {
    $item_class .= " number";
    }
    return "<li class=\"".$item_class."\"><span>".$item->text."</span></li>";
    }
Now the li elements of each pagination item should have a class that matches the text of the element. In addition, the numbers should have a second class of “number.”
Your HTML should look like this:
<ul class="pagination">
    <li class="start"><span>Start</span></li>
    <li class="prev"><span>Prev</span></li>
    <li class="1 number"><span>1</span></li>
    <li class="2 number"><a title="2" href="/category/Page-2">2</a></li>
    <li class="3 number"><a title="3" href="/category/Page-3">3</a></li>
    <li class="next"><a title="Next" href="/category/Page-2">Next</a></li>
    <li class="end"><a title="End" href="/category/Page-3">End</a></li>
</ul>

Tuesday 23 July 2013

Create Facebook comment and Like button for each page ( each Link, each Product)

Create Like Button
- Go to https://developers.facebook.com/docs/reference/plugins/like/
- Clear URL to Like and choice some options by yourself.
- Press Get Code and paste those code on your source code.

Create Comment Facebook
- Go to https://developers.facebook.com/docs/reference/plugins/comments/
- Clear URL to comment on and choice some options by yourself
- Press Get Code and paste those code on your source code with some changes.
- Include code
data-href="http://yourweb.com<?=$_SERVER['REQUEST_URI']?>"
 into this code:
<div class="fb-comments" data-width="470" data-num-posts="10"></div>
This is the final code to put comment box to. Example your website is http://bantudong.com
<div class="fb-comments" data-href="http://bantudong.com<?=$_SERVER['REQUEST_URI']?>" data-width="470" data-num-posts="10"></div>

Sunday 21 July 2013

Correct Facebook share thumbnail and description - Joomla 2.5 & Virtuemart 2.0

This is a great way to add Open Graph meta tags to the flypage of Virtuemart, to specify the image used by Facebook like, share, send, etc buttons 
I have made some little improvements to your code though, so that it will not be necessary to hard code the domain name of your site and also i added the og::site_name meta tag.
Also I wanted the generated html code to be valid (http://validator.w3.org/) so i had to use addCustomTag() instead of setMetaData() to generate "meta property" instead of "meta name" .

Code: 
$og_type = 'article';
$og_url = JURI::current();
$og_image =  JRoute::_(JURI::base().$this->product->images[0]->file_url);
$og_desc = $this->product->product_s_desc;
$og_title = $this->product->product_name;

$app =& JFactory::getApplication();
$og_sitename = $app->getCfg('sitename');

$doc = JFactory::getDocument();
$doc->addCustomTag('<meta property="og:type" content="article"/>');
$doc->addCustomTag('<meta property="og:url" content="'.$og_url.'"/>');
$doc->addCustomTag('<meta property="og:site_name" content="'.$og_sitename.'"/>');
$doc->addCustomTag('<meta property="og:image" content="'.$og_image.'"/>');
$doc->addCustomTag('<meta property="og:description" content="'.$og_desc.'"/>');
$doc->addCustomTag('<meta property="og:title" content="'.$og_title.'"/>');


This piece of code has to be inserted at the first lines of file "components/com_virtuemart/views/productdetails/tmpl/default.php" just after the line:

Code: 
defined('_JEXEC') or die('Restricted access');
It would be even better if you copy this file at your template directory (folder: templates/my_Joomla_template/html/com_virtuemart/productdetails/) so that it will not be modified by any Virtuemart upgrades.


Check this Change by link:
https://developers.facebook.com/tools/debug

Product sort order on browse/category view - ascending to descending

Problem:
When i show virtuemart home page the product will show in ASC order , (the oldest first) how can i change this with the newest first ?
In the configuration i use date_created_on , if i press this option (in selectbox) is correct but i would that was by default

Solution:
change file: /administrator/components/com_virtuemart/models/product.php
Find the following code:
Code: [Select]
/* invert order value set*/
if ($order =='ASC') {
$orderlink ='&order=DESC';
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_DESC');
} else {
$orderTxt = JText::_('COM_VIRTUEMART_SEARCH_ORDER_ASC');
$orderlink ='';
}

and just switch the order. Be AWARE that this will change all your default sort by to descend.

ALSO, Do you have SEF on or off?

if SEF on, then go to /components/com_virtuemart/router.php.
Inside the file, move the following:
Code: [Select]
if ( isset($query['order']) ) {
if ($query['order'] =='DESC') $segments[] = $helper->lang('orderDesc') ;
unset($query['order']);
}
to after 
Code: [Select]
if ( isset($query['orderby']) ) {
$segments[] = $helper->lang('by').','.$helper->lang( $query['orderby']) ;
unset($query['orderby']);
}