Thursday, 3 October 2013

LWP::UserAgent and HTTP::Request for a POST request

LWP::UserAgent and HTTP::Request for a POST request

In a certain script I tried to write this:
my $ua = LWP::UserAgent->new;
my $res = $ua->post($url, Content => $data);
and got "400 Bad Request". After some reading I tried this:
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new( 'POST', $url );
$req->content( $data );
my $res = $ua->request( $req );
and it worked, but I thought these two should do the same. What am I
missing here? Am I misunderstanding something in the documentation of
HTTP::Request and LWP::UserAgent?
Is there a way to ask LWP::UserAgent to print what it is doing?

Wednesday, 2 October 2013

Complex Regex composition - Regex that match "if"

Complex Regex composition - Regex that match "if"

I'm making a Regex to match hashtags to my project. I want that regex
match hashtags that are separeted by one single space, don't have another
hashtag inside this content and just match a space in the string if this
is followed by any word (except other blank space or #).
I'm really curious to know if I can do something like "if" in regular
expressions and I hope you can help me with this.
So, in:
"#hashtag?!-=_" "#hashhash#" "#hash tag" "#hash tag" "#hash
#ahuhuhhuasd" "#hash "
The regex must match the following sentences:
"#hashtag?!-=_" "#hashhash" "#hash tag" "#hash" "#hash #ahuhuhhuasd" "#hash"
(all hashtag) (one) (another h.)
Actually, this is my code:
#{1,1}\S+\s{0,1}
You can test here this code, but it matches things that isn't desired:
"#ahusdhuas?!__??###hud #ahusdhuads "
The blank space in the end of the string, the 3 '#' inside the string.
none of the following content is desired in this string, just
"#ahusdhuas?!__??"
Glad if you can help me!

Problems with geotools library to create a .jar?

Problems with geotools library to create a .jar?

I have a java project and it works in eclipse then I create a .jar for
this project and when a try to execute the jar the following errors
appears:
If I create the .jar with eclipse: Exception in thread "main"
java.lang.NoClassDefFoundError: org/geotools/data/FeatureSource
If I create the .jar with mvn: Error: no se ha encontrato o cargado la
clase principal client.Client
Thanks

comparing pointer to a negative value

comparing pointer to a negative value

Can i typecast a pointer to a structure to a signed value to return a
different types of errors. Does the C standard allow this or is an
undefined behaviour.
typedef enum lError
{
l_OK = 0,
l_ERROR = -1,
l_ABORT = -2,
l_HALT = -3
}L_STATUS;
typedef struct dataCards
{
int card1;
int card2;
char flag;
}DATACARD;
DATACARD dataCardG;
DATACARD *getCard(int i)
{
if(i == 1)
return &dataCardG;
else if (i == 2)
return (DATACARD *)l_ERROR;
else if (i==3)
return (DATACARD *)l_ABORT;
else
return (DATACARD *)l_HALT;
}
int main ()
{
DATACARD *ptr = NULL;
ptr = getCard(3);
if(ptr < (DATACARD *) 1) /* Is this allowed or undefined behaviour */
printf("Card failed\n");
}
How can i make this condition work?

Getting the JAXB exception like "Two classes have the same XML type name..."

Getting the JAXB exception like "Two classes have the same XML type name..."

Getting the JAXB exception like "Two classes have the same XML type name...",
Here is the exception details:
Exception in thread "main"
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts
of IllegalAnnotationExceptions Two classes have the same XML type name
"city". Use @XmlType.name and @XmlType.namespace to assign different names
to them. this problem is related to the following location: at
com.model.City at public com.model.City com.model.Address.getCurrentCity()
at com.model.Address this problem is related to the following location: at
com.common.City at public com.common.City
com.model.Address.getPreviousCity() at com.model.Address
at
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown
Source) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown
Source) at
com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown
Source) at
com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown
Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
javax.xml.bind.ContextFinder.newInstance(Unknown Source) at
javax.xml.bind.ContextFinder.find(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
javax.xml.bind.JAXBContext.newInstance(Unknown Source) at
com.PojoToXSD.main(PojoToXSD.java:17)
I took the example like:
package com.model; ---->this package contains 'Address' class and 'City'
class
public class Address {
private String areaName;
private City currentCity;
private com.common.City previousCity;
}
package com.model;
public class City {
private String cityName;
}
Another city class in "com.common" package.
package com.common;
public class City {
private String pinCode;
}
We need to create XSDs and needs to do the Marshalling and unmarshalling
with the existing code in our project(like as above example code), code
does not have any annotations like "@XmlRootElement/@XmlType" and we can
not able to change the source code.
I would like to know is there any solution to fix the above issue or any
other ways to create XSDs and marshaling/unmarshalling(like MOXy..etc)?
It would be great if i can get the solution from any one....May thanks in
advance.
Thanks,
Satya.

Tuesday, 1 October 2013

Multiple and dynamic databases in doctrine 2

Multiple and dynamic databases in doctrine 2

I checked already multiple answers on stackoverflow but couldnt find a
sufficient answer for that problem.
Imagine I have a MAIN database and multiple SLAVE databases. Based on some
information in the MAIN database I will then know which SLAVE database I
will connect to and which table I will use for my model.
As an example:
A Person entity can be connected to a database1234 database using the
table person_india or to database7834 using a table person_uk etc. Which
one I will connect to is decide on runtime and cant be configured before.
What I found so far:
I can directly bind a model to a database.table via
@Entity @Table(name="databaseName.tablename")
So Im able to join over databases. So basically Im ignoring the dbname in
the connection params for the entityManager.
Question:
How to dynamically set the information(database,table) for an entity on
the fly?
Will this affect caching?
If this is not possible in a good manner. Is there any other orm which
will provide me that kind of functionality.
Thanks in advance

How to trigger two function on form submit?

How to trigger two function on form submit?

I have a form when the form is submitted i'll call one javascript function
and action it to to form handler.
<form action="subscribe.php" onsubmit="return form_check(this)"
method="post">
<input type="text" value="">
<input type="submit" value="click">
</form>
Everything Works fine, Now i want to send the same form fields to another
javascript function so i tried like this on submit code
<form action="subscribe.php"
onsubmit="return (form_check(this) & another_script(this))" method="post">
Added & in onsubmit but the function is not triggering when the button is
clicked. I think this is due to the action="subscribe.php" in the form.
I want to send the form value to another javascript function also. how can
i achieve this?

What's a neutral word for "father" and "mother"? – english.stackexchange.com

What's a neutral word for "father" and "mother"? – english.stackexchange.com

Is there a neutral word to refer to "father" and "mother" without the
family connotations? For example, there was a guy who refer to his parents
using the terms "sperm and egg bank": They were my …

Postix dosen't forward to Gmail Yahoo Hotmail

Postix dosen't forward to Gmail Yahoo Hotmail

I have a problem with my Postfix 2.8.4 (Cent OS 6 with Plesk 11.0)
If i sent an email to one of these providers, it will be delivered ok.
If I setup my email to forward all emails to one of these providers:
a. if i sent from an email from the same server, it will be delivered ok
b. If I sent from an email not hosted on the server, the mail will be
stuck in the queue forever.
Below is my main.cf
#
#soft_bounce = no
# LOCAL PATHNAME INFORMATION
#
queue_directory = /var/spool/postfix
# The command_directory parameter specifies the location of all
# postXXX commands.
#
command_directory = /usr/sbin
# The daemon_directory parameter specifies the location of all Postfix
# daemon programs (i.e. programs listed in the master.cf file). This
# directory must be owned by root.
#
daemon_directory = /usr/libexec/postfix
# The data_directory parameter specifies the location of Postfix-writable
# data files (caches, random numbers). This directory must be owned
# by the mail_owner account (see below).
#
data_directory = /var/lib/postfix
# QUEUE AND PROCESS OWNERSHIP
#
#
mail_owner = postfix
#
#default_privs = nobody
# INTERNET HOST AND DOMAIN NAMES
#
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
#
#mydomain = domain.tld
# SENDING MAIL
#
#myorigin = $myhostname
#myorigin = $mydomain
# RECEIVING MAIL
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = all
# Enable IPv4, and IPv6 if supported
inet_protocols = all
#
#proxy_interfaces =
#proxy_interfaces = 1.2.3.4
#
mydestination = localhost.$mydomain, localhost, localhost.localdomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
# REJECTING MAIL FOR UNKNOWN LOCAL USERS
#
#
#local_recipient_maps = unix:passwd.byname $alias_maps
local_recipient_maps = proxy:unix:passwd.byname $alias_maps
#local_recipient_maps =
#
unknown_local_recipient_reject_code = 550
# TRUST AND RELAY CONTROL
#
#mynetworks_style = class
#mynetworks_style = subnet
mynetworks_style = host
#
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
#mynetworks
= $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
#
#relay_domains = $mydestination
# INTERNET OR INTRANET
#
#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
# REJECTING UNKNOWN RELAY USERS
#
#
#relay_recipient_maps = hash:/etc/postfix/relay_recipients
# INPUT RATE CONTROL
#
#
#in_flow_delay = 1s
# ADDRESS REWRITING
#
# The ADDRESS_REWRITING_README document gives information about
# address masquerading or other forms of address rewriting including
# username->Firstname.Lastname mapping.
# ADDRESS REDIRECTION (VIRTUAL DOMAIN)
#
# The VIRTUAL_README document gives information about the many forms
# of domain hosting that Postfix supports.
# "USER HAS MOVED" BOUNCE MESSAGES
#
# See the discussion in the ADDRESS_REWRITING_README document.
# TRANSPORT MAP
#
# See the discussion in the ADDRESS_REWRITING_README document.
# ALIAS DATABASE
#
#
#alias_maps = dbm:/etc/aliases
alias_maps = hash:/etc/aliases, hash:/var/spool/postfix/plesk/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases
# The alias_database parameter specifies the alias database(s) that
# are built with "newaliases" or "sendmail -bi". This is a separate
# configuration parameter, because alias_maps (see above) may specify
# tables that are not necessarily all under control by Postfix.
#
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
# ADDRESS EXTENSIONS (e.g., user+foo)
#
#
#recipient_delimiter = +
# DELIVERY TO MAILBOX
#
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
# The mail_spool_directory parameter specifies the directory where
# UNIX-style mailboxes are kept. The default setting depends on the
# system type.
#
#mail_spool_directory = /var/mail
#mail_spool_directory = /var/spool/mail
# The mailbox_command parameter specifies the optional external
# command to use instead of mailbox delivery. The command is run as
# the recipient with proper HOME, SHELL and LOGNAME environment settings.
# Exception: delivery for root is done as $default_user.
#
#
#mailbox_command = /some/where/procmail
#mailbox_command = /some/where/procmail -a "$EXTENSION"
#
#mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
#
# To use the old cyrus deliver program you have to set:
#mailbox_transport = cyrus
#
#fallback_transport = lmtp:unix:/var/lib/imap/socket/lmtp
#fallback_transport =
#luser_relay = $user@other.host
#luser_relay = $local@other.host
#luser_relay = admin+$local
# JUNK MAIL CONTROLS
#
#
#header_checks = regexp:/etc/postfix/header_checks
# FAST ETRN SERVICE
#
#
#fast_flush_domains = $relay_domains
# SHOW SOFTWARE VERSION OR NOT
#
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
# PARALLEL DELIVERY TO THE SAME DESTINATION
#
#local_destination_concurrency_limit = 2
#default_destination_concurrency_limit = 20
# DEBUGGING CONTROL
#
#
debug_peer_level = 2
#
#debug_peer_list = 127.0.0.1
#debug_peer_list = some.domain
#
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
#
# debugger_command =
# PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH; screen
# -dmS $process_name gdb $daemon_directory/$process_name
# $process_id & sleep 1
# INSTALL-TIME CONFIGURATION INFORMATION
#
# The following parameters are used when installing a new Postfix version.
#
# sendmail_path: The full pathname of the Postfix sendmail command.
# This is the Sendmail-compatible mail posting interface.
#
sendmail_path = /usr/sbin/sendmail.postfix
# newaliases_path: The full pathname of the Postfix newaliases command.
# This is the Sendmail-compatible command to build alias databases.
#
newaliases_path = /usr/bin/newaliases.postfix
# mailq_path: The full pathname of the Postfix mailq command. This
# is the Sendmail-compatible mail queue listing command.
#
mailq_path = /usr/bin/mailq.postfix
# setgid_group: The group for mail submission and queue management
# commands. This must be a group name with a numerical group ID that
# is not shared with other accounts, not even with the Postfix account.
#
setgid_group = postdrop
# html_directory: The location of the Postfix HTML documentation.
#
html_directory = no
# manpage_directory: The location of the Postfix on-line manual pages.
#
manpage_directory = /usr/share/man
# sample_directory: The location of the Postfix sample configuration files.
# This parameter is obsolete as of Postfix 2.1.
#
sample_directory = /usr/share/doc/postfix-2.8.4/samples
# readme_directory: The location of the Postfix README files.
#
readme_directory = /usr/share/doc/postfix-2.8.4/README_FILES
virtual_mailbox_domains = $virtual_mailbox_maps,
hash:/var/spool/postfix/plesk/virtual_domains
virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
transport_maps = hash:/var/spool/postfix/plesk/transport
smtpd_tls_cert_file = /etc/postfix/postfix_default.pem
smtpd_tls_key_file = $smtpd_tls_cert_file
smtpd_tls_security_level = may
smtpd_use_tls = yes
smtp_tls_security_level = may
smtp_use_tls = no
smtpd_timeout = 3600s
smtpd_proxy_timeout = 3600s
disable_vrfy_command = yes
mynetworks = 127.0.0.0/8, [::1]/128, xxx.xxx.xxx.xxx/32
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks,
reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, permit
smtpd_sender_restrictions = permit_mynetworks,
reject_unknown_sender_domain, reject_unknown_address,
reject_unlisted_sender, reject_non_fqdn_sender,
reject_unknown_sender_domain, permit
# smtpd_client_restrictions = permit_mynetworks, reject_rbl_client
sbl.spamhaus.org
smtp_send_xforward_command = yes
smtpd_authorized_xforward_hosts = 127.0.0.0/8 [::1]/128
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks,
permit_sasl_authenticated, reject_unauth_destination, permit
# smtpd_recipient_restrictions = reject_unauth_pipelining,
reject_non_fqdn_recipient, reject_unknown_recipient_domain,
permit_mynetworks, reject_unauth_destination, check_sender_access
hash:/etc/postfix/sender_access, reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net, check_policy_service
unix:postgrey/socket, permit
virtual_mailbox_base = /var/qmail/mailnames
virtual_uid_maps = static:110
virtual_gid_maps = static:30
smtpd_milters = inet:localhost:12768
non_smtpd_milters = inet:localhost:12768
sender_dependent_default_transport_maps =
hash:/var/spool/postfix/plesk/sdd_transport_maps
virtual_transport = plesk_virtual
plesk_virtual_destination_recipient_limit = 1
mailman_destination_recipient_limit = 1
myhostname = mail.myinternet.gr
milter_connect_macros = j {daemon_name} v
milter_data_macros = i
milter_end_of_data_macros = i
milter_end_of_header_macros = i
milter_helo_macros = {tls_version} {cipher} {cipher_bits} {cert_subject}
{cert_issuer}
milter_macro_daemon_name = $myhostname
milter_macro_v = $mail_name $mail_version
milter_mail_macros = i {auth_type} {auth_authen} {auth_author} {mail_addr}
milter_rcpt_macros = i {rcpt_addr}
message_size_limit = 40960000
Thank you for your time