SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

How do I remove accents from characters in a PHP string?

I'm attempting to remove accents from characters in PHP string as the first step to making the string usable in a URL. I'm using the following code: $input = "Fóø Bår"; setlocale(LC_ALL, "en_US.utf8"); $output = iconv("utf-8", "ascii//TRANSLIT"...

Dynamically set value of a file input

Is there a way to set the value of a file input (<input type="file" />) or is that all blocked for security? I'm trying to use google gears' openFiles to make a simple multi-uploader. Note: The answer(s) below reflect the state of lega...

Get started with Latex on Linux

Impressed by is-latex-worth-learning-today, and many how-to's on Windows, How do you have someone started with LaTeX on Linux? How do you generate a pdf out of it and give up the OOO Word processer? Update: Thanks to all the suggestions given in...

How to get screen dimensions as pixels in Android

I created some custom elements, and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge). Therefore I need to get the screen width and screen height and then set position: int ...

Converting .NET DateTime to JSON

Possible Duplicate: How to format a JSON date? My webs service is returning a DateTime to a jQuery call. The service returns the data in this format: /Date(1245398693390)/ How can I convert this into a JavaScript-friendly date?...

What to do with "Unexpected indent" in python?

How do I rectify the error "unexpected indent" in python?...

Difference between "\n" and Environment.NewLine

What is the difference between two, if any (with respect to .Net)?...

Get most recent file in a directory on Linux

Looking for a command that will return the single most recent file in a directory. Not seeing a limit parameter to ls......

Is there a CSS parent selector?

How do I select the <li> element that is a direct parent of the anchor element? As an example, my CSS would be something like this: li < a.active { property: value; } Obviously there are ways of doing this with JavaScript, but I'm ho...

Force IE8 Into IE7 Compatiblity Mode

Is there a way to force IE8 into IE7 compatibility mode using .NET or Javascript?...

How to type a new line character in SQL Server Management Studio

In the "datagrid" view of an open table of data, how can I type a new line character into an nvarchar field directly in SSMS? Is there an alt code?...

Regex to match 2 digits, optional decimal, two digits

I've spent half an hour trying to get this, maybe someone can come up with it quickly. I need a regular expression that will match one or two digits, followed by an optional decmial point, followed by one or two digits. For example, it should match...

Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

What would be a good way to attempt to load the hosted jQuery at Google (or other Google hosted libs), but load my copy of jQuery if the Google attempt fails? I'm not saying Google is flaky. There are cases where the Google copy is blocked (apparent...

How to populate/instantiate a C# array with a single value?

I know that instantiated arrays of value types in C# are automatically populated with the default value of the type (e.g. false for bool, 0 for int, etc.). Is there a way to auto-populate an array with a seed value that's not the default? Either on ...

Can I restore a single table from a full mysql mysqldump file?

I have a mysqldump backup of my mysql database consisting of all of our tables which is about 440 megs. I want to restore the contents of just one of the tables from the mysqldump. Is this possible? Theoretically, I could just cut out the section tha...

Using Cygwin to Compile a C program; Execution error

I'm enrolled in a masters computer science course. The course is using C and the instructor wants us to use Cygwin to compile programs if we are using windows. I've downloaded and installed Cygwin and I've ensured that I've installed the GCC compil...

What is the difference between a function expression vs declaration in JavaScript?

What is the difference between the following lines of code? //Function declaration function foo() { return 5; } //Anonymous function expression var foo = function() { return 5; } //Named function expression var foo = function foo() { return 5; } ...

Entity Framework and SQL Server View

For several reasons that I don't have the liberty to talk about, we are defining a view on our Sql Server 2005 database like so: CREATE VIEW [dbo].[MeterProvingStatisticsPoint] AS SELECT CAST(0 AS BIGINT) AS 'RowNumber', CAST(0 AS BIGINT) AS...

Can I get the name of the currently running function in JavaScript?

