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,929,777
3,929,778
Script for the functionality of Code Sample
<p>I just want to have the functionality of Code Sample(this is a button above text format box in SOF when we ask a question) which is also there in StackOverFlow. How to get the color of keywords which are shown in IDE. <code>&lt;pre&gt;&lt;code&gt;</code> works good to show the code but how to display the exact color which IDE is displaying, that is what I don't know. Can we have same functionality in Windows form to display the code. </p>
javascript
[3]
1,410,129
1,410,130
Readably print out a python dict() sorted by key
<p>I would like to print a python dictionary to a file using PrettyPrinter (for human readability) but have the dictionary be sorted by key in the output file to further improve readability. So:</p> <pre><code>mydict = {'a':1, 'b':2, 'c':3} pprint(mydict) </code></pre> <p>currently prints to</p> <pre><code>{'b':2, 'c':3, 'a':1} </code></pre> <p>I would like to PrettyPrint the dictionary but have it printed out sorted by key eg.</p> <pre><code>{'a':1, 'b':2, 'c':3} </code></pre> <p>What is the best way to do this?</p>
python
[7]
1,563,366
1,563,367
How to properly do sliding on android?
<p>ALL, I have the following "simple" question. ;-) I have an application which has an image background loaded from the png file. On top I have an Image View which I would like to rotate with my fingers. I am using MotionEvent to catch the sliding but apparently it works when I slide my fingers on the background but not on the image view.</p> <p>My guess is that the view cover the background and the events are not ending up on the place.</p> <p>How to overcome this problem?</p> <p>Thank you.</p>
android
[4]
5,893,090
5,893,091
How to define multiple variables on a single line?
<p>Reading documentation online, I'm getting confused how to properly define multiple JavaScript variables on a single line.</p> <p>If I want to condense the following code, what's the proper JavaScript "strict" way to define multiple javascript variables on a single line?</p> <pre><code>var a = 0; var b = 0; </code></pre> <p>Is it:</p> <pre><code>var a = b = 0; </code></pre> <p>or</p> <pre><code>var a = var b = 0; </code></pre> <p>etc...</p>
javascript
[3]
323,843
323,844
Getting weird results while subtraction manipulation in python
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/306313/python-is-operator-behaves-unexpectedly-with-integers">Python &ldquo;is&rdquo; operator behaves unexpectedly with integers</a><br> <a href="http://stackoverflow.com/questions/11476190/why-0-6-is-6-false">Why (0-6) is -6 = False?</a> </p> </blockquote> <pre><code>&gt;&gt;&gt; (0 - 10) is -10 False &gt;&gt;&gt; (0 - 5) is -5 True </code></pre> <p>Can anybody explain me , how I am getting False in one case and True in another case for same manipulation...</p> <p>Some more weirdness...</p> <pre><code>&gt;&gt;&gt; (0 - 10) is (0 - 10) False </code></pre>
python
[7]
4,576,981
4,576,982
android map overlay size
<p>I've used images for my overlay and using </p> <pre><code>Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pushpin); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); </code></pre> <p>It looks like the overlay size doesn't change with the zoom level. </p> <p>Any idea how to achieve this?</p>
android
[4]
5,390,987
5,390,988
Button placed in FrameLayout does not work properly in 2.3.6 device, even though compiled from 2.3.3 (API 10) SDK
<p>I have installed API Level 10 SDK ( aka 2.3.3 ). </p> <p>I've made a simple linear arrangement of Buttons added programmatically on FrameLayout.</p> <p>minTargetVersion = "8" maxTargetVersion = "10"</p> <p>Runs properly on ICS 4.0.4 device. Runs properly on Simulator. But when I install the apk in devices having OS 2.3.5 or 2.3.6, then the buttons do not obey the left margin parameters and all comes clubbed one onto another. </p> <p>I've seen that FrameLayout was introduced in API Level 1, while the running devices are at API level 10 or higher, which shouldn't be a problem.</p> <p>My sample code of adding a button</p> <pre><code>Button b1 = new Button(this); FrameLayout frameLayout = (FrameLayout)this.findViewById(R.id.mainActivityView); FrameLayout.LayoutParams params = FrameLayout.LayoutParams(100,100); //a 100x100 button params.leftMargin = 10; // in other buttons, this values is incremented as 100, 200 params.topMargin = 10; frameLayout.addView(b1,params); </code></pre> <p>Can anyone let me know what could be causing such improper behaviour?</p>
android
[4]
3,851,847
3,851,848
Face not detect when change orientation?
<p>I have problem with face detection. When I change the orientation of my device from landscape to portrait, face detection fails.</p> <p>I am unable to find a solution. This is what I tried:</p> <pre><code>if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { mCamera = Camera.open(camIdx); Camera.Parameters params = mCamera.getParameters(); params.set("orientation", "portrait"); //params.set("rotation", 90); mCamera.setDisplayOrientation(90); //params.setRotation(90); //params.setPictureSize(640, 480); mCamera.setParameters(params); mCamera.startPreview(); } </code></pre> <p>Whenever I change the orientation of my device, I did'nt got face detect . please anybody help me, i did try all thinks but not able detect face.</p>
android
[4]
513,546
513,547
Why does second function declaration win even though I return before it?
<p>I have the following JavaScript code:</p> <pre><code>(function() { function f(){ alert(1); } return f(); function f(){ alert(2); } })(); </code></pre> <p>Can you explain why the alert pops up with 2 and not 1?</p> <p>Thanks,</p>
javascript
[3]
4,100,857
4,100,858
How to get query in the URL after #
<p>I am using PHP and want to check links of the same page but with different trailing info. </p> <p>The URL to the page normally is <a href="http://www.mypage.com/?about" rel="nofollow">http://www.mypage.com/?about</a> but if the user accessed it by clicking on the link SEND the user get send to <a href="http://www.mypage.com/?about#send" rel="nofollow">http://www.mypage.com/?about#send</a> </p> <p>If the user clicked INFO they go to <a href="http://mypage.com/?about#info" rel="nofollow">http://mypage.com/?about#info</a></p> <p>Question how do I check for <code>#</code> and what comes after it? I tried <code>$_SERVER[query_string]</code> and it shows <code>about#send</code> and I only need to check for what comes after the number sign <code>#</code>. </p>
php
[2]
281,479
281,480
difference between Object reference and Object hash code
<p>whats the difference between an Object's reference and the same object's hash code value in java ?</p>
java
[1]
4,445,353
4,445,354
How do I pass parameters in window.open method
<p>How do I pass parameters in window.open method.</p> <pre><code>&lt;table id="tblUsers" cellspacing="0" &gt; &lt;asp:Repeater ID="repUsers" runat="server"&gt; &lt;ItemTemplate&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;a ID="hlUser" runat="server" Target="_new" onclick="return OpenWindow();" &gt;&lt;%# Eval("Username") %&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/table&gt; function OpenWindow() { var toUsername = document.getElementById("hlUser"); window.open("ChatWindow.aspx?username=" + toUsername.value, "ChatWindow", "width=350,height=250"); return null; } </code></pre>
asp.net
[9]
5,225,903
5,225,904
MediaController appears only after tapping in Android
<p>I am writing an Android App where I am playing video using VideoView,but the mediaController appears only after tapping the screen.Is this correct procedure ? If not how can we make it to appear without tapping on the screen.</p> <p>Thanks in Advance,</p>
android
[4]
642,959
642,960
i am using ContactsContract is shows error that mean it creates anothor class
<p>hi all how can i get phone numbers, email_ids and names from contact list </p> <p>when i am using ContactsContract it shows error how con i avoid those problems so anyone </p> <p>kindly help me now it is urgent for me.</p>
android
[4]
3,792,738
3,792,739
how to do tooltip on button in iphone?
<p>I am having download icon on my page i want that when the user takes his finger over the button a tooltip should show as showing download in text.</p> <p>is there any option in iphone to show a tooltip??? </p>
iphone
[8]
1,277,990
1,277,991
Parsing certain data with lxml
<p>I'm a beginner in coding and a friend of mine told me to use BeautifulSoup instead of htmlparser. After running into some problems I got a tip to use lxml instead of BeaytifulSoup because it's 10x better. </p> <p>I'm hoping someone can give me a hint how to scrape the text I'm looking for. </p> <p>What I want is that in the html page is to find a table with the following rows and data. </p> <pre><code>&lt;tr&gt; &lt;td&gt;&lt;a href="website1.com"&gt;website1&lt;/a&gt;&lt;/td&gt; &lt;td&gt;info1&lt;/td&gt; &lt;td&gt;info2&lt;/td&gt; &lt;td&gt;&lt;a href="spam1.com"&gt;spam1&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="website2.com"&gt;website2&lt;/a&gt;&lt;/td&gt; &lt;td&gt;info1&lt;/td&gt; &lt;td&gt;info2&lt;/td&gt; &lt;td&gt;&lt;a href="spam2.com"&gt;spam2&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>How do I scrape the website with info 1 an 2 without spam with lxml and get the following results?</p> <p>[['url' 'info1', 'info2'], ['url', 'info1', 'info2']]</p>
python
[7]
3,738,862
3,738,863
iPhone error "NsUrlConnetionInternalConnection_WithConnectionDisconnectFromConnection"
<p>We are getting an error:</p> <blockquote> <p>[NsUrlConnetionInternalConnection_WithConnectionDisconnectFromConnection]: message send to deallocated instance 0*7a58e60 while runnting an iPhone application.</p> </blockquote> <p>It is using a live webservice. But it is working with locally created webservice. Please give us a solution to solve it. </p>
iphone
[8]
2,083,795
2,083,796
How to embed jquery library in asp.net custom server control?
<p>I emebeded jquery library in custom server control. but it's not working. it throws "object expected error". the complete code listing is given below.</p> <p>jquery-1.4.1.js is rename it to jquery.js</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ServerControl1 { [DefaultProperty("Text")] [ToolboxData("&lt;{0}:ServerControl1 runat=server&gt;&lt;/{0}:ServerControl1&gt;")] public class ServerControl1 : WebControl { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? "[" + this.ID + "]" : s); } set { ViewState["Text"] = value; } } protected override void RenderContents(HtmlTextWriter output) { output.Write("&lt;p&gt;Hello World!!&lt;/p&gt;"); } public static void RegisterJQuery(ClientScriptManager cs) { cs.RegisterClientScriptResource(typeof(ServerControl1), "ServerControl1.Resources.jquery.js"); } protected override void OnPreRender(EventArgs e) { if (!this.DesignMode) { // Register the JavaScript libraries ClientScriptManager cs = this.Page.ClientScript; ServerControl1.RegisterJQuery(cs); } } protected override void OnInit(EventArgs e) { string javascript = "&lt;script type='text/javascript'&gt; " + "$(document).ready(function () { " + "alert($('p').text()); " + "});&lt;/script&gt;"; if (!(Page.ClientScript.IsClientScriptBlockRegistered("bhelp"))) Page.ClientScript.RegisterStartupScript(this.GetType(), "bhelp", javascript); base.OnInit(e); } } } [assembly: System.Web.UI.WebResource("ServerControl1.Resources.jquery.js", "text/javascript")] </code></pre>
asp.net
[9]
4,428,722
4,428,723
Problems with dojo event and Jquery
<p>I can't find the answer in the other posts.</p> <p>I use: <a href="https://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dojo/dojo.xd.js" rel="nofollow">https://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dojo/dojo.xd.js</a> and libs/jquery/1.5.0/jquery.min.js</p> <p>I need to read the event of the client of my dijit.form.ComboBox.</p> <p>I have used all, .live , .click but i obtain the same results; nothing.</p> <pre><code> $('#Place').live('change',(function () { alert("Campos ocultos OK"); })); </code></pre> <p>or </p> <pre><code> $('#Place').click (function () { var thischeck = $(this); alert("Ok1"); if (thischeck.is (':checked')) { alert("OK2"); } }); </code></pre> <p>Could somebody help me please?</p> <p>Where i'm worng?</p> <p>Thank you very much,</p> <p>Álvaro</p>
jquery
[5]
1,455,300
1,455,301
PHP remove all characters before specific string
<p>I need to remove all characters from any string before the occurrence of this inside the string:</p> <p>"www/audio"</p> <p>Not sure how I can do this.</p>
php
[2]
4,332,396
4,332,397
php POST summation
<p>i am sending 5 different data across to a php file through POST method. the data is all integers. i want to add up all these integer values to produce a sum. </p> <pre><code> $.post( "user_submit.php", {score: $('#ques'+qn).find('input[name=vote]:checked').val() }, function(data){ $("#ques"+qn).hide(); ++qn; $("#ques"+qn).show(); }); }); </code></pre> <p>in the php file:</p> <pre><code>$score = $_POST['score']; $total = $total + $score; echo $total; </code></pre> <p>it is not adding up the values. what am i doing wrong?</p>
php
[2]
3,029,251
3,029,252
how to get the id of a div when using jquery hasClass method?
<p>This code is not working:</p> <pre><code> $("div").hasClass("testSection").attr("id"); </code></pre> <p>I get the following error message:</p> <pre><code> TypeError: $(...).hasClass(...).attr is not a function </code></pre> <p>Any idea what could be the problem</p>
jquery
[5]
26,517
26,518
Error:Could not find filename.apk
<p>when i run the emulator it give the error in console . Could not find filename.apk. and i installed the plugins ADT 11.0.what should now i do.please help me. thanx </p>
android
[4]
4,703,375
4,703,376
Javascript function argument in array
<p>I have:</p> <pre><code>String.prototype.callcm = function(something[]){ alert(something); }; </code></pre> <p><code>"something".callcm({a:50,b:60});</code></p> <p>how can the arguments with there variable name get in the something array.</p>
javascript
[3]
4,638,919
4,638,920
create a function of a repetitive else if
<p>the question title might not justify my question at all since I have no idea what to write as the title.</p> <p>So, if I have something like this:</p> <pre><code>if($type=="a"){ $s.= " AND type= 'List Apart "; }elseif($type=="b"){ $s.= " AND type = 'Before CSS3' "; }elseif($type=="C"){ $s.= " AND type = 'Tricks' "; }elseif($type=="D"){ $s.= " AND type = 'Stackoverflow' "; .. etc until Z (just for example) </code></pre> <p>So can I do this? I've tried it but it doesn't work.</p> <pre><code>$arr = array("b"=&gt;"Before CSS3",..."Z"=&gt;"Somethingd"); // it's not just a simple a-z. A is hardcoded because of the if. foreach($arr as $r){ $r.= "}elseif($type=='key($r)'){ //not the syntax cos I kinda forget :p $s.= ' AND type = \'value($r)\' "; //same here } return $r; </code></pre> <p>UPDATE : Sorry if I was not being clear enough, I've already edited my question. So it's not just a simple a-z loop, it's an array with keys and values.</p>
php
[2]
4,859,921
4,859,922
Android - app not searchable in Android store
<p>I have a new app that I made and put in the store yesterday.</p> <p>I am able to see it here: <a href="https://play.google.com/store/apps/details?id=com.problemio" rel="nofollow">https://play.google.com/store/apps/details?id=com.problemio</a></p> <p>but there is absolutely no way I can see it in the app store when I search for any terms. Any idea how I can get it to show up in the app store?</p> <p>It says that the app IS compatible with my phone so I don't see why it wouldn't show up for me.</p>
android
[4]
3,964,921
3,964,922
Which is a more efficient implementation of a linked list?
<p>There are at least two ways to represent a linked list:</p> <p>1.)Using an array based representations of the linked list, where we keep an <code>std::vector</code> of structs of the type</p> <pre><code>struct { &lt;whatever-type-you-want&gt; item ; int nextitem; } </code></pre> <p>Here inserting into the list, is doing a push_back() on the vector and giving an appropriate value to next-item. </p> <p>2) In which you have a collection of structs all over RAM. Here insert is done with the C++ operators <code>new</code> .</p> <p>Is it correct to say, that the first method is more efficient since all the items are in consecutive locations in memory, because of which one might be able to grow the linked list to a much larger size than the second method</p> <p>In the second method, there might be memory fragmentation with huge linked lists because of which one might get a segmentation fault much earlier.</p>
c++
[6]
1,546,239
1,546,240
How to generate light colour shades in javascript
<p>Hello all I am working in JavaScript and want to generate colors for my graph.And I want a new color for every line and also the color should be light in shade.</p> <p>I have read about question of color generation in java script</p> <p><a href="http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript">Random Color generator in Javascript</a></p> <p>As I want new color for my line so random number generation will not work in my case Also the color should be light</p> <p>I have read about the colors RGB values but I didn't find them following any pattern as how to choose light color</p> <p>So any one can please guide me as is there a way to generate colors in sequence (avoid random) and choose only light color or any other function to make dark color lighter</p> <p>Thanks</p> <p><a href="http://cloford.com/resources/colours/500col.htm" rel="nofollow">http://cloford.com/resources/colours/500col.htm</a> </p>
javascript
[3]
4,154,611
4,154,612
Significance of Super?
<p>Can anybody tell me why we need the super in every method for e.g.:</p> <pre><code>-(void)viewDidLoad { [super viewDidLoad]; } </code></pre> <p>I am confused about the <code>super</code> keyword....</p>
iphone
[8]
2,917,226
2,917,227
string compare jQuery
<p>I'm having some problems to compare two strings in jQuery:</p> <pre><code>var option = ""; $.each(data, function(key, value) { option += "&lt;option "; if(selected == value) { option += "selected"; } option += "&gt;" + value + "&lt;/option&gt;"; }); </code></pre> <p>selected and value are the same strings.</p> <p>Is there an anither way to compare strings or could it be, that selected and value are different types?</p>
jquery
[5]
4,566,441
4,566,442
In IB, I created a table and now want to assign a variable to it
<p>I now want to refer to the table, but there isn't a variable in my .h file as it wasn't required when originally created. The table works great, can add/display/etc.</p> <p>I tried adding "myTable" to the .h and then linking in IB (the table was linked to "view" and I could/did select "myTable"), but my first try didn't work and I was afraid of messing up my (somewhat) working app ;-)</p> <p>Hope the question makes sense!!!</p> <p>thx!</p>
iphone
[8]
3,357,283
3,357,284
Delete the only node from a BST
<p>My BST have only ONE node. I wrote a code to delete that node but it's still there. Just like it hasn't been... updated. Here is my simple code, just to test the case</p> <pre><code>void Delete(BSTree* tree, int&amp; key) { if (key == tree-&gt;key) tree=NULL; } </code></pre> <p>And my BSTree class doesn't have a parrent part. Just the value and the left and right pointer. What is wrong with my code? Thank you!</p>
c++
[6]
1,972,853
1,972,854
Constructor Overloading in C++
<p>My C++ overloading does not act as I assume it should:</p> <pre><code>#include "Node.h" #include &lt;iostream&gt; Node::Node() { cout &lt;&lt; "1" &lt;&lt; endl; Node(Game(), 0.0); } Node::Node(double v) { cout &lt;&lt; "2" &lt;&lt; endl; Node(Game(),v); } Node::Node(Game g, double v) { cout &lt;&lt; "3" &lt;&lt; endl; numVisits = 0; value = v; game = g; } </code></pre> <p>And the output from:</p> <pre><code>Node n(16); cout &lt;&lt; n.value &lt;&lt; endl; </code></pre> <p>is 0, when it should be 16.</p> <p>What am I doing incorrectly?</p>
c++
[6]
96,047
96,048
parseInt misbehaves when passed as argument to a map call
<p>Why is this happening?</p> <pre><code>var numbers = [ '1', '2', '3', '4' ]; var intNumbers = numbers.map( parseInt ); // intNumbers = [1, NaN, NaN, NaN] var fltNumbers = numbers.map( parseFloat ); // fltNumbers = [1, 2, 3, 4, 5 ] </code></pre> <p>But <code>Array.prototype.map.call( numbers, parseInt );</code> returns <code>[ 1, 2, 3, 4];</code>. I'm running this code in Google Chrome 26.0.1410.65.</p>
javascript
[3]
4,795,288
4,795,289
ASP.NET Refrence to my local PC in users event log, why?
<p>A customer has sent my a screen shot of their event log which shows an error from my ASP.Net app, the problem is it shows the line number where the error occurred but references my PC and the path into my files. Why? There's no references in my code.</p> <p>Thanks Lee</p>
asp.net
[9]
5,069,339
5,069,340
custom view with buttons over the picker view
<p>Trying to create custom view with buttons than pickerview. Problem i m having is that custom view is displaying but not buttons</p> <pre><code>UIView *view=[[[UIView alloc]initWithFrame:CGRectMake(0,200,320,300)]autorelease]; view.backgroundColor=[UIColor grayColor]; UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside]; myButton.frame = CGRectMake(50, 300, 60, 50); [myButton.layer setMasksToBounds:YES]; [myButton.layer setCornerRadius:10.0f]; [myButton setTitle:@"English" forState:UIControlStateNormal]; myButton.backgroundColor = [UIColor whiteColor]; [self.view addSubview:view]; [self.view addSubview:myButton]; </code></pre> <p>Any idea what i m missing here.</p>
iphone
[8]
5,760,882
5,760,883
How to fade the aspx page and open the dialog on buttonClick in aspx page
<p>Defaulttimesheet.aspx page in my application contains two buttons(search and back) and a multiview with attribute visible=false. Initially my page displays only two(Search and back) buttons when i click on search button the defaulttimesheet.aspx page colour changes to fade and displays multiview in white color. multiview contains toolbar with filter button, when i clicked on this filter button it should change the multiview colour to fade and open a search dialog also when i close the dialog the multiview colour should changed to white. Am able to open the dialog but not possible to fade the view. How can i do this? Anyone plz help me..............</p> <p>Thanks in advance </p>
asp.net
[9]
1,132,363
1,132,364
Do not want to repeat myself
<p>I have some links and when someone click on those links it will show up a popup which has some info.And then close it when user clicks on x.I have used jquery's show and hide to do this. Different links have different info so i have repeated myself and i want to know is there any way to not repeat myself.<a href="http://jsbin.com/ovomaw/1/edit" rel="nofollow">This Link</a> will take you to jsbin where my code is and you understand what i am talking about. Thank You.</p>
jquery
[5]
3,043,778
3,043,779
PHP - Looping inside a loop, maybe?
<p>I am currently using a foreach loop to display some radio buttons like so</p> <pre><code>&lt;?php foreach($roles as $role){ $output .= '&lt;div class="row"&gt;'; $output .= ' &lt;input name="_'.$role-&gt;key.'" type="radio" id="'.$role-&gt;key.'" class="radio" /&gt;'; $output .= ' &lt;label for="'.$role-&gt;key.'" style="text-transform: lowercase;"&gt;'.$role-&gt;name.'&lt;/label&gt;'; $output .= '&lt;/div&gt;'; } </code></pre> <p>?></p> <p>So thats fairly straight forward .... The bit that i need to do next is confusing ... i need to take the $role->key and see if it matches an entry in another table, if so, echo 'checked="checked"' on the radio button.</p> <p>It will need to be matched by the $role->key and also the $userid.</p> <p>Any help would be great.</p>
php
[2]
1,274,995
1,274,996
TOO MANY if (obj is thisObj) statements
<p>I currently have method which is trying to find out what the obj is it recieved. It knows is on a certain interface, for example IService but I have code which looks at it and tries to tell me is it is for example Service1 or Service2. I currently a lot of if(obj is thisObj) style statements, what would be the best solution to make this code pretty?</p> <p>here is a sample of what exactly I have:</p> <pre><code> public void DoSomething(IService service) { if (service is Service1) { //DO something } if (service is Service2) { //DO something else } } </code></pre> <p>now having two isnt too much of a bad thing, but I am looking at having probably 20+ of these which just becomes awful to use.</p> <p>Any ideas?</p> <hr> <p>ok further details I think are needed and here they are:</p> <p>prior to this method I have another method which is recieving a xml doc, which it them deserializes into the interface IService, so we have something like this:</p> <pre><code> private static void Method(InnerXml) { var messageObj = (IServiceTask)XmlSerialization.Deserialize(typeof(IServiceTask), InnerXml); var service = GetService(messageObj); service.PerformTask(xmlDoc); } private static IService GetService(IServiceTask messageObj) { var service = new IService (); if (messageObj is Task1) { service = (SomeService)messageObj; } if (messageObj is Task2) { service = (SomeOtherService)messageObj; } return service ; } </code></pre> <p>Hopefully that makes it a bit clearer.</p>
c#
[0]
4,867,051
4,867,052
How to detect when a property is added to a JavaScript object?
<pre><code>var obj = {}; obj.a = 1; // fire event, property "a" added </code></pre> <p>This question is different from <a href="http://stackoverflow.com/questions/1759987/listening-for-variable-changes-in-javascript-or-jquery">this one</a>, where ways to detect when an already declared property is changed, being discussed. </p>
javascript
[3]
1,062,908
1,062,909
Set photo as marker in map
<p>Let's say I got the absolute path into the photo. /mnt/sdcard/....jpg</p> <pre><code> String path = "/mnt/sdcard/....jpg"; BitmapDrawable d = new BitmapDrawable(this.getResources(), path); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); overlayItem.setMarker(d); </code></pre> <p>This is what i tried, however the photo does not display.</p> <p>EDIT: fixed, wrong path to file.</p>
android
[4]
2,943,605
2,943,606
what is the most efficient way to creating a dict with two lists?
<p>I have two lists like </p> <pre><code>x = ['a', 'b', 'c', 'd'] and y = [1, 2, 3, 4] </code></pre> <p>I have to create a dict from these two lists so that result is</p> <pre><code>{ 'a': 1, 'b': 2, 'c': 3, 'd': 4 } </code></pre> <p>I do it using the following</p> <pre><code>dict(zip(x, y)) </code></pre> <p>Is there a better and fast/efficient way of doing it?<br> I have to perform this operation on [m, b]illion of times and on different lists </p> <p>Thank you</p>
python
[7]
2,896,876
2,896,877
jquery - how to get properties from object Object?
<p>My php class is returning an array of object Objects, and I'd like to call or select attributes of each one. </p> <p>My JS looks like this:</p> <pre><code>$.get("getData.php", function(result){ var data = jQuery.parseJSON(result); $.each(data, function(i, v){ console.log($(this).attr('myPlantCode')); </code></pre> <p>...but the console just returns 'undefined' for each object in the array. </p> <p>I know it must be something simple and I'm probably not far off...but how do I call out specific attributes by name?</p>
jquery
[5]
4,139,031
4,139,032
how can I create the solution file for already existing visual studio 2003 web project
<p>I have one visual studio 2003 web project, I got this project form my friend, and how can I run this application in visual studio 2003.Becuse now I don't have a solution file for this application. In my system I don't have administrative access.</p>
asp.net
[9]
5,463,293
5,463,294
Run external program concurrently
<p>I want to be able to run an external program concurrently with my Java code, i.e. I want to start the program, then return control to the calling method while keeping the external program running at the same time. The Java code will then keep generating input and send it to the external program and receive output back. </p> <p>I don't want to keep loading the external program as it has very high overhead. What is the best way to accomplish this? Thanks!</p>
java
[1]
5,302,277
5,302,278
Is it possible to insert external variable inside javascript function variable?
<p>I have two javascript methods ( <code>imports</code>, and <code>namespace</code>) <code>imports</code> take a string argument( eg. <code>imports("com.x.y.MyClass")</code>) and based on <code>string</code> it create a relative path and append it to head tag as script ( <code>type = text/javascript</code>). using <code>imports</code> I can attach any javascript file of my project main page.</p> <p><code>namespace</code> can take 2 to 3 paramaters ( eg. <code>namespace("com.x.y", "MyClass", "google.maps.Marker")</code> or <code>namespace("com.x.y", "MyClass" )</code> )</p> <p>if we call <code>var clssObj = new com.x.y.MyClass( param1, param2 )</code> then it searches for function <code>MyClass</code> and calls it if it exists.</p> <pre><code>imports("com.x.y.HelperClass1"); imports("com.x.y.HelperClass2"); imports("com.x.z.OtherClass"); namespace("com.x.y","MyClass","MyBaseClass").Class = function(){ var ... .. .; function privateFunc(){ this.baseclassFunction(); \\ since Myclass is a prototype of MyBaseClass var otherClass = com.x.z.OtherClass(); } this.publicFun = function(){ privateFunc(); }; this.MyClass = function( param1, param2 ){ this.base();// calling base class costructor var helperObj1 = com.x.y.HelperClass1(); var helperObj2 = com.x.y.HelperClass2(); }; }; </code></pre> <p>Is it possible to add all imported class as <code>MyClass</code> private variable? as in Java instead of using <code>com.x.y.HelperClass2</code> we use <code>HelperClass2</code> only.</p>
javascript
[3]
2,411,434
2,411,435
Is there an easy way in Python to wait until certain condition is true?
<p>I need to wait in a script until a certain number of conditions become true?</p> <p>I know I can roll my own eventing using condition variables and friends, but I don't want to go through all the trouble of implementing it, since some object property changes come from external thread in a wrapped C++ library (Boost.Python), so I can't just hijack <code>__setattr__</code> in a class and put a condition variable there, which leaves me with either trying to create and signal a Python condition variable from C++, or wrap a native one and wait on it in Python, both of which sound fiddly, needlessly complicated and boring.</p> <p>Is there an easier way to do it, barring continuous polling of the condition?</p> <p>Ideally it would be along the lines of</p> <pre><code>res = wait_until(lambda: some_predicate, timeout) if (not res): print 'timed out' </code></pre>
python
[7]
4,954,364
4,954,365
Change parameters according to phone orientation
<p>I would like to set up these parameters</p> <pre><code>IF (the phone is in vertical orientation) imageView.setLayoutParams(new Gallery.LayoutParams(400, 400)); ELSE () imageView.setLayoutParams(new Gallery.LayoutParams(600, 600)); </code></pre>
android
[4]
114,591
114,592
jquery settimeout function
<p>I try to learn the magic behind ajax-php configuration so that i tried to implement a code like a clock via php. But, it seems i am still missing something. Here is what i did so far.</p> <p>HTML(starting the clock when it is clicked)</p> <pre><code>&lt;div id="bu" onclick="clock()"&gt;asccasascascsc&lt;/div&gt; </code></pre> <p>JS</p> <pre><code>&lt;script type="text/javascript"&gt; var a = 0; function clock() { $.ajax({ type: "GET", url: "asd.php", data: { 'p':a }, dataType: "json", cache: false, success: function(data) { $('#bu').html(data.p); setTimeout (clock (),10000 ); }, }); } &lt;/script&gt; </code></pre> <p>In here i wanted to replace "bu" with an integer 1 and create a loop to increase that number every 1 second. I know that setTimeout function works only once(I am a liar from where i read it:)) But i am calling it every single time.</p> <p>PHP(asd.php)</p> <pre><code>&lt;?php $asd = $_GET['p']; $asd++; $data = array(); $data['p'] = $asd; echo json_encode($data); ?&gt; </code></pre> <p>PHP is where i did te increment part.</p> <p>So, why is it not working? I am only seeing 1 but no more. Note: I am pretty new as you can see:)</p>
jquery
[5]
451,940
451,941
How to direct users to my android app store
<p>I know this question has been asked and answered before. But when I try the following code:</p> <pre><code>Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=your.game.package.name")); startActivity(intent); </code></pre> <p>I get the message "the method parse(String) is undefined for the type String.</p> <p>Could it be I need to import something? I have imported android.net.URI</p>
android
[4]
453,778
453,779
Use jQuery to scroll all the way down
<p>I've got some list items that get shown when the user clicks a button, the button is at the very bottom of the page, so if the user clicks a few times they are forced to continue scrolling down to see the button.</p> <p>I want to set the scroll bar to the very bottom when the user clicks the button.</p>
jquery
[5]
4,392,836
4,392,837
Google Map V3 infowindows
<p>I’m developing a website that incorporates a Google map v3 and I would like to know how to programmatically close the infowindows that can be opened when the user clicks on the icons that are loaded with the map. I don’t mean the infowindows opened when the markers the site places on the map are clicked on. </p> <p>Is this possible?</p> <p>Thanks in advance</p>
javascript
[3]
3,817,340
3,817,341
How to render a variable inside another?
<p>I want to place the variable $all right in the middle of $code, which is HTML code that I gathered from another file. My current code is like this.</p> <pre><code>ob_start(); ---code here--- $all = ob_get_clean(); $code = file_get_contents("file.txt"); echo $code; </code></pre> <p>file.txt would look a little something like this.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Title&lt;/title&gt; &lt;/head&gt; &lt;body&gt; ---HTML code here--- $all ---More HTML code--- &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What should I do so that when I echo $code, $all is rendered inside it?</p>
php
[2]
1,417,481
1,417,482
no cpickle module
<p>When I tried</p> <pre><code>import cpikcle as pickle </code></pre> <p>I got an error message saying <code>no module named cpickle</code>. </p> <p>Does anybody know how to get <code>cpickle</code> module?<br> Because I heard that <code>cpickle</code> is faster than <code>pickle</code>.</p> <p>Thanks</p>
python
[7]
1,530,960
1,530,961
Async P/Invoke calls
<p>I'm working on a wrapping library for a robot controller, that mostly relies on P/Invoke calls.</p> <p>However, a lot of the functionality for the robot, such as homing, or movement, takes quite a while, and do thread locks while running.</p> <p>So I'm wondering how I can wrap the functionality in a async manner, so the calls don't block my UI thread. My idea so far is to use Tasks, but I'm not really sure it's the right approach.</p> <pre><code>public Task&lt;bool&gt; HomeAsync(Axis axis, CancellationToken token) { return Task.Factory.StartNew(() =&gt; Home(axis), token); } </code></pre> <p>Most of the MSDN articles on the Async model in .NET as of right now, mostly is relaying on libraries already having Async functionality (such as File.BeginRead and so on). But I can't seem to find much information on how to actually write the async functionality in the first place.</p>
c#
[0]
5,600,211
5,600,212
Accessing the message body before or after received to inbox
<p>` package com.example.smsTest;</p> <pre><code>import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.widget.Toast; public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { //---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i&lt;msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); str += "SMS from " + m sgs[i].getOriginatingAddress(); str += " :"; str += msgs[i].getMessageBody().toString(); str += "\n"; } //---display the new SMS message--- Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } } }` </code></pre> <p>This the code whic receives my sms sent.. But i could display it to inbox.. I am trying to decrypt it and den send it to the inbox.. or at least make use of inbox message and decrypt it... So is there any way to access the text body before or after receiving the message to inbox.</p>
android
[4]
2,515,773
2,515,774
Adding 30 days to date giving one day less
<p>I am adding 30 days to a date but its giving me 1 day less.</p> <p>i.e. if I put 20 oct 2011 then it is giving 19 Nov 2011 one day less .</p> <p>Please suggest me some solution. </p>
java
[1]
3,850,669
3,850,670
Checking argv[] against a string? (C++)
<p>So I'm attempting to check the arguments that I'm inputting into my program, and one of them is either the word "yes" or "no", entered without the quotes. </p> <p>I'm trying to test equivalency ( if (argv[n] == "yes") ) but that seems to be returning false every time when the input is, in fact, yes(When I output it it confirms this). What am I missing here that I'm doing improperly? If I understand properly argv[n] returns a cstring that is null-terminated, so it should allow me to do this.</p>
c++
[6]
4,492,100
4,492,101
Transparent Panel in android
<p>how to use Transparent Panel in List View.. </p>
android
[4]
335,905
335,906
generate random long number in C++
<p>We know that to generate random long number we do following steps in Java</p> <pre><code>Random r=new Random() return r.nextLong(); </code></pre> <p>what will be equivalent of this code in C++? like this?</p> <pre><code>return (long) rand(); </code></pre>
c++
[6]
1,016,651
1,016,652
When i am trying to upload it in market it shows.. "You need to reduce your APK file size to 50MB or use APK Expansion Files."
<p>My project apk file size is 101mb,When i am trying to upload it in market it shows.. "You need to reduce your APK file size to 50MB or use APK Expansion Files."</p>
android
[4]
3,430,666
3,430,667
Android: TabLayout not working
<p>I was trying the TabLayout Tutorial from official developers site. I didnt copy paste it as such and some minor changes and corrections to typos in the tut.</p> <pre><code>package com.org.example; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.widget.TabHost; public class HalloTabLayout extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent; TabHost tabhost = getTabHost(); TabHost.TabSpec tabspec; Resources res = getResources(); //For the Family Tab //Intent intent = new Intent().setClass(this, FamilyLayout.class); //Setting the tab tabspec = tabhost.newTabSpec("family").setIndicator("Family", res.getDrawable(R.drawable.tab_spec)).setContent(intent); tabhost.addTab(tabspec); //Default tab to display tabhost.setCurrentTabByTag("family"); } </code></pre> <p>}</p> <p>As a first step and make sure the code is right, I wanted to have a Single tab displayed.</p> <p>I added the FamilyLayout activity to AndroidManifest.xml file and also made changes suggested in here. <a href="http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example">http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example</a></p> <p>But the application keeps crashing on run time in the emulator. Any help would be much appreciated. </p> <p><strong>[Solution:]</strong> I used a .jpeg of high resolution and size(3.5mb) which was cause of trouble. I changed it into a lower resolution, size pic and it worked without troubles. I found out via trial and error that images beyond 1600*900 will make apps crash. Not an exact statistic, but it may help.</p>
android
[4]
4,611,752
4,611,753
Android menu controls
<p>I am developing an application and I would like to use the control that I can see in the Photos application and the Desk Clock (on an HTC Desire).</p> <p>The one I am referring to is the bar along the bottom of the screen that has various icons in it. When you press on an icon, the bubble moves along the bar to the icon you have pressed and the icon is then shown in colour.</p> <p>What is the name of this control? </p>
android
[4]
1,564,931
1,564,932
how to genarate Json for jsTree
<p>i found yestarday the jsTree plugin, it's great. Have sombody a SQL sample to create the json for it?</p>
jquery
[5]
5,487,041
5,487,042
How to convert an H:MM:SS time string to seconds in Python?
<p>Basically I have the inverse of this problem: <a href="http://stackoverflow.com/questions/775049/python-time-seconds-to-hms">Python Time Seconds to h:m:s</a></p> <p>I have a string in the format H:MM:SS (always 2 digits for minutes and seconds), and I need the integer number of seconds that it represents. How can I do this in python?</p> <p>For example:</p> <ul> <li>"1:23:45" would produce an output of 5025</li> <li>"0:04:15" would produce an output of 255</li> <li>"0:00:25" would produce an output of 25</li> </ul> <p>etc</p>
python
[7]
496,284
496,285
Does variable assignment with var do not execute right away in Javascript?
<p>I'm asking this, because when I try to debug code by using safari console, I found </p> <blockquote> <p>my_string = 'abc'</p> <p>"abc"</p> </blockquote> <p>it return the the string itself in the console right away</p> <p>but with var</p> <blockquote> <p>var my_string = 'abc'</p> <p>undefined </p> </blockquote> <p>Does this mean with var, the expression of variable assignment do not execute or evaluate right away?</p>
javascript
[3]
3,262,740
3,262,741
Any good site that teaches C++?
<p>I am searching for any good site that teaches C++, that can explain most to all things about it(general) and has a decent active community.</p> <p>About Me: I am new to programming(knows nothing of it, so please bare with me), I have only learned(to a very basic form) LUA scripting Language, so yes I am your complete newbie.</p> <p>I got interested in programming, from scripting in LUA, so you can say it was my small stepping stone, One would basically take a course in college, but not everyone is well funded for that and I can't buy books for the same said reason(yes I'm somewhat poor, only money for essentials and bills), I'm not trying to get sympathy, just stating my conditions.</p> <p>and Please, something in between the lines of 'Programming for Dummies'(I'm not the brightest crayon in the box), I know this will not be easy, but your help will be most appreciated.</p> <p>I would learn for either Windows and/or Linux/Unix. I use both.</p> <p>Site(s) I know: Cplusplus.org(quite inactive and tutorials are a little for the programming savvy.</p>
c++
[6]
4,439,984
4,439,985
Newbie to Python syntax - Error - suspect use of single/double quotes
<p>This is my first time using Python and I am receiving the attached message when attempting to run a script.</p> <p>here is the code (line 32 is the line starting "font-size:...":</p> <pre><code># County style 'font-size:12px;fill-rule:nonzero;stroke:#FFFFFF;stroke-opacity:1; stroke-width:0.1;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:butt; marker-start:none;stroke-linejoin:bevel;fill:' </code></pre> <p>Could any helpful person tell me whats up here?<img src="http://i.stack.imgur.com/uVCSv.png" alt="enter image description here"></p>
python
[7]
3,094,692
3,094,693
Jquery easy variables issue
<p>I am trying to pass the variables to callback function in Jquery</p> <p>I have:</p> <pre><code>var test; $('.img').hover(function(){ test='this is test'; }, function (){ //how do I pass the test value to the callback function..?? console.log(test) }) </code></pre> <p>Thanks for the help.</p>
jquery
[5]
1,943,974
1,943,975
Loading picture show loading progress
<p>I use the function to show picture:</p> <pre><code>Bitmap imageBitmap = loadBitmap(URL); </code></pre> <p>loadBitmap() as below:</p> <pre><code>private Bitmap loadBitmap(String url) { try { Bitmap bm = BitmapFactory.decodeStream((InputStream)this.fetch(url)); return bm; } catch(Exception e) { e.printStackTrace(); return null; } } </code></pre> <p>And fetch() below:</p> <pre><code>public Object fetch(String address) { try { URL url = new URL(address); Object content = url.getContent(); return content; } catch(Exception e) { e.printStackTrace(); } return this; } </code></pre> <p>I want to show the loading progress or a load.png while it loading. And end with the picture loading finish and show it. How can I do? I try to make like ProgressDialog. But I don't know how to use?</p>
android
[4]
3,391,252
3,391,253
Python: elegant way of creating a list of tuples?
<pre><code>&gt;&gt;&gt; a=["a"]*4 &gt;&gt;&gt; a ['a', 'a', 'a', 'a'] &gt;&gt;&gt; b=range(4) &gt;&gt;&gt; b [0, 1, 2, 3] &gt;&gt;&gt; c = [range(4,8), range(9,13), range(14,18), range(19,23)] &gt;&gt;&gt; c [[4, 5, 6, 7], [9, 10, 11, 12], [14, 15, 16, 17], [19, 20, 21, 22]] &gt;&gt;&gt; &gt;&gt;&gt; result = map(lambda x,y:[x,y],a,b) &gt;&gt;&gt; map(lambda x,y:x.extend(y),result,c) &gt;&gt;&gt; result = map(tuple, result) &gt;&gt;&gt; result # desired output: [('a', 0, 4, 5, 6, 7), ('a', 1, 9, 10, 11, 12), ('a', 2, 14, 15, 16, 17), ('a', 3, 19, 20, 21, 22)] &gt;&gt;&gt; &gt;&gt;&gt; try_test = zip(a,b,c) &gt;&gt;&gt; try_test # NOT DESIRED: leaves me with the list within the tuples [('a', 0, [4, 5, 6, 7]), ('a', 1, [9, 10, 11, 12]), ('a', 2, [14, 15, 16, 17]), ('a', 3, [19, 20, 21, 22])] </code></pre> <p>I was wondering whether anyone has a more succinct way to do the "result"?</p>
python
[7]
475,114
475,115
Theoretically, would it be possible to allow multiple C++ templates to have the same name?
<p>It would be like function overloading. E.g. it is ok to do this:</p> <pre><code>void foo(int i) { ; } // Function overload ftw. void foo(int i, int j) { ; } </code></pre> <p>But it is not (yet) ok to do this:</p> <pre><code>template&lt;typename T&gt; class Foo { }; // Fail! template&lt;typename T1, typename T2&gt; class Foo { }; </code></pre> <p>Does this feature not exist in order simply to avoid confusion? Or is there some reason this wouldn't actually make sense?</p>
c++
[6]
622,976
622,977
Design item template with xaml
<p>I have to design a calculator like interface. i'm utterly confused with how to do this.can any provide me with an insight? how to bind data with these buttons at runtime.?</p>
c#
[0]
2,682,854
2,682,855
restrict NSArray to having only one kind of object
<p>i have two class Screen and control. now in screen class i have declare one NSArray variable and this variable should only contain control type object only(in c like control[]) how could i achieve this functionality?????</p>
iphone
[8]
3,153,371
3,153,372
option item selection in Dialog menu
<p>I have been running into some troubles recently and I think I need your help :). I am currently trying to show a menu on top of a dialog, I know that it could be far easier to launch a new activity yet doing so would compell me to store/pass a lot of data. I managed to show an optionmenu by writing a custom dialog and rewriting the oncreateOptionMenu method. My problem is I can't get any listener to these button, I tried to rewrite the onoptionitemselectedmethod but nothing happens. Ps: my dialog is nearly full screen so i can't see the activity dialog (i didn't find any put on top method)</p> <p>I would be glad to try any solution you could provide.</p> <p>Thanks a lot</p> <pre><code>public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(Menu.NONE,0,Menu.NONE,c.getString(R.string.home)); menu.add(Menu.NONE,4,Menu.NONE,c.getString(R.string.report)); return true; } public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); if(item.getItemId()==0){ getOwnerActivity().startActivity(new Intent(c,Home.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); } else if(l&gt;1) getOwnerActivity().startActivity(new Intent(c,report.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); else dismiss(); return true; } </code></pre>
android
[4]
6,004,372
6,004,373
Application close unexpectedly after calling web service if result is null
<p>i use the following lines in my program to call web service and taking the result</p> <p>all thing is fine, but if any time if a web page has no content it has null or white space then application close unexpectedly.</p> <pre><code> 1) SoapPrimitive result=null; 2) androidHttpTransport.call(SOAP_ACTION, envelope); //upto this line program run smoothly 3) result = (SoapPrimitive)envelope.getResponse(); </code></pre> <p>plz suggest me, how i handle this, because i can only check the result value after completion of 3 line, but error occur before completion of line number 3.</p> <p>i checked the envelop before result =(SoapPrimitive)envelope.getResponse(); but it not have any null, but i have still same problem</p> <p>waiting for reply</p>
android
[4]
5,505,195
5,505,196
Call Control Example Issue on Emulator
<p>I am testing call control example given on: <strong>http://prasanta-paul.blogspot.com/2010/09/call-control-in-android.html</strong> on emultaor.</p> <p>Code is as below:</p> <pre><code>package com.example.callblock; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.RemoteException; import android.telephony.TelephonyManager; import android.widget.Toast; import com.android.internal.telephony.ITelephony; public class CallBlock extends BroadcastReceiver{ String[] blockedNumbers = {"5556"}; String incommingNumber; Context context; String incomingNumber; ITelephony telephonyService; public void onReceive(Context context, Intent intent) { //Log.v(TAG, "Incoming Call BroadCast received..."); // Log.v(TAG, "Intent: ["+ intent.getAction() +"]"); Bundle b = intent.getExtras(); incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, "Phone no:"+incomingNumber, Toast.LENGTH_LONG).show(); // Additional Step // Check whether this number matches with your defined Block List // If yes, Reject the Call if(incommingNumber.equals(blockedNumbers[0])){ try { telephonyService.endCall(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } </code></pre> <p>When i tried to run this example ie make call from one emulator(5556) to the second emulator(5554). It shows <strong>Phoneno:null</strong>.</p> <p>I am unable to understand the reason for this.</p>
android
[4]
2,492,592
2,492,593
TypeError: sequence item 0: expected string, int found
<p>I am attempting to insert data from a dictionary into a database. I want to iterate over the values and format them accordingly, depending on the data type. Here is a snippet of the code I am using:</p> <pre><code>def _db_inserts(dbinfo): try: rows = dbinfo['datarows'] for row in rows: field_names = ",".join(["'{0}'".format(x) for x in row.keys()]) value_list = row.values() for pos, value in enumerate(value_list): if isinstance(value, str): value_list[pos] = "'{0}'".format(value) elif isinstance(value, datetime): value_list[pos] = "'{0}'".format(value.strftime('%Y-%m-%d')) values = ",".join(value_list) sql = "INSERT INTO table_foobar ({0}) VALUES ({1})".format(field_names, values) except Exception as e: print 'BARFED with msg:',e </code></pre> <p>When I run the algo using some sample data (see below), I get the error:</p> <blockquote> <p>TypeError: sequence item 0: expected string, int found</p> </blockquote> <p>An example of a value_list data which gives the above error is:</p> <pre><code>value_list = [377, -99999, -99999, 'f', -99999, -99999, -99999, 1108.0999999999999, 0, 'f', -99999, 0, 'f', -99999, 'f', -99999, 1108.0999999999999, -99999, 'f', -99999, 'f', -99999, 'f', 'f', 0, 1108.0999999999999, -99999, -99999, 'f', 'f', 'f', -99999, 'f', '1984-04-02', -99999, 'f', -99999, 'f', 1108.0999999999999] </code></pre> <p>What am I doing wrong?</p>
python
[7]
671,071
671,072
File is being used by another process
<p>I am developing a c# application, backend as sqlite.In my application i have an option for clean databse.It means the curren .db file will delete using File.Delete method and again it create empty databse using File.create method.Now let me explain the problem.</p> <p>To perform cleandatabse task, i have to stop all the process which is running ,after doing that if i click on clean database it is throwing an error that file cannot delete, it is being used by another process.i am able to stop all the thread which is running.</p> <p>Somehow i am able to find which process is blocikng the file ,</p> <pre><code>foreach (var process in Process.GetProcesses()) { var files = GetFilesLockedBy(process); if (files.Contains(filePath)) { procs.Add(process); Console.WriteLine(process.ProcessName); process.Kill(); File.Delete(filePath); } } </code></pre> <p>But in the above code i used process.Kill, which close the window form which i am running. without using kill, i tried close and dispose which doesn't work for me.</p> <p>Can you please help me to release the file from the process without closing the application and then yo delete the db file.</p> <p>Thank you in advance</p> <p>Best regards</p> <p>Sangita.</p>
c#
[0]
1,976,227
1,976,228
C# ambiguous call DataColumnCollection.Add(System.Data.DataColumn)' and 'System.Data.DataColumnCollection.Add(string)
<p>below is the code i'm using and i've used this 100x's before. And now it's throwing an error, basically i'm trying to dynamically create the Columns based on the first row of an excel file. The error that i'm receiving now is:</p> <p><code>The call is ambiguous between the following methods or properties: 'System.Data.DataColumnCollection.Add(System.Data.DataColumn)' and 'System.Data.DataColumnCollection.Add(string)'</code></p> <pre><code>DataTable excel_Holding_Table = new DataTable(); DataRow row; Microsoft.Office.Interop.Excel.Range range = workSheet.UsedRange; for (int i = 1; i &lt;= range.Columns.Count; i++) { excel_Holding_Table.Columns.Add(Convert.ToString(((Microsoft.Office.Interop.Excel.Range)workSheet.Cells[1, i]).Value2)); } </code></pre> <p>What do I need to do to prevent this from happening, this has never appeared.</p> <p>here is my using:</p> <pre>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; </pre>
c#
[0]
2,048,512
2,048,513
Acronym generator in javascript. It only grabs the first letter of the first word, but the not the other words
<p>Am I missing something in my code? It seems to only grab the first letter, and the while loop, doesn't go onto the next word. So what could I be missing?</p> <pre><code>function acr(s){ var words, acronym, nextWord; words = s.split(); acronym= ""; index = 0 while (index&lt;words.length) { nextWord = words[index]; acronym = acronym + nextWord.charAt(0); index = index + 1 ; } return acronym } </code></pre>
javascript
[3]
76,976
76,977
Check difference in seconds between two times
<p>Hi all I am currently working on a project where when a certain event happens details about the event including the time that the event occurred is added into a list array. </p> <p>Once the method has finished I then pass on the list to another method that checks its values. Before I go through the loop I check the current time of my PC and I need to check whether the difference between the time saved in the list array and the current time is greater than 5 seconds. </p> <p>How would I go about doing this. </p>
c#
[0]
5,158,413
5,158,414
What is the best way to implement a web service for Android?
<p>I post this question to get an idea about the best way to implement a web service for an Android application since I have confused on this.(I think this question is acceptable here)</p> <p>I have to implement a simple order management system for Android. The order management system working as follows.</p> <p>1.Sales person places a order using desktop client. </p> <p>2.This order details will be stored in MySQL database.</p> <p>3.Android user need to access that order(database) details remotly through a web service and he should be able to accept or reject the order.</p> <p>My question is, what is the best way to implement the web service to access the database as mentioned in No.3. What is most acceptable way for this procedure using java web service or PHP web service with json ??</p> <p>Please help! Thanks in advance.</p>
android
[4]
3,354,963
3,354,964
Finding minimum using recursion
<p>Ok, so I need to keep on getting the user inputs until they enter 0. I need to store them in an array and print out the minimum. But it keeps on giving me the last input number given instead of sorting and getting the minimum in the list. Here's what I've done so far.</p> <pre><code>import java.io.*; import java.util.*; public class FindingMin { public static void main(String[] args) throws IOException { int[] Numbers = new int[100]; int minimum = 0; int InputParser; String input= "1"; try { InputStreamReader stream = new InputStreamReader (System.in); BufferedReader scan = new BufferedReader(stream); InputParser = Integer.parseInt(input); while(InputParser != 0) { input = scan.readLine(); InputParser = Integer.parseInt(input); for(int i = 0;i&lt;Numbers.length;i++) { if(InputParser == 0) { InputParser = 0; } else Numbers[i] = InputParser; } } minimum = findingMin(Numbers,Numbers[0],Numbers.length-1); System.out.println("The minimum number is "+minimum); } catch(NumberFormatException exception) { System.out.println("Please enter integers only"); } } public static int findingMin(int[] list, int start, int end) { if (start == end) return list[start]; else { int Min = findingMin(list, start, end-1); if (Min &lt; list[end]) return list[end]; else return Min; } } } </code></pre> <p>Any suggestion will be greatly appreciated!</p>
java
[1]
4,725,401
4,725,402
Retrieving all entries except who are blocked query
<p>I have following table</p> <pre><code>id blocked blocker 1 2 1 2 4 2 3 xx xx 4 xx xx </code></pre> <p>Suppose i provide an id 2</p> <p>1- I want to perform a query in which both first and second result will be output.</p> <p>I am using following query </p> <pre><code>$statement = $conn-&gt;prepare('SELECT * FROM blocks WHERE blocker = :blocker OR blocked=:blocked'); </code></pre> <p>WILL THIS WORK?</p> <p>Now Once I got array of these entries that is </p> <pre><code>$row = $statement-&gt;fetchAll(PDO::FETCH_ASSOC) </code></pre> <p>Note: It must get all the row because I need their alternative values i-e 1 and 4 in above example.</p> <p>Secondly using above results, I have another table users. I want to perform a query which will get all entries except 1 and 4 (REFER TO TABLE ABOVE) will be output</p> <pre><code>id username password etc 1 2 3 4 </code></pre> <p>How can I perform these two queries without using much server resources.</p>
php
[2]
3,071,561
3,071,562
Minimizing Javascript
<p>Ok, so I just learned about minimizing JS to make it load quicker, so what I've been doing is copying that and putting it into the JSbeautifier. However, when I do this it comes back as like 7k lines of JS and I'm curious if this is just one function or a whole library or does it depend?</p>
javascript
[3]
1,167,799
1,167,800
How to remove issues in jQuery
<p>I wrote a small jQuery application recently to practise the language and got some feedback which criticised it in the following:</p> <ol> <li>you don't use any message passing in your functions,</li> <li>you had hard coded values for some of your data (eg: the colours),</li> <li>you had initalisation code embedded rather than extracted out into a separate JSON file</li> </ol> <p>But I dont really understand what they mean, and how I remove these issues.</p> <p>Can anyone give me rough examples of them, and the correct approach?</p> <p>Thanks for any help!</p>
jquery
[5]
1,461,252
1,461,253
Default.png
<p>Ok. I've got an openGL ES application up and running on the iPhone.</p> <p>And my project has a Default.png to show something other than a black screen on powerup.</p> <p>This image appears when I compile a DEBUG version for the simulator and the device. If I do a compile for the DEVICE in RELEASE mode, the image does not show up (black screen instead).</p> <p>I'm running OS3.0 Beta 5. Anyone got a clue?</p> <p>Thanks.</p>
iphone
[8]
5,467,504
5,467,505
How to show copy option in webview
<p>I want to show copy option in web view. When user select text from web view and when user select text then it show toast with message like text is copied into clipboard. So when user select text then what event called which copy the selected text into clipboard or any event which called after text copied into web view?</p>
android
[4]
3,264,317
3,264,318
C# antivirus block smtp check
<p>I am trying to check smtp server with the below method.</p> <p>Seems working fine, but there is a block alert from my antivirus.</p> <p>Is there anyway to check if the antivirus is blocking and then stop the smtp check?</p> <p>Thanks.</p> <pre><code>public static bool Check(string host, string port, string username, string password) { TcpClient tcpClient = new TcpClient(); tcpClient.Connect(host, Convert.ToInt32(port)); NetworkStream netStream = tcpClient.GetStream(); System.IO.StreamReader strReader = new System.IO.StreamReader(netStream); byte[] WriteBuffer = new byte[1024]; ASCIIEncoding enc = new System.Text.ASCIIEncoding(); WriteBuffer = enc.GetBytes("USER " + username + "\r\n"); netStream.Write(WriteBuffer, 0, WriteBuffer.Length); WriteBuffer = enc.GetBytes("PASS " + password + "\r\n"); netStream.Write(WriteBuffer, 0, WriteBuffer.Length); if (strReader.ReadLine().Contains("+OK")) { return true; } return false; } </code></pre>
c#
[0]
1,872,748
1,872,749
display text if value is 2 in echo statement?
<p>I have the following echo statement that displays a numerical value from a session:</p> <pre><code>&lt;?php echo(str_replace('"', '&amp;quot;', $row_WAATKgblqemplisting['Group'])); ?&gt; </code></pre> <p>How do I alter this statement so that if <code>$row_WAATKgblqemplisting['Group']</code> </p> <p>is equal to 2 it says: This is #2 if its equal to 1 it says: This is #1 and if its equal to 3 it says: This is #3?</p>
php
[2]
4,739,786
4,739,787
What's the point of passing a parameter by reference in C#?
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://programmers.stackexchange.com/questions/57068/why-are-objects-passed-by-reference">Why are objects passed by reference?</a> </p> </blockquote> <p>Doesn't C# send the objects themselves? So unless it's some kind of swap function for primitive typed variables - why would I send an object by reference?</p>
c#
[0]
3,011,520
3,011,521
How to apply a variable filter to this model?
<p><strong>I have this view how do I only iterate this unit model when the $wprice is > 1</strong></p> <pre><code>&lt;?php $model-&gt;getFeaturedVehicles(10, 0, unserialize($vtype), unserialize($makes), $p1range, $p2range, $filters) ?&gt; &lt;div id="adspecials"&gt;&lt;?php while ($unit = $model-&gt;iterate()): ?&gt; &lt;div class="adwrapper"&gt; &lt;div class="ad"&gt; &lt;h1 class="cufon"&gt;&lt;?php echo $unit-&gt;wprice,'&lt;/h1&gt;&lt;h4&gt;Preferred Club Pricing&lt;/h4&gt;' ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;?php endwhile; ?&gt; &lt;/div&gt; </code></pre>
php
[2]
201,590
201,591
How to open a file and find the longest length of a line and then print it out
<p>Here's is what I have done so far but the length function isn't working. import string</p> <pre><code>def main(): print " This program reads from a file and then prints out the" print " line with the longest length the line ,or with the highest sum" print " of ASCII values , or the line with the greatest number of words" infile = open("30075165.txt","r") for line in infile: print line infile.close() def length(): maxlength = 0 infile = open("30075165.txt","r") for line in infile: linelength = lengthofline if linelength &gt; maxlength: #If linelength is greater than maxlength value the new value is linelength maxlength = linelength linelength = line print ,maxlinetext infile.close() </code></pre>
python
[7]
3,111,301
3,111,302
Implementing smooth div toggle
<p>I am trying to recreate the "div toggle" effect on this page, but with jQuery:</p> <p>cordon-bleu.se</p> <p>I want this effect, but working like the above page: the visible div hides when you click to show another:</p> <p>sohtanaka.com/web-design/easy-toggle-jquery-tutorial/</p> <p>My javascript so far is:</p> <pre><code>$(document).ready(function(){ $("h2.menutrigger").click(function(){ $('.active').removeClass('active').slideToggle("slow"); $(this).next().addClass('active').slideToggle("slow"); }); }); </code></pre> <p>These are the divs I am trying to toggle:</p> <pre><code>&lt;div class="menuitem active"&gt; &lt;img src="images/img_header.png" style="margin: 15px auto;"/&gt; &lt;/div&gt; &lt;h2 class="menutrigger"&gt;&lt;a href="#"&gt;Historia&lt;/a&gt;&lt;/h2&gt; &lt;div class="menuitem"&gt; &lt;p&gt;Bla bla&lt;/p&gt; &lt;p&gt;Bla Bla&lt;/p&gt; &lt;/div&gt; &lt;h2 class="menutrigger"&gt;&lt;a href="#"&gt;Spisar&lt;/a&gt;&lt;/h2&gt; &lt;div class="menuitem"&gt; &lt;p&gt;Bla bla&lt;/p&gt; &lt;/div&gt; </code></pre> <p>And this is my (relevant) css:</p> <pre><code>.menuitem { height: 385px; background-color: #000; display:none; } .active { display: block; } </code></pre> <p>You can see <a href="http://rutinerad.com/projekt/cb_test/" rel="nofollow">here</a> how it works right now.</p> <p>I appreciate any help I can get.</p>
jquery
[5]
3,497,330
3,497,331
Recommended way to initialize variable in if block
<p>I have the following code (minus some other operations):</p> <pre><code>def foobar(): msg=None if foo: msg='foo' else: msg='bar' return msg </code></pre> <p>Is the following better practice for the <code>msg</code> variable? </p> <pre><code>def foobar(): if foo: msg='foo' else: msg='bar' return msg </code></pre> <p>I'm aware that I could simplify the above functions to ternary expressions, however there are operations in each if-else block that I've left out.</p>
python
[7]
5,268,625
5,268,626
Why isn't my @override for contains working?
<pre><code>@Override public boolean contains(Object o) { if ((this.name).equals((String) o)) { return true; } else { return false; } } </code></pre> <p>I get the error: The method c<code>ontains(Object)</code> of type <code>Team</code> must override or implement a supertype method</p>
java
[1]
2,582,538
2,582,539
Real-time audio capture and playback from an external mic
<p>How can I capture audio from an external mic plugged in the 3.5mm jack and play it back in real-time to the phone speaker?</p> <p>I'm able to capture the audio from that source, save it to a file and play it then to the speaker. However, when I try to mix the things, the audio is being captured from the in-built microphone.</p> <p>Any ideas?</p>
android
[4]
6,012,445
6,012,446
Dictionary out of list in python
<p>How can I create a dictionary out of the a in python?</p> <p>If I have a list like this:</p> <pre><code>a = ["Albert Einstein", "Nils Bohr"] </code></pre> <p>And I want it to become this:</p> <pre><code>b = {'Albert Eienstein': ['Albert', 'Eienstein'], 'Neils Bohr': ['Neils', 'Bohr']} </code></pre>
python
[7]