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,352,516 | 1,352,517 | JavaScript "normalize event object" | <p>This program taken from a book Pro JavaScript Techniques is used to create hover-like functionality for an Element.</p>
<p>I don`t understand what the author means when he says, in the comments, Normalize the Event object.</p>
<p>Can you tell me</p>
<p>a) why is this necessary, explaining what would happen if it wasn`t normalized</p>
<p>b) how does the code provide achieve the effect</p>
<p>Thank you.</p>
<pre><code>var div = document.getElementsByTagName('div')[0];
div.onmouseover = div.onmouseout = function(e) {
//Normalize the Event object
e = e || window.event;
//Toggle the background colover of the <div>
this.style.background = (e.type == 'mouseover') ? '#EEE' : '#FFF';
};
</code></pre>
| javascript | [3] |
5,702,706 | 5,702,707 | Hotkeys for web application buttons | <p>I have a command button on my web app, when I click on the button I want it to act like it is entering keystrokes (<kbd>Ctrl</kbd>+<kbd>O</kbd>). Is there any way to do this, and if so, how?</p>
| asp.net | [9] |
2,758,526 | 2,758,527 | How do I use jquery in comparing the two selectors? | <p>I have to compare two selectors and I was wondering why does this return false in firebug...and how do I compare two selectors</p>
<pre><code>$('.product-info:last') == $('.product-info:last')
</code></pre>
<p>this is what I have to do</p>
<pre><code> var previous = $('.product-info:visible');
if(previous == $('.product-info:last')){
return false;
}
</code></pre>
| jquery | [5] |
1,431,898 | 1,431,899 | What's the difference between /usr/lib/python and /usr/lib64/python? | <p>I was using ubuntu.</p>
<p>I found that many Python libraries installed went in both <code>/usr/lib/python</code> and <code>/usr/lib64/python</code>.</p>
<p>When I <code>print</code> a module object, the module path showed that the module lived in <code>/usr/lib/python</code>.</p>
<p>Why do we need the <code>/usr/lib64/python</code> directory then?
What's the difference between these two directories?</p>
<p><strong>BTW</strong></p>
<p>Some package management script and <code>egg-info</code> that lived in both directories are actually links to packages in <code>/usr/share</code>.</p>
<p>Most Python modules are just links, but the <code>so</code> files are not.</p>
| python | [7] |
5,790,624 | 5,790,625 | How to append a tag with specific id using Jquery? | <p>i want to append a tag to with different ids, for eg.</p>
<pre><code><div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id="4"></div>
</code></pre>
<p>if i use <code>$('div').append('<span>Hello World</span>);</code>
then it attached the <code><span></code> tag with every <code><div></code>, but i want to attach it to only 1 div based on it id. for example some time to 4 some times to 3 etc.</p>
| jquery | [5] |
898,345 | 898,346 | Database connection wrapper | <p>I have written the following class to make life easier for me:</p>
<pre><code>import pymssql
class DatabaseConnection:
def __init__(self):
self.connection = pymssql.connect(host='...', user='...', password='...', database='...', as_dict=True)
def select(self, statement, arguments={}):
cur = self.connection.cursor()
cur.execute(statement, arguments)
return list(cur)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
if self.connection:
self.connection.close()
</code></pre>
<p>I use it like this:</p>
<pre><code><script language = "Python" runat="server">
# get all that data we need to present on this asp page
with database.DatabaseConnection() as connection:
orders = connection.select('select * from ordersview')
special_orders = connection.select('select * from ordersview where paymenttype = %(paymentType)s', {'paymentType': 'Card'})
</script>
<script language = "Python" runat="server">
# later on lets use that data
for row in special_orders:
...
</script>
</code></pre>
<p>I intend on having a connection host class later to manage the database hosts I wish to connect to but for now I hard code this.</p>
<p>Have I done anything here which is not recommended or unsafe in your opinion? Is it a reasonable design? Is it ok to return list(cur) since the iterator will be out of scope otherwise, outside the with scope?</p>
<p>Thanks for your help,</p>
<p>Barry</p>
| python | [7] |
3,120,548 | 3,120,549 | JavaScript callback function | <p>please help
I have a simple example here
</p>
<pre><code><script type="text/javascript" language="javascript">
function test(callback1) {
callback1();
}
var f1 = function () {
alert(1);
}
</script>
</code></pre>
<p>Currently, parameter of the test function is a function, when abc button is clicked, test function will be called and then test will call f1. Everything okie with me.</p>
<p>However, I'd like a small change like this: parameter of the test function will be a string, I mean it should be a function name, test('f1') instead of test(f1).
Is it possible?How can I implement this?</p>
<p>Thanks</p>
| javascript | [3] |
1,184,181 | 1,184,182 | javascript split with multi separator & returning used separator to array? | <p>I have String</p>
<pre><code>var t = '@qf$q>@gf';
</code></pre>
<p>and array of separators</p>
<pre><code>var s = '@$>';
</code></pre>
<p>I would like to have a function which returns:</p>
<pre><code>var a = f(t,s);
// a is array = ["@","qf","$","q",">","@","gf"];
</code></pre>
<p>Can you help me ?</p>
| javascript | [3] |
4,743,412 | 4,743,413 | Solution for encoding $.ajax posts without JSON? | <p>I've been doing some research to find a solution to use $.ajax with JSON that can handle character encoding issues. Looking through past posts I've seen notes about contentType and other suggestions I've incorporated.</p>
<p>Long story short, an entry like "Bobs Resume" works in vanity_name, but "Bob's Resume" doesn't.</p>
<p>Wondering if there is something else I'm missing? </p>
<pre><code>var myData = {
resume_id : '<?php echo $this->session->userdata('resume_id'); ?>',
vanity_name: $('#vanity_name').val()
}
$.ajax({
type : 'POST',
url : '<?php echo site_url('resume/change_vanity_name'); ?>',
contentType : "application/x-www-form-urlencoded; charset=iso-8859-1",
data: myData,
dataType: "html",
success : function(msg){
$('#vanity_name_session').text($('#vanity_name').val());
},
error: function(){
alert('failure');
}
});
});
</code></pre>
| jquery | [5] |
3,756,568 | 3,756,569 | How can i filter missed cals data from CalLog information in android? | <p>My requirement is to filter missed/incoming/outgoing calls data from total cal log information programetically in Android?
can any one help me..</p>
<p>Thanks in advance..</p>
<p>Shiva.M</p>
| android | [4] |
897,315 | 897,316 | How to move a <tr> up or down within <table> via jQuery? | <p>What's the elegant way to do this?</p>
| jquery | [5] |
208,006 | 208,007 | Passing contents of array from one class to another | <p>I've got an array populating a small tableView in a DetailView class, and when the user presses a button I need the array to be sent to another View Controller, to populate a tableView there, but I'm having some difficulty getting it working. This is what I've been trying to do so far:</p>
<pre><code>*DetailViewController.m*
#import "DetailViewController.h"
#import "OtherViewController.h"
-(IBAction) toCart:(id)sender {
OtherViewController *oVC = [[OtherViewController alloc] init];
oVC.shoppingList = sList;
NSLog(@"Ingredients count %d", [sList count]); //This returns a number, so the sList definitely contains values, and the method is definitely being called.
[oVC release];
}
</code></pre>
<hr>
<pre><code>*OtherViewController.m*
#import "OtherViewController.h"
#import "DetailViewController.h"
@synthesize shoppingList;
-(void) viewWillAppear: (BOOL)animated {
NSLog(@"list count: %d", [shoppingList count]); // This returns 0
}
</code></pre>
<p>sList is populated elsewhere in the class, and sList and shoppingList are both declared in their respective .h files, with @property (nonatomic, retain)...</p>
<p>Any help much appreciated!</p>
| iphone | [8] |
472,518 | 472,519 | why javascript's charAt() with a string returns the first letter | <p>I am doing some exercises in my object-oriented javascript book, I notice that this:</p>
<pre><code>var a = "hello";
a.charAt('e'); // 'h'
a.charAt('adfadf'); //'h'
</code></pre>
<p>Why is the string in the argument seemingly evaluated to the integer 0 for the charAt() method for strings?</p>
<p>Edit: I was aware that the charAt()'s usage usually takes an integer, and the exercise feeds charAt() with a string, and I also was aware that the string is likely then to be coerced into an integer first, which I did verify to be NaN. Thanks Kendall, for suggesting putting this missing bit of information in the question proper</p>
<p>Thanks!</p>
| javascript | [3] |
269,473 | 269,474 | How do i make a copy of an object? Javascript | <p>I have a class in json format. I would like to make two instance. Right now (its pretty obvious why) when i 'make' two objects i really have 2 vars pointing to one. (b.blah = 'z' will make a.blah=='z')</p>
<p>How do i make a copy of an object?</p>
<pre><code>var template = {
blah: 0,
init: function (storageObj) {
blah = storageObj;
return this; //problem here
},
func2: function (tagElement) {
},
}
a = template.init($('form [name=data]').eq(0));
b = template.init($('form [name=data2]').eq(0));
</code></pre>
| javascript | [3] |
5,777,772 | 5,777,773 | Is there a way to call a function every time a jquery basic function is called? | <p>I would like everytime I call a jquery load function:</p>
<pre><code>$("#div").load("file.php");
</code></pre>
<p>To then call a separate function:</p>
<pre><code>function secondFunction() {
//do stuff
}
</code></pre>
| jquery | [5] |
2,838,202 | 2,838,203 | Simulate ASP.NET Page lifecycle | <p>I have an HttpHandler in which I want to render the HTML for some custom controls.</p>
<p>Currently my code looks like this:</p>
<pre><code>Page p = new Page();
var customControl = new CustomControl { Data = data, Blah = blah };
p.Controls.Add(customControl );
context.Response.Write(customControl.RenderToString());
</code></pre>
<p>The problem is that customControl (and child controls thereof) needs to do stuff in the OnInit, OnLoad and OnPreRender methods.</p>
<p>I have tried manually calling this methods through helper methods but I get various errors. My general problem is that I need the ASP.NET page lifecycle to run on the <code>p</code> variable. Is there any way to get that to work?</p>
| asp.net | [9] |
4,821,107 | 4,821,108 | Search Code in AJAX | <p>I perform one task to hear ........I am searching data like google search engine in performing that i can only select value using mouse how can I select that data using arrow key?
My code is below.</p>
<pre><code><html>
<head>
<script type="text/javascript">
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<input type="text" size="30" onkeyup="showResult(this.value)" />
<div id="livesearch"></div>
</form>
</body>
</html>
</code></pre>
| javascript | [3] |
4,959,427 | 4,959,428 | Java compiler behaviour question | <p>I have an interface & its implementation class in the same package. I using javac in commandline to compile them. I am able to compile the interface class successfully, but when try to compile the implementation class after compiling the interface class, I get the error - Symbol not found. However, as both the interface & its implementation are in the same folder, if I do a Javac *. I am able to compile both of them . </p>
<p>Can someone help me understand this behaviour ? Thanks for your time</p>
| java | [1] |
3,767,746 | 3,767,747 | Reducing lines of jQuery code, unnecessary repetition | <p>I am hoping to be able to reduce the repetition in the following code, which changes an image source and also the background image of a div when you click a numbered link.</p>
<p>I was thinking that since I numbered the variables and selectors in the same way (1, 2, 3...) I could rewrite the click function part in less lines to avoid having to change this every time I change the number of images? Maybe the click function could get its own class (eg 2) and apply it to the other lines?</p>
<p>Images (can be any number)</p>
<pre><code>var image1 = 'Home.jpg';
var image2 = 'About.jpg';
var image3 = 'Contact.jpg';
</code></pre>
<p>Click function (currently repeats to cover all images above)</p>
<pre><code>$('.1').click(function() {
$("#image").attr('src', image1);
$('#center').css('background', 'url(' + image1 + ') no-repeat center top');
});
$('.2').click(function() {
$("#image").attr('src', image2);
$('#center').css('background', 'url(' + image2 + ') no-repeat center top');
});
$('.3').click(function() {
$("#image").attr('src', image3);
$('#center').css('background', 'url(' + image3 + ') no-repeat center top');
});
</code></pre>
<p>HTML</p>
<pre><code><a href="#" class="1">Option 1</a>
<a href="#" class="2">Option 2</a>
<a href="#" class="3">Option 3</a>
</code></pre>
<p>You can see the code in action here: <a href="http://carolineelisa.com/zack/" rel="nofollow">http://carolineelisa.com/zack/</a></p>
<p>Any suggestions for making this smaller and easier to update would be greatly appreciated!</p>
| jquery | [5] |
4,703,550 | 4,703,551 | JavaScript book question | <p>Hey everyone I just purchased the book JavaScript demystified to read and learn JavaScript but I just noticed that it was published in 2005 and it references netscape browsers and other "pratices" I believe are out dated like using the language attribute in the script tag and also not ending each line with a semicolon</p>
<p>My main question is has javascript changed so much since this book was published that reading this book not teach me what I need to know or could it still be a good reference?</p>
| javascript | [3] |
5,816,335 | 5,816,336 | What is beneficial about this program?? When using Pointer to Setter and Getters | <pre><code>class Animal
{
public:
void setName(string *Animal_Name);
void setAge(int *Animal_Age);
string getName();
int getAge();
private:
string Name;
int Age;
};
</code></pre>
| c++ | [6] |
2,269,613 | 2,269,614 | Strange output when compiling c++ code. Any Ideas? | <p>When i compile my code i get a set of errors that appear to related to the output files as in the .o file. I'm not sure why these sorts of errors would occur. Any Ideas?</p>
<pre><code>/tmp/ccjPLJVV.o: In function `PubSub::~PubSub()':
Video_process.cpp:(.text._ZN6PubSubD2Ev[_ZN6PubSubD5Ev]+0x12): undefined reference to `vtable for PubSub'
/tmp/ccjPLJVV.o: In function `main':
Video_process.cpp:(.text.startup+0x34): undefined reference to `vtable for PubSub'
Video_process.cpp:(.text.startup+0xeb): undefined reference to `PubSub::run()'
/tmp/ccjPLJVV.o:(.rodata._ZTI13Video_process[typeinfo for Video_process]+0x10): undefined reference to `typeinfo for PubSub'
collect2: ld returned 1 exit status
</code></pre>
<p>This is essentially the output i'm getting when I attempt to compile.</p>
| c++ | [6] |
4,274,956 | 4,274,957 | How do I iterate over cin line by line in C++? | <p>I want to iterate over cin, line by line, addressing each line as a std::string. Which is better:</p>
<pre><code>string line;
while (getline(cin, line))
{
// process line
}
</code></pre>
<p>or</p>
<pre><code>for (string line; getline(cin, line); )
{
// process line
}
</code></pre>
<p>? What is the normal way to do this?</p>
| c++ | [6] |
146,319 | 146,320 | Downloading a file cause error when it contains spaces - PHP | <p>Consider that i am uploading a file with following names:</p>
<ol>
<li>test.pdf</li>
<li>test file.pdf</li>
</ol>
<p>When i download the test.pdf it's working fine.. </p>
<p>But when i download test file.pdf it doesn't. <strong>The case is the space between the file name.</strong></p>
<p><strong>Unfortunately i should not change the file name when i upload (If i can i will set "_" using str_replace between spaces and resolve this issue).</strong></p>
<p><strong>Now how should i download the file ?</strong> </p>
<p>My code is given below:</p>
<pre><code>header('Content-disposition: attachment; filename=test file.pdf');
header('Content-type: application/pdf');
readfile('test file.pdf');
</code></pre>
<p>Thanks in advance...</p>
| php | [2] |
3,689,525 | 3,689,526 | Not able to add a System.Windows.Controls.TextBox to groupbox controls in C# | <p>Is there any way to add a <code>System.Windows.Controls.TextBox</code> to <code>GroupBox</code> controls in C#?</p>
<p>I tried the following but it doesn't show up in the groupbox:</p>
<pre><code> public System.Windows.Controls.TextBox textBox6 = new System.Windows.Controls.TextBox();
public System.Windows.Controls.TextBox textBox7 = new System.Windows.Controls.TextBox();
public ElementHost sumtext = new ElementHost();
public ElementHost loctext = new ElementHost();
private void Form1_Load(object sender, EventArgs e)
{
textBox6.Name = "Summary";
textBox7.Name = "Location";
textBox6.FontFamily = new System.Windows.Media.FontFamily("Microsoft Sans Serif");
textBox6.FontSize = 12;
textBox6.SpellCheck.IsEnabled = true;
textBox7.FontFamily = new System.Windows.Media.FontFamily("Microsoft Sans Serif");
textBox7.FontSize = 12;
textBox7.SpellCheck.IsEnabled = true;
groupBox4.Controls.Add(sumtext);
sumtext.Dock = DockStyle.None;
sumtext.Width = 246;
sumtext.Height = 35;
sumtext.Child = textBox6;
sumtext.Location = new Point(3, 33);
sumtext.Visible = true;
sumtext.Enabled = false;
groupBox4.Controls.Add(sumtext);
groupBox4.Controls.Add(loctext);
loctext.Dock = DockStyle.None;
loctext.Width = 246;
loctext.Height = 35;
loctext.Child = textBox7;
loctext.Location = new Point(3, 90);
loctext.Visible = true;
loctext.Enabled = false;
this.Controls.Add(sumtext);
this.Controls.Add(loctext);
}
</code></pre>
<p>I need to use <code>System.Windows.Controls.TextBox</code> rather than <code>Form.TextBox</code> as I need it for spell check.</p>
<p>Any help would be greatly appreciated! </p>
| c# | [0] |
5,327,026 | 5,327,027 | Load event triggers server side script before script has loaded | <p>I have an iframe that has a onload event. This event called a function (iframe_load) that I placed into a server side script. It appears that when my screen is launched, the onload event is triggered before the server side script has loaded and I get an error as the function is not found. </p>
<p>I have got around this by changing the onload event to call a checking function (iframe_check_load) in the client side script. This checks for the existence of parameter in the server side script, where if found it will then call the original function (iframe_load). </p>
<p>However ideally I would prefer not to have this checking funtion and to keep the client side code to a minimum. Is there a way I can add some code to the onload event to do this check, without having to use the checking function? </p>
<p>My current code:</p>
<pre><code>function iframe_check_load(ctrl) {
if(typeof iframe_flag != "undefined"){
iframe_load();
}
}
<IFRAME id=iFrame2 onload=iframe_check_load() ></IFRAME>
</code></pre>
<p>I am sure there must be better ways to do all of this, please go easy as I'm stil learning JS!</p>
<p>Many thanks</p>
<p>Mark</p>
| javascript | [3] |
2,709,431 | 2,709,432 | How to avoid global variable with incrementing function? | <p>Here is my self-executing function:</p>
<pre><code>var incrementInt = (function() {
var manyOut = 10;
if(incInt) {
incInt+=manyOut;
} else {
var incInt = 0;
}
return {
s: incInt,
m: manyOut
};
})();
</code></pre>
<p>I have privatized the variables incInt and manyOut, and tied the variable incrementInt to the returned object.</p>
<p>My goal is to create a function that returns an object where one property is an integer that increments every time that it is called. I would like the incrementing variable to have the most narrow scope possible.</p>
<p>My problem with the solution I have above is that the variable incInt is re-initialized every time the function is called. Due to its scope within the function, the variable is destroyed automatically.</p>
| javascript | [3] |
2,372,027 | 2,372,028 | Constructing a temp object and calling a method that returns a pointer - is it safe? | <p>My intution says it isn't, but the fact that everything is going on in the same line is a bit confusing. I wonder if the pointer is still valid when <code>cout</code> uses it.</p>
<pre><code>#include <iostream>
#include <string>
struct A {
A() : m_s("test"){ }
const char* c_str() { return m_s.c_str(); }
std::string m_s;
};
int main() {
std::cout << "abc " << A().c_str() << " def" << std::endl;
}
</code></pre>
| c++ | [6] |
2,016,171 | 2,016,172 | Forcing application to use a dll in a specific folder | <p>I am responding to a pervious post :</p>
<p><a href="http://stackoverflow.com/questions/8505784/how-to-force-a-vb6-program-to-use-a-dll-in-a-specified-folder">How to force a VB6 program to use a dll in a specified folder?</a></p>
<p>(Although the application I have is not an application written in VBA - but Java)</p>
<p>I have added an empty txt file in the same folder as my .exe application. </p>
<p>IpmGun.exe.local</p>
<p>In the same folder is also the mqic32.dll which the application is using. Unfortunately it does not work. When if run IpmGun.exe I get "Server DLL (MQIC32.dll) not loaded"</p>
<p>Any ideas how to bridge this problem?</p>
| java | [1] |
1,387,400 | 1,387,401 | how to call a base class method by super keyword | <pre><code>class base
{
public void superMethod()
{
System.out.println("Hello i m a super class method");
}
}
class der extends base
{
super.superMethod();// error identifier expected
}
</code></pre>
<p>i need to call a base class method without overloading it into derive class please provide me solution for it</p>
| java | [1] |
1,362,005 | 1,362,006 | PHP Multiple condition if statement returning nothing | <p>I have been trying to figure this out for weeks, it is a simple statement yet it never executes the if statement. I'm echoing the variables to the screen so I know they exist and each condition is true, but the echo "something" never executes.</p>
<pre><code> if ($db_a==$session_a && $db_b==$session_b && $dbfreq_b=="1")
{
echo "something";
}
</code></pre>
<p>I thought it was just the brackets as I had this originally:</p>
<pre><code>if (($db_a==$session_a) && ($db_b==$session_b) && ($dbfreq_b=="1"))
</code></pre>
<p>I am comparing variables stored in a MYSQL database with session variables. </p>
<p>If I use Var_dump the db variables are null, yet they echo the expected string value to the screen. </p>
<pre><code>$db_a="username";
$session_a="username";
$db_b=="keyword string"; -mostly one word but could be multiple
$session_b=="keyword string";
$dbfreq_b="1"; - This is the frequency that the keyword appears in the MYSQL database
</code></pre>
<p>using vardump $db_a and $db_b are NULL yet they echo what I am expecting to see to the browser.</p>
<p>Hopefully this explains things a bit more?</p>
<p>Thank you for the very prompt help!!</p>
| php | [2] |
5,305,953 | 5,305,954 | Python debugging tips | <p>What are your best tips for debugging Python?</p>
<p>Please don't just list a particular debugger without saying what it can actually do.</p>
<h3>Related</h3>
<ul>
<li><a href="http://stackoverflow.com/questions/299704">What are good ways to make my Python code run first time?</a> - This discusses minimizing errors</li>
</ul>
| python | [7] |
4,216,602 | 4,216,603 | graphs used to compare two datasets? | <p>I have two data sets, each dataset contains the pixel values of an image. I need to verify the difference of two datasets is a linear or something like that.</p>
<p>which open libraries can be used to draw graph to compare two datasets using C#?</p>
<p>Thanks in advance. </p>
| c# | [0] |
1,910,390 | 1,910,391 | How to add Transition between videos using AVMutableVideoComposition | <p>I have a problem adding transitions between videos. I successfully merge two videos using AVMutableComposition. I also see AVEditDemo sample. How do I add transitions between videos? Please provide me a way how to achieve this. </p>
<p>Thanks in advance. </p>
| iphone | [8] |
2,238,943 | 2,238,944 | Android View Flipper | <p>I have two Activity ActivityOne and ActivtyTwo.This two has Corresponding XML Files main.xml and main1.xml.if i press the next button in ActivityOne ActivityTwo appears with animation.is it possible through viewflipper</p>
| android | [4] |
5,498,194 | 5,498,195 | How to change the value of id or name? | <p>Example:</p>
<pre><code><table id ='table'>
<tr>
<td>1</td>
<td><select id='old' name='old'></select></td>
<td><select id='old2' name='old2'></select></td>
<td><div id='old3' name='old3'></div></td>
</tr>
</table>
</code></pre>
<p><strong>How to change the value of id or name</strong> from select id ='<em>old</em>' to select id ='<em>new</em>' (for example) after deleting rows in javascript?
I have been trying all the methods like trying getElementById('old') = 'new' but not work, used replaceChild also not work (or maybe I put the wrong code, no idea).
Do you have other alternatives? (No JQuery, please).</p>
<p>Thanks.</p>
| javascript | [3] |
811,094 | 811,095 | JavaScript Math (parameter passing, arrays, and the "apply" method) | <p>1) Why does the <code>function smallest</code> fail? I think it conforms to the example in the Mozilla documentation <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/min" rel="nofollow">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/min</a>, which says</p>
<pre><code> function getMin(x,y) { //from Mozilla documentation
return Math.min(x,y)
}
function smallest(array){ //my own experimentation with Resig`s example
return Math.min(array);
}
function largest(array){ //from John Resig`s learning advanced JavaScript #41
return Math.max.apply( Math, array );
}
assert(smallest([0, 1, 2, 3]) == 0, "Locate the smallest value.");
assert(largest([0, 1, 2, 3]) == 3, "Locate the largest value.");
</code></pre>
| javascript | [3] |
60,430 | 60,431 | How do I make a toast display for this specific edit text field | <p>Hi I am kind of stuck here, I have an activity which lets the user create a transaction from his bank account, the activity has some text fields.One of the text field is for balance entry. When the user enters the balance he wants to withdraw there should be an internal checking of the balance present already in the user's account. I know how to create the internal checking, the problem is that when the user enters an amount in that particular text field there should be a toast displayed letting the user know that he has entered an invalid balance withdraw request,or something like that. How can I do this? Are there any listeners for accessing that particular text field?Thanks.</p>
| android | [4] |
3,657,409 | 3,657,410 | How to display a webpage from a python program? | <p>I've got a list of webpages that I need to categorise so I'm trying to write a script in python that will display the webpage and then depending on a key press it will save the url of that webpage to a different file depending on the key.</p>
<p>However I'm not sure what would be the easiest way to display the webpages from the urls I've got?</p>
<p>Thanks</p>
| python | [7] |
2,156,851 | 2,156,852 | Why does this global Javascript variable behave differently inside and outside of a function? | <p>I'm trying to understand why my global variable 'imageUrl' behaves differently inside and outside of the function 'genericOnClick()'</p>
<pre><code>var imageUrl
var id = chrome.contextMenus.create({
"title": "Add to JC Queue",
"contexts": ["image"],
"onclick": genericOnClick
});
function genericOnClick(info) {
imageUrl = info.srcUrl;
console.log(imageUrl);
chrome.tabs.create({
url: chrome.extension.getURL('dialog.html'),
active: false
}, function (tab) {
// After the tab has been created, open a window to inject the tab
chrome.windows.create({
tabId: tab.id,
type: 'popup',
focused: true
});
});
}
console.log(imageUrl);
</code></pre>
<p>Please let me know where I am going wrong:</p>
<ol>
<li>Declare imageUrl as a global variable</li>
<li>Declare id as a global variable and run a function OnClick()</li>
<li>Log imageUrl to the console inside the function (it displays fine)</li>
<li>Log imageUrl to the console after the function runs (it is undefined)</li>
</ol>
| javascript | [3] |
1,919,535 | 1,919,536 | Any workarounds for non-static member array initialization? | <p>In C++, it's not possible to initialize array members in the initialization list, thus member objects should have default constructors and they should be properly initialized in the constructor. Is there any (reasonable) workaround for this apart from not using arrays?</p>
<p>[Anything that can be initialized using only the initialization list is in our application far preferable to using the constructor, as that data can be allocated and initialized by the compiler and linker, and every CPU clock cycle counts, even before <code>main</code>. However, it is not always possible to have a default constructor for every class, and besides, reinitializing the data again in the constructor rather defeats the purpose anyway.]</p>
<p>E.g. I'd like to have something like this (but this one doesn't work):</p>
<pre><code>class OtherClass {
private:
int data;
public:
OtherClass(int i) : data(i) {}; // No default constructor!
};
class Foo {
private:
OtherClass inst[3]; // Array size fixed and known ahead of time.
public:
Foo(...)
: inst[0](0), inst[1](1), inst[2](2)
{};
};
</code></pre>
<p>The only workaround I'm aware of is the non-array one:</p>
<pre><code>class Foo {
private:
OtherClass inst0;
OtherClass inst1;
OtherClass inst2;
OtherClass *inst[3];
public:
Foo(...)
: inst0(0), inst1(1), inst2(2) {
inst[0]=&inst0;
inst[1]=&inst1;
inst[2]=&inst2;
};
};
</code></pre>
<p><b>Edit</b>: It should be stressed that <code>OtherClass</code> has no default constructor, and that it is very desirable to have the linker be able to allocate any memory needed (one or more static instances of <code>Foo</code> will be created), using the heap is essentially <i>verboten</i>. I've updated the examples above to highlight the first point.</p>
| c++ | [6] |
4,438,880 | 4,438,881 | how to use the schedule method | <p>How shall I use Timer class schedule method?My requirement is that the task that I will write in the schedule method should run once a day.Can anybody please write the required signature for the method?</p>
| java | [1] |
4,827,062 | 4,827,063 | how to solve this type of compilation error? | <pre><code>import java.net.*;
import java.io.*;
public class DjPageDownloader {
public URL url;
public InputStream is = null;
public DataInputStream dis;
public String line;
public static void main(String []args){
try {
url = new URL("http://stackoverflow.com/");
is = url.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
while ((line = dis.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
</code></pre>
<p>this on compilation shows error as:-</p>
<pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot make a static reference to the non-static field url
Cannot make a static reference to the non-static field is
Cannot make a static reference to the non-static field url
Cannot make a static reference to the non-static field dis
Cannot make a static reference to the non-static field is
Cannot make a static reference to the non-static field line
Cannot make a static reference to the non-static field dis
Cannot make a static reference to the non-static field line
Cannot make a static reference to the non-static field is
at djPageDownloader.DjPageDownloader.main(DjPageDownloader.java:16)
</code></pre>
| java | [1] |
3,470,487 | 3,470,488 | Get the value from one window to another window - javascript | <p>Is it possible to get the value from first page to second page.. BUT with out FORM</p>
<p>Shall we use window.parent.document.getElementById("").value..</p>
<p>But this is working in popup window, but i need this for between two pages which redirecting from first page to second page.</p>
| javascript | [3] |
2,907,175 | 2,907,176 | Use Strict : How to test it? | <p>I have been reading people recommending using "use strict" option. As mentioned <a href="http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/?utm_source=javascriptweekly&utm_medium=email" rel="nofollow">here</a></p>
<p>every major browser supports strict mode in their latest version, including Internet Explorer 10 and Opera 12. I wanted to test it with IE10 and i have following code segemnt. IE 10 /FF did not gave any error message. What am i missing ? How do i test that "use strict" is actually working if i make any mistake ?</p>
<pre><code><html>
<head>
<script type = "text/javascript">
"use strict";
function doSomething(value1, value1, value3) {
alert('hello');
}
</script>
</head>
<body>
hello
</body>
</html>
</code></pre>
| javascript | [3] |
3,479,446 | 3,479,447 | Classpath in Manifest | <p>I have download a xSocket.jar which will be use as a classpath and compile myprogram.jar, both are in Java folder.
Is adding a classpath in Manifest able to find xSocket.jar without the need to define a <code>-cp</code> in commandline?</p>
<p>In my commandline <code>D:\></code> location, I tried running <code>java -jar java\myprogram.jar -n 0</code></p>
<pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/xsocket/connectio
n/IBlockingConnection
at myprogram.main(myprogram.java:114)
Caused by: java.lang.ClassNotFoundException: org.xsocket.connection.IBlockingCon
nection
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 1 more
</code></pre>
<p>My Manifest in myprogram.jar:</p>
<pre><code>Manifest-Version: 1.0
Created-By: 1.6.0_22 (Sun Microsystems Inc.)
Main-Class: myprogram
Class-Path: xSocket
</code></pre>
| java | [1] |
5,876,068 | 5,876,069 | How can I access an object attribute that starts with a number? | <p>I'm working on an existing code base and got back an object with an attribute that starts with a number, which I can see if I call <code>print_r</code> on the object. </p>
<p>Let's say it's <code>$Beeblebrox->2ndhead</code>. When I try to access it like that, I get an error:</p>
<pre><code>Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$'
</code></pre>
<p>How can I get that attribute?</p>
| php | [2] |
2,275,985 | 2,275,986 | Why application is crashing during calling next activity in Android? | <p>Can any one suggest me, Why my application is crashing when calling next activity? I am having default frame animation in both activity which is running inside <code>onWindowFocuschanged()</code> method..is there any solution to run it smoothly.</p>
| android | [4] |
4,106,076 | 4,106,077 | What's going on with this Generic Factory | <p>I’ve been working on a generic factory recently which bypasses the ‘where’ constraint regarding constructors with parameters, and due to a mistake, I came across something which I don’t quite understand and wondered if anyone would be able to shine some light on it.</p>
<p>The lines of code in question are:</p>
<pre><code>ITestInterface myObj = new GenericFactory<ITestInterface>(
() => (new TestClass("username", "password"))
).CreateObject() as ITestInterface;
ITestInterface myNewObj = new GenericFactory<ITestInterface>(
(string x, string y) => (new TestClass(x, y))
).CreateObject("username ", " password") as ITestInterface;
</code></pre>
<p>Both of these lines do the same thing, but I expected the first one to fail.</p>
<p>The code in the factory is as follows:</p>
<pre><code>public GenericFactory (Func<T> getNewT)
{
_getNewObject = getNewT;
}
public GenericFactory(Func<string, string, T> getNewT)
{
_getNewObjectTwoParams = getNewT;
}
public T CreateObject ()
{
if (_getNewObject == null)
{
return default(T);
}
else
{
return _getNewObject();
}
}
public T CreateObject (string username, string password)
{
if (_getNewObjectTwoParams == null)
{
return default(T);
}
else
{
return _getNewObjectTwoParams(username, password);
}
}
</code></pre>
<p>The TestClass has the following constructor:</p>
<pre><code>public TestClass (string name, string password)
{
_name = name;
_password = password;
}
</code></pre>
<p>If anyone could shine some light on why the first call to the factory works I'd be very grateful.</p>
<p>Thanks.</p>
| c# | [0] |
4,130,690 | 4,130,691 | function.arguments question | <p>Please help me to understand following code:</p>
<p>Add method called 'later' to all objects. This method is used to call other method in future using <code>setTimeout</code>.</p>
<pre><code>Object.prototype.later = function (msec, method) {
// save 'this' as 'that' so we can use 'this' in inner function
var that = this;
// I cannot understand: what [2] means
// args will be ['Make is']. How?
var args = Array.prototype.slice.apply(arguments, [2]);
if (typeof method === 'string') {
method = that[method];
}
// now use setTimeout to call method in future
setTimeout(function () { method.apply(that, args); }, msec);
return that;
}
// example of using later method
var car = {};
car.make = 'Ford';
car.show = function (message) {
alert(message + ' ' + this.make);
}
car.later(1000, 'show', 'Make is');
</code></pre>
<p>So, when we call <code>car.later</code>, the third parameter is passed and will be used in <strong>alert</strong> function</p>
<p>Question is: how do we read third parameter "Make is"?</p>
| javascript | [3] |
4,216,005 | 4,216,006 | how to get values from a json to implement it in a drop down list? | <pre><code>var g_Vehicle = {
g_Vehicle1: [
Year: "2011",
Make: "abc",
Model: "Avenger",
SubModel: "def"
],
g_Vehicle2: [
Year: "2012",
Make: "abc",
Model: "200",
SubModel: "deft"
],
g_Vehicle3: [
Year: "2011",
Make: "dfg",
Model: "300",
SubModel: "sde"
],
}
</code></pre>
| jquery | [5] |
5,116,794 | 5,116,795 | Disabling "Force Stop" Button in Android | <p>Okay, I'm pretty sure that this is not possible but a client had asked me to do so in one of our Android application we developed for her.</p>
<p>What she had wanted is that if our application is running, and user navigate to:</p>
<pre><code> Settings > Manage Application > [Our Application]
</code></pre>
<p>, the button for "Force Stop" is disabled.</p>
<p>Is this possible? If it is possible, could someone point me out which way I should walk, or if it is not possible, how, using a valid argument based on facts, should I break the news to her.</p>
<p><strong>Update:</strong>
She just sent me a screenshot that, in her opinion, validates her request that there's an Android application that disables "Force Stop" button. How am I supposed to explain this to her?</p>
<p><img src="http://i.stack.imgur.com/akS25.png" alt="Evernote Launcher - Force Stop disabled"></p>
| android | [4] |
2,255,786 | 2,255,787 | LinQ Statement for filterings | <p>Im trying to filter out an <code>ObservableCollection<MainBusinessObject></code> where I need to filter all items in the collection that have <code>Subobject.PropertyX == true</code>.</p>
<pre><code> MainBusinessObject
- PropertyA int
- PropertyB string
- ListOfSubobject ObservableCollection<Subobject>
Subobject
- PropertyX bool
- PropertyY int
- PropertyZ - string
</code></pre>
<p>I really want to stay away from looping and if statements, but I can't seem to get the LinQ statements right. This is what I have so far:</p>
<pre><code>return (MainBusinessObjectCollection)
listOfMainBusinessObject.Where(x =>
(x as MainBusinessObject).CanBePartitioned == true);
</code></pre>
<p><strong>EDIT</strong>
I need to filter out the <code>ListOfSubobject</code> from the main business object</p>
| c# | [0] |
2,718,463 | 2,718,464 | java script dice game issue | <p>Having a slight issue calling a math.random image for a dice game. When I click the roll button the image does not change. I have the images saved where the .html file is. Any help is much appreciated!</p>
<p></p>
<p></p>
<pre><code><head>
<meta charset = "utf-8">
<title>Roll The Dice</title>
<link rel = "stylesheet" type = "text/css" href = "dice.css">
<script type="text/javascript">
var dieImage;
function start()
{
var button = document.getElementById(rollButton);
button.addEventListener("click", rollDice, false);
dieImage = document.getElementById("die1");
}
function rollDice()
{
setImage(dieImage);
}
function setImage(dieImg)
{
var dieValue = Math.floor(1 + Math.random() * 6);
dieImg.setAttribute("src", "die" + dieValue + ".jpg");
dieImg.setAttribute("alt", "dieImg with" + dieValue + "spots");
if (dieValue == 6)
{
document.getElementById("sometext").innerHTML = "You Win!";
}
else
{
document.getElementById("sometext").innerHTML = "Roll Again";
}
}
window.addEventListener("load", start, false);
</script>
</head>
<body>
<form action = "#">
<input id = "rollButton" type = "button" value = "Roll Dice">
</form>
<li>
<img id = "die1" src = "die1.jpg" alt = "blankImage">
</li>
<div id = "sometext">Roll for a 6!</div>
</body>
</code></pre>
<p></p>
| javascript | [3] |
426,700 | 426,701 | JSON Parsing Error? | <p>I am using JSON (SBJson) but it's giving the error :</p>
<pre><code>JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x5f2f7f0 {NSLocalizedDescription=Unrecognised leading character}.
</code></pre>
<p>am using this web service : "<a href="http://xoap.weather.com/search/search?where=India" rel="nofollow">http://xoap.weather.com/search/search?where=India</a>"
please give me the solutions why does error come?</p>
| iphone | [8] |
3,920,978 | 3,920,979 | reading a text file with specfic string | <p>I want to read a data from 'newline' to 'endline', create a separate file to store this data .
Iwant to repeat this process upto end of file. I am using .net 1.1.</p>
| c# | [0] |
3,178,307 | 3,178,308 | C# Visible windows but I don't want them to show up in Alt+Tab? | <p>I have a program I'm working that is a ticker across the bottom of the screen. All that functionality is fine, but I've noticed that when I hit Alt+Tab I see it in the list. I already have ShowInTaskbar set to false, but I don't want my program to appear in this list. Is there a property I'm forgetting about or a WinAPI call I can make to keep my app from showing up in Windows Alt+Tab?</p>
| c# | [0] |
4,407,705 | 4,407,706 | How to use CSS template in my ASP.net web site | <p>Hiii
I am using asp.net visual studio-2010 framework 3.5 on win 7. I have download readymade template designed made in css.I copied index.html code and paste it in masterpage and also copy the code of div content and paste it in content place holder.It's working. I want to add another page like about.html,sevice.html, etc.Plzz help me what the procedure to add another page
thank you.....</p>
| asp.net | [9] |
2,266,685 | 2,266,686 | 403 Forbidden on php mkdir | <p>I'm having a 403 Forbidden page when excecuting a php script with mkdir function.</p>
<p>here is the mkdir code:</p>
<pre><code>mkdir('uploads/'.$upload_folder.'/', 777)
</code></pre>
<p>I have tried 775, 666 permissions, but nothing.
Insde the dir i want to store images, mp3's and videos.
Can anyone help me?</p>
<p><em><strong>UPDATE 1</em></strong></p>
<p>here is the whole script:</p>
<pre><code>$folderStr = $_REQUEST['folderName'];
//create SEO firndly directory name
$upload_folder = preg_replace("'\s+'", '-', $folderStr);
// The place the files will be uploaded to (currently a 'files' directory).
$upload_path = 'uploads/'.$upload_folder.'/';
//Check whether folder exists or create with the name supplied
if(is_dir($upload_folder))
echo 'directory exists';
else
mkdir('uploads/'.$upload_folder.'/', 777);
</code></pre>
<p>It supposed to make a new directory into the folder "uploads" with the name given from the form which i get it from there with value 'folderName', and upload the files given from the form into the new dir which is created.
Also it can't write greek characters on the foldername. what i have to change to make it work?</p>
| php | [2] |
3,837,354 | 3,837,355 | TreeMap Iterator behaviour not consistent upon removal | <p>Today when tying to discover a bug I found the TreeMap iterator behavior a little strange when removing objects. In fact has I tested different uses, in a simple example: </p>
<pre><code> TreeMap<String, String> map = new TreeMap<String, String>();
map.put("1", "1");
map.put("2", "2");
map.put("3", "3");
map.put("4", "4");
map.put("5", "5");
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
System.out.println("Before "+entry.getKey());
iterator.remove();
System.out.println("After " +entry.getKey());
}
</code></pre>
<p>the result is:</p>
<pre><code>Before 1
After 1
Before 2
After 2
Before 3
After 3
Before 4
After 4
Before 5
After 5
</code></pre>
<p>But if I change it to:</p>
<pre><code> TreeMap<String, String> map = new TreeMap<String, String>();
map.put("1", "1");
map.put("2", "2");
map.put("3", "3");
map.put("4", "4");
map.put("5", "5");
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
String key = "4";
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
if(entry.getKey().equals(key)){
iterator.remove();
System.out.println(entry.getKey());
}
}
</code></pre>
<p>Then for key = 4 the result is 5 and for key = 5 the result is 5 due to the links being changed upon removal. But why are the behaviors different. JIT? Even if that is the answer, shouldn't they be uniform? </p>
| java | [1] |
4,311,818 | 4,311,819 | Using AJAX to make a call to the database | <p>What I would like to do here is to use these functions but when the user clicks the element, I need to make a call to the database with the id that was clicked.</p>
<p>I have about 6 of these buttons that I would like to implement so how would I utilize one function to do this? I'm thinking to use one function that would take an id param</p>
<pre><code>function toggle(id){
//I'm lost from here. :)
}
</code></pre>
<p>Also, do I need an AJAX call on the enable and disable toggles or can I use one call?</p>
<p>I'm not sure how any of this would be done. Can someone lend a hand?</p>
<pre><code> $(".enable").click(function(){
var parent = $(this).parents('.switch');
$('.disable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', true);
});
$(".disable").click(function(){
var parent = $(this).parents('.switch');
$('.enable',parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox',parent).attr('checked', false);
});
</code></pre>
| jquery | [5] |
3,422,433 | 3,422,434 | Null value when accessing object property created by decoding JSON string | <p>In my PHP script I need to decode a Json string and then transfer the decoded value to a class. Something like:</p>
<p>index.php</p>
<pre><code>$params = json_decode('input');
$obj = new User();
$obj->setParams($params);
$obj->Register();
</code></pre>
<p>class.php</p>
<pre><code>class User{
private $mParams;
public function setParams($params)
$mParams = $params;
}
public function Register(){
$username = $mParams->{'username'};
$password = $mParams->{'password'};
}
....
}
</code></pre>
<p>The problem is, in Register(), when I print the $username and $password, I just got NULL. But I'm sure the $params decoded from Json is not NULL because, if I print it in setParams, I can get username and password. And, if I directly transfer the $params to Register() everything is fine.</p>
<p>So I feel strange that why I can not set the $params to the class's member and then call the class's member function to access it.</p>
<p>Thanks,</p>
| php | [2] |
3,256,716 | 3,256,717 | Is <Button android:alpha="0.5"... API version 11+? | <p>The java <code>setAlpha()</code> method says that it is API level 11. but the XML side of it does not say anything and when I use it, it is not picked up in Lint as a warning since I have specified min SDK 8.</p>
<p>Will it crash on 2.2 if I use android:alpha="" ?</p>
| android | [4] |
3,490,347 | 3,490,348 | Is there a dynamic way of building java regular expressions for patterns? | <p>I'm converting a perl program to java. In the perl script a value that is read from a file is checked against hundreds of regex patterns. I would like not to do this statically as it's been done in the original perl program. Is there any sort of design pattern that can be used to make this more dynamic?</p>
<p>This is a single line of the current code:</p>
<pre><code>$flag++ if ($Part_Name =~ /(harmonic|nsg|white\ sands|sphix|battery|collection|allied)/i);
</code></pre>
<p>Now repeat that for another 50-60 lines and that's how many there are. The unique strings that are being tested against are in fact stand alone, all we care at the end is if ($flag > 0).</p>
| java | [1] |
5,285,927 | 5,285,928 | split function (list index out of range) | <pre><code>textData = "SENDER|%|SUB|%|HTML|%|username{*|*}password{*|*}mail{*|*}data1|*|username{*|*}password{*|*}mail{*|*}data1"
genelData = textData.split("|%|")
userData = genelData[3].split("|*|")
for userDataTable in userData:
usersData = userDataTable.split("{*|*}")
self.response.out.write("<br>" + usersData[2])
</code></pre>
<p>in this code i try to parse some string data.But when i try to print "usersData" variable everything looks fine.But when i tried to use like "usersData[2]" im getting list index out of range problem.</p>
| python | [7] |
4,538,488 | 4,538,489 | How do I pass a method as a parameter in python | <p>Is it possible to pass a method as a parameter to a method?</p>
<pre><code>self.method2(self.method1)
def method1(self):
return 'hello world'
def method2(self, methodToRun):
result = methodToRun.call()
return result
</code></pre>
| python | [7] |
945,734 | 945,735 | Try all the combinations (cases) Function | <p>I've been struggling with the <a href="http://en.wikipedia.org/wiki/Cutting_stock_problem" rel="nofollow">cutting stock problem</a> for a while, and I need to do a funcion that given an array of values, gives me an array of array for all the possible combinations.</p>
<p>I trying to do this function, but (as everything in python), I think someone must have done it better :).</p>
<p>I think the name of the function is combination. Does anyone know whats the best way to do this, and what's the best module and function for this</p>
<p>P.s. I have read some papers on the matter, but the matematical terms dazzle me :)</p>
| python | [7] |
2,067,228 | 2,067,229 | How to i set boundaries? android java | <p>How can i set bounds so my image which moves using acclerometer can only move a certain distance? Really need help been trying for a while and getting no where. I have an image moveing with my accelerometer but i want to set boundaries so it only moves within them, example i dont want it to move backwards and only a certain distance to the left and right and forward. </p>
| android | [4] |
4,941,976 | 4,941,977 | Negate the value going to less than 0 | <p>I have this code in the if else statement... I'm trying to block the textview value from going below 0, but it still goes below 0.</p>
<pre><code>else if(iv1.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.airplane2).getConstantState())){
int e =Integer.parseInt(textView5.getText().toString());
int f = e-1;
String s3 = String.valueOf(f);
textView5.setText(s3);
int dInt = Integer.parseInt(textView5.getText().toString());
if(dInt <= 0)
{
Toast.makeText(getApplicationContext(), "GameOver",Toast.LENGTH_SHORT).show();
}
}
</code></pre>
<p>P.S. sorry for my english i`ve lessen my code but it still goes to a negative value</p>
| android | [4] |
4,177,247 | 4,177,248 | Single sign on in two applications using windows identity foundation | <p>I have a two web application and a sts server. when user calls first web app it is redirected to sts server for validation. on validation the user logs in to the 1st web app. In my 1st web app there is a button when clicked should open the 2nd web app without me asking for
validation from sts server. Since I have added reference of sts in my second web app it is asking for validation again from sts server.</p>
<p>Can anyone please help me.</p>
<p>Thanks
Nilesh</p>
| c# | [0] |
5,190,292 | 5,190,293 | copy a class, C# | <p>Is there a way to copy a class in C#? Something like var dupe = MyClass(original).</p>
| c# | [0] |
5,749,665 | 5,749,666 | Extracting a string before a space | <p>the name Subhajit Sinha is entered in textbox.
how to extract only Subhajit in one textbox and Sinha in another textbox after clicking the Submit button in the form.</p>
| c# | [0] |
1,573,898 | 1,573,899 | What do numbers starting with 0 mean in python? | <p>When I type small integers with a 0 in front into python, they give weird results. Why is this?</p>
<pre><code>>>> 011
9
>>> 0100
64
>>> 027
23
</code></pre>
<p>Note: Python version 2.7.3
I have tested this in Python 3.0, and apparently this is now an error. So it is something version-specific. </p>
<p>Edit: they are apparently still integers:</p>
<pre><code>>>> type(027)
`<type 'int'>`
</code></pre>
| python | [7] |
120,664 | 120,665 | How to use IHTTPAsyncHandler? | <p>Imagine I have some code to read from the start to end of a file like so:</p>
<p>while(sw.readline != null)
{</p>
<p>}</p>
<p>I want this to be fully asynchronous. When deriving from IHTTPAsyncHandler, where would this code go and where would would the code to get the content of each line go? I'm a little confused of how to use this interface as I haven't seen a good example on the net.</p>
<p>Thanks</p>
| asp.net | [9] |
4,724,353 | 4,724,354 | Jquery check if parent has an ID | <p>Hi i'm trying to check if a parent element contains an ID</p>
<p>Here is my list</p>
<pre><code><ul>
<li></li>
<li id="selected">
<ul>
<li></li>
<li></li>
</ul>
</li>
<li></li>
</ul>
</code></pre>
<p>Don't know how to make a correct list in here?</p>
<pre><code>if (jQuery(LiElement).parent("#selected"))
{
//If parent has id=selected
}
else
{
//If parent dont have id=selected
}
</code></pre>
<p>Can someone help me please?</p>
| jquery | [5] |
4,155,180 | 4,155,181 | Is there a way to run short bits of Java code without compiling? | <p>Is there a way to run or simulate running Java statements (kind of like IDLE - the Python GUI) without compiling and running the executable? I want to quickly test statements to see if they work. Thanks.</p>
| java | [1] |
2,493,966 | 2,493,967 | x+=y+=z in Javascript | <p>I know in javascript</p>
<p><code>x = y = z</code> means <code>x = z</code> and <code>y = z</code></p>
<p><code>x+=z</code> means <code>x=x+z</code>;</p>
<p>So if I want <code>x=x+z</code> and <code>y=y+z</code>, I tried <code>x+=y+=z</code> not working</p>
<p>anyone have a better idea to write short code instead <code>x+=z;y+=z</code></p>
<p><strong>EDIT</strong></p>
<p>First thanks for everyone involved in my question.
Here I wanna explain something why I have this question in first place.</p>
<p>I tried to write some code like <code>x+='some html code'</code>, and I need to <code>y+='the same html code'</code>. So naturally I do not want to create another <code>var z='the html code</code> first then do <code>x+=z</code> and <code>y+=z</code></p>
<p>Hope my explain make sense. Anyway, I am going to close this question now. Thanks again.</p>
| javascript | [3] |
3,809,142 | 3,809,143 | How to remotely log in and call an API? | <p>Let's abstract away the difficulties of the world and suppose that this fellow here has currently one HTML page with two forms in his arsenal. They look like this:</p>
<pre><code> <form method="POST" action="foobar.com/login"> ...
<form method="POST" action="foobar.com/getstuff"> ...
</code></pre>
<p>The first logs in a remote server, setting cookies and so on, and the second one sends a request to that server to show data.</p>
<p>How can I accomplish this task in PHP, logging in and fetching the data in a single page load? </p>
| php | [2] |
3,551,718 | 3,551,719 | Android Application Restriction | <p>Is there any way to install some kind of policy/certificate that will restrict applications. Such as only allow application signed by google or not allowing any applications that require gps? </p>
| android | [4] |
362,465 | 362,466 | Passing function as argument with variables inside - possible? | <p>Code: </p>
<pre><code>function remove_comment(){
var id = "bla";
Msg().prompt( "blabla" , function(){ Ajax().post( "id=" + id ) } , id );
}
Msg().prompt( txt , fn , args ){
$( elem ).click( fn );
}
</code></pre>
<p>As you can notice, I need to pass this function to prompt(), while inside the passed function one of the arguments depends on the variable <code>id</code>.</p>
<p>Now, after the function passed I need it to be assigned to an element's onclick event (the code abode is not using jQuery).</p>
<p>First, I'd tried to do this:
<code>$( elem ).click( fn.apply( this , id ) );</code>,
<code>$( elem ).click( fn.call( id ) );</code>, but these codes execute the function immediately (I already know why, no need to explain).
Then I'd tried to play with the function and arrange it as string to pass directly as <code>onclick='THE_FUNCTION'</code> html code to the element, but with no success.</p>
| javascript | [3] |
3,467,755 | 3,467,756 | How to throw new Exception gracefully | <p>How can I throw exception gracefully?</p>
<pre><code>public void Test()
{
if (error != 0) {
string msg = "Error";
throw new Exception(msg);
}
// Other function
...
}
</code></pre>
<p>I have also change the <code>throw new Exception(msg);</code> with logger</p>
<pre><code>public void Test()
{
if (error != 0) {
string msg = "Error";
//throw new Exception(msg);
logger.Error(msg);
}
// Other function
...
}
</code></pre>
<p>Should I use Exit function to exit the function when error hit?</p>
<p>Thnak you.</p>
| c# | [0] |
1,046,152 | 1,046,153 | substr_count and an array as a needle | <p>How to use substr_count with an array as a needle. Like this:</p>
<pre><code>substr_count($str, array('find_this', 'or_find_this'));
</code></pre>
| php | [2] |
3,926,998 | 3,926,999 | Does BroadcastReceiver.onReceive always run in the UI thread? | <p>in my App, I create a custom <code>BroadcastReceiver</code> and register it to my Context manually via <code>Context.registerReceiver</code>. I also have an <code>AsyncTask</code> that dispatches notifier-Intents via <code>Context.sendBroadcast</code>. The intents are sent from a non-UI worker thread, but it seems that <code>BroadcastReceiver.onReceive</code> (which receives said Intents) always runs in the UI thread (which is good for me). Is this guaranteed or should I not rely on that?</p>
| android | [4] |
4,869,869 | 4,869,870 | Sending Emails (Java) | <p>The code below opens up Outlook Email as soon as a button is pressed.
Is there a way to automatically attach a file to the mail as well along with a subject possibly?</p>
<pre><code>public void onSubmit() {
try {
Desktop.getDesktop().browse(new URI("mailto:username@domain.com"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
</code></pre>
<p>I tried changing the Desktop line to this. Should this work? Its not compiling though:</p>
<pre><code> Desktop.getDesktop().browse(new URI('mailto:username@domain.com?subject=New_Profile&body=see attachment&attachment="xyz.xml"'));
</code></pre>
| java | [1] |
546,592 | 546,593 | how to convert 24-hour format TimeSpan to 12-hour format TimeSpan? | <p>I have TimeSpan data represented as 24-hour format, such as 14:00:00, I wanna convert it to 12-hour format, 2:00 PM, I googled and found something related in stackoverflow and msdn, but didn't solve this problem, can anyone help me? Thanks in advance.</p>
<p><strong>Update</strong>
Seems that it's possible to convert 24-hour format TimeSpan to String, but impossible to convert the string to 12-hour format TimeSpan :(</p>
<p>But I still got SO MANY good answers, thanks!</p>
| c# | [0] |
3,754,517 | 3,754,518 | How do you investigate python's implementation of built-in methods? | <p>I'm currently going through a basic compsci course. We use Python's <code>in</code> a lot. I'm curious how it's implemented, what the code that powers <code>in</code> looks like. </p>
<p>I can think of how <em>my</em> implementation of such a thing would work, but something I've learned after turning in a couple homework assignments is that my ways of doing things are usually pretty terrible and inefficient.. So I want to start investigating 'good' code. </p>
| python | [7] |
4,894,195 | 4,894,196 | Who set IsPostBack's value in asp.net | <p>I want to know in which event or process asp.net page set/update the value of IsPostBack.
How page figure out it value?</p>
| asp.net | [9] |
3,110,414 | 3,110,415 | How do i calcalate using the padding | <p>I am trying to do some calculation with the height of an element and i need to factor in the padding of an element.</p>
<pre><code>var element_top = $(".box").position().top;
var element_height = $(".box").height();
var element_padding = $(".box").css("padding");
</code></pre>
<p>the first two give me numbers i can user for addition and subtraction but the the padding gives me 8px...any ideas...I am trying to use the padding to subract from the height to get the actual height from the box element</p>
| jquery | [5] |
3,460,216 | 3,460,217 | How to make a rounded corner image in Java | <p>I want to make a image with rounded corners. A image will come from input and I will make it rounded corner then save it. I use pure java. How can I do that? I need a function like</p>
<pre><code>public void makeRoundedCorner(Image image, File outputFile){
.....
}
</code></pre>
<p>Thanks</p>
<p><img src="http://i.stack.imgur.com/fm0VA.png" alt="Schema"></p>
<p><strong>Edit</strong> : Added an image for information.</p>
| java | [1] |
1,369,589 | 1,369,590 | Android -Adding content to bottom of ListView instead of top | <p>I writing list view which must should always show message at bottom of list not at top. I want it also to auto scroll to this point whenever I add a new item. The ListView is for a chat which displays latest item at bottom of list view. Thanks</p>
| android | [4] |
227,414 | 227,415 | Get parent object within jQuery callbacks | <p>This is my issue:</p>
<pre><code>var greatapp = {
start : function(){
$.AJAX({
url : 'foo.com',
success : function(data){
greatapp.say(data);
}
})
},
say : function(s){
console.log(s);
}
}
</code></pre>
<p>What i don't like about this example is the fact that i repeat my self in the <code>success</code> function by defining the object's name instead of just <code>this</code> which obviously won't work because it's in an <em>external</em> function.</p>
<p>How to only have the name <code>greatapp</code> one time in a JS object?</p>
| javascript | [3] |
852,146 | 852,147 | check to see if value exists then display different pages based on reply | <p>I have a mysql database set up, i was wondering if it is possible to check the mysql database for a value (e.g. a username) and then report back if the username exists load one activity, if not load another. all of this done on an android app</p>
<p>Thanks</p>
| android | [4] |
5,203,314 | 5,203,315 | display original image color with UIBarButtonItem | <p>I used codes below to display a image on an UIBarButtonItem</p>
<pre><code>UIBarButtonItem *myButtonItem;
myButtonItem= [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image.png"] style:UIBarButtonItemStylePlain target:self action:@selector(pressB:)];
</code></pre>
<p>but the image color is two colors(red/blue), but the image displayed on the ButtonItem is white.</p>
<p>Iy looks like IOS change it to white color automatically.</p>
<p>Welcome any comment</p>
| iphone | [8] |
687,729 | 687,730 | simple php code syntax error | <p>What is wrong with this code. It's giving me syntax error in the editor</p>
<pre><code>$posts = if($row['plans'] == 1000) { 2 } elseif($row['plans'] == 1001){ 8 }else{ $row['posts'] }
</code></pre>
| php | [2] |
2,271,981 | 2,271,982 | Android create Insert statemnet at runtime | <p>I have fileds list & values list.I want to insert records using DBAdapter.I tried from this link <a href="http://mfarhan133.wordpress.com/2010/10/24/database-crud-tutorial-for-android/" rel="nofollow">http://mfarhan133.wordpress.com/2010/10/24/database-crud-tutorial-for-android/</a></p>
<pre><code> DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(Insert.this);
dbAdapter.openDataBase();
ContentValues initialValues = new ContentValues();
initialValues.put("name", etName.getText().toString());
initialValues.put("age", etAge.getText().toString());
long n = dbAdapter.insertRecordsInDB("user", null, initialValues);
Toast.makeText(Insert.this, "new row inserted with id = " + n, Toast.LENGTH_SHORT).show();
</code></pre>
<p>Please anybody help me how to send the fields & their values at runtime.Please help me as soon as possible</p>
| android | [4] |
4,195,212 | 4,195,213 | findViewById(R.id.list_view); returning "null" | <p>I am trying to display <code>ListView</code>.</p>
<p>I have created one <code>activity</code> , in <code>onCreate()</code> method I am launching one <code>AsyncTask</code> and in <code>onPostExecute()</code> method I am trying display <code>ListView</code> in that .</p>
<p>but <code>listView</code> object receiving null..</p>
<p>Below is the code snippet.</p>
<pre><code> protected void onPostExecute(KpiResponseObject kpiReportResponse) {
ListView listView;
listView = (ListView) findViewById(R.id.list_view);
}
</code></pre>
<p>Here I'am receiving null in <code>listView</code> object.</p>
<p>I am suspecting this is the <code>context</code> problem , but not able figure out what exactly it is.</p>
| android | [4] |
3,816,551 | 3,816,552 | using another web site in the same domain from our web site | <p>we have a ASP.NET web site that all our clients use to view their information. We have created another web site that would be used to create online forms. we want to call this new web site pages from our web site. This way the user can create online forms from our web site. We are thinking of using iframe to point to the new web site from our web site. we are not sure of what kind of problems we might run into. Both the web sites will be in the same domain. we do not want to redirect the users to the new web site. we just want to call the new web site pages from our existing web site. </p>
<p>Thanks,
Sridhar.</p>
| asp.net | [9] |
642,940 | 642,941 | mysql_fetch_array() expects parameter 1 to be resource | <pre><code><?php
//connect to MYSQL
$con=mysql_connect("localhost","root","");
if (!$con)
{
die ('cannot connect:'.mysql_error());
}
//to show the original message
mysql_select_db("tracking", $con);
$result = "SELECT lat, lng, DATE_FORMAT(datetime,'%W %M %D, %Y %T') AS datetime FROM markers1 WHERE 1";
if (!$result) { // add this check.
die('Invalid query: ' . mysql_error());
}
echo "<table border='1'>
<tr>
<th>id No</th>
<th>lat Time</th>
<th>lng</th>
<th>datetime</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['lat'] . "</td>";
echo "<td>" . $row['lng'] . "</td>";
echo "<td>" . $row['datetime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
</code></pre>
<p>It show me mysql_fetch_array() expects parameter 1 to be resource.</p>
<p>Can anyone help me .thx.</p>
| php | [2] |
2,165,198 | 2,165,199 | php webserver equivalent of mongrel? | <p>Is there a php equivalent of mongrel? I don't want to install Apache, just to preview a simple template.</p>
| php | [2] |
3,093,855 | 3,093,856 | A + B in a two tables and return to C | <p>Okey this is going to be difficult to make my mind go trough.
I have tables in my DB called "Member", and one "Workout", and one "MemberWorkout".</p>
<p>Now i want to make a view on Visual Studio on the Member with a table with all of the Workouts possible for booking. So when i choose one workout and press the button "Book" it shall send the MemberName and the Workout informations that i just chose to "MemberWorkout". </p>
<p>I now wonder what is the best way of doing this? I simply just need some kind of guidence. I wonder if the datagridview is the best way for this or if there is something better for my process. </p>
| c# | [0] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.