SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

How to monitor Java memory usage?

We have a j2ee application running on Jboss and we want to monitor its memory usage. Currently we use the following code System.gc(); Runtime rt = Runtime.getRuntime(); long usedMB = (rt.totalMemory() - rt.freeMemory()) / 1024 / 1024; ...

Can I define a class name on paragraph using Markdown?

Can I define a class name on paragraph using Markdown? If so, how?...

Java Refuses to Start - Could not reserve enough space for object heap

Background We have a pool of aproximately 20 linux blades. Some are running Suse, some are running Redhat. ALL share NAS space which contains the following 3 folders: /NAS/app/java - a symlink that points to an installation of a Java JDK. Curre...

Exporting result of select statement to CSV format in DB2

Is there any way by which we can export the result of a select statment to CSV file, just like in MySQL. MySQL Command; SELECT col1,col2,coln into OUTFILE 'result.csv' FIELDS TERMINATED BY ',' FROM testtable t; ...

What are queues in jQuery?

I found the jQuery.com document on queue()/dequeue() is too simple to understand. What exactly are queues in jQuery? How should I use them?...

Wait for a process to finish

Is there any builtin feature in Bash to wait for a process to finish? The wait command only allows one to wait for child processes to finish. I would like to know if there is any way to wait for any process to finish before proceeding in any script....

Mysql Compare two datetime fields

I want to compare two dates with time, I want all the results from tbl where date1 > date2 Select * From temp where mydate > '2009-06-29 04:00:44'; but it is just comparing dates not time. it is giving me all the result set of today's date ...

How to compile the finished C# project and then run outside Visual Studio?

I just finished designing a simple code program. I called it a "Guessing Game". The program is so far working fine and I would like to open it without opening my Microsoft Visual Studio. How can I do that?...

TortoiseSVN icons not showing up under Windows 7

I can't seem to get the icons to display under Windows 7 and I really miss this from Windows XP. How can it be fixed?...

Wrap text in <td> tag

I want to wrap some text that is added to a <td> element. I have tried with style="word-wrap: break-word;" width="15%". But it is not wrapping the text. Is it mandatory to give it 100% width? I have other controls to display so only 15% width i...

Pretty git branch graphs

I've seen some books and articles have some really pretty looking graphs of git branches and commits. How can I make high-quality printable images of git history?...

How to increment an iterator by 2?

Can anybody tell me how to increment the iterator by 2? iter++ is available - do I have to do iter+2? How can I achieve this?...

How to load all modules in a folder?

Could someone provide me with a good way of importing a whole directory of modules? I have a structure like this: /Foo bar.py spam.py eggs.py I tried just converting it to a package by adding __init__.py and doing from Foo import * but...

how to make div click-able?

<div><span>shanghai</span><span>male</span></div> For div like above,when mouse on,it should become cursor:pointer,and when clicked,fire a javascript function,how to do that job? EDIT: and how to change the ba...

How do I automatically set the $DISPLAY variable for my current session?

I see that $DISPLAY is set to localhost:0.0 if I am running over a vnc server this may not be correct, is there a way to automatically set it in my login script?...

How to change Named Range Scope

When I create a named range through the Name Manager, I'm given the option of specifying Workbook or [worksheet name] scope. But if then want to change scope, the drop-down is grayed out. Is there a way, in either Name Manager or, preferablly, VBA to...

How to get the title of HTML page with JavaScript?

How can I get the title of an HTML page with JavaScript?...

Finding the last index of an array

How do you retrieve the last element of an array in C#?...

Where can I find documentation on formatting a date in JavaScript?

I noticed that JavaScript's new Date() function is very smart in accepting dates in several formats. Xmas95 = new Date("25 Dec, 1995 23:15:00") Xmas95 = new Date("2009 06 12,12:52:39") Xmas95 = new Date("20 09 2006,12:52:39") I could not find docu...

How to Auto-start an Android Application?

I'm not sure how to autostart an android application after the android emulator completes its booting. Does anyone have any code snippets that will help me?...

iPhone App Development on Ubuntu

Possible Duplicate: Starting iPhone app development in Linux? Is there a way to use Ubuntu Linux for developing iPhone applications destined to be listed on Apples app store ?...

How to pass variable number of arguments to printf/sprintf

