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
4,765,042
4,765,043
program checking string of characters for capital letters
<p>Ok, i have a function which checks if a letter is upper case and returns 'true' or 'false' value.</p> <pre><code>function isUpperCase(aCharacter) { return (aCharacter &gt;= 'A') &amp;&amp; (aCharacter &lt;= 'Z'); } </code></pre> <p>now I would like it to check a string of characters e.g. 'AdfdfZklfksPaabcWsgdf' and after the program encounters capital letter it will execute function decryptWord on all small letters after this letter and until next capital letter and so on. Function decryptWord works fine on single words i just cant get it work on more than one ;(</p> <pre><code>function decryptMessage(cipherText, indexCharacter, plainAlphabet, cipherAlphabet) { for (var count = 0, count &lt; cipherText.length; count++) { if (isUpperCase(cipherText.charAt(count))) { decryptWord(cipherText, indexCharacter, plainAlphabet, cipherAlphabet) } else //i dont know what to do next } </code></pre> <p>can you tell me if i'm going in the right direction?</p>
javascript
[3]
5,676,111
5,676,112
Does anyone have a good java BitBuffer?
<p>I was working on a school assignment (doing Hoffman encoding) and I need some sort of bitbuffer to use to put all the bits in. While I did find several things doing a google, most of the stuff was garbage - didn't compile, referenced <em>other</em> libraries I didn't have, etc. Does anyone have an actual good bitbuffer class out there? All that I really even want to do is read and write bits one at a time. If nobody has a good one, is there some existing data structure that would be good for holding that sort of data efficently that I could use to write one myself?</p>
java
[1]
3,561,903
3,561,904
Sorting of data in specific format
<p>I have tried to edit my code to the following But dont seem to be the correct way:</p> <pre><code>public int Compare(object x, object y) { string s1 = (string)x; string s2 = (string)y; return DateTime.Compare(DateTime.ParseExact(s1.Substring(1), "MMddyyyy", CultureInfo.InvariantCulture), DateTime.ParseExact(s2.Substring(1), "MMddyyyy", CultureInfo.InvariantCulture)); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); if (scheduleListBox.Items.Count == 0) { try { //Get all the directories name that start with "a" fileNames = myStore.GetDirectoryNames("a*"); //Sort according to the schedule month //Array.Sort(fileNames); Array.Sort(new Compare(fileNames)); </code></pre> <p>I have a data in a format of <strong>a08102011</strong> in a array list.</p> <p>Where <strong>08</strong> is the <strong>month</strong>, <strong>10</strong> is the <strong>day</strong>, <strong>2011</strong> is the <strong>year</strong>.</p> <p>How can it be sorted in the way that?</p> <p>a08102011</p> <p>a09112011</p>
c#
[0]
4,843,625
4,843,626
Fatal error: Call to undefined function easter_date()
<p>I'm trying to get the easter_date from this year. This is my code:</p> <pre><code>&lt;?php $year = date ("Y"); $easter = date ("d-M-Y", easter_date ($year)); echo "Easter " . $year . ": " . $easter . ""; ?&gt;</code></pre> <p>When I execute the code following error appears: Fatal error: Call to undefined function easter_date() in</p> <p>My phpVersion is 5.3.3. I'm using Linux(Ubuntu).</p> <p>Have you got an idea what is missing?</p>
php
[2]
1,134,463
1,134,464
string variable shows wrong length
<p>So I have a function that gets some string variables from a form (after the form is submitted), then runs a query using those variables and returns lines of results. I have several conditions that work fine, except for one and I can't figure out what's wrong. When I print out the query and run it in phpMyadmin - it works just fine (returns 3 rows for example), but it doesn't run on the page (shows that 0 rwos are returned). One thing that I have noticed is that when I do var_dump it gives the correct type (string) but wrong length. trim doesn't make any difference. So fo example</p> <pre><code>$name2 = "John Doe"; var_dump($name1); var_dump($name2); </code></pre> <p>The name2 returns string(8) But when for name1 it returns string(9), even though name1 is also "John Doe" - I have no idea what that extra character is. That variable is coming from a form, from a select element. Select is populated from a table. I trim resulting POST value before assigning to name1. Character encoding is the same for the table where names in select element are coming from and table on which I run a query. All other variables from the form are passing fine and query runs correctly if I don't add the name. Again, if I print out the query (with name condition included) and copy and paste into phpMyAdmin - it runs just fine. I'm going crazy here.</p>
php
[2]
6,005,361
6,005,362
hide/show Scrollview in Navigation Contoller
<p>I am using a Navigation Controller. On top of the AppDelegate window I added a view that contains a scrollview and toolbar that I want to be using throughout the app. They appear fine on all the view controllers that I am using in the navigation controller. Now I would like to be able to hide and show them from each view controller. I cant figure out how that should work, any suggestions?</p>
iphone
[8]
2,899,141
2,899,142
Python calling function with return statement
<p>I have the below piece that created few person objects and apply some methods on those objects.</p> <pre><code>class Person: def __init__(self, name, age, pay=0, job=None): self.name = name self.age = age self.pay = pay self.job = job def lastname(self): return self.name.split()[-1] def giveraise(self,percent): return self.pay *= (1.0 + percent) if __name__ == '__main__': bob = Person('Bob Smith', 40, 30000, 'software') sue = Person('Sue Jones', 30, 40000, 'hardware') people = [bob,sue] print(bob.lastname()) print(sue.giveraise(.10)) </code></pre> <p>Once I run this program, this is the output--</p> <p>Syntax Error: Invalid syntax</p> <p>but when I run using the below code, I don't have any problem,</p> <pre><code>if __name__ == '__main__': bob = Person('Bob Smith', 40, 30000, 'software') sue = Person('Sue Jones', 30, 40000, 'hardware') people = [bob,sue] print(bob.lastname()) sue.giveraise(.10) print(sue.pay) </code></pre> <p>What is the difference in two cases</p>
python
[7]
241,968
241,969
how to play MID sound file in iphone?
<p>I have implement game application in which i want to play mid sound file in the background.How it possible?</p>
iphone
[8]
1,263,304
1,263,305
Sharing resources between service and application in android
<p>The code I am trying to implement includes a service and an application. When the application is first launched, it starts the service using the startService(svc_name) call. Here svc name is an intent pointing to the class that runs the service. </p> <p>I want to share a resource(file/socket connection) between the service and the application. For example one writes to a file and another reads from it. I am unable to get proper sync between the service and app. </p> <p>Could you please let me know how this can be achieved? Thanks in advance. </p>
android
[4]
1,882,077
1,882,078
C# Calling a Method, and variable scope
<p>Why is cards being changed below? Got me puzzled.. understand passing by ref which works ok.. but when passing an Array is doesn't do as I expect. Compiling under .NET3.5SP1</p> <p>Many thanks</p> <pre><code>void btnCalculate_Click(object sender, EventArgs e) { string[] cards = new string[3]; cards[0] = "old0"; cards[1] = "old1"; cards[2] = "old2"; int betResult = 5; int position = 5; clsRules myRules = new clsRules(); myRules.DealHand(cards, betResult, ref position); // why is this changing cards! for (int i = 0; i &lt; 3; i++) textBox1.Text += cards[i] + "\r\n"; // these are all new[i] .. not expected! textBox1.Text += "betresult " + betResult.ToString() + "\r\n"; // this is 5 as expected textBox1.Text += "position " + position.ToString() + "\r\n"; // this is 6 as expected } public class clsRules { public void DealHand(string[] cardsInternal, int betResultInternal, ref int position1Internal) { cardsInternal[0] = "new0"; cardsInternal[1] = "new1"; cardsInternal[2] = "new2"; betResultInternal = 6; position1Internal = 6; } } </code></pre>
c#
[0]
2,887,479
2,887,480
inline function -- "unresolved external" error?
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/3540931/inline-functions-in-c">Inline functions in C++</a> </p> </blockquote> <p><code>#foo.cpp</code></p> <pre><code>void func1(){ ... } inline void func2(){ ... } </code></pre> <p><code>#boo.cpp</code></p> <pre><code>void func3{ func1(); func2(); } </code></pre> <p>for <code>func1</code>, we say that after everything has been compiled, linker uses the address of func1 to make a call to it. For <code>func2</code>, as it is inline and defined in <code>foo.cpp</code>, compiler will not get the it's definition to replace <code>func2</code> call but inline functions also have addresses then why can't linker use this address of <code>func2</code> to link its call and gives the error of unresolved external?</p>
c++
[6]
4,217,060
4,217,061
With Javascript, enforce using scientific notation to represent numbers in IE8
<p>I found that when using IE8, the large number will NOT be represented in scientific notation (e.g., 5e25), but it will be with Firefox3. </p> <p>Can I enfore using scientific notation representation for <strong>large number</strong> with IE8?</p> <p>Thanks.</p>
javascript
[3]
4,176,514
4,176,515
Python: inspecting module to pick out classes of certain type?
<p>I have a module where all classes that implement my "policies" are defined. </p> <pre><code>class Policy_Something(Policy_Base): slug='policy-something' ... class Policy_Something_Else(Policy_Base): slug='policy-something-else' ... </code></pre> <p>I need to create a mapping from slug to class. Something like:</p> <pre><code>slug_to_class = { 'policy-something': Policy_Something, 'policy-something-else': Policy_Something_Else } </code></pre> <p>I was thinking instead of automatically creating slug_to_class by inspecting the module and looking for classes that inherit from Policy_Base (similar to how unittest finds tests, I assume).</p> <p>Any reason I shouldn't do that? If not, how exactly would I do that?</p>
python
[7]
289,414
289,415
Imposing Restrictions on the installation of apk
<p>I want to make certain restrictions on distribution of the Android mobile application(apk).</p> <p>I am currently not uploading the apk to Android market.</p> <p>I want to provide the apk to the user with the following restrictions.</p> <p>i> After the Android mobile application(apk) is installed , the application should work for only 5 days.</p> <p>ii> The apk file cant be reinstalled on the same mobile device more than once.</p> <p>Is there any way using code by which , I can make the above restrictions?</p> <p>Kindly provide your suggestions/hints for implementing the same.</p> <p>Warm Regards,</p> <p>CB</p>
android
[4]
156,344
156,345
How can I use jQuery to change the class of a DIV inside an A element?
<p>I have the following:</p> <pre><code>&lt;a id="menuPrev"&gt; &lt;div class="sprite-contol-double-180"&gt;&lt;/div&gt; &lt;/a&gt; </code></pre> <p>Is there a way that I can use jQuery to change the class to "sprite-blank"</p>
jquery
[5]
5,619,511
5,619,512
Saving numpy.ndarray in python as an image
<pre><code>b=ndimage.gaussian_filter(imagefile,5) </code></pre> <p>Being new to python, not able to figure this out.<br> how to save <code>b</code> as an image, <code>b</code> is of type 'numpy.ndarray'? </p> <p>Tried these,<br> 1.</p> <pre><code>im = Image.fromarray(b) im.save("newfile.jpeg") </code></pre> <p><code>Error: TypeError("Cannot handle this data type")</code></p> <p>2.</p> <pre><code>imsave('newfile.jpg', b) </code></pre> <p><code>Error: ValueError: 'arr' does not have a suitable array shape for any mode.</code></p> <p>Which is the right way to save an <code>ndarray</code> into an image?</p> <p>EDIT:</p> <p>Solved:<br> im = Image.fromarray(b)<br> im.save('newfile.jpeg') worked, The way I was loading the image was wrong,</p> <p>file = Image.open("abc.jpg")<br> imagefile = file.load() </p> <p>// I was using imagefile after loading, which was not giving proper shape to reconstruct the image.</p> <p>// Instead If I use file (i.e. directly after opening, I can save by above method)</p>
python
[7]
2,835,007
2,835,008
i am using sleep method of class Thread in java, can anyone tell how avoid this thing
<p>i am using sleep because one method is taking time to execute and i want to execute next method when it is completed. this is what i am trying.</p> <pre><code>method1(); Thread.sleep(3000); method2(); </code></pre>
java
[1]
3,059,364
3,059,365
Disable backspace and delete key with javascript in IE
<p>Anyone know how can I disable backspace and delete key with Javascript in IE? This is my code below, but seems it's not work for IE but fine for Mozilla.</p> <pre><code>onkeydown="return isNumberKey(event,this)" function isNumberKey(evt, obj) { var charCode = (evt.which) ? evt.which : evt.keyCode if (charCode == 8 || charCode == 46) return false; return true; } </code></pre>
javascript
[3]
6,024,270
6,024,271
google analytics in JS file instead?
<p>Instead of putting the code at the head or end of body (i put it at the end of body), is it ok if i stick the code inside of a JS file instead of its own script tag in html?</p> <p>(i assume it works fine like any other code but i am asking in case)</p>
javascript
[3]
5,031,204
5,031,205
ImportError: cannot import name Parser
<p>This is how I get an error. To find the code please refer to following link:</p> <p><a href="http://baderlab.org/Software/TCSS?action=AttachFile&amp;do=view&amp;target=TCSS.tar.gz" rel="nofollow">http://baderlab.org/Software/TCSS?action=AttachFile&amp;do=view&amp;target=TCSS.tar.gz</a></p>
python
[7]
4,437,024
4,437,025
how can I call bowtie program to run within my python program
<p>I want to integrate a web available program bowtie in to my python scripts, does anyone know how to do it? </p>
python
[7]
859,446
859,447
_PHP - Image $_Post is not sending anything
<p>I have a html $_POST page which posts a image the name &amp; iD is called image_filename.However when i try to view what the variable value is , its blank below is the code and i cant understand where the issue is. Any suggestions would be grateful.</p> <pre><code> $image_file = fopen($_POST['image_filename'], 'wb'); $encodedData = str_replace(' ','+',$_POST['image_file']); $decodedData = base64_decode($encodedData); fwrite($image_file, $decodedData); fclose($image_file); echo $image_file; </code></pre>
php
[2]
3,042,654
3,042,655
how to create a custom datatype in java?
<p>I want to create an custom datatype in Java,for example datatype Email , that having following method isValidate(String email),isEmailExist(String email),getDomain(String email), get Id(String email),just like Integer class in java.</p> <p>Integer is a class and I can initialise the object of Integer class as follows:</p> <p>Integer i = 100;</p> <p>I created my class Email and I want to initialise it as follows Email e = "sam";</p> <p>How can i perform this functionality in my Email class.<pre>import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern;</p> <p>public class Email { private String email; public Email(String email) { this.email=email; }</p> <pre><code>Email() { } public Boolean isvalid(String email) { </code></pre> <p>String lastToken = null; Pattern p = Pattern.compile(".+@.+\.[a-z]+"); // Match the given string with the pattern Matcher m = p.matcher(email); // check whether match is found boolean matchFound = m.matches(); StringTokenizer st = new StringTokenizer(email, "."); while (st.hasMoreTokens()) { lastToken = st.nextToken(); }</p> <p>if (matchFound &amp;&amp; lastToken.length() >= 2 &amp;&amp; email.length() - 1 != lastToken.length()) {</p> <pre><code> return true; </code></pre> <p>} else return false;</p> <pre><code>} </code></pre> <p>public String toString() { return email; }</p> <p>}</p> <p></pre></p> <p>Thanks</p>
java
[1]
1,161,626
1,161,627
Blank Spaces also Bind When Binding a Dropdown list
<p>when i Bind the dropdownlistHostelRoomType, it binds with empty spaces left above.. i dont have any idea why this is happening. help me getting out from this issue please.. My Code:</p> <pre><code>&lt;div&gt; &lt;fieldset&gt; &lt;legend&gt;Hostel Details &lt;/legend&gt; &lt;asp:Label ID="LabelHostelRoomType" runat="server" Text="Room Type"&gt;&lt;/asp:Label&gt; &lt;asp:DropDownList ID="DropDownListHostelRoom" runat="server" DataTextField="HTypeName" DataValueField="_HRTypID" OnSelectedIndexChanged="DropDownListHostelRoom_SelectedIndexChanged"&gt; &lt;/asp:DropDownList&gt; &lt;asp:GridView ID="GridViewHostelRoom" runat="server"&gt; &lt;/asp:GridView&gt; &lt;/fieldset&gt; &lt;/div&gt; private void FillHostelRoomType() { SqlConnection cn = new SqlConnection(@"Data Source=.;Initial Catalog=_uniManagement;Integrated Security=True"); string sqlDropdownHostelRoom = String.Format("SELECT [_HRTypID], [HTYPeNAME] FROM [_HOSTELS_Room_TYPE]"); SqlCommand cmd = new SqlCommand(sqlDropdownHostelRoom); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); DropDownListHostelRoom.DataSource = dt; DropDownListHostelRoom.DataBind(); } protected override void OnInit(EventArgs e) { DropDownListHostelRoom.AppendDataBoundItems = true; DropDownListMemberType.AppendDataBoundItems = true; FillHostelRoomType(); FillHostelMember(); base.OnInit(e); } </code></pre>
asp.net
[9]
2,973,253
2,973,254
Error when trying to import ActionBarSherlock Sample Project
<p><img src="http://i.stack.imgur.com/pmqGY.gif" alt="enter image description here">When I import the ActionBarSherlock Sample Project I get error saying [SampleList] Unable to resolve target 'android-14'. What could it be.please help</p>
android
[4]
2,002,598
2,002,599
Emulate Array Objects
<p>Question from Object-Oriented JavaScript book: <strong>Imagine Array() doesn't exist and the array literal notation doesn't exist either. Create a constructor called MyArray() that behaves as close to Array() as possible.</strong></p> <p>I thought it would be a good challenge to test my skills. This is what I came up with, but it doesn't work and is very incomplete.. I am a bit stumped:</p> <pre><code>function MyArray(){ // PRIVATE FIELDS ----------------------- var initialData = arguments; var storage; // PRIVATE METHODS ---------------------- function refresh(){ //this doesn't work :( for(var i = 0; i &lt; storage.length; i++){ this[i] = storage[i] } }; function initialize(){ storage = initialData; refresh(); } function count(){ var result = 0; for(var item in this){ //console.log(item, parseInt(item), typeof item); if(typeof item == 'number'){ result++; } } return result; }; initialize(); // PUBLIC FIELDS ------------------------- this.length = count(); // PUBLIC METHODS ------------------------ //todo: this.push = function(item){ refresh(); } this.pop = function(){} this.join = function(){} this.toString = function(){} } var c = new MyArray(32,132,11); console.log(c, c.length); </code></pre> <p>This isn't for any production code or any project.. just to try to learn JavaScript a lot more. Can anyone try to help me with this code?</p>
javascript
[3]
2,569,912
2,569,913
jquery undisable list onselect
<p>I have a list of options dependent on what is selected in the first option. How can I make it so that after they select location the second options only displays options avaliable to that location?</p> <p>Right now I have a bunch of</p> <pre><code>&lt;option class=2 DISABLED&gt;Blah&lt;/option&gt; </code></pre> <p>jQuery Code</p> <pre><code>$(document).ready(function() { $('#location').change(function() { $(.$(this).val()).removeAttr('disabled'); }); }); </code></pre> <p>The value of the location option is = to the class of the second. But it doesn't seem to work?</p>
jquery
[5]
3,247,396
3,247,397
Enigmatic Naming of Lists in Python
<p>I am writing a program in python and I am using a dictionary. I need to create an empty list for each key in the dictionary, and each list needs to have the same name as the key. The keys are user entered, which is why I can't just make a list in the conventional way. This was the first thing I tried</p> <pre><code>a = {"x":1, "y":2, "z"3} list(a.keys()) a.pop() = [] # This raises an error </code></pre> <p>I also tried to make the lists when the dictionary was being created, but this did not work either:</p> <pre><code>a = {} b = input("INPUT1") c = input("INPUT2") a[b] = c b = [] </code></pre> <p>This created a list with the name "b" rather than whatever the user entered. Please help!!</p>
python
[7]
4,452
4,453
Need Suggestion to do a task when Android Boots-Up
<p>I have written an activity A, when users press a button, it will do MyConfig.doSomething() where MyConfig is simple class with activity A passed to it.</p> <pre><code>public class A extends PreferenceActivity { private MyConfig mMyConfig; /* pseudo code, when button clicked, call */ mMyConfig.doSomething(); } </code></pre> <p>In mMyConfig, it accesses SharedPreferences for some configuration. Thus, I can do this to pass the activity to mMyConfig for calling getSharedPreferences().</p> <pre><code>mMyConfig = new MyConfig ( this ); </code></pre> <p>Here comes my request:</p> <p>I want to do something that <code>MyConfig.doSomething()</code> already does, but except when users click some button to invoke it, I want to invoke it when Android Boots-Up.</p> <p>I can write another class to extend BroadcastReceiver and then starts activity A by calling <code>startActivity(A.class)</code>, and then in A, do some tricks to make <code>mMyConfig.doSomething()</code> happen. It works but the Application will be shown on screen when Android Boots-Up.</p> <p>I want to make <code>mMyConfig.doSomething()</code> happen implicitly without letting users be aware of it. I suppose two possible solutions but I don't know how to do it.</p> <p>Solution A: Write a class that extends BroadcastReceiver, start a service (instead of activity A) that reads the SharedPreferences of A and create MyConfig object to do <code>doSomething()</code>. However, I don't if this can work if activity itself is never launched and how could I do this (read SharedPreferences from a service)?</p> <p>Solution B: Write a class that extends BroadcastReceiver, start activity A without showing it, put it to activity stack by calling <code>startActivity(A.class)</code> in onReceive. Is this possible?</p>
android
[4]
1,763,844
1,763,845
Why can't I use int to calculate bytes to gigabytes?
<p>I ran into some trouble when converting bytes to gigabytes in my current project. Initially I did this:</p> <pre><code> long requiredDiskSpace = 5000000000000; // In bytes int gb = (int)requiredDiskSpace / 1024 / 1024 / 1024; </code></pre> <p>This calculation becomes 0. (Correct should be 4 656). Then I switched to the <code>decimal</code> type, like this:</p> <pre><code> long requiredDiskSpace = 5000000000000; // In bytes decimal gb = requiredDiskSpace / 1024 / 1024 / 1024; int gbAsInt = (int)gb; </code></pre> <p>This calculation (correctly) makes <code>gbAsInt</code> 4 656.</p> <p>Now, my question is simply; why? To me, the calculations look similar, as I'm not interested in any decimal numbers I don't understand why I can't just use int in the actual calculation.</p>
c#
[0]
2,163,088
2,163,089
set scrolltop of one div in the other one's scroll event cause endless loop
<p>I am trying to write a jquery plugin for reading different contents synchronously in two divs. When one div scrolls, the other div's <code>scrollTop</code> will be set in the event's code.</p> <p>The problem is the scroll event of the other div will be fired when <code>scrollTop</code> is set, then the first div's <code>scrollTop</code> will set and the other div's scroll event will be fired (followed by an endless loop).</p> <p>It is similar with this situation: </p> <ol> <li>Two soldiers receive a same command, "jump when you see the other one jump".</li> <li>Then, when you order one of them to jump, they will jump forever.</li> </ol> <p>Sample code:</p> <pre><code>function syncReading(contentDiv) { this.contentDiv = contentDiv; contentDiv.onscroll = function(){ this.Scroll(); } } syncReading.prototype.Scroll = function() { //calc scrolldistance; for(var i in divCollection) { if(this != divCollection[i]) { divCollection[i].scrollTop=scrollDistance; } } } var one = new syncReading(getelementbyid("one"); var other = new syncReading(getelementbyid("other")); var divCollection = [one,other]; </code></pre> <p>(English is not my native language.)</p>
javascript
[3]
453,686
453,687
How to retrieve id of an object?
<p>How to retrieve id of an object ie. typeof? I mean ways to guarantee that I am dealing with the object I concern most about, not any others. ALso, this helps preventing substitution of different object values. ") i think everyone knows about this. please advise.</p> <p>Thank you.</p>
c++
[6]
592,811
592,812
php - Convert String To Date
<p>I'm trying to convert given string in format <code>1899-12-30 19:00:00.000</code> to date using this function:</p> <pre><code>$startDate = strtotime("1899-12-30 19:00:00.000"); </code></pre> <p>but as a result I get a wrong date, e.g. </p> <pre><code>30.10.2008 00:00:00 </code></pre> <p>what am I doing wrong?</p>
php
[2]
30,769
30,770
Override equals and hashCode just to call super.equals/hashCode or throw AssertionError?
<p>is there a best practice, when to override equals?</p> <p>Should I override equals/hashCode and throw an AssertionError? Just to be sure nobody uses that? (as recommended in the book Effective Java)</p> <p>Should I override equals/hashCode and just invoke super.equals/hashCode, because the super class behaviour is the same wanted? (FindBugs recommended this, because I added one field)</p> <p>Are they really best practices?</p>
java
[1]
5,950,102
5,950,103
Introductory JavaScript programming task for an expert developer
<p>What would be a good mini-project to get intimate with JavaScript, as an advanced 'introduction' to the language? I want to actually code an application in JS, not hook up bits of it to enhance a web application.</p>
javascript
[3]
3,083,758
3,083,759
Android mp3 cross class
<p>I am trying to play an mp3 sound using the MediaPlayer class inside a regular class, which means non Activity, Service or other. My problem is probably initializing the MediaPlayer object since I have no Context in a non Activity class. How is this solvable?</p>
android
[4]
4,618,092
4,618,093
how to convert € ’ “ ” into simple utf8 chars
<p>i have scrapped posts from site and some times it the posts titles some strange chars came like this</p> <pre><code> € ’ “ ” </code></pre> <p>and when i store them into database it store them like </p> <pre><code>’, “, etc </code></pre> <p>how i can convert these chars into simple utf8-chars..</p> <p>Any Help i have searched a lot but no one helped me so hopping so i will get answer from their.</p> <p>And one more thing if you can't answer then please don't down vote this post.</p>
php
[2]
3,562,255
3,562,256
Looping through a mutidimentional array in python
<p>How do i achieve line 9 and 10 i.e the two <code>for</code> loops in python </p> <pre><code>matrix = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ] newMatrix = [] for (i=0; i &lt; len(matrix); i++): for (j=0; j &lt; len(matrix[i]); j++): newMatrix[j][i] = matrix[i][j] print newMatrix </code></pre> <p>PS: i know i can do <code>[[row[i] for row in matrix] for i in range(4)]</code> but how i do only using for loops</p>
python
[7]
5,444,567
5,444,568
load() not working in jquery
<p>Hello Friends check my code <a href="http://jsfiddle.net/sUaky/2/" rel="nofollow">http://jsfiddle.net/sUaky/2/</a> i want to load a web page in a div using the <code>load()</code> function but code is not working plz help me out </p> <p>Thank in advance </p>
jquery
[5]
1,110,379
1,110,380
Issue with RegQueryValueEx
<p>I am using RegQueryValueEx to read a String value (REG_SZ) from the registry. The value if this registry contains some Japanese Characters along with english.<br> For eg: C:\Program Files\MyReg\チチチ\helloworld</p> <p>I am using the following code snippet:</p> <pre><code>BYTE* dwValue = 0; DWORD dwSize = 0; DWORD dwType = SZ_REG; TCHAR* valueName= TEXT("test"); //Get the size if(RegQueryValueEx(hKey, valueName,NULL,&amp;dwType,NULL,&amp;dwSize) == ERROR_SUCCESS) { dwValue = new BYTE[dwSize]; if(RegQueryValueEx(hKey, valueName,NULL,&amp;dwType,( BYTE* )( dwValue ),&amp;dwSize) == ERROR_SUCCESS ) ) _tprintf(TEXT("The value is %s"),(TCHAR*)dwValue); } </code></pre> <p>The output i get is-</p> <p>The value is C:\Program Files\MyReg\</p> <p>This exe is console application and has got UNICODE preprocessor defined. If i remove it then it works correctly and gives the correct string. I am not sure whats going wrong due to UNICODE.</p> <p>-Thanks</p>
c++
[6]
849,861
849,862
calculate value of sin 30
<p>I can not find the correct value of sin 30 ,</p> <pre><code> double degrees = 30.0; double radians = Math.toRadians(degrees); System.out.println(Math.sin(radians)); </code></pre> <p>which produces .499999999 but the exact value matching to calculator is .5</p> <p>please help me..</p>
java
[1]
3,068,371
3,068,372
Creating Simple Xml In C#
<p>I need help some help printing out some xml. Here is my code (which isnt working its not even formatting the full url right, it doesnt understand "//" in the url string) It also doesnt understand "&lt;". There must be a better way to do this??</p> <pre><code> foreach (string url in theUrls) { fullurl=@"http://www.cambit.com/restaurants" +url; xml = xml + @"&lt;url&gt;" + Environment.NewLine + @"&lt;loc&gt;" + fullurl + @"&lt;/loc&gt;" + Environment.NewLine + @"&lt;changefreq&gt;weekly&lt;/changefreq&gt;" + Environment.NewLine + @"&lt;priority&gt;0.80&lt;/priority&gt;" + Environment.NewLine + @"&lt;/url&gt;" + Environment.NewLine; } </code></pre> <p>It returns 400 of these appended right next to each other. Environment.NewLine isn't working either....</p> <blockquote> <p><a href="http://www.cambit.com/restaurantsBerwyn" rel="nofollow">http://www.cambit.com/restaurantsBerwyn</a> weekly 0.80</p> </blockquote> <p>I tried this and it says the loc object is not set to an instance of an object</p> <pre><code> XmlDocument aNewNode = new XmlDocument(); XmlElement urlRoot = aNewNode.CreateElement("url"); //aNewNode.DocumentElement.AppendChild(urlRoot); XmlElement loc = aNewNode.CreateElement("loc"); XmlText locText = aNewNode.CreateTextNode(fullurl); aNewNode.DocumentElement.AppendChild(loc); aNewNode.DocumentElement.LastChild.AppendChild(locText); XmlElement chgFreq = aNewNode.CreateElement("changefreq"); XmlText chgFreqText = aNewNode.CreateTextNode("weekly"); aNewNode.DocumentElement.AppendChild(chgFreq); aNewNode.DocumentElement.LastChild.AppendChild(chgFreqText); XmlElement priority = aNewNode.CreateElement("priority"); XmlText priorityText = aNewNode.CreateTextNode("0.80"); aNewNode.DocumentElement.AppendChild(priority); aNewNode.DocumentElement.LastChild.AppendChild(priorityText); </code></pre> <p>What am doing wrong??</p>
c#
[0]
5,964,977
5,964,978
a question on using xhtml2pdf to parse css from website
<p>I am trying to use xhtml2pdf to convert a webpage to pdf. After reading out the content of the webpage using urllib2, I found pisa.CreatePDF needs to process every link in the webpage content too. Especially, whenever it tried to parse .css file after I tried several websites, I got the following error:</p> <pre><code>pisa-3.0.33-py2.6.egg/sx/w3c/cssParser.py", line 1020, in _parseExpressionTerm sx.w3c.cssParser.CSSParseError: Terminal function expression expected closing ')':: (u'Alpha(Opacity', u'=0); }\n\n\n\n.ui-state-') </code></pre> <p>Do you seem this issue too? Could anyone please help? Thanks a lot.</p>
python
[7]
5,054,532
5,054,533
Strange C++ behaviour involving multiple calls to destructor
<p>I'm running the following code in Dev Studio 2010:</p> <pre><code>struct Foo { Foo() {cout &lt;&lt; "Foo()" &lt;&lt; endl;} ~Foo() {cout &lt;&lt; "~Foo()" &lt;&lt; endl;} void operator ()(const int &amp;) const {} }; int bar[] = {0}; for_each(begin(bar), end(bar), Foo()); </code></pre> <p>The output is not what I expected, and is the same in both debug and release regardless of the contents of the "bar" array:</p> <pre><code>Foo() ~Foo() ~Foo() ~Foo() </code></pre> <p>I've looked at the outputted assembly and I can't for the life of me understand why the compiler is generating extra calls to the destructor. Can anyone explain to me exactly what's going on?</p>
c++
[6]
2,231,668
2,231,669
C basics, const unsigned char* to integer or bool
<p>I'm trying to get integer or bool from database result this way:</p> <pre><code>bool tblexist = false; int t_exists = 0; tblexist = (bool)sqlite3_column_text(chkStmt, 1); t_exists = atoi(sqlite3_column_text(chkStmt, 1)); </code></pre> <p>... but no one works.<br> Expected value from sqlite3_column_text(chkStmt, 1) is always 0 or 1. But I get error message:</p> <blockquote> <p>invalid conversion from ‘const unsigned char*’ to ‘const char*’<br> initializing argument 1 of ‘int atoi(const char*)’<br> ||=== Build finished: 2 errors, 0 warnings ===| </p> </blockquote> <p>How to solve this and get integer or bool on elegant way? </p>
c++
[6]
5,214,753
5,214,754
How to pass value from Broadcast receiver to Activity in android?
<p>I am developing the sample application in android.I want to know how to pass the variable from broadcast receiver to to the Activity class</p> <p>Please any one help me how to do that in android Thanks in advance</p>
android
[4]
407,838
407,839
List is a raw type. References to generic type List<E> should be parameterized
<p>bellow is my syntax </p> <pre><code>List synchronizedpubliesdList = Collections.synchronizedList(publiesdList); </code></pre> <p>I am facing syntax error as "List is a raw type. References to generic type <code>List&lt;E&gt;</code> should be parameterized". Please suggest the solution.</p>
java
[1]
1,132,229
1,132,230
In ASP.NET, how does disabling the ViewState of a databound control affect the event handling of its children controls?
<p>I have a ListView control and in the LayoutTemplate I have Previous and Next paging buttons. On clicking the buttons, a PageButton_Click event handler in the code behind file is called to do the paging. It works fine, but if I switch off the ViewState of the ListView, clicking the buttons would not be able to call the event handler in the code behind. What is happening here?</p>
asp.net
[9]
4,132,667
4,132,668
Store Battery Level Status In a txt File
<p>I am a New B to Android. I have been Able to get the Battery Status/Level with the Following Code:</p> <pre><code>private void BattStatus() { BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { context.unregisterReceiver(this); int rawlevel = intent.getIntExtra("level", -1); int scale = intent.getIntExtra("scale", -1); int level = -1; if (rawlevel &gt;= 0 &amp;&amp; scale &gt; 0) { level = (rawlevel * 100) / scale; } batteryLevel = level; BattStatus.setText("Battery Level : " + batteryLevel + "%"); } }; IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(batteryLevelReceiver, batteryLevelFilter); } </code></pre> <p>I would Like to Store the Battery Level In A text file (Using a thread). Code :</p> <pre><code>public final Runnable DBThread = new Runnable() { String AllInfo = batteryLevel+"%"+" , "+new SimpleDateFormat("HH:mm , dd.MM.yy ").format(new Date()); public void run() { try { Log.d("DBThread","Battery :"+batteryLevel); Log.d("DBThread","Updating DB"); myDbHelper.CreateAndWriteFile(sdDir+"/", AllInfo ); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mHandler.postAtTime(this, SystemClock.uptimeMillis() + 2000); Log.d("DBThread","Updated DB"); Log.d("DBThread",AllInfo); } </code></pre> <p>Unfortunately the Battery Status/Level returns 0% in the text file, when I test it using the Log function in the thread it returns the correct value.</p> <p>Please could some one be so kind to tell me what I am doing wrong or what I am not doing, and maybe provide me with a code snippet as I am new to Development.And Sorry If My Post is incorrect First timer on Stack Overflow :)</p> <p>Thank you very much!</p>
android
[4]
4,806,284
4,806,285
Gridview related problem in asp.net
<p>How can I enter data from textbox to gridview on the buttonclick event</p>
asp.net
[9]
2,707,283
2,707,284
How can I add more directories to my file deletion program?
<p>I'm trying to use this to delete all .htm files in certain in a couple of directories I have by using recursion. So far it works fine with just one folder, but I haven't been able to find a way to add more than one folder to the code. Is there any way i can add more directories to the directory path so I don't have to keep changing the code every time I want it to delete files in another directory?</p> <pre><code>namespace ConsoleApplication { class Deleter { static void Main(string[] args) { string directorypath = @"C:\Public\"; string[] directories = System.IO.Directory.GetDirectories(directorypath); DeleteDirectories(directories); } private static void DeleteDirectories(string[] directories) { foreach (string directory in directories) { string[] files = System.IO.Directory.GetFiles(directory, "*.htm"); DeleteFiles(files); directories = System.IO.Directory.GetDirectories(directory); DeleteDirectories(directories); } } private static void DeleteFiles(string[] files) { foreach (string file in files) { FileInfo f = new FileInfo(file); if (f.CreationTime &lt; DateTime.Now) f.Delete(); } } } } </code></pre>
c#
[0]
4,536,635
4,536,636
how to collate an array of dictionaries into a dictionary of arrays?
<p>I have this data:</p> <pre><code>list = [ {name:'apple', category: "fruit", price: 1.22 }, {name:'pear', category: "fruit", price: 2.22 }, {name:'coke', category: "drink", price: 3.33 }, {name:'sprite', category: "drink", price: .44 }, ]; </code></pre> <p>And I'd like to create a dictionary keyed on category, whose value is an array that contains all the products of that category. My attempt to do this failed:</p> <pre><code> var tmp = {}; list.forEach(function(product) { var idx = product.category ; push tmp[idx], product; }); tmp; </code></pre>
javascript
[3]
1,191,892
1,191,893
Use a jQuery script so it can work without having to call the url
<p>Is there a way I can use this script so it can work without having to call the <code>url: "http://localhost/a/rate/update.php"</code></p> <p>Here is the script.</p> <pre><code>function getRatingText(){ $.ajax({ type: "GET", url: "http://localhost/a/rating/update.php", data: "do=getavgrate", cache: false, success: function(result) { // add rating text $("#rating-text").text(result); }, }); } </code></pre>
jquery
[5]
1,410,950
1,410,951
Cross-platform method for finding python include folder
<p>I have python extension code that I need to cross-platform compile, and to do so, I need to be able to find the python include folder. On Linux and Mac OSX, I can do <code>python-config --include</code> and it gives me something like <code>-I/Library/Frameworks/Python.framework/Versions/6.3/include/python2.6</code>. This is fine and dandy, except that my Windows python distro doesn't have <code>python-config</code>. Is there an easy way, through python code, of finding where it thinks the include folder is? For <code>numpy</code>, this snippet does the job: </p> <pre><code>try: numpy_include = numpy.get_include() except AttributeError: numpy_include = numpy.get_numpy_include() </code></pre> <p>Is there an analogous method for the python include folder?</p>
python
[7]
4,526,102
4,526,103
difference between {} and function(){}
<p>I thought these were equivalent.</p> <pre><code>var __Panel = { this.header = null; }; var __Panel = function() { this.header = null; }; </code></pre> <p>The first one gives a compiler error "Expected identifier or string" for <code>this</code>, and "Expected ','" for <code>;</code>.</p> <p>Can someone clarify this a little for me?</p>
javascript
[3]
3,600,633
3,600,634
Vector option in Java
<p>I am using vector of object. My issue is the removal from vector is expensive operation( O(n^2)). What would be the replacement of vector in Java. In my uses addition and removal is extensively happens. </p> <p>i am C++ person don't know much Java</p>
java
[1]
3,324,467
3,324,468
How can I remove all classes that are not named "message" from an element?
<p>I have the following:</p> <pre><code>&lt;div id="abc"&gt; &lt;/div&gt; </code></pre> <p>Inside that div there can be one only of the following:</p> <pre><code>&lt;p class="message"&gt; &lt;p class="message error"&gt;&lt;/p&gt; &lt;p class="message warning"&gt;&lt;/p&gt; &lt;p class="message success"&gt;&lt;/p&gt; &lt;p class="message loading"&gt;&lt;/p&gt; </code></pre> <p>Is there a way that I can find and remove only the class from the <code>&lt;p&gt;</code> element that's NOT "message". I realize I could remove everything and then add what I need with .removeClass() but this won't work for me as after I previously added the message class I did some CSS changes and these will be lost if I remove all and then add again the message class.</p>
jquery
[5]
4,739,089
4,739,090
How can i take image upload value
<p>In my .aspx , </p> <pre><code>&lt;div id="pictureBox"&gt; &lt;img width="150" height="150" runat="server" id="imageField" /&gt; &lt;/div&gt; &lt;br /&gt; &lt;input id="Upload" style="width: 200px; font-family: Myanmar3;" type="file" name="Upload" runat="server" accept="image/*" &gt; &lt;br /&gt; &lt;asp:Button ID="ImageButton1" runat="server" OnClick="upload_Click" CssClass="styleButton" Text="Upload" /&gt; </code></pre> <p>In my .cs ,</p> <pre><code> protected void upload_Click(object sender, EventArgs e) { if (Upload.Value !="") { System.IO.Stream fs = Upload.PostedFile.InputStream; img_uploadStream = Upload.PostedFile.InputStream; System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] bytes = CreateThumbnail(br.ReadBytes((Int32)fs.Length),150); string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); imageField.Src = String.Format("data:{0};base64,{1}", "image/jpeg", base64String); } } </code></pre> <p>The image has upload and show successfully in "imageField" , but the value field of "Upload" input is empty when after "upload_Click" event . I want to take this value back to make another process !</p>
asp.net
[9]
1,443,820
1,443,821
browser identification
<p>I want to identify if the broswer is IE then goto if block, other browser to else block in Java script. I have one code here, </p> <pre><code>var browserName=navigator.appName; if(browserName == "Microsoft Internet Explorer"){ IE code } else{ Other code } </code></pre> <p>but i want to know is there any other way of implementing it?</p>
javascript
[3]
5,448,787
5,448,788
How can I create a sliding layout, like the main android menu?
<p>I need to create an application with 4 view. I need to pass from a view to an other simply by a touch and a move to the left or to the right (no button). The effect I would like is the same that you see when you navigate in the main menu of android when you pass from a page to another.</p> <p>I have tested the ViewFlipper, but I cannot use it: it seems not to catch the touch event correctly. I don't even know if it is the right component.</p> <p>What is the right way to handle this?</p>
android
[4]
2,446,195
2,446,196
Difference between OAuth 2.0 Two legged and Three legged implementation
<p>Can you please explain me the Difference between OAuth 2.0 Two legged and Three legged implementation. And how to chose? Which ones for me?</p>
android
[4]
3,652,651
3,652,652
validate first of multiple text boxes
<p>I need to validate only first text box, among multiple text-boxes, which share a common name</p> <p>Example</p> <pre><code>&lt;input type="text" name="value[]" /&gt; &lt;input type="text" name="value[]" /&gt; &lt;input type="text" name="value[]" /&gt; </code></pre> <p>How can I validate only first text box, using jQuery? I am using jQuery Validation Plugin</p> <p>My jQuery code is like, but it's not working</p> <pre><code>rules: { name:"required", "value[]":"required", }, </code></pre> <p>Please help</p>
jquery
[5]
46,340
46,341
php captcha cannot load when upload to server
<p>Regarding captcha In local PC is working fine but when upload to server (CentOS5.5)</p> <p>PHP captcha cannot load.</p> <p>This is php code call get_captcha.php:</p> <pre><code>$('#captcha-refresh').click(function() { change_captcha(); }); function change_captcha() { document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random(); } </code></pre> <p>get_captcha.php:</p> <pre><code>for ($i = 0; $i &lt; 4; $i++) { $word_1 .= chr(rand(97, 122)); } for ($i = 0; $i &lt; 4; $i++) { $word_2 .= chr(rand(97, 122)); } $_SESSION['random_number'] = $word_1.' '.$word_2; $dir = 'fonts/'; $image = imagecreatetruecolor(165, 50); $font = "recaptchaFont.ttf"; // font style $color = imagecolorallocate($image, 0, 0, 0);// color $white = imagecolorallocate($image, 255, 255, 255); // background color white imagefilledrectangle($image, 0,0, 709, 99, $white); imagettftext ($image, 22, 0, 5, 30, $color, $dir.$font, $_SESSION['random_number']); header("Content-type: image/png"); imagepng($image); $_SESSION['random_numberafter'] = $_SESSION['random_number']; </code></pre>
php
[2]
3,194,691
3,194,692
How to get class name through JavaScript
<p>How do I get the class name through JavaScript given no id with this <code>span</code>.</p> <p>Like: <code>&lt;span class="xyz"&gt;&lt;/span&gt;</code> </p> <p>I want to change the background color of this <code>span</code>.</p> <p>How can I solve this? Please help me.</p>
javascript
[3]
1,213,099
1,213,100
Need help in creating a file tree using jQueryFileTree.js
<p>I am trying to build a file tree structure using jquery.I came across this link</p> <p><a href="http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/" rel="nofollow">http://www.abeautifulsite.net/blog/2008/03/jquery-file-tree/</a></p> <p>So i tried to use it.Below is the html source code of my file.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;script src="js/jquery-1.7.2.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="js/jquery.easing.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="js/jqueryFileTree.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link href="css/jqueryFileTree.css" rel="stylesheet" type="text/css" media="screen" /&gt; &lt;script type="text/javascript"&gt; $(document).ready( function() { $('#container_id').fileTree({ root: '/some/folder/' }, function(file) { alert(file); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container_id"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>But when I open this page in a browser it shows a blank page.Nothing appears.Am I missing something?Please help.Thnx in advance.</p> <p>Note:All the src of script tags are correct.</p>
jquery
[5]
1,033,059
1,033,060
Removing DOM element using jQuery
<p>I have a custom error script that displays custom error messages on a page if a user tries to submit a form and it fails validation.</p> <p>On the focusout of the input element (the input that failed validation) I am trying to remove the DOM element I added, but its removing all of the DOM elements with the class name I specify that exist on the page.</p> <p>Adding the DOM element:</p> <pre><code>$('#' + el).closest('tr').addClass('pink_bg'); var error_txt = $('#' + el).attr('rel'); $('#' + el).before('&lt;span class="registration_error_message"&gt;' + error_txt + '&lt;/span&gt;'); </code></pre> <p>Attempting to remove the DOM element (this removes all of the DOM elements of class="registration_error_message"), all I want to do is remove one of the elements:</p> <pre><code>$("#" + el).focusout(function(){ $(this).parent().remove('[class^=registration_error_message]'); $(this).closest('tr').removeClass('pink_bg red_border'); }); </code></pre>
jquery
[5]
1,252,854
1,252,855
how to set ImageView visible through out the android application for header
<p>I have a header design which contains an ImageView and it is common for all the layouts in my application. I want to set the ImageView visible onclick of some button. The ImageView must visible in all the activities. I am using <code>.setVisibility(View.VISIBLE);</code> but its not working for all the activities.</p>
android
[4]
4,432,237
4,432,238
Why is the C++ scope resolution operator ::?
<p>This is one of the few questions I didn't find an answer to in Design and Evolution of C++ by Stroustroup. Why is the C++ scope resolution operator ::, as opposed to just :?</p> <p>I'm guessing it's because : is already used to indicate the start of an initialization list in a constructor. Does anyone else agree, disagree, or have a definitive answer on this?</p>
c++
[6]
2,884,490
2,884,491
Use a variable-object that was given as an argument
<p>I have some classes that sometimes should connect to the database during the same request. The solution I thought about was to give the PDO Object as an argument to the methods. There is a class that DB() that creates the connection and stores into a public attribute:</p> <pre><code>class DB{ public $conn; public function DB(){ $this-&gt;conn = new PDO(...);//missed :S thxs! } } class Foo{ public function Foo($db[, $more_possible_variables]){ //implementing some stuff with $db } } /*index.php*/ require_once 'DB.php'; require_once 'Foo.php'; $db = new DB(); $foo = new Foo($db-&gt;conn); /*End of index*/ </code></pre> <p>I tried some ideas to make this work, but I always get the error that is not possible to handle a variable like an object. I have other solutions, but they are not recommended from an efficiency point of view...</p>
php
[2]
902,175
902,176
Javascript get nextSibling not class "foo"
<p>I need to get the next sibling of an element but it should not have the class "foo". In jQuery this would be:</p> <pre><code>myEl.next("div.goodClass") or myEl.next().not(".foo") </code></pre> <p>Can this be done with <em>nextSibling</em>?</p>
javascript
[3]
1,544,489
1,544,490
Working with Bitmap? Giving error?
<p>In web application, i am using Bitmap for finding the width and hight of the image. When i write the code it is giving error: Parameter is not a valid.</p> <pre><code> Bitmap bmp = new Bitmap(Server.MapPath("./Images/" + ds.Tables[0].Rows[0]["image"].ToString())); </code></pre> <p>I am getting error can you help me. Thank you. </p>
asp.net
[9]
3,926,223
3,926,224
Running example of NAppUpdate updater
<p>hi can anyone give me running example of NAPPUpdate</p> <p><a href="http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/" rel="nofollow">NAppUPdate</a></p>
c#
[0]
2,337,411
2,337,412
What are some of the must know concepts in ASP.NET?
<p>I am giving a small presentation to a group of Java developers and looking for some core areas to target. Ideally I would like to only talk about the core concepts in ASP.NET.</p> <p>I am coming up with</p> <ul> <li>Authentication</li> <li>Session State</li> <li>ASP.NET MVC</li> <li>LINQ (more .net)</li> </ul> <p>Any more that I should be considering?</p>
asp.net
[9]
1,193,236
1,193,237
Make Div Expand Smoothly
<p>I'm using Javascript to expand a div, but when the content is expanded it's highly abrupt and at best highly unattracive. I was wondering if there was a way to make this div expand slower and more of a visual expand then a BLAM. Now I'm done. </p> <pre><code>&lt;script language="javascript"&gt; function toggle_profile() { var ele = document.getElementById("toggleProfile"); var text = document.getElementById("displayProfile"); if(ele.style.display == "block") { ele.style.display = "none"; text.innerHTML = "View Profile"; } else { ele.style.display = "block"; text.innerHTML = "Hide Profile"; } } &lt;/script&gt; &lt;a id="displayProfile" href="javascript:toggle_profile();"&gt;View Profile&lt;/a&gt;&lt;/p&gt; &lt;br /&gt; &lt;div id="toggleProfile" style="display: none"&gt; </code></pre>
javascript
[3]
4,871,955
4,871,956
How to identify buttons click event which is on the custom cell?
<p>I have custom cell which contains number of rows in it.i want to write it's Action(click event) so how should i identify which buttons clicked and how can i write it's click event for it.Please give me some guidelines for that.i have not implemented yet.</p>
iphone
[8]
2,154,306
2,154,307
onItemSelectedListener is not fired when i select the same previous value
<p>When i am selecteing the same value again which is in adapter the values are not refreshed and even onItemSelectedListener or NothingSelected not fired</p> <p>Here follows my code:</p> <pre><code> spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { new MyBackgroundAsyncTask().execute(); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { new MyBackgroundAsyncTask().execute(); } }); </code></pre>
android
[4]
4,627,108
4,627,109
Apple Push Notification Service
<p>how to know my iphone device is registered or not for applepushnotification service?</p>
iphone
[8]
5,749,331
5,749,332
How do I randomly generate a grid style island map, given two tile types?
<p>I need to write an algorithm than can assign a tile type (one for water and one for land) to every square in a 100 x 100 grid, and I would like it to generate an "island". Something random, but all the land squares together, and all the water squares on the border. Any ideas? </p> <p>I have heard of "perlin noise" but I don't know how to implement it to give the result I want. I feel like also my case is probably too basic for such a complicated algorithm.</p> <p>Thanks!</p>
c++
[6]
1,190,693
1,190,694
Why does code with successive semi-colons compile?
<p>According to my scientific Java experimentation, <code>int x = 0;</code> is equivalent to <code>int x = 0;;</code> which is equivalent to <code>int x = 0;;;;;;;;;;;;;;;</code></p> <ol> <li>Why does Java allow for this? Does it have any practical application?</li> <li>Are each of these just empty statements? Do they actually take up any extra processing time during runtime? (I would assume they're just optimized out?)</li> <li>Do other languages do this? I'm guessing it's something inherited from C, like a lot of things in Java. Is this true?</li> </ol>
java
[1]
5,204,891
5,204,892
Sending large files over socket
<p>I got working over socket file sender, it worked perfectly, but I couldn't send large files with it. Always got heap error. Then I changed the code of client, so it would send file in chunks. Now I can send big files, but there is new problem. Now I recieve small files empty and larger files for example videos can't be played. Here is the code of client that sends file:</p> <pre><code>public void send(File file) throws UnknownHostException, IOException { // Create socket hostIP = "localhost"; socket = new Socket(hostIP, 22333); //Send file FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); OutputStream os = socket.getOutputStream(); //Sending size of file. DataOutputStream dos = new DataOutputStream(os); dos.writeUTF(file.getName() + ":" + userName); byte[] arr = new byte[1024]; try { int len = 0; while ((len = dis.read(arr)) != -1) { dos.write(arr, 0, len); } } catch (IOException ex) { ex.printStackTrace(); } dos.flush(); socket.close(); } </code></pre> <p>and here is the server code:</p> <pre><code>void start() throws IOException { // Starts server on port. serverSocket = new ServerSocket(port); int bytesRead; while (true) { connection = serverSocket.accept(); in = connection.getInputStream(); clientData = new DataInputStream(in); String[] data = clientData.readUTF().split(":"); String fileName = data[0]; String userName = data[1]; output = new FileOutputStream("C:/" + fileName); long size = clientData.readLong(); byte[] buffer = new byte[1024]; // Build new file while (size &gt; 0 &amp;&amp; (bytesRead = clientData.read(buffer, 0, (int) Math.min(buffer.length, size))) != -1) { output.write(buffer, 0, bytesRead); size -= bytesRead; } output.close(); } } </code></pre>
java
[1]
4,829,986
4,829,987
does not execute any code in php tag
<p>I do not know PHP programming, and we have an PHP application in our organization that should be launched. and I have problem with it. when iIdelete this part of index.php application working properly. with in this part of code application does not run. I think the problem is the PHP tag. in this tag does not execute any code.</p> <pre><code> &lt;?php session_start(); if(!isset($_SESSION['initiated'])){ $_SESSION['initiated']=true; session_regenerate_id(true); } error_reporting(0); include("includes/cn.php"); include("includes/config.php"); include("includes/jdf.php"); include_once ('parts/header.php'); if(isset($_GET['df'])) { $qStr = "set GLOBAL read_only = false"; $db_conn-&gt;query($_qstr); if ($db_conn-&gt;errno) { die("Execution failed: ".$db_conn-&gt;errno.": ".$db_conn-&gt;error); } } ?&gt; </code></pre>
php
[2]
5,820,254
5,820,255
Not allowed to start service Intent
<p>I'm trying to call a service from a activity:</p> <p>When I'm running the program the activity throws an error which says: Not allowed to start service Intent. What am I doing wrong? I'm sorry for possible stupid mistakes in the code, but I'm a newbie.</p> <p>activity code: </p> <pre><code>public void startService() { try { startService (new Intent ( this , SmsReminderService.class)) ; } catch (Exception e ) { Log.v("Error" , e.getMessage()) } } </code></pre> <p>service code :</p> <pre><code>public class SmsReminderService extends Service { @Override public void onStart(Intent intent, int startid) { Log.v("SSms", "Service started") ; }} </code></pre> <p>manifest: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="me.sms.smsReminder" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" /&gt; &lt;permission android:name="SEND_SMS"&gt;&lt;/permission&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:label="@string/app_name" android:name=".SmsReminderActivity" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name=".SmsReminderService" android:permission="android.permission.BIND_REMOTEVIEWS"&gt; &lt;intent-filter&gt; &lt;action android:name = "android.intent.category.LAUNCHER" &gt;&lt;/action&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Thanks in advance, Tom </p>
android
[4]
2,017,043
2,017,044
connection refused exception in socket programming
<p>In simple socket programming in java , what ip should be given while making new socket and its on wan </p> <p>//Server side</p> <pre><code>ServerSocket ss = new ServerSocket(8888); System.out.println("\n\n\tWaiting for connection\n"); Socket c = ss.accept(); System.out.println("\n\n\tConnection established\n"); //Client side Socket c=new Socket("192.16*****",8888); System.out.println("\n\n\tSuccessfully connected to the server"); //in **** there is complete ip address of my computer .... i.e. IPV4 address (checked //from ipconfig command on cmd) </code></pre>
java
[1]
3,251,818
3,251,819
Android SDK and AVD Manager hangs trying to rename temporary folders
<p>I run Android SDK and AVD Manager in Vista and have problems installing components. The installer downloads components successfully, but at the end of the installation it hangs for about minute and then asks to disable AV software. If I choose 'No', the installer stops with error message like: "Filed to rename directory '...' to '...' ". Thus, I have to unpack downloaded components and place them to proper folders manually.</p> <p>I have no AV software. I assumed that the installer requires Administrator rights, but runing it as Administrator didn't help.</p> <p>If anybody fixed the issue, please advice something. Thanks.</p>
android
[4]
3,361,523
3,361,524
How to change CreationTime.ToShortDateString() date format?
<p>Code line and output:</p> <pre><code>fileInfo.CreationTime.ToShortDateString(); </code></pre> <p>And the output is for example is <strong><code>11/19/2012</code></strong> which is in this format <strong>MM/dd/yyyy</strong>.<br> How can i change the format to <strong>dd/MM/yyyy</strong>??</p>
c#
[0]
3,885,204
3,885,205
Session value to TextBox Value
<p>How to call a Session and use it as a value of Text Box Form. I am using asp.net</p> <pre><code>&lt;form id="frmLog" name="frmLog" method="post" action="/Page/"&gt; &lt;input type="text" name="UserId" value="&lt;%=Sessiopn["UserID"] %&gt;"&gt;" /&gt; &lt;/form&gt; </code></pre> <p>Thanks!</p>
asp.net
[9]
3,332,733
3,332,734
Controlling how WallpaperManager.setBitmap centers bmp?
<p>I want to set a picture as the wallpaper. I'm simply doing:</p> <pre><code>WallpaperManager wm = WallpaperManager.getInstance(context); wm.setBitmap(bmp); </code></pre> <p>The bmp seems to have a really tight zoom level set, such that only like 40% of the photo is actually visibile on the desktop. Slightly exaggerated, but this is how it appears:</p> <pre><code>------------ | | | -- | | || | (visible rect of phone in center) | -- | | | ------------ </code></pre> <p>There doesn't appear to be a way to control how the wallpaper manager sets the bmp. Do we implicitly control this by cropping our supplied bmp in a different way?</p> <p>Thanks</p>
android
[4]
5,559,335
5,559,336
What is the best way to get all webpage links with Html Agility Pack?
<p>i am try to get all links from webpage with Html Agility Pack, after send web URL (cnn.com) i have this list (return by Html Agility class):</p> <p><img src="http://i.stack.imgur.com/3loeL.jpg" alt="enter image description here"></p> <p>what is the best way to get all this page links cause some of those links start with "/" and not with the page address ?</p>
c#
[0]
1,717,538
1,717,539
something olike the multi desktops app
<p>any idea how to implement something like the multiple desktops of the android?</p> <p>I tried Gallery but it sucks I wansted something just like the desktop app </p> <p>thanks </p>
android
[4]
5,469,465
5,469,466
How to send a php variable using a url
<p>I want to for example send the <code>$test</code> in a url then I want to use <code>$_GET</code> ti get the variable.</p> <p>This is probably a stupid question but if you have another way of doing this then please let me know. By the way I would usually use include for this but I can't use it this time because of some really long reason. The other option I considered was fwrite. The problem with this is that multiple users will be trying to write this files at once. Its just not practical.</p> <p>Any help or hints will be great. Thanks guys. Sorry for the stupid question</p>
php
[2]
4,041,709
4,041,710
Stretch layout to screen
<p>I have the following layout. I'm using layout_weight="1", so that everything will stretch to fit the screen uniformly. The user has the option to delete images, by basically setting visibility="gone".</p> <p>Let's say the user deletes both images in the middle LinearLayout, I want that layout to disappear. Currently, if you delete both images the empty layout stays there leaving a gap. How might I get this to work properly so that the other layouts fill in the empty space?</p> <pre><code>&lt;LinearLayout android:orientation="vertical" android:width="fill_parent" android:height="fill_parent"&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_weight="1"&gt; &lt;Image&gt;&lt;/Image&gt; &lt;Image&gt;&lt;/Image&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_weight="1"&gt; &lt;Image&gt;&lt;/Image&gt; &lt;Image&gt;&lt;/Image&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_weight="1"&gt; &lt;Image&gt;&lt;/Image&gt; &lt;Image&gt;&lt;/Image&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
android
[4]
4,017,922
4,017,923
jQuery - Finding Distinct Values in Object Array
<p>I've got an array of objects where each object has fields like title, description, family, etc. How can I perform a jQuery operation that grabs all objects in this array with a unique family name - similar to SQL's DISTINCT clause?</p>
jquery
[5]
2,735,542
2,735,543
Jquery "nth-child" Issues
<p>I have a list of items, ten in total and will have more however...</p> <p>I've got a "sorting" function which allows the user to view items by "price" or "alphabetically".</p> <p>This works fine, the issue I'm having is the selector line I'm using to get 5th child within the list is bugging out.</p> <p>Here is the line of code:</p> <pre><code>$("#list-category-results li:nth-child(5n)").css("margin-right", "0"); </code></pre> <p>Also, here is a <a href="http://jsfiddle.net/De8Ku/1483/" rel="nofollow">jsFiddle</a> of my current progress.</p> <p>When you click on "price" or "alphabetical" the placement of the "margin-right: 0" doesn't stay on 5th element and I have no idea why??</p>
jquery
[5]
3,001,504
3,001,505
Can't create a zip file with PHP
<p>I've created the following code to create a zip file. I'm pulling a list of files from the database depending on the $job_number (which I'm getting from the global $_GET array) and then trying to add them to the zip file.</p> <p>That part is working fine. It's pulling the list of files from the database, as I can see by echoing or dumping with <code>print_r</code> the results.</p> <p>The only problem is that the .zip file isn't being created at all. I can't see where I've gone wrong.</p> <pre><code>$sth = $conn-&gt;prepare('SELECT `dp_filename` FROM damage_pics WHERE dp_job_number = :job_number'); $sth-&gt;bindParam(':job_number', $job_number); $sth-&gt;setFetchMode(PDO::FETCH_ASSOC); $sth-&gt;execute(); $zip = new ZipArchive(); $zip-&gt;open('example5.zip', ZipArchive::CREATE); $result = $sth-&gt;fetchAll(); echo '&lt;pre&gt;'; print_r($result); foreach ($result as $file) { // just echoing for testing purposes to see if file name is created correctly. $image = $file['dp_filename']; echo $image . "&lt;br /&gt;"; $zip-&gt;addFile("uploads/{$image}"); } $zip-&gt;close(); </code></pre>
php
[2]
3,153,672
3,153,673
getting illegal start of expression error
<p>i'm totally new to java. i 'm try to create my first program &amp; i get this error.</p> <pre><code>E:\java&gt;javac Robot.java Robot.java:16: error: illegal start of expression public String CreateNew (); { ^ Robot.java:16: error: ';' expected public String CreateNew (); { ^ 2 errors </code></pre> <p>below is my program.</p> <pre><code>public class Robot { public static void main(String args[]){ String model; /*int year;*/ String status; public String CreateNew () { Robot optimus; optimus = new Robot(); optimus.model="Autobot"; /*optimus.year="2008";*/ optimus.status="active"; return (optimus.model); } } } </code></pre>
java
[1]
3,560,418
3,560,419
Good practices for intialising properties?
<p>HI, I have a class property that is a list of strings, List. Sometimes this property is null or if it has been set but the list is empty then count is 0. However elsewhere in my code I need to check whether this property is set, so currently my code check whether it's null and count is 0 which seems messy. </p> <pre><code>if(objectA.folders is null) { if(objectA.folders.count == 0) { // do something } } </code></pre> <p>Any recommendation on how this should be handled? Maybe I should always initialise the property so that it's never null? Appolgies if this is a silly question.</p>
c#
[0]
3,495,605
3,495,606
I Have a question about jquery performance
<p>Will I have a performance problem if there are 500 elements with this class?</p> <pre><code>$('.class').hover(function handleIn() { /*code*/ },function handleOut() { /*code*/ }); </code></pre>
jquery
[5]
825,863
825,864
Relations between an object, its constructor and its methods
<p>this is #33 from John Resig`s Learning Advanced JavaScript. <a href="http://ejohn.org/apps/learn/#33" rel="nofollow">http://ejohn.org/apps/learn/#33</a> Would appreciate as much help as you can provide on this.</p> <p>1) technically speaking, is <code>ninja.changeName("Bob")</code> "calling" the function Ninja, or does it go immediately to <code>this.changeName(name);</code> </p> <p>2) Once <code>ninja.changeName("Bob")</code> is invoked, what is the order in which the processing events take place inside function Ninja(name)? </p> <p>3) what exactly is the purpose/function of this.changeName ( name);</p> <pre><code>function Ninja(name){ this.changeName = function(name){ this.name = name; }; this.changeName( name ); } var ninja = new Ninja("John"); assert( ninja.name == "John", "The name has been set on initialization" ); ninja.changeName("Bob"); assert( ninja.name == "Bob", "The name was successfully changed." ); </code></pre>
javascript
[3]
5,248,709
5,248,710
How to resume state of application
<p>I have one activity which starts multiple threads and one doInBackground method. when I launch it is working fine.</p> <p>But everytime I press the back button of the emulator and then again double click of this app it creates a new instance of the application rather than resume it where it is now.</p> <p>I had searched out and read about onRetainNonConfigurationInstance() but how to return instance off all the threads and doInBackground method</p> <p>Hope anyone will understand my problem and what actually I what to do.</p>
android
[4]
896,108
896,109
displaying only thumbnails in directory, but linking to full size image
<p>I have a directory with fullsize images and thumbnails. The thumbnails are prefixed with <code>thumb_</code> and then share the same name as the full size counterparts.</p> <p>What do i need to do the script below to get both the full image and the thumb, so i can echo the correct link? As is, it returns all images.</p> <pre><code>&lt;? $dirHandle = opendir("images"); while ($file = readdir($dirHandle)) { if(!is_dir($file) &amp;&amp; strpos($file, '.jpg')&gt;0 || strpos($file, '.gif')&gt;0 || strpos($file, '.png')&gt;0) { echo ("&lt;a href=images/$file&gt;&lt;img src=images/thumb_$file&gt;&lt;/a&gt;"); } } closedir($dirHandle); ?&gt; </code></pre>
php
[2]