Wednesday, October 23, 2013

How to read a character using scanf in a loop

It is tricky to read a character in a loop using scanf function.

if you use scanf like below
#include <stdio.h>
 
int main(void) {
  char ch;
  do
  {
    printf("enter a char: ");
    scanf("%c", &ch);
 
    printf("\nentered: %c\n", ch);
  } while(ch != 'q');
 
  return 0;
}

You will see an output like below
enter a char: s

entered: s
enter a char: 
entered: 

enter a char: 

The second input get automatically printed. This is because the when you reading characters using scanf, it reads all the types of characters one by one, including the special characters like "enter". Therefore, in this case it reads "s" character in the first scanf and "enter" in the next scanf. But if you read a integer (%d) using scanf then this does not happen, thats because %d discard all the special characters and only reads the integer part.

You can instruct the scanf to ignore the special characters by prefixing %c by a space character. See the following example.
#include <stdio.h>
 
int main(void) {
  char ch;
  do
  {
    printf("enter a char: ");
    scanf(" %c", &ch);
 
    printf("\nentered: %c\n", ch);
  } while(ch != 'q');
 
  return 0;
}

You will see the following output
enter a char: s

entered: s
enter a char: 

Wednesday, October 16, 2013

How to check whether the GPU support power profiling in NVIDIA Visual Profiler

CUDA 5.5 announced that NVIDIA's Visual Profiler supports power, thermal and clock profiling. I tried the profiler on a GTX 480, but it only profile the thermal values in different timestamps, but not power nor clock.

If you are wondering whether your GPU supports power profiling, you can verify it by running the following command.

nvidia-smi -q -d power

This command should return something similar to below with actual power values.

Attached GPUs                       : 1
GPU 0000:00:00.0
    Power Readings
        Power Management            : XXX
        Power Draw                  : XXX
        Power Limit                 : XXX
        Default Power Limit         : XXX
        Enforced Power Limit        : XXX
        Min Power Limit             : XXX
        Max Power Limit             : XXX

If the values are "N/A", then your GPU does not support power profiling.

Monday, May 14, 2012

Webinar - Using WSO2 Carbon to Help Convert One-Sixth of New Zealand’s Population into Mobile Telecom Customers

The webinar for my previous post - WSO2 Middleware to Enable Mobile Services for Telecommunications is scheduled on 17th May 2012.

Join Asanka Abeysinghe, WSO2 Director Solutions Architecture, and Waruna Ranasinghe, WSO2 Senior Software Engineer, along with Guest Speaker Neeraj Satja, 2degrees Mobile Software Development Manager, for a discussion on how the WSO2 Carbon enterprise middleware platform has enabled 2degrees to deliver the innovation, high volume and high performance required to be a mobile market leader.


Sunday, March 11, 2012

WSO2 Middleware to Enable Mobile Services for Telecommunications

"With WSO2 Carbon, we’ve found a strong middleware platform that is enabling us to deliver the innovation, high volume and high performance required to be a mobile market leader." says 2degrees Software Development Manager Neeraj Satija.

2Degrees Mobile, despite being the newest mobile company in New Zealand, has been able attract 1/6 of the New Zealand population. Having entered a saturated market, 2Degrees has been providing innovative services to users to attract customers from established mobile companies. WSO2 Middleware Platform (i.e WSO2 ESB) has facilitated them to enable innovative mobile services rapidly. It is the WSO2 Middleware that enabled 2Degrees to increase the response to the market by providing most suited middleware to rapidly implement mobile services. 

Currently, 2 Degrees uses WSO2 ESB, WSO2 DSS and WSO2 BPS to enable Mobile Services to the customers.

Read More...
Download the complete case-study.

Saturday, November 26, 2011

How to read HTTP headers through Synapse Config

You can use the following property mediator to read HTTP headers inside WSO2 ESB through Synapse Configuration.
<property name="Lang" expression="get-property('transport', 'Accept')"/>

Here, the value of the HTTP header called "Accept" get assigned in to property called "Lang"

Thursday, November 24, 2011

How to apply throttling policies through service.xml