I have a class that holds an "error" function that will format some text. I want to accept a variable number of arguments and then format them using printf. Example: class MyClass { public: void Error(const char* format, ...); }; The Error m...

Set mouse focus and move cursor to end of input using jQuery

This question has been asked in a few different formats but I can't get any of the answers to work in my scenario. I am using jQuery to implement command history when user hits up/down arrows. When up arrow is hit, I replace the input value with pre...

Difference between numeric, float and decimal in SQL Server

What are the differences between numeric, float and decimal datatypes and which should be used in which situations? For any kind of financial transaction (e.g. for salary field), which one is preferred and why?...

Algorithm for Determining Tic Tac Toe Game Over

I've written a game of tic-tac-toe in Java, and my current method of determining the end of the game accounts for the following possible scenarios for the game being over: The board is full, and no winner has yet been declared: Game is a draw. Cros...

How to create JSON string in C#

I just used the XmlWriter to create some XML to send back in an HTTP response. How would you create a JSON string. I assume you would just use a stringbuilder to build the JSON string and them format your response as JSON?...

Print the address or pointer for value in C

I want to do something that seems fairly simple. I get results but the problem is, I have no way to know if the results are correct. I'm working in C and I have two pointers; I want to print the contents of the pointer. I don't want to dereference t...

How can I get the behavior of GNU's readlink -f on a Mac?

On Linux, the readlink utility accepts an option -f that follows additional links. This doesn't seem to work on Mac and possibly BSD based systems. What would the equivalent be? Here's some debug information: $ which readlink; readlink -f /usr/bin/...

How do I add a tool tip to a span element?

In the following code, I want a tool-tip to come up when the user hovers the span, how do I do that? I don't want to use any links. <span> text </span> ...

C++ Get name of type in template

I'm writing some template classes for parseing some text data files, and as such it is likly the great majority of parse errors will be due to errors in the data file, which are for the most part not written by programmers, and so need a nice message...

Throw keyword in function's signature

What is the technical reason why it is considered bad practice to use the C++ throw keyword in a function signature? bool some_func() throw(myExc) { ... if (problem_occurred) { throw myExc("problem occurred"); } ... } ...

Changing the browser zoom level

I have need to create 2 buttons on my site that would change the browser zoom level (+) (-). I'm requesting browser zoom and not css zoom because of image size and layout issues. Well, is this even possible? I've heard conflicting reports....

Is a Java hashmap search really O(1)?

I've seen some interesting claims on SO re Java hashmaps and their O(1) lookup time. Can someone explain why this is so? Unless these hashmaps are vastly different from any of the hashing algorithms I was bought up on, there must always exist a datas...

Is there a way to make HTML5 video fullscreen?

Is there a way to play a video fullscreen using the HTML5 <video> tag? And if this is not possible, does anybody know if there is a reason for this decision?...

How can I get column names from a table in SQL Server?

I want to query the name of all columns of a table. I found how to do this in: Oracle MySQL PostgreSQL But I also need to know: how can this be done in Microsoft SQL Server (2008 in my case)?...

Vertically align text to top within a UILabel

I have a UILabel with space for two lines of text. Sometimes, when the text is too short, this text is displayed in the vertical center of the label. How do I vertically align the text to always be at the top of the UILabel? ...

How to import a Python class that is in a directory above?

I want to inherit from a class in a file that lies in a directory above the current one. Is it possible to relatively import that file?...

URL string format for connecting to Oracle database with JDBC

I'm a newbie to Java-related web development, and I can't seem to get a simple program with JDBC working. I'm using off-the-shelf Oracle 10g XE and the Eclipse EE IDE. From the books and web pages I've checked so far, I've narrowed the problem down t...

Best way to store password in database

I am working on a project that has to have authentication (username and password) It also connects to a database, so I figured I would store the username and password there. However, it seems like not such a good idea to have passwords as just a tex...

How to convert a Title to a URL slug in jQuery?

I'm working on an app in CodeIgniter, and I am trying to make a field on a form dynamically generate the URL slug. What I'd like to do is remove the punctuation, convert it to lowercase, and replace the spaces with hyphens. So for example, Shane's Ri...

Get the element with the highest occurrence in an array

I'm looking for an elegant way of determining which element has the highest occurrence (mode) in a JavaScript array. For example, in ['pear', 'apple', 'orange', 'apple'] the 'apple' element is the most frequent one....

How do I enable the column selection mode in Eclipse?

