Wednesday, May 2, 2012

How to get all sub-elements of an element tree with Python ElementTree?

I want to find a way to get all the sub-elements of an element tree like the way ElementTree.getchildren() does, since getchildren() is deprecated since Python version 2.7, I don't want to use it anymore, though I can still use it currently.



Thanks.





How do i make a history calculator in android?

I am making a calculator same as windows calculator. I am stuck at the history feature. How do I code for history feauture of the calculator. What should I use in android for that? Thanks in advance.





Why the <DIV> CSS applied for Repeater Control get Distorted when placed in UpdatePanel?

i am new to AJAX i am trying to update a Repeater Control When user Click on Search Button which is out side the updatePanel using Trigger event of UpdatePanel the CSS get Distorted when Repeater Control is Placed inside UpdatePanel Whhen the Update Panel is Removed Then the CSS is applied perfectly why does it happen?



Code:





 <div class="jqueryresultsBackground">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="ResultsRepeater" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
&nbsp;
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table align="center" width="100%">
<tr>
<td align="left" class="searchResFieldName" width="40%">
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/deleted.png"
Style="z-index: 1; position: absolute; margin-left: -5px;"
Visible='<%# DeletedImageVisibility(Eval("IsActive"))%>' />
<br />
<%# Eval("UnicodeFullName")%>
</td>
<td width="10%">
Col1
</td>
</tr>
</table>
</td>
<td width="10%">
Col2
</td>
<td width="10%">
Col3
</td>
<td width="8%">
Col4
</td>
<td width="5%">
Col5
</td>
<td width="10%">
Col6
</td>
</tr>
<tr>
<td align="left" class="searchResFieldName" width="35%">
<%# Eval("EnglishFullName")%>
</td>
<tr>
<td align="left">
<%# Eval("HouseNumber")%>
<br />
<%# Eval("UnicodeAddress")%>
</td>
<td>
<b><%# Eval("ConstituencyNumber")%></b>
</td>
<td>
<b><%# Eval("PartNumber")%></b>
</td>
<td>
<b><%# Eval("SerialInPart")%></b>
</td>
<td>
<b><%# Eval("Age")%></b>
</td>
<td>
<b><%# Eval("Sex")%></b>
</td>
<td>
<b><%# Eval("CardNo")%></b>
</td>
</tr>
<tr>
<td>
<%# Eval("Address")%>
</td>
<tr>
<td>
</td>
<td align="left" class="searchResPrabhag" colspan="7">
&nbsp;
</td>
</tr>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
</ItemTemplate>


<FooterTemplate>
<tr>
<td>
&nbsp;
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>

<Triggers>
<asp:AsyncPostBackTrigger ControlID="SearchButton" EventName="Click" />
</Triggers>

</asp:UpdatePanel>
<asp:HiddenField ID="CurrentPageHiddenField" runat="server" />
</div>




Prolog - writing a combination of k numbers in the given list

I am trying to define a function in prolog that takes arguments of the form combination(3,[a,b,c,d],L) , the result returns



L=a,b,c
L=a,b,d
L=a,c,d
L=b,c,d


My implementation is as follows:



combination(K,argList,L):-
unknown(X,argList,Y),
Z is select(X,argList),
length(Z,K),
L is Z,
combination(K,Z,L).

unknown(X,[X|L],L).
unknown(X,[_|L],R) :- unknown(X,L,R).


The unknown predicate behaves as follows:
![enter image description here][1]



Please help.





How would I go about building an API converter?

I have multiple different APIs with different schemas serialised in XML or JSON which I need to output as a standardised schema.



Main features needed:




  • Serialisation to XML and JSON

  • Authentication

    • I.e.: can't get/set data unless you have the correct user+pass


  • Role/Scope limitation

    • I.e.: you can't access everything in our database, only what your role allows for


  • Get/set (conversion) between different schemas

    • I.e.: No matter the input API, you can get it formatted in whichever output API you request




Is this the sort of problem Slumber with TastyPie would be best for?



Or are there a different libraries you'd recommend? - [happy to use C#, C++ or Ruby instead if they have libraries better suited to this problem]





Test app on iPad without paying Apple

I want to test my iPad app on my device without paying for an Apple developer account. Is there any method to do that? How can I install my iPad app on my device for testing?





NFC Android: Decode an Mifare tag written with NXP NFC Writer

