SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

SQL how to increase or decrease one for a int column in one command

I have an Orders table which has a Quantity column. During check in or check out, we need to update that Quantity column by one. Is there a way to do this in one action or we have to get the existing value and then add or minus one on top of it? Ano...

What size do you use for varchar(MAX) in your parameter declaration?

I normally set my column size when creating a parameter in ADO.NET But what size do I use if the column is VARCHAR(MAX)? cmd.Parameters.Add("@blah", SqlDbType.VarChar, ?????).Value = blah; ...

How to include header files in GCC search path?

I have the following code in a sample file: #include "SkCanvas.h" #include "SkDevice.h" #include "SkGLCanvas.h" #include "SkGraphics.h" #include "SkImageEncoder.h" #include "SkPaint.h" #include "SkPicture.h" #include "SkStream.h" #include "SkWindow....

What does HTTP/1.1 302 mean exactly?

Some article I read once said that it means jumping (from one URI to another), but I detected this "302" even when there was actually no jumping at all!...

document.getElementById().value and document.getElementById().checked not working for IE

I tried to assign a new value into the hidden input and checkbox of an input form. It's working fine in Firefox but not in IE (I'm using IE 7). Does anyone know what is wrong with my code? HTML: <input type="hidden" id="msg" name="msg" value="" ...

add column to mysql table if it does not exist

My research and experiments haven't yielded an answer yet, so I am hoping for some help. I am modifying the install file of an application which in previous versions did not have a column which I want to add now. I do not want to add the column manu...

Casting a variable using a Type variable

In C# can I cast a variable of type object to a variable of type T where T is defined in a Type variable?...

View array in Visual Studio debugger?

Is it possible to view an array in the Visual Studio debugger? QuickWatch only shows the first element of the array....

How to loop through all enum values in C#?

This question already has an answer here: How do I enumerate an enum in C#? 26 answers public enum Foos { A, B, C } Is there a way to loop through the possible values of Foos? Basically? foreach(Foo in Foos) ...

How to create a template function within a class? (C++)

I know it's possible to make a template function: template<typename T> void DoSomeThing(T x){} and it's possible to make a template class: template<typename T> class Object { public: int x; }; but is it possible to make a class ...

Get first 100 characters from string, respecting full words

I have asked a similar question here before, but I need to know if this little tweak is possible. I want to shorten a string to 100 characters and use $small = substr($big, 0, 100); to do so. However, this just takes the first 100 characters and do...

LIMIT 10..20 in SQL Server

I'm trying to do something like : SELECT * FROM table LIMIT 10,20 or SELECT * FROM table LIMIT 10 OFFSET 10 but using SQL Server The only solution I found looks like overkill: SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY name) as ...

What is a unix command for deleting the first N characters of a line?

For example, I might want to: tail -f logfile | grep org.springframework | <command to remove first N characters> I was thinking that tr might have the ability to do this but I'm not sure....

Why avoid increment ("++") and decrement ("--") operators in JavaScript?

One of the tips for jslint tool is: ++ and -- The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to vir...

jQuery UI Color Picker

I have heard that jQuery UI includes a Color Picker but could find little documentation regarding it. Does it exist? Any decent documentation on how to implement it? I found this: http://docs.jquery.com/UI/Colorpicker But using: $("#colorpicker...

CSS: fixed to bottom and centered

I need my footer to be fixed to the bottom of the page and to center it. The contents of the footer may change at all time so I can't just center it via margin-left: xxpx; margin-right: xxpx; The problem is that for some reason this doesn't work: #...

Is there an "if -then - else " statement in XPath?

