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 |
|---|---|---|---|---|---|
2,975,291 | 2,975,292 | Operations on 1-D array | <p>How to insert and delete an element of a 1-D array.<br>
for ex:<br>
suppose the array is: 1 3 4 2 5<br>
we want to insert 7 between 3 and 4 so that the new array is: 1 3 7 4 2 5</p>
| c++ | [6] |
1,650,411 | 1,650,412 | Assign a function to a variable in C# | <p>i saw a function can be define in javascript like </p>
<pre><code>var square = function(number) {return number * number};
</code></pre>
<p>and can be called like </p>
<pre><code>square(2);
var factorial = function fac(n) {return n<3 ? n : n*fac(n-1)};
print(factorial(3));
</code></pre>
<h2>c# code</h2>
<pre><code>MyDelegate writeMessage = delegate ()
{
Console.WriteLine("I'm called");
};
</code></pre>
<p>so i need to know that can i define a function in the same way in c#. if yes then just give a small snippet of above like function definition in c# please. thanks.</p>
| c# | [0] |
1,661,418 | 1,661,419 | Items return null value from query in sharepoint? | <p>I'm using this code to get items from the folder but it return <code>null</code> value in the <code>SPListItemCollection</code>. What's the wrong in my code?</p>
<pre class="lang-cs prettyprint-override"><code>siteurl = SPContext.Current.Site.Url;
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["PoAlbum"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='ContentType'/><Value Type='Computed'>Folder</Value></Eq></Where>";
DataTable listItemsTable = list.GetItems(query).GetDataTable();
string name = (listItemsTable.Rows[0]["NameOrTitle"]).ToString();
SPFolder folder = web.GetFolder("/PoAlbum/" + name);
query.Folder = folder;
SPListItemCollection itms = list.GetItems(query);
reapeat.DataSource = itms.GetDataTable();
reapeat.DataBind();
</code></pre>
| asp.net | [9] |
4,096,623 | 4,096,624 | Efficient Data structure which supports search on 2 keys of Node | <p>Suppose I have my node structure as:</p>
<pre><code>struct Employee
{
int age;
int salary;
string title;
...
}
</code></pre>
<p>I wanted an efficient data structure by which I can do search query based on age as well as salary.
Can somebody suggest me some god data structure for that.</p>
| c# | [0] |
623,013 | 623,014 | Is Java String really immutable? | <p>In String source it looks like the hash code value (private int hashCode) is set only if the method public int hashCode() was called at least once. That means a different state. But will the hashCode be set in the following example: </p>
<pre><code>String s = "ABC"; ?
</code></pre>
<p>Will </p>
<pre><code>String s = "ABC";
s.hashCode();
</code></pre>
<p>help with subsequent comparisons performance?</p>
| java | [1] |
4,441,466 | 4,441,467 | Weighted website rotator | <p>I need a weighted rotator for all links that I create so that traffic can be distributed on a weighted scale to the destinations i define. I currently use the following:</p>
<pre><code><?
header('Location: www.destinationwebsite1.com/index.php');
?>
</code></pre>
<p>however this only distributes traffic to 1 source.. I want something that distributes based on "weight" to however many destinations i define..</p>
<p>such as:</p>
<pre><code>25% to www.destinationwebsite1.com/index.php
25% to www.destinationwebsite2.com/index.php
25% to www.destinationwebsite3.com/index.php
25% to www.destinationwebsite4.com/index.php
</code></pre>
<p>or whatever percentages i choose. Anyone have any ideas?</p>
<p>Best
-N</p>
| php | [2] |
4,003,583 | 4,003,584 | STL big int class implementation | <p>Does STL has a "big int" class implementation? (numbers with many digits held into an array)</p>
| c++ | [6] |
1,286,468 | 1,286,469 | Strange problem with dynamic cast C++ | <p>I'm just new to C++, and doing a small project which implementing some inheritance. It can basically be summarized below:</p>
<pre><code>//.h file
class Food{
public:
Food();
virtual ~Food();
};
class Animal{
public:
Animal();
virtual ~Animal();
virtual void eat( Food f);
};
class Meat : public Food{
public:
Meat();
~Meat();
};
class Vegetable : public Food{
public:
Vegetable();
~Vegetable();
};
class Carnivore : public Animal{
public:
Carnivore();
~Carnivore();
void eat(Food f);
};
//.cpp file
Food::Food()
{
do something;
}
Food:~Food()
{
do something;
}
Animal::Animal()
{
do something;
}
Animal::~Animal()
{
do something;
}
Meat::Meat()
{
do something;
}
Meat::~Meat()
{
do something;
}
Vegetable::Vegetable()
{
do something;
}
Vegetable::~Vegetable()
{
do something;
}
Carnivore::Carnivore()
{
do something;
}
Carnivore::~Carnivore()
{
do something;
}
void Carnivore::eat(Food f)
{
Meat* m = dynamic_cast<Meat*>(&f);
if(m != 0) cout << "can eat\n";
else cout << "can not eat\n";
}
//main.cpp
int main()
{
Animal* a;
Food* f;
Meat m;
Vegetable v;
Carnivore c;
a = &c;
f = &v;
a->eat(*f);
f = &m;
a->eat(*f);
return 1;
}
</code></pre>
<p>And the output:</p>
<pre><code>can not eat
can not eat
</code></pre>
| c++ | [6] |
5,858 | 5,859 | When the TrafficStats tx and rx values gets reset? | <p>My application uses TrafficStats class to read tx and rx of every application. I am checking tx and rx value periodically. what i had observe is these values resets when device reboots or user switch from 3g to wifi. My question is, apart from these activities, when does tx and rx values gets reset and what is the maximum range of the tx, rx value?</p>
| android | [4] |
3,656,322 | 3,656,323 | Cannot update the project in android ndk | <p>I'm using linux and i have successfully installed ndk and configured it. with the help of <a href="http://developer.android.com/sdk/ndk/index.html" rel="nofollow">Android NDK installation</a> But i can't able to generate build.xml file</p>
<pre><code>root@ndot-173:~/Desktop/NDK4/samples/bitmap-plasma# android update project -p . -s
android: command not found
</code></pre>
<p>It shows command not found.
How do i generate build.xml file..?</p>
| android | [4] |
1,115,630 | 1,115,631 | how to get default printer port number in java | <p>I want to access the default printer port in Java.</p>
<p>Also, I want to know if the default printer is inkjet, laser, dot matrix, etc.
Please provide references.</p>
| java | [1] |
2,758,379 | 2,758,380 | Trying to check $_GET for empty parameters | <p>I'm putting together a script that pulls through several $_GET variables which are then used within the script for the purposes of calculating a quote, etc.</p>
<p>The nightmare I'm having is simply being able to determine if any of them are without a value, for example ?var1=500&var2=&var3=Yes with var2 being the culprint there. </p>
<p>Depending on whether or not all of the $_GET variables have a value, or not, I'll take different actions accordingly.</p>
<p>I researched and came up with this as an option:</p>
<pre><code><?php
foreach($_GET as $name => $value) {
if ($value == "") {
$proceed = 0;
} else {
$proceed = 1;
}
}
?>
</code></pre>
<p>I'm echo'ing a simple bit of text using $proceed at the moment just for testing purposes.</p>
<p>This doesn't work, and I've considered <strong>isset</strong> and <strong>empty</strong> but I believe both options are useless in this case. I've read in a number of sources that $_GET parameters that aren't given values default to "' so I'm puzzled as to why this isn't working.</p>
<p>I can't use <strong>empty</strong> here due to the fact that sometimes the parameters will be set to 0.</p>
<p>It goes without saying that I've printed the contents of $_GET and get satisfactory results, so the data is all good.</p>
<p>Any help greatly appreciated.</p>
| php | [2] |
453,828 | 453,829 | Starting ASP.NET SPA project | <p>I've downloaded the latest SPA template for ASP.NET and was wondering if it is best to start from the template and remove things or start a new project and add things based on what I've learned from using the template on another project.</p>
| asp.net | [9] |
4,641,356 | 4,641,357 | Java - cannot find symbol - constructor | <p>I'm trying to use a method from another class called Digits but referring to it in a class called FourDigits. I've tried to create an instance variable by using the following code:</p>
<pre><code>public class FourDigits
private Digits TwoDigitA;
private Digits TwoDigitB;
/**
* Constructor for objects of class FourDigits
*/
public FourDigits()
{
TwoDigitA = new Digits();
TwoDigitB = new Digits();
setValues();
setIncrement();
getDisplayString();
}
</code></pre>
<p>The first class, Digits:</p>
<pre><code>public class Digits
private int value;
private int tooHigh;
private String displayString;
public Digits(int anyNum)
{
value = 0;
tooHigh=anyNum;
displayString = "";
}
</code></pre>
<p>Thanks!</p>
| java | [1] |
137,110 | 137,111 | JSONObject as class attribute storage/retrieval | <p>In android, I'm using model classes with methods to handle the data manipulation. My data is brought in from webservices as json. I'm contemplating the possibility of using JSONObjects to store the values of class level attributes. But, I don't know of a way to use the JSONObj as the "holder" variable and create access methods. I don't want to predetermine these methods, as jsonRepository should hold the values, not always known at design time</p>
<p>For example, I'd like to have:
public class User {
private JSONObject jsonAttributes;</p>
<pre><code>public User(String json) {
this.jsonAttributes= new JSONObject(json);
}
[IMPLICIT attribute access methods]
public string Prop1() returns jsonAttributes.getString("prop1");
public string Prop1(String newProp1) returns jsonAttributes.putString("prop1",newProp1);
public string Prop2() returns jsonRepository.getString("id");
public string Prop2(String newProp2) returns jsonAttributes.putString("prop2",newProp2);
....
</code></pre>
<p>from outside this class then, I would access the attributes simply...</p>
<pre><code>User myUser = new User(someValidJson);
String myString = myUser.Prop1
</code></pre>
<p><strong>Misguided? If not, how does one manage implicit property setting/getting?</strong></p>
| android | [4] |
1,298,560 | 1,298,561 | Can I create custom directives in ASP.NET? | <p>I have created a menu control in asp.net and have put it into master page. This menu control have property ActiveItem which when modified makes one or another item from menu appear as active.</p>
<p>To control active item from child page I have created a control which modifies master page property enforced by IMenuContainer interface to update menu control's active item in master page.</p>
<pre><code>public class MenuActiveItem : Control
{
public ActiveItemEnum ActiveItem
{
get
{
var masterPage = Page.Master as IMenuContainer;
if (masterPage == null)
return ActiveItemEnum.None;
return masterPage.ActiveItem;
}
set
{
var masterPage = Page.Master as IMenuContainer;
if (masterPage == null)
return;
masterPage.ActiveItem = value;
}
}
}
</code></pre>
<p>Everything works perfectly and I really enjoy this solution, but I was thinking that, if I knew how, I would have created a custom directive with same feature instead of custom control because it just makes more sense that way.</p>
<p>Does anybody know how to do it?</p>
| asp.net | [9] |
4,831,943 | 4,831,944 | startActivity crashes when trying to respond to menu click | <p>I know this has been covered elsewhere, but I'm new to the Android platform and am having a hard time figuring out how to add basic menu options to my first app.</p>
<p>I have an options menu setup using</p>
<pre><code>@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
</code></pre>
<p>and</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menuPrefs" android:icon="@android:drawable/ic_menu_preferences" android:title="Settings"></item>
</menu>
</code></pre>
<p>Then within my main java class I have</p>
<pre><code>@Override
public boolean onOptionsItemSelected(MenuItem item){
if(item.getItemId()==R.id.menuPrefs) {
showPrefs();
}
private void showPrefs() {
Intent i = new Intent(this, Prefs.class);
startActivity(i);
}
</code></pre>
<p>And then in Prefs.java I have</p>
<pre><code>public class Prefs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(getBaseContext(), "FNORD", Toast.LENGTH_LONG).show();
}
}
</code></pre>
<p>Now from this I would expect to see the Toast message "FNORD" when the menu option is pressed, however the application stops unexpectedly.</p>
<p>If I move the toast statement into the showPrefs() function in place of the startActivity call it works.</p>
| android | [4] |
803,123 | 803,124 | Simple jquery selector | <p>I want to select span of $(this) element, how i can do it?</p>
<p>i want something like this:
<a href="http://jsfiddle.net/W28fE/2/" rel="nofollow">http://jsfiddle.net/W28fE/2/</a></p>
<p>but with one ( $(this) ) span element hover effect, not 3</p>
| jquery | [5] |
3,591,633 | 3,591,634 | Trouble with posting new thread to vbulletin v4.2 with c# | <p>Ive done some seachings but couldnt find answer to my problem yet.</p>
<p>I see the struct of submit form :</p>
<pre><code>enter code here
<input type="hidden" name="s" value="" />
<input type="hidden" name="securitytoken" value="1367653850-9f17d492870df7a0ffa4db0810a39cc88d567918" />
<input type="hidden" name="f" value="113" />
<input type="hidden" name="do" value="postthread" />
<input type="hidden" name="posthash" value="c79839fea233195a70c70ac237faa5f0" />
<input type="hidden" name="poststarttime" value="1367653850" />
<input type="hidden" name="loggedinuser" value="114098" />
<input type="submit" class="button" name="sbutton" id="vB_Editor_001_save" value="Submit New Thread" accesskey="s" tabindex="1" />
<input type="submit" class="button" name="preview" value="Preview Post" accesskey="r" tabindex="1" />
</code></pre>
<p>Forum is based on vbulletin v4.2,ive done logged in and got sessionhash,securitytoken and loggedinuser.Ive tried some method but the result not succeeded.Can some one give me some point out plz.I see no subject or message param to post in the code above,is that strange or i mus have missed something out.</p>
| c# | [0] |
5,080,525 | 5,080,526 | Question about Intent, android | <p>I am confused, and need to get my concepts straight.</p>
<p>After executing the last statement, which function is called, in MapsActivity? is it onResume? and under which function (onResume()?) should i put getExtra()?</p>
<pre><code>Log.i("onMenuAnimate", "Attempting to animate to:");
Intent intent = new Intent(SearchDB.this, MapsActivity.class);
intent.putExtra("com.gpsdroid.SearchDB.Lat", nameLatitude.getText());
intent.putExtra("com.gpsdroid.SearchDB.Long", nameLatitude.getText());
SearchDB.this.startActivity(intent);
</code></pre>
| android | [4] |
4,106,194 | 4,106,195 | Bluetoothsocket timeout on read and write | <p>I'm designin an application in Android that connects the mobile to a bluetooth device. I can do this, as I open a BluetoothSocket like this:</p>
<pre><code>Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
socket.connect();
</code></pre>
<p>Where <em>device</em> is the paired device with the mobile bluetooth desired. The thing is, this external device is a bit special, and it has different times for writing and answering to the mobile, so I need to put some timeouts on my socket for reading and writing, but I've searched a lot and it seems like <em>BluetoothSocket</em> doesn't support this.</p>
<p>Can anybody tell me a different way to admin timeouts on reading and writing to the port on the <em>BluetoothSocket</em> class for Android?</p>
<p>Thank you!</p>
| android | [4] |
1,009,705 | 1,009,706 | Cast a pointer to char to a double C++ | <p>How can i cast a pointer to char to a double ?<br>
I am using command line arguments and one of the argument is a double but in the program is it passed as a char*.<br>
I tried using static_cast and reinterpret_cast but with no effect.</p>
| c++ | [6] |
2,884,081 | 2,884,082 | How to have Image and Text Center within a Button | <p>I want to display Text and Icon on a Button. </p>
<pre><code>+----------------------------+
| Icon TEXT |
+----------------------------+
</code></pre>
<p>I tried with </p>
<pre><code><Button
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="40dip"
android:text="TEXT"
android:drawableLeft="@drawable/Icon" />
</code></pre>
<p>But Text and Icon is not in Center.<br>
My Text Size varies, according to text size Icon and Text Should get Adjusted to center. </p>
<p>How should i do it? </p>
<p>Thanks,<br>
PP.</p>
| android | [4] |
972,034 | 972,035 | Javascript in list | <p>What's the easiest way to check to see if a number is in a comma delimited list?</p>
<pre><code>console.log(provider[cardType]);
//returns: Object { name="visa", validLength="16,13", prefixRegExp=}
if (ccLength == 0 || (cardType > 0 && ccLength < provider[cardType].validLength)) {
triggerNotification('x', 'Your credit card number isn\'t long enough');
return false;
} else {
if ($('.credit-card input[name="cc_cvv"]').val().length < 3) {
triggerNotification('x', 'You must provide a CCV');
return false;
}
</code></pre>
| javascript | [3] |
1,540,918 | 1,540,919 | difference between char (*test)[] vs char *test1[] and how elegantly initialize test? | <p>just excersize from stroustrup: declare and initialize pointer of string array.
I can do </p>
<pre><code>char *test1[]={"ddd"}
</code></pre>
<p>but can't </p>
<pre><code>char (*test)[] ={"dfsdf"}.
</code></pre>
<p>which is difference between these declarations and how initialize second ?</p>
| c++ | [6] |
3,389,211 | 3,389,212 | asp.net 4 get values from connection string | <p>I have a SQL connection string being stored in the web.config.</p>
<p>How can I pull items like server name, username, password... inside of C# ASP.Net code?</p>
| asp.net | [9] |
1,695,540 | 1,695,541 | What is the best way to print this matrix without a for loop | <p>I have a matrix like this:</p>
<pre><code>[[a1,a2,a3],[a4,a5,a6],[a7,a8,a9]]
</code></pre>
<p>I know this code:</p>
<pre><code>for row in matrix:
print row
</code></pre>
<p>What is the best way to print each row on separate lines?</p>
<p>I don't want to use for a loop.</p>
<p>Desired output:</p>
<pre><code>[a1, a2, a3]
[a4, a5, a6]
[a7, a8, a9]
</code></pre>
| python | [7] |
2,116,621 | 2,116,622 | Hosting a web app -- technical details | <p>I have some experience with writing scrapers/bots. So far, I've been writing them in C#, to be ran from a local computer. But the new client wants a web application that will monitor a website and mail him whenever there is a change. So I have questions:</p>
<p>1) What language should I use? PHP?</p>
<p>2) If I do use PHP, will the app be drastically different to develop? I would have no problems with writing it as a C# program.</p>
<p>3) What's a good host to test the project?</p>
| php | [2] |
4,761,834 | 4,761,835 | php print vs echo | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/234241/how-are-echo-and-print-different-in-php">How are echo and print different in PHP?</a> </p>
</blockquote>
<p>difference between print and echo
give example</p>
| php | [2] |
413,594 | 413,595 | how to get the source code as register user | <p>i downloaded a sourcecode of a site,but i downloaded it i saw it identify my program as a guest,i search at google and figure out that i can send a cookie when i "ask" the source code.
that what i have managed to do and it still dont identify me as register user:</p>
<pre><code>CookieContainer cj = new CookieContainer();
string all = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.CookieContainer = cj;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
CookieCollection cs=cj.GetCookies(req.RequestUri);
CookieContainer cc = new CookieContainer();
cc.Add(cs);
req.CookieContainer = cc;
StreamReader read = new StreamReader(res.GetResponseStream());
all = read.ReadToEnd();
read.Close();
return all;
</code></pre>
<p>what is wrong here?
tyvm for help:)
(if that help,i can have a simple details of a register user of the site).</p>
| c# | [0] |
5,228,085 | 5,228,086 | my PHP code will NOT insert records into my SQL dabase table | <p>I have the following PHP code/file on my website but for some ungodly reason it will not insert the records typed in by the user into the mySQL database table as it is required to. Can anyone tell me why this is? </p>
<p>So far as I can tell the code is completely correct I don't know why this is happening...</p>
<p>Please help...Code is below...</p>
<pre><code><html>
<head>
</head>
<body>
<form action="register_development_file_1.php" method="post">
Email: <input type="text" name="email"><br />
Date: <input type="text" name="date"><br />
Time: <input type="text" name="time"><br />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit']))
{
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die("Could not connect to the database: " . mysql_error());
}
mysql_select_db("wwwbrecs_BREC",$con);
$sql = "INSERT INTO 'signups' ('signup_email_address', 'signup_date', 'signup_time') VALUES ('$_POST[email]','$_POST[date]','$_POST[time]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
</body>
</html>
</code></pre>
| php | [2] |
5,373,121 | 5,373,122 | iphone app - dynamic functionality allowed? | <p>I re-framed this question from before to be a little simpler:</p>
<p>Is it allowed to have dynamic functionality in your iphone app i.e. connect to our servers and see what functionality should be downloaded and run on this instance of the app for a specific customer?</p>
<p>Please ask questions if you don't understand what we are after here. Thanks.</p>
| iphone | [8] |
2,209,300 | 2,209,301 | Terminate the "logcat" process started by my application using Python | <p>I have created one small application having a button tapping on which will start the "adb logcat" process, but after starting this process we have to give Ctrl+C command to stop it.
I want to make it generic so don't want to use Ctrl+C command and want to terminate it itself after few seconds (say 5 secs). </p>
<h2>code that start executing on tapping the button is:</h2>
<pre><code>def LOGGER():
buildID=os.popen("adb shell getprop ro.build.id").read().strip()
device=os.popen("adb shell getprop ro.product.device").read().strip()
Log = ("D:\\Profiles\\hjv743\\Desktop\\Logs\\"+device+"_"+buildID)
if not os.path.isdir(Log):
os.mkdir(Log)
os.system("adb pull /data/logger "+Log+"\\flash")
os.system("adb pull /sdcard-ext/logger "+Log+"\\sdcard-ext")
</code></pre>
<hr>
<p>I have tried killing the process using its pid but it does not terminate it and it continues to run in background (Needless to mention the process name is always "logcat" as the process is adb logcat)</p>
<p>Also during this complete process my <em>application kept hung as the process is running</em>, so I cannot have another button (using Tkinter) tapping on which will terminate the running process. So the only option left with me is to terminate it automatically after some time.
This is very important for my applications as I cannot interact with it during the whole process.</p>
<p>Am I doing this wrong way and there any other way of doing the same process. Can I start the (adb logcat) process as a process in background and introduce one more button which will fetch the pid and will terminate it manually.</p>
<p>Any help is appreciated.</p>
| python | [7] |
300,889 | 300,890 | Use of header in PHP | <p>What are some possible uses of the <code>header</code> function in PHP?</p>
<p>Could someone provide me with some links for reading about this function?</p>
<p>Thank you.</p>
| php | [2] |
783,557 | 783,558 | create onChange in javascript issue | <p>I am trying to assign an change event to an element. I have</p>
<pre><code> var testDiv=getElementById('testDiv');
var SelectMenu=document.createElement('select');
SelectMenu.id='SelectMenu';
SelectMenu.onchange=changeFuntion();
testDiv.appendChild(SelectMenu);
function changeFuntion(){
//it calls right after I load the page....
alert('call');
}
</code></pre>
<p>html </p>
<pre><code> <div id='testDiv'></div>
</code></pre>
<p>I want the alert shown only when user change the dropdonw menu. However, it seems the alert is called right after the element is created.
Any tips? Thanks a lot!</p>
| javascript | [3] |
4,240,215 | 4,240,216 | Input string was not in a correct format Error | <p>I am getting an "Input string was not in a correct format" error for the below mentioned code: </p>
<pre><code>Convert.ToInt32(TextBox2.ToString());
</code></pre>
| c# | [0] |
581,106 | 581,107 | Use a layout_height of 0dip instead of wrap_content for better performance.....how to remove ths warning | <p>Use a layout_height of 0dip instead of wrap_content for better performance</p>
| android | [4] |
175,916 | 175,917 | Is it preferable to use "this" or "that" (where var that = this)? | <p>I'm fairly new to JavaScript and I'm cleaning up some JavaScript code I downloaded. One of the inconsistencies in this code is mixed usage of both <code>this</code> and the local variable <code>that</code> that references it.</p>
<p>An example code snippet (private method within a jQuery UI widget):</p>
<pre><code>_populateLists: function(options) {
//do stuff with this
var that = this;
options.each(function(index) {
//use both this AND that, they are different in this scope
});
//here this and that are the same thing
//I want to be consistent, is one preferable over the other?
},
</code></pre>
<p>In many places throughout the code, where the scope is such that <code>this === that</code>, there is mixed usage, even within the same line of code.</p>
<p>For the sake of readability and maintainability, is it preferable to use <code>this</code> or <code>that</code>?</p>
<p>Note: I realize a lot of these types of things depend on developer preference. But before I decide to rewrite the code to use one over the other, I'd like to understand any reasoning if/why one would be preferred over the other.</p>
<p><strong>EDIT:</strong> In this script, I think the <em>only</em> reason <code>this</code> is being assigned to a local variable is so that it can be referred to from within the inner closure.</p>
| javascript | [3] |
2,590,231 | 2,590,232 | How to define a Python class to inherit all other modules function? | <p>I wrote several modules to operate a system for different stuff. Only need the IP address of the system.
Now, is it possile to define a class to inherit all functions already developed in other python modules? Thanks,</p>
| python | [7] |
1,504,596 | 1,504,597 | How to get element with plain javascript | <p>I would like to get the li element.How to do?tks? I am a newbie </p>
<pre><code> html = "<ul id=\"leftMenu\"><li id=\"a.aspx\"></li></ul>";
//alert(html.children[0]);
</code></pre>
<p>$(html).find("li:eq(0)") //I dot not want to with jquery</p>
| javascript | [3] |
5,920,449 | 5,920,450 | Python global variable is not working as expected | <p>I'm just starting out with Python and experimenting with different solutions. I was working with global variables and I ran into something but don't know why it's doing what it's doing.</p>
<p>To start, I have two modules: test1 and test2. test1 is as follows:</p>
<pre><code>import test2
num = 0
def start():
global num
num = num + 5
print 'Starting:'
print num
test2.add()
print 'Step 1:'
print num
test2.add()
print 'Step 2:'
print num
</code></pre>
<p>And test2 is this:</p>
<pre><code>import test1
def add():
test1.num = test1.num + 20
</code></pre>
<p>When I run test1.start() the output is:</p>
<blockquote>
<p>Starting:<br>
5<br>
Step 1:<br>
25<br>
Step 2:<br>
45</p>
</blockquote>
<p>Why doesn't test2 need the global declaration to modify the variable in test1? Line 5 in test1 requires it at line 4, but if I remove both it still works (0, 20,40). I'm just trying to figure out why it's not working as I expected it to.</p>
<p>Thanks.</p>
| python | [7] |
5,467,997 | 5,467,998 | Is there a PHP framework considered to be Ruby's Ruby On Rails? | <p>The PHP community has been so vastly fragmented with lots of frameworks while Ruby only has Ruby on Rails being the sole framework of choice of the masses. Although there's also minor players like Sinatra but you know what I mean.</p>
<p>I believe there has been great improvements in PHP lately except the frameworks kept multiplying relentlessly. As I remember back then, there was Mojavi, Symfony, CakePHP, CodeIgniter, Kohana, Zend, then there was Yii, DooPHP, FuelPHP among others, not to mention the "thin" frameworks like FatFree, Slim, Recess, FRAPI, Tonic, etc... </p>
<p>I am having trouble deciding which is which. For example, I have long abandoned CodeIgniter and now that I am just about to consider FuelPHP, suddenly a new client requires me to code in CodeIgniter.</p>
<p>I am beginning to think I should convert to Ruby and avoid all these fragments altogether. Since most of the "converts" treat it like religion, I'm intrigued I might achieve inner peace if I do :-)</p>
<p>I honestly think the PHP community could do well if all the authors of these great frameworks unite as one, make the ultimate framework and name it possibly Zend Framework "Done Right". Feel me?</p>
<p>Now my question is, as experienced programmers, is there any PHP framework that you think is heading on the right track? As we know Zend should've done it but the community feedback was otherwise. Is there a framework right now in the PHP realm, that in due time will probably be recognized as PHP's RoR?</p>
| php | [2] |
5,277,860 | 5,277,861 | show radio buttons on one line? | <p>Am trying to follow this tutorial:
<a href="http://whyandroid.com/android/227-tipster-building-a-tip-calculator-for-the-android-os.html" rel="nofollow">http://whyandroid.com/android/227-tipster-building-a-tip-calculator-for-the-android-os.html</a></p>
<p>All's fine, except I can't understand why my radio buttons aren't on one line, I've pasted my code so far below - I know it's not the same as the tutorial, but I'm really trying to understand every line, so want to know what the equivalent to 'float' is in android - tried playing with gravity, weight etc, but didn't seem to put them onto one line..</p>
<p>Many thanks in advance!</p>
<pre><code><RadioGroup
android:id="@+id/RadioGroup01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_column="0"
android:layout_span="3">
<RadioButton
android:id="@+id/RadioButton01"
android:layout_height="wrap_content"
android:freezesText="true"
android:textSize="10sp"
android:text="15%" android:layout_width="wrap_content">
</RadioButton>
<RadioButton android:id="@+id/RadioButton02" android:layout_height="wrap_content" android:text="20%" android:textSize="10sp" android:layout_width="wrap_content">
</code></pre>
<p>
</p>
| android | [4] |
1,057,856 | 1,057,857 | How to use long integers in Python to build a range? | <p>I am trying to build a range with an upper bound bigger than limit of integer in Python. I was looking for something like the following:</p>
<pre><code>import sys
start = 100;
step = 100;
limit = sys.maxint + 1;
result = xrange(start, limit, step);
</code></pre>
<p>However, <code>xrange</code> parameters are limited to the integer. According to <a href="http://docs.python.org/library/functions.html#xrange" rel="nofollow">Python Standard Library</a>, I have to use <code>itertools</code> module: <code>islice(count(start, step), (stop-start+step-1)//step)</code>, but <code>islice</code> seems to have the same integer limitations for the parameters. </p>
<p>Is there any other way to build the list with upper limit represented by long integer?</p>
| python | [7] |
1,108,265 | 1,108,266 | how to read a value inside a loop? | <p>i am trying to run a very simple java program. i want to write a program that reads 10 integers and that the programs finds witch one is the maximum of them.
i wonder if is possible that inside a loop i can read the 10 values.</p>
<pre><code>Scanner input = new Scanner (System.out);
int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
System.out.print(" please enter the numer " +i);
===>num[i] = input.nextInt();//
</code></pre>
<p>i am trying to find the way to do it without using an array, since i haven't see this in school yet.
any idea how to do it inside a loop? or is just no possible to do?</p>
| java | [1] |
2,070,278 | 2,070,279 | Need tutorials on Content providers in android | <p>I am in desperate need of good tutorials on Content Providers in Android. I have been searching in the web for the tutorials but none could give me a clear idea on how content providers work. I'll be grateful if anyone can provide me with sample codes of the projects that implement content providers... </p>
| android | [4] |
2,827,820 | 2,827,821 | JQuery Cookie values not maintained while moving from http to https | <p>I am creating cookie using jquery, please see below code:</p>
<pre><code>var divID = $(link).next(".open-block-holder").find("div:first").attr("id");
$('#panelOpen').val(divID);
$.cookie('currentPanelOpen', divID);
</code></pre>
<p>the above Cookies 'currentPanelOpen' is been created in HTTP page, now on my login click I am reloading whole page in HTTPS for security reasons. The problem is that my cookie 'currentPanelOpen' value is not maintained while it is moving to HTTPS page. (happening only for first time, once gone to https mode and again coming back to http page and doing above step works fine)</p>
<p>Surprisingly, If I directly open the page in HTTPS mode then the value is maintained and my clicked panel is opened.</p>
<p>Please suggest!</p>
<p>Thanks.</p>
| jquery | [5] |
108,862 | 108,863 | Netbeans 6.9.1 port error | <p>Deployment error: Starting of Tomcat failed, the server port 8080 is already in use. See the server log for details.</p>
<p>Please help i tried to change the ports, but still it gives the same message that : </p>
<p>Deployment error: Starting of Tomcat failed, the server port 8081 is already in use. See the server log for details.</p>
<p>Can any one help me out...?</p>
| java | [1] |
1,011,504 | 1,011,505 | Why filename in java should be same as class name? | <p>In Java, the name of the file should be the same as the name of the public class contained in that file. Why is this limitation? What purpose does it serve?</p>
| java | [1] |
1,501,550 | 1,501,551 | Get Element ID by String it Contains using Plain Javascript | <p>How can I get an elemnts ID based on the string it contains?</p>
<pre><code><span id="th67">This the string I need to match</span>
</code></pre>
<p>I can't make use of JQuery or any other Javascript library to do this.</p>
<p>I need to do this for a selenium test.</p>
<p>I didn't realise how useless I am in JS without my libraries!</p>
<p>Thanks all for any help.</p>
| javascript | [3] |
5,753,679 | 5,753,680 | Is there any easy or automatic way to specify text color selector for click event? | <p>I specified a selector drawable for the background of a layout as below, so when user clicks on the layout, the layout will have a different background. But, I didn't specify color selector for the TextViews in the layout, because there are many TextViews with different colors and I am too lazy to define color selector for them. So the text color keeps the same when the layout is clicked. My questions is, is there an automatic way to specify that the text color is highlighted/changed when the layout is clicked, so I don't have to define color selector for each of the TextViews in a layout? Thanks.</p>
<pre><code><RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/background_selector"
>
<TextView android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/my_green"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<TextView android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/my_blue"
android:layout_alignParentLeft="true"
android:layout_below="@id/text1"
/>
</RelativeLayout>
</code></pre>
| android | [4] |
5,968,929 | 5,968,930 | how to store table of data in sqlite? | <p>I am new to android.</p>
<p>I am been working with <code>sqlite.</code></p>
<p>Through sqlite i am creating two tables like <code>table1,table2</code></p>
<p>table1 is looking like this</p>
<pre><code>key_id Names places
1 pal us
2 jan uk
</code></pre>
<p>table 2 is looking like this</p>
<pre><code>key_id designation salary
1 employee 100$
2 employee 200$
</code></pre>
<p>i want to store this two tables and send through a mail.</p>
<p>If any one has the solution please help me.</p>
<p>Thanks in advance</p>
| android | [4] |
1,078,759 | 1,078,760 | How do I make this template argument variadic? | <p>Say I have a template declaration like this:</p>
<pre><code>template <class A, class B, class C = A (&)(B)>
</code></pre>
<p>How would I make it so that I could have a variable amount of objects of type <code>C</code>? Doing <code>class C ...c = x</code> won't work because variadic template arguments can't have default values. So this is what I've tried:</p>
<pre><code>template <typename T>
struct helper;
template <typename F, typename B>
struct helper<F(B)> {
typedef F (&type)(B);
};
template <class F, class B, typename helper<F(B)>::type ... C>
void f(C ...c) { // error
}
</code></pre>
<p>But up to the last part I get error messages. I don't think I'm doing this right. What am I doing wrong here?</p>
| c++ | [6] |
4,050,830 | 4,050,831 | Python Datatype for a fixed-length FIFO | <p>I would like to know if there is a native datatype in Python that acts like a fixed-length FIFO buffer. For example, I want do create a length-5 FIFO buffer that is initialized with all zeros. Then, it might look like this:</p>
<p>[0,0,0,0,0]</p>
<p>Then, when I call the put function on the object, it will shift off the last zero and put the new value, say 1, into the left side:</p>
<p>[1,0,0,0,0]</p>
<p>If I put a 2, it would then shift and put to look like this:</p>
<p>[2,1,0,0,0]</p>
<p>...and so on. The new value goes at the front and the oldest one is shifted off. I understand that this would be very easy to implement myself, but I would like to use native python datatypes if at all possible. Does anyone know which datatype would be best for this?</p>
| python | [7] |
5,520,717 | 5,520,718 | Layout with image and "bottom bar" issues | <p>I am fairly new at the whole Android thing so I am hoping this is something obvious that I am overlooking since I have not been able to find a solution online yet.</p>
<p>I am creating a view which contains an ImageView and a "bottom bar". The problem I am having is that since the image is larger than the screen and I would prefer to use something similar to "fill_parent" or "wrap_content". Ideally I would set the ImageView's height to "fill_parent-44px", but I have not found a way to do this in the XML.</p>
<p>Eventually I plan to have the ImageView function with multi-touch zoom, so it is therefore not an option to resize the image for different screen resolutions.</p>
<p>Thanks for any help.</p>
| android | [4] |
4,702,498 | 4,702,499 | How to get deleted message info? | <p>I am implemening one application related to sms.</p>
<p>I am getting send and received sms info.</p>
<p>For that it is working fine.</p>
<p>My requirement is getting info about deleted message info also.</p>
<p>If any one know the solution please help me.</p>
<p>Thanks in advance.</p>
| android | [4] |
842,832 | 842,833 | I have to concentric circles how do i limit the drag of inner circle within the outer circle +java | <p>I have to concentric circles how do i limit the drag of inner circle within the outer circle +java</p>
| java | [1] |
286,820 | 286,821 | android - auto-login with facebook sdk | <p>I want to use the facebook sdk and be able to automatically login after the app has already logged in once.</p>
<p>Currently from what I can gather if you use the facebook api and you have the facebook app installed and you have signed in with the facebook app then you don't have to login and you will be automatically logged in. </p>
<p>But if you don't have the facebook app then this automatic login will not happen. -----------I want to handle this case and be still able to automatically log in after the user has logged in with my app once.-------------. From my understanding the facebook sdk requires you to login if the facebook app is not there.</p>
<p>Also if the user has logged in once with my app, I will have the access token then as long as the access token has not expired then you don't need to log in again. But if the access token expires then you have to log in again.</p>
<p>Any help will be appreciated. Thanks.</p>
| android | [4] |
1,756,241 | 1,756,242 | Reducing the total size of a Bitmap in Android without loss of quality | <p>How can I reduce the total file size (in Bytes) of a Bitmap in Android without a loss of quality?</p>
<p>Is it possible to Image filtering in Android programmability like: <a href="http://www.jhlabs.com/ip/filters/index.html" rel="nofollow">http://www.jhlabs.com/ip/filters/index.html</a></p>
<p>Thanks, for your suggestions.</p>
| android | [4] |
3,439,137 | 3,439,138 | validate an image before uploading in php | <p>i am uploadind an image in php using copy function. my imade doesnt display when the image height is less than 981pz & width is less than 477pz </p>
| php | [2] |
2,695,635 | 2,695,636 | jQuery .load() doesn't load script | <p>I have jQuery <code>.load()</code> function like in load_to.html page</p>
<pre><code>$('#targetID').load('/load_from.html #bodyPart, script')
</code></pre>
<p>However, this doesn't seems to be loading javascript from load_from.html page. Is there any way, I can load javascript.</p>
| jquery | [5] |
4,784,948 | 4,784,949 | How to package a Activity into jar file in Android? | <p>I want to make an interface of Activity so that other peolpe can use it ,My activit calls XML file which contain image source.I don't know how to package this Activity into jar file?thank you.</p>
| android | [4] |
1,353,819 | 1,353,820 | how to specify the connection string if the excel file name contains white space?using c# | <pre><code>string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\data\\[Proj_Resource Details 20110118.xlsx];Extended Properties=Excel 12.0";
</code></pre>
<p>i mentioned [ ] still it is throwing exception.how can i solve this problem.
plz mention the correct path</p>
| c# | [0] |
555,428 | 555,429 | When should I use a reference? | <p>Newbie here, I am reading some code, and I see sometimes the author used the reference in a function as </p>
<pre><code>funca (scalar& a)
// Etc
</code></pre>
<p>Sometimes he just use</p>
<pre><code>funcb (scalar a)
// Etc
</code></pre>
<p>What's the difference? Is using a reference a good habit that I should have?</p>
<p>Thank you!</p>
| c++ | [6] |
3,604,023 | 3,604,024 | attachment of file in compose mail in iphone | <p>I am making a window based application. In this I have put some entries which become record for one person now I have put mailcomposer to send mail but I want to send the record in mail of that person in attachment automatically. Can I set document or excel file in mailcomposer in iphone application.</p>
<p>If anyone know please help me.</p>
<p>Thanks alot. </p>
| iphone | [8] |
3,600,251 | 3,600,252 | Center the page around a div | <p>I want to center a div in the document body in jquery.</p>
<p>I have a read more button that shows an extra div when you click it, and i want the move the window position to be centered around this div.</p>
| jquery | [5] |
923,297 | 923,298 | how to play image sequence in loop,reverse order | <p>I am using below code</p>
<pre><code> UIImageView* campFireView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 175, 175)];
// load all the frames of our animation
campFireView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"a1.png"],
[UIImage imageNamed:@"a2.png"],
[UIImage imageNamed:@"a3.png"],
[UIImage imageNamed:@"a4.png"],
[UIImage imageNamed:@"a5.png"],
[UIImage imageNamed:@"a6.png"],
[UIImage imageNamed:@"a7.png"],
[UIImage imageNamed:@"a8.png"],
[UIImage imageNamed:@"a9.png"],
[UIImage imageNamed:@"a10.png"],
nil];
// all frames will execute in 1.75 seconds
campFireView.animationDuration = 0.75;
// repeat the annimation forever
campFireView.animationRepeatCount = 0;
// start animating
[campFireView startAnimating];
// add the animation view to the main window
[self.view addSubview:campFireView]; // [campFireView release];
</code></pre>
<p>this works well for a1 to a10 ,
how can i keep moving in reverse order,So it should animate a1 to a10 to a1 continuously?</p>
| iphone | [8] |
1,088,799 | 1,088,800 | set textview color programaically for the item under section header Listview | <p>I have implemented a Section header Listview where i inflate a layout which have three textviews in it as item.i have referred this example <a href="http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/" rel="nofollow">here</a> to achieve it.</p>
<p>My code is </p>
<pre><code>adapter.addSection(monthitems2[l], new SimpleAdapter(this, security, R.layout.phone_row,
new String[] {"Title", "Caption","val1" }, new int[] { R.id.tvContact, R.id.tvMobile,R.id.tvMail }));
</code></pre>
<p>I have a condition where i need to change text color of ID "R.id.tvContact".I havent defined the textview anywhere in thelayout.i have just referred it as simpleadapter parameter.How to change the textview color the default is white.Any suggestions answers are highly appreciated.</p>
| android | [4] |
2,503,815 | 2,503,816 | Include a class in inline code block in asp.net | <p>I'm playing around with inline code blocks in asp.net. Can somebody tell me why the following code doesn't work?</p>
<pre><code><%@ Language="C#" %>
<%
Response.Write(TestClass.ShowMessage());
public class TestClass
{
public static string ShowMessage()
{
return "This worked!!";
}
}
%>
</code></pre>
<p>I get the following error message: CS1513: } expected</p>
| asp.net | [9] |
5,446,086 | 5,446,087 | Server.Transfer does not work? | <p>I want to redirect to another page using Server.Transfer and I have this simple code:</p>
<pre><code>if (Page.IsPostBack)
{
try
{
Server.Transfer("AnotherPage.aspx");
}
catch (Exception)
{
throw ;
}
}
</code></pre>
<p>But I'm getting an error: "Error executing child request for AnotherPage.aspx.". Could not find the solution on the net. </p>
<p>Just to mention, Response.Redirect works flawlessly. </p>
| asp.net | [9] |
2,963,238 | 2,963,239 | How is this illegal | <pre><code>a) int i[] = new int[2]{1,2};
b) int[] i = new int[]{1,2,3}{4,5,6};
</code></pre>
<p>I know we cannot give size of an array at declaration . But in statement(a) we are giving size in initialization . Then how is statement (a) illegal and statement (b) is legal in java</p>
| java | [1] |
5,024,895 | 5,024,896 | why two date classes one in java.util.Date and java.sql.Date? | <p>HI
I like to know why there are two Date classes in two different packages one in <code>java.util.Date</code> and one in <code>java.sql.Date</code>?
Whats the use of having two Date classes?</p>
| java | [1] |
2,178,408 | 2,178,409 | java gui removing a label using JButton | <p>What i need some help with is removing a label and creating a new one with a button click. At the moment this will add a new label but won't remove the old. I can't find a command that will work, northpanel.remove() will destroy the panel and the previous label, but then i can't create any new ones.</p>
<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class test2 extends JFrame implements ActionListener {
private JTextField textfield;
private JPanel northPanel = new JPanel();
private JPanel southPanel = new JPanel();
public test2() {
setSize(400, 200);
BorderLayout layout = new BorderLayout ();
setLayout(layout);
JLabel label1 = new JLabel("remove this");
northPanel.add(label1);
JLabel label2 = new JLabel("Enter move");
southPanel.add(label2);
textfield = new JTextField(10);
southPanel.add(textfield);
JButton button = new JButton("Move / remove label");
button.addActionListener(this);
southPanel.add(button);
add(northPanel, BorderLayout.NORTH);
add(southPanel, BorderLayout.SOUTH);
}
@Override
public void actionPerformed(ActionEvent e) {
String text = textfield.getText();
if (text.equals("")) {
System.out.println("textfield is empty");
} else {
System.out.println(text);
}
// northPanel.remove();
JLabel label3 = new JLabel("new label");
northPanel.add(label3);
repaint();
validate();
}
public static void main(String[] args) {
test2 app = new test2();
app.setVisible(true);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
</code></pre>
| java | [1] |
4,354,838 | 4,354,839 | Can a cast from object to class ever fail when both are exactly the same? | <p>If I have the following code</p>
<pre><code>object o = new Building(4, "something");
</code></pre>
<p>And I attempt the following</p>
<pre><code>if(o.GetType() == typeof(Building))
Building buildingCast = o as Building;
</code></pre>
<p>What could go wrong? I want to make sure that <code>buildingCast</code> can never be null from a problematic cast. Is there any way at all that cast could fail? Even something obscure? </p>
<p>The reason I ask is that I am cleaning up a test project and I am trying to weed out redundant code. There are checks against <code>buildingCast</code> possibly being null...</p>
<pre><code>if(buildingCast == null)
etc
</code></pre>
<p>...but we cannot reach the code in the if statement.</p>
| c# | [0] |
2,209,915 | 2,209,916 | problem with php script in 1and 1 hosting | <p>I have a problem.</p>
<p>I have wrote an upload form on my html page. Then created an upload php file. I added both to my webserver 1 and 1. when clicking on the script on the live webpage - it starts uploading, however the domain name/upload.php file sits there with nothing there (blank) when i check the destination folder nothing is there.</p>
<p>any gurus willing to help with this - i'm baffled - its my first time dabbling with php?</p>
| php | [2] |
5,966,688 | 5,966,689 | How do you correctly use php filters for validation? | <p>I have recently discovered PHP Filter functions for sanitation and validation.</p>
<p>I have been wondering if im using them correctly and struggle to find much info about them, especially flags.</p>
<p>for example I have a sanitize function for email addresses.</p>
<pre><code>function sanitize_email($var){
$var = trim($var);
$var = filter_var($var,FILTER_UNSAFE_RAW);
$var = filter_var($var,FILTER_SANITIZE_EMAIL);
$var = filter_var($var,FILTER_VALIDATE_EMAIL);
return $var;
}
</code></pre>
<p>My questions are as follows?</p>
<p>Should i be using a combination of filters? or is FILTER_VALIDATE_EMAIL sufficient to secure the form field on its own?</p>
<p>Ive read that UNSAFE_RAW doesnt work unless you use a flag with it but i cant find a good example showing its use with a flag.</p>
<p>I also have a similar function for sanitizing a text field which looks like this...</p>
<pre><code>function sanitize_text($var){
$var = trim($var);
$var = htmlspecialchars($var);
$var = filter_var($var,FILTER_SANITIZE_STRING);
$var = filter_var($var,FILTER_SANITIZE_MAGIC_QUOTES);
return $var;
}
</code></pre>
<p>Again I'm not sure I really need to do everything that I am with this function. </p>
<p>How do I improve on this function with regard to making the input secure?</p>
| php | [2] |
5,975,508 | 5,975,509 | Limit number of page visits based on ip | <p>I wanted to know how can I prevent a single ip address from using too much bandwidth and rapidly access my webpages. That is, checking the user's ip address (I think <code>$_SERVER['REMOTE_ADDR']</code>?), check for latest visit from this user, compute time difference and block rendering the page if the interval is short. Am I right? If so, how can I do it without consuming too much resource and/or time on the server? If there is a database approach, isn't it going cause too many locks?</p>
| php | [2] |
3,918,405 | 3,918,406 | Using jQuery iterate in images inside div and change their src and also add one new attribute | <p>each div has one image having fixed class. i need to change all images src inside those div which has class called ".<strong>diagnostic_picture</strong>" using jquery and also add one new attribute to all the images called "<strong>delaySrc</strong>" inside that div having class called ".diagnostic_picture". here this way wrote the code but did not work....can anyone help me. thanks</p>
<pre><code><div class="diagnostic_picture"><img src="test1.gif" /></div>
<div class="diagnostic_picture"><img src="test2.gif" /></div>
<div class="diagnostic_picture"><img src="test3.gif" /></div>
$(document).ready(function () {
$(".diagnostic_picture").each(function () {
$(this).children("img")
.attr("src", 'images/ajax-loader.gif') // this way i change the src
.attr('delaySrc', $this.attr("src")); ; // this way i add new attribute
});
});
</code></pre>
<p>the attribute called <strong>delaySrc</strong> not being added to img tag inside the div so i change the code bit but still new attribute not being added....i check source by firebug.</p>
<h2>change code</h2>
<pre><code> $(".diagnostic_picture img").each(function () {
var img = $(this);
img.attr("delaySrc", function () { img.attr("src") })
img.attr("src", 'images/ajax-loader.gif');
});
</code></pre>
| jquery | [5] |
5,723,774 | 5,723,775 | Get the div inside another div without using ID attribute in jQuery | <p>I need to access the div with class <code>formErrorContent</code> inside the div with id <code>emailMsg</code> without putting ID attribute for the inner div. How can I achieve that?</p>
<pre><code><div id="emailMsg" class="formError" style="opacity: 0.80; margin-top: 0px;display:none;" onclick="this.style.display='none';">
<div class="formErrorContent">* This field is required<br>
</div>
</div>
</code></pre>
| jquery | [5] |
2,877,055 | 2,877,056 | Using virtual function in child after casting operation in C++ | <p>I have the following code:</p>
<pre><code>class A
{
};
class B : public A
{
public:
virtual void f() {}
};
int main()
{
A* a = new A();
B* b = static_cast<B*>(a);
b->f();
}
</code></pre>
<p>This program fails with a segmentation fault. There are two solutions to make this program work:</p>
<ol>
<li>declare f non-virtual</li>
<li>do not call b->f() (i.e. it fails not because of the cast)</li>
</ol>
<p>However, both are not an option. I assume that this does not work because of a lookup in the vtable.</p>
<p>(In the real program, A does also have virtual functions. Also, the virtual function is not called in the constructor.)</p>
<p>Is there a way to make this program work?</p>
| c++ | [6] |
1,595,094 | 1,595,095 | jQuery contains | <p>Is there a way to get the deepest element matching a contains statement?</p>
<p>Basicly if I have nested divs, I want the last element not the parent element:</p>
<pre><code><div id="hayStack">
<div id="needle">Needle</div>
</div>
</code></pre>
<p><code>$("div:contains('Needle')")</code> is returning the hayStack div.</p>
<p>The only solution I have come up with so far is explicitly exlcuding parent divs by their id with .not</p>
| jquery | [5] |
3,141,273 | 3,141,274 | I want an example to make shortcut file | <p>I used a compiler MinGW. I want an example to make shortcut file. I found examples but did not work.</p>
| c++ | [6] |
2,819,835 | 2,819,836 | jQuery: How to position one element relative to another? | <p>I have a hidden DIV which contains a toolbar-like menu.</p>
<p>I have a number of DIVs which are enabled to show the menu DIV when the mouse hovers over them.</p>
<p>Is there a built-in function which will move the menu DIV to the top right of the active (mouse hover) DIV? I'm looking for something like <code>$(menu).position("topright", targetEl);</code></p>
| jquery | [5] |
1,891,730 | 1,891,731 | Art & Science of Java Chapter 4, Exercise 8 | <p>I'm trying to write a program that does a countdown to liftoff, but using a while loop, instead of an for loop.</p>
<p>So far, all I succeed in doing is creating an infinite loop, even though I'm using the same basic principles as the for loop code.</p>
<pre><code>import acm.program.*;
public class CountDownWhile extends ConsoleProgram {
public void run() {
int t = START;
while (t >= 0); {
println(t);
t = t--;
}
println("Liftoff!");
}
private static final int START = 10;
}
</code></pre>
| java | [1] |
4,693,188 | 4,693,189 | Add hover to a .live('click', function () | <p>This function shows <strong>arrow-img-down</strong> (a 'show' icon). When I click it open sliding div then the img turns <strong>arrow-img-up</strong> (a 'hide' icon)</p>
<p>I want to add to this img replace .src function and also a hover on current img as follows:</p>
<pre><code>$(".showhide").live('click', function () {
if ($(this).attr("class") == "showhide") {
this.src = this.src.replace("img/show_btn.png", "img/hide_btn.png");}
else {
this.src = this.src.replace("img/hide_btn.png", "img/show_btn.png");}
$(this).toggleClass("img/show_btn.png");
});
</code></pre>
<p>How can I add it?</p>
| jquery | [5] |
1,812,745 | 1,812,746 | error when calling a simple function | <p>Please advise me what is wrong with the following code: I want to print the values "10", and "20" by calling the function <code>someFunction</code>.</p>
<p>thx</p>
<pre><code> class myfirstjavaprog
{
void someFunction(int someParam)
{
System.out.println(someParam);
} <-- error
someFunction(10); <-- error
someFunction(20);
}
</code></pre>
| java | [1] |
5,768,395 | 5,768,396 | how to know device is power off | <p>i want to do something when the mobile is closing,but i donot know what is the method,could you tell me How to detect mobile will shut down. i know the method about mobile restart android.intent.action.BOOT_COMPLETED ,but i cannot find power off.</p>
| android | [4] |
4,896,939 | 4,896,940 | jquery event dont works | <pre><code><form id='new_key' action='/foo/bar' method='post'>
<input type="text" id="u">
<input type="submit" value="submit">
</form>
</code></pre>
<p>I can bind a jquery event to this element like:</p>
<pre><code><script type="text/javascript">
$('#new_key').ready(function() {
alert('Handler for .submit() called.');
return false;
});
</code></pre>
<p>It works as expected</p>
<p>but if i do:</p>
<pre><code><script type="text/javascript">
$('#new_key').submit(function() {
alert('Handler for .submit() called.');
return false;
});
</code></pre>
<p>it dont work. does anybody knows why? what am i missing?</p>
| jquery | [5] |
5,500,724 | 5,500,725 | Assigning permissions to System Settings File | <p>I am trying to assign permission to a file i have created which is used to set the system Settings.I am getting an Io Exception on line </p>
<pre><code>inputStream=context.getAssets().open(fileName);
</code></pre>
<p>In my manifest file i have assigned the file permission using </p>
<pre><code><uses-permission android:name="android.permission.WRITE_SETTINGS"/>
</code></pre>
<p>which allows to read and write to system settings file.But still the Exception.Thanks in advance.
As per request I am adding the code where Error occurs</p>
<pre><code>public boolean copyConfigFile(String fileName) throws IOException {
File configFile = new File(systemDir, fileName);
Log.d(getClass().getSimpleName(), "Config file path :" + configFile.getAbsolutePath());
Log.d(getClass().getSimpleName(), "FILE NAME::" + fileName);
if(!configFile.exists()){
configFile.createNewFile();
InputStream is = null;
OutputStream os = null;
try {
is = ctx.getAssets().open(fileName);
os = new FileOutputStream(configFile);
byte []fileBytes = new byte[is.available()];
is.read(fileBytes);
os.write(fileBytes);
Log.d(getClass().getSimpleName(), "File copied.");
return true;
} finally {
if(is != null){
is.close();
}
if(os != null){
os.close();
}
}
}else{
Log.d(getClass().getSimpleName(), "File already exist.");
return true;
}
}
</code></pre>
| android | [4] |
2,799,990 | 2,799,991 | how to add fieldname as a variable in OCCI | <p>In the below C++ code, i am updating a field of emp table based on the search value. But this code is not working properly. I am getting output as aborted. </p>
<pre><code>void UpdateData(string field_name,string updated_value,string search_value)
{
stmt->createStatement("UPDATE emp SET :1=:2 where search=:3");
stmt->setString(1,field_name);
stmt->setString(2,updated_value);
stmt->setString(3,search_value);
stmt->executeUpdate();
}
</code></pre>
<p>In my program user will select which field they have to update and the selected field name is passed into function as field_name parameter. updated_value is the new value entered by the user and search_value is the search key to find the appropriate record. </p>
<p>If i do like
stmt->createStatement("UPDATE emp SET field_name=:2 where search=:3");</p>
<p>its working..</p>
<p>But the problem is, the field name will change according to user selection. How i can overcome this problem. Is there any other way ?</p>
| c++ | [6] |
2,832,249 | 2,832,250 | A Better Way to Load a Javascript Slider | <p>Ok, maybe I've been going about this the wrong way. Maybe someone can point me in the right direction as to what I should be Googling to accomplish either loading the second and third images in my slider only after the page has fully loaded. Another option would be not to load anything in the div containing the slider at all until the page has fully loaded and the images within that div have fully loaded. I tried LazyLoad for the slider images before, but it only conflicted with the slider's 'slide left' effect <a href="http://varmag.com/" rel="nofollow">http://varmag.com/</a> . Thanks in advance for any help</p>
| jquery | [5] |
2,347,801 | 2,347,802 | Executor Service with LIFO ordering | <p>i wrote a lazy imageDownloader for my app using an ExecutorService. (It gives me great control about how many downloads are running paralel at what time and so on)</p>
<p>Now the only problem that i have, is that if i submit a task it ends up at the tail of the quene (FIFO).</p>
<p>Does anyone know how to change this?</p>
<p>thanks!</p>
| android | [4] |
701,617 | 701,618 | Unexpected error from external database driver (22) | <p>Here's my code which is in the beginning of a method for converting .xls file to .csv.</p>
<pre><code>sourceFile="C:\\Users\\myUser\\Desktop\\Folder\\myFile.xls";
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sourceFile + ";Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\"";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
</code></pre>
<p>And it crashes on the last line, throwing this exception: Unexpected error from external database driver (22).</p>
<p>I tried removing the IMEX=1 part, but it still didn't work.</p>
<p>What is the problem?</p>
| c# | [0] |
3,861,799 | 3,861,800 | Resolving ip-address of a hostname | <p>I have the DNS server IP address and a hostname.</p>
<p>Using Java, how can I find the IP address of the hostname as returned by that DNS server using the IP address and the hostname?</p>
| java | [1] |
2,354,036 | 2,354,037 | convert US date time to culture specific value | <p>My problem is that i am not able to convert the US date value into british format. The TryParse condition is always coming out as false and thus the outputValue is never filled up.</p>
<p>Is there something wrong with the implementation ? Please pin point or suggest better alternative. Thanks.</p>
<pre><code> string filterValue = "12/22/2011"
string outputValue = ""
DateTime dt;
string strCulture = "en-GB";
CultureInfo ci = new CultureInfo(strCulture);
if (DateTime.TryParse(filterValue, ci, DateTimeStyles.AdjustToUniversal, out dt))
outputValue = dt.ToString("d", ci);
</code></pre>
| asp.net | [9] |
1,501,677 | 1,501,678 | Open/Close on click JQuery | <p>When the ID 'Home' is clicked in the following example, the div.panel will appear, and then if the ID 'Home' is clicked again, the div.panel is hidden. Currently I have this:</p>
<pre><code>$(document).ready(function() {
$('#home').on('click', function() {
$('div.panel').animate({
'width': 'show'
}, 1000, function() {
$('div.home').fadeIn(500);
});
});
$('#home').on('click', function() {
$('div.home').fadeOut(500, function() {
$('div.panel').animate({
'width': 'hide'
}, 1000);
});
});
});
</code></pre>
| jquery | [5] |
4,742,472 | 4,742,473 | Assignment operator and deep copy | <p>I'm learning C++ and there is something I don't get about assignment operators. As far as I understand, they are supposed to provide deep copies of object. Here is an example</p>
<pre><code>Test::Test(int i){
value = i;
}
Test& Test::operator=(const Test& rhs){
value = rhs.value;
return *this;
}
</code></pre>
<p>Now:</p>
<pre><code>Test* t1 = new Test(1);
Test* t2 = t1; //t2 should be now a deep copy of t1
t1->value = 2;
cout << t1->value;
cout << t2->value;
</code></pre>
<p>Output is <code>22</code> but I expected '21'. What is the obvious thing I am missing here?</p>
| c++ | [6] |
5,712,443 | 5,712,444 | library for search questions and answers | <p>I am looking for a library (preferably in C#) that can solve me the concept of Q&A search.
like stackoverflow has. a query is inserted, and is picking out of a DB of Q&A</p>
<p>thanks</p>
| c# | [0] |
4,376,462 | 4,376,463 | Many buttons, jquery | <p><strong>jQuery</strong>:</p>
<pre><code>$("#direction").click(function() {
var direction = $(this).text();
alert(direction);
}
</code></pre>
<p><strong>HTML</strong></p>
<pre><code><button id="direction">South</button>
<button id="direction">North</button>
</code></pre>
<p>Only the first button alerts the text. I don't understand why. How can I fix this?</p>
| jquery | [5] |
3,554,672 | 3,554,673 | Form_Activated is messing up closing the program | <p>I'm currently trying to bring two forms to the front when I activate them from the Task bar or via Alt+Tab. The problem is that I can't close the main form if the second one exists:</p>
<p>This is the code I use</p>
<pre><code> private void Haupt_Activated(object sender, EventArgs e)
{
cardLibrary.Focus(); //Focus the second form
this.Focus(); //refocus the first one
}
</code></pre>
<p>What am I doing from?</p>
<p>EDIT:
Haupt is the main form.
CardLib is variable in Haupt
this is how CardLib is called:</p>
<pre><code> private void cMenuOpenLibrary_Click(object sender, EventArgs e)
{
if (!Config.libOpen)
{
if (cardLibrary == null) cardLibrary = new CardLib(this);
cardLibrary.Show();
cardLibrary.Left = this.Left - cardLibrary.Width - 5;
cardLibrary.Top = this.Top;
}
}
</code></pre>
<p>EDIT 2: Sry I was being dumb. Adding closing the CardLib via Haupt_FormClosed fixed it.</p>
| c# | [0] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.