i`m messing around with some nfc tags, I have written plain text to them with the application 'TagWriter' made by the company nxp. Is it possible to make an application that can read this plain text? or is this impossible due certain authorizations keys of the nxp app? or has someone done this before?



any suggestion is appreciated





Replacing specific characters in first column of text

I have a text file and I'm trying to replace a specific character (.) in the first column to another character (-). Every field is delimited by comma. Some of the lines have the last 3 columns empty, so they have 3 commas at the end.



Example of text file:



abc.def.ghi,123.4561.789,ABC,DEF,GHI
abc.def.ghq,124.4562.789,ABC,DEF,GHI
abc.def.ghw,125.4563.789,ABC,DEF,GHI
abc.def.ghe,126.4564.789,,,
abc.def.ghr,127.4565.789,,,


What I tried was using awk to replace '.' in the first column with '-', then print out the contents.



ETA: Tried out sarnold's suggestion and got the output I want.



ETA2: I could have a longer first column. Is there a way to change ONLY the first 3 '.' in the first column to '-', so I get the output



abc-def-ghi-qqq.www,123.4561.789,ABC,DEF,GHI
abc-def-ghq-qqq.www,124.4562.789,ABC,DEF,GHI
abc-def-ghw-qqq.www,125.4563.789,ABC,DEF,GHI
abc-def-ghe-qqq.www,126.4564.789,,,
abc-def-ghr-qqq.www,127.4565.789,,,




What is corresponding c++ data type to SQL numeric(18,0) data type?

What is corresponding c++ data type to SQL numeric(18,0) data type?



I need a datatype in C++ to store numeric(18,0) of SQL in it.





How can I get the memory of one process in Linux

Why I use 'top' in Linux to show my memory of one process,I get that the storage of the process do only increase and do not decrease except I close the all process.I don't know why,though I use 'free' only behind 'malloc'.
How can I get the correct actual REAL-TIME storage of my process?
thanks all.





Missing start boundary Exception when sending messages with an attachment file in Tomcat

I've found a number of possible matches to this problem but none that work for me.



I'm using Apache Camel to deliver a file as an email attachement. It works perfectly using the following maven goals:



jetty:run
jetty:run-exploded
jetty:run-war



I'm using java 1.6. My deployment container is tomcat6. In tomcat6 and tomcat7 I get the following exception:



org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: Missing start boundary; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Missing start boundary
at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:882)



The advice on the web suggests this is a class loader problem. Its either that the activation-1.1.jar or mail-1.4.4.jar files are not being found, or the mailcap file in mail-1.4.4.jar is not being found.



I've tried putting these jar files in tomcat/lib. I've tried copying the mailcap from the jar file into the META-INF directory of the exploded war. Neither of these make a difference.



Versions:



Windows: Apache Tomcat/7.0.5 JDK 1.6.0_27-b07 Apache Camel 2.8.0-fuse-00-08



Linux - the versions that come with ubuntu 10.04 LTS - I'll check these later and add.



This is a simplified version of my camel routes:



<route id="uploadFileForm">
<from uri="jetty:http://0.0.0.0:9095/premier"/>
<to uri="velocity:form.html"/>
</route>
<route id="uploadFile">
<from uri="jetty:http://0.0.0.0:9095/fup"/>
<to uri="log:mail?showBody=true&amp;showHeaders=true"/>
<to uri="smtp://localhost"/>
<setHeader headerName="content-type"><constant>text/plain</constant></setHeader>
<setBody><constant>Message Sent</constant></setBody>
</route>


This is what the log shows:



[4 - seda://mail-ws-audio-files] mail                           INFO  Exchange[ExchangePattern:InOut, Headers:{Connection=Keep-Alive, CamelHttpServletRequest=org.eclipse.jetty.servlets.MultiPartFilter$Wrapper@bb32c5, upfile=D:downloads!37SQFTS.pdf, CamelHttpPath=/fup, subject=BBC Premier League Update - Edition 1, CamelHttpQuery=null, CamelHttpServletResponse=HTTP/1.1 200 

, UntilMessage=until 10:30 GMT when a second bulletin is available (Mon-Fri only), Host=localhost:9095, User-Agent=Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E), Accept-Encoding=gzip, deflate, bulletin_type=am, to=julian.cable@yahoo.com, cc=admin@localhost, breadcrumbId=ID-B1-L0N336601-58958-1335935026761-0-2, CamelHttpUrl=http://localhost:9095/fup, Content-Length=24896, Referer=http://localhost:9095/premier, from=jfbcable@gmail.com, Accept=image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*, Accept-Language=en-GB, Content-Type=multipart/form-data; boundary=---------------------------7dc3a8371906f6, CamelHttpUri=/fup, Cache-Control=no-cache, CamelHttpMethod=POST}, BodyType:String, Body:Dear Partner,

please find attached the latest edition of our file.


Any ideas?





after deploy my ajax website missing ajax control

I have website using ajax control ,On development machine its working fine but after deployee ajax control is not showing or missing .my deployement server is windows 2008.



Please help me in fixing this..





reading error dialog in java

i need to read some error message in java, i tried to do this in getErrorStream and then readLine, but i got exeption.
i added a link to a picture of the error message i want to read
http://yfrog.com/0986806495p



TNX





Hide password text

I have a textbox using UseSystemPasswordChar, so it will not display the password that the user enters. The issue is that the password is still able to be read by something like Spy++. I'm looking for a way to hide this like they do in the password fields in the Services.msc > Log On tab.





python django - no module psycopg2.extension even after installing compiled version psycopg2-2.4.5.win32-py2.7.?exe

I am using python django on windows,and trying to deploy to heroku . When i tried to install psycopg2 using pip,



     pip install psycopg2 


i got error :

unable to find vcvarsall.bat

Then i found that i need to install visual studio 2008 (or) i can directly download and install compiled version , so downlaoded from this link :

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Filename i downloaded : psycopg2-2.4.5.win32-py2.7.?exe

Even after installing this i am getting error : no module named psycopg2.extensions



So, what more should i do ?



            D:\mycode\python\mysite>heroku run python manage.py syncdb
Running python manage.py syncdb attached to terminal... up, run.1
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site- packages/django/core/management/__i
nit__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/sql
.py", line 6, in <module>
from django.db import models
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line24, in load_backend
return import_module('.base', backend_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 13, in <module>
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation

File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/backends/postgre
sql_psycopg2/creation.py", line 1, in <module>
import psycopg2.extensions
ImportError: No module named psycopg2.extensions

D:\mycode\python\mysite>





While isntalling psycopg2 both by pip and easy_install, installdidnt work as i got this error : unable to find vcvarsall.bat with some msg : no previsouly included directores matching 'doc\src_build'



Thanks





is it possible to communicate over webservices in web2py application?

I have to develop one web2py application which will run on one machine (lets say SERVER), this machine will have MySql database also installed and running.
Users can connect remotely to the Web2py app over Https(Lets say it CLIENT)
There is one more system running over the network(Lets say N/W Panel) which can send the data to the SERVER and which will be further saved to the MySql database and Web2Py application will display the updated data to the CLIENT.
So the scenarios are:
1. SERVER can act like a client when CLIENT can request some data from N/W Panel (here N/W Panel acts as Server) using Web2Py application.
2. N/W Panel can act like a client when it gets some updated data from different devices and needs to save to the MySql database which is running on SERVER(here SERVER acts as Server).



Now My question is how to achieve it using web services as it is a bi-directional communication between SERVER and N/W Panel AND how to integrate with Web2Py application?
Web services can be SOAP OR REST.



Regards,
Piks





Search an XML file using Javascript then retrieving specific attributes based on matched string

I've looked through this entire site as various ways in searching through an XML file using a value taken from a html input field and have managed to do this, however when it finds the match thats all I can do is display a message saying "Match Found!".



What I'd like to do is be able to search the XML file using the search string value put into the html input field, then once its found a match pull the rest of the information for that specific node - as in all the attributes.



Example of my XML file:



<dvdcatalogue>
<dvd year="1979" rating="18" director="ridley scott">Alien</dvd>
</dvdcatalogue>


The title of the film being "Alien" so that would be the search string.



Any ideas how this could be done? I'm guessing it has something to do with loading into a javascript array maybe. Just to make anyone who answers aware none of the examples I've seen thus far have been that clear on the exact code that would achieve this.



Thanks in advance for the help!!





How to add one image onto another in java

I have an image with a plain background. Now I need to place another image onto it at (x, y) location. How is it possible?





common constant variables in Zend Framework

Where is the best place to create a class that contain all the application constant variables ?


is it :
- Bootstrap

- In the Application Common library





How to use manytomany field in symfony2?

I am stuck at a point from last 2 days. I am having two entities Subjects and Teachers. There is a manytomany relation between two. i have created a manytomany field in teacher entity like this :-



/**
* @ORM\ManyToMany(targetEntity="College\StudentBundle\Entity\Subjects", inversedBy="assets", cascade={"persist"})
* @ORM\JoinTable(name="employee_subjects")
*/

private $subjects;


which resulted in a third table. My subject entity contains only 3 fields, ID, Department_id and name, Now I want to open a regester form for a teacher where i want add the subjects he can teach, for this i created the subjecttype form ist like this :-



namespace College\StudentBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class SubjectsType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('name')
// ->add('name', 'entity', array('class' => 'CollegeStudentBundle:Subjects', 'property'=>'name', 'multiple' => false, ))
->add('departmentId', 'entity', array('class' => 'CollegeStudentBundle:Department', 'property'=>'name', 'multiple' => false, ))
;
}


public function getName()
{
return 'college_studentbundle_subjectstype';
}
}


And here is my teacher form where i included the subject:-



namespace College\HumanResourceBundle\Form;

use College\StudentBundle\Form\SubjectsType;
use College\StudentBundle\Entity;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class HumanResourceType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('empid')
->add('joining_date', 'date', array('years' => range(date('Y') - 10, date('Y'))))
->add('firstname')
->add('nationality')
->add('usertype', 'entity', array('class' => 'CollegeUserBundle:Usertype', 'property'=>'name', 'multiple' => false, ))

->add('subjects', 'collection', array('type' => new SubjectsType()));
;
}

public function getName()
{
return 'College_humanresourcebundle_humanresourcetype';
}
}

It is not working properly, I want, when i add new teacher it should display subject at the bottom where i can assign subjects to the teacher which gets saved in manytomany table.