Unnamed: 0
int64
65
6.03M
Id
int64
66
6.03M
Title
stringlengths
10
191
input
stringlengths
23
4.18k
output
stringclasses
10 values
Tag_Number
stringclasses
10 values
3,002,410
3,002,411
How to scale program to correct screen resolution?
<p>I am putting on a concert at my university in the next forty minutes in which I am projecting a full screen application I wrote on several different screens. I was only able to get hold of the projection system tonight and low and behold when plugged in the resolution of my screen changes drastically but when I execute my program it works as if it is using my old screen resolution. I've coded the entire visual display to exact pixel values but now half of it isn't displaying as it is pushed off the side of the screen. I've tried changing my displays manually in system preferences but it has no effect. I've tried creating different display modes to fit the resolutions but I keep getting the message UnsupportedOperationException: Cannot change display mode. Is there anyway I can scale my program to the correct size or change to the correct display mode?</p> <p>Below is the code I use to initialise the full screen:</p> <pre><code> frame = new display(); canvas = new Canvas(); canvas.addKeyListener(this); frame.setUndecorated(true); frame.getContentPane().add(canvas); strategy = canvas.getBufferStrategy(); environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); device = environment.getDefaultScreenDevice(); oldDisplay = device.getDisplayMode(); try { device.setFullScreenWindow(frame); newDisplay = new DisplayMode(1440, 900, 60, 60); device.setDisplayMode(newDisplay); catch (Exception ex) { } canvas.requestFocus(); canvas.setFocusTraversalKeysEnabled(false); frame.setVisible(true); canvas.createBufferStrategy(2); strategy = canvas.getBufferStrategy(); </code></pre> <p>Display is just a direct extension of JFrame.</p> <p>If I don't get this working I fail this module of my degree. Please stackoverflow don't fail me now! Thank you!</p> <p>Edit: FIXED EXCEPTION however program seems to not be changing resolution at all despite setting things 800, 600, 60, 60.</p>
java
[1]
1,791,608
1,791,609
Javascript Validation Form
<p>I am working with a form that has a catcha image. When a user fills out the form, and presses submit ( and only when the captcha number is wrong) the fields are reset or cleared. How can I prevent this from happening? If a visitor fills out the form, presses submit, the expected behaviour is theform is submitted, or if the captch number is wrong, retain the information that the visitor had input in the fields and ask the visitor to fill in the correct captcha number...</p> <p>Here is the js:</p> <pre><code>function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i&lt;(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p&lt;1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num&lt;min || max&lt;num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } } </code></pre>
javascript
[3]
2,991,537
2,991,538
Is it true that PHP teaches us how the web works more than others?
<p>I have seen an article (cannot find the URL) that says that PHP teaches you how the web works more than others such as asp.net. So in PHP you get the details of web security, how the requests are handled, etc.</p> <p>It is said that asp.net for example hides the details.</p> <p>Is that true? And could you say why?</p>
php
[2]
1,307,550
1,307,551
Is it possible to use too many functions in Python?
<p>This kind of a broad question.</p> <p>As I find myself having to write longer and longer scripts, I find that my instinct is to break everything up into bite-sized functions; however, this ultimately results in functions calling functions calling functions calling functions.... and I'm wondering if I'm completely thinking about this the wrong way.</p> <p>Here's what an abridged script might look like. Sorry it's kind of contrived.</p> <pre><code>def simple_task_1(): return def simple_task_2(): return def simple_task_3(): return def simple_task_4(): return def complex_task_1(): simple_task_2() simple_task_3() simple_task_4() return def startup(): simple_task_1() complex_task_1() simple_task_4() def finish(): # other function calls return def main(): startup() finish() </code></pre> <p>So, is this the correct way to be using functions? Is there an objective point where you can say you've made too many function calls inside each other? Should I even be making functions for tasks that only end up being done once?</p>
python
[7]
1,524,870
1,524,871
iPhone - general methods on a separate file
<p>I have some methods that are used by several classes. My idea was to put these methods on a general separate file and have this be seen by other classes.</p> <p>How do I do that in Xcode?</p> <p>Sorry but I am new to iPhone development.</p> <p>thanks</p>
iphone
[8]
129,946
129,947
Error with Python Code 2.7.3
<p>I'm getting this error with the code the error specified:</p> <pre><code>print str(i+1)+". Horse number "+str(winners[i])+" - "+str(odds(winners[i])) TypeError: 'list' object is not callable </code></pre> <p>I believe it may be caused by the printing of one of the objects. Thank you!</p>
python
[7]
5,773,121
5,773,122
.apk file upload error
<p>When i upload my .apk file it gives this error</p> <p>The certificate that signed this apk is not valid until the future. Create a new certificate.</p> <p>Thanks</p>
android
[4]
5,409,751
5,409,752
Why is Context used in this piece of code?
<pre><code>public class ImageAdapter extends BaseAdapter { private Context mContext; public ImageAdapter(Context c) { mContext = c; } </code></pre> <p>Here in this code,what does this <strong>Context</strong> means and what is the purpose of using this?</p>
android
[4]
2,150,924
2,150,925
parseInt() error: invalid argument
<p>I get a javascript error "invalid arguement" when I use parseInt(). What am i doing wrong?</p> <p>The function is to increase the font size of every element on a frame by 1</p> <pre><code>&lt;script&gt; var sizeCounter = 1; function changeFontSize(){ //var elements = parent.main.document.getElementsByTagName var myElements = parent.main.document.getElementsByTagName('*') for (i=0;i&lt;myElements.length;i++){ if(myElements[i].style.fontSize != null){ var elmFontSize = myElements[i].style.fontSize + ""; elmFontSize.replace("px",""); if(elmFontSize != "") { var elmFontSizeNum = parseInt(elmFontSize); } var resultSize = elmFontSizeNum + sizeCounter; myElements[i].style.fontSize = resultSize + "px"; //alert(myElements[i].className) } sizeCounter++; } } &lt;/script&gt; </code></pre>
javascript
[3]
5,561,245
5,561,246
In iphone can i add one picker view on two text boxes /uilabel with diffrent values?
<p>In my project i am filling the picker view array with the value which i am getting from the service.And in the same view i have another label on click of button in the label i want to get the same uipickerview with different value is that possible.....so with one picker view my work will be done no need to call to different picker views...anyone has solution for this isssue</p>
iphone
[8]
2,193,001
2,193,002
Which method signature is good and why?
<p>Given an IP Address Range ( a.b.c.d - a.b.c.e) i would like a method to return the ip address's in an array list between the range.</p> <p>Option 1 :</p> <pre><code>public static int getIPAddressesFromRange(String rangeStr, List list ) ; </code></pre> <p>return value is <code>count</code> and the input list would be populated with list of IP's the range has</p> <p>Option 2:</p> <pre><code>public static List getIPAddressesFromRange(String rangeStr) </code></pre> <p>return value is the list of ip addresses' </p> <p>My Option is 2, but that is intuition, not able to support my argument though.</p> <p>Edit: Is there any design principle the option 1 is violation ?</p>
java
[1]
5,348,810
5,348,811
global variable usage
<p>I have one basic question,I am declaring xmlfile as global in xml function,can I use it in another subroutine without any issues?does the order of subroutines matter?</p> <pre><code> def xml(): global xmlfile file = open('config\\' + productLine + '.xml','r') xmlfile=file.read() def table(): parsexml(xmlfile) </code></pre>
python
[7]
3,505,987
3,505,988
Dynamic casting
<p>why does the two last lines doesn't work and give me "The type or namespace name 'myType' could not be found" :</p> <pre><code>Type myType = this.GetType(); bool test = obj is myType; var p = (myType)obj; </code></pre> <p>thx</p>
c#
[0]
1,772,815
1,772,816
Checking for last record in PHP
<p>How can I implement the part below that I do not want to display on the last result?</p> <pre><code>&lt;?php foreach ($products-&gt;result() as $row): ?&gt; &lt;h3&gt;&lt;?= $row-&gt;header; ?&gt;&lt;/h3&gt; &lt;p&gt;&lt;?= $row-&gt;teaser; ?&gt; &lt;/p&gt; &lt;a href=""&gt;Read More&lt;/a&gt; &lt;!-- DONT DISPLAY THIS LAST LINE IF ITS THE LAST RECORD --&gt; &lt;div class="divider"&gt;&lt;/div&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>Thanks</p>
php
[2]
114,933
114,934
disable-enable a hyperlink by clicking on radio-buttons
<p><strong>i have a hyperlink code like :</strong> Click Here <strong>and i want to customize this link on the basis of my radio button click,which are like :</strong> YES NO <strong>on radio-button value:'yes',i want to enable the hyperlink. while on radio-button value:'no',i want to disable the hyperlink. So,to make the hyperlink disable after clicking radio-button 'NO', i have written the following in disable-link() method :</strong> function disable-link() { //document.getElementById('disable-link').disabled=true; document.getElementById('disable-link').href = '#'; } Now,what i have to write in enable-link() method so that the hyperlink gets re-enabled after clicking radio-button 'YES'</p> <pre><code>function enable-link() { //document.getElementById('disable-link').disabled=false; // SOME LINE OF CODE TO RE-ENABLE THE LINK } </code></pre> <p><em>document.getElementById('disable-link').disabled=true</em>*/*<em>false;</em> -: it makes the disable but user is able to click on the hyperlink though.So, i have used "<em>document.getElementById('disable-link').href = '#';</em>" -: it makes the link unclickable too Please suggest.</p>
javascript
[3]
1,166,140
1,166,141
JavaScript preloaded images are getting reloaded
<p>I am preloading images via JS like so:</p> <pre><code>Image1= new Image(234,273) Image1.src = "001.png" </code></pre> <p>The images successfully get called on page load (confirmed from the Firebug Net panel). </p> <p>After that, there's a button that triggers a function which replaces an image like so:</p> <pre><code>document.getElementById("myImage").src = "001.png"; </code></pre> <p>The problem is that when that function is called it's reloading the 001.png file, even though it was previously loaded. </p> <p>Any ideas on why it does that / how to avoid it?</p>
javascript
[3]
3,995,967
3,995,968
Single download file upload mechanism
<p>Sorry for the relatively vague title, I couldn't think of anything else.</p> <p>So in short what I'm asking for is what would be an optimal (least resource intensive) way of creating a simple file upload service that would delete the file after the first download. Can be PHP or anything else (as long as it's relatively easy to implement). It's basically for streaming screenshots for a single user.</p> <p>The first thing that comes to mind is simply doing a regular upload and then doing a readfile() followed by an unlink(). sendfile is obviously out of the question since then I don't have a way of executing code after the file has been transferred. But readfile() doesn't seem like such a good idea.</p> <p>I wouldn't mind installing a separate daemon or something along those lines.</p>
php
[2]
5,649,576
5,649,577
PHP how to mark and essay quizes
<p>i am doing an online quiz using PHP, which contain essays and multiple questions. After finish answering, student will be graded immediately. for the multiple questions there are no problem, but having problem at the essay part.</p> <p>My problem is:</p> <ol> <li>how can i do auto check</li> <li>and later i can edit the student answer to make a correction.</li> </ol> <p>thanks</p>
php
[2]
2,827,324
2,827,325
How to display selector in ListView
<p>I have a requirement that I need to dispaly ListView and at bottom of my List I have to display two buttons (scroll up/down).</p> <p>Whenever user press on these buttons my list should scroll accordingly.</p> <p>for this I have used </p> <pre><code> if(view == scrollupbtn) { if(listViewPosition &gt;= 1) listView.smoothScrollToPosition(-- listViewPosition); } else if(view == scrolldownbtn) { listView.smoothScrollToPosition(++ listViewPosition); } </code></pre> <p>This code able to scroll my listview but I am not able to see list item selector when I press my buttons..</p> <p>I want to display default list item selector when I press my buttons..</p> <p>Please let me know what to do for this..</p>
android
[4]
1,362,443
1,362,444
PHP Syntax validator?
<p>Im just wondering if theres a recommended syntax validator out there anybody can recommend?</p> <p>Having major issues and cant figure it out...</p> <pre><code> &lt;?php session_start(); if (isset ($_SESSION['id'])) {header("location: home.php");} if (array_key_exists("login", $_GET)){$oauth_provider = $_GET['oauth_provider']; if ($oauth_provider == 'twitter') { header("Location: login-twitter.php"); } else if ($oauth_provider == 'facebook'){ header("Location: login-facebook.php"); } } ?&gt; &lt;a href="?login&amp;oauth_provider=twitter"&gt;Twitter_Login&lt;/a&gt; &lt;a href="?login&amp;oauth_provider=facebook"&gt;Facebook_Login&lt;/a&gt; </code></pre>
php
[2]
3,883,138
3,883,139
Javascript date format like ISO but local
<p>how do I format a javascript date like ISO format, but in local time?</p> <p>with <code>myDate.toISOString()</code> I am getting the time as: "2012-09-13T19:12:23.826Z"</p> <p>but here, it is 22:13, so how do I include the timezone in above format?</p> <hr> <p>I ended up doing...</p> <pre><code>pad=function(e,t,n){n=n||"0",t=t||2;while((""+e).length&lt;t)e=n+e;return e} c = new Date() c.getFullYear()+"-"+pad(c.getMonth()+1)+"-"+pad(c.getDate()-5)+"T"+c.toLocaleTimeString().replace(/\D/g,':')+"."+pad(c.getMilliseconds(),3) </code></pre>
javascript
[3]
2,766,856
2,766,857
First PHP program, any suggestions?
<p>Below is the first program that I've made in PHP. Please let me know if there are any other improvements or consolidations that can be made. Thank you for your time.</p> <pre><code>&lt;?php $ages = array(); $agesfile = fopen("agelist.txt", "r"); while (!feof($agesfile) { array_push($ages, intval(fgets($agesfile))); } $total = 0; for ($i = 0; $i &lt; count($ages); $i++) { $total += $ages[$i]; } echo($total / count($ages) . "&lt;br/&gt;\n"); fclose($agefile); ?&gt; </code></pre>
php
[2]
3,118,251
3,118,252
jQuery blur event except when clicking a particular div
<p>This is my code:</p> <pre><code> $("#newGenreTxt").blur(function () { $("#txtAddGenreContainer").slideUp(); }); </code></pre> <p>I want to hide the text box if it loses its focus, but the problem is that I want to hide it if a user clicks anywhere but my button: </p> <pre><code>$("#addGenreFinal").click(function () {}); </code></pre> <p>So If user clicks the addGenreFinal nothing happens and if it's something else hide the textbox. </p>
jquery
[5]
5,204,875
5,204,876
Python object instance inheriting changes to parent class by another instance
<p>I am confused by this behaviour of Python(2.6.5), can someone shed light on why this happens?</p> <pre><code>class A(): mylist=[] class B(A): j=0 def addToList(self): self.mylist.append(1) b1 = B() print len(b1.mylist) # prints 0 , as A.mylist is empty b1.addToList() print len(b1.mylist) # prints 1 , as we have added to A.mylist via addToList() b2 = B() print len(b2.mylist) # prints 1 !!! Why ????? </code></pre>
python
[7]
2,171,169
2,171,170
Add image in first column in list view C#
<p>I have 7 column in my list view then i want to add image in first column. How I can solve this problem.</p> <p>Thanks in advance</p>
c#
[0]
2,712,441
2,712,442
How to creat a loop through LinkedHashMap<String,ArrayList<String>>?
<p>Please help me to create a loop through <code>LinkedHashMap&lt;String,ArrayList&lt;String&gt;&gt; h</code>:</p> <pre><code> if (h.get("key1").size() == 0) System.out.println("There is no errors in key1."); else System.out.println("ERROR: there are unexpected errors in key1."); if (h.get("key2").size() == 0) System.out.println("There is no errors in key2."); else System.out.println("ERROR: there are unexpected errors in key2."); if (h.get("key3").size() == 0) System.out.println("There is no errors in key3."); else System.out.println("ERROR: there are unexpected errors in key3."); if (h.get("key4").size() == 0) System.out.println("There is no errors in key4.\n"); else System.out.println("ERROR: there are unexpected errors in key4.\n"); </code></pre>
java
[1]
3,634,717
3,634,718
PHP Automatic Self Trigger
<p>Not sure if I understood the use/purpose of PHP entirely, but what seems to me that a .php file only executes when it is being called/executed by something before it, could be a html or a php file.</p> <p>A thought, is it possible that a php file written, and it would just be activated by its own, example over a duration span of time, every week or so it would do something?</p> <p>Thanks for looking...</p>
php
[2]
141,545
141,546
Using a substring function along with jQuery?
<p>I have the following HTML that can appear but only one at a time:</p> <pre><code>&lt;a id="menuRange" class="button" href="#"&gt;1 - 100&lt;/a&gt; &lt;a id="menuRange" class="button" href="#"&gt;101 - 200&lt;/a&gt; &lt;a id="menuRange" class="button" href="#"&gt;201 - 300&lt;/a&gt; </code></pre> <p>and I used this code to get the range: </p> <pre><code>var $field = $('#menuRange'); var nums = $field.text().split('-').map(function (a) { return parseInt(a, 10) + d * 100 }); </code></pre> <p>Now I want to change the HTML into:</p> <pre><code>&lt;a id="menuRange" class="button" href="#"&gt;Lines 1 - 100&lt;/a&gt; &lt;a id="menuRange" class="button" href="#"&gt;Lines 101 - 200&lt;/a&gt; &lt;a id="menuRange" class="button" href="#"&gt;Lines 201 - 300&lt;/a&gt; </code></pre> <p>How can I make it so I still get nums data like before. In other words, how can I make it ignore the word "Lines " as though it was not there?</p>
jquery
[5]
4,909,503
4,909,504
Adding class variables to defined class
<p>I'm a little confused on this particular problem and I have had this trouble for quite sometime now. The problem is that I don't know how to properly add a new class variable to an already defined class. In my scenario, I am using the tweepy module and using its Streaming API in order to get twitter messages that contain 'lol' in them.</p> <p><strong>Here is the code so far:</strong></p> <pre><code>import tweepy class StreamListener(tweepy.StreamListener): #I want to add some code here in order to open a file def on_status(self, status): try: #Rather than printing here I would like to write to the file print status.text except: self.textOut.close() auth1 = tweepy.auth.OAuthHandler(XXXXX, XXXX) auth1.set_access_token(XXXXX, XXXXX) api = tweepy.API(auth1) textOut = open('twitterMessages.txt') l = StreamListener() streamer = tweepy.Stream(auth=auth1, listener=l, timeout=3000000000 ) setTerms = ['lol', 'Lol', 'LOL'] streamer.filter(None,setTerms) </code></pre> <p>Look at the comments I made. I want to open a file to begin with and write to the file. The problem is when I create an <strong>init</strong> method, it seems to override the original <strong>init</strong> method.</p>
python
[7]
344,720
344,721
How might I get the serial number/ID of my Android emulator programmatically?
<p>How might I get the serial number/ID (like 5554,5556 etc.) of my Android emulator programmatically?</p>
android
[4]
1,303,549
1,303,550
Why do functions/objects inside anonymous namespace have external linkage?
<p>Why don't symbols (functions and variables) that are defined in an anonymous namespace have internal linkage as with static keyword? If a function is not visible/accessible outside, what is the reason to have external linkage?</p>
c++
[6]
3,596,984
3,596,985
How to remove a class from a page inside onclick html attribute?
<p>So how can I remove a class from all HTML elements on the page?</p> <p>I need to to it inside the onclick html element. So:</p> <pre><code>&lt;div onclick="remove class 'someClass' from all elements on the page"&gt;&lt;/div&gt; </code></pre>
javascript
[3]
1,733,667
1,733,668
How to execute a file that requires being in the same directory?
<p>I have a python script that needs to execute a <code>.jar</code> file that is located in another directory. What would be the best way to do this? So far I was thinking -</p> <pre><code>subprocess.call(["cd","/path/to/file"]) subprocess.call(["./file.jar"]) </code></pre> <p>How should I do this?</p> <p><strong>Update:</strong></p> <p>Using both of the answers below, this is what I ended up doing:</p> <pre><code>subprocess.call(shlex.split("./file.jar -rest -of -command"), cwd=COMMAND_FOLDER) </code></pre>
python
[7]
3,100,509
3,100,510
How to enumerate strings in a string resources file?
<p>I have a resources file called string.xml in res/valus directory</p> <p>the file has many string resources</p> <p>how can I obtain these items in an array from code ?</p> <p>I tried</p> <pre><code>Field[] x=R.string.class.getFields(); </code></pre> <p>but it does not work.</p> <p>thanks</p>
android
[4]
4,143,228
4,143,229
compile time polymorphism?
<p>The book im reading says when you override a method in a subclass it means runtime polymorphism. Is there a thing like compile time polymorphism? I thought simple inheritance happens at compile time then polymorphism is runtime.</p>
java
[1]
4,053,762
4,053,763
If we import one package in java program means Is there need to extend it?
<p>If we import one package in java program means Is there need to extend it?</p> <pre><code>import Apack.Bpack.Myclass class Thisclass extends Myclass{ } </code></pre> <p>my question is whether we need extends here?</p> <p>for example<br> if i want a variable from Myclass then need to extend or import or both?</p>
java
[1]
1,611,611
1,611,612
MotionEvent ACTION_MOVE still firing after dragging outside original view bounds
<p>I have 3 Imageview in relativelayout and i have added onTouchListener for all ImageView</p> <p>Now when i press my finger on any imageview onTouchListener is fired, which is working correctly, also when i move finger arround without lifting up ACTION_MOVE touch is fired, everything works correctly.</p> <p>However when i take my finger outside the imageview ACTION_MOVE is still fired :(</p> <p>i don't want ACTION_MOVE when finger goes outside the ImageView, on the other hand if my finger goes to some other ImageView, ACTION_MOVE touch should be fired from that ImageView as TouchListener is added for all ImageView</p>
android
[4]
1,774,241
1,774,242
How to loop through a table and read the first colum in every rowspan
<p>How do I read each and every value of the first column using jquery?</p> <p>I have the code which is not working.</p> <pre><code>$("foo:eq(1) tr").each(function(){ alert( $(this).find('td:first[rowspan]').text()); }); &lt;table id="foo" border="1px"&gt; &lt;tr&gt; &lt;td rowspan='3' id="date"&gt; Monday5 &lt;/td&gt; &lt;td id="Name"&gt;Jim &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="Name"&gt; Remy &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre>
jquery
[5]
2,687,904
2,687,905
cxfreeze (or equivalent) and cross build?
<p>Is it possible for cx_freeze (or any other tool with the same purpose) to cross build binaries? I.e. build Windows binary on a Linux PC? Or is this too much to ask?</p> <p>I tried with cx_freeze and got the following:</p> <pre><code>cx_Freeze.freezer.ConfigError: no base named Win32GUI </code></pre> <p>Thanks,</p>
python
[7]
3,971,743
3,971,744
Web Page Size Using Java
<p>How to get the web page size from an url in bytes. This should include all images. How can we do that. Any help Thanks in Advance</p>
java
[1]
4,861,871
4,861,872
comma in raw_input function
<p>What would be the output of this ? I see the output but not able to understand why that happens.</p> <pre><code>def multiple(x,y): mul = x*y return mul x=int(raw_input("Enter value 1 ")), y=int(raw_input("Enter value 2 ")) print multiple(x,y) </code></pre>
python
[7]
3,401,696
3,401,697
How to create javascript variable with other variable value in name
<p>Hi I need to create a load of variables in a javascript loop so say my loop goes round 5 times starting at 0 by the end of it the following variables should be defined:</p> <pre><code>variable_0 variable_1 variable_2 variable_3 variable_4 </code></pre> <p>Can anyone tell me how to do this please?</p>
javascript
[3]
4,892,510
4,892,511
PHP write binary file
<p>I have wrote a PHP file which will save a JPEG file in the server and part of the code is listed as follow:</p> <pre><code> //create folder if folder not exist if (!is_dir($save_path)){ $old = umask(0); $flag = @mkdir($save_path,0777); umask($old); if(isset($flag)){ $string = 'Folder Create Success!'."\n"; }else{ $string= 'Folder Create Fail!'."\n"; } echo $string; }else{ echo "Folder exist!!!!"; } //write the content to the server $base=$_REQUEST['image']; $binary=base64_decode($base); header('Content-Type: image/jpg; charset=utf-8'); if(!$file = fopen($path, 'wb')){ echo 'Image upload Fail!'."\n"; return; } else { fwrite($file, $binary); fclose($file); } </code></pre> <p>The problem is when I run the code, if the folder does not exist, it create the folder only but the content can't save in the folder. The error message is :</p> <p>[Thu Jul 05 16:59:06 2012] [error] [client 10.95.61.220] PHP Warning: fopen(/mnt/csis/upload/newphoto/others/12346_test/12346_test_2012-07-05_others_abc.jpg): failed to open stream: Permission denied in /var/www/html/upload_image.php on line 57</p> <p>However, if I run the code again, since the folder was created in the past, it work properly. The content can save in the folder......</p> <p>Anything I get wrong? I try to find the answer on the web but still can't solve the problem.</p> <p>Anyone can help, many thanks!</p>
php
[2]
3,025,785
3,025,786
PHP - Where should I call ini_set?
<p>I am looking for a best practice for where I should place the statement ini_set.</p> <p>For example,</p> <pre><code>ini_set('session.use_only_cookies', 1); </code></pre> <p>Thank you</p>
php
[2]
1,820,184
1,820,185
Error can't get value other from input type hidden
<p>index.php i am using:</p> <pre><code>&lt;script src="srcipt.js"&gt;&lt;/script&gt; &lt;div id="demo"&gt; &lt;h3&gt;&lt;input type="hidden" name="id" value='1' /&gt;test1&lt;/h3&gt; &lt;h3&gt;&lt;input type="hidden" name="id" value='2' /&gt;test2&lt;/h3&gt; &lt;h3&gt;&lt;input type="hidden" name="id" value='3' /&gt;test3&lt;/h3&gt; &lt;h3&gt;&lt;input type="hidden" name="id" value='4' /&gt;test4&lt;/h3&gt; &lt;h3&gt;&lt;input type="hidden" name="id" value='5' /&gt;test5&lt;/h3&gt; &lt;/div&gt; </code></pre> <p>in script.js</p> <pre><code>$(document).ready(function(){ $('#demo h3').click(function(){ var id = $(this).parent().find('input[type="hidden"][name="id"]').val(); alert(id); }); }); </code></pre> <p>When I click on "test1" result 1 , click on "test2" result 1 ... , click on "test5" result 1</p> <blockquote> <p>How to get value when click on "test2" is result 2, how to fix it ?</p> </blockquote>
jquery
[5]
1,517,727
1,517,728
what is the difference between Sleep mode and Deep sleep mode?
<p>I would like to know what is the difference between Sleep mode and Deep sleep mode in android phone and what will be the impact of when phone goes to sleep mode and deep sleep mode.</p> <p>Please provide me the answer in details.</p> <p>regards, Piks</p>
android
[4]
1,804,847
1,804,848
Restart aspnet_state.exe every dat
<p>I am using the stateserver for storing the session data but as the session data keeps increasing as number of users increase so is ther any way we can restart the aspnet_state.exe every day so that all session data is cleared</p> <p><strong>Is there any kind of script or .exe that can be automated to restart aspnet_state.exe</strong></p> <p>i am uisng 5 webservers where one webserver acts as a stateserver this server aspnet_state.exe has to be restarted every day at 1 AM is there any code snippnet that can be this works automatically</p> <pre><code>&lt;sessionState mode="StateServer" stateConnectionString="tcpip=127.23.45.56:80" /&gt; </code></pre> <p>Any help is much apprciated !</p> <p>Thanks Prince</p>
asp.net
[9]
826,582
826,583
django.core.exceptions.ImproperlyConfigured: Directory 'uploads/' for the site filebrowser.filebrowser does not exist.
<p>I am trying to use FileBrowseFile in my project but when i run the program it says django.core.exceptions.ImproperlyConfigured: Directory 'uploads/' for the site filebrowser.filebrowser does not exist.</p> <p>my settings file looks like</p> <pre><code>MEDIA_ROOT = getattr(settings, "FILEBROWSER_MEDIA_ROOT", settings.MEDIA_ROOT) MEDIA_URL = getattr(settings, "FILEBROWSER_MEDIA_URL", settings.MEDIA_URL) DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/') </code></pre> <p>my models.py has </p> <pre><code>banner_url = FileBrowseField("Image",max_length=200,blank=True,null=True, extensions=['.jpg']) </code></pre> <p>what can be done to get rid of this error?</p>
python
[7]
2,895,518
2,895,519
Simplest way of choosing a preferred variable value
<p>I have 3 variables, that are not always set. <code>o1</code>, <code>o2</code>, <code>o3</code>.</p> <p>I want to create a new variable as follows:</p> <p>if none are set: <code>o4 = null</code></p> <p>if <code>o1</code> is set, <code>o4 = o1</code>, regarded of what the other are.</p> <p>when <code>o1</code> is not set and <code>o2</code> is set: <code>o4 = o2</code></p> <p>So <code>o4 = o3</code> only gets set when 1 and 2 are not set.</p> <p>==</p> <p>I am now using a long switch, but I bet it can be done better.</p> <p>JavaScript / jQuery</p> <pre><code> var tmpl = ''; if(data.o3 != null) tmpl = data.o3; if(data.o2 != null) tmpl = data.o2; if(data.o1 != null) tmpl = data.o1; </code></pre>
javascript
[3]
2,428,038
2,428,039
display items from an xml file when condition is satisfied
<p>I have a problem of comparaison </p> <pre><code> for (int i = 0; i &lt; posteList.getgouvernorat().size(); i++) { if (posteList.getgouvernorat().get(i).toString()==text){ gouvernorat[i] = new TextView(this); gouvernorat[i].setText("gouvernorat = "+posteList.getgouvernorat().get(i)); ville[i] = new TextView(this); ville[i].setText("ville = "+posteList.getville().get(i)); localite[i] = new TextView(this); localite[i].setText("localite = "+posteList.getlocalite().get(i)); } layout.addView(gouvernorat[i]); layout.addView(ville[i]); layout.addView(localite[i]); String b="-------------------"; } a = new TextView(this); a.setText(text); layout.addView(a); /** Set the layout view to display */ setContentView(layout); } } </code></pre> <p>gouvernorat[i] is an arrayList</p> <p>text is a String</p> <p>this code display an error message <code>Sorry Force Close</code></p> <p>i used XML parser, and the code is to parse the xml file </p> <p>i want to display on a layout only the item equal to text</p> <p>when i remove the test <code>if (posteList.getgouvernorat().get(i).toString()==text)</code> all the file will be displayed</p> <p>thank you in advance</p>
android
[4]
4,564,961
4,564,962
Android Global variable source not found
<p>I've declared a global variable class like this:</p> <pre><code>public class globalVar extends Application { private String globalVar= ""; public String getGlobalVar() { return globalVar; } public void setGlobalVar(String globalVar) { this.globalVar = globalVar; } @Override public void onCreate() { //reinitialize variable } } </code></pre> <p>And declared it in my androidmanifest file like this:</p> <pre><code>&lt;application android:name=".globalVar" android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;/application&gt; </code></pre> <p>And tried to set its value in a list under a onclicklistener:</p> <pre><code>((globalVar)getApplication()).setGlobalVar("something"); </code></pre> <p>I've got it to work before in another application, but for some reason it's giving me the source not found error...I've been scratching my heads off since this is my only obstacle now, has anyone experience this issue before or has an idea as to why I keep getting the error? Thanks!!</p>
android
[4]
4,100,506
4,100,507
Best way of calling code from different projects in a C# solution
<p>I have a solution with multiple projects. Both the projects have Forms.</p> <p>Example</p> <p>MySolution</p> <p>|<strong><em>_</em>__<em>_</em>__<em>_</em>___</strong> Project1 (Windows Form)</p> <p>|<strong><em>_</em>__<em>_</em>__<em>_</em>___</strong> Project2 (Also a Windows Form)</p> <p>Now I want to call the Form in Project2 from the Form in Project1. Sort of going like this</p> <pre><code>using (Form2 f2 = new Form2(myFile)) { //.... } </code></pre> <p>Moving Form2 into Project1 is not an option unfortunately.</p> <p>What's the best way to go about it.</p> <p>Thanks</p>
c#
[0]
2,672,933
2,672,934
how to fix or optimize code to ignore memory size error in PHP
<p>I wrote a image crawler with simple_html_dom library, I used this code to fetch all images in a web site ;</p> <pre><code>include 'simple_html_dom.php'; $img_array = array(); if (isset($_POST['url'])) { $url = $_POST['url']; $html = file_get_html($url); echo $html-&gt;getElementByTagName('title')-&gt;innertext(); foreach ($html-&gt;find('a') as $a) { if (strpos($a-&gt;href, $url) !== FALSE) // only images from this site { // // find_images($a-&gt;href); $imgs = file_get_html($a-&gt;href); foreach ($imgs-&gt;find('img') as $img) { if(!in_array($img-&gt;src, $img_array)) { echo '&lt;img src="' .$img-&gt;src. '" class="thumb"&gt;'; $img_array[] = $img-&gt;src; } } echo '&lt;hr&gt;'; } } } </code></pre> <p>but whene i execute this code i get <code>Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 71 bytes) in /home/iphotosh/public_html/test/simple_html_dom.php on line 122</code></p> <p>test and demo : <a href="http://test.iphotoshop.ir/" rel="nofollow">test.iphotoshop.ir</a></p> <p>how to fix this error or how to opti,ize this code for fetch all images from a web site?</p>
php
[2]
1,402,854
1,402,855
Nested C++ class outer members' access
<p>This code does not work (MS VS 2005),</p> <pre><code>b-&gt;funcA(); B::iterator iter; </code></pre> <p>cant access protected members declared in class A.</p> <p>If I remove class D, everything compiles nicely.</p> <p>I wonder if it's just a bug or standard?</p> <pre><code>class A { protected: void funcA() { } class iterator { }; }; class D { class B : public A { class C { B* b; public: void funcC() { b-&gt;funcA(); B::iterator iter; } }; public: void funcB() { funcA(); } }; }; </code></pre> <p>Thanks!</p>
c++
[6]
4,628,710
4,628,711
Error Reading From A file Inside A Directory
<p>I am trying to read files, inside a folder, reason is the number of files inside the folder is not fixed, but if there are 3 text folder, I have to read all the 3 files if 4 all the 4 text files.</p> <p>Here is the code I'm trying to use, but comes up with an IOError:</p> <pre><code>for i in os.listdir("./RecordFolder"): print i </code></pre> <p>Output is: record1.txt record2.txt</p> <p>Now the problem is reading the files:</p> <pre><code>for files in os.listdir("./RecordFolder"): filecontent = open(files).readlines() for lines in filecontent: print lines </code></pre> <p>Output:</p> <pre><code>IOError: [Errno 2] No such file or directory: 'record.txt' </code></pre> <p>Need some help here, thanks </p>
python
[7]
1,329,946
1,329,947
c# minimum of two numbers if one or both is greater than 0
<p>The logic I'm looking for is if either of the numbers are >= 0 (which they don't have to be), then return the minimum of the two that is also greater than 0. The code I've written for it is so ugly that I'm ashamed to post it! </p> <p>EDIT: Samples 1, -1 => 1 5,6 => 5 -1,-1 => 0</p> <p>(if both are less than 0, return 0)</p>
c#
[0]
879,232
879,233
Letter positions, figuring out a smart way for a word guess game
<p>I am learning Java and in the process I am writing a Word Guess game. Now mine problem is the following:</p> <p>Assume the word to guess is "lingo". And assume "oodle" is a word you suggested. On processing your guess, the following should be output: Correct Letters: none Wrong Position Letters: 'o' at first position, 'l' at fourth position Note that the second 'o' should not be mentioned as a letter in the wrong position, as we already have reported an 'o' prior to that. So if you enter 'ooooo', only the last letter should be highlighted as it is in the correct position, and if you enter 'ooooz', only the first letter should be highlighted, and not the other 'o's. </p> <p>I have tried some solutions but all seem to fail. I know there is a smart/not so complex way to do this. So could anyone help me with that? </p> <p>The code:</p> <pre><code>// / Indicates whether a letter has been accounted for // / while highlighting letters in the guess that are not // / in the correct position private Boolean[][] marked = new Boolean[WordLength][5]; // / Holds which all letters have been solved so far private Boolean[][] solved = new Boolean[WordLength][6]; public void CheckLetters() { for (int j = 0; j &lt; currentAttempt; j++) { tempWord = list.get(j); //The guessed words for (int i = 0; i &lt; WordLength; i++) { if (tempWord.charAt(i) == CurrentPuzzleWord.charAt(i)) { solved[i][j] = true; //CurrentPuzzleWord is the string with the hidden word } else if (CurrentPuzzleWord.indexOf(tempWord.charAt(i)) != -1) { marked[i][j] = true; } } } </code></pre>
java
[1]
1,166,072
1,166,073
How to use in_array() for caseless?
<p>It's a big array, so i won't to strtolower every value.</p>
php
[2]
2,559,589
2,559,590
Business/Holiday date handling
<p>I'm looking for a C# class/library that works similarly to the Perl module <a href="http://search.cpan.org/dist/Date-Manip/" rel="nofollow"><code>Date::Manip</code></a> as far as business/holiday dates. Using that module in Perl, I can pass it a date and find out whether it's a business day (ie, Mon-Fri) or a holiday. Holidays are very simple to define in a config file (see <a href="http://search.cpan.org/dist/Date-Manip/lib/Date/Manip/Holidays.pod" rel="nofollow"><code>Date::Manip::Holidays</code></a>). You can enter a 'fixed' date that applies to every year like:</p> <pre><code>12/25 = Christmas </code></pre> <p>or 'dynamic' dates for every year like:</p> <pre><code>last Monday in May = Memorial Day </code></pre> <p>or 'fixed' dates for a given year like:</p> <pre><code>5/22/2010 = Bob's Wedding </code></pre> <p>You can also pass in a date and get back the next/previous business day.</p> <p>Does anyone know of anything like that in the C# world? I've found a couple of things that implement parts of what I need (<a href="http://www.codeproject.com/KB/cs/busdatescalculation.aspx" rel="nofollow">http://www.codeproject.com/KB/cs/busdatescalculation.aspx</a> and <a href="http://www.codeproject.com/KB/dotnet/HolidayCalculator.aspx" rel="nofollow">http://www.codeproject.com/KB/dotnet/HolidayCalculator.aspx</a>) and I can pick them apart and make what I need. But if someone else has already done that, why do it again?</p> <p>Thanks!</p> <p>Dave</p>
c#
[0]
281,790
281,791
Permanently passing variable to function
<p>Can someone help me simplify this code? Is there a way I can permanently pass $the_campus to is_campus() without using a global scope? $the_campus is pulling from a database and the value changes, but the variable is always called $the_campus.</p> <p>Thanks!</p> <pre><code> $the_campus = $search_term['campus']; function is_campus($the_campus, $selected_campus) { if ( $selected_campus == $the_campus ) { echo 'selected'; } } &lt;?php is_campus($the_campus, 'university-of-minnesota-tc'); ?&gt; &lt;?php is_campus($the_campus, 'university-of-wisconsin'); ?&gt; &lt;?php is_campus($the_campus, 'university-of-chicago'); ?&gt; </code></pre>
php
[2]
3,442,881
3,442,882
Where did I go wrong in this code?
<p>A few of my classes aren't passing automated tests. Unfortunately, said tests do not provide any useful information about why they failed. Here is my code for a couple of the classes. I'd really appreciate it if you could tell me where I went wrong. The comments should explain what each method is supposed to do.</p> <pre><code>public class CellPhone { protected String ownerName; public CellPhone(String owner) { ownerName = owner; } public String receiveCall(CellPhone sender) { // returns a String of the form: // owner's name " is receiving a call from " sender's name String receivingCall = ownerName + " is receiving a call from " + sender; return receivingCall; } public String call(CellPhone receiver) { // returns a String by using the receiver to invoke receiveCall // while passing in the current phone String invokingReceiveCall = receiver.receiveCall(receiver); return invokingReceiveCall; } } </code></pre> <hr> <pre><code>public class TextMessagingPhone extends CellPhone { private int availMessages; public TextMessagingPhone(String owner, int messageLimit) { // invokes the superclass constructor super(owner); // sets the new instance variable availMessages = messageLimit; } public TextMessagingPhone(String owner) { // invokes the other constructor of this class with 15 as the message limit this(owner, 15); } public String receiveText(TextMessagingPhone sender, String message) { // decreases the number of messages available to send availMessages--; // returns a String of the form: // owner's name " has received TEXT from " sender's name ":" message String receivedText = ownerName + " has received TEXT from " + sender + ":" + message; return receivedText; } public String sendText(TextMessagingPhone receiver, String message) { // decreases the number of messages available to send availMessages--; // returns a String by using the receiver to invoke receiveText // while passing in the current phone and the message String invokingReceiveText = receiver.receiveText(receiver, message); return invokingReceiveText; } } </code></pre>
java
[1]
3,463,001
3,463,002
How to switch the server in apk
<p>I have one test apk which is pointing 3 different environments.</p> <p>Is there any way to switch from one to another environment or Is there any app to switch between one server to another?</p> <p>Thanks Chandra</p>
android
[4]
2,657,484
2,657,485
how to install apk file programmatically
<p>I want to install an apk file from my application.</p> <p>I have created an app that contains a button, when I click that button then another apk that I have stored in resources folder should be install, <br>Heres something I have done :</p> <pre><code>public void onClick(View v) { // Intent intent = new Intent("com.google.zxing.client.android.SCAN"); // intent.setPackage("com.google.zxing.client.android"); // intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // startActivityForResult(intent, 0); File file = new File("android.resource://com.app.barcodescanner/raw", "scan.apk"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent); } </code></pre> <p>any ideas ? <br>please help me with this</p>
android
[4]
5,634,720
5,634,721
if files mtime is less than x amount. print those files
<p>I am able to print mtime attribute of files. I am only concerned with files modified in say the last xxxx amount of minutes. I touched files in the directory so i know there are new files there. </p> <pre><code>file_list_attr = sftp.listdir_attr('/path') fdir = sftp.listdir(path=source) for f in file_list_attr: print "name=%s, modified date=%s, size=%s" % (f.filename, f.st_mtime,f.st_size) mt = f.st_mtime now=dt.datetime.now() while f.st_mtime == now-dt.timedelta(minutes=2120): print 'You have something here' else: print 'nada' </code></pre>
python
[7]
5,479,087
5,479,088
How would you weigh something using an Iphone?
<p>Provided you know the weight of the phone, how would you weight any object using the phone?</p> <p>Edit: Ok what if you had a device that would let you compare the weights?</p>
iphone
[8]
5,831,041
5,831,042
Is it possible to override only required abstract methods in interface or Abstract classes among n-methods?
<p>Is it possible to override only some abstract methods in interface among set of abstract methods?</p>
java
[1]
70,162
70,163
How to set the options of select dynamically?
<p>I have a combo-box which works as a filter for a column. On changing any value in the column, I want to update the options in the combo-box. obj.default gives me the old value of the changed field in the column.</p> <pre><code>function valueChange(obj) { var optionsArray = document.getElementById('filter').options; for (var index = 0; index &lt; optionsArray.length; index++) { if (optionsArray[index].value == obj.defaultValue) { optionsArray[index].value = new Option(obj.value, obj.value); } } } </code></pre> <p><code>optionsArray</code> is getting populating correctly. How to set back <code>optionsArray</code> back to the element's option?</p>
javascript
[3]
3,181,523
3,181,524
Stream reference error
<p>Compiler Error Message: 'Stream' is an ambiguous reference between 'System.IO.Stream' and 'WebReference.Stream'</p> <p>Any thoughts?</p> <p>I have web method accepting <code>System.IO.Stream</code> stream as an input parameter &amp; internally i assing <code>stream=new MemoryStream(bytes[]);</code></p>
c#
[0]
3,451,196
3,451,197
Zoom an image with mouseover on image in another div
<p>There is many plugins for zooming image (like <a href="http://www.mind-projects.it/projects/jqzoom/index.php" rel="nofollow">jqzoom</a>). But I want to zoom image with hovering on image in another div: <img src="http://i.stack.imgur.com/6bHta.jpg" alt="enter image description here"></p> <p>Is there any way to have an effect like jqzoom (inner zoom)but with mouseover on another element? I want this effect : seavello.com/r/zoom/zoom.html, but with mouseover on thumbnial not main image Thanks in advance</p>
jquery
[5]
1,603,016
1,603,017
How to create service in Android and consume it?
<p>I am very new to the Android platform. Now in my app I want to create service and so please give me some info that how to create a service and consume it in my app. And how to start the service when the OS starts up?</p>
android
[4]
168,919
168,920
System.NullReferenceException when trying to read config file from a unit test project
<p>Am doing a unit test, testing my connection string. This is the code I have on my test method:</p> <pre><code> [TestMethod()] public void connectionStringTest() { //string expected = null; // TODO: Initialize to an appropriate value string actual; string expected = " User Id=ownitsbio;Password=ownitsbio;Data Source=preprod"; actual = ConfigurationManager.ConnectionStrings["ownitsbio"].ConnectionString; Assert.AreEqual(expected, actual); //Assert.Inconclusive(expected); } </code></pre> <p>I get this error <code>System.NullReferenceException: Object reference not set to an instance of an object</code>. What could be the problem?? Please help!</p>
c#
[0]
4,873,475
4,873,476
how can i verify that RegistrationServices successfully unregistered a file
<p>I am creating an uninstall utility in C#. The utility will unregistered the files registered through Regasm.I wrote the code below </p> <pre><code>RegistrationServices regAsm = new RegistrationServices(); for(int i = 0; i &lt; 100; i++) { Assembly asm = Assembly.LoadFrom("filespath[i]"); if (regAsm.UnregisterAssembly(asm)) logToFile(SuccessfullyUnregistered); } </code></pre> <p>it worked fine but if i execute the above code 100 times and don't delete those files(which are registered throguht Regasm), then regAsm.UnregisterAssembly(asm) always return true. Is this the right behaviour? How can i verify that RegistrationServices successfully unregistered a file?</p> <p>Thanks and Regards</p>
c#
[0]
2,949,146
2,949,147
How to upload file on server with file name which is given from client side
<p>I am uploading file from iphone to sever using php code but when upload it gives random number name to file with my filename so how to remove that number and only filename should remain in script</p> <pre><code> &lt;?php $uploaddir = './'; //Uploading to same directory as PHP file $file = basename($_FILES['userfile']['name']); $uploadFile = $file; $randomNumber = rand(0, 99999); $newName = $uploadDir . $randomNumber . $uploadFile; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Temp file uploaded. \r\n"; } else { echo "Temp file not uploaded. \r\n"; } if (move_uploaded_file($_FILES['userfile']['tmp_name'], $newName)) { $postsize = ini_get('post_max_size'); //Not necessary, I was using these $canupload = ini_get('file_uploads'); //server variables to see what was $tempdir = ini_get('upload_tmp_dir'); //going wrong. $maxsize = ini_get('upload_max_filesize'); echo "http://www.iroboticshowoff.com/dir/{$file}" . "\r\n" . $_FILES['userfile'] ['size'] . "\r\n" . $_FILES['userfile']['type'] ; } ?&gt; </code></pre>
php
[2]
449,428
449,429
Is it possible to add some functionality to a class without subclassing?
<p>In Ojective-C there is something called Categories which allow the user to add methods from outside the original .h or .m file (objective-c's version of .cpp) I wonder if there exist such functionally in C++.?</p> <p>I specially want implement &lt;&lt; operator for debugging and maybe others of a class that is in a library I frequently use. (And don't want to use macros since it looks ugly ;) )</p> <p>Thanks.</p>
c++
[6]
311,817
311,818
Adding an email to existing contact
<p>I am trying to add an email to existing contact. Here's the code... Any help is much appreciated!</p> <pre><code> addToThisContact.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;(); int contactId = Integer.parseInt(id); ContentValues contentValues = new ContentValues(); contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId); contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract. CommonDataKinds.Email.CONTENT_ITEM_TYPE); contentValues.put(ContactsContract.CommonDataKinds.Email.DATA, "emailAddress@email.com"); contentValues.put(ContactsContract.CommonDataKinds. Email.TYPE, ContactsContract. CommonDataKinds.Email.TYPE_HOME); ops.add(ContentProviderOperation.newInsert(ContactsContract.Data. CONTENT_URI).withValues(contentValues).build()); } }); </code></pre>
android
[4]
2,587,317
2,587,318
Why is it possible to pass an array instead of a selector?
<pre><code>var arr = [1, 2, 3]; $(arr).each(function() { alert(this) }); </code></pre> <p>This works OK with jQuery except the set isn't made up of DOM elements but integers. Shouldn't this be not allowed?</p>
jquery
[5]
1,932,076
1,932,077
Python syntax inconsistency?
<p>I've been reading up on python's <a href="http://www.diveintopython.net/object_oriented_framework/special_class_methods2.html">special class methods</a> in <a href="http://www.diveintopython.net">Dive into Python</a>. And it seems like some methods have odd or inconsistent syntax.</p> <p>To get the items from a dictionary you would call the dictionary class method items()</p> <pre><code>&gt;&gt;&gt; my_dictionary.items() [('name', 'Old Gregg'), ('Race', 'Scaly Man-Fish')] </code></pre> <p>However, to determine the number of keys in that dictionary you would call len() and supply it with the dictionary as an argument.</p> <pre><code>&gt;&gt;&gt; len(my_dictionary) 2 </code></pre> <p>I always assumed that methods like len() weren't actually part of whatever class you called them on given their syntax but after reading chapter 5 of Dive into Python I see that len() actually does result in a dictionary method being called.</p> <pre><code>my_dictionary.__len__() </code></pre> <p>So why isn't it and methods like it called like a typical class method? </p> <pre><code>my_dictionary.len() </code></pre> <p>Is there a convention I'm unaware of? </p>
python
[7]
840,292
840,293
Can two classes access each other?
<p>If I have two classes called A and B,</p> <p><em>Note:</em> The following doesn't compile.</p> <pre><code>class A { public: static void funcA() {} void call_funcB() { B::funcB(); } // call class B's function }; class B { public: static void funcB() {} void call_funcA() { A::funcA(); } // call class A's function }; </code></pre> <p><strong>Errors:</strong></p> <pre><code>error C2653: 'B' : is not a class or namespace name error C3861: 'funcB': identifier not found </code></pre> <p>Can you call the static functions of each class?</p>
c++
[6]
3,945,212
3,945,213
I'm stuck in a Javascript variable incrementing tutorial
<p>This is what it says:</p> <blockquote> <p>You can use an incrementer to make a number increase by one or a decrementer to make it decrease by one. To increase the number, you can use ++ after a variable.</p> <p>Let's make the variable i, in the editor, equal to 2 by incrementing it twice. This should involve two separate lines with i++; on them. Try it out now.</p> <p>Here you can have two separate lines of iteration. Each should contain just i++.</p> </blockquote> <p>I have to modify this code:</p> <pre><code>var i = 0; print( "i is equal to " + i ); </code></pre> <p>I'm not sure if I'm too dumb, but I don't know how to complete this tutorial.</p>
javascript
[3]
5,256,471
5,256,472
jQuery closest() not working
<p>I have an AJAX method that deletes a row from a database from a list of results from the database. Once the row has been successfully deleted, I want jQuery to fade out that row from the page.</p> <p>After clicking on the delete button, the row is successfully deleted from the database, but the list item that is the parent of the button that was clicked does not fade out when searching for it using closest().</p> <p>Here is my DOM:</p> <pre><code>&lt;ul&gt; &lt;li&gt; &lt;div class="two columns alpha"&gt; &lt;/div&gt; &lt;div class="ten columns"&gt; &lt;ul&gt; &lt;li&gt;&lt;p&gt;&lt;/p&gt;&lt;/li&gt; &lt;li&gt;&lt;p&gt;&lt;/p&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div class="admin_buttons"&gt; &lt;div class="two columns"&gt; &lt;button type="submit" class="admin_button edit_event"&gt;Edit&lt;/button&gt; &lt;/div&gt; &lt;div class="two columns omega"&gt; &lt;button type="submit" value="5" class="admin_button delete_event"&gt;Delete&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Here is the jQuery:</p> <pre><code>$(document).on('click', '.delete_event', function() { $.ajax({ type: 'POST', url: 'php/deleteEvent.php', cache: false, data: { id: $(this).val() }, success: function(data) { if(data === 'Error') { alert('Error: event not deleted.'); } else { $(this).closest("li").fadeOut('slow'); } } }); }); </code></pre>
jquery
[5]
2,424,528
2,424,529
Killing an app that fails the License check
<p>I've been implementing the Android market Licensing in my app and it looks like everything works. At present, however, when the chec kfails, I'l displaying a Toast message and calling moveTaskToBack().</p> <p>This is obviously not an acceptable way to close the app, since the user can simply open it again and carry on as before.</p> <p>What would be the best way to actually kill the app after the Toast has displayed?</p>
android
[4]
4,771,881
4,771,882
How can i identify whether iphone is locked or not
<p>How can i identify whether iphone is locked or not. </p> <ul> <li>(void)applicationWillResignActive:(UIApplication *)application fires in all cases that while receiving sms , phone call</li> </ul> <p>But i want to isolate lock event only.</p> <p>Is there any possible to identify lock event alone?</p>
iphone
[8]
1,616,223
1,616,224
Python array indexing
<p>I am writing a code for doing some integration. But I am stuck at some point(the last two lines). As it says Index Error: Index out of bounds. What I would like to do is- each time r has a value it should write to the empty corresponding index as an increment of 1 so that it can keep track of it. Any help would be appreciated. Here is the code-</p> <pre><code>from pylab import* from math import* dx = 981 dy = 1043 bx = 534.4 by = 109.5 index = zeros(shape=(1,dx+dy)) r=0 r_max=0 for i in xrange(1,dy+1): for j in xrange (1,dx+1): if i-by &gt; 0: theta = 180*atan(abs(j-bx)/(i-by))/pi if theta&lt;10: r = round(sqrt((j-bx)**2+(i-by)**2)) if r&gt;0: index[r]+=1 </code></pre>
python
[7]
5,514,590
5,514,591
Implementing Dispose() with class derived from System.ComponentModel.Component
<p>I made a class that derives from Component:</p> <pre><code>public class MyComponent: System.ComponentModel.Component { } </code></pre> <p>I saw that Visual Studio put this code in for me:</p> <pre><code>protected override void Dispose(bool disposing) { try { if (disposing &amp;&amp; (components != null)) { components.Dispose(); } } catch { throw; } finally { base.Dispose(disposing); } } </code></pre> <p><code>MyComponent</code> has a member that is a <code>DataSet</code> and maybe there's some other members that implement <code>IDisposable</code>. What, if anything, do i need to modify with the <code>Dispose()</code> method to make sure things are cleaned up properly? Thanks for helping.</p>
c#
[0]
207,948
207,949
Downcasting using the Static_cast in C++
<pre><code>class base { base(); virtual void func(); } class derived : public base { derived(); void func(); void func_d(); int a; } main { base *b = new base(); sizeof(*b); // gives 4. derived * d = static_cast&lt;derived*&gt;(b); sizeof(*d); // gives 8- means whole derived obj size..why? d-&gt;func_d(); } </code></pre> <p>In the above code i did downcasting of a base pointer which points to base object to derived class pointer. i am wondering how derived pointer has the whole derived class object. i can call the derived class function (declared in derived class only). i did not get the concept here.</p>
c++
[6]
2,059,666
2,059,667
What's window.onunload?
<p>Im a beginner and i see that line of code a lot on javascript files , for example : </p> <pre><code>window.onunload=function(){}; </code></pre> <p>when should i use this and what is it role exactly ? </p> <p>thank you .</p>
javascript
[3]
4,291,118
4,291,119
My Arrray Value is Overwritten in nested foreach loop
<p>I have the following code:</p> <pre><code>foreach ($model_name as $md) { foreach ($years as $y) { $model_w_year[$y] = $md; } } </code></pre> <p>It's obviously not working. The array it outputs looks like like:</p> <pre><code>Array ( [1994] =&gt; Maxima [1995-1998] =&gt; Maxima ) </code></pre> <p>I want it to look like this:</p> <pre><code>Array ( [1994] =&gt; Sentra [1995-1998] =&gt; Maxima ) </code></pre> <p>Model_name is a $_SESSION['model_name'] from previous page and years is a form array</p> <pre><code>echo "&lt;form action='engine.php' method='post'&gt;"; for ($i = 0; $i &lt; count($model_name); $i++) { echo "Enter year or year range for: ", $model_name[$i], " &lt;input type='text' name='years[]'&gt;&lt;/input&gt;&lt;br /&gt;"; } </code></pre> <p>And here are all array structures that I have:</p> <pre><code>Model make: Nissan model name: Array ( [0] =&gt; Sentra [1] =&gt; Maxima ) Number of models: 2 Number of years: Array ( [0] =&gt; 1994 [1] =&gt; 1995-1998 ) Model with Year: Array ( [1994] =&gt; Maxima [1995-1998] =&gt; Maxima ) </code></pre> <p>Answer: yes I want the year to be the key and the model to be the value.</p>
php
[2]
613,636
613,637
How do i fetch a single value from serialize()
<p>I have a form and i fetch the values of form using jQuery <code>.serialize();</code> for example to fetch the form data i use the following.</p> <pre><code>var formData = $('form').serialize(); </code></pre> <p>now the variable formData holds the following value.</p> <pre><code>subcategoryname=aaaa&amp;prefix=AA&amp;categoryid=1 </code></pre> <p>from the above string i want to fetch only the value of <code>categoryid</code> i.e 1 here, how do i do it using jQuery?</p>
jquery
[5]
5,378,622
5,378,623
Why the andoid awesomeplayer was made using struct not class
<p>I found that the native layer of android uses class and struct.</p> <p>For examaple, MediaPlayer, stagefrightplayer, audioplayer, MetaData was class. But awesomeplayer and MediaSource are struct.</p> <p>Although I read that class and struct is similar in use, I wonder why awesomeplayer was created as struct. Is there any reason or just developer's taste?</p>
android
[4]
896,722
896,723
From JavaScript to jQuery
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/836725/what-is-the-best-way-to-learn-jquery">What is the best way to learn jQuery?</a> </p> </blockquote> <p>I notice that most of users here uses jQuery, and I don't know anything about it rather that it's ready packages users reuse it. NOW, I want to increase my knowledge and know more about jQuery. What are some easy and informative toturials? And any other helpful website.</p>
jquery
[5]
4,642,565
4,642,566
What is the difference b/n Session and Application objects?
<p>I know that Session is for a single user , and application is for multi user purpose.The Data in the application object is shared. Right? Then how can access the application data from an another client.</p> <p>if My concept is wrong then what's right?</p>
asp.net
[9]
4,280,095
4,280,096
How to validate a Long data type field in java
<p>I have a Long field in java.I need to test whether this field has a value or not.I am using the following code:</p> <pre><code> Long phone_temp = queryAllPhoneNumbersForContact(contactId); if(phone_temp.equals("")) { System.out.println("Value is null",""+phone_temp); } </code></pre> <p>Long has a null value however when i try to print the value of phone_temp it gives app crashed.How do i check whether phone_temp has a value. </p>
java
[1]
4,432,285
4,432,286
How to extract only 'Day' value from full 'Date' string?
<p>I have an array of Date values in the format of 'Y-m-d'. I want to loop over the array and only extract the 'd' of each member, but can't figure out to split it. Do I use substrings in some way?</p> <p>Put simply, I have '2010-11-24', and I want to get just '24' from that. The problem being the day could be either single or double figures.</p> <p>Thanks in advance.</p>
php
[2]
2,637,463
2,637,464
How to obtain a localized string representation of the weekdays like monday, tuesday, etc.?
<p>How to obtain a localized string representation of the weekdays like monday, tuesday, etc.?</p> <p>Sure I could localize these myself but I bet that I can suck them out from a calendar class or something similar?</p>
iphone
[8]
3,875,096
3,875,097
Open Save DialogBox Window (Desktop application)
<p>Is there any DialogBox in window c# (Desktop Application) which has both save and open button?.</p>
c#
[0]
3,139,529
3,139,530
c# code error The name 'i' does not exist
<p>in line </p> <pre><code> urls[i] = Reader.GetValue(i).ToString(); </code></pre> <p>it say Error 1 The name 'i' does not exist in the current context </p> <p>how can I fix it </p> <pre><code>private void Form1_Load(object sender, EventArgs e) { string MyConString = "SERVER=192.168.0.78;" + "DATABASE=webboard;" + "UID=aimja;" + "PASSWORD=aimjawork;" + "charset=utf8;"; MySqlConnection connection = new MySqlConnection(MyConString); MySqlCommand command = connection.CreateCommand(); MySqlDataReader Reader; command.CommandText = "SELECT url FROM `listweb` WHERE `url` IS NOT NULL AND ( `webbordkind` = '¿¿¿¿¿¿¿¿¿¿¿¿' ) and `nourl`= 'n' order by province, amphore limit 4 "; connection.Open(); Reader = command.ExecuteReader(); string[] urls = new string[2]; string thisrow = ""; string sumthisrow = ""; string urlname ; while (Reader.Read()) { thisrow = ""; for (int i = 0; i &lt; Reader.FieldCount; i++) thisrow += Reader.GetValue(i).ToString(); urlname = Reader.GetValue(i).ToString(); urls[i] = Reader.GetValue(i).ToString(); // System.IO.File.AppendAllText(@"C:\file.txt", thisrow + " " + Environment.NewLine); sumthisrow = sumthisrow + thisrow; </code></pre>
c#
[0]
1,996,800
1,996,801
JQuery: Loading dynamic content into dynamic div
<p>To access a click event of a div that was created dynamically you use something like: </p> <pre><code>$(#divId).on('click', function() { }); </code></pre> <p>What I am trying to do is access that dynamic div itself instead of its event. I want to grab some dynamic data and load it into that div. The problem is the data isn't loading since that div is created dynamically. How do I fix this issue?</p>
jquery
[5]
5,901,792
5,901,793
Javascript Dialog box w/ Multiple Buttons
<p>Is there a type of Javascript dialog box (similar to alert) that offers customizable, multiple buttons (besides "OK") and will return some sort of indication of which button was clicked? I am <em>not</em> looking for a JQuery or third-party dialog/modal box, I'm just wondering if there's something already built into Javascript. As far as I've researched, Javascript only offers alert(), confirm(), and prompt().</p> <p>Thanks!</p>
javascript
[3]
1,974,690
1,974,691
PHP Converting a date to timestamp using DateTime decreases 1 day - weird
<p>Have the following simple PHP code:</p> <pre><code>$day = '2013-05-04'; $disp_day = DateTime::createFromFormat('U', strtotime($day)); echo $day . " " . $disp_day-&gt;format('F j'); </code></pre> <p>It outputs </p> <pre><code>2013-05-04 May 3 </code></pre> <p>But <code>$disp_date</code> should be May 4 right?</p>
php
[2]
3,823,432
3,823,433
Javascript: How can I use a variable name when updating a form value?
<p>Here is part of the function:</p> <pre><code>function updateResponse(question, answer) { questionId = 'q'+question; document.forms[0].questionId.value = answer; </code></pre> <p>Calling the function with something like:</p> <pre><code>&lt;td onClick='javascript:updateResponse(1, 1);'&gt; </code></pre> <p>The form element I want it to update looks something like:</p> <pre><code>&lt;input type='hidden' name='q1' value='' /&gt; </code></pre> <p>Using Firefox web console I get:</p> <pre><code>TypeError: document.forms[0].questionId is undefined </code></pre> <p>Thanks!</p> <p>UPDATE: Found this after much googling and it works. Still seems like there may be a more graceful way to achieve this though?</p> <pre><code>eval(\"document.forms[0].\"+questionId+\".value = answer;\"); </code></pre>
javascript
[3]