You can always apply throttling to services deployed in WSO2 AS using the Management console. But what if you want to apply the throttling policy while the service get deployed. Then you can specify the throttling policy in the service.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was auto-generated from WSDL -->
<!-- by the Apache Axis2 version: 1.6.1-wso2v1  Built on : Jun 08, 2011 (07:37:38 IST) -->
<serviceGroup>
    <service name="echo">
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.wso2.carbon.sample.service.echo.EchoMessageReceiverInOut"/>
        </messageReceivers>
        <parameter name="ServiceClass">org.wso2.carbon.sample.service.echo.EchoSkeleton</parameter>
        <parameter name="useOriginalwsdl">true</parameter>
        <parameter name="modifyUserWSDLPortAddress">true</parameter>
        <operation name="echoString" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoString</actionMapping>
            <outputActionMapping>urn:echoStringResponse</outputActionMapping>
            <faultActionMapping faultName="echoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault">urn:echoFaultMessage</faultActionMapping>
            <faultActionMapping faultName="EchoFault_Exception">urn:echoFaultMessage</faultActionMapping>
        </operation>
        <operation name="throwAxisFault" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:throwAxisFault</actionMapping>
            <outputActionMapping>urn:throwAxisFaultResponse</outputActionMapping>
        </operation>
        <operation name="echoStringArrays" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoStringArrays</actionMapping>
            <outputActionMapping>urn:echoStringArraysResponse</outputActionMapping>
        </operation>
        <operation name="echoOMElement" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoOMElement</actionMapping>
            <outputActionMapping>urn:echoOMElementResponse</outputActionMapping>
        </operation>
        <operation name="echoInt" mep="http://www.w3.org/ns/wsdl/in-out" namespace="http://echo.services.core.carbon.wso2.org">
            <actionMapping>urn:echoInt</actionMapping>
            <outputActionMapping>urn:echoIntResponse</outputActionMapping>
        </operation>
 
       <module ref="wso2throttle"/>
       <wsp:Policy wsu:Id="WSO2ServiceThrottlingPolicy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <wsp:ExactlyOne>
    <wsp:All>
      <throttle:ServiceThrottleAssertion xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">172.16.49.1</throttle:ID>
          <wsp:Policy>
            <throttle:Control>
              <wsp:Policy>
                <throttle:MaximumCount>2</throttle:MaximumCount>
                <throttle:UnitTime>20000</throttle:UnitTime>
                <throttle:ProhibitTimePeriod wsp:Optional="true">30000</throttle:ProhibitTimePeriod>
              </wsp:Policy>
            </throttle:Control>
          </wsp:Policy>
        </wsp:Policy>
        <wsp:Policy>
          <throttle:ID throttle:type="DOMAIN">other</throttle:ID>
          <wsp:Policy>
            <throttle:Deny/>
          </wsp:Policy>
        </wsp:Policy>
      </throttle:ServiceThrottleAssertion>
    </wsp:All>
  </wsp:ExactlyOne>
</wsp:Policy>
    </service>
</serviceGroup>

Tuesday, August 9, 2011

WSO2Con 2011

Architects, Developers, IT Managers and technology enthusiasts, WSO2Con 2011, focuses on you! Newbie or seasoned professional, WSO2Con offers a great week of learning, sharing and the opportunity to connect with experts who have shaped the future enterprise. Register here

Sunday, April 3, 2011

How to hide vertical grid lines in jQuery flot

There is a straight forward method to hide vertical or horizontal grid lines in your jQuery flot bar chart. First of all you need to checkout the flot trunk and include jquery.flot.js and jquery.flot.stack.js scripts in your script. You need the trunk, since released flot - 0.6 does not support this feature.

Then include the following as the options.
xaxis: {
  tickLength: 0
}

 i.e.