News wrote that Eclipse 3.5 finally supports column selection. Unfortunately I don't know HOW to enable it. I tried pressing the ALT-key like I am used to in Visual Studio and all other Microsoft products but that had no effect. How can I mark a v...

What is the difference between class and instance methods?

What's the difference between a class method and an instance method? Are instance methods the accessors (getters and setters) while class methods are pretty much everything else?...

How do I save a String to a text file using Java?

In Java, I have text from a text field in a String variable called "text". How can I save the contents of the "text" variable to a file?...

How do I get PHP errors to display?

I have checked my PHP ini file (php.ini) and display_errors is set and also error reporting is E_ALL. I have restarted my Apache webserver. I have even put these lines at the top of my script, and it doesn't even catch simple parse errors. For examp...

A generic error occurred in GDI+, JPEG Image to MemoryStream

This seems to be a bit of an infamous error all over the web. So much so that I have been unable to find an answer to my problem as my scenario doesn't fit. An exception gets thrown when I save the image to the stream. Weirdly this works perfectly w...

Eclipse - java.lang.ClassNotFoundException

When trying to start my JUnit-Test out of Eclipse, I get a "ClassNotFoundException". When running "mvn test" from console - everything works fine. Also, there are no problems reported in Eclipse. My project structure is the following: parent proje...

Create a pointer to two-dimensional array

