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
3,138,674
3,138,675
c# press a button from a window using user32 dll
<p>I have a handler hwd over a window. How can I programatically press the button the the window has?Thx</p>
c#
[0]
5,051,938
5,051,939
Local variable output in a function surprises me
<p>The following program:</p> <pre><code>a_var = 10 b_var = 15 e_var = 25 def a_func(a_var): print "in a_func a_var = ",a_var b_var = 100 + a_var d_var = 2*a_var print "in a_func b_var = ",b_var print "in a_func d_var = ",d_var print "in a_func e_var = ",e_var return b_var + 10 c_var = a_func(b_var) </code></pre> <p>Prints this output:</p> <blockquote> <p>in a_func a_var = 15<br> in a_func b_var = 115<br> in a_func d_var = 30<br> in a_func e_var = 25</p> </blockquote> <p>I'm unsure why the "in a_func a_var" is equal to 15 and not 10. </p>
python
[7]
222,389
222,390
How to get ICCID number from IPhone?
<p>I am Trying to get the ICCID from Iphone. can anyone please help me on this.</p>
iphone
[8]
4,256,372
4,256,373
How can I "get" the return value of a function?
<p>What is the syntax to find out in method2 whether method1 one returned true or false?</p> <pre><code>class myClass{ public function method1($arg1, $arg2, $arg3){ if(($arg1 + $arg2 + $arg3) == 15){ return true; }else{ return false; } } public function method2(){ // how to find out if method1 returned true or false? } } $object = new myClass(); $object-&gt;method1(5, 5, 5); </code></pre>
php
[2]
860,893
860,894
What's the difference in this condition : STRING.equals("myValue") vs STRING == "myValue"?
<p>What's the difference in <code>STRING.equals("myValue")</code> vs <code>STRING == "myValue"</code>?</p> <p>I first used <code>STRING == "myValue"</code> but my IDE recommends to switch to using <code>.equals()</code>. Is there a specific benefit to doing this?</p>
java
[1]
3,843,323
3,843,324
drawText Canvas method not working
<p>I am very new to Java and android. my 1st app using canvas and paint. for some reason I get a force close whenever I try using the drawText method.. Please help. I am basically trying to display text in a specific x,y coordinate. which will need updates throughout game play, my code:</p> <pre><code>public class MyGame extends Main { TextView timeDisplay; public String clock; int x_pos = 10; int y_pos = 100; int radius = 20; float x = 10; float y = 20; android.graphics.Paint p; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); super.onCreate(savedInstanceState); setContentView(R.layout.main); // setup Drawing view Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); c.drawText("test", 30, 0,x,y, p); &lt;-- if I comment this out, no force close... </code></pre> <p>Your help is appreciated.</p>
android
[4]
469,926
469,927
jQuery. Get tag + class name
<p>I've got that html</p> <pre><code>&lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;input name="price" class="chrome-input" /&gt; &lt;/td&gt; &lt;td&gt; &lt;button name="sellButton" class="chrome-button"&gt; &lt;/button&gt; &lt;button name="priceButton" class="chrome-button"&gt; &lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>How can I get <code>tr</code> that contains control with class <code>chrome-button</code> inside. Something like this </p> <pre><code>alert($("tr+.chrome-button").html()); </code></pre>
jquery
[5]
4,467,043
4,467,044
how to make implode create <br /> automatic after displaying 5 things in a row?
<p>I want to make implode to display only 5 arrays after that it automatic creates a new row displaying 5 arrays again and it keep repeating itself. like is it possible to use <code>&lt;br /&gt;</code> or something else I had to use to do that?</p> <pre><code>$result = mysql_query("SELECT * FROM `im_album` WHERE username = '".$user_data['username']."' "); $types = array(); $d_array = array(); while(($row = mysql_fetch_assoc($result))) { $types[] = $row['name']; $d_array[] = $row['description']; } echo "&lt;h1&gt;".implode($types )."&lt;/h1&gt;" </code></pre>
php
[2]
2,408,295
2,408,296
Creation of New Thread is Giving an error
<p>I am new to android i am trying to create a new thread to invoke another method. But don't why it is throwing the error.</p> <p>here is my stub</p> <pre><code>void test() { int i=0; Toast.makeText(getApplicationContext(), "Testing", Toast.LENGTH_SHORT).show(); } public void Button2_Click(View v) { Thread thread = new Thread() { @Override public void run() { test(); } }; thread.start(); } </code></pre>
android
[4]
3,542,954
3,542,955
Reading a series of input / output in Python
<p>For my app, I need to print out a series of outputs and then accepts inputs from the user. What would be the best way of doing this?</p> <p>Like:</p> <pre><code>print '1' x = raw_input() print '2' y = raw_input() </code></pre> <p>Something like this, but it would go on for at least 10 times. My only concern with doing the above is that it would make up for poor code readability. </p> <p>How should I do it? Should I create a function like this:</p> <pre><code>def printOut(string): print string </code></pre> <p>Or is there a better way?</p>
python
[7]
717,091
717,092
Replacing periods (".") in a string
<p>I have a string of the type <code>../sometext/someothertext</code>, and I'm trying to replace the <code>..</code> in the string with the name of a website <code>http://www.website.com</code>.</p> <p>In Python, what I've done is like so :</p> <pre><code>strName = "../sometext/someothertext" strName.replace("..", "http://www.website.com") print strName </code></pre> <p>But the only output I get is </p> <pre><code>../sometext/someothertext </code></pre> <p>I've also tried escaping the periods, like </p> <pre><code>strName = ../sometext/someothertext strName.replace("\.\.", "http://www.website.com") </code></pre> <p>but the output doesn't change. How do I do this?</p>
python
[7]
849,732
849,733
test if display = none
<p>This does not work. Should it? Or can you stop the error if another line could do the same:</p> <pre><code>function doTheHighlightning(searchTerms) { // loop through input array of search terms myArray = searchTerms.split(" "); for(i=0;i&lt;myArray.length;i++) { // works. this line works if not out commented. Will highlight all words, also in the hidden elements //$('tbody').highlight(myArray[i]); // not working when trying to skip elements with display none... $('tbody').css('display') != 'none').highlight(myArray[i]); } // set background to yellow for highlighted words $(".highlight").css({ backgroundColor: "#FFFF88" }); } </code></pre> <p>I need to filter rows in a table and color some word. The data has become way to much for the coloring if many words are chosen. So I will try to limit the coloring by only going through the none hidden elements.</p>
jquery
[5]
765,153
765,154
jquery simple example change() function
<p>I'm just learning jQuery, I'm so noob.</p> <p>see, we have 2 divs as follows:</p> <pre><code>&lt;div id="div1"&gt; &lt;ul&gt; &lt;li&gt; This is Line 1&lt;/li&gt; &lt;li&gt; This is Line 2&lt;/li&gt; &lt;li&gt; This is Line 3&lt;/li&gt; &lt;li&gt; This is Line 4&lt;/li&gt; &lt;li&gt; This is Line 5&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="div2"&gt; &lt;ul&gt; &lt;li&gt; &lt;input type="text" /&gt;&lt;/li&gt; &lt;li&gt; &lt;input type="text" /&gt;&lt;/li&gt; &lt;li&gt; &lt;input type="text" /&gt;&lt;/li&gt; &lt;li&gt; &lt;input type="text" /&gt;&lt;/li&gt; &lt;li&gt; &lt;input type="text" /&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>since I'm just learning change() function, this is what I want to do: When each value of input boxes in div2 changes, the div1 li of the same number should be changed to the entered value, for example if we start typing in the second input box in div2, the second li text should go what we entered in the second input box.</p> <p>here is what i've tried so far, but not working:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#div2 :input').change(function(i){ var str = $(this).text; $('#div1 li').eq(i).text(str); }); }); &lt;/script&gt; </code></pre> <p>what's wrong with this? Thanks in advance</p>
jquery
[5]
1,274,784
1,274,785
How do I pass a jQuery function parameter automatically to an outside function?
<p>I am trying to pass "term" to an outside function.</p> <pre><code>$('#item').terminal(function(command, term) { </code></pre> <p>The only way I have been able to do this is by passing "term" in the function.</p> <pre><code>myfucntion(term, 'hello world'); </code></pre> <p>Is there a way I can do this without having to pass it each time?</p> <p><strong>Edit:</strong></p> <pre><code>$(function () { $('#cmd').terminal(function (command, term) { switch (command) { case 'start': cmdtxt(term, 'hello world'); break; default: term.echo(''); } }, { height: 200, prompt: '@MQ: ' }); }); function cmdtxt(term, t) { term.echo(t); } </code></pre>
jquery
[5]
1,223,094
1,223,095
Why does Java Pattern class use a factory method rather than constructor?
<p>There's a good discussion of this in the <a href="http://stackoverflow.com/questions/628950/constructors-vs-factory-methods">general case</a>.</p> <p>However, I was wondering specifically why the Pattern class uses the <code>compile</code> static method to create an object, rather than the constructor?</p> <p>Seems to me to be more intuitive to use a constructor.</p>
java
[1]
4,294,097
4,294,098
How to make a list that can show the changeable content
<p>I have build an application in android. This app needs to display a list of text, but the list of text increase continuously. It means user can see increased list of text. Each text is separated by a horizontal row. It looks like google market when market try to show list of applications. How can i do in this situation ?</p>
android
[4]
5,899,484
5,899,485
How to use simple_list_item_2 with android listview?
<p>how did I have to extend my example to use a two line listview (for example read out the email from database)?</p> <pre><code> ArrayList&lt;String&gt; db_results = new ArrayList&lt;String&gt;(); Cursor c = db.rawQuery("SELECT lastname, firstname FROM contacts ORDER BY lastname",null); while(c.moveToNext()) { db_results.add(String.valueOf(c.getString(c.getColumnIndex("lastname"))) + ", " + String.valueOf(c.getString(c.getColumnIndex("firstname")))); } c.close(); lv1.setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,db_results)); </code></pre> <p>Thanks ...</p>
android
[4]
945,951
945,952
searchDisplayController removes my searchtext
<p>I need help with the searchDisplayController. Right now I am using the searchDisplayController with textDidChange, but whenever I press search or on one of the rows my search text is removed from the searchBar. After that it returns to textDidChange and I execute my code with an empty string. Can someone help me please?</p> <p>Thanks in advance</p> <pre><code>- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ if(connectionStatus.boolNoConnection||connectionStatus.boolErrorConnection) { [self.searchDisplayController setActive:NO animated:YES]; MKCoordinateSpan span; span.latitudeDelta = 2.5f; span.longitudeDelta = 2.5f; CLLocationCoordinate2D location; location.latitude = 52.30; location.longitude = 5.45; MKCoordinateRegion region; region.span = span; region.center = location; [map setRegion:region animated:YES]; } else { if (![geoArray count] == 0) { [map removeAnnotations:pins]; [pins release]; [pinPlacemark removeAllObjects]; [self readArray:geoArray]; [self.searchDisplayController setActive:NO animated:YES]; } } } </code></pre> <p>I only call the searchdisplaycontroller here, nowhere else</p>
iphone
[8]
3,473,254
3,473,255
Directory.GetCurrentDirectory
<p>I've written a program that checks if it is in a specific folder; if not, it copies itself into that folder,run the copied program and exit. but the problem is when I call <code>Directory.GetCurrentDirectory();</code> in the copied program(only when It runs by the first one) I get the directory of the first program not the copied one. What's the problem here?</p> <p>the code:</p> <pre><code>if(Directory.GetCurrentDirectory()!=dir) { File.Copy(Application.ExecutablePath,dir+name); System.Diagnostics.Process.Start(dir+@"\"+name); System.Environment.Exit(System.Environment.ExitCode); } </code></pre> <p>i summarized my codes.</p>
c#
[0]
2,001,166
2,001,167
How to animate a set of jQuery objects one at a time (instead of all at once)
<p>I'm trying to build a picture slider. (I know there are tons of plug-ins out there, but this is more for educational purposes).</p> <p>Basically, I have a set of images with z-index: 0. What I am trying to do is take the set of images, then select each one of the images and change the index to 1, animate the opacity, and then put it back at 0, so that the next image will do the same thing.</p> <p>This is the first part, but the problem I have is that when I am testing this part, all the images do the animation at the same time. Instead of doing one after the other. I know that you can use callback functions such as:</p> <pre><code>image1.animate(the animation, function({ image2.animation(the animation, function({ image3.animation(the animation, function}) etc... </code></pre> <p>})</p> <p>But if I had more images it would become more complicated. I am trying to find a more efficient way of doing this, but I am not finding the answer.</p> <p>This is what I have tried:</p> <pre><code>images.each(function () { $(this).css({ "opacity" : "0.0", "z-index" : "1" }).animate({ opacity: "1.0" }, 3000); }); </code></pre> <p>but it doesn't work. All the images do the animation at the same time. I even tried with a "for" loop, but I get the same thing:</p> <pre><code>for (var i=0; i&lt;images.length; i++){ images.eq(i).css({ "opacity" : "0.0", "z-index" : "1" }).animate({ opacity: "1.0" }, 3000); } </code></pre> <p>I know I am doing something wrong, but I can't figure out what it is. If anyone has any help it would be greatly appreciated!</p>
jquery
[5]
1,084,380
1,084,381
help with php/cake error
<p>I tried to clone beta.neighborrow.com - i copied the directory file for file but im getting this error on the new url instillbliss.neighborrow.com</p> <p>Warning: require(cake/basics.php) [function.require]: failed to open stream: No such file or directory in /home/neighborrow/instillbliss.neighborrow.com/index.php on line 53</p> <p>Fatal error: require() [function.require]: Failed opening required 'cake/basics.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear:/home/neighborrow/instillbliss.neighborrow.com:/home/neighborrow/instillbliss.neighborrow.com/app/') in /home/neighborrow/instillbliss.neighborrow.com/index.php on line 53</p> <p>i found the right file thanks to ahmed... </p> <pre><code> */ if (!defined('APP_DIR')) { define('APP_DIR', basename(dirname(dirname(__FILE__)))); } /** * The absolute path to the "cake" directory, WITHOUT a trailing DS. * */ if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', '/home/neighborrow'); } /** * Editing below this line should NOT be necessary. * Change at your own risk. * */ if (!defined('WEBROOT_DIR')) { define('WEBROOT_DIR', basename(dirname(__FILE__))); </code></pre> <p>assuming i have to change /home/neighborrow but what do i change it to... is that the database?</p>
php
[2]
679,815
679,816
Problems to simulate download on ie
<p>i'm doing:</p> <pre><code>iframe = document.createElement("iframe"); frame.src="http://localhost/file.csv"; iframe.style.display='none'; document.body.appendChild(iframe); </code></pre> <p>it works fine on ff,chrome,safari but on ie always come a message about security that blocks it.</p> <p>someone knows how to fix it?</p>
javascript
[3]
1,064,580
1,064,581
Java Error: Should be declared in a file named
<p>I'm fairly new to Java and trying to figure out how to solve the following error:</p> <h2>Error reads</h2> <pre><code>CalculatorWithMemory.java:1: class Calculator is public, should be declared in a file named Calculator.java public class Calculator </code></pre> <p>So my thought was that this means that I have to save 2 different .java files. However, this being for a class, I only have a provided text block to type my solution into so I cannot save these as .java files. Any thoughts on a solution would be great.</p> <p>Thanks in advance!</p> <p>To Provide all the information. I'm trying to solve for the following.</p> <h2>Question</h2> <p>The superclass Calculator contains:</p> <ul> <li>a (protected) double instance variable, accumulator, that contains the current value of the calculator.</li> </ul> <p>write a subclass, CalculatorWithMemory, that contains:</p> <ul> <li>a double instance variable, memory, initialized to 0</li> <li>a method, save, that assigns the value of accumulator to memory</li> <li>a method, recall, that assigns the value of memory to accumulator</li> <li>a method, clearMemory, that assigns zero to memory</li> <li>a method, getMemory, that returns the value stored in memory</li> </ul>
java
[1]
5,011,944
5,011,945
ASP.NET: the static instance will get volatile?
<p>If I implement a Singleton as follows, putting into App_Code, will the instance be <strong>reclaimed</strong> by GC after each round-trip HTTP requests? Or it'll still persist in the runtime? Thanks for any help.</p> <pre><code>public sealed class Singleton { static readonly Singleton instance=new Singleton(); static Singleton() { } Singleton() { } public static Singleton Instance { get { return instance; } } } </code></pre>
asp.net
[9]
3,455,750
3,455,751
How to check whether the Input Text Field is visible or hidden in Javascript?
<p>I have an input text field which has </p> <pre><code>style: "visibility: visible" </code></pre> <p>or</p> <pre><code>style: "visibility: hidden" </code></pre> <p>What is the easiest way to find out if it is visible or not ?</p> <p>Suppose the input text field is E. What should be the condition here:</p> <pre><code>if &lt;something with E&gt; { alert("The text filed is visible !!"); } </code></pre> <p>?</p> <p>Thanks in advance !</p>
javascript
[3]
3,289,744
3,289,745
Fastest method to detect if there is a tag with attribute [itemtype='http://schema.org/Offer']
<p>I am looking to detect with Javascript the fastest possible way, if there is a HTML tag with attribute <code>[itemtype='http://schema.org/Offer']</code> in the current page.</p>
javascript
[3]
1,699,802
1,699,803
C++ Reading From File Loop Messing Up
<p>I have a problem with a simple file read. I have 4 four long lines of T/F's with a count at the beginning. I read in with a myfile >> count, and myfile >> value to get the values with a while with the count to finish it off the line and goto the next but I have a problem going to the third line for some reason. Not sure how to get the data file on here... Thanks for looking!</p> <pre><code>int main() { ifstream myfile; int count; string value; myfile.open("branches.txt"); while(!myfile.eof()) { myfile &gt;&gt; count; cout &lt;&lt; count &lt;&lt; endl; while(count &gt; 0) { myfile &gt;&gt; value; count--; //cout &lt;&lt; value; } myfile &gt;&gt; count; } system("pause"); return 0; } </code></pre>
c++
[6]
2,698,143
2,698,144
Generate all the points on the circumference of a circle
<p>Could someone help me with a code that could generate all the points on the circumference of a circle, Given the radius and center of the circle. I need the code in Python. Also could someone explain what would happen if K-Means is applied to two sets of points (i mean the points on the circumference) for 2 circle with same center but different radius. How would the clustering happen.</p>
python
[7]
52,735
52,736
android webview and youtube
<p>hi am trying to play the you tube video using webview ,for this am using following code but it wont work for me ,but it work in system browser</p> <pre><code>"&lt;html&gt;&lt;head&gt;&lt;style type=\"text/css\"&gt; body{ background-color: transparent; color: white; }&lt;/style&gt;&lt;/head&gt;&lt;body style=\"margin:0\"&gt;&lt;embed id=\"yt\" src=" +'"'+youTubeDetails.getVideoUrl()+'"'+"type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt; &lt;/body&gt;&lt;/html&gt;" </code></pre>
android
[4]
1,789,807
1,789,808
passing url as parameter in javascript is not calling the function
<pre><code>&lt;a href="javascript:void();" onclick="openWindow(2,1,4326,http://www.../images/icon_tree1.gif);"&gt;Edit Asset Info&lt;/a&gt; </code></pre> <p>Function openWindow is not called and I am see the folowing error on console</p> <p><code>Uncaught SyntaxError: Unexpected token :</code> and </p> <p><code>Uncaught SyntaxError: Unexpected token )</code></p> <p>This is the actual code I am using </p> <pre><code>return "&lt;a href='javascript:void();' onclick='openWindow(" 2 "," + 1 + "," + 4326 + "," + symbolurl + ");'&gt;Edit Asset Info&lt;/a&gt;"; </code></pre>
javascript
[3]
2,630,298
2,630,299
How can I force a file download in all browsers?
<p>I am working on script which allows user to download pptx and zip files using php, but this script behaves different on different browsers. I tried many scripts available on the internet, but nothing worked properly so I made this one collecting chunks from different scripts. </p> <ol> <li>firefox => works perfect </li> <li>Opera => Downloads file as a HTM file</li> <li>Safari => 0kb File </li> <li>IE => Catching old file</li> </ol> <p>My Code:-</p> <pre><code>// content type for pptx file $ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; $file = "http://www.abc.com/presentation.pptx"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: ".$ctype); header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($file)); ob_clean(); flush(); readfile( $file); </code></pre> <p>How can I get all browsers to reliably download the file instead of displaying the seemingly random behaviour above?</p> <p>Edit: Below is the code that worked for me, I am not sure what was the problem, unwanted headers or file path ? I made both the changes and it worked. </p> <pre><code>$ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; $file = "Presentation3.pptx"; header("Pragma: public"); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: ".$ctype); header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($file)); readfile( $file); </code></pre>
php
[2]
3,603,505
3,603,506
C# picking random string
<p>i basically just want to pick a random value in a string split by '|'. I can't find a good example does anybody have an idea?</p> <pre><code>string[] mystrings = ("apple|orange|mayo|fruit|dog"): string blah = "here i am "+resultsofrandom+" result chosen from mystring was " resultofrandom </code></pre> <p>obviously string blah is just an example, i just want the random chosen string from mystrings back into a new string...</p>
c#
[0]
867,372
867,373
Error while using exit(0) in javascript
<pre><code>var inDoubleTap = false; // Shared across all bound elements return $list.live('touchstart', function(e) { if (e.originalEvent.touches.length === 1) { if (!inDoubleTap) { inDoubleTap = true; setTimeout(function() { inDoubleTap = false }, delay); } else { inDoubleTap = false; callback.call(this, e); exit(0); } } }); </code></pre> <p>The above code shows an error if i use exit(0) in mobile browsers (iphone, ipad)</p>
javascript
[3]
2,717,777
2,717,778
iPhone Add support for Backgrounder
<p>I'm trying to create a app for my personal use that uses Backgrounder. Are there any prerequisite that the app can be used by Backgrounder as it refuses to put my app in background. </p> <p>I have seen the wiki and Google code page of Backgrounder and it states "If you wish to run a non-AppStore 3rd-party application in the background, it is suggested that you contact the author of the application and request that proper background support be added. " </p> <p>But there is no additional info about it... and mailing list is ... where ? Joining the group is also a mystery. </p> <p>What constitutes a "proper background support"?</p>
iphone
[8]
754,069
754,070
Google Android supported tags and atttributes
<p>I am a newbie of android developer, how can I find the reference of all default tags and attributes supported by android plantform in the layout resource file?</p> <p>Thanks a lot in advance</p>
android
[4]
4,693,138
4,693,139
Why is the global variable not being changed in certain circumstances in a function if you don't declare it with var or it's not an argument?
<p>ECMAScript is pretty straightforward about <code>var</code>. If you don't use <code>var</code> inside a function to declare a variable you assign to you assign to the global scope. This happens because of the way chain scoping works. The executing environment looks for the identifier in the local scope and then moves up until it reaches the global scope. If hasn't found a declaration for the the identifier and it's not identified as an argument the variable is created in the global scope.</p> <p>For example local scope:</p> <pre><code>var car = 'Blue'; function change_color () { var car = 'Red'; } change_color(); console.log(car); //logs 'Blue' as car is in the local scope of the function. </code></pre> <p>When <code>car</code> is not found in the local scope:</p> <pre><code>var car = 'Blue'; function change_color () { car = 'Red'; } change_color(); console.log(car); //logs 'Red' as car is not in the local scope and the global variable is used. </code></pre> <p>Now apparently there's an exception to this rule that I wasn't aware of and don't understand (<strong>notice the function name</strong>):</p> <pre><code>var car = 'Blue'; (function car () { car = 'Red'; })(); console.log(car); //Logs 'Blue'???? </code></pre> <p>Can anyone explain this please? I don't see where this is explained in the ECMASpec. Tested in Chrome 8 and Firefox 3.6</p>
javascript
[3]
4,618,441
4,618,442
Getting the replica ID of Access database using DAO
<p>I've recently ported an MFC project form VS6 to VS2005. The VS6 project linked ddao35d.lib (DAO 3.5) which is no longer compatible with the 'new' MFC used in VS2005. To get around this I'm now including afxdao.h and changing my database classes from <code>CdbDatabase</code> to <code>CDaoDatabase</code> as recommended by other posts : -</p> <p><a href="http://www.experts-exchange.com/Programming/Languages/CPP/Q_22465486.html" rel="nofollow">http://www.experts-exchange.com/Programming/Languages/CPP/Q_22465486.html</a></p> <p>However, there was a member function in <code>CdbDatabase</code> called <code>GetReplicaID()</code> which is no longer in <code>CDaoDatabase</code>. Does anyone know how to get the replica ID of an Access database using the <code>CDaoDatabase</code> class or otherwise?</p> <p>Here are the important exerpts from that post: -</p> <p>"As of Visual C++ .NET, the Visual C++ environment and wizards no longer support DAO (although the DAO classes are included and you can still use them). Microsoft recommends that you use OLE DB Templates or ODBC for new projects. You should only use DAO in maintaining existing applications.</p> <p>The DAO MFC libraries, including ddao35d.lib, are part of PlatformSDK and are not compatible with the new MFC. You are expected to #include and it will link daouuid.lib." </p> <p>...</p> <p>"Adding the and daouuid.lib was the trick. PLUS: changing the declaration of CdbLastOLEError TO CDaoErrorInfo. The CdbLastOLEError is still in , but apparently no longer in the ddao35.lib. Changing to CDaoErrorInfo and linking with the addition of daouuid.lib has corrected the linker error."</p>
c++
[6]
1,245,624
1,245,625
What is wrong with my array append function?
<pre><code>$allAmazonMatches = Array ( [1] =&gt; B002I0HJZO [2] =&gt; B002I0HJzz [3] =&gt; B002I0HJccccccccc ) </code></pre> <p>I am doing: </p> <pre><code>array_push($allAmazonMatches, array("0"=&gt;"None of the products match")); </code></pre> <p>How ever, I am unable to add the additional array to $allAmazonMatches?</p>
php
[2]
3,669,840
3,669,841
URL mapping in the webconfig query
<pre><code>&lt;urlMappings enabled="true"&gt; &lt;add url="~/Name.aspx" mappedUrl="~/ActualName.aspx"/&gt; &lt;/urlMappings&gt; </code></pre> <p>Any idea why this is not working for me?</p>
asp.net
[9]
3,625,581
3,625,582
How to catch device back button event in android?
<p>I have open pdf file through my application.when click on device back button it is automatically come back to my application .It is working fine.Here i want catch back button event in device.I override the back button.but it is not working.please help me.</p>
android
[4]
3,546,612
3,546,613
Passing page variable to function in PHP
<p>How do I pass variable itself to the function ? here's snippet </p> <pre><code>$user_name; $user_id; function set($variable,$value) { $variable = $value ; } </code></pre> <p>to call set($user_name,'abc');set($user_id,'abc123')</p> <p>i want to set the value of $user_name,$user_id. </p> <p>thanks</p>
php
[2]
2,513,408
2,513,409
Ways to disable mouse events using jquery?
<p>I am looking for a way to disable the mouse event when my animations start using jquery, and when event start again when animation was done.I know this can be done using a webkit css support. </p> <pre><code>'pointer-events', 'none' </code></pre> <p>But it will not work on IE.please help.</p>
jquery
[5]
1,747
1,748
check if a collection is empty in java : Which is the best method
<p>I have two ways of comparing if a List is empty or not</p> <pre><code>if (CollectionUtils.isNotEmpty(listName)) </code></pre> <p>and </p> <pre><code>if(listName != null &amp;&amp; listName.size() != 0) </code></pre> <p>My arch tells me that the former is better than latter. </p> <p>But I think latter is better. Can anyone please clarify it.</p>
java
[1]
5,011,878
5,011,879
Where definitions in public.xml are linking to?
<p>Let me explain with example... Consider 'android.R.layout.simple_list_item_multiple_choice'. It used to create multi-select lists. But the only definitions I found:</p> <p>/platform/frameworks/base/core/res/res/values/public.xml:</p> <pre><code>&lt;public type="layout" name="simple_list_item_multiple_choice" id="0x01090010" /&gt; </code></pre> <p>/platform/frameworks/base/api/current.xml:</p> <pre><code>&lt;field name="simple_list_item_multiple_choice" type="int" transient="false" volatile="false" value="17367056" static="true" final="true" deprecated="not deprecated" visibility="public" &gt; </code></pre> <p>But where is actual layout defined? When multi-select list created I see checkbox, where it comes from?</p>
android
[4]
4,395,979
4,395,980
It appears some parts of an expression may be evaluated at compile-time, while other parts at run-time
<p>Probably a silly question, since I may have already answered my question, but I just want to be sure that I'm not missing something </p> <p>Constant expressions are evaluated at compile time within checked context. I thought the following expression shouldn't be evaluated at compile time, since I assumed C# considers a particular expression as a constant expression only if all operands on the left-hand side are constants:</p> <pre><code>int i= 100; long u = (int.MaxValue + 100 + i); //error </code></pre> <p>Instead it appears compiler considers any subexpression where both operands are constants as a constant expression, even if other operands in an expression are non-constants? Thus compiler may only evaluate a part of an expression at compile time, while the remained of the expression ( which contains non-constant values ) will get evaluated at run-time --> I assume in the following example only <code>(200 +100)</code> gets evaluated at compile time</p> <pre><code>int i=100; long l = int.MaxValue + i + ( 200 + 100 ); // works </code></pre> <p>Are my assumptions correct?</p> <p>thanx</p>
c#
[0]
4,235,767
4,235,768
Jquery clone element, altering id then use keyup() not working
<p>The Problem: When i clone <code>&lt;div id="#cloneme1"&gt;...&lt;/div&gt;</code> i get <code>&lt;div id="cloneme2"&gt;...&lt;/div&gt;</code> but the .keyup() function wont read the new DOM elements</p> <pre><code>$('#btnAdd').click(function() { var num= $('.clonedInput').length; // how many "duplicatable" input fields we currently have var newNum= new Number(num + 1); // the numeric ID of the new input field being added // create the new element via clone(), and manipulate it's ID using newNum value var newElem = $('#cloneme' + num).clone().attr('id', 'cloneme' + newNum); // manipulate the name/id values of the input inside the new element newElem.children(':first').attr('id', 'alteredguianswer' + newNum) // insert the new element after the last "duplicatable" input field $('#cloneme' + num).after(newElem); }); $('input[type="text"]').keyup(function(){ var id = $(this).attr("id"); // variable id = id of current textfield var value=$(this).val(); // variable value = value in current textfield $("#someplace"+id).text(value); // edit text elsewhere on page using value }); &lt;div&gt; &lt;input type="button" id="btnAdd" value="add another name" /&gt; &lt;/div&gt; &lt;div id="cloneme1" style="margin-bottom:4px;" class="clonedInput"&gt;Question:&lt;input type="text" id="guianswer1" value="Answer 1" /&gt;&lt;/div&gt; </code></pre> <p>I dont understand how to get a function to read the new cloned elements </p>
jquery
[5]
170,150
170,151
"reverse" in JavaScript
<p>From <a href="http://www.blogohblog.com/cool-javascript-tricks/" rel="nofollow">this cool post</a>, one of the pieces of code is:</p> <pre><code>javascript:function flood(n) {if (self.moveBy) {for (i = 200; i &gt; 0;i--){for (j = n; j &gt; 0; j--) {self.moveBy(1,i); self.moveBy(i,0);self.moveBy(0,-i); self.moveBy(-i,0); } } }}flood(6);{ var inp = "D-X !msagro na dah tsuj resworb rouY"; var outp = ""; for (i = 0; i &lt;= inp.length; i++) {outp =inp.charAt (i) + outp ; } alert(outp) ;}; reverse </code></pre> <p>What is this <code>reverse</code> at the very end?</p> <p><strong>Edited Formatted Code From Above:</strong></p> <pre><code>javascript:function flood(n) { if (self.moveBy) { for (i = 200; i &gt;0;i--) { for (j = n; j &gt; 0; j--) { self.moveBy(1,i); self.moveBy(i,0); self.moveBy(0,-i); self.moveBy(-i,0); } } } } flood(6); { var inp = "D-X !msagro na dah tsuj resworb rouY"; var outp = ""; for (i = 0; i &lt;= inp.length; i++) { outp =inp.charAt (i) + outp ; } alert(outp); }; reverse </code></pre>
javascript
[3]
3,260,810
3,260,811
how to override backpress to not kill activity?
<p>I would like to display some images when the application is opened for the first time. Or if its being reopened. I don't want the application to be killed when the user presses the back button, to go to the home screen. But instead keep it alive but still return to the home screen. </p>
android
[4]
5,605,149
5,605,150
Blocking Internet Using c#
<p>I am trying to develop a parental software which can be scheduled to block internet in specific intervals. How can I do this in C#?</p> <p>Can I use <code>System.Net, System.Net.NetworkInformation</code>namespace in c# is there any build in function for blocking/disabling network?</p>
c#
[0]
1,449,656
1,449,657
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
<p>Hi I have written a code and I run it a lot but suddenly this exception occurred please hep me thanks Exception:</p> <pre><code> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at javax.media.j3d.BoundingBox.&lt;init&gt;(BoundingBox.java:86) at javax.media.j3d.NodeRetained.&lt;init&gt;(NodeRetained.java:198) at javax.media.j3d.LeafRetained.&lt;init&gt;(LeafRetained.java:40) at javax.media.j3d.LightRetained.&lt;init&gt;(LightRetained.java:44) at javax.media.j3d.DirectionalLightRetained.&lt;init&gt;(DirectionalLightRetained.java:50) at javax.media.j3d.DirectionalLight.createRetained(DirectionalLight.java:116) at javax.media.j3d.SceneGraphObject.&lt;init&gt;(SceneGraphObject.java:119) at javax.media.j3d.Node.&lt;init&gt;(Node.java:178) at javax.media.j3d.Leaf.&lt;init&gt;(Leaf.java:50) at javax.media.j3d.Light.&lt;init&gt;(Light.java:270) at javax.media.j3d.DirectionalLight.&lt;init&gt;(DirectionalLight.java:87) </code></pre>
java
[1]
856,213
856,214
PHP deleting 1 image of certain name?
<p>I made a user image upload. It works, but I need it to delete the old image after making the new one, how can I achieve this?</p>
php
[2]
2,907,955
2,907,956
enforcing compile-time checking on runtime annotation
<p>I declare an annotation that should only be used on class properties of primitive type or of java.lang.String type or when the property has been annotated with another annotation @Annot. How Do i ensure that the user does not annotate the wrong property? who do i enforce rather compile-time checking on the annotations?</p>
java
[1]
585,840
585,841
jQuery Plugin Options: Extend before or inside this.each block?
<p>I'm looking at the Plugin Authoring article at <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">http://docs.jquery.com/Plugins/Authoring</a> and saw this example in the Defaults and Options section:</p> <pre><code>$.fn.tooltip = function( options ) { var settings = { 'location' : 'top', 'background-color' : 'blue' }; return this.each(function() { // If options exist, lets merge them // with our default settings if ( options ) { $.extend( settings, options ); } </code></pre> <p>I don't fully understand why the .extend call is inside the this.each block? My first intuition would be to write it as:</p> <pre><code>$.fn.tooltip = function( options ) { var settings = { 'location' : 'top', 'background-color' : 'blue' }; $.extend( settings, options || {} ); return this.each(function() { </code></pre> <p>So I moved the .extend call above the return (and replaced the ugly if with a || {} - I assume that makes sense?).</p> <p>Is there anything I'm not seeing here? Any weird closure related stuff maybe? As in: Modifying the settings globally vs. only on that call? (Edit: Apparently I am not - <a href="http://jsfiddle.net/fVSDH/" rel="nofollow">http://jsfiddle.net/fVSDH/</a> )</p>
jquery
[5]
4,969,790
4,969,791
Absolute path PHP
<p>I have a problem because i can´t work my images or css when my site is like www.site.com/shop</p> <p>Situation: I have these folders inc img css js</p> <p>In my root documents i have and in this include i have all the styles.css, scripts and metadata.</p> <p>So far so good, all the documents work when they are in root document but now i have a new folder called shop where i am putting code to make a store.</p> <p>mysite/shop</p> <p>How can i call from the shop/index.php all my images, and css, js and inc ? </p> <p>I want to avoid using ../img/bla.jpg or ../inc/header.php also because when i include the footer or menu i can´t find the images.</p> <p>Thanks for all the help.</p>
php
[2]
2,197,020
2,197,021
how to create multi choice list view with search box in android
<p>I m having a list of around more than 100 items that i m building a multi choice list, out of which user can select as many items he need, I created the list view with multi choice selection but scrolling the 100 items is too complex for user so is there any way to put the search box at the top of list view so upon typing the text in search box user will see only related items and can make a multi choice selection out of that</p> <p>any help is appreciated</p>
android
[4]
935,989
935,990
generate unique random numbers in javacript
<p>I am trying to generate a set of random unique numbers as shown in my code below:</p> <pre><code>if(document.getElementsByTagName("a")!=null&amp;&amp;document.getElementsByTagName("a").length&gt;0){ var titleArray=newArray(); var urlArray=newArray(); var j=0; var arr = []; for(i=1;i&lt;document.getElementsByTagName("a").length;i++){ var anchorLength = document.getElementsByTagName("a").length ; var randNumber=Math.floor(Math.random()*anchorLength); var found=false; for(var k=0;k&lt;arr.length;k++){ if(arr[k]==randNumber ){ found=true; break; } } if (!found &amp;&amp; randNumber!=0) { arr[arr.length] = randNumber; var uniqueRandNumber = randNumber; } else{ continue; } if(document.getElementsByTagName("a")[uniqueRandNumber].title!=null&amp;&amp;document.getElementsByTagName("a")[uniqueRandNumber].title!=""){ j++; if (j &lt; 36) { urlArray[j] = document.getElementsByTagName("a")[uniqueRandNumber].href; titleArray[j] = document.getElementsByTagName("a")[uniqueRandNumber].title; } } } } myWindow=window.open('http://inside-files.mathworks.com/public/Sathish_Balu/faces/faces.html?faces&amp;titles='+titleArray+',&amp;url='+urlArray); myWindow.focus();} </code></pre> <p>What happens here is, its entering the if loop less than exact number of times it should actually enter .. can some1 help me in this ?</p>
javascript
[3]
237,438
237,439
How to set height , width to image using jquery
<p>Is there any way to set height and width of an image using jquery? The following is my code </p> <pre><code>var img = new Image(); // Create image $(img).load(function(){ imgdiv.append(this); }).error(function () { $('#adsloder').remove(); }).attr({ id: val.ADV_ID, src: val.ADV_SRC, title: val.ADV_TITLE, alt: val.ADV_ALT }); </code></pre> <p>Thanks.</p>
jquery
[5]
5,169,935
5,169,936
Fetching Image Id from Iphone Photo Album
<p>I need the imageid of the images that are stored in photo album. How can i achieve it? I have heard that PLPhotoLibrary helps in fetching the id, but because it is a private framework, app store does not allow it. Please help.</p>
iphone
[8]
4,754,582
4,754,583
Make property assignment an Action
<p>Just an example: I have a class that reacts to set properties. More specifically, there are three properties from which an assembly is loaded once they are all set. Afterwards an event is triggered.</p> <p>My unit test for this behavior look something like this:</p> <pre><code>bool assemblyLoaded = false; loader.AssemblyLoaded += () =&gt; assemblyLoaded = true; loader.Type = "someType"; Assert.IsFalse(assemblyLoaded); // not loaded, only one property was set </code></pre> <p>This would lead to three unit tests, one test for each property. So I'd like to abstract the test by using a helping method (see below) to avoid code replication:</p> <pre><code>private void Testfoobar(Action setProperty) { bool assemblyLoaded = false; loader.AssemblyLoaded += (sender, args) =&gt; assemblyLoaded = true; setProperty(); } </code></pre> <p>Unfortunately, I cannot make a property assignment an Action.</p> <p>So, I wonder, can you somehow "transform" the assignment to Action? Or is there maybe a different way to abstract the code?</p>
c#
[0]
4,558,274
4,558,275
java overriding not working
<p>I'm a beginner in Java, I used PHP, C++ and Lua and never had this problem, I made two classes just for exercising's sake <code>Facto</code> and <code>MyFacto</code>, first one does find a factorial and the second one should find factorial not by adding, but by multiplying. Don't blame me for the stupid and pointless code, I am just testing and trying to get the hang of Java. </p> <p>Main:</p> <pre><code>public class HelloWorld { public static void main(String[] args) { Facto fc = new Facto(5); fc.calc(); System.out.println(fc.get()); MyFacto mfc = new MyFacto(5); mfc.calc(); System.out.println(mfc.get()); } } </code></pre> <p>Facto.java:</p> <pre><code>public class Facto { private int i; private int res; public Facto(int i) { this.i = i; } public void set(int i) { this.i = i; } public int get() { return this.res; } public void calc() { this.res = this.run(this.i); } private int run(int x) { int temp = 0; if(x&gt;0) { temp = x + this.run(x-1); } return temp; } } </code></pre> <p>MyFacto.java:</p> <pre><code>public class MyFacto extends Facto { public MyFacto(int i) { super(i); } private int run(int x) { int temp = 0; if(x&gt;0) { temp = x * this.run(x-1); } return temp; } } </code></pre> <p>I thought the result should be 15 and 120, but I get 15 and 15. Why is that happening? Does it have something to do with <code>calc()</code> method not being overriden and it uses the <code>run()</code> method from the <code>Facto</code> class? How can I fix this or what is the right way to override something like this?</p>
java
[1]
3,891,155
3,891,156
Selection list cut off in AutoCompleteTextView in Dialog
<p>I have a dialog window that covers 1/3 of the entire screen height and is displayed on top of my activity. The dialog holds two AutoCompleteTextView fields.</p> <p>The problem I'm facing is that when the user starts typing something into the AutoCompleteTextView, the list with all suggestions only shows up to the bottom end of the dialog, but doesn't go beyond that even the list is longer. It looks like it's cut off. (screenshot left)</p> <p>Only after I long-press an item from the suggestion list, the list will be shown in full length. (screenshot right)</p> <p>Screenhot is at: <a href="http://img704.imageshack.us/i/dialogdropdown.png/" rel="nofollow">http://img704.imageshack.us/i/dialogdropdown.png/</a> <img src="http://img704.imageshack.us/img704/1893/dialogdropdown.png" alt="screenshot"></p> <p><strong>How to fix this behaviour so that the list shows in full length right from the beginning, when the user starts typing something?</strong></p> <p>Code-wise there's nothing special, all I do is:</p> <pre><code>ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this.getContext(), R.layout.nav_route_autocomplete_row, locStrings); AutoCompleteTextView txtStartPos = (AutoCompleteTextView) findViewById(R.id.txtStartPos); txtStartPos.setAdapter(adapter); ... </code></pre> <p>One workaround idea is to somehow dispatch a motion event to simulate a touch (but then not selecting though) one of the list items. Any concrete idea in code for a solution, anybody?</p>
android
[4]
3,930,051
3,930,052
How to bind the same handler to multiple events with jQuery
<p>Just wondering if there are ways to simplify the following script...Thanks for the help.</p> <pre><code>$('#right-arrow').live('click', function(){ removt(); callAjaxToCheck(); show = true; }) $('#tab').click(function(){ removeTut(); callAjaxToCheck(); show = true; }) $('left-arrow').live('click', function(){ removeT(); callAjaxToCheck(); show = true; }) </code></pre>
jquery
[5]
1,199,396
1,199,397
How to change input option text with jQuery?
<p>I want to target this input and change it dynamically with jQuery:</p> <pre><code>&lt;select id="sub_cat" style="" name="sub_cat"&gt; &lt;option selected="selected" value="-10"&gt;All&lt;/option&gt; </code></pre> <p>I want to be able to change 'All' with an if statement based on different variables. Is this possible with jQuery? And how? Any help is appreciated. Thanks</p>
jquery
[5]
5,982,938
5,982,939
Best way to check if a collection only contains elements in another collection?
<p>What is the best way to check if an array/tuple/list only contains elements in another array/tuple/list?</p> <p>I tried the following 2 approaches, which is better/more pythonic for the different kinds of collections? What other (better) methods can I use for this check?</p> <pre><code>import numpy as np input = np.array([0, 1, -1, 0, 1, 0, 0, 1]) bits = np.array([0, 1, -1]) # Using numpy a=np.concatenate([np.where(input==bit)[0] for bit in bits]) if len(a)==len(input): print 'Valid input' # Using sets if not set(input)-set(bits): print 'Valid input' </code></pre>
python
[7]
780,771
780,772
Why does typeof(window.onevent)=='undefined' testing not work in FF3.6?
<pre><code>typeof(window.onhashchange)=='undefined' </code></pre> <p>This returns <code>false</code> in every browser that does indeed support the <code>hashchange</code> event, except for FF3.6, even though it supports <code>hashchange</code> just fine. I know I can use <code>in</code> for property testing instead, but I'm just curious why FF3.6 does not support it and what the difference is.</p>
javascript
[3]
1,847,264
1,847,265
How to sum-up the numbers for the similar groups?
<p>I'm not a regular python programmer, so please bare with me. </p> <p>I've two questions. I'm trying to write a script which takes command line arguments and I see I can start the script either using:</p> <pre><code>#!/bin/env python </code></pre> <p>or</p> <pre><code>exec python -x "$0" "$@" </code></pre> <p>What's the difference between those two?</p> <p>The second question is with scripting. I have an input data-set like this:</p> <pre><code>group_a 5 group_a 7 group_c 6 group_a 8 group_b 8 group_b 4 group_c 7 group_a 8 .... .... </code></pre> <p>How can I group together all the similar items and sum up the numbers like this: </p> <pre><code>group_a 28 group_b 12 group_c 13 </code></pre> <p>Thanks in advance for your time. I really appreciate your help. cheers!! </p>
python
[7]
2,823,863
2,823,864
java shell script question
<p>I am developing a license Generation tool in java.I required to call a shell script from my java program which is license generation tool and after that I have to send command to license generation tool which takes a xml as a input but I am unable to do it please help me</p>
java
[1]
3,846,807
3,846,808
Red exclamation mark over the project in eclipse
<p>I am trying to run a project but there is a red exclamation mark over the project name. When checked in Problems, its throwing an error "project is missing required library". The library is pointed to android.jar located in some path. When checked in package explorer, I found the android.jar in Android 2.3.1 folder structure of project in package explorer. The android.jar located in Android 2.3.1 folder is pointing to some other path. Is the build error occurring due to the difference in paths for android.jar files? I have imported the project.So, how should I modify the path which is shown in the problems window? I am newbie to android and so pls help me.</p> <p>Thanks!!!</p>
android
[4]
3,540,491
3,540,492
how to avoid user to click outside popup window javascript?
<p>How to avoid user to click outside popup window javascript ?</p>
javascript
[3]
2,592,571
2,592,572
Couldn't find main class error is coming while running java in eclipse
<p>I'm running java program in eclipse and I'm calling one class from another class.. if I run class contains main method it gave an error like:</p> <blockquote> <p>could not find main class. program wil exit</p> </blockquote> <p>please tell me what is happening.</p> <p>A sample code is here :</p> <pre><code>public static void main(String[] args) { Test t1=suitToRun(); TestRunner.run(t1); } public static Test suitToRun() { TestSuite suite= new TestSuite(); suite.addTestSuite(Login.class); return suite; } </code></pre>
java
[1]
4,262,804
4,262,805
$_session variable
<p>I want to store some information like user_name, country_name etc and need to be available through out the session. </p> <ol> <li>what will be the best way to achieve this?</li> <li>I have the following code to <code>$_session</code> variable but have no result.</li> </ol> <p><strong>page1.php</strong></p> <pre><code> session_start; $_SESSION['country_no']=1; </code></pre> <p><strong>page2.php</strong></p> <pre><code>session_start; echo "here is session variable=".$_SESSION['country_no']; exit; </code></pre>
php
[2]
805,026
805,027
How to Implement Undo for Treeview
<p>I am working in windows application. My problem is..</p> <p>I have treeview &amp; a textbox control in the form. For each node text present in the textbox is saving in a database. </p> <p>Currently my program is working like this. 1) Treeview_BeforeSelect() : in this method i have written the code to save the textbox data in a database. 2) Treeview_AfterSelect() : in this method i have written the code to get the data from the database &amp; display it in a textbox.</p> <p>Now i have to implement Undo for this treeview. Please suggest any ideas regarding this.</p>
c#
[0]
4,934,381
4,934,382
Getting 417 error when using webrequest
<p>I have a schedule task that is making a webrequest. This was all working fine. However all of sudden i'm getting the following error log. </p> <hr> <p>12/05/2010 20:21:17 Failure reading XML System.Net.WebException: The remote server returned an error: (417) Expectation failed. at System.Net.HttpWebRequest.GetResponse() at DelegateImport.Update.UpdateLiveSite(String delegateId, String badgeId) at DelegateImport.Rss.RssReader()</p> <p>Here is the code making the web request</p> <pre><code> WebRequest request = WebRequest.Create (uri); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes (postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; request.Timeout = 30000000; Stream dataStream = request.GetRequestStream (); dataStream.Write (byteArray, 0, byteArray.Length); dataStream.Close (); WebResponse response = request.GetResponse (); Console.WriteLine (((HttpWebResponse)response).StatusDescription); dataStream = response.GetResponseStream (); StreamReader reader = new StreamReader (dataStream); string responseFromServer = reader.ReadToEnd (); Console.WriteLine (responseFromServer); reader.Close (); dataStream.Close (); response.Close(); </code></pre>
asp.net
[9]
216,370
216,371
I want to call a method after particular time until my app opened in iphone?
<p>I want to call a method after each 2 minutes, how can I apply such logic?</p>
iphone
[8]
5,674,648
5,674,649
Using Libraries
<p>I need some advice on how to use Libraries with Android and have the following questions. I have successfully created a project and a number of libraries and I am able to set the project as libraries and to link the libraries into my projects and reference the code in the libraries from the projects or other libraries.</p> <p>The problem I have is that when I execute the project in the emulator it complains about a missing shared library.</p> <p>So here are my questions</p> <ol> <li><p>If a shared library links to another shared library using eclipse, so I need to manually reference the name of the library in the using libraries manifest file</p></li> <li><p>In the case where there is a chain of say 4 libraries that reference each other ( contrived I know ) e.g. Lib A used Lib B, Lib uses Lib C, Lib C uses Lib D. Is it only necessary to add the reference in the using Lib manifest e.g. Lib C shall have only the ref to the Lib D in its manifest or must I add additional references in the Application Parent Manifest even though Lib4 is not used in the main application parent.</p></li> <li><p>Do I need to do something special for Android to package the shared libraries when using the emulator or can anyone explain why I should get a missing shard library.</p></li> </ol>
android
[4]
1,170,366
1,170,367
C++ compilers implementing dynamic initialization after main
<p>The C++ standard section 3.6.2 paragraph 3 states that it is implementation-defined whether dynamic initialization of non-local objects occurs after the first statement of main().</p> <p>Does anyone know what the rationale for this is, and which compilers postpone non-local object initialization this way? I am most familiar with g++, which performs these initializations before main() has been entered.</p> <p>This question is related: <a href="http://stackoverflow.com/questions/6372032/dynamic-initialization-phase-of-static-variables">Dynamic initialization phase of static variables</a> But I'm specifically asking what compilers are known to behave this way.</p> <p>It may be that the only rationale for this paragraph is to support dynamic libraries loaded at runtime, but I do not think that the standard takes dynamic loading issues into consideration.</p>
c++
[6]
5,451,806
5,451,807
Nonetype object has no attribute '__getitem__'
<p>I am trying to use an API wrapper downloaded from the net to get results from the new azure Bing API. I'm trying to implement it as per the instructions but getting the runtime error:</p> <pre><code>Traceback (most recent call last): File "bingwrapper.py", line 4, in &lt;module&gt; bingsearch.request("affirmative action") File "/usr/local/lib/python2.7/dist-packages/bingsearch-0.1-py2.7.egg/bingsearch.py", line 8, in request return r.json['d']['results'] TypeError: 'NoneType' object has no attribute '__getitem__' </code></pre> <p>This is the wrapper code:</p> <pre><code>import requests URL = 'https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%(query)s&amp;$top=50&amp;$format=json' API_KEY = 'SECRET_API_KEY' def request(query, **params): r = requests.get(URL % {'query': query}, auth=('', API_KEY)) return r.json['d']['results'] </code></pre> <p>The instructions are:</p> <pre><code>&gt;&gt;&gt; import bingsearch &gt;&gt;&gt; bingsearch.API_KEY='Your-Api-Key-Here' &gt;&gt;&gt; r = bingsearch.request("Python Software Foundation") &gt;&gt;&gt; r.status_code 200 &gt;&gt;&gt; r[0]['Description'] u'Python Software Foundation Home Page. The mission of the Python Software Foundation is to promote, protect, and advance the Python programming language, and to ...' &gt;&gt;&gt; r[0]['Url'] u'http://www.python.org/psf/ </code></pre> <p>This is my code that uses the wrapper (as per the instructions):</p> <pre><code>import bingsearch bingsearch.API_KEY='abcdefghijklmnopqrstuv' r = bingsearch.request("affirmative+action") </code></pre>
python
[7]
850,737
850,738
create executable file from php
<p>i want to create executable file from php. for example after create zip from files i want to create executable it for other user</p> <p>for example after prepare zip file</p> <pre><code>$files_to_zip = array( 'preload-images/1.jpg', 'preload-images/2.jpg', 'preload-images/5.jpg', 'kwicks/ringo.gif', 'rod.jpg', 'reddit.gif' ); </code></pre> <p>can create exe file from this:</p> <pre><code>$result = create_zip($files_to_zip,'my-archive.exe'); </code></pre>
php
[2]
3,413,876
3,413,877
php issue when using image fader script
<p>I am having trouble with the following piece of code. I believe it's an issue with incorrect use of single/double quotes, but cant figure it out, can anyone advise?</p> <pre><code>foreach ($page-&gt;images as $image) { echo '&lt;img src= "&lt;?php echo $image-&gt;url;?&gt;" &gt;'; } </code></pre>
php
[2]
2,270,388
2,270,389
Can someone help me with the GD library in windows?
<p>I cannot get this to work on Wondows. There is a dll file bundled in the gdwin.zip file that I downloaded called "bgd.dll". I read that this file needs to go into the ext directory and then simply add / uncomment the library in the ini file. I've done that but I cannot get this working. Can someone please help? I'm on 5.2</p> <p><hr /></p> <p>This is the error message I'm getting. I have restarted the server.</p> <pre><code>PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\Program Files\\PHP\\ext\\php_gd2.dll' - The specified module could not be found.\r\n in Unknown on line 0 </code></pre> <p>I renamed the dll back to its original name and now I am getting this error after I restart the server:</p> <pre><code>PHP Startup: Invalid library (maybe not a PHP library) 'bgd.dll' in Unknown on line 0 </code></pre>
php
[2]
2,014,711
2,014,712
In need of JavaScript Solution for Exporting table to Excel which works in all browsers
<p>Mr. Alfasin's answer which is posted on february 29 - 2012 on the question "I want to export a jsp table of search results to an MS-Excel '.xlsx' format file" is useful for creating the output either in CSV or HTML. </p> <p>Similarly My Requirement is that I want the Table to be exported to Excel by clicking on Button "Export".In my code I have one issue in Exporting HTML table (in JSP Page) to Excel . As of now , it is exporting from Internet explorer but not from mozillaFireFox. There is no option of plugins of ActiveXObject in mozilla. I want to Export from all Browsers like mozilla firefox, Internet explorer. Can any one help me in this? My java Script as follows. </p> <pre><code>script type="text/javascript" function Export_to_Excel() { alert (" Welcome ! Have a Nice Day"); var x=excel.rows; var objExcel = new ActiveXObject("Excel.Application"); objExcel.Visible = true; var objWorkbook = objExcel.Workbooks.Add; for(i=0;i&lt;x.length;i++) { var y=x[i].cells; for(j=0;j&lt;y.length;j++) { objWorkbook.ActiveSheet.Cells(i+1, j+1).value=y[j].innerText; } } } </code></pre> <p>Thanks in Advance</p>
javascript
[3]
995,347
995,348
Managing layout runtime android
<p>I am getting runtime dynamic imagebutton displayed but i am having some things that are displayed on the screen before, so now when i add my runtime imagebutton it will overlap the previous static display and i want to add the runtime imagebutton after the static layout which comes through xml. please help.</p> <pre><code> for (int i =0;i&lt;adapt_objmenu.image_array.length;i++){ ImageButton b1 = new ImageButton(myrefmenu); b1.setId(100 + i); b1.setImageResource(R.drawable.bullet_1); // b1.setPadding(left, top, right, bottom) b1.setPadding(0, 10, 0, 10); b1.setBackgroundColor(R.drawable.bg_navitionbar); // b1.setText(adapt_objmenu.city_name_array[i]); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (i &gt; 0) { lp.addRule(RelativeLayout.RIGHT_OF, b1.getId() - 1); } b1.setLayoutParams(lp); relative.addView(b1); //relate.addView(b1, i, new RelativeLayout.LayoutParams(width,height)); //height = height+80; } </code></pre>
android
[4]
2,285,198
2,285,199
How to take control of Dismissal of UIAlertView in iPhone
<p>I need to know if I can decide in the action method of the Buttons of UIAlertView whether to dismiss the alertView or not. In short On click of certain buttons of AlertView, I dont want my alert view to dismiss.</p>
iphone
[8]
4,264,564
4,264,565
how to write online quiz project code
<pre><code>$answers=array(); $rightanswer=array(); echo '&lt;form action="question_check.php" method="post"&gt;'; $result=mysql_query("select * from sual where sual_id='1'"); if(mysql_num_rows($result)) { $row=mysql_fetch_row($result); { $question_id=$row[0]; $question=$row[1]; $answers[0]=$row[2]; $answers[1]=$row[3]; $answers[2]=$row[4]; $rightanswer=$row[4]; $rand_keys=array_rand($answers,3); $answer0=$answers[$rand_keys[0]]; $answer1=$answers[$rand_keys[1]]; $answer2=$answers[$rand_keys[2]]; echo "question:".$row[1]."&lt;br&gt;"; echo '&lt;input type="radio" value="'.$answer0.'"&gt;'.$answer0."&lt;br&gt;"; echo '&lt;input type="radio" value="'.$answer1.'"&gt;'.$answer1."&lt;br&gt;"; echo '&lt;input type="radio" value="'.$answer2.'"&gt;'.$answer2."&lt;br&gt;"; echo '&lt;input type=hidden value="'.$rightanswer.'"&gt;'; echo '&lt;input type="submit" value="answer"&gt;';echo '&lt;input type="reset" value="sil"&gt;'; } } echo "&lt;/form&gt;"; </code></pre> <p>i want to create online exam project.but there is a problem.i write question_check.php page but it isnt working,how should i write it. code above is my index.php...problem is i dont know exactly how to compare my selected answer with right answer in the database..pls help me<code>enter code here</code></p>
php
[2]
1,686,605
1,686,606
How to get a particular string from a sentence in Android?
<p>I stored my data in a <a href="http://en.wikipedia.org/wiki/SQLite" rel="nofollow">SQLite</a> database. The data which I stored is in the HTML tags, for example, "Who is a good leader?"</p> <p><img src="http://i.stack.imgur.com/Lwuvc.png" alt="Enter image description here"></p> <p>Actually, my task is to display a question and its related image. I kept my images in a drawable folder. Now when the question is displayed along with that the image it should also display. How do I achieve this task?</p>
android
[4]
4,759,222
4,759,223
Java Grade class, letter grade to number
<p>I'm writing a program that takes a letter grade. You'd get 4.0 for A, 3.0 for B, and so forth. If you enter B+ or B-, it will take subtract .3 or add .3 respectively (so B+ would be 3.3).</p> <p>In my code, when I test a letter like B+ it gives me .3 instead of actually returning the subtracted value of the actual grade. What am I doing wrong?</p> <pre><code>public class Grade { private String grade; private double gradeNum; // Constructor public Grade(String showGrade) { grade = showGrade; gradeNum = 0; } // getNumericGrade method to return grade number public double getNumericGrade() { String suffix; suffix = grade.substring(1); if(suffix.equals("+")) { gradeNum = gradeNum + .3; } else if(suffix.equals("-")) { gradeNum = gradeNum - .3; } String letterGrade = grade.substring(0); if(letterGrade.equalsIgnoreCase("A")) { gradeNum = 4.0; } else if(letterGrade.equalsIgnoreCase("B")) { gradeNum = 3.0; } else if(letterGrade.equalsIgnoreCase("C")) { gradeNum = 2.0; } else if(letterGrade.equalsIgnoreCase("D")) { gradeNum = 1.0; } else if(letterGrade.equalsIgnoreCase("F")) { gradeNum = 0.0; } else { System.out.println("Invalid letter grade"); } return gradeNum; } } </code></pre>
java
[1]
5,401,579
5,401,580
Should I declare Message object as class member?
<p>I have a few classes that frequently communicate with a service. Message are sent using </p> <pre><code>private void sendMessage(int what) { Message msg = Message.obtain(null, what); try { mServerMessenger.send(msg); } catch (RemoteException e) { } } </code></pre> <p>My question is </p> <ul> <li><p>Should I declare a class member <code>Message mMessage</code> instead of declaring it locally.</p></li> <li><p>If declare as a class member should I use the <code>Message constructor</code> or use <code>Message.obtain</code>.</p></li> <li><p>As class member do I need to call <code>recycle</code> in <code>onDestroy</code> if using <code>Message.obtain</code>.</p></li> </ul> <p>So far I do not experience any memory problem, but I would like to use the system resource as efficiently as possible.</p>
android
[4]
4,726,056
4,726,057
Measure start/pause/duration of video in android
<p>How can I measure the start,stop,duration and pause time of different video which is streaming from website?</p>
android
[4]
3,405,620
3,405,621
Using declaration for a class member shall be a member declaration (C++2003)
<p>Paragraph 7.3.3. of C++2003 standard states that</p> <blockquote> <p>Using declaration for a class member shall be a member declaration.</p> </blockquote> <p>This means that the following gives a syntax error:</p> <pre><code>struct S1 { static int var1; }; using S1::var1; </code></pre> <p>While the following compiles fine:</p> <pre><code>namespace N2 { int var2; } using N2::var2; </code></pre> <p>Does anybody know the rationale (if any) behind that?</p> <p>Even more, the standard gives explicit example with static data member of the struct and tells that it should cause syntax error. MS C++ gives this error:</p> <blockquote> <p>cpptest1.cxx(9) : error C2885: 'S1::var1': not a valid using-declaration at non-class scope</p> </blockquote> <p>It is still not clear why this should be banned.</p>
c++
[6]
4,272,228
4,272,229
Is the way I have my admin panel set up good?
<p>So basically, <a href="http://github.com/a2h/Ze-Very-Flat-Pancaek-CMS/blob/1630d6337d93fd7cc7612020ac136fb3edef8b00/trunk/zvfpcms/admin/admin.php" rel="nofollow">this</a> is what I have.</p> <p>But is this a good practice? I started splitting up my admin.php file due to it growing in size.</p> <p>However, I have a slight concern over how many files I could potentially end up with, and also problems to work with in case something may need to be updated over all the files.</p>
php
[2]
589,335
589,336
Problem adding custom view to navBarItem
<p>Can anyone explain to me why the code below does not work correctly on iOS 3.1.3? On 4.0 it works great however on earlier versions the image is not respecting the size of the frame and is displaying in its original size leaving a huge image where my navItem should be???</p> <pre><code>flipView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; flipView.contentMode = UIViewContentModeScaleAspectFit; detailFlipButton = [UIButton buttonWithType:UIButtonTypeCustom]; detailFlipButton.frame = CGRectMake(0, 0, 30, 30); [detailFlipButton setImage:self.myImage forState:UIControlStateNormal]; detailFlipButton.imageView.contentMode = UIViewContentModeScaleAspectFit; [detailFlipButton addTarget:self action:@selector(flipAction) forControlEvents:UIControlEventTouchUpInside]; [flipView addSubview:detailFlipButton]; UIBarButtonItem *flipBarButton = [[UIBarButtonItem alloc] initWithCustomView:flipView]; self.navigationItem.rightBarButtonItem = flipBarButton; [flipBarButton release]; </code></pre> <p>Basically i am trying to accomplish something similar to the navItem in the top right corner of the iPod app which flips the view when tapped.</p>
iphone
[8]
670,502
670,503
PHP loop optimization
<p>I have a php method that creates an HTML table with data it retrieves from a property. My biggest concern is the performance of my application because I deal with a large amount of data.</p> <pre><code>public function getHTML() { $phpObj = json_decode($this-&gt;data); // array(object, object, object, ....); $table = "&lt;table&gt;&lt;tbody&gt;\n"; if (count($phpObj-&gt;query-&gt;results-&gt;row) &gt; 0) { $row = $phpObj-&gt;query-&gt;results-&gt;row; foreach ($row as $value) { $table .= "&lt;tr&gt;\n"; foreach ($value as $key =&gt; $val) { // concerned about loop inside loop $table .= "&lt;td&gt;" . $value-&gt;$key . "&lt;/td&gt;"; } $table .= "\n&lt;/tr&gt;\n"; } $table .= "&lt;/tbody&gt;&lt;/table&gt;"; return $table; } else { return 'HTML table not created.'; } } </code></pre> <p>Is there a more efficient way of traversing through the array and objects without creating a loop inside a loop?</p>
php
[2]
2,634,341
2,634,342
jQuery: How to make news ticker stop move when over on it
<p>Does anyone help me to make the <a href="http://geschke.name/dev/newsticker/" rel="nofollow">news items</a> stop moving when hover on it?</p> <p><a href="http://geschke.name/dev/newsticker/" rel="nofollow">http://geschke.name/dev/newsticker/</a></p> <p>Many thanks.</p>
jquery
[5]
3,966,127
3,966,128
Android Web Service call stopped working all of a sudden
<p>I had the following code working for months...and all of a sudden it stops working:</p> <p>Here is the error I get: org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @1:6 in java.io.InputStreamReader@4494c480)</p> <p>Does anybody know why..??</p> <pre><code> try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("ZIP", zipcode); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); Object result = envelope.getResponse(); WeatherResult = result.toString(); } catch (Exception E) { E.printStackTrace(); } </code></pre>
android
[4]
5,373,777
5,373,778
Foreground on window except for specified element
<p>I have found how to make a semi-transparent foreground on a set of HTML elements <a href="http://stackoverflow.com/questions/7642030/transparent-foreground">here</a>.</p> <p>However, I would like to put a foreground on the whole document <em>except</em> a specified element. How can I do that?</p>
jquery
[5]
819,587
819,588
Properties added to object are undefined?
<p>I'm trying to create an object that acts similarly to a hash or dictionary in other languages. I'm doing this with a <code>for</code> loop and assigning a key and value from an array but if I have more than one property the others become undefined. I'm trying to create key value pairs of from data (<code>i</code>). Any help would be appreciated, thanks!</p> <pre><code>arrayOfRecievedHTML = recievedHTML.split('&lt;endOfCommentInformation&gt;'); for(j = 0; j &lt; i.length - 1; j++) { arrayOfIndividualComment = arrayOfRecievedHTML[j].split('&lt;commentSeperator&gt;'); arrayOfComments[arrayOfIndividualComment[0]] = arrayOfIndividualComment[1]; } </code></pre> <p>Edit: Example of what e would be is:</p> <pre><code>3&lt;commentSeperator&gt;Intersting&lt;endOfCommentInformation&gt; 5&lt;commentSeperator&gt;Nice&lt;endOfCommentInformation&gt; </code></pre>
javascript
[3]
3,351,144
3,351,145
How to know if is the app first execution after device reboot
<p>I want to know if there are any method to know if is the first exuction of an app after reboot, or the app is alredy executed by the user (the app have one activity and to recivers).</p> <p>I'm thinking in methods like write and rewrite a token file every minute, and each time the app starts, check the lastmodified property to know the state, but i think that must be smart ways to do it.</p> <p>Any idea?</p> <p>Thanks in advance,</p>
android
[4]
1,467,750
1,467,751
Usage of extern keyword and multiple translation units
<p>I am reading Item 4 of Scott Meyer's Effective C++ where he is trying to show an example where a static non-local object is used across different translation units. He is highlighting the problem whereby the object used in one translation unit does not know if it has been initialised in the other one prior to usage. Its page 30 in the third edition in case anyone has a copy.</p> <p>The example is such:</p> <p>One file represents a library:</p> <pre><code>class FileSystem{ public: std::size_t numDisks() const; .... }; extern FileSystem tfs; </code></pre> <p>and in a client file:</p> <pre><code>class Directory { public: Directory(some_params); .... }; Directory::Directory(some_params) { ... std::size_t disks = tfs.numDisks(); ... } </code></pre> <p>My two questions are thus:</p> <p>1) If the client code needs to use <code>tfs</code>, then there will be some sort of include statement. Therefore surely this code is all in one translation unit? I do not see how you could refer to code which is in a different translation unit? Surely a program is always one translation unit?</p> <p>2) If the client code included FileSystem.h would the line <code>extern FileSystem tfs;</code> be sufficient for the client code to call tfs (I appreciate there could be a run-time issue with initialisation, I am just talking about compile-time scope)?</p> <p><strong>EDIT to Q1</strong></p> <p>The book says these two pieces of code are in separate translation units. How could the client code use the variable <code>tfs</code>, knowing they're in separate translation units??</p>
c++
[6]
1,444,183
1,444,184
checkbox select all toggle function
<p>I have multiple checkboxes and the first checkbox value is select all. My jQuery code is</p> <pre><code>$(".checkboxFilter input:checkbox:first").change().toggle(function () { alert("inside first toggle"); $(".checkboxFilter").find(':checkbox').prop("checked", true); }, function () { alert("inside second toggle"); $(".checkboxFilter").find(':checkbox').prop("checked", false); }); </code></pre> <p>The issue is when I render the page, by default the select all button is checked but no other options are checked. When i click the select all checkbox again it selects all and when i click the select all button once more it deselects all but the select all button still remains checked. Can anyone help me </p>
jquery
[5]
2,041,950
2,041,951
listbox select issue
<p>I have the code provided below. I've tried using jquery to select to make something happen but eventually what I have doesnt work or may be incorrect.</p> <pre><code>$("#emailList option").click(function() { alert("OMG"); }); &lt;select id="emailList" multiple="multiple" name="emailList"&gt; &lt;option&gt;abc@123.com&lt;/option&gt; &lt;/select&gt; </code></pre> <p>can someone provide me with the correct way of selecting an item from my listbox?</p>
jquery
[5]