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 |
|---|---|---|---|---|---|
5,771,322 | 5,771,323 | faster way to handle time string with python | <p>I have many log files with the format like:</p>
<pre><code>2012-09-12 23:12:00 other logs here
</code></pre>
<p>and i need to extract the time string and compare the time delta between two log records.
I did that with this:</p>
<pre><code>for line in log:
l = line.strip().split()
timelist = [int(n) for n in re.split("[- :]", l[0]+' ' + l[1])]
#now the timelist looks like [2012,9,12,23,12,0]
</code></pre>
<p>Then when i got two records </p>
<pre><code>d1 = datetime.datetime(timelist1[0], timelist1[1], timelist1[2], timelist1[3], timelist1[4], timelist1[5])
d2 = datetime.datetime(timelist2[0], timelist2[1], timelist2[2], timelist2[3], timelist2[4], timelist2[5])
delta = (d2-d1).seconds
</code></pre>
<p>The problem is it runs slowly,is there anyway to improve the performance?Thanks in advance.</p>
| python | [7] |
5,412,562 | 5,412,563 | Clarification on Android Activity Lifecycle | <p>Can someone clarify - if in my activity, I leave to call an intent via startActivityForResult (such as take a picture), when users return to my app, what is the entry point for that activity? Is it onCreate, onStart, or onResume?</p>
<p>Thanks!</p>
| android | [4] |
3,453,691 | 3,453,692 | Extracting contents of a string within parentheses | <p>I have the following string: </p>
<pre><code>string = "Will Ferrell (Nick Halsey), Rebecca Hall (Samantha), Michael Pena (Frank Garcia)"
</code></pre>
<p>I would like to create a list of tuples in the form of <code>[(actor_name, character_name),...]</code> like so:</p>
<pre><code>[(Will Ferrell, Nick Halsey), (Rebecca Hall, Samantha), (Michael Pena, Frank Garcia)]
</code></pre>
<p>I am currently using a hack-ish way to do this, by splitting by the <code>(</code> mark and then using .rstrip('('), like so:</p>
<pre><code>for item in string.split(','):
item.rstrip(')').split('(')
</code></pre>
<p>Is there a better, more robust way to do this? Thank you.</p>
| python | [7] |
3,762,469 | 3,762,470 | Building android application | <p>I am trying to build a simple application with a button "Play" for Android.In the MainActivty.java file,I get errors with the following code,so what do I need to rectify here?</p>
<pre><code>package com.example.simplemusicplayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Button playButton=(Button) findViewById(R.id.button1);
playButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
//TODO Auto generated method stub
Toast.makeText(MainActivity.this,"Starting to play",Toast.LENGTH_SHORT).show();
}
});
}
}
</code></pre>
| android | [4] |
2,920,905 | 2,920,906 | Would using covariant return type in clone really break compatibility? | <p>I've recently encountered <a href="http://stackoverflow.com/questions/3751160/why-doesnt-java-5-api-take-advantage-of-covariant-return-types">Why doesn't Java 5+ API take advantage of covariant return types?</a>. </p>
<p>I agree with the Question, in Java 5 JDK developers could have used covariant return type for clone and changed existing classes so we could write</p>
<pre><code>ArrayList<String> list = new ArrayList<String>();
ArrayList<String> clone = list.clone();
</code></pre>
<p>instead of</p>
<pre><code>ArrayList<String> clone = (ArrayList<String>)list.clone();
</code></pre>
<p>but by some reasons the did not do that.</p>
<p>I've done some experiments changing my <code>test.ArrayList.clone</code> return type from Object to ArrayList to see if "Previously compiled classes cannot find the method with the new return type" but could not reproduce the problem. In the bytecode, a call to old <code>test.ArrayList.clone</code> looks like</p>
<pre><code> INVOKEVIRTUAL test.ArrayList.clone()Ljava/lang/Object;
</code></pre>
<p>that is, the method signature contains return type, so after my change its signature changes to <code>test.ArrayList.clone()Ltest.ArrayList</code>. So it seems that old class will break, but in fact it doesn't because there are 2 clone methods in test.ArrayList.class</p>
<pre><code> public clone()Ltest.ArrayList;
public bridge clone()Ljava/lang/Object;
</code></pre>
<p>the second one is a bridge, all it does is calling the covariant version</p>
<pre><code> ...
INVOKEVIRTUAL ArrayList.clone()Ltest.ArrayList;
...
</code></pre>
<p>so old classes continue working with no problem. </p>
<p>Can anyone explain how changing clone's return type can break the bytecode?</p>
| java | [1] |
4,973,869 | 4,973,870 | custom User control in ASCX | <p>I am implementing a user control in ASCX similar to which is shown in the link below
<a href="http://easylistbox.com/demoMultiDropDown.aspx" rel="nofollow">http://easylistbox.com/demoMultiDropDown.aspx</a></p>
<p>I could achieve everything except when I click on the dropdown and click on outside the list is not disappearing again.</p>
<p>Please help me on this.</p>
| asp.net | [9] |
24,123 | 24,124 | mobile phone's carrier information | <p>We need to test the sms text notifications thru our project which is implemented in PHP. We have used the phone number combine with the carrier gateway. For example 7-11 Speakout (USA GSM) has a gateway @cingularme.com, so while send sms we are combining the number with the gateway as 9860112354@@cingularme.com and sending this thru PHP's mail function.</p>
<p>Now wee need to test this on our mobile phones. However we are unabel to find the carrier gateway list for the same (Nokia 6300). Please advise.</p>
| php | [2] |
5,337,739 | 5,337,740 | What is the need Indexers in C# | <p>Today I've gone through what indexers are, but I am bit confused. Is there really a need for indexers? What are the advantages of using an indexer..... thanks in advance</p>
| c# | [0] |
5,306,982 | 5,306,983 | Why is this program valid? | <p>Reading <a href="http://stackoverflow.com/questions/11695110/why-is-this-program-valid-i-was-trying-to-create-a-syntax-error">this fascinating question</a> made me remember a code snippet I stumbled across a few weeks ago; it gave me quite a few minutes of confusion until I figured out why it works, maybe it will be interesting for others as well.</p>
<pre><code><?php
http://example.com/some-article
$items = get_items();
// etc.
</code></pre>
<p>Obviously the programmer wanted to add an explanatory link as a comment before the code block, but forgot to add the <code>//</code> to the beginning. Nevertheless, the code works fine. Can you tell why?</p>
| php | [2] |
2,200,321 | 2,200,322 | How to get the last but not empty line in a txt file | <p>I want to get the last but not empty line in a txt file.</p>
<p>This is my code:</p>
<pre><code>string line1, line2;
ifstream myfile(argv[1]);
if(myfile.is_open())
{
while( !myfile.eof() )
{
getline(myfile, line1);
if( line1 != "" || line1 != "\t" || line1 != "\n" || !line1.empty() )
line2 = line1;
}
myfile.close();
}
else
cout << "Unable to open file";
</code></pre>
<p>The problem is I cannot check the empty line.</p>
<p>Thanks in advanced</p>
<p>Zhong</p>
| c++ | [6] |
2,799,474 | 2,799,475 | Correct C++ file extension | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/1545080/correct-c-code-file-extension-cc-vs-cpp">Correct C++ code file extension? .cc vs .cpp</a><br>
<a href="http://stackoverflow.com/questions/5171502/c-vs-cc-vs-cpp-vs-hpp-vs-h-vs-cxx">.c vs .cc vs. .cpp vs .hpp vs .h vs .cxx</a> </p>
</blockquote>
<p>I have written C++ code in files with extension <code>.cpp</code>, <code>.cc</code> or <code>.cxx</code></p>
<p>Can anyone explain that what is the difference between these three and which one is the best ( is that platform dependent ) and why?</p>
<p>I am currently working on cygwin.</p>
| c++ | [6] |
5,916,442 | 5,916,443 | jQuery.noConflict() vs Ajax : variable scope limited? | <p>This is my code that load (if not present) jquery library : </p>
<pre><code>(function () {
var pathWidget = "http://www.mywebsite.com";
var jQuery;
if (window.jQuery === undefined) {
var script_tag = document.createElement('script');
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("src", pathWidget + "/scripts/jquery-1.7.2.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
jQuery = window.jQuery;
mainWidget();
}
function scriptLoadHandler() {
jQuery = window.jQuery.noConflict(true);
mainWidget();
}
function mainWidget() {
jQuery(document).ready(function ($) {
var widget_url = pathWidget + "/widget/widget.aspx?&callback=?"
$.getJSON(widget_url, function (data) {
$('#container').html(data.htmlWidget);
});
});
}
})();
</code></pre>
<p>This is the code loaded trought ajax/jsonp :</p>
<pre><code><div id="exDiv">First</div>
<script type="text/javascript">
$('#exDiv').html("Second");
</script>
</code></pre>
<p>The problem is : if the host page doesnt have jquery, when the aspx code try to execute <code>$('#exDiv')</code>, it "crash", and I get <code>$ is not a function</code>. Seems that after the ajax call the <code>$</code> setted as no-conflict variable is vanished.</p>
<p>How can I resolve this trouble?</p>
| jquery | [5] |
5,947,111 | 5,947,112 | How to move an anonymous function out | <p>I have a $.ajax call with an error callback:</p>
<pre><code>error: function(result){
$('#msg').text(result.statusText).addClass('err');
}
</code></pre>
<p>I'd like to change it to a more generic:</p>
<pre><code>error: myError(result)
</code></pre>
<p>And then all by itself:</p>
<pre><code>function myError(theError){
$('#msg').text(theError.statusText).addClass('err');
}
</code></pre>
<p>But firebug is telling me "result" is not defined.</p>
<p>Q: Do I call it this way?</p>
<pre><code>error: function(result){
myError(result);
}
</code></pre>
| jquery | [5] |
590,535 | 590,536 | php file uploads' size | <p>do we have any size issue with the file uploads that we perform in php using
$_file[upload][name]? is there any restriction for the file upload using this ??? juz need to know ..</p>
| php | [2] |
4,111,815 | 4,111,816 | php performance: template files in database or file? | <p>I just wonder what is best practice to store template files? In CMS I have using templates and some of parameters are stored in database... But there are some issues then i need to change something in templates or change one of parameter in many pages. Site has 100K unique visits every day... and I don't really want to make experiments with site. Just whant to know what is best for performance, to store templates and parameters in database or in file?</p>
| php | [2] |
3,716,352 | 3,716,353 | Old URL for web.config 301 redirect ends in "." | <p>Someone thought they were doing me a favor linking to my content, but they added a "." to the end of the link and I'm missing out on traffic and rankings.</p>
<p>I want to redirect all requests for "dir/page.html." to "dir/page.html". My usual code (in web.config) is not working:</p>
<pre><code><location path="dir/page.html.">
<system.webServer>
<httpRedirect enabled="true" destination="[fullURL]/dir/page.html" httpResponseStatus="Permanent" />
</system.webServer>
</location>
</code></pre>
<p>It works on any other url (real or not) not ending in a ".".</p>
| asp.net | [9] |
5,789,021 | 5,789,022 | INotifyPropertyChanged Not Working | <p>I am using INotifyPropertyChanged but it will give me null when I shaw the PropertyChanged so what i can do..
my code is like this.. </p>
<pre><code>public class Entities : INotifyPropertyChanged
{
public Entities(int iCount)
{
_iCounter = iCount;
}
private int _iCounter;
public int iCounter
{
get
{
return _iCounter;
}
set
{
value = _iCounter;
NotifyPropertyChanged("iCounter");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
</code></pre>
<p>Thanks...</p>
| c# | [0] |
5,261,514 | 5,261,515 | Python - reference object in memory by address | <p>This is kind of a silly question, but I'm just curious about it.</p>
<p>Suppose I'm at the Python shell and I have some database object that I query. I do:</p>
<p><code>db.query(queryString)</code></p>
<p>The query returns a response <code><QueryResult object at 0xffdf842c></code> or something like that.</p>
<p>But then I say "Oh! I forgot to put <code>result = db.query(queryString)</code> so that I can actually use the result of my query!"</p>
<p>Well isn't there some method that just lets me reference the object in memory?</p>
<p>Something like <code>result = reference('<QueryResult object at 0xffdf842c>')</code>?</p>
| python | [7] |
5,798,765 | 5,798,766 | Class not having copy constructor issue? | <p>I have a class which does not have copy constructor or <code>operator=</code> overloaded.
The code is pretty big but the issue is around this pseudo-code:</p>
<pre><code>ClassA object1(x,y);
object1.add(z)
myVector.push_back(object1);
//Now when I retrieve from myVector and do add it
// apparently creates another object
myVector.at(index).add(z1);
</code></pre>
<p>Like I said it is pseudo-code. I hope it make sense to experts out there!</p>
<p>So, ClassA looks like this (of course not all data members included) </p>
<pre><code>Class ClassA {
private:
int x;
string y;
ClassB b;
vector<int> i;
public:
int z;
}
</code></pre>
<p>Since ClassB b is a new data member for this release, is the need of copy constructor now become a must?
Thanks again all of you for responding.</p>
<pre><code>Class ClassB {
private:
vector<ClassC*> c;
Class D
}
Class ClassC {
private:
vector<ClassE*> e;
}
Class ClassD{
private:
vector<ClassF*> f;
}
</code></pre>
<p>Then ClassE and ClassF have basic types like int and string.</p>
| c++ | [6] |
6,029,397 | 6,029,398 | Port possible? (grim fandandroido) | <p>The dream is to run Grim fandango on my android,
And i stumbled onto 'residual' (http://residual.sourceforge.net/ it's a c++ application) and someone who made it to run on his nokia n900 (http://www.youtube.com/watch?v=TO9a5nTMHYI). </p>
<p>So for the question, would this be possible for android? My initial thought was the support debian and ubuntu and my android is faster then the n900, why not?</p>
<p>So before i spend days/weeks learning and getting it to work on my android,
I thought it might be a good idea to ask people who actually know about these things if its even possible.
And maybe how much work it really would be, in my head it's currently only:</p>
<ol>
<li>make allot of Android.mk's</li>
<li>try to compile and fix errors still it works.</li>
</ol>
<p>Which (if i don't get to many errors) doesn't sound to hard.</p>
<p>Any thoughts are welcome,
Thanks for reading!</p>
| android | [4] |
2,920,959 | 2,920,960 | Reasons for member hiding in C# | <p>I'm new to the C# language and I've got a question regarding member hiding prevalent in C#. Seeing how very few(if any) languages that supports this, I was wondering if there was any specific reason for Microsoft to include this in their programming language..?
How is this superior to the solutions found other languages..?</p>
<p>Thanks in advance.</p>
| c# | [0] |
3,444,109 | 3,444,110 | Extension Methods | <p>I have a Query Regarding Internal working Scnerio of Extension Methods.
suppose 1 am using an Agreegate Extension function of a list in LINQ. I want to Know how it works internally and how to make any Custom Extesion Method same like Aggregate(for e.g)</p>
| c# | [0] |
5,220,678 | 5,220,679 | String Comparison in Java...? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java">How do I compare strings in Java?</a> </p>
</blockquote>
<p>why first comparison ( s1 == s2 ) displays equal whereas 2nd comparison ( s1 == s3 ) displays not equal....?</p>
<pre><code> public class StringComparison
{
public static void main( String [] args)
{
String s1 = "Arsalan";
String s2 = "Arsalan";
String s3 = new String ("Arsalan");
if ( s1 == s2 )
System.out.println (" S1 and S2 Both are equal...");
else
System.out.println ("S1 and S2 not equal");
if ( s1 == s3 )
System.out.println (" S1 and S3 Both are equal...");
else
System.out.println (" S1 and S3 are not equal");
}
}
</code></pre>
| java | [1] |
14,409 | 14,410 | how do websites do this index.php?something=somepage | <p>i've seen alot of php based websites where no matter where you navigate your stuck at the index.php and some random parameters are passed in the url. and when i take a look at an open source version who does the same the index.php has a bunch of includes in them</p>
<p>whats a basic way i can do the same thing? does this include mod rewrite?</p>
<p>thanks</p>
| php | [2] |
1,239,688 | 1,239,689 | Jquery Dropdown Display Default Div | <p>I have the following JQuery, I want to display the default divarea1 visible when the user goes to the page, I am newbie to Jquery so any help would be great.</p>
<p>Best
SPS </p>
<pre><code> <script type="text/javascript">
$(document).ready(function() {
$('.box').hide();
$('#dropdown').change(function() {
$('.box').hide();
$('#div' + $(this).val()).show();
});
});
</script>
<select id="dropdown" class="boxformwh" name="dropdown">
<option style="margin:20px;" value="area1"><b>DIV Area 1</b></option>
<option style="margin:20px;" value="area2"><b>DIV Area 2</b></option>
<option style="margin:20px;" value="area3"><b>DIV Area 3</b></option>
</select>
<div>
<div id="divarea1" class="box">DIV Area 1</div>
<div id="divarea2" class="box">DIV Area 2</div>
<div id="divarea3" class="box">DIV Area 3</div>
</div>
</code></pre>
| jquery | [5] |
4,284,893 | 4,284,894 | Add Get Variable (QueryString) into PostBackUrl in FormView asp.net | <p>I have following code:</p>
<pre><code><asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Add Form"
PostBackUrl="~/APPLICATION/FormView.aspx?postquestion="/>
</code></pre>
<p>I using FormView Control.</p>
<p>I need to add Request.QueryString["postquestion"] variable into "FormView.aspx?postquestion=" for PostBackUrl. </p>
<p>I found following code on net, however it's not working:</p>
<pre><code>PostBackUrl='<%# ="~/APPLICATION/FormView.aspx?postquestion=" + Request.QueryString ["postquestion"].ToString() %>'
</code></pre>
<p>Thanks for help!</p>
| asp.net | [9] |
2,321,647 | 2,321,648 | Is this the correct way of using a void* member pointer? | <p>Can I use the method doSomething like this; first having assigned the pointer to the A class to the void* member of b?</p>
<pre><code>class A
{
public:
A(int);
int m_x;
int doSomething(){};
};
class B
{
public:
void* m_y;
};
#include "x.h"
using namespace std;
A::A(int x)
{
m_x = x;
}
int main()
{
//create 2 pointers to A and B
B *b;
A *a;
b = new B();
a = new A(15);
b->m_y = a;
((A*)b->m_y)->doSomething();
delete a;
delete b;
return 0;
}
</code></pre>
| c++ | [6] |
3,638,618 | 3,638,619 | Identifying the market category of an installed app | <p>If you the <code>ApplicationInfo</code> of a installed app, is there a way you can find out what its market category is?</p>
| android | [4] |
5,594,382 | 5,594,383 | how to add picker view programmiticaly for list of image names | <p>Im new to iphone development.In my application i want to add image picker for list of image names.here i added picker view and i dont no how to add list of image names programmiticaly in iphone with out using IB.</p>
<p>can any one plz give me code for displaying image names programmiticaly in pickerview.</p>
<p>Thankyou in advance. </p>
| iphone | [8] |
3,130,276 | 3,130,277 | what is applicationDelegate - iPhone | <p>(WebService_1AppDelegate*)[[UIApplication sharedApplication] delegate]</p>
<p>here - in above statement "WebService_1AppDelegate" is my application name.</p>
<p>But i don't understand what does this statement mean.</p>
<p>Please explain me - briefly this statement.</p>
<p>I will be thankful.</p>
<p>Thanks in advance for helping me.</p>
| iphone | [8] |
1,068,121 | 1,068,122 | Android share on facebook via what? | <p>I have successfully built my android app to support sharing on facebook. The problem is when someone shares something there is a link that facebook adds for me automatically that says shared via "my app name". If I click on it, a error occurs on facebook *note this link is usually on facebook and says shared via mobile or shared via android</p>
<p>error code-
The page you requested was not found.
You may have clicked an expired link or mistyped the address. Some web addresses are case sensitive.</p>
<p>How can i fix this link or where do i set it?
*I think this may be set on the settings on facebook but am unsure</p>
<p>my code to share comment</p>
<pre><code> facebook.dialog(this, "feed", new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
}
@Override
public void onCancel() {
}
});
</code></pre>
| android | [4] |
1,238,657 | 1,238,658 | Whats the significant use of Unary Plus and Minus operators? | <p>If Unary +/- operators are used to perform conversions as the Number() casting function, then why do we need unary operators? Whats the special need of these unary operators? </p>
| javascript | [3] |
423,548 | 423,549 | What is "android.R.id.text1"? | <p>I am new to Android development. In the Notepad sample, I saw the following code snippet:</p>
<pre><code>SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
new String[] { Notes.TITLE }, new int[] { android.R.id.text1 });
</code></pre>
<p>and in the notelist_item.xml file:</p>
<pre><code><TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1" <-----------HERE
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:singleLine="true"
/>
</code></pre>
<p>so i am wondering, what is this "<strong>android.R.id.text1</strong>"?</p>
<p>also, i found <strong>android.R.id.button1, button2, button3</strong> in android.jar file.</p>
<p>Are they some kind of well known IDs for some 3rd party controls?</p>
<p>Thanks~</p>
| android | [4] |
2,158,760 | 2,158,761 | How to save Android edit text content with rich text | <p>I have an <code>EditText</code> where users can set text to bold, italic, etc but I can't figure out how to save that text with styles as .txt file/any other way to save it.If we save as HTML page we can't edit the webview. I use <code>getText</code> but that only returns text and no style info.</p>
| android | [4] |
5,415,734 | 5,415,735 | Alternate method for android sdk installation | <p><br/>
Is there an offline installation package for android? I installed the basic ADT and every time I try to access the site and download the APIs and other tools using sdk manager, there is an access problem(I dont even have the adb.exe). I found that downloading using sdk manager is out of option for me due to company policies. Is there some simple exe installation that would help me start my work? Thanks in advance for your help.</p>
| android | [4] |
534,883 | 534,884 | this in javascript | <p>I'm having a confusing problem using 'this' in javascript. I have a method 'get_data' which returns me some member variable of an object. Sometimes it returns to me the object itself... I have no idea why. Can someone explain what is happening here?</p>
<pre><code>function Feed_Item(data) {
this.data = data;
this.get_data = function() {
return this.data;
}
this.foo = function() {
return this.foo2();
}
this.foo2 = function() {
//here type of this.data() == Feed_Item!!! It should be of type Data
}
this.bar = function() {
//here type of this.data() == Data, as I'd expect
}
}
</code></pre>
| javascript | [3] |
1,788,262 | 1,788,263 | Hide keyboard and next line feature when using using text view | <p>I'm using text view, for hiding keyboard i'm doing,</p>
<pre><code>- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
</code></pre>
<p>but by doing so even if i'm hitting enter button, keyboard gets hide. What to do to go on next line directly? I wanna implement next line feature.</p>
| iphone | [8] |
3,937,410 | 3,937,411 | Executing javascript inside div | <p>Question updated. Update at the bottom-</p>
<p>I have to put script on a page. Unfortunately, I don't have control over the header or footer or even the body tag. All, I have is a set of inner html that goes inside a wrapping DIV which sits inside the body tag. Something like this:</p>
<pre><code><body>
<div id="wrap">
<!-- My controlled content -->
</div>
</body>
</code></pre>
<p>Now, I have to place some javascript. So, I obviously put it inside the section that I control. The problem is that the javascript is not being executed. I even put an alert but there is NO alert box popping up. The final code looks something like this:</p>
<pre><code><body>
<div id="wrap">
<div id="mycontent">
<script type="text/javascript" language="javascript" src="somesource"></script>
<script>
var x, y;
//Do something here with x,y;
alert("hello");
</script>
</div>
</div>
</body>
</code></pre>
<p>Any idea what could be wrong? And how I can fix it?</p>
<p>Thanks.</p>
<p>UPDATE: I am not sure if this makes any difference, but I forgot to mention that all this HTML is present inside a frame tag (under a frameset). Will that make a difference?</p>
| javascript | [3] |
427,353 | 427,354 | The largest double value | <p>The question is about how to model infinity in C++ for the double data type. I need it in a header file, so we cannot use functions like numeric_limits. </p>
<p>Is there a defined constant that represents the largest value? </p>
| c++ | [6] |
4,622,834 | 4,622,835 | what is the difference between response.redirect and response status 301 redirects in asp? | <p>Our asp application is moving to new server and i want to implement a permenant url redirection. I am aware of following two approaches , i need to understand which one to user over other and when ?</p>
<p>Option 1:</p>
<pre><code><%@ Language=VBScript %><% Response.Redirect "http://www.example.com" %>
</code></pre>
<p>Option 2:</p>
<pre><code><%@ Language=VBScript %><% Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.example.com/" %>
</code></pre>
<p>Thanks,</p>
<p>Nikhil.</p>
| asp.net | [9] |
546,010 | 546,011 | Concatenated many strings in PHP easily | <p>The following code is correct:</p>
<pre><code>$str = "INSERT INTO table ('".$val1."',"."'".$val2."'".","."'".$val3."'".","."'".$val4."')";
</code></pre>
<p>but the code below is incorrect:</p>
<pre><code>$str = "INSERT INTO table ('".$val1."',"."'".$val2."'".","."".$val3."'".","."'".$val4."')";
</code></pre>
<p>The above example is small but you can see that larger cases of the above are annoying to debug when one misses out a ' or a ". Is there a better way of concatenating strings in PHP? I want to have variables having single inverted commas on bother sides and I want the string to be made using double inverted commas.</p>
<p>There must be a better way.. I write a lot of queries from PHP that talk to an Oracle DB and I am constantly making mistakes with these strings!!</p>
<p>Thank you :).</p>
| php | [2] |
4,646,076 | 4,646,077 | Permanent Login | <p>How can I have permanent login of the people who log in to my site (Even if the browser is turned off) until they log out.</p>
| php | [2] |
4,070,978 | 4,070,979 | Showing content of String Arrays | <p>I have this in my <code>OnItemClick</code> method.</p>
<pre><code>final String[] links = getResources().getStringArray(R.array.pokemon_stats);
String content = links[position];
Intent showContent = new Intent(getApplicationContext(),
PokedexViewActivity.class);
showContent.setData(content);
startActivity(showContent);
</code></pre>
<p>It doesn't like that I have .setData(content). I believe setData is for URI's. What do I do for a string array? This is the exact error when I hover. <code>The method setData(Uri) in the type Intent is not applicable for the arguments (String)</code></p>
<p>I switched it to this and I can't get the pokemon stats:</p>
<pre><code> public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
final String[] links = getResources().getStringArray(R.array.pokemon_stats);
String content = links[position];
Intent showContent = new Intent(getApplicationContext(),
PokedexViewActivity.class);
Bundle extras = getIntent().getExtras();
String pokeStats = extras.getString("MarcsString");
showContent.putExtra(pokeStats, content);
startActivity(showContent);
</code></pre>
| android | [4] |
611,057 | 611,058 | multiplying two floats in C++ give me unknown results | <p>I am a C++ newbie and having a problem with my first program. I'm trying to multiply two float numbers and the result always show like 1.1111e+1 where 1s are the random numbers. Following is the little program I wrote.</p>
<pre><code>#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
float bank;
float dollor;
cout<<"Enter amount of $ deposited at Bank: ";//the data to input is 5000
cin>>bank;
cout<<"Enter current $ price: ";//1usd = 800mmk: the data to input is 800
cin>>dollor;
bank*=dollor;//all deposited $ to local currency
cout<<"Result is "<<bank;
getch();
}
</code></pre>
<p>and the result of this program is 4e+006.</p>
<p>ps: I declared as float in order to input floats sometime.
Please help me with this program where I was wrong. Thanks all..</p>
| c++ | [6] |
4,113,668 | 4,113,669 | Lazy loading of attributes | <p>How would you implement lazy load of object attributes, i.e. if attributes are accessed but don't exist yet, some object method is called which is supposed to load these?</p>
<p>My first attempt is</p>
<pre><code>def lazyload(cls):
def _getattr(obj, attr):
if "_loaded" not in obj.__dict__:
obj._loaded=True
try:
obj.load()
except Exception as e:
raise Exception("Load method failed when trying to access attribute '{}' of object\n{}".format(attr, e))
if attr not in obj.__dict__:
AttributeError("No attribute '{}' in '{}' (after loading)".format(attr, type(obj))) # TODO: infinite recursion if obj fails
return getattr(obj, attr)
else:
raise AttributeError("No attribute '{}' in '{}' (already loaded)".format(attr, type(obj)))
cls.__getattr__=_getattr
return cls
@lazyload
class Test:
def load(self):
self.x=1
t=Test() # not loaded yet
print(t.x) # will load as x isnt known yet
</code></pre>
<p>I will make lazyload specific to certain attribute names only.
As I havent done much meta-classing yet, I'm not sure if that is the right approach.
What would you suggest?</p>
| python | [7] |
3,174,065 | 3,174,066 | How can I reduce memory consumption of lists I no longer need? | <p>I've searched for this but can't seem to find a straight answer for this.</p>
<p>Basically I have some code that creates a copy of an array(using <code>Arrays.copyOf</code> to create <code>int[]</code>), and it does some work and either outputs the results or sends the <code>Arrays.copyOf</code> to a queue for further processing. </p>
<p>If I change the copyof my results are no longer correct so I think I need it but I'm wondering if there's something I can do after its done because, as per my memory profiling, its taking up all my memory and garbage collecting helps but it just builds up again. I'm really not sure if this will help but I wanted to test to see if my program functions as it did with a smaller memory footprint if I somehow delete the <code>int[]</code> after submitting it to a queue.</p>
<p>I'm new to Java so if this logic is totally flawed, is there another way to achieve the same result? Bottom line is I'm creating a new array its being used a bit but lingers around when no longer needed(it takes 15G of my max memory, then I believe garbage collector comes in and reduces it but it shots back to max within a few seconds again). Maybe can I set the variable to null or something once I'm sure its not needed(the objects I'm copying are quite large)?</p>
<p>Here's some code just to show what I mean(its kind of crappy but hopefully it lets you understand how its setup in the code, all this is within a multithreaded callable):</p>
<pre><code> while(!queue.isEmpty()) {
int[] data_list = Arrays.copyOf(current.list, current.list.length);
if (things work) {
Sysout("print results");
} else if (current.k > 0) {
queue.add(new Queue(data_list));
}
}
}
</code></pre>
| java | [1] |
465,881 | 465,882 | Can we delete name of a variable in C++? | <p>I want to know if it is possible that for example I defined <code>int temp</code> then later, I define <code>temp</code> as a <code>float</code>.</p>
<p>I mean I want to use the name "temp" more than once in a <code>.cpp</code> file. Is this possible? If it's possible, how?</p>
<p>edit: I meant in the same scope.</p>
| c++ | [6] |
1,066,891 | 1,066,892 | Select the 3rd <td> using jQuery? | <p>I have a table a row and multiple tds in that row, like that:</p>
<pre><code><tr class="first odd">
<td class="a-center">
<td>...</td>
<td>...</td> --> I want this
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</code></pre>
<p>I am able to get the parent tr of all the tds, but is there a way to get the 3rd td inside the tr only?</p>
<p>The code to get the tr is:</p>
<pre><code>jQuery('#shopping-cart-table > tbody > tr').each(function(index, value) {
...
});
</code></pre>
<p>Thanks</p>
| jquery | [5] |
4,214,388 | 4,214,389 | Does the ASP.NET session support only available for current page and the child page? | <p>I have a user control (placed in parent page) that has a session to store the data table and there is a button to open child page (in iFrame, window.showModalDialog or window.open). </p>
<p>I want the session(data table) can be only shared between the parent page and the child page, and not available for outside page. The session will be expired when leaving the parent page.</p>
<p>Please advice me, thank you!</p>
| asp.net | [9] |
2,282,551 | 2,282,552 | Does java have attributes like C#? | <p>I wonder if they have attributes now and their similarities with this C#'s powerful feature.</p>
| java | [1] |
263,883 | 263,884 | Correct way of creating DTO | <p>When I create a Data transfer Object (DTO) which I use to store user input data to manager layer, I have a doubt that I'm doing it in correct way.</p>
<p>For example </p>
<p>Scenario one</p>
<pre><code>public class Person{
private String name;
private int age; // primitive type
private double weight; // primitive type
}
</code></pre>
<p>Scenario 2</p>
<pre><code>public class Person{
private String name;
private Integer age;
private Double weight;
}
</code></pre>
<p>in this case what is the best scenario that I can use and what are the factors that I should think about when decide on each scenarios. Kindly advice me.</p>
| java | [1] |
4,445,111 | 4,445,112 | What effect has a statement like 'var and do_something_with(var)' in Python? | <p>While looking for some answers in a package source code (<em>colander</em> to be specific) I stumbled upon a string that I cannot comprehend. Also my <em>PyCharm</em> frowns on it with 'statement seems to have no effect'.</p>
<p>Here's the code abstract:
</p>
<pre><code>...
for path in e.paths():
keyparts = []
msgs = []
for exc in path:
exc.msg and msgs.extend(exc.messages()) # <-- what is that?
keyname = exc._keyname()
keyname and keyparts.append(keyname) # <-- and that
errors['.'.join(keyparts)] = '; '.join(interpolate(msgs))
return errors
...
</code></pre>
<p>It seems to be extremely pythonic and I want to master it!</p>
<p>UPD. So, as I see it's not pythonic at all - readability is harmed for the sake of shorthand.</p>
| python | [7] |
724,247 | 724,248 | I want to select all and copy it to clipboard | <p>I have a WebBrowser displaying text.
If i copy it to clipbaord it copy's all the html tags to and i don't want that.</p>
<p>I want to be able to <strong>select all</strong> then copy to clipboard.</p>
<p>I want to copy the <strong>text and its formatting</strong> to the clipboard.</p>
<p>When i highlight the text my self and click copy when i paste, its perfect just how i want it.</p>
<p>But when i use this code to copy just the Document text i get the Html tags to.</p>
<p>This is how i copy to clipboard:</p>
<pre><code>void CopyCellText()
{
Clipboard.Clear();
if (webBrowser1 != null)
{
Clipboard.SetText(webBrowser1.DocumentText.ToString().Trim());
}
}
</code></pre>
| c# | [0] |
2,676,778 | 2,676,779 | Replacing Class with variable | <p>Just a simple question,</p>
<p>Im trying to replace class with var, but obviously still something wrong in the string. </p>
<p>I'm doing this:</p>
<pre><code>var C = $('.form')
$(" ' " + C + "' tr").remove();
</code></pre>
<p>and trying to achieve this: </p>
<pre><code>$(".form tr").remove();
</code></pre>
<p>I know that might be simple question, but please forgive me, Im still learning basics</p>
<p>Thanks</p>
| jquery | [5] |
3,069,379 | 3,069,380 | global objects in C++ | <p>In the following C++ code, where is s allocated? Does it use heap, data, bss, or some combination? I'm on a Linux/x86 platform in case that makes a difference. Is there a way to have the g++ compiler show me the layout?</p>
<pre><code>#include <string>
#include <iostream>
using namespace std;
string s;
int main()
{
s = "test";
cout << s;
}
</code></pre>
| c++ | [6] |
5,699,751 | 5,699,752 | Search only particular folder in Directory | <p>I need to search particular folder in directory. </p>
<p>I dont want to go for files, no need to search files. </p>
<p>I can search particular folder in directory but for I have to go for loop of files like </p>
<pre><code>foreach (FileInfo f in dir.EnumerateFiles())
{
//code
}
foreach (DirectoryInfo d in dir.EnumerateDirectories())
{
Call function recursively
}
</code></pre>
<p>I need to search particular folder only. Because I have so many files around 20,000 , so If I use above code than loop will go all the files, and take more time.</p>
<p>But I need some folders only like </p>
<pre><code>Regex.IsMatch(dir.FullName, @"1293.*T.*"))
</code></pre>
<p>How can i do that without going in files loop.</p>
| c# | [0] |
4,700,024 | 4,700,025 | make java startup faster | <p>Is there some way to get reasonable (not noticeable) starting times for Java, thus making it suitable for writing command line scripts (not long-lived apps)?</p>
<hr>
<p>For a demonstation of the issue, take a simple Hello World program in Java and JavaScript (run w/ node.js) on my Macbook Pro:</p>
<pre><code>$ time java T
Hello world!
real 0m0.352s
user 0m0.301s
sys 0m0.053s
$ time node T.js
Hello world!
real 0m0.098s
user 0m0.079s
sys 0m0.013s
</code></pre>
<p>There is a noticeable lag with the Java version, not so with Node. This makes command line tools seem unresponsive. (This is especially true if they rely on more than one class, unlike the simple <code>T.java</code> above.</p>
| java | [1] |
532,568 | 532,569 | Android Application History | <p>Is there a way to check what applications a user used in the last 24 hours? In other words, is there an 'application history log' of some kind which is accessible through programming?</p>
| android | [4] |
4,577,542 | 4,577,543 | Add a play button to a jQuery slider | <p>I have the following code which works perfectly fine, however I would like to add a play and stop button to it. Any ideas on how to do this?</p>
<pre><code>$(document).ready(function () {
var slides = $(".slide").length;
$("#slidesContainer").css("overflow", "hidden");
(function () {
for (i = 0; i < slides; i++) {
var tabNumber = i + 1;
$("#tabsstyle ul").append('<li><a href="#" rel="' + tabNumber + '"></a></li>')
}
$("#tabsstyle li a").bind("click", function () {
$("#tabsstyle li a").removeClass("active");
$(this).addClass("active");
var tabNumber = "n" + $(this).attr("rel");
$("div.slide").delay(200).fadeOut();
$("#" + tabNumber).delay(200).fadeIn(600)
})
})()
$('#tabsstyle ul li a:first').addClass('active'); // first tab selected on doucment ready
});
</code></pre>
| jquery | [5] |
3,313,011 | 3,313,012 | how to hide datagrid column | <p>I have one data grid,I want to Hide last entire column of data grid
How to do this...
Iam using Asp.net1.1</p>
| asp.net | [9] |
1,418,446 | 1,418,447 | Faster image processing | <p>Can someone suggest me a library that can do simplest operations like scale, crop, rotate without loading image fully into memory?</p>
<p>The situation: I need to scale image down from a very large size, but the scaled down image is still too large to be allocated in memory (if we use standard android tools). Since I only need to upload scaled down version, I thought of scaling it through native library and upload it through FileInputStream.</p>
<p>I've tried to use ImageMagic and it does the job, but performance is very poor (maybe there is a way to speed things up?)</p>
| android | [4] |
4,688,700 | 4,688,701 | flatten array from single dimensional array | <p>hi my array is like this </p>
<pre><code>Array(['a1','aa1','1'],['a2','aa2','2'],['a3','aa3','3'],['a4','aa4','4'])
</code></pre>
<p>my required array</p>
<pre><code> Array(['a1','1'],['aa1',[1]],['a2','2'],['aa2','2'],['a3','3'],['aa3','3'],
['a4','4'],['aa4','4'])
</code></pre>
<p>my requirement is i'll get the array with the combination of 1 & 3,2 & 3 </p>
<p>please help me</p>
<p>Thank you</p>
| php | [2] |
1,603,673 | 1,603,674 | How to get an average hue / saturation of a bitmap? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/12408431/how-can-i-get-the-average-colour-of-an-image">How can I get the average colour of an image</a> </p>
</blockquote>
<p>Say I'm making an application where a bitmap would be applied over user's photo. For the applied bitmap to look realistic, it had to have similar hue / saturation as in the user's photo.</p>
<p>So I wanted to ask, is there a way to get an average hue/sat or some other mean of color from the user photo? To use it as a coefficient to adjust hue/sat of the applied bitmap.</p>
<p>THanks.</p>
| android | [4] |
418,608 | 418,609 | Python sys.path | <p>If I have the following file structure in python:</p>
<pre><code> directory1
├── directory2
│ └── file2
└── file1
</code></pre>
<p>where directory 2 is a sub directory of directory 1 and assuming that neither is a package, how do I reference the file1 module from file2 assuming I am using sys.path? What import statement would I used in file 2 assuming I have x=1 in file 1 and i would like to print out the value of x in file2?</p>
| python | [7] |
1,688,448 | 1,688,449 | JavaScript - Test for an integer | <p>I have a text field that allows a user to enter their age. I am trying to do some client-side validation on this field with JavaScript. I have server-side validation already in place. However, I cannot seem to verify that the user enters an actual integer. I am currently trying the following code:</p>
<pre><code> function IsValidAge(value) {
if (value.length == 0) {
return false;
}
var intValue = parseInt(value);
if (intValue == Number.NaN) {
return false;
}
if (intValue <= 0)
{
return false;
}
return true;
}
</code></pre>
<p>The odd thing is, I have entered individual characters into the textbox like "b" and this method returns true. How do I ensure that the user is only entering an integer?</p>
<p>Thank you</p>
| javascript | [3] |
5,880,494 | 5,880,495 | Is java that secure? | <p>Will the fact that java class files can be decompiled and need of third party software for obfuscation in any way compromise security?</p>
| java | [1] |
510,463 | 510,464 | Is it possible to test my iPhone/iPod application on iOS 3.1.3 | <p>When building I am getting this error. </p>
<p>The Info.plist for application at /Users/guest2/Documents/MOYMalpha/build/Debug-iphoneos/MOYMalpha.app specifies a minimum OS version of 4.0, which is too high to be installed on iPod touch </p>
<p>I tried to change the verison in Xcode but minimum verison it is showing for iPhone is of 3.2..so what changes I should do to run in iOS 3.1.3</p>
| iphone | [8] |
6,014,715 | 6,014,716 | jQuery append css link to iframe head | <p>I'm trying to append a css file to an iframe that is created on a page from a global script. I can access part of it, but for some reason I can't append to the head. It's not throwing errors either, which is frustrating.</p>
<pre><code><script type="text/javascript">
$(document).ready(function() {
$('#outline_text_ifr')
.contents()
.find('head')
.append('<link type="text/css" rel="stylesheet" href="/include/outline.css" media="all" />');
});
</script>
</code></pre>
| jquery | [5] |
4,285,547 | 4,285,548 | Get option.remove work in firefox javascript only | <p>I have an class remover that works just fine in IE och Chrome, wont get any errors but in firefox. it dosent work at all.
Just get an error thats thas remove is not a function.</p>
<p>I been trying different ways to make it work, but none of them removes the class.</p>
<pre><code>function removeDice(){
document.getElementsByClassName("dice")[0].remove(0);
}
</code></pre>
<p>An nice function that lets me remove dice classes one by one...
works in chrome but not firefox.</p>
<p>Been reading different methods here in stackoverflow and tried this</p>
<pre><code>document.getElementById("dice").className =
document.getElementById("dice").className.replace
( /(?:^|\s)MyClass(?!\S)/g , '' )
</code></pre>
<p>But no luck either.
Any tips ?</p>
<p>Thanks</p>
| javascript | [3] |
4,165,336 | 4,165,337 | Alarm not ringing in android | <p>Hi
In my android application i would like to set alarm for particular time.
I am using the below code.I am able to view the toast but no ring or alert is observed.
Could anyone please let me know if i can display the toast with an default alarm tone.</p>
<pre><code> int newAlarmPeriod = 15000; // For debugging
Intent alarmIntent = new Intent(this, GroupsCheckAlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this,0,alarmIntent, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ newAlarmPeriod, newAlarmPeriod, sender);
public class GroupsCheckAlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
Log.d("XXX", "GroupsCheckAlarmReceiver.onReceive"); }
</code></pre>
<p>}</p>
<p>Do i need to set any manifest permissions except receiver registery.</p>
<p>Please share your valuable suggestions.</p>
<p>Thanks in advance :)</p>
| android | [4] |
4,895,443 | 4,895,444 | save camera clicked image on exernal folder and fetch all saved images in that folder:android | <p>I need to save camera clicked image in external folder rather then in gallery , for doing this i make a external directory and save clicked image in that folder now i need to fetch that images and display all clicked images in gridview , i am able to save image only one , but it replace previos clicked image from the folder , my code are below please refer it , and suggest how to save all camera clicked images in a folder and fetch all that imaged for displaying it in Grid view
:</p>
<pre><code>try {
File root = new File(
Environment.getExternalStorageDirectory()
+ File.separator + "myFolder" + File.separator);
if (!root.exists()) {
root.mkdirs();
}
// root.mkdirs();
sdImageMainDirectory = new File(root, "myimage.jpg");
outputFileUri = Uri.fromFile(sdImageMainDirectory);
startCameraActivity(outputFileUri);
} catch (Exception e) {
Toast.makeText(Photos_Grid_Activity.this,
"Error occured. Please try again later.",
Toast.LENGTH_SHORT).show();
finish();
}
}
}
protected void startCameraActivity(Uri uri) {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(cameraIntent, 101);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101 && resultCode == -1) {
try {
}
}
</code></pre>
| android | [4] |
2,175,145 | 2,175,146 | python: how binding works | <p>I am trying to understand, how exactly variable binding in python works. Let's look at this:</p>
<pre><code>def foo(x):
def bar():
print y
return bar
y = 5
bar = foo(2)
bar()
</code></pre>
<p>This prints 5 which seems reasonable to me.</p>
<pre><code>def foo(x):
def bar():
print x
return bar
x = 5
bar = foo(2)
bar()
</code></pre>
<p>This prints 2, which is strange. In the first example python looks for the variable during execution, in the second when the method is created. Why is it so?</p>
<p>To be clear: this is very cool and works exactly as I would like it to. However, I am confused about how internal bar function gets its context. I would like to understand, what happens under the hood.</p>
<p><strong>EDIT</strong></p>
<p>I know, that local variables have greater priority. I am curious, how python knows during execution to take the argument from a function I have called previously. <code>bar</code> was created in <code>foo</code> and <code>x</code> is not existing any more. It have bound this <code>x</code> to the argument value when function was created?</p>
| python | [7] |
544,617 | 544,618 | how to make android devices cpu usage to 100%? and memory usage to 100%? | <pre><code>i'm doing hardware testing on android devices ,
and thinking about this :
</code></pre>
<ol>
<li>make CPU usage to 100%.</li>
<li>make memory(RAM) usage to 100.</li>
</ol>
<p>if i create a lot of threads and services , sure it does.</p>
<p>but is there a normal way to test?</p>
| android | [4] |
3,539,319 | 3,539,320 | Input datatype error | <p>I have a program which takes a string and converts it into list which looks like this - <code>['CTTC', 'CGCT', 'TTTA', 'CATG']</code>. (its actually a lot longer than this). Now I need to find how many of these list elements have a <code>C or A or T or G</code> as its 1st letter. This needs to be taken from the terminal i.e. using the <code>input</code> function.</p>
<p>Now as far i know, in python 3.2 the datatype of input function is by default taken as a string (<code>str</code>) and not like an integer (<code>int</code>) (can be seen by using <code>isinstance</code>). However since I am using a college server, the python version is older (i think 2.7 or later but below 3.0). In this case, when I use the input function to ask the user to choose a letter- <code>initial = input("Choose a letter:")</code>, and when I enter any letter (A,T,G,or C) it gives me an error <code>NameError: name 'C' is not defined</code>. When i checked the datatype using <code>isinstance</code>, i realized that the python version takes the datatype of input as an <code>int</code> . When i try to convert it into a string, it gives the same error. Is it the problem of the version or is it something i am doing wrong. My code is below.</p>
<pre><code>import sys
#import random
file = open(sys.argv[1], 'r')
string = ''
for line in file:
if line.startswith(">"):
pass
else:
string = string + line.strip()
w = input("Please enter window size:")
test = [string[i:i+w] for i in range (0,len(string),w)]
#seq = input("Please enter the number of sequences you wish to read:")
#first = random.sample((test), seq)
print test
l = input("Enter letter for which you wish to find the probability:")
lin = str(l)
print lin
</code></pre>
| python | [7] |
388,230 | 388,231 | AsyncTask and Background Thread when to Use | <p>What is the difference between AsyncTask and Background Thread. Which should be preferred or any scenarios to use these?</p>
<p>What I am trying to achieve right now is Will be sending request to server when user goes on a specific activity and display the data received on the same activity? The data received may be images or some text which I need to display in TextView or ListView.</p>
| android | [4] |
3,476,919 | 3,476,920 | How can i perform automatic updates (of course by checking) a boolean field from the gridview? | <p>I already enable the linqdatasource in Advanced Options.</p>
<p>Code below:</p>
<pre><code><asp:CheckBoxField DataField="ValidData" HeaderText="Valid Risk Item"
SortExpression="ValidData" />
</code></pre>
| asp.net | [9] |
2,558,989 | 2,558,990 | I have a certain script for Feed back. | <p>I have a certain script for Feed back. when i submit the form, it shows</p>
<p>"
Warning: substr() expects parameter 2 to be long, string given in /home/jetkvdmn/public_html/genFunctions.php on line 26"</p>
<p>the code below</p>
<pre><code><?php
$cEpro ="&copy; Redeeming Mission 2012.";
function checkText($ElementVal) {
// If Text is too short
if (strlen($ElementVal)< 3) {
//alert('Text too small');
return false;
} else{
return true;
}
}
function checkEmail($vEmail) {
$invalidChars ="/:,;" ;
if(strlen($vEmail)<1) return false; // Invalid Characters
$atPos = stripos($vEmail,"@",1); // First Position of @
if ($atPos != false)
$periodPos = stripos($vEmail,".", $atPos); //If @ is not Found Null . position
for ($i=0; $i<strlen($invalidChars); $i++) { //Check for bad characters
$badChar = substr($invalidChars,i,1); //Pick 1
if(stripos($vEmail,$badChar,0) != false) //If Found
return false;
}
if ($atPos == false) //If @ is not found
return false;
if ($periodPos == "") //If . is Null
return false;
if (stripos($vEmail,"@@")!=false) //If @@ is found
return false;
if (stripos($vEmail,"@.") != false) //@.is found
return false;
if (stripos($vEmail,".@") != false) //.@ is found
return false;
return true;
}
?>
</code></pre>
| php | [2] |
3,822,416 | 3,822,417 | JOptionPane won't show its dialog on top of other windows | <p>I have problem currently for my swing reminder application, which able to minimize to tray on close. My problem here is, I need JOptionPane dialog to pop up on time according to what I set, but problem here is, when I minimize it, the dialog will pop up, but not in the top of windows when other application like explorer, firefox is running, anyone know how to pop up the dialog box on top of windows no matter what application is running?</p>
| java | [1] |
3,031,976 | 3,031,977 | List of all possible PHP errors | <p>Sometimes, while coding in PHP we get parse or syntax errors like those:</p>
<pre><code>Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /var/www/example/index.php on line 4
</code></pre>
<p>I would like to know, if there is a list of all possible errors that PHP interpreter can output. I've searched php.net, but couldn't find such thing. I need this list for academic purposes.</p>
<p><strong>UPDATE:</strong> Thank you for help, everybody. Seems there is no such list because of several reasons and I will have to do my research the other way.</p>
| php | [2] |
1,642,090 | 1,642,091 | How to display the previous map zoom level after finishing the current map in android | <p>I have two maps that are displaying one after the other. Let the activites be Map1 and Map2. First I am displaying the Map1 and then going to Map2 from Map1. Whenever I click on the back button on Map2 I am finishing the Map2 and going to the Map1.</p>
<p>But here the issue is the Map1 is getting the same zoom level as Map2. In the Map1 I am displaying a Marker for the specified address and in the Map2 I am displaying the current location. Both are different MapViews. Can anyone tell me how I can fix this?</p>
| android | [4] |
2,516,831 | 2,516,832 | Android LunarLander and JetBoy Thread source | <p>Hallo,</p>
<p>Is there a reason why the Thread class in the SDK LunarLander and JetBoy examples are not each in a separate java file, rather than being inside the View file?</p>
<p>It would make things a bit clearer, IMHO. Am I missing something?</p>
<ul>
<li>Frink</li>
</ul>
| android | [4] |
746,402 | 746,403 | How can I make a jQuery countdown | <p>I want a jQuery countdown:</p>
<ol>
<li>It starts counting after page download finishes</li>
<li>After counting to 0 it redirects to a url</li>
</ol>
<p>How i can do that?</p>
<p>Thanks in advance</p>
| jquery | [5] |
1,077,688 | 1,077,689 | How can I have bigger imageview for larger screen size layout? | <p>I am looking at my android design for medium and large screen. I have designed my layout for mdeium screen (viewing it on the eclipse editor and emulator) and making sure it is good. My design involves textview and images view. I have create the 3 drawable folders for different density sizes so the picture can occupies the rough space on different densities.</p>
<p>Now, I am looking at the large screens (and even xtra large screens) but my textviews and images views looks very small (compared to the size of the screen). Therefore I would like to make use ofd the extra space by enlarging everything. </p>
<p>I know how to do it for text views, basically I would make textsize bigger (ie. instead of 12 sp I can make it 16sp)</p>
<p>But How can I do it for ImageView? The Imageview displays the image according to its size. And the size of the image is really meant for medium screen. How can I make it bigger? Should I provide the same image with a bigger size and a different name?</p>
<p>Please help, btw plz dont point me to the android develoment supporting mutliple screens cause I read it and I couldn't find what I need unless I missed a certain line that answers my question.
Thank you for your help</p>
<p>Decided to edit the question maybe people can understand my question more.
I have an image that is 50 X 50 pix in medium density medium screen size. Let say that this image occupies 5 by 5 millimeters, Now if I want to display the same image on medium desnity XLARGE screen but I want it to be bigger (say occupies 10 by 10 millimters). How do I achieve that? I understand I wil lneed different layout in the XLARGE folder so in this layout what should I do with that image view? Do I create a new PNG file with 100X100 pix and place it in the medium density folder?</p>
| android | [4] |
4,447,223 | 4,447,224 | Counting successive occurrences of numbers satisfying certain conditions in python | <p>I have a specific data set that reads like </p>
<pre><code>array([ 2.1, 3. , 179.1, 1.9, 2.6, 425.8, 1.7, 3.1,
4. , 144. , 2.2, 2.3, 5.3, 135.5, 2. , 2.7,
.....])]
</code></pre>
<p>Here I want to count the successive occurrences of numbers below 6 and save them in specific counters. For example, in the first three numbers there are two numbers that are continuously below 6 before a bigger number appears. So counter2 would get an addition of 1. If three numbers occur continuously like that, then counter3 would be incremented by 1 (as in the 2nd row) and so on. Are there any functions to do it in python, if not how do I proceed? Thanks in advance. </p>
| python | [7] |
3,716,927 | 3,716,928 | How does createElement() work with innerHTML? | <p>I have the following code that pretty much creates a div element and whatever is inside and puts it into </p>
<pre><code>function create(htmlStr) {
var frag = document.createDocumentFragment(), temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
var fragment = create('<div id="test">HELLO</div>');
document.body.insertBefore(fragment, document.body.childNodes[0]);
</code></pre>
<ol>
<li><p>I am, however, confused as to why do we create another
<code>div</code> <code>temp = document.createElement('div');</code>
If we are already passing <code><div id="test">HELLO</div></code> to <code>create()</code> function. Seems to me that would create a div within a div (but it doesn't). Or does that just get extracted with <code>temp.firtChild</code>?</p></li>
<li><p>What does <code>temp.innerHTML = htmlStr;</code> do since <code>temp</code> is a <code>div</code>?</p></li>
</ol>
| javascript | [3] |
269,064 | 269,065 | "Couldn't get connection factory client"API Key is fine | <p>Ok this has been making me crazy. I get the following crash (Couldn't get connection factory client), but my Maps API key is fine. </p>
<p>This line causes the crash</p>
<pre><code> mapView.getProjection().toPixels(point, somePoint);
</code></pre>
<p>But if I omit the toPixels part it runs fine, but does not do what I want it to do(display an image on a map).</p>
<p>Any guidance? This seems like a different issue than the API key issue and I am testing on a device running Android 2.2, if that it matters. </p>
| android | [4] |
5,475,533 | 5,475,534 | jQuery: radio button name contains string | <p>I'm trying to target a group of radio buttons that's name contains a part of a string...</p>
<pre><code>if (!$("input:radio[name=PercentageValue]:checked"))
alert("you need to check a percentage");
</code></pre>
<p>That isn't working...</p>
| jquery | [5] |
605,348 | 605,349 | Android ant run-tests artifacts | <p>When I do an ant run-tests on my android test project it runs fine and I can see a summary of tests run and failures. Is there more detailed information available, like a log file I can save on each test run? Basically I want to be able to run my tests from the command line and for each run have a list of failures/passes with as much detail as possible plus a capture from logcat (but I guess I have to do that manually).
Thanks</p>
| android | [4] |
3,841,079 | 3,841,080 | Insert statement not working in foreach statement | <p>I have a crawler which crawls the sites that begin with www.bbc.co.uk/news. It it grabs all the links that start with <a href="http://www.bbc.co.uk/news" rel="nofollow">http://www.bbc.co.uk/news</a> and finds their description, link and title and inserts them into a database. </p>
<p>For some reason, it doesn't seem to be inserting.</p>
<p>Any ideaS?</p>
<p>PS There is completely not output, completely blank web page</p>
<pre><code> foreach ($links as $link) {
$output = array(
"title" => Titles($link), //dont know what Titles is, variable or string?
"description" => getMetas($link),
"keywords" => getKeywords($link),
"link" => $link
);
if (empty($output["description"])) {
$output["description"] = getWord($link);
}
if (substr($ouput, 0, 26) == "http://www.bbc.co.uk/news/") {
$data = '"' . implode('" , "', $output) . '"';
$success = mysql_query( "INSERT INTO news_story (`title`, `description` , `keywords`, `link`)
VALUES (" . $data . ")") or zerror_reporting();
if ($sucess) {
echo "YEAH!";
}
if (!$sucess) {
echo "NO!!";
}
print_r($data);
}}
</code></pre>
| php | [2] |
2,170,393 | 2,170,394 | Android How to determine whether the ClientConnectionManager opened a new connection or used existing one? | <p>We created a class deriving from <code>DefaultHttpClient</code> and use a <code>ConnectionKeepAliveStrategy</code>. Now I'd like to know during runtime whether the <code>ClientConnectionManager</code> reused a connection or created a new one (for instance because the connection with the server timed out).</p>
<p>How can I tell?</p>
<pre><code>public class MyHttpClient extends DefaultHttpClient
{
// some code setting constants
public MyHttpClient()
{
super();
// some code setting http connection params
setKeepAliveStrategy(new ConnectionKeepAliveStrategy()
{
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context)
{
return KEEP_ALIVE_TIMEOUT * MS_PER_SECOND;
}
});
}
@Override
protected ClientConnectionManager createClientConnectionManager()
{
// some code registering HTTP and HTTPS
return new ThreadSafeClientConnManager(getParams(), registry);
}
// some code for the socketfactory
}
// At some other class:
public class SomeClass
{
private static final HttpClient HTTP_CLIENT = new MyHttpClient();
public void someMethod()
{
/* some code */
HttpGet get = new HttpGet(some url);
HttpResponse getResponse = HTTP_CLIENT.execute(get);
/* more code */
}
}
</code></pre>
<p>When we call <code>HTTP_CLIENT.execute()</code> how can I see whether a new connection was created by the <code>ClientConnectionManager</code> or an existing connection was reused?</p>
| android | [4] |
5,738,563 | 5,738,564 | Jquery 1.2.6 .click on body doesn't have any effect | <p>I have a script that completly work with JQuery 1.5.2 but it doesn't with 1.2.6, only the <strong>$('body').click</strong> doesn't have any effect.</p>
<p>I have made an example on <a href="http://jsfiddle.net/Awea/MkYMF/" rel="nofollow">jsfiddle</a>, someone have an idea to solve this ?</p>
| jquery | [5] |
5,452,935 | 5,452,936 | PHP: Encrypt/Decrypt Short String | <p>I need to encrypt and decrypt short strings (Ex. 'product1234'). I have used mcrypt_encrypt and mcrypt_decrypt with various ciphers. The problem is that invariably it throws in extended characters into resulting string, which causes some issues with certain aspects of my application code that I cannot control.</p>
<p>So, the question is whether there is either a cipher that reduces the list of characters that are used in the encrypted string (i.e. leaving out things such as '+', '\', or '/').</p>
| php | [2] |
5,253,403 | 5,253,404 | jQuery find by inline css attribute | <p>I need to find an element based on a specific css attribute. the css is applied inline and I can not use a class.
Is there anyway to achieve this in jquery?</p>
| jquery | [5] |
1,190,966 | 1,190,967 | Android when to close the DatabaseHelper? | <p>With reference to this link <a href="http://stackoverflow.com/questions/6113244/busy-timeout-for-sqlite-on-android">Busy timeout for SQLite on Android</a>, when is a good time to close the connection if all u have is 1 connection? I have a service running in the background too all the time, so was wondering where is good to call the close(). Thanks!</p>
| android | [4] |
5,635,153 | 5,635,154 | Explode string except where surrounded by parentheses? | <p>I'm trying to explode a string by vertical bars. That's the easy part. However, I DON'T want the split to affect substrings that are surrounded by parentheses. That means I need a string such as:</p>
<pre><code>Hello (sir|maam).|Hi there!
</code></pre>
<p>to explode into:</p>
<pre><code>Array
(
[0] => Hello (sir|maam).
[1] => Hi there!
)
</code></pre>
<p>By using the normal explode function, I don't believe there is a way to tell it to ignore that bar surrounded by the parentheses. However, I have some ideas.</p>
<p>I know that it would be possible to do this by exploding the string normally, and then looping through the array and merging everything between strings that contain <code>(</code> to the closing string that contains <code>)</code>. However, I have a feeling that there should be a more elegant way of achieving this.</p>
<p>Am I right? Is there a less code-intensive means of spliting a string into an array given these restrictions?</p>
| php | [2] |
956,432 | 956,433 | not able to retrieve old session variable values in php | <p>Hi i am new to PHP.I am having "item.php" page and "cart.php" page. In item.php 3 checkboxes are available. if i click on one checkbox from item.php the value is sent to to cart.php page. however if i go back and select another checkbox the old value is not retained. Only the new value is getting printed.
I am storing the retrieved checkbox value in a session variable in cart.php but still not able to retrieve the old values selected. Can anybody help me out? Thanks in advance</p>
| php | [2] |
5,767,822 | 5,767,823 | how to display images from a selected folder in the form of a slideshow | <p>I am using the following code to pick a folder from the SDCard.</p>
<pre><code>Environment.getExternalStorageDirectory();
</code></pre>
<p>After selecting the folder, I return the path of the folder and display it in a text view currently.
What I want to do is, I want to display all images in the selected folder in the form of a slide show. How do I go about in doing this?</p>
| android | [4] |
1,864,629 | 1,864,630 | Setting a folder type with Exchange Web Service API | <p>I am trying to create global folders in a Exchange 2010 server that are to be used by the users. If I am right I have to set a specific folder type (in my case contacts)so that the users are able to save contacts in these folders. For this, I am using the
I am using the EWSJava 1.1.5. My problem is that I cannot find a way to do this, respectively cannot find a class to manage this for me. Can anybody help me out? Many thanks in advance.</p>
<p>Regards,
Bene</p>
| java | [1] |
5,388,079 | 5,388,080 | jQuery update CSS in future elements part of div | <p>I am using jQuery to do something like:</p>
<pre><code>$("#div1 .code").css('display','inline');
</code></pre>
<p>Now the problem is that when I add another element with class "code" inside div1, it does not get the CSS tag of display inline.</p>
<p>How can I make it so that it always updates the CSS for any new elements part of div1.</p>
<p>Thank you for your time.</p>
| jquery | [5] |
3,541,076 | 3,541,077 | Practice for Basic C++ | <p>This is a practice question I'm having trouble answering. Anybody have a clue about the formula? I was thinking sum of the numbers as so.. 2^0 + 2^1 + 2^2 ... 2 ^ n ?
What is the (sign = -sign; ) used for? Thanks for anyone that can give some assistance.</p>
<p>Give a description of the mathematical formula that the following function computes.</p>
<pre><code>// Pre: n>=0
// Post: ???
double WhatAmI(int n) {
int result=0;
int ctr=0;
int sign = 1;
while(ctr<=n) {
result = result + power(2,ctr);
sign = -sign;
ctr++;
}
return result;
}
</code></pre>
| c++ | [6] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.