I need a pointer to a static 2-dimensional array. How is this done? static uint8_t l_matrix[10][20]; void test(){ uint8_t **matrix_ptr = l_matrix; //wrong idea } I get all kinds of errors like: warning: assignment from incompatible pointer ...

Keyboard shortcut to "untab" (move a block of code to the left) in eclipse / aptana?

Well, hopefully the question is self-explanatory. It's so easy to select a block of code and tab out, but how about the reverse? Currently, I just search & replace for whitespace at the beginning of the line. Anything faster?...

java.io.IOException: Invalid Keystore format

Does anyone know how to solve this? I tried many things, but none of them worked. And when I click more details I get this: at sun.security.provider.JavaKeyStore.engineLoad(Unknown Source) atsun.security.provider.JavaKeyStore$JKS.engineLoad(Unknown...

What is Scala's yield?

I understand Ruby and Python's yield. What does Scala's yield do?...

scrollbars in JTextArea

How do I add scrollbars to a JTextArea?...

C multi-line macro: do/while(0) vs scope block

Possible Duplicates: What’s the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? do { … } while (0) what is it good for? I've seen some multi-l...

Initialising a multidimensional array in Java

What is the correct way to declare a multidimensional array and assign values to it? This is what I have: int x = 5; int y = 5; String[][] myStringArray = new String [x][y]; myStringArray[0][x] = "a string"; myStringArray[0][y] = "another string"...

JOIN queries vs multiple queries

Are JOIN queries faster than several queries? (You run your main query, and then you run many other SELECTs based on the results from your main query) I'm asking because JOINing them would complicate A LOT the design of my application If they are f...

Subclipse svn:ignore

I'm new to Eclipse. I'm using subclipse for connecting to my SVN. There are some folders and files I would like to add to svn:ignore, but it's grayed out. Is there an easy way to get subclipse to ignore files and directories? ...

Problem with converting int to string in Linq to entities

var items = from c in contacts select new ListItem { Value = c.ContactId, //Cannot implicitly convert type 'int' (ContactId) to 'string' (Value). Text = c.Name }; var items = from c ...

How to iterate over a std::map full of strings in C++

I have the following issue related to iterating over an associative array of strings defined using std::map. -- snip -- class something { //... private: std::map<std::string, std::string> table; //... } In the constructor I populat...

Iterate through a HashMap

What's the best way to iterate over the items in a HashMap?...

MySQL "Group By" and "Order By"

I want to be able to select a bunch of rows from a table of e-mails and group them by the from sender. My query looks like this: SELECT `timestamp`, `fromEmail`, `subject` FROM `incomingEmails` GROUP BY LOWER(`fromEmail`) ORDER BY `timestamp...

Easiest way to open a download window without navigating away from the page

What is the best cross browser way to open a download dialog (let's assume we can set content-disposion:attachment in the headers) without navigating away from the current page, or opening popups, which doesn't work well in Internet Explorer(IE) 6....

How to read a single char from the console in Java (as the user types it)?

Is there an easy way to read a single char from the console as the user is typing it in Java? Is it possible? I've tried with these methods but they all wait for the user to press enter key: char tmp = (char) System.in.read(); char tmp = (char) new ...

How can I remove leading and trailing quotes in SQL Server?

I have a table in a SQL Server database with an NTEXT column. This column may contain data that is enclosed with double quotes. When I query for this column, I want to remove these leading and trailing quotes. For example: "this is a test messag...

Has Windows 7 Fixed the 255 Character File Path Limit?

As I understand it, the limitation of 255 characters in a file path is a Windows limitation. What is the reasoning for this? If so, has this been resolved in Windows 7? In our continuous integration practices, we often have deeply nested project str...

jQuery: Selecting by class and input type

I would like to select a set of elements that are both of a certain input type (say, a checkbox) and have a certain class using jQuery. However, when I try the following: $("input:checkbox .myClass") I don't get any items returned. How can I ac...

How to bind Close command to a button

The easiest way is to implement ButtonClick event handler and invoke Window.Close() method, but how doing this through a Command binding? ...

How to get jQuery to wait until an effect is finished?

I am sure I read about this the other day but I can't seem to find it anywhere. I have a fadeOut() event after which I remove the element, but jQuery is removing the element before it has the chance to finish fading out. How do I get jQuery to wait u...

Initialization of all elements of an array to one default value in C++?

C++ Notes: Array Initialization has a nice list over initialization of arrays. I have a int array[100] = {-1}; expecting it to be full with -1's but its not, only first value is and the rest are 0's mixed with random values. The code int array[1...

How to Set the Background Color of a JButton on the Mac OS

Normally with Java Swing you can set the background color of a button with: myJButton.setBackground(Color.RED); which would cause the button to be red. But on the Mac OS, this method seems to be ignored. The button just stays the default color. H...

Can a CSS class inherit one or more other classes?

I feel dumb for having been a web programmer for so long and not knowing the answer to this question, I actually hope it's possible and I just didn't know about rather than what I think is the answer (which is that it's not possible). My question is...

What is dynamic programming?

What is dynamic programming? How is it different from recursion, memoization, etc? I have read the wikipedia article on it, but I still don't really understand it....

What's the main difference between Java SE and Java EE?

What's the main difference between Java SE and Java EE?...

In PHP, what is a closure and why does it use the "use" identifier?

I'm checking out some PHP 5.3.0 features and ran across some code on the site that looks quite funny: public function getTotal($tax) { $total = 0.00; $callback = /* This line here: */ function ($quantity, $product) use ($tax...

Setting background images in JFrame

Are any methods available to set an image as background in a JFrame?...

How to use XPath contains() here?

I'm trying to learn XPath. I looked at the other contains() examples around here, but nothing that uses an AND operator. I can't get this to work: //ul[@class='featureList' and contains(li, 'Model')] On: ... <ul class="featureList"> <li...

Random Number Between 2 Double Numbers

Is it possible to generate a random number between 2 doubles? Example: public double GetRandomeNumber(double minimum, double maximum) { return Random.NextDouble(minimum, maximum) } Then I call it with the following: double result = GetRando...

Creating a file name as a timestamp in a batch job

We have a batch job that runs every day and copies a file to a pickup folder. I want to also take a copy of that file and drop it into an archive folder with the filename yyyy-MM-dd.log What's the easiest way to do this in a Windows batch job? I...

How to list all Git tags?

In my repository, I have created tags using the following commands. git tag v1.0.0 -m 'finally a stable release' git tag v2.0.0 -m 'oops, there was still a major bug!' How do you list all the tags in the repository?...

Unable to show a Git tree in terminal

Killswitchcollective.com's old article, 30 June 2009, has the following inputs and outputs git co master git merge [your_branch] git push upstream A-B-C-D-E A-B-C-D-E-F-G \ ----> \ your branch ...

ASP.NET MVC - Set custom IIdentity or IPrincipal

I need to do something fairly simple: in my ASP.NET MVC application, I want to set a custom IIdentity / IPrincipal. Whichever is easier / more suitable. I want to extend the default so that I can call something like User.Identity.Id and User.Identity...

How Do I Insert a Byte[] Into an SQL Server VARBINARY Column

I have a byte array highlighted below, how do I insert it into a SQL Server database Varbinary column? byte[] arraytoinsert = new byte[10]{0,1,2,3,4,5,6,7,8,9}; string sql = string.format ( "INSERT INTO mssqltable (varbinarycolumn) VAL...

Inserting a text where cursor is using Javascript/jquery

I have a page with a lot of textboxes. When someone clicks a link, i want a word or two to be inserted where the cursor is, or appended to the textbox which has the focus. For example, if the cursor/focus is on a textbox saying 'apple' and he click...

Passing arrays as parameters in bash

How can I pass an array as parameter to a bash function? Note: After not finding an answer here on Stack Overflow, I posted my somewhat crude solution myself. It allows for only one array being passed, and it being the last element of the parameter l...

Objective-C Static Class Level variables

I have a class Film, each of which stores a unique ID. In C#, Java etc I can define a static int currentID and each time i set the ID i can increase the currentID and the change occurs at the class level not object level. Can this be done in Objectiv...

How to resolve "Server Error in '/' Application" error?

I am trying to deploy an asp.net application in our server while I am receiving the following error. Server Error in '/' Application. ________________________________________ Configuration Error Description: An error occurred during the processing...

How to sort an array of integers correctly

Trying to get the highest and lowest value from an array that I know will contain only integers seems to be harder than I thought. _x000D_ _x000D_ var numArray = [140000, 104, 99]; numArray = numArray.sort(); console.log(numArray)_x000D_ _x000D_ _x00...

What is an idempotent operation?

What is an idempotent operation?...

Can the Android drawable directory contain subdirectories?

In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my project. I am wondering if it is explicitly not okay to create a sub direct...

Hello World in Python

I tried running a python script: print "Hello, World!" And I get this error: File "hello.py", line 1 print "Hello, World!" ^ SyntaxError: invalid syntax What is going on?...

How do you Make A Repeat-Until Loop in C++?

How do you Make A Repeat-Until Loop in C++? As opposed to a standard While or For loop. I need to check the condition at the end of each iteration, rather than at the beginning....

Refresh image with a new one at the same url

I am accessing a link on my site that will provide a new image each time it is accessed. The issue I am running into is that if I try to load the image in the background and then update the one on the page, the image doesn't change--though it is upd...

Max length for client ip address

Possible Duplicate: Maximum length of the textual representation of an IPv6 address? What would you recommend as the maximum size for a database column storing client ip addresses? I have it set to 16 right now, but could I get an ip addr...

SQL Server using wildcard within IN

Since I believe this should be a basic question I know this question has probably been asked, but I am unable to find it. I'm probably about to earn my Peer Pressure badge, but I'll ask anyway: Is there a way in SQL Server that I am not aware of for...

Difference Between $.getJSON() and $.ajax() in jQuery

I am calling an ASP.NET MVC action public JsonResult GetPatient(string patientID) { ... from JavaScript using jQuery. The following call works $.getJSON( '/Services/GetPatient', { patientID: "1" }, function(jsonData) { alert(jsonData); }); wh...

How can multiple rows be concatenated into one in Oracle without creating a stored procedure?

How can I achieve the following in oracle without creating a stored procedure? Data Set: question_id element_id 1 7 1 8 2 9 3 10 3 11 3 12 Desired Result: question_...

How can I catch all the exceptions that will be thrown through reading and writing a file?

In Java, is there any way to get(catch) all exceptions instead of catch the exception individually?...

Simple way to find if two different lists contain exactly the same elements?

What is the simplest way to find if two Lists contain exactly the same elements, in the standard Java libraries? It shouldn't matter if the two Lists are the same instance or not, and it shouldn't matter if the type parameter of the Lists are diffe...

Using the AND and NOT Operator in Python

Here is my custom class that I have that represents a triangle. I'm trying to write code that checks to see if self.a, self.b, and self.c are greater than 0, which would mean that I have Angle, Angle, Angle. Below you will see the code that check...

Linq to SQL how to do "where [column] in (list of values)"

I have a function where I get a list of ids, and I need to return the a list matching a description that is associated with the id. E.g.: public class CodeData { string CodeId {get; set;} string Description {get; set;} } public List<Code...

Can't use method return value in write context

I would think the following piece of code should work, but it doesn't (Edited: Now works in PHP 5.5+): if (!empty($r->getError())) Where getError() is simply: public function getError() { return $this->error; } Yet I end up with this ...