programming

Create a class object out of a generic type

Write a class which looks like the following <code> public class Test<T> { public Test() { Class<T> clazz = ? } } </code> Call this class with some self generated class which contains Annotations and try to read out the Annotations of this class from the clazz variable which has to be defined.

using reCAPTCHA

A CAPTCHA, short for "Completely Automated Public Turing Test To Tell Computers and Humans Apart" is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. Normally they use distorted text, which humans can readbut current computer programs and OCR software can't.

reCAPTCHA is a free service which can be integrated into a website via plugins for multiple programing languages (PHP, ASP.NET, Java, Perl, ...) and content management systems (WordPress, MediaWiki, ...)

Additionally to helping you handling your spam-problem, reCAPTCHA helps digitizing books by showing words that could not be deciphered by OCR software and letting them read and fill in by humans.

Spam-Protect web forms

Spam is not only a problem for emails, but more so for web forms. Bots from spammers try to fill out forms all over the internet. But unlike in your email inbox, the data from your web forms normally does not get spam filtered, which makes spam in these cases an even bigger problem. The goal is to add spam protection (CAPTCHA) to your web forms to make sure only humans fill in and submit the form.

mutliprocessing

The multiprocessing library uses functional programming patterns to enable simple multithreading.
So to load and parse a website a simple solution looks like this (_ are used instead of spaces because the platform doesn't support spaces in code-tags):

def load_parse_page(url):
____request = urllib2.Request(url)
____page = urllib2.urlopen(request).read()
____print page # do the parsing
_
urls = ["http://localhost:80", "http://localhost:90"]
_
p = multiprocessing.dummy.Pool(10)
p.map(load_parse_page, urls)

This will create a thread-pool consisting of 10 threads.
Then the method map is called which takes a function and a list of arguments.
For each argument the function is called inside a thread.

Taggings:

Speed up parsing HTML pages in Python

Using a command-line Python utility a website is queried and parsed, consecutively other websites are queried and parsed. Loading and parsing each website takes a considerable amount of time. For loading the websites <code>urllib2</code> is used and for parsing them <code>BeautifulSoup</code> is used.

Integrate Online Payment into Website

For different purposes it is necessary to integrate an online payment system in to an existing website. These purposes can be for the payment of registration fees, donations, membership fees, small selection of products, etc. However, in these cases a full-blown webshop solution is not needed, since the range of products is very limited and most of the webshop features, like inventory management are not needed. The existing website already features a registration-procedure and the payment process shall be integrated there. Moreover the design of the integrated parts shall be adapted to the website itself. Requirements for the customer side: * trusted system * secure (https) * support of multiple payment methods (credit cards, etc.) Requirements for the website owner * easy to integrate, with current website (typo3/php) * design and styles should be adaptable to the design of the website * easy management of incoming payments * work with an Austrian bank account Since the frequency and amount of payments is not expected to be very high, there should be no recurring fees for using the service. Fees per payment shall be as low as possible. The system should be able to handle a larger amount of payments flawlessly should the need arise at one time in the future.

Capture network traffic with Pcapy

Description of Pcapy (http://oss.coresecurity.com/projects/pcapy.html):
"Pcapy is a Python extension module that interfaces with the libpcap packet capture library. Pcapy enables python scripts to capture packets on the network. Pcapy is highly effective when used in conjunction with a packet-handling package such as Impacket, which is a collection of Python classes for constructing and dissecting network packets."

Getting all available devices:
http://pastebin.com/fXfTwuU4

Start the sniffing:
http://pastebin.com/eWHGRA9q

Read the stream:
http://pastebin.com/xU9yy0pM

(I had to use links because correct indentation is important in python and not supported by this editor.)

Taggings:

Capturing network traffic with Python

<p> It is necessary to capture the traffic on a specific network-interface between a server and a client. Most of the messages can be ignored, but some of them should be filtered and evaluated.<br /> This depends on the message-body. </p> <p> Other requirements: <li>The network-interface should be choosable from a list of all available devices.<li>The body should be readable by a human-beings. <li>only SYN-Packages, no ACKs<li>specific IP-Adresses </p> It should run on Linux.

How to install the JBoss Tools on Eclipse

The following is the solution of install: Prerequisites: Eclipse IDE for Java EE Developers is installed I guess that you all probably have worked or at least have an idea what Java EE is, if not then here is a short explanation of Java EE. Java Platform, Enterprise Edition (Java EE) builds on the solid foundation of Java Platform, Standard Edition (Java SE) and is the industry standard for implementing enterprise-class service-oriented architecture (SOA) and next-generation web applications. The SDKs contain Sun GlassFish Enterprise Server, previously named Sun Java System Application Server, and provide support for Java EE 5 specifications. For more information look on Internet. 1. Start Eclipse. Click the Help menu and go to Software Updates -> Find and Install. 2. Click the radio button next to “Select for new features to install” and click Next. 3. Add a new remote site by clicking on the “New Remote Site” button. In the name field put in “JBossTools Stable Update Site” and for the URL put in “http://download.jboss.org/jbosstools/updates/stable/” then click OK. Make sure the JBossTools Stable Update Site is checked then click Finish. 4. Eclipse’s Update Manager will connect to the JBossTools site and parse the features to be displayed. On the Search Results dialog window, click the check box next to JBossTools Stable Update Site to install all the features under JBossTools Stable Update Site: 2.0.1.GA and Mozilla Libraries. Click Next. 5. Accept the terms and conditions in the license agreements after reading them and click Next. Make sure all the features you want to be installed are on the “Features to install” list then click Finish to start the actual install. 6. Once the downloading and installing is complete, restart Eclipse so all changes can be applied.

Taggings:

Send an email in C# without attachment

Here is the code snippet for the implementation:System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();message.To.Add("luckyperson@online.microsoft.com");message.Subject = "This is the Subject line";message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");message.Body = "This is the message body";System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");smtp.Send(message);

Taggings:

Pages

Subscribe to programming