SyntaxFix.com - Programming Questions & Answers Hub For Beginners

Some Of The Best Answers From Latest Asked Questions

New line in Sql Query

How you get new line or line feed in Sql Query ?...

How to check if a given directory exists in Ruby

I am trying to write a script which automatically checks out or updates a Subversion URL based on whether a specified directory exists or not. For some reason, my code isn't working and always returns true even if it's false: def directory_exists?(...

Commit only part of a file in Git

When I make changes to a file in Git, how can I commit only some of the changes? For example, how could I commit only 15 lines out of 30 lines that have been changed in a file?...

Regular expressions in C: examples?

I'm after some simple examples and best practices of how to use regular expressions in ANSI C. man regex.h does not provide that much help....

input type=file show only button

Is there a way to style (or script) <input type=file /> element to have visible only "Browse" button without text field? Thanks Edit: Just to clarify why to I need this. I'm using multi file upload code from http://www.morningz.com/?p=5 and i...

A cycle was detected in the build path of project xxx - Build Path Problem

I'm in the process of converting my projects to OSGI bundles using maven and eclipse. Maven builds the stuff just fine, only I get the above error now within Eclipse. How can I find out which project causes this? Is there a special view or something?...

How to get difference between two dates in Year/Month/Week/Day?

How to get difference between two dates in Year/Month/Week/Day in an efficient way? eg. difference between two dates is 1 Year, 2 Months, 3 Weeks, 4 Days. Difference represents count of year(s), month(s), week(s) and day(s) between two dates....

How to check for an active Internet connection on iOS or macOS?

I would like to check to see if I have an Internet connection on iOS using the Cocoa Touch libraries or on macOS using the Cocoa libraries. I came up with a way to do this using an NSURL. The way I did it seems a bit unreliable (because even Google ...

How to block calls in android

I want to block calls from few numbers, for that I want to write a app of my own. So what are the APIs which I should be using? Basically I want to get notified when a call comes, i want to compare numbers if it is what i want to block, i want to cu...

Downloading video from YouTube

I wish to download a video from YouTube and then extract its audio. Can anyone point me to some C# code to download a video? For clarification purposes, I already know how to extract audio from a .FLV file like these. ...

Why Would I Ever Need to Use C# Nested Classes

I'm trying to understand about nested classes in C#. I understand that a nested class is a class that is defined within another class, what I don't get is why I would ever need to do this....

Mod of negative number is melting my brain

I'm trying to mod an integer to get an array position so that it will loop round. Doing i % arrayLength works fine for positive numbers but for negative numbers it all goes wrong. 4 % 3 == 1 3 % 3 == 0 2 % 3 == 2 1 % 3 == 1 0 % 3 == 0 -1 % 3 =...

How to build jars from IntelliJ properly?

I have a project that contains a single module, and some dependencies. I'd like to create a jar, in a separate directory, that contains the compiled module. In addition, I'd like to have the dependencies present beside my module. No matter how I twi...

How to TryParse for Enum value?

I want to write a function which can validate a given value (passed as a string) against possible values of an enum. In the case of a match, it should return the enum instance; otherwise, it should return a default value. The function may not intern...

How do I make text bold in HTML?

I'm trying to make some text bold using HTML, but I'm struggling to get it to work. Here's what I'm trying: Some <bold>text</bold> that I want emboldened. Could someone tell me what I'm doing wrong?...

Objective-C - Remove last character from string

In Objective-C for iOS, how would I remove the last character of a string using a button action?...

How do I remove a MySQL database?

You may notice from my last question that a problem caused some more problems, Reading MySQL manuals in MySQL monitor? My database is now unusable partly due to my interest to break things and my inability to look at error messages. I know that I sh...

How to remove entity with ManyToMany relationship in JPA (and corresponding join table rows)?

Let's say I have two entities: Group and User. Every user can be member of many groups and every group can have many users. @Entity public class User { @ManyToMany Set<Group> groups; //... } @Entity public class Group { @ManyT...

Linking to an external URL in Javadoc?

Something like: /** * See {@linktourl http://google.com} */ ...

Escaping double quotes in JavaScript onClick event handler

The simple code block below can be served up in a static HTML page but results in a JavaScript error. How should you escape the embedded double quote in the onClick handler (i.e. "xyz)? Note that the HTML is generated dynamically by pulling da...

Setting background color for a JFrame

Just how do you set the background color for a JFrame?...

Java Date - Insert into database

I need to figure out a way to insert a record with a java.util.Date field into a database and i'm stuck. Does anyone know how i can do this? Right now i have something like. java.util.Date myDate = new java.util.Date("01/01/2009"); ...

How can I lookup a Java enum from its String value?

I would like to lookup an enum from its string value (or possibly any other value). I've tried the following code but it doesn't allow static in initialisers. Is there a simple way? public enum Verbosity { BRIEF, NORMAL, FULL; private stat...

Android Endless List

How can I create a list where when you reach the end of the list I am notified so I can load more items? ...

How can I draw vertical text with CSS cross-browser?

I want to rotate a single word of text by 90 degrees, with cross-browser (>= IE6, >= Firefox 2, any version of Chrome, Safari, or Opera) support. How can this be done?...

How to convert an Stream into a byte[] in C#?

Is there a simple way or method to convert an Stream into a byte[] in C#?...

retrieve links from web page using python and BeautifulSoup

How can I retrieve the links of a webpage and copy the url address of the links using Python?...

GZIPInputStream reading line by line

I have a file in .gz format. The java class for reading this file is GZIPInputStream. However, this class doesn't extend the BufferedReader class of java. As a result, I am not able to read the file line by line. I need something like this reader ...

Mysql: Select all data between two dates

I have a mysql table with data connected to dates. Each row has data and a date, like this: 2009-06-25 75 2009-07-01 100 2009-07-02 120 I have a mysql query that select all data between two dates. This is the query: SELECT data FROM tbl ...

When do I need to use a semicolon vs a slash in Oracle SQL?

We have been having some debate this week at my company as to how we should write our SQL scripts. Background: Our database is Oracle 10g (upgrading to 11 soon). Our DBA team uses SQLPlus in order to deploy our scripts to production. Now, we had...

How can I configure my makefile for debug and release builds?

I have the following makefile for my project, and I'd like to configure it for release and debug builds. In my code, I have lots of #ifdef DEBUG macros in place, so it's simply a matter of setting this macro and adding the -g3 -gdwarf2 flags to the c...

good example of Javadoc

is there a good example of a source file containing Javadoc? I can find lots of good examples of Javadoc on the internet, I would just like to find out the particular syntax used to create them, and assume I can pore through the source of some libr...

How to test enum types?

I'm currently trying to build a more or less complete set of unit tests for a small library. Since we want to allow different implementations to exist we want this set of tests to be (a) generic, so that we can re-use it to test the different impleme...

How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?

I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear The Portal ear file resides in, say /home/foo/bar/ jar xf /home/foo/bar/Portal.e...

Facebook Post Link Image

When someone posts a link on facebook, a script usually scans that link for any images, and displays a quick thumbnail next to the post. For certain URLs though (including mine), FB doesn't seem to pick up anything, despite their being a number of im...

When to use RDLC over RDL reports?

I have been studying SSRS 2005 / 2008 in the past weeks and have created some server side reports. For some application, a colleague suggested that I look into RDLC for that particular situation. I am now trying to get my head around the main differe...

What's the difference between IFrame and Frame?

Looking at options for embedding the 3D Secure page inside my own order form, I came across the following: "Some commerce sites will devote the full browser page to the authentication rather than using a frame (not necessarily an iFrame, which is a ...

Where does the @Transactional annotation belong?

Should you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classes which are calling using the DAO objects? Or does it make sense to annotate both "layers"?...

jQuery send HTML data through POST

I am using jQuery to make a POST to a PHP file with the HTML content of a div. The HTML content contain tables, inputs, smaller divs and I would like to grab the content of the main DIV and send it to the database. The only option I could think of is...

Passing parameter via url to sql server reporting service

I'm trying to pass a parameter via the url to SSRS and it appears not to work! I'm trying to pass a userId (string) via the url which will be passed to the database and used by the query. base url: http://blah/Reports/Pages/Report.aspx?ItemPath=MyR...

How to specify the download location with wget?

I need files to be downloaded to /tmp/cron_test/. My wget code is wget --random-wait -r -p -nd -e robots=off -A".pdf" -U mozilla http://math.stanford.edu/undergrad/ So is there some parameter to specify the directory?...

How to take complete backup of mysql database using mysqldump command line utility

How can I make a complete backup of mysql database using mysqldump? When I am making a backup, my tables from specified database are only getting backed up. The procedures and functions are not. Here's the backup command I am using : (Operating syst...

Re-doing a reverted merge in Git

I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had done it too fast, so I used git-revert to undo the merge. Now, however, the time has come to merge 28s i...

How do I iterate over a JSON structure?

I have the following JSON structure: [{ "id":"10", "class": "child-of-9" }, { "id": "11", "classd": "child-of-10" }] How do I iterate over it using JavaScript?...

Delete/Reset all entries in Core Data?

Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank. Edit I'm looking to do this programmatically so that a user can essentially hit a reset button....

How to detect the currently pressed key?

In Windows Forms, you can know, at any time, the current position of the cursor thanks to the Cursors class. The same thing doesn't seem to be available for the keyboard. Is it possible to know if, for example, the Shift key is pressed? Is it absol...

Multiline string literal in C#

Is there an easy way to create a multiline string literal in C#? Here's what I have now: string query = "SELECT foo, bar" + " FROM table" + " WHERE id = 42"; I know PHP has <<<BLOCK BLOCK; Does C# have something similar?...

JavaScriptSerializer.Deserialize - how to change field names

Summary: How do I map a field name in JSON data to a field name of a .Net object when using JavaScriptSerializer.Deserialize ? Longer version: I have the following JSON data coming to me from a server API (Not coded in .Net) {"user_id":1234, "detai...

How do you get an iPhone's device name

If you open Settings -> General -> About, it'll say Bob's iPhone at the top of the screen. How do you programmatically grab that name?...

Member '<method>' cannot be accessed with an instance reference

I am getting into C# and I am having this issue: namespace MyDataLayer { namespace Section1 { public class MyClass { public class MyItem { public static string Property1{ get; set; } ...

Why can't Python find shared objects that are in directories in sys.path?

I'm trying to import pycurl: $ python -c "import pycurl" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: libcurl.so.4: cannot open shared object file: No such file or directory Now, libcurl.so.4 is ...

jQuery $.ajax(), $.post sending "OPTIONS" as REQUEST_METHOD in Firefox

Having trouble with what I thought was a relatively simple jQuery plugin... The plugin should fetch data from a php script via ajax to add options to a <select>. The ajax request is pretty generic: $.ajax({ url: o.url, type: 'post', co...

When is it appropriate to use UDP instead of TCP?

Since TCP guarantees packet delivery and thus can be considered "reliable", whereas UDP doesn't guarantee anything and packets can be lost. What would be the advantage of transmitting data using UDP in an application rather than over a TCP stream? In...

What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java?

What's the difference between getPath(), getAbsolutePath(), and getCanonicalPath() in Java? And when do I use each one?...

Spring - @Transactional - What happens in background?

I want to know what actually happens when you annotate a method with @Transactional? Of course, I know that Spring will wrap that method in a Transaction. But, I have the following doubts: I heard that Spring creates a proxy class? Can someone exp...

Objective-C: Extract filename from path string

When I have NSString with /Users/user/Projects/thefile.ext I want to extract thefile with Objective-C methods. What is the easiest way to do that?...

What is the largest Safe UDP Packet Size on the Internet

I've read a number of articles about UDP packet sizes but have been unable to come to a conclusion on whats correct. A number of services restrict the largest UDP packet to 512 bytes (like dns) Given the minimum MTU on the internet is 576 , and the...

Run bash script from Windows PowerShell

In cygwin, I could just do ./script.sh args, but this opens the script file in notepad in PowerShell. What do I need to do have it execute?...

IndexError: list index out of range and python

I'm telling my program to print out line 53 of an output. Is this error telling me that there aren't that many lines and therefore can not print it out?...

Proper way to use **kwargs in Python

What is the proper way to use **kwargs in Python when it comes to default values? kwargs returns a dictionary, but what is the best way to set default values, or is there one? Should I just access it as a dictionary? Use get function? class Exa...

JVM heap parameters

After reading already asked question on the subject and a lot of googling I am still not able to have a clear view of -Xms option My question is: what's the difference between java -Xms=512m -Xmx=512m and java -Xms=64m -Xmx=512m? For now I have the...

How to make child divs always fit inside parent div?

My question is if there is a way, without using JavaScript, to cause child divs to extend to the borders of their parent, without exceeding those borders, when you cannot know beforehand the size of the parent div? Below is sample markup/styles demo...

Can one do a for each loop in java in reverse order?

I need to run through a List in reverse order using Java. So where this does it forwards: for(String string: stringList){ //...do something } Is there some way to iterate the stringList in reverse order using the for each syntax? For clarity: I...

Checking if a key exists in a JavaScript object?

How do I check if a particular key exists in a JavaScript object or array? If a key doesn't exist, and I try to access it, will it return false? Or throw an error?...

Rethrowing exceptions in Java without losing the stack trace

In C#, I can use the throw; statement to rethrow an exception while preserving the stack trace: try { ... } catch (Exception e) { if (e is FooException) throw; } Is there something like this in Java (that doesn't lose the original stack...

Select elements by attribute

I have a collection of checkboxes with generated ids and some of them have an extra attribute. Is it possible to use JQuery to check if an element has a specific attribute? For example, can I verify if the following element has the attribute "myattr"...

Java Swing revalidate() vs repaint()

I'm putting together a Swing application where I often want to replace the contents of a JPanel. To do this, I'm calling removeAll(), then adding my new content, then calling revalidate(). However I'm finding that the old content is still actually v...

Removing whitespace between HTML elements when using line breaks

I have a page with a row of about 10 imgs. For readability of the HTML, I want to put a linebreak in between each img tag, but doing so renders whitespace between the images, which I do not want. Is there anything I can do other than break in the mid...

Iterating a JavaScript object's properties using jQuery

Is there a jQuery way to perform iteration over an object's members, such as in: for (var member in obj) { ... } I just don't like this for sticking out from amongst my lovely jQuery notation!...

Print directly from browser without print popup window

As it said in the subject I've to create a feature for a web-based application that will allow users to send print directly without prompting any dialog boxe just make the print i.e click and print, simple! but not for me :(. Please, suggest what w...

Calculate difference between 2 date / times in Oracle SQL

I have a table as follows: Filename - varchar Creation Date - Date format dd/mm/yyyy hh24:mi:ss Oldest cdr date - Date format dd/mm/yyyy hh24:mi:ss How can I calcuate the difference in hours minutes and seconds (and possibly days) between the two ...

Can Mysql Split a column?

I have a column that has comma separated data: 1,2,3 3,2,1 4,5,6 5,5,5 I'm trying to run a search that would query each value of the CSV string individually. 0<first<5 and 1<second<3 and 2<third<4 I get that I could retu...

Why doesn't JUnit provide assertNotEquals methods?

Does anybody know why JUnit 4 provides assertEquals(foo,bar) but not assertNotEqual(foo,bar) methods? It provides assertNotSame (corresponding to assertSame) and assertFalse (corresponding to assertTrue), so it seems strange that they didn't bother...

Read String line by line

Given a string that isn't too long, what is the best way to read it line by line? I know you can do: BufferedReader reader = new BufferedReader(new StringReader(<string>)); reader.readLine(); Another way would be to take the substring on th...

How can I use interface as a C# generic type constraint?

Is there a way to get the following function declaration? public bool Foo<T>() where T : interface; ie. where T is an interface type (similar to where T : class, and struct). Currently I've settled for: public bool Foo<T>() where T :...

C# string reference type?

I know that "string" in C# is a reference type. This is on MSDN. However, this code doesn't work as it should then: class Test { public static void Main() { string test = "before passing"; Console.WriteLine(test); T...

document.getElementById(id).focus() is not working for firefox or chrome

When ever I do onchange event, its going inside that function its validating, But focus is not comming I am using document.getElementById('controlid').focus(); I am using Mozilla Firefox and Google Chrome, in both its not working. I don't want any I...

how to check the jdk version used to compile a .class file

Possible Duplicate: Tool to read and display Java .class versions I'm trying to debug a "Bad version number in .class file' error in java, is there a way for me to check which version the .class files are? I'm using JRE1.5.0_6, bu...

How do I turn off Oracle password expiration?

I'm using Oracle for development. The password for a bootstrap account that I always use to rebuild my database has expired. How do I turn off password expiration for this user (and all other users) permanently? I'm using Oracle 11g, which has pas...

Are SSL certificates bound to the servers ip address?

We have two different ldap providers in two different physical office locations. When I connect my laptop to one location and I 'retrieve from port' (in Websphere 6.1) to import the ssl cert of the ldap provider, I can authenticate to the respective...

GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'

I'm setting up a C++ project, on Ubuntu x64, using Eclipse-CDT. I'm basically doing a hello world and linking to a commerical 3rd party library. I've included the header files, linked to their libraries, but I still get linker errors. Are there so...

Select a dummy column with a dummy value in SQL?

I have a table with the following Table1 col1 col2 ------------ 1 A 2 B 3 C 0 D Result col1 col2 col3 ------------------ 0 D ABC I am not sure how to go about writing the query , col1 and col2 can be sel...

Convert objective-c typedef to its string equivalent

Assuming that I have a typedef declared in my .h file as such: typedef enum { JSON, XML, Atom, RSS } FormatType; I would like to build a function that converts the numeric value of the typedef to a string. For example, if the message [sel...

LINQ to SQL - How to select specific columns and return strongly typed list

I'm trying to use LINQ to SQL to select a few specific columns from a table and return the result as a strongly typed list of objects. For Example: var result = (from a in DataContext.Persons where a.Age > 18 ...

Is there a difference between x++ and ++x in java?

Is there a difference between ++x and x++ in java?...

Get human readable version of file size?

A function to return human readable size from bytes size: >>> human_readable(2048) '2 kilobytes' >>> How to do this?...

Network tools that simulate slow network connection

I would like to visually evaluate web pages response time for several Internet connections types (DSL, Cable, T1, dial-up etc.) while my browser and web server are on the same LAN or even on the same machine. Are there any simple network tools or bro...

Convert a string to integer with decimal in Python

I have a string in the format: 'nn.nnnnn' in Python, and I'd like to convert it to an integer. Direct conversion fails: >>> s = '23.45678' >>> i = int(s) Traceback (most recent call last): File "<stdin>", line 1, in <mo...

Get Current date in epoch from Unix shell script

How to get the current date value in epoch i.e., number of days elapsed since 1970-1-1. I need solution in unix shell script....

What's the purpose of git-mv?

From what I understand, Git doesn't really need to track file rename/move/copy operations, so what's the real purpose of git mv? The man page isn't specially descriptive... Is it obsolete? Is it an internal command, not meant to be used by regular us...

Enable SQL Server Broker taking too long

I have a Microsoft SQL server 2005 and I tried to enable Broker for my database with those T-SQL: SELECT name, is_broker_enabled FROM sys.databases -- checking its status 0 in my case ALTER DATABASE myDatabase SET ENABLE_BROKER The Alter Datab...

Make the image go behind the text and keep it in center using CSS

I am creating a web page, where I have an image that I want to place in the center. On the top of that image I want to have input boxes, labels, and a submit button. I am trying to use this CSS img.center { z-index:-1; } but this does not wor...

Add a user control to a wpf window

I have a user control that I've created, however when I go to add it to the XAML in the window, Intellisense doesn't pick it up, and I can't figure out how to add it to the window....

How do I check what version of Python is running my script?

How can I check what version of the Python Interpreter is interpreting my script?...

aspx page to redirect to a new page

What is the code required to redirect the browser to a new page with an ASPX page? I have tried this on my page default.aspx : <% Response.Redirect("new.aspx", true); %> or <%@ Response.Redirect("new.aspx", true); %> And these resu...

Get current time in seconds since the Epoch on Linux, Bash

I need something simple like date, but in seconds since 1970 instead of the current date, hours, minutes, and seconds. date doesn't seem to offer that option. Is there an easy way?...

Event system in Python

What event system for Python do you use? I'm already aware of pydispatcher, but I was wondering what else can be found, or is commonly used? I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones so...

AssertContains on strings in jUnit

Is there a nicer way to write in jUnit String x = "foo bar"; Assert.assertTrue(x.contains("foo")); ...

OVER clause in Oracle

What is the meaning of the OVER clause in Oracle?...

What characters do I need to escape in XML documents?

What characters must be escaped in XML documents, or where could I find such a list?...