Tuesday, June 18, 2013

They know what we did last summer !


The United States National Security Agency (NSA) is watching your emails, chat conversations, voice calls, documents and more since 2007.

The PRISM program of NSA that was leaked by NSA contractor Edward Snowden and published by The Guardian and The Washington Post on June 6, 2013, claims direct access to servers of firms including Google, Apple, Facebook, Microsoft, yahoo and skype.

PRISM is a clandestine national security electronic surveillance program operated by the United States NSA since 2007.
more info at wikipedia

at first, Silicon Valley executives insist they did not know of secret PRISM program that grants access to servers.
here

then, In recent days, their strategy has shifted to admitting the NSA requests, espousing transparency by publishing their US request figures, while seeking to stress that they push back against requests they see as inappropriate.
here

firm like Yahoo has claimed receiving between 12,000 and 13,000 requests, Apple receiving between 4,000 and 5,000 requests, Facebook said it received between 9,000 and 10,000 requests in that six-month period, while Microsoft said it received between 6,000 and 7,000.

here to follow The latest news and comment on PRISM

Thursday, May 2, 2013

Top web Sites implementations


Here are the web technologies used to build the most famous and largest web sites in the world, you can click on the links if you want to see references or more details.


Facbook.com
written in PHP, C++ and Java

data is output in PHP format (compiled with HipHop for PHP). The backend is written in Java and Thrift is used as the messaging format so PHP programs can query Java services.here

HipHop converts PHP into heavily optimized C++ code, which can then be compiled into an efficient native binary. the company's engineers reported that it reduced average CPU consumption on Facebook by roughly 50 percent. here

eBay.com
from Perl .. to .. XSL(front end) & C++ (back end) .. to .. XSL (front end) & Java (back end)

Youtube.com
written in Python

Twitter.com
from Ruby on Rails .. to .. Scala .. to .. Java

James Gosling explaining why twitter moved from ruby to java


Amazon.com
written in C++ and Java with Oracle database engines on Linux-based Hewlett Packard servers

LinkedIn.com
written in Java

PayPal.com
written in C++

Tuesday, March 26, 2013

Not able to start local socket server

Problem:
if you try to start local socket server on unix using QLocalServer for IPC and the server crashed without closing , then when you try to start it again, listen will fail unless you change the serverName you are listening on...

here is a sample code:

m_server = new QLocalServer(this);
if (!m_server->listen("serverUniqueName")) {
    qDebug() << "Not able to start the Server";
    return;
}

proposed solution:

when the local socket server starts, it creates a file in /tmp with the name of the server, so next attempt to listen will find this address in use, you should remove the file /tmp/serverName to be able to start again.

sample code:
 
m_server = new QLocalServer(this);
    if (!m_server->listen("serverUniqueName")) {
        if(!QFile::remove("/tmp/serverUniqueName") ||
                !m_server->listen("serverUniqueName")){
            qDebug() << "Not able to start the Server";
            return;
        }
    }
 

Monday, July 16, 2012

how to implement double click listener for Google maps in Android

here is the code for implementing onDoubleTap listener in your MapActivity.

note mapview.setOnTouchListener() method and return true in onDown method.

the code:
 
public class MYMapActivity extends MapActivity implements  
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener{
GestureDetector gestureDetector;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mymapview);
        //get the MapView
        MapView mapView = (MapView) findViewById(R.id.mapview);
        // enable zoom controls in the map view 
        mapView.setBuiltInZoomControls(true);

        gestureDetector = new GestureDetector(this, this);
        //register the double tap listener to this object
        gestureDetector.setOnDoubleTapListener(this);
        mapView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });

    }
@Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    @Override
    public boolean onDoubleTap(MotionEvent mev) {
        System.out.println("******onDoubleTap*******");
        //do what ever you want here
        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        System.out.println("******onDown*******"); 
        //must return true so that onDoubleTap method fires
        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, 
           float velocityX, float velocityY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, 
           float distanceX, float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }
}

Sunday, October 30, 2011

Wednesday, October 5, 2011

If a programming language was a boat

I saw this article in a programming forum and I found it nice and accurate in describing programming languages and shows us the difference between them in a simple way, so I copied it here for you.

Java
Java is a cargo ship. It’s very bulky. It’s very enterprisey. Though it can also carry a lot of weight. Will carry a project, but not very fun to drive.



Perl
Perl is a tugboat. Powerful enough to tug Java around, in 80 characters or less.



Ruby
Ruby is difficult to describe. It’s sleek, sexy, and very fun to drive. Here’s a picture. Very trendy.



PHP
PHP is a bamboo raft. A series of hacks held together by string. Still keeps afloat though.



C
C is a nuclear submarine. The instructions are probably in a foreign language, but all of the hardware itself is optimized for performance.



C-sharp
Like a luxury cruiser. Sleek, good looking and quite comfy. However, not very fast , expensive and somewhat limiting.



Visual Basic

As time went on you realized it was completely bloody useless.



HTML

HTML isn’t really a programming language boat.



Python
Undeniably beautiful and elegant in the water, tends to be solid and reliable. Will work with little intervention, but also provides sails to help you go that little bit faster.



