Skip to main content

Posts

Showing posts from March, 2017

Tutorial : Mule Creating a simplest flow using Http and Groovy component

In this example, we're going to create the simplest Mule app flow. Our flow basically consist of a Http and a Groovy component which looks like this :-






Using Groovy is optional and entirely up to developers to choose. If you're using it for simple and not so complicated task, then it is fine. Otherwise, Java gives you ability to debug through the code.
Groovy does give you direct access to message which you otherwise need to call getMessage() - [if you are to use java component ].

And here is our script looks like :-



User submits are request like this, http://localhost:3004/?username='jeremy'.

If it is jeremy, great, if not it returns invalid user.

For beginners, it's pretty hard to know what message property and types that are available.
Perhaps picture below would give a better way for newbies to work with mule in the future.











Tutorial : Mule Creating a simplest flow using Http and Java component

In this example, we're going to create the simplest Mule app flow. Our flow basically consist of a Http and a Java component which looks like this :-


User basically connects to something like this :- http://localhost:3003/?username=jeremy.

Query parameter called ussername get pass into java's class and returns "jeremy" or "unknow user" depending on the string passed.

Here is what our java class looks like :-




From the code above, our java class implements mule class callable and we attempted to extract username parameter from 'http.query.params' which is a Map object type. With this, we proceed to get our value by calling get Map's method 

Well, that's it. Done! :)







using mule cxf component

This is by far the coolest way to create a web service, using mule CXF. CXF is a component that allows you to easily create and expose a web service using Mule runtime.

Just create normal java interface and implements it. Cook up some Mule connector and you're good to publish your web service.

Lets create your interface.



Lets create your class. Notice we're not annotating it with @webservice.




Finish it up with the following Mule script :-



After this, we just have to consume this service and gets a return results.

using panda to find value matching certain criteria.

Say you have the following dataframe read into panda.

Id | F1    | F2      | Class
0  | True | True   | 0
0  | True | True   | 1
0  | True | True   | 0
0  | True | True   | 1

To select all the class with value 0 in a data frame, you can use

data.loc[data['Class'] == 0]

Class column name is case sensitive. You won't get anything out of using data['class'].


Mule Http Client Request logging

Best piece of logging i found - literally no code modification. Just add the following code in your log4j configuration file and all your logs will be revealed. :)



<AsyncLogger name="org.mule.module.http.internal.HttpMessageLogger" level="DEBUG" />
<AsyncLogger name="com.ning.http" level="DEBUG" />

Getting started with Credit Card Detection using xgBoost

One fine day i came across this article. Curiously wanted to see if this works, i found a way to quickly setup your machine to run it using docker. Yeap you can setup and run it in 30 minutes time.

All you have to do is install docker and run the following command


docker pull continuumio/anaconda docker run -i -t continuumio/anaconda /bin/bash This install anaconda with python 2.7. Don't worry about this version. Its all good plus xgboost works only on this version.

Additional library you might need to install are

conda install -c bioconda xgboost=0.6a2

conda install pyqt=4
After that, just run python and you can run all the command given in the article. 

django serving static files

In order to serve static files, you need to configure settings.py.  In this example, say we are hosting our static files under a folder called 'static' (and app) with a filename called index.html.


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['static', 'app'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

And finally set your "urls.py" 
from django.conf.urls import url from django.views.generic.base import TemplateView
urlpatterns = [     #url(r'^$', views.index, name='index2…

Golang Revel Web Framework for Windows installation

This is a guide to help setup Revel GoLang webframework on Windows.

So first thing you gotta do is install, golang here.

Next up, goto Revel website and follow


go get github.com/revel/cmd/revel It will install to "C:\Users\DefaultUserFolder\go\bin". So please add this to your PATH manually instead of the installation folder which is C:\Go. 

When you run the command above, you most likely don't need to run :- go build or go install.

Time to go! :)

Running XGBoost with R Studio

Let's say we are trying to use xgboost to make prediction about our data and here is a sample data that we're going to be using :-





Some terminology before moving on. R uses the term label to say, this is our expected output when we're building our model. Yes, it is really confusing. A label to becomes final output of our predictions.



Basically what we're trying to find is relation between smoking and high sugar intake will lead to a person having disease.  These are fake data of course.  There are people who smokes and eat as much choc as they like,  they still look sharp. (not me tho)

First we will create these data using R. Code example shows we're loading some libraries and then create a data frame called  'a'. Next it convert 'a' into a data table 'd'.

require(xgboost) require(Matrix) require(data.table) if (!require('vcd')) install.packages('vcd') a = data.frame(id=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, 18, 19…

bootstrap grid system col-sm-offset

Regardless of what, that offset is to say "hey, leave some gaps/space" for me. For example, say we have a grid of col-sm-10 and i specify col-sm-offset-2, that gives me something like a full grid with 2 2 column is reserved for spacing.

This is a good way to see this would be looking at example below :-



Was abit confusing, initially but I guess offset would have been ok.

git reverse commit is great.....

I found myself looking at a long list of commits which i need to remove. So i fire up my SourceTree and zoom in on list of commits that i need to undo. Right click on it and choose reverse commit. All the check-ins for that commit is gone.

That's it. :)