Unnamed: 0
int64
65
6.03M
Id
int64
66
6.03M
Title
stringlengths
10
191
input
stringlengths
23
4.18k
output
stringclasses
10 values
Tag_Number
stringclasses
10 values
3,740,912
3,740,913
php check open through iframe
<p>I want to check using php if the current page is called by an iframe and not directly in the browser.</p> <p>It's a page that gets some $_POST parameters while the sending form's target is an iframe, so the page will display in an iframe.</p> <p>I want to check that using PHP, How?</p> <p>Thanks.</p>
php
[2]
2,557,002
2,557,003
Include $_POST, $_GET, $_SERVER values in PHP Error Log
<p>I have code like this</p> <pre><code>try { header("Location: http://www.google.com\n-abc"); } catch (Exception $e) { error_log(print_r($_POST, true)); error_log(print_r($_GET, true)); error_log(print_r($_SERVER, true)); } </code></pre> <p>Without the try {} catch {} block, I can see the POST, GET and SERVER variables in my error_log, but with the try {} catch {} block, I only see the default PHP error. </p> <ol> <li>Is there a way to show the POST, GET, and SERVER variables in a try {} catch {} block?</li> <li>Is there a way to have PHP include POST, GET, and SERVER variables for ALL errors that get logged to file and not just wherever I have added error_log(print_r($_POST, true)); ....?</li> </ol>
php
[2]
2,196,175
2,196,176
How to read an array and animate the results
<p>I read through several examples of loading an array manually with graphical image file names. The array is then referenced with a few lines of code and the graphical images are animated which looks great.</p> <p>I have a method that I call that reads data from a SQLITE table and loads an array that contains the file names of the images. The SQL call includes an order by statement to get the images ordered correctly in the array.</p> <p>I then return from the call to the method and can get the count from the array. I can not figure out how to read the array from the SQL call and get an array built in a way that I can hand it to the UIImage to animate the results. It seems that my main stumbling block is the reading of the text values in the array. I anticipate that I would actually define a new array using initWithObjects and supply the text value of each element in the array in a statement that looks similar to: [UIImage imageNamed: (value of an element from the array)] but am not having any luck reading the initial array and be able to see the clear text value of what was stored initially.</p>
iphone
[8]
5,020,818
5,020,819
expandable list not looking properly in 2.1 QVGA
<p>i have developed an application for 1.5 and above which uses expandable list ,but when i test it on 2.1 QVGA emulator expandable list dosent look proper . Also i have tried running sample Expandablelist1 ,but it also has same issue. so can anyone tell me is this issue with emulator only? if yes how to resolve it?</p> <p>Thanks in advance</p>
android
[4]
4,875,847
4,875,848
Get entire BODY content using PHP DOM DOCUMENT
<p>I want to get entire body tag content using DOM Document. </p> <p>I used following code:</p> <pre><code>$dom = new domDocument; /*** load the html into the object ***/ $dom-&gt;loadHTML($html); /*** the table by its tag name ***/ $tables = $dom-&gt;getElementsByTagName('body')-&gt;list(0)-&gt;nodeValue; </code></pre> <p>This gives me TExt. I want entire body content. </p>
php
[2]
4,953,341
4,953,342
Javascript Incrementer
<pre><code>&lt;script type="text/javascript"&gt; function Incrementer() { debugger; var txtBox = document.getElementById('MainContent_TextBox1').value; int i = parseInt(txtBox); i = i + 1; var v = i + ""; document.getElementById('MainContent_TextBox1').value = v; alert(v); } &lt;/script&gt; &lt;asp:TextBox ID="TextBox1" runat="server" Text="0"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt; &lt;asp:Button ID="Button1" runat="server" Text="Up" OnClientClick="Incrementer();"/&gt; &lt;asp:Button ID="Button2" Text="Down" runat="server"/&gt; &lt;/asp:Content&gt; </code></pre> <p>I am unable to increment the value in javascript....what is the problem?</p>
javascript
[3]
5,580,115
5,580,116
too see if checkboxes have been checked javascript
<p>Hallo </p> <p>How would I go about in checking whether checkBox has been checked in javascript? I C# it is simple enough</p> <pre><code>int selected = 0; for (int loop = 0; loop &lt; chkMeal.CheckedItems.Count; loop++) { selected++; } if (selected &gt; 1) { MessageBox.Show("only one meal allowed", "Halt", MessageBoxButtons.OK, MessageBoxIcon.Error); } </code></pre> <p>How could I do a simlar thing with javascript?</p> <p>kind regards Arian</p>
javascript
[3]
3,029,014
3,029,015
Why does the command, alert($(this).attr("id")); return "undefined"?
<p>Why does the command</p> <pre><code>alert($(this).attr("id")); </code></pre> <p>return "undefined"? I'm using it in ASP NET and Internet Explorer 8.</p>
jquery
[5]
1,379,917
1,379,918
Stop a fadeOut within a callback of another fadeOut
<p>I am trying to stop an animation from propagating on a call back of another animation, i have tried to stop the animation directly by adding <code>.stop(true, true)</code> onto the element that i wish to stop from fading but it doesn't seem to stop the animation.</p> <p>I have created a fiddle -> follow the link <a href="http://jsfiddle.net/5rEWa/" rel="nofollow">http://jsfiddle.net/5rEWa/</a></p> <p>Here is the code:</p> <pre><code>$('.fadeMe').delay(3000).fadeOut(1000, function(){ $('.meToo').fadeOut(1000); }); $('#stop').click(function(){ $('.meToo').stop(true, true); }); </code></pre> <p><em>As always stack i am greatful for your help</em></p>
jquery
[5]
218,749
218,750
From Java SE to web development
<p>I am about to start a new job as a junior web developer with a small company. I do have a degree in Software Engineering and have done some work with building web sites, but very basic, html, and VB.net. My experience with Java is very strong and thus that is why I think this company is taking me on, the fact I can code in Java/C++ and understand OOP. Yet, they want me to learn CakePHP and frankly I dont know jack about web technology like js, php, etc...</p> <p>Has any other Java/C++ programmer jumped from desktop application programming to web development? and if so what tips would you have and how difficult was it to make the change.</p> <p>It seems like in todays world everyone wants web programming rather then your standard Desktop programmers. I don't mind mastering web development but I find it funny that they push Java/C++ in colleges but the real world wants programmers which know web development. I could be wrong.</p>
java
[1]
2,762,893
2,762,894
How to get id of previous element by using mouseovered element's id which was taken from its class
<p>I did this but it didn't work. Can anyone help me? Thanks.</p> <pre><code>$('.current_element').mouseover(function() { var currentElementId = $(this).attr('id'); var previousElementId = $('#' + currentElementId).prev('.previous_element').attr('id'); }); </code></pre>
jquery
[5]
2,964,749
2,964,750
PHP secure downloader with PayDotCom or Paypal
<p>The script below is a quick and dirty attempt to provide a means of protecting my files that I'm selling on PayDotCom and Paypal.</p> <p>If anyone has experience with these services, I have a few questions...</p> <p>1) Is there a token that I can set at either of these pay sites that I can then check for in the script below before executing the download?</p> <p>2) In the script below, the file that is retrieved is correct, however, the filename it wants to save it to is the same as the PHP processing page (secure-download.php). How can I change the saved file's filename? e.g. it will be a zip file.</p> <p>3) There's a few notes in the code below, I need some advice on...</p> <pre><code>&lt;?php $file = basename(urldecode($_GET['file'])); $fileDir = dirname(dirname( dirname( __FILE__ ) ) )."/secure/"; // The secure directory is outside of www root if (file_exists($fileDir . $file)) { // Note: Need advice here to do some more checks // on the filetype, size, etc. $contents = file_get_contents($fileDir . $file); // Note: Need to implement some kind // of check on filetype header('Content-type: application/zip'); echo $contents; //currently the filename is same as the processing file, need to change it to [somefile].zip } ?&gt; </code></pre>
php
[2]
2,776,861
2,776,862
Heritage, dynamic binding, counstructor in superclass. Java.
<p>How come the first System.out.println does not print a value of 10? It prints a 0. First a new Child-object is created which calls the constructor in Parent. The constructor in Parent calls lookup in Child because of dynamic binding. So why does lookup in Child return a zero and not a ten?</p> <pre><code>public class Main332 { public static void main(String args[]) { Child child = new Child(); System.out.println("child.value() returns " + child.value());//Prints 0 Parent parent = new Child(); System.out.println("parent.value() returns " + parent.value());//Prints 0 Parent parent2 = new Parent(); System.out.println("parent2.value() returns " + parent2.value());//Prints 5 } } public class Child extends Parent { private int num = 10; public int lookup() { return num; } } public class Parent { private int val; public Parent() { val = lookup(); } public int value() { return val; } public int lookup() { return 5;// Silly } } </code></pre>
java
[1]
1,228,813
1,228,814
How to know if another application set the largeHeap or not programatically?
<p>I found some game apps use larger memory than the default limit (64MB in Nexus 7). </p> <p>To achieve that, I assume they set the <code>android:largeHeap="true"</code> </p> <p>In my codes, I want to check if an app set this flag or not. Any clue?</p>
android
[4]
3,512,286
3,512,287
Referencing the current jQuery object in a chain?
<p>At DevDays in SF last year (before jQuery 1.4 was released), I thought they mentioned an upcoming feature in 1.4 that would allow you to reference the current jQuery object while in a chain. I've read through all of the 1.4 improvements and wasn't able to find it. Does anyone know how this can be done?</p> <p><strong>Example</strong></p> <p>Being able to access the current jQuery object would be helpful when working with methods that are in relation to the current object like .next():</p> <pre><code>// Current way var items = $(this).closest('tr'); items = items.add(items.next(':not([id])')); // Magical 1.4 way? Is there a "chain"-like object? var items = $(this).closest('tr') .add(chain.next(':not([id])')); </code></pre>
jquery
[5]
5,021,143
5,021,144
Simple application development
<p>i want to know how to develope a simple application for nokia mobile phone ?</p>
c++
[6]
1,478,130
1,478,131
Call an external function from inside function in jQuery
<p>I try to extend jQuery, but when I call myTest this will return this.myTest.test() is undefined...</p> <p>can someone tell me why...</p> <pre><code>(function($) { $.fn.myTest=function() { var x=function() { this.myTest.test(); var b = function() { this.myTest.coba(); } } x(); return this.each(function(){ }); }; $.fn.myTest.test = function(){ alert('test'); }; $.fn.myTest.coba = function(){ alert('coba'); }; $.fn.myTest.iseng = function(){ alert('iseng'); }; })(jQuery); </code></pre>
jquery
[5]
3,803,178
3,803,179
Reload a table view on close of add subview
<p>I have three objects in the applicaion. There is a UItableviewcontroller(with nib file) that shows a list of the items. One UIviewcontroller to add item (with nib file) and a model class that contains item object.</p> <p>I show the list of item firstly (on application start). I have a navigation button on navigation bar to pop up add view (add as subview) on the same screen (on table view). In add view I have a add button. when I click on add button it adds the record and disappear from the table view but doesn't reload the that.</p> <p>I have used following code in add item button click action</p> <pre><code>listitem *home= [[listitem alloc] initWithNibName:@"listitem" bundle:nil]; [self.navigationController pushViewController:home animated:YES]; [home viewWillAppear:YES]; [home release]; [self.view removeFromSuperview]; </code></pre> <p>In viewwillappear function I am reloading the data from database and also reloading the table view data using reloadData.</p> <p>Am I doing correct. What is the mistake I am doing.</p>
iphone
[8]
385,503
385,504
timeoffset in whole minutes in c#
<p>I have a method that calculates the number of minutes between two times. Something like this:</p> <pre><code>DateTime UserLocalTime = DateTime.UtcNow.ConvertToUserTime(UserTimezoneID); double TheOffset = (UserLocalTime - DateTime.UtcNow).TotalMinutes; return TheOffset.ToString(); </code></pre> <p>The problem is that it's returning something like 119.83723 because it's calculating minutes AND seconds and such.</p> <p>How can I fix this? I'm afraid sometimes it'll also return 120.11233 so rounding might not totally help either.</p> <p>Thanks for your suggestions.</p> <p><em>Update1: (int)(Math.Round((UserLocalTime - DateTime.UtcNow).TotalMinutes)); returns 119.</em></p> <p>Update2: I tried this, it looks like it works but will fail when the offset is weird (sometimes it might be 5:30 and the answer should be 330 minutes)</p> <pre><code>int TheOffset = (int)(Math.Round((UserLocalTime - DateTime.UtcNow).TotalHours)); TheOffset = TheOffset * 60; </code></pre>
c#
[0]
5,836,227
5,836,228
Good framework for logins in PHP
<p>I have a MySQL database full of members of an organization with their passwords and other accompanying data. Is there a good PHP framework for a log-in system? I'd like something like what they do on yahoo, where you can browse the pages without logging in but you need to log in to access certain content.</p>
php
[2]
5,980,125
5,980,126
Is there a encryption api's available to encrypt log file while using Microsoft Enterprise Library 3.1
<p>How to encrypt a string message while it is being logged into the log file using Logger.Write(...) in Microsoft Enterprise Library 3.1. Are there any inbuilt API's in Microsoft Enterprise Library which does encryption? </p>
c#
[0]
4,688,618
4,688,619
there is no alert prompt when run this simple javascript code?
<pre><code>var foo = function(){}; foo.prototype.value = 5; foo.prototype.addValue = function(){ foo.value = 6; } function bar(func) { func(); // I'm running the function! } bar(foo.addValue); // pass in the function alert(foo.value); // it's now 6! </code></pre> <p>Why is the no alert prompt when running this JavaScript code?</p>
javascript
[3]
3,683,598
3,683,599
Assign variable in Java while-loop conditional?
<p>I have a method that does a lot of checking and computation and returns a custom class, returnMessage. returnMessage has 2 booleans and a String. What I want to do is run this method in a while loop from my main class and have access to the returnMessage object after the while loop terminates for the last time. </p> <p>In php this would be a case of </p> <pre><code>while ( $returned = myObject-&gt;myMethod()-&gt;finished ) { } if( $returned -&gt; finished == FALSE) { ... } </code></pre> <p>However trying to assign like this gives me a boolean expected error in java (there might be php errors in the above, it's late :D ) </p>
java
[1]
2,619,859
2,619,860
std compliant stringstream using stack allocated storage?
<p>Can't seem to find anything currently available in the wild, which seems odd.</p> <p>So before I roll my own, does anyone know of a std compliant stringstream which allocates storage on the stack?</p> <p>I'm thinking of 2 ways to achieve this:</p> <p>Initially use a statically sized buffer on the stack (probably a template parameter to allow compile-time customization)</p> <ol> <li>When space runs out revert to using dynamic storage</li> <li>When space runs out use <code>alloca</code> to increase the stack storage</li> </ol> <p>This will allow quick input into a stringstream for strings shorter than the predetermined size. </p> <p>A suitable choice for the initial size will mean that things like logging can be achieved without frequent resizing from the heap.</p>
c++
[6]
874,486
874,487
Please help flicker implement on android
<p>Anybody idea how to integrate flicker to my application on android?. i got API key secrete key for my application from flicker.com site. i am confused how to use it. Api key separate for every user? how to get token number for flickr by code ? i have refer photostream and Flicker free code . but both code give the exceptiion.?</p> <p>plz any body have code ,plz give me it?</p> <p>also explain steps for implement it?</p> <p>Thank you,</p>
android
[4]
2,260,411
2,260,412
Populating ComboBox
<p>i have this questions... my scenario is to populate combobox from the database and display customer name and hold a value of the id...my id i use identity increment...tnx</p> <pre><code>SqlConnection conn = new SqlConnection(connectionString); conn.Open(); //SelectCustomerById(int x); comboBoxEx1.Items.Clear(); SqlCommand comm = new SqlCommand("spSelectCustomerByID", conn); //comm.Parameters.Add(new SqlParameter("cust_name", cust_name)); //comm.CommandText = "spSelectCustomerByID"; comm.Parameters.Add(new SqlParameter("cust_id", SqlDbType.Int)); comm.CommandType = CommandType.StoredProcedure; comm.ExecuteNonQuery(); SqlDataAdapter sdap = new SqlDataAdapter(comm); DataSet dset = new DataSet(); sdap.Fill(dset, "cust_registrations"); if (dset.Tables["cust_registrations"].Rows.Count &gt; 0) { comboBoxEx1.Items.Add("cust_registrations").ToString(); } comboBoxEx1.DataSource = dset; comboBoxEx1.DisplayMember = "cust_name"; </code></pre>
c#
[0]
4,619,883
4,619,884
adding multiple Views to multiple layouts
<p>I want to add ovals to each view that I have but it seems like it only adds it to the first layout. Any ideas</p> <p>Here is my xml code</p> <pre><code>&lt;RelativeLayout android:id="@+id/first_plane" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/RelativeLayout&gt; &lt;RelativeLayout android:id="@+id/second_plane" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/RelativeLayout&gt; </code></pre> <p>These are both inside a LinearLayout</p> <p>Here is the code that I am trying</p> <pre><code>DrawOval firstOval = new DrawOval(this, 400, 20, 650, 100); firstOval.setBackgroundColor(Color.TRANSPARENT); ViewGroup firstLayout = (ViewGroup) findViewById(R.id.first_plane); firstLayout.addView(firstOval); DrawOval secondOval = new DrawOval(this, 200, 150, 450, 230); secondOval.setBackgroundColor(Color.TRANSPARENT); ViewGroup secondLayout = (ViewGroup) findViewById(R.id.second_plane); secondLayout.addView(secondOval); </code></pre> <p>THank you</p>
android
[4]
4,440,380
4,440,381
Getting objects from an Array
<p>I may be doing this very badly but I'm new to this! if I have an array that contains objects like this</p> <pre><code>var company = [H7 = {companyName:"company1"},F4 = {companyName:"company2"}] </code></pre> <p>If I get a reference as a string say "F4" is there any way I can go</p> <pre><code>myCompName = company "F4" companyName and get the result "company2" </code></pre> <p>I was trying to use inArray like this</p> <pre><code>myStand = $.inArray("F4", companyObjects) myCompName = companyObjects[myStand].companyName </code></pre> <p>but this doesn't work and yet</p> <pre><code>myStand = $.inArray(F4, companyObjects) myCompName = companyObjects[myStand].companyName </code></pre> <p>does work. Do I have my array set up wrong or is there a way to do this? Thank you Alex</p>
jquery
[5]
4,820,140
4,820,141
Java API that can analyze HTTP requests for malicious inputs?
<p>my idea is to create a proxy application firewall that will analyze and filter out HTTP requests from the client accessing a web application, here's a scenario let say a web application that will ask a user for log in details, the proxy application firewall should then be able to analyze the HTTP request from the user for any invalid characters like quotes '',""_-@ and so on. </p>
java
[1]
4,366,046
4,366,047
a generic error occurred in gdi+. while saving an image
<p>Dear Expert i am getting an error while saving an image the code is as follows </p> <pre><code> ClsImageManager objImgManager = new ClsImageManager(); Bitmap ImageBitmap = objImgManager.GetBitmapFromBytes(ImageData); Response.ContentType = "image/tiff"; ImageBitmap.Save(Response.OutputStream, ImageFormat.Tiff); ImageBitmap.Dispose(); Response.End(); </code></pre> <p>when i used Image.format.jpeg the code is working good but when i changes it to ImageFormat.Tiff then i am getting an error <strong>a generic error occurred in gdi+.</strong></p>
asp.net
[9]
881,419
881,420
Android: Proper Way to use onBackPressed()
<p>I wrote a piece of code that will give the user a prompt asking them to press back again if they would like to exit. I currently have my code working to an extent but I know it is written poorly and I assume there is a better way to do it. Any suggestions would be helpful!</p> <p>Code:</p> <pre><code>public void onBackPressed(){ backpress = (backpress + 1); Toast.makeText(getApplicationContext(), " Press Back again to Exit ", Toast.LENGTH_SHORT).show(); if (backpress&gt;1) { this.finish(); } } </code></pre>
android
[4]
2,424,609
2,424,610
python logging.info does not print, logging.warn and logging.error does
<pre><code>import logging if __name__ == "__main__: logging.info('info') logging.warn('warning') logging.error('error') </code></pre> <p>Result: </p> <pre><code>warning error </code></pre> <p>Why does <code>logging.info</code> doesn't report? </p> <p>Thank you</p>
python
[7]
5,144,971
5,144,972
What's the value of characters in execution character set?
<p>Quote from C++03 2.2 Character sets:</p> <blockquote> <p>"The basic execution character set and the basic execution wide-character set shall each contain all the members of the basic source character set..The values of the members of the execution character sets are implementation-defined, and any additional members are locale-specific."</p> </blockquote> <p>According to this, <code>'A'</code>, which belongs to the execution character set, its value is implementation-defined. So it's not 65(ASCII code of <code>'A'</code> in decimal), what?!</p> <pre><code>// Not always 65? printf ("%d", 'A'); </code></pre> <p>Or I've a misunderstanding as to the <strong>value</strong> of a character in execution character set?</p>
c++
[6]
1,173,042
1,173,043
I need to primitive root of prime number?
<p>I need to primitive root of prime number.I wrote this code but it has heap size error and it doesn't work for big number like 101.I don't have any other idea for calculating primitive root .If you have please help me .I need to it so much.Do you have any other algorithm for calculating primitive root of prime number?</p> <pre><code>static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; list1=new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;(); private static int primitiveRoot(int prim){ ArrayList&lt;ArrayList&lt;Integer&gt;&gt; number=new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();// this has all sequence numbers of x power of 0 to prime-1 ArrayList&lt;Integer&gt; sublist=new ArrayList&lt;Integer&gt;(); for (int x=2;x&lt;prim;x++ ){ sublist = new ArrayList&lt;Integer&gt;(); for (int power=0;power&lt;prim-1;power++){ int i=(int)((Math.pow(x, power))%prim); sublist.add(i); } number.add(sublist); } for (int j=0;j&lt;number.size();j++){ for (int m=0;m&lt;list1.size();m++){ if(number.get(j).equals(list1.get(m)) ){// element of number arraylist compare to list1,equality means that we find one of primitive root a=j+2; break; } } } return a;// this is primitive root } </code></pre> <p>list1 is an arraylist of arraylists ,It contains all permutations of numbers between 1 to prime-1.It only work for small prime number like 7 or 11 .I increased heap size but It didn't effect.</p>
java
[1]
1,281,575
1,281,576
Does Android support 'Receiver' mode for playing audio files?
<p>I have a requirement where I need to play an audio file in receiver mode(earpiece).I am not sure whether higher versions of Android SDK supports this receiver mode.I went through some links which said about 1.5/1.6 having changes in these Audio APIs and hence not sure. :(</p> <p>Can someone please help?</p> <p>Thanks.</p>
android
[4]
374,133
374,134
How i campare two dates in Iphone?
<p>I want to set date and time two days after my current date and time.How i set it using NSDate and dateformatter. I want compare date after two days, it was perviously set or not.</p> <p>I write code now for it, NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];</p> <pre><code>NSDate *pickerDate = [self.datePicker date]; NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit ) fromDate:pickerDate]; NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:pickerDate]; NSDateComponents *dateComps = [[NSDateComponents alloc] init]; [dateComps setDay:[dateComponents day]]; [dateComps setMonth:[dateComponents month]]; [dateComps setYear:[dateComponents year]]; [dateComps setHour:[timeComponents hour]]; [dateComps setMinute:[timeComponents minute]]; [dateComps setSecond:00]; NSDate *itemDate = [calendar dateFromComponents:dateComps]; [dateComps release]; appDelegate.setTimerByUser = [itemDate retain]; </code></pre> <p>How i compare it with current time and date? Thanks</p>
iphone
[8]
3,194,385
3,194,386
Benefits of JavaScript anonymous function with namespaces
<p>Is there any benefit when writing JavaScript classes and namespaces of this...</p> <pre><code>if(typeof MyNamespace === 'undefined'){ var MyNamespace = {}; } (function(){ MyNamespace.MyClass = function(){ this.property = 'foo' return this; } }()); </code></pre> <p>Versus just this...</p> <pre><code>if(typeof MyNamespace === 'undefined'){ var MyNamespace = {}; } MyNamespace.MyClass = function(){ this.property = 'foo' return this; } </code></pre> <p>I have seen the first pattern implemented in a few libraries, and was trying to find how out if there is any added benefit unless some sort of other function was declared inside of the anonymous function in the first example.</p>
javascript
[3]
2,451,514
2,451,515
Javascript 'this' not returning object clicked on
<p>i have an anchor tag generated in my code behind that calls a function with </p> <pre><code>href="javascript:blah('string',this);" </code></pre> <p>I need to interact with the object but it doesn't seem to be returning the correctly. When I alert this it returns "object Window" and calls to this.id return undefined (the anchor has an ID)</p> <p>any ideas?</p> <p>Thanks</p>
javascript
[3]
941,203
941,204
null pointer to object inside object method
<p>I have a class A</p> <pre><code>class A { A(); ~A(); DoSomething(); } </code></pre> <p>I then declare an object and a pointer to the allocated object</p> <pre><code>A Obj; A* pObj = &amp;Obj; </code></pre> <p>I've found out that inside DoSomething() I am setting pObj to NULL</p> <pre><code>A::DoSomething() { pObj=NULL; } </code></pre> <p>So inside a method I am killing the pointer to myself... and this isn't crashing...</p> <p>note: I've noticed that in the debbuger <em>this is (Obj</em> const).</p> <p>I am having some trouble understanding why this isn't causing any kind of corruption. I assume that this isn't safe, but I can't really understand the ramifications of this.</p> <p>Cheers</p>
c++
[6]
5,642,430
5,642,431
quick javascript function help
<p>I have this function, and I want to pass a variable (z) to the OnClick event of an image.</p> <p>I have this:</p> <pre><code>for (z=1; z&lt;img_src.length; z++){ path_th_img= 'ad_images/'+category+'/'+'thumbs/'+img_src[z]; document.getElementById("thumb_pic_div").innerHTML += "&lt;img src='"+path_th_img+"' class='shadow2' style='margin:7px;' onclick='imageShow(z);'&gt;"; } </code></pre> <p>img_src.lengt is in this case 4... So no matter which of the three images I click, the nr 4 gets passed on... ideas?</p> <p>Thanks</p>
javascript
[3]
1,387,685
1,387,686
Why is assigning to $bool1 or $bool2 different from assigining to the same statement wrapped in parenthesis?
<p>I'm completely confused. Why, on a grammatical level, would the two statements below be any different?</p> <pre><code>$bool1=false; $bool2=true; //Statement1 $result=$bool1 or $bool2; // Returns false //Statement2 $result=($bool1 or $bool2); // Returns true </code></pre> <p>As far as I'm aware, those two statements should be completely and absolutely identical. But, for some reason, they aren't. I can work around this, but the fact that they aren't identical means I'm missing some aspect of the language, and I don't have a clue where to check.</p>
php
[2]
3,071,230
3,071,231
Cannot make reference to Facebook sdk project
<p>I am tryin to integrate facebook in my android app. In some tutorials, I see that i must make a reference to base facebook project. I try this and all looks like must be:<a href="http://i53.tinypic.com/vkehl.png" rel="nofollow">here</a> After that i open properties again and here is result : <a href="http://i51.tinypic.com/29yjtzc.png" rel="nofollow">here</a> There is no connection between the projects. Can you help me with that? 10x in advance.</p>
android
[4]
214,346
214,347
How to read all splitcontainers and i
<p>Hi I have 50 splitcontainers.. i want to read all the splitcontainers &amp; its panels programmatically...Is it possible...?</p> <p>Because the below code only reads Splitcontainer4 &amp; Panel1, But Iam looking to read all the splitcontainers and its panels programmatically...</p> <pre> foreach (Control Ctrl in this.splitContainer4.Panel1.Controls) { if (Ctrl is RichTextBox) { ((RichTextBox)(Ctrl)).KeyPress += new KeyPressEventHandler(this.Common_KeyPress); } } </pre> <p>Thanks for ideas...</p> <p>Regards PARAMU </p>
c#
[0]
1,203,667
1,203,668
Have I got the syntax incorrect for this jquery else if statement?
<p>Edit: <strong>Question resolved. Syntax error.</strong></p> <p>Here it is (the if part omitted as I know it is correct)</p> <pre><code>else if($('.now [name="stuff"]').val() !==''){...} </code></pre> <p>I want to check the value of the input field withhin the class 'now' and with the name 'stuff' and if the value is not empty, then execute the code within the braces.</p> <p>have I made a mistake? as my code isn't working.</p> <p>Edit here is the code in context: (NOTE - if i delete the else if part the code runs. Currently when I try to run the below code firefox tells me the function which contains the code is undefined)</p> <pre><code>if($("#form").length==0) { .... } else if($('.now [name="stuff"]').val() !==''){ $.post("ajax.php", { "action": "refresh", "app_id": app, "type": type, "page": page, "test": "test"; "refresh": "1", "br": $("#br").val(), "brtwo": $('.current [name="brtwo"]').val(), }, function(data) { $(".current").html(data); scrollTo(0, 0); }); } else { ... } </code></pre>
jquery
[5]
4,561,491
4,561,492
Query about scope of variables in java
<pre><code>public class Knowing { static final long tooth = 343L; static long doIT(long tooth) { System.out.print(++tooth + " "); return ++tooth; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.print(tooth + " "); final long tooth = 340L; new Knowing().doIT(tooth); System.out.println(tooth); } } </code></pre> <p>Okay so here is my question: </p> <ul> <li><p>If we have a global variable declared <code>static final long tooth = 343L;</code> How can we have another variable in the main method declared <code>final long tooth = 340L;</code> I just want to know why this is allowed because I ran it and there was no error?</p></li> <li><p>And also shouldn't the access of the global static variable tooth be by using <em>className.variableName</em> and not by creating a new <em>instance.variable</em> name how come that is allowed with only a warning?</p></li> </ul>
java
[1]
5,856,485
5,856,486
PHP Wordpress add class="last" to last item in menu list
<p>I'm drawing out a listing of menu items inside a wordpress template (header.php) and need to assign a special className to the last menu item in the list. I'm building the list with this code...</p> <pre><code>$myposts = get_posts(); foreach($myposts as $post) :?&gt; &lt;li&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; </code></pre> <p>I'd like to add this to the last menu item...</p> <pre><code>&lt;li class="last"&gt;... </code></pre>
php
[2]
4,707,042
4,707,043
Context in a PreferenceFragment
<p>taken from <a href="http://developer.android.com/guide/topics/ui/settings.html" rel="nofollow">http://developer.android.com/guide/topics/ui/settings.html</a>:</p> <blockquote> <p>Note: A PreferenceFragment doesn't have a its own Context object. If you need a Context object, you can call getActivity(). However, be careful to call getActivity() only when the fragment is attached to an activity. When the fragment is not yet attached, or was detached during the end of its lifecycle, getActivity() will return null.</p> </blockquote> <p>If I call getActivity() from within the OnCreate() method of a PreferenceFragment then can I be assured that the fragment is attached to its activity - or is there some other way you should get the Context in this instance?</p> <p>The reason I need a Context is I'm trying to use a Toast notification from the PreferenceFragment</p>
android
[4]
4,212,313
4,212,314
How can i know app information from appstore programamtically
<p>I am developing one application. In that I want to know some X application is available in AppStore or not programmatically. So please tell me how can I access and get the information from app store programmatically.</p>
iphone
[8]
49,497
49,498
Bulk Rename Files in a Folder - PHP
<p>I have 1000 images in a Folder, which has SKU# word in all the images. For examples</p> <pre><code>WV1716BNSKU#.zoom.1.jpg WV1716BLSKU#.zoom.3.jpg </code></pre> <p>what i need to do is read all the filenames and rename it to the following</p> <pre><code>WV1716BN.zoom.1.jpg WV1716BL.zoom.3.jpg </code></pre> <p>So remove SKU# from filename, is it possible in PHP to do bulk renaming ?</p>
php
[2]
1,160,280
1,160,281
How do I remove ' ' from a string in PHP?
<p>This character is coming from the database. I have a description which contains the image tag and text, but <code></code> is appearing in the beginning of that description.</p>
php
[2]
4,478,434
4,478,435
What are some good resources for Javascript Error handling
<p>I recently ran into some issues this week on a web app that I built and I realized that I didn't have a good process in place for handling errors. What are some good resources on the subject? I'm talking links, books, videos, slides, whatever. </p>
javascript
[3]
1,687,460
1,687,461
Two conditions in a for loop
<p>Why does this for loop work with each condition on their own, but together the first condition doesn't matter?</p> <pre><code>for ($j = 0; $j &lt; 5 or $j &lt; $synCount; $j++) </code></pre> <p>I only want the loop run five times</p> <p>or</p> <p>if synCount is less than this.</p>
php
[2]
4,043,307
4,043,308
To continue in Android career?
<p>Ive been learning android for two months now,Its pretty long,a little bit interesting,I have java knowledge but the question is,I want to venture into writing apps for companies like stores e.t.c,how this can metamorphosize into a career. Some say its too early to make it a career line..Is it?</p>
android
[4]
969,127
969,128
Create video in iPhone
<p>I need to convert image sequences(ie,png) to video file in iPhone. How i can convert the images to video. </p> <p>Regards,</p>
iphone
[8]
5,452,060
5,452,061
Round DateTime to closest quarter hour
<p>How can I round a DateTime object to the closest quarter hour?</p> <p>So: 2011-05-30 09:11:00 will be rounded to 2011-05-30 09:15:00, 2011-05-30 09:47:00 will be rounded to 2011-05-30 09:45:00 and so on.</p>
php
[2]
4,135,332
4,135,333
Get website source
<p>So I have this source which gets the source from a website:</p> <pre><code>WSADATA wsaData; if (WSAStartup(MAKEWORD(2,2), &amp;wsaData) != 0) { cout &lt;&lt; "WSAStartup failed.\n"; system("pause"); return 1; } SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); struct hostent *host; host = gethostbyname("www.site.com"); SOCKADDR_IN SockAddr; SockAddr.sin_port=htons(80); SockAddr.sin_family=AF_INET; SockAddr.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr); cout &lt;&lt; "Connecting...\n"; if(connect(Socket,(SOCKADDR*)(&amp;SockAddr),sizeof(SockAddr)) != 0){ cout &lt;&lt; "Could not connect"; system("pause"); return 1; } cout &lt;&lt; "Connected.\n"; send(Socket,"GET / HTTP/1.1\r\nHost: www.site.com/auth.php\r\nConnection: close\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: www.site.com/auth.php\r\nConnection: close\r\n\r\n"),0); char buffer[10000]; int nDataLength; while ((nDataLength = recv(Socket,buffer,10000,0)) &gt; 0){ int i = 0; for(; i != nDataLength; ++i) cout &lt;&lt; buffer[i]; } closesocket(Socket); WSACleanup(); </code></pre> <p>The problem is, its not navigating to auth.php. Also, how would I send GET vars like ?name=bleh</p>
c++
[6]
2,413,048
2,413,049
code not working when checking table row count
<p>I'm trying to count the number of rows in a table of search results when the user presses the search button. I am doing this, so that the table is cleared of previous search results if any are present.</p> <p>However, the code doesn't work. Nothing happens when the user presses search. If I remove or comment out the code, then it works fine. </p> <p>Here is my code that is causing issues:</p> <pre><code> var rowCount = $(this + " tr").length; if (rowCount &gt; 1) { alert("true"); $(this + " tr").remove(); } ...go on to populate table with search results.... </code></pre> <p>thanks</p>
jquery
[5]
3,853,275
3,853,276
jQuery rounded corners IE problem
<p>I've tried <a href="http://www.malsup.com/jquery/corner/" rel="nofollow">http://www.malsup.com/jquery/corner/</a> and "curvyconvers", both with the same result. In ie7 &amp; 8, my div is visible for about a second, without rounded corners, and then it dissapears. The div is 100x100px with a 1px black border. </p>
jquery
[5]
3,717,971
3,717,972
Why does float('3') apparently return a TypeError in Python 2.6.8?
<p>I have (anonymized) a hash constructed from values in Python 2.6.8:</p> <pre><code>sys.stderr.write('#' + str(dictionary['Field 4']) + '#\n') kpis_found.append(float(int(dictionary['Field 1']), 1) * max(float(dictionary['Field 2']), 1) * max(float(dictionary['Field 3']), 1) * max(float(dictionary['Field 4']), 1) * max(float(dictionary['Field 5']), 1)) </code></pre> <p>The output I get is:</p> <pre><code>[Fri Jul 13 09:04:44 2012] [error] [client ::1] #3# [Fri Jul 13 09:04:44 2012] [error] [client ::1] Traceback (most recent call last): [Fri Jul 13 09:04:44 2012] [error] [client ::1] File "/Users/jonathan/mirror/civic/google_maps/index.cgi", line 357, in &lt;module&gt; [Fri Jul 13 09:04:44 2012] [error] [client ::1] max(float(dictionary['Field 4']), 1) * [Fri Jul 13 09:04:44 2012] [error] [client ::1] TypeError: float() takes at most 1 argument (2 given) </code></pre> <p>To the best of my knowledge, the CSV files yield (usually) strings convertible to ints, or (occasionally) strings convertible to floats. If I run into a NULL, that should be easier to diagnose. The debugging output appears to confirm that the field in question is '3'.</p> <p>How is this getting a TypeError? I've run through parentheses to ensure that I'm not calculating</p> <pre><code>max(float(foo, bar)) </code></pre> <p>but instead calculating</p> <pre><code>max(float(foo), bar) </code></pre> <p>Any insight would be welcome.</p>
python
[7]
5,565,500
5,565,501
var myFunction = function() {}; vs fuction myFunction() {};
<p>What do you think, which one is the better, faster, nicer solution to declare a function?</p> <p>First:</p> <pre><code>(var) myFunction = function(){ //Stuff to do }; </code></pre> <p>or Second:</p> <pre><code>function myFunction() { //Stuff to do }; </code></pre> <p>Both will work in JavaScript and JQuery. But what do you think is better?</p> <p>Regards</p>
javascript
[3]
2,814,506
2,814,507
How to make a simple command-line chat in Python?
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PORT = 21567 BUFSIZE = 1024 ADDR = (HOST, PORT) tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(ADDR) while 1: data = raw_input('&gt; ') if not data: break tcpCliSock.send(data) data = tcpCliSock.recv(BUFSIZE) if not data: break print data tcpCliSock.close() </code></pre> <p>So if another client sends a message, this client will only receive it after sending a message too. I bet you understand me. I have googled for the matter and found out many interesting things such as asynchronous I/O, threading, non-blocking synchronization, concurrent programming and so on. I have also installed the twisted package. In brief, I've been learning all these things but yet haven't found what I was looking for. (Of course, I will keep trying and trying until I get to the point.)</p> <p>So, my question is how make that? =) </p>
python
[7]
4,862,118
4,862,119
Can we convert a string variable to long or viceversa in android?
<p>Is it possible to convert a string variable to long or a long variable to string type in android? If so how can I achieve that? Please help me regarding this....</p> <p>thanks in advance</p>
android
[4]
562,190
562,191
How to adjust UINavigationBar's text and buttons when you change tintColor?
<p>I was able to change the tintColor of the UINavigationBar by doing:</p> <pre><code> self.navigationController.navigationBar.tintColor = [UIColor redColor]; </code></pre> <p>However the problem is when the color gets too light, the button, backButton and the title text is not visible. Why is it that it doesn't automatically adjust itself based on the tint color? Do I have to create custom button, custom title view and custom back button if I change the tint color?</p> <p><img src="http://img210.imageshack.us/img210/9617/picture1tlv.png" alt="alt text" /></p>
iphone
[8]
3,828,244
3,828,245
Adding Content-type to Pear Mail
<p>i'm assuming setting a content type of text/html format income emails to the default font style and size of the clients/users machine. User Pear Mail how would I add in a content type. All the examples I've send only show adding content-type with mime attachments.</p> <p>Also if there is another way to make and incoming email default to users mail clients font style and size, I'd like to know. </p> <p>would like to add</p> <pre><code>$headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; </code></pre> <p>current mail code</p> <pre><code>$from = "[email protected]"; $to = $SendTo; $subject = "Contact : " . $uxGlobalLocation; $body = $Bodycopy; $host = "mail.set.co"; $username = "[email protected]"; $password = "empty00"; $headers = array ('From' =&gt; $from, 'To' =&gt; $to, 'Subject' =&gt; $subject); $smtp = Mail::factory('smtp', array ('host' =&gt; $host, 'auth' =&gt; true, 'username' =&gt; $username, 'password' =&gt; $password)); $mail = $smtp-&gt;send($to, $headers, $body); if (PEAR::isError($mail)) { echo("&lt;p&gt;" . $mail-&gt;getMessage() . "&lt;/p&gt;"); } else { header ('Location: /'); exit(); } </code></pre> <p><strong>EDIT Possible answer</strong></p> <pre><code>$headers = array ('From' =&gt; $from, 'To' =&gt; $to, 'Subject' =&gt; $subject, 'Content-Type' =&gt; 'text/html; charset=iso-8859-1', 'MIME-Version' =&gt; '1.0'); </code></pre>
php
[2]
1,693,617
1,693,618
Set a global timer in a php web environment
<p>I'm trying to make a function in PHP that counts how many times a function is used by all the users.</p> <p>If this function has been used, let's say, 30 times, then it should block access for some minutes and then reset the counter to 0. </p> <p>Is this possible in PHP?</p>
php
[2]
5,177,077
5,177,078
How to make Local Notification in android?
<pre><code>public class ChildLock extends Activity implements OnClickListener { ProgressDialog dialog; int increment; int maximum ; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button startbtn = (Button) findViewById(R.id.startbtn); startbtn.setOnClickListener(this); } @Override public void onClick(View arg0) { EditText et = (EditText) findViewById(R.id.increment); // convert the text value to a integer increment = Integer.parseInt(et.getText().toString()); dialog = new ProgressDialog(this); dialog.setCancelable(true); dialog.setMessage("Loading..."); // set the progress to be horizontal dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // reset the bar to the default value of 0 dialog.setProgress(0); // get the maximum value EditText max = (EditText) findViewById(R.id.maximum); // convert the text value to a integer maximum = Integer.parseInt(max.getText().toString()); // set the maximum value dialog.setMax(maximum); // display the progressbar dialog.show(); // create a thread for updating the progress bar Thread background = new Thread (new Runnable() { public void run() { try { while(dialog.getProgress()&lt;= dialog.getMax()) { // wait 500ms between each update Thread.sleep(500); // active the update handler progressHandler.sendMessage(progressHandler.obtainMessage()); } } catch (java.lang.InterruptedException e) { // if something fails do something smart } } }); background.start(); } // handler for the background updating Handler progressHandler = new Handler() { public void handleMessage(Message msg) { if(dialog.getProgress()== dialog.getMax()) { Intent i = new Intent(ChildLock.this, notifi.class); startActivity(i); } dialog.incrementProgressBy(increment); } }; } </code></pre>
android
[4]
1,607,359
1,607,360
Does jQuery continue filtering if it finds 0 matches?
<p>I have a question regarding efficiency of jQuery filtering. I've just written quite a lengthy expression and I was wondering if jQuery stops filtering if the current number of matches is 0.</p> <pre><code>passengers.filter('input.FromDate[value="01/09/2011"]') .closest('tr') .filter('input.ToDate[value="08/09/2011"]') .length; </code></pre> <p>If after the first <code>filter()</code> call the number of matches is 0 will jQuery continue to search the DOM or will it forego the additional calls and just return 0?</p>
jquery
[5]
412,417
412,418
Is it the best practice to catch thowrable?
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/6083248/is-it-a-bad-practice-to-catch-the-throwable">Is it a bad practice to catch the Throwable?</a> </p> </blockquote> <p>Is it best practice to catch throwable? If catching throwable, will it catch out of memory etc exception? </p>
java
[1]
5,836,557
5,836,558
Service, activity and notifications
<p>I have program that starts Service. </p> <p>Service periodically checks server for updates. If there are new updates on server service creates notification. It creates notificatins even if my application is foreground. But I want it to create notification only if my application is background or stopped.</p> <p>Can you advice me best way to implement it?</p>
android
[4]
217,091
217,092
Querying the status of a bit flag?
<p>I am trying to parse some files that have a bitwise flag column. There are 11 bits in this flag and I need to find out, for each row in the files, what is the value of the 5th bit (1-based).</p>
c++
[6]
5,834,224
5,834,225
How can I make a clock tick?
<p>I'm making a clock right now and currently my second hand, minute hand, and hour hand are all drawn graphically using a <code>Line</code> object with an <code>(x0, y0)</code> beginning coordinate and <code>(x1, y1)</code> end coordinate. </p> <p>What's confusing me right now is how to make the second hand "tick" every time a second passes. That is, how can I update the <code>(x1, y1)</code> coordinate (since the beginning coordinate is always in the center of the clock, we don't need to update it) so that it will move clockwise 6 degrees? This is confusing to me because the direction of the unit circle (and thus the direction of radians) goes counter-clockwise. </p>
java
[1]
5,915,125
5,915,126
my jquery code not working IE6,IE7
<p>code below working fine but not in IE6, IE7, below is the code is there any error please help</p> <pre><code>$(document).ready(function(){ $(".backgroundElement").bind( "keyup change", function () { var color=$("#colorpickerField1").attr('value'); var brnbackgroundurl=$("#brnbackgroundurl").attr('value'); var scrollwithpage=$('#scrollwithpage').val(); var bgposition=$('#bgposition').val(); var bgrepeat=$('#bgrepeat').val(); $("body").css({ 'background':'#'+color, 'background':'url('+brnbackgroundurl+')'+bgrepeat+' '+ bgposition, 'background-attachment':scrollwithpage }); }); }); </code></pre>
jquery
[5]
5,404,619
5,404,620
Show Multiline View in GridView
<p>I have Stored a Data in database by multiline Textbox.. When i link it with the gridview.. It shows that data in a Single line.. I cant get the multiline view.. please give ur valuable suggestions for that.. Thanks in advance..</p>
asp.net
[9]
255,553
255,554
C# Convert String to Size
<p>Hey is there a way to convert a string variable to the datatype Size?</p> <p>for example, if I had this variable</p> <p>string tempSize;</p> <p>how could I convert that to a dataType Size for reading purposes??</p>
c#
[0]
962,335
962,336
make jquery procedure run better
<p>I have the following code:</p> <pre><code>$('#MyDiv .TheClass').eq(TheIndex).removeClass('ClassA'); $('#MyDiv .TheClass').eq(TheIndex).removeClass('ClassB'); $('#MyDiv .TheClass').eq(TheIndex).addClass('ClassC'); $('#MyDiv .TheClass').eq(TheIndex).children().each(function () { //do something here }); </code></pre> <p>It seems I'm using the <strong>$('#MyDiv .TheClass').eq(TheIndex)</strong> line several times; how can I make this better?</p> <p>I thought of doing</p> <pre><code>var TheDiv = $('#MyDiv .TheClass').eq(TheIndex); TheDiv.removeClass('ClassA'); TheDiv.removeClass('ClassB'); TheDiv.addClass('ClassC'); TheDiv.children().each(function () { //do something here }); </code></pre> <p>But I'm wondering if there's a better suggestion out there.</p> <p>Thanks.</p>
jquery
[5]
4,345,319
4,345,320
Debug which Javascript is causing a redirect
<p>We have mountains of Javascript. Somewhere in there, a redirect is happening that we don't want. How can you generically debug which code caused a redirect? A stack trace would be perfect.</p>
javascript
[3]
3,652,886
3,652,887
Non Static/Constant values in case statements within a Switch
<p>I'd like to do something like this in c sharp:</p> <pre><code>int i = 0; foreach ( Item item in _Items ) { foreach (Field theField in doc.Form.Fields) { switch (theField.Name) { case "Num" + i++.ToString(): // Number of Packages theField.Value = string.Empty; break; } } } </code></pre> <p>I have 20 or so fields named Num1, Num2, etc. If I can do this all in one statement/block, I'd prefer to do so.</p> <p>But the compiler complains that the case statements need to be constant values. Is there a way to use dynamic variables in the case statement so I can avoid repeating code? </p> <p>I just thought I'd mention, the purpose of this method is to populate the fields in PDF form, with naming conventions which I can not control. There are 20 rows of fields, with names like "Num1" - "Num20". This is why string concatenation would be helpful in my scenario.</p>
c#
[0]
1,345,590
1,345,591
Add Some Links to some words issue
<p>I have some words Such as</p> <p>"Hello this article about games. Our choice is train games. Name of game is My Little Train"</p> <p>I want to add automatic links as below</p> <p><strong>"games" » "<a href="http://www.mywebsite.com" rel="nofollow">http://www.mywebsite.com</a>"</strong></p> <p><strong>"train games" » "<a href="http://www.myothersiteadrwesss.com" rel="nofollow">http://www.myothersiteadrwesss.com</a>"</strong></p> <p><strong>"game" » "<a href="http://www.my3thsiteadress.com" rel="nofollow">http://www.my3thsiteadress.com</a>"</strong></p> <p>I tried it with PHP and <code>str_replace</code> but after my codes</p> <p>"games" word has 2 links nested ("<a href="http://www.mywebsite.com" rel="nofollow">http://www.mywebsite.com</a>" and "<a href="http://www.my3thsiteadress.com" rel="nofollow">http://www.my3thsiteadress.com</a>" )</p> <p>"train games" word has 3 links nested (all 3 links)</p> <p>How can I solve my problem?</p> <p>finally i want</p> <pre><code>&lt;a href="http://www.my3thsiteadress.com"&gt;game&lt;/a&gt; &lt;a href="http://www.myothersiteadrwesss.com"&gt;train games&lt;/a&gt; &lt;a href="http://www.mywebsite.com"&gt;games&lt;/a&gt; </code></pre> <p>words count can be change</p>
php
[2]
2,669,488
2,669,489
Losing focus at buttons in android application
<p>I made one simple android application and I notice next problem: I have several controls with attached click (or i say touch) event (buttons, imageviews). Some of them are loaded from android xml file, and some I make "in fly". </p> <p>Now when I scroll screen, I must 2 time click on button to make effect (click event). It seems to me that this have some connection with losing focus. Am I right and how to solve it? I want just one click to execute some operation.</p> <p>This happen only on real device (HTC Wildfire). In emulator there is no this problem. </p> <p>Thanks!</p>
android
[4]
4,294,080
4,294,081
How to --enable-xmlreader in PHP
<p>I am running Fedora 10 and have php 5.2.9, Unfortunately I saw that '--disable-xmlreader' (from phpinfo() ) was passed to the RPM file when PHP was intalled. How can I enable xmlreader for a pre-existing php install?</p>
php
[2]
1,701,664
1,701,665
Where is the oposite of imagecreatefromstring
<p>I have an image in a string <code>$data</code>. I need to resize that image, so I convert it to a <code>image</code> with <code>imagecreatefromstring</code>. How to I get that resized image back to <code>$data</code> variable? All I've found is <code>imagepng</code> in its ilk.</p>
php
[2]
452,523
452,524
Android HTTP request always returns code 404
<p>I'm trying to implement a simple HTTP request. The request will verify a username and password from a server. The server is configured such that it will only return two error codes, 200 for verified and 404 for everything else. I've done extensive debugging with eclipse and found that I always receive code 404. I've read all other existing questions before posting this.</p> <pre><code>private class loginTask extends AsyncTask&lt;String, Integer, Boolean&gt; { String check; @Override protected Boolean doInBackground(String... arg0) { ("http://www.unite.upmc.edu/account/IPhoneLogin?username=username&amp;password=password String username = arg0[0]; String password = arg0[1]; URI uri = null; try { uri = new URI("http://unite.upmc.edu/account/IPhoneLogin?"+"username="+username+"&amp;"+"password="+password);// I know the method is called IPhoneLogin, it's being used by both Android and IOS clients } catch (URISyntaxException e1) { e1.printStackTrace(); } HttpClient client = new DefaultHttpClient(); try {//Look here HttpResponse response = client.execute(new HttpGet(uri)); String code = "" + response.getStatusLine().getStatusCode(); check = code; if(code.equals("200")){ loggedIn = true; }else{ //need to re-enter username and password } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } hasPin = false; return true; } @Override protected void onProgressUpdate(Integer... integers) { setProgress(integers[0]); } @Override protected void onPreExecute() { ProgressDialog dialog = new ProgressDialog(UniteActivity.this); dialog.setMessage("Logging in...." + check); dialog.show(); } </code></pre> <p>I know the server is up and the password and username are correct because I've logged in normally many times using internet explorer. I'm using the eclipse IDE with Android SDK and am concerned this might be a product of the buggy emulator it provides. Any ideas on what I'm doing wrong?</p>
android
[4]
4,035,752
4,035,753
Find the second highest variable in array
<p>I would like to find the second highest variable in an array.</p> <p><strong>For example if I have:</strong></p> <pre><code>$cookies = array( "chocolate" =&gt; "20", "vanilla" =&gt; "14", "strawberry" =&gt; "18", "raspberry" =&gt; "19", "bluebery" =&gt; "29" ); </code></pre> <p>I can use <code>max($cookies)</code> to find the highest variable, which is <code>"bluebery" =&gt; "29"</code>.</p> <p><strong>But how do I find the second highest?</strong> <code>"chocolate" =&gt; "20"</code></p>
php
[2]
289,245
289,246
Java - Runtime.freeMemory()
<p>I was trying to see usage of Runtime.freeMemory().</p> <p>Documentation says it 'Returns the amount of free memory in the Java Virtual Machine'</p> <p>I executed a simple program test this. Program below:</p> <pre><code>public class Test { public static void main(String a[]) throws Exception { System.out.println("Total memory: " +Runtime.getRuntime().totalMemory()); System.out.println("Free memory: " +Runtime.getRuntime().freeMemory()); Integer intArr[]= new Integer[10000]; for(int i =0; i&lt;10000;i++){ intArr[i] = new Integer(i+500); } System.out.println("Free memory: " +Runtime.getRuntime().freeMemory()); System.out.println("sample print :"+ intArr[0]); System.out.println("sample print :"+ intArr[5000]); System.out.println("sample print :"+ intArr[9999]); } } </code></pre> <p>Output:</p> <p>Total memory: 67108864</p> <p>Free memory: 61822408 &lt; Before allocating 10000 objects></p> <p>Free memory: 61822408 &lt; Size remains same even after allocating 10000 objects. why?></p> <p>sample print :500</p> <p>sample print :5500</p> <p>sample print :10499</p> <p>Since the objects are created on heap, the 'Free memory' value printed second time should be less than the first output, right?</p> <p>But it prints same value. Can anyone please explain why it print same value? </p>
java
[1]
2,759,219
2,759,220
PHP white screen on error
<p>I'm getting a white screen every time a PHP application drops an error. I checked php.ini and error_reporting = E_ALL and display_errors = On Also I checked with the php_info() function and error_reporting is set to 6135 which is correct.</p> <p>I already tried adding: error_reporting(E_ALL); ini_set('display_errors', TRUE); to my index.php but didn't worked.</p> <p>Also I don't have any custom error handler function. Does anybody what else can cause a white screen in PHP?</p> <p>by the way, it's not caused by an unclosed bracket neither, if I intentionally leave an error in the index.php it is displayed.</p> <p>But when I try to load a heavy page, the white screen is displayed. I'm using the same MySql server for other applications without problems.</p>
php
[2]
3,829,751
3,829,752
The structure of reference type in detail
<p>I know a reference type object is comprised of two parts: a reference to the object, which is essentially a pointer holds the address of the real object, and the object itself that resides on the heap, which might be moved by the GC. The object itself, in turn, consists of two parts: the instance data part (fields) and the metadata part. </p> <p>I've read numerous pages on the web talking about the storage model of reference type, but none of them gives specific description about how is the metadata part organized. I only learned that it occupied 8 bytes on 32-bit system (which could be observed via profiling), and 4 bytes out of it holds a pointer points to the vtable, but what about the extra 4 bytes? GC marks? built-in attributes? Does anyone know it in detail? I know it's implementation specific, I'm just dying to know how is it actually bit-for-bit organized. For instance, Boehm GC only need a bit as mark, why on earth does CLR need 4 bytes? </p> <p>--->8----</p> <p>See the link provided by Damian in the comments! That's the answer I've been looking for.</p>
c#
[0]
5,680,888
5,680,889
PHP add an item from an array
<p>Let's say i have this array:</p> <pre><code>$array = (1,2,4,5); </code></pre> <p>Now how do i add missing 3 in above array in the correct position <strong>index/key</strong>-wise?</p>
php
[2]
1,389,596
1,389,597
javascript deleting the array of elements
<p>i am having 10 check boxes.if i click the value of the check box has to push to the array,if i unchecked the check box then the corresponding check box value has to be deleted from the array? pls...anyone give reply for this</p>
javascript
[3]
2,317,973
2,317,974
Trying to add Imageview to canvas via FrameLayout.addView();
<p>I can add this logo to the canavas if I do this:</p> <pre><code>FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(200,200); ImageView boo = new ImageView(ExampletouchActivity.this); boo.setImageResource(R.drawable.ic_launcher); boo.setLayoutParams(lp); fr.addView(boo); //this works fine </code></pre> <p>But if I try to add the same logo to the canvas like this it does not show anything up:</p> <pre><code>fr.addView(new Toucher(ExampletouchActivity.this)); </code></pre> <p>My Toucher class is like so...</p> <pre><code>public class Toucher extends View{ ImageView boo; public Toucher(Context context) { super(context); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(200,200); boo = new ImageView(context); boo.setImageResource(R.drawable.ic_launcher); boo.setLayoutParams(lp); } @Override public void onDraw(Canvas c) { boo.draw(c); } </code></pre> <p>I have been trying for ages and cannot work out why this imageview will not draw itself to the canvas?</p> <p>Many Thanks</p>
android
[4]
1,137,812
1,137,813
Nested class display member value
<pre><code>class A { public: class B { private: int ii; }; void print(){cout&lt;&lt;B::ii&lt;&lt;endl;} }; </code></pre> <p>My compiler says I can't access the interger inside ii; I search through this site and come up with friend key I change it into </p> <pre><code>class A { public: class B { private: int ii; }; friend void print(){cout&lt;&lt;B::ii&lt;&lt;endl;} }; </code></pre> <p>But it doesn't work too. Can you help me ? I am stuck.really really really sad as no way out!</p>
c++
[6]
5,498,803
5,498,804
Android: Creating file uisng createNewFile() method
<p>As described in android documentation, to create a new file which will be situated in the application's directory there is the method in <code>Context</code> class: <code>openFileOutput()</code>. </p> <p>But where will be the file situated if I use simple <code>createNewFile()</code> method from <code>File</code> class?</p>
android
[4]
1,093,041
1,093,042
fast way to find find min/max/avg value in file
<p>I have a file in the format</p> <pre><code>1 52 2 456 3 4516 5 4545 6 41 </code></pre> <p>what would be the fastest way to read in the file and get the min/max/avg value in the second column in PHP?</p>
php
[2]
949,481
949,482
Rotating A Dial in Android
<p>I need to rotate my image in my on touch listener when the user touches it. I am rotating a dial graphic, so it needs to rotate around its center point. Does anyone have an example?</p>
android
[4]
5,563,242
5,563,243
Executing a line after finishing of previous line in jquery
<p>I am new to jQuery and I am trying a simple program. In this program what I am trying to achieve is that when I will click the div text then first line will fadeout then it will change background colour and then it will fade in so overall it will give effect of changing colour slowly, but what happening here is when I click the text the line changes colour suddenly then it fades out and then it fades in. So I was wondering if there is a way to make colour changing code execute after execution of fadeout.</p> <p>my program:</p> <p> </p> <pre><code> $(document).ready(function(){ $("#firstDiv").click(function(){ // $(this).fadeOut(1000); $(this).fadeOut(1000); $(this).css("background-color", "aqua"); $(this).fadeIn(1000); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="firstDiv" style="background-color: yellowgreen"&gt; Click Me &lt;/div&gt; &lt;/body&gt; </code></pre> <p></p>
jquery
[5]
1,517,657
1,517,658
Check Query for DateTime being X seconds ago
<p>I am using PHP and MySQL to create a flood-filter for my forums I've recently created and I did research this, but little results came and only one of them potentially brought me further to my resolution.</p> <p>This is the code</p> <pre><code>$overview_threads = mysql_query("SELECT * FROM `forum_posts` WHERE `author`='".$_SESSION['username']."' AND TIMESTAMPDIFF(SECOND, `created`, now()) &lt;= 20"); </code></pre> <p>The code is made in attempt to select a thread made by the user within an interval of 20 seconds or less and then do an if statement to prevent the user of posting within that time.</p> <p>What do I do for this?</p>
php
[2]
2,188,635
2,188,636
Permutation of string without recursion
<p>Here is the recursive code.<br /> Can you guys give inputs on how I can implement this using iterative method?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PermAndComb { class Program { static void Main(string[] args) { string s = "abcd"; Permutation(s); Console.ReadKey(); } public static void Permutation(string s) { int len = s.Length; char [] inStr = s.ToCharArray(); StringBuilder outStr = new StringBuilder(); bool[] used = new bool[len]; doPermute(inStr, outStr,used, len, 0); } public static void doPermute(char[] instr, StringBuilder outStr,bool [] used, int len, int level) { if (level == len) { Console.WriteLine(outStr.ToString()); return; } for (int i = 0; i &lt; len; i++) { if (used[i]) continue; outStr.Append(instr[i]); used[i] = true; doPermute(instr, outStr, used, len, level + 1); used[i] = false; outStr.Length = outStr.Length - 1; } } } } </code></pre>
c#
[0]
2,879,789
2,879,790
C++ string value as another strings name
<p>How can i convert a vartiables value int anothers name in C++? like in this php snippet.</p> <pre><code>$string = 'testVar'; ${$string} = 'test'; echo $testVar; // test </code></pre>
c++
[6]
4,598,536
4,598,537
How do I set the width of a child views to be divided amongst eachother?
<p>I'm trying to create a LinearLayout with the left view width being 80% of its parents width and the second view taking up the remaining space. How do I accomplish this?</p> <p><img src="http://i.stack.imgur.com/fKeOA.png" alt="enter image description here"></p>
android
[4]
2,662,653
2,662,654
Adding message before shutting down the program
<p>Before i close my program (press X on the frame) i wish to have a Conformation message that says something alike: "Are you sure you want to close this window" Followed by a yes and no button.</p> <p>How exactly can i achieve such a thing? Ive tried looking up a window listener but not much luck so far.</p> <p>Where do i exactly play this override Windows listener? I have a seperate view and frame class.</p> <p>Since i do not wish to add controls for the option pane in my frame.</p>
java
[1]
5,350,357
5,350,358
Getting all possible value combinations
<p>For an automatic test thing, I have a class with ~15 parameters. I want to automatically generate instances of the class for every possible value combination. For instance, if the class was defined like so:</p> <pre><code>class meep(): def __init__(self): self.par1 = 0 # can be in range {0-3} self.par2 = 1 # can be in range {1-2} self.par3 = a # can be in range {a-c} </code></pre> <p>What is the most efficient to get instances of it with all possible value combinations? (IE </p> <pre><code>inst1=(par1=0,par2=1,par3=a), inst2=(par1=0,par2=1,par3=b), inst3=(par1=0,par2=1,par3=c), inst4=(par1=1,par2=1,par3=a), inst5=(par1=1,par2=1,par3=b), inst6=(par1=1,par2=1,par3=c), </code></pre> <p>etc.)</p>
python
[7]