Monday, April 16, 2012

"Could not find the main class" error.

I have a .jar generated by Eclipse, which I cannot run on other computer (with Windows XP). The "Could not find the main class. Program will exit" message appears. That computer runs fine another .jar generated by Netbeans, so it is not a problem with JRE, I guess. I updated JRE but it changed nothing. What is the problem?

Remove noise and make the output better

I have the input image :

enter image description here

and the output of vein detection in leaf but the output is really

enter image description here

However i don't want to loose the fine details in the leaf veins so median filter won't suit my problem

Please help

Looping over lines with Python

So I have a file that contains this:

SequenceName 4.6e-38 810..924
SequenceName 1.6e-38 887..992

I want my program to read only the lines that contain these protein sequences. Up until now I got this, which skips the first line and read the second one:

handle = open(filename, "r")
linearr = handle.readline().split()

filenamealpha = filename + ".txt"
handle = open(filenamealpha, "w")
handle.write(">%s\n%s\n" % (linearr[0], linearr[1]))

But it only processes the first sequence and I need it to process every line that contains a sequence, so I need a loop, how can I do it?
The part that saves to a txt file is really important too so I need to find a way in which I can combine these two objectives.
My output with the above code is:


Which Java CLI library with currently active community is more feature-rich?

Main goal of this question is to create a table with easy-to-use, wide-spread (more or less) Java CLI libraries (and their features). So, if someone need such library, he could select one from this page, filtering table for required features.


  1. OpenSource libraries only.

  2. That's not the goal of this question to cover ALL existing CLI libraries. It's easier to select something useful if we don't add "almost dead" libraries with hard-to-find documentation. If you unsure about your CLI library, but proud of it's features and could describe why it's better then others, than add answer/comment with info. If answer/comment gets 10 upvotes, it's OK to add such library to table.

  3. Same applies to addition of features to table. If feature is not very useful and you are unsure - check with "10 upvotes" method.

Music Recognition API (Paid or free)

I got a requirement of creating an APP for mobile which will recognize the playing music and show the meta content of that song (genre, singer, lyrics etc). Just like shazam application.

I have the database ready. But, I am not sure if there is any API available which will recognize the music and execute a search in our database of songs and music. Please let me know if there is any API like that, it will really help.

MS VC++ Compiler equivocation

In my project, I trying reload global operator new and delete ([] too). And when I try to compile in first time, I get link error:

Main.obj : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)

When I try to compile in second time, errors magically disappear! But sometimes return.
How to resolve this problem?

Run-time Library: MTd.

javascript/svg submit form or input button

Can someone please guide me on how to go about creating a submit form or input button that can be used to create the option of adding for example shapes to the screen.

for example something like do you want 2, 3 or 4 shapes on the screen then you choose and press submit or just click with an input button the amount you want

Quicksort Algorithm throws StackOverflowException

For a homework assignment, I have to write an implementation of the QuickSort algorithm and use this to sort a list with 100k numbers in some random order.

In the first part of the assignment, I have to use the first item of the array as the pivot element. This indeed returns a sorted list. However, for the second part of the assignment I have to use the last item as the pivot, which results in a StackOverflowException. When I try it in a smaller collection of 8 records, it DOES work correctly. I've been looking at my code but I can't figure out where I'm making a mistake. Any help would be greatly appreciated. My code is as follows:

