Unnamed: 0
int64
65
6.03M
Id
int64
66
6.03M
Title
stringlengths
10
191
input
stringlengths
23
4.18k
output
stringclasses
10 values
Tag_Number
stringclasses
10 values
1,450,489
1,450,490
Inside function variables to be used in includes in PHP
<p>I have a function that includes another file like so</p> <pre><code>// some function function SomeFunction() { $someData = 'SomeData'; include_once('some_file.php'); } // some_file.php &lt;?php echo $someData; ?&gt; </code></pre> <p>How would I get this to work where the include file can use the variables from the calling function? I will be using some output buffering.</p>
php
[2]
1,420,038
1,420,039
commands.getoutput() raises Errno 12 - Cannot allocate memory
<p>I have a Python script which runs on a server with RHEL5. The server has 32GB memory and 8 Intel Xeon CPUs at 2.83GHz. I think the hardware resource should not be a problem, but when I attempt to upload and process a 15 million line text file, the program gives me an error message:</p> <pre><code>Traceback (most recent call last): File "./test.py", line 511, in &lt;module&gt; startup() File "./test.py", line 249, in startup cmdoutput = commands.getoutput(cmd_file) File "/usr/local/lib/python2.6/commands.py", line 46, in getoutput return getstatusoutput(cmd)[1] File "/usr/local/lib/python2.6/commands.py", line 55, in getstatusoutput pipe = os.popen('{ ' + cmd + '; } 2&gt;&amp;1', 'r') OSError: [Errno 12] Cannot allocate memory </code></pre> <p>I have investigated this problem and did not found any answers that exactly match my problem. Those answers were focused on the "popen" subroutine, but I do not use this routine. I just use the "<code>commands.getoutput()</code>" to display the file type of a document.</p> <p>It should be noted that if I try to process a 10 million line text, this problem does not happen. It only happens when the text file is large. Can any people help me out on this issue? The answer could be a better module other than the "<code>command.getoutput()</code>". Thanks!</p>
python
[7]
4,631,293
4,631,294
I want to print the value in sales
<p>I want to print the value of the amount of sales entered by user times .10. My first issue is I want to store a value that a user enters into sales then times that by .10 then print the value of sales. We I run the program I get two lines one is the amount of sales entered the other is .5. </p> <pre><code> const double COMMRATE = 0.10; string inputstring; double sales =5; char response; Console.Write("Do you want to Calculate Sales A or B or E..."); inputstring = Console.ReadLine(); response = Convert.ToChar(inputstring); while (response == 'A') { Console.WriteLine("Enter Sales", sales.ToString("C")); sales = sales * COMMRATE; inputstring = Console.ReadLine(); response = Convert.ToChar(inputstring); } </code></pre>
c#
[0]
4,032,141
4,032,142
Easy: Addclass removeClass hasClass issue?
<p>I have some buttons in a container div that need to toggle active but only 1 active button at a time. </p> <p>EDIT:</p> <p>html is: div container of .filter(btn, btn, btn, etc) there are 3 containers of buttons. The third container has a button with an id of: #filter1-none</p> <p>The code below works to have only 1 button active per group. </p> <p>Additionally, how would I remove active only from the button with an ID of #filter1-none ONLY if any of the other buttons are active?</p> <pre><code>$('.filter .btn').click(function () { $(this).addClass('active').siblings('.active').removeClass('active'); }); </code></pre>
jquery
[5]
4,911,761
4,911,762
Java: How many times is arr.length called in a for-loop?
<p>If <code>arr</code> is an array of size 10, in the following code block, how many times is <code>arr.length</code> accessed?</p> <pre><code>for (int i = 0; i &lt; arr.length; ++i); </code></pre> <p>Once? Or every time it loops?</p> <p>Thanks everyone! Here's what I ended up doing:</p> <pre><code>final int len = arr.length; for (int i = 0; i &lt; len; ++i); </code></pre>
java
[1]
4,063,588
4,063,589
group list of ints by continuous sequence
<p>I have a list of integers...</p> <pre><code>[1,2,3,4,5,8,9,10,11,200,201,202] </code></pre> <p>I would like to group them into a list of lists where each sublist contains integers whose sequence has not been broken. Like this...</p> <pre><code>[[1,5],[8,11],[200,202]] </code></pre> <p>I have a rather clunky work around...</p> <pre><code>lSequenceOfNum = [1,2,3,4,5,8,9,10,11,200,201,202] lGrouped = [] start = 0 for x in range(0,len(lSequenceOfNum)): if x != len(lSequenceOfNum)-1: if(lSequenceOfNum[x+1] - lSequenceOfNum[x]) &gt; 1: lGrouped.append([lSequenceOfNum[start],lSequenceOfNum[x]]) start = x+1 else: lGrouped.append([lSequenceOfNum[start],lSequenceOfNum[x]]) print lGrouped </code></pre> <p>It is the best I could do. Is there a more "pythonic" way to do this? Thanks..</p>
python
[7]
1,689,223
1,689,224
Javascript: performance of var functionName = function() {} vs function functionName() {}
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/80802/does-use-of-anonymous-functions-affect-performance">Does use of anonymous functions affect performance?</a> </p> </blockquote> <p>What are performance implications (if any) on parse and run-time when using function expression vs declaration in Javascript? </p> <p>For example, what are performance characteristics and differences of the following two ways:</p> <pre><code>var functionOne = function() { // Some code } </code></pre> <p>or:</p> <pre><code>function functionTwo() { // Some code } </code></pre> <p>NOTE: The question is not about whether it is faster to declare function but about function execution. </p>
javascript
[3]
5,666,325
5,666,326
jQuery load method not working
<p>This is not loading page where is the error ? ,this is using jquery version 1.9.1 ,the page <code>http://localhost/ReportsSec/MapNavigation.aspx</code> contains google maps api the error given below:</p> <p>Refresh the page to see messages that may have occurred before the F12 tools were opened. SCRIPT5009: 'google' is undefined Default.aspx, line 116 character 1 SCRIPT257: Could not complete the operation due to error 80020101. jquery-1.9.1.js, line 602 character 4</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="js/jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { $("button").click(function () { $("#div1").load("http://localhost/ReportsSec/MapNavigation.aspx"); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="div1" style="width:450px;height:450px"&gt;&lt;/div&gt; &lt;button&gt;Get External Content&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
jquery
[5]
1,995,390
1,995,391
Only seeing results from last .each() iteration in jQuery
<p>I'm trying to iterate through some stuff in a JSON file and I'm having trouble getting the each() to do what I want. Here's what I have:</p> <pre><code>$.each(response.data.items, function(i,data) { var id=data.id; var results="&lt;div&gt;&lt;iframe width='320' height = '190' src='http://www.example.com/"+id+"' frameborder='0' type='text/html'&gt;&lt;/iframe&gt;&lt;/div&gt;"; $("#resultsOut").html(results); }); </code></pre> <p>Right now, the only HTML that is being output is</p> <pre><code>&lt;div&gt;&lt;iframe width='320' height = '190' src='http://www.example.com/"+id+"' frameborder='0' type='text/html'&gt;&lt;/iframe&gt;&lt;/div&gt; </code></pre> <p>where id is the last id that occurs in the JSON. How do I change this so that instead I see that HTML block once for every id that occurs?</p>
jquery
[5]
3,494,340
3,494,341
Reference of 2.0 DLL in 3.5 client Profile C# project
<p>I have C# DLL created using frameowrk 2.0 this DLL I have added as a reference in another C# project created using #.5 client profile framework. AFter adding reference and build the code I got warning saying reference could not be reolved as the referenced DLL has reference to system.web of versiob 2.0. If I add reference of system.web in 2.0 DLL and build and use this DLL as reference warning is removed.</p> <p>So I would like is it not possible to reference 2.0 DLL in 3.5 client profile project? Adding system.web as a refernce increasing external DLL dependency so i am looking for solution which would remove this dependency.</p> <p>Thanks </p>
c#
[0]
4,867,727
4,867,728
echo two fields data subtracted from each other in php
<pre><code>echo "&lt;&lt;td&gt;td&gt;".$rec["year1"] * $rec["year2"]."&lt;&lt;/td&gt;/td&gt;"; </code></pre> <p>Now this works. But when I replace '*' with a '-' (minus) it doesn't work and gives the list of 4rec["id"] values with minus symbol infront. (ie. -10-12-14 etc;)</p> <p>Please help. Thanks</p>
php
[2]
4,564,590
4,564,591
jQuery - IF then Remove class on .hover
<p>I have the following jQuery function:</p> <pre><code>$(function(){ if ($(".menu li").hasClass("active")) { $(".active").css("margin-top", "6px"); } }); </code></pre> <p>This is applied to a CSS/jQuery menu, which expands and contracts when each menu item is hovered over. The onClick event adds a <code>margin-top of 6px</code> to give the impressions of a button depress. </p> <p>I'm then using PHP to detect which page the user is visiting to add an <code>.active</code> class to the relevant menu item.</p> <p>The question, the .active class should remain in place <strong>until</strong> the user hovers over a different menu item. At which point the <code>.active</code> class should be removed from this element - As the <code>.active</code> class is reused on the <code>.hover</code> events.</p> <p>Here is the basic HTML Markup:</p> <pre><code>&lt;ul id="menu"&gt; &lt;li&gt; &lt;div class="inner"&gt; &lt;div class="button"&gt;&lt;img src="images/insightbutton.png" /&gt;&lt;/div&gt; &lt;div class="description"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;li&gt; &lt;div class="inner"&gt; &lt;div class="button"&gt;&lt;img src="images/insightbutton.png" /&gt;&lt;/div&gt; &lt;div class="description"&gt;&amp;nbsp;&lt;/div&gt; &lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>How can I keep the .active class applied to the active menu item, but remove it when .inner is hovered over?</p>
jquery
[5]
4,139,370
4,139,371
Handling events in .ASPX file not in .CS
<p>I have a problem that how can i handle control's events in .ASPX file. For example if there is server Button control then my requirement is how to handle its click event in .ASPX file. I have compulsion to not use .cs file so there is no code behind file. Any help is appreciated. </p>
asp.net
[9]
1,178,739
1,178,740
strange HtmlElement error
<p>I am using HtmlElement in .net framework to parser a webpage, first I find an element in the page, let's name it as x HtmlElement, then I tried to run some code and check the return.</p> <p>strange things happened:</p> <pre><code>x.TagName return "SPAN" x.Parent.Children.Count return 1 x.Parent.Children[0].TagName return "DIV" </code></pre> <p>while I think the third line should return "SPAN" cause x is the only one element in it's parent element, does any one know the reason? is this a bug of .net framework?</p> <p>my vs is 2008 and the webpage url is: <a href="http://zu.sz.soufun.com/house-a085/" rel="nofollow">http://zu.sz.soufun.com/house-a085/</a> I got my x element through one of the links in the list, let's say it's a A element named y, and then I set x=y.Parent.Parent.Parent.Parent.Parent.Parent;</p> <p>if this is not clear, please let me know and I will explain more</p> <p>note the content is not in English, </p>
c#
[0]
3,831,618
3,831,619
How do I fully integrate jQuery into SharePoint 2010
<p>Hi I'm a bit of a newby to Sharepoint!</p> <p>I have created a masterpage based on nightandday and added some jQuery code that successfully does some simple link hiding/revealing as part of a menu structure and everything works fine for me. However, when a 'read restricted' user logs in, the jQuery doesn't work - in fact, when looking at the page source in the browser, the code that links the jquery.min.js file is not present and the $(document).ready(function() { etc.. code is also absent.</p> <p>They are both definitely using the same masterpage as the link for my custom css is present in both.</p> <p>I'd be hugely greatful if anyone has any ideas as to what I need to do to correct this ?</p> <p>Rab</p>
jquery
[5]
3,054,941
3,054,942
.height() adding decimal points to value
<p>I have this function, which works as it needs to (I think it's pretty self explanatory). However, the outputted value is 473.4615384340286. I don't want all the .decimal points. I'd like to actually round up. The <code>.height()</code> of <code>#campaign-header</code>is 475px.</p> <p>What's up with the decimals?</p> <pre><code>// add billboard height value to modal input var inputBillboard = $('#campaign-header').height(); $('.billboard-height').val(inputBillboard); </code></pre>
jquery
[5]
197,607
197,608
Check for an anchor
<p>I would like to check if the current page has an anchor</p> <p>so I am using this</p> <pre><code>var qs = window.location.hash; </code></pre> <p>then checking if qs is not an empty string</p> <pre><code>if (qs !== '') { </code></pre> <p>Is this the correct way to do that? It seems to work, but I am confusing myself reading about JavaScript's various ways to check for null/undefined/empty string.</p>
javascript
[3]
279,889
279,890
Javascript, AJAX, Extend PHP Session Timeout, Bank Timeout
<p>Greetings,</p> <p>I have the following JS code:</p> <pre><code>var reloadTimer = function (options) { var seconds = options.seconds || 0, logoutURL = options.logoutURL, message = options.message; this.start = function () { setTimeout(function (){ if ( confirm(message) ) { // RESET TIMER HERE $.get("renewSession.php"); } else { window.location.href = logoutURL; } }, seconds * 1000); } return this; }; </code></pre> <p>And I would like to have the timer reset where I have the comment for RESET TIMER HERE. I have tried a few different things to no avail. Also the code calling this block is the following:</p> <pre><code>var timer = reloadTimer({ seconds:20, logoutURL: 'logout.php', message:'Do you want to stay logged in?'}); timer.start(); </code></pre> <p>The code may look familiar as I found it on SO :-)</p> <p>Thanks!</p>
javascript
[3]
4,149,454
4,149,455
Simple arithmetic in PHP
<p>Here is a simple php program which gives a strange output. Can anyone explain why it is coming like this and how to get the expected output?</p> <pre><code>&lt;?php $a=2;$b=3; echo "&lt;br&gt; ADD:".$a+$b; echo "&lt;br&gt; SUB:".$a-$b; echo "&lt;br&gt; MUL:".$a*$b; echo "&lt;br&gt; DIV:".$a/$b; ?&gt; </code></pre> <p>Output:</p> <pre><code>3-3 MUL:6 DIV:0.66666666666667 </code></pre> <p>Expected Output:</p> <pre><code>ADD:5 SUB:-1 MUL:6 DIV:0.66666666666667 </code></pre>
php
[2]
4,448,005
4,448,006
jquery: bind "click" event
<p>in my bind "click" event, i would like to chop the last character off a given string incrementally. however, each time i click it, it seems to stop after the first chomp.</p> <pre><code>var somestring = "mary had a little lamb"; $("#removelaststring").unbind("click").bind("click",function(e){ alert(somestring.slice(0,-1)) }); </code></pre> <p>it should return "one less character" each time it's clicked</p>
jquery
[5]
2,553,801
2,553,802
Weird variable behaviour PHP
<p>This little piece of code isn't behaving as I would expect it to:</p> <pre><code>$flash_messages = $_SESSION['flash']; $_SESSION['flash'] = array(); return $flash_messages; </code></pre> <p>I am wanting <code>$flash_messages</code> to have the saved values of the <code>$_SESSION</code> variable. But when I change the <code>$_SESSION</code> to a blank array, flash messages is also returned as a blank array. What is going on?</p>
php
[2]
3,138,852
3,138,853
JQuery Applying CSS to Inner DIV
<p>I am trying to apply a style to the inner div which is contained in the parent div. The parent div also contains tons of other div but I just want to apply the color to the [0] div. </p> <pre><code>$("#parentDiv div")[0].css('background-color', 'red'); </code></pre> <p>For some reason it says "css function is not defined!" </p>
jquery
[5]
3,096,187
3,096,188
invalid initialization of non-const reference when returning an array element
<p>I'm writing a class that wraps a dynamically allocated array and I'm trying to write the operator[] function. Currently I have:</p> <pre><code>bool&amp; solution::operator[](unsigned int pos) { if(pos &lt; _size) { return this-&gt;_data[pos]; } else { return false; } } </code></pre> <p>But I get the following error from g++:</p> <p><code>error: invalid initialization of non-const reference of type ‘bool&amp;’ from an rvalue of type ‘bool’</code></p> <p>How should I be doing this? I need the [] operator to be able to modify elements.</p>
c++
[6]
3,072,069
3,072,070
passing string to event listener giving NULL
<p>I have the following piece of code. The string is being sent to <code>uploadFile</code> correctly but the line <code>alert(str)</code> is giving me <code>undefined</code>?</p> <pre><code>function uploadFile(str){ alert(str); //prints correctly var fileTag = document.getElementById('fileinput'); var file = fileTag.files[0]; var xmlhttp=new XMLHttpRequest(); var formData = new FormData(); formData.append("thefile", file); xmlhttp.addEventListener("load", function(evt,str){ alert(str); //undefined }, false); .... } </code></pre> <p>I'm fairly new to javascript, so can anyone tell me why this is happening? thank you</p>
javascript
[3]
2,630,680
2,630,681
Calculating the number of holidays between a date range in C#
<p>I would like to know how to calculate the number of holidays between a date range in C#.</p> <p>Example :Date Range 1st jan 2012 to 1st Feb 2012</p> <pre><code> conditions: holiday1=&gt;From Date (30th Dec 2011 to 2nd jan 2012) holiday2 =&gt;From Date(16th jan 2012 to 18 th jan 2012) holiday3=&gt;From Date(30the jan 2012 to 2nd Feb 2012) </code></pre> <p>Here as first holidays is till 2nd jan I need to calculate 2 days for holiday1 as well as 2 days for holidays 3 and for holidays 2nd that's not a problem for me to calculate.</p>
c#
[0]
3,916,978
3,916,979
what are the Steps for uploading iPhone application to apple store...?
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/308290/procedure-to-submit-iphone-application-to-app-store">Procedure to submit iPhone application to App Store?</a> </p> </blockquote> <p>what are the Steps for uploading iPhone application to apple store...?</p>
iphone
[8]
1,291,063
1,291,064
What is the best book for learning object oriented javascript?
<p>I'm a pro when it comes to HTML/CSS, and can use jQuery pretty well to move things around on my sites, but I need a good book for a NON PROGRAMMING person to learn OO JS. I just can't grasp it. I need a good book for learning! Thanks :)</p>
javascript
[3]
5,955,160
5,955,161
Java and using method addAll for List<Character>
<p>I have something simple, but can't solve. I just want to add one list of chars to another . It's working with <code>String</code> types. Why does it not work with <code>char</code>? </p> <pre><code>Character [] myChar={'a', 's', 'd','f', 't', 'i'}; List&lt;Character&gt; listChar= Arrays.asList(myChar); Character[] newChar= new Character[listChar.size()]; List&lt;Character&gt; newlistChar= Arrays.asList(newChar); Collections.fill(newlistChar, 'd'); output(newlistChar,"filled d"); Collections.addAll(listChar,newlistChar); // does not work </code></pre> <p>I tried to do something like casting the list, but still got an exception. </p> <pre><code> ...((String)(listChar),(String)(newlistChar)) </code></pre> <p>Even if I use something like this it still throws and exception. So how do I use addAll with <code>char</code>?</p> <pre><code>Collections.addAll(listChar,newlistChar.toArray(new Character[newlistChar.size()])); </code></pre>
java
[1]
2,634,875
2,634,876
Array class property
<p>This code gives the error "unexpected '.', expecting ')'". Why is this invalid? I'd thought that as both parts are constant, I could concatenate them. New to PHP. Thanks.</p> <pre><code>class c { const HELLO = 'hello'; public $arr = array( 'hw' =&gt; self::HELLO . 'world' ); } </code></pre>
php
[2]
97,284
97,285
convert small mootools script to jquery
<p>Can i use this Script for jquery? </p> <pre><code>window.addEvent('domready', function() { var myAccordion = new Accordion($('maincol'), 'h2.contentheader', 'div.content', { opacity:true, display: -1, duration: 300, alwaysHide: true, onActive: function(contentheader, content){ contentheader.setStyle('font-weight', 'bold'); }, onBackground: function(contentheader, content){ contentheader.setStyle('font-weight', 'bold'); } }); }); </code></pre> <p>I wanted this in jQuery as I don't want to load 2 libraries just for this bit of script. I am actually very new to programming and still in the learning stage. Hence looking forward for some help on this issue.</p>
jquery
[5]
3,844,778
3,844,779
how to use cellValueChanged event in datadrid view to use filter function?
<p>I write a function to filter datagridview(dgv) </p> <pre><code>void filterDataGridView(DataGridView dgv, string columnName, string filterValue) { foreach (DataGridViewRow row in dgv.Rows) { if (row.Cells[columnName].Value.ToString().Contains(filterValue)) { row.Visible = true; } else row.Visible = false; } } </code></pre> <p>I have 2 dgv with same column!<br> . one of them is for searching in the secend dgv.<br> I write this function for dgv1.<br> first dgv has one row to write string in each column secend dgv contains data for searching.</p> <p>please help me how can i use firs dgv ?-->(in each cell of dgv1 i write a string ,in dgv2 it be filter) how can i do that ? how can i set properties og dgv1 and what event will be helpful and how can i use it</p> <p>thanks :)</p>
c#
[0]
3,002,462
3,002,463
Want to change this format $1,000,000 to 1000000 this
<p>Well i have calculator. In which i want to accept value in this <code>$1,000,000</code> format</p> <p>so below are my codes want to know how to replace them using php</p> <p>Live: <a href="http://ffsng.deewayz.in/index.php?v=1000000&amp;sv=1951153458" rel="nofollow">http://ffsng.deewayz.in/index.php?v=1000000&amp;sv=1951153458</a></p> <p>I just want to know code to replace them with php this <code>$1,000,000</code> to this <code>1000000</code> and also if float can accept this value or have to change float to some other.</p> <p>My HTML</p> <pre><code>Enter Present Value of Pet: &lt;input type="text" name="v" value="1000000"/&gt;&lt;br&gt; Enter value of pet you want: &lt;input type="text" name="sv" value="1951153458"/&gt;&lt;br&gt; </code></pre> <p>My PHP</p> <pre><code>$v = isset($_GET['v']) ? (float) $_GET['v'] : 1000000; $sv = isset($_GET['sv']) ? (float) $_GET['sv'] : 1951153458; </code></pre> <p>Thanks</p>
php
[2]
3,854,197
3,854,198
Android EditText not respecting size settings
<p>I'm trying to get my EditText field to not be as tall but to no avail. Is there some way to get the text field (the white part around the text) to take up less vertical space? paddingTop and paddingBottom and maxHeight and height all appear to be ignored. Do I need to replace it with my own drawable background for it to do what I want (is that even an option)?</p> <p>[EDIT] So, for example in the code below I'm interested in the field being 10dip tall.</p> <pre><code>&lt;EditText android:id="@+id/frame0" android:width="100dip" android:singleLine="true" android:inputType="phone" android:maxLength="4" android:textStyle="bold" android:paddingLeft="10dip" android:paddingRight="10dip" android:textSize="8dip" android:height="10dip" android:maxHeight="10dip" android:paddingTop="0dip" android:paddingBottom="0dip" android:gravity="center" android:layout_gravity="center" /&gt; </code></pre> <p>[EDIT 2]</p> <p>It would appear that a partial solution is to just scrap the style of the background and use one's own...</p> <pre><code>style="?android:attr/textViewStyle" android:background="@null" android:textColor="@null" </code></pre> <p>Basically you get a clickable TextView that you can edit. But this doesn't strike me as the most elegant solution, so, I'm still hoping someone will chime in with my simply overlooking something obvious.</p>
android
[4]
188,983
188,984
multiple preg_replace on the same variable
<p>While delving into some old code I've stumbled upon a function which is used to clean up special characters using <a href="http://de3.php.net/manual/en/function.preg-replace.php" rel="nofollow"><code>preg_replace</code></a> very excessively. Unfortunatly there's no way to avoid this cleanup, the messed up data arrive from outside.</p> <pre><code>/* Example 1: current code */ $item = preg_replace('/' . chr(196) . '/',chr(142),$item); $item = preg_replace('/' . chr(214) . '/',chr(153),$item); $item = preg_replace('/' . chr(220) . '/',chr(154),$item); </code></pre> <p>Alot of those lines are in there, and all do the same (using different characters), so there should be a better way to do this. My first iteration to optimize this would be to use an indexed array, like this:</p> <pre><code>/* Example 2: slightly optimized code */ $patterns = array(); $patterns[0] = '/'.chr(196).'/'; $patterns[1] = '/'.chr(214).'/'; $patterns[2] = '/'.chr(220).'/'; $reps = array(); $reps[0] = chr(142); $reps[1] = chr(153); $reps[2] = chr(154); $item = preg_replace($patterns,$reps,$item); </code></pre> <p><em>It does the job</em>, but I guess there's somewhere a better and/or faster way of doing this alot easier and smarter - maybe even without preg_replace. Due to the early morning and/or the lack of good coffee, I was unable to find it myself so far.</p> <p>Any suggestions?</p>
php
[2]
1,466,479
1,466,480
Activity does not finish even after using return statement or finish call
<p>Following is an onclick method called when a button is clicked. But the code doesn't stop my application. It sends a message and then closes and then restarts again.. I have read the lifecycle model of an activity and fyi this is a single activity application. I also researched on stackoverflow, many of the post describing to have a return statement after finish() call so i have done that too but no results.</p> <p>Where am i going wrong ???</p> <pre><code>public void onClick(View v) { String text = "Demo Message"; String number = &lt;set via a particular code&gt;; if(number.equals("")) { Toast.makeText(this, "Please Enter or Select a Number", Toast.LENGTH_SHORT).show(); } else { sms = SmsManager.getDefault(); PendingIntent sentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0); sms.sendTextMessage(number, null, text, sentIntent, null); Toast.makeText(this, "Message Sent to : " + number, Toast.LENGTH_SHORT).show(); // Stop the Activity... finish(); return; } } </code></pre>
android
[4]
4,313,149
4,313,150
Using directive best practice
<p>Is there <em>any</em> functional or optimization difference between the following?</p> <pre><code>// SomeClass.cpp #include "SomeClass.h" #include "SomeOtherClassInSomeClassNamespace.h" using namespace SomeClassNamespace; SomeClass::SomeClass() {} void SomeClass::SomeFunc() { // uses some stuff in SomeClassNamespace not defined in SomeClass.h } </code></pre> <p>or</p> <pre><code>// SomeClass.cpp #include "SomeClass.h" #include "SomeOtherClassInSomeClassNamespace.h" namespace SomeClassNamespace { SomeClass::SomeClass() {} void SomeClass::SomeFunc() { // uses some stuff in SomeClassNamespace not defined in SomeClass.h } } </code></pre>
c++
[6]
4,365,551
4,365,552
using resource files in asp.net
<p>I have a folder in asp.net 4.0 application with local resource files for different cultures. These resource files have name/value pairs. I want to use these name/value pairs in asp.net page. how can i use it.</p> <p>Regards, Asif Hameed</p>
asp.net
[9]
1,023,097
1,023,098
Allowing Members to give rep points once in a day
<p>I am new to PHP and don't have much knowledge so that's why I'm asking here. My problem is that the following code allows my site members to give points to other members, but it only allows it one time, so I want it to give points once per day. What things do I need to make it possible?<br> Here is the code:</p> <pre><code>// users can not give 2 x points $repeat = mysql_query("SELECT userid FROM {$TABLE_PREFIX}reputation WHERE userid ='$id' AND whoadded=".$CURUSER["uid"]); if( mysql_num_rows( $repeat) &gt; 0 ) { stderr("Hold On","You already gave reputation points to this user!"); stdfoot(); exit; } </code></pre> <p>Any help will be highly appreciated.</p>
php
[2]
5,739,944
5,739,945
Dynamic keyboard capture for bank accounts
<p>I want to create a jquery for capturing an input box and write it in bank format. I mean:</p> <p>A Spanish bank format is like follows:</p> <p><strong>0000 - 0000 - 00 - 0000000000</strong></p> <p>4 digits, 4 more digits, 2 digits, and finally 10 digits.</p> <p>I want to create or find a jquery that, when you introduce the numbers, it puts the <strong>-</strong> dynamically while typing the numbers on your keyboards.</p> <p>Does anybody know any jquery that does that?</p>
jquery
[5]
5,517,050
5,517,051
Is String.replace implementation really efficient?
<p>I used to think that String.replace is faster than String.replaceAll because the latter uses Pattern regex and the former does not. But in fact there is no significant difference either in performance or implementation. This is it:</p> <pre><code>public String replace(CharSequence target, CharSequence replacement) { return Pattern.compile(target.toString(), Pattern.LITERAL).matcher( this).replaceAll(Matcher.quoteReplacement(replacement.toString())); } </code></pre> <p>What's the need to use Pattern here? I wrote a non-regex replace version</p> <pre><code>static String replace(String s, String target, String replacement) { StringBuilder sb = new StringBuilder(s); for (int i = 0; (i = sb.indexOf(target, i)) != -1; i += replacement.length()) { sb.replace(i, i + target.length(), replacement); } return sb.toString(); } </code></pre> <p>and compared performance</p> <pre><code> public static void main(String args[]) throws Exception { String s1 = "11112233211"; for (;;) { long t0 = System.currentTimeMillis(); for (int i = 0; i &lt; 1000000; i++) { // String s2 = s1.replace("11", "xxx"); String s2 = replace(s1, "11", "22"); } System.out.println(System.currentTimeMillis() - t0); } } </code></pre> <p>Benchmarks: my version - <code>400ms</code>; JDK version - <code>1700ms</code>. </p> <p>Is my test wrong or is String.replace really inefficient?</p>
java
[1]
5,043,296
5,043,297
What is the point of the symlink to com.apple.PeoplePicker.plist?
<p>Any Xcode project I create from scratch always contain either a sym link to the com.apple.AddressBook.plist file or to com.apple.PeoplePicker.plist in the folder:</p> <blockquote> <p>Application Support/iPhone Simulator/(SDK Version)/Applications/(GUID)/Library/Preferences</p> </blockquote> <p>Anyone know why this is and how do I go about the app never creating this?</p> <p>It seems to get created after I run the app in the simulator and always comes back no matter what I do.</p> <p>What purpose does this link serve?</p>
iphone
[8]
6,020,031
6,020,032
Exporting an image on the browser to xls or pdf
<p>I'm using MS Chart Control to generate reports as png files. How do I now make it possible for the user to click a button and download the report as xls or pdf?</p> <p>ie. i have a png file on the client, is there any way to send this to the server to convert?</p> <p>(ms chart control can only export to image or xml on the server side)</p>
asp.net
[9]
4,895,315
4,895,316
PayPal GetVerifiedStatus PHP
<p>I was wondering if someone could point me in the right direction to some samples about how to integrate the PayPal GetVerifiedStatus using PHP? I am new to the PayPal API and couldnt find any code samples anywhere.</p> <p>Thanks!</p>
php
[2]
934,472
934,473
Making a Function-Activated Link Appear Without Having to Refresh Browser
<p>I'm trying to use the code below to make the <code>&lt;a href='http://www...com/.../footervote.php'&gt;Vote&lt;/a&gt;</code> link appear if a user logs in and a user shows up in the function <code>getEditorsList()</code>. The vote link only appears if the browser is refreshed. </p> <p>Any idea how I could make the vote link appear without having to refresh the browser?</p> <p>Thanks in advance,</p> <p>John</p> <p>index.php:</p> <pre><code>&lt;?php require_once "header.php"; //content include "login.php"; // more content require_once "footer.php"; ?&gt; </code></pre> <p>In header.php:</p> <pre><code>&lt;?php error_reporting(0); session_start(); require_once ('db_connect.inc.php'); require_once ("function.inc.php"); $seed="0dAfghRqSTgx"; $domain = "...com"; $editors = getEditorsList(); foreach($editors as $editor) { $editorids[] = $editor['loginid']; } if(in_array($_SESSION['loginid'], $editorids)) { echo "&lt;div class='footervote'&gt;&lt;a href='http://www...com/.../footervote.php'&gt;Vote&lt;/a&gt;&lt;/div&gt;"; } ?&gt; </code></pre> <p>login.php:</p> <pre><code>&lt;?php if (!isLoggedIn()) { if (isset($_POST['cmdlogin'])) { if (checkLogin($_POST['username'], $_POST['password'])) { show_userbox(); } else { echo "Incorrect Login information !"; show_loginform(); } } else { show_loginform(); } } else { show_userbox(); } ?&gt; </code></pre>
php
[2]
3,831,000
3,831,001
Id for setInterval. How does it work?
<p>Suppose I have an array that stores all my ids used for <code>setInterval</code>.</p> <p>What if I want to create an id, dynamically... can I do like this?</p> <pre><code>id_array.push(++id_var) = setInterval(function, milliseconds); </code></pre> <p>See?</p> <p>I also have a variable, called 'id_var', that I believe, if I increment it, it will give me, a new 'id'.</p> <p>Is this code correct?</p>
javascript
[3]
3,857,367
3,857,368
HttpHandler - Process Request method in Page Life Cycle
<p>when i type the URL and press enter, request is send to server. As we know that the Web Page inherits IHttpHandler. So when requesting the page, the Httphandler gets called.</p> <p>I heard the above statement from somebody. I know very well about the page life cycle events. But I am not sure about the HttpHandler involvement during Page Life Cycle.</p> <p>I searched a lot on Google but could not found out any link. Any Ideas/Links/Tutorials will be very helpful.</p>
asp.net
[9]
526,079
526,080
Experiencing an issue with my while loop
<p>I would like some advice on where I am going wrong here. The console application displays menu choices and asks the user to enter a valid menu option. </p> <p>Now it's meant to work so that if the number entered is 1, 2 or 3, it says 'You have chosen option x' then 'Press any key to close' but the program doesn't display the 'You have chosen option x' then 'Press any key to close'. It works though if the number is less than 1 or above 3, saying 'Menu choice not between 1-3' then 'Please re-enter'. Where am I going wrong? </p> <p>I haven't been doing programming for very long and if I can correct my error this time, I know for the future.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _4._6 { class Program { static void Main(string[] args) { int iChoice = 0; Console.WriteLine("1: Add two numbers"); Console.WriteLine("2: Multiply two numbers"); Console.WriteLine("3: Exit the program"); Console.WriteLine("Enter your choice: "); iChoice = Convert.ToInt32(Console.ReadLine()); while (iChoice &lt; 1 || iChoice &gt; 3) { Console.WriteLine("Menu choice not between 1-3: "); Console.Write("Please re-enter: "); iChoice = Convert.ToInt32(Console.ReadLine()); Console.ReadKey(); if (iChoice &gt; 1 || iChoice &lt; 3) { Console.WriteLine("You have chosen option " + iChoice); iChoice = Convert.ToInt32(Console.ReadLine()); Console.ReadKey(); } } } } </code></pre> <p>}</p>
c#
[0]
1,472,958
1,472,959
How to create a dynamic object in C#
<p>I use this to create a dynamic object in Visual Basic before sending it as an JSON</p> <pre><code>Dim my_object = New With { _ .Name = String.Empry, _ .Telephone = String.Empry, _ .ID = String.Empry } </code></pre> <p>How can this be done in C#?</p>
c#
[0]
3,308,313
3,308,314
Prog error: for replacing spaces with "%20"
<p>below is the prog i am compiling for replacing spaces with "%20" but when I run it output window shows blank and a message "arrays5.exe has occurred a prob"</p> <pre><code>#include &lt;iostream&gt; #include&lt;cstring&gt; using namespace std; void method(char str[], int len) //replaces spaces with "%20" { int spaces, newlen,i; for (i=0;i&lt;len;i++) if(str[i]==' ') spaces++; newlen=len+spaces*2; str[newlen]=0; for (i=len-1;i&gt;=0;i--) { if(str[i]==' ') { str[newlen-1]='0'; str[newlen-2]='2'; str[newlen-3]='%'; newlen=newlen-3; } else { str[newlen-1]=str[i]; newlen=newlen-1; } } } int main() { char str[20]="sa h "; method(str,5); cout &lt;&lt;str&lt;&lt;endl; return 0; } </code></pre> <p>Please help me finding the error.Thanks</p>
c++
[6]
4,142,511
4,142,512
jquery checked checkbox IE problem
<p>I'm having an issue verifying if a checkbox is checked using jquery on Internet Explorer. This is the code I'm using:</p> <pre><code>if ($('#chkjq_1').attr('checked') == true) </code></pre> <p>It works fine on Firefox or Chrome, but on Internet Explorer 7, the condition is always false because the browser sets the property this way:</p> <pre><code>&lt;input id="chkjq_1" type="checkbox" CHECKED/&gt; IE7 </code></pre> <p>And the right way is the following: (Firefox, Chrome):</p> <pre><code>&lt;input id="chkjq_1" type="checkbox" checked="checked"/&gt; FF, Chrome, etc </code></pre> <p>What should I do to avoid this issue on Internet Explorer 7; is there a generic way in jquery to solve this?</p> <p>Thanks in advance.</p>
jquery
[5]
4,351,558
4,351,559
CRC_CCITT Kermit 16 in C#
<p>I'm currently working on a hard way that requires the CRC_CCITT Kermit 16 protocol with the formula (X16 + X12 + X5 + 1). However some of the code I've found online both on this site or the web in general I don't seem to get my desired result. I saw this website (http://www.lammertbies.nl/comm/info/crc-calculation.html) that actually provides me with the exact match I want but it was written in C++. So can anyone help me with this? </p> <p>I look forward to hearing from you.</p> <p>Kind regards</p> <p>Michael</p>
c#
[0]
4,866,433
4,866,434
Android Service Distribution
<p>I have developed an android service. Any android app can use it's API's to get some kind of news updates from this service. I want to distribute this service so that any android app on the phone can use this service. My questions here are :</p> <ol> <li>When some android application try to use its API on the phone and suppose that service is not available on the phone then what will happen ?</li> <li>How will android application developer will make sure that the service is available on the phone ?</li> <li>Does application developer has to bundle service with his application ? If yes then wont be there multiple instances of same service on phone if multiple application contains same service on the phone ?</li> </ol> <p>Thanks Dalvin</p>
android
[4]
5,334,382
5,334,383
In C# why do I need to prefix MYClass when I name its namespace with MYClass also?
<p>I have created a class:</p> <pre><code>namespace MyClass { public partial class MyClass: UserControl { </code></pre> <p>I want to use it in another project so I add the above project as reference and the instruction</p> <pre><code>using MyClass </code></pre> <p>but I still have to refer to the class as</p> <pre><code>MyClass.MyClass </code></pre> <p>and not just</p> <pre><code>MyClass </code></pre> <p>Why ?</p>
c#
[0]
319,326
319,327
Understanding of a float counter
<p>I have following simple code:</p> <pre><code>for (float i=0; i&lt;1f; i+=0.1) { System.out.println(i); } </code></pre> <p>I have just got following results:</p> <pre><code>0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.70000005 0.8000001 0.9000001 </code></pre> <p>But I can't understand why there is. Please, I hope you can tell me. Thank you. </p>
java
[1]
5,287,663
5,287,664
How to delete SMS before save inbox
<p>I have followed this <a href="http://stackoverflow.com/questions/419184/how-to-delete-sms-from-inbox-in-android-programmatically">Thread</a> . But using that, I'm not able to delete current receiving SMS. If I'm delete ALL message in in box. But currently receiving (BroadcastReceiver invoking SMS) not able to delete.</p> <p>Is there any way to delete that message also.</p> <p>Thank You, Chandana</p>
android
[4]
2,202,938
2,202,939
How to get the value of String Array?
<p>I want to print the String Array. This is my Code:</p> <pre class="lang-c# prettyprint-override"><code>System.out.println(WMSLoggerFactory.getGlobalLogValue(WMSLoggerIDs.FD_ALL)); </code></pre> <p>I got this error:</p> <pre><code>The method getGlobalLogValue(String) in the type WMSLoggerFactory is not applicable for the arguments (String[]) </code></pre> <p>How can I print this?</p>
java
[1]
4,753,409
4,753,410
ScrollView with an OnClickListeners for each item?
<p>I have made a ScrollView and filled it with ImageViews that have OnClickListeners attached to them, but now when I try to scroll the ScrollView, it seems that the OnClickListeners get in the way and don't give a smooth scroll.</p> <p>Is there a way to fix that, other then using a ListView instead of ScrollView?</p> <p>Thanks!</p>
android
[4]
2,089,309
2,089,310
Using jQuery delay() with css()
<p>Why does delay() work here:</p> <pre><code>$('#tipper').mouseout(function() { $('#tip').delay(800).fadeOut(100); }); </code></pre> <p>But this fails to delay:</p> <pre><code>$('#tipper').mouseout(function() { $('#tip').delay(800).css('display','none'); }); </code></pre> <p>// EDIT - here's a working solution</p> <pre><code>$('#tipper').mouseleave(function() { setTimeout( function(){ $('#tip').css('display','none'); },800); }); </code></pre>
jquery
[5]
3,688,562
3,688,563
Are there any 3rd party chatting apps available for android,BB and iPhone?
<p>I have a client who has a requirement for a chatting app. This app should make communication possible on Android and Blackberry.</p> <p>Wonder if this is technically feasible? If yes then how? Any clue?</p>
android
[4]
3,988,444
3,988,445
Transferring value between activities in Android not working
<p>I am trying to produce a value with a temperature conversion which works and then have this value transferred into a blank text box in another activity but the code doesn't seem to be working. Here are the two parts - the one it is coming from and the one it needs to go to...</p> <pre><code>public class MainActivity extends Activity { private EditText text; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (EditText)findViewById(R.id.MainActivityText); final EditText et = (EditText) findViewById(R.id.MainActivityText); Button b = (Button) findViewById(R.id.Button01); b.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), SecondScreen.class); startActivityForResult(myIntent, 0); Intent intent=new Intent(MainActivity.this, SecondScreen.class); intent.putExtra("value", et.getText().toString()); startActivity(intent); } }); } @SuppressLint("NewApi") public class SecondScreen extends Activity { /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.secondscreen); TextView nameView=(TextView) findViewById(R.id.SecondScreenText); nameView.setText(getIntent().getExtras().getString("Value")); Button next = (Button) findViewById(R.id.Button02); next.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent intent = new Intent(); setResult(RESULT_OK, intent); finish(); } }); }} </code></pre>
android
[4]
208,394
208,395
What is the best way to return items in Python that meet a specific condition
<p>The code I'm currently using is:</p> <pre><code>def f(*args): lst=[str(i) for i in args] if len(lst)==1:lst = lst[0] return lst </code></pre> <p>What I would like is:</p> <pre><code>a=f(1) #'1', not [1] a,b = f(1,2) #'1', '2' </code></pre> <p>Only one argument would be a list, which would be represented by <code>a</code>. </p> <p>What alternative exists aside from using an <code>if</code> statement?</p>
python
[7]
1,063,211
1,063,212
How to append the project path across all source files in python(in most efficient way)?
<p>I have a directory structure for my project as </p> <pre><code>&lt;some_path&gt;/code/project/ /conf /data /src/ a/x.py b/ c/y.py ... </code></pre> <ul> <li>each of x.py, y.py can run in isolation, so has to append the project path in its own script as </li> </ul> <blockquote> <p>sys.path.append('~/code/project')</p> </blockquote> <ul> <li><p>This becomes unmanageable when your code needs to run on multiple machines on cluster and I end up changing the paths manually :(</p></li> <li><p>Its a bad design and I want to learn what is the best way to append the project </p></li> <li><p>what is the best way to append the project path in this case so that </p> <ul> <li>I dont write <code>sys.path.append</code> in each of the <code>.py file</code></li> <li>I can define a master configuration that runs every time a <code>.py file</code> runs </li> </ul></li> </ul> <p>Thank you</p>
python
[7]
5,733,578
5,733,579
how could i show a loading bar with javascript to show the status of a running javascript
<p>I have a Javascript which is a little larger so I tried to show a .gif on the begin off the script and hide it after its finished. But if i do so the script runs and does all steps in one process so the picture is never shown. How can I force javascript to complete the show of the picture before run the rest of the script?</p>
javascript
[3]
4,053,147
4,053,148
T_object_operator error
<p>I'm trying to understand why I am getting a unexpected T_object_operator error from this function and not sure why. It says its line 34 and on line 34 is the start of the function.</p> <pre><code>public function is_user_locked($user_data-&gt;lock_date) { if ($user_data-&gt;lock_date !== '0000-00-00 00:00:00') { /* User is locked out */ if (strtotime(gmdate('Y-m-d H:i:s', time())) &lt; strtotime($user_data-&gt;lock_date)) { /* User is still locked out */ return TRUE; } else { /* User is no longer locked out */ return FALSE; } } } </code></pre>
php
[2]
92,643
92,644
fopen() error handling
<p>I'm working on a script at the moment that reads in an HTML template file, populates it with data and then saves the populated HTML file as a cached copy in my cache folder. </p> <p>I'm having real difficulties evaluating whether an error has occured with fopen() whilst runtime errors are suppressed:</p> <pre><code>$file = @fopen($location,"w+"); // manual states fopen() returns false on error // though the below does not catch any errors if (!$file) { $this-&gt;doSomething(); } </code></pre> <p>Is the suppression working against me? I would really appreciate some insight into this. I have tried setting error_reporting to display no errors,</p> <pre><code>ini_set('display_errors',0); ini_set('log_errors',1); error_reporting(E_ALL); </code></pre> <p>and removed the supression from fopen() but to no avail.</p> <p>Thank you in advance!</p>
php
[2]
2,075,525
2,075,526
How to migrate web.config?
<p><strong>situation</strong></p> <p>We use migrations to update the database schema and configuration files for all deployments of our web application. Now we have a problem with migrating the web.config.</p> <p><strong>current implementation</strong></p> <p>The migration process does the following:</p> <ol> <li>Open the database connection</li> <li>Read configuration from web.config into a configuration object</li> <li>Retrieve all migrations</li> <li>Iterate migrations <ol> <li>Update database schema (database connection is passed as parameter)</li> <li>Update configuration object (configuration object is passed as parameter)</li> </ol></li> <li>Save configuration object</li> <li>Close database connection</li> </ol> <p>Of course there is a lot of code that makes sure that the migrations are not screwing things up when something goes wrong. No worries there. Also restarting the webserver upon save the configuration is not a problem either.</p> <p><strong>problem</strong></p> <p>The problem is that it does not seem possible to make certain changes to the web.config through the configuration object. Like adding a location.</p> <p><strong>possible solution</strong></p> <p>My thoughts are now to not pass the configuration object, but the *.config files as a dictionary of xml documents. The migrations can then make changes to the raw xml. </p> <p><strong>worries</strong></p> <p>I am not too exited about this approach, because the configuration object does some configuration data integrity checks. This capability is lost when working with raw xml.</p> <p><strong>question</strong></p> <p>Is this the best approach?</p>
asp.net
[9]
4,583,118
4,583,119
Cannot compute Count for a data source that does not implement ICollection
<p><code>enter code here</code>hi. i am trying to implment custom paging in datalist control . and i am using Pagedatasource to schive this one PagedDataSource objPage = new PagedDataSource();</p> <pre><code>try { datatable ds= (datatable)viewstate["dtimages"] objPage.AllowPaging = true; //Assigning the datasource to the 'objPage' object. objPage.DataSource = ds.Dataset.Tables["Gallery"].ToString(); //Setting the Pagesize objPage.PageSize = 8; dlGallery.DataSource = objPage; dlGallery.DataKeyField = "Image_ID"; **dlGallery.DataBind();// getting error** } catch(Exception ex) { throw ex; } </code></pre> <p>Cannot compute Count for a data source that does not implement ICollection.</p> <p>why is this happening does any one can help me out thank you </p>
asp.net
[9]
4,816,734
4,816,735
How to store processed file in users desktop?
<p>I have created a website.In that scaling an image option is created.. Now i want to store that scaled image in users desktop..But its saving in code existing folder.. Please help me by sending php script to store that file in desktop</p>
php
[2]
5,757,782
5,757,783
Process.exitValue() in Java
<p>Below is piece of program I was using to simply Open and close the Internet Explorer from my command line program. im running my program with Java 6 on Windows XP OS:</p> <pre><code>Runtime runtime = Runtime.getRuntime(); Process p1 = runtime.exec("C:\\Program Files\\Internet Explorer\\iexplore.exe"); Thread.sleep(5000); p1.destroy(); Thread.sleep(2000); System.out.println("p1.exitValue(): "+p1.exitValue()) </code></pre> <p>The exit value is : 1.</p> <p>Javadoc says: by convention, the value 0 indicates normal termination. <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Process.html#exitValue" rel="nofollow">http://download.oracle.com/javase/6/docs/api/java/lang/Process.html#exitValue</a>()</p> <p>Then I commented p1.destroy and instead of closing the browser from my Java program, I closed the window manually (File>Exit). In this case p1.exitValue started returning '0'.</p> <p>My question is:</p> <ol> <li>Why program returns exit code as '1' in first case? Does JVM treats p1.destroy() as abnormal way of terminating a program? </li> <li>In general the 'exit status code' value is JVM specific or Operating system specific? I have seen some question where people have reported exit code value as '10', '34545' etc..</li> </ol> <p>Thank you for reading,</p>
java
[1]
223,001
223,002
Benefit of using static inner builder class
<p>During the course of writing the code guidelines for a company I found myself recommending using the <a href="http://stackoverflow.com/questions/5007355/builder-pattern-in-effective-java">Builder pattern</a> from Effective Java, instead of telescopic constructors.</p> <p>However, after thinking about it a bit more, surely a more elegant solution is to just remove the builder class and the also remove the extra constructors with optional arguments. </p> <p>So just have the one constructor with required parameters, normal getters/setters, and comment the code. When implementing just create a new instance of yr object then set values.</p> <p>My original thinking was the benefit came from removing the confusion as to what paramters were optional and what were required; however the true benefit comes from using method chaining/fluent interface.</p> <p>The builder pattern has benefits when you make lots of new instances as the ide can do the leg work and also if there are many (15+) optional parameters. However, is it worth the extra time coding the static inner class, would you recommend using the builder, or is it a waste of time ? </p>
java
[1]
1,536,059
1,536,060
Strange behavior of the except-function of a SortedDictionary
<p>I'm trying to utilize the Except-Function of a SortedDicationary but I'm running crazy as it does not behave as I would have expected. The Excpet function works as long as the entries of the dictionary are of a simple data type. However, I'd like to store objects in the dictionay.</p> <p>Here is my sample:</p> <pre><code> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DictionaryTest { class Program { static void Main(string[] args) { SortedDictionary&lt;string, Object&gt; objects = new SortedDictionary&lt;string, Object&gt;(); SortedDictionary&lt;string, Object&gt; objects2 = new SortedDictionary&lt;string, Object&gt;(); objects.Add("A", new Object()); objects.Add("B", new Object()); objects2.Add("A", new Object()); IEnumerable&lt;KeyValuePair&lt;string, Object&gt;&gt; objects_a_only = objects.Except(objects2); foreach (KeyValuePair&lt;string, Object&gt; o in objects_a_only) { Console.WriteLine(o.Key); } Console.WriteLine("Program finished. Press any key to continue"); Console.ReadKey(); } } } </code></pre> <p>I was expecting to only get 'A' as output but it actually returns 'A' and 'B'. </p> <p>As far as I understood it matching only takes place based on the Key of each entry. So I do not see any reason to work with a customized compare-class. </p> <p>Any ideas on this?</p>
c#
[0]
4,082,279
4,082,280
how can i close an app launched from another app?
<p>I used an external player in my app to play a file.But after playing when i click the back button it is asking for saving the url.But in my app it must not be saved how to do that. Please help me.I tried closing the player forcebly but it not worked. Thanks in advance</p>
android
[4]
1,907,899
1,907,900
jquery: how to set class members' widths to those of their respective parents?
<p>Say .item members are contained inside several elements of different widths. I want every .item to have the width of the element it's contained in... I don't know how to do that.</p> <pre><code>$(".item").width(???); </code></pre>
jquery
[5]
1,377,898
1,377,899
Single line "FromValue - ToValue" (Not a Class, not a Dictionary/List/Array). Howto?
<p>How often are you into a fromdate-todate scenario. <br> Or perhaps a fromValue-toValue.</p> <p>How do you do those times? <br> I use one of those commonly,</p> <p>T = ObjectType (DateTime, int, string..)</p> <p><code>Dictionary&lt;T,T&gt;</code> (used with .Single())<br></p> <p><code>T fromDate;</code><br> <code>T toDate;</code><br></p> <p><code>T[] comparison;</code><br></p> <p>Which are directly used or returned by a method.</p> <p>Very Very seldom i stand create a whole object</p> <pre><code>public struct T { T fromDate { get; set;} T toDate { get; set;} } public Method T(params) { ..some operations.. return T { fromDate = someBegin, toDate = someEnd }; } </code></pre> <p>Everytime time, I want a stright and simple <code>KeyValuePair&lt;T,T&gt; test;</code>. The problem to me, using KeyValuePair, is missleading if used this way?? If I see a KeyValuePair in someones code, i look at the variable like "index 10, category books".</p> <p>What are your suggestion?</p>
c#
[0]
1,336,428
1,336,429
I want to clear search result set when click out side the div of result set.and all content of body requested by ajax
<p>I'm developing a web page and it included search box. I want to clear search results set using jquery after when click out side the div of result set.and all content of body requested by ajax.</p>
jquery
[5]
3,120,785
3,120,786
Monthly report for C# application
<p>I am building a report for my application using VS2010. </p> <p>The data for the application is stored in a SQL Server 2008 R2 database. </p> <p>The columns are </p> <pre><code>DateCreated (DateTime) CardPrinted (bit) DatePrinted(DateTime) </code></pre> <p>I want to create a report that will show, for each month starting from January 2012,</p> <ol> <li>Total Number of <code>CardPrinted</code> for week1</li> <li>Total Number of <code>CardPrinted</code> for week2</li> <li>Total Number of <code>CardPrinted</code> for week3</li> <li>Total Number of <code>CardPrinted</code> for week 4 </li> </ol> <p>NB: If a card is printed, it is Marks 1 in the database, so that the <code>CardPrinted</code><br> column is either 1 or 0. </p> <p>Please I need someone to to help with the query I needed to achieve this.</p>
c#
[0]
1,665,534
1,665,535
Is there a way to use Server.MapPath in a class in my asp.net application
<p>I have a log.txt file on the root of my application. I would like to be able to have my log class be able to access this file and write to it. But i am not sure how to tell it the correct path of the file in my code. Thanks for any help</p> <pre><code>using (StreamWriter w = File.AppendText("log.txt")) { Log(e.ToString(),w); w.Close(); } </code></pre>
c#
[0]
4,958,241
4,958,242
how to calculate cos , sin , tan in IPhone SDK?
<p>How do you calculate trig functions like cos, sin, tan in the iPhone SDK?</p> <p>i tried tan(45) but it returns wrong output? any help?</p>
iphone
[8]
4,563,429
4,563,430
How can i access the functions from other JS files
<pre><code>(function () { pm.view.functionName= function () { function nameFunction() { var something; return something; } return win; }; })(); </code></pre> <p>I am in another JS file and i want to call this nameFunction()... how can i do this. I tried... </p> <pre><code>pm.view.functionName().nameFunction() </code></pre> <p>But i get an error called, cannot call function in the Object. How can i access the functions from other JS files.</p>
javascript
[3]
3,950,966
3,950,967
Grabbing the name from data sent through post
<p>When I send over post data I do a print_r($_POST); and I get something like this...</p> <p>Array ( [gp1] => 9 )</p> <p>Is there a way to get the "gp1", the name sent over as a value? I tried doing.</p> <pre><code>echo key($_POST["gp1"]); </code></pre> <p>But no luck there, I figured it would echo gp1. Is there a way to do this?</p>
php
[2]
5,714,696
5,714,697
What are the pitfalls in the approach to calculate time diff
<p>I wish to calculate the difference b/w 2 times in min:sec format . so is my approch correct </p> <pre><code>date("i:s",(strtotime($User['end_time']) - strtotime($User['start_time']))); </code></pre>
php
[2]
3,537,826
3,537,827
Getting date from the DB and add days to it in Java
<pre><code>res = stat.executeQuery("select st_date from tmp1 where Name = '" + tname.getText() + "'"); while (res.next()) { System.out.println(res.getDate(1)); int i = 0; while (i &lt; 14) { statement.executeUpdate("Insert into datetab values(DATE_ADD('" + res.getDate("st_date") + "',INTERVAL 1 DAY),'" + tempname + "')"); i = i + 1; } } </code></pre> <p>All the updates in <code>datetab</code> table occurs, but there is a problem. I will explain the problem with an example.</p> <p>If the date from <code>tmp1</code> table is <code>28-12-2000</code> then after executing the insert query with <code>date_add()</code>, what happens is that 13 new inserts are happening, but all those inserts are <code>29-12-2000</code>.</p>
java
[1]
824,223
824,224
Jquery - alternative to .length to check if element exists
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery">Is there an &ldquo;exists&rdquo; function for jQuery</a> </p> </blockquote> <p>Just as the title suggests, whats the best way to check if an element exists with jquery. I find myself constantly using .length on elements.</p> <p>Is there a better way of doing this?</p> <p>The way i typically use it is that if i am going to do anything with an element in a script ill check if the element exists on that page or not. This is ending up in a lots of blocks of code wrapped in if($('el').length) {</p>
jquery
[5]
566,872
566,873
passing parameter
<p>How to pass parameter value to webservice in android</p>
android
[4]
1,364,328
1,364,329
android how to control shutter time
<p>I develop a camera app ,I want to control camera's shutter time ,is that possible to realize?and what I want to realize final is prolong the exposure function,thank for your answer.</p>
android
[4]
2,480,335
2,480,336
mouseleave, clearing interval and stopping script
<p>I've got this bit of code:</p> <pre><code>slider.controls.next.bind('mouseenter', function() { setInterval(clickNextBind, 300); }); </code></pre> <p>working with bxslider so that if the user hovers over the "next" button, the slideshow scrolls automatically. But I need it to stop when the user moves away from the "next" button.</p> <p>I tried this:</p> <pre><code>slider.controls.next.bind('mouseleave', function() { clearInterval(); }); </code></pre> <p>But it doesn't stop the scrolling. How should I be doing this?</p> <p>MTIA.</p>
jquery
[5]
5,548,187
5,548,188
Div Lightbox JQueryPlug-in
<p>i am searching for a Div Lightbox JQuery Plugin that executes automatically when i enter the web page. Example :www.alljobs.co.il (like the popup div) </p>
jquery
[5]
2,320,203
2,320,204
Saving formatted timestring as file name problem in c#
<p>HI guys, I only started c# recently so I'm not 100% familiar with it's syntax yet and I got into a problem. I'd like to write the current time into a filename. I'm using the following code:</p> <pre><code>DateTime now = DateTime.now; string dateString = string.Format(@"Z:\test\{0}.bmp",now.ToString("s")); bitmap.Save(dateString); </code></pre> <p>Now this gives me a can't access filepath error. Apparently it has something to do with the ":" characters at the time part (at least when I give a now.ToString("d") ) it saves fine. Any idea whats causing this? Thanks. </p>
c#
[0]
3,394,702
3,394,703
Crashing with a null pointer de-reference, why?
<p>I was reading <a href="http://en.wikipedia.org/wiki/Moai_%28game_development_platform%29" rel="nofollow">Moai</a> source code, and I became curious about why this should cause a crash (or not...)</p> <p>I do not really understood that snippet.</p> <p>In file A:</p> <pre><code>#define UNUSED(p) (( void )p) </code></pre> <p>In file B:</p> <pre><code>//----------------------------------------------------------------// /** @name crash @text Crashes Moai with a null pointer dereference. @out nil */ int MOAISim::_crash ( lua_State* L ) { UNUSED(L); int *p = NULL; (*p) = 0; return 0; } </code></pre> <p>EDIT:</p> <p>I think part of what I was not understanding is what "deference" means. So if you put that in your answers it would be awesome.</p>
c++
[6]
5,206,610
5,206,611
Return Max value + name from a 2 dimensional List C#
<p>I have created a 2-dimensional list and want to return the maximum value, the minimum value, and the names that have the same index as these values.</p> <p>This is what i did.</p> <pre><code>class Info { private string stad; private double temperatur; public string Stad { get { return stad; } set { stad = value; } } public double Temperatur { get { return temperatur; } set { temperatur = value; } } } static double SearchMax(List&lt;Info&gt; list) { if (list.Count == 0) { throw new InvalidOperationException("Tomt Lista"); } double Temperatur = double.MinValue; foreach (Info temperatur in list) { if (temperatur.Temperatur &gt; Temperatur) { Temperatur = temperatur.Temperatur; } } return Temperatur; } static double SearchMin(List&lt;Info&gt; list) { if (list.Count == 0) { throw new InvalidOperationException("Tomt Lista"); } double Tempertatur = double.MaxValue; foreach (Info temperatur in list) { if (temperatur.Temperatur &lt; Tempertatur) { Tempertatur = temperatur.Temperatur; } } return Tempertatur; } </code></pre> <p>But what I get in return is only the maximum and minimum values, not the name of the city that the temperature is in.</p> <p>Can anyone tell me or show me how to return both?</p> <p>Thank you for all the help you provide but it just put me back to where I was before posting this up here. What I want is for the program to return both the city and the temperature in the city i.e "Warmest city is Oslo and it's 20 °C warm" and not "Warmest city is consoleaplication.info"</p> <p>edit:2 Thank you for all yours help and especialy Alex ^_^</p>
c#
[0]
422,144
422,145
How to create the build of PHP application
<p>I have developed a web application in php. And i need to host it in the server. But before that i have convert the source code into build. How can i achieve this..</p>
php
[2]
5,348,690
5,348,691
Saplin Dropdown checkboxes default selectall
<p><a href="http://forums.asp.net/p/1849542/5210080.aspx/1?Re+Saplin+Dropdown+checkboxes+default+selectall" rel="nofollow">http://forums.asp.net/p/1849542/5210080.aspx/1?Re+Saplin+Dropdown+checkboxes+default+selectall</a></p> <p><a href="http://saplin.blogspot.com/2011/05/dropdowncheckboxes-using-control.html" rel="nofollow">http://saplin.blogspot.com/2011/05/dropdowncheckboxes-using-control.html</a></p> <p>Hey All, I want to check all in the dropdown..do we have any shortcut to do it...I have thousands items in the dropdown...looping is making my page slow...how to automatically make it selected?</p> <pre><code>foreach (ListItem item in DD.Items) { item.Selected = true; } </code></pre> <p>Please help me, I am using it for the company i am working for...they are asking me to improve the page performance...it is a high priority for me....</p>
asp.net
[9]
2,545,082
2,545,083
I have this jquery function...that slides up. I want it to slide left
<p>Here's a working example of my function. Works as it should. However, how do I make it slide left, instead of sliding up/down?</p> <p><a href="http://jsfiddle.net/QWQYS/24/" rel="nofollow">http://jsfiddle.net/QWQYS/24/</a></p>
jquery
[5]
1,646,634
1,646,635
Countdown Timer
<p>My project in php</p> <p>I want to create a countdown timer for asking question in limited timeframe like LMS here i have use the javascript countdown timer but when refresh the page javascript timer are reset.</p>
php
[2]
4,268,816
4,268,817
Is there a UI pattert to change positions of elements in a list?
<p>I need to create a list of elements. The elements in the list are sorted according to a field (for instance, position). I should have a possibility to add elements in this list, to delete them and to move elements in the list. Are there any UI patters for this task in Android? Can you recommend some resources for this?</p>
android
[4]
1,248,076
1,248,077
Double the occurence of character in Javascript
<p>Input String : abcd </p> <p>Output String : aabbccdd </p> <p>How to achieve this using Javascript if 'a' 'b' 'c' 'd' are an elements of an array ..</p>
javascript
[3]
3,664,155
3,664,156
HEX to BIN convert
<p>I wrote 2 programs that converts HEX to DEC and DEC to BIN. When i test them seperatly they work. When i place them together it outputs the right DEC code but the wrong BIN code. How can i fix this?</p> <h1>HEX to DEC</h1> <pre><code>#include &lt;iostream&gt; int main() { int hex; std::cin &gt;&gt; std::hex &gt;&gt; hex; std::cout &lt;&lt; hex &lt;&lt; std::endl; system("pause"); return 0; } </code></pre> <h1>DEC to BIN</h1> <pre><code>#include &lt;iostream&gt; using namespace std; int main () { int Number; cin &gt;&gt; Number; bool Binary[sizeof(int) * CHAR_BIT]; for(unsigned int i = 0; i &lt; sizeof(int) * CHAR_BIT; i++) Binary[(sizeof(int) * CHAR_BIT - 1) - i] = Number &amp; (1 &lt;&lt; i); for(unsigned int i = 0; i &lt; sizeof(int) * CHAR_BIT; i++) std::cout &lt;&lt; Binary[i]; std::cout &lt;&lt; endl; system ("pause"); return 0; } </code></pre> <h1>HEX to BIN</h1> <pre><code>#include &lt;iostream&gt; int main() { int hex = 0; int Number = 0; std::cin &gt;&gt; std::hex &gt;&gt; hex; std::cout &lt;&lt; hex &lt;&lt; std::endl; hex = Number; bool Binary[sizeof(int) * CHAR_BIT]; for(unsigned int i = 0; i &lt; sizeof(int) * CHAR_BIT; i++) Binary[(sizeof(int) * CHAR_BIT - 1) - i] = Number &amp; (1 &lt;&lt; i); for(unsigned int i = 0; i &lt; sizeof(int) * CHAR_BIT; i++) std::cout &lt;&lt; Binary[i]; std::cout &lt;&lt; std::endl; system("pause"); return 0; } </code></pre>
c++
[6]
1,412,682
1,412,683
python store variable in function and use it later
<p>is it possible to store a variable from a while loop to a function and then call that same variable from the fucntion at the end of the loop</p> <p>for eg:during while loop, problem here is that when i try to retrieve the variable from store() it fails...as it needs arguments to be passed..</p> <pre><code>def store(a,b,c): x1 = a y1 = b z1 = c return (x1,y1,z1) def main(): while condition: loop .. x = ....... y = ....... z = ....... ....... ....... store(x,y,z) #store to function... ...... ...... ....... ...... s1,s2,s3 = store() ..... ....... ... end </code></pre>
python
[7]
4,770,860
4,770,861
FileNotFoundException while unzipping a file
<p>I have this code that's supposed to unzipp a file.</p> <pre><code>public class dec extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Toast.makeText(this, "hello, starting to unZipp!", 15500).show(); String location = Environment.getExternalStorageDirectory() + "/unzipped/"; ///////////////////////////////////////////////////////////////////// try { ZipInputStream zin = new ZipInputStream(getAssets().open("totalkeys.zip")); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { Log.v("Decompress", "My UNZIPPING: " + ze.getName()); if(ze.isDirectory()) { dirChecker(ze.getName()); } else { FileOutputStream fout = new FileOutputStream(location + ze.getName()); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } } zin.close(); } catch(Exception e) { Log.v("Decompress", "My ERROR: "+e.toString()); /// throws My ERROR: java.io.FileNotFoundException: /mnt/sdcard/unzipped/Eng_blue/altlayout.txt (No such file or directory) /// and dies. } } //////////////////////////////////////////////////// private void dirChecker(String dir) { String location = Environment.getExternalStorageDirectory() + "/unzipped/"; File f = new File(location + dir); if(!f.isDirectory()) { f.mkdirs(); } //////////////////////////////////////////////////// finish(); } } </code></pre> <p>Yet it only throws "ava.io.FileNotFoundException: /mnt/sdcard/unzipped/Eng_blue/altlayout.txt" which is the name of the first file and dies.</p> <p>I thought that dirChecker() method would create this folders on the flow... any ideas how to fix that?</p> <p>Thanks!</p>
android
[4]
1,593,789
1,593,790
WCF Service returns an XML, how to prase using jquery?
<p>i am calling an api for registration and if everything goes well then api returns an xml file </p> <pre><code>"&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\"?&gt;\u000a&lt;successNotification&gt;\u000a\u0009&lt;message&gt;Successful web registration&lt;\/message&gt;\u000a\u0009&lt;registrationId&gt;22342347&lt;\/registrationId&gt;\u000a&lt;\/successNotification&gt;" </code></pre> <p>if something wrong then it returns a line of message </p> <p><code>you are missing something</code></p> <p>my question is: how can i display message regardless whether it returns xml or just line of message:</p> <pre><code>$.getJSON('http://localhost:4126/service.svc/alert', { phoneNumber: '01231231233' }, function (data) { var result = $(data).find('message').html; display.innerHTML = result; }); </code></pre>
jquery
[5]