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 |
|---|---|---|---|---|---|
1,248,423 | 1,248,424 | In C# how can I safely exit a lock with a try catch block inside? | <p>Here is an example of an exception happening inside a lock, with a try-catch block.</p>
<pre><code>int zero = 0;
int j = 10;
lock (sharedResource.SyncRoot)
{
try
{
j = j / zero;
}
catch (DivideByZeroException e)
{
// exception caught but lock not released
}
}
</code></pre>
<p>How do I safely release this lock in the catch?</p>
| c# | [0] |
2,441,901 | 2,441,902 | Monitor/logging who signs into the asp.netapp? | <p>I want to have a log file keep rows of who logs in and timestamp. is there a place to do this? And what sort of code is needed?</p>
| asp.net | [9] |
5,743,674 | 5,743,675 | Cannot get the httpPost params but can get the httpGet from php | <p>Here is my android code to send request:</p>
<pre><code>// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(serverUrl);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("abc", "abc2"));
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = null;
is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String json = "";
json = sb.toString();
Log.d("JSON", "JSON is:" + json);
</code></pre>
<p>and here is my php code to get the request:</p>
<pre><code><?php
echo $_POST['abc'];
?>
</code></pre>
<p>When I run the application, the string <code>json</code> is nothing. I expect to get <code>JSON is:abc2</code><br>
Then I change the some code, in android part: </p>
<pre><code>HttpPost httpPost = new HttpPost(serverUrl);
</code></pre>
<p>change to: </p>
<pre><code>HttpPost httpPost = new HttpPost(serverUrl + "?abc=abc3");
</code></pre>
<p>in php part: </p>
<pre><code><?php
echo $_GET['abc'];
?>
</code></pre>
<p>This time, the string <code>json</code> in logcat is <code>JSON is:abc3</code>. It is correct!!<br>
I have tried lots of time, but seems cannot send HttpPost request with params.<br>
Any one can help me to find out what wrongs with my code??</p>
| android | [4] |
1,779,880 | 1,779,881 | I can't find Generate local resource from tools menu in visual studio 2010 | <p>Even i'm in design view(markup) at webpage. i can't find Generate Local Resource from my tools menu. Can any one tell me how to enable this tool.</p>
<p>Thanks,</p>
| asp.net | [9] |
3,323,575 | 3,323,576 | Translating C++ project from .exe to .dll? | <p>I have develped my GUI Application in Qt though Qt Creator IDE & MinGW compiler.
I plan to Open source it under the terms of GNU-LGPL.
Now since I had developed all the source code with my GUI Application in my mind, I am having difficulty in modifying the project so as to build a .dll which others can use in their applications. Here are some of my doubts:</p>
<ol>
<li><p>Should I maintain a different sets of source files for .exe project & another for .dll project, considering that I will be maintaining my project on GitHub.</p></li>
<li><p>Should I delete all the GUI related code from the .dll project? Or it would be fine to just put bool flag's everywhere GUI is created/modified?</p></li>
<li><p>Should I delete those functions which were only used in .exe project & will never be called in .dll project? Or should I let them be as it is?</p></li>
</ol>
<p>This is my first time at Application development as well as Open Source development. Since I have developed it myself, I dont have proper guidance.
Thank You.</p>
| c++ | [6] |
5,762,055 | 5,762,056 | How to call this.function within setTimeout in JS? | <p>I have the following JS:</p>
<pre><code>function TrackTime() {
this.CountBack = function(secs) {
setTimeout(function(){this.CountBack(secs)}, SetTimeOutPeriod);
}
}
</code></pre>
<p>I have tried this with a closure (seen above) and also about a dozen other ways. I can't seem to get this to work in any browser. The setTimeout function works fine when not being called in a "class" function. Can someone please help me with this? </p>
| javascript | [3] |
1,028,409 | 1,028,410 | how can I run a iPad project on a iPhone or touch | <p>I build a iPad project,i want to run the project on iPhone with auto-resize and it's run successful on iPhone 4.1 simulator,but it's always alert 'can only installed on ipads' when i run it with my iPhone,how can I run a iPad project on a iPhone or touch,what can i do?</p>
| iphone | [8] |
3,962,340 | 3,962,341 | What does "This method is deprecated" mean for application developers | <p>I see quite a few <a href="http://developer.android.com/reference/android/webkit/WebView.PictureListener.html#onNewPicture%28android.webkit.WebView,%20android.graphics.Picture%29">good old useful methods</a> or even entire classes being "deprecated and obsolete". </p>
<p>But code that used to call those methods continues to work. So, what does this mean to me, as an Android applications developer?</p>
<ol>
<li>Continue using this method as long as I want, because newer SDKs
will <em>always</em> remain backward compatible.</li>
<li>It will work as long as I build for older targets (e.g. API 8), but
if I build from API 14 up, the compiler will refuse to complete
the build.</li>
<li>Both (1) and (2)</li>
<li>Other?</li>
</ol>
<p>This is especially confusing when no alternatives are provided, as in the case of <a href="http://developer.android.com/reference/android/webkit/WebView.PictureListener.html#onNewPicture%28android.webkit.WebView,%20android.graphics.Picture%29">WebView.PictureListener.html#onNewPicture</a>.</p>
| android | [4] |
2,517,125 | 2,517,126 | Nested scrolling on Android | <p>We have a main horizontal scroll view in our activity, and several vertical scroll views nested inside it. The idea is to scroll horizontally till you find the vertical list you want, then scroll that up and down.</p>
<p>Ideally, I'd want the vertical scrolling to have a "lock" once you start scrolling vertically. What happens now, if you're very careful, you can scroll vertically, but if you move your finger a little too much to the left/right while doing it, the vertical stops and the horizontal takes over.</p>
<p>What would probably make sense is, whatever scroll view gets "activated" first by your movement, that one stays active until you finish your interaction (ie remove your finger).</p>
<p>Any way to make it behave like that?</p>
| android | [4] |
1,291,205 | 1,291,206 | php - display a table row by row | <p>I print my table like that:</p>
<pre><code>print $tableHeader . $dataRow . $tableFooter;
</code></pre>
<p>the $dataRow is the result of a loop (getting data from DB and building the row, nothing unusual), it's something like:</p>
<pre><code>while ($obj = mysql_fetch_object($res)) {
$dataRow .= ' <td width="210" style="...">' . $obj->title . ' <br /> '. $obj->screenName .' </td>';
...
...
}
</code></pre>
<p>The problem is when there is a huge amount of information to handle => huge amount of rows to build before displaying the final table.</p>
<p>How could I tell Apache to display it row by row ?</p>
| php | [2] |
1,194,840 | 1,194,841 | Know When a listener's method has been called | <p>I am struggling trying to google this subject. I must not being using the correct search terms. I have a location listener, in Android, and I usually nest the listener inside the class I am using it for.</p>
<pre><code>public class ClassName {
...
private class Listener implements SomeListener{
...
public void somethingChanged(){
...
}
}
}
</code></pre>
<p>This time I decided to make the listener a new class to make the code easier to read and so I can reuse it. So now my listener and the class that is using the listener are separate.</p>
<pre><code>public class ClassName{
...
}
public class Listener implements SomeListener{
...
public void somethingChanged(){
...
}
}
</code></pre>
<p>So inside the <code>somethingChanged()</code> method, I just want to notify my main class that an event has occurred so I can do some updating. I can't think of a way to do this. I can't put anything specific in the listener's method or it is not reusable. How do I make a method that has been called from a Listener call a method in the class using the listener?</p>
| java | [1] |
4,126,615 | 4,126,616 | Swap value of two properties on object(s) | <p>I'm trying to make a simple function that will swap the values of two properties on the same or different global objects. </p>
<pre><code>object1 = {"key 1":"value 1"};
object2 = {"key 2":"value 2"};
swapValuesInObject ("object1['key 1']","object2['key 2']",true)
// should result in:
// object1 === {"key 1":"value 2"};
// object2 === {"key 2":"value 1"};
</code></pre>
<p>Another example:</p>
<pre><code>object1 = {"key 1":"value 1", "key 2":"value 2"};
swapValuesInObject ("object1['key 1']","object1['key 2']",1===1)
// should result in:
// object1 === {"key 1":"value 2", "key 2":"value 1"};
</code></pre>
<p>Here's what I've been able to come up with so far, but it's not much. Getting hung up on how to do the assignment.</p>
<pre><code>function swapValuesInObject(property1, property2, condition) {
if (condition) {
// temp assignment
var Obj1Value = property1;
// do the switcheroo
array1 = array2Value;
array2 = array1Value;
}
return true;
};
</code></pre>
<p>What's the proper way to do this?</p>
| javascript | [3] |
4,967,349 | 4,967,350 | Execute script at variable time | <p>I'm aware of cron jobs to execute commands at a certain time, but what if that time is not constant? For instance, suppose a user asks for a reminder email exactly 1hr after signing up for something, is there an easy way to go about doing this? </p>
<p>Timing is critical. I am actually trying to create AI that will essentially act on its own but only at variable points during the day. Any help would be appreciated!</p>
| php | [2] |
2,182,164 | 2,182,165 | Script only to run if window is bigger than div | <p>I have the following script that is working great, but I want to wrap it in an if statement that only runs this script when the window height is larger than the #tip element. What do I add?</p>
<pre><code>$(document).scroll(function () {
if($(window).scrollTop() >= 40){
$('#tip').css({'position' : 'fixed', 'top' : '20px', 'left' : '50%', 'margin-left' : '250px' });
}
if($(window).scrollTop() <= 40){
$('#tip').css({'position' : 'absolute', 'top' : '15px', 'left' : '', 'margin-left' : ''});
}
console.log($(window).scrollTop());
});
</code></pre>
| javascript | [3] |
2,094,971 | 2,094,972 | read write mode python | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/1466000/python-open-built-in-function-difference-between-modes-a-a-w-w-and-r">python open built-in function: difference between modes a, a+, w, w+, and r+?</a> </p>
</blockquote>
<pre><code>try:
f = open("file.txt", "r")
try:
string = f.read()
line = f.readline()
lines = f.readlines()
finally:
f.close()
except IOError:
pass
try:
f = open("file.txt", "w")
try:
f.write('blah') # Write a string to a file
f.writelines(lines) # Write a sequence of strings to a file
finally:
f.close()
except IOError:
pass
</code></pre>
<p>Hi,</p>
<p>this is mode which i can read and write file but i want to open file once and perform both read and write operation in python</p>
| python | [7] |
4,758,655 | 4,758,656 | python link values dictionary 1 to keys dictionary 2 | <p>I have two dictionaries. I have to match the values in the first to the keys in the second and then return the value found in the second dictionary. I came up with this so far:</p>
<pre><code>d1 = {}
with open ("file1.txt") as f:
for line in f:
(key,val) = line.split()
d[int(key)] = val
d2 = {}
with open("file2.txt") as f:
for line in f:
(key,val) = line.split()
d[int(key)] = val
for item in d1.values():
if d2.has_key(item):
print value.d2(item)
</code></pre>
<p>I keep getting the error "too many values to unpack" and aside from that, would my script actually do what I want it to do?</p>
<p>UPDATE (Sorry didn't know I could edit my question!):
I my two text files, file1 maps a word to a number system, and file2 maps the number to its relevant category. The end result should be that the word of file1 is linked to its category which is found in file2. This is done by first linking the word to a number and then linking the number to a category. For example: Aanbidden (dutch word) > 12 > Cat. "affect". The lines in my file look like this:</p>
<p>file1.txt:</p>
<pre><code>aanbidden: 12 13 14 57 58
leven : 15
drinken: 23 56
...
(As you see each key can have one or more values)
</code></pre>
<p>file2.txt:</p>
<pre><code>12: affect
13: posemo
14: Posfeel
15: Optim
23: discrep
56: money
57: metaph
58: religious
...
(In this file each key has only one value)
</code></pre>
| python | [7] |
3,149,059 | 3,149,060 | How to create clickable imageButton? | <p>I am creating a custom button to use in imageButton. I want to know will the button have a click effect when it is clicked by a user? If not what do i need to do to make it this way?</p>
| android | [4] |
3,815,061 | 3,815,062 | I am planning to build a website for my college final year project | <p>I am planning to build a website for my college final year project which is in regards to online test in php where people can practice for various examination like ibps etc.Please give ur sugesstion where I will start and how i am going to upload the questions?Thanks in advance</p>
| php | [2] |
3,670,880 | 3,670,881 | How to select forms except those under div #target in jQuery? | <p><code>$('form')</code> is selecting too many for me,</p>
<p>how to restrict it so that those not under <code>#target</code> are selected?</p>
| jquery | [5] |
1,109,244 | 1,109,245 | C# match and export based on listbox textfile and wildcard | <p>I like to thank stackoverflow member AlbertEin for helping with this code. What I have is a file being created from a massive directory listing, and i also have a listbox full of items that are only part of the file name in the directory listing. What I want to do is write out a text file for every listboxitem in listbox1.item based on the item and a wildcard</p>
<p>Example Listbox:<br>
Apple<br>
Orange </p>
<p>Results Apple.txt:<br>
Apple13.txt<br>
Apple15.txt<br>
Apple19.txt </p>
<p>and just do this foreach item in the listbox. I'd also like to only read the master txt file once to save me from reading it everytime. Any help appricated.</p>
<p>Better explaination:</p>
<p>I have a listbox of 100 items, and 1 master text file that was created.</p>
<p>For all items in the listbox that match the master test file, I want to write out the matching contents of the master text file to a new textfile with the listboxs name.</p>
<p>The listbox items needs a wildcard in order to match the master text file.</p>
| c# | [0] |
2,948,174 | 2,948,175 | Python if modifier precedence | <p>Sorry, I'm sure it was asked a billion times, but I couln't have found exact answer:</p>
<pre><code>var = value if condition else other_value
</code></pre>
<p>What is the precedence of <code>if .. else</code> relative to assignment? Like in C/Java ternary or not?</p>
| python | [7] |
3,020,176 | 3,020,177 | Declare python class, and create class instances. (Core Python Programming) | <p>I'm learning python out of "core python programming 2nd edition"</p>
<p>Im stuck at the part "How to Create Class instances". Page 84.</p>
<p>The example is as follows:</p>
<p>classes.py:</p>
<pre><code>class FooClass(object):
"""my very first class: FooClass"""
version = 0.1 # class (data) attribute
def __init__(self, nm='John Doe'):
"""constructor"""
self.name = nm # class instance (data) attribute
print'Created a class instance for', nm
def showname(self):
"""display instance attribute and class name"""
print 'Your name is', self.name
print 'My name is', self.__class__.__name__
def showver(self):
"""display class(static) attribute"""
print self.version # references FooClass.version
def addMe2Me(self, x): # does not use 'self'
"""apply + operation to argument"""
return x + x
</code></pre>
<p>Then i have to create Class Instances:</p>
<p>in my interpreter i do the follow:</p>
<pre><code>Import classes *
fool = FooClass()
</code></pre>
<p>But nothing happends. It should print the <strong>init</strong>.</p>
<p>also when i use</p>
<p><code>fool.showname()</code> and <code>fool.showver</code> it doesn't print any. It says</p>
<blockquote>
<p>FooClass' object has no attribute 'showver</p>
</blockquote>
<p>i really want to know what going on here, before i proceed.
Hopefully someone can help me out!</p>
<p>Thanks in advance! :)</p>
| python | [7] |
4,841,501 | 4,841,502 | Trim part of html text c# without trimming a html tag | <p>I need to generate an excerpt for a piece of html text, I cant use just Substring method because I could be trimming a tag, is there a function that takes tags in to consideration so it skips until the tag ends?</p>
| c# | [0] |
2,724,832 | 2,724,833 | jQuery count that includes all chars including ENTER, etc? | <p>I know that usually you want to strip these out, but I need the true char count and I can't find out how to get it...</p>
<p>Thanks for the help</p>
| jquery | [5] |
3,198,528 | 3,198,529 | Android Developer: change version | <p>Is there a way to change the Android version on my app without redoing everything? I just realized that Nook Color only has version 1.4. Well, I have my app set at 3.2 ... so those who have the Nook Color will not be able to access it. Why on earth did I do this to myself!</p>
<p>I am using Eclipse.</p>
| android | [4] |
2,858,266 | 2,858,267 | If any textbox on page is changed, call function | <p>I know how to check if <em>one</em> textbox is changed, but what about if <em>any</em> textbox is changed?
Any ideas? </p>
| javascript | [3] |
1,773,624 | 1,773,625 | ModalPopupExtender Hiding Behind IFrame | <p>I am using an Ajax ModalPopupExtender, but when it is activated it hides behind an IFrame on my web page. If I remove the IFrame then the ModalPopupExtender is top most. Any ideas? I've seen some other posts but they didn't help. I am using ASP.NET 4.0</p>
| asp.net | [9] |
414,483 | 414,484 | Asp.net file upload to a shared location | <p>I have this load balanced asp.net application which needs to upload files to a shared location. The web app is not impersonated, which means it will cross the machine boundry using network service credentials. Now my question is, to which account do I need to assign permissions on the folder where the files are being uploaded? How can I say the network service of these web servers need write permissions?</p>
| asp.net | [9] |
2,173,795 | 2,173,796 | Making a list of User Defined Objects available throughout the application | <p>I have created some business objects which are created with the data from the database. I am doing this so that I don't want to hit the DB again and again. The business objects implements parcelable interface. So I can put the arraylist of business objects to the next activity. I am using APILevel 8 so there is no point of using SharedPreferences.editor putExtraSet. Even if I am using API level 11 or above. PutExtraSet can have only set of Strings. </p>
<p>How can I make the arrayList or some collection of business objects available for the entire application rather than forwarding from one activity to another?</p>
<p>Thanks in advance for your help.</p>
| android | [4] |
3,898,647 | 3,898,648 | Regarding swapping of widgets using jquery in php | <p>I have a drag andn drop option to be made for multiple widgets in my website. It should perform swapping, but not sorting of the images. </p>
<p>Can you suggest to me any solutions for this, with demo if possible?</p>
| jquery | [5] |
5,404,674 | 5,404,675 | Get value of dropdown in jquery | <p>How do I write a click event in jQuery that will capture the value of a dropdown? I have:</p>
<pre><code>var select = $('select #dealerName');
$(function {
select.click(function {
alert( $('#dealerName').val() );
});
});
</code></pre>
<p>I'm just trying to get the value -- that's why I'm alerting it. What would the click function look like? The id on my dropdown is "dealerName". The above is not alerting anything.</p>
| jquery | [5] |
762,548 | 762,549 | How does condition statement work with bit-wise operators? | <p>I tried to understand how if condition work with bitwise operators.
A way to check if a number is even or odd can be done by:</p>
<pre><code>#include <iostream>
#include <string>
using namespace std;
string test()
{
int i = 8; //a number
if(i & 1)
return "odd";
else
return "even";
}
int main ()
{
cout << test();
return 0;
}
</code></pre>
<p>The Part I don't understand is how the if condition work. In this case if i = 8 then the in If statement it is doing <code>1000 & 1</code> which should gives back 1000 which equal 8.</p>
<p>If i = 7, then in if statement it should be doing <code>111 & 1</code> which gives back 111 which equal 7</p>
<p>Why is it the case that if(8) will return "even" and if(7) return "odd"? I guess I want to understand what the if statement is checking to be True and what to be False when dealing with bit-wise operators.</p>
<p>Just A thought when I wrote this question down is it because it's actually doing </p>
<pre><code>for 8: 1000 & 0001 which gives 0
for 7: 0111 & 0001 which gives 1?
</code></pre>
| c++ | [6] |
660,347 | 660,348 | jQuery slideUp() only 'this' div | <p>I have this markup x 3:</p>
<pre><code> <div class="features">
<span class="overlay"><img src="img/webdesign.png" /></span>
<h2>Web Design</h2>
<p>Cow pig turkey, chuck sausage pork loin venison biltong shoulder. Shoulder pancetta short loin beef ribs, turkey corned beef shankle swine spare ribs pork chop hamburger beef brisket shank. Pork belly tenderloin brisket, strip steak ribeye bacon tail andouille shoulder t-bone flank venison chicken.</p>
</div>
</code></pre>
<p><code>Span class overlay</code> is positioned absolutely covering the h2 + P. I have three of these <code>div class features</code>. I'd like to use jQuery to when hovering over a <code>features div</code>, the overlay in that div alone slides up and when the user leaves the hover, slide the <code>overlay div</code> back down.</p>
<pre><code>$(".features").hover(
function () {
$('.overlay').slideUp();
},
function () {
$('.overlay').slideDown();
}
);
</code></pre>
<p>I have this so far, but i'm very aware it doesnt work : )</p>
| jquery | [5] |
422,206 | 422,207 | Java, Finding prime numbers | <p>My goal in this program is to list all of the prime numbers from 1 to 10000. I keep getting close changing things around and then get further. Any help would be grateful.</p>
<pre><code>public class FindPrimes {
public static void main(String[] args) {
for (int x = 0; x < 10000; x++) {
if(isPrime(x)){
}
}
System.out.println("Prime numbers < 10k:");
}
public static boolean isPrime(int num){
boolean isPrime = true;
for (int y = (num -1); y > 1; y--) {
if (num % y == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println();
}
}
}
</code></pre>
| java | [1] |
1,839,284 | 1,839,285 | How long is a piece of $string.... too long... php | <p>what am I doing wrong here guys? </p>
<pre><code> $string = "string How Long is a Piece of String?";
if $string = <5;
{
echo "string is less than 5";
}
else
{
echo "string is more than 5";
}
</code></pre>
| php | [2] |
1,090,656 | 1,090,657 | ConnectivityManager.getBackgroundDataSetting() deprecated, what to use instead? | <p>Previously one could use:</p>
<pre><code>ConnectivityManager.getBackgroundDataSetting();
</code></pre>
<p>to check if the user had background data setting = true. This method is now deprecated:</p>
<pre><code>http://developer.android.com/reference/android/net/NetworkInfo.html
</code></pre>
<p>The docs say to use:</p>
<pre><code>ConnectivityManager.getActiveNetworkInfo();
</code></pre>
<p>instead, which returns a NetworkInfo object, but what's the equivalent check in NetworkInfo then?</p>
<p>Thanks</p>
| android | [4] |
1,359,939 | 1,359,940 | missing ; after for-loop initializer | <pre><code>var nodeWordsString = document.getElementById("nodeWordsTextArea").value.trim();
var nodeWordsStringArray=nodeWordsString.split(" ");
var strLength = nodeWordsStringArray.length;
for(int i = 0; i < nodeWordsStringArray.length; i++)----->******
{
for(int j = 0; j < nodeWordsStringArray.length; j++)
{
if(nodeWordsStringArray(i) == nodeWordsStringArray(j))
{
alert("Node duplication occurred at:"+nodeWordsStringArray(i));
return false;
//break;
}
}
}
</code></pre>
<p><strong>*</strong>*showing error like <code>missing ; after for-loop initializer</code> in java script console(firebug).
please help me. </p>
| javascript | [3] |
5,368,146 | 5,368,147 | How I can monitor all Internet requests? | <p>Is there any way to monitor all requested URLs using the .NET framework classes?</p>
| c# | [0] |
933,627 | 933,628 | How do I make a different icon name for the home screen and the App Store? | <p>How do I make a different icon name for the home screen and the App Store in iPhone?</p>
| iphone | [8] |
268,524 | 268,525 | How to get the length of an array in c++? | <p>I tried to write my own function for this, but I get wrong result</p>
<pre><code>#include <iostream>
using namespace std;
template<typename T>
int array_length(T v[]) {
return (sizeof v)/sizeof(T);
}
int main() {
int v[] = {1, 2, 3, 4};
cout << array_length(v) << endl;
return 0;
}
</code></pre>
| c++ | [6] |
6,025,694 | 6,025,695 | Java arrays in methods | <p>I'm making a method that take a list of arrays and finds the average of the numbers.
I know that my method works since I just moved it from my main method to the "average" method. I'm just having problems getting the array to work with the method. </p>
<p>I'm not sure if I'm wrong by calling the method by <code>average(a);</code>, or if it's because the method is written as <code>public static void average(double[] a){</code> </p>
<p>Could someone point me to the right direction?</p>
<pre><code>public class Ass10{
public static void main(String[] args) {
System.out.println("asdf");
int a[] = {1, 2, 3,4};
average(a);
}
public static void average(double[] a){
int sum = 0;
for (int counter = 0; counter<a.length;counter++){
sum += a[counter];
}
System.out.println(sum/a.length)
}
</code></pre>
| java | [1] |
623,257 | 623,258 | How to set the value for an HTML element from external javascript | <p>I'm using an external javascript file (eg:<code>myjs.js</code>) with function <code>setval()</code> to set the <code>innerText</code> property of a HTML lable.</p>
<p>I have PHP page with <code><lable id="abc"></lable></code> and I have included <code>myjs.js</code> in <code><head></code> section. <code>myjs.js</code> is included in <code><head></code> section of one more PHP file and I'm calling <code>setval()</code> from this file, so when it runs it must set the <code>innerText</code> of lable in the first PHP file.</p>
<p>Is it possible to achieve? Any suggestions are greatly appreciated.
I hope I made question clear.</p>
<p>Thanks</p>
| javascript | [3] |
3,062,949 | 3,062,950 | Where should private methods be placed when using the JavaScript Module pattern? | <p>I've started using the Module pattern in a project of mine. As I understand it, it goes something like this:</p>
<pre><code>var obj = (function(foo){
//Some initialization logic up here.
//Private methods
var privateBazz = function(){
return "I'm known only to this closure!";
}();
//Public methods
return {
publicFoo: foo,
publicBar: function(){
return foo + privateBazz;
}
}
})();
</code></pre>
<p>This looked pretty good on paper and, in practice, seems to work reasonably well. Initialization logic at the top is intuitive, then private methods, then public. </p>
<p>I've encountered one issue, though. How should I call publicFoo or publicBar from outside the scope of the return statement and inside the scope of obj's function declaration? </p>
<p>My current solution is to do something like:</p>
<pre><code>var obj = (function(foo){
//Private methods declared early for use.
var privateBazz = function(){
return "I'm known only to this closure!";
}();
var privateBar = function(){
return foo + privateBazz;
};
//Some initialization logic up here.
var dependentOnBar = privateBar();
//Public methods
return {
publicFoo: foo,
publicBar: privateBar
}
})();
</code></pre>
<p>This works, but suddenly the declarations of my private variables are placed above my objects private property declarations. The problem becomes exacerbated if I attempt to keep the private function declarations as close to the code which first calls them, so I have just been declaring all the private functions I need at the top, then initializing properties afterwards. Again, this works, but I am used to having code as close to the execution point as possible. So, declaring blocks of private functions at the top is really awkward to me. Does anyone else feel this way, or is this something I just need to get over for JavaScript? Are there any steps I should be taking when I see this happening?</p>
| javascript | [3] |
5,231,938 | 5,231,939 | Static Way to get Context on android? | <p>Is there a way to get the current Context instance by using a static method? </p>
<p>I'm looking for that way because i hate saving the context instance each time it changes.</p>
| android | [4] |
1,965,611 | 1,965,612 | cant open sms conversation wid incoming number | <p>hey guys check out my code...</p>
<p>whenever a text comes and i click on the notification ,,, the person or number with whom i exchanged texts earlier...that conversation appears and it doesnot opens the conversation with the new number .... how can i solve it...?</p>
<p>int icon = R.drawable.messageicon;</p>
<pre><code> CharSequence tickerText = from + ": " + body;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon,
tickerText, when);
CharSequence contentTitle = from;
CharSequence contentText = body;
// Intent notificationIntent = new
// Intent(context,SMS.class);
/* Show the Notification containing the Message. */
notificationIntent
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.putExtra("address",
messages[i].getOriginatingAddress());
notificationIntent.setType("vnd.android-dir/mms-sms");
PendingIntent contentIntent = PendingIntent
.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle,
contentText, contentIntent);
notification.defaults=Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(1, notification);
}
</code></pre>
| android | [4] |
2,616,975 | 2,616,976 | How do you set the max number of characters for an EditText in Android? | <p>How do you set the max number of characters for an Android EditText input. I see setMaxLines, setMaxEMS, but nothing for number of characters.</p>
| android | [4] |
842,815 | 842,816 | Script only picking up first 3 letter | <p>Im using the following script in conjunction with a autocomplete script to search my db. If I put in the letter a for example it is finding all the ID's with an a. I want to change it so by typing the letter a it will only bring up data in the id field that begings with the letter a. </p>
<pre><code><?php
require('json.php');
error_reporting(E_ALL);
mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("timetable") or die("No such database");
$sql = sprintf("SELECT id,dsc FROM module WHERE id LIKE '%%%s%%'",
mysql_real_escape_string($_REQUEST['term']));
$result = mysql_query($sql)
or die(mysql_error());
$all = array();
while ($row = mysql_fetch_array($result))
$all[] = array('value'=>$row[1],'label'=>$row[1]);
print json_encode($all);
?>
</code></pre>
| php | [2] |
2,486,845 | 2,486,846 | JavaScript Date Function | <p>I'm using the following function that changes a calendar selection at a set time during the day (all code works perfectly).
However, I'd like to modify it slightly so that on a SATURDAY the dd=dd+1 becomes dd=dd+2, because I want to skip Sunday. Can anyone help?</p>
<pre><code>$(function() {
var dd = 0
if (<%= currentHour %> > <%= cutoffHour %>) {
dd = dd + 1; // go one day in the future
}
</code></pre>
| javascript | [3] |
3,624,929 | 3,624,930 | AlarmManager.RTC not working? | <p>I changed AlarmController.java in ApiDemo a little bit, so I want the alarm not to go off when the phone is sleeping by using AlarmManager.RTC.</p>
<pre><code> Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
0, intent, 0);
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
firstTime += 15*1000;
// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC, //AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, 15*1000, sender);
</code></pre>
<p>The receiver code is like below:</p>
<pre><code>public class RepeatingAlarm extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("DEBUG", "In RepeatingAlarm.onReceive, intent=" + intent);
Toast.makeText(context, R.string.repeating_received, Toast.LENGTH_SHORT).show();
}
}
</code></pre>
<p>I ran the modified app, but I still see many log messages as below after the phone wento sleep (the screen was black):</p>
<p>D/DEBUG ( 1390): In RepeatingAlarm.onReceive, intent=Intent { flg=0x4 cmp=com.example.android.apis/.app.RepeatingAlarm (has extras) }</p>
<p>This means the flag AlarmManager.RTC didn't work. Can someone tell me why?</p>
<p>Thanks.</p>
| android | [4] |
3,815,350 | 3,815,351 | Iphone displaying the data in word format | <p>A call to a webservice returns to me a byte[] which I would like to display in word format on the iphone. </p>
<p>How can I achieve this?
Which view i can use to display the view? </p>
<p>Please provide code samples if possible. Thanks in advance. Please answer as soon as possible. </p>
| iphone | [8] |
727,771 | 727,772 | How to split a sentence into two separate arrays | <pre><code>String input0 = "G1 and G2 are the founders of Microsoft.";
String input1 = "The swimming medals were won by G1 and G2";
</code></pre>
<p>I would like to parse the above strings and create 2 separate arrays (Note: G1, G2, G3, ... are placeholders for user input and would like to get them separately)</p>
<pre><code>e.g. for input0 the following arrays should be created array0 [G1, G2] and array1 [" and ", " is the founder of Microsoft."]
e.g for input1 the following arrays should be created array0 [G1, G2] and array1 ["The swimming medals were won by ", " and "]
</code></pre>
<p>I've tried using <code>indexOf</code> functions and <code>split</code>, but haven't been able to get it working properly so far.</p>
| java | [1] |
3,485,156 | 3,485,157 | What is the name of the "onload" event? | <p>I've a textarea that has <code>keyup</code> event to show a preview of rendered input. However, I want to display the same preview immediately after the element is loaded.</p>
<pre><code>$('textarea[name="ay[description]"]').on('keyup', function(e){
</code></pre>
<p>The simplest of all is to initiate <code>.trigger('keyup')</code> at the end of the declaration. However, isn't there event such as <code>load</code>, <code>onload</code> or <code>ready</code> that I've missed under different name?</p>
| jquery | [5] |
3,326,326 | 3,326,327 | How to compare value or keys in the hash table? | <p>Suppose I have code </p>
<pre><code>public static void main(String args[])
{
Hashtable ht = new Hashtable();
Hashtable ht2 = new Hashtable();
for(int i=0;i<100;i++)
{
ht.put(i, new Integer (i));
}
for(int i=50;i<100;i++)
{
ht2.put(i, new Integer (i));
}
}
</code></pre>
<p>If I wanted to compare the two different hashtable, how would I go about to do this in Java? EDIT: if I wanted to compare key or the actual value in the hashtable</p>
| java | [1] |
4,835,213 | 4,835,214 | Do templates shorten the size of source or binary or both | <p>I read that templates are complied into different entities so does that mean the binary size will be same as we have complied it using different functions?</p>
| c++ | [6] |
1,984,993 | 1,984,994 | Cancel jquery auto refresh timer | <p>I am using the following script to refresh a div once every minute.</p>
<pre><code>var auto_refresh = setInterval(
function() { $('#posting').load('posts.php').fadeIn("slow"); }, 60000);
</code></pre>
<p>It works great, just as it should. My question is, is there a way that I can cancel that refresh when a user clicks on a particular link on the site. I have a comments section and when they click on View More Comments, i'd like for the site to not auto refresh anymore since that will mess up what they are looking at.</p>
| jquery | [5] |
25,769 | 25,770 | Self-referencing anonymous closures: is JavaScript incomplete? | <p>Does the fact that anonymous self-referencing function closures are so prevelant in JavaScript suggest that JavaScript is an incomplete specification? We see so much of this:</p>
<pre><code>(function () { /* do cool stuff */ })();
</code></pre>
<p>and I suppose everything is a matter of taste, but does this not look like a kludge, when all you want is a private namespace? Couldn't JavaScript implement packages and proper classes?</p>
<p>Compare to ActionScript 3, also based on EMACScript, where you get</p>
<pre><code>package com.tomauger {
import bar;
class Foo {
public function Foo(){
// etc...
}
public function show(){
// show stuff
}
public function hide(){
// hide stuff
}
// etc...
}
}
</code></pre>
<p>Contrast to the convolutions we perform in JavaScript (this, from the <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">jQuery plugin authoring documentation</a>):</p>
<pre><code>(function( $ ){
var methods = {
init : function( options ) { // THIS },
show : function( ) { // IS },
hide : function( ) { // GOOD },
update : function( content ) { // !!! }
};
$.fn.tooltip = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
</code></pre>
<p>I appreciate that this question could easily degenerate into a rant about preferences and programming styles, but I'm actually very curious to hear how you seasoned programmers feel about this and whether it feels natural, like learning different idiosyncrasies of a new language, or kludgy, like a workaround to some basic programming language components that are just not implemented?</p>
| javascript | [3] |
5,686,905 | 5,686,906 | twisted c++ code | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/4176328/faq-undefined-behavior-and-sequence-points">FAQ : Undefined Behavior and Sequence Points</a> </p>
</blockquote>
<pre><code> #include< iostream.h>
int main()
{
int i=7,j=i;
j=(i++,++i,j++*i);
cout <<j;
return 0;
}
</code></pre>
<p>what will be output of the c++ code? Its my homework that my professor gave me.</p>
| c++ | [6] |
2,829,629 | 2,829,630 | Storing data in the app sandbox - what if the user runs out of space? | <p>I am storing some images locally in my app's sandbox. I currently have the minimum set at 10MB, and will be allowing the user to choose how much storage is allowed (up to 500MB).</p>
<p>In the scenario that the app is installed on a device where there's simple no space on it, or if there's 1MB space left and I start saving a 2MB image what happens?</p>
| iphone | [8] |
5,176,798 | 5,176,799 | Will a nested function always have to be redefined? | <p>For architecture and namespacing purposes, I want to do this:</p>
<pre><code>function outer (arr) {
function inner(arrElement) {
return doStuffTo(arrElement);
}
var results = [];
arr.forEach(element, index, array) {
results.push(inner(element));
}
return results;
}
</code></pre>
<p>So basically, a function within a function. Simple stuff. But <code>outer()</code> is something that will be executed <em>a lot</em>. Does this mean the overhead of defining a function (on top of evaluating it) will apply every time <code>outer()</code> is called? For this to be efficient, must I define <code>inner()</code> outside?</p>
| javascript | [3] |
4,283,183 | 4,283,184 | Problem in Internationlization | <p>I have a requirement where my UI should be shown in 5 different languages apart from english. </p>
<p>I have created two DLLs </p>
<p>1) Component.dll
2) Component.resources.dll</p>
<p>Component.resources.dll contains nothing but all the strings that are shown in the UI and a class </p>
<p>public class PResources
{
private static System.Resources.ResourceManager resourceMgr = new System.Resources.ResourceManager(typeof(PEditResources));</p>
<pre><code> /// <summary>
/// Get NLS String method string method
/// </summary>
/// <param name="identifier"></param>
/// <returns></returns>
public static string GetNLSString(string identifier)
{
return resourceMgr.GetString(identifier, Thread.CurrentThread.CurrentUICulture);
}
/// <summary>
/// Returns the NLS Resource Mgr.
/// </summary>
/// <returns></returns>
public static System.Resources.ResourceManager GetNLSResourceMgr()
{
return resourceMgr;
}
</code></pre>
<p>}</p>
<p>In Component.dll to display the label text i use the following </p>
<p>label1.text = PResources.GetNLSString("IDS_LABEL1");</p>
<p>In english it works fine...
But when the language settings is changed to French or any other the string displayed is still the English text. </p>
<p>Note: The Component.Resources.dll strings are translated in all languages. </p>
<p>When i debugged... i found that the GetNLSString function the Thread.Current.UICulture is french ... but the resourceMgr object is still pointing to the englis dll path and also the Thread.Current.Culture is English! </p>
<p>Is there any solution to this ? have i missed anything. </p>
| c# | [0] |
5,996,671 | 5,996,672 | php - problem with set_error_handler | <p>I'm trying to setup a custom landing error page in the event there is php errros, I'm using:</p>
<pre><code>function xhandler($number,$string,$file,$line,$context){
include('/path/to/error_text_page.tpl');
exit;
}
error_reporting(E_ALL ^ E_NOTICE);
set_error_handler('xhandler',E_ALL ^ E_NOTICE);
</code></pre>
<p>This isn't working though, anyone know what I'm doing wrong?</p>
| php | [2] |
2,260,749 | 2,260,750 | The application RCApps (process com.examples) has stopped unexpectantly | <p>My application was running fine but then I got the error and tried to re run the API, clean the build but nothing worked. When lookied into the logcat error found two errors with which I could find a solution for. The following are the errors. </p>
<p>11-08 21:50:09.981: ERROR/AndroidRuntime(352): Caused by: java.lang.ClassNotFoundException: android.view.Relativelayout in loader dalvik.system.PathClassLoader[/data/app/com.examples-1.apk]</p>
<p>11-08 21:50:09.981: ERROR/AndroidRuntime(352): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class Relativelayout</p>
<pre><code> The following is the contents of my class:
public class Vathiyar extends Activity{
private Button findvathiyar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vathiyar);
}
}
Following is my xml code..
<?xml version="1.0" encoding="utf-8"?>
<Relativelayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vathiyar_1"
android:orientation = "vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/widget32"
android:layout_width="wrap_content"
android:layout_height="-11px"
android:text="Welcome to the Selection of Vathiyar page"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
>
</TextView>
</Relativelayout>
</code></pre>
| android | [4] |
4,744,413 | 4,744,414 | using no conflict with jquery | <p>I need to use noconflict in my web site,but i think there is a problem.Here is my code :</p>
<pre><code>calling... src="jquery-1.7.2.min.js"
var jQuery_1_7_2 = jQuery.noConflict(true);
(function($){
$(window).load(function () {
$("#content_1").mCustomScrollbar({
advanced:{
updateOnContentResize: true
},
scrollButtons: {
enable: true
}
});
});
})(jQuery_1_7_2);
</code></pre>
<p>Where am i wrong?
Thanks.</p>
| jquery | [5] |
2,452,996 | 2,452,997 | How to find offsetWidth with a multiline element? | <p>I've built a tooltip where I calculate the position for the tooltip from the hovered element's offsetWidth and offsetHeight, that works great with one exception: When the element which is to be hovered over runs down onto the next line the elements offsetWidth becomes much larger and therefore sends the tooltip the width length away from the element. </p>
<p>Whats the best way to handle that? I'd like to avoid repositioning the tooltip to where the mouse is as that wouldn't be as aesthetically appealing and would be a larger re-factor.</p>
<p>Note: Javascript only, no jQuery please.</p>
| javascript | [3] |
353,437 | 353,438 | How to get document object through window? | <p>the scenario is window is passed as a parameter to a function , and I also need to use the document of the window for searching element in the function. No idea about how to get the document object through $(winObjParamter).winObjParamter is the parameter passed to the function.</p>
| jquery | [5] |
334,624 | 334,625 | The method putExtra(String, String) is undefined for the type PendingIntent | <p>whether it's possible to use putExtra method in pendingintent</p>
| android | [4] |
3,982,976 | 3,982,977 | How to add event in calendar date box? | <p>I have to make event show in box of date in calendar with color in background.But i don't know how to display it.What i have to use?What is logic for it?</p>
| iphone | [8] |
2,224,147 | 2,224,148 | Remove disabled attribute onClick of disabled form field | <p>I have a form field that starts out disabled and has an onClick to enable it. The onClick doesn't fire (at least in FF) nor does a simple alert(1);.</p>
<p>The hacky version is to show a fake form field in its place that "looks" like it's disabled (grayed out style) and onClick, hide it and show the correct field enabled, but that's ugly.</p>
<p><strong>Example Code</strong></p>
<p>This works:</p>
<pre><code><input type="text" id="date_end" value="blah" onClick="this.disabled=true;">
</code></pre>
<p>This works:</p>
<pre><code><label for="date_end_off" onClick="document.getElementById('date_end').disabled=false">Test</label>
<input type="text" id="date_end" value="blah" onClick="alert(1);" disabled>
</code></pre>
<p>This fails:</p>
<pre><code><input type="text" id="date_end" value="blah" onClick="alert(1);" disabled>
</code></pre>
<p>This fails:</p>
<pre><code><input type="text" id="date_end" value="blah" onClick="document.getElementById('date_end').disabled=false" disabled>
</code></pre>
| javascript | [3] |
1,379,871 | 1,379,872 | Is there a way to add error checking to a stylesheet background image loader in Javascript? | <p>I'm using a background image in a div and want to have the div behave differently depending on whether the image loads or not.</p>
<p>So, rather than doing img.onerror | img.onload
I want to do style.backgroundImage.onerror or something along those lines</p>
<p>this isn't possible, is it?</p>
| javascript | [3] |
210,488 | 210,489 | How to work with virtual key board in android(catch event on keys which display Toast after press) | <p>i am doing R&D on virtual key board (How to catch key event),but no more success found
i got only few things about virtual key board</p>
<p>we need to implements</p>
<p><code>onKeyboradActionListener</code></p>
<pre><code>/* and these override methode*/
public void onKey(int primaryCode, int[] keyCodes) {
// TODO Auto-generated method stub
}
@Override
public void onPress(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onRelease(int primaryCode) {
// TODO Auto-generated method stub
}
</code></pre>
<p>if any one know this share his knowledge</p>
| android | [4] |
1,220,541 | 1,220,542 | show text view and edit text in row | <p>show text view and edit text in row in linear layout </p>
| android | [4] |
3,410,998 | 3,410,999 | Iterating over os.walk in linux | <p>We have multiple linux server and i would like to get all the details of files and directories in a particular linux server. I know this can be done with os.walk function but it is storing only single file information. Please find the below code</p>
<pre><code>import os
for d in os.walk('/'):
F = open('/home/david/Desktop/datafile.txt', 'w')
F.write(str(d) + '\n')
F.close()
</code></pre>
<p>Thanks in advance</p>
| python | [7] |
2,085,163 | 2,085,164 | Code Contract C# ensure value is in array | <p>This is most likely very simple but I can't seem to figure it out:)</p>
<p>I have 2 arrays of int.
I want to make sure one value is in both arrays using code contracts in some form.
If the value is not both arrays I don't want to continue</p>
<p>Can this be done?
I was thinking of something like this but can't seem to get it to work</p>
<pre><code>Contract.Requires(g[variable ] == y[variable])
</code></pre>
<p>The value must be in the same posion in both arrays</p>
<p>This is what I have now</p>
<pre><code> private static int FirstCut(int[] g, int[] h)
{
int x = 0;
Contract.Requires(g.Length > 0);
Contract.Requires(g.Length == h.Length); //skal være lige lange
while (g[x] != h[x])
{
x++;
}
return x;
}
</code></pre>
<p>Regards </p>
<p>Birger</p>
| c# | [0] |
4,871,070 | 4,871,071 | How can I customize an iPhone first launch experience based on specific users? | <p>I am trying to make my app automatically load specific content for a user upon the first launch.</p>
<p>For example, if a user is searching for information on product X via Safari, I would like to give them a referral to download my app in iTunes. After download, I would then like the app to automatically load screens relevant to product X without the user entering that info in themselves.</p>
<p>It seems that since apps are sandboxed they wouldn't have access to Safari cookies, as this would otherwise be the perfect solution. Any advice?</p>
| iphone | [8] |
5,018,386 | 5,018,387 | including (STL) header files in a header | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/4416765/reincluding-header-in-implementation">reincluding header in implementation</a> </p>
</blockquote>
<p>What I am wondering is that it is common practice to not use <code>using namespace xxx</code> in a header file as not to pollute the global namespace.
How does this go for <code>#includes</code>?</p>
<p>If I have <code>foo.h</code> and <code>foo.cpp</code>.:</p>
<pre><code>//Foo.h
#ifndef FOO_H_
#define FOO_H_
#include <string>
class Foo
{
public:
Foo(std::string * a, std::string * b);
virtual ~Foo();
};
#endif /* FOO_H_ */
//Foo.cpp
#include <string>
#include <Foo.h>
Foo::Foo(std::string * a, std::string * b)
{
// TODO Auto-generated constructor stub
}
Foo::~Foo()
{
// TODO Auto-generated destructor stub
}
</code></pre>
<p>Would I really need to <code>#include <string></code> in both files? Would including it only in the .h or .cpp suffice? (I know both will work, but what is advisable?)</p>
<hr>
<p>edit, a bit more background information regarding my question.<br>
If I would be using certain classes in my header file (either as variables or method arguments) I would forward declare them in the header file and only include the header file itself in the source file. But this will not work for most STL libs because you can't forward declare class-templates?</p>
| c++ | [6] |
4,445,112 | 4,445,113 | jQuery animate help | <p>This isn't working. I'm trying to replicate the animate to red and then remove effect as in the WordPress admin. The element gets removed, but it doesn't animate before that. </p>
<pre><code>$('.delete-item').live('click', function(){
$(this).parent().parent().animate({backgroundColor: '#ff0000'}, 'slow').empty().remove();
});
</code></pre>
| jquery | [5] |
1,482,130 | 1,482,131 | Auto pointer for unsigned char array? | <p>I'd need a class like std::auto_ptr for an array of unsigned char*, allocated with new[]. But auto_ptr only calls delete and not delete[], so i can't use it.</p>
<p>I also need to have a function which creates and returns the array. I came out with my own implementation within a class ArrayDeleter, which i use like in this example:</p>
<pre><code>#include <Utils/ArrayDeleter.hxx>
typedef Utils::ArrayDeleter<unsigned char> Bytes;
void f()
{
// Create array with new
unsigned char* xBytes = new unsigned char[10];
// pass array to constructor of ArrayDeleter and
// wrap it into auto_ptr
return std::auto_ptr<Bytes>(new Bytes(xBytes));
}
...
// usage of return value
{
auto_ptr<Bytes> xBytes(f());
}// unsigned char* is destroyed with delete[] in destructor of ArrayDeleter
</code></pre>
<p>Is there a more elegant way to solve this? (Even using another "popular" library)</p>
| c++ | [6] |
2,957,985 | 2,957,986 | problem in performSelectorOnMainThread in iphone | <p>i did this <pre><code>
[(OfficeLinQViewController*)sharedManager.m_o performSelectorOnMainThread:@selector(findLocalListing::)
withObject:(folderList,path)
waitUntilDone:NO];</code></pre>
but the problem is that in findLocalListing function in both the arguments path is saved not folderList.</p>
| iphone | [8] |
2,655,392 | 2,655,393 | looping lists in java | <p>I have a simple java statement along the lines of:</p>
<pre><code> String[] ykl = yklList.get(0).split(" ");
</code></pre>
<p>where, yklList is an ArrayList containing sentences which are split into words. The above works fine.</p>
<p>When I now try and loop this:</p>
<pre><code>Loop:1
for (int i=0;i<=4;i++)
{
String[] ykl = yklList.get(i).split(" ");
}
</code></pre>
<p>It does not seem to work and throws me a compile error. Is the above loop wrong?</p>
<p>I have another for loop after the above:</p>
<pre><code>Loop:2
for (String ykl : yklList)
{
//do something
}
</code></pre>
<p>It throws me a compile error here saying:</p>
<pre><code>cannot find symbol
symbol : variable ykl
location: class test
for (String ykl : yklList)
</code></pre>
<p>Presumably Loop 1 went wrong somewhere?</p>
<p><strong>Edit:</strong></p>
<p>The "full" code looks something like this:</p>
<pre><code>for (int i=0;i<=yklList.size()-1;i++)
{
String[] ykl = yklList.get(i).split(" ");
}
for (String y : ykl)
{
t.add(y);
}
</code></pre>
<p>and the error is:</p>
<pre><code>cannot find symbol
symbol : variable ykl
location: class test
for (String y : ykl)
</code></pre>
| java | [1] |
4,399,362 | 4,399,363 | Dynamically open php file and check if class extends abstract class (for custom module) | <p>I have an admin process that scans some directories and files to see if certain php files extend an abstract class. So I have a directory structure as follows.</p>
<pre><code>/models
/models/Random.php
/models/Payment/Abstract.php
/models/Payment/Cash.php
/models/Payment/Credit.php
/models/Payment/Cheque.php
</code></pre>
<p>cash.php, credit.php and cheque.php extends abstract.php which are named as MyApp_Payment_Cash, MyApp_Payment_Credit, MyApp_Payment_Cheque.php and MyApp_Payment_Abstract.
I need to produce an array that is <code>array('Cash', 'Credit', 'Cheque');</code>. I have code as follows:</p>
<pre><code>$aModules = array();
foreach (new DirectoryIterator(APPLICATION_PATH . '/models/Payment') as $oFile) {
if (preg_match('/^(.*)\.php$/', $oFile->getFileName(), $aMatches)) {
$sName = sprintf('MyApp_Payment_%s', $aMatches[1]);
if ($sName instanceof MyApp_Payment_Abstract) {
$aModules[] = $sName;
}
}
}
</code></pre>
<p>But that obviously doesn't work (instanceof doesn't work this way on strings). I tried also tried try... catch on <code>new $sName()</code> but PHP threw a fatal when it tried <code>new MyApp_Payment_Abstract</code>.</p>
<p>As you might gather I'm trying to build an extendable payment system that allows new payment methods to be added in the future.</p>
<p>I could change my regex to something like <code>/^(?!Abstract|.*)\.php$/</code> but that seems a rather blunt instrument for a true test.</p>
| php | [2] |
1,569,835 | 1,569,836 | Null Reference in file | <p>I am getting and error on this line:</p>
<pre><code>String selectedValue = this.employeeList.SelectedValue.ToString();
</code></pre>
<p>The error I am getting is </p>
<blockquote>
<p>NullReferenceException was unhandled. </p>
</blockquote>
<p>What does this mean? Can someone help me understand why I am getting this error. Down below is the whole code.</p>
<pre><code>String filePath = this.txtFilePath.Text;
if (!String.IsNullOrEmpty(filePath))
{
MessageBox.Show("No file path specified");
}
if (this.employeeList.SelectedIndex != -1)
{
String selectedValue = this.employeeList.SelectedValue.ToString();
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine(selectedValue);
}
}
else
{
MessageBox.Show("No item selected");
}
</code></pre>
| c# | [0] |
293,796 | 293,797 | Money Transaction without using in-app purchase for iphone app | <p>I want to implement the payment gateway like functionality in my iphone application other than In-App Purchase feature provided by Apple. </p>
<p>So, i have one Question regarding the application approval on Appstore that, if i will redirect user to the UIwebview for payment related functionality, then apple will reject this application for not following the human interface guideline or it will allow this.</p>
<p>Other way i can do it by calling web-service for the transaction of money. So, again there is any chance of app rejection on AppStore.</p>
<p>Please share your thought on this</p>
| iphone | [8] |
3,466,242 | 3,466,243 | Application exits with segmentation fault when Terminated | <p>I receive following error in console when I terminate my application forcefully.Could someone suggest what could be reason behind this.No crash report is generated for this.</p>
<pre><code>Fri Feb 25 09:41:33 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.xyz.gps[0xf9a]) Bug: launchd_core_logic.c:3252 (24226):3
Fri Feb 25 09:41:33 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.xyz.gps[0xf9a]) Bug: launchd_core_logic.c:2681 (24226):10
Fri Feb 25 09:41:33 unknown com.apple.launchd[1] <Notice>: (UIKitApplication:com.apple.xyz,gps[0xf9a]) Working around 5020256. Assuming the job crashed.
Fri Feb 25 09:41:33 unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.apple.xyz.gps[0xf9a]) Job appears to have crashed: Segmentation fault
Fri Feb 25 09:41:33 unknown SpringBoard[27] <Warning>: Application 'GpsDemo' exited abnormally with signal 11: Segmentation fault
</code></pre>
| iphone | [8] |
2,460,676 | 2,460,677 | Const Overloading: Public-Private Lookup in C++ Class | <p>The following code does not compile, saying " error C2248: 'A::getMe' : cannot access private member declared in class 'A'". Why? I am trying to call the public interface. </p>
<pre><code>class B
{
};
class A
{
public:
const B& getMe() const;
private:
B& getMe();
};
int main()
{
A a;
const B& b = a.getMe();
return 0;
}
</code></pre>
| c++ | [6] |
90,690 | 90,691 | checking of whether clicked+Jquery | <p>I'm new to JQuery
In my App, I have some 5 divs. While clicking any one of the div, I want to check whether any other divs have been clicked before</p>
<p>Actually in my code I have </p>
<pre><code>Text
Textarea
Dropdown
</code></pre>
<p>while clicking on Text/textarea/dropdown for the first time (i.e. I need to check whether any of the others including its own has been clicked before) so that I can proceed based on that.</p>
<p>Even if I use what you said having a variable=1 there arose an issue that while clicking on any of text/textarea/dropdown, I want to check whether the one I'm clicking and the others have clicked before.</p>
| jquery | [5] |
635,123 | 635,124 | php2connect, encrypt and workaround | <p>I have used this script, but it is not serving me well anymore. I have to visit mysite.com/serv.php to call the script. So, first here is the script:</p>
<pre><code>$ip = "ip";
$user = "user";
$pass = "password";
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect($ip, 22))){
echo "<font color='red'>fail: unable to establish connection</font>\n";
} else {
if(!ssh2_auth_password($con, $user, $pass)) {
echo "fail: unable to authenticate";
} else {
echo "Sucessful";
if (!($stream = ssh2_exec($con, "/home/boza/serv.sh" ))) {
echo "fail: unable to execute command";
} else {
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream,4096)) {
$data .= $buf;
}
fclose($stream);
}
}
}
</code></pre>
<p>The script works well, but I want to have some changes in it.
1. I would like to add md5 hash into it, to make it more secure
2. I would like for the script to not be executed when visiting serv.php, but by pressing a button to make an ajax call.
3. I would like there to be user feedback, like "sucessful" or "fail"... like I did now, with live ajax or something without refreshing site.</p>
<p>I have googled and I have tried to put md5('xxxx') into the script, I have got a weird errors and I'm sure I was doing something wrong.</p>
<p>Could someone help me with this case please?</p>
| php | [2] |
5,405,848 | 5,405,849 | run multiple webservices at a time | <p>I have written a webservice which is taking URL as an input and producing a JSON respone. My problem is that now I have list of 1000 URLs and want to execute maximum threads of Webapplications to get output. Like I want to execute 100 instances of webservice at a time to get response.Please can anybody give some guidance how can I do it using java.
Thank you in advance</p>
| java | [1] |
4,566,019 | 4,566,020 | How to set the properties of a file to 0777? | <p>How can I set the properties of a file to 0777 which i created through php create file?</p>
<pre><code>$myFile = "test.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = 'test';
fwrite($fh, $stringData);
fclose($fh);
</code></pre>
| php | [2] |
2,100,236 | 2,100,237 | How to Modify DateFormatSymbols month values | <p>I am trying to add specific month names for a particular locale.
The issue I have is with locale for norwegian bokmal (nb) the names of the months returned by SimpleDateFormat are in English not norweigan. However it seems that locale (no) works fine </p>
<p>e.g. This code results in January, February, etc.</p>
<pre><code>String pattern = "MMMM";
DateFormat monthFormat = new SimpleDateFormat(pattern, new Locale("nb"));
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 12; i++) {
cal.set(Calendar.MONTH, i);
System.out.println(monthFormat.format(cal.getTime()));
}
</code></pre>
<p>vs this code which results in Januar, Februar etc </p>
<pre><code>String pattern = "MMMM";
DateFormat monthFormat = new SimpleDateFormat(pattern, new Locale("no"));
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 12; i++) {
cal.set(Calendar.MONTH, i);
System.out.println(monthFormat.format(cal.getTime()));
}
</code></pre>
<p>I know I can configure SimpleDateFormat with a specific DateFormatSymbols however this doesn't help keep my code generic for any future locals. I was wondering if anyone knows how to modify the default month values for a supported java locale? I figured there would be a resource file I could add but couldn't figure out how.</p>
| java | [1] |
266,008 | 266,009 | Is PHP compiled or interpreted? | <p>Is PHP compiled or interpreted?</p>
| php | [2] |
5,855,974 | 5,855,975 | Array spinner selection | <pre><code>int nvalue=2;
Spinner[] spinner = new Spinner[nvalue];
spinner[].setonitem?
</code></pre>
<p>I have the array of spinner and I want to use <code>setOnItemSelectedListener</code> for every spinner.How can I use <code>setOnItemSelectedListener</code> for array spinner?</p>
<pre><code>spinner[0].setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3)
{
}
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
</code></pre>
<p>will shows error</p>
| android | [4] |
2,599,855 | 2,599,856 | How do I get this expression Chr$(&H8) in Javascript | <p>How do I get this expression Chr$(&H8) in Javascript. I need to get this escape code in Javascript</p>
<pre><code>sCmd = Chr$(&H8) + Chr$(&H2)
</code></pre>
<p>Thanks a lot.</p>
| javascript | [3] |
5,021,331 | 5,021,332 | Unable to understand this python code | <p>I was reading about python functions
and saw this code:</p>
<pre><code>def happyBirthday(person):
print("Happy Birthday to you!")
print("Happy Birthday to you!")
print("Happy Birthday, dear " + person + ".")
print("Happy Birthday to you!")
happyBirthday('Emily')
happyBirthday('Andre')
</code></pre>
<p>I couldn't understand why these brackets were being used
for the print commands and so I removed them.</p>
<pre><code>def happyBirthday(person):
print "Happy Birthday to you!"
print "Happy Birthday to you!"
print "Happy Birthday, dear " + person + "."
print "Happy Birthday to you!")
happyBirthday('Emily')
happyBirthday('Andre')
</code></pre>
<p>Even after removing those brackets I am getting
the exact same results, so I am not sure which one is correct
or whether I should use those brackets at all.
Is it really necessary to use those brackets?</p>
<p>One more thing.
when I use the brackets then the <code>+person+</code> gives
the result as Happy Birthday, dear Andre.
but when I use <code>,person,</code> then it gives
the result as <'Happy Birthday,dear ',' 'Andre','.'></p>
<p>I am unable to understand these differences in the results.
Could you shed some light on this?</p>
| python | [7] |
4,320,459 | 4,320,460 | How to split my treeview single row into 2 r 3 rows in ASP.NET (Web Application) | <p><strong>EXAMPLE:</strong> some bla bla goes here</p>
<p>1.Kalaiselvan(<strong>Parent node</strong>)</p>
<p>1.1 kalai is from india and he lives in tamilnadu(1988-2011),klaisewkkladslh kjkhlghjg khkgl.</p>
<p>1.2.scales related to single book some thing goes like that and huge text goes here</p>
<p>2.kannan(Parent node)</p>
<p>2.1 kannan is a gud man and he is a brother of kalaiselvan jghkljg hkjlgh tyugkjhg ghjgglkl.</p>
<p>2.2 there are some problems to split the nodes of single treeview rows into 2 r 3 rows. </p>
<p>I need to split that 1.1,1.2,2.1,2.2 nodes into atleast 2 r 3 rows..</p>
<p><strong>Note: Am using sql server as back-end..these nodes r fetched from sql server oly</strong></p>
<p>Thanks.</p>
| asp.net | [9] |
3,692,608 | 3,692,609 | Single threaded OpenGL ES Android application | <p>I'm trying to create single threaded OpenGL application for Android like in <a href="http://groups.google.com/group/android-developers/browse_thread/thread/16a2216b39513674#" rel="nofollow">this</a> example.</p>
<p>But when I added onTouchEvent, onKeyDown and onKeyUp methods in the activity class, application starts to work very slowly.</p>
<p>Also I tried to add sleep(20) into the onDraw method, but it didn't help.</p>
<p>Please, tell, how I should to organise my single threaded OpenGL app?</p>
| android | [4] |
1,776,798 | 1,776,799 | Is there a "best" way to do something in Python | <p>I'm just starting getting into Python - my focus being on using it with Maya and its API - and I've found that when I'm working on something there's, generally, at least 2 or 3 ways to do the same thing that I'm trying to do. For instance:</p>
<pre><code>for key, value in locNameConnector.iteritems():
value = locNameConnector[key]
cmds.connectJoint(value, key, pm=True)
</code></pre>
<p>or </p>
<pre><code>for name in locNameConnector:
cmds.connectJoint(locNameConnector[name][0], name, pm=True)
</code></pre>
<p>now the code is calling specific things in Maya, but my question is, which way is more correct? I feel like the first one is because it's taking advantage of Python's power, while the second one could be written in any language. Is there a more correct way? Is one faster than the other?</p>
| python | [7] |
2,488,533 | 2,488,534 | C++ -- When recompilation is required | <p>You have a class that many libraries depend on. You need to modify the class for one application. Which of the following changes require recompiling all libraries before it is safe to build the application?</p>
<ul>
<li>add a constructor</li>
<li>add a data member</li>
<li>change destructor into virtual</li>
<li>add an argument with default value to an existing member function</li>
</ul>
<p>Thank you</p>
| c++ | [6] |
4,149,635 | 4,149,636 | C# Calling a Method, and variable scope | <p>Why is cards being changed below? Got me puzzled.. understand passing by ref which works ok.. but when passing an Array is doesn't do as I expect. Compiling under .NET3.5SP1</p>
<p>Many thanks</p>
<pre><code>void btnCalculate_Click(object sender, EventArgs e)
{
string[] cards = new string[3];
cards[0] = "old0";
cards[1] = "old1";
cards[2] = "old2";
int betResult = 5;
int position = 5;
clsRules myRules = new clsRules();
myRules.DealHand(cards, betResult, ref position); // why is this changing cards!
for (int i = 0; i < 3; i++)
textBox1.Text += cards[i] + "\r\n"; // these are all new[i] .. not expected!
textBox1.Text += "betresult " + betResult.ToString() + "\r\n"; // this is 5 as expected
textBox1.Text += "position " + position.ToString() + "\r\n"; // this is 6 as expected
}
public class clsRules
{
public void DealHand(string[] cardsInternal, int betResultInternal, ref int position1Internal)
{
cardsInternal[0] = "new0";
cardsInternal[1] = "new1";
cardsInternal[2] = "new2";
betResultInternal = 6;
position1Internal = 6;
}
}
</code></pre>
| c# | [0] |
5,331,558 | 5,331,559 | Javascript function returns before its subroutine finishes | <p>I'm trying to test if urls dynamically passed to image tags would resolve or not. I'm using the following javascript function: </p>
<pre><code> testImageUri = function(src) {
var img = new Image();
var imgStatus = false;
var goodUri = function() {
imgStatus = true;
};
var badUri = function() {
imgStatus = false;
};
img.onload = goodUri;
img.onerror = badUri;
img.src = src;
return imgStatus;
}
</code></pre>
<p>The functions badUri and goodUri get called as expected, but they appear to be "late" as the testImageUri function seems to return before they get to change the imgStatus variable.</p>
<p>How do one resolve such problems in javascript?<br/>
How do one avoid them?<br/>
is there a rule of thumb to recognize situations susceptible to create this?</p>
<p><strong>EDIT</strong>
<br/>Thanks all for your replies. I think I understand what's going on now. I will be implementing the function as described in the first reply, but with an additional parameter for the callback as suggested.</p>
<p>Thanks again.</p>
| javascript | [3] |
2,209,228 | 2,209,229 | Trim string completely | <p>I am using the following code to fetch the output of <code>FtpWebRequest</code> and then parse the lines one by one.</p>
<pre><code>FTPEntity entity = new FTPEntity(entityName);
entities.Add(entity);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(textBoxFTPSite.Text + entityName);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(textBoxFTPUserName.Text, textBoxFTPPassword.Text);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string[] outputlines = reader.ReadToEnd().Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
foreach (string info in outputlines) {
if (info == "") {
worker.ReportProgress(1);
continue;
}
var tokens = info.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
</code></pre>
<p>Since there is nothing in that FTP directory, the output of <code>ReadToEnd()</code> is blank. But still the Split function is creating an array of one blank element and I had to use an <code>if</code> statement to filter that one out.</p>
<p>Why is <code>Trim()</code> not trimming completely?</p>
| c# | [0] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.