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,415,415 | 1,415,416 | How to get natural order of values? | <p>Below code is not giving me order of values .Please correct me to get order of values while printing .</p>
<pre><code>Iterator<Search> iterator = parts.iterator();
MultiHashMap pen = new MultiHashMap();
StringBuilder sb = new StringBuilder();
List list = null;
while(iterator.hasNext()) {
Search req = (Search)iterator.next();
String product = req.getProduct();
sb.append(req.getreqspart());
sb.append(" ");
sb.append(req.getOp()));
sb.append(" ");
pen.put(product, sb.toString());
sb.setLength(0);
req.getProductDescr();
req.getreqspart();
req.getreqprod();
}
Set set = pen.entrySet();
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
list = (List)pen.get(me.getKey());
int itemCount = list.size();
for (int z = 0; z < itemCount; z++) {
String values = "";
for(int j = 0; j < list.size(); j++) {
values += list.get(j) + " ";
}
System.out.println(me.getKey() + ": value :" + values);
}
}
</code></pre>
| java | [1] |
6,026,553 | 6,026,554 | Android programming using eclipse, | <p>I need to know how to develop database driven application, i have three tables. how to put data in database and how to report them?</p>
| android | [4] |
5,703,864 | 5,703,865 | how to get the date-time for a particular city in C#? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city">Web service - current time zone for a city?</a> </p>
</blockquote>
<p>Just wondering whether there is a public web service (without reading from local machine time zone) that I could use to get the current date-time in that city using C#. </p>
| c# | [0] |
3,075,707 | 3,075,708 | How to handle the more than two images in the tableview? | <p>Iam developing one application.In that i use the 4 rows for table view.Each row contain the imageview.Every imageview canget the image from CAMERA.My problem is after getting the third image,images will be appear at different positions.ANd if u scroll the tableviewthen imageviews will got the black color.Images not appeared.Please tell me how to solve this one.Is this memory problem or not.please tell me.</p>
| iphone | [8] |
1,074,444 | 1,074,445 | Getting hash tagged words from a string with PHP | <p>I am trying to create an array of all of the hash tags in a given string and then loop through them and echo each one to show that they have been stored. What could I be doing wrong?</p>
<pre><code><?php
$string= "Went for an awesome bike ride today! #biking";
preg_match_all('/#(\w+)/',$string, $matches);
foreach ($matches as $tag) {
echo $tag;
}
?>
</code></pre>
| php | [2] |
3,001,489 | 3,001,490 | Issue getting the height of an element | <p>I'm trying to get the height of an element with jQuery, but for some reason it always returns <code>0</code>.</p>
<p>I load content using ajax in a container. This content is hidden by default (<code>display: none</code>). Before showing the content I need to retrieve the height of an element in the new content.</p>
<p>Which <a href="http://jsfiddle.net/vgTDr/" rel="nofollow">should work</a>.</p>
<p>My simplified code:</p>
<pre><code>success: function(data) // this is the success callback of jquery's ajax call
{
var content = $('#content');
content.fadeOut('slow', function() {
content.html(data.html);
set_comments_height();
content.fadeIn('slow');
});
}
function set_comments_height()
{
var content = $('#content');
var info = $('.trackinfo .artwork-and-info', content);
console.log(parseInt(info.outerHeight(true), 10));
}
</code></pre>
<p>You can see the issue on <a href="http://new.upcoming-djs.com" rel="nofollow">my website</a> after clicking a track at the left side.</p>
<p>I might be missing something here, but I don't see why it doesn't return the correct height.</p>
| jquery | [5] |
4,027,691 | 4,027,692 | Failsafe looping trough array of urls | <p>How can I loop trought an array of external websites and not fail catastrophically if one of the websites doesn't respond? Consider the following psuedo code:</p>
<pre><code>$urls = array(list of urls);
foreach ($urls as $url) {
try {
$page = get_page($url);
$title = $page['title'];
catch(Exception $e) {
continue;
}
}
</code></pre>
<p>What i want to happen is to try and load page, if it doesn't respond then skip to the next url in the list. The problem is $title is set to blank. I tried grouping the code in a function but I still can't get the error exception to skip whole blocks of code.</p>
| php | [2] |
2,223,010 | 2,223,011 | <T> cannot be resolved to a type | <p>I want to change the return type of this method to a class (<code>ReturnContainer</code>) that can hold the <code>tupelo</code> object in addition to another return value that I need to send back to the calling method.</p>
<p>I've never worked with this <code><T></code> concept in Java before so I don't how to reconfigure this method to work the way I need it to.</p>
<pre><code>public static <T extends LocationCapable> List<T> test(Class<T> incomingClass)
{
List<TestTuple<T>> tupelo = new ArrayList<TestTuple<T>>();
return tupelo;
}
</code></pre>
<p>When I try to change the code to the listing below, I get the error:</p>
<pre><code>T cannot be resolved to a type
</code></pre>
<p><strong>How can I have a return type of <code>ReturnContainer</code> but still allow the incomingClass to be a dynamic type?</strong></p>
<pre><code>public static ReturnContainer test(Class<T> incomingClass)
{
List<TestTuple<T>> tupelo = new ArrayList<TestTuple<T>>();
ReturnContainer rc = new ReturnContainer(tupelo, incomingClass);
return rc;
}
</code></pre>
| java | [1] |
2,539,339 | 2,539,340 | jQuery assign css class to divs in loop | <p>I have these html structure here,</p>
<pre><code><div class="myCaption">
<h2>caption 1</h2>
<h2>caption 2</h2>
<h2>caption 3</h2>
<h2>caption 4</h2>
<h2>caption 5</h2>
</div>
</code></pre>
<p>I wonder how to use jquery to add a Class "active" to the first <strong>H2</strong> tag, and then every e.g, <strong>2 second</strong>, switch the "active" class from the first <strong>H2</strong> tag to the second <strong>H2</strong> tag and then to the third.....when come to the last H2 tag, it will loop again to the first <strong>H2</strong>, <strong>infinitely</strong>. Please advise. Thanks.</p>
| jquery | [5] |
581,835 | 581,836 | Cutting a string with regular expression | <p>I have a string containing some tags in it.</p>
<p>Example: <strong>asp.net vb6 crystal-reports</strong></p>
<p>I use a regular expression to cut this string into several tags like below:</p>
<pre><code>string[] technos = Regex.Split(technoString, @"\W+");
foreach (var techno in technos)
{
...
}
</code></pre>
<p>The problem is that this regular expression is wrong: it produces too much tags. I mean asp.net must be only one tag and crystal-reports must also be only one tag. </p>
<p>At this time, the regular expression gives me the following tags:</p>
<ul>
<li>asp</li>
<li>net</li>
<li>vb6</li>
<li>crystal</li>
<li>reports</li>
</ul>
<p>and I would like</p>
<ul>
<li>asp.net</li>
<li>vb6</li>
<li>crystal-reports</li>
</ul>
<p>Does someone know which regular expression to use?</p>
<p>Thanks.</p>
| c# | [0] |
335,556 | 335,557 | Return a random word from a word list in python | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random() * len(file))],
</code></pre>
| python | [7] |
2,652,024 | 2,652,025 | What ever happened to Java and Sun? | <p>What happened to Java and Sun? The community surrounding them had some of my favorite tools and software to develop with. The Java platform anyway, still looked like it had some promise to it: Groovy and Grails. Why does all of this seem to be going the way of the dodo lately?</p>
<p>(Yes, I know their stock price is dropping badly.) Is it just the economy? Or did the lack of cohesion (i.e., not settling on a framework) among the community finally lead to its demise?</p>
| java | [1] |
623,185 | 623,186 | How to call functions/methods inside objects in python | <p>Here is my code.</p>
<p>How do I execute the print_point line? <strong>Edited to work. Thank you</strong></p>
<pre><code>class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def distance_from_origin(self):
return ((self.x **2) + (self.y **2)) **.5
def print_point(p):
print '(%s, %s)' % (str(p.x), str(p.y))
</code></pre>
<p>Here is what I type into the shell after running module:</p>
<pre><code>p = Point(5,2)
p.x
5
p.y
2
p.distance_from_origin()
5.385164807134504
p.print_point(p)
Traceback (most recent call last):
File "<pyshell#196>", line 1, in <module>
p.print_point(p)
TypeError: print_point() takes exactly 1 argument (2 given)
</code></pre>
| python | [7] |
2,674,199 | 2,674,200 | prompt cancel button not working | <p>function name
I have give </p>
<pre><code>var name != " " || var name!= null
{
go
}
}
</code></pre>
<p>cancel is posting to next page.I should stop it.</p>
| javascript | [3] |
5,585,884 | 5,585,885 | .toggleClass not working with .live | <p>I'm trying to get a .toggleClass working on a form that I have multiple text/inputs in but its not working the way I'd like. I want all the input[type="text"] fields on the page to have this functionality. Some fields are static and some are added with .append and .live those are not working right. Basically I want a function that works for all fields static or dynamic.</p>
<h2>Code not working</h2>
<pre><code>$(document).ready(function(e) {
$(this).live('focusin, blur', function() {
$(':input[type="text"]').bind('focusin blur', function() {
$(this).toggleClass('fieldFocus');
})
});
});
</code></pre>
<h2>Works for static ones</h2>
<pre><code>$(':input[type="text"]').bind('focusin blur', function() {
$(this).toggleClass('fieldFocus');
});
</code></pre>
<p>I'm sure it's a basic problem, but for the life of me I can't figure it out.</p>
<p>Any help would be great! Thanks!</p>
<h2>Works!</h2>
<pre><code>$(document).ready(function(e) {
$(':input[type="text"]').live('focusin blur', function() {
$(this).toggleClass('fieldFocus');
});
});
});
</code></pre>
| jquery | [5] |
2,239,301 | 2,239,302 | Incorrect Device API version in android | <p>I am new to android. In my application I tried to call a SOAP web service, but when I run the project it says: Required API is 9,but Device API is 8.</p>
<p>What can I do for that. </p>
| android | [4] |
5,865,493 | 5,865,494 | Method signature through call stack introspection | <p>Is there any way of finding the signature of a called method through call stack introspection. Do we have any alternatives for finding out the same. I do not have the source code and have only bytecode files</p>
<p>Thanks in advance. </p>
| java | [1] |
91,343 | 91,344 | How to create grid button on iphone. 10/10 matrix | <p>How to create Grid of Buttons on iphone.
10/10 matrix...</p>
<p>I found NSMatrix for MAC ... Not for iphone...</p>
<p>any alternative way to create grid of button on my view.</p>
<p>@Thanks in advance.</p>
| iphone | [8] |
5,083,488 | 5,083,489 | Android package replace intent | <p>In my application I am listening for following 3 intents by using broadcast receiver.</p>
<pre><code>ACTION_PACKAGE_REPLACED
ACTION_PACKAGE_REMOVED
ACTION_PACKAGE_ADDED
</code></pre>
<p>The problem is that whenever I reinstall some application First I get
<code>ACTION_PACKAGE_REMOVED</code> then I get <code>ACTION_PACKAGE_ADDED</code> then I get <code>ACTION_PACKAGE_REPLACED</code>.</p>
<p>Is there any way to know that in reinstallation of application the <code>ACTION_PACKAGE_REMOVED</code> and <code>ACTION_PACKAGE_ADDED</code> intents belongs to <code>ACTION_PACKAGE_REPLACED</code>. I mean these are not the intents when only application is removed and installed respectively.</p>
<p>Thx
Dalvin</p>
| android | [4] |
6,023,239 | 6,023,240 | SQLite+Android book | <p>I've been looking around for some examples to explain SQLite in android. I failed to create a simple application called find a doctor, where you search for a doctor then you get the result back with doctors' name and address. </p>
<p>Well, does any of you guys know a good book that take you through handling SQLite with android in details? or any tutorial that would do the same thing basically. </p>
| android | [4] |
5,334,763 | 5,334,764 | Split long text into string array | <p>I need a method to split a string into an array of smaller strings, spliting it by word count. It is, I'm looking for a function like that:</p>
<pre><code>function cut(long_string, number_of_words) { ... }
var str = "word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12";
var arr = cut(str, 3);
</code></pre>
<p>In this case, cut should return 4 arrays with 3 words each. I've tried to figure out a regex for String.match() or String.split(), but I don't know how to do it..</p>
| javascript | [3] |
718,846 | 718,847 | When defining a derived class, why is the base class marked "public?" | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/860339/difference-between-private-public-and-protected-inheritance-in-c">Difference between private, public and protected inheritance in C++</a> </p>
</blockquote>
<p>One of the examples in my lecture notes is</p>
<pre><code>class TransportShip : public GameUnit {
int capacity;
public:
...
}
</code></pre>
<p>Why do we need the "public" modifier before the name of the base class? What would it mean if it wasn't there?</p>
| c++ | [6] |
5,025,332 | 5,025,333 | How Can I access the first result? | <pre><code> $tmp = mysql_query("SELECT commercial FROM Channels WHERE name='".mysql_real_escape_string($_POST['name'])."'");
while( $row = mysql_fetch_assoc($tmp))
{
echo $row['commercial'];
}
</code></pre>
<p>I only want to access the first element.
not in a while loop</p>
| php | [2] |
5,560,859 | 5,560,860 | How to recognize any four ints in Python | <p>I am trying to scrape a series of websites that look like the following three examples:</p>
<pre><code>www.examplescraper.com/fghxbvn/17901234.html
www.examplescraper.com/fghxbvn/17911102.html
www.examplescraper.com/fghxbvn/17921823.html
</code></pre>
<p>Please, keep in mind that there are 200 of these websites and I'd like to iterate through a loop rather than copying and pasting each website into a script. </p>
<p>Where the base is <code>www.examplescraper.com/fghxbvn/</code>, then there's a year, followed by four digits that do not follow a pattern and then <code>.html</code>.</p>
<p>So in the first website:</p>
<pre><code>base = www.examplescraper.com/fghxbvn/
year = 1790
four random digits = 1234.html
</code></pre>
<p>I would like to call (in beautiful soup) a url where url:</p>
<pre><code>url = base + str(year) + str(any four ints) + ".html"
</code></pre>
<h3>My question:</h3>
<p>How do I (in Python) recognize any four digits? They can be any digits. I don't need to generate four ints or return the four ints I just need Python to accept any four ints to feed into beautiful soup.</p>
| python | [7] |
2,805,978 | 2,805,979 | Why are there so many string classes in the face of std::string? | <p>It seems to me that many bigger C++ libraries end up creating their own string type. In the client code you either have to use the one from the library (<code>QString</code>, <code>CString</code>, <code>fbstring</code> etc., I'm sure anyone can name a few) or keep converting between the standard type and the one the library uses (which most of the time involves at least one copy). </p>
<p>So, is there a particular misfeature or something wrong about <code>std::string</code> (just like <code>auto_ptr</code> semantics were bad)? Has it changed in C++11?</p>
| c++ | [6] |
2,057,139 | 2,057,140 | I want to print any text without using Print function in java? | <p>I want to print any text without using system.out.println() in java? It is possible If yes
then how; Any idea.</p>
| java | [1] |
444,758 | 444,759 | jQuery Object Not able to find the class | <p>I am not sure why but jQuery find function is not able to find the class using the class name. </p>
<p>Here is the result from Visual Studio immediate window which shows that there is a class called TBLCONTENTS but when searched using the find method it returns nothing.</p>
<pre><code>optionRows[0].className
"TBLCONTENTS"
optionRows.find(".TBLCONTENTS")
{...}
context: {object}
jquery: "1.7.1"
length: 0
prevObject: {...}
selector: ".TBLCONTENTS"
</code></pre>
<p>Can I remove rows based on the filter: </p>
<pre><code>$(optionRows).filter(".TBLCONTENTS").not(":first").remove();
</code></pre>
| jquery | [5] |
4,110,679 | 4,110,680 | Is it possible to bind more than one column to a DropDownList's DataTextField? | <p>The following is my code...</p>
<p><strong>DropDownList2.DataSource = td.DataSet
DropDownList2.DataSource = td
DropDownList2.DataTextField = td.Columns("Name").ColumnName.ToString
DropDownList2.DataValueField = td.Columns("VendorCode").ColumnName.ToString
DropDownList2.DataBind()</strong></p>
<p>Now I have a requirement to show the type of vendor and the Name of the vendor on the dropdownlist. The type of vendor can be retreived with this statement...</p>
<p>td.Columns("VendorType").ColumnName.ToString</p>
<p>Is it possible to do this? Please help</p>
| asp.net | [9] |
2,132,865 | 2,132,866 | Gallery of TextViews, using styles etc | <p>I want to use <code>Gallery</code> as a horizontal menu so I've taken the code for the <a href="http://developer.android.com/resources/tutorials/views/hello-gallery.html" rel="nofollow">Gallery tutorial</a> to use <code>TextView</code>s instead of <code>ImageViews</code> by using a <code>String[]</code> and changing the adapter's <code>getView((...)</code> method as follows...</p>
<pre><code>public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(mContext);
tv.setText(mMenuItems[position]);
tv.setLayoutParams(new Gallery.LayoutParams(150, 100));
return tv;
}
</code></pre>
<p>The problem I have now is as shown in the image...</p>
<p><img src="http://i.stack.imgur.com/78WkM.png" alt="enter image description here"></p>
<p>As you can see, what should be the 'selected' <code>TextView</code> is 'greyed' (although I can select it) and the other items are 'highlighted and I'd like the reverse. So the question is what is <code>Gallery</code> doing to cause this and how do I override it?</p>
<p>UI stuff is a weak point of mine (I'm learning gradually honest) but I think I need to define styles as explained here...<a href="http://developer.android.com/guide/topics/ui/themes.html#DefiningStyles" rel="nofollow">Definining styles</a> and I understand what's being explained but how do I get the <code>Gallery</code> to automatically apply the styles I define? Do I have to apply the styles the <code>TextView</code>s I return from the adapter's <code>getView(...)</code> method or can I apply them 'globally' to the <code>Gallery</code> somehow?</p>
| android | [4] |
2,588,516 | 2,588,517 | How do I generate a random number within my javascript code? | <p>I'm using some 3rd party javascript to generate a slideshows within each of the posts on a blog. Each slideshow must have a unique ID to work properly. I figured the easiest way to do this would be to generate a large random number for each slideshow when it's loaded on the page.</p>
<p>Below is a snippet of the relevant parts of the code where POSTID represents the random number. Note that the same random number must be referenced in the div below the script.</p>
<pre><code><script language="javascript" type="text/javascript">
$(function() {
$("#POSTID").webwidget_slideshow_dot({
slideshow_time_interval: '',
slideshow_window_width: '320',
slideshow_window_height: '480',
slideshow_title_color: '#17CCCC',
soldeshow_foreColor: '#000',
});
});
</script>
<div id="POSTID" class="webwidget_slideshow_dot">
<!-- some content goes here -->
</div>
</code></pre>
<p>Any help would be greatly appreciated!</p>
<p>Thanks</p>
| javascript | [3] |
480,762 | 480,763 | PHP crop image from base64_decode | <p>i am generating a screen grab jpg using html2canvas from this code. However i cant target a particaular div so i am grabbing the entire screen.</p>
<pre><code>$canvasImg = $_POST['img'];
$data = base64_decode($canvasImg);
$File = "z.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, $data);
fclose($Handle);
</code></pre>
<p><br/>
<strong>question</strong>: how can i crop the image?<br/><br/>
this is my attampt</p>
<pre><code>$canvasImg = $_POST['img'];
$image = base64_decode($canvasImg);
$dest_image = 'z.jpg';
$img = imagecreatetruecolor('200','150');
$org_img = imagecreatefromstring($image);
$ims = getimagesize($image);
imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150);
imagejpeg($img,$dest_image,90);
imagedestroy($img);
</code></pre>
<p><br/><br/>
but im getting a errors<br/>
<code>Warning: getimagesize(�PNG ) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: Invalid argument</code></p>
| php | [2] |
2,382,766 | 2,382,767 | NSScanner, reaching the end of parsing string | <p>I have a string that's like</p>
<p>"Condition: <strong><em>some text which can have a comma in it but not always</em></strong>, Type <em><code>more text</code></em> Product: <strong><em>more text, can be NULL sometimes</em></strong></p>
<p>What I did was:</p>
<pre><code>NSString *condition = @"Condition:";
NSString *type = @", Type";
NSString *product = @"Product:";
NSScanner *scanner = [NSScanner scannerWithString:myString];
[scanner scanString:condition intoString:NULL];
[scanner scanUpToString:type intoString &conditionName];
[scanner scanUpToString:type intoString:NULL];
[scanner scanUpToString:product intoString:&typeName];
[scanner scanString:product intoString:NULL];
// stuck here
</code></pre>
<p>I don't know how to scan till the end of the string since scanString:intoString: takes a NSString parameter. I wasn't sure how to put these into a while loop either to scan till the end. Any thoughts? Thanks.</p>
| iphone | [8] |
3,576,310 | 3,576,311 | get the Bitmap from ImageView in a ListView | <p>I have a <code>ListActivity</code> that displays two pieces of information in each line of the list (one image sett in an <code>ImageView</code> and a text description set in a <code>TextView</code>). These information I get through a XML file from a download. Every thing works fine!!!!! :-).</p>
<p>On <code>OnListItemClick</code>, I would like to get the <code>Bitmap</code> from the <code>ImageView</code> that the user selected.</p>
<p>To get an image from an <code>ImageView</code>, I use this :</p>
<pre><code>ImageView img = (ImageView) l.findViewById(R.id.imageViewXYZ);
img.buildDrawingCache();
Bitmap b = img.getDrawingCache();
</code></pre>
<p>But inside the <code>onClick</code> event of the <code>ListActivity</code>, how can I get the this bitmap?</p>
| android | [4] |
2,480,116 | 2,480,117 | Select all li's but not children | <p>I have this code:</p>
<pre><code>$li = $("li", this)
</code></pre>
<p>Which is selecting all of the <code>li</code>'s in my code. This works fine however I want <code>$li</code> to exclude the <code>li</code>'s that are within a submenu.</p>
<pre><code> <ul id="navigation">
<li><a href="#">blah 1</a></li>
<ul id="subnav">
<li><a href="#">sub 1</a></li>
<li><a href="#">sub 2</a></li>
<li><a href="#">sub 3</a></li>
</ul>
</li>
<li><a href="#">blah 2</a></li>
<li><a href="#">blah 3</a></li>
<li><a href="#">blah 4</a></li>
<li><a href="#">blah 5</a></li>
</ul>
</code></pre>
<p>So <code>$li</code> would only reference the blah's not the sub's.</p>
<p>I thought it was something like:</p>
<pre><code>$li = $("li", this).parents()
</code></pre>
<p>But this doesn't do what I want.</p>
| jquery | [5] |
933,418 | 933,419 | Difference Between Javascript Wrapping Methods | <p>It is generally accepted that Javascript code should be wrapped in a function to prevent leaking to the global scope and just assign whatever you need outside of each function to the <code>head</code> object (<code>window</code> in web browsers).</p>
<p>I've seen two primary methods of this in the wild:</p>
<p><strong>Method 1:</strong></p>
<pre><code>(function() {
// code here
}).call(this);
</code></pre>
<p><strong>Method 2:</strong></p>
<pre><code>(function() {
// code here
})();
</code></pre>
<p><strong>Method 1</strong> is from compiled CoffeeScript code, and <strong>Method 2</strong> seems to be the preferred style for jQuery plugins:</p>
<p>Modified Method 2 for jQuery:</p>
<pre><code>(function($) {
// JQuery Code
})(jQuery);
</code></pre>
<p><strong>Question:</strong> What is the difference between <strong>Method 1</strong> and <strong>Method 2</strong>? CoffeeScript likes to focus on conciseness, so I figure there must have been a reason for the people behind CoffeeScript to choose <strong>Method 2</strong> over <strong>Method 1</strong>.</p>
| javascript | [3] |
293,110 | 293,111 | how to get all objects of a given type in javascript | <p>I want to retrieve all objects (not DOM elements) of a given type created with the "new" keyword.</p>
<p>Is it possible ?</p>
<pre><code>function foo(name)
{
this.name = name;
}
var obj = new foo();
</code></pre>
<p>How can I retrieve a reference to all the foo objects ?</p>
| javascript | [3] |
2,765,186 | 2,765,187 | When should I define my own copy ctor and assignment operator | <p>I am reading effective C++ in Item 5, it mentioned two cases in which I must define the copy assignment operator myself. The case is a class which contain const and reference members. </p>
<p>I am writing to ask what's the general rule or case in which I must define my own copy constructor and assignment operator?</p>
<p>I would also like to know when I must define my own constructor and destructor. </p>
<p>Thanks so much!</p>
| c++ | [6] |
1,190,183 | 1,190,184 | Another way to compile java without servlet-api | <p>Up to this point I used the Tomcat installation that comes with servlet-api.jar to compile my java files. Is there another way to compile it? Simply using the JDK?</p>
| java | [1] |
4,516,427 | 4,516,428 | How to copy an add on of android sdk to android android sdk | <p>Can anyone tell me the steps to copy an installed add on in android sdk to android android sdk.</p>
<p>My problem is now that add on is not available in google now(this is pretty old sdk).</p>
<p>Now I want to copy this add on to new sdk so that while creating new android project, it will ask to create project based on this add on. Can anyone tell me how can I do this?</p>
<p><strong>UPDATE</strong></p>
<p>To clarify more, in my old sdk api level 9 is installed but now its not available. So I want to add this api level 9 to new sdk so that when I create new Android project, it should give me option to create project with api level 9</p>
| android | [4] |
298,137 | 298,138 | How to loop my data for PHP | <p>I have some data which was json decoded and looks like this:</p>
<pre><code>stdClass Object
(
[6] => stdClass Object
(
[13] => stdClass Object
(
[buildingId] => 1
)
)
[8] => stdClass Object
(
[20] => stdClass Object
(
[Id] => 1
)
)
</code></pre>
<p>Thing is i don't know how to loop to get the information to use it in my script.</p>
<p>I need to get for example:</p>
<pre><code>$key, $innerkey, $Id = 1
Object [8][20].Id = 1
</code></pre>
<p>The two numbers are X;Y co ordinates so its important i get those values aswell as the id.</p>
<p>I managed to get the first key:</p>
<pre><code>$obj = JSON_decode($_GET['data']);
foreach($obj as $key) {
echo $key;
}
</code></pre>
<p>How do i get the innerkey assigned to a variable ?</p>
| php | [2] |
4,337,991 | 4,337,992 | Counting number of characters in a file C# | <p>How do you count the number of characters in a file using C#?</p>
| c# | [0] |
3,988,324 | 3,988,325 | Where is the jQuery API on `$.`? | <p>I saw this somewhere,</p>
<p>For example there is the <code>each</code> function to iterate over objects and arrays:</p>
<pre><code>$($arr).each(
function(idx)
{
//do stuff
}
);
</code></pre>
<p>But then there is the format $.each($arr, function);</p>
<p>What is this "<code>$.</code>"? Does it have a name?</p>
<p>What else can you do with it?</p>
| jquery | [5] |
2,562,574 | 2,562,575 | Can I use JQuery Slidshow in my Commercial Project | <p>I would like to use <a href="http://caroufredsel.frebsite.nl/" rel="nofollow">http://caroufredsel.frebsite.nl/</a> this jquery gallery in my commercial project. It is under MIT licence, I already searched about this licence on net but am still confusing whether we can use this or not... anyone please help me out... thanks in advance </p>
| jquery | [5] |
3,848,429 | 3,848,430 | c# read attribute value | <p>ich have a xml file with the following structure:</p>
<pre><code><layer1 name="this is layer1">
<messages>
<message name ="com_request">0</message>
<message name="send">1</message>
<message name="request">2</message>
</messages>
</layer1>
</code></pre>
<p>I try to collect all the message names in one indexer using the code:</p>
<pre><code>SampleCollection<string> paramCollection = new SampleCollection<string>();
string pathxml = @"C:\myXML.xml";
int j=0;
XmlTextReader xmlin = new XmlTextReader(pathxml);
XmlDocument xmldoc = new XmlDocument();
XmlNode node = xmldoc.ReadNode(xmlin);
foreach (XmlNode item in node.ChildNodes)
{
paramCollection[j] = item.Attributes["message name"].Value;
Console.WriteLine(paramCollection[j]);
j++;
}
</code></pre>
<p>However it doesn't work. Please help.</p>
| c# | [0] |
3,097,411 | 3,097,412 | Change event is not working in this scenario | <pre><code><table>
<tr>
<td><input type='checkbox'><span>Text1</span><input type='text'></td>
</tr>
<tr>
<td><input type='checkbox'><span>Text2</span></td>
</tr>
<tr>
<td><input type='checkbox'><span>Text3</span></td>
</tr>
<tr>
<td><input type='radio'><span>None of all</span></td>
</tr>
</table>
</code></pre>
<p>Below is my jQuery code.. </p>
<pre><code>$(':checkbox').live('change',function()
{
$(':radio').prop('checked',!$(this).prop('checked'));
});
$(':radio').live('change',function()
{
$(':checkbox').prop('checked',!$(this).prop('checked'));
});
$('table :text').live('keyup', function() {
var um = $(this).closest('td').find('input');
if ($(this).val().length > 0) {
um.prop('checked', true);
}
else {
um.prop('checked', false);
}
});
</code></pre>
<p>What the above code will do is </p>
<pre><code> 1. Checkboxes and Radio button are mutually exclusive
2. On change of a textbox automatically the checkbox inside its parent will checked/unchecked.
</code></pre>
<p>But </p>
<p><b>My concern is When i first click radio button, Then if i change text in textbox the checkbox will be checked but the radio button remains unchecked..</b> Why this is happening.. Please help me on this..</p>
| jquery | [5] |
3,628,385 | 3,628,386 | How to test executable JAR? | <p>I have a simple class in executable JAR file:</p>
<pre><code>public final class Main {
public static void main(String[] args) {
System.out.println("hello, world!");
System.exit(-1);
}
}
</code></pre>
<p>Now I'm trying to test this class/method:</p>
<pre><code>public class MainTest {
@Test public void testMain() {
Main.main(new String[] { "something" });
}
}
</code></pre>
<p>Testing crashes on <code>System.exit(0)</code>, and I can understand why. Now what should I do? Shall I mock <code>System</code>? What is a standard approach here? Btw, maybe I should test the method "in container" (read "in JAR"), the same way we're doing it with WAR files?</p>
| java | [1] |
2,438,929 | 2,438,930 | Android LivePerson Agent? | <p>Is there a liveperson agent for android? Specificly one which pushes notifications to your phone when people request a chat.</p>
| android | [4] |
4,150,992 | 4,150,993 | How do I clear a String local to a method? My text gets appended everytime the method is run | <p>I have a local String in a method like so:</p>
<pre><code>String jString = new String();
</code></pre>
<p>or</p>
<pre><code>String jString = "";
</code></pre>
<p>The result is the same.</p>
<p>Later in the method I append:</p>
<pre><code>for(int i = 0; i != someArrayList.size(); ++i) {
jString += someArrayList.get(i).getText() + "\n";
}
</code></pre>
<p>Everytime the method is run, the text from getText() gets appended to jString. </p>
<p>Why is this and how can I prevent it from happening?
Thanks!</p>
<p>OK edit. This is basically what happens. Either that or you tell me it is impossible to get the results I described with this code.</p>
<pre><code>public void requestData() {
String jString = new String();
for(int i = 0; i != someArrayList.size(); ++i) {
jString += someArrayList.get(i).getText() + "\n";
}
}
</code></pre>
<p>Say inside the array I have values ["a", "b", "c"]. When I run the method jString contains:
a
b
c
Next time I run it, I want it to be the new contents of the array not
a
b
c
plus the new contents. </p>
| java | [1] |
4,930,604 | 4,930,605 | Easiest way to convert array into xml string? | <p>So I'm trying to convert an array to an XML document (just outputting it as a string). I know php has <code>json_encode</code> built in and it works fine, but I can't seem to find any good XML equivalents.</p>
<p>Basically, the array is the result of a <code>PDOStatement->fetchAll();</code> </p>
<p>I'd like the output to look like this:</p>
<pre><code><arrayitem>
<iteminfo1>text</iteminfo1>
<iteminfo2>text</iteminfo2>
<iteminfo3>text</iteminfo3>
<iteminfo4>text</iteminfo4>
<iteminfo5>text</iteminfo5>
</arrayitem>
</code></pre>
| php | [2] |
5,345,457 | 5,345,458 | Creating count-down application for desktop background c# | <p>I would like to write a small application which will be a countdown application, it's basically should have no frame and no background - just a counts the time from now to a date set in app.config.</p>
<p>I know how to write the countdown itself. My problem is that I don't know which kind of application can have no form ?</p>
<p>How can I make something look like that? what type of application should I create?</p>
<p>thanks</p>
| c# | [0] |
2,407,772 | 2,407,773 | What is causing this behavior, in our C# DateTime type? | <pre><code>[Test]
public void Sadness()
{
var dateTime = DateTime.UtcNow;
Assert.That(dateTime, Is.EqualTo(DateTime.Parse(dateTime.ToString())));
}
</code></pre>
<p>Failed :</p>
<pre><code> Expected: 2011-10-31 06:12:44.000
But was: 2011-10-31 06:12:44.350
</code></pre>
<p>I wish to know what is happening behind the scenes in ToString() etc to cause this behavior.</p>
<p>EDIT After seeing Jon's Answer :</p>
<pre><code>[Test]
public void NewSadness()
{
var dateTime = DateTime.UtcNow;
Assert.That(dateTime, Is.EqualTo(DateTime.Parse(dateTime.ToString("o"))));
}
</code></pre>
<p>Result :</p>
<pre><code>Expected: 2011-10-31 12:03:04.161
But was: 2011-10-31 06:33:04.161
</code></pre>
<p>Same result with capital and small 'o' . I'm reading up the docs, but still unclear.</p>
| c# | [0] |
993,160 | 993,161 | difference between object code and embeded code? | <p>i have a doubt difference between object code and embeded code .
thank you.</p>
| asp.net | [9] |
4,529,439 | 4,529,440 | List_view getting items back | <p>I have 3 different function in an activity namely , main category,sub_category and list of items. By clicking main category it displays sub_category and same like list of item.I want to give back option, in order to view back functions. for example at the time of viewing list_of item by clicking back option, i want to show sub_category and by clicking back button from sub_category i want to display main category. I dont know how to do this. All the above function are reside in one class. can anyone give solution for this..?? </p>
| android | [4] |
305,126 | 305,127 | finding substring c++ | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/236129/how-to-split-a-string">How to split a string?</a> </p>
</blockquote>
<p>Hi,</p>
<p>I have a string say "1,0,1", how can i get the substring separated by comma operator.</p>
| c++ | [6] |
4,933,214 | 4,933,215 | C# elegant way to check if a property's property is null | <p>In C#, say that you want to pull a value off of PropertyC in this example and ObjectA, PropertyA and PropertyB can all be null.</p>
<p>ObjectA.PropertyA.PropertyB.PropertyC</p>
<p>How can I get PropertyC safely with the least amount of code?</p>
<p>Right now I would check:</p>
<pre><code>if(ObjectA != null && ObjectA.PropertyA !=null && ObjectA.PropertyA.PropertyB != null)
{
// safely pull off the value
int value = objectA.PropertyA.PropertyB.PropertyC;
}
</code></pre>
<p>It would be nice to do something more like this (pseudo-code).</p>
<pre><code>int value = ObjectA.PropertyA.PropertyB ? ObjectA.PropertyA.PropertyB : defaultVal;
</code></pre>
<p>Possibly even further collapsed with a null-coalescing operator.</p>
<p><strong>EDIT</strong> Originally I said my second example was like js, but I changed it to psuedo-code since it was correctly pointed out that it would not work in js.</p>
<p>Thanks much,
Jon</p>
| c# | [0] |
4,820,530 | 4,820,531 | how to get raw folder uri path and save in internal memory in android? | <p>here my code.where is my errors errors.the errors is file not found exception.</p>
<pre><code>Uri video = Uri.parse("android.resource://com.ring.app/raw/"+a[i]+".mp3");
file= new File(video.toString());
try
{
inputStream= new FileInputStream(file);
fos = super.openFileOutput("output"+i+".mp3", MODE_WORLD_READABLE);
byte buffer[]=new byte[1024];
while((len=inputStream.read(buffer))>0)
fos.write(buffer,0,len);
fos.close();
}
</code></pre>
| android | [4] |
4,897,958 | 4,897,959 | cancel load page in javascript | <p>I define a link <a href="http://www.example.com">Hello</a>.when i click this link javascript should check the link is exist/valid.if true,the page should be load or the page should resirect to another page.i am using javascript ajax to check the page exist/not.i am using the condition xmlhttp.status == 200.But it is not working.here is the code:</p>
<pre><code>function check(url){
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if (xmlHttp.status==200)
{
alert("Page Available");
}
else
{
window.location.href= "http://www.hello.com";
}
}
}
xmlHttp.send(null);
}
</script>
</head>
<body>
<a href="http://www.example.com" onclick="check(this)">Click this Link</a>
</code></pre>
<p>here xmlHttp.status==200 is not working.can anyone help me?</p>
| javascript | [3] |
5,646,933 | 5,646,934 | typedef synonymous substitution | <p>My understanding is typedef acts as a synonym for a type, or can be used as an alias for a particular type. Also, the simplified codes below built perfectly. The question here is if I change the second line in the main function to :</p>
<pre><code>Array<int>::ArrayIter<T> pa = a.begin(); // substituting back the typedef “iterator” to its original form of ArrayIter<T>.
</code></pre>
<p>I get the following error message during compilation:</p>
<blockquote>
<p>“ArrayIter” is not a member of “Array”</p>
</blockquote>
<p>But the codes compiled perfectly using the "typedef" (iterator) notation. Why is “iterator” and ArrayIter suddenly not synonymous any more:</p>
<p>Reference codes below:</p>
<pre><code>template<class T> class ArrayIter {
public:
ArrayIter(T* p) : m_p(p) {
}
private:
T* m_p;
};
template<class T> class Array {
public:
Array(int size) throw (const char*) {
if ( size > 0 ) {
m_p = new T[size];
m_size = size;
} else {
throw "Array: invalid array dimension";
}
}
// typedef and methods to support the new iterator for this class
typedef ArrayIter<T> iterator;
ArrayIter<T> begin() {
return ArrayIter<T>(m_p);
}
private:
T* m_p;
int m_size;
};
int main(int argc, char* argv[]) {
Array<int> a(10);
Array<int>::iterator pa = a.begin();
return 0;
}
</code></pre>
| c++ | [6] |
1,962,467 | 1,962,468 | Is there is reliable way to find out which revision of ECMA-262 my browser supports? | <p>How do I find out if my browser supports Javascript 1.5 or not? using javascript of course. (or should I have googled or binged some more?)</p>
| javascript | [3] |
2,449,447 | 2,449,448 | Problem in login page in asp.net | <p>I have created a login page. In this page i used div tag which is mapped with images for good design purposes. i have enabled the forms authentication in web.config. </p>
<p>So finally images i mapped in div is not appearing in the login page.
please help me!</p>
| asp.net | [9] |
5,584,338 | 5,584,339 | How do I inherit a variable with prototype? | <p>I'm just setting up a little framework for my canvas, I haven't used Prototype a lot, but it seems to be pretty damn awesome, just having one little problem, the <code>create</code> function is not inheriting the width and height from the <code>new</code> function, how might I do this? Code:</p>
<pre><code>function CtxCanvas() {
this.fps = undefined;
this.width = undefined;
this.height = undefined;
}
CtxCanvas.prototype = {
constructor: CtxCanvas,
new: function(fps, width, height) {
this.fps = fps;
this.width = width;
this.height = height;
},
create: function() {
var df = document.createDocumentFragment()
, canvasElement = document.createElement('canvas');
canvasElement.width = this.width;
canvasElement.height = this.height;
df.appendChild(canvasElement);
document.getElementsByTagName('body')[0].appendChild(df);
return canvasElement.getContext('2d');
}
}
var ctx = new CtxCanvas(30, 1000, 1000).create();
</code></pre>
| javascript | [3] |
3,486,955 | 3,486,956 | document.writeln doesn't write to a new line | <p>I was just writing some simple code and I noticed that using document.writeln doesn't write to a new line, permit me to demonstrate...</p>
<pre><code> // this is my JSON object
var myObject = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": [{
"Address1": "11 My Street",
"Address2" : "Nice Area",
"Town" : "Nice Town",
"PCode" : "P05T 0DE"
}]
}
document.writeln(myObject.firstName);
document.writeln(myObject.address[0].Address1);
</code></pre>
<p>now this outputs the following....</p>
<blockquote>
<p>John 11 My Street</p>
</blockquote>
<p>It's all on one line? If I used document.write() I'd expect this? It's happening in both IE & Firefox. Obviously I could add <code>+ "<br/>"</code> or <code>+ "\n"</code> but I shouldn't need to do that?</p>
<p>Am I being stupid?</p>
| javascript | [3] |
132,439 | 132,440 | Javascript: alert checking for mouseover and mouseout firing multiple times | <p>Writing a code that does the following:</p>
<ol>
<li>Adds a mouse listener to a web-page on load</li>
<li>Checks what element the mouse is positioned over</li>
<li>If the mouse is positioned over an anchor tag then execute a certain functionality if it stays there for a certain period of time before leaving. For now am just arbitrarily using 10000 ms </li>
</ol>
<p>Below is a sample code that I'm using as a testbed</p>
<pre><code><html>
<head></head>
<title>A test page</title>
<body>
<script type='text/javascript'>
document.addEventListener("mouseover", checkElement, false);
function checkElement(ev){
var elm = ev.target || ev.srcElement;
if(elm.tagName === 'A'){
var focusTime = new Date().getTime();
elm.addEventListener("mouseout", function() {tellTime(focusTime)}, false);
}
}
function tellTime(focusTime){
var blurTime = new Date().getTime();
if ((blurTime - focusTime) > 10000) {
alert ('You spent a long time there');
}
}
</script>
<a href="www.google.co.in">This is a hyperlink</a>
<p> This is just some bloody text </p>
</body>
</html>
</code></pre>
<p>When testing what I have found is that when the alert is fired it gets fired multiple times; twice, thrice or even more. I wanted to know why this could be happening and what I can do to avoid firing the alert multiple times for the same element.</p>
| javascript | [3] |
1,618,856 | 1,618,857 | PHP error message: call to undefined function | <p>(Disclaimer) MY php experience is approx 2 hours old and I have know idea what I am doing. </p>
<p>This is my error and I am wondering how do you know where the error is, for example.</p>
<p>as rendered in my browser, this is my error.</p>
<pre><code>Fatal error: Call to undefined function array_key_exist() in
/home/mjcrawle/public_html/cit/home/processlogin.php on line 47
</code></pre>
<p>Line 47 is actually <code>if (array_key_exist('submit', $_post)){</code></p>
<p>I do not know if the error is before or after - this is my code.</p>
<pre><code>/*Determine if the form data was submitted*/
if (array_key_exist('submit', $_post)){
/*this removes left over data*/
$emailaddress = sanitize($_post['emailaddress']);
$password = sanitize($_POST['password']);
/*verify form data*/
$auth_status = validateLogin($emailaddress, $password);
}
</code></pre>
| php | [2] |
2,453,293 | 2,453,294 | can user see session information | <p>If I start a session with php , can user see session vars with cookies ?</p>
<p>I want to keep some settings of user infrmation in a session , but I do not want user know them .</p>
<p>thanks.</p>
| php | [2] |
803,114 | 803,115 | Accessing method from another class | <p>I have a simple button which will open up the <code>AddStation</code> form (this button is placed on the <code>MainForm</code> form):</p>
<pre><code>var AddStation = new AddStation();
AddStation.Show();
</code></pre>
<p>It shows the form fine, however the form <code>AddStation</code> has a save button. When this button is pressed the <code>AddStation</code> form is closed, <strong>but</strong> I want to run a method which is in the <code>MainForm</code>'s class (to update a listbox which is present on <code>MainForm</code>).</p>
<p>This isn't possible the way I do it right now, since the form <code>AddStation</code> doesn't have a reference to the <code>MainForm</code>, but how will I do this? How can I run the method <code>MainForm.UpdateListBox</code> from the <code>AddStation</code> form?</p>
| c# | [0] |
2,672,774 | 2,672,775 | How can I convert a byte array to a bitmap and stream the images through a web server? | <p>The project I am working on is capturing a frame from a security camera, with the help of <a href="http://en.wikipedia.org/wiki/Arduino" rel="nofollow">Arduino</a> UNO and <a href="http://nootropicdesign.com/ve/" rel="nofollow">Video Experimenter shield</a>. Then I am sending the frame as byte arrays through a serial port. I would like to ask, how could I, with Java, convert back this byte arrays to an image, and stream this image - or even make this images a video and then stream it - through a web server?</p>
<p>The code I have stacked with is this:</p>
<blockquote>
<p>//Handle an event on the serial port. Read the data and save the image.</p>
<p>public synchronized void serialEvent(SerialPortEvent oEvent) {</p>
<pre><code> if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
System.out.println("Got it!");
int available = input.available();
byte[] chunk = new byte[available];
input.read(chunk, 0, available);
InputStream in = new ByteArrayInputStream(chunk);
BufferedImage image = ImageIO.read(in);
ImageIO.write(image, "BMP", new File ("/home/zuss/images/image.BMP"));
} catch (Exception e) {
System.err.println(e.toString());
}
}
</code></pre>
<p>}</p>
</blockquote>
<p>That returns to my terminal window: java.lang.IllegalArgumentException: image == null!
continuously as long as arduino is sending data to the serial port.
Any suggestion?</p>
| java | [1] |
3,978,932 | 3,978,933 | Modify all img src tags in a particular way | <p>I want to use <a href="http://phpthumb.sourceforge.net/" rel="nofollow">phpThumb</a> to resize all images in the content divs of my pages when they are served up to mobile devices.</p>
<p>So in my page templates for mobile devices I need to change all <code><img></code> tags in <code><div id="content></code> in the following manner:</p>
<pre><code><img src="/images/image_01.jpg">
-> <a href="/images/image_01.gif">
<img src="phpThumb.php?src=images/image_01.jpg&w=300">
</a>
<img src="/images/image_02.gif">
-> <a href="/images/image_02.gif">
<img src="phpThumb.php?src=images/image_02.gif&w=300">
</a>
</code></pre>
<p>What is the best way to do this?</p>
| php | [2] |
4,109,022 | 4,109,023 | What is wrong with next jQuery code? | <p>can you help me why it returns error.</p>
<p>part of code /publications/deleteItem/' + valueClicked works ok, i checked (proper item is properly deleted). </p>
<pre><code>var valueClicked = 123456;
$.ajax({
type: "post",
url: '/publications/deleteItem/' + valueClicked, // 100% works!
success: function(xml) {
alert('602!');
},
error:function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown); // throwns undefined?!
}
});
</code></pre>
<p>so, alert('602!') never exetutes...</p>
| jquery | [5] |
4,254,170 | 4,254,171 | Append tag at the place of an Event | <p>I have a Ul like this</p>
<pre><code><ul class="fine">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</code></pre>
<p>On clicking Li i want to add an <code><textarea></code> under that corresponding li
like this</p>
<pre><code><li>One</li>
<li><textarea></textarea></li>
</code></pre>
| jquery | [5] |
46,468 | 46,469 | Processing files with C# in folders whose names contain spaces | <p>There are plenty of C# samples that show how to manipulate files and directories but they inevitably use folder paths that contain no spaces. In the real world I need to be able to process files in folders with names that contain spaces. I have written the code below which shows how I have solved the problem. However it doesn't seem to be very elegant and I wonder if anyone has a better way.</p>
<pre><code> class Program
{
static void Main(string[] args)
{
var dirPath = @args[0] + "\\";
string[] myFiles = Directory.GetFiles(dirPath, "*txt");
foreach (var oldFile in myFiles)
{
string newFile = dirPath + "New " + Path.GetFileName(oldFile);
File.Move(oldFile, newFile);
}
Console.ReadKey();
}
}
</code></pre>
<p>Regards,
Nigel Ainscoe</p>
| c# | [0] |
868,606 | 868,607 | Better way to output days of the week between other functions | <p>I am new to c++. What is a better way to do this? I am trying to output the days of the week and also put functions between the days. I want to output Monday separate from outputting the other days of the week.</p>
<pre><code>#include <iostream>
#include <string>
#include <ctime>
using namespace std;
void day(char* name[]);
int main()
{
char* dayNames[] =
{ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday"};
day(dayNames);
day(dayNames + 1);
day(dayNames + 2);
day(dayNames + 3);
day(dayNames + 4);
day(dayNames + 5);
day(dayNames + 6);
system ("pause");
return 0;
}
void day(char* name[])
{
int n = 0;
if (n >=0 && n <= 6)
{
cout << "Today is " << name[n] << "." << endl;
cout << endl;
}
}
</code></pre>
| c++ | [6] |
954,847 | 954,848 | Do machine.config/web.config in .NET Framework 3.0/3.5 and .NET Framewor 1.1/1.0 cascade? | <p>I made a change in my machine.config for a 1.1 application and then later I upgraded the application to .Net Framework 3.0/3.5. Will that configuration change still apply or do I have to make that change in my local web.config for the 2.0 machine.config/web.config? Thank you in advance.</p>
| asp.net | [9] |
1,124,893 | 1,124,894 | Custom method to native event object. | <p>For quite some time I think that it is possible to add custom method to native Event object. How do you think? I have not found a way. I would be grateful for any opinions and recommendations.</p>
<p>Best regards. </p>
| javascript | [3] |
2,481,517 | 2,481,518 | python and assigning variable values in if statements | <p>I'm somewhat of a beginner in python and I swear I got a very similar program to what I'm doing right now to work. But, for some reason, I can't make it work. I was able to pinpoint my problem and created a fake program to play around with it. Here is what the program:</p>
<pre><code>global heading
global heading2
global a
heading=2
a=2
heading2=4
def function ():
if a==2:
heading=heading2
print 'yes'
print heading
function()
print heading
</code></pre>
<p>This is what appears:</p>
<pre><code>yes
4
2
</code></pre>
<p>Why doesn't the heading variable heading keep the value 4? I tried putting return heading all over. Didn't work. I tried putting the variables in the parentheses of the function. Didn't work either... Do you know what I'm doing wrong?</p>
| python | [7] |
4,935,145 | 4,935,146 | xEditable wysihtml5 giving unexpected text area | <p>I use xEditable (bootstrap) to allow me to edit text on pages. In my HTML code I have the following:</p>
<pre><code><span id="1" class="xEditableManyToOne" data-pk="1" data-type="wysihtml5"
data-name="desc" data-url="/POST">
</code></pre>
<p>It should give a formatted editable area, but I just get the standard editable textarea. All the wysihtml5 css and js files have been added correctly.</p>
<p>Any ideas?</p>
| javascript | [3] |
4,807,249 | 4,807,250 | extend click event for plugins? | <p>is it possible to extend normal events for plugins in a general way?</p>
<p>e.g.
say i have a plugin A which does stuff and react to the click event on an element
i would now to perform some actions when that element is clicked, and AFTER i have done my stuff i want the plugin to do whatever it does onlick.</p>
<p>at the moment i am manually looking at the plugin and create custom code, but maybe there is some general way that one can prevent a click event for a plugin temporarily, and then trigger it?</p>
| jquery | [5] |
2,381,924 | 2,381,925 | How to extract number and String in java | <p>i want to extract number and add these numbers using Java and String remain same.</p>
<p>String as-</p>
<pre><code>String msg="1,2,hello,world,3,4";
</code></pre>
<p>output should come like- 10,hello,world</p>
<p>Thanks</p>
| java | [1] |
299,734 | 299,735 | Looped function calling not looping correctly! (C++) | <p>I am doing a homework for my Systems Programming course.
I have to implement a University simulation.
I have a Course abstract class, and child class of it ComputerScienceCourse (and a bunch of other child classes that don't affect what I'm going to ask).
and I have a Student abstract class, and child class of it ComputerScienceStudent (and a bunch of other child classes that don't affect what I'm going to ask).
In the ComputerScienceCourse child class there is a function:</p>
<pre><code>void teach(){
for(i = all students that take this course [stored in a vector of pointers to Student objects, which is a member field of the CSCourse child class, called students]){
this->students.at(i)->study(*this);
}
}
</code></pre>
<p>This function calls study function for all students that have taken this class. The function is a member function of child class CSStudent</p>
<pre><code>void study(Course &c){
if(this->failedclass){
c.removeStudent(this)
}
}
</code></pre>
<p>Now when I check the output, the loop in the teach function does not call the study function for all the students within.
For example, if I have 4 students doing this course, sometimes it would call the study function of only the first three, sometimes it calls the function for the first and the last student... varies.
What could be causing the for loop to not call ALL students study functions?!
Here's the full code for the teach function:</p>
<pre><code> for(unsigned int i=0; i<this->studentMembers.size(); i++){
this->studentMembers.at(i)->study(*this);
}
</code></pre>
| c++ | [6] |
2,942,046 | 2,942,047 | How to save image in photo album? | <p>I am using GLImageProcessing sample code.I want to save modified image in photo album how it possible.please help me.</p>
| iphone | [8] |
4,326,840 | 4,326,841 | I/O Relative Paths | <p>I'm having a problem with relative paths in my program. The absolute path to the file which I want to use is:</p>
<pre><code>C:\Users\User\Documents\Projects\Project1\src\files\test.txt
</code></pre>
<p>Now, I'm unsure of how to make this a relative path, I've tried:</p>
<pre><code>.\files\test.txt
</code></pre>
<p>Which throws an error at me, I don't know how to make this go up a folder and read from the test.txt file.</p>
| java | [1] |
1,126,324 | 1,126,325 | Is there a better way to declare an object | <p>Currently I check if sed object already exists as to not wipe it if it does, then create the object.</p>
<pre><code>if (typeof result === 'undefined') {
results = {};
}
</code></pre>
<p>It's just that I come from using PHP where you don't really have to declare things as much as you do in JS.</p>
<p>Though I tend to use JS objects as I use arrays in PHP, as a way to temporarily store information which I need to access further down in a script.</p>
| javascript | [3] |
4,585,612 | 4,585,613 | PHP - Cleaning Rich Text Area Input | <p>I am using a rich text box in my application and am looking at ways to clean the input before storing it in a database. Because I want to allow some HTML through I was thinking of using strip_tags with the allowed tags specified, something like this:</p>
<pre><code>public function cleanRichInput($text)
{
return strip_tags(trim($text),"<a><div><p><strong>");
}
</code></pre>
<p>That seems kind of cumbersome though, could anyone suggest a better way to handle input where you want some HTML to get through? Any advice would be appreciated, thanks! </p>
| php | [2] |
1,438,106 | 1,438,107 | ArrayList cast to PriorityQueue + java | <p>I am having this problem that I had used Arraylist in my entire program up till now and now I need its functioning to be that of priority queue too.</p>
<p>So I did the obvious that seemed to me and casted it like <code>PriorityQueue z = (PriorityQueue) x</code>
where x was arraylist.</p>
<p>At runtime this gave an error that this is not possible.</p>
<p>Is there any simple way to make this work. I can't change entire array list as a priority queue since then I'll have to update all the functions used.....</p>
<p>Should I add item each time from arraylist to a new priority queue or is there a better method...</p>
<p>Thanks a lot...</p>
| java | [1] |
4,534,739 | 4,534,740 | .before()/.after() element without it closing automaticly | <p>This is what I'm trying to do.</p>
<p>I am calling on a xml file and creating alto of div around the content from the file. What I want to do is to add a div around every 15 div. The divs have the class "item". The items are enclosed in a div called "container".</p>
<p>I first try to add a open <code><div></code> in front of the first div in the container. Then I look for the sixteenth div and try to add a closing <code></div></code> and then I open another <code><div></code> and then I try to close the last one by adding a closing <code></div></code> after the lest "item"</p>
<pre><code>$(".container .item:first-child").before('<div class="inner-container">');
$(".container .item:nth-child(16)").before('</div><div class="inner-container">');
$(".container .item:last-child").after('</div>');
</code></pre>
<p>My problem is is that the div are closed automatically so the appear as an empty divs with the rest of the "item"s</p>
<p>I'm not sure if this is a jquery thing ore if the browser is doing it. But what can I do to make this work?</p>
<p>I'm doing this because I want to scroll the container from left to right.</p>
| jquery | [5] |
4,930,138 | 4,930,139 | Generating random test cases | <p>I am working on a library and need to test it. There are several operations (as functions) defined in my class which can be called in any order by the client.</p>
<pre><code>Operation1(param1, param2)
Operation2(param3)
.
.
.
OperationN(paramX, paramY, paramZ)
</code></pre>
<p>param1, param2 etc are integers/double</p>
<p>Now, I am thinking of writing a test code to randomize the execution of the operations, such that a sequence of M operation will be performed in random. Each time an operation is called, the parameters need to be random generated.</p>
<p>What is the best way to do this in Java.</p>
| java | [1] |
5,153,606 | 5,153,607 | Script randomly cuts off | <p>I've made a VERY basic website which takes an array of image URLs, zips them, and returns the zip location. The problem is that the script cuts off at some point.</p>
<p>One of the following usually happens:</p>
<ul>
<li>not all the pictures are copied</li>
<li>not all pictures are copied and the last picture has 0 file size</li>
<li>sometimes the ajax call doesn't run the error or success callback</li>
</ul>
<p>Is this because the server is only allowing a certain amount of time for the script to execute? It does seem to work with less pictures. What can I do? </p>
<p>I have the following settings:</p>
<p>max_execution_time 10 10
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 10</p>
<p>also, set_time_limit is disabled. </p>
<p>I tried ini_set('max_execution_time', 300); and nothing changed</p>
<p>edit: Probably a REALLY stupid question, but would it change anything if I executed another PHP page after a certain amount of time if the script isn't going to finish before the limit?</p>
| php | [2] |
5,714,218 | 5,714,219 | Ping in ASP.NET | <p>I can ping using console app, but I want to ping from ASP.NET, the problem is that, ping object doesn't show ping.send(....).
Is it not possible to ping from ASP.NET Web App?</p>
<p>for image please visit : <a href="http://coscientech.blogspot.com/2010/09/ping-trouble-aspnet.html" rel="nofollow">http://coscientech.blogspot.com/2010/09/ping-trouble-aspnet.html</a></p>
<p>Directives are : <code>using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
</code></p>
| asp.net | [9] |
1,040,569 | 1,040,570 | How to examine SharedPreferences from adb shell? | <p>Now that we can <a href="http://developer.android.com/guide/developing/tools/adb.html#sqlite">Examining sqlite3 Databases from a Remote Shell</a>, is it possible to examine SharedPreferences from adb shell? Since it would be much more convenient to examine and manipulate SharedPreferences from command line when debugging.</p>
<p>Or put in another way, in what files SharedPreferences are saved, and how to view and modify these files?</p>
| android | [4] |
3,867,776 | 3,867,777 | Save contact to app database CursorIndexOutOfBoundsException | <p>In this code I keep getting an error, I know its how I'm saving the contact to the database. because if I take out the cdata/cdata2 and just put a string it works fine. Any help will be appreciated.</p>
<p>How do I convert this to accept the string from the contact?</p>
<pre><code>switch (item.getItemId()) {
case 1:
//Save current contact to stash database
Cursor phones2 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null, null);
String cdata = phones2.getString(phones2.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String cdata2 = phones2.getString(phones2.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
ContentValues values=new ContentValues(2);
values.put(DatabaseHelper.NAME, cdata);
values.put(DatabaseHelper.cALUE, cdata2);
db.getWritableDatabase().insert("constants", DatabaseHelper.NAME, values);
constantsCursor.requery();
//Refresh contact list
Intent refresh = new Intent(this, MainTab.class);
startActivity(refresh);
this.finish();
return(true);
case 2:
//uncoded option
Toast.makeText(this, "here is the info", Toast.LENGTH_SHORT).show();
}
</code></pre>
<p>ERROR:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2</p>
| android | [4] |
5,194,707 | 5,194,708 | Login encrypt password to compare | <p>Updated code still not working?</p>
<pre><code><?php
$host="localhost";
$username="root";
$password="power1";
$db_name="members";
$tbl_name="users";
string sha1 ( string $Password [, bool $raw_output = false ] )
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect. Please contact us");
mysql_select_db("$db_name")or die("cannot select DB. Please contact us");
$Email=$_POST['Email'];
$Password=$_POST['Password'];
$Email = stripslashes($Email);
$Password = stripslashes($Password);
$Email = mysql_real_escape_string($Email);
$Password = mysql_real_escape_string($Password);
$sql="SELECT * FROM $tbl_name WHERE Email='$Email' AND password ='$Password'";
$result=mysql_query($sql, $link) or die ('Unable to run query:'.mysql_error());
$count=mysql_num_rows($result);
if($count==1){
session_register("Email");
session_register("Password");
header("location:login_success.php");
}
else {
echo "Wrong Email or Password. Please Wait.<meta http-equiv='REFRESH' content='1;url=login.php'>";
}
?>
</code></pre>
| php | [2] |
4,822,347 | 4,822,348 | Navigation bar common to all activities | <p>I have been looking for options on how to place <strong>Navigation bar</strong> common to all activities. Still can't figure out the best way to do it. The Navigation bar should have a title for screen and a back button. Or may be two in some activities.<br>
What is the best practice I should follow?</p>
<p>Thanks</p>
| android | [4] |
3,261,990 | 3,261,991 | Find Replace a Function in JQuery | <p>I have a HTML page where there are many <code><a onclick="javascript></code></p>
<p>What i need to do using Jquery is find the below tag as it is </p>
<p><code><a onclick="javascript:OpenNewWindow('/help_options.php?ID=2', 350, 250);" href="javascript:void(0);"></code></p>
<p>and replace it with </p>
<p><code><a onclick="javascript:OpenNewWindow('/help_options.php?ID=2', 600, 500);" href="javascript:void(0);"></code></p>
<p>Note </p>
<p>1) the values 350 is changes to 600 and 250 is changed to 500
2) there are also many similar tags but i want the code to do Exact find and replace of the above tag.</p>
<p>IS this possible ? </p>
| jquery | [5] |
2,111,938 | 2,111,939 | can an child class access parent class property data? | <p>I have a child class extending a parent class.</p>
<p>In my parent class have a protected property that stores config data. In the parent class this property has all the configuration files needed.</p>
<p>But in the child class I cannot access that data. How can I bring over the config property data into the child class?</p>
<p>I am using</p>
<pre><code>class Child extends Parent
{
public function __construct()
{
print_r($this->config);
}
}
</code></pre>
<p>but i get an empty response.</p>
| php | [2] |
2,370,121 | 2,370,122 | Update Datatable and DatagridView with database Changes by Timer | <p>Scenario : i have a database table that is being updated frequently by some services.</p>
<p>I have a c# Winforms Application that load this table in a datagridview by binding a datatable as Datasource, then i whant to add a Timer that every 10 seconds update a the content of a datatable with the last changes in the database table ...</p>
<p>I don't need to update a database with the datatable changes, but i need to update datatable with the last changes in the database table, that is the inverse of the usually.... </p>
<p>Is there a way to do that ? What is the best way ?</p>
<p>i've tried with this code : </p>
<pre><code>private void ServiceTimer_Tick(object state)
{
OdbcConnection oCon = new OdbcConnection();
oCon.ConnectionString = ConnectionStrings;
OdbcDataAdapter dp = new OdbcDataAdapter("SELECT * FROM table", oCon);
dsProva.Tables.Clear();
dp.Fill(dsProva,"table");
dataGridViewMessaggi.DataSource = dsProva.Tables["table"];
dataGridViewMessaggi.Refresh();
}
</code></pre>
<p>But every Timer Tick i lost the selection in DatagridView and Current Row .... </p>
<p>Is There a better solution ?</p>
| c# | [0] |
3,899,704 | 3,899,705 | Structuring a combination of 'functions' in a cohesive manner | <p>My application needs to use a bunch of variations of the code below. There are roughly six or seven variations of the code below, but I'm having trouble organizing them.<br>
At first, I created a class and separated them into functions but for some reason all of the functions stopped working. Just glancing over the code below, do you see maybe a good way to organize something like this?</p>
<pre><code>try{
$fql = "select uid,name,education from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['education'])) {
foreach ($friend['education'] as $school) {
if (isset($school['concentration'])) {
foreach ($school['concentration'] as $concentration) {
if (strpos(strtolower($concentration['name']), 'business') !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
d($friends_BA);
</code></pre>
| php | [2] |
4,584,368 | 4,584,369 | Trigger a loaded page's ready state | <p>With JQuery I am trying to load a page in another, and have the ready state of that loaded page be triggered.</p>
<p><strong>Page1.html</strong></p>
<pre><code>$(document).ready(function() {
$("#content").load("Slides/page2.html");
});
</code></pre>
<p><strong>Page2.html</strong></p>
<pre><code>$(document).ready(function() {
alert("ready");
//....
});
</code></pre>
<p>Is this possible?</p>
<p>If not, could I load page 2, and when loaded, trigger a named function IN page 2? (If so, how can I?)</p>
<p>Thanks,</p>
<p>S.</p>
| jquery | [5] |
5,837,692 | 5,837,693 | How to reset textbox values in dialog after destroy? | <p>I have a dialog in which there are 2 textboxes. I want to reset the textboxes values once the dialog is destroyed. How can I do that?</p>
<p>If I have entered values in the textboxes and clicked cancel, reopening the dialog will show the data entered previously.</p>
<pre><code>function setDialogWindows($element) {
$('#change').dialog({
autoOpen: true,
width: 380,
buttons: {
"Cancel": function() {
$(this).dialog('destroy');
},
"Accept": function() {
}
}):
}
</code></pre>
<hr>
<pre><code>$('#link').click(function() {
setDialogWindows('#change');
});
</code></pre>
<hr>
<pre><code><div id="change" title="Change password" >
<input type="hidden" id="User_Name" name="Name"/>
<input type="textbox" id="text1" />
<input type="textbox" id="text2" />
</div>
</code></pre>
| jquery | [5] |
5,871,647 | 5,871,648 | Is there a popular C++ service framework? | <p>... like Remoting or WCF in C# or Java RMI?</p>
<p>I am learning c++ and need a simple to use tcp service framework with built in binary serialization for c++ to c++ communication. </p>
<p>Thanks</p>
| c++ | [6] |
3,534,091 | 3,534,092 | Rock Paper Scissors Java game | <p>I am writing a Rock Paper Scissors Java game. Here is the code:</p>
<pre><code>import java.util.Scanner;
public class RPS {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String personPlay; //Player A -- "R", "P", or "S"
String secondUser; //Player B
Scanner scan = new Scanner(System.in);
System.out.println(" Player A enter R for Rock, P for Paper, S for Scissors: "); //Get player's play -- note that this is stored as a string
personPlay = scan.next();
personPlay = personPlay.toUpperCase();
System.out.println("Player B enter R for Rock, P for Paper, and S for Scissors");
secondUser = scan.next();
secondUser = secondUser.toUpperCase();
if (personPlay.equals(secondUser)) {
System.out.println("It's a tie!");
} else if (personPlay.equals("r")) {
if (secondUser.equals("s")) {
System.out.println("Rock beats scissors! You win!");
} else if (secondUser.equals("p")) {
System.out.println("Paper eats Rock! You lose!");
} else if (personPlay.equals("p")) {
if (secondUser.equals("s")) {
System.out.println("Scissors cut Paper, you lose!");
} else if (secondUser.equals("r")) {
System.out.println("Paper covers rock, you win!!");
} else if (personPlay.equals("s")) {
if (secondUser.equals("p")) {
System.out.println("Scissors beat paper, you win!");
}
} else if (secondUser.equals("r")) {
System.out.println("Rock beats Scissors, you lose!");
}
}
}
}
}
</code></pre>
<p>The winner is determined using an if-else block, however my if-else block does not seem to work. It only prints <strong>Its a tie!!</strong> What is the problem?</p>
| java | [1] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.