<script id="source">
$(function () {
    var d1 = [];
    for (var i = 0; i <= 10; i += 1)
        d1.push([i, parseInt(Math.random() * 30)]);
 
    var d2 = [];
    for (var i = 0; i <= 10; i += 1)
        d2.push([i, parseInt(Math.random() * 30)]);
 
    var d3 = [];
    for (var i = 0; i <= 10; i += 1)
        d3.push([i, parseInt(Math.random() * 30)]);
 
    var stack = 0, bars = true, lines = false, steps = false;
 
    function plotWithOptions() {
        $.plot($("#placeholder"), [ d1, d2, d3 ], {
            series: {
                stack: stack,
                lines: { show: lines, steps: steps },
                bars: { show: bars, barWidth: 0.6, align: "center" }
            },
            xaxis: { tickLength: 0}
        });
    }
 
    plotWithOptions();
});
</script>






Friday, March 4, 2011

How to list all svn externals recursively

You can use the following command to list all the svn externals in a directory structure.

svn propget svn:externals -R

Wednesday, March 2, 2011

How to get the transitive dependency list using Maven

You may need to find the list of transitive dependencies, so that you can exclude unnecessary dependencies. Add the following maven plugin

  <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

Use dependency:tree as the goal.

mvn clean install dependency:tree

If maven fails with some error, then, use dependency:tree as the goal with -X option.

mvn clean install dependency:tree -X

Sample:

com.hp.hpl.jena.wso2:arq:bundle:1.0.0.wso2v1
+- com.ibm.icu:icu4j:jar:3.8:compile
\- com.hp.hpl.jena:arq:jar:2.8.3:compile
   +- com.hp.hpl.jena:jena:jar:2.6.2:compile
   |  +- org.slf4j:slf4j-log4j12:jar:1.5.6:runtime
   |  \- log4j:log4j:jar:1.2.13:runtime
   +- com.hp.hpl.jena:iri:jar:0.8:compile
   +- org.codehaus.woodstox:wstx-asl:jar:3.2.9:compile
   |  \- stax:stax-api:jar:1.0.1:compile
   +- org.apache.lucene:lucene-core:jar:2.3.1:compile
   +- junit:junit:jar:3.8.1:compile (version managed from 4.5)
   +- org.slf4j:slf4j-api:jar:1.5.8:compile
   \- xerces:xercesImpl:jar:2.7.1:compile
------------------------------------------------------------------------

Tuesday, February 8, 2011

How to Deploy WSO2 BPS on JBoss

This article from Pavithra provides step by step directions to deploy WSO2 BPS 2.0.2 in JBoss 5.1.0 GA.
WSO2 BPS can also be installed on other application servers as well. Refer Oxygen Tank for more information.

Monday, February 7, 2011

Orchestration vs Choreography

Service orchestration and service choreography are widely spoken topics when it comes to service composition. Lets take a look at the definitions.

Orchestration

Analogy: Orchestra

Applause

The conductor of the orchestra is the one who knows the entire composition. The musicians in the orchestra do not necessarily have to know what other musicians part or what they do. The musicians just have to know how play their instrument in which they best at. The conductor orchestrate the group of musicians to achieve the final output (composition).

Orchestration is the coordination of web services in order to compose the business processes. The business process plays the role of orchestrator/conductor and coordinate the services to fulfill the business process. The individual web services do not aware (it is not necessarily need to know) of the other services involved in the process and the services even do not know that they participate in a business process, they just serve the requests. WS-BPEL specification is an example. WS-BPEL is a language for defining processes that can be executed on an orchestration engine such as WSO2 BPS.

Choreography

Analogy: Group Dance
Hacettepe University Folk Dances Group

Each and every dancer know, exactly what to do and what other dances will do. They synchronize them selves according to the other dances.  The dancers aware of the each others moves.

Therefore, in choreography, services do not rely on a central coordinator. Each of the service, knows exactly when to execute them selves and when to talk to its peers and sync up. WS-CDL standard is an example.

References: http://www.infoq.com/news/2008/09/Orchestration

Sunday, September 12, 2010

WSO2Con 2010

WSO2 celebrates 5th year anniversary with WSO2Con 2010.




The conference will feature some of WSO2’s most renowned technical thought leaders. Topics range from Platform-as-a-Service (PaaS) and On-Premise Cloud Systems, Enterprise Security, Governance, and Managing Business Processes.

