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 |
---|---|---|---|---|---|
5,478,939 | 5,478,940 | How To Call A Function With Proper 'Arguments' | <p>I have a function that takes 2 returned variables from another function to write them with a little bit more padding text to an external text file.</p>
<p>The code that I am using to write to the text file is below but it is being called automatically at runtime with the <code>if</code> statement at the bottom of the program</p>
<pre><code>def function1()
# Some code
def function2()
# Some code
return startNode
return endNode
def function3(var)
# Some code
return differentVariable
def createFile(startNode, endNode):
outputFile = open('filename.txt','w') # Create and open text file
start = chr(startNode +65) # Converts the int to its respective Char
end = chr(endNode +65) # Converts the int to its respective Char
outputFile.write('Route Start Node: ' + start + '\n') # e.g Route Start Node: B
outputFile.write('Route end node: ' + end + '\n') # e.g Route End Node: F
outputFile.write('Route: ' + Path + '\n') # e.g Path: B,A,D,F
outputFile.write('Total distance: ' + Distance) # e.g Total Distance: 4
outputFile.close # Close file
if __name__ == "__main__":
function1()
function3(function2())
createFile( # Don't Know What Goes Here )
</code></pre>
<p>At the moment I am only able to run this function by manually calling it and entering <code>createFile(1,5)</code> where the 1 is the startNode value and the 5 is the endNode value</p>
<p>But if I am to put <code>createFile(startNode, endNode)</code> in the <code>if</code> statement to call the function, it tells me <code>NameError: name 'startNode' is not defined</code> and then it would obviously give me the same error for endNode too</p>
<p>How do I call that function properly without having to enter the values manually because they can change depending on what the startNode and endNode values are at the start of the program?</p>
| python | [7] |
2,689,965 | 2,689,966 | DataKey names in Form view | <p>How to access dataKey values</p>
<pre><code> <asp:FormView ID="FormView1" runat="server" Style="margin-right: 65px"
DataKeyNames="MMBProfileID"
<ItemTemplate>
<table id="FormViewTable" style="width: 100%;">
<tr>
<td>
Name:
</td>
<td>
<%# Eval("MMB_Name") %>
</td>
</code></pre>
<p></p>
<pre><code> protected void Page_Load(object sender, EventArgs e)
{
MMBProfileId = Convert.ToInt32(FormView1.DataKey["MMBProfileID"]);
FormView1.DataSource = objBLL.Execute_ViewBusinessProfile(MMBProfileId);
</code></pre>
<p>}
This is giving me an error.
Input string not in correct format at (FormView1.DataKey["MMBProfileID"]);</p>
<p>Any hints will be appreciated
Thanks
Sun</p>
| asp.net | [9] |
1,799,516 | 1,799,517 | stop the calendar control in asp,net from doing a postback everytime the month is changed | <p>The Calendar control in asp.net has a default behaviour to do a postback whenever the month is changed (when clicking on next or previous month arrows). This causes the calendar control to collapse. How to prevent this. I want a postback only when the date selection changes and the calendar control should not collapse when month is changed.</p>
<p>Any help is appreciated</p>
<p>thanks in advance</p>
| asp.net | [9] |
5,601,785 | 5,601,786 | Is it a good practice to create a reference to application context and use it anywhere? | <p>I have to use context in many places of my code such as database operations, preference operations, etc. I don't want to pass in context for every method.</p>
<p>Is it a good practice to create a reference to application context at the main Activity and use it anywhere such as database operations? So, I don't need some many context in method parameters, and the code can avoid position memory leak due to use of Activity Context.</p>
<pre><code>public class MainActivity extends Activity {
public static Context s_appContext;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
s_appContext = this.getApplicationContext();
</code></pre>
| android | [4] |
3,080,255 | 3,080,256 | Check if a string starts with certain values | <p>I am working on a chat script, and I am trying to check if the entered value contains /staff at the start of the string $message, if it does contain /staff then I would like it to split the $message into two variables $type (which would just have the value of staff) and $message (containing everything after /staff).</p>
<p>I've tried</p>
<pre><code>if(strstr($message, '/staff')){
}
</code></pre>
<p>But this checks the ENTIRE variable, not the first 6 characters. So if the $message contained "Hey, try out /staff", it would save it as a staff $type message.</p>
| php | [2] |
1,614,532 | 1,614,533 | How to improve my android custom Rom? | <p>I just wanted to know which parts of the android OS i have to edit to improve my rom? I mean, editing the build.prop won't do the entire trick.
What do you guys suggest? </p>
| android | [4] |
1,994,578 | 1,994,579 | time limit for Process.waitFor | <p>Is there a way (either builtin, or with external library) to have a time limit for <code>Process.waitFor</code>? It's a good safeguard against buggy processes, and implementing it with an extra thread and an interrupt seems like reinventing the wheel.</p>
| java | [1] |
3,307,680 | 3,307,681 | How do 2 dimentional lists work in Python | <p>I am doing <a href="http://projecteuler.net/problem=15" rel="nofollow">Project Euler Problem 15</a>. I used the right algorithm, but it didn't seem to work. Here's my code:</p>
<pre><code>f = [[0] * 21] * 21
# init the list
for i in range(21):
f[0][i] = 1
f[i][0] = 1
for i in range(21):
for j in range(21):
f[i][j] = f[i-1][j] + f[i][j-1]
print f[20][20]
</code></pre>
<p>when I finished initializing the list, I printed it. I expected it like <code>[[1, 1, 1...], [1, 0, 0...]...]</code>, but it turned <code>[[1, 1, 1...], [1, 1, 1...]...]</code> and I can't figure why.</p>
<p>I used to use C-like language and I thought the list in Python is kind of like the array in C, so I used them in the same way.</p>
| python | [7] |
5,857,550 | 5,857,551 | Can an unescaped apostrophe in a literal defined in strings.xml cause my app to crash? | <p>Google's official documentation mentions:</p>
<p>Escaping apostrophes and quotes</p>
<p>If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes. For example, here are some stings that do and don't work:</p>
<pre><code><string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don&apos;t work</string>
</code></pre>
<p>My question is: Would unescaped quotes cause the application to crash or would it just have no effect and the quotes won't appear in the app UI? Would it crash on specific Android versions? I ask this because if I don't escape this symbol, Eclipse SDK gives me compilation errors but I came across a third-party app code which does not escape these characters, it crashes randomly and I'd like to confirm that this is/ is not one of the possible reasons for the crash.</p>
| android | [4] |
5,183,306 | 5,183,307 | Query javascript collection with same syntax as MongoDB | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/8695718/is-there-a-way-to-use-mongodb-query-objects-to-filter-regular-javascript-arrays">Is there a way to use MongoDB query objects to filter regular JavaScript arrays?</a> </p>
</blockquote>
<p>So I have an array of objects stored in javascript, and I want to query that array of objects using the same type of syntax you would you in MongoDB.</p>
<p>For example</p>
<pre><code>var collection = [
{color:'blue', name:'obj1'},
{color:'green', name:'obj2', size:3},
{color:'red', name:'obj2', size:4}
]
</code></pre>
<p>I would like to do something like,</p>
<pre><code>doQuery(collection, query, function(result_array){...});
</code></pre>
<p>where the query could be any of the following</p>
<pre><code>var query = {color:'blue'}
var query = { $or :[color:'blue', size: {$gt: 3}] }
</code></pre>
<p>Are there any libraries that are like this?</p>
| javascript | [3] |
3,206,006 | 3,206,007 | another javascript copy question | <p>The original json</p>
<pre><code>var json =
[{ "LABEL":"foo1", "DATA":340020, "BAR":235 },
{ "LABEL":"foo2", "DATA":140084, "BAR":330 },
{ "LABEL":"fooN", "DATA":126489, "BAR":120 }];
</code></pre>
<p><br/>
Below the desired format, where new <code>DATA</code> corresponds to old <code>BAR</code></p>
<pre><code> [{ "LABEL":"foo1", "DATA":235 },
{ "LABEL":"foo2", "DATA":330 },
{ "LABEL":"fooN", "DATA":120 }];
</code></pre>
| javascript | [3] |
4,949,780 | 4,949,781 | Partial wake lock power drain in Android phones | <p>I am creating a remote service that keeps the PARTIAL_WAKE_LOCK in order to continually
do some background work. What range of power drain should I expect in the Android devices
from this? On my devices, it eats anything between 30 min and 2 hours of battery life as measured from full charge.</p>
| android | [4] |
1,941,168 | 1,941,169 | Saving data with sharedpreferences | <p>Does SharedPreference work for when the user presses the back button.Then what is the way to store data when the user presses the back button.</p>
| android | [4] |
3,462,871 | 3,462,872 | Help! basic ASP.NET 3.5 radiobuttonlist not working right inside a updatepanel | <p>So I have a radiobuttonlist inside an updatepanel. I seem to be hitting a really simple yet vexing problem - </p>
<p>Even though I've set AutoPostBack=true, when I click on a radio button, I see the postback happen but the SelectedIndexChanged event does not fire at all. Not only that, even in the postback, when I check SelectedIndex it shows -1 instead of the button I clicked.</p>
<p>this is so annoying and I don't know what I'm doing wrong. It's plain and simple postback and server side processing to know which radio button in the list got clicked, there is nothing fancy in the code on either the server or client sides.</p>
<p>Please help!</p>
<p>(PS - I tried with/without adding the rbList control and the SelectedIndexChanged as triggers for the update panel and it still doesn't work..the SelectedIndexChanged does not fire)</p>
| asp.net | [9] |
2,673,006 | 2,673,007 | Did button actually click? | <p>I have some javascript that ends up programatically clicking on a button:</p>
<pre><code> document.getElementById("myButton").click();
</code></pre>
<p>This in turn results in the form being submitted using a function call:</p>
<pre><code> <form onsubmit="submit_this_form(this);return false;" action="" method="POST">
</code></pre>
<p>It seems that a good percentage of the time either the actual button click is not going through or the form is not being submitted. I think the button click is going through and I know the code is being called because I have a counter embedded and I can see it is executing. </p>
<p>My question is...is there an event or a way to verify that the form actually posted? By the way, I don't have control of the HTML code so I can't change the tag content.</p>
| javascript | [3] |
2,241,405 | 2,241,406 | C# :remove one line in a Txt file | <p>i want to remove one line in a txt file after i've gotten the data with StreamReader.WriteLine().
but i cannot get any useful reference for the web.
somebody tell me that i can do it with the Repalce() method .but i dont think its efficent.
can anyone tell me how to resolve it. thanks! </p>
| c# | [0] |
3,595,364 | 3,595,365 | Android Tabs in Bottom of the Layout | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom">Android: Tabs at the BOTTOM</a> </p>
</blockquote>
<p>How to add tabs at the bottom of the screen in android.Please any one tell the answer</p>
| android | [4] |
1,855,979 | 1,855,980 | How do I prevent spaces from being URL encoded for a `javascript:` URL? | <p>I'm trying to use the following as a URL that executes javascript:</p>
<pre><code>javascript:var field = document.getElementsByName("actions[hide]"); + for (i = 0; i &lt; field.length; i++)field[i].click();
</code></pre>
<p>However, the spaces get URL encoded when I bookmark it, replaced with <code>%20</code>, which (for a reason unknown to me) causes the JS code not to work.</p>
<pre><code>javascript:var%20field%20=%20unescape%20document.getElementsByName("actions[hide]");%20+%20for%20(i%20=%200;%20i%20&lt;%20field.length;%20i++)field[i].click();
</code></pre>
| javascript | [3] |
2,034,991 | 2,034,992 | defined or define in PHP | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/7008830/why-defined-define-syntax-in-defining-a-constant">Why 'defined() || define()' syntax in defining a constant</a> </p>
</blockquote>
<p>This piece of code is created by the zf tool that Zend Framework provides. </p>
<pre><code>defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
</code></pre>
<p>My questions is :
What is the purpose of this line of code? There are no conditional statements such as if, switch. Does it imply a conditional statement automatically? </p>
<p>Here is how i understand it:
if APPLICATION_PATH is defined, leave it alone else set it to : <code>realpath(dirname(__FILE__) . '/../application')</code>.</p>
<p>If my assumption is true this is a really confusing syntax.</p>
<p>Any help will be appreciated.</p>
| php | [2] |
3,829,314 | 3,829,315 | Get a sum in python dictionary | <p>I got a dictionary like from my code</p>
<pre><code>city = place_user['full_name'].encode("utf-8").split('full_name')
city_point = dict.fromkeys(city, sum)
# the result is below:
{'Los Angeles': 30}
{'Batu Ceper' : 20}
{'Ocean Acres': 10}
{'Los Angeles': 20}
</code></pre>
<p>I want to get result which item has the biggest point in dictionary.
The result like this:</p>
<pre><code>Lo(or LA): 50
</code></pre>
<p>I'd like to abbreviate item like LA or Lo(first two characters). </p>
<p>How do I write a code in simple way? </p>
| python | [7] |
1,731,284 | 1,731,285 | file_get_contents should load after clicking a link | <p>I'm passing a value to a string using the file_get_contents function as below:</p>
<pre><code>$value=file_get_contents('http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId='.$app.'&from='.$fr.'&to='.$tol.'&text='.urlencode($lastline));
$speaktext="http://api.microsofttranslator.com/V2/http.svc/Speak?appId=$app&language=$tol&format=audio/wav&text=$value";
</code></pre>
<p>I'm using the variable $speaktext in the code below to output some sound out of it.</p>
<pre><code>$sound="<object data=\"$speaktext\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\"width=\"200\" height=\"30\">
<param name=\"url\" value=\"$text\"/>
<param name=\"autostart\" value=\"false\"/>
</object>";
</code></pre>
<p>When I pass the $value variable to the $speaktext variable it first renders the whole $value variable (receives data from api.microsofttranslator.com) and the passes it to $speaktext.</p>
<p>Is there a way that the $value variable is rendered exactly when I use the <code><object data=...></code>? I mean when the user clicks the play button on the <code><object></code>, It renders $value, passes it to $speaktext and the file will be played.</p>
<p>I know the question seems a bit hard to understand but I couldn't find a better way to explain it.</p>
| php | [2] |
1,201,423 | 1,201,424 | Can I programatically make my website go to full screen via F11? | <p>I want to make my page viewed at full screen.</p>
<p>How can I programatically press <kbd>F11</kbd> on page load. Is it possible?</p>
<p>Thank you</p>
| javascript | [3] |
5,190,839 | 5,190,840 | Passing String array using intent | <p>i am struck with passing String array from one activity to another using intent. while passing only a String from two activities, its work clear. but whenever i tried to access string array i am getting force close error. can any one guide me to rectify the problem. </p>
| android | [4] |
5,810,843 | 5,810,844 | How to avoid data lose when UIImagePickerController unloads my controller? | <p>I am using UIImagePickerController to take a photo from the camera. However, the I find that randomly my calling controller (the one that is shown before the UIImagePickercontroller is shown) gets unloaded. I logged the viewDidUnload, and indeed it does get called. When the camera is done and dismissed, my controller's viewDidLoad will be called, unfortunately all the state is now gone. Things like text entered or things selected will be gone. </p>
<p>Obviously this is something to do with running out of memory. But is this behavior normal? Should I be handling it? This is NOT typically how modalViewController works. Usually you show it and dismiss it, everything should be intact. </p>
<p>What is a good way to avoid data lost in this case? Should I have to write a bunch of code to save the full state?</p>
| iphone | [8] |
3,867,542 | 3,867,543 | File size is zero | <p>I'm trying to write a simple script that looks at various files and manipulates them depending on file size, but I've tried both :</p>
<pre><code>os.stat(path + fname).st_size
</code></pre>
<p>and</p>
<pre><code>os.path.getsize(path + fname)
</code></pre>
<p>but both return a result of '0'. I'm running Kubuntu but the file system is NTFS formatted, could this be the problem, or does anyone have any reason why this may be happening?</p>
<p>** EDIT **</p>
<p>Somehow all my files have been emptied of all their data. Please ignore this, the filesize is being reported correct. </p>
| python | [7] |
5,674,139 | 5,674,140 | Documenting exception? | <p>I noticed in mscorlib.xml (the xml file that is generated from the summaries) it has </p>
<pre><code><member name="M:System.Console.ReadKey">
<summary>Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.</summary>
<returns>A <see cref="T:System.ConsoleKeyInfo" /> object that describes the <see cref="T:System.ConsoleKey" /> constant and Unicode character, if any, that correspond to the pressed console key. The <see cref="T:System.ConsoleKeyInfo" /> object also describes, in a bitwise combination of <see cref="T:System.ConsoleModifiers" /> values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key.</returns>
<exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>
<filterpriority>1</filterpriority>
</member>
</code></pre>
<p>I am interested in</p>
<pre><code><exception cref="T:System.InvalidOperationException">The <see cref="P:System.Console.In" /> property is redirected from some stream other than the console.</exception>
</code></pre>
<p>How do you document exceptions in code so that they end up in the xml?</p>
| c# | [0] |
784,349 | 784,350 | Can someone explain this line of code please? (Logic & Assignment operators) | <p>I've seen the following lines of code and I know what they do, but I don't know how the second line works (and hence how to apply it to another situation).</p>
<pre><code>$user = User::model()->findByPk(123);
empty($user->profile) and $user->profile = new Profile();
</code></pre>
<p>The code tries to look up the User from the database, and if there isn't a profile, creates a new for use later on.</p>
<p>I have also seen code before that goes something like the following:</p>
<pre><code>$variable1 = $variable2 = $variable3;
</code></pre>
<p>It did something a bit more complex than simple assigning three things to be the same, but I'm finding it impossible to search for this type of thing to find out any information about it, let alone find the original code that I came across. I think it originally had an 'and' in there somewhere. Does anyone know how to search for code that has more than one equals sign in it that wasn't just an if statement?</p>
<p>Sorry for the two questions in one (and vague at that) and the terrible title (I'll fix it up when I know what the names are, if it's anything like a tenary statement)).</p>
| php | [2] |
5,541,707 | 5,541,708 | Android - in app payments crashing during checkout | <p>I am adding in-app functionality to my app, and I am able to get the user to go to the checkout page of Google Play after they press buy. But when they click on "Accept & Buy" in the checkout screen, the system crashes, and says:</p>
<pre><code>Error
-----
Your order could not be processed. Please try again.
</code></pre>
<p>But if I try again, the same thing happens.</p>
<p>And when I check my crash reports, there is nothing related. Maybe I need to do something in my merchant account? What could it be?</p>
<p>Update - when I asked a friend to try, they got a forced-closed crash report, but then they said the transaction went through.</p>
<p>Thanks!</p>
| android | [4] |
4,984,834 | 4,984,835 | Not all code paths have a return value | <p>This is very strange because as far as I can tell the method does return a value or null...I have ran it with null before and it worked...ever since I entered those 2 if statements inside the if statement, I am getting the error "not all code paths have a return value"</p>
<pre><code> if (dt.Rows.Count != 0)
{
if (dt.Rows[0]["ReportID"].ToString().Length > 40)
{
string ReportID = dt.Rows[0]["ReportID"].ToString().Substring(0, 36);
string ReportIDNumtwo = dt.Rows[0]["ReportID"].ToString().Substring(36, 36);
MyGlobals1.versionDisplayTesting = ReportID;
MyGlobals1.secondversionDisplayTesting = ReportIDNumtwo;
return ReportID;
}
else if (dt.Rows[0]["ReportID"].ToString().Length < 39)
{
string ReportID = dt.Rows[0]["ReportID"].ToString();
MyGlobals1.versionDisplayTesting = ReportID;
return ReportID;
}
}
else
{
return null;
}
}
</code></pre>
| c# | [0] |
3,413,846 | 3,413,847 | Website potential file lock issue | <p>I am writing a blog where I upload text documents to a directory that contain HTML. Using the code below, do you anticipate I will have any issues with file locking or other problems I am not seeing? I am most concerned about the File.ReadAllText().</p>
<p>The directory will contain a list of files ex:</p>
<p>20120101_2300.txt</p>
<p>20120201_0100.txt</p>
<p>etc...</p>
<pre><code>public class Website
{
private string directory = "C:\\Web";
public List<BlogEntry> GetArchives()
{
return GetArchives("");
}
public List<BlogEntry> GetArchives(string date)
{
var files = !string.IsNullOrEmpty(date) ? Directory.GetFiles(directory, "*.txt").Where(t => t.Contains(date)) : Directory.GetFiles("C:\\Web", "*.txt");
var sb = files.Select(file => new BlogEntry {FullPath = file}).ToList();
return sb.OrderByDescending(t => t.FileDate).Skip(5).ToList();
}
public List<BlogEntry> GetRecent()
{
var files = Directory.GetFiles(directory, "*.txt");
var sb = files.Select(file => new BlogEntry {FullPath = file}).ToList();
return sb.OrderByDescending(t => t.FileDate).Take(5).ToList();
}
}
public class BlogEntry
{
public string FullPath { get; set; }
public DateTime FileDate
{
get { return DateTime.ParseExact(Path.GetFileNameWithoutExtension(FullPath), "yyyyMMdd_HHmm", CultureInfo.InvariantCulture); }
}
public string FileContents
{
get { return File.ReadAllText(FullPath); }
}
}
</code></pre>
| c# | [0] |
2,279,100 | 2,279,101 | Not able to fill the textboxes in frameset. ? how can i do that | <pre><code><html>
<head>
<script type="text/javascript">
function load()
{
var the_form = parent.document.frames['myFrame'].document.forms['form1'];
var source = the_form.elements['Login1_UserName'];
var target = the_form.elements['Login1_Password'];
alert('');
}
</script>
</head>
<frameset>
<frame name="myFrame" src="http://xyz.com/" onload="load()" />
</frameset>
</html>
</code></pre>
| javascript | [3] |
5,607,148 | 5,607,149 | c# file move (file is already used by another process) | <p>I am moving files from one folder to another. If I try to move the entire folder to the folder within that particular folder I cannot do that. But if I move it outside it works fine. How can I move my folder to the folder within that folder?</p>
<p><strong>this gives error</strong></p>
<pre><code> if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\copypath\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
</code></pre>
<p><strong>this works fine</strong></p>
<pre><code> if (System.IO.Directory.Exists(PhysicalPath))
{
string sourcePath = "c:\\copypath\\";
string targetPath = "c:\\abc\\";
System.IO.Directory.Move(sourcePath, targetPath);
}
</code></pre>
| c# | [0] |
79,575 | 79,576 | Refresh Page Auto | <p>How To auto refresh index (Php Page) or any , after update or insert data to (TABLE) mysql database ? the best example : Gmail (googlemail) . in gmail auto refresh page(inbox) after received new email. </p>
| php | [2] |
4,107,286 | 4,107,287 | Input and store to Array | <p>I'm new to android programming and not really good at java programming.
Simple question here:How to store value typed in EditText to array once button
is pressed, the way that I will able to compare each index to a constant value of
another variable.</p>
| android | [4] |
4,596,509 | 4,596,510 | Jquery: Hide child <div> when user clicks inside parent <div> | <p>I have the following code and would like to hide a DIV when the user clicks anywhere inside it's parent DIV. If the user clicks outside of the parent DIV then nothing would happen.</p>
<pre><code><div id="BodyField">
<div class="video-field-new"></div>
</div>
</code></pre>
<p>So I would like the DIV with "video-field-new" to hide when user clicks inside of #BodyField.</p>
<p><strong>Background</strong>: I have a small banner that lays over a video in the corner when the video is new, but I do not want it to block the video player when the user plays the video. So ideally when the user clicks to play the video, which is inside the #BodyField then the banner will hide.</p>
| jquery | [5] |
1,886,932 | 1,886,933 | Setting a number between tags as a variable | <p>I'm trying to get a number (<code>x</code>) inside tags, ie: <code><span id="Number">x</span></code> and set that as a variable.</p>
<p>Am I even on the right track with this? Not even close?</p>
<pre><code>var y = $('#Number').nextUntil('span');
</code></pre>
| jquery | [5] |
5,351,687 | 5,351,688 | Issue with Media scanner broadcast events...! | <p>I am developing an application where I am displaying gallery images for that I have used the device native gallery source code(From grep code). Everything is working fine in other devices, but I am facing the problem with the jelly bean version devices. After digging in to the problem I found one issue in the code is that it is not firing the broad cast events for media scanner.</p>
<p>Here is the code snippet:</p>
<pre><code>private void onResume()
{
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
intentFilter.addDataScheme("file");
BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
} else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
// SD card unavailable
rebake(true, false);
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) {
rebake(false, true);
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
rebake(false, false);
} else if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
rebake(true, false);
}
}
};
registerReceiver(mReceiver, intentFilter);
}
</code></pre>
| android | [4] |
5,444,889 | 5,444,890 | How can I set curl_init to a variable? | <p>I'm trying to create a line like this, in PHP:</p>
<pre><code>$cURL = $curl_init('http://mysite.com/2');
</code></pre>
<p>I'm doing this so I can set options for $cURL...</p>
<pre><code>curl_setopt($cURL, CURLOPT_PROXY, $proxy); // proxy
curl_setopt($cURL, CURLOPT_PROXYPORT, $port); // proxy port
curl_setopt($cURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // use authentication
curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); // send the headers
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); // We need to fetch something from a string, so no direct output!
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1); // we get redirected, so follow
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($cURL, CURLOPT_UNRESTRICTED_AUTH, 1); // always stay authorised
$wrong = curl_exec($cURL); // Get it
curl_close($cURL); // Close the curl stream
</code></pre>
<p>Why can't I set $cURL (it gives me an error on that line), and is there any way around it?</p>
| php | [2] |
5,942,178 | 5,942,179 | php include will not work one level up | <p>I'm trying to include a file v-functions.php that's in htdocs/sc-dev/</p>
<p>The file I'm working on is in htdocs/sc-dev/accounts/verify</p>
<p>How do I write the include for the file v-functions so I can include it in index.php which is in /verify</p>
<p>I tried using include ('../../sc-dev/v-functions.php'); but that wont work, although it works fine in /accounts.</p>
<p>I'm running php 5.3.13 on Windows 7 Home Premium using apache server</p>
| php | [2] |
3,990,351 | 3,990,352 | Danish Æ being recognized as 2 letters instead of one | <p>I've a simple code like so:</p>
<p><code>echo strlen('Grækenland');</code></p>
<p>and it's returning 11 instead of expected 10</p>
<p>The server is in denmark, locale was set to danish, but it still returns 11...</p>
| php | [2] |
1,843,039 | 1,843,040 | python program with match_ends | <pre><code># 5.- match_ends
# Given a list of strings, return the count of the number of
# strings where the string length is 2 or more and the first
# and last chars of the string are the same.
# Note: python does not have a ++ operator, but += works.
# For example, the result of n = n + 1 can be also achieved by n += 1.
def match_ends(words):
# +++your code here+++
if len(words)>=2:
return words[0]and words[-1:]==words[-1:]
words+=words
</code></pre>
<p>What do you guys think I'm doing wrong and how should I improve this?</p>
<p>Here's the result:</p>
<pre><code>match_ends
X got: True expected: 3
X got: '' expected: 2
OK got: True expected: 1
</code></pre>
| python | [7] |
5,971,470 | 5,971,471 | getting null pointer exception on using savedInstanceState.getInt( "Phase", 1 );? | <p>I'm getting null pointer exception on this line inside OnCreate function:</p>
<pre><code>int Phase = savedInstanceState.getInt( "Phase", 1 );
</code></pre>
<p>According to what I read, this function should return the value associated with "Phase" or 1 if no mapping exits for the key "Phase". However for some reason I'm getting this exception, any ideas as to why this is happening?</p>
| android | [4] |
5,562,297 | 5,562,298 | How to compare two vectors, in C++ | <p>This is my code:</p>
<pre><code>#include <algorithm>
void f() {
int[] a = {1, 2, 3, 4};
int[] b = {1, 2, 100, 101};
// I want to do something like this:
// int* found = compare(a[0], a[3], b[0]);
// in order to get a pointer to a[2]
}
</code></pre>
<p>Maybe I missed this algorithm in the manual… Please help :)</p>
| c++ | [6] |
5,983,064 | 5,983,065 | UITableView very slow scrolling with images from the web | <p>I am loadingimages from a url it's about 20-30 images over http.</p>
<p>The UITableView is very very slow sticky.</p>
<p>What can i do to make it smother?</p>
| iphone | [8] |
1,282,370 | 1,282,371 | write to file an object of an odd type? in java | <p>The resulting cyphertext from my project is an object consisting of 3 fields: two byte arrays and a Point on elliptic curves in Affine coordinates. Because of this Point type field I cannot use serialization so i cannot write the cyphertext in a file. What can I do to save (write in a file or any other solution) the cyphertext and be able to use it (read it from file) in decryption afterwards?</p>
| java | [1] |
4,476,489 | 4,476,490 | How do i get url address from browser(Mozilla/IE) using C#? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/430614/get-firefox-url">Get Firefox URL?</a> </p>
</blockquote>
<p>I am writing a program to search for a keyword in google and get the links displayed in search back to the program. Can anyone please suggest how can i get url from browser in C#.</p>
| c# | [0] |
4,972,528 | 4,972,529 | Creating directories problem | <p>Can't figure out why this keeps creating 2 folders? It makes a '0' folder and whatever the jobID is from the html. I want uploaded files in the jobID folder, not the '0' folder.</p>
<pre><code> int userID = 1; // test
String coverLetter = "";
String status = "Review";
int jobID = 0;
String directoryName = "";
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart && request.getContentType() != null)
{
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List /* FileItem */ items = null;
try
{
items = upload.parseRequest(request);
}
catch(FileUploadException e) {}
// Process the uploaded items
Iterator iter = items.iterator();
while(iter.hasNext())
{
FileItem item = (FileItem)iter.next();
if(item.isFormField())
{
if(item.getFieldName().equals("coverLetter"))
coverLetter = item.getString();
if(item.getFieldName().equals("jobID"))
jobID = Integer.parseInt(item.getString());
}
directoryName = request.getRealPath("/") + "/Uploads/CV/" + jobID + "/";
File theDir = new File(directoryName);
if (!theDir.exists())
theDir.mkdir();
if(item.getFieldName().equals("file"))
{
File uploadedFile = new File(directoryName + item.getName());
try
{
item.write(uploadedFile);
}
catch(Exception e) {}
}
}
</code></pre>
<p>Edit:</p>
<p>Problem solved.I want uploaded files</p>
<p>It was because it was in the jobID folder, not the '0' folder.</p>
| java | [1] |
4,159,253 | 4,159,254 | PHP Bolding The 'x' Instance of a Variable In a String | <p>Basically I have a variable which contains a few paragraphs of text and I have a variable which I want to make bold within the paragraphs. (By wrapping <code><strong></strong></code> tags around it). The problem is I don't want to make all instances of the word bold, or else I'd just do a str_replace(), I want to be able to wrap the first, second, fourth, whatever instance of this text in the tags, at my own discretion.</p>
<p>I've looked on Google for quite awhile but it's hard to find any results related to this, probably because of my wording..</p>
| php | [2] |
4,690,302 | 4,690,303 | Android: How to use a Android Pad as a customer information Terminal | <p>I want to us an Android-powered Pad as an information terminal for my customers.</p>
<p>The only thing it has to to is to show a HTML5 Webpage.</p>
<p>Therefore,
1. it should not be posiible to show another website (only the local one), should be no problem</p>
<ol>
<li><p>it should be only possible to leave the app with a password (how?)</p></li>
<li><p>and all buttons should be disabled (that´s hard).</p></li>
</ol>
<p>I found out how to set the target for the home button, but maybe there is an existing solution.</p>
<p>Thanks</p>
<p>Christian</p>
| android | [4] |
5,570,173 | 5,570,174 | Methods returning values vs. those which don't | <p>When you write methods you almost always have to check for things that must be valid.</p>
<p>Lets say you need to throw an <code>IllegalArgumentException</code> if the price argument on a method is invalid. Because I want to break my programs into small pieces I make a private method for it. However is it best practice to create a method that is named something like <code>validatePrize</code> and returns a boolean which I then check in an if statement where I invoke the <code>validatePrize</code> method, and then throw an IllegalArgumentException?</p>
<p>Or is it better that the method does not return anything and also throws the exception?</p>
| java | [1] |
481,563 | 481,564 | Variable timestamp might not have been initialized | <p>I have a class with two constructors - one accepts a <code>Date</code> object and the other attempts to create a date object based upon a given timestamp string. The caveat of this is that the conversion to a <code>Date</code> object can throw an exception. I'm getting the 'variable timestamp might not have been initialized' error.</p>
<p>First constructor:</p>
<pre><code>public Visit(Date timestamp) {
this.timestamp = timestamp;
}
</code></pre>
<p>Second constructor (the one that produces the error):</p>
<pre><code>public Visit(String timestamp) {
try {
this.timestamp = dateFormat.parse(timestamp);
} catch (ParseException ex) {
Logger.getLogger(Visit.class.getName()).log(Level.SEVERE, null, ex);
}
}
</code></pre>
<p>I've tried adding the initialization of <code>this.timestamp</code> to the <code>finally</code> statement of the <code>try</code> but this then gives an error that the variable may already have been initialized.</p>
| java | [1] |
1,470,495 | 1,470,496 | How to display popup from code-behind in ASP.net? | <p>I wonder how it would be possible to launch a series of popups, containing a form,
from code-behind.</p>
<p>I possess a list of objects 'Products'</p>
<p>and I wish I could change one property (quantity) of each "product".</p>
<p>Here's how I build my list (normally I use a database).</p>
<pre><code>Private List<Product> listProduct;
listProduits = new List<Product>();
Product objProduit_1 = new Produit;
objProduct_1.ref = "001";
objProduct_1.article = "G900";
objProduct_1.quantity = 30;
listProducts.Add(objProduct_1);
ProductobjProduit_2 = new Product;
objProduct_2.ref = "002";
objProduct_2.article = "G900";
objProduct_2.quantity = 35;
listProduits.Add(objProduct_2);
</code></pre>
<p>And I would like displayed popup one after one.</p>
<p>Thank you in advance for your help</p>
| asp.net | [9] |
4,050,042 | 4,050,043 | c++ trivial try-catch causes abort | <p>the simple code below</p>
<pre><code>// g++ centro.cc -o centro
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
try
{
cout << "Going to throw" << endl;
throw;
}
catch(...)
{
cout << "An exception occurred" << endl;
}
return 0;
}
</code></pre>
<p>produces an abort:</p>
<pre><code>Going to throw
terminate called without an active exception
Aborted (core dumped)
</code></pre>
<p>I don't understand what's wrong, can anybody point me in the right direction?</p>
| c++ | [6] |
1,649,409 | 1,649,410 | Python -- Quotations around filenames | <p>I'm not quite sure when I need to put quotations around the filenames in Python.<br>
For example, when I set</p>
<pre><code>f = open(file)
</code></pre>
<p>I can run something like</p>
<pre><code>len(f.read())
</code></pre>
<p>and it will run fine.
However, when I do it directly, it only works with</p>
<pre><code>len(open("file").read())
</code></pre>
<p>Likewise, in terminal when running from Python I always have to use quotations.<br>
What is the 'rule' when using quotations? </p>
<p>Thank you.</p>
| python | [7] |
4,097,423 | 4,097,424 | JQuery Image and Text Slider | <p>I am working on a project in which I have to implement Image and Text Slider like <a href="http://www.pikachoose.com/" rel="nofollow">this </a>, and <a href="http://galleria.io/" rel="nofollow">this</a>, My structure of slide is like below(this is on one slide)</p>
<pre><code>Question
Image
Answer
</code></pre>
<p>Where Images are optional,sometimes they appear sometimes not,but Questions and Answers are mandatory and on right side I will have Questions like in images are appearing in pikachoose below.</p>
<p>I have seen many sliders but each of those works only on images and not on text :(
Plus I want to implement Play, Pause and Shuffle with separate buttons.
Can anyone suggest some good slider which supports text, Thumbnail navigation and Separate control buttons.</p>
| jquery | [5] |
2,476,716 | 2,476,717 | Java String manipulation | <p>I have a string</p>
<p><code>String a = "/home/eric/workspace/" + file;</code></p>
<p><code>file</code> can be any variable. I'ts a directory. How can i get the <code>/home/eric/workspace/</code> substring from the above?</p>
| java | [1] |
3,671,362 | 3,671,363 | PHP 5.3 and '::' | <p>I started into PHP with 5.3 and am using the '::' to access constants ex; class::const. However, when I try to use my code in an older PHP namely 5.1.6 and 5.2.12, I get an error that the '::' is unexpected.</p>
<p>How do I access constants in these older versions of PHP5?</p>
| php | [2] |
677,268 | 677,269 | Escape hyphen in PHP /mySQL query | <p>The following line throws an error:</p>
<pre><code>$query = "INSERT INTO mail_senders(mailAddress) VALUES ('$_POST[sender-email]')";
</code></pre>
<p>and the problem is the hyphen "-"</p>
<p>I might easily change "-" with "_" but I would like to know if it possible to escape that character for future reference.</p>
<p>Thanks in advance</p>
| php | [2] |
1,787,537 | 1,787,538 | when selecting the datasource it is not showing properly | <p>i am trying to see the datasource that was added previously. but while trying to see..there is not any configure data source option..how to get it.. my screen shot is below.
<img src="http://i.stack.imgur.com/NSaBa.png" alt="enter image description here"></p>
| asp.net | [9] |
1,474,763 | 1,474,764 | How do you delete null objects (not values) from a list | <p>I have objects of a class Choice which are in a list.</p>
<p>Choice looks like this.</p>
<pre><code>public class Choice extends MorphiaModel{
public String name;
public Double price;
}
</code></pre>
<p>Some of them are empty, that is name is "" and price is null.</p>
<p>I want to remove these empty values.</p>
<p>I tried iterating over the list and removing them empty Choice objects, but I got a ConcurrentModificationException then I did this (after implementing equals and hashcode), but it doesn't work, the empty values are still there.</p>
<p>Note: option.choices is a list of Choice objects</p>
<pre><code>Choice emptyChoice = new Choice();
emptyChoice.name = "";
emptyChoice.price = null;
option.choices.remove(emptyChoice);
</code></pre>
| java | [1] |
1,731,400 | 1,731,401 | Black background when rotating image with PHP | <p>I´m trying to rotate a PNG image with PHP. The image rotates but a black background appears.</p>
<p>This is my code:</p>
<pre><code>$image = $_GET['image'];
$degrees = $_GET['degrees'];
header('Content-type: image/png');
$source = imagecreatefrompng($image) ;
$rotate = imagerotate($source, $degrees, 0);
imagesavealpha($rotate, TRUE);
imagepng($rotate);
return rotate;
</code></pre>
| php | [2] |
5,817,950 | 5,817,951 | After removal of a overlay view which method get called | <p>i have a small doubt that how to call a method form one class to other class ,and this method is define in called class .</p>
<p>i wants to use the Protocol class but i don't know how to use this .
so can any one can help me to use the protocol class,with a example </p>
| iphone | [8] |
200,449 | 200,450 | parent:: in instantiated classes | <p>i was wondering why there is no <code>$parent->function();</code> syntax in php, but instead we can use <code>parent::function();</code> which looks like it's used inside a static class. Am i missing some php oop basics?</p>
| php | [2] |
554,556 | 554,557 | Clickable Tooltips with Timeline | <p>im searching now houres on google to find an effect like this: <a href="http://www.wilhelm-manz.de/de/unternehmen" rel="nofollow">tooltip</a> You see there a little timeline in the header with like clickable tooltips. Would anyone help me to create such an effect? I would be very grateful! </p>
| jquery | [5] |
4,553,445 | 4,553,446 | Polygons on Google Maps for WPF application | <p>How to draw polygons on a google map in WPF application using GMAp.Net </p>
| c# | [0] |
541,015 | 541,016 | strlen for two or more strings? | <p>Which is the correct way of making strlen return the lenght of several strings put together.</p>
<p>For example if one string is hello and other is jim it should return: 8. (hello=5 jim=3)</p>
<p>I need to get the combined lenght of $array[0] $array[1] $array[2] $array[3] and $array[4]</p>
<p>Thanks</p>
| php | [2] |
4,675,578 | 4,675,579 | Application config file | <p>My application needs a configuration file. In the order of priority:<br>
1) User should be able to update it by connecting the phone to the pc & select mass storage mode<br>
2) My application needs to be able to read & overwrite<br>
3) I should be able to distribute it with my installer</p>
<p>How can I do this? I checked <a href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow">"Using the External Storage" on this this page</a> but <code>getExternalFilesDir(null).getAbsolutePath()</code> returns <code>/mnt/sdcard/Android/data/com.MyApp/files</code> and I think I cannot put files in that location with installer.</p>
| android | [4] |
1,446,404 | 1,446,405 | Draw and move animation from xml in android | <p>What I want to do:
I want to draw image from xml and then animate it from xml.
this image should move with constant speed anywhere on our screen.</p>
<p>Now the problem is:
I can draw and animate image from xml but i can not move this image with constant speed.</p>
<p>I am using two xml files: One for animate and other for moving.
XML for animation:
android:duration="200"/></p>
<h2></h2>
<p>XML file for move:
</p>
<pre><code><translate
android:interpolator="@android:anim/linear_interpolator"
android:fromXDelta="2%"
android:toXDelta="400%"
android:fromYDelta="2%"
android:toYDelta="800%"/>
</code></pre>
<p></p>
<p>Activity.java file code in onCreate() method:</p>
<pre><code> ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
AnimationDrawable rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
rocketImage.startAnimation(hyperspaceJump);
</code></pre>
| android | [4] |
747,105 | 747,106 | install apk from url | <p>I try to install an apk from an URl, this is my code:</p>
<pre><code> Intent promptInstall = new Intent(android.content.Intent.ACTION_VIEW);
promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
promptInstall.setDataAndType(Uri.parse("http://10.0.2.2:8081/MyAPPStore/apk/Teflouki.apk"), "application/vnd.android.package-archive" );
startActivity(promptInstall);
</code></pre>
<p>But i have this problem:</p>
<pre><code> 05-10 15:09:29.511: ERROR/AndroidRuntime(1668): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://10.0.2.2:8081/MyAPPStore/apk/Teflouki.apk typ=application/vnd.android.package-archive flg=0x10000000 }
</code></pre>
<p>Thanks in advance</p>
| android | [4] |
3,643,646 | 3,643,647 | Progress Dialog in Android | <p>is it possible to add any layout in progress dialog box in android??</p>
| android | [4] |
2,601,233 | 2,601,234 | Python display string multiple times | <p>I want to print a character or string like '-' n number of times.</p>
<p>Can I do it without using a loop?.. Is there a function like</p>
<pre><code>print('-',3)
</code></pre>
<p>..which would mean printing the <code>-</code> 3 times, like this:</p>
<pre><code>---
</code></pre>
| python | [7] |
617,470 | 617,471 | Add values to an associative array in PHP | <p>I want to append an element to to end of an associative array.</p>
<p>For example, my array is </p>
<pre><code>$test=Array ([chemical] => asdasd [chemical_hazards] => ggggg )
</code></pre>
<p>and my result should be </p>
<pre><code>$test=Array ([chemical] => asdasd [chemical_hazards] => ggggg [solution] => good)
</code></pre>
<p>Could you tell me how to implement this?</p>
| php | [2] |
60,831 | 60,832 | Access Page variable from User Control | <p>I have a property on a page called </p>
<pre><code>public string productName { get; set; }
</code></pre>
<p>I want to access this in my usercontrol code behind. What's the right way to do it?</p>
<p>Currently I am doing</p>
<pre><code>((MyPage)Page).productName
</code></pre>
<p>But the user control is not compiling. My pagename is MyPage and I have also added a Reference</p>
<pre><code><%@ Reference VirtualPath="~/MyPage.aspx" %>
</code></pre>
| asp.net | [9] |
1,008,152 | 1,008,153 | jQuery - Wrap div to a specific element | <pre><code><div id="last"></div>
<p id="text">text</p>
<a id="link" href="xxx">link</a>
</code></pre>
<p>Suppose I have the code above, how can I wrap a <code><div></div></code> to the a element, and insert it after div element, the result should be:</p>
<pre><code><div id="last"></div>
<div><a id="link" href="xxx">link</a></div>
<p id="text">text</p>
</code></pre>
<p>Tried the code below, but not works</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</head>
<body>
<div id="last"></div>
<p id="text">text</p>
<a id="link" href="xxx">link</a>
<script>
$('#link').wrap('<div></div>').detach().insertAfter('#last');
</script>
</body>
</html>
</code></pre>
<p>Thanks you</p>
| jquery | [5] |
567,440 | 567,441 | how to show progress bar moving from one activity to another activity in android | <p>I want to show progress bar to going from one activity to another activity until another activity is loaded can anybody give example</p>
<p>Thanks</p>
| android | [4] |
1,492,128 | 1,492,129 | javascript highlight a string | <p><code>var str = 'test TEST';</code></p>
<p>How to get <code>str</code> = '<code><span class="red">test</span> <span class="red">TEST</span></code>' in return.</p>
<p>Thanks a lot.</p>
<p>=============The correct answer=================</p>
<p>Idea from <code>Tim Down</code></p>
<pre><code>var highlighted = str.replace(/(test)/gi, '<span class="red">$1</span>');
</code></pre>
<p><code><span class="red">test</span> <span class="red">TEST</span></code></p>
| javascript | [3] |
4,840,491 | 4,840,492 | Return a random word from a word list in python | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random() * len(file))],
</code></pre>
| python | [7] |
4,569,277 | 4,569,278 | jQuery - Add ID instead of Class | <p>I'm using the current <a href="http://en.wikipedia.org/wiki/JQuery" rel="nofollow">jQuery</a>:</p>
<pre><code>$(function() {
$('span .breadcrumb').each(function(){
$('#nav').addClass($(this).text());
$('#container').addClass($(this).text());
$('.stretch_footer').addClass($(this).text())
$('#footer').addClass($(this).text());
});
});
</code></pre>
<p>It applies the text held in the breadcrumb to 4 elements on the page, allowing me to style specifically to the page there on.</p>
<p>I'd like to try adding an ID instead of a class, how can I achieve this?</p>
| jquery | [5] |
3,277,925 | 3,277,926 | creating error log file in asp.net | <p>To Handle the error in my web application
I am Creating a log file which will be created in Application_Error() event of global.asax
and Those log file created based on date (1 per day)</p>
<p>I am Considering scenario where error occured and at same instance of time
file getting write from multiple users at same time</p>
<p>so it may throw exception that file already being used by another user
it may be like that i am not sure</p>
<p>can anybody help to deal with such scenario</p>
<p>many thanks</p>
| asp.net | [9] |
1,241,726 | 1,241,727 | How to Convert Xml output as String to Key Value pair in PHP | <p>I have this output:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<root>
<disc>SVD1679354</disc>
<cut>18349570</cut>
<previewaac>http://api.7digital.com/1.2/track/preview?trackid=18349570&amp;oauth_consumer_key=7dadeprwudk7&amp;country=GB</previewaac>
<previewmp3>http://api.7digital.com/1.2/track/preview?trackid=18349570&amp;oauth_consumer_key=7dadeprwudk7&amp;country=GB</previewmp3>
<downloadlink></downloadlink>
<codec></codec>
</root>
</code></pre>
<p>I want this string output to be read in key value pair so that I can directly read a particular key to get its value. </p>
<p>The output is stored in string but the string represents an xml.</p>
| php | [2] |
5,301,309 | 5,301,310 | How to add buttons in ContextMenu in Android | <p>I am newbie to androids Apps, guys i have one doubt,Whether is it possible to add buttons(ok,cancel) in the ContextMenu,if so please provide some reference..</p>
<p>Forgive me if i have asked a silly novice question</p>
<p>Thanks a lot in Advance</p>
| android | [4] |
3,722,251 | 3,722,252 | php save prompt | <p>Alright so I have an image the user creates. When they are finished creating the image I have a button appear that says SAVE. What I want to do is prompt the user to save the image on the page on their local disk or where ever they want to put it. I have looked on here and nothing seems to answer this directly. </p>
<p>Thanks in advance.</p>
| php | [2] |
2,319,521 | 2,319,522 | Fast ascii block to integer | <p>Is there any command in stl that converts ascii data to the integer form of its hex representation? such as: "abc" -> 0x616263.</p>
<p>i have the most basic way i can think of: </p>
<pre><code>uint64_t tointeger(std::string){
std::string str = "abc";
uint64_t value = 0; // allow max of 8 chars
for(int x = 0; x < str.size(); x++)
value = (value << 8) + str[x];
return value;
}
</code></pre>
<p>as stated above: <code>tointeger("abc");</code> returns the value <code>0x616263</code></p>
<p>but this is too slow. and because i have to use this function hundreds of thousands of times, it has slowed down my program significantly. there are 4 or 5 functions that rely on this one, and each of those are called thousands of times, in addition to this function being called thousands of times</p>
<p>what is a faster way to do this?</p>
| c++ | [6] |
2,974,220 | 2,974,221 | String.Replace not replacing vbCrlf | <p>I am trying to replace all the occurrences of "\n" in the Text property of an ASP.NET TextBox with <br /> using String.Repalce function, but it doesn't seem to work: </p>
<pre><code>taEmailText.Text.Replace("\n", "<br />")
</code></pre>
<p>As a solution I am using Regex.Replace:</p>
<pre><code>New Regex("\n").Replace(taEmailText.Text, "<br />")
</code></pre>
<p>My question is why String.Replace can't find "\n" for me, even though this solution has been proposed on many sites and it has worked for many people. </p>
<p>Thanks,</p>
| asp.net | [9] |
4,894,209 | 4,894,210 | visualize structure python module | <p>Is there tool out there which can be used to graphically represent the structure of a python module? I'm thinking that a graph of sub-modules and classes connected by arrows representing imports. </p>
| python | [7] |
3,712,770 | 3,712,771 | When are thread local variables freed in C# | <p>In the following code:</p>
<pre><code>public void f()
{
List l1<int> = new List<int>();
List l2<int> = new List<int>();
//.. populate l1 and l2
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
{
// use l1 and l2
// force gc.collect l1 and l2?
}));
//..
}
</code></pre>
<p>l1 and l2 are Thread local very large lists. When do they become eligible for garbage collection? When the thread is done executing the block, do they become eligible?</p>
<p>Is it a good idea to force garbage collection of l1 and l2 when the thread is done with them?</p>
<p>thanks</p>
| c# | [0] |
1,879,447 | 1,879,448 | Posting input form array in another php page | <p>I have this piece of code which permits me to print multiple dates, so this is the form, which gets populated with dates separated by a comma, like 19/02/1990,12/12/1220 etc etc..</p>
<p>Now, what i need to do is to save them in an array and then print the array!</p>
<p>For the moment i have this code, could you please help me?
Thanks!</p>
<pre><code><form action="insert_date.php" method="post">
<div id="with-altField"></div>
<input type="text" id="altField" name="altField">
</div>
<input type="submit" value="Submit" />
</form>
</code></pre>
<p>This doesn't work if i select more than one date, but if i select one, it does, that's why i need to save it in an array form!</p>
<p>insert_date.php</p>
<pre><code><?php
$date=$_POST['altField'];
echo $date;
?>
</code></pre>
| php | [2] |
651,416 | 651,417 | Separate first, middle and last names (Python) | <p>I have a list of several hundred members that I want to separate by First Name, Middle Name and Last name, but some of the members have prefixes (denoted by 'P'). All possible combinations:</p>
<pre><code>First Middle Last
P First Middle Last
First P Middle Last
P First p Middle Last
</code></pre>
<p>How do I separate First (with P, if available), Middle (with P, if available) and Last names in Python? This is what I came up with but it doesn't quite work.</p>
<pre><code>import csv
inPath = "input.txt"
outPath = "output.txt"
newlist = []
file = open(inPath, 'rU')
if file:
for line in file:
member = line.split()
newlist.append(member)
file.close()
else:
print "Error Opening File."
file = open(outPath, 'wb')
if file:
for i in range(len(newlist)):
print i, newlist[i][0] # Should get the First Name with Prefix
print i, newlist[i][1] # Should get the Middle Name with Prefix
print i, newlist[i][-1]
file.close()
else:
print "Error Opening File."
</code></pre>
<p>What I want is:</p>
<ol>
<li>Get first and middles names with their prefixes if available</li>
<li>Output each (first, middle, last) to separate txt files, or a single CSV file (preferable).</li>
</ol>
<p>Many thanks for your help.</p>
| python | [7] |
1,337,897 | 1,337,898 | positions in a list. python | <p>Lets say I have this list:</p>
<pre><code> lst = [[0], [0, 0], [0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0, 0]...]
</code></pre>
<p>how can I add a certain number to each cell according to its position in the lists
for exapmle:
I want to add a formula to each cell by multipying 3 with the position on the list*position in the nested list
so lets say the second cell on the third list will be </p>
<pre><code> 3*3*2
(random number)*(the third nested list)*(second spot on that list)
</code></pre>
<p>so eventually the list will look like that (only for the number 3)</p>
<pre><code> lst = [[3], [6, 12], [9, 18, 27], [12, 24, 36, 48], [15, 30, 45, 60, 75]...]
</code></pre>
<p>anyway this is just an example and Im asking generally about how to apply a certain formula considaring the position of nested list and inner cells in a list.
Its kind of difficult to explain so I hope it came out clear enough.
thank you.</p>
| python | [7] |
604,605 | 604,606 | Below LinearLayout Not Showing? | <p>Only ScrollView is visible?Y so? </p>
<pre><code><?xml version="1.0" encoding="utf-8"?><LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent" android:layout_height="110px">
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="30px"
android:orientation="vertical">
<Button android:text="1" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:text="2" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:text="3" android:id="@+id/Button03"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="30px"
android:orientation="vertical">
<Button android:text="1" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:text="2" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:text="3" android:id="@+id/Button03"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</code></pre>
<p></p>
| android | [4] |
1,838,186 | 1,838,187 | Getting the password from Wordpress to pass back to RemotePost class | <p>Does anyone know how to get the uname and esp the psword from Wordpress to pass into the remotepost.class.php</p>
<p>eg
private $uname = $current_user->user_login;
private $pass = '???';</p>
<p>This is related to this question: <a href="http://stackoverflow.com/questions/2695323/how-to-use-metaweblog-newpost-xmlrpc-api-properly-with-php">http://stackoverflow.com/questions/2695323/how-to-use-metaweblog-newpost-xmlrpc-api-properly-with-php</a></p>
| php | [2] |
851,722 | 851,723 | Value changed when using $.extend() | <p>I am using <code>$.extend()</code> to make a copy of a data set. Most time it works OK. But for some certain data set. The copy would be different from the original one.</p>
<p>For example, the following is the code.</p>
<pre><code>console.log(dataset[key].data)
var dataTemps = $.extend(true, [], dataset[key]);
console.log(dataTemps.data);
</code></pre>
<p>For the first console.log, the log was something like</p>
<pre><code>Array[7]=[1,1, null, "academicreport",330, 22, "M.Sc"]
</code></pre>
<p>But for the second console.log, the log was </p>
<pre><code>Array[7]=[1,1, null, NaN,330, 22, "M.Sc"]
</code></pre>
<p>Does anyone know how the <code>$.extend</code> changed the value of <code>data[3]</code> from <code>"academicreport"</code> to <code>NaN</code>?</p>
| jquery | [5] |
5,205,567 | 5,205,568 | Why doesn't this set comprehension work? | <p>In Python 2.6.5, given this list
mylist = [20, 30, 25, 20]</p>
<p>Why does this set comprehension not work?</p>
<pre><code>>>> {x for x in mylist if mylist.count(x) >= 2}
File "<stdin>", line 1
{x for x in mylist if mylist.count(x) >= 2}
^
SyntaxError: invalid syntax
</code></pre>
<p>Thank you.</p>
| python | [7] |
1,035,777 | 1,035,778 | ArrayAdapter Help? | <p>Hi i want to display a list view in my application. Each row should contains a text and an image. i have used ArrayAdapter to display this, but how to insert an image after the text.Please help ?</p>
<pre><code>String lvr[]={"Android","iPhone","BlackBerry","AndroidPeople"};
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list1 = (ListView) findViewById(R.id.cg_listview1);
list1.setAdapter(new ArrayAdapter<String>(this,R.layout.alerts , lvr));
</code></pre>
<p>Here alerts is my layout contains only textView.</p>
| android | [4] |
2,147,005 | 2,147,006 | How can I do this int to String transformation? | <p>I want to transform an <code>int</code> to a <code>String</code> such that:</p>
<blockquote>
<p>0 -> "a"<br>
1 -> "b"<br>
2 -> "c"<br>
and so on...</p>
</blockquote>
<p>How can I do this?</p>
| java | [1] |
1,593,590 | 1,593,591 | Android app gets stuck when I turn tablet - first timer | <p>I'm first time developer for these types of devices, and UI in general, so I could be missing something basic and obvious.</p>
<p>Everything seems to work fine in the emulator, but I don't know how to simulate turning it.
So I tried running the app on my pandigital (white model - lowest of the low it seems), and each time I turn the Android, it freezes up. At least the UI freezes up, I believe the debug messages are still printing.
This is a home project, I don't have other devices to try it on.</p>
<p>Sorry for being so vague, it's an issue I have been a bit neglecting, trying to work on more interesting issues first, but it's an issue that is bothering me in the back of my mind.</p>
<p>Anyway, I have an Activity that starts up a thread, and creates a class which responds to various events, it implements: MainInterface and SurfaceHolder.Callback. Is there something else I should be handling? possibly?
Is there some specific call I get when the tablet is turned? I'd like to put a debug message in there.</p>
| android | [4] |
3,237,003 | 3,237,004 | Javascript: Run function when onmousedown on any div except one | <p>I need to run function: <code>hideLogin(event)</code> when the user clicks (<code>onmousedown</code> actually) anywhere except </p>
<pre><code><div id="loginForm">
</code></pre>
<p>How can I do this? Thanks</p>
| javascript | [3] |
256,020 | 256,021 | Line numbers and text files Java | <p>I'm studying for my finals and i wondering if there is a particular way of printing out the data of a line in a text file. for example if i had the following in a text file:</p>
<pre><code>11
1c20
203
G2
</code></pre>
<p>I was wondering if there is a way where I input for example 2 ,4 i would get an output 1c20 203 G2. by using two integers start and finish. i have research for this method, but unable to find anything. I understand there is a is a getLineNumber() but i want to use the two Integers.</p>
<p>Thanks in advance!</p>
| java | [1] |
4,195,860 | 4,195,861 | What is best and simple way to get view height except navigation bar? | <p>I want to get height of view except navigation bar. I used below method so far. Is there better way? And isn't it dangerous to hardcode height of navigation bar as 44.0? </p>
<pre><code>CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
viewHeight = screenRect.size.height - 44.0;
</code></pre>
| iphone | [8] |
4,614,540 | 4,614,541 | Unable to select date fom jquery calender | <p>I am using jquery calender with following modifications but unable to select date .please Help i dont want any change in looks .</p>
<pre><code><script>
$(document).ready(function() {
$(".datepicker").datepicker( {
yearRange: '1900:2012',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'dd MM yy',
onClose: function(dateText, inst) {
var day = $("#ui-datepicker-div .ui-datepicker-day :selected").val();
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
},
beforeShow : function(input, inst) {
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length-4, datestr.length);
month = jQuery.inArray(datestr.substring(0, datestr.length-5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
$(this).datepicker('setDate', new Date(year, month, 1));
}
}
});
});
</script>
</code></pre>
| jquery | [5] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.