Is it possible to do this: myfile.js: function foo() { alert(<my-function-name>); // pops-up "foo" // or even better: "myfile.js : foo" } I've got the Dojo and jQuery frameworks in my stack, so if either of those make it easier, ...

LaTeX: Prevent line break in a span of text

How can I prevent LaTeX from inserting linebreaks in my \texttt{...} or \url{...} text regions? There's no spaces inside I can replace with ~, it's just breaking on symbols. Update: I don't want to cause line overflows, I'd just rather LaTeX insert...

Getting started with Haskell

For a few days I've tried to wrap my head around the functional programming paradigm in Haskell. I've done this by reading tutorials and watching screencasts, but nothing really seems to stick. Now, in learning various imperative/OO languages (like C...

std::string to float or double

I'm trying to convert std::string to float/double. I tried: std::string num = "0.6"; double temp = (double)atof(num.c_str()); But it always returns zero. Any other ways?...

Uses of content-disposition in an HTTP response header

I have found the following asp.net code to be very useful when serving files from a database: Response.AppendHeader("content-disposition", "attachment; filename=" + fileName); This lets the user save the file to their computer and then decide how ...

Maven2 property that indicates the parent directory

I have a multi-modules project, like this one: main-project/ module1/ module2/ sub-module1/ sub-module2/ sub-module3/ ... module3/ module4/ ... I need to define a set of properties (that are depe...

Eclipse "Server Locations" section disabled and need to change to use Tomcat installation

I have set up a dynamic web project in Eclipse with a Tomcat 5.5 installation. I want to be to set the server to us the Tomcat installation instead of the workspace metadata location, but when Eclipse displays the "Overview" screen for the server th...

In Python, how do I index a list with another list?

I would like to index a list with another list like this L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] Idx = [0, 3, 7] T = L[ Idx ] and T should end up being a list containing ['a', 'd', 'h']. Is there a better way than T = [] for i in Idx: T...

Delaying a jquery script until everything else has loaded

I have a jquery script which I need to run only once everything else on the page, including some other javascripts (over which I have no control) have finished doing their thing. I though perhaps there was an alternative to $(document).ready but I h...

What is the use of style="clear:both"?

I happened to see a div which had the style clear:both! What is the use of clear in style? <div style="clear:both"> ...

Python loop that also accesses previous and next values

How can I iterate over a list of objects, accessing the previous, current, and next items? Like this C/C++ code, in Python? foo = somevalue; previous = next = 0; for (i=1; i<objects.length(); i++) { if (objects[i]==foo) { previous = ...

How do I speed up the gwt compiler?

We're starting to make heavier use of GWT in our projects, and the performance of the GWT compiler is becoming increasingly annoying. We're going to start altering our working practices to mitigate the problem, including a greater emphasis on the h...

Capture event onclose browser

How I can capture event, close browser window, in jQuery or javascript ?...

The best way to remove duplicate values from NSMutableArray in Objective-C?

The best way to remove duplicate values (NSString) from NSMutableArray in Objective-C? Is this the easiest and right way to do it? uniquearray = [[NSSet setWithArray:yourarray] allObjects]; ...

How do you automatically resize columns in a DataGridView control AND allow the user to resize the columns on that same grid?

I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF). My goal is to display a grid that neatly fills all available width with cells - i.e. no unused (dark grey) areas down the right and sizes each column appropriately according ...

System.IO.IOException: file used by another process

I've been working on this small piece of code that seems trivial but still, i cannot really see where is the problem. My functions do a pretty simple thing. Opens a file, copy its contents, replace a string inside and copy it back to the original fil...

Determine a string's encoding in C#

Is there any way to determine a string's encoding in C#? Say, I have a filename string, but I don't know if it is encoded in Unicode UTF-16 or the system-default encoding, how do I find out?...

Find an object in SQL Server (cross-database)

If I've been told a table (or proc) name, but not which connected database the object is located in, is there any simple script to search for it? Maybe search somewhere in the System Databases? (I'm using SQL Server 2005)...

Converting an integer to a string in PHP

Is there a way to convert an integer to a string in PHP?...

Reading binary file and looping over each byte

In Python, how do I read in a binary file and loop over each byte of that file?...

What is the difference between Set and List?

What is the fundamental difference between the Set<E> and List<E> interfaces?...

Creating SVG graphics using Javascript?

How can I create SVG graphics using JavaScript? Do all browsers support SVG?...

Get the current URL with JavaScript?

All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please....

Python: most idiomatic way to convert None to empty string?

What is the most idiomatic way to do the following? def xstr(s): if s is None: return '' else: return s s = xstr(a) + xstr(b) update: I'm incorporating Tryptich's suggestion to use str(s), which makes this routine work for...

Why are only a few video games written in Java?

Why aren't many commercial, 3D video games (not random open source 2D ones) written in Java? In theory, it makes a lot of sense: you get a productivity boost and a cross-platform application almost for free, among other things, such as the vast amoun...

Creating an abstract class in Objective-C

I'm originally a Java programmer who now works with Objective-C. I'd like to create an abstract class, but that doesn't appear to be possible in Objective-C. Is this possible? If not, how close to an abstract class can I get in Objective-C?...

Easiest way to make lua script wait/pause/sleep/block for a few seconds?

I cant figure out how to get lua to do any common timing tricks, such as sleep - stop all action on thread pause/wait - don't go on to the next command, but allow other code in the application to continue block - don't go on to next command until...

How to get a unix script to run every 15 seconds?

I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal. I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuri...

Why do you have to link the math library in C?

If I include <stdlib.h> or <stdio.h> in a C program I don't have to link these when compiling but I do have to link to <math.h>, using -lm with gcc, for example: gcc test.c -o test -lm What is the reason for this? Why do I have t...

is it possible to update UIButton title/text programmatically?

I have a UIButton, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I'd like to update the title/text of the UIButton to reflect the new state. I'm calling: [myButton setTitle: @"myTitle"...

What does DIM stand for in Visual Basic and BASIC?

What does DIM stand for in Visual Basic? ...

How to execute a function when page has fully loaded?

I need to execute some JavaScript code when the page has fully loaded. This includes things like images. I know you can check if the DOM is ready, but I don’t know if this is the same as when the page is fully loaded....

How to write a:hover in inline CSS?

I have a case where I must write inline CSS code, and I want to apply a hover style on an anchor. How can I use a:hover in inline CSS inside the HTML style attribute? E.g. you can't reliably use CSS classes in HTML emails....

Like Operator in Entity Framework?

We're trying to implement the "LIKE" operator in Entity Framework for our entities with string fields, but it doesn't appear to be supported. Has anyone else tried to do something like this? This blog post summarizes the issue we're having. We cou...

How to make a div fill a remaining horizontal space?

I have 2 divs: one in the left side and one in the right side of my page. The one in the left side has fixed width and I want the one of the right side to fill the remaining space. _x000D_ _x000D_ #search {_x000D_ width: 160px;_x000D_ height: 25...

insert datetime value in sql database with c#

How do I insert a datetime value into a SQL database table where the type of the column is datetime?...

How to write LDAP query to test if user is member of a group?

I want to write an LDAP query which tests whether a user (sAMAccountName) is a member of a particular group. Is it possible to do that so that I get either 0 or 1 result records? I guess I can get all groups for the user and test each one for a matc...

What is the use of the @ symbol in PHP?

I have seen uses of @ in front of certain functions, like the following: $fileHandle = @fopen($fileName, $writeAttributes); What is the use of this symbol?...

sed whole word search and replace

How do I search and replace whole words using sed? Doing sed -i 's/[oldtext]/[newtext]/g' <file> will also replace partial matches of [oldtext] which I don't want it to do....

Oracle DB: How can I write query ignoring case?

As I had written in title, I have SQL query, run on Oracle DB, lets say: SELECT * FROM TABLE WHERE TABLE.NAME Like 'IgNoReCaSe' If I would like, that the query would return either "IGNORECASE", "ignorecase" or combinations of them, how can this be...

Simulate string split function in Excel formula

I am trying to split a string in an excel formula, something like I can do in many programming languages, e.g. string words = "some text".split(' '); The problem is that I can't be sure that there is more than one word in the cell. If I try to us...

What is polymorphism, what is it for, and how is it used?

What is polymorphism, what is it for, and how is it used?...

What are projection and selection?

What is the difference between projection and selection? Is it: Projection --> for selecting the columns of table; and Selection ---> to select the rows of table? So are projection and selection vertical and horizontal slicing respectively?...

How do I insert a drop-down menu for a simple Windows Forms app in Visual Studio 2008?

There appears to be every other kind of drop-down menu--those that allow user input, those for integers only, those that don't...drop down, and even those that have ugly check boxes next to them. I just want a simple drop-down menu (like you'd see if...

How do I get TimeSpan in minutes given two Dates?

To get TimeSpan in minutes from given two Dates I am doing the following int totalMinutes = 0; TimeSpan outresult = end.Subtract(start); totalMinutes = totalMinutes + ((end.Subtract(start).Days) * 24 * 60) + ((end.Subtract(start).Hours) * 60) +(end....

How can I copy network files using Robocopy?

How can I copy network files using Robocopy?...

Easy way to pull latest of all git submodules

We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to ju...

HTML table headers always visible at top of window when viewing a large table

I would like to be able to "tweak" an HTML table's presentation to add a single feature: when scrolling down through the page so that the table is on the screen but the header rows are off-screen, I would like the headers to remain visible at the top...

Get MIME type from filename extension

How can I get the MIME type from a file extension?...

SQL Bulk Insert with FIRSTROW parameter skips the following line

I can't seem to figure out how this is happening. Here's an example of the file that I'm attempting to bulk insert into SQL server 2005: ***A NICE HEADER HERE*** 0000001234|SSNV|00013893-03JUN09 0000005678|ABCD|00013893-03JUN09 0000009112|0000|000...

Seeking useful Eclipse Java code templates

You can create various Java code templates in Eclipse via Window > Preferences > Java > Editor > Templates e.g. sysout is expanded to: System.out.println(${word_selection}${});${cursor} You can activate this by typing sysout followed by CTRL+SP...

Get first key in a (possibly) associative array?

What's the best way to determine the first key in a possibly associative array? My first thought it to just foreach the array and then immediately breaking it, like this: foreach ($an_array as $key => $val) break; Thus having $key contain the f...

How do you rename a Git tag?

Today I was looking through the logs for a project and realized that I fat fingered a tag name some time ago. Is there some way to rename the tag? Google hasn't turned up anything useful. I realize I could check out the tagged version and make a new...

Best font for coding

Possible Duplicate: Recommended Fonts for Programming? What font do you use when writing code? Specifically, this font should be: Freely available Easily installable on multiple platforms (Linux, Mac, Win, etc.) Easily installable on mult...

What is (functional) reactive programming?

I've read the Wikipedia article on reactive programming. I've also read the small article on functional reactive programming. The descriptions are quite abstract. What does functional reactive programming (FRP) mean in practice? What does reactive...

How to combine class and ID in CSS selector?

If I have the following div: <div class="sectionA" id="content"> Lorem Ipsum... </div> Is there a way to define a style that expresses the idea "A div with id='content' AND class='myClass'"? Or do you have simply go one way or the...

How to execute a file within the python interpreter?

I'm trying to execute a file with python commands from within the interpreter. EDIT: I'm trying to use variables and settings from that file, not to invoke a separate process....

I need an unordered list without any bullets

I have created an unordered list. I feel the bullets in the unordered list are bothersome, so I want to remove them. Is it possible to have a list without bullets?...

How can I test if a letter in a string is uppercase or lowercase using JavaScript?

How can I test if a letter in a string is uppercase or lowercase using JavaScript?...

How to redirect to Login page when Session is expired in Java web application?

I'm running a web application in JBoss AS 5. I also have a servlet filter which intercepts all the requests to the server. Now, I want to redirect the users to the login page, if the session has expired. I need to do this 'isSessionExpired()' check i...

How to get only time from date-time C#

Suppose I have the value 6/22/2009 10:00:00 AM. How do I get only 10:00 Am from this date time....

How to convert a byte array to its numeric value (Java)?

I have an 8 byte array and I want to convert it to its corresponding numeric value. e.g. byte[] by = new byte[8]; // the byte array is stored in 'by' // CONVERSION OPERATION // return the numeric value I want a method that will perform the abov...

How to convert a Map to List in Java?

What is the best way to convert a Map<key,value> to a List<value>? Just iterate over all values and insert them in a list or am I overlooking something?...

Is there a way to crack the password on an Excel VBA Project?

I've been asked to update some Excel 2003 macros, but the VBA projects are password protected, and it seems there's a lack of documentation... no-one knows the passwords. Is there a way of removing or cracking the password on a VBA project?...

How do I make the first letter of a string uppercase in JavaScript?

How do I make the first letter of a string uppercase, but not change the case of any of the other letters? For example: "this is a test" -> "This is a test" "the Eiffel Tower" -> "The Eiffel Tower" "/index.html" -> "/index.html" ...

Why do I get access denied to data folder when using adb?

I connected to my live device using the adb and the following commands: C:\>adb -s HT829GZ52000 shell $ ls ls sqlite_stmt_journals cache sdcard etc system sys sbin proc logo.rle init.trout.rc init.rc init.goldfish.rc init default.prop data root d...

What is the difference between SQL, PL-SQL and T-SQL?

What is the difference between SQL, PL-SQL and T-SQL? Can anyone explain what the differences between these three are, and provide scenarios where each would be relevantly used?...

How to list active / open connections in Oracle?

Is there any hidden table, system variable or something to show active connections in a given moment?...

Does List<T> guarantee insertion order?

Say I have 3 strings in a List (e.g. "1","2","3"). Then I want to reorder them to place "2" in position 1 (e.g. "2","1","3"). I am using this code (setting indexToMoveTo to 1): lis...

What does void mean in C, C++, and C#?

Looking to get the fundamentals on where the term "void" comes from, and why it is called void. The intention of the question is to assist someone who has no C experience, and is suddenly looking at a C-based codebase. ...

Is it possible to create a 'link to a folder' in a SharePoint document library?

Is it possible to create a shortcut to a folder in a different document library in a document library?...

How to create a DataTable in C# and how to add rows?

How do create a DataTable in C#? I did like this: DataTable dt = new DataTable(); dt.clear(); dt.Columns.Add("Name"); dt.Columns.Add("Marks"); How do I see the structure of DataTable? Now I want to add ravi for Name and 500 for Marks. How ca...

How can I create an MSI setup?

I've created setups for all my Delphi tools with Inno Setup for years. Now some users rather want an MSI installation package, so they can deploy the setups from a central server to all workstations. How do I create one? Do I have to buy Visual Stud...

Finding smallest value in an array most efficiently

There are N values in the array, and one of them is the smallest value. How can I find the smallest value most efficiently?...

How do you use global variables or constant values in Ruby?

I have a program that looks like: $offset = Point.new(100, 200); def draw(point) pointNew = $offset + point; drawAbsolute(point) end draw(Point.new(3, 4)); the use of $offset seems a bit weird. In C, if I define something outside of any fun...

How to reset a timer in C#?

There are three Timer classes that I am aware of, System.Threading.Timer, System.Timers.Timer, and System.Windows.Forms.Timer, but none of these have a .Reset() function which would reset the current elapsed time to 0. Is there a BCL class that has ...

Removing the textarea border in HTML

I'm working with the textarea element in HTML and want to remove the border of the box. I also want to align the text in the bottom of my textarea....

How do you concatenate Lists in C#?

If I have: List<string> myList1; List<string> myList2; myList1 = getMeAList(); // Checked myList1, it contains 4 strings myList2 = getMeAnotherList(); // Checked myList2, it contains 6 strings myList1.Concat(myList2); // Checked mylis...

How to check if function exists in JavaScript?

My code is function getID( swfID ){ if(navigator.appName.indexOf("Microsoft") != -1){ me = window[swfID]; }else{ me = document[swfID]; } } function js_to_as( str ){ me.onChange(str); } However, sometimes my...

How do I convert Int/Decimal to float in C#?

How does one convert from an int or a decimal to a float in C#? I need to use a float for a third-party control, but I don't use them in my code, and I'm not sure how to end up with a float....

What is the effect of extern "C" in C++?

What exactly does putting extern "C" into C++ code do? For example: extern "C" { void foo(); } ...

What's the most efficient way to erase duplicates and sort a vector?

I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sort it. I currently have the below code, but it doesn't work. vec.erase( std::unique(vec.begin(), vec.end()), vec.end()); std::sort(vec.begin(), vec....