Javascript

Like James Bond Q Boat. It’s small but powerful and it’s really easy to get yourself killed trying to use it.



FORTRAN77

A concrete boat that still lurkes under the surface. You wouldn’t want to set sail with it though. Try navigating around it.



Monday, September 19, 2011

htkdict load error in Julius

some people met this error while trying to operate julius 4.1.x

Error: voca_load_htkdict: the line content was: DECORATE [DECORATE] d eh k er ey t sp
Error: voca_load_htkdict: line 3118: triphone "ax-d+sp" not found
Error: voca_load_htkdict: line 3118: triphone "d-sp+*" or biphone "d-sp" not found
Error: voca_load_htkdict: the line content was: DECORATED [DECORATED] d eh k er ey dx ax d sp
Error: voca_load_htkdict: line 3119: triphone "iy-s+sp" not found
Error: voca_load_htkdict: line 3119: triphone "s-sp+*" or biphone "s-sp" not found
Error: voca_load_htkdict: the line content was: DECREASE [DECREASE] d ix k r iy s sp
Error: voca_load_htkdict: line 3120: triphone "ax-z+sp" not found
Error: voca_load_htkdict: line 3120: triphone "z-sp+*" or biphone "z-sp" not found
Error: voca_load_htkdict: the line content was: DECREASES [DECREASES] d ix k r iy s ax z sp
Error: voca_load_htkdict: line 3121: triphone "ix-ng+sp" not found
Error: voca_load_htkdict: line 3121: triphone "ng-sp+*" or biphone "ng-sp" not found
Error: voca_load_htkdict: the line content was: DECREASING [DECREASING] d ix k r iy s ix ng sp
Error: voca_load_htkdict: line 3122: triphone "r-iy+sp" not found
Error: voca_load_htkdict: line 3122: triphone "iy-sp+*" or biphone "iy-sp" not found

and so on ( the error is sill long)
************************************

Error reason:
julius optput these messages when your word dictionary contains words that are not trained in the Acoustic Model because the "voca_load_htkdict.c" tries to match the triphones in dict file with the triphone list in Acoustic Model, so when it does not find it, it shows this error and stops the program.

Possible error solutions:
1. enable -forcedict option or uncomment it jconf file to Skip error words in dictionary and force running.
or..
2. map the "not found triphone" to the most close physical triphone in hmmlist file "tiedlist".
for example:
b-ey+t v-eh+t
The first column is the name of triphone (generated from your dictionary), and the second column is the name of the HMM actually defined in your AM.

but this solution can be done if the "not found triphones" are little not too many.

3. the best solution is to not to include words in your dict file that are not in the A.M
note that the first two solutions are for testing julius only because for production or comercial projects you must train the acoustic model and language model with the same corpus.

How software is produced

this is how software is produced from what the user wanted and what is really done, I found it while crawling in the net.
and believe me, as a developer .. I can say that this is really true :D


Monday, June 27, 2011

Function calls in Julius ASR

That's what I was feeling when I began to develop and modify in Julius code (an open source ASR system implemented by C language by a brilliant Japanese person).


When to use static nested classes?

It may be confusing at first that, which one to use when using nested classes? static nested classes or inner classes? and in this article I will answer this question for you.

first:
the use of terms:
A nested class is a class which is contained in another class at the source code level.
If you declare it with the static modifier, then its name is static nested class.
A non-static nested class is called inner class.

second:
the key differences between static nested classes and inner classes
static nested classes:
1. They do not have access to the fields and methods of the enclosing class.
2. they can be instantiated without a corresponding instance of the outer class.
inner classes:
1. inner class has an implicit reference to the enclosing class, so they have access to the fields and methods of the enclosing class even if they are declared private.
2. they cannot be instantiated without a corresponding instance of the outer class.

third:
when to use nested classes in general?
if you just want to keep your classes together if they belong typically together or if you need a class that do some functionality that is exclusively related to the outer class, The nesting creates a type of namespace. To denote a nested class from outside its enclosing class, the nested class is prefixed with the name of the enclosing class.

when to use static vs non static?
from an OO design point of view you decide which one to use depending on whether you want your nested class to have access to enclosing class members or no, so ask yourself, does your nested class need that access?
it is a better idea if you are using a nested class is to start off with it being static, and then decide if it really needs to be non-static based on your usage.

to fully understand the decision rule we can see a practical and real example that is in LinkedList class
note my comments beside the code.


public class LinkedList
{
transient int size = 0;

transient Node first; /*LinkedList consists of Nodes so we made it as nested class*/
transient Node last;
...

private class ListItr implements ListIterator { /* ListItr needs access to outer class members to iterate through them, it needs access to size, first and last members, so we made it inner class*/
private Node lastReturned = null;
private Node next;
private int nextIndex;
private int expectedModCount = modCount;
...
}

private static class Node { /*Node do not need access to the outer class members so it is declared as static, Node is the basic unit that consist the LinkedList*/
E item;
Node next;
Node prev;
...
}

} //outer class end

references:
Sybex SCJP for Java platform SE6, Richard F. Raposa
http://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class
http://stackoverflow.com/questions/253492/static-nested-class-in-java-why
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html