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,616,867
1,616,868
How can I create a copy of my data type I created in Java?
<p>If I have a class:</p> <pre><code>public class MyType { private List&lt;Integer&gt; data; private boolean someFlag; public MyType(List&lt;Integer&gt; myData, boolean myFlag) { this.data = myData; this.myFlag = someFlag; } } </code></pre> <p>Now, if I create an instance of MyType, how do I do a deep copy of it? I don't want the new object to point to the old reference, but an entirely new instance.</p> <p>Is this a case when I should implement the Cloneable interface, or is that a used for shallow copies? </p> <p>I can't just do:</p> <pre><code>MyType instance1 = new MyType(someData, false); MyType instance2 = new MyType(instance1.getData(), instance1.getFlag()); </code></pre> <p>I'm concerned about new instances of MyType pointing to the same reference for its "data" variable. So I need to copy it entirely.</p> <p>So, if I have an existing object:</p> <pre><code>MyType someVar = new MyType(someList, false); // Now, I want a copy of someVar, not another variable pointing to the same reference. </code></pre> <p>Can someone point me in the right direction?</p>
java
[1]
3,610,541
3,610,542
Web connection does not work if I automatically concat 'http://' to the front
<p>I made a WebConnection Java script that gets the HTML from a specified website. It works, but when I try to make things easier by automatically concatinating <code>http://</code> onto the front, it does not work, despite the fact that the Strings should be the same (it gives a <code>java.lang.IllegalArgumentException</code>). Here is my code:</p> <pre><code>package WebConnection; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import javax.swing.JOptionPane; public class WebConnect { URL netPage; public WebConnect() { String s = "http://"; s.concat(JOptionPane.showInputDialog(null, "Enter a URL:")); System.out.println(s); System.out.println(getNetContent(s)); //The above does not work, but the below does //System.out.println(getNetContent(JOptionPane.showInputDialog(null, "Enter a URL:"))); } private String getNetContent(String u) { try { netPage = new URL(u); } catch(MalformedURLException ex) { JOptionPane.showMessageDialog(null, "BAD URL!"); return "BAD URL"; } StringBuilder content = new StringBuilder(); try{ HttpURLConnection connection = (HttpURLConnection) netPage.openConnection(); connection.connect(); InputStreamReader input = new InputStreamReader(connection.getInputStream()); BufferedReader buffer = new BufferedReader(input); String line; while ((line = buffer.readLine()) != null) { content.append(line + "\n"); } } catch(IOException e){ JOptionPane.showMessageDialog(null, "Something went wrong!"); return "There was a problem."; } return content.toString(); } public static void main(String[] args) { new WebConnect(); } </code></pre> <p>For example, if I run first section of webConnect() and type <code>google.com</code> it does not work, but if I run the commented out line instead, and type <code>http://google.com</code>, it does not give an error. Why?</p> <p>Thanks in advance!</p>
java
[1]
34,726
34,727
class constructor not processing when called from inside another class constructor
<p>I have a ready made class X</p> <pre><code>class X { private $pA; function __construct($id=0) { $pA=new myClass($id); } } class myClass { private $id; function __construct($id=0) { echo 'constructing....'; } } </code></pre> <p>But there is no echo output the class construction stops at the new operator.</p> <p>sorry there is () after myclass I mistook</p>
php
[2]
1,468,455
1,468,456
Interface for Service class?
<p>I want to implement my database helper class as a service, but it already extends SQLiteOpenHelper... is there an interface for Service available in android? </p>
android
[4]
5,913,662
5,913,663
Strange char**/calloc behavior
<p>When I debug the following code, <code>strncpy</code> works fine but as soon as the loop exits, I see that <code>parent_var_names</code> is pointing <code>NULL/0xfdfdfddf</code>. I am puzzled!</p> <pre><code>parent_var_names = (const char**)calloc(net-&gt;nodes[x]-&gt;num_parents, sizeof(const char*)); for(int i(1); i &lt; net-&gt;nodes[x]-&gt;num_parents; ++i) { parent_var_names[i] = (const char*)malloc(strlen(rhs_arr[net-&gt;nodes[x]-&gt;markov_parents[i]])); strncpy((char*)parent_var_names[i], (char*)rhs_arr[net-&gt;nodes[x]-&gt;markov_parents[i]], strlen(rhs_arr[net-&gt;nodes[x]-&gt;markov_parents[i]])); } </code></pre>
c++
[6]
970,732
970,733
Android button font size
<p>I;ve been trying to create a custom button in android using this tutorial - <a href="http://www.gersic.com/blog.php?id=56">http://www.gersic.com/blog.php?id=56</a></p> <p>It works well but it doesn't say how to change the font size or weighting. Any ideas?</p> <p>There was another question on here and the only answer was to use html styling but you can't change a font size in html without using css (or the deprecated font tag). There must be a better way of setting the pixel size of the font used on buttons?</p>
android
[4]
4,824,164
4,824,165
about the concept of jQuery load()
<p>I just started learning jquery and I am struggling on some concept problem. If I use load() to update one of the div sections in my website, e.g.:</p> <pre><code> //link to open another page $('a#open_page').click(function() { var myURL = "page.php"; $('#ajaxHandle').load(myURL); return false; }); </code></pre> <p>My question is, is everything in page.php going to be loaded literally? If page.php has some headers or php code, are they going to be loaded as well? </p>
jquery
[5]
8,674
8,675
Dynamically allocating memory on stack
<p>There is such code:</p> <pre><code>#include &lt;iostream&gt; int main() { int a; int* p = new (&amp;a) int(2); std::cout &lt;&lt; a &lt;&lt; std::endl; // delete p; error BLOCK TYPE IS INVALID std::cin.get(); return 0; } </code></pre> <p>The output is:</p> <pre><code>2 </code></pre> <p>Why is it possible to dynamically allocate memory on stack? (I thought that heap is the right place to do this). And, why does delete operator return error in this case, but new operator work?</p>
c++
[6]
915,254
915,255
validate an image before uploading in php
<p>i am uploadind an image in php using copy function. my imade doesnt display when the image height is less than 981pz &amp; width is less than 477pz </p>
php
[2]
254,656
254,657
Novice Javascript query about bad input
<p>I am making a simple tip calculator to help myself learn Javascript. The problem I can't solve is how to compensate for "bad input".</p> <p>In the code below if the user prefaces the numeric input amount with a dollar sign <code>$</code>, the result is <code>NAN</code>. </p> <pre><code>function tipAmount(){ var dinner=prompt("How much was dinner?"); result = dinner*.10; alert("Your tip is " +"$"+result ); } </code></pre> <p>How do I fix that.</p>
javascript
[3]
3,813,448
3,813,449
Stack over flow in java script inheritance!
<p>i have the below prog</p> <pre><code> Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor = this; }; Object.prototype.method = function(name, func) { this.prototype[name] = func; }; function StrangeArray(){} StrangeArray.inherit(Array); StrangeArray.method("push", function(value) { Array.prototype.push.call(this, value); }); var strange = new StrangeArray(); strange.push(4); alert(strange); </code></pre> <p>and when irun it i get stack over flow? any ideas why?</p>
javascript
[3]
4,332,523
4,332,524
How to use remember me function in my android login application
<p>I am using the code for remember my username and password. i have tried a lot of hours for the code for remember my username name and password but i cant success in it.</p> <p>Here is my code which i have download from internet but it didn't work for me.</p> <p>I have declared this variable in the extends activity.</p> <pre><code> public static final String PREFS_NAME = "MyPrefsFile"; public static final String PREFS_USER = "prefsUsername"; public static final String PREFS_PASS = "prefsPassword"; </code></pre> <p>after that I have also declare different variable like below.</p> <pre><code> public String PREFS_USERS; public String PREFS_PASS; String username; String upass; </code></pre> <p>and in the click listener i have given the following code.</p> <pre><code> SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE); username = etUsername.getText().toString(); upass = etPassword.getText().toString(); getSharedPreferences(PREFS_NAME, MODE_PRIVATE) .edit() .putString(PREFS_USERS, username) .putString(PREFS_PASS, upass) .commit(); </code></pre> <p>and at the time at retry i have return the following code in the <code>oncreate</code> activity to retry my user name and password.</p> <pre><code> SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE); username = pref.getString(PREFS_USERS, ""); upass = pref.getString(PREFS_PASS, ""); </code></pre> <p>But when I run the application i cant get the username and password.First time when i load the application i checked the remember me check box after log in and log out back from the application and close the application and when come back to it.it was not saved for me. </p>
android
[4]
4,736,224
4,736,225
IPhone app crash report
<p>I am building an iphone app.However my app crashes at a point when i run simulator.I want to know the reason.But i don't know how to see crash logs. Please give me some information about how to see crash logs. </p>
iphone
[8]
4,934,707
4,934,708
How to show image on hover in popup using jquery?
<p>I have lots of pets in a dropdown. what i want to achieve is that when ever i hover on dropdown, it will display the image of particular pet as a popup.</p> <p>Any idea how can i achieve that?</p>
jquery
[5]
3,151,828
3,151,829
java modify existing openoffice ods file with macro
<p>i have a openoffice spreadsheet which contains marco. im using jopendocument to modify a cell and it's taking forever. the file size is about 4mb. i tried on a small file and it works without much problem.</p> <p>is there a way around it? here is my code:</p> <pre><code>File fileinput = new File("/dir/to/my/file/filename.ods"); final Sheet sheet = SpreadSheet.createFromFile(fileinput).getSheet(2); sheet.getCellAt("A6386".setValue("helloworld"); sheet.getSpreadSheet.saveAs(fileinput); </code></pre>
java
[1]
2,054,103
2,054,104
C++ function that returns system date
<p>I need function in c++ that allows me to retrieve and store the system date. I have a class for storing dates.</p>
c++
[6]
863,757
863,758
How to use NTEventLogAppender?
<p>HI, I used this code in WindowXP, but I can't use NTEventLogAppender. I dont't find the help documnet about NTEventLogAppender. Please give an example! Thank you!</p>
c++
[6]
4,087,032
4,087,033
Best practice switching place of two items in an array
<p>What is best practice for switching two items place in an Array via JavaScript?</p> <p>For example if we have this array <code>['one', 'two', 'three', 'four', 'five', 'six']</code> and want to replace two with five to get this final result: <code>['one', 'five', 'three', 'four', 'two', 'six']</code>.</p> <p><img src="http://i.stack.imgur.com/CK1DO.png" alt="enter image description here"></p> <p>The ideal solution is short and efficient. </p> <p>Update:</p> <p>The <code>var temp</code> trick is working and I know it. My question is: is using <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array#Methods" rel="nofollow">JavaScript native Array methods</a> faster or not? </p> <p>Something like <code>array.splice().concat().blah().blah()</code> seems is faster and use less memory. I didn't develope a function that using Array methods but I'm sure it's possible.</p>
javascript
[3]
4,075,053
4,075,054
JS Invalid left-hand side expression in postfix operation?
<p>I am playing with a javascript and am running into an error. The error is this:</p> <p>Invalid left-hand side expression in postfix operation.</p> <p>And the script is long but I think this is this issue. The weird thing is this works when I run it locally, but when it is packaged, using asset_packager, it fails.</p> <p>Any ideas why I might be getting this error?</p> <p><strong>UPDATE:</strong> After doing more research I found this function. The error seems to happen after in the "while" statement and I assume it's the "++ + a + ". This is a plugin so I didn't want to go messing with the code...but do you thing this could be it?</p> <pre><code>m.getInternetExplorerMajorVersion = function() { var a = m.getInternetExplorerMajorVersion.cached = typeof m.getInternetExplorerMajorVersion.cached != "undefined" ? m.getInternetExplorerMajorVersion.cached : function() { var a = 3, b = d.createElement("div"), c = b.getElementsByTagName("i"); while ((b.innerHTML = "&lt;!--[if gt IE "++ + a + "]&gt;&lt;i&gt;&lt;/i&gt;&lt;![endif]--&gt;") &amp;&amp; c[0]) Uncaught ReferenceError: Invalid left-hand side expression in postfix operation ; return a &gt; 4 ? a : !1 }(); return a } </code></pre>
javascript
[3]
971,594
971,595
Scandir fails to open directory
<pre><code>$contentdirectory = '/dead-wave/dead-wave_content'; $contentlaunch = scandir($contentdirectory); </code></pre> <p>that's what I'm using to create an array from which I echo it's values using a for each statement. this works perfectly on my dedicated server, but once hosted on godaddy servers returns an error message 'failed to open dir: No such file or directory in...' now the directory path is certainly correct the actual problem is unknown to me. Any Thoughts?</p>
php
[2]
5,904,175
5,904,176
python Ansi escape Sequences can I get the size of a window
<p>So I'm writing a program, to learn about ANSI escape sequences, like \033... So I was wondering if there was a way I could get the height and width of the window it's displayed in, like the terminal window on a mac. I looked for a while, but this could still be a duplicate question.</p> <p>Edit: Duplicate of <a href="http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python">How to get console window width in python</a></p>
python
[7]
1,321,528
1,321,529
c# how to get the row number from a datatable
<p>i am looping through every row in a datatable:</p> <pre><code>foreach (DataRow row in dt.Rows) {} </code></pre> <p>i would like to get the index of the current row within the dt datatable. for example:</p> <pre><code>int index = dt.Rows[current row number] </code></pre> <p>how do i do this?</p>
c#
[0]
1,913,623
1,913,624
ASP.net Imitate Slow Connection Speed
<p>Our web application is meant to be run on remote locations with very slow internet speed. We are considering various factors to reduce application overheads. This question is only related to see how our application would work on slow bandwidth.</p> <p>We are still on development, we would like to be able to browse our web application on speed around 32kbps and 128 kbps on an internet browser, preferably firefox.</p> <p>Is this possible with firefox to browse a website with max "x" speed?</p>
asp.net
[9]
5,685,675
5,685,676
Need help with custom validation for jQuery validation plugin
<p>I'm using the jQuery validation plugin found here:</p> <p><a href="http://plugins.jquery.com/project/validate" rel="nofollow">http://plugins.jquery.com/project/validate</a></p> <p>In my form I have default values saying "Please enter your name" in the name field. I'd like a custom validation to ensure that a user has not left this when they submit the form.</p> <p>Here's the jQuery i'm using.... Can someone please help me with the missing code.</p> <p>Thanks :)</p> <pre><code>$(document).ready(function(){ $.validator.addMethod('defaultText', function(value, element) { // need code to go here!!! }, 'Please enter your first name'); $("#commentForm").validate({ rules: { firstname: { required: true, defaultText: true, }, email: { required: true, email: true } }, messages: { firstname: "Please enter your first name", email: "Please enter a valid email address" } }); }); </code></pre>
jquery
[5]
920,897
920,898
File download involving HTTP Basic Authentication
<p>In my Java program i want to download a file from a server that uses Http Basic Authentication. Can i use the URL class of java.net package for this purpose ?.If not,which java class should i use ?</p> <p>Please Help Thank You</p>
java
[1]
4,733,272
4,733,273
how to display next array value on button click?
<p>I have a session array containing lessonid, lesson name and description.</p> <pre><code>&lt;?php include "db.php"; $_SESSION['lesson_ids']; ?&gt; &lt;table&gt; &lt;tr&gt;&lt;td&gt;Lesson name &lt;/td&gt; &lt;td&gt; description &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;input type="button" name="next" value="next"&gt; &lt;/table&gt; </code></pre> <p>In that session array, I have 3 sets of data. I want to display one lesson in the current page.</p> <p>When I click next the button, I need to display the next one.</p> <p>How can this be done?</p>
php
[2]
4,858,094
4,858,095
XMLType - SQL state [99999]; error code [31011]; could not update:
<p><a href="http://stackoverflow.com/questions/3064330/how-to-map-xmltype-with-jpa-hibernate">http://stackoverflow.com/questions/3064330/how-to-map-xmltype-with-jpa-hibernate</a></p> <p>I have done XMLType mappings with Hibernate @Type with the help of above URL.</p> <p>It works fine when I persist with the data type HibernateXmlType. It has results however, it throws below exception:</p> <p>org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [update BTI_DBA.SAMPLE_XMLINSTRUCTIONS set INSTRUCTION_XML=? where INSTRUCTION_ID=?]; SQL state [99999]; error code [31011]; could not update: [com.tutorial.model.SampleXmlInstructions#4871852354547076634]; nested exception is org.hibernate.exception.GenericJDBCException: could not update: [com.tutorial.model.SampleXmlInstructions#4871852354547076634] ......... ......... Caused by: java.sql.SQLException: ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00209: PI names starting with XML are reserved Error at line 1</p>
java
[1]
5,819,254
5,819,255
Force JavaScript exception/error when reading an undefined object property?
<p>I'm an experienced C++/Java programmer working in Javascript for the first time. I'm using Chrome as the browser.</p> <p>I've created several Javascript classes with fields and methods. When I read an object's field that doesn't exist (due to a typo on my part), the Javascript runtime doesn't throw an error or exception. Apparently such read fields are 'undefined'. For example:</p> <pre><code>var foo = new Foo(); foo.bar = 1; var baz = foo.Bar; // baz is now undefined </code></pre> <p>I know that I can check for equality against 'undefined' as mentioned in "<a href="http://stackoverflow.com/questions/27509/detecting-an-undefined-object-property-in-javascript">Detecting an undefined object property in JavaScript</a>", but that seems tedious since I read from object fields often in my code.</p> <p><strong>Is there any way to force an error or exception to be thrown when I read an undefined property?</strong></p> <p>And why is an exception thrown when I read an undefined variable (as opposed to undefined object property)?</p>
javascript
[3]
3,776,752
3,776,753
How to print or get JRE version of an application running on a server?
<p>I mean using javacode I want to find the JRE version of application but not server. In my production server I am having thousands of applications in java like tomcat,websphere,axway etc. I want to know particular application jre version.I will write a class and I want print using that. That class will be placed in particular application.</p> <p>I tried <a href="http://stackoverflow.com/questions/222187/how-to-check-jre-version-prior-to-launch">this link</a> but I didn't get it.</p>
java
[1]
3,832,455
3,832,456
ASp.net tooth charting components?
<p>Just wondering if any of you have idea how to display tooth charts (dental related) in asp.net. Any links/references would be helpful. Thanks N</p>
asp.net
[9]
903,482
903,483
String split() not working correctly
<pre><code>temp = line.split(","); if (i &lt; paymentFieldsMapIndex.size()) { paymentFields.put(paymentFieldsMap.get(next).toString(), temp[i]); } </code></pre> <p>This code splits up a comma delimited string into substrings and populates a HashMap value using the resulting substrings.</p> <p>Some substring values look funny in the resulting HashMap, looks like it's due to the presence of commas in the token.</p> <p>For instance</p> <p>,"LONDON,UNITED KINGDOM",</p> <p>in the string appears in the HashMap like</p> <p>Key = key, Value = "LONDON</p> <p>I thought that String split(), will not break up substrings containing the delimiter if they are enclosed in double quotes?</p> <p>I've also tried escaping the embedded comma like</p> <p>,"LONDON\,UNITED KINGDOM",</p> <p>but the string in the HashMap looks like</p> <p>Key = key, Value = "LONDON\</p> <p>Am I missing something, or is there any way around this problem? Thanks.</p>
java
[1]
1,111,562
1,111,563
Calling Static Void Methods
<p>I'm still learning to use methods, but I hit another stump in the road. I'm trying to call a static void method in another static void method. So it roughly looks like this:</p> <pre><code>public static void main(String[] args) { .... } //Method for total amount of people on earth //Must call plusPeople in order to add to total amount of people public static void thePeople (int[][] earth) { How to call plusPeople? } //Method adds people to earth //newPerson parameter value predefined in another class. public static void plusPeople (int[][] earth, int newPerson) { earth = [newPerson][newPerson] } </code></pre> <p>I've tried a few different things which hasn't really worked.</p> <pre><code>int n = plusPeople(earth, newPerson); //Though I learned newPerson isn't recognized because it is in a different method. int n = plusPeople(earth); \ //I don't really understand what the error is saying, but I'm guessing it has to do with the comparison of these things..[] int n = plusPeople; //It doesn't recognize plusPeople as a method at all. </code></pre> <p>I feel very stupid for not being able to even call a method, but I've literally been stuck on this issue for about two hours now.</p>
java
[1]
4,835,446
4,835,447
Class method with class instace/object as arguments
<p>in Java is it valid to have the Class method with the argument as Class instance/object?</p> <p>Like:</p> <pre><code>Class.method(obj)? </code></pre>
java
[1]
4,439,516
4,439,517
PHP redirect to HTTPS if page is
<p>I need a PHP if/else statement that if the sign-in.php or register.php page is access over HTTP I would like to redirect to HTTPS else if any other page is accessed over HTTPS redirect to HTTP plus have any query string appended for example if a user tries to access a restricted page (<a href="http://domain.com/my-account.php" rel="nofollow">http://domain.com/my-account.php</a>) the site redirects the user to <a href="http://domain.com/sign-in.php?redirect=my-account" rel="nofollow">http://domain.com/sign-in.php?redirect=my-account</a> however, I would like the page to redirect to <a href="https://domain.com/sign-in.php?redirect=my-account" rel="nofollow">https://domain.com/sign-in.php?redirect=my-account</a>.</p> <p>I know I could simply change the header redirects to include https instead of http but users may type <a href="http://domain.com/sign-in.php?redirect=my-account" rel="nofollow">http://domain.com/sign-in.php?redirect=my-account</a> so just need to ensure if this happens sign in (or others) happen over https.</p> <p>Any help is appreciated</p>
php
[2]
2,357,807
2,357,808
C# display arraylist contents on main application with selection
<p>I have a form with a text box for a user to enter a search string for folder names. The app then finds matching folder(s) on the network.</p> <p>If a single folder is returned it opens in explorer.</p> <p>If multiple folders are returned in the search they are added to an array as a unc path.</p> <p>I need to know the best way or which object to use to populate the contents of the array with on the main form. I then need to be able to double click on the desired result to open the containing folder in explorer to handle multiple matches.</p> <p>searching for match1 array could contain something like: H:\match1, G:\Match1, K:\folder1\Match1</p>
c#
[0]
6,012,945
6,012,946
jquery is not refreshing the function
<p>I have a jquery function that suppose to delete last dynamic created div it delete first time but when I try to delete again it's giving me </p> <p>Microsoft JScript runtime error: 'null' is null or not an object</p> <pre><code>&lt;script type="text/javascript"&gt; jQuery("btnDeleteALineButton").click(function(e){ var lineCount = GetServiceLineCount(); if(lineCount &gt; 0 ){ $('ctrlServiceLine'+lineCount).remove(); lineCount = lineCount -1; } //e.preventDefault() }); &lt;/script&gt; </code></pre> <p>When I put alert I see that firt time give lineCount correct but never do -1</p> <p>can some one please help me</p>
jquery
[5]
4,306,629
4,306,630
Is there a way to invoke a static method of a class using a string which has the name of the class?
<p>I have an array of strings containing names of classes. Is it possible to invoke the static methods of the actual class using the 'name of the class' in the string array.</p> <pre><code>public class SortCompare { // There are classes called 'Insertion', 'Selection' and 'Shell' which have a // method called 'sort' private static String[] algorithm = { "Insertion", "Selection", "Shell"}; public static double timeTheRun(String alg, Comparable[] a) { for (int i = 0; i &lt; algorithm.length; i++) if (alg.equalsIgnoreCase(algorithm[i])) { Stopwatch timer = new Stopwatch(); // I want to invoke one of Insertion.sort(), Selection.sort() // or Shell.sort() depending on the value of 'alg' here break; } return timer.elapsedTime(); } </code></pre> <p>I could forget about the array of strings and simple use a if-else block to invoke them.</p> <pre><code> if (alg.equals("Insertion")) Insertion.sort(a); else if (alg.equals("Selection")) Selection.sort(a); else if (alg.equals("Shell")) Shell.sort(a); </code></pre> <p>But I will keep implementing other sorts and variations of them in future and every time I will have to make changes in multiple places(The above if-else loop, the help message of my program). If the former approach is possible then I'll just have to insert an extra string to the array every time.</p>
java
[1]
563,293
563,294
XMLHttpRequest in a loaded XMLHttpRequest
<p>I'm using javascript to load data in a <code>div</code> trough XMLHttpRequest now i'm wondering if it's possible to make another XMLHttpRequest in that loaded <code>div</code> so an new onclick in my result</p> <p>Greetings</p>
javascript
[3]
5,124,988
5,124,989
converting binary string into float
<p>I have an object that I am storing bits in. </p> <pre><code>class Bitset: def __init__(self, bitstring): self.bitlist = [] for char in bitstring: self.bitlist.append(int(char)) def flipBit(self, index): val = self.bitlist[index] val = (val + 1) % 2 self.bitlist[index] = val self.newBitstring() def bitstring(self): newString = '' for val in self.bitlist: newString = newString + str(val) return newString def __len__(self): return len(self.bitlist) def __str__(self): return self.bitstring() def __repr__(self): return self.bitstring() </code></pre> <p>Is there anyway I can convert the bits into a float? Thanks.</p>
python
[7]
5,366,576
5,366,577
looping through hidden fields within a php while loop that are in a table row
<p>How do I know which hidden field I should fetch a value from given a button clicked that is adjacent to the hidden fields. this button is also in the while loop hence giving rise to a list of buttons and hidden fields. each button has a hidden field adjacent to it.</p> <p>I want to use jquery ajax to insert data from the hidden field into a table in the DB but wen i loop through all the buttons to find out which one is clicked, it works well but the problem comes in wen i loop through the hidden fields, it gets the value of the last hidden field. How do i get the value of the hidden field just adjacent to the button that was clicked? I will really appreciate the help. Thanx in advance.</p> <pre><code>&lt;Table id="list_tb"&gt; &lt;?php while($rows=mysql_fetch_assoc(orderSQL)) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $rows['name'];?&gt;&lt;/td&gt; &lt;td&gt; &lt;form&gt; &lt;input type="submit" name="add_btn" id="add_btn" value="Add"/&gt; &lt;input type="hidden" name="order_id" id="order_id" value="&lt;?php echo $rows['order_id'];?&gt;"/&gt; &lt;/form &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/Table&gt; </code></pre> <p>THE JQUERY</p> <pre><code>$(#list_tb input[type=submit]).each(function(){ $(this).click(function(){ $(#list_tb input[type=hidden]).each(function(){ var value=$(this).val(); alert(value); }); }); }); </code></pre>
jquery
[5]
2,643,350
2,643,351
Need a map but only need to know if contained?
<p>I'm wondering if there is a more appropriate structure for my needs.</p> <p>I need to have a dictionary or strings (words). All I need to know is if a given word is in the dictionary.</p> <p>It seems like a waste of memory to make a map of string,string. Is there a better way?</p> <p>Thanks</p>
c++
[6]
5,037,493
5,037,494
Multiple upload put image names in same database row
<p>hi i have this script that works great but now im trying to get it to add the names of the 3 images to my database in the same database row if you upload 3 images the $extension will show the 3 names of the images but i have no idea how to get the 3 names into the same database row under image1 , images2, images3 anyone have any idea how this can be done? i tried everything i know of with no luck thanks.</p> <pre><code>`$connection = mysql_connect("localhost", "????", "????"); mysql_select_db("????", $connection); $uploaddir = "upload/"; $MaxSize = "600000"; $number_of_files = count($_FILES['userfile']); for($i=0;$i&lt;=$number_of_files;$i++) { $filename_format = uniqid(Img_); if (!$_FILES['userfile']['size'][$i] == 0) { if ($_FILES['userfile']['size'][$i] &gt; $MaxSize) { echo "ERROR: file too big"; exit;} $tempfile = $_FILES['userfile']['tmp_name'][$i]; $uploadfile = $_FILES['userfile']['name'][$i]; $extension = $_FILES['userfile']['type'][$i]; if (strstr($extension,"jpeg")) { $extension=".jpg"; } elseif (strstr($extension,"gif")) { $extension=".gif"; } elseif (strstr($extension,"png")) { $extension=".png"; } else { echo "ERROR: Only gif/jpeg/png allowed."; exit; } if(copy($tempfile, $uploaddir.$uploadfile)) { echo "Copy Successfull!"; } else { echo "ERROR: something happened trying to copy the temp file to the folder"; } if(rename($uploaddir.$uploadfile,$uploaddir.$filename_format.$extension)) { }else{ $query = "INSERT INTO photos (image1, image2, image3) VALUES ('WHAT TO PUT HERE?','HERE','AND HERE')"; $result = mysql_query($query); echo " and renamed to $filename_format$extension"; } } else { echo "ERROR: Problem renaming the file.. $uploadfile"; } }`. </code></pre>
php
[2]
4,666,702
4,666,703
Search in site contents by php
<p>I use codeigniter.I want search in site contents for several word, that did existence it word in it site or no? if existence a word (of all words) in it site return is FALSE. i tried as following code but get error. How can done it?</p> <p><strong>DEMO:</strong> <a href="http://codepad.viper-7.com/rFiL01" rel="nofollow">http://codepad.viper-7.com/rFiL01</a></p> <pre><code>&lt;?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'stackoverflow.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $contents = curl_exec($ch); curl_close($ch); $link[] = array("Questions", "Favorite", "myfoodho"); foreach($link as $val){ stristr($contents,$val); // Line 148 //if(){ // return true; //}else{ // return false; //} } ?&gt; </code></pre> <p>Error:</p> <blockquote> <p>A PHP Error was encountered</p> <p>Severity: Warning</p> <p>Message: stristr() [function.stristr]: needle is not a string or an integer</p> <p>Filename: views/exchange.php</p> <p>Line Number: 148</p> </blockquote>
php
[2]
5,121,505
5,121,506
Creating a select tag with options in JQUERY
<p>Is it possible to create a select tag with options in JQuery.</p> <pre><code> $("&lt;select id="jSelect"&gt; &lt;option value="1"&gt;String&lt;/option&gt; &lt;option value="2"&gt;Number&lt;/option&gt; &lt;option value="3"&gt;Date&lt;/option&gt; &lt;/select&gt;").appendTo(".menu li") </code></pre> <p>Should this work? Its not working for me.</p>
jquery
[5]
2,622,617
2,622,618
Running an exe from C# with arguments that have spaces in
<p>I am scratching my head with this one. I am trying to run an exe from C# using system.diagnostics but it isnt passing over my arguments correctly so the exe falls over.</p> <p>It splits the path after the word 'here' (see below) because of the space in it.</p> <p>Does anyone know how I can get round this without renaming the directory (which isn't an option for me)</p> <p><strong>This works from command line:</strong></p> <p>"C:\Users\me\Desktop\myexternalexe\myexternalexe.exe" comments “\192.168.1.1\a\here is the problem\c\d\"</p> <p><strong>This doesn't from with in Visual Studio:</strong></p> <pre><code>Process myexternalexe = new Process(); myexternalexe.StartInfo.FileName = @"C:\Users\me\Desktop\myexternalexe\myexternalexe.exe"; myexternalexe.StartInfo.Arguments = @"comments \\192.168.1.1\a\here is the problem\c\d\"; myexternalexe.Start(); </code></pre>
c#
[0]
350,595
350,596
free function and inheritance
<p>I am trying a basic thing with two classes and a free functions. First I have two classes : </p> <pre><code>struct BASE{ BASE(int a = 0):a_(a){}; virtual ~BASE(){}; virtual void foo(){std::cout &lt;&lt; "BASE " &lt;&lt; std::endl;} int a_; }; struct DERIVED: public BASE{ DERIVED():BASE(){}; void foo(){std::cout &lt;&lt; "DERIVED " &lt;&lt; std::endl;} }; </code></pre> <p>then I fill up a std::vector (or boost::ptr_vector)</p> <pre><code>std::vector&lt;BASE* &gt; vec; vec.push_back( new BASE(2)); vec.push_back( new DERIVED); </code></pre> <p>If I call my function foo, no pb the virtual stuff works well, but if I create two free functions :</p> <pre><code>void foo(BASE* a, DERIVED* b){ std::cout &lt;&lt; " mix base/derived " &lt;&lt; std::endl; } void foo(BASE* a, BASE* b){ std::cout &lt;&lt; " full base " &lt;&lt; std::endl; } </code></pre> <p>if I do </p> <pre><code>foo(vec[0], vec[1]); //failed </code></pre> <p>I will get the message </p> <pre><code>full base </code></pre> <p>Well it is logical because I have vector of BASE*, but does it exist anyway to get the good call to my free function ? I need the inheritance so I can not really separate the 2 classes because I must fill up this container</p> <p>Moreover at the end my vector will be fill up randomly, so I can not know by advance how cast properly.</p>
c++
[6]
613,561
613,562
why getMonth() starts with 0
<p>I was coding a function to remove a day from a date value in javascript and i was kind of surprise that javascript's getMonth() starts from 0 for January to 11 for December. Why javascript's getMonth() starts with 0?</p>
javascript
[3]
817,024
817,025
Not processing php file for highlight_file function
<p>showcode.php</p> <pre><code>&lt;?php $source = $file; highlight_file( $source ); ?&gt; </code></pre> <p>showcode.php?file=to_study.php</p> <p>In some cases to_study.php file gets processed and I do not get the highlighted code. Error something like:</p> <pre><code>Warning: Unterminated comment starting line 197 on line 3 </code></pre> <p>I do not want to process the to_study.php file. I just want it to be highlighted in browser.</p>
php
[2]
356,501
356,502
Evaluating subset of a list using in operator
<p>I have following test code.</p> <pre><code>a = ['a', 'b', 'c', 'd', 'e'] c = a * 3 b = a </code></pre> <p>but <code>b in c</code> returns False. b is a sub sequence of c and the list c contains b. So why is it returning false?</p> <p>Thanks in advance.</p>
python
[7]
1,817,501
1,817,502
Javascript Interval not working
<p>I got 2 function in my javascript interval: I start the interval with 2 html buttons, start (starts it) and stop (stops it)</p> <p>This is started:</p> <pre><code>function start_sync(){ //runs the interval if(sync_interval == false) { sync_interval = setInterval(function(){ gl_context.drawImage(gl_video,0,0,gl_cw,gl_ch); update_seek_slider_position(gl_video.currentTime); },10); sync_interval_running = true; }; console.log("Sync Interval Started"); }; </code></pre> <p>This is called when I press stop:</p> <pre><code>function stop_sync(){ if(sync_interval == true) { clearInterval(sync_interval); //stops the interval sync_interval_running = false; }; console.log("Sync Interval Stopped"); } </code></pre> <p>ok the thing is that, the second functions DOES NOT STOP, "update_seek_slider_position(gl_video.currentTime);" it still goes one. </p> <p>Does the js interval only accepts one function?</p>
javascript
[3]
5,639,889
5,639,890
all divs in my jquery code
<p>I have 3 html box as follow:</p> <pre><code>&lt;div class="tabs"&gt; &lt;ul class="tabNav"&gt; &lt;li&gt;&lt;a href="#video"&gt;Video Gallery&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#photo"&gt;Photo Gallery&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="video"&gt; video div &lt;/div&gt; &lt;div id="photo"&gt; photo div &lt;/div&gt; &lt;/div&gt; &lt;div class="tabs"&gt; &lt;ul class="tabNav"&gt; &lt;li&gt;&lt;a href="#comment"&gt;comment&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#links"&gt;links&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="comment"&gt; comment div &lt;/div&gt; &lt;div id="links"&gt; links div &lt;/div&gt; &lt;/div&gt; </code></pre> <p>for show and hide tabs i used this jquery code:</p> <pre><code>$(function () { var container = $('div.tabs &gt; div'); container.hide().filter(':first').show(); $('div.tabs ul.tabNav a').click(function () { container.hide(); container.filter(this.hash).show(); $('div.tabs ul.tabNav a').removeClass('selected'); $(this).addClass('selected'); return false; }).filter(':first').click(); }); </code></pre> <p>This code only works with firts box (gallery) and with page load, the comment and links are also hidden. How can I solve this? Thanks in advance</p>
jquery
[5]
1,788,916
1,788,917
Android imagebutton does not flash on click
<p>I've implemented an ImageButton. All works well except when I press on it, it doesn't "flash" before moving on (to another activity). Does Android has intrinsic "flash" for ImageButton or I have to write/animate that explicitly inside onClickEvent? or use Selector? </p> <p>Thanks in advance for all your help.</p>
android
[4]
1,824,447
1,824,448
Python: Custom Exception Class deriving from ValueError
<p>My question seems rather simply, but I didn't find any post to this particular issue. I need my own custom exception class deriving from ValueError to print the expected type (standard error msg) as well as the type that was entered (with custom text).</p> <pre><code>class MyOwnException(ValueError): ... try: raise MyOwnException ( int('str') ) #not sure what to do here, as I only want to #raise the exception if incorrect value type except MyOwnException as e: print "Error: Expected type", e.expType() #int print "Error: Entered type", e.entType() #string </code></pre> <p>To add to the above and raising my custom exception via the built-in ValueError:</p> <pre><code>class MyOwnException(ValueError): def __init__(self, value): self.value = value print "Error: Expected type", type(self.value) #int print "Error type", self.value #how to return expected value type? try: int('str') except ValueError as e: raise MyOwnException(e) </code></pre> <p>I would very much appreatiate any help in this regard. Thanks very much! Cheers, Manuel</p>
python
[7]
246,150
246,151
Strange error at a ternary operator usage
<p>I have a following code:</p> <pre><code>#include &lt;iostream&gt; int main() { int i = 3; do { (i == 3) ? (std::cout &lt;&lt; "Is 3.\n") : ++i; ++i; } while ( i &lt; 4 ); return 0; } </code></pre> <p>And got a following error in response:</p> <pre><code>ternary.cc: In function ‘int main()’: ternary.cc:5:43: error: invalid conversion from ‘void*’ to ‘int’ [-fpermissive] </code></pre> <p>What is wrong with my code?</p>
c++
[6]
5,560,255
5,560,256
Determine inheritance at compile time
<p>I have some code that behaves like this:</p> <pre><code>class Base {}; class MyClass : public Base {}; MyClass* BaseToMyClass(Base* p) { MyClass* pRes = dynamic_cast&lt;MyClass*&gt;(p); assert(pRes); return pRes; } </code></pre> <p>Is there a way to add a compile time check so I can catch calls to this function where p is not an instance of MyClass? I had a look at Alexandrescu's SUPERSUBCLASS function but I'm not sure if it can do the job.</p> <p>Thanks!</p>
c++
[6]
3,648,950
3,648,951
LocationManager updates every minute, consuming a lot of battery power
<p>I've got some code similar to the following:</p> <pre><code>LocationManager m = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_COARSE); String provider = m.getBestProvider(c, true); Intent i = new Intent(context, LocationReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); m.requestLocationUpdates(provider, 900000, 0, pi); </code></pre> <p>Here is the manifest entry for the receiver:</p> <pre><code>&lt;receiver android:name=".LocationReceiver" /&gt; </code></pre> <p>Most of the time it works fine, and updates every 15 minutes. Sometimes, however, it updates every minute, and consumes a bunch of battery power. What am I doing wrong here?</p> <p>Edit: Is the LocationManager not meant to be used like this for background operations?</p>
android
[4]
4,168,815
4,168,816
javascript Array comparision to check weightage is 100 or not for same program
<p>i have 2 arrays as bellow</p> <p>1)ProgramId(numeric)<br> 2)Weightage(numeric)<br> How to check,for the same programid weather weightage of that programid is 100 or not ie </p> <p><strong>ProgramId</strong><br> 2<br> 2<br> 3<br> 3<br> 2<br> 4<br> <strong>Weightage</strong><br> 25<br> 25<br> 30<br> 70<br> 50<br> 45<br> here for <strong>ProgramId</strong> 3 <strong>Weightage</strong> becomes 100(30+70) so now onwards <strong>ProgramId</strong> 3 should not be insert into array(programid)</p> <p>next same to programid 2<br> here also weightage=25+25+50=100 so nowonwards should not insert programid 2</p> <p>thanks in advance</p>
javascript
[3]
3,043,387
3,043,388
JAXBElement<String> to String using Simple Framework for Android
<p>I'm having big time trouble with Android Webservice.</p> <p>I am converting JAXB Annotation to Simple Annotation. Please see below.</p> <p>Here is my JAXB Annotation:</p> <pre><code>@XmlElementRef(name = "Title", namespace = "http://xxx.org/2004/07/Course", type = JAXBElement.class, required = false) protected JAXBElement&lt;String&gt; title; </code></pre> <p>I get the value using getTitle().value();</p> <p>After mapping to Simple Annotation like this:</p> <pre><code>@Element(name = "Title", required = false) protected String title; </code></pre> <p>and getTitle() returns null. how can i get the value ?</p> <p>I cannot use JAXB on Android. So how could I properly use Simple Framework to get the value?</p> <p>I badly need help on this. Thank you so much. </p>
android
[4]
5,195,354
5,195,355
XML array with 2 href attributes
<p>I have the following XML array:</p> <pre><code>["link"]=&gt; array(2) { [0]=&gt; object(SimpleXMLElement)#311 (1) { ["@attributes"]=&gt; array(3) { ["type"]=&gt; string(9) "text/html" ["href"]=&gt; string(48) "http://twitter.com/bob/statuses/1226112723" ["rel"]=&gt; string(9) "alternate" } } [1]=&gt; object(SimpleXMLElement)#312 (1) { ["@attributes"]=&gt; array(3) { ["type"]=&gt; string(9) "image/png" ["href"]=&gt; string(59) "http://a3.twimg.com/profile_images/226895523/Dan_normal.png" ["rel"]=&gt; string(5) "image" } } } </code></pre> <p>It's inside a bigger array, I need to get the first and second hef attribute seperatly so that I can put one href as a <code>&lt;a&gt;</code> link and another with a <code>&lt;img&gt;</code>.</p> <p>How can I output each href rather than both together?</p> <p>Currently trying this:</p> <pre><code> foreach($entry-&gt;link as $link) { echo $link-&gt;attributes()-&gt;href; } </code></pre>
php
[2]
311,723
311,724
Standing Instruction Execution in a Batch Process in different streams
<p>To answer this question needs a bit of Banking knowledge :</p> <p>Say I had setup SI from account a1->a2 and a2->a3 These are only two instructions, which needs to be processed in a batch. But I want that these two instructions will be processed in two different streams.</p> <p>Which is not possible, as the account a2 is locked in stream 1 and cannot be processed in stream 2, till the stream 1 finished its processing.</p> <p>A work around to this problem: Either I execute all SI's in one stream or I identify the dependency of instructions and put these instructions into stream accordingly.</p> <p>Or is there any other way around to work on this.</p> <p>I am using Java and Hibernate.</p>
java
[1]
4,492,643
4,492,644
Game Development in OpenGL
<p>I want to design a game like Mario but I don't know How to start with it. I hear that I have to design map to the game, how can I do that?...</p>
java
[1]
4,582,498
4,582,499
How to run a nested javascript function?
<p>I am new to object orientated programming in javascript and am trying to understand some functions in a project I am working on.</p> <p>How would I call/run the internal function (the one listed 'this.getFieldset = function() {') to execute?</p> <pre><code>function Fieldset() { this.id = ""; this.content = document.createElement("DIV"); this.content.id = "content"; this.title = "Title"; this.getFieldset = function() { var div = document.createElement("DIV"); div.id = this.id; var span = document.createElement("SPAN"); var fieldset = document.createElement("DIV"); fieldset.id = "fieldset"; var header = document.createElement("DIV"); header.id = "header"; span.appendChild(document.createTextNode(this.title)); header.appendChild(span); div.appendChild(header); div.appendChild(this.content); div.appendChild(fieldset); return div; } } var myFieldset = new Fieldset(); myFieldset.getFieldset(); </code></pre>
javascript
[3]
2,605,190
2,605,191
How to know the type of an jQuery object?
<p>I need to detect whether it's a <code>&lt;option&gt;</code> or something else</p>
jquery
[5]
1,372,647
1,372,648
Python or django reporting tools not how to generate pdf, like asp.net crystal report
<p>Python or django reporting tools not how to generate pdf, like asp.net crystal report</p>
python
[7]
5,203,161
5,203,162
Understanding jQuery draggable
<pre><code>$(".item").draggable({ revert: true }); $("#cart_items").draggable({ axis: "x" }); $("#cart_items").droppable({ drop: function(event, ui) { var item = ui.draggable.html(); console.log(item); var html = '&lt;div class="item icart"&gt;'; html = html + '&lt;div class="divrm"&gt;'; html = html + '&lt;a onclick="remove(this)" class="remove"&gt;&amp;times;&lt;/a&gt;'; html = html + '&lt;div/&gt;'+item+'&lt;/div&gt;'; $("#cart_items").append(html);+ </code></pre> <p>I understand that with <code>var html</code> I am creating all html and appending it to the DOM, but why I need this? <code>var item = ui.draggable.html();</code> What does <code>ui.draggable</code> stands for? </p>
jquery
[5]
1,293,577
1,293,578
Get array of object's keys
<p>I would like to get the keys of a JavaScript object as an array, either in jQuery or pure JavaScript.</p> <p>Is there a less verbose way than this?</p> <pre><code>var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' }; var keys = []; for (var key in foo) { keys.push(key); } </code></pre>
javascript
[3]
249,906
249,907
next element in a jquery object
<p>I'm given a jQuery object <code>$myObject</code> and a DOM element <code>myElement</code> contained in <code>$myObject</code>.</p> <p>How can I find the next DOM element contained in <code>$myObject</code> right after <code>myElement</code>?</p>
jquery
[5]
2,822,415
2,822,416
Check if string contains only combinations of array elements (numbers and words)
<p>I've searched for hours and can't find any example of what I'm trying to do. I can't even figure out what php function needs to be used, but I'm thinking probably a regex. I attempted to use in_array and it didn't work. I don't know enough about regexes to even set up a test. Here's the problem... Say my array is:</p> <pre><code>$sizeopts = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.5', ' Wide', ' Narrow', 'XS', 'Small', 'Medium', 'Large', 'XL'); </code></pre> <p>The textbox name is "size", and I want to only allow combinations of the above to be submitted. Example valid input: "10.5 Wide" or "3XL". Invalid input: "1X" or "2Wide" (missing the space in front of Wide). I have several different size arrays I need to validate. I'm not just using drop-downs because there are two many different possible combinations. Thanks for any help you can offer!</p>
php
[2]
649,794
649,795
Javascript loop giving me problems
<p>I want to extract only groups from this string</p> <p>I want to have something like in alert "group1,group2" but it returns empty.</p> <pre><code>var phone_nos = "group1,group2,564774890900"; var recipients = phone_nos.split(","); for( var i=0; i&lt;recipients.length; i++ ) group =recipients[i].substring(0,5) { if (group=="group") {groups.push(recipients)} } alert(groups.join(",")) </code></pre>
javascript
[3]
3,839,685
3,839,686
Who to find out the Id of TimePickerDialog?
<p>Look at the Title</p> <p>I don't wont to make anything in the main.xml</p>
android
[4]
361,801
361,802
Showing a Dialog and still delivering clicks to the background?
<p>I want to show a small Custom Dialog on top of the current user activity, but have clicks to the area outside of my Dialog delivered to the background (which would be the launcher, or another activity). I tried to create a transparent base-activity and have the Dialog shown on top of it, but clicks are registered on the transparent activity and not on whatever is behind it...</p> <p>I know that a <code>Popup</code> has a <code>setOutsideTouchable</code>-Method, but setting this to true just dismisses the popup, rather than delivering clicks to the background, to my knowledge...</p> <p>Thanks for your help,<br> Nick</p>
android
[4]
5,379,498
5,379,499
converting list<int> to int[]
<p>Is there builtin method that would do this or do I always have to manually create a new array and then fill it up with a foreach loop</p>
c#
[0]
443,256
443,257
Using NSXML parser how to parse the attribute contents in iphone
<p>How do you parse the attribute contents in the XML file below?</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-15"?&gt; &lt;ROOT_ELEMENT&gt;&lt;RESPONSE READ_TAG="LEVEL_LIST" RESULT="" TEXT=""/&gt; &lt;USER USER_NAME="newadmin01" TOKEN_ID="0.0768059253258988" FULL_NAME="newadmin01, newadmin01"/&gt; &lt;DATETIME UNFORMATTED_TEXT="Aug 10 2011 10:12PM" FORMATTED_TEXT="10 Aug 22:12"/&gt; &lt;BREADCRUMB/&gt; &lt;LEVEL_LIST&gt;&lt;LEVEL ID="4519" NAME="Mega Mart" CHILD_EXISTS="Y" ADD_EDIT_PRIVILEGE="Y"/&gt;&lt;/LEVEL_LIST&gt; &lt;/ROOT_ELEMENT&gt; </code></pre>
iphone
[8]
2,684,037
2,684,038
Please help me clean up my function
<p>Here is my function's objective: </p> <blockquote> <p>Define a procedure, <code>find_last</code>, that takes as input two strings, a search string and a target string,and returns the last position in the search string where the target string appears, or <code>-1</code> if there are no occurrences.</p> </blockquote> <p><a href="https://www.udacity.com/course/viewer#!/c-cs101/l-48713769/e-48634826/m-48739128" rel="nofollow">Here is a link to the question.</a></p> <p>And here's my function so far:</p> <pre><code>def find_last(target, search): find = target.find(search, 0) if find != -1: targets = target.find(search, find) while targets != -1: find = find + 1 targets = target.find(search, find) return find - 1 else: return -1 </code></pre> <p>The code returns the answer I'm looking for with <code>return find - 1</code>, but I know there is a better way to go about doing this.</p> <p>Any help would be greatly appreciated!</p>
python
[7]
1,983,352
1,983,353
php using special symbols
<pre><code>&lt;?php do { ?&gt; &lt;?php echo "&lt;a href=\"".$row_pageDetails['website']."\"&gt;"; ?&gt;&lt;?php echo $row_pageDetails['name']; ?&gt;(&lt;?php echo $row_pageDetails['profile']; ?&gt;) &lt;/br&gt; &lt;/a&gt; &lt;?php } while ($row_pageDetails = mysql_fetch_assoc($rspageDetails)); ?&gt; </code></pre> <p>This gives a clickable link name(profile) but if the profile is empty It shows () how can I improve it so that when the profile record is empty it shows nothing.</p>
php
[2]
1,356,239
1,356,240
how to encrypt and decrypt text in php
<p>how to encrypt and decrypt text in php</p>
php
[2]
5,354,854
5,354,855
How to add "or" in my method?
<p>I have following code that determines the user's language.</p> <pre><code> if (locale.equalsIgnoreCase("eng")) { .... } else { .... } </code></pre> <p>I want to add "or". For example:</p> <pre><code> if (locale.equalsIgnoreCase("eng" OR "fra")) { .... </code></pre> <p>Syntax is incorrect because I don't know how to do that. Help, please.</p> <p>Thank you all for the quick answers.</p>
java
[1]
1,093,411
1,093,412
BigInteger Problem in C#
<p>So I just asked the question <a href="http://codereview.stackexchange.com/questions/12165/efficency-in-c/12169">here</a>, and I tried my best to use BigIntegers in place of the ulongs, but i didnt do something right... I am new (like, I started looking at it today) to C#, and I am familiar to Java. This was my best shot at conversion:</p> <pre><code>using System; namespace System.Numerics{ public class Factorial{ public static void Main(){ String InString = Console.ReadLine(); BigInteger num = 0; BigInteger factorial = 1; try { num = BigInteger.Parse(InString); Console.WriteLine(num); } catch (FormatException) { Console.WriteLine("Unable to convert the String into a BigInteger"); } for (BigInteger forBlockvar = num; forBlockvar &gt; 1; forBlockvar--){ factorial *= forBlockvar; } Console.WriteLine("The Factorial for the Given input is:"); Console.WriteLine(factorial); } } } </code></pre> <p>And I got the following errors:</p> <pre><code>prog.cs(11,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference? prog.cs(13,18): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference? prog.cs(26,22): error CS0246: The type or namespace name `BigInteger' could not be found. Are you missing a using directive or an assembly reference? </code></pre> <p>Any Ideas???</p>
c#
[0]
2,744,446
2,744,447
Displaying images in android?
<p>I am working on student details application. I stored all the student details in sqlite database and I kept my sqlite file in assets folder. I need to display <strong>the student photo also</strong>. So for that I kept a <strong>column in db and stored the image names of the students.</strong> Now I am displaying the students names in a listview. When the student name is clicked it has to display all the details of that particular student along with the photo. How can I display a particular student photo? I kept the student photos in drawable folder. </p> <p>My Code:</p> <p>student.xml</p> <pre><code>&lt;ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/yes" android:src="@drawable/photo"/&gt; </code></pre> <p>Student.java</p> <pre><code>Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.photo); ImageView Image1 = (ImageView) findViewById(R.id.yes); Image1.setImageBitmap(image ); </code></pre> <p>Please help me regarding this....thanks in advance</p>
android
[4]
5,313,212
5,313,213
issue occurs when doing in LandscapeLeft
<p>I am working to support the rotation screen in Iphone now and running into the issue. When the screen is in Poitrait mode, the position of navigation bar and its items on it looks perfectly. </p> <p>When I switch to LandscapeToLeft, the width of navigation bar is stretched and it is fine.However, the position of items bar on it stay the same...Their positions are not changed at all.Therefore, there are huge room from the rightmost button to a right margin. ...I cant not attach any images so that you guys can easily see it....Sorry about that</p> <p>If you were experiencing it before, please help Any ideas are welcomed here. Thanks</p> <p>PS: these itemBarButton are added by drag and drop in the toolbar in StoryBoard </p>
iphone
[8]
2,778,473
2,778,474
Issue voice recognition c#
<p>I'm a beginner in programming and I'm trying to build a simple application to display message box that shows what I tried to say using voice recognition. The problem is when I say "hello" for the first time, for example, no message box is displayed. If I try one more time, a correct message box is played. In the third time that I say "hello", 2 message boxes are displayed. In the 4th time, 3 message boxes, and so on. Can anyone help with this problem?</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Speech.Recognition; namespace Voices { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private SpeechRecognitionEngine sre; private void Form1_Load(object sender, EventArgs e) { sre = new SpeechRecognitionEngine(); sre.SetInputToDefaultAudioDevice(); Choices commands = new Choices(); commands.Add(new string[] { "hello" }); GrammarBuilder gb = new GrammarBuilder(); gb.Append(commands); Grammar g = new Grammar(gb); sre.LoadGrammar(g); sre.RecognizeAsync(RecognizeMode.Multiple); sre.SpeechRecognized += (s, args) =&gt; { foreach (RecognizedPhrase phrase in args.Result.Alternates) { if (phrase.Confidence &gt; 0.9f) sre.SpeechRecognized += new EventHandler&lt;SpeechRecognizedEventArgs&gt;(sre_SpeechRecognized); } }; } void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { switch (e.Result.Text) { case "hello": MessageBox.Show(e.Result.Text); break; } } } } </code></pre>
c#
[0]
5,411,426
5,411,427
Fragment become visible
<p>Each time my fragment become visible to the user I want to execute a peace of code that will call a web service, fetch some data and display it on the screen. I got the web service part etc working but not sure in what event I must add my code.... I tried:</p> <ol> <li>onStart</li> <li>onResume </li> <li>onAttach</li> </ol> <p>But my code doesn't fire everytime.</p> <p>Am using the Android v4 comp lib with SherlockFragment as my base class.</p>
android
[4]
4,909,204
4,909,205
android getting pictures from drawables
<p>Bitmap picture = BitmapFactory.decodeResource(getResources(),R.drawable.phscale);</p> <p>apart from above code any other ways to get the bitmap from drawables</p> <p>this is very urgent for my project</p> <p>thanks in advance</p>
android
[4]
497,495
497,496
what is the exception when we overriding a method
<p>I am new in Java ,i have a question ,what is the exception allows to use when i override a method ,what are checked exception and what are the unchecked exception, and can i use checked exceptions in overriding ?</p>
java
[1]
937,895
937,896
Capture the webpage content in Android
<p>I am adding a context menu for Browser using intent filters. My custom menu item is visible under Share page option. Now on menu click I need to capture the web page content and upload to server. I am not able to capture the web page content. Please let me know if we can capture the web page content.</p> <p>Thanks, Mamatha </p>
android
[4]
3,418,906
3,418,907
Permanent_Dialog_Message
<p>i want to show dialog box as message got displayed user must not allowed to go anywhere.just that message must shown....please give me some code with XML too......</p>
android
[4]
1,444,917
1,444,918
largest number we can use to assure exact precision in Javascript?
<p>I have not been able to find a straight answer on this. I've check the spec but don't see anything that defines the precision.</p> <pre><code>Number.MAX_VALUE 1.7976931348623157e+308 a = 9007199254740992 a == a-1 false a+1 9007199254740992 a+2 9007199254740994 a*a 8.112963841460668e+31 a*a == ((a*a)-1) true a*a == ((a*a)*a) false </code></pre>
javascript
[3]
1,109,530
1,109,531
php HOW To send item on the same page as the form
<p>Good day! I am a newbie in php.. I made a form using html where I can input the grade of the student. Then a php page to know if they pass or not. My problem is how can i send back the reply on the html page. Example how can I send the You Failed status on my html page under the form.</p> <p>My code is as follows:</p> <pre><code> &lt;HTML&gt; &lt;BODY&gt; Please enter your grade (0-100 only): &lt;FORM ACTION="grade2.php" METHOD="POST"&gt; &lt;table border = "1"&gt; &lt;tr&gt; &lt;td&gt;Grade&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="grade" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;INPUT type="submit" name="submit" value="grade"&gt; &lt;/BODY&gt; &lt;/HTML&gt; &lt;?php $grade = $_POST['grade']; IF ($grade&gt;=0 &amp;&amp; $grade&lt;=50){ print "You failed"; } ELSE IF ($grade&lt;=60){ print "You Passed! But Study Harder!"; } ELSE IF ($grade&lt;=70){ print "Nice"; } ELSE IF ($grade&lt;=80) { print "Great Job"; } ELSE IF ($grade&lt;=90){ print "Excellent"; } ELSE IF ($grade&lt;=100){ print "God Like!"; } ELSE { print "Invalid Grade!"; } ?&gt; </code></pre>
php
[2]
3,956,983
3,956,984
JavaScript LastFM
<p>Hi have the following function:</p> <pre><code>function last() { /* Create a cache object */ var cache = new LastFMCache(); alert("test"); alert("test2"); /* Load some artist info. */ lastfm.artist.getInfo({artist: 'The Killers'}, {success: function(data){ alert(data.bio); $('gallery').append(data.to_html('&lt;p&gt;${bio}&lt;/p&gt;')); }, error: function(code, message){ /* Show error message. */ }}); } </code></pre> <p>alert(data.bio) shows up as undefined. How would I check what data is being held and how can I used and format it correctly on my webpage?</p>
javascript
[3]
4,232,028
4,232,029
moving back to the position of a div is not correct jquery
<p>I have a div and then move the div by using drag function of Jquery.</p> <p>after dropping the item, I made it such a way that if I click on the item, it will be back to the old position.</p> <p>I saved the initial position of the div: <code>offset()</code> and then set it again.</p> <p>I check on the debug data, the initial and the position after moving back are the same but the div is not located at the same as it was.</p> <p>where could be the problem?</p> <p>Thanks in advance</p>
jquery
[5]
2,053,237
2,053,238
To pass the ID of DIV tag in JQuery
<p>I am learning JQuery.</p> <pre><code>&lt;Div ID="top"&gt; &lt;DIV ID="testing1"&gt; &lt;DIV ID="testing2"&gt;&lt;DIV ID="testing3"&gt;...&lt;DIV ID="testing100"&gt;&lt;/Div&gt; </code></pre> <p>Since there are tens of DIV tags with different ID generated by a PHP file And I am trying to pass a dynamic ID of a DIV tag to a JQuery self-defined function:</p> <pre><code>&lt;script&gt;$(function() { $("div").mouseover(function() { var ID = $(this).children().attr('id'); alert(ID); });}); &lt;/script&gt; </code></pre> <p>But it wont work.</p>
jquery
[5]
4,266,638
4,266,639
activeElement property of document object usage and behavior?
<p>activeElement property of the document object sets current element that has the keyboard focus.</p> <p>But i see strange behavior:</p> <p>If i put mouse over image/anchor, activeElement shows </p> <pre><code>&lt;body&gt; </code></pre> <p>If i right click on anchor, activeElement shows </p> <pre><code>&lt;a href=.... </code></pre> <p>If i right click on image, activeElement shows </p> <pre><code>&lt;body&gt; </code></pre> <p>Can someone please exaplain correct behavior?</p> <p>I am using Firefox.</p> <pre><code>console.log(document.activeElement); </code></pre>
javascript
[3]
5,597,746
5,597,747
Populate array from an object array in javascript
<p>I've got the following object that's an object array (an array of objects), on a variable:</p> <p>variable: myVar1</p> <p>On fireBug I get the following lines when I call myVar1:</p> <pre><code>[Object { myId= "1", myName= "Name1" }, Object { myId= "2", myName= "Name2" }, Object { myId= "3", myName= "Name3" }] </code></pre> <p>I need this data to be in the followng format stored on a variable too:</p> <pre><code>myVar2 = [ [1, 'Name1'], [2, 'Name2'], [3, 'Name3'] ] </code></pre> <p>I've tried so many things like the use of for loops and js functions but can't get it work. I supose it's so easy. Anyone could try to explain the procedure.</p> <p>Thank you</p>
javascript
[3]
884,786
884,787
Java: Take action on process death?
<p>I am debugging a Java app, which frequently involves killing the process. I would like to do some cleanup before the app dies. Is there a way to catch the event and react accordingly? (Sort of like catching a <code>KeyboardInterrupt</code> in Python.</p> <p><strong>Update</strong>: I tried adding this to <code>main()</code>, but it doesn't seem to be working: </p> <pre><code>Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Closing..."); } }); </code></pre> <p>The code does not get run.</p>
java
[1]
4,167,284
4,167,285
how to show data on tableview
<p>I created a simple SQLite database. in database create a table table1,in table1 has two column. inserted tow data record. i want to show table1 Data on tableview. how do this? thank for help. </p>
android
[4]
1,818,235
1,818,236
How to pass a tableview cell value to another page(uiviewcontroller)?
<p>Ha ii,everybody i have a tabeview cell containing some values.if the user tap one of the cell a subview with buttons appears and there in popoup i have a button named save.My need is when the user tap the save button it redirect to the save page with the value of the cell,and show it in the textview of the save page.This is my code for redirecting to save page.</p> <pre><code>-(IBAction)buttonclick{ StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:@"StatusViewController" bundle:nil]; detailViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentModalViewController:detailViewController animated:YES]; [UIView commitAnimations]; [detailViewController release];} </code></pre>
iphone
[8]
3,968,759
3,968,760
Removing certain elements of array not working
<p>i have this array, and all i want it to do is cycle through and just remove certain elements that appear in the if, however whenever i output the array it always just shows</p> <pre><code>array(0) { } </code></pre> <p>instead of </p> <pre><code>["addon_h_id"]=&gt; string(1) "1" </code></pre> <p>Here is the code which cycles through it, if i remove this code then the array displays as normal</p> <pre><code> foreach ($new_shopping_array as $columnName =&gt; $columnData) { if($columnName == "s_list_id" || "user_id"){ unset($new_shopping_array[$columnName]); } } </code></pre> <p>Thanks for any and all help</p>
php
[2]
791,173
791,174
How to call a sibling method in an object defined with object syntax?
<p>How to do this?</p> <pre><code>var obj = { func1 : function(){ // Do stuff }, func2 : function(){ func1(); // does not work this.func1(); // does not work } } </code></pre> <p>Edit: missed a semicolon</p>
javascript
[3]
3,394,551
3,394,552
Android: get Application with a static method
<p>I'm using the pattern of extending <code>Application</code> class to save my global variables (<a href="http://stackoverflow.com/a/708317/1709805">http://stackoverflow.com/a/708317/1709805</a>). From my Android Components (<code>Activity</code>, <code>Fragment</code>, <code>Service</code>, ecc) i access them using (<code>(MyApp) getApplicaction()</code>), but in my project i have a lot of helper classes where i can't (obviously) use that method. To solve this problem i have decalred a static method which returns the Application. This is the code:</p> <pre><code>public class MyApp extends Application{ private static MyApp app; @Override public void onCreate(){ super.onCreate(); app = this; } public static MyApp getApp() { return app; } } </code></pre> <p>is it a good pattern? Any suggestion to achieve my purpose in a better way? Thank you</p>
android
[4]
3,177,009
3,177,010
Does adding trivial handler to event cause significant overhead?
<p>From the content of the answer to this <a href="http://stackoverflow.com/questions/289002/how-to-raise-custom-event-from-a-static-class">question</a> I learned a new trick; to add a trivial handler to an event in order to avoid null checking when it is raised.</p> <pre><code>public static event EventHandler SomeEvent = delegate {}; </code></pre> <p>and to invoke it without the null checking:</p> <pre><code>SomeEvent(null,EventArgs.Empty); </code></pre> <p>Does this add significant overhead? If not, why isn't something like this built in?</p>
c#
[0]