Unnamed: 0
int64
65
6.03M
Id
int64
66
6.03M
Title
stringlengths
10
191
input
stringlengths
23
4.18k
output
stringclasses
10 values
Tag_Number
stringclasses
10 values
2,244,291
2,244,292
What's the Pythonic way to loop through an iterator when the first few values are special?
<p>The standard away is:</p> <pre><code>it = iter(sequence) for value in it: print value </code></pre> <p>I'm using a third party library that returns an iterator with the first value being a header, the second value being metadata and the rest of the values being records. I have tried something like:</p> <pre><code>db = dbfreader(f) headers = db.next() spec = db.next() record = db.next() while record: print record record = db.next() </code></pre> <p>But that results in a StopIteration error</p>
python
[7]
2,531,843
2,531,844
C# Abstract class clarification
<p>As abstract class can not be initialized,why the constructors are allowed?</p> <p>I thought ,Incase i need to pass information to base class (abstract class in this class),i need to have constructor. I .. mean</p> <pre><code> abstract class Person { string regNo,name; public Person(string regNo,string name) { this.regNo = regNo; this.name = name; } public string RegNo { get { return regNo; } } public string Name { get { return name; } } } class student : Person { student(string regno, string name) : base(regno, name) { } } </code></pre> <p>is this the purpose the constructor is allowed inside abstract class?</p>
c#
[0]
1,930,333
1,930,334
Having trouble writing XML in Python
<p>I have a XML file that I read with Python. I want to make some changes in the XML file and write it back out.</p> <p>Here is my code:</p> <pre><code>from xml.dom.minidom import * filename = "file.xml" dom = xml.dom.minidom.parse(filename) dicts = dom.getElementsByTagName("dict") for dict in dictList: keys = dict.getElementsByTagName("key") for key in keys: keyCData = key.firstChild.wholeText if keyCData == "kind": print keyCData #prints "kind" key.firstChild.wholeText = "new text" print key.firstChild.wholeText #prints "new text" f = open("temp.xml", 'w') dom.writexml(f) f.close() </code></pre> <p>When I open "temp.xml" to look at though, all my elements with the "key" tag still have their CData as "kind" instead of "new text". So how do I get the new data to be written out to the file?</p>
python
[7]
4,083,046
4,083,047
Static analysis of Python code, in a codebase that includes multiple implementations of the same module all having the same interface
<p>I don't miss having to type out type declarations all the time - that's one of many reasons I love python.</p> <p>But I like to at least have some "variable used before set", "variable set but never used" and "wrong number of arguments" checks, to avoid trivial errors.</p> <p>pylint is reportedly the most stringent static analysis tool for Python, so I've been using it to get such checks.</p> <p>However, I have a bit of a disappointment with pylint: EG, I have 3 modules that do compression in 3 different ways (subprocess, ctypes, bz2 module), and I want to add a 4th (the new lzma module in CPython 3.3, which hasn't yet been released). These modules all have slightly different portability and behavior. I want pylint to be able to check these alternatives, but it seems to get lost.</p> <p>So I started using a tiny "dispatch module" for a while, that would do nothing but choose between the different compression alternatives, and that Wouldn't Be Pylint'd, and that sort of works, but not as well as I'd like. It allows me to pylint most of my code, but it seems to make pylint unable to check uses of the compression code.</p> <p>Is there some way of getting static analysis for python that allows the checking of multiple modules all providing the same interface, as well as calls into those modules from the same code? Maybe pyflakes? Or a magic "# pylint:" hint I don't don't know about?</p> <p>Thanks!</p>
python
[7]
4,702,086
4,702,087
Is there any serious logic behind the Xcode Organizer bug when screenshot's don't work?
<p>I always try to make screenshots of running apps, with a 70% chance that it won't work. There is a green light showing my connected device. Most of the times I have to connect and disconnect like 10 times until it can make a screenshot.</p> <p>What causes this problem? Must I wait 10 minutes after build? Is there any logic behind this failure?</p>
iphone
[8]
4,372,477
4,372,478
Is there a short way to store image variable?
<p>I would like to find a shorter way of storing an image and its source in a variable.</p> <p>Something that looks like:</p> <pre><code>ctx = document.getElementById("canvas").getContext('2d'); </code></pre> <p>but for:</p> <pre><code>var img = new Image(); img.src = "image.png"; </code></pre> <p>Can this be done in a single clean line like the first example?</p>
javascript
[3]
4,621,345
4,621,346
How To Modify This Array Into Associative Array?
<p>I have this code :</p> <pre><code>$genders = array('Male', 'Female'); foreach ( $genders as $gender ) { echo '&lt;option' . ( $rowMyBiodata['Gender'] == $gender ? ' selected' : '' ) . '&gt;'; echo $gender; echo '&lt;/option&gt;'; } </code></pre> <p>and that code produce HTML code like this :</p> <pre><code>&lt;option selected&gt;Male&lt;/option&gt; &lt;option&gt;Female&lt;/option&gt; </code></pre> <p>now, I want to add a value on each option so that output will be like this :</p> <pre><code>&lt;option selected value='M'&gt;Male&lt;/option&gt; &lt;option value='F'&gt;Female&lt;/option&gt; </code></pre> <p>I think by changing the array into associative array can solve this problem :</p> <pre><code>$genders = array('M'=&gt;'Male', 'F'=&gt;'Female'); </code></pre> <p>but how to get array's index so it can be used as value on the option tag?</p>
php
[2]
3,587,581
3,587,582
Best ASP.NET Websites for Sample Code / Code Projects
<p>I am new to .NET development. </p> <p>Would you please let me know few best ASP.NET Websites for Sample Code / Code Projects?</p> <p>Thank you &amp; Regards.</p> <p>Shravya.</p>
asp.net
[9]
3,919,509
3,919,510
How to get a list of favorite contacts with android sdk?
<p>The question is "How to get a list of favorite contacts with android sdk?". Now I am using android v1.5. Thanks.</p>
android
[4]
2,015,920
2,015,921
Couchdb Replication Notifications on Android Emulator
<p>I am new to android development. I tried to use couchdb on android emulator. I was installed and used successfully in android emulator.</p> <p>Now my scenario is,</p> <p>I am able to do replication process in android emulator couchdb, it is replicated in remote couchdb database. i was done the same replication from remote database to emulator database, it works fine, the couch database replicated.</p> <p>My question is how to display the notification in android emulator when the couchdb database updated from the remote couchdb. (means updating the database in android couchdb from the remote couchdb, at the time of updating how to display the notification in android emulator?)</p> <p>Please help me</p>
android
[4]
4,034,837
4,034,838
copy a class, C#
<p>Is there a way to copy a class in C#? Something like var dupe = MyClass(original).</p>
c#
[0]
404,010
404,011
Specifying startup window/form location on multiple displays
<p>I have two displays (two monitors) connected to my machine, and I noticed a strange thing happening today. I had an Explorer window open with my compiled exe on my primary display, and when I double-clicked it, it opened in the primary display (left monitor). However if I pressed enter to launch the executable, it started in the secondary display (right monitor). The window state of the initial form is maximized. Is there a way to tell C# to open the initial form in the primary display?</p>
c#
[0]
3,338,335
3,338,336
C# - Deleting a file permanently
<p>I've been out of the C# game for a while since I started iPhone stuff, But how can you delete a file completely (so its not stored in memory) and isn't recoverably. If you cant delete it forever can you scramble it up with random data so its un-openable but still exists?</p> <p>Thanks! </p>
c#
[0]
1,498,886
1,498,887
DropDownList DataValue as object
<pre><code>DataTextField="Name" DataValueField="ID_ListGroupParIzm" </code></pre> <p>???? DataValueField2="ID_Point"</p> <p>is it real to load 2 values from sqlDataSource in one DropDown list ? Get structure object from sqlDataSource ?</p> <p>I can see only one way - making a new table to combine ID_Point and ID_ListGroupParIzm to one ID but that's really weird.</p>
asp.net
[9]
4,851,483
4,851,484
No module named profile
<p>when i tried to search bookdetails from library of congress using python with the help of z3950 module, I got following error</p> <pre><code>from PyZ3950 import zoom File "/usr/local/lib/python2.6/dist-packages/PyZ3950/zoom.py", line 72, in &lt;module&gt; from PyZ3950 import z3950 File "/usr/local/lib/python2.6/dist-packages/PyZ3950/z3950.py", line 72, in &lt;module&gt; from PyZ3950 import asn1 File "/usr/local/lib/python2.6/dist-packages/PyZ3950/asn1.py", line 2009, in &lt;module&gt; import profile ImportError: No module named profile </code></pre> <p>please help me for a solution</p>
python
[7]
754,448
754,449
Calling a new activity when threads running - IllegalThreadStateException
<p>I am developing a game which so far has involved just two activities: a splash screen and a main activity. The main activity starts up a new thread which handles the drawing and game mechanics. So far the game has been working nicely. Now I have just added a new button for the purposes of viewing a "high scores" page in a new activity. So I set up an onClick handler and when the button is clicked I call the following code:</p> <pre><code>in = new Intent("android.intent.action.HIGH"); startActivity(in); </code></pre> <p>and in the high scores activity I have an [Ok] button which instigates the following:</p> <pre><code>back_but.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { finish(); } }); </code></pre> <p>When I click the button to view the high scores, the high scores activity starts up fine, unfortunately when I click the [Ok] button the program crashes with an IllegalThreadStateException.</p> <p>Should I have stopped or paused the game thread in the main program before calling the new activity?</p>
android
[4]
2,099,703
2,099,704
Structuring an iPhone app with several views
<p>I am confused by the relationship between the appDelegate, MainWindow and the various views (and corresponding contollers). What I want to achieve is to immediately after app launch, hand control over to a "mainController" class that in turn loads the nib-files as needed (to minimize program logic in the app delegate). First, I need to load a login screen, and after successful login the application content, whose logic I have read ideally should reside outside the appDelegate, hence the "mainController" class.</p> <p>Does the "mainController" need to be connected with a (blank) nib-file? Should this mainController subclass the UIViewController class albeit it holds no GUI contents on itself and be instanciated with [window addSubview:mainViewController.view]; [window makeKeyAndVisible]; ? Or should I use the alloc/init syntax. In which case, how do I reference the window from the (sub)views in order to add views programmatically?</p> <p>Any hints, tips or tutorials would be helpful.</p>
iphone
[8]
4,576,493
4,576,494
Fill out javascript with python?
<p>I am trying to parse an html page but I need to filter the results before I parse the page.</p> <p>For instance, 'http://www.ksl.com/index.php?nid=443' is a classified listing of cars in Utah. Instead of parsing ALL the cars, I'd like to filter it first (ie find all BMWs) and then only parse those pages. Is it possible to fill in a javascript form with python?</p> <p>Here's what I have so far:</p> <pre><code>import urllib content = urllib.urlopen('http://www.ksl.com/index.php?nid=443').read() f = open('/var/www/bmw.html',"w") f.write(content) f.close() </code></pre>
python
[7]
3,721,593
3,721,594
moveTaskToBack and restore to front prevorious application
<p>I have a small question. My application sometimes reorders to front when some my events fires, but i want after 5-10 seconds move it to back and restore previous application which was active before. How can i do it?</p> <p>Thank you!</p>
android
[4]
2,831,691
2,831,692
What are Modules in a project?
<p>Hi i want to know what is meant by modules in a project??how they are classified and how many modules we can have in a project?can anyone explain with simple examples??What modules we can have in a typical online shopping website?</p>
asp.net
[9]
3,390,198
3,390,199
Destroying session
<p>i want to destroy a session by clicking on a link. if i click on that link the session will be destroyed, otherwise not. I don't know the exact code for this, but i have tried with this one : </p> <pre><code>&lt;?php echo $sess_destory = "&lt;a href='department.php'&gt; Back &lt;/a&gt;"; if($sess_destory) { session_destroy(); } ?&gt; </code></pre> <p>In this way, the session is simply destroying before the time i want. That's why the desired data cannot pass through the other page and showing the error below :</p> <p>"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id, semester, sem_id) VALUES ('','Second Year First Semester','2-1')' at line 1"</p>
php
[2]
85,513
85,514
Different font sizes for different screen sizes
<p>In my application I must use a smaller font for the medium density devices. Is it possible to specify that?</p>
android
[4]
1,879,449
1,879,450
User Authentication in ASP.NET when authentication is checked by javascript functions
<p><em>Please suggest or change some suitlable title for this question as i am not able to find one</em> </p> <p>I am using Facebook to allow the users to authenticate to my site.</p> <p>I use Facebook Login Button and somehow i find out the user is authenticated or not.</p> <p>I am developing my website in ASP.NET 4.0</p> <p>I check whether the user is authenticate through Javascript.</p> <p>The problem is how should i tell my server that this user is authenticated and assign some ASP.NET roles. I cannot use Ajax becuase of securoty reasons and might be a attack of Impersonation. This site may have transactions in the future so it need to be less security vunerable.</p> <p>RIght now what i did is create a session using javascript and redirect to some other page and then assign roles but i am not statisfied with this method</p> <p>Any help is appreciated. </p>
asp.net
[9]
329,025
329,026
How to detect that a PC has been idle for 30 seconds using Java?
<p>How to detect that a PC has been idle for 30 seconds using Java?</p> <p>EDITED</p> <p>With idle I mean that there are no user activity. The user does nothing in 30 seconds. I wold like to do an apllication like Windows, that detects that the user does nothing and enter in stad-by.</p>
java
[1]
3,434,924
3,434,925
How to get the highlighted text on any windows applications (word, sharepoint portal, web browser)
<p>I am developing an c# application.</p> <p>Whenever my window gets activated, I want to get the highlighted/selected text on any windows applications (like word, excel, sharepoint portal, web browser, etc.,).</p> <p>How to do this with C#?</p> <p>I will really appreciate if someone comes up with a small sample instead of suggesting the links.</p> <p>Thanks in Advance !</p> <p>Let me explain it again in detail</p> <p>I have to create a search application in c#. </p> <p>Suppose if i select a text "vimal" in internet explorer (or word or excel or any application) and open the Search application then word "vimal" should be displayed in the search application.</p> <p>Hope the requirement is clear now.</p>
c#
[0]
2,835,103
2,835,104
Convert Doc to Pdf file in android
<p>I am looking for Lib file which is helpful in converting <code>Doc</code> to <code>Pdf</code> file , I uses <code>iText</code> and <code>appache poi</code> but they are creating the <code>PDF</code> file, not converting to <code>PDF</code> file . If anyone have idea about this then please refer some sample code for the same or is there any another way?</p>
android
[4]
2,312,632
2,312,633
Strange behaviour with jQuery animation
<p>I have a simple animation:</p> <pre><code>$(function () { $(".galleryButtonLeft").mousedown(function(){ $("#theGallery").animate({ marginLeft: "-=300px", }, 1000 ); }); }); </code></pre> <p>theGallery is just a <code>div</code> with <code>position:relative</code>.</p> <p>Nothing fancy:</p> <pre><code> &lt;div style="position:relative"&gt; &lt;img/&gt; &lt;/div&gt; </code></pre> <p>When I click my galleryButtonLeft to move it <code>300px</code> to the left, the page immediately goes to the top if I have my browser unmaximized and scroll to the middle of the page where my gallery sits. I want the page to stay where it is and not jump to the top everytime the button is clicked. How do I do that?</p>
jquery
[5]
3,213,180
3,213,181
How to get emails and save them into mysql database
<p>I got requirement to build a email box. In which I am going to save incomming and outgoing emails in/out of mysql database. How can I write a php script so my all emails will arrive in my mysql database?</p>
php
[2]
2,817,031
2,817,032
Keyboard in HTML text-input disappear when WebView call 'loadUrl' again
<p>I use WebView for my Androind App. I got a problem and request a solution for help.</p> <p>There is a textfield in the HTML page. When it gets 'focus' and then I call </p> <pre><code> mWebView.setFocusableInTouchMode(true); </code></pre> <p>in Java code so that the Android soft-keyboard will pop-up to let me key in.</p> <p>The problem is I need using multi-thread for some processes in Java and call</p> <pre><code> mWebView.loadUrl(strJSCall); </code></pre> <p>as callback to execute JavaScript function, but the keyboard gets hidden!</p> <p>The way I try is to force the keyboard to show again. But how can the keyboard always show when 'loadUrl' is called? Dose anyone meet the same issue and solve it already?</p> <p>Sincerely, Jr.</p>
android
[4]
1,196,555
1,196,556
How does scoping work with JavaScript includes?
<p>For example suppose I have the following within my HTML</p> <pre><code>&lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt; </code></pre> <p>The script defines a variable named socket. Immediately below I have the following</p> <pre><code>&lt;script src="/javascripts/script.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>Within script.js I try to access socket and get a not defined error. However if I use an inline script I can access the variable. How can I access 'socket' from within script.js?</p>
javascript
[3]
3,707,316
3,707,317
How to find whether an element exists in std::map?
<p>My use case:</p> <pre><code>map&lt;string, Car&gt; cars; bool exists(const string&amp; name) { // somehow I should find whether my MAP has a car // with the name provided return false; } </code></pre> <p>Could you please suggest the best and the most elegant way to do it in C++? Thanks.</p>
c++
[6]
3,016,604
3,016,605
using multimedia files in asp.net in background
<p>let's say i want to play an mp3 song in the background of the website alog the user's travesal between the different pages... is is possible?</p>
asp.net
[9]
1,656,125
1,656,126
How to set Color of control without using the Enumeration?
<p>I want to set the color of my control using a string variable with a value of say "Blue". Normally you would set it:</p> <p>Label1.Color = Color.Blue;</p> <p>But now I want to replace Color.Blue with the value that is in my string variable, like:</p> <p>Label1.Color = sColor; // sColor = "Blue"</p> <p>But I get the error: Cannot convert type 'string' to "System.Drawing.Color"</p> <p>Any help appreciated.</p>
c#
[0]
3,786,620
3,786,621
How does one run javascript that has been inserted into a .innerHTML in embedded form?
<p>Is this possible?</p> <p>I inserted a simple test snippet like this</p> <pre><code>&lt;script type="text/javascript"&gt;//&lt;![CDATA[ document.write('foo'); //]]&gt;&lt;/script&gt; </code></pre> <p>but it does nothing. ( W3 schools suggest the use of CDATA <a href="http://www.w3schools.com/tags/tag_script.asp" rel="nofollow">here</a>, but this did not help ).</p> <p>To reiterate this snippet was written into the .innerHTML property of the body tag.</p> <p>I've seen some mentions of eval() on google but not too sure if this is relevant or good practice?</p> <p>Wrapping the code in eval like they do <a href="http://www.w3schools.com/jsref/jsref_eval.ASP" rel="nofollow">here at W3</a> has no effect.</p>
javascript
[3]
3,263,742
3,263,743
Installation error: INSTALL_PARSE_FAILED_NO_CERTIFICATES
<p>At the risk of repeating what appears to be a very common complaint, I think I have a substantial variation on this bug.</p> <p>The application won't install from Eclipse and this appears in the console: Installation error: INSTALL_PARSE_FAILED_NO_CERTIFICATES.</p> <p>LogCat provides some illumination: Package com.xxx has no certificates at entry assets/fonts/helvetica_neue.ttf; ignoring!</p> <p>Meaning that the device (or emulator) believes that this particular file wasn't signed.</p> <p>The usual solutions proposed for this are:<br/> - Rename the offending file. We've tried that, it then complains about the next file, then the next, and so on.<br/> - Add a dummy file. Tried that too. It complains about the new file, regardless of what it's called.<br/> - Compile for greater than Android 1.6. We're compiling for 2.3.</p> <p>It's worth noting this only happens when we launch a unit test. We can install the "real" application on its own with no difficulties. We're also using Maven and, of course, the Maven Android plugin.</p> <p>Any insights or suggestions would be very welcome and of course if we figure it out on our own I'll post any findings.</p>
android
[4]
53,987
53,988
iPhone:Recording conversation feature?
<p>I want to develop an iPhone application which has to record the phone conversation. Can some one give me the instruction how can i achieve this?</p> <p>thank you. </p>
iphone
[8]
1,860,041
1,860,042
How to get the outerHTML after the first jquery method?
<p>Anyone knows how to get the outerHTML from this point?....</p> <pre><code> $("#sectionA tr[data-testlog='"+variableName+"']").first().outerHTML; </code></pre> <p>Returns an undefined....</p>
jquery
[5]
3,422,570
3,422,571
How to view 2seperate forms by clicking two different buttons
<p>I did the php code with two buttons in <strong>1st php file</strong>.Now i am trying to do in <strong>another php file, by clicking the button one seperate form is to be open and by clicking the other button another seperate form is to get open</strong>. But i dont know how to do this.</p> <pre><code>&lt;input type="submit" name="question" value="question" /&gt; &lt;input type="submit" name="answer" value="answer" /&gt; </code></pre> <p>please tell me how to do this.</p>
php
[2]
2,688,047
2,688,048
Android: Establish internet connection
<p>I'm surprised I cannot find any info on the internet on this common situation: How can I start an internet connection? I looked at <a href="http://developer.android.com/reference/android/net/ConnectivityManager.html" rel="nofollow"><code>ConnectivityManager</code></a> but it seems it is just for monitoring network connectivity.</p> <p>PS: The phone will be rooted, so it is not a problem.</p>
android
[4]
967,156
967,157
PHP Parse Error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
<p>I've been trying to debug this for the past five minutes, I just don't get what the problem is:</p> <p>Here's my code, lines 33 - 37:</p> <pre><code>for($i = 0; $i &lt; 5; $i++) { $followers_change[$i] = $en_array1[$i]['followers']-$en_array2[$i]['followers']; $rank_change[$i] = $en_array1[$i]['rank']-$en_array2[$i]['rank']; echo "&lt;tr&gt;&lt;td&gt;$en_array1[$i]['rank']&lt;/td&gt;&lt;td&gt;&lt;img src='$en_array1[$i]['imageurl']' width='48' height='48'/&gt;&lt;/td&gt;&lt;td&gt;$en_array1[$i]['name']&lt;/td&gt;&lt;td&gt;$en_array1[$i]['followers]'&lt;/td&gt;&lt;td&gt;$en_array1['followers_change']&lt;/td&gt;&lt;/tr&gt;"; } </code></pre> <p>I keep getting the error:</p> <blockquote> <p>Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /.../ on line 36</p> </blockquote> <p>I apologize for this being such a stupid/rookie error, I'm just stumped and tired at the same time (which doesn't make a good combination :)).</p>
php
[2]
529,308
529,309
disable a column sorting using datatables of jquery
<p>i am using datatables of jquery to sort the table fields.my question is how to disable particular column with out sorting . i tried with the following code ,but get excepted result.</p> <pre><code>"aoColumns": [ { "bSearchable": false }, null ] </code></pre> <p>i also tried with following code</p> <pre><code>"aoColumnDefs": [ { "bSearchable": false, "aTargets": [ 1 ] } ] </code></pre> <p>but the result is not accepted .please tell me any idea</p> <p>usman</p>
jquery
[5]
4,487,171
4,487,172
Looking to pass size of files back to a directory listing
<p>I needed some help with passing the size of a list of files to a method and having it list the files size next to the name. For some reason I am having an issue getting this to pass through. I have all the files assigned to a value "directory"</p> <p>I have the files called and the method as a private String xyz(long size)</p> <p>I have tried calling by xyz(directory), or long file = new directory.legnth then xyz(directory)....</p> <p>I am banging my head against the wall with this any assistance appreciated.</p> <p>EDIT 1:</p> <p>When I say directory that is just what I am using to refer to the path of the directory to be traversed, I have one method that is recursively listing the files in a folder, and I am trying to pass a long variable to anther method to return the size of each file. So currently I get a listing of all files but thats about it. For some reason it will just not come to me as to how to get the method called.</p>
java
[1]
3,722,277
3,722,278
Does java(compiler or jvm) handles static final members of class differently? If yes how
<p>It seems logical to do some optimization around static final constants ( e.g. replace the variable with literals etc ) to improve the performance</p>
java
[1]
4,513,016
4,513,017
Strange javascript operator: expr >>> 0
<p>the following function is designed to implement the <code>indexOf</code> property in IE. If you've ever had to do this, I'm sure you've seen it before.</p> <pre><code>if (!Array.prototype.indexOf){ Array.prototype.indexOf = function(elt, from){ var len = this.length &gt;&gt;&gt; 0; var from = Number(arguments[1]) || 0; from = (from &lt; 0) ? Math.ceil(from) : Math.floor(from); if (from &lt; 0) from += len; for (; from &lt; len; from++){ if (from in this &amp;&amp; this[from] === elt) return from; } return -1; }; } </code></pre> <p>I'm wondering if it's common to use three greater than signs as the author has done in the initial length check? </p> <p><code>var len = this.length &gt;&gt;&gt; 0</code></p> <p>Doing this in a console simply returns the length of the object I pass to it, not true or false, which left me pondering the purpose of the syntax. Is this some high-level JavaScript Ninja technique that I don't know about? If so, please enlighten me!</p>
javascript
[3]
3,828,399
3,828,400
Calling one parameter in another function?
<p>Hi Actually i want to take url and id from one fn to another whether this method will work.</p> <pre><code>function addElement(url, id) { alert(url); var main = document.getElementById('mainwidget'); main.innerHTML = "&lt;iframe src=" + url + " align='left' height='1060px' width='576px' scrolling='no' frameborder='0' id='lodex'&gt;&lt;/iframe&gt;"; alert("google"); addUrl(url, id); } function add() { addUrl(url, id) alert("id" + id); document.getElementById("Listsample").innerHTML = "&lt;a href='#' onclick='addUrl(" + url + ");' id='cricket' tabindex='1' name='cricket'&gt;" + id + "&lt;/a&gt;"; } </code></pre>
javascript
[3]
468,247
468,248
Python Ordered Dictionary to regular Dictionary
<p>I have something like</p> <pre><code>[('first', 1), ('second', 2), ('third', 3)] </code></pre> <p>and i want a built in function to make something like</p> <pre><code>{'first': 1, 'second': 2, 'third': 3} </code></pre> <p>Is anyone aware of a built-in python function that provides that instead of having a loop to handle it?</p> <p>Needs to work with python >= 2.6</p>
python
[7]
1,751,167
1,751,168
can we convert a variable data into variable
<pre><code>boolean isdata=false; // converting this to true String qname="data"; String abc="is"+qname; isdata = true // works here but i dont wanna hard code.. there is much data like this // i am trying to automate the process. i have basic knowledge of doing it manually </code></pre> <p>but i want to convert isdata to true now. Is there any implementation for this.</p>
java
[1]
4,627,250
4,627,251
View state is not getting in the Page PreInit event
<p>Hii,,</p> <p>I need a help. I have a master page and i am changing the masterpage file property to some other master page dynamically in the page PreInit event and that changing url is taken from a viewstate. but the view state is not getting in the pre init event. If you finding any solution regarding this pls help me.... </p>
asp.net
[9]
2,717,338
2,717,339
this returns the wrong date when subtracted
<p>Why when I subtract these two dates do I get the wrong answer</p> <pre><code>var a = new Date("1990","0","1"); var b = new Date("1900","0","1"); var x = new Date(a - b); console.log(x); answer: Date {Thu Jan 01 1880 02:00:00 GMT+0200 (South Africa Standard Time)} </code></pre> <p>How do I make it return : 90 years and 0 days and 0 months</p>
javascript
[3]
2,511,755
2,511,756
Get a contact's groups?
<p>I'm trying to make a many-to-many mapping of contacts to groups.</p> <p>For example, if I have:</p> <ul> <li>User 1, belongs to group 701, 702, 704</li> <li>User 2, belongs to no groups</li> <li>User 3, belongs to group 702</li> </ul> <p>I'm hoping to get a relation that looks like this:</p> <pre><code>userID | groupID 1 | 701 1 | 702 1 | 704 3 | 702 </code></pre> <p>I've tried this:</p> <pre><code>Cursor cursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, null, new String[] { ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID, ContactsContract.CommonDataKinds.GroupMembership.GROUP_SOURCE_ID }, null, null, null); </code></pre> <p>But that doesn't quite work. The GROUP_SOURCE_ID column returns weird numbers that aren't the ID of any groups. Sometimes it even returns 0 or a negative number.</p> <p>I could construct a mapping of this by going through each group, and finding all contacts in that group, but that would take a lot of queries, and I'm trying to stay fast (apparently, just those few queries are quite slow!).</p> <p>Can anyone tell me how I can get this contacts-to-groups mapping in one query?</p> <p>Thanks!</p>
android
[4]
2,452,060
2,452,061
Fading In A prepended element in jquery
<p>I've got some code like this:</p> <pre><code>var newrootcomment = $("&lt;div class='comment'&gt;&lt;div class='comment-holder'&gt;&lt;div class='comment-body'&gt;"+ data.message + "&lt;/div&gt; &lt;abbr class='timestamp' title=''&gt;&lt;/abbr&gt;&lt;div class='aut'&gt;" + data.author + "&lt;/div&gt; &lt;a href='#comment_form' class='reply' id=''&gt;Reply&lt;/a&gt; &lt;/div&gt; &lt;/div&gt;"); $('#wholecontainer').prepend(newrootcomment).hide().fadeIn(300); </code></pre> <p>Basically, I'm prepending the code to the #wholecontainer div. however, I want the prepended code and fade it into view. The above code fades in all the #wholecontainer div. How can I actually do it?</p>
jquery
[5]
5,117,069
5,117,070
How to invoke Application.AddMessageFilter in a Dll
<p>I'd like to create a dll file in C# that has a static method calling Application.AddMessageFilter() on a Win form loading this dll.</p> <p>For example,</p> <pre><code>public Form1() { // initializing MyDll.InvokeFilter(SomeClass); // Perfect! } </code></pre> <p>And I don't want it to look like as below, (I don't even think that this code would correctly work though)</p> <pre><code>public Form1() { // initializing // Send also the delegate to Application.AddMessageFilter as a parameter // to let MyDll know it, which is not as good. MyDll.InvokeFilterWithDelegate(SomeClass, Application.AddMessageFilter); } </code></pre> <p>The thing is I don't know how to invoke Application.AddMessageFilter from my Dll file because Application class belongs to Form1, not to my Dll library.</p> <p>What am I missing? </p> <p>Thanks in advance.</p>
c#
[0]
427,809
427,810
Trouble with self keyword in python
<p>am creating a browser in ubuntu.. using Glade<br> when i compile it's showing "NameError: name 'self' is not defined"<br> code : </p> <pre><code>self.reload = self.bulider.get_object("reload") def on_pressbutton_clicked(self, widget): print"reload" </code></pre> <p>it is just a sample code to check button's action.. </p>
python
[7]
4,894,594
4,894,595
How can use history.go(-1) but ignore hash fragments?
<p>I have the following links:</p> <pre><code>index.php test.php test.php#tab1 test.php#tab2 </code></pre> <p>On the <code>test.php</code> page I click on link <code>#tab1</code>, and then <code>#tab2</code>. I want clicking on the back link:</p> <pre><code>&lt;a href="javascript: history.go(-1);" title="Back"&gt;« Back&lt;/a&gt; </code></pre> <p>...to go back to <code>index.php</code>.</p> <p>Any ideas ?</p>
javascript
[3]
386,752
386,753
erase(remove_if()) anomaly
<p>I've created a function to run through a vector of strings and remove any strings of length 3 or less. This is a lesson in using the STL Algorithm library.</p> <p>I'm having trouble in that the functions work but not only does it delete strings of length 3 or less but it also appends the string "vector" to the end. </p> <p>The output should be</p> <pre><code>This test vector </code></pre> <p>and instead it is</p> <pre><code>This test vector vector" </code></pre> <p>How can I fix it?</p> <pre><code>/* * using remove_if and custom call back function, write RemoveShortWords * that accepts a vector&lt;string&gt; and removes all strings of length 3 or * less from it. *shoot for 2 lines of code in functions. */ #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;algorithm&gt; #include &lt;vector&gt; #include &lt;iterator&gt; using namespace std; bool StringLengthTest(string test) //test condition for remove_if algo. { return test.length() &lt;= 3; } void RemoveShortWords(vector&lt;string&gt; &amp;myVector) { //erase anything in vector with length &lt;= 3 myVector.erase(remove_if(myVector.begin(), myVector.end(), StringLengthTest)); } int main () { //add some strings to vector vector&lt;string&gt; myVector; myVector.push_back("This"); myVector.push_back("is"); myVector.push_back("a"); myVector.push_back("test"); myVector.push_back("vector"); //print out contents of myVector (debugging) copy(myVector.begin(), myVector.end(), ostream_iterator&lt;string&gt;(cout," ")); cout &lt;&lt; endl; //flush the stream RemoveShortWords(myVector); //remove words with length &lt;= 3 //print out myVector (debugging) copy(myVector.begin(), myVector.end(), ostream_iterator&lt;string&gt;(cout," ")); cout &lt;&lt; endl; system("pause"); return 0; } </code></pre>
c++
[6]
1,803,348
1,803,349
What is Webprofile useful for?
<p>I stumbled upon this project <a href="http://webprofile.codeplex.com/" rel="nofollow">ASP.NET WebProfile Generator</a></p> <p>Why would I need proxy class to access profile?</p>
asp.net
[9]
4,484,006
4,484,007
Does jQuery continue filtering if it finds 0 matches?
<p>I have a question regarding efficiency of jQuery filtering. I've just written quite a lengthy expression and I was wondering if jQuery stops filtering if the current number of matches is 0.</p> <pre><code>passengers.filter('input.FromDate[value="01/09/2011"]') .closest('tr') .filter('input.ToDate[value="08/09/2011"]') .length; </code></pre> <p>If after the first <code>filter()</code> call the number of matches is 0 will jQuery continue to search the DOM or will it forego the additional calls and just return 0?</p>
jquery
[5]
4,258,291
4,258,292
Android 9-patch batch
<p>I am using the Android 9-patch tool to generate my 9-patch images. I have to support a number of different resolutions and button states. This means that for a single 9-patch button I need to generate 16 separate assets. Currently I am generating each of these separately using the Android 9-patch tool interface which is taking a lot of my time. If I was able to specify the 9-patch dot for a range of buttons which have the same properties this would save me a lot of time. Is there the equivalent of a command line tool or other approach which would help.</p> <p>Thanks</p>
android
[4]
2,365,454
2,365,455
Android Using Soap Library or Rest WebServices
<p>I'm a little bit confused on Soap and Rest web services!! </p> <ol> <li>which of them is better to consume</li> <li>advantages and disadvantages of each one</li> </ol>
android
[4]
3,349,776
3,349,777
Problem with jQuery.before().remove
<p>All what's the problem this ..</p> <pre><code>jQuery(function() { var $tooltip = jQuery('&lt;div class="tooltip"&gt;You can mention..?&lt;/div&gt;'); jQuery('.link-class:first').live("hover", function() { jQuery(this).before($tooltip); }, function() { jQuery(this).before($tooltip).remove(); }); }); </code></pre>
jquery
[5]
1,631,688
1,631,689
ajax not working in plugin
<p>The code below works beautifully outside of WordPress but as soon as I attempt to execute it inside of WordPress nothing happens:</p> <pre><code>var js = jQuery.noConflict(); js(document).ready(function(){ js('#ClientID').live('change', function() { js.ajax({ url : 'includes/form.php', type : 'POST', dataType: 'json', data : js('#myform').serialize(), success: function( data ) { for(var id in data) { js(id).val( data[id] ); } } }); }); }); </code></pre> <p>I have triple checked everything, I've put an alert just above js.ajax and it executes, however if it's inside of the js.ajax({ it doesnt do anything. I'm at a loss at why this isn't working.</p>
jquery
[5]
3,806,426
3,806,427
How to call activity of one project from activity of another project in android?Also vice versa?
<p>I am doing an integration project,which involves integrating two projects into one.How I want to do this is,I have a common project,the activity of this common project should be able to call activities of the other two projects,as per different events like a particular button press,etc.How can I do this?Is it possible through intents?</p> <p>Also,the activities of the other two projects should be able to call each other.How to do this?</p> <p>Thanks a looot in advance!!!</p> <p>Dipti!!</p>
android
[4]
2,227,290
2,227,291
how to take the output from command prompt and make a text file out of it using language Java
<p>This is what I have found, but in this code it reads line on what you put in, and I don't want that</p> <p>I am doing a program called Knight's Tour, and I getting output in Command prompt. All I want to do is to read the lines from Command prompt and store it an output file called knight.txt. Can anyone help me out. Thanks.</p> <pre><code>try { //create a buffered reader that connects to the console, we use it so we can read lines BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //read a line from the console String lineFromInput = in.readLine(); //create an print writer for writing to a file PrintWriter out = new PrintWriter(new FileWriter("output.txt")); //output to the file a line out.println(lineFromInput); //close the file (VERY IMPORTANT!) out.close(); } catch(IOException e) { System.out.println("Error during reading/writing"); } </code></pre>
java
[1]
5,180,504
5,180,505
how to apply background color to the found text
<p>hello i have following code and it works fine for finding and replacing string... but it is not working globally..how to make it to work as globally and after replacing i want to highlight that string into green color.. how..?</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; New Document &lt;/title&gt; &lt;script type="text/javascript" src="../js/jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $('#replace').click(function(){ var oldstr=$('#inputstring').val(); var newstr=$('#newstring').val(); var para=$('#para').html(); var result=$('p:contains('+oldstr+')'); if(result) { var x=para.replace(new RegExp(oldstr, 'i','g'), newstr); $('#para').empty().html(x); } }) }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Enter the string to find:&lt;input type="text" id="inputstring"&gt;&lt;br&gt; Enter string to replace:&lt;input type="text" id="newstring"&gt;&lt;br&gt; &lt;input type="button" value="Replace" id="replace"&gt;&lt;br&gt; &lt;p id="para"&gt;This is the new paragraph written to test how to replace the a string with desired string&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
jquery
[5]
3,035,376
3,035,377
Open options menu from custom Adapter Android
<p>I have a custom adapter populating a listview.</p> <p>Each row has a checkbox which has an OnCheckedChangeListener set in the getView() method.</p> <p>All is working in that regard, however I want to open the options menu in my activity that is 'hosting' my listview from the event listener in the Adapter.</p> <p>I've tried passing in an instance of my Activity to no avail and I can't access a static method with openOptionsMenu() in my Activity from the Adapter class because openOptionsMenu() is non-static.</p> <p>Any ideas?</p> <p>I'm assigning my adapter like so,</p> <p><code>mAdapter = new CustomFileAdapter&lt;String&gt;(this, filenames, this);</code> (context, array, activity)</p> <p>And the constructor in the Adapter like so,</p> <p><code>public CustomFileAdapter(Context context, String[] images, Activity a)</code></p>
android
[4]
276,742
276,743
the types of flags to run an application in android
<p><strong>please help me.</strong></p> <ul> <li>I want know about what types of flags to run an application in android. asked me in interview. </li> </ul>
android
[4]
1,674,552
1,674,553
Managing subview when orientation change on iPhone OS 3.0
<p>I am experiencing difficulties managing my view controller rotation. Here is my app structure :</p> <pre> [Window] ---[addSubview:MainViewController.view] </pre> <p>My MainViewController's view contains an UIImageView which I need to rotate, this is my app background.</p> <p>In my AppDelegate and MainController I overrided shouldAutorotateToInterfaceOrientation to return YES, but when I rotate my device nothing change. Even the status bar.</p> <p>Should I manually apply transformation to my views when I receive UIDeviceOrientationDidChangeNotification ?</p> <p>In IB I set resize subviews to YES in mainViewController.view.</p> <p>So I am a little bit lost...</p> <p>Thanks for your help.</p> <p>thierry</p>
iphone
[8]
3,626,188
3,626,189
text box using jquery
<p>Below code is used to delete text box.I have used <strong>x</strong>.I need to insert a image here and i need to place 3 text boxes in same line.This is like stack overflow.</p>
jquery
[5]
1,564,945
1,564,946
convert 64 bit windows date time in python
<p>I need to convert a windows hex 64 bit (big endian) date time to something readable in python?</p> <p>example '01cb17701e9c885a'</p> <p>converts to "Tue, 29 June 2010 09:47:42 UTC"</p> <p>Any help would be appreciated.</p>
python
[7]
1,565,630
1,565,631
Possible to assign to multiple variables from an array?
<p>Is it a standard way to assign to multiple variables from an array in JavaScript? In Firefox and Opera, you can do:</p> <pre><code>var [key, value] = "key:value".split(":"); alert(key + "=" + value); // will alert "key = value"; </code></pre> <p>But it doesn't work in IE8 or Google Chrome.</p> <p>Does anyone know a nice way to do this in other browsers without a tmp variable?</p> <pre><code>var tmp = "key:value".split(":"); var key=tmp[0], value=tmp[1]; </code></pre> <p>Is this something that will come in an upcoming JavaScript version, or just custom implementation in FF and Opera?</p>
javascript
[3]
1,763,627
1,763,628
How to implement full advertisement using greystrip sdk?
<p>I want to display a full advertisement in my application. I don't know how to implement it. I know this is possible using greystrip sdk. Can you give me advice?</p>
iphone
[8]
2,899,300
2,899,301
passing by reference in Java doubts
<p>So I was reading <a href="http://stackoverflow.com/questions/40480/is-java-pass-by-reference">this post</a> and response no. 2. In that example, after calling that method, does the Dog value at address 42, name's changes to Max?</p> <pre><code>Dog myDog; Dog myDog = new Dog("Rover"); foo(myDog); public void foo(Dog someDog) { someDog.setName("Max"); // AAA someDog = new Dog("Fifi"); // BBB someDog.setName("Rowlf"); // CCC } </code></pre>
java
[1]
2,670,942
2,670,943
Convert an android acreen as Jpeg image
<p>Hi everyone I am creating a greeting card application wherein the user can choose from a set of backgrounds and add text to it.Now my question is how can I convert this screen as a JPEG image which can be sent as a mail to someone.That is the entire greeting card (image+text) is a jpeg image for the viewer.</p> <p>Thanks everyone in advance</p>
android
[4]
4,236,544
4,236,545
jquery tools .onSuccess
<p>Can someone point me in the right direction on this? I am using Tools as a validator but wanting to execute the ajax submit function that I have ONLY IF ALL validation passes. I have a working validation script here that works, and an ajax call that works; but I'm having a time trying to figure out how to get them to work together.</p> <p>How can I do this?</p> <pre><code>$(document).ready(function() { $("#leadbanker_intake_form").validator({ position: 'center right', offset: [0, 0], message: '&lt;div&gt;&lt;em/&gt;&lt;/div&gt;' }).bind("onSuccess", function(e, els) { // FUNCTION HERE still works even though some forms haven't validated } }); </code></pre>
jquery
[5]
1,478,314
1,478,315
JavaScript - array of objects, etc
<p>Say I have the following:</p> <pre><code>var a = '1', b = 'foo'; </code></pre> <p>How do I create an object using the above variables such that my object looks like this:</p> <pre><code>'1' =&gt; 'foo' </code></pre> <p>I'm trying to make this like an associative array. Furthermore, I want <code>1</code> to contain an array of objects. I have the variable that have the array of object; I just need to put it in <code>1</code>.</p>
javascript
[3]
1,512,756
1,512,757
store emails in textfile one per line
<p>This snippet of code renders a users email when a user enters a page of my site: ...</p> <pre><code>$email=$userprofile-&gt;email; </code></pre> <p>... you can echo it like this:</p> <pre><code>&lt;?php echo $email;?&gt; </code></pre> <p>but how would you store it in a text file in a directory or folder of my choosing with one email per line? thanks</p> <p>i tried this but it wont work</p> <pre><code>&lt;?php $file = 'http://mydomain.com/file/email.txt'; // Open the file to get existing content // Write the contents back to the file file_put_contents($file, $email); ?&gt; </code></pre>
php
[2]
4,622,822
4,622,823
how to develop a python wrapper for a C code?
<p>Well given a C code , is there a way that i can use other languages like python to execute the C code . What i am trying to say is , there are soo many modules which are built using a language , but also offer access via different languages , is there any way to do that ?</p>
python
[7]
1,550,233
1,550,234
javascript split and url encoding
<p>I have a string of a url:</p> <pre><code>var url = "/_imgs/media/image/Picture%201.png" </code></pre> <p>When I try to split it lke:</p> <pre><code>var path = url.split('image/'); console.log(path); </code></pre> <p>gives:</p> <pre><code>["/_imgs/media/", "Picture%201.png"] </code></pre> <p>ok fine, but when I do</p> <pre><code>console.log(path[1]); </code></pre> <p>I get:</p> <pre><code>/Picture%png </code></pre> <p>What is happening here?</p>
javascript
[3]
5,591,262
5,591,263
.ashx File Downloader - Auto-Detect MIME Type
<p>I'm throwing together a simple file upload/download component for the navigation menu on our intranet site to give it some really basic document management functionality. It's nothing you probably haven't seen a dozen times before, but the downloader code is included below for reference. This is ASP.NET 3.5 on IIS 7.5</p> <p>The big question is how can I have the MIME type automatically set using the IIS MIME type map for the site? I'd like to have the handler do its work getting the file content and filename from the database, then tell IIS, "Here, you figure out the MIME type, since you're so good at it."</p> <pre><code>public void ProcessRequest(HttpContext context) { int id = Int32.Parse(context.Request.QueryString["id"]); string AttachmentName = null; byte[] Attachment = null; using (SqlConnection dbconn = new SqlConnection(WebConfigurationManager.ConnectionStrings["NavMenu"].ConnectionString)) { dbconn.Open(); using (SqlCommand sql = new SqlCommand("NavMenu_GetFile", dbconn)) { sql.CommandType = CommandType.StoredProcedure; sql.Parameters.AddWithValue("@id", id); using (SqlDataReader reader = sql.ExecuteReader()) { if (reader.Read()) { AttachmentName = reader["AttachmentName"] as string; Attachment = (byte[])reader["Attachment"]; } else { return; } } } dbconn.Close(); } context.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", AttachmentName)); context.Response.BinaryWrite(Attachment); } </code></pre>
asp.net
[9]
2,734,963
2,734,964
How to trigger events after ending all calls?
<p>I am new in android.</p> <ul> <li>I want to <strong>trigger incomming and outgoing calls</strong>, and <strong>code should be executed when any call( incomming and outgoing) started and ended</strong>...</li> <li>I know that BroadcastReceiver is helpful for that. But can u give me the code/idea for that..</li> </ul> <p>Thanks in advance...</p>
android
[4]
2,115,279
2,115,280
-1 as a return value
<p>This question is specifically about PHP, but I'm guessing it might be applicable to other languages as well.</p> <p>I've noticed that between PHP4 and PHP5, the designers of the language shifted away from using <code>-1</code> as a return value to using constants or other forms of output. This makes sense, as <code>-1</code> is not particularly evocative, and I'm guessing this practice led to confusion.</p> <p>That said, I am sometimes inclined to return <code>-1</code> when I want to quickly add another return option to a function, and <code>-1</code> often seems like a perfectly valid way to express the outcome I am coding for. </p> <p>So here are my questions:</p> <ol> <li><p>Is my observation generally correct, regarding the move away from <code>-1</code> as a return value in PHP5 vs PHP4?</p></li> <li><p>What are the cons of returning <code>-1</code>, beyond for the reason I mentioned above, wherein the <code>-1</code> return value doesn't contribute positively to code clarity?</p></li> </ol>
php
[2]
3,462,798
3,462,799
Which way of checking for Document ready() is better in jQuery from a performance point of view?
<p>I've read <a href="http://viralpatel.net/blogs/20-top-jquery-tips-tricks-for-jquery-programmers/" rel="nofollow">an article about 20 top jQuery tips</a> that uses the below code snippet: </p> <pre><code>//Use $(function(){ //document ready }); </code></pre> <p>is better than using the below code: </p> <pre><code>//Instead of $(document).ready(function() { //document ready }); </code></pre> <p>I've always used the second code snippet. Is there any benefit on using the first one? Why is the second code snippet is better from performance perspective?</p>
jquery
[5]
5,818,248
5,818,249
Ternary Operator - What am I doing wrong?
<pre><code>$profilePic = isset( $userservice-&gt;getProfilePic($userid)) ? filter($userservice-&gt;getProfilePic($userid)) : '&lt;img&gt;&lt;/img&gt;'; </code></pre> <p>Returns the error:</p> <pre><code>Fatal error: Can't use method return value in write context </code></pre> <p>What am I doing wrong here?</p>
php
[2]
2,645,295
2,645,296
How do I make Java return a HTTP header in JSON as a Key Value Array
<p>I have the following as part of a method that is basically grabbing a webpage, I want to map the resulting header and body to JSON, the body is spat out as a string but ideally I want the header values split into key value so in the JavaScript I can access them directly.</p> <pre><code>Map&lt;String, String&gt; assoc = new HashMap&lt;String, String&gt;(); Map&lt;String, List&lt;String&gt;&gt; headerMap = new LinkedHashMap&lt;String, List&lt;String&gt;&gt;(); headerMap = connection.getHeaderFields(); for (String key : headerMap.keySet()) { assoc.put(key, headerMap.get(key).toString()); } JSONObject returnObj = new JSONObject(); returnObj.put("header", assoc); returnObj.put("body", sb.toString()); return returnObj.toString(); //Set digit to add indent spacing. </code></pre> <p>This unfortunately returns the header as a string rather than an array...</p> <pre><code>{"header":"{cache-control=[max-age=0], content-type=[text\/html], connection=[Keep-Alive], </code></pre> <p>Ideally this would be more like (friendlier for javascript)...</p> <pre><code>{ "headers": [ {"test": "testval"}, {"testb": "testbval"} ] } </code></pre>
java
[1]
2,736,398
2,736,399
Check files in current directory
<p>How can I tell python to scan the current directory for a file called "filenames.txt" and if that file isn't there, to extract it from a zip file called "files.zip"? I know how to work zipfile, I just don't know how to scan the current directory for that file and use if/then loops with it..</p>
python
[7]
2,138,251
2,138,252
Displaying Error Page based on the error exception?
<p>I am using the exception catching procedure which is the module to track the errors and it write the error description in a log file in the server.I want to display the error details in a common Error page which is having a multi-line textbox from the common function in the module.Is it possible to do that.If possible,How can I do that....</p> <p>Try</p> <p>;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;</p> <p>Catch ex as exception</p> <p>CreateLogFile(Ex)</p> <p>End Try</p> <p>The above description is the error catching portion from the code</p> <p>In the module I have written the CreateLogFile function which write the log file.</p> <p>I want to display the Error Page after writing the log file which should contain the error details....</p> <p>Please Help...?.<img src="http://file:///C:/Documents%20and%20Settings/Ramesh.DEV/Desktop/bbbb.bmp" alt="alt text"></p>
asp.net
[9]
1,467,818
1,467,819
Displaying text from database. Dissapears when page is refreshed
<p>I'm currently building a social network from home and have a very nice looking newsfeed. Now I'm able to post my status to the database and it pops up underneath, just like Facebook's newsfeed. However, when I refresh the page the status I inputted disappears and wondering if someone could tell me where I may have gone wrong as Dreamweaver isn't showing any errors within my code. </p> <p>I have checked my database and the status is still in there, just the box with the inputted text disappears completely from view.</p> <p>Here is my status code. Any help is greatly appreciated. </p> <pre><code>&lt;?PHP //Include connection to database include('connect_to_mysql.php'); //Get posted values from form $status=$_POST['status']; $date=$_POST['date']; //Strip slashes $status = stripslashes($status); $date = stripslashes($date); //Strip tags $status = strip_tags($status); $date = strip_tags($date); //Inset into database $insert_status=mysql_query("INSERT INTO status (status, date) VALUES('$status','$date')") or die (mysql_error()); while($row=mysql_fetch_array($insert_status)){ $status=$row['status']; $date=$row['date']; } //Line break after every 80 $status = wordwrap($status, 80, "\n", true); //Line breaks $status=nl2br($status); //Display status from data base echo '&lt;div class="load_status"&gt; &lt;div class="status_img"&gt;&lt;img src="blankSilhouette.png" /&gt;&lt;/div&gt; &lt;div class="status_text"&gt;&lt;a href="#" class="blue"&gt;Test Name&lt;/a&gt;&lt;p class="text"&gt;'.$status.'&lt;/p&gt; &lt;div class="date"&gt;'.$date.' &amp;middot; &lt;a href="#" class="light_blue"&gt;Like&lt;/a&gt; &amp;middot; &lt;a href="#" class="light_blue"&gt;Comment&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt;'; ?&gt; </code></pre>
php
[2]
3,113,821
3,113,822
load() responds correctly, but html not loaded into div
<p>I have an AJAX request to <code>post-bid.php</code> that is the result of this call:</p> <pre><code>$('#alert-container').load("post-bid.php", data); </code></pre> <p>According to firebug, this AJAX request returns the following code:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() {alert("My alert")}); &lt;/script&gt; </code></pre> <p>I have this line of code above <code>load()</code> line:</p> <pre><code>&lt;div id="alert-container"&gt;&lt;/div&gt; </code></pre> <p>Yet no HTML is loaded into this div. Any ideas?</p> <p><strong>SOLUTION</strong>: I simply needed to return data to the callback function of <code>load()</code>.</p>
jquery
[5]
512,740
512,741
can strstr() be used to look for 2 separate key words within a sentence?
<p>can strstr() be used to look for 2 separate key words within a sentence?</p> <p>ex:</p> <pre><code>$sentence = 'the quick brown fox'; if (strstr($sentence, 'brown') &amp;&amp; strstr($sentence, 'fox')) { echo 'YES'; } else { echo 'NO'; } </code></pre>
php
[2]
3,388,649
3,388,650
Accessing Files On A Hosted Asp.Net Site
<p>I want to create an asp.net based website. When I create the sit eon my local machine I am uploading pdf files to my file system then accessing the files to view in my website. When I make the site go live how do I translatye this? Can I have files saved somehow with my interenet host? How would I access the files though the internet host on my application?</p>
asp.net
[9]
135,447
135,448
I want to change the current wallpaper to another one programatically in android.Is it possible?
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/1964193/android-how-to-set-the-wallpaper-image">Android - how to set the wallpaper image</a> </p> </blockquote> <p>I want to change the current wallpaper to another one programatically in android.Is it possible?I am doing a project that automatically changes wallpaper depending on the conditions set by the user</p>
android
[4]
6,028,772
6,028,773
Why does java not convert my time correctly?
<p>I have the following method to convert a String to Date object</p> <pre><code>public Date convertTime(String time) { SimpleDateFormat parser = new SimpleDateFormat("d/M/y HH:mm:ss.S"); try { return parser.parse(time); } catch (Exception ex) { ex.printStackTrace(); return null; } } </code></pre> <p>I have the following method to convert it back</p> <pre><code>public String dateToTimeMillis(Date date) { //StringBuffer formatted = new StringBuffer(); SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss.S"); try { String formatted = parser.format(date); return formatted; } catch (Exception ex) { ex.printStackTrace(); return null; } } </code></pre> <p>The following test code</p> <pre><code> TraderLib lib = new TraderLib(); Date d1 = lib.convertTime("01/11/2011 10:41:09.045"); System.out.println(lib.dateToTimeMillis(d1)); </code></pre> <p>returns 10:41:09.45</p> <p>How do I preserve the 0?</p>
java
[1]
5,321,091
5,321,092
Is javascript worth learning if you do not plan on being a web developer?
<p>I heard Javascript is a full language just like c++. Is this true? What else is it good for programming besides web stuff?</p>
javascript
[3]
213,473
213,474
How do I create a 3 second delay in this jQuery?
<pre><code>jQuery.noConflict(); jQuery(document).ready(function() { // milliseconds var intervalTime = 75, div = jQuery(".animate"), st = div.text(), timer, count = 0, total = st.length; div.html("").css("visibility", "visible"); timer = setInterval(showLetters, intervalTime); function showLetters() { if(count &lt; total) { div.html(div.text().split("_").join("") + st.charAt(count) + ""); count++; } else { clearInterval(timer); } } }); </code></pre> <hr> <pre><code>&lt;div class="animate"&gt;Some text here.&lt;/div&gt; </code></pre>
jquery
[5]
1,785,036
1,785,037
How to find whether phone is in sleep/idle mode for Android
<p>How to find whether phone is in sleep/idle mode for Android?</p> <p>My problem is I am able to wake up the phone from sleepmode by using alarm manager </p> <p>But when the phone is not sleep mode and at the same instant if Alarm manager is used to wake the phone..android force closes the App..</p> <p>whether there is anyway to find whether the Phone is in sleep or idle mode?(Black screen)</p> <p><strong>Update:</strong></p> <p>My requirement:</p> <p>When the phone is in sleep mode ---> Intent should be launched from the service When the phone is not in sleep mode --> The same Intent should be launched from the service</p> <p>None of the solutions below worked perfectly so here is my little tweak which worked perfectly :):)</p> <pre><code> //Pending intent for my alarm manager Intent intentaa=new Intent(this,MyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentaa, 0); //Intent to be launched where MyIntent is the intent Intent intenta = new Intent(); intenta.setClass(this, MyIntent.class); intenta.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //Real code try { startActivity(intenta); }catch(Exception E) { AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime(), pendingIntent); startActivity(intenta); } </code></pre>
android
[4]
3,879,422
3,879,423
Jquery :first-line for IE8
<p>I have a need to wrap the first line of the following sentences inside :</p> <pre><code>&lt;span class="span"&gt;This is the first line &lt;br&gt; this should be the second line&lt;/span&gt; &lt;span class="span"&gt;This is another first line &lt;br&gt; this should be another second line&lt;/span&gt; </code></pre> <p><strong>Using jquery:</strong></p> <pre><code>$('.span:first-line').wrap('&lt;em&gt;&lt;/em&gt;'); </code></pre> <p>I expected the result:</p> <pre><code>&lt;span class="span"&gt;&lt;em&gt;This is the first line &lt;/em&gt;&lt;br&gt; this should be the second line&lt;/span&gt; </code></pre> <p><strong>The CSS:</strong></p> <pre><code>.span { display:block; white-space:pre; } </code></pre> <p>But no matter what IE do not seem to recognize it.</p> <p>Looping through each resulting unexpected:</p> <pre><code>$('.span:first-line').each(function() { $(this).wrap('&lt;em&gt;&lt;/em&gt;'); }); </code></pre> <p><strong>Bad Result:</strong></p> <pre><code>&lt;em&gt;&lt;span class="span"&gt;.................&lt;/span&gt;&lt;/em&gt; </code></pre> <p><strong>Also:</strong></p> <pre><code>$('.span').each(function() { $(this).filter(':first-line').wrap('&lt;em&gt;&lt;/em&gt;'); }); </code></pre> <p>Does anyone know other way to wrap the first line broken by a line break (<code>&lt;br&gt;</code>) whitespace to make it work for IE8?</p> <p>Thanks</p>
jquery
[5]
3,762,624
3,762,625
Disable USB transfer from code Android
<p>I need lock the usb data transfer, from my android application, exists a form to make this in a no rooted device?</p>
android
[4]
1,720,367
1,720,368
Is it safe to cast away template arguments in C++?
<p>I'm playing around with inheritance of template arguments in C++. I've got a Child class and a Parent class. The Parent class attempts to cast itself as the Child class. Although this does compile and appears to work, I'd like to know if it's safe to do. Here's the code:</p> <pre><code>class Empty { }; template&lt;class T&gt; class Child : public T { public: void do_something() { /* ... */ } }; class Parent { public: void go_crazy() { Child&lt;Empty&gt; &amp; self_as_child = *((Child&lt;Empty&gt; *)this); self_as_child.do_something(); } } void main() { Child&lt;Parent&gt; c; c.go_crazy(); } </code></pre> <p>So, is the self-cast unreliable? It appears to work, but maybe that's just because I got lucky with my particular compiler.</p>
c++
[6]
795,825
795,826
Pointing toward a top-level style sheet in all directories
<p>I have a html_headers.inc.php script that I want to include in every script on the site, to drop in a style sheet, the headers of the page, etc.</p> <p>It refers to main.css as the stylesheet to use, but when I get down into a subdirectory, i.e. /foo, the link obviously breaks because it's pointing to main.css and not ../main.css. What's the best way to guarantee it always points toward that top-level where main.css lives? I've got </p> <p><code>http://&lt;?= $_SERVER['HTTP_HOST']; ?&gt;/main.css</code> </p> <p>working, but it seems like there must be a more correct way.</p>
php
[2]
325,312
325,313
Problems accessing newly built elements
<p>This one is killing me :(. I'm loading saved filter sets and building each filter dynamically, inside a $.get() response function. I'm finding that, even though I'm correctly creating unique IDs for each of my selects and inputs, I'm not able to access the values of these inputs while inside the function that builds them. I tried multiple ways of adding delays to the jQuery selection process but nothing worked.</p> <pre><code>function onSavedFilterChange(item){ $.get('url', function(response) { //filters with uniquely ID'd inputs get built here //Can't access them here, immediately after creation } ); // Can't access them here either } $(document).ready(function(){ $('#randomButton').click(function(){ // but here, I can access the new inputs!! }); }); </code></pre> <p>My way of adding the elements is a bit complicated and may be the root of my problems. For each saved filter set returned, I start by cloning an initialized div and setting it's id attribute:</p> <pre><code>newFilter = $('#initialFilter') .clone() .removeAttr('id') .attr('id', 'fd_'+filterCount); </code></pre> <p>This div has three inputs; the first two are selects, the third can be a select or a text input. After that div has been cloned, I set the value of the first select like so:</p> <pre><code>var thisSelect = newFilter.find('select.filterBy'); var thisFieldName = rows[filterCount-1]['FIELD_NAME']; thisSelect.val(thisFieldName); </code></pre> <p>Next, depending upon the value of thisFieldName, I build the options of the second select using another ajax call, and I build the third input using yet another ajax call.</p> <p>And it just occurred to me... because I'm modifying an existing site built with ColdFusion, the last two ajax calls are called through ExtJS ajax proxies. I'm gonna bet that ExtJS isn't playing nice with jQuery and I'm going to have to rewrite those two functions.</p> <p>Either that or I'm insane to nest get calls inside get calls???</p>
jquery
[5]