SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

How to run a script file remotely using SSH

I want to run a script remotely. But the system doesn't recognize the path. It complains that "no such file or directory". Am I using it right? ssh [email protected] `./test/foo.sh` ...

How can I select an element with multiple classes in jQuery?

I want to select all the elements that have the two classes a and b. <element class="a b"> So, only the elements that have both classes. When I use $(".a, .b") it gives me the union, but I want the intersection....

How to put a div in center of browser using CSS?

How to put a div in center of browser both vertically and horizontally using CSS only? Make sure it works on IE7 too. If everything fails, we may use JavaScript, but a last choice....

removing html element styles via javascript

I'm trying to replace an element's inline style tag value. The current element looks like this: `<tr class="row-even" style="background: red none repeat scroll 0% 0%; position: relative; -moz-background-clip: -moz-initial; -moz-background-ori...

Difference between session affinity and sticky session?

What is the difference between session affinity and sticky session in context of load balancing servers? ...

Remove all files in a directory

Trying to remove all of the files in a certain directory gives me the follwing error: OSError: [Errno 2] No such file or directory: '/home/me/test/*' The code I'm running is: import os test = "/home/me/test/*" os.remove(test) ...

How to bind inverse boolean properties in WPF?

What I have is an object that has an IsReadOnly property. If this property is true, I would like to set the IsEnabled property on a Button, ( for example ), to false. I would like to believe that I can do it as easily as IsEnabled="{Binding Path=!Is...

What are FTL files

I am new to a project and have to learn it inside out. I see a lot of files with the extension .ftl in them. I'm not sure what they are. I know they can be modified and the user sees changes in the front end....

How can I check if a Perl module is installed on my system from the command line?

I tried to check if XML::Simple is installed in my system or not. perl -e 'while (<@INC>) { while (<$_/*.pm>) { print "$_\n"; } }' The above one-liner was used for listing all modules installed in my system. However, it is not listing ...

How do I remove a substring from the end of a string in Python?

I have the following code: url = 'abcdc.com' print(url.strip('.com')) I expected: abcdc I got: abcd Now I do url.rsplit('.com', 1) Is there a better way?...

Equivalent of String.format in jQuery

I'm trying to move some JavaScript code from MicrosoftAjax to JQuery. I use the JavaScript equivalents in MicrosoftAjax of the popular .net methods, e.g. String.format(), String.startsWith(), etc. Are there equivalents to them in jQuery?...

How to get browser width using JavaScript code?

I am trying to write a JavaScript function to get the current browser width. I found this one: javascript:alert(document.body.offsetWidth); But its problem that it fail if the body has width 100%. Is there any other better function or a workarou...

How can I convert an Integer to localized month name in Java?

I get an integer and I need to convert to a month names in various locales: Example for locale en-us: 1 -> January 2 -> February Example for locale es-mx: 1 -> Enero 2 -> Febrero...

What does the Excel range.Rows property really do?

OK, I am finishing up an add-on project for a legacy Excel-VBA application, and I have once again run up against the conundrum of the mysterious range.Rows (?) and worksheet.Rows properties. Does anyone know what these properties really do and wha...

SQL conditional SELECT

I would like to create a stored procedure with parameters that indicate which fields should be selected. E.g. I would like to pass two parameters "selectField1" and "selectField2" each as bools. Then I want something like SELECT if (selectField1 ...

how to set default method argument values?

Is it possible to set the default method parameter values in Java? Example: If there is a method public int doSomething(int arg1, int arg2) { //some logic here return 0; } is it possible to modify the given method in order to be able to call ...

Data structure for maintaining tabular data in memory?

My scenario is as follows: I have a table of data (handful of fields, less than a hundred rows) that I use extensively in my program. I also need this data to be persistent, so I save it as a CSV and load it on start-up. I choose not to use a databas...

How to find current transaction level?

How do you find current database's transaction level on SQL Server?...

Good Patterns For VBA Error Handling

What are some good patterns for error handling in VBA? In particular, what should I do in this situation: ... some code ... ... some code where an error might occur ... ... some code ... ... some other code where a different error might occur ... ....

How to force link from iframe to be opened in the parent window

I need to open the link in the same parent page, instead of open it in a new page. note : The iframe and parent page are the same domain....

Nesting optgroups in a dropdownlist/select

I have created a customer c# DropDownList control that can render out it's contents are optgroups (Not from scratch, I edited some code found on the internet, although I do understand exactly what it's doing), and it works fine. However, I have now ...

Sorting a tab delimited file

I have a data with the following format: foo<tab>1.00<space>1.33<space>2.00<tab>3 Now I tried to sort the file based on the last field decreasingly. I tried the following commands but it wasn't sorted as we expected. $ sor...

How to clear browser cache with php?

How to clear browser cache with php?...

sql use statement with variable

I'm trying to switch the current database with a SQL statement. I have tried the following, but all attempts failed: USE @DatabaseName EXEC sp_sqlexec @Sql -- where @Sql = 'USE [' + @DatabaseName + ']' To add a little more detail. EDIT: I would ...

How to set column header text for specific column in Datagridview C#

How to set column header text for specific column in Datagridview C#...

Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

I developed a Windows service using C#.NET to generate PDF report. To generate PDF file I am using a third party dll. The application is running in my Windows XP platform. When I deployed the service in Windows Server 2008 64 bit version, I got this ...

Automatically start a Windows Service on install

I have a Windows Service which I install using the InstallUtil.exe. Even though I have set the Startup Method to Automatic, the service does not start when installed, I have to manually open the services and click start. Is there a way to start it ei...

Is it possible to use jQuery to read meta tags

Is it possible to use jQuery to read meta tags. If so do you know what the basic structure of the code will be, or have links to any tutorials....

How do I use boolean variables in Perl?

I have tried: $var = false; $var = FALSE; $var = False; None of these work. I get the error message Bareword "false" not allowed while "strict subs" is in use....

What does $1 mean in Perl?

What does $1 mean in Perl? Further, what does $2 mean? How many $number variables are there?...

Real world use of JMS/message queues?

I was just reading abit about JMS and Apache ActiveMQ. And was wondering what real world use have people here used JMS or similar message queue technologies for ?...

How to call a .NET Webservice from Android using KSOAP2?

I have a problem while calling a webservice. I have a .NET web service on the server, and I am using KSOAP2 (ksoap2-j2se-full-2.1.2) in Android. While running the program I got an runtime exception like "org.ksoap2.serialization.SoapPrimitive". What ...

Group by & count function in sqlalchemy

I want a "group by and count" command in sqlalchemy. How can I do this?...

What's the difference between '$(this)' and 'this'?

I am currently working through this tutorial: Getting Started with jQuery For the two examples below: $("#orderedlist").find("li").each(function (i) { $(this).append(" BAM! " + i); }); $("#reset").click(function () { $("form").each(function...

Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project

When creating a new Java project in IntelliJ IDEA, the following directories and files are created: ./projectname.iml ./projectname.ipr ./projectname.iws ./src/ I want to configure IntelliJ IDEA to include my dependency JARs in ./lib/*.jar to the ...

Get the last day of the month in SQL

I need to get the last day of the month given as a date in SQL. If I have the first day of the month, I can do something like this: DATEADD(DAY, DATEADD(MONTH,'2009-05-01',1), -1) But does anyone know how to generalize it so I can find the last da...

Check if Python Package is installed

What's a good way to check if a package is installed while within a Python script? I know it's easy from the interpreter, but I need to do it within a script. I guess I could check if there's a directory on the system that's created during the inst...

WPF ListView turn off selection

I have a simple WPF ListView and a simple question: Is it possible to turn off the selection, so when user clicks row, the row is not highlighted? I would like the row 1 to look just like row 0 when clicked. Possibly related: can I style the loo...

What is a Data Transfer Object (DTO)?

What is a Data Transfer Object? In MVC are the model classes DTO, and if not what are the differences and do we need both?...

Convert JSON array to an HTML table in jQuery

Is there a really easy way I can take an array of JSON objects and turn it into an HTML table, excluding a few fields? Or am I going to have to do this manually?...

How to send PUT, DELETE HTTP request in HttpURLConnection?

I want to know if it is possible to send PUT, DELETE request (practically) through java.net.HttpURLConnection to HTTP-based URL. I have read so many articles describing that how to send GET, POST, TRACE, OPTIONS requests but I still haven't found an...

Singleton with Arguments in Java

I was reading the Singleton article on Wikipedia and I came across this example: public class Singleton { // Private constructor prevents instantiation from other classes private Singleton() {} /** * SingletonHolder is loaded on th...

Adding hours to JavaScript Date object?

It amazes me that JavaScript's Date object does not implement an add function of any kind. I simply want a function that can do this: var now = Date.now(); var fourHoursLater = now.addHours(4); function Date.prototype.addHours(h) { // how do I...

VIM Disable Automatic Newline At End Of File

So I work in a PHP shop, and we all use different editors, and we all have to work on windows. I use vim, and everyone in the shop keeps complaining that whenever I edit a file there is a newline at the bottom. I've searched around and found that th...

VBScript: Using WScript.Shell to Execute a Command Line Program That Accesses Active Directory

I'm attempting to execute a .NET (3.5) command line program from within a VBScript file which does two main things: Connects to an Active Directory that is on the same domain as the server the script is hosted to retrieve an attribute value. I sea...

How can I get log4j to delete old rotating log files?

How can I get log4j to delete old rotating log files? I know I can set up automated jobs (cron for UNIX and scheduled task for Windows), but I want it cross platform, and I want it in our application's log configuration as a part of our application,...

What is the difference between concurrency and parallelism?

What is the difference between concurrency and parallelism? Examples are appreciated....

How to read a CSV file into a .NET Datatable

How can I load a CSV file into a System.Data.DataTable, creating the datatable based on the CSV file? Does the regular ADO.net functionality allow this?...

How do I see what character set a MySQL database / table / column is?

What is the (default) charset for: MySQL database MySQL table MySQL column ...

What is “2's Complement”?

I'm in a computer systems course and have been struggling, in part, with Two's Complement. I want to understand it but everything I've read hasn't brought the picture together for me. I've read the wikipedia article and various other articles, includ...

Create a SQL query to retrieve most recent records

I am creating a status board module for my project team. The status board allows the user to to set their status as in or out and they can also provide a note. I was planning on storing all the information in a single table ... and example of the dat...

CharSequence VS String in Java?

Programming in Android, most of the text values are expected in CharSequence. Why is that? What is the benefit, and what are the main impacts of using CharSequence over String? What are the main differences, and what issues are expected, while usin...

Adding an identity to an existing column

I need to change the primary key of a table to an identity column, and there's already a number of rows in table. I've got a script to clean up the IDs to ensure they're sequential starting at 1, works fine on my test database. What's the SQL com...

Concatenating Column Values into a Comma-Separated List

What is the TSQL syntax to format my output so that the column values appear as a string, seperated by commas. Example, my table CARS has the following: CarID CarName ---------------- 1 Porsche 2 Mercedes 3 Ferrari ...

Best way to get value from Collection by index

What is the best way to get value from java.util.Collection by index?...

What is lexical scope?

What is a brief introduction to lexical scoping?...

What's the difference between Cache-Control: max-age=0 and no-cache?

The header Cache-Control: max-age=0 implies that the content is considered stale (and must be re-fetched) immediately, which is in effect the same thing as Cache-Control: no-cache....

How can I disable inherited css styles?

So I am creating a container with rounded corners using the following method: div.rounded { background: #CFFEB6 url('tr.gif') no-repeat top right; } div.rounded div { background: url('br.gif') no-repeat bottom right; } div.rounded div div { ...

String.contains in Java

String s1 = "The quick brown fox jumps over the lazy dog"; String s2 = ""; boolean b = s1.contains(s2); System.out.println(b); I run the Java code above, the b return true. Since s2 is empty, why does s1 contains s2? I check the Java API, it write...

How can I validate a string to only allow alphanumeric characters in it?

How can I validate a string using Regular Expressions to only allow alphanumeric characters in it? (I don't want to allow for any spaces either)....

What type of hash does WordPress use?

What type of hash does WordPress use? Here is an example of a WordPress hash: $P$Bp.ZDNMM98mGNxCtHSkc1DqdRPXeoR. ...

How to import load a .sql or .csv file into SQLite?

I need to dump a .sql or .csv file into SQLite (I'm using SQLite3 API). I've only found documentation for importing/loading tables, not entire databases. Right now, when I type: sqlite3prompt> .import FILENAME TABLE I get a syntax error, since...

Using a cursor with dynamic SQL in a stored procedure

I have a dynamic SQL statement I've created in a stored procedure. I need to iterate over the results using a cursor. I'm having a hard time figuring out the right syntax. Here's what I'm doing. SELECT @SQLStatement = 'SELECT userId FROM users' DEC...

How to call a JavaScript function from PHP?

How to call a JavaScript function from PHP? <?php jsfunction(); // or echo(jsfunction()); // or // Anything else? The following code is from xyz.html (on a button click) it calls a wait() in an external xyz.js. This wait() calls wait...

How can I list all of the files in a directory with Perl?

Is there a function in Perl that lists all the files and directories in a directory? I remember that Java has the File.list() to do this? Is there a comparable method in Perl?...

How do I share variables between different .c files?

beginner question about C declaration: In a .c file, how to use variables defined in another .c file?...

How do I generate random number for each row in a TSQL Select?

I need a different random number for each row in my table. The following seemingly obvious code uses the same random value for each row. SELECT table_name, RAND() magic_number FROM information_schema.tables I'd like to get an INT or a FLOAT out...

What's the difference between "2*2" and "2**2" in Python?

What is the difference between the following codes? code1: var=2**2*3 code2: var2=2*2*3 I see no difference. This raises the following question. Why is the code1 used if we can use code2?...

C# Reflection: How to get class reference from string?

I want to do this in C#, but I don't know how: I have a string with a class name -e.g: FooClass and I want to invoke a (static) method on this class: FooClass.MyMethod(); Obviously, I need to find a reference to the class via reflection, but how...

Objective-C: Reading a file line by line

What is the appropriate way of dealing with large text files in Objective-C? Let's say I need to read each line separately and want to treat each line as an NSString. What is the most efficient way of doing this? One solution is using the NSString m...

How do you get the length of a string?

How do you get the length of a string in jQuery?...

WCFTestClient The HTTP request is unauthorized with client authentication scheme 'Anonymous'

I've created one WCF service and deployed it on Server. When I browse this service it gives me positive response with ?wsdl URL. Now I'm trying to test the service through WCF Test client. It shows proper metadata. But when I try to invoke any of the...

Clearing <input type='file' /> using jQuery

Is it possible to clear an <input type='file' /> control value with jQuery? I've tried the following: $('#control').attr({ value: '' }); But it's not working....

Speed tradeoff of Java's -Xms and -Xmx options

Given these two commands A: $ java -Xms10G -Xmx10G myjavacode input.txt B: $ java -Xms5G -Xmx5G myjavacode input.txt I have two questions: Since command A reserves more memory with its parameters, will A run faster than B? How do -Xmx and -...

C# generic list <T> how to get the type of T?

I'm working on a reflection project, and now I'm stuck. If I have an object of myclass that can hold a List<SomeClass>, does anyone know how to get the type as in the code below if the property myclass.SomList is empty? List<myclass> my...

Counting Line Numbers in Eclipse

I have a Java project in Eclipse with ~10 packages and ~10 class files per package. Is there a way to determine total lines of code for the whole project from within Eclipse? I am familiar with other tools (e.g., Code Analyzer, wc, etc.) but I want...

How to auto-remove trailing whitespace in Eclipse?

The question has two parts, one of which I already have the answer for. How to auto-remove trailing whitespace from the entire file being edited? -> Answer: use the AnyEdit plugin, which can be set to do that on any save to the file. How to auto-re...

JavaScript for detecting browser language preference

I have been trying to detect the browser language preference using JavaScript. If I set the browser language in IE in Tools>Internet Options>General>Languages, how do I read this value using JavaScript? Same problem for Firefox. I'm not ab...

How do browser cookie domains work?

Due to weird domain/subdomain cookie issues that I'm getting, I'd like to know how browsers handle cookies. If they do it in different ways, it would also be nice to know the differences. In other words - when a browser receives a cookie, that cooki...

Map implementation with duplicate keys

I want to have a map with duplicate keys. I know there are many map implementations (Eclipse shows me about 50), so I bet there must be one that allows this. I know it's easy to write your own map that does this, but I would rather use some existing...

Build project into a JAR automatically in Eclipse

I have an Eclipse project where I want to keep my Java project built into a JAR automatically. I know I have an option to export the project into a JAR; if I do a right click; but what I am really looking for is, that like Eclipse automatically build...

How to disable horizontal scrolling of UIScrollView?

I have a UIView like iPhone's Springboard. I have created it using a UIScrollView and UIButtons. I want to disable horizontal scrolling on said scrollview. I want only vertical scrolling. How do I accomplish this?...

Difference between objectForKey and valueForKey?

What is the difference between objectForKey and valueForKey? I looked both up in the documentation and they seemed the same to me....

Updating a java map entry

I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map, and I want to update the value in a Key-Value pair. Right now, I'm doing it lik this: private Map<String,int> table = new HashMap<String,int>(...

Fastest way to write huge data in text file Java

I have to write huge data in text[csv] file. I used BufferedWriter to write the data and it took around 40 secs to write 174 mb of data. Is this the fastest speed java can offer? bufferedWriter = new BufferedWriter ( new FileWriter ( "fileName.csv" ...

Why do table names in SQL Server start with "dbo"?

At least on my local instance, when I create tables, they are all prefixed with "dbo.". Why is that?...

How to configure socket connect timeout

When the Client tries to connect to a disconnected IP address, there is a long timeout over 15 seconds... How can we reduce this timeout? What is the method to configure it? The code I'm using to set up a socket connection is as following: try { ...

How to select between brackets (or quotes or ...) in Vim?

I'm sure there used to be a plugin for this kinda stuff, but now that I need it, I can't seem to find it (naturally), so I'll just ask nice and simple. What is the easiest way to select between brackets, or quotes, or generally a list of matching ch...

What exactly is Spring Framework for?

I hear a lot about Spring, people are saying all over the web that Spring is a good framework for web development. What exactly is Spring Framework for?...

What's the easiest way to escape HTML in Python?

cgi.escape seems like one possible choice. Does it work well? Is there something that is considered better?...

How to normalize a vector in MATLAB efficiently? Any related built-in function?

I normalize a vector V in MATLAB as following: normalized_V = V/norm(V); however, is it the most elegant (efficient) way to normalize a vector in MATLAB?...

Eliminate space before \begin{itemize}

In Latex, how do I eliminate the space inserted before itemize? \begin{itemize} % produces lots of vertical space \item ... \item ... \end{itemize} ...

Calling Objective-C method from C++ member function?

I have a class (EAGLView) which calls a member function of a C++ class without problems. Now, the problem is that I need to call in that C++ class a objective-C function [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.lay...

Iterating through a range of dates in Python

I have the following code to do this, but how can I do it better? Right now I think it's better than nested loops, but it starts to get Perl-one-linerish when you have a generator in a list comprehension. day_count = (end_date - start_date).days + ...

Changing variable names with Python for loops

I was just wondering if anyone knew of a way to change variable names based off of a for loop for something like this: for i in range(3) group+i=self.getGroup(selected, header+i) so that the names of the variables change to accomodate the dat...

Is there a way to detect if a browser window is not currently active?

I have JavaScript that is doing activity periodically. When the user is not looking at the site (i.e., the window or tab does not have focus), it'd be nice to not run. Is there a way to do this using JavaScript? My reference point: Gmail Chat plays...

Default value to a parameter while passing by reference in C++

Is it possible to give a default value to a parameter of a function while we are passing the parameter by reference. in C++ For example, when I try to declare a function like: virtual const ULONG Write(ULONG &State = 0, bool sequence = true); ...

Split Strings into words with multiple word boundary delimiters

I think what I want to do is a fairly common task but I've found no reference on the web. I have text with punctuation, and I want a list of the words. "Hey, you - what are you doing here!?" should be ['hey', 'you', 'what', 'are', 'you', 'doing'...

Get IPv4 addresses from Dns.GetHostEntry()

I've got some code here that works great on IPv4 machines, but on our build server (an IPv6) it fails. In a nutshell: IPHostEntry ipHostEntry = Dns.GetHostEntry(string.Empty); The documentation for GetHostEntry says that passing in string.Empty w...

How to remove "Server name" items from history of SQL Server Management Studio

When trying to connect to a server in Management Studio (specifically 2008), there is a field where you enter the Server name. That field also has a drop-down list where it shows a history of servers that you have attempted to connect to. I would li...