Thursday, September 26, 2013

new instructions for installing Java JDK 8 on Ubuntu


http://www.java.com/en/download/faq/java_win64bit.xml


Which Java download should I choose for my 64-bit  operating system?


Verify that you are using a 64-bit OS

In Firefox type

about:support


Oracle Java download site


From Oracle Java installation instructions:


# Download from this page
# http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
# Linux x64 180.95 MB jdk-8u151-linux-x64.tar.gz

sudo mkdir -p /usr/local/java
cd /usr/local/java
sudo cp ~/Downloads/jjdk-8u151-linux-x64.tar.gz .
sudo tar xvf jdk-8u151-linux-x64.tar.gz
ls -a
sudo emacs /etc/profile

# Scroll down to the end of the file using your arrow keys and add the following lines below to the end of your /etc/profile file:
# Type/Copy/Paste:
#
export JAVA_VERSION=jdk1.8.0_151
export JAVA_HOME=/usr/local/java/$JAVA_VERSION

export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

# In the shell

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/$JAVA_VERSION/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/$JAVA_VERSION/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/$JAVA_VERSION/bin/javaws" 1

sudo update-alternatives --set java /usr/local/java/$JAVA_VERSION/bin/java

sudo update-alternatives --set javac /usr/local/java/$JAVA_VERSION/bin/javac

sudo update-alternatives --set javaws /usr/local/java/$JAVA_VERSION/bin/javaws

. /etc/profile

cd /opt/google/chrome/plugins
sudo rm -f libnpjp2.so
sudo ln -s /usr/local/java/$JAVA_VERSION/jre/lib/amd64/libnpjp2.so .

sudo mkdir -p /usr/lib/mozilla/plugins
cd /usr/lib/mozilla/plugins
sudo rm -f libnpjp2.so
sudo ln -s /usr/local/java/$JAVA_VERSION/jre/lib/amd64/libnpjp2.so

Tuesday, September 17, 2013

Python pages

Short cuts to useful Python tutorials from other web pages.
Snippets of code from the other pages is included in this blog.
Attribution is given int he form of a link to the original reference.

Lamda and multiple args

Python lists explained
The list type is a container that holds a number of other objects, in a given order. The list type implements the sequence protocol, and also allows you to add and remove objects from the sequence.

Python List len() Method

list1, list2 = [123, 'xyz', 'zara'], [456, 'abc']
print "First list length : ", len(list1);
print "Second list length : ", len(list2);


The Python yield keyword explained
3,400+ votes on Stack Overflow

calling the function str.lower and assigning the return value which is definitely not iterable
Change the line
content = inputFile.read().lower
to
content = inputFile.read().lower()
Your original line assigns the built-in function lower to your variable content instead of calling the function str.lower and assigning the return value which is definitely not iterable.

Python sets
> > > y = [1, 1, 6, 6, 6, 6, 6, 8, 8]
> > >; sorted(set(y))
[1, 6, 8]

