19 January 2014

jboss7_mod_util

Because the "modules" in jboss7 is the worst thing ever, it like manage maven dependencies by hand...

I decided to write some shell scripts to help me manipulate and organize the modules..

The first script is "mod_create", to create a module....
the second script is "mod_dependency_add", to add module dependency to existing module...

My plan is to add additional scripts for example ...

"mod_modify" to add jars to existing module

Any contributions are welcome .....

The project is on github at:

https://github.com/MuhammadHewedy/jboss7_mod_util

Thanks.

18 November 2013

Request WebService simply with cURL

If you have a webservice you need to consume, you can simply test it using cURL as follows:

curl
-d 'soap request, you can create yourself, or let any tool create it for you, Eclipse can do.'
-H "Content-Type: text/xml; charset=utf-8" -- Content type, and you should specify it.
then the webservice URL, for example http://www.w3schools.com/webservices/tempconvert.asmx


Example:

curl -d '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/"> <Celsius>20</Celsius> </CelsiusToFahrenheit> </soap:Body> </soap:Envelope>' -H "Content-Type: text/xml; charset=utf-8" http://www.w3schools.com/webservices/tempconvert.asmx

03 November 2013

Unboxing NPE in Java

It is very famous error, and you can find it in google very easy.

I am just trying to duplicating it here...

import java.util.List;
import java.util.ArrayList;

public class Unboxing{
    public static void main(String[] args){
        List<Integer> list = new ArrayList();
        list.add(getInteger());
        int x = list.get(0);
        System.out.printf("x value is %i\n", x);
    }

    private static Integer getInteger(){
        return null;
    }
}


And here's the result

$ java Unboxing 
Exception in thread "main" java.lang.NullPointerException
    at Unboxing.main(Unboxing.java:8)

That's all folks.

04 October 2013

SemVer, an Versioning guidelines

http://semver.org/ is very simple, yet powerful versioning specs (guidelines) - you should read the whole page.

Highlights:

Given a version number MAJOR.MINOR.PATCH, increment the:
  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards-compatible manner, and
  3. PATCH version when you make backwards-compatible bug fixes.

Example:


// suppose I've some software lib with the following code.
// current version 1.0.0
int sum (int x, int y){
    return x;    // note, buggy code
}

// I did a bugfix in backward compatible manner
// Clients Do *not* need to change in thier code to access same API
// version => 1.0.1
int sum (int x, int y){
    return x + y;
}

// I did add a logging feature in a backward compatible manner
// Clients Do *not* need to change in thier code to access same API
// version => 1.1.1
int sum (int x, int y){
    logger.info("client requests addition of " + x " and " + y);
    return x + y;
}

// I did an incompatible API change
// Clients Do needs to change in thier code to access same API
// version 2.0.0
int sum (int x, int y, Caller caller){
    logger.info("caller" + caller + " requests addition of " + x " and " + y);
    return x + y;
}

02 October 2013

Orders Aggregator - a funny program

Today, I was responsible about aggregating the food orders from my colleges, and since I wanted it to be accurate I decided to write my first ruby script (Thanks to Google)

Here it is:
# Orders Aggregator

class BreadType
  attr_accessor :type
  def initialize(type)
    @type = type
  end
  
  def eql?(other)
    @type = other.type
  end
  
  def hash
    @type.hash
  end
  
  def to_s
    @type
  end
end

class Sandwich
  attr_accessor :name, :type

  def initialize (name, type)
    @name = name
    @type = type
  end
  
  def eql?(other)
    @name = other.name #&& @type = other.type # buggy and I cannot resolve, so I decided to comment
  end
  
  def hash
    @name.hash ^ @type.hash
  end
  
  def to_s
    @name.to_s << " : " << @type.to_s
  end
end

balady = BreadType.new "Balady"
shamy = BreadType.new "Shamy"

# Talaat
talaat = []
talaat << Sandwich.new(:Ta3mya, balady) << Sandwich.new(:Batates_omlete, balady)
# Hewedy
hewedy = []
2.times {
  hewedy << Sandwich.new(:Ta3mya, balady)
}
# Ahmad
ahmad = []
ahmad << Sandwich.new(:Swabe3_Salada, balady) << Sandwich.new(:Fol_Eskandrany, balady)
# Khalid
khalid = []
khalid << Sandwich.new(:Ta3mya_Eskandrany, balady)
# Alaa
alaa = []
alaa << Sandwich.new(:Ta3mya_Eskandrany, balady)
# Hatem
hatem = []
3.times {
  hatem << Sandwich.new(:Ta3mya, shamy)
}

total = talaat + hewedy + ahmad + khalid + alaa + hatem

counts = Hash.new(0)
total.each { |name| counts[name] += 1 }

puts "Aggregation: "
counts.each { |k, v|
  puts k.to_s << " ::" << v.to_s
}

Output:
Aggregation: 
Batates_omlete : Balady ::1
Ta3mya : Shamy ::3
Swabe3_Salada : Balady ::1
Ta3mya : Balady ::3
Ta3mya_Eskandrany : Balady ::2
Fol_Eskandrany : Balady ::1

IPLookup now validates IP before processing on it.

IPAddress, which is an Intelligent and extensible IP => Country converter is now validates the IPs before send to the lookup services.

The Intelligence in that, it downgrade the service if it doesn't return data.
The Extensible in that, you can extend it and add your own service implementations.

You can check it at: https://github.com/MuhammadHewedy/IpLookup