SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

When using a Settings.settings file in .NET, where is the config actually stored?

When using a Settings.settings file in .NET, where is the config actually stored? I want to delete the saved settings to go back to the default state, but can't find where it's stored... any ideas?...

How to compare values which may both be null in T-SQL

I want to make sure I'm not inserting a duplicate row into my table (e.g. only primary key different). All my fields allow NULLS as I've decided null to mean "all values". Because of nulls, the following statement in my stored procedure can't work:...

Find Oracle JDBC driver in Maven repository

I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14. In MVNrepository site the dependency to put in the POM is: <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc14<...

The executable was signed with invalid entitlements

I am having a problem with ad-hoc distribution on my iPhone. I have developed an application with SDK 3.0. I have a developer's license. I have added certificates and provisioning profiles in my project. So, no problem with that. But, when I try to ...

MetadataException when using Entity Framework Entity Connection

This code: using (EntityConnection conn = new EntityConnection("name=ELSCommonEntities")) { conn.Open(); } Gives me the following error: Test method ELS.Service.Business.IntegrationTest.Base.ServiceBaseIntegrationTest.StartLoggingTestMethod thr...

How can I see the raw SQL queries Django is running?

Is there a way to show the SQL that Django is running while performing a query?...

Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

I have two user Objects and while I try to save the object using session.save(userObj); I am getting the following error: Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated...

Is it possible to disable floating headers in UITableView with UITableViewStylePlain?

I'm using a UITableView to layout content 'pages'. I'm using the headers of the table view to layout certain images etc. and I'd prefer it if they didn't float but stayed static as they do when the style is set to UITableViewStyleGrouped. Other then...

How to convert int[] into List<Integer> in Java?

How do I convert int[] into List<Integer> in Java? Of course, I'm interested in any other answer than doing it in a loop, item by item. But if there's no other answer, I'll pick that one as the best to show the fact that this functionality is ...

print spaces with String.format()

how I can rewrite this: for (int i = 0; i < numberOfSpaces; i++) { System.out.print(" "); } using String.format()? PS I'm pretty sure that this is possible but the javadoc is a bit confusing....

Clearing content of text file using php

I have a filelist.txt file and I created a file called clear.php to clear the content of filelist. I put a button in index.html to call clear.php to clear the file. Can anyone help me out regarding what PHP code I should write in clear.php? How to...

Is generator.next() visible in Python 3?

I have a generator that generates a series, for example: def triangle_nums(): '''Generates a series of triangle numbers''' tn = 0 counter = 1 while True: tn += counter yield tn counter += + 1 In Python 2 I a...

Function Pointers in Java

This may be something common and trivial, but I seem to be having trouble finding a concrete answer. In C# there is a concept of delegates, which relates strongly to the idea of function pointers from C++. Is there a similar functionality in Java? Gi...

Circle line-segment collision detection algorithm?

I have a line from A to B and a circle positioned at C with the radius R. What is a good algorithm to use to check whether the line intersects the circle? And at what coordinate along the circles edge it occurred?...

Count number of matches of a regex in Javascript

I wanted to write a regex to count the number of spaces/tabs/newline in a chunk of text. So I naively wrote the following:- numSpaces : function(text) { return text.match(/\s/).length; } For some unknown reasons it always returns 1. What is ...

How can I make grep print the lines below and above each matching line?

I have to parse a very large file and I want to use the command grep (or any other tool). I want to search each log line for the word FAILED, then print the line above and below each matching line, as well as the matching line. For example: id : 1...

see if two files have the same content in python

Possible Duplicates: Finding duplicate files and removing them. In Python, is there a concise way of comparing whether the contents of two text files are the same? What is the easiest way to see if two files are the same content-wise in Py...

How can I read numeric strings in Excel cells as string (not numbers)?