public class QuickSort {

private QuickSortStrategyEnum quickSortStrategy;

public QuickSort(QuickSortStrategyEnum quickSortStrategy) {

this.quickSortStrategy = quickSortStrategy;

public List<Integer> sortIntegerArray(List<Integer> arrayList, int left, int right) {

if ( left >= right ) {
return arrayList;

int i = partition(arrayList, left, right);

if (i <= right) {

int pivotNew = partition(arrayList, i, right);
int pivotIndex = arrayList.indexOf(pivotNew);

arrayList = sortIntegerArray(arrayList, left , pivotIndex - 1);
arrayList = sortIntegerArray(arrayList, pivotIndex + 1, right);

return arrayList;

private int partition(List<Integer> arrayList, int left, int right) {

int pivot = getPivot(arrayList, left, right);
int i = left + 1;

for (int j = i; j <= right; j++) {

if (arrayList.get(j) < pivot) {

Collections.swap(arrayList, j, i);

Collections.swap(arrayList, left, i - 1);
return i;

private int getPivot(List<Integer> arrayList, int left, int right) {

int pivot = 0;

switch (quickSortStrategy) {

case FIRST:
pivot = arrayList.get(left);

case LAST:
pivot = arrayList.get(right);
return pivot;


zend framework images from database

Simply I'm looking to get images from a database displayed on page.

I have the image path saved as a blob in the database and then tried to echo the field in the source property of the img tag. But I get loads of random characters displayed and no image.. Below is what I have in the view of the page I want images displayed:

<div id="club_pictures">
<img id="pic_1" src="<?php echo $this->clubs['pic_1']; ?>" />
<img id="pic_2" src="<?php echo $this->clubs['pic_2']; ?>" />
<img id="pic_3" src="<?php echo $this->clubs['pic_3']; ?>" />

If I then click view source in the browser I get the exact HTML I would want to display the image.



Calling another method to get resultset and closing the connection correctly?

String query= "select user_name from user";
ResultSet rs = queries.performQuery(query);

System.out.println("User Name :" + rs.getString("user_name"));

in another class I have something like this:

public ResultSet performQuery(String query) throws SQLException
connection = DriverManager.getConnection(sqlUrl,sqlUser,sqlPassword);
stmt = connection.createStatement();
rs = stmt.executeQuery(query);

catch(SQLException ex)

return rs;

Now I get the error Operation not allowed after ResultSet closed, and it's obviously because I'm closing the rs/stmt/connection.

I don't have my code with me so this is just off the top of my head, disregard any syntax errors and I hope my question is still clear enough.

So my question is this:

If you want to have a method that for example performs queries, and you call that in another method and then do, what is the appropriate way to close the resultset/stmt/connection? To me it makes sense to close them the performQuery, but that gives me the error.

NSManagedObject NSNumber properties convert booleans to integers?

I am running into a problem with a NSManagedObject subclass where the value is set to boolean value, but the primitive type always seems to be an integer.

Here's a scenario that describes the problem:

If I have a method to check the primitive type of an NSNumber, like so:

- (BOOL) numberIsBool:(NSNumber*)numberToCheck {

const char *primitiveType = [numberToCheck objCType];

return (strcmp(primitiveType, @encode(BOOL)) == 0 );

And I execute the following code:

NSNumber *num = [NSNumber numberWithBool:YES];

BOOL isBool = [self numberIsBool:num];

As expected, primitiveType will be "c" and isBool will be YES.

However, if I take the NSManagedObject subclass:

@interface MyClass : NSManagedObject

@property (nonatomic, retain) NSNumber *myBoolValue;

where myBoolValue is set to type Boolean in the model, and I execute the following code:

MyClass *myClass = ... (create from NSManagedObjectContext)

myClass.myBoolValue = [NSNumber numberWithBool:YES];

BOOL isBool = [self numberIsBool:num];

primitiveType will be set to "i" and isBool will be NO

Can anyone explain to me the reason for this or how I can get the myBoolValue property to honor the primitive type it was set with?

EDIT: So there is no confusion on what I am trying to accomplish - I am NOT trying to convert the NSNumber to a boolean. I already know how to do this with [myBoolValue boolValue].

EDIT #2 - More clarification: If I interrogate an NSManagedObject's properties. When the property is an NSNumber and it's value is 1 or 0, I need to take a different code path if it was intended to be a boolean than if it was intended to be an integer.

Avoiding cast when using CImage

Recently I have seen a few people telling others that if they need to cast they are doing something wrong. I have this code in C++

byte* pixel = (byte*)image->GetBits();

Here I cast to a byte* because GetBits() returns a void*. So how would I either

  • have pixel hold a byte* without casting

  • use void* (I have never used this type before)

To clarify, I then go on to use pixel similar to this.

*(pixel) += 20;
*(pixel + 1) += 20;
*(pixel + 2) += 20;

Android create new Activity on Top despite "singleTop"

I have got a Activity with


How can i manipulate an Intent in order to create a new Activity on Top.
Cause in an exceptional case I need a new Activity.

Or is it impossible?

MKMapView not properly removing annotation?

I found something odd, maybe this is familiar to anyone:
I am adding a simple MKPointAnnotation to a MKMapView, then modifying its coordinate property using KVO-compliance, then removing the annotation using -removeAnnotation: . However, when I move the map after the annotation was deleted, the pin occurs again - even though the annotation was supposedly removed! Checking further, it looks like MKMapView has not really removed the annotation.

Please see the following code snippet. You may paste it into a new Xcode iOS project, single view will suffice. Add a MKMapView to the view, then 3 buttons Start, Step, Stop, and connect them to the appropriate actions.
"userAnnotation" is a MKPointAnnotation ivar in the view controller.
If you press Stop, the number of annotations of the MKMapView is printed to console, before and after removal.
ARC is enabled.

How to reproduce:

  1. Press Start; a pin appears.

  2. Press Step; the pin moves a bit.

  3. Press Stop; the pin disappears.

  4. Drag the map - the pin reappears!

If you press Start and then Stop (not press Step), the annotation is removed correctly, check the counter in the console: 1, 1 = weird; 1, 0 = ok

Any idea what's happening? I thought I did the KVO-thing correctly.

- (IBAction)startTouched:(id)sender
userAnnotation = [[MKPointAnnotation alloc] init];
userAnnotation.coordinate = CLLocationCoordinate2DMake(50.85, 4.72); // some coord
[mapView addAnnotation:userAnnotation];

MKMapPoint p = MKMapPointForCoordinate(userAnnotation.coordinate);
double w = 500 * MKMapPointsPerMeterAtLatitude(userAnnotation.coordinate.latitude);
[mapView setVisibleMapRect:MKMapRectMake(p.x - w, p.y - w, 2*w, 2*w) animated:NO];

- (void)nextLocation
MKMapPoint p = MKMapPointForCoordinate(userAnnotation.coordinate);
p.x += 10 * MKMapPointsPerMeterAtLatitude(userAnnotation.coordinate.latitude);

[userAnnotation willChangeValueForKey:@"coordinate"];
userAnnotation.coordinate = MKCoordinateForMapPoint(p);
[userAnnotation didChangeValueForKey:@"coordinate"];

NSLog(@"pin at %@, %@", MKStringFromMapPoint(p), [NSThread currentThread]);

- (IBAction)stepTouched:(id)sender
[self nextLocation];

- (IBAction)stopTouched:(id)sender
NSLog(@"mark 10, map has %u annotations, %@", [mapView.annotations count], userAnnotation);
[mapView removeAnnotation:userAnnotation];
NSLog(@"mark 20, map has %u annotations, %@", [mapView.annotations count], [NSThread currentThread]);
userAnnotation = nil;

update linq to sql with variable names?

im pretty much a beginner to using and linq to sql but what im trying to do is update a column of a table based on a variable. at the momment i have

Dim db As New sqldcDataContext
Dim update As tableName = (From i in db.tableNames _ Select i)

i think this selects everything, how could i have two variables, one to store what table to update and the other what column. is this possible?

Training, testing and validation datasets in Matlab Neural Networks

I am trying to setup a neural network, it is supposed to have 3 inputs vectors, each one with 10 inputs, that should be read as described in the manual in batch mode in opposition to the sequential input for dynamic networks.

I have managed to setup everything correctly, but the training method is not being able to divide the inputs correctly into training, testing and validation datasets, from what i understand in the "tr" variable resulting from the training procedure, all input vectors are assigned to the train dataset.

Does anyone have an idea on how to set this up?

Example data:

inputs = 

[10x1 double] [10x1 double] [10x1 double]
[10x1 double] [10x1 double] [10x1 double]
[10x1 double] [10x1 double] [10x1 double]





 targets = { 0 1 0 }

Thanks in advance,


servlet 3.0 import package of annotation

In Servlets 3.0 we have to import the annotations package. So i want to know which are classes and interfaces??

import javax.servlet.annotation.WebServlet;

What is here servlet, annotation and WebServlet a class or interface in the javax package? 


full screen fancybox(iframe)

I use fancybox plugin on my website and I want to display an iframe in fullscreen.
I use this <a href="">This goes to iframe</a>, and the problem is that the iframe is not displayed full screen.

Check this and click on details to see what I'm talking about.

Why is not working ?

how to intentionally corrupt a file in java

Note: Please do not judge this question. To those who think that I am doing this to "cheat"; you are mistaken, as I am no longer in school anyway. I took on this project because I thought it might be fun. Before you down-vote, please consider the value of the question it's self, and not the speculative uses of it, as the purpose of SO is not to judge, but simply give the public information.

I am developing a program in java that is supposed intentionally corrupt a file (specifically a .doc, txt, or pdf, but others would be good as well) The purpose of this project is for students who want to get extra time on assignments, so they create a corrupt file, and send that in first (similar to this)

I initially tried this:

public void corruptFile (String pathInName, String pathOutName) {
curroptMethod method = new curroptMethod();
ArrayList<Integer> corruptHash = corrupt(getBytes(pathInName));
writeBytes(corruptHash, pathOutName);
new MimetypesFileTypeMap().getContentType(new File(pathInName));
// "/home/ephraim/Desktop/testfile"

public ArrayList<Integer> getBytes(String filePath) {
ArrayList<Integer> fileBytes = new ArrayList<Integer>();
try {
FileInputStream myInputStream = new FileInputStream(new File(filePath));
do {
int currentByte =;
if(currentByte == -1) {
System.out.println("broke loop");
} while (true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
return fileBytes;

public void writeBytes(ArrayList<Integer> hash, String pathName) {
try {
OutputStream myOutputStream = new FileOutputStream(new File(pathName));
for (int currentHash : hash) {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block

public ArrayList<Integer> corrupt(ArrayList<Integer> hash) {
ArrayList<Integer> corruptHash = new ArrayList<Integer>();
ArrayList<Integer> keywordCodeArray = new ArrayList<Integer>();
Integer keywordIndex = 0;
String keyword = "corruptthisfile";

for (int i = 0; i < keyword.length(); i++) {

for (Integer currentByte : hash) {

//Integer currentByteProduct = (keywordCodeArray.get(keywordIndex) + currentByte) / 2;
Integer currentByteProduct = currentByte - keywordCodeArray.get(keywordIndex);
if (currentByteProduct < 0) currentByteProduct += 255;

if (keywordIndex == (keyword.length() - 1)) {
keywordIndex = 0;
} else keywordIndex++;

return corruptHash;

but the problem is that the file is still openable. When you open the file, all of the words are changed (and they may not make any sense, and they may not even be letters, but it can still be opened)

so here is my actual question:

Is there a way to make a file so corrupt that the computer doesn't know how to open it at all (ie. when you open it, the computer will say something along the lines of "this file is not recognized, and cannot be opened")?

Is it advisable to use USER_NAME as the object_id in user details collection?

I am new to MongoDB and design schema for the user details collection. Is it advisable to use USER_NAME as the object_id in user details collection? What are all the Pros and Cons of it?

ajax background process after submit button

the script I post works fine, it just execute in background my php code at the load of the page.. What I cannot do is to start the php in background after having pressed a submit button.. I tried to add a form in the body but I don't know how to link it with the ajax.. how could be done?

<script src=""></script>
<script src=""></script>

<script type="text/javascript">
$(document).ready(function() {
url: 'trial.php',
beforeSend: function() {
// you could also put a spinner img or whatever here too..
success: function(result) {




Ruby mechanize post with header

I have page with js that post data via XMLHttpRequest and server side script check for this header, how to send this header?

agent = { |a|
a.user_agent_alias = 'Mac Safari'
a.log ='./site.log')
'act' => '_get_page',
"gid" => 1,
'order' => 0,
'page' => 2
) do |page|
p page

Turn a meteor method returning a single object into a context for handlebar

In the basic leaderboard example on there is a method called selected_name.

  Template.leaderboard.selected_name = function () {
var player = Players.findOne(Session.get("selected_player"));
return player &&;

{{#if selected_name}}
<div class="details">
<div class="name">{{selected_name}}</div>
<input type="button" class="inc" value="Give 5 points" />

Instead I would like to return the entire player object and then have that object be treated as a context by handlebar. I wish I could say this:

  Template.leaderboard.selected_person = function () {
var player = Players.findOne(Session.get("selected_player"));
return player || false;

{{#if selected_person}}
<div class="details">
<div class="name">{{name}}</div>
<input type="button" class="inc" value="Give 5 points" />

The #if block above does not actually work in meteor. The #if statement is just evaluating the selected_person method and the nested {{name}} does absolutely nothing. I would like to know if it is possible to write a method so that the returned object can be used as the context of an #if block.

Reference another class in python

I'm just starting out with Python for Google App Engine. I have a file, and in here, I will be creating User entities, which are specified in How can I do this? I've tried import users, but I get an error: NameError: global name 'User' is not defined

What is the visibility of ivar?

What is the visibility of ivar? Is it @private or @public?

@interface Jack : NSObject
NSString *string;

Java Stanford NLP: Part of Speech labels?

The Stanford NLP, demo'd here, gives an output like this:

Colorless/JJ green/JJ ideas/NNS sleep/VBP furiously/RB ./.

What do the Part of Speech tags mean? I am unable to find an official list. Is it Stanford's own system, or are they using universal tags? (What is JJ, for instance?)

Also, when I am iterating through the sentences, looking for nouns, for instance, I end up doing something like checking to see if the tag .contains('N'). This feels pretty weak. Is there a better way to programmatically search for a certain part of speech?

How to call javascript function from a controller in MVC3

I have looked round and I cannot find a solutions hence I find myself here. from what i have read i would been able to do this in web forms using RegisterClientScript or RegisterClientScriptBlock. I cannot find this in any MVC3 documentation.
I have the following function in a MVC 3 View :

MyTest View :

<div data-role="content">

<div id="mappingTable"></div>


@section Scripts {
<script type="text/javascript">

$("#jqm-home").live('pageinit', function () {
addTableRow(' adding data to table <br/>');

//I want to the able to call the function from the controller.
function addTableRow(msg) {


In My Controller I have the following.

public class MyTestController : Controller
#region Class Constractor

public MyTestController()
Common.ControllerResourceEvent += new System.EventHandler<ResourceEventArgs>(Common_ResourceEvent);

private void Common_ResourceEvent(object sender, ResourceEventArgs e)
//I want to call the function addTableRow and pass ResourceEventArgs

Why do we use the "class << self" expression?

In Ruby there are several ways to declare a class method.

We have these two forms...

class Dog

def self.species
puts "I'm a dog."

def Dog.species_rly?
puts "Still a dog."


And this other, longer form...

class Dog
class << self
def species_srsly?
puts "OK, fine. I'm a cat."

Why is the last form used? How is it better than just doing this?

class Dog
def Dog.some_method
# ...

Namespace, argparse, and usage

This is really a few questions:

  1. Is there a reason argparse uses a namespace instead of a dictionary?

  2. Assuming I have a class with __init__(self, init_method, *args). The init_method parameter tells the init_function which way I want to initialize the class, while arg parameter gives all the arguments neccesary for the init. The arguments may be different for different methods. Should I use a dictionary, or a namespace?

  3. Assuming that I use a namespace, how do I pass the namespace to __init__()?

Rails 3 render layout in action causes error with Twitter Bootstrap

Im using twitter bootstrap for design. I want to use a different template for a specific action

def view
render :layout => 'single'
@movie = Movie.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @movie }

As soon as i add in the render layout to the action I get this error message

undefined method `model_name' for NilClass:Class

Extracted source (around line #2):

1: <%- model_class = @movie.class -%>
2: <h1><%=t '.title', :default => model_class.model_name.human %></h1>
4: <p>
5: <strong><%= model_class.human_attribute_name(:title) %>:</strong><br>

If I take the render away the page will load just fine.