Search This Blog
Popular Posts
-
Let say we have a String something like below. String sample="abc*123"; We want to split this String by '*'. We can...
-
sound -Convert matrix of signal data to sound Syntax sound(y,Fs) sound(y,Fs,bits) Description sound(y,Fs) sends audio signal y to the speak...
-
There are new phones will remove within next few weeks from sony. Sony xperia tipo, sony xperia tipo dual Sony xperia dual has dual sim...
-
When i try to configure mysql with CAS There were lots of problem occurred and i cannot find a good tutorials about this.I followed some tut...
-
PROBLEM 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st pr...
-
This delete the file f1 File f1 = new File(file); boolean success = f1.delete(); if (!success){ System.out.println("Deleti...
-
PROBLEM The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. ANSWER 142913828...
-
In this post i will show you how to configure tomcat 7.x for SSL protocol in windows First we want to generate certificate file using jav...
-
samsung smart app challenge 2012 This contest offers $4.08 million in cash prizes and mega marketing support for app promotion to the to...
-
If you did not format your flash drive, then check whether the files are in hidden mode. Then follow these steps: Click on the link below ...
Followers
Thursday, June 20, 2013
Thursday, April 4, 2013
Apache ant Build files
Apache ant Build
files
Introduction
Apache
Ant is a Java library and command-line tool whose mission is to drive processes
described in build files as targets and extension points dependent upon each
other. The main known usage of Ant is the build of Java applications. Ant
supplies a number of built-in tasks allowing to compile, assemble, test and run
Java applications. Ant can also be used effectively to build non Java
applications, for instance C or C++ applications. More generally, Ant can be
used to pilot any type of process which can be described in terms of targets
and tasks.
How install Apache Ant (on windows)
The
Apache Ant distribution package can be downloading as a zip file from the
Apache site and extract it to the location that Ant should install. Then, add
the environment variables to the system as follow.
ANT_HOME=path to ant
extracted folder
PATH=path to ant
folder/bin
Open
command prompt and type “ant” will give the result shown below. If this result
will receive, then the installation is success.
Buildfile: build.xml
does not exist!
Build failed
How work with Ant
In
order to execute a build process with Ant, need a build script called
“build.xml”. The build script is used to define where the library files are
located, where the source code are located, how to compile, make directory ,
delete directory, make jar file, run jar files, run batch files and many more.
In order to do this, it is required to know the basic commands in the Apache
Ant. Following example shows the sample build script that compile a simple
HelloWorld.java file and run it.
<?xml version="1.0"?>
<project name="HelloWorld"
default="run" basedir=".">
<property
name="src" location="src" />
<property
name="bin" location="bin" />
<property
name="build" location="build" />
<target
name="clean">
<delete
dir="${bin}" />
<delete
dir="${build}"/>
</target>
<target
name="compile" depends="clean" >
<mkdir
dir="${bin}" />
<javac
destdir="${bin}" srcdir="${src}"
debug="true"></javac>
</target>
<target
name="jar" depends="compile">
<mkdir
dir="${build}"/>
<mkdir
dir="${build}/jar"/>
<jar
destfile="${build}/jar/HelloWorld.jar" basedir="${bin}">
<manifest>
<attribute
name="Main-Class" value="HelloWorld"/>
</manifest>
</jar>
</target>
<target
name="run">
<java
jar="${build}/jar/HelloWorld.jar" fork="true"/>
</target>
</project>
The
steps of the build process (methods) can be defined inside the tag “target”. It
is possible to give a name for each target and dependency. The dependency means,
before run that target the dependent target will be run by the Ant. For an
example, if execute compile target, since it depends on the clean target, the
clean target will run first. Inside the “property” tag, the source directory,
bin directory and other required paths with a logical name can be defined. The
name of the project can be defined inside the “project” tag and also the
default method that run, if required method does not specify when run the build
script. The basedir is defined, from where the relative path should consider.
For an example, the folder structure of the “HelloWorld” is as below.
Folder structure
of the “HelloWorld” project
String Templates
StringTemplate is a template engine library used for generating text from data structures. StringTemplate's distinguishing characteristic is that it strictly enforces model-view separation unlike other comparable template engines. It is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization. It is also developed for multiple languages, such as Java, C#, Python. Following code show the steps of a simple “Hello World” printing using StringTemplates.
import org.antlr.stringtemplate.*;
StringTemplate hello = new StringTemplate("Hello, $name$");
hello.setAttribute("name", "World");
System.out.println(hello.toString());
Friday, March 29, 2013
disable cache on html5 application
I have developed an android application which continuously get update from a server through AJAX call and there is a PHP file on the server which respond to the AJAX request. My application working properly in localhost. But after i install the application on my android phone, First two or three updates are successfully happens and then after it gives me the historical value( not update).
The problem is the cache. Application hold values on cache and give the cache data when request through AJAX.
I fixed this problem by simply added few codes on the top of my server side PHP file fro disabling the cache. Below is the code.
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
The problem is the cache. Application hold values on cache and give the cache data when request through AJAX.
I fixed this problem by simply added few codes on the top of my server side PHP file fro disabling the cache. Below is the code.
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
Wednesday, March 27, 2013
XmlHTTPRequest: “XML Parsing Error: no element found”
I have an html5 application which get details from database through javascript. It is working properly on localhost. But after i move the database to hosting place i get the error XmlHTTPRequest: “XML Parsing Error: no element found”.
This error come because of same origin policy. That mean in my case, database in one host and my application in an another host.
I fix this issue by following steps.(i call database hosting is hostA and my application hosting hostB)
* I have php file on hostA. I add below code to the top of the file.
header('Access-Control-Allow-Origin: *');
This error come because of same origin policy. That mean in my case, database in one host and my application in an another host.
I fix this issue by following steps.(i call database hosting is hostA and my application hosting hostB)
* I have php file on hostA. I add below code to the top of the file.
header('Access-Control-Allow-Origin: *');
Wednesday, February 13, 2013
Reorder/Reset auto increment primary key?
Following query can be used for reorder auto increment of a table.In this example reorder the id column of users table. If there are foreign key, make sure the action is cascade.
SET @count = 0;
UPDATE `users` SET `users`.`id` = @count:= @count + 1;
Tuesday, February 12, 2013
locks in python thread
When doing multi threading program in any language, it is a big problem when having shared variables or some shared objects. In this kind of situation, it is required to lock some variables until finish the some process of one thread. In order to do this we can use locks. In python there is a library for import in order to do this.
ex:
from threading import Lock
......
....
#initialize lock
lock=Lock()
.....
#when needed to add lock
lock.acquire()
#do the stuff
#remove lock
lock.release()
ex:
from threading import Lock
......
....
#initialize lock
lock=Lock()
.....
#when needed to add lock
lock.acquire()
#do the stuff
#remove lock
lock.release()
copy object to another object using python
it is really easy to copy object with all attributes to another object in python. All you need to import copy library.
ex:
import copy
class Test:
def __init__(self,name):
self.name=name
def main():
a=Test('madura')
b=copy.deepcopy(a)
This will copy Test class object a, to Test class object b with the attribute values
ex:
import copy
class Test:
def __init__(self,name):
self.name=name
def main():
a=Test('madura')
b=copy.deepcopy(a)
This will copy Test class object a, to Test class object b with the attribute values
Monday, February 11, 2013
Thursday, January 17, 2013
generate number of random numbers that have not repeat in a given range in python
random.sample(range(1, 16), 3)
[11, 10, 2]
get element, sublist and length of a list using python
d = range(10)
>>> d
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> d[9]
9
>>> d[-1]
9
>>> d[0:9]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
>>> d[0:-1]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
>>> len(d)
10
Matrix in python
There are no inbuilt function for define matrix. You can define the matrix as a list of list as follow
table= [ [ 0 for i in range(6) ] for j in range(6) ]
print table
result
[[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
make a list of class objects
class Person(object):
"""__init__() functions as the class constructor"""
def __init__(self, name=None, job=None, quote=None):
self.name = name
self.job = job
self.quote = quote
# make a list of class Person(s)
personList = []
personList.append(Person("Payne N. Diaz", "coach", "Without exception, there is no rule!"))
personList.append(Person("Mia Serts", "bicyclist", "If the world didn't suck, we'd all fall off!"))
personList.append(Person("Don B. Sanosi", "teacher", "Work real hard while you wait and good things will come to you!"))
personList.append(Person("Hugh Jorgan", "organist", "Age is a very high price to pay for maturity."))
personList.append(Person("Herasmus B. Dragon", "dentist", "Enough people can't find work in America!"))
personList.append(Person("Adolph Koors", "master-brewer", "Wish you were beer!"))
personList.append(Person("Zucker Zahn", "dentist", "If you drink from the fountain of knowledge, quench your thirst slowly."))
print "Show one particular item:"
print personList[0].name
print "Sort the personList in place by job ..."
import operator
personList.sort(key=operator.attrgetter('job'))
print "... then show all quotes and who said so:"
for person in personList:
print "\"%s\" %s (%s)" % (person.quote, person.name, person.job)
print "Show the quote(s) from any dentist:"
look = 'dentist'
for person in personList:
if look in person.job:
# title() capitalizes the job's first letter
print "%s %s: \"%s\"" % (person.job.title(), person.name, person.quote)
print "What the heck did the person named Sanosi say?"
look = "Sanosi"
for person in personList:
if look in person.name:
print "%s: \"%s\"" % (person.name, person.quote)
for loops in python
for num in range(10,20): #to iterate between 10 to 20
for i in range(2,num): #to iterate on the factors of the number
if num%i == 0: #to determine the first factor
j=num/i #to calculate the second factor
print '%d equals %d * %d' % (num,i,j)
break #to move to the next number, the #first FOR
else: # else part of the loop
print num, 'is a prime number'
Subscribe to:
Comments (Atom)