I have excel file with such contents: A1: SomeString A2: 2 All fields are set to String format. When I read the file in java using POI, it tells that A2 is in numeric cell format. The problem is that the value in A2 can be 2 or 2.0 (and I want ...

Is it possible to style a select box?

I've got an HTML select box that I need to style. I'd prefer to use just CSS but if I have to I'll use jQuery to fill in the gaps. Can anyone recommend a good tutorial or plugin? I know, Google, but I've been searching for the last two hours and I'...

How do you remove an invalid remote branch reference from Git?

In my current repo I have the following output: $ git branch -a * master remotes/origin/master remotes/public/master I want to delete remotes/public/master from the branch list: $ git branch -d remotes/public/master error: branch 'remotes/pub...

Call a VBA Function into a Sub Procedure

I know this is a simple question for someone out there, but I have never really used function module at all because I did not understand what they were. So I have a whole bunch of things I can use this for (cut down on redundancy), but I want to kno...

How do I print part of a rendered HTML page in JavaScript?

The JavaScript code window.print() can print the current HTML page. If I have a div in an HTML page (for example, a page rendered from an ASP.NET MVC view), then I want to print the div only. Is there any jQuery unobtrusive JavaScript or normal Jav...

How do I 'svn add' all unversioned files to SVN?

I'm looking for a good way to automatically 'svn add' all unversioned files in a working copy to my SVN repository. I have a live server that can create a few files that should be under source control. I would like to have a short script that I ca...

In C - check if a char exists in a char array

I'm trying to check if a character belongs to a list/array of invalid characters. Coming from a Python background, I used to be able to just say : for c in string: if c in invalid_characters: #do stuff, etc How can I do this with regu...

Is it possible to hide the cursor in a webpage using CSS or Javascript?

I want to hide the cursor when showing a webpage that is meant to display information in a building hall. It doesn't have to be interactive at all. I tried with the cursor property and a transparent cursor image but I didn't make it work. Does anybo...

UIView's frame, bounds, center, origin, when to use what?

UIView has the properties frame, bounds, center, and origin, and they all seem to be interrelated. Most of the time, I deal with frame when setting the position and size of a UIView. I understand that frame is using global coordinate system and bou...

Searching if value exists in a list of objects using Linq

Say I have a class Customer which has a property FirstName. Then I have a List<Customer>. Can LINQ be used to find if the list has a customer with Firstname = 'John' in a single statement.. how?...

jQuery add blank option to top of list and make selected to existing dropdown

So I have a dropdown list <select id="theSelectId"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi&...

Editing dictionary values in a foreach loop

I am trying to build a pie chart from a dictionary. Before I display the pie chart, I want to tidy up the data. I'm removing any pie slices that would be less than 5% of the pie and putting them in a "Other" pie slice. However I'm getting a Collectio...

JavaScript function in href vs. onclick

I want to run a simple JavaScript function on a click without any redirection. Is there any difference or benefit between putting the JavaScript call in the href attribute (like this: <a href="javascript:my_function();window.print();">....&...

C++ convert hex string to signed integer

I want to convert a hex string to a 32 bit signed integer in C++. So, for example, I have the hex string "fffefffe". The binary representation of this is 11111111111111101111111111111110. The signed integer representation of this is: -65538. ...

How to set a value of a variable inside a template code?

Say I have a template <html> <div>Hello {{name}}!</div> </html> While testing it, it would be useful to define the value of the variable without touching the python code that invokes this template. So I'm looking for someth...

How do I get the current date in Cocoa

I'm getting started developing for the iPhone and as such I am looking at different tutorials online as well as trying some different things out myself. Currently, I'm trying to create a countdown until midnight. To get the number of hour, minutes, a...

How to determine the first and last iteration in a foreach loop?

The question is simple. I have a foreach loop in my code: foreach($array as $element) { //code } In this loop, I want to react differently when we are in first or last iteration. How to do this?...

How can I make directory writable?

How can I make a directory writable, from the OS X terminal?...

JPA EntityManager: Why use persist() over merge()?

EntityManager.merge() can insert new objects and update existing ones. Why would one want to use persist() (which can only create new objects)?...

Neither BindingResult nor plain target object for bean name available as request attr

Hi Experts, I have this controller code which is throwing the above mentioned error. It was working fine till yesterday, I have no clue what colleague did to this code and today I am seeing the error: Neither BindingResult nor plain target object ...

Sorting object property by values

If I have a JavaScript object such as: var list = { "you": 100, "me": 75, "foo": 116, "bar": 15 }; Is there a way to sort the properties based on value? So that I end up with list = { "bar": 15, "me": 75, "you": 100, "foo": ...

Are members of a C++ struct initialized to 0 by default?

I have this struct: struct Snapshot { double x; int y; }; I want x and y to be 0. Will they be 0 by default or do I have to do: Snapshot s = {0,0}; What are the other ways to zero out the structure?...

Limit on the WHERE col IN (...) condition

I'm using the following code: SELECT * FROM table WHERE Col IN (123,123,222,....) However, if I put more than ~3000 numbers in the IN clause, SQL throws an error. Does anyone know if there's a size limit or anything similar?!!...

Passing an array of parameters to a stored procedure

I need to pass an array of "id's" to a stored procedure, to delete all rows from the table EXCEPT the rows that match id's in the array. How can I do it in a most simple way?...

Using the star sign in grep

I am trying to search for the substring "abc" in a specific file in linux/bash So I do: grep '*abc*' myFile It returns nothing. But if I do: grep 'abc' myFile It returns matches correctly. Now, this is not a problem for me. But what if I wan...

How to get the IP address of the server on which my C# application is running on?

I am running a server, and I want to display my own IP address. What is the syntax for getting the computer's own (if possible, external) IP address? Someone wrote the following code. IPHostEntry host; string localIP = "?"; host = Dns.GetHostEntry...

How can I get the current stack trace in Java?

How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace? I found Thread.dumpStack() but it is not what I want - I want to get the stack trace back, not print it out....

Object comparison in JavaScript

What is the best way to compare objects in JavaScript? Example: var user1 = {name : "nerd", org: "dev"}; var user2 = {name : "nerd", org: "dev"}; var eq = user1 == user2; alert(eq); // gives false I know that two objects are equal if they refer t...

Can I pass parameters by reference in Java?

I'd like semantics similar to C#'s ref keyword....

Update with two tables?

I am trying to update table A with data from table B. I thought I could do something like: UPDATE A SET A.name = B.name WHERE A.id = B.id but alas, this does not work. Anyone have an idea of how I can do this?...

Format numbers in JavaScript similar to C#

Is there a simple way to format numbers in JavaScript, similar to the formatting methods available in C# (or VB.NET) via ToString("format_provider") or String.Format()?...

Post an object as data using Jquery Ajax

My code that I tried is as follows: var dataO = new Object(); dataO.numberId = 1; dataO.companyId = 531; $.ajax({ type: "POST", url: "TelephoneNumbers.aspx/DeleteNumber", data: "{numberId:1,companyId:531}", contentType: "application/json; chars...

Assigning out/ref parameters in Moq

Is it possible to assign an out/ref parameter using Moq (3.0+)? I've looked at using Callback(), but Action<> does not support ref parameters because it's based on generics. I'd also preferably like to put a constraint (It.Is) on the input of ...

What is the difference between Cloud Computing and Grid Computing?

What are the significant differences between Cloud Computing and Grid Computing ? What are the precise definations and target application domains for both ? I'm looking for conceptual insights along with technicalities. Like Windows Azure is a Cloud...

ASP.net Repeater get current index, pointer, or counter

the question is really simple. Is there a way to access the current pointer/counter for an asp Repeater control. I have a list with items and I would like one of the repeaters columns (it repeats and html table) to be something like ... Item 1 | so...

How to upload a file using Java HttpClient library working with PHP

I want to write Java application that will upload a file to the Apache server with PHP. The Java code uses Jakarta HttpClient library version 4.0 beta2: import java.io.File; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; imp...

Are there any log file about Windows Services Status?

I want to figure out when the services was start up and terminated. Are there any kind log file about it?...

Combine Multiple child rows into one row MYSQL

Thanks in advance, I just can't seem to get it! I have two tables Ordered_Item ID | Item_Name 1 | Pizza 2 | Stromboli Ordered_Options Ordered_Item_ID | Option_Number | Value 1 43 Pepperoni 1 ...

Can I set enum start value in Java?

I use the enum to make a few constants: enum ids {OPEN, CLOSE}; the OPEN value is zero, but I want it as 100. Is it possible?...

How to set the allowed url length for a nginx request (error code: 414, uri too large)

I am using Nginx in front of 10 mongrels. When I make a request with size larger then 2900 I get back an: error code 414: uri too large Does anyone know the setting in the nginx configuration file which determines the allowed uri length ?...

C# Timer or Thread.Sleep

I am running a windows service and using a loop and Thread.Sleep to repeat a task, would it be better to use a timer method? If yes a code example would be great I am currently using this code to repeat int curMinute; int lastMinute = DateTime.No...

Detect element content changes with jQuery

change() function works and detects changes on form elements, but is there a way of detecting when a DOM element's content was changed? This does not work, unless #content is a form element $("#content").change( function(){ // do something }); ...

Show "Open File" Dialog

How would I go about showing an open file (or file select) dialog in access 2007 VBA? I have tried using Application.GetOpenFileName as I would in Excel, but this function doesn't exist in Access....

Getting the client's time zone (and offset) in JavaScript

How can I gather the visitor's time zone information? I need both: the time zone (for example, Europe/London) and the offset from UTC or GMT (for example, UTC+01) ...

Change URL parameters

I have this URL: site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc what I need is to be able to change the 'rows' url param value to something i specify, lets say 10. And if the 'rows' doesn't exist, I ne...

Why is 1/1/1970 the "epoch time"?

Why is 1 January 1970 00:00:00 considered the epoch time?...

How to clone a Date object?

Assigning a Date variable to another one will copy the reference to the same instance. This means that changing one will change the other. How can I actually clone or copy a Date instance?...

Java: how to convert HashMap<String, Object> to array

I need to convert a HashMap<String, Object> to an array; could anyone show me how it's done?...

Instantiating a generic class in Java

I know Java's generics are somewhat inferior to .Net's. I have a generic class Foo<T>, and I really need to instantiate a T in Foo using a parameter-less constructor. How can one work around Java's limitation?...

git: undo all working dir changes including new files

How to delete all changes from working directory including new untracked files. I know that git checkout -f does that, but it doesn't delete new untracked files created since last commit. Does anybody have an idea how to do that?...

/usr/bin/codesign failed with exit code 1

I am attempting to deploy my first development iPhone app, and am running into some problems. I have successfully went though the online Provisioning Assistant, but now I am stuck. No matter what I do, I always get the following error. /usr/bin...

How do you set autocommit in an SQL Server session?

How do you set autocommit in an SQL Server session?...

Newline in JLabel

How can I display a newline in JLabel? For example, if I wanted: Hello World! blahblahblah This is what I have right now: JLabel l = new JLabel("Hello World!\nblahblahblah", SwingConstants.CENTER); This is what is displayed: Hello W...

Maven Run Project

Is there a Maven "phase" or "goal" to simply execute the main method of a Java class? I have a project that I'd like to test manually by simply doing something like "mvn run"....

SelectSingleNode returning null for known good xml node path using XPath

Consider this simple XML document. The serialized XML shown here is the result of an XmlSerializer from a complex POCO object whose schema I have no control over. <My_RootNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:...

.NET HashTable Vs Dictionary - Can the Dictionary be as fast?

I am trying to figure out when and why to use a Dictionary or a HashTable. I have done a bit of a search on here and have found people talking about the generic advantages of the Dictionary which I totally agree with, which leads the boxing and unbo...

Setting a property by reflection with a string value

I'd like to set a property of an object through Reflection, with a value of type string. So, for instance, suppose I have a Ship class, with a property of Latitude, which is a double. Here's what I'd like to do: Ship ship = new Ship(); string value...

Why can't decimal numbers be represented exactly in binary?

There have been several questions posted to SO about floating-point representation. For example, the decimal number 0.1 doesn't have an exact binary representation, so it's dangerous to use the == operator to compare it to another floating-point numb...

SQL: sum 3 columns when one column has a null value?

SELECT sum(TotalHoursM) + (TotalHoursT) + (TotalHoursW) + (TotalHoursTH) + (TotalHoursF) AS TOTAL FROM LeaveRequest ...

How do I create an array of strings in C?

I am trying to create an array of strings in C. If I use this code: char (*a[2])[14]; a[0]="blah"; a[1]="hmm"; gcc gives me "warning: assignment from incompatible pointer type". What is the correct way to do this? edit: I am curious why this sh...

How to fully clean bin and obj folders within Visual Studio?

If you right click on a folder, you will see a "Clean" menu item. I assumed this would clean (remove) the obj and bin directory. However, as far as I can see, it does nothing. Is there another way? (please don't tell me to go to Windows Explorer or ...

How to call a method after bean initialization is complete?

I have a use case where I need to call a (non-static) method in the bean only-once at the ApplicationContext load up. Is it ok, if I use MethodInvokingFactoryBean for this? Or we have a some better solution? As a side note, I use ConfigContextLoader...

Get element from within an iFrame

How do you get a <div> from within an <iframe>?...

What's wrong with using == to compare floats in Java?

According to this java.sun page == is the equality comparison operator for floating point numbers in Java. However, when I type this code: if(sectionID == currentSectionID) into my editor and run static analysis, I get: "JAVA0078 Floating point v...

How do I divide in the Linux console?

I have to variables and I want to find the value of one divided by the other. What commands should I use to do this?...

HTML email with Javascript

How to include javascript in HTML emails - We need it for expanding and collapsing of the content in the HTML email. ...

Press Enter to move to next control

I have a few TextBox on the WinForm. I would like the focus to move to the next control when Enter key is pressed? Whenever a textbox gains control, it will also select the text, so that any editing will replace the current one. What is the best way...

When does Java's Thread.sleep throw InterruptedException?

When does Java's Thread.sleep throw InterruptedException? Is it safe to ignore it? I am not doing any multithreading. I just want to wait for a few seconds before retrying some operation....

Using Mockito to test abstract classes

I'd like to test an abstract class. Sure, I can manually write a mock that inherits from the class. Can I do this using a mocking framework (I'm using Mockito) instead of hand-crafting my mock? How?...

Validate SSL certificates with Python

I need to write a script that connects to a bunch of sites on our corporate intranet over HTTPS and verifies that their SSL certificates are valid; that they are not expired, that they are issued for the correct address, etc. We use our own internal...

What's the difference between OpenID and OAuth?

I'm really trying to understand the difference between OpenID and OAuth? Maybe they're two totally separate things?...

Script for rebuilding and reindexing the fragmented index?

Can anyone provide the script for rebuilding and re-indexing the fragmented index when 'avg_fragmentation_in_percent' exceeds certain limits (better if cursor is not used)?...

Assigning the return value of new by reference is deprecated

I've just got an error. When I try to assign an object like this: $obj_md = new MDB2(); The error I get is "Assigning the return value of new by reference is deprecated". Actually I've been looking for a solution but the only one I've seen is ju...

Rename multiple files based on pattern in Unix

There are multiple files in a directory that begin with prefix fgh, for example: fghfilea fghfileb fghfilec I want to rename all of them to begin with prefix jkl. Is there a single command to do that instead of renaming each file individually?...

Ant build failed: "Target "build..xml" does not exist"

When I run the ant file in verbose mode, I got an error like the one below. Does anyone have any ideas what is going wrong? I am new to this antlib:org.apache.tools.ant] Could not load definitions from resource org/apach e/tools/ant/antlib.xml. It c...

String to object in JS

I have a string as string = "firstName:name1, lastName:last1"; now I need one object obj such that obj = {firstName:name1, lastName:last1} How can I do this in JS?...

How does facebook, gmail send the real time notification?

I have read some posts about this topic and the answers are comet, reverse ajax, http streaming, server push, etc. How does incoming mail notification on Gmail works? How is GMail Chat able to make AJAX requests without client interaction? I would...

Is there a method for String conversion to Title Case?

Are there any built in methods available to convert a string into Title Case format?...

Locate current file in IntelliJ

How do I locate the current file in the project structure? (Similar to Visual Studio's Ctrl + Alt + L). What is the name of the operation (so I can define it in the keymap)...

Get selected value in dropdown list using JavaScript

How do I get the selected value from a dropdown list using JavaScript? I tried the methods below, but they all return the selected index instead of the value: _x000D_ _x000D_ var as = document.form1.ddlViewBy.value; var e = document.getElementById("d...

How to Delete Session Cookie?

How to dynamically, via javascript, delete a session cookie, without manually restarting the browser? I read somewhere that session cookie is retained in browser memory and will be removed when the browser is closed. // sessionFooCookie is session ...

What does 'synchronized' mean?

I have some questions regarding the usage and significance of the synchronized keyword. What is the significance of the synchronized keyword? When should methods be synchronized? What does it mean programmatically and logically? ...

SQL comment header examples

Would just like too see what peoples Stored Procedure/Function etc comment headers look like (so post your examples)...I've only really seen what the SQL Server Management Studio creates but am interested in what other peoples look like...the formatt...