Most importantly, there will be a demo of an end to end business scenario which is powered by WSO2 product stack.

Still not too late. Register for WSO2Con 2010.


Friday, July 16, 2010

WSO2 Business Activity Monitor 1.1.0 Released

WSO2 Business Activity Monitor (WSO2 BAM) is a tool designed to exercise Business Activity Monitoring (BAM). WSO2 BAM is intended to serve the needs of both business and IT domain experts to monitor and understand business activities within a SOA deployment. It is specifically designed for monitoring SOA deployments, and can be extended to cater for other general monitoring requirements as well.

New Features:
  • Support for Oracle DBMS
  • Error category monitoring for WSO2 ESB mediation data
  • Improvements to analytics summary calculations, storage and visualization
  • Support for deployment on JBoss, Apache Tomcat, and WebLogic Application servers
  • Improved P2 based provisioning and feature management support
  • Support for deleting Monitored Servers

Thursday, July 15, 2010

WSO2 Webinar - Business Processes with Human Smarts


What is a business process? A series of steps that need to be performed in order to provide goods or services. Processes that used to be performed by humans are becoming increasingly automated by enterprise IT, allowing them to be performed more quickly and reliably and at much greater scale. But there can be unintended consequences - reverberation of failures, lack of accountability, an inability to handle situations outside the norm.
So why are business processes challenging to get right? Getting it right often means striking a good balance between automation and using the wisdom and flexibility of the human mind. But the technologies and systems for automating interactions which include humans differs substantially from automating interactions among software applications. This gulf has been difficult to bridge. Until now.
The recent introduction of two new standards in this space - BPEL4People and WS-Human Task - enables organizations to extend automated systems smoothly to include human interaction. WSO2 supports these new capabilities in the latest release of the WSO2 Business Process Server.
Your presenter, Milinda Pathirage, will cover the following topics:
Scenarios highlighting business process involving humans
Insights into BPEL4People and WS-Human Tasks
Overview of the WSO2 Business Process Server
Review of the new human-interaction features of the latest version of the WSO2 BPS
Who should attend:
Architects and developers expanding their toolkit to include business processes
Business process analysts
Consultants and analysts specializing in SOA
Milinda Pathirage is product manager for the WSO2 Business Process Server and is an active contributor for Apache ODE project. He brings a wealth of knowledge on business processes and how enterprises leverage these technologies today.

Wednesday, July 14, 2010

MySQL with C/C++ - My First BLOG post

MySQL with C/C++

WSO2 Business Process Server 2.0.0 Released

WSO2 Business Process Server (WSO2 BPS) 2.0.0 is released few weeks back.
WSO2 BPS is an opensource BPEL process engine which support BPEL4People and WS-HumanTasks

New features are:
  • BPEL4People and WS-HumanTask Support(Experimental)
  • Instance cleanup scheduled task for production deployments
  • Component manager to install and uninstall features (provisioning support)
  • External service invocation via JMS
  • XPath extension support
  • Various bug fixes and performance improvements for Apache ODE
WS-HumanTask support is in its early stages. The upcoming releases will provide comprehensive support for Human Tasks. 

Component manager is a cool feature which enables you to install other features to BPS server. For instance, now you can install WSO2 ESB or any other WSO2 products' features to the BPS server itself. 

You can find a sample XPath extension for WSO2 BPS here.


WSO2 BPS is an opensource product. If you found an issue, please raise a jira at https://wso2.org/jira/browse/CARBON under BPEL and HumanTask components.
Please feel free to fix issues and attach patches as well ;)

Friday, February 12, 2010

How to enable Google Buzz

If you haven't offered Google buzz yet, you can try it by enabling multiple inboxes in Gmail Labs and set is:buzz in one of the empty panes.


Reference: http://aext.net/2010/02/12-undocumented-tricks-for-google-buzz/

Saturday, January 2, 2010

Batch Resize Images in GIMP

It is always required to resize a set of images at once. So that, no need to do it one by one. Let's see, how this can be achieved using GIMP image editor in Ubuntu.