It seems with all the rich amount of function in xpath that you could do an "if" . However , my engine keeps insisting "there is no such function" , and I hardly find any documentation on the web (I found some dubious sources , but the syntax they ha...

JavaScript string and number conversion

How can I do the following in JavaScript? Concatenate "1", "2", "3" into "123" Convert "123" into 123 Add 123 + 100 = 223 Covert 223 into "223" ...

Change auto increment starting number?

In MySQL, I have a table, and I want to set the auto_increment value to 5 instead of 1. Is this possible and what query statement does this?...

Postgres and Indexes on Foreign Keys and Primary Keys

Does Postgres automatically put indexes on Foreign Keys and Primary Keys? How can I tell? Is there a command that will return all indexes on a table?...

jQuery disable a link

Anyone know how to disable a link in jquery WITHOUT using return false;? Specifically, what I'm trying to do is disable the link of an item, performing a click on it using jquery which triggers some stuff, then re-enabling that link so that if it's ...

How do I call a dynamically-named method in Javascript?

I am working on dynamically creating some JavaScript that will be inserted into a web page as it's being constructed. The JavaScript will be used to populate a listbox based on the selection in another listbox. When the selection of one listbox is ...

ASP.NET - How to write some html in the page? With Response.Write?

I need that some html in the area in the asp.net page that i am coding, is changed according to a string variable. I was thinking about creating a label, and then change the text on it. But the string variable contains something like: <h2><...

What is the difference between C++ and Visual C++?

What is the difference between C++ and Visual C++? I know that C++ has the portability and all, so if you know C++ how is it related to Visual C++? Is Visual C++ mostly for online apps? Would Visual Basic be better for desktop applications?...

Exact time measurement for performance testing

What is the most exact way of seeing how long something, for example a method call, took in code? The easiest and quickest I would guess is this: DateTime start = DateTime.Now; { // Do some work } TimeSpan timeItTook = DateTime.Now - start; B...

How do I translate an ISO 8601 datetime string into a Python datetime object?

I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe). One hackish option seems to be to parse the string using time.strptime and passing the first six elements of the tuple into the datetime constructor, ...

Hot deploy on JBoss - how do I make JBoss "see" the change?

I am developing a Java EE application that I deploy over and over again on a local JBoss installation during development. I want to speed up the build by hot deploying my application straight into [JBOSS]/server/default/deploy/myApp It seems to work...

How to print out the method name and line number and conditionally disable NSLog?

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently. In particular, I have two questions: is there a way to easily NSLog the current method's name / line number? is there a way to "disab...

Regular expression for decimal number

I need to validate a textbox input and can only allow decimal inputs like: X,XXX (only one digit before decimal sign and a precision of 3). I'm using C# and try this ^[0-9]+(\.[0-9]{1,2})?$?...

What is the right way to check for a null string in Objective-C?

I was using this in my iPhone app if (title == nil) { // do something } but it throws some exception, and the console shows that the title is "(null)". So I'm using this now: if (title == nil || [title isKindOfClass:[NSNull class]]) { //...

Can a java file have more than one class?

What is the purpose of having more than one class in a Java file ? I am new to Java. Edited: That can be achieved by creating a inner class inside a public class, right?...

Convert web page to image

What are some utilities to obtain an image of a webpage? Basically equivalent to taking a "screenshot" of the page after opening it....

What is the string length of a GUID?

I want to create a varchar column in SQL that should contain N'guid' while guid is a generated GUID by .NET (Guid.NewGuid) - class System.Guid. What is the length of the varchar I should expect from a GUID? Is it a static length? Should I use nvarc...

How do you fade in/out a background color using jquery?

How do I fade in text content with jQuery? The point is to draw the user's attention to the message....

Using jQuery to test if an input has focus

On the front page of a site I am building, several <div>s use the CSS :hover pseudo-class to add a border when the mouse is over them. One of the <div>s contains a <form> which, using jQuery, will keep the border if an input within ...

How do I vertical center text next to an image in html/css?

What is the best and easiest way to vertically center text that's next to an image in html? Needs to be browser version/type agnostic. A pure html/CSS solution....

Mythical man month 10 lines per developer day - how close on large projects?

Everybody always says that they can beat the "10 lines per developer per day" from the "Mythical Man Month", and starting a project, I can usually get a couple hundred lines in in a day. But at my previous employer, all the developers were very shar...

How to detect pressing Enter on keyboard using jQuery?

I would like to detect whether the user has pressed Enter using jQuery. How is this possible? Does it require a plugin? EDIT: It looks like I need to use the keypress() method. I wanted to know if anyone knows if there are browser issues with tha...

Sorting an array of objects by property values

I've got the following objects using AJAX and stored them in an array: var homes = [ { "h_id": "3", "city": "Dallas", "state": "TX", "zip": "75201", "price": "162500" }, { "h_id": "4", ...

Struct inheritance in C++

Can a struct be inherited in C++?...

Changing the action of a form with JavaScript/jQuery

I'm having an issue that is driving me crazy. I'm trying to modify the openid-selector to support facebook. I'm using RPXNow as my provider so it requires the form to be submitted to a different url than the standard. For example. RpxNow requires m...

Is there an easy way to convert jquery code to javascript?

Is there an easy way to convert jQuery code to regular javascript? I guess without having to access or understand the jQuery source code....

Javascript - How to detect if document has loaded (IE 7/Firefox 3)

I want to call a function after a document loads, but the document may or may not have finished loading yet. If it did load, then I can just call the function. If it did NOT load, then I can attach an event listener. I can't add an eventlistener aft...

Logging in Scala

What is a good way to do logging in a Scala application? Something that is consistent with the language philosophy, does not clutter the code, and is low-maintenance and unobtrusive. Here's a basic requirement list: simple does not clutter the code...

HTTP GET with request body

I'm developing a new RESTful webservice for our application. When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example sorting a list) they can add these parameters in the ...

Selecting only first-level elements in jquery

How can I select the link elements of only the parent <ul> from a list like this? <ul> <li><a href="#">Link</a></li> <li><a href="#">Link</a> <ul> <li><a href="#">Link<...

Why does Math.Round(2.5) return 2 instead of 3?

In C#, the result of Math.Round(2.5) is 2. It is supposed to be 3, isn't it? Why is it 2 instead in C#?...

What does the M stand for in C# Decimal literal notation?

In order to work with decimal data types, I have to do this with variable initialization: decimal aValue = 50.0M; What does the M part stand for?...

Regular Expressions and negating a whole character group

I'm attempting something which I feel should be fairly obvious to me but it's not. I'm trying to match a string which does NOT contain a specific sequence of characters. I've tried using [^ab], [^(ab)], etc. to match strings containing no 'a's or '...

warning: incompatible implicit declaration of built-in function ‘xyz’

I'm getting a number of these warnings when compiling a few binaries: warning: incompatible implicit declaration of built-in function ‘strcpy’ warning: incompatible implicit declaration of built-in function ‘strlen’ warning: incompatible im...

How to reset radiobuttons in jQuery so that none is checked

I have radio buttons in HTML like this: <td> <input id="radio1" type="radio" name="correctAnswer" value="1">1</input> <input id="radio2" type="radio" name="correctAnswer" value="2">2</input> <input id="ra...

Redirecting unauthorized controller in ASP.NET MVC

I have a controller in ASP.NET MVC that I've restricted to the admin role: [Authorize(Roles = "Admin")] public class TestController : Controller { ... If a user who is not in the Admin role navigates to this controller they are greeted with a b...

How to style the UL list to a single line

I want to render this list in a single line. List item1 List item2 Should be shown as *List item2 *List item2 What CSS style to use?...

Shuffling a list of objects

I have a list of objects and I want to shuffle them. I thought I could use the random.shuffle method, but this seems to fail when the list is of objects. Is there a method for shuffling objects or another way around this? import random class A: ...

How to check if a date is in a given range?

If you have a $start_date and $end_date, how can you check if a date given by the user falls within that range? e.g. $start_date = '2009-06-17'; $end_date = '2009-09-05'; $date_from_user = '2009-08-28'; At the moment the dates are strings, wou...

Get POST data in C#/ASP.NET

I am trying to get POST data, but I'm having no luck. My code is below. When I click the form button nothing happens. I expected at least my IDE to snap at A.Ret(), but nothing happens whatsoever. File Test.cs using System.Web; public class A { ...

Java generics - why is "extends T" allowed but not "implements T"?

I wonder if there is a special reason in Java for using always "extends" rather than "implements" for defining bounds of typeparameters. Example: public interface C {} public class A<B implements C>{} is prohibited but public class A<...

How to split a delimited string in Ruby and convert it to an array?

I have a string "1,2,3,4" and I'd like to convert it into an array: [1,2,3,4] How?...

How to get the month name in C#?

How does one go about finding the month name in C#? I don't want to write a huge switch statement or if statement on the month int. In VB.Net you can use MonthName(), but what about C#?...

Eclipse Error: "Failed to connect to remote VM"

I’m getting the following error when I start Debug from the Eclipse IDE. Message: “Failed to connect to remote VM. Connection Refused” What could be the reason?...

#ifdef in C#

I would like to do the below but in C# instead of C++ #ifdef _DEBUG bool bypassCheck=TRUE_OR_FALSE;//i will decide depending on what i am debugging #else bool bypassCheck = false; //NEVER bypass it #endif ...

Remote debugging a Java application

I have a java application running on linux machine. I run the java application using the following: java myapp -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000, suspend=n I have opened port 4000 for TCP on this Linux machine. I use ec...

How do I instantiate a JAXBElement<String> object?

I need to create one of these as the interface requires it. Can someone please let me know how to create one, as there doesn't seem to be a c'tor defined?...

Passing Javascript variable to <a href >

<script language="javascript" type="text/javascript"> var scrt_var = 10; </script> HTML Part: <html> this is a <a href ="2.html & Key= scrt_var">Link </a> </html> I just want to sent the javascript vari...

Java Timestamp - How can I create a Timestamp with the date 23/09/2007?

How can I create a Timestamp with the date 23/09/2007? ...

Split an integer into digits to compute an ISBN checksum

I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split...

Automatically get loop index in foreach loop in Perl

If I have the following array in Perl: @x = qw(a b c); and I iterate over it with foreach, then $_ will refer to the current element in the array: foreach (@x) { print; } will print: abc Is there a similar way to get the index of the cur...

Find all controls in WPF Window by type

I'm looking for a way to find all controls on Window by their type, for example: find all TextBoxes, find all controls implementing specific interface etc....

What is a database transaction?

Can someone provide a straightforward (but not simpler than possible) explanation of a transaction as applied to computing (even if copied from Wikipedia)? ...

Setting mime type for excel document

MS Excel has the following observed MIME types: application/vnd.ms-excel (official) application/msexcel application/x-msexcel application/x-ms-excel application/x-excel application/x-dos_ms_excel application/xls application/x-xls application/vnd.op...

How to run regasm.exe from command line other than Visual Studio command prompt?

I want to run regasm.exe from cmd. which is available in c:\windows\Microsoft.net\framework\2.057 I do like this c:\ regasm.exe It gives regasm is not recognized as internal or external command. So I understood that I need to set the path for rega...

Why does the Visual Studio editor show dots in blank spaces?

I have a strange bug in the Visual Studio text editor. All my blank spaces are replaced by a "." public class Person { int age; } looks like this public..class..Person.......................... {.................. ..int age;................... ...

How to set Sqlite3 to be case insensitive when string comparing?

I want to select records from sqlite3 database by string matching. But if I use '=' in the where clause, I found that sqlite3 is case sensitive. Can anyone tell me how to use string comparing case-insensitive?...

Getting a list of all subdirectories in the current directory

Is there a way to return a list of all the subdirectories in the current directory in Python? I know you can do this with files, but I need to get the list of directories instead....

Batch file to copy files from one folder to another folder

I have a storage folder on a network in which all users will store their active data on a server. Now that server is going to be replaced by a new one due to place problem so I need to copy sub folders files from the old server storage folder to new ...

In jQuery, how do I select an element by its name attribute?

I have 3 radio buttons in my web page, like below: _x000D_ _x000D_ <label for="theme-grey">_x000D_ <input type="radio" id="theme-grey" name="theme" value="grey" />Grey</label>_x000D_ <label for="theme-pink">_x000D_ <in...

How do I pass a variable by reference?

The Python documentation seems unclear about whether parameters are passed by reference or value, and the following code produces the unchanged value 'Original' class PassByReference: def __init__(self): self.variable = 'Original' ...

SQL Error with Order By in Subquery

I'm working with SQL Server 2005. My query is: SELECT ( SELECT COUNT(1) FROM Seanslar WHERE MONTH(tarihi) = 4 GROUP BY refKlinik_id ORDER BY refKlinik_id ) as dorduncuay And the error: The ORDER BY clause is invalid in views, inline fu...

PHP Date Time Current Time Add Minutes

Simple question but this is killing my time. Any simple solution to add 30 minutes to current time in php with GMT+8?...

Max parallel http connections in a browser?

I am creating some suspended connections to an HTTP server (comet, reverse ajax, etc). It works ok, but I see the browser only allows two suspended connections to a given domain simultaneously. So if a user is looking at my website in Tab1 of their b...

Delete duplicate records from a SQL table without a primary key

I have the below table with the below records in it create table employee ( EmpId number, EmpName varchar2(10), EmpSSN varchar2(11) ); insert into employee values(1, 'Jack', '555-55-5555'); insert into employee values (2, 'Joe', '555-56-5555'); ...

What is the closest thing Windows has to fork()?

I guess the question says it all. I want to fork on Windows. What is the most similar operation and how do I use it....

Can I call an overloaded constructor from another constructor of the same class in C#?

Can I call an overloaded constructor from another constructor of the same class in C#?...

Selecting text in an element (akin to highlighting with your mouse)

I would like to have users click a link, then it selects the HTML text in another element (not an input). By "select" I mean the same way you would select text by dragging your mouse over it. This has been a bear to research because everyone talks a...

search in java ArrayList

I'm trying to figure out the best way to search a customer in an ArrayList by its Id number. The code below is not working; the compiler tells me that I am missing a return statement. Customer findCustomerByid(int id){ boolean exist=false; ...

What are the file limits in Git (number and size)?

Does anyone know what are the Git limits for number of files and size of files?...

Shell command to tar directory excluding certain files/folders

Is there a simple shell command/script that supports excluding certain files/folders from being archived? I have a directory that need to be archived with a sub directory that has a number of very large files I do not need to backup. Not quite solu...

Simple 3x3 matrix inverse code (C++)

What's the easiest way to compute a 3x3 matrix inverse? I'm just looking for a short code snippet that'll do the trick for non-singular matrices, possibly using Cramer's rule. It doesn't need to be highly optimized. I'd prefer simplicity over speed...

Python JSON encoding

I'm trying to encode data to JSON in Python and I been having a quite a bit of trouble. I believe the problem is simply a misunderstanding. I'm relatively new to Python and never really got familiar with the various Python data types, so that's mos...

Initialise a list to a specific length in Python

How do I initialise a list with 10 times a default value in Python? I'm searching for a good-looking way to initialize a empty list with a specific range. So make a list that contains 10 zeros or something to be sure that my list has a specific len...

Where can I find a list of escape characters required for my JSON ajax return type?

I have an ASP.NET MVC action that is returning a JSON object. The JSON: {status: "1", message:"", output:"<div class="c1"><div class="c2">User generated text, so can be anything</div></div>"} Currently my HTML is breaking ...

How do you strip a character out of a column in SQL Server?

How do you remove a value out of a string in SQL Server? ...

How to make a script wait for a pressed key?

I want my script to wait until the user presses any key. How do I do that?...

How to access the first property of a Javascript object?

Is there an elegant way to access the first property of an object... where you don't know the name of your properties without using a loop like for .. in or jQuery's $.each For example, I need to access foo1 object without knowing the name of foo...

Oracle 11g SQL to get unique values in one column of a multi-column query

Given a table A of people, their native language, and other columns C3 .. C10 represented by ... Table A PERSON LANGUAGE ... bob english john english vlad russian olga russian jose spanish How do I construct a query whic...

python and sys.argv

if len(sys.argv) < 2: sys.stderr.write('Usage: sys.argv[0] ') sys.exit(1) if not os.path.exists(sys.argv[1]): sys.stderr.write('ERROR: Database sys.argv[1] was not found!') sys.exit(1) This is a portion of code I'm working on. ...

Type Checking: typeof, GetType, or is?

I've seen many people use the following code: Type t = typeof(obj1); if (t == typeof(int)) // Some code here But I know you could also do this: if (obj1.GetType() == typeof(int)) // Some code here Or this: if (obj1 is int) // Some ...

C# Generics and Type Checking

I have a method that uses an IList<T> as a parameter. I need to check what the type of that T object is and do something based on it. I was trying to use the T value, but the compiler does not not allow it. My solution is the following: pri...

SQL update query using joins

I have to update a field with a value which is returned by a join of 3 tables. Example: select im.itemid ,im.sku as iSku ,gm.SKU as GSKU ,mm.ManufacturerId as ManuId ,mm.ManufacturerName ,im.mf_item_number ,mm.Manufactu...

How do I remove the first characters of a specific column in a table?

In SQL, how can I remove the first 4 characters of values of a specific column in a table? Column name is Student Code and an example value is ABCD123Stu1231. I want to remove first 4 chars from my table for all records Please guide me...