> > > s = set([1,6,8])
> > > print(s)
{8, 1, 6}
> > > s.update(range(10,100000))
> > > for v in range(10, 100000):
    s.remove(v> > >> > > print(s){1, 6, 8}

Python regexs
Python regexs 2

NameError: name 're' is not defined
-import the re module

Python - Using regex to find multiple matches and print them out

line = 'bla bla bla
Form 1
some text...
Form 2
more text?'
matches = re.findall('
(.*?)
'
, line, re.S) print matches


Python Dictionary (hashes)

Python : List of dict, if exists increment a dict value, if not append a new dict

urls = {'http://www.google.fr/' : 1 }
for url in list_of_urls:
    if not url in urls:
        urls[url] = 1
    else:
        urls[url] += 1
http://stackoverflow.com/questions/13757835/make-python-list-unique-in-functional-way-map-reduce-filter?rq=1

Is there a way in Python of making a List unique through functional paradigm ?
Input : [1,2,2,3,3,3,4]
Output: [1,2,3,4] (In order preserving manner)




In [29]: a = [1,2,2,3,3,3,4]
In [30]: reduce(lambda ac, v: ac + [v] if v not in ac else ac, a, [])
Out[30]: [1, 2, 3, 4]


Pretty printing a dictionary
Use the module name to reference the pprint function
import pprint
pprint.pprint(...)

Python sets

Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
Curly braces or the set() function can be used to create sets. Note: to create an empty set you have to use set(), not {}; the latter creates an empty dictionary, a data structure that we discuss in the next section.
Here is a brief demonstration:
>>>
>>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
>>> fruit = set(basket)               # create a set without duplicates
>>> fruit
set(['orange', 'pear', 'apple', 'banana'])
>>> 'orange' in fruit                 # fast membership testing
True
>>> 'crabgrass' in fruit
False

>>> # Demonstrate set operations on unique letters from two words
...
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a                                  # unique letters in a
set(['a', 'r', 'b', 'c', 'd'])
>>> a - b                              # letters in a but not in b
set(['r', 'd', 'b'])
>>> a | b                              # letters in either a or b
set(['a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'])
>>> a & b                              # letters in both a and b
set(['a', 'c'])
>>> a ^ b                              # letters in a or b but not both
set(['r', 'd', 'b', 'm', 'z', 'l'])
Similarly to list comprehensions, set comprehensions are also supported:
>>>
>>> a = {x for x in 'abracadabra' if x not in 'abc'}
>>> a
set(['r', 'd'])

 python remove whitespaces in string

Looping through python regex matches

import re

s = "ABC12DEF3G56HIJ7"
pattern = re.compile(r'([A-Z]+)([0-9]+)')

for (letters, numbers) in re.findall(pattern, s):
    print numbers, '*', letters

Why does comparing strings in Python using either '==' or 'is' sometimes produce a different result?

is is identity testing, == is equality testing. what happens in your code would be emulated in the interpreter like this:

>>> a = 'pub'
>>> b = ''.join(['p', 'u', 'b'])
>>> a == b
True
>>> a is b
False

How to test if a dictionary contains a specific key? [duplicate]

x = {'a' : 1, 'b' : 2}
if (x.contains_key('a')):
    ....
How to check a string for specific characters?

 How to return more than one value from a function in Python? [duplicate]

Sunday, July 14, 2013

Coding conventions

People spend time in corporations writing coding convention documents. Often they think in terms of an ideal world. Enforcing coding conventions creates friction on teams. Coding conventions should be light weight. Coding conventions should make the code easier to read, understand, maintain, and debug. Coding conventions should not add unnecessary overhead to the project.

Sun Microsystems published the above Java coding convention in 1999. Most of the convention is irrelevant since formatting is handled by Eclipse.

I don't completely agree with their code structuring conventions. The first thing that their coding convention assumes is that programmers adequately comment their code. Since we know that this is not the case you should at least write code which is SELF DOCUMENTING. See below.

1. Embedding function calls inside of function calls may be faster to code but makes the code more difficult to debug, read, and understand. The code is also self documenting if the var names are descriptive. Since people put limited comments in their code using descriptive var names is the minimum requirement.

var = someMethod1(longExpression1,
                someMethod2(longExpression2,
                        longExpression3));

Should be

descriptive_var = someMethod2(longExpression2, longExpression3);

var = someMethod1(longExpression1, descriptive_var );

Now when you step through the debugger you can see the return value for the first method.
Others who read the code can see what the descriptive_var represents.
  
2. Complex boolean equations should be broken down into individual booelnas. The code is easier to debug, read, and understand. The code is also self documenting if the boolean names are descriptive. Since people put limited comments in their code using descriptive boolean names is the minimum requirement.

//DON'T USE THIS INDENTATION
if ((condition1 && condition2)
    || (condition3 && condition4)
    ||!(condition5 && condition6)) { //BAD WRAPS
    doSomethingAboutIt();            //MAKE THIS LINE EASY TO MISS
}

Should be

// each var is descriptive and describes the condition
// each var is in effect a COMMENT
// the debugger shows the value of each boolean in the complex conditional expression

dv1 = condition1 && condition;
dv2 = condition3 && condition4;
dv3 = !(condition5 && condition;
dv4 = dv1 || dv2 || dv3;

if (dv4) {
    doSomethingAboutIt();     
}

3.This is nonsense. The best programmers I know declare vars when they are first used in blocks not at the beginning of blocks. It makes the program easier to follow. You don't have to jump around to see the type of the var. The program looks like a dataflow/pipeline (data announces its arrival) and is easier to DEBUG.


6.3 Placement
Put declarations only at the beginning of blocks. (A block is any code surrounded by curly braces "{" and "}".) Don't wait to declare variables until their first use; it can confuse the unwary programmer and hamper code portability within the scope.

void myMethod() {
    int int1 = 0;         // beginning of method block

    if (condition) {
        int int2 = 0;     // beginning of "if" block
        ...
    }
}

4. Put vars in returns. Make the code self documenting and readable.

return (size ? size : defaultSize);

Should be

int realSizeOfSomeObject = (size ? size : defaultSize);
return realSizeOfSomeObject; 

5. There are some guys from MIT who completely disagree with putting the else on the same line as the left curly }. They think the else goes on the line below the curly. I agree with the MIT guys.

7.4 if, if-else, if else-if else Statements
The if-else class of statements should have the following form:
if (condition) {
    statements;
}

if (condition) {
    statements;
} else {
    statements;
}

if (condition) {
    statements;
} else if (condition) {
    statements;
} else {
    statements;
}

6. No assignments in condition checks...
Do not use the assignment operator in a place where it can be easily confused with the equality operator. Example:

if (c++ = d++) {        // AVOID! (Java disallows)
    ...
}
should be written as
if ((c++ = d++) != 0) {
    ...

}

Thursday, April 11, 2013

Gearman

Gearman is a great tool for transparent distribution of jobs to a pool of worker machines.

http://gearman.org/

Friday, February 8, 2013

How to improve server hardware

  •  
  • Derek Pappas
    DeleteDerek Pappas Maybe they will figure out that they need to take the servers apart, put the components in separate packages that have different cooling requirements, run the liquid cooling out of the building instead of using air, put the power supplies at the rack level instead of in the servers which they just heat up, and figure out to make the whole system like Lego so you can add as much capacity to each system as the CPU supports with respect to DRAM and HDD's.less

Thursday, February 7, 2013

Have integration meetings.-skip all the others.

In response to PG's YC article on meetings I have this to say.

Hiding in your office or cubicle staring at the monitor for 12 hours a day does not get projects finished. There are integration issues that have to be ironed out between developers. Successfully pushing data down entire software or hardware pipelines usually requires coordination and face to face interaction. Meetings have their place in the project development cycle. Integration of discrete software modules rarely happens without meetings. Particularly if the project is large and building something complex such as a graphics chip pipeline (yes that is software - RTL) or a data processing pipeline spread across two computer centers running down loaders, map reduce data processing jobs, and indexers.Good luck trying to get the engineers to talk to each other about integration without a regular meeting more than once a week (this is based on my experience at Intel and Sun). Of course there are other companies in the Valley that are less organized, where the people work harder and get less done under more pressure because they do not talk to each other (that would be a waste of time in the eyes of management). They tend not to have coordination meetings. And when they do have meetings the managers mostly do the talking. And good luck to the manager who thinks he can build a team with a common set of values without have meetings that go over the mission that the team is on. Meetings that review PERT charts on a weekly basis for the duration of the project are a waste of time. Meetings to review status are a waste of time. Meetings to discover issues are a waste of time. Engineers will tell you in private what the issues are. Intel used to have open communication when Grove was running the show. But that company and time was an exception. There is something to be said for aligning everyone behind one single short term milestone, meeting daily to ensure that the milestone is being met, meeting the milestone, and then letting the team take over the project management for the rest of the project.