Unnamed: 0
int64 65
6.03M
| Id
int64 66
6.03M
| Title
stringlengths 10
191
| input
stringlengths 23
4.18k
| output
stringclasses 10
values | Tag_Number
stringclasses 10
values |
---|---|---|---|---|---|
2,340,632 | 2,340,633 | Methods on File Object is undeclared | <p>When I wrote this method it gave me an error that the method exists() and canRead() is undeclared in the File Object:
// TODO: Remove or fix this.</p>
<pre><code>public static Pixa readFiles(File dir, String prefix) {
if (dir == null)
throw new IllegalArgumentException("Directory must be non-null");
if (!dir.exists())
throw new IllegalArgumentException("Directory does not exist");
if (!dir.canRead())
throw new IllegalArgumentException("Cannot read directory");
throw new RuntimeException("readFiles() is not current supported");
}
</code></pre>
<p>can anyone fix this error ? </p>
| android | [4] |
537,295 | 537,296 | Why do I get this error: Cannot open include file: 'FL/Fl.h'? | <p>I've tried to compile a program on VSEXPRESS 2008 EDITION coupled with fltk-1.1.9 but I coutinuosly get the following error:
fatal error C1083: Cannot open include file: 'FL/Fl.h': No such file or directory</p>
<p>Can anyone one help me out?
Thanks a lot</p>
| c++ | [6] |
3,958,884 | 3,958,885 | Why c++? Where to start? | <p>I know there was many questions like this one, but please hold on one more. All programming languages I know now are made for web purposes. I've been learning ActionScript, php and a bit of Javascript, AJAX, etc.. I've liked php very much but I'm still looking something I'll really love! That's why I want to try something new. Can You tell me what are positives and negatives of this language? Is there some big example of C++ usage? Is it a good language to start this journey (maybe You can recommend something else)? Are there some good video tutorials which I can buy on CD/DVD? Could You recommend some books?</p>
<p>@edit:
After reading Your answers and some info on the internet I'm confused about two languages. Those are C++ and Python. Python can be used for web so it combine great with my current knowledge. But how about Python for desktop applications? Is it hard to build cross-platform apps? Could You compare for me this two languages?</p>
<p>PS.
I'm really glad about all of Your answers. It is very helpful for me & it forces me to productive thinking about my future ;)</p>
| c++ | [6] |
3,667,846 | 3,667,847 | How to determine if a square is inside a rectangle? | <p>Higuys,</p>
<p>In Java, I wonder how can I determine if a square is inside a rectangle, or touching at the edges or touching at one corner, if these are given:</p>
<ul>
<li>x and y coordinates of the square, width of the square</li>
<li>x and y coordinates of the rectangle, width & length of the rectangle</li>
</ul>
<p>I know I have to use Math.abs() and find the x and y coordinate differences, but I could not formulate the problem mathematically.</p>
<p>All data types are doubles, by the way.</p>
<p>Even if you don't know Java, your ideas about mathematical formulation of this problem would be much appreciated.</p>
<p>Thanks in advance.</p>
| java | [1] |
3,176,307 | 3,176,308 | std::ostream printing address at end of function | <p>I have the following function:</p>
<pre><code>std::vector<double>residuals;
std::cout << Print_res(std::cout);
std::ostream& Print_res(std::ostream& os) const {
os << "\tresidual" << std::endl;
for (unsigned int i = 0 ; i < 22 ; i++) {
os << "\t\t" << residuals[i] << std::endl;
}
os << std::flush;
return os;
};
</code></pre>
<p>It prints the residuals correctly, but at the end of the output tags an address as follows:</p>
<pre><code>2275
2279.08
2224.0835
0x80c5604
</code></pre>
<p>how do I fix this?
EDIT: after reading everyone's comments I replaced the call to the function <code>Print_res</code> with a <code>std::copy</code> as</p>
<pre><code> std::copy(residuals.begin(), residuals.end(), std::ostream_iterator<double>(std::cout,"\n"));
</code></pre>
<p>and that did not print the address, so I presume there is something wrong in the way I have written the function.</p>
| c++ | [6] |
3,650,797 | 3,650,798 | UIAlertview with advertiesment and message? | <p>Can we add advertisement in UIAlertview with some message?
I know custom alert is possible but don't know how to add advertise in that.</p>
| iphone | [8] |
1,761,044 | 1,761,045 | Does turning on/off GPS broadcast the android.location.PROVIDERS_CHANGED message? | <p>On Froyo:</p>
<p>When turning on and off the GPS, is the android.location.PROVIDERS_CHANGED message supposed to be broadcast? I have an application that turns the GPS on and off, and a listener is set for this message (to verify that the action occurred), and the listener is never called even though the GPS is being enable and disabled. Because I have to use a hack to programatically control the GPS, I'm wondering if I should be broadcasting this message myself.</p>
<p>Launcher Pro is seeing that I'm toggling the state of the GPS, and it changes it's widget icons appropriately, so I'm not sure if I need to send the message. In which case the message is being sent and I'm not listening for the message properly (but if I send it myself the receiver does respond). Or I'm not listening for the correct message.</p>
<p>On a related note, in which source code modules should I look to see when the PROVIDERS_CHANGED message is being broadcast?</p>
| android | [4] |
1,143,014 | 1,143,015 | catch editing-Mode left and change label from UITableViewCell | <p>i have a little problem. when i enter the edit mode of my uitableview the a manuel added label should disappear. i realized this by setting the alpha of this label-field to 0 in following method:</p>
<pre><code>- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([self isEditing] && [indexPath row] == [tripArray count]) {
return UITableViewCellEditingStyleInsert;
}
[[[[self tableView] cellForRowAtIndexPath:indexPath] detailTextLabel] setAlpha:0];
return UITableViewCellEditingStyleDelete;
}
</code></pre>
<p>But in which delegate-methode of my tableview i can set the alpha back to 1, when the edit mode was finished???
hopefully someone has an idea? i didn't find the right one......</p>
| iphone | [8] |
2,953,104 | 2,953,105 | IF- ELSE condition - run the code in the ELSE section | <p>I have got the following IF condition code:</p>
<pre><code>if ((depth <= min_depth ) && (leaf_colour == "red")){
for (i = 0; i < array_2D.length; i++) {
var leaf_size = array_2D[i][1];
if (leaf_size == 10 || leaf_size == 11){
alert("Error message.");
break; // we found an error, displayed error message and now leave the loop
}
else{ go to the next else section }
}
}//end of if condition
else{
...
...
...
...
...
}
</code></pre>
<p>Inside the 'FOR' loop, if (leaf_size == 10 || leaf_size == 11), we break the loop and do nothing but if this is not the case, i would like to run the code in the next ELSE section.</p>
<p>I do not want to copy the whole block of code and paste it inside the 'else' section of the for loop as it's quite long.</p>
<p>Is there a way of running the code in the second else section?</p>
| javascript | [3] |
2,551,383 | 2,551,384 | why we need interface instead of class and what we are achieving from interface | <p>As we know that we can declare only the method signature and also can not create the instance of a Interface. then why we need interface. Unnecessary its loading into JVM. This is also one performance degradation. We are creating the interface and several classes implementing that interface and defining all the methods of the interface. Actually what we achieved from this interface. Could you please give me some example.</p>
| java | [1] |
1,388,880 | 1,388,881 | Unfortunately android app has stopped | <p>I am doing a simple program for addition of two numbers which are input from EditText.
But when user clicks the button 'Click to Add' leaving the fields empty, program exits saying 'Unfortunately, program has stopped.'</p>
<p>Here is the code:</p>
<pre><code>public class MainActivity extends Activity {
long a, b, sum;
Button add, clr;
EditText e1, e2, res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add = (Button) findViewById(R.id.bAdd);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) throws NumberFormatException {
// TODO Auto-generated method stub
e1 = (EditText) findViewById(R.id.tv1);
String str1 = e1.getText().toString();
e2 = (EditText) findViewById(R.id.tv2);
String str2 = e2.getText().toString();
try{
a = Integer.parseInt(str1);
b = Integer.parseInt(str2);
}catch(NumberFormatException e){
res.setText("Please enter valid entries");
}
sum = a + b;
res = (EditText) findViewById(R.id.result);
res.setText("Your sum is " + sum);
}
});
clr = (Button) findViewById(R.id.bClr);
clr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) throws NumberFormatException {
// TODO Auto-generated method stub
e1.setText("");
e2.setText("");
res.setText("");
}
});
}
}
</code></pre>
<p>I want the app to respond 'Please enter valid entries' for blank EditText entries.</p>
| android | [4] |
2,043,615 | 2,043,616 | Validating e-mail address | <p>I am trying to validate an e-mail address using javascript. The problem is the if statements aren't executing correctly. If I delete the 'else statement' the code runs correnctly and the page does not load with errors. If I include the 'else statement' the else statement never executes and the status bar says that the page loads with errors. I was wondering if anyone can find any errors that I am unable to pick up?</p>
<pre><code><h4>Example 4:</h4>
<div style="border:3px dashed #aaa; width:200px;">
<div id="text">e-mail: <input id="email" onblur="verifyEmail()"/></div>
<div id="verification" > </div>
</div>
<script type="text/javascript">
function verifyEmail(){
var email = document.getElementById("email").value;
var atPos=0;
var dotPos=0;
atPos = email.indexOf("@");
dotPos = email.lastIndexOf(".");
if(atPos<=3 || dotPos<atPos+2 || dotPos+2>=email.length){
document.getElementById("verification").innerHTML = "Invalid E-mail Address";
}else{
document.getElementById("verification").innerHTML = "Valid";
}
}
</script>
</code></pre>
| javascript | [3] |
1,163,216 | 1,163,217 | Can a class method be both inline and static? | <p>Does it even make sense?</p>
| c++ | [6] |
3,545,911 | 3,545,912 | Convert Double to String without precision loss in javascript | <p>I would like to convert a floating point variable to a string without losing any precision.</p>
<p>I.e. I would like the string to have the same information as my floating point variable contains, since I use the output for further processing (even if it means that the string will be very long and readable).</p>
<p>To put this more clearly, I would like to have functions for cyclic conversion</p>
<pre><code>var dA = 323423.23423423e4;
var sA = toString(dA);
var dnA = toDouble(sA);
</code></pre>
<p>and I would like dnA and dA to be equal</p>
<p>Thanks</p>
<p>PS: Sources on the internet usually talk about how to round strings but I have not found information on exact representation. Also I am not interested in Arbitrary Precision calculations, I just need double precision floating point arithmetic.</p>
| javascript | [3] |
2,943,620 | 2,943,621 | Programmatically disable specific PHP functions for testing | <p>I have a function that makes HTTP requests with cURL that falls back to <code>file_get_contents()</code> if cURL is not available on the system.</p>
<p>I would like to write unit tests for this function (utilizing PHPUnit) where cURL is available for some tests, and not available for others.</p>
<p><strong>Is it possible to programmatically disable PHP functions, such as <code>curl_init()</code>?</strong></p>
<p>I know I can use the <code>disable_functions</code> setting in php.ini, but I was hoping to find a way to do unit tests without reconfiguring PHP in between runs.</p>
| php | [2] |
2,813,694 | 2,813,695 | How to copy dictionaries with matching values for a given key from list to new list? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/5762643/copy-dictionaries-with-matching-values-for-a-given-key">Copy dictionaries with matching values for a given key</a> </p>
</blockquote>
<p>With an interface like <code>a = copyf(dictlist, key, valuelist)</code>.</p>
<pre><code>>>> dictlist = [{'first': 'James',
'last': 'Joule'},
{'first': 'James',
'last': 'Watt'},
{'first': 'Christian',
'last': 'Doppler'}]
>>> valuelist = ['James', 'John']
>>> x = copyf(dictlist, 'first', valuelist)
>>> print(x)
[{'first': 'James',
'last': 'Joule'},
{'first': 'James',
'last': 'Watt'}]
</code></pre>
<p>The <code>dictlist</code> is effectively a <code>csv.DictReader</code> instance.</p>
| python | [7] |
5,081,986 | 5,081,987 | Keycode hooks in android | <p>I use my android tablet with a wireless bluetooth keyboard. This keyboard has a few built in "hot keys" to launch specific programs. For example fn+f10 launches gmail. I am wanting to add some custom hotkeys. Does anyone have an idea of how the android os catches these keycodes from a bluetooth device? I know that this is probably something done on a system level, but I can't figure out were or how they are doing it. My device is rooted, so I should be able to make any necessary changes on the system level. Any thoughts on how I could accomplish this? </p>
| android | [4] |
1,633,707 | 1,633,708 | How can I encrypt a file (video/audio/image), save to SDCard, then decrypt that same file and play it via VideoView? | <p>I am trying to create an app that would download a file from a remote server and save it to the SD card. The file is quite confidential so I need an encryption for this. I would like it to be saved as encrypted. When I want to play the file, it should only be played on my media player which has the decrypt code. No other player can play that file. How is this possible? Thanks for any suggestions you may have. </p>
| android | [4] |
3,663,345 | 3,663,346 | Why doesn't my object inherent the keys functions? | <p>If I have an object:</p>
<pre><code>A = {a:true}
</code></pre>
<p>Why do I have to use:</p>
<pre><code>Object.keys(A)
</code></pre>
<p>and not:</p>
<pre><code>A.keys()
</code></pre>
<p>If keys is a method of Object, and everything inherits from Object, shouldn't A be able to call keys?</p>
| javascript | [3] |
4,427,990 | 4,427,991 | Pygame using TKinter to make a popup menu? | <p>I need to have a pygame window check if the user right clicked (I can do) and then make a popup menu to display options using TKinter (?). Is this possible?</p>
| python | [7] |
2,918,533 | 2,918,534 | How to update the pre-installed application programmatically in android | <p>I am working on an app where app installs .apk file which is available on my local server.
and if there is any update notification for the installed local server application,its need to update the application. I am using GCM to send notification to the android device for update and get the <strong>versionCode</strong> from notification and compare it with the installed .apk version. Upto this things are right. But I stuck with how to update the per-installed local server application so that its setting doesn’t changes.</p>
<p>THANKS.</p>
| android | [4] |
977,345 | 977,346 | will Python ever have LINQ like thing | <blockquote>
<p><strong>Possible Duplicate:</strong><br />
<a href="http://stackoverflow.com/questions/1085337/linq-in-python">LINQ in Python</a> </p>
</blockquote>
<p>Hi</p>
<p>Will python ever have Microsoft LINQ ported to it .
I find LINQ to be very cool</p>
| python | [7] |
5,583,625 | 5,583,626 | get index of item in listbox c# | <p>I am trying to get index of each items in a listbox
Here is my code</p>
<pre><code> foreach (ListItem lstItem in lstCostCenter.Items)
{
int x = lstCostCenter.Items.IndexOf(lstItem);
}
</code></pre>
<p>But each time its returning 0 only.</p>
<p>Please some one help me.</p>
<p>Thanks
Gulrej</p>
| c# | [0] |
646,420 | 646,421 | Getting the client's timezone in JavaScript | <p>How can I gather the visitor's time zone information? I need the GMT offset hours.</p>
| javascript | [3] |
3,967,268 | 3,967,269 | Select A Specific Class In An Each Statement | <p>I the following code returns every text that has the "price" class associated to it. I just want to return the price of the specific item the each statement is on..</p>
<pre><code><div class="item">
<p class="price">$388.00</p>
<p class="part_number">VM2327T23A00T</p>
<p class="real_price"></p>
</div>
<div class="item">
<p class="price">$88.00</p>
<p class="part_number">AA327T23A00T</p>
<p class="real_price"></p>
</div>
<div class="item">
<p class="price">$38.00</p>
<p class="part_number">AA327T23A00T</p>
<p class="real_price"></p>
</div>
<script>
jQuery('.part_number').each(function () {
parts.push(jQuery(this).text());
var aPrice= jQuery('.price').text();
});
</script>
</code></pre>
| jquery | [5] |
672,385 | 672,386 | How do I return false if the typeof a function is equal to undefined? | <p>In JavaScript, is there a way to display a message or to return false if the type of an object or function is undefined? It seems as though if an object or function is not present, there's no way to display an error message on screen, but rather the error appears in the Web Console.</p>
| javascript | [3] |
4,219,127 | 4,219,128 | QuickFlip JQuery Plugin | <p>I'm using quicklfip (<a href="http://jonraasch.com/blog/quickflip-2-jquery-plugin" rel="nofollow">http://jonraasch.com/blog/quickflip-2-jquery-plugin</a>) for Chinese character flashcards. The front panel will have the character and the back panel will have the definition. The problem I am having is that I want to show example sentences but only when the back panel is visible. There doesn't seem to be any callback function. Any JQuery experts have any ideas on how I could do this?</p>
| jquery | [5] |
98,050 | 98,051 | I just uploaded my first app to the Android Market, and I'm getting a 404 when I try to download it | <p>Here's the link to download my app from the play store:</p>
<p><a href="https://play.google.com/store/apps/details?id=com.dgolder.BCDining" rel="nofollow">https://play.google.com/store/apps/details?id=com.dgolder.BCDining</a></p>
<p>I'm getting a 404 when I try to install it and I'm not sure what could be causing it. I'll put my manifest in here too and I can provide any other info.</p>
<p>Any insight would be greatly appreciated!</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dgolder.BCDining"
android:versionCode="3"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/logo"
android:label="@string/app_name" >
<activity
android:name="me.activity.DiningExpList"
android:theme="@android:style/Theme.NoTitleBar"
>
</activity>
<activity
android:name="me.activity.DiningActivity"
android:theme="@android:style/Theme.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
</code></pre>
| android | [4] |
389,130 | 389,131 | jquery checked checkbox on refresh and unique value query | <p>I'm trying to run a piece of code only when a <code>checkbox</code> is checked on refresh with the correct value? </p>
<pre><code>if ($("input[name='business_group']").attr("checked")==true && .val("accommodation")) {
$(".acc_title").show();
$(".fd_title").hide();
$(".dest_title").hide();
$(".ttt_title").hide();
$(".c_name_container").show();
$(".stay").show();
$(".visit").hide();
alert("accommodation checked");
}
else if ($("input[name='business_group']").attr("checked")==true && .val("food_drink")) {
$(".fd_title").show();
$(".acc_title").hide();
$(".dest_title").hide();
$(".ttt_title").hide();
$(".c_name_container").show();
$(".stay").hide();
$(".visit").show();
alert("food_drink checked");
}
</code></pre>
<p>Any idea why the above code doesn't work? </p>
| jquery | [5] |
3,860,736 | 3,860,737 | how to check a string is not null | <pre><code> if(string.equals(""))
{
}
</code></pre>
<p>how to check the string is not null </p>
<pre><code> if(!string.equals(""))
{
}
</code></pre>
<p>???</p>
| java | [1] |
2,254,107 | 2,254,108 | WeakValueDictionary for holding any type | <p>Is there any way to work around the limitations of WeakValueDictionary to allow it to hold weak references to built-in types like dict or list? Can something be done at the C level in an extension module? I really need a weakref container that can hold (nearly) any type of object.</p>
| python | [7] |
217,789 | 217,790 | Difference between Javascript function declarations | <p>What is the difference between the following two examples?</p>
<pre><code>setInterval(myFunc, 100);
function myFunc() { alert('asdf'); }
</code></pre>
<hr>
<pre><code>setInterval(myFunc, 100);
var myFunc = function myFunc() { alert('asdf'); }
</code></pre>
| javascript | [3] |
1,456,346 | 1,456,347 | Can't get recursive function to work in Java | <p>I read docs about java recorsion and I thought I have understood it, but when I try to use it in the following example, it does not work as expected.</p>
<p>I a class <code>account</code>, which has <code>amount</code> and can have forther subAccount. I would have implemented one method <code>getSum</code>, which has to return the summ of the amount of the account and amount of all of its subaccount. In the following code, the call of the method <code>getSumm()</code> should return 550, but it behaves strange. can somebody help please?</p>
<pre><code>public class Balance{
ArrayList<Balance> subAccounts = new ArrayList<Balance>();
String accountID = null;
Double amount = null;
double result=0;
public double getSum(ArrayList<Balance> subAccounts){
if(subAccounts !=null && subAccounts.size()>0){
for (int i = 0; i < subAccounts.size(); i++) {
result = result + getSum(subAccounts.get(i).subAccounts);
}
}
else {
return amount;
}
return result;
}
public static void main(String[] args) {
Balance bs1 = new Balance();
Balance bs2 = new Balance();
Balance bs3 = new Balance();
bs1.amount=100.0;
bs2.amount=150.0;
bs3.amount=300.0;
ArrayList<Balance> subAccounts1 = new ArrayList<Balance>();
bs2.subAccounts=null;
bs3.subAccounts=null;
subAccounts1.add(bs2);
subAccounts1.add(bs3);
bs1.subAccounts=subAccounts1;
double sum= bs1.getSum(subAccounts1);
System.out.println(sum);
}
}
</code></pre>
| java | [1] |
3,763,199 | 3,763,200 | how to avoid deep sleep mode in android phone programmatically? | <p>I have develop one android application which will talk to server 24*7 over WiFi but when phone goes to sleep mode it stops talking to server means socket is getting closed so for resolving this I added code to acquire partial wake lock in service onCreate() and release it on OnDestroy() method o service so even though phone goes to sleep mode my application can talk to the server.</p>
<p>Problem is: If you keep the device idle for longer period (more than 8 hours ), it stops communicating with the server and WiFi turned off. I heard about deep sleep mode of device, in this case it will shutdown CPU,WiFi etc.. so how to restrict it for getting CPU and Wifi turned off?</p>
<p>Please help me with some sample example.</p>
<p>Regards,
Piks</p>
| android | [4] |
750,075 | 750,076 | Where should we use finish() to end the application? | <p>In my application after the user goes from one activity to another and vice versa. Im calling the activities using Intents on the event "onClick".</p>
<pre><code>public void onClick(DialogInterface dialog, int whichButton) {
Intent intent = new Intent();
intent.setClass(Field.this,Boll.class);
startActivity(intent);
finish();
}
</code></pre>
<p>After using the application when the back button is pressed then application must end and should go back to the Home screen. </p>
<p>However what happening in my app is, when the Back button is clicked the activities are still in the stack and are traced back one by one(i.e to their previous state), and finally returns back to the Home Screen.</p>
<p>I have learned that Android takes care of quitting the application, <a href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238">from here</a></p>
<p>Please let me know where should i add the <code>finish()</code> in order to finsh all activities in the stack and go back to Home Screen(i.e to end the application).</p>
| android | [4] |
3,760,162 | 3,760,163 | ideal resolution value for android application | <p>What is the ideal resolution value that can i choose for my android application.</p>
| android | [4] |
196,093 | 196,094 | Preserving scroll position of PreferenceActivity across invocations | <p>Let's say I have a <code>PreferenceActivity</code> (which I cannot convert to use Fragments for compatibility reasons). One setting within that <code>PreferenceActivity</code> is for the current application theme, which I would like to apply instantly when changing the preference by calling <code>PreferenceActivity#recreate()</code> to force recreating the activity (using the new theme).</p>
<p>Unfortunately, the activity contains so many settings that scrolling may be required. Upon recreating the activity, I would like to restore the previous scroll position to allow for a seamless transition from one theme to another.</p>
<p>Attemting to preserve the embedded <code>ListView</code>'s scroll position using <code>getListView().getScrollY()</code> in <code>onSaveInstanceState</code>, however, always returns zero.</p>
<p>Is there any way to get hold of the <code>PreferenceActivity</code>'s list scroll position and to restore it later on?</p>
| android | [4] |
5,923,553 | 5,923,554 | Template Class Static Data Instantiation? | <p>Any one can tell me what on earth is going on in this code?</p>
<pre><code>#include <iostream>
class BBB {
public:
BBB() { std::cout << std::endl << "BBB()" << std::endl; }
~BBB() { std::cout << std::endl << "~BBB()" << std::endl; }
};
template<class T>
class AAA {
public:
AAA(){}
~AAA(){}
void foo() {}
private:
static BBB b;
};
template<class T>
BBB AAA<T>::b;
//class CCC {
//
//private:
//
// static BBB bb;
//
//};
//
//BBB CCC::bb;
AAA<int> a;
int main()
{
//AAA<int> a;
a.foo();
return 0;
}
</code></pre>
<p>It seems that the constructor of "b" object in AAA is not called when the containing class is template. Try uncomment the CCC class definition and the "bb" object constructor will be called. This is strange since the template class A is instantiated.</p>
<p>Help is greatly appreciated.</p>
| c++ | [6] |
1,560,578 | 1,560,579 | How to stop loop when user enters "quit", "end", etc? | <p>This is my code</p>
<pre><code> #!/usr/bin/python3.1$
#Break Statement$
while True:$
s=(input('enter an string: '))$
if s=='Quit,quit,End,end':$
break$
print('Your string length is',len(s))$
print("done")$
</code></pre>
<p>Here my program fails to check the condition....even if it checks it even calculates for the length for 'quit,Quit,End,end' -- any ideas why?</p>
| python | [7] |
1,088,335 | 1,088,336 | MKMapView Current Location Display | <p>I am Getting the pin which Display Current Location in english but i want to display in Different language so how can i do this?</p>
| iphone | [8] |
2,089,013 | 2,089,014 | Trying to find the indexOf a string from an ArrayList filled with strings from hashtable, only returning -1 | <p>I am trying to get the indexOf of a specific string from an ArrayList but the string is not matching when doing the check. I am filling the StringList from hashtable with the code below.</p>
<pre><code>stringList = new ArrayList<String>
Set st = hashtable.keySet();
Iterator itr = st.iterator();
while(itr.hasNext())
{
stringList.add(((String)itr.next()).trim());
}
</code></pre>
<p>The string I am trying to get from the stringList is input by the user, the string is generally in the form of “! Xxxx ##:##:## xx” if that makes a difference. I know the string match in the fact that I test it visually by printing out the stringList. So I figure it is something similar to the == and .equals().</p>
<p>I tested also by filling the stringList with a specific String from the hashtable and using the code below and it always returns false.</p>
<pre><code>String keyString = "! Xxxx ##:##:## xx";
if(stringList.get(0).equals(keyString))
System.out.println("true");
System.out.println("false");
</code></pre>
<p>So I am trying to figure out how to get the code below to work</p>
<pre><code>stringList.indexOf(keyString)
</code></pre>
<p>because it only returns -1 which it should, as it is not seeing the strings are equal. What am I doing wrong that is preventing the output I am looking for, which would be the correct index that I think it should be returning since I am typing exactly what is being print out by stringList. Like I said before, I thought it was an issue with .equals() but from what I can tell indexOf uses .equals() when looking for the index as well as seeing the results from me testing .equals() myself.</p>
| java | [1] |
782,480 | 782,481 | error! got undefined variable if sent empty post | <p>i got error message if sent empty post in my registration form</p>
<p><strong>Notice: Undefined index: terms in /opt/lampp/htdocs/user/register.php on line 34</strong></p>
<p>in the line 34 i have this </p>
<pre><code>$terms = trim($_POST["terms"]);
</code></pre>
<p>and in the form i have this</p>
<pre><code><p>
<input type="checkbox" name="terms" id="terms"> I have read and accept the conditions of use
</p>
</code></pre>
<p>and this is all the validation form</p>
<pre><code>if(!empty($_POST))
{
$errors = array();
$terms = trim($_POST["terms"]);
$captcha = md5($_POST["captcha"]);
$name = trim($_POST["name"]);
if($terms == "")
{
$errors[] = lang("ACCOUNT_SPECIFY_NAME");
}
//End data validation
if(count($errors) == 0)
{
//Construct a user object
$user = new User($username,$password,$email,$name,$lastname);
//Checking this flag tells us whether there were any errors such as possible data duplication occured
if(!$user->status)
{
if($user->username_taken) $errors[] = lang("ACCOUNT_USERNAME_IN_USE",array($username));
if($user->email_taken) $errors[] = lang("ACCOUNT_EMAIL_IN_USE",array($email));
if($user->email_blocked) $errors[] = lang("ACCOUNT_EMAIL_BLOCKED");
}
else
{
//Attempt to add the user to the database, carry out finishing tasks like emailing the user (if required)
if(!$user->userCakeAddUser())
{
if($user->mail_failure) $errors[] = lang("MAIL_ERROR");
if($user->sql_failure) $errors[] = lang("SQL_ERROR");
}
}
}
}
</code></pre>
<p>?></p>
<p>why i got this alert message?</p>
<p>thanks</p>
| php | [2] |
5,206,545 | 5,206,546 | Login Script problem | <pre>
if (isset($_POST['login'])){
$query = mysql_query("SELECT id FROM users
WHERE username = '".mysql_real_escape_string($_POST['username'])."'
AND password = '".mysql_real_escape_string($_POST['password'])."'");
/* wrong login information? redirect to error message */
if (mysql_num_rows($query) == 0){
header("Location: error.php");
exit;
}
/* set session with unique index */
$_SESSION['id'] = mysql_result($query, 0, 'id');
mysql_query("UPDATE users SET last_login = NOW(), _last_ip = '".$_SERVER['REMOTE_ADDR']."' WHERE id = '{$_SESSION['id']}'");
header("Location: welcome.php");
exit;
}
/* if logout, destroy session */
if (isset($_GET['logout'])){
mysql_query("UPDATE users SET online = '0' WHERE id = '{$_SESSION['id']}'");
session_unset();
session_destroy();
header("Location: index.php");
exit;
}
</pre>
<p>This works but if you leave username and password inputs empty, it log in too :/
I found it this script on a site. </p>
<p>How can I fix this hole?</p>
| php | [2] |
2,662,207 | 2,662,208 | CurrentThread/ProcessThread objects | <p>In the .NET BCL, there is a CurrentThread and a ProcessThread object. What is the difference between these?</p>
<p>Thanks</p>
| c# | [0] |
1,075,981 | 1,075,982 | jquery: stop everything happening at once | <p>I am just learning jquery, and it took me ages of browsing the jquery api site to create these few lines of code. What I want to do is use ajax to load content from another page and put it into an existing div. currently, the code works but when I click on a link all the steps get executed in one go, so its doing the load() function while the #content div is sliding up...</p>
<p>What I want it to do is to each line step by step, so after one line finishes THEN the next line starts (eg #content div slides up and then the things inside #content get deleted, but currently, #content div gets empty before it finishes sliding up)</p>
<pre><code>$(document).ready(function(){
$("#nav a").click(function(event){
event.preventDefault();
$("#content").slideUp();
$("#content").empty();
var navlink = $(this).attr("href");
$("#content").load(navlink + " " + "#content");
$("#content").slideDown();
})
});
</code></pre>
| jquery | [5] |
1,412,557 | 1,412,558 | Alternative for PHP linter | <p>Basically, php -l does not detect any syntax error, given this code:</p>
<pre><code><?php
date®;
?>
</code></pre>
<p>Obviously, it's an error when you execute it.</p>
<p>Is there any alternative or additional linter to use for PHP?</p>
<p>EDIT:</p>
<p>Thanks alot guys. Apparently it <em>is</em> a valid constant name, as the documentation suggests ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*).</p>
| php | [2] |
4,024,821 | 4,024,822 | how encode a string using base64 and how to convert this encoded string into orginal string? | <p>i am new to iphone</p>
<p>in my app i connect to twitter and send message in encoded form to display on message textfield to post but that code display in encoded form i want displat that in orginal textformate any help to how to convert it into orginal string formate, my code</p>
<pre><code>NSString *str1 = twittermessage;//twitter message is my orginal string
NSData *encrypteddata1 = [str1 dataUsingEncoding:NSASCIIStringEncoding];
NSString *b64EncStr1 = [Base64 encode:encrypteddata1];
NSLog(@"Encoded:%@",b64EncStr1);
//NSData *plainTextData = [NSData dataFromBase64String:b64EncStr1];
//NSString *plainText = [[NSString alloc] initWithData:plainTextData
// encoding:NSUTF8StringEncoding];
//NSLog(@"Decode:%@",plainText);
//NSString *urlAddress = @"http://twitter.com/?status=%@",;
//NSString *urlAddress = [NSString
// stringWithFormat:@"http://mobile.twitter.com/?status=%@",
// twittermessage];
NSString *urlAddress = [NSString
stringWithFormat:@"http://mobile.twitter.com/?status=%@",b64EncStr1];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[twitterview loadRequest:requestObj];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(twitterloading) userInfo:nil repeats:YES];
[self.view addSubview:webview];
</code></pre>
<p>by using this code i can login to twitter and display my encoded message on textfield to post but it display in encoded form how can i display this in normal text(orginal string formate)please help to me.
thanks in advance.</p>
| iphone | [8] |
3,783,646 | 3,783,647 | get image height and width in file tag using javascript | <blockquote>
<p><strong>Possible Duplicates:</strong><br>
<a href="http://stackoverflow.com/questions/6633190/get-image-height-and-width-in-file-tag-javascript">get image height and width in file tag javascript</a><br>
<a href="http://stackoverflow.com/questions/1310378/determining-image-file-size-dimensions-via-javascript">Determining image file size + dimensions via Javascript?</a><br>
<a href="http://stackoverflow.com/questions/4094012/how-to-upload-preview-image-before-upload-through-javascript">How to upload preview image before upload through JavaScript</a> </p>
</blockquote>
<p>how can i get the height and width of image without page refresh in file tag?</p>
<pre><code><HTML>
<HEAD>
<TITLE></TITLE>
<script language="javascript">
function getW()
{
var theImg = document.getElementById('testimg');
alert(theImg.width);
}
function getH()
{
var theImg = document.getElementById('testimg');
alert(theImg.height);
}
</script>
</HEAD>
<BODY>
<input type="file" id="testimg"/>
<input type="button" value="get Width" onclick="getW()"/>
<input type="button" value="get Height" onclick="getH()"/>
</BODY>
</HTML>
</code></pre>
<p>i get the image height and width of image using php code, but that time page will be refreshed, without page refresh i get image size but not a height and width....</p>
| javascript | [3] |
369,848 | 369,849 | Best way to set master page properties in content page in asp.net? | <p>There are different ways to set the title for content pages from Master page </p>
<ol>
<li>by findcontrol</li>
<li>by creating property in master page and setting the value in content page</li>
</ol>
<p>As both method requires an object creation of master page which will be little heavy<br>
<code>myMasterPage myMaster = (myMasterPage)this.Master;</code></p>
<p>so I have tried it by creating a class and it worked -</p>
<pre><code>public class clsmaster
{
public static clsmaster objmaster = new clsmaster();
public strtitle {get;set;}
}
</code></pre>
<p>Now I just need to access this static object and set the property in the content page and in the master page I just need the controls to take the value from this class (clsmaster).</p>
<p>I would like to know which one is the better approach and why with description please?</p>
| asp.net | [9] |
6,004,334 | 6,004,335 | PHP code Output | <p>I was studying for my finals and I came across this question: </p>
<blockquote>
<p>write the output after running this code.</p>
</blockquote>
<pre><code><?php
function swap($x, $y)
{
$x = $x + 1;
$y = $y + 2;
return $x * $y;
}
$a = 3;
$b = swap($a, $a);
print "$a, $b";
$b = swap(&$a, &$a);
print "$a, $b";
?>
</code></pre>
<p>I understand exactly what this code does, however after I ran it I got a completely different answer to what I answered with and I really don't understand the output.
The output I got was 3, 206, 36.</p>
<p>Could someone explain the output to me?</p>
| php | [2] |
4,176,479 | 4,176,480 | Button Works Only for One Time | <pre><code>$("#button_title_delete").click(function(){
jQuery.ajax({type:'POST',
url:'delete.php',
data: 'id='+$("bid").val(),
success: function(veri) { $("#delete_result").html(veri);}
});
});
</code></pre>
<p>When i click the button with "button_title_delete" id, this function works for only one time. What am i doing wrong? How should i fix this problem?</p>
| jquery | [5] |
3,337,128 | 3,337,129 | How to make numbers not repeated in a random number generated app in C++? | <p>I have an app that will display Lotto Max numbers, I need to make my app generate random numbers but I need the numbers to not repeat. I have my code done and would like to change a little as possible. But any help would be awesome!</p>
<pre><code> #include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
{
cout << "*** LOTTO MAX INSTA PICK ***" << endl;
cout<< " " << endl << endl;
}
{
cout << "Your Insta Pick Numbers" << endl;
cout<< " " << endl << endl;
}
for (int counter = 1; counter <= 21; ++ counter)
{
cout << setw(1) << (1 + rand() % 49) << " ";
if (counter % 7 == 0)
cout << endl;
}
{
cout<< " " << endl << endl;
}
{
cout << "Your Tag Numbers" << endl;
cout<< " " << endl << endl;
}
for (int counter = 1; counter <= 9; ++ counter)
{
cout << setw(1) << (0 + rand() % 9)<< " ";
if (counter % 9 == 0)
cout << endl;
}
{
cout<< " " << endl << endl;
}
{
cout << "Thank you for playing!! please check ticket\n a year minus a day from date of purchase" <<endl;
}
};
</code></pre>
| c++ | [6] |
4,408,953 | 4,408,954 | Two identical strings, yet different lengths. Trimmed, cleansed, etc | <p>I have two strings, one is generated by PHP and stored in a database at 128 characters. The generated string is e-mailed to the user and they must input the string.</p>
<p>Now for some reason, the one from the user (with me testing), is 132 characters long through <code>var_dump</code>. When I <code>echo</code> them, they are exactly the same. Same thing for <code>var_dump</code>. Except the character count. Where are these extra 4 (invisible) characters coming from? </p>
| php | [2] |
4,672,152 | 4,672,153 | Android Service With Notification | <p>I have one android application in i have to create a service that run 24 hours a day
it also use xml parsing based on that data it gives notification on the particular time?</p>
<p>How can I do this?</p>
| android | [4] |
255,971 | 255,972 | Javascript expression to define object's property name? | <p>I'd like to create this object...</p>
<pre><code>object = {
'object[1][var_name_1]' : 'value1',
'object[1][var_name_2]' : 'value2',
};
</code></pre>
<p>I'm trying to it this way, but I'm getting error <strong>missing : after property id</strong>...</p>
<pre><code>function getPrefix() {
return 'object[1]';
}
object = {
getPrefix() + '[var_name_1]' : 'value1',
getPrefix() + '[var_name_2]' : 'value2',
}
</code></pre>
<p>What am I doing wrong? Or maybbe it is impossible to set object property name using js experession?</p>
<p>Thank you</p>
| javascript | [3] |
2,893,364 | 2,893,365 | In Main function, after a try block throws an exception how can I make it keep on execute the next try block | <p>In Main function, after a try_block throws an exception the function is supposed to be break. My question is how can I make it keep on executing to the next try_block. Below I'm giving an example: </p>
<pre><code>public static void main(String [] s){
ABC aBC = new ABC();
try {
aBC.execute();
} catch (Exception e) {
_log.error(ErrorCodeEnum.ERROR,
"XXXXXXX!!! in " + new Date(),e);
}
BCD bCD = new BCD();
try {
bCD.execute();
} catch (Exception e) {
_log.error(ErrorCodeEnum.ERROR,
"YYYYYYYYYYY!!! in " + new Date(),e);
}
}
</code></pre>
| java | [1] |
727,808 | 727,809 | show/hide div using scrollTop | <p>I'm trying to create a script which would show div if 500px < scrollTop < 800px otherwise it would be hidden. So if my scroll is from 0 to 500 and from 800 and more it is hidden and between 500 and 800 it is shown. I'm new to javascript but this is what I have tried:</p>
<pre><code>$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 500) {
$('.myDiv').fadeIn();
} else {
$('.myDiv').fadeOut();
}
if ($(this).scrollTop() > 800) {
$('.myDiv').fadeOut();
}
});
</code></pre>
<p>However after scrolling to 800 it bugs and starts endlessly hiding and showing. Any way to fix it please?</p>
| javascript | [3] |
1,502,378 | 1,502,379 | How to create string "Version 1.0" in C# | <p>I have to store versionName of a template. VersionName is autoincremented.If last versionName is "Version 1.0", next should be "version 2.0". First time when a template is created, I have to store "Version 1.0".</p>
<p>I am using </p>
<pre><code>VersionName = "Version "+((LatestVersion+1).ToString())
</code></pre>
<p>LatestVersion holds the last version which is 0 in case added for first time.</p>
<p>This seems to be a ugly workaround and doesnot even yield Version 1.0. it yields Version 1. I Tried with Version class as well,it does not work. How to accomplish this.Please suggest</p>
| c# | [0] |
3,655,845 | 3,655,846 | ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for me to learn | <p>ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for me to learn. </p>
| asp.net | [9] |
271,443 | 271,444 | Is text in code char or const char? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/3303411/string-literals-vs-const-char-in-c">String literals vs const char* in C</a> </p>
</blockquote>
<p>Why i can do this?</p>
<pre><code>void foo(char * cstr) {
...
}
</code></pre>
<p>and in code</p>
<pre><code>foo("some text");
</code></pre>
<p>shouldnt "some text" be of type <strong>const</strong> char * ?</p>
<p>if its char *, means i can modify it?</p>
| c++ | [6] |
22,046 | 22,047 | Jquery select class inside parent class | <p>I'm trying to select a class inside the same parent class of a link.</p>
<p>This is the html:</p>
<pre><code><div id="productList">
<ul>
<li class="productListItem">
Product 1 <span class="smallText">stuff</span>
<div class="skuFinder"></div>
<ul class="merchantsInProductList">
<li><a class="merchantLink" href="/Pricing/SkuFinder/1/1">Merchant 1 $5.99</a></li>
</ul>
</li>
</ul>
</div>
</code></pre>
<p>When class "merchantLink" is clicked, I'd like to perform a jQuery load into the class "skuFinder"</p>
<p>What is the best way to select the class "skuFinder"?</p>
| jquery | [5] |
3,612,877 | 3,612,878 | Is it bad practice to create new objects without storing them? | <p>I've seen objects created in Java code without storing a reference to the object. For example, in an eclipse plugin I've seen a SWT Shell created like so:</p>
<pre><code>new Shell();
</code></pre>
<p>This new Shell object is not stored in a variable, but will remain referenced until the window is disposed which [I believe?] happens by default when the window is closed.</p>
<p>Is it bad practice to create objects like this without storing a reference to them? Or was the library poorly designed? What if I don't have need of a reference, but only want the "side effects" of the object? Should I store a reference anyways?</p>
<p>UPDATE:</p>
<p>Admitedly, my above example is poor. While I have seen UI elements created like this, creating a SWT Shell like this would probably be pointless because you need to call the open method on the Shell instance. There are <a href="http://stackoverflow.com/a/8841716/565879">better examples provided by aix</a> such as the following from the <a href="http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html" rel="nofollow">Java concurrency tutorial</a>:</p>
<pre><code>(new HelloThread()).start();
</code></pre>
<p>This practice is seen in many contexts, so the questions remains. Is it good practice?</p>
| java | [1] |
4,115,310 | 4,115,311 | What tools and/or libraries should I use to make an animated book | <p>I want to make a book rather like The Pedlar Lady for iPad. Each page has some rich text, and then an animation with sound effects that runs automatically after the user flips to a new page.</p>
<p>I have some idea how I could do that programmatically - Cocos2D is looking pretty useful - but what I don't know is how I could work with my artist. What tools could he use, and what would he deliver so that I can just slot each page's animation in with minimal effort.</p>
| iphone | [8] |
5,729,832 | 5,729,833 | Custom menu in android | <p>Is it possible to create a menu of this type in android?</p>
<p><img src="http://i.stack.imgur.com/OJDGN.jpg" alt="is it possible to create amenu of this type in android.?"></p>
| android | [4] |
2,312,723 | 2,312,724 | Reading a file relative to an included file | <p>I need to load some text (shader code) from a file that is placed next to my library file. This way, I can <code>#include TextureBloomer.h</code> in several projects, and TextureBloomer will take care of loading its shader without needing to set paths through configuration or environment variables. The directory hierarchy looks like this:</p>
<pre><code>libs/libName/src/TextureBloomer/TextureBloomer.{h,cpp}
libs/libName/src/TextureBloomer/shaders/shader_name.{frag,vert}
apps/mine/appName/src/[several .h files that #include "TextureBloomer/TextureBloomer.h"]
</code></pre>
<p>I've been looking around for ways to do this, but all I found was posts saying "you can't", or "why would you even want to do that?" I found a (hacky) solution that works for me, but I've seen other posts that say using <code>__FILE__</code> is bad juju (with no justification). So, the question is a) what's so bad about this, and b) is there a way to improve it, eg. so I don't have to have "TextureBloomer.cpp" in the source file in case I change its name.</p>
<pre><code>string filename ("shaders/shader_name.frag");
string currentFile (__FILE__);
currentFile.replace(currentFile.find("TextureBloomer.cpp"), 18, "");
file.open((currentFile + filename).c_str());
</code></pre>
<p>EDIT: </p>
<p>I'm on OSX, compiling with XCode. I only really need it to work there, but other *nixes wouldn't hurt.</p>
| c++ | [6] |
2,072,737 | 2,072,738 | PHP or PHPUnit. Select a random option from drop down excluding selected one | <p>If my drop down has 10 options to select from, and option 4 is selected, how can I write the code to select an option from 1-10 exluding 4?</p>
<p>I know rand(1, 10) picks a random number from 1 to 10, but it sometimes can land on 4. How can I make sure that it doesn't pick the number 4, or any number that is already selected?</p>
| php | [2] |
2,643,079 | 2,643,080 | Why should some methods be invoked only from the main application thread? | <p>I read about <a href="http://developer.android.com/reference/android/speech/SpeechRecognizer.html" rel="nofollow">this class</a>:</p>
<blockquote>
<p>Do not instantiate this class directly, instead, call
createSpeechRecognizer(Context). This class's methods must be invoked
only from the main application thread.</p>
</blockquote>
<p>I suppose that the main application thread is the main Activity of an Android application...
Why should this class's methods be invoked only from the main application thread?</p>
| android | [4] |
1,429,376 | 1,429,377 | Compress If Conditions | <p>Is there such a way to compress a block of conditions in an <code>if</code> statement?
As you can see from the code, <code>itemKey</code> is a variable. I set the first letter to be lowercased so I can match it to another variable <code>letter</code>. The below works perfectly, but I would like to clean it up. Can I somehow pull all the <code>||</code> after the <code>&&</code> together to encompass all number 0-9? This is acting as a <code>string</code>, not <code>integer</code>.</p>
<pre><code>firstLetterLower = itemKey.charAt(0).toLowerCase();
if(firstLetterLower==letter || (letter=='number' && (firstLetterLower=='0' || firstLetterLower=='1' || firstLetterLower=='2' || firstLetterLower=='3' || firstLetterLower=='4' || firstLetterLower=='5' || firstLetterLower=='6' || firstLetterLower=='7' || firstLetterLower=='8' || firstLetterLower=='9'))) {
</code></pre>
| javascript | [3] |
1,111,572 | 1,111,573 | how to implement water animation in iphone(ripple animation)? | <p>I have implement one game application .In that game i want to implement wateer animation.PLease give me idea about that.</p>
<p>same like:http://www.heikobehrens.net/2009/10/02/burlington-ducky-iphone-app/</p>
| iphone | [8] |
1,624,715 | 1,624,716 | creating excel, powerpoint and documents in asp.net and saving the files | <p>I have a dropdownlist in my application with items document, excel and powerpoint. When i click on each of them say for example excel, an excel sheet should open and I write in it and I should be able to save the file in gridview. How can I do that?</p>
| c# | [0] |
1,786,224 | 1,786,225 | using eval in Java | <p>I am new to Java. I have a string like the following:</p>
<pre><code> str="4*5";
</code></pre>
<p>Now I have to get the result of 20 by using the string. I know in some other languages the eval function will do this. How do I do this in Java?</p>
| java | [1] |
403,913 | 403,914 | cookies handling on webrequest and response | <p>I have created a application that has a function <code>mainpost</code>. It is created to post data on a https sites. Here I want to handle cookies in this function. How can I do this task?</p>
<pre><code>public string Mainpost(string website, string content)
{
// this is what we are sending
string post_data = content;
// this is where we will send it
string uri = website;
// create a request
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri); request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
// turn our request string into a byte stream
byte[] postBytes = Encoding.ASCII.GetBytes(post_data);
// this is important - make sure you specify type this way
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
Stream requestStream = request.GetRequestStream();
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
// grab te response and print it out to the console along with the status
// code
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string str = (new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine(response.StatusCode);
return str;
}
</code></pre>
| c# | [0] |
5,562,738 | 5,562,739 | How to crawl markup with PHP, check if images exists and replace non-existing paths? | <p>I have some markup which I need to crawl for images, and check if the images exists in the paths they have specified. If an image does not exists in location A, the path should be replaced with location B.</p>
<p>I'm wondering what would be the most efficient way of achieving this?</p>
| php | [2] |
3,970,041 | 3,970,042 | How to start an Activity from a Service? | <p>Is it possible to start an Activity from a Service? If yes, how can we achieve this?</p>
| android | [4] |
4,348,572 | 4,348,573 | accessing functions or methods of the non .net dlls | <p>how to access the methods of non .net dll in .net in c#? which class is used to access the dll methods.</p>
| c# | [0] |
857,909 | 857,910 | Training Naive-Bayesian Classifier using 4J classifier java library | <p>I need to categorize input queries on mobile platform sent by users as SMS into ten pre-defined categories such as sports, finance, health etc.</p>
<p>How do I begin and then go about training Bayesian Classifier, i.e. how do I prepare a training document, how extensive should it be, are there any assured directives that can be followed or do I just keep on modifying the training document till good results start showing up?</p>
| java | [1] |
2,536,503 | 2,536,504 | Jquery dropdown control with tags | <p>Does anyone know a good Jquery plugin control for dropdown list. A user should be able to select multiple values from dropdown list and those selected values should be displayed as tags in the same control.</p>
<p>Please see the attached image for reference.<img src="http://i.stack.imgur.com/k6bDF.jpg" alt="enter image description here"></p>
| jquery | [5] |
1,997,745 | 1,997,746 | Effective IPhone programing techniques | <p>While creating an IPhone application I always care about techniques which greatly effect working of an application on one side <em>and</em> understanding of code on the other. For instance, I prefer creating <strong>Singleton</strong> to manage data, which separates <em>Data</em> from <em>View</em>. Similarly, use of <strong>Asynchronous images</strong> and <strong>memory management</strong> are few techniques which I always use whenever I work with some <em>web service</em> or any <em>database</em>.<br>
What I believe is, there are a lot many <em>effective</em> programing techniques which programmers follow to make their application best presented before the client.<br>
Which techniques I should keep in perspective while creating an <em>IPhone</em> application which makes use of <em>web data</em> or <em>local data</em>? Are their concepts similar to <em>Singleton</em> which I should consider using in my application? </p>
<p>Thanks for letting out few of your secrets :)</p>
| iphone | [8] |
1,819,556 | 1,819,557 | stack trace when debug on android device | <p>when I debug my android app using emulator, the stacktraces and error messages are shown in Eclipse's Logcat.<br>
However, when I debug on my physical android device, when app crashes there is no stacktrace shown in eclipse. Is there anything i need to configurate in order to get stacktrace when debugging on physical device??</p>
| android | [4] |
4,716,669 | 4,716,670 | how to restore contacts from vcf file with my own code | <p>I am abel to take backup of all the phone contacts into a vcf file by writing my own code. but how to restore contacts from a vcf file to the android phone with my own code. is there any way to not to use the android activity.</p>
| android | [4] |
4,515,037 | 4,515,038 | convert byte[] to AES key | <p>i have a AESkey which encrypted by a public key, and later decrypted by a private key</p>
<pre><code> Cipher cipher = Cipher.getInstance("RSA");
PrivateKey privateKey = keyPair.getPrivate();
// decrypt the ciphertext using the private key
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] decryptedText = cipher.doFinal(theBytes);
</code></pre>
<p>theBytes is a byte[] containing a encrypted AESkey, the question is how to convert the decryptedText back to the AESkey?</p>
| java | [1] |
5,795,065 | 5,795,066 | Exception in checkAndLoadTargetData.Java heap space | <p>I tried increasing the heap size of JVM. But still no luck. I am getting this error when I open the eclipse and when Android SDk is getting loaded. Please help me regarding this.</p>
| android | [4] |
1,323,869 | 1,323,870 | Elegant solution to retrieve custom date and time? | <p>I am currently using a date and time picker to retrieve a user-submitted date and time, and then I set a control's text to the date and time selected. </p>
<p>I am using the following code:</p>
<pre><code>new DatePickerDialog(newlog3.this, d, calDT.get(Calendar.YEAR), calDT.get(Calendar.MONTH), calDT.get(Calendar.DAY_OF_MONTH)).show();
new TimePickerDialog(newlog3.this, t, calDT.get(Calendar.HOUR_OF_DAY), calDT.get(Calendar.MINUTE), true).show();
optCustom.setText(fmtDT.format(calDT.getTime()));
</code></pre>
<p>Now, while the above code block does bring up the date and time widgets and sets the text, the code block is being executed in full before the user can select the date.. ie: It brings up the date box first, then the time box over that, and then updates the text, all without any user interaction. I would like the date widget to wait to execute the time selector until the date selection is done, and i would like the settext to execute only after the time widget is done. </p>
<p>How is this possible? Or is there is a more elegant solution that is escaping me?</p>
<p>Edit: This is the code for DatePickerDialog/TimePickerDialog which is located within the class:</p>
<pre><code> DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
calDT.set(Calendar.YEAR, year);
calDT.set(Calendar.MONTH, monthOfYear);
calDT.set(Calendar.DAY_OF_MONTH, dayOfMonth);
//updateLabel();
}
};
TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
calDT.set(Calendar.HOUR_OF_DAY, hourOfDay);
calDT.set(Calendar.MINUTE, minute);
//updateLabel();
}
};
</code></pre>
<p>Thanks in advance</p>
| android | [4] |
724,043 | 724,044 | must press enter key twice to do the work | <p>I have a problem with the enter key in android, I have an edittext where I enter a value and then when I click on enter, I want it to make something. My problem is that I have to press enter twice to get the desired results.</p>
<pre><code> editText1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
mWebView.loadUrl(editText1.getText().toString());
mWebView.requestFocus();
return true;
}
return false;
}
});
</code></pre>
| android | [4] |
3,089,378 | 3,089,379 | Count lower case characters in a string | <p>What is the most pythonic and/or efficient way to count the number of characters in a string that are lowercase?</p>
<p>Here's the first thing that came to mind:</p>
<pre><code>def n_lower_chars(string):
return sum([int(c.islower()) for c in string])
</code></pre>
| python | [7] |
624,158 | 624,159 | Dynamic drop down list! | <p>I have edited the question as what I said before was two pieces of code together.</p>
<p>I have the following code:</p>
<pre><code> $f = "SELECT * FROM ".TBL_FIXTURES." WHERE compname = '$_POST[league]' AND home_user = '$_SESSION[username]' ORDER BY away_user";
$fixtures = mysql_query($f);
?>
<?
while( $row = mysql_fetch_assoc($fixtures))
{
extract($row);
$info = explode("_",$row[compname]);
?>
<select name="hu" class="combo">
<option value="<? echo $home_user ?>"><? echo $home_user?></option>
</select>
<select name="au" class="combo">
<?php
while( $row = mysql_fetch_assoc($fixtures))
{
$u=$row['away_user'];
echo "<option value=\"$u\">$u</option>";
}
?>
</select>
<?
}
?>
</code></pre>
<p>As you can see, there are two while loops. But the first value from the dropdown list for away_user is missing. If i remove the first loop, it appears but the drop down for home_user disappears. How can i get around this?</p>
<p>THanks</p>
| php | [2] |
443,639 | 443,640 | Exposing class types directly through another class | <p>I have a class called Config with the declaration
<code>public class Config<T> where T : class, new()</code></p>
<p>It contains some methods to save a configuration of type <code>T</code> as well as the actual configuration in property called <code>Configuration</code>.</p>
<p>Is it possible to expose the configuration of type <code>T</code> directly in my Config class without having to go through the <code>Configuration</code> property.</p>
<p>So far, I have a bit of an ugly work around</p>
<pre><code>public T this[int index]
{
get { return _configuration; }
}
</code></pre>
<p>If not, then I was wondering if it can be done by inheriting from the <code>T</code>, but I'm not clear on the syntax of how to do this.</p>
<p><strong>Edit:</strong><br>
I imagined you could do something like </p>
<pre><code>public T this
{
get { return _configuration; }
}
</code></pre>
| c# | [0] |
1,163,305 | 1,163,306 | Getting assembly error | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/4693185/how-to-add-microsoft-visualstudio-teamsystem-data-unittesting-reference">How to add ‘Microsoft.VisualStudio.TeamSystem.Data.UnitTesting’ reference</a> </p>
</blockquote>
<p>I am getting an error in visual studio 2008</p>
<blockquote>
<p>Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.TeamSystem.Data.UnitTesting, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.</p>
</blockquote>
| asp.net | [9] |
4,086,878 | 4,086,879 | Javascript two equals | <p>Trying to deepen my knowledge of JS, can someone tell me what this does/is please?</p>
<pre><code>jQuery = $ = this.jQuery;
</code></pre>
<p>What exactly does two equal signs do here?</p>
| javascript | [3] |
589,425 | 589,426 | problem of CGContext | <p>i want to draw a line in the rect of UIView when i touch screen.
please can someone help me to check the code !
thanks </p>
<pre><code>- (void)drawRect:(CGRect)rect {
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 5.0);
CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
CGContextMoveToPoint(context, 100.0, 30.0);
CGContextAddLineToPoint(context, 200.0, 30.0);
CGContextStrokePath(context);
}
</code></pre>
<p>thanks.</p>
| iphone | [8] |
5,305,421 | 5,305,422 | Will not update the ID for a link on click | <p>I have this function to create a request to another file to update the database:</p>
<pre><code>$('#thumb-up').live('click', function() {
$('#loading').show();
$.ajax({
context: this,
type: 'GET',
url: '/gallery/configurations/required/photo-thumbs.php',
data: 'i=21&t=1',
success: function() {
$('#loading').hide();
$(this).attr('id', 'thumbup-undo').text('Sluta gilla');
$('#thumbup-count').load('/gallery/configurations/required/thumbup-count.php?i=21&t=1');
}
});
});
$('#thumbup-undo').click(function() {
alert('das');
});
</code></pre>
<p>When I click on the link with the id <code>thumb-up</code> the text changes to "Sluta gilla" as expected. When I now have clicked on this link the ID for the same a tag will be changed from <code>thumb-up</code> to <code>thumbup-undo</code> and the alert "dsa" will appear. The problem here is that it does not appear! I don't even know if it changes to <code>thumbup-undo</code> but I expect that it does not.</p>
<p>You can try the code <a href="http://jsfiddle.net/HbSjm/" rel="nofollow">here</a> (I have shortened the code to make the demo work properly).</p>
<p>How can I fix this problem?</p>
<p>Thanks in advance</p>
| jquery | [5] |
3,308,788 | 3,308,789 | Could not find lvl License.apk | <p>I am getting this error message when I try to run my app that has the lvl installed as a library.</p>
<p>I followed the steps outlined on the developer.android.com site for installing the lvl library:</p>
<p>I copied the "market_licensing" folder into my project folder,</p>
<p>I created a new library called "License" with "new", "android project using Motodev studio", "create project from existing source", "SDK Target" API-7. </p>
<p>I set the main project "project","properties", "android", "add library" to "License", and checked "IsLibrary".</p>
<p>Still, the lvl library doesn't seem to build with the main application, giving me this error.</p>
| android | [4] |
1,146,142 | 1,146,143 | Javascript/HTML, is it possible to create variable names from a loop | <p>Imagine i had: <code><div id names>142,140,150</names></code></p>
<p>could i then (in Javascript) write a forloop which declares variable names, with these values appended ie</p>
<pre><code>var list = document.getElementById('names').innerHTML.Split(',');
for(i=0; i<list.Length; i++){
var 'beginning' + list[i];
}
</code></pre>
<p>so i'd essentially want to create:</p>
<pre>
var beginning142
var beginning140
var beginning150
</pre>
| javascript | [3] |
1,637,314 | 1,637,315 | responding to wifi availability | <p>how exactly should I configure my broadcast receiver to make my app respond to changes in the wifi availability. I do not really care about reacting to it when the app is not running though.</p>
<p>What I am trying to accomplish here is that as the app is running I need to keep the local DB in synch with a copy on the server. If for whatever reason I lost my connection I need to know when it makes sense to try to re connect.</p>
| android | [4] |
4,424,099 | 4,424,100 | python super question | <p>I have a syntax question about python's super() and multiple inheritance. Say I have class A and B, both of which have a method hello(). I have a class C that inherits from both A and B, in that order. </p>
<p>How do I call the hello() method of B explicitly from C? Seems simple enough, but I can't seem to find the syntax for it. </p>
| python | [7] |
2,178,065 | 2,178,066 | Javascript keeps undefining my vars, it's harshing my buzz. Help? | <p>This is my first experience with javascript, and... Well... Ugh. Here's what's happening:</p>
<pre><code>function step_1(id) {
//blah blah
step_2(id);
}
function step_2(id) {
//blah blah
step_3(id);
}
function step_3(id) {
//blah blah
alert(id);
}
step_1(0); // I can stick any number here, same thing happens...
</code></pre>
<p>The alert pops up and says "Undefined". But, if I throw an alert(id); in step_2, then both alerts say "0".</p>
<p>Why/how is id undefined? What am I doing wrong?</p>
<p>I've even tried reassigning id in each function, like:</p>
<pre><code>var nid = id;
step_2(nid);
</code></pre>
<p>etc... But that still doesn't work without the alerts.</p>
<p>EDIT: Since my example apparently works fine, perhaps it would help to <a href="http://pastebin.com/78W0pVCK" rel="nofollow">look at the blah blah that's going on in my code</a>. It works fine, unless I take out the alert(id); on line 11.</p>
| javascript | [3] |
3,453,646 | 3,453,647 | Execute some functions without submit and then submit | <p>I have two inputs the must be validate on submit.
I'm trying this:</p>
<pre><code>$("#phase1_form").submit(function(e){
var result1 = $("#phase1_responsVibleByFirstSignOff").isValid();
var result2 = $("#phase1_responsibleBySecondSignOff").isValid();
if ((result1
&& result2
))
{
return true;
}
});
</code></pre>
<p>But the "isValid" function is not so fast and the form is submitted.
I though that maybe I could use the "preventDefault" method, but I have no idea how to "cancel" the effect of this method after the "isValid" function returns some result.</p>
<p>Thanks</p>
| jquery | [5] |
133,659 | 133,660 | Problems parsing a xml file | <p>I am editing a xml file that is originally like that:</p>
<pre><code> <SequencerLoopCommand id="1073"
IterationCount="2"
CommandList="1241 1242"
Name="Loop Stream IDU64ToIDU63">
<IterateLoadSizeCommand id="1241"
LoadType="STEP"
LoadUnits="KILOBITS_PER_SECOND"
LoadStart="100"
LoadEnd="200"
LoadStep="100"
CustomLoadList=""
StreamBlockList="1543"
Name="Iterate Stream IDU64ToIDU63">
</IterateLoadSizeCommand>
<WaitCommand id="1242"
WaitTime="5"
Name="Stream IDU64ToIDU63">
</WaitCommand>
</SequencerLoopCommand>
</code></pre>
<p>With the following code...</p>
<pre><code>doc = minidom.parse("directory")
#processing
fh = open(os.path.join(self.__dirname,self.__xmlfile),"w")
doc.writexml(fh)
fh.close()
doc.unlink()
</code></pre>
<p>after that, my new xml is something like:</p>
<pre><code><SequencerLoopCommand CommandList="1241 1242" IterationCount="2" Name="Loop Stream IDU64ToIDU63" id="1073">
<IterateLoadSizeCommand CustomLoadList="" LoadEnd="200" LoadStart="100" LoadStep="100" LoadType="STEP" LoadUnits="KILOBITS_PER_SECOND" Name="Iterate Stream IDU64ToIDU63" StreamBlockList="1543" id="1241">
</IterateLoadSizeCommand>
<WaitCommand Name="Stream IDU64ToIDU63" WaitTime="5" id="1242">
</WaitCommand>
</SequencerLoopCommand>
</code></pre>
<p>I need that the new file to have the same structure as the old one. Any tip?</p>
<p>Thank you</p>
| python | [7] |
3,085,542 | 3,085,543 | Why must I wrap a number to call its methods? | <pre><code>js> (5).toString(2)
101
js> 5.toString(2)
js: "<stdin>", line 53: missing ; before statement
js: 5.toString(2)
js: ..........^
js>
</code></pre>
| javascript | [3] |
5,643,267 | 5,643,268 | Comparing two lists and "looking back" | <p>How would you approach comparing two lists and "looking back"?</p>
<p>I'm comparing the elements of two lists like this:</p>
<pre><code>score = 0
for (x,y) in zip(seqA,seqB):
if x == y:
score = score +1
if x !=y :
score = score - 1
</code></pre>
<p>Now I would like <code>score + 3</code> if the <strong>previous</strong> pair was a match, so basically I would have to "look back" one iteration.</p>
| python | [7] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.