We are using the batch mode of GIMP to do image processing from the command line. Let's write a simple script in Scheme language to resize a set of image files.

(define (batch-resize pattern width height)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))

This particular script takes a pattern for filename, desired width and height as inputs and resize all image files that are matched. This script overwrite the existing file. In order to run the script, save it with .scm extension in the ~/.gimp-/scripts/ directory.
Then goto the directory which contains images, then run the following command to resize images.

gimp -i -b '(batch-resize "*.JPG" 604 453)' -b '(gimp-quit 0)'
The above command will resize all the image files end with .JPG to 604X453
The above script can be customized to any other image processing requirements as well. Refer the Help -> Procedure Browser in GIMP for more operations.

The following script rename the resized image file by adding 'a' to the beginning of the file name

(define (batch-resize-rename pattern width height)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(gimp-image-scale-full image width height INTERPOLATION-CUBIC)
(let ((nfilename (string-append "a" filename)))
(gimp-file-save RUN-NONINTERACTIVE image drawable nfilename nfilename))
(gimp-image-delete image))
(set! filelist (cdr filelist)))))

By referring to the GIMP procedure and plugins browser and a Scheme tutorial, it is possible to customize the above script as required.

References:

Friday, November 20, 2009

How to write a BPEL extension for WSO2 BPS 1.1.0 and Apache ODE

You may always wanted to write your own BPEL activity to handle your scenario. This article will go through step by step process to implement a simple BPEL extension activity for WSO2 BPS and Apache ODE.
WSO2 Business Process Server (BPS) is an easy-to-use open source business process server that executes business processes written using the WS-BPEL standard. It is powered by Apache ODE (open source BPEL engine) and provides a complete Web-based graphical console to deploy, manage and view processes in addition to managing and viewing process instances.

Implementation of Extension Bundle

Create a class by implementing one of the ExtensionOperation interfaces which are available at [1]. The run* method of this class should contain the implementation of the extension activity. You can find a sample implementation of this class at [2].
Then You have to create a class by implementing AbstractExtensionBundle interface. Within this class, the above implemented ExtensionOperation class should be registered. A sample implementation can be found at [3].

Configure WSO2 BPS

There are two methods to expose the extension classes to BPS.
  • Creating a jar.

    Copy the jar to BPS_HOME/repository/components/lib directory.
  • Creating an OSGI bundle

    Copy the bundle to BPS_HOME/repository/components/dropins directory.
Add the following configuration entry to the bps.xml file in BPS_HOME/conf directory. Repalce org.wso2.bps.samples.extension by your extension class name.
Note: By default, the sample extension bundles shipped with WSO2 BPS are copied to BPS_HOME/repository/components/lib. You have to add the following configuration to get them registered in BPS.
<bps xmlns="http://wso2.org/bps/config">
...
<extensionBundles>
<runtimes>
<runtime>org.wso2.bps.samples.extension</runtime>
</runtimes>
</extensionBundles>
...
</bps>
Now, restart WSO2 BPS sever, and you are ready to use the new extension in your BPEL.

The process is almost the same for Apache ODE. But there is a separate configuration file to register the extension. Please refer ODE extensions documentation for more details.

Using the Extension activity in your BPEL

The extension must be declared before, it is used.
<bpel:process...>

<bpel:extensions>
<bpel:extension namespace="#extension-namespace#" 
                        mustUnderstand="yes|no"/>
</bpel:extensions>

...
</bpel:process>
If the mustUnderstand attribute is set to yes, then the extension should be registered in BPS server in order to deploy the BPEL process. Otherwise, it will throws an error at the compilation stage of the process. If the mustUnderstand attribute is set to no, then the BPEL process will be deployed without checking whether there is an extension registered in the server.

Using the activity. According to the sample anyElementQName should be equal to b4ptest
<extensionActivity>
<anyElementQName standard-attributes>
standard-elements
</anyElementQName>
</extensionActivity>
You can find a sample BPEL process at TestExtensionActivity.zip

References:

[1] - extension