Unnamed: 0 int64 65 6.03M | Id int64 66 6.03M | Title stringlengths 10 191 | input stringlengths 23 4.18k | output stringclasses 10 values | Tag_Number stringclasses 10 values |
|---|---|---|---|---|---|
4,105,682 | 4,105,683 | Multiple key presses in JavaScript only working in IE | <p>I have the following code:</p>
<pre><code>function handle_paste_keydown(key)
{
if(key.keyCode == 86 && key.ctrlKey) // Ctrl + V
{
alert("Test...");
}
}
</code></pre>
<p>This works in IE, but none of the other browsers. My reason for doing this is that I have finished creating a rich-text editor, but I need to handle the onpaste event carefully because formatted text is able to make it in to my editor, which could pose a minor risk to security, but also butchers my layout if malicious <code><span></code>s and <code><div></code>s make it in.</p>
<p>My current method is to give focus to an off-screen textarea, which means all code will be pasted in to that (which removes formatting); then I immediately grab the textarea.value and insert it at the current caret position in my contentEditable <code><div></code>.</p>
<p>So anyway, how do I get the Ctrl+V to work in all browsers <i>and</i> why doesn't it work in its current state?</p>
<p>Thank you.</p>
| javascript | [3] |
3,949,633 | 3,949,634 | When does jQuery click function need an 'event'? | <p>I had a click function with jquery which didnt work until I added the 'event' (see below). </p>
<p>When is the event needed? This documentation doenst use it: <a href="http://api.jquery.com/click/" rel="nofollow">http://api.jquery.com/click/</a></p>
<p>Didnt work:</p>
<pre><code>$(document).ready(function () {
$('#div a').click(function () {
event.preventDefault();
$('#menu,#wrapper').toggleClass('open');
});
})
</code></pre>
<p>Works:</p>
<pre><code>$(document).ready(function () {
$('#div a').click(function (event) {
event.preventDefault();
$('#menu,#wrapper').toggleClass('open');
});
})
</code></pre>
| jquery | [5] |
3,364,249 | 3,364,250 | How to identify the begin and end of an incoming call in Android? | <p>I'm developing an application which should:</p>
<ul>
<li>Start when incoming call begins.</li>
<li>End as soon as the call has ended.</li>
</ul>
<p>More specifically, I don't want the application to begin while the phone is ringing, but when the actual <strong>conversation</strong> is begins (aka, the user has accepted the incoming call). </p>
<p>Does anyone know how to do this? And how to catch these events?</p>
| android | [4] |
2,568,657 | 2,568,658 | If just the index.php loads as its generic unparsed self, what exactly is [not] happening? | <p>I visited a client's site today, and I'm getting the actual content of their index.php file itself rather than their website. The function of the index.php file says:</p>
<pre><code>This file loads and executes the parser. *
</code></pre>
<p>Assuming this is not happening, what would be some common reasons for that?</p>
| php | [2] |
3,401,422 | 3,401,423 | How to change the text of "More" bar item in a tab bar base iphone application | <p>I faced a problem that I can not find a way to change the text of "More" bar item in the tab bar, just like what I can do on other tab bar items. After searching the forum, I only find a way to change the title of the "More" view pushed by "More" button. Can anyone help me out? Thanks in advance.</p>
<pre><code>UINavigationBar *moreNavigationBar = tabBarController.moreNavigationController.navigationBar;
moreNavigationBar.topItem.title = @"More Features";
</code></pre>
| iphone | [8] |
3,445,175 | 3,445,176 | ListView become black in color whenuser scrolls | <p>I have a ListView on my Android Activity. When i scroll it the background of each text will be black until i click on one of the items. How i can fix it???</p>
<p>my xml file is</p>
<pre><code><ListView android:id="@id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</code></pre>
| android | [4] |
5,611,117 | 5,611,118 | Detecting Audio Input & output devices connected to system | <p>I want to findout how many audio input and output devices connected to my system in C#.net</p>
<p>Please suggest any.</p>
<p>Thanks.</p>
| c# | [0] |
1,535,546 | 1,535,547 | what are the algorithms to use for recognizing objects? | <p>Using Artificial intelligence, what should be the algorithms for recognizing objects??
can Neuural network recognize objects??</p>
| c# | [0] |
5,001,993 | 5,001,994 | T_STRING error even when I don't have any PHP code, just the open close PHP markings | <p>Yes, another one of these T_STRING errors...but hopefully this one is different.</p>
<p>Here is all the code I have on my page:</p>
<pre><code><?php
?>
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
</urlset>
</code></pre>
<p>As you can probably see, I'm trying to do a sitemap for my site. But I didn't put anything on it and I already have a </p>
<pre><code>Parse error: syntax error, unexpected T_STRING in ..../sitemap.php on line 4
</code></pre>
<p>Which points to the end of PHP code marking ?></p>
<p>Any input much appreciated. Thanks.</p>
| php | [2] |
3,727,076 | 3,727,077 | how to read bytes from a video file in android | <p>I have a question that I want to read bytes from video resided in sdcard in chunk size 1024,
means I have to read 1024 bytes from the file at a time. I am able to fetch number of bytes from the video but I can't get it in chunks, I don't know how to achieve this. Please suggest me the right solution regarding the same.</p>
<p>Thanks in advance.</p>
| android | [4] |
1,886,417 | 1,886,418 | Quickest way to clone element and autioincrement id (jquery) | <p>A simple task of cloning an element and autoincrement its id.</p>
<p>can it be done in 1 line?</p>
| jquery | [5] |
1,727,469 | 1,727,470 | Recomendations for books / other resources to learn android real time game dev? | <p>I would like to create my first real time game for the android platform.
I am searching for good resources to get started from, I have little knowledge about game development (just the basic ideas) and would appreciate any helpful websites or books you could recommend.</p>
<p>Thanks,
Jason </p>
| android | [4] |
5,452,693 | 5,452,694 | Using all parameters of a function? I'm confused | <pre><code>DrawBorderBox(55, 20, 200, 50, 4, fontBlack, pDevice );
void Menu::DrawBorderBox( int x, int y, int w, int h, int thickness, D3DCOLOR Colour, LPDIRECT3DDEVICE9 pDevice)
{
//Top horiz line
DrawFilledRect( x, y, w, thickness, Colour, pDevice );
//Left vertical line
DrawFilledRect( x, y, thickness, h, Colour, pDevice );
//right vertical line
DrawFilledRect( (x + w), y, thickness, h, Colour, pDevice );
//bottom horiz line
DrawFilledRect( x, y + h, w+thickness, thickness, Colour, pDevice );
}
void Menu::DrawFilledRect(int x, int y, int w, int h, D3DCOLOR color, LPDIRECT3DDEVICE9 pDevice)
{
//We create our rectangle to draw on screen
D3DRECT BarRect = { x, y, x + w, y + h };
//We clear that portion of the screen and display our rectangle
pDevice->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_TARGET, color, 0, 0);
}
</code></pre>
<p>The values entered into <code>DrawBorderBox</code> are used in <code>BarRect</code>, well the call to <code>DrawFilledRect</code> doesn't use all the parameters? So does <code>BarRect</code> assume <code>h</code>?</p>
<p>So I get (55,20) point 1 and (255,70) point 2? But this says it draws 1 line? I'm confused.</p>
<p>I think thickness is being used as h in BarRect??? I'm I correct?
Which means that it would actually overwrite 4 pixels down of the original square?</p>
| c++ | [6] |
2,851,376 | 2,851,377 | Problem with onListItemClick and clicklisteners | <p>I am trying to create a onListItemClick which will show to the user a dialog with two options. Each option should call a function to execute a certain action. The error i am getting is:</p>
<p>Cannot refer to a non-final variable position inside an inner class defined in a different method</p>
<pre><code> protected void onListItemClick(ListView l, View v, int position, long id){
final CharSequence[] items = {"Delete", "Show"};
MyPOI mpoi= myAdapter.getItem(position);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick an option");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(items[item].equals("Delete")){
dbc.deletePOI(position);
}
}
});
AlertDialog alert = builder.create();
alert.show();
super.onListItemClick(l, v, position, id);
}
</code></pre>
| android | [4] |
5,649,090 | 5,649,091 | c++ to c#'s "As"? | <p>How do I cast a struct to one of its base types?</p>
<p>In c# you can do that with the keyword "as" like <code>Entity as Monster</code>. How can I do this in c++?</p>
<p>This is my structure:</p>
<pre><code>struct Entity
{
USHORT X;
USHORT Y;
UINT Serial;
USHORT SpriteID;
};
struct Monster : Entity
{
UINT UNKNOWN;
BYTE Direction;
USHORT Type;
};
struct Item : Entity
{
BYTE UNKNOWN1;
USHORT UNKNWON2;
};
struct NPC : Entity
{
UINT UNKNOWN1;
BYTE Direction;
BYTE UNKNOWN2;
BYTE NameLength;;
byte Name[];
};
</code></pre>
| c++ | [6] |
4,730,341 | 4,730,342 | Why we should use inverse version of int defined by hex in C# | <p>Quote from <a href="http://www.codeproject.com/Articles/35134/How-to-calculate-CRC-in-C" rel="nofollow">this article</a>:</p>
<blockquote>
<p>In many industries, the first polynomial is in use to create CRC tables and then apply it for performance purposes. The default polynomial, defined by IEEE 802.3 is 0xA001 for 16 bit and 0×04C11DB7 for 32 bit. <strong>We're in C#, thus we should use its inversed version</strong> which is 0×8408 for 16 bit and 0xEDB88320 for 32 bit. We're going to use those polynomials also in our sample.</p>
</blockquote>
<p>Why should we use the inverse version of int defined by hex in C#?<br>
And how did the author of quoted article invert <strong>04C11DB7</strong> to <strong>0xEDB88320</strong>?</p>
<p>Also I've looked into other crc32 C# and C implementations. In all of them C uses 04C11DB7, C# uses 0xEDB88320</p>
| c# | [0] |
2,341,559 | 2,341,560 | Setting a background drawable for a dialog? | <p>Tried posting this at android dev, wanted to go here too in case anyone knows. I'm trying to supply a custom background drawable for a dialog. I've created the following in my styles.xml file:</p>
<pre><code> <style name="CustomDlg" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/my_background</item>
</style>
</code></pre>
<p>This works fine on 1.6+. On my g1 running 1.5 (and the 1.5 emulator) the drawable is used, but the area around the dialog is opaque black instead of being translucent.</p>
<p>Is there something I'm missing here, or is this a bug with 1.5? Any work arounds? Is 1.5 just the ie6 of Android?</p>
<p>Thanks</p>
| android | [4] |
489,555 | 489,556 | Variable getting stuck, won't change | <p>So I have a list of elements like:</p>
<pre><code><span class="rank" id="someID1" user_id="1">Whatever 1</span>
<span class="rank" id="someID2" user_id="2">Whatever 2</span>
<span class="rank" id="someID3" user_id="3">Whatever 3</span>
</code></pre>
<p>And I have a JQuery Selector set up like: </p>
<pre><code>$(".rank").click(function(){
var url = "utilities.php?id=" + $(this).attr("user_id");
$(".rank").editable("save_url", {
loadurl: url, type: "select" });
});
</code></pre>
<p>Now, the issue is that no matter which one I click, the "user_id" is always whatever the first one I click is. It's very frustrating and I don't understand why it's sticking. If If use console.log to check the URL, the id is set properly, but then in the Ajax call it's the first one that I clicked for every one of them.</p>
| jquery | [5] |
3,483,309 | 3,483,310 | Dynamic creating table? | <p>I am writing a code for dynamically creating table in a button click, i Write the code it is working fine, But when i click the button again i want to add the rows to the existing table. Please help me. My code is :</p>
<pre><code>Table table = new Table();
table.ID = "Table1";
Page.Form.Controls.Add(table);
TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID ="t1";
tb.Text = "sasi";
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
table.Rows.Add(row);
</code></pre>
| asp.net | [9] |
1,118,499 | 1,118,500 | How to pop up an alert box when the browser's refresh button is clicked? | <p>If the user refreshes the page in question it will add another record to the database, so I want to warn the user through an alert box if they really want to refresh the page and if they click ok then the page should be refreshed otherwise if they click cancel it won't be.</p>
<p>How to make this type of alert box appear when the browser's refresh button is clicked in a way that is cross browser compatible?</p>
| javascript | [3] |
5,731,757 | 5,731,758 | Java Graphics.drawImage with different source color spaces and image types | <p>I'm trying to overlay a mostly-transparent PNG over a JPEG, and output the result as a JPEG file. I've attached my test input. Here's the code: (edit: FYI, this was translated into Java from Scala, not sure if I missed a syntax error or two, but you should get the idea from the code)</p>
<pre><code>BufferedImage img = new BufferedImage(800, 800, BufferedImage.TYPE_4BYTE_ABGR); //Goes to test.jpg
img.getGraphics.drawImage(source, 0, 0, Color.black, null); //source.jpg
img.getGraphics.drawImage(overlay, 0, 0, 400, 400, Color.black, null); //overlay.png
//First, get the final JPG into memory in a byte array (I use this elsewhere in my actual code)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
FileUtils.writeByteArrayToFile(new File("test.jpg"), bytes);
</code></pre>
<p>Obviously, the output is not what I expected. What am I doing wrong here?
<img src="http://i.stack.imgur.com/iv4Vg.jpg" alt="source.jpg"><img src="http://i.stack.imgur.com/ZNVnJ.png" alt="overlay.png"><img src="http://i.stack.imgur.com/0yRge.jpg" alt="test.jpg"></p>
| java | [1] |
2,641,710 | 2,641,711 | Hide Android "voice to Text" Dialog Box | <p>I am working with an Voice to Text Application where I need to keep Voice command Dialog in background, means I don't want to hide it again n again.</p>
<p>Pls shows me how can I do this.</p>
| android | [4] |
3,246,143 | 3,246,144 | linking events two way | <p>I have the following code:</p>
<pre><code> $('#Element1').event(function() {
$('#Element2').event({ prop: $('#Element1').someMethod() });
});
</code></pre>
<p>Now the Element 2 responds on an Event of Element1 and when Element 1 property changes. How to do it vice-versa in an optimum manner.</p>
| jquery | [5] |
3,244,160 | 3,244,161 | Does python have a "causes_exception()" function? | <p>I have the following code:</p>
<pre><code>def causes_exception(lamb):
try:
lamb()
return False
except:
return True
</code></pre>
<p>I was wondering if it came already in any built-in library?</p>
<p>Ya'ir</p>
<p>Edit: Thx for all the commentary. It's actually impossible to detect whether code causes an exception without running it -- otherwise you could solve the halting problem (raise an exception if the program halts). I just wanted a syntactically clean way to filter a set of identifiers for those where the code didn't except.</p>
| python | [7] |
623,264 | 623,265 | What's the difference between TouchPaint and FingerPaint Android samples? | <p>They both seem rather similar. Is one a newer version of the other? Or does one demonstrate something conceptually different from the other?</p>
| android | [4] |
1,625,118 | 1,625,119 | How to achieve this animatied transition effect when selection changes? | <p>(The title sucks. How to improve?)</p>
<p><img src="http://www.clafy.com/images/mwsnap001.jpg" alt="Animated selection"></p>
<p>In the picture above, there are 5 items. Use gestures to change selected item. During selection changing, there is some kind of animation like the Dock of MacOSX(although not that fancy). After that, the selected item will be in the screen center and in a highlighted mode(like cycling through a series of image).</p>
<p>I don't have a clue to start. Can you give me a hint? Thanks.</p>
| iphone | [8] |
3,100,813 | 3,100,814 | OptionalDataException in java | <pre><code> package com.n;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class S implements Serializable {
private static final long serialVersionUID = 1L;
transient int i;
public static void main(String[] args) throws Exception, IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
"c:\\jav\\f.txt"));
S obj1 = new S(10);
oos.writeInt(obj1.i);
oos.writeObject(obj1);
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"c:\\jav\\f.txt"));
System.out.println("Object contains >> "+ois.readObject());
System.out.println("Transient variable written separately yields >> i= "+ois.readInt());
}
public S(int i) {
this.i = i;
}
@Override
public String toString() {
return "i= " + i;
}
}
</code></pre>
<p>The code above throws</p>
<pre><code> Exception in thread "main" java.io.OptionalDataException
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at com.n.S.main(S.java:27)
</code></pre>
<p>but when i interchange the the output lines like</p>
<pre><code> System.out.println("Transient variable written separately yields >> i= "+ois.readInt());
System.out.println("Object contains >> "+ois.readObject());
</code></pre>
<p>It runs fine. But why is it so and do i have to write as well as read the serialized primitive values 1st and then read or write the object ??? And what is optional data exception???</p>
| java | [1] |
1,241,022 | 1,241,023 | How to sort this jQuery element to this | <p>I want to make id="a" element div to be the second div in the div.b element.
And I want to how to make id="a" element div to be the last div in the div.b element. </p>
<p>Here is the code:</p>
<pre><code><div class='b'>
<div>a</div>
<div>a</div>
<div id="a">I want to moderate this div </div>
<div>a</div>
</div>
</code></pre>
<p>The result I want to achieve is:</p>
<pre><code><div class='b'>
<div>a</div>
<div id="a">I want to moderate this div</div>
<div>a</div>
<div>a</div>
</div>
</code></pre>
<p>And:</p>
<pre><code><div class='b'>
<div>a</div>
<div>a</div>
<div>a</div>
<div id="a">I want to moderate this div</div>
</div>
</code></pre>
| jquery | [5] |
5,449,242 | 5,449,243 | Android - Idle time? | <p>How to know the idle time for an android device?</p>
<p>Idle time is the time where human interaction is last made with the device (touch on screen or keyboard click)</p>
<p>Partial or full code is very much appreciated.</p>
| android | [4] |
3,711,672 | 3,711,673 | mediaplayer dies android | <p>i have a little problem with the media player class. I have a button, and by pressing it a sound will be played. The thing is that there is some delay between when i press the button and when the sound is played, and if i press it too many times the media player dies, and then no sound is played at all and i get the following errors: </p>
<pre><code>ERROR/MediaPlayer(3960): error (-19, 0)
ERROR/AudioTrack(3931): AudioFlinger could not create track, status: -12
ERROR/AudioSink(3931): Unable to create audio track
</code></pre>
<p>Here's the code:</p>
<pre><code>Button b = (Button)findViewById(R.id.button);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AssetFileDescriptor afd;
try {
afd = getAssets().openFd("bassdrum6.mp3");
player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
}
});
</code></pre>
<p>I don't know what's wrong here. I need some help.</p>
<p>Thanks in advance.</p>
| android | [4] |
3,657,564 | 3,657,565 | How to store an audio file into database using Android Sqlite? | <p>I am New to Android. My Requirement is to storing an audio file into database using Android Sqlite. can any one suggest me?</p>
<p>Thanks in advance.</p>
| android | [4] |
4,487,218 | 4,487,219 | Get a copy of a large (160000+ internal object tree) object | <p>Ok, I have a set of very large, identical, trees cached in memory (to be populated with non-identical data [they contain information about stuff inside each node]).</p>
<p>I want to copy a single instance of the tree, and populate each copy with a seperate set of data.</p>
<p>However, at the moment, the cached 'blank' copy of the tree is not being copied, but simply referenced and filled with every single set of data.</p>
<p>How can I force the method that gets the cached blank tree to return a copy of the object, instead of a reference?</p>
| c# | [0] |
4,378,466 | 4,378,467 | C++ - Too Many Initializers for Arrays | <p>I have made an array like this but then it keeps saying I had too many initializers. How can I fix this error?</p>
<pre><code> int people[6][9] = {{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0},
{0,0,0,0,0,0}};
</code></pre>
| c++ | [6] |
1,321,924 | 1,321,925 | When is better to complete a save of Seekbar onProgressChanged vs. onStopTrackingTouch? | <p>I have a Seekbar and I want to save the state to database when the progress is changed. </p>
<p>I am wondering in which event to put my code <a href="http://developer.android.com/intl/fr/reference/android/widget/SeekBar.OnSeekBarChangeListener.html" rel="nofollow">onProgressChanged</a> vs. <a href="http://developer.android.com/intl/fr/reference/android/widget/SeekBar.OnSeekBarChangeListener.html" rel="nofollow">onStopTrackingTouch</a>?</p>
| android | [4] |
1,709,339 | 1,709,340 | How to redirect external links in page like Google using jQuery? | <p>I want to make a redirect for every external link on my page like Google</p>
<p>when u hover the link it shows the real one but when you click it it becomes a redirect page.</p>
<p>Please Help!!</p>
<p>Thanks.</p>
| jquery | [5] |
2,389,749 | 2,389,750 | Base64 encode uploaded file then save in database | <p>I want to base 64 encode uploaded file then save this into Blob type column of a table in MySQL database.</p>
<p>I have tried built in PHP function base64_encode with file variable but this does not seem to work.</p>
<p>Is there a way we can do this?</p>
<p>The reason is that I do not want to use moveuploaded file into a folder.</p>
<p>Thank you.</p>
| php | [2] |
2,992,019 | 2,992,020 | Java: can I have arrays in Hashmaps? | <p>Can I have arrays in Hashmaps ?</p>
<p>If so, what's the exact syntax to declare such hashmap ?</p>
<p>thanks</p>
| java | [1] |
187,074 | 187,075 | How to iterate through multiple select options | <p>i have like 50 select boxes.</p>
<p>I like to understand how I can go through all the select boxes that have ids like select_1 select_2 select 3.</p>
<p>Also, I like to go through all the select list and values that were not selected. </p>
| jquery | [5] |
746,521 | 746,522 | Java: Using scanner to read in boolean values failing. | <pre><code>import java.util.Scanner;
public class Cardhelp2{
private static String[] pairArray={"A,A","K,K","Q,Q","J,J","10,10","9,9","8,8","7,7","6,6","5,5","4,4","3,3","2,2"};
public static void generateRandom(int k){
int minimum = 0;
int maximum = 13;
for(int i = 1; i <= k; i++)
{
int randomNum = minimum + (int)(Math.random()* maximum);
System.out.print("Player " + i +" , You have been dealt a pair of: ");
System.out.println(pairArray[randomNum]);
}
} //reads array and randomizes cards
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("How many players would you like to play with? ");
int m = scan.nextInt();
generateRandom(m);
//displays the cards
___________________________________________________
System.out.println("Would you like to play?");
Scanner scanner = new Scanner(System.in);
if(scanner.next().equalsIgnoreCase("y")||scanner.next().equalsIgnoreCase("yes")) {
System.out.println("This will be fun");
} else if(scanner.next().equalsIgnoreCase("n")||scanner.next().equalsIgnoreCase("no")) {
System.out.println("Maybe next time");
} else {
System.out.println("Invalid character");
}
}
}
</code></pre>
<p>Im having trouble understanding why the end part is not working, I've been told i need to change scanner.next(); to a variable but im not sure how to do it and get the code working. Is there a simple way of reading in the users answer then displaying a response to the user?</p>
<p>Thanks</p>
| java | [1] |
301,350 | 301,351 | python : FTP with TarFile | <p>i have the following code, and i want to know how can supress the error, i tried some google search but with no sucess.</p>
<pre><code>def backup_system(dirs):
""" Funcao para fazer backup das confs do systema """
os.walk("/")
try:
tar = tarfile.open("/home/backup/system/system_backup_%s.tgz" % today, "w:gz")
for dir in system_dirs:
tar.add(dir,recursive=True)
finally:
tar.close()
print tar
ftp_put(tar)
def ftp_put(file):
"""Funcao para fazer upload dos arquivos para FTP"""
conn = ftplib.FTP(ftp_server, backup_user, backup_password)
f = open(file, 'r')
conn.storbinary("STOR ", f)
try:
f = open(file, 'r')
conn.storbinary("STOR ", f)
f.close()
finally:
conn.quit()
</code></pre>
<p>Well, it's ok, except for the fact that this code returns error with the ftplib. It says that expect str, but found tarfile.
Many thanks.</p>
<p>Right, here is the error:</p>
<pre><code>Traceback (most recent call last):
File "/usr/local/bin/backup.py", line 89, in <module>
main()
File "/usr/local/bin/backup.py", line 78, in main
backup_system(system_dirs)
File "/usr/local/bin/backup.py", line 42, in backup_system
ftp_put(tar)
File "/usr/local/bin/backup.py", line 55, in ftp_put
f = open(file, 'rb')
TypeError: coercing to Unicode: need string or buffer, TarFile found
</code></pre>
| python | [7] |
263,077 | 263,078 | New message popup | <p>I currently have a messaging system.
I am looking to make it so that when a user receieves a new message, they get an alert. A popup perhaps? Like a message box saying "you have a new message".</p>
<p>How could I achieve this?
Thanks</p>
| php | [2] |
931,975 | 931,976 | Returning A Custom Object From XMLHttpRequest Object | <p>I am returning an "Employee" object from my javascript ajax call..</p>
<pre><code>var xhReq = new XMLHttpRequest();
xhReq.open("POST", "MobileClientService.svc/REST/TestReturnEmployee", false);
xhReq.send(null);
var serverResponse = xhReq.responseText;
</code></pre>
<p>What is returned is JSON data. I would like to return an Object that has the structure of my Employee object so I could write in javascript..</p>
<pre><code>var name = serverResponse.Name;
</code></pre>
<p>Is this possible to do or is my only choise to parse the returned JSON string? No I cant use jquery (it returns the object fine that way) it must be javascript only.</p>
| javascript | [3] |
3,431,543 | 3,431,544 | Issues when installing the application in iphone | <p>I am developing iPhone applications. I have to use push notification for my iPhone application. For that, I have created new provisioning profiles for my iPhone application. I have configured for APNS. Before installing this profile, the application was working in my device. But after installing the profile, I am getting a message. That is;</p>
<p>Failed to upload "myapps.app".</p>
<p>How to resolve this issue?</p>
| iphone | [8] |
5,569,590 | 5,569,591 | jQuery .change() stops working when I remove a debug alert() | <p>So I have the following code at the moment:</p>
<pre><code><form action="">
<div id="term"><select name="s2" >
<option name="" value="">--Select Term--</option>
</select></div>
<div id="dept"><select name="s3" >
<option name="" value="">--Select Department--</option>
</select></div>
<div id="course"><select id='selCourse' value="">
<option name="" value="">--Select Course--</option>
</select></div>
<div id="sec"><select id='selSec' value="">
<option name="" value="">--Select Section--</option>
</select></div>
</code></pre>
<p> </p>
<pre><code><script>
$('#term').load('fetchcourses.php?');
alert('It Works');
</script>
<script>
$('[name=s2]').change(function() {
$('#dept').load('fetchcourses.php?term='+$(this).val());
});
</script>
</code></pre>
<p>It works as it, however, if I remove the <code>alert('It Works')</code> the code will load the data correctly for the first line, but nothing happens for .change().</p>
<p>I've looked at similar issues on here and other places, and apparently it has to do with asynchronous code? However, I don't really understand what that means, or how to resolve it. Any help is appreciated!</p>
| jquery | [5] |
3,063,265 | 3,063,266 | .each() find the last item and create an if statement | <p>I've got the following jQuery,</p>
<pre><code>function animTweets($tweets) {
$tweets.each(function () {
var $tweet = $(this);
$('#twitterTile').queue('myQueue', function (next) {
$tweet.animate({top: 0, height: 'show'},
{duration: 300,
queue: false,
complete: next
});
}).delay(1E10, 'myQueue');
});
}
</code></pre>
<p>It iterates through items contained in a list ($tweets).</p>
<p>How can I create an <code>if</code> statement so that the last item has a different animation?</p>
| jquery | [5] |
1,169,196 | 1,169,197 | Destroy an Intent? | <p>When I create a Intent:</p>
<pre><code>Intent in = new Intent(this, myclass.class);
this.startActivity(in);
</code></pre>
<p>I create a new Intent but the last Intent is not destroy<br>
It's still in memory<br>
How can I kill this last destroy?</p>
<p>So I want to create two Intents in two different classes:
in the first class I write this:</p>
<pre><code>Intent in1 = new Intent(this, myclass2.class);
this.startActivity(in);
</code></pre>
<p>and in second class I write this:</p>
<pre><code>Intent in2 = new Intent(this, myclass1.class);
this.startActivity(in2);
</code></pre>
<p>but when I Click in1 will create and the in2 will destroy, and when i Click on in2 the in2 will create and in1 will destroy.</p>
<p>a want to clean my phone memory.</p>
| android | [4] |
463,223 | 463,224 | javascript select element | <p>I have a select element like this</p>
<pre><code><select name ="cars">
<option value="frd"> Ford </option>
<option value="hdn"> Holden </option>
<option value="nsn"> Nissan </option>
</select>
</code></pre>
<p>I want to set selected to "Holden" with javascript without selected by value. how can I achieve this?</p>
<p>Thanks in advance</p>
| javascript | [3] |
3,695,865 | 3,695,866 | java.lang.OutOfMemoryError: bitmap size exceeds VM budget? | <p>friends,</p>
<p>i am using following code to display bitmap on screen and having next and previous buttons to change images.</p>
<p>and getting out of memory error</p>
<p><strong>New Code</strong></p>
<pre><code>HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(mImage_URL[val]);
} catch (Exception e) {
return 0;
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
Bitmap bm;
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufHttpEntity.getContent();
try
{
bm = BitmapFactory.decodeStream(is);
}catch(Exception ex)
{
}
is.close();
</code></pre>
<p><strong>Old Code</strong></p>
<pre><code>URL aURL = new URL(mImage_URL[val]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = null;
try
{
is= conn.getInputStream();
}catch(IOException e)
{
}
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
img.setImageBitmap(bm);
</code></pre>
<p>and it was giving me error decoder->decode return false.</p>
<p>on images of size bigger than 400kb.</p>
<p>so after googling i got new code as answer
the old code was not giving me out of memory error on those images but decoder->decode return false, so i choosed new code.</p>
<p>any one guide me what is the solution and which is the best approach to display live images?</p>
| android | [4] |
3,831,314 | 3,831,315 | How to find out extension of a file through its url? | <p>I am trying to find out what extensions a particular url has, Here is what I am trying to do:</p>
<pre><code>$pathinfo = pathinfo('http://imgur.com/9P54j');
$extension = $pathinfo['extension'];
echo $extension;
</code></pre>
<p>The url 'http://imgur.com/9P54j' is actually a url having 9P54j.gif image, and its not evident in the url, how do I extract the extension .gif of the the file '9P54j' ?</p>
| php | [2] |
3,932,088 | 3,932,089 | Java: ArrayLists help, references | <p><strong>Class A:</strong>
Contains a filled arraylist of Employee objects which each contain employeeName and employeeNumber</p>
<p>Is it possible for <strong>Class B</strong> to create a variable that references class A's arraylist of Employee objects? I only need to search that arraylist. Maybe print it. Not change anything in it.</p>
<p>Any strategies or examples of how I could do this?</p>
| java | [1] |
5,332,964 | 5,332,965 | Imports Excel File in GridView (Editing ans searching) | <p>does anyone know how to load an Excel file to a asp.net application? And GriView charged you can edit and search data in GridView?</p>
| asp.net | [9] |
4,451,575 | 4,451,576 | VCRedist - how can I tell if it's been run? | <p>I have an old, old VC++ app that we've ported to VS2005. Our existing users need to get the VC++2005 DLLs, so my app is placing the vcredist_x86.exe on their machines and running it. I check a registry entry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Installations\ which is x86_Microsoft.VC80.MFC blah blah 8.0.50727.762 blah blah...
But... it appears that this doesn't exist on Vista. What is the correct entry to check to make sure that the vcredist ran to completion, so that I don't have to run it again?</p>
<p>Thanks!</p>
| c++ | [6] |
5,554,289 | 5,554,290 | jquery image tooltip | <p>What I'm trying to achieve here is an image tooltip. When I hover over a link, the corresponding image will show up. </p>
<pre><code><html>
<head>
<style type='text/css'>
.tooltipcontent{
position:absolute;
display:none;
opacity:0.0;
}
</style>
<script type='text/javascript' src='jq.js'></script>
<script type='text/javascript'>
$(function(){
$('a').hover(
function(){
var currentimg= $(this).html();
var offset =$('#link1').offset();
$("div img[src='" + currentimg +".jpg']").css('top', offset.top).css('left', offset.left).css('display','block');
$("div img[src='" + currentimg +".jpg']").animate({opacity: 1.0}, 300);
},
function(){}
);
});
</script>
</head>
<body>
<div class='tooltipcontent' id='tooltip1'>
<img src='numone.jpg'></img>
<img src='numtwo.jpg'></img>
</div>
<div id='link1'><a href='numone' target='_blank' id='viewlarger'>numone</a></div>
<div id='link2'><a href='numtwo' target='_blank' id='viewlarger'>numtwo</a></div>
<input type='text' value='a'></input>
<div id='forimage'></div>
</body>
</html>
</code></pre>
| jquery | [5] |
1,325,072 | 1,325,073 | How to update TextView from a class that doesn't extend Activity class | <p>I am New to Android. I am having a tough time with my code.
Here is my problem.
I have a TextView in my MainActivity which extends activity. And this textview has top be updated from another class which extends an Adapter class and implements GestureDetector. </p>
<p>Based on the fling event I am updating my textview. How can i achieve this.</p>
| android | [4] |
3,076,617 | 3,076,618 | Utility activities? | <p>I'm a little confused about the naming conventions used here... but AFAIK it is possible to build an activity(?) that performs some small function than many different programs could use. For example a date-picker tool for use in a calendar or alarm program.</p>
<p>Fist of all I wish to know what these things are called. Where can I see a list of common ones that people expect on their phones pre-installed. And finally is it possible to make and distribute your own?</p>
<p>I had initially thought these things may be called widgets, but having had a look at a few of them, they appear to be complete programs in their own right - so I'm assuming that widget is not the word I'm looking for.</p>
| android | [4] |
1,422,693 | 1,422,694 | Python script to script enter and exit | <p>I am trying to create a python script that on a click of a button opens another python script and closes itself and some return function in the second script to return to the original script hope you can help.</p>
<p>Thanks.</p>
| python | [7] |
5,709,822 | 5,709,823 | Is conversion necessary for integer comparisons in PHP? | <p>Throughout much of the code I review, I often see things such as:</p>
<pre><code>// $myvar could be anything
if (intval($myvar) > 0) {
// do stuff
}
</code></pre>
<p>Or similarly:</p>
<pre><code>if ($myvar != null && intval($myvar) > 0) {
// do stuff
}
</code></pre>
<p>In an ongoing quest to produce more elegant and less-wasteful code, I am wondering if it is necessary to call intval(), for example, when performing a numeric comparison. My understanding from reading the documentation and from various responses here is that when a numeric comparison is asked for, it checks the type of the var and then performs either an integer cast or a string conversion depending on what it finds -- or are these the same as far as PHP is concerned, operations-wise?</p>
<p>Based on that, it seems the least expensive way is to tell PHP to cast it directly as an integer, as such:</p>
<pre><code>if ((int)$myvar > 0) {
// do stuff
}
</code></pre>
<p>However, I almost never see it written that way. Am I missing anything? Does PHP automatically do this any time it seems a comparison operator?</p>
<p>I realize in 99.9% of situations it is sufficient to just perform the comparison and let PHP type juggle on its own, but I see this so often that either I am missing something or many others are!</p>
| php | [2] |
1,445,372 | 1,445,373 | c# search arraylist problem | <p>In my code I have an arraylist, called heart, which contains numbers from 1-13.</p>
<pre><code>heart.Add("any");
for(int i = 0; i < 14; i++)
{
heart.Add(i);
}
</code></pre>
<p>As you can see it also contains "any" placed in the first element. When I use this code to get the all of the elements that has a value over 5 I get an error.</p>
<pre><code>int store = heart.Cast<int>().Where(item => item > 5).Count().ToString();
</code></pre>
<p>I get the error "Specified cast is not valid" and that's because of the
"any" I have in the first element. Could anyone help me fix this?</p>
| c# | [0] |
4,704,371 | 4,704,372 | Loading an application from Eclipse to a real Android device over wifi | <p>I read many articles on how we can launch an Android emulator faster.</p>
<p>I found <a href="http://stackoverflow.com/questions/1554099/slow-android-emulator/2049798#2049798">this SO post</a> where <em>user286101</em> said that he "can load the app over wifi onto the real device in a fraction of the time".</p>
<p>My question is : how can I load an application, from Eclipse, to my real device through wifi ?</p>
<p>Regards.</p>
| android | [4] |
1,684,443 | 1,684,444 | How do I name these php variables | <p>I want to use a forloop to create a number of vars... their names are <code>$var1</code> to <code>$var15</code>. How do I do that? I'm doing <code>$$var.$i</code> but it's not working. </p>
<pre><code>for($i=1; $i <= 15; $i++){
$$var.$i = 'this is the content of var'.$i;
}
</code></pre>
| php | [2] |
2,823,528 | 2,823,529 | styles and theme | <p>I still not understanding the parent role in the android styles I have put my XML code into the style XML which works well. I have been trying to get my head round android styles and I just not getting it. Any help would be great.</p>
<p>ps. I have been reading all about styles on the net. But the information is good but could be a lot better </p>
<p><a href="http://imageshack.us/photo/my-images/843/holo.png/" rel="nofollow">http://imageshack.us/photo/my-images/843/holo.png/</a></p>
| android | [4] |
3,560,200 | 3,560,201 | How can i create dynamic rhythm graph in android | <p>i have to create a dynamic graph in android .... picture is given below..</p>
<p><img src="http://medicineworld.org/images/blogs/heart-rhythm-5580.jpg" alt="alt text"></p>
<p>Please guide me.....</p>
| android | [4] |
5,210,406 | 5,210,407 | In Java why is length a method for Strings, while it is a variable for Arrays? | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="http://stackoverflow.com/questions/8720220/why-is-string-length-a-method">Why is String.length() a method?</a> </p>
</blockquote>
<p>If I want to know the length of an array I will have to type the following:</p>
<pre><code>array.length
</code></pre>
<p>Therefore, it is a variable in which is written the length of the array called 'array'.</p>
<p>On Strings the same thing will look like this:</p>
<pre><code>string.length()
</code></pre>
<p>Therefore, it's a method that returns the length of the 'string' variable.</p>
<p>But why did they choose to make those two different, while it basically does the same thing... Is this because of efficiency or why else?</p>
<p>Thank you in advance.</p>
| java | [1] |
1,586,587 | 1,586,588 | how to call split method on designtime binding value | <p>Hi all
I have a grid with some templatecolumn , now i want to bind to on object property.
one of these property is a string type that i want split it in design time.
my code is here, but i have error. i know my code is wrong. please help me if any one know the right option to do this.</p>
<pre><code> <telerik:GridTemplateColumn DataField="FilePath" UniqueName="FilePath" HeaderText="نام فایل" >
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"FilePath.Split('-').Last();")%>
</ItemTemplate>
</telerik:GridTemplateColumn>
</code></pre>
| asp.net | [9] |
5,326,256 | 5,326,257 | function name as as input of another function? | <p>I an image processing enginner, and am using Python as a prototyping language. </p>
<p>Most of the time, as I get thousands of images, named "imagen.jpg", n being the increment. </p>
<p>So the main structure of my program may be seen as :</p>
<pre><code>def main_IP(imgRoot, stop_ncrement):
name = update_the_increment(imgRoot, stop_increment)
img = load_the_image(name)
out_img = process_image(img)
displays_images(img, out_img)
return out_img
</code></pre>
<p>As you can see it, from one application to another, the only change would be the process_image function.
Is there a way so that the process_image can be inserted as an input? </p>
<p>I would get a generic function, prototyped as :
main_IP(imgRoot, stop_increment, process_image)</p>
<p>Thanks !
Julien</p>
| python | [7] |
2,914,737 | 2,914,738 | How to stop intentservice in android? | <p>Could anyone tell me how to stop <code>intentservice</code> in Android?</p>
<p>If I use <code>stopservice</code> to stop an intentservice, it doesn't work.</p>
<p>I have browsed the website, but nobody has given a clear answer to this question.</p>
| android | [4] |
2,553,808 | 2,553,809 | Opening new window and allowing & sign/ numbers | <p>Goal: when users type in anything in an input box, it will open a new window and append &yuri=0 to it.
<br>
<br>
Current code:
<br></p>
<pre><code> $(function() {
$('.baseUrl').click( function() {
window.location = $(this).attr('href') + $('.appendUrl').val() + '&yuri=0';
return false;
});
});
</code></pre>
<p>The HTML:</p>
<pre><code> <input type="text" class="appendUrl" /><br>
<a href="http://" class="baseUrl">Click Here</a>
</code></pre>
<p><br>
Right now it opens in the same window, and the & and =0 are not showing up properly.<br>
Any insight would be great.</p>
| jquery | [5] |
3,690,534 | 3,690,535 | Extract number from variable | <p>I have this string:</p>
<pre><code>$guid = 'http://www.test.com/?p=34';
</code></pre>
<p>How can I extract the value of get var <code>p</code> (34) from the string and have <code>$guid2 = '34'</code>?</p>
| php | [2] |
1,987,311 | 1,987,312 | jQuery trigger function on change | <p>I have the following two slider functions which work well and display like so:
<img src="http://mpasqualone.com/sliders.png" alt="alt text"></p>
<p>I have diskAmount and transferAmount stored in global vars, however what I am now trying to figure out is how do I get the sum of the two to initially show as the monthly fee, and then update when either of the two sliders are changed.</p>
<p>So in my screenshot above the initial state will be $24.75, and the fee will update if the sliders change.</p>
<p>Can anyone point me in the right direction? I get can the initial fee to show, but can't figure out how to get 1 function to call another function within jQuery.</p>
<pre><code>$(function() {
$("#disk").slider({
value:3,
min: 1,
max: 80,
step: 1,
slide: function(event, ui) {
$("#diskamount").val(ui.value + ' Gb');
$("#diskamountUnit").val('$' + parseFloat(ui.value * diskCost).toFixed(2));
}
});
// Set initial diskamount state
$("#diskamount").val($("#disk").slider("value") + ' Gb');
// Set initial diskamountUnit state
diskAmount = $("#disk").slider("value") * diskCost;
$("#diskamountUnit").val('$' + diskAmount.toFixed(2));
});
$(function() {
$("#data").slider({
value:25,
min: 1,
max: 200,
step: 1,
slide: function(event, ui) {
$("#dataamount").val(ui.value + ' Gb');
$("#dataamountUnit").val('$' + parseFloat(ui.value * transferCost).toFixed(2));
}
});
// Set initial dataamount state
$("#dataamount").val($("#data").slider("value") + ' Gb');
// Set initial dataamountUnit state
transferAmount = $("#data").slider("value") * transferCost;
$("#dataamountUnit").val('$' + transferAmount.toFixed(2));
});
</code></pre>
| jquery | [5] |
2,011,064 | 2,011,065 | how to upload the image taken by calling camera activity from android phone? | <p>hi i have an image which is taken from andorid by calling image _capture
how do i upload it to a windows server?</p>
<pre><code> Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_CANCELED) {
Toast toast = Toast.makeText(this,"camera cancelled", 10000);
toast.show();
return;
}
// lets check if we are really dealing with a picture
if (requestCode == 0 && resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
Bitmap b = (Bitmap) extras.get("data");
//setContentView(R.layout.main);
ImageView mImg;
mImg = (ImageView) findViewById(R.id.head);
mImg.setImageBitmap(b);
// save image to gallery
String timestamp = Long.toString(System.currentTimeMillis());
MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);
}
</code></pre>
| android | [4] |
3,324,692 | 3,324,693 | Fill an actionsheet with an array | <p>I have an actionsheet popup in my iphone application. I would like to fill it with strings from an array instead of predetermined values. </p>
<p>I can't find anything online to do this! Perhaps actionsheet isn't the right thing to use?</p>
<p>Right now this is what I'm using to build it:</p>
<pre><code>roomspopup = [ [ UIActionSheet alloc ]
initWithTitle: alertname
delegate: self
cancelButtonTitle: @"Cancel"
destructiveButtonTitle: nil
otherButtonTitles: @"Kitchen", "Dining Room", nil ];
</code></pre>
<p>But, instead of "Kitchen" and "Dining Room" I'd like it to fill in from an array. The size of the array (i.e. the number of rooms) is not a fixed number.</p>
| iphone | [8] |
5,542,467 | 5,542,468 | Regex checks for a specific string | <p>How can I modify this script so it checks and makes sure it contains the exact string "abc"?</p>
<pre><code>(/^[a].*/i.test(mystring))
</code></pre>
<p>It needs to be case insensitive and take lower and upper caps.</p>
| javascript | [3] |
801,689 | 801,690 | java recommendation algorithm | <p>can you please help me with the following? </p>
<p>Assume we have about 100 movies which are rated by users in a <strong>1-10</strong> scale. Each user has a <em>unique</em> name and rates as many movies as he wants. I want to implement an algorithm that finds out common interests between users. Specifically, when a user presses a ''get Recommendations'' button, the system would search for everyone's else common movies with that user and does the following:<br>
For every movie two users have seen in common, it subtracts the two scores made by these two users for this movie. Then it finds the average of all these subtractions. The smaller this average number is, the more same interests they have. So, let's assume User_A gets the smallest average with User_B. Then, the system should recommend for User_A something that User_B has seen, while User_A hasn't.</p>
<p>Could you give me an idea of how to do that?<br>
Some code snippets would be really helpful but if that's not the case, could you at least tell me what java structures do I need to implement this algorithm? </p>
<p>Thank you..</p>
| java | [1] |
1,392,423 | 1,392,424 | How can I use Jquery show() hide() table rows based on a query string variable? | <p>I have a landing page with several actions. The action are within table rows that are hidden by default and open when a user clicks the action title. I want to control what is shown/hidden based on a query string variable.</p>
<p>For example one of the actions is "Request a call." There are links on other pages of the site to request a call. When a user clicks that link I want them to go to the landing page with the "Request a call" row shown.</p>
| jquery | [5] |
1,254,091 | 1,254,092 | Identifying a random repeating pattern in a structured text string | <p>I have a string that has the following structure:</p>
<p><code>ABC_ABC_PQR_XYZ</code></p>
<p>Where PQR has the structure:</p>
<p><code>ABC+JKL</code></p>
<p>and</p>
<p><code>ABC</code> itself is a string that can contain alphanumeric characters and a few other characters like "_", "-", "+", "." and follows no set structure:</p>
<p>eg.<code>qWe_rtY-asdf</code> or <code>pkl123</code></p>
<p>so, in effect, the string can look like this:</p>
<p><code>qWe_rtY-asdf_qWe_rtY-asdf_qWe_rtY-asdf+JKL_XYZ</code></p>
<p>My goal is to find out what string constitutes <code>ABC</code>.</p>
<p>I was initially just using </p>
<pre><code>$arrString = explode("_",$string);
</code></pre>
<p>to return <code>$arrString[0]</code> before I was made aware that <code>ABC</code> (<code>$arrString[0]</code>) itself can contain underscores, thus rendering it incorrect.</p>
<p>My next attempt was exlpoding it on "_" anyway and then comparing each of the exploded string parts with the first string part until I get a semblance of a pattern:</p>
<pre><code>function getPatternABC($string)
{
$count = 0;
$pattern ="";
$arrString = explode("_", $string);
foreach($arrString as $expString)
{
if(strcmp($expString,$arrString[0])!==0 || $count==0)
{
$pattern = $pattern ."_". $arrString[$count];
$count++;
}
else break;
}
return substr($pattern,1);
}
</code></pre>
<p>This works great - but I wanted to know if there was a more elegant way of doing this using regular expressions?</p>
| php | [2] |
4,967,750 | 4,967,751 | ASP.net Imitate Slow Connection Speed | <p>Our web application is meant to be run on remote locations with very slow internet speed. We are considering various factors to reduce application overheads. This question is only related to see how our application would work on slow bandwidth.</p>
<p>We are still on development, we would like to be able to browse our web application on speed around 32kbps and 128 kbps on an internet browser, preferably firefox.</p>
<p>Is this possible with firefox to browse a website with max "x" speed?</p>
| asp.net | [9] |
2,510,881 | 2,510,882 | Enumerations in C# negative side effects of using a negative number | <p>In a C# enumeration, are there any negative side effects of using a negative number?</p>
<p>I am modelling response codes and one of the codes in negative. This compiles but I want to know if there are any negative side effects to this.</p>
<pre><code>public enum ResponseCodes
{
InvalidServerUserPasswordCombo = -1,
// etc.
}
</code></pre>
| c# | [0] |
4,528,823 | 4,528,824 | Most efficient way to remove non-numeric list entries | <p>I'm looking to 'clean' a list by excluding any items which contain characters other than 0-9, and wondering if there's a more efficient way than e.g.</p>
<pre><code>import re
invalid = re.compile('[^0-9]')
ls = ['1a', 'b3', '1']
cleaned = [i for i in ls if not invalid.search(i)]
print cleaned
>> ['1']
</code></pre>
<p>As I'm going to be operating on large-ish lists (5k items) of long strings (15 chars).</p>
| python | [7] |
2,523,132 | 2,523,133 | How to use multiple URLs in PHP REQUEST_URI statement? | <p>Here is my code...</p>
<pre><code>if($_SERVER['REQUEST_URI'] == '/shop/category/handheld-thermal-imaging/')
{
echo
'<div class="current-mark"></div><div class="top-level"><a href="/shop/category/handheld-thermal-imaging/">HANDHELD<br />THERMAL IMAGING</a></div>';
}
else if($_SERVER['REQUEST_URI'] == '/shop/category/mobile-imaging/')
{
echo
'<div class="current-mark"></div><div class="top-level"><a href="/shop/category/mobile-imaging/">MOBILE IMAGING</a></div>';
}
</code></pre>
<p>Basically this code displays a different left side site navigation depending on which page you're on in the site. It detects what page you're on by the URL of the page by using the PHP REQUEST_URI feature.</p>
<p>My question is this, how can I make the code detect multiple URLs for the same navigation piece?</p>
<p>I tried this code...</p>
<pre><code>if($_SERVER['REQUEST_URI'] == '/shop/category/handheld-thermal-imaging/' , '/shop/iphone-thermal-imaging-adapter/')
{
</code></pre>
<p>But that code doesn't seem to work. Basically all I'm trying to figure out here is how I can use multiple URLs for the REQUEST_URI 'if' statement. Thanks in advance!</p>
| php | [2] |
1,396,996 | 1,396,997 | BackgroundWorker and WebBrowser Control | <p>Is it possible/recommended to use background worker threads with the web browser control?</p>
<p>I am creating a bot that searches google for keywords, then checks for sites in the first 10 pages to see if a site is ranked.</p>
<p>The user can provide a maximum of 20 sites to check, and can use proxies. So ideally I'd like to have 5 threads working at once.</p>
<p>Is it possible? I might have heard somewhere that there are problems with WebBrowser control and threads.</p>
| c# | [0] |
56,908 | 56,909 | jQuery: Unbind event handler | <p>I chose to go with binding element to the body to have them affecting elements even though they are not yet there. Now, I want to unbind some handlers as I go and this is where I am encountering some difficulties. </p>
<p>Code: </p>
<pre><code>$('body').unbind('click', deleteComment); //unbind
$('body').on('click', '.deleteCommentButton > img', deleteComment); //binding
</code></pre>
<p>The question is how I am supposed to unbind it specifically for <code>.deleteComment > img</code>?</p>
| jquery | [5] |
6,929 | 6,930 | How to check if the last column of line in csv file is "True" in a buffered reader | <p>I have a CSV file and I am reading data byte by byte by using buffered stream. I want to ignore reading the line if the last <code>column = "True"</code>. How do I achieve it?</p>
<p>So far I have got:</p>
<pre><code>BufferedStream stream = new BufferedStream(csvFile, 1000);
int byteIn = stream.ReadByte();
while (byteIn != -1 && (char)byteIn != '\n' && (char)byteIn != '\r')
byteIn = stream.ReadByte();
</code></pre>
<p><strong>I want to ignore reading the line if the last column of the line is "True"</strong></p>
| c# | [0] |
5,218,222 | 5,218,223 | Mutex Lock wait time and watchdog | <p>We are measuring a performance scale of multi threaded real time application. I need to write a adapter to measure the time spent on</p>
<ol>
<li>Waiting time for locking the mutex </li>
<li>Time spent between mutex.lock -> mutex.unlock : critical section execution time </li>
</ol>
<p>and also component like locktimer or watchdog timer. If a thread holding a mutex lock for more than a configured time.. Have to notify to error log..</p>
<p>Any best way of doing this..?</p>
| c++ | [6] |
3,609,642 | 3,609,643 | PHP Try Catch Exceptions how does it work | <p>I'm new to try catch in php, and I was playing around with it.</p>
<p>when I try this one, it works fine</p>
<pre><code>try {
if (!$connect)
{
throw new Exception("it's not working");
}
} catch (Exception $e) {
$e->getMessage();
}
</code></pre>
<p>When I try this one, it doesn't work</p>
<pre><code>try {
if (!$connect) {
throw new MyException("it's not working");
}
} catch (MyException $e) {
echo $e->getMessage();
}
</code></pre>
<p>I have only changed the name of the exception, can someone explain where I went wrong pls.
thanks</p>
| php | [2] |
4,140,860 | 4,140,861 | Java Utility Classes and Extension through Inheritance | <p>I have a utility class with some static methods which I use in some places around my code. I am facing a problem now. I want to replace the functions in this utility class in order to provide better implementation. Obviously this cannot be achieved directly without some serious hacking.</p>
<p>My question is: what is the best way to solve this problem. How can someone still use utility classes in such a way that they can still be extended upon. I am thinking around the idea of wrapping the particular utility function for each class that makes use of them so that even if the actual utility method cannot be replaced at least it is possible to replace the class method that calls it. Still, I am curious to know about what are the best practices.</p>
| java | [1] |
793,413 | 793,414 | How to build native web app for iPhone or iPad | <p>I have installed Phonegap and trying to build native web app for iPhone/iPad. But am not getting how to do. i have some knowledge in html,css and javascript. If any one will suggest me how to do if possible with a small example. Thank you.</p>
| iphone | [8] |
1,961,945 | 1,961,946 | How to Downgrade my android application? | <p>In my application i need to run my application of both versions android 2.1 and android 2.2. my application run sucessfully in android 2.2 but it shows error "DTD handler not supported" when i run on 2.1. My build is made in 2.1,but this application only run in
its a web application and i am using sax parser.
please suggest what should to do. its urgent
Thanks in advance.</p>
| android | [4] |
2,593,807 | 2,593,808 | Dynamically adding imageViews onto a linear Layout | <p>I am a newbie in Android. I have a requirement where I have to add the imageViews dynamically onto a linear layout and then have to animate each image individually. </p>
<p>I am not aware of the way to add the imageViews dynamically onto a linear layout. Plz help me out.</p>
<p>Thanks</p>
| android | [4] |
3,362,112 | 3,362,113 | Get a user-defined object in Javascript | <p>I have a script which creates a user-defined object like this:</p>
<pre><code>obj = new Tree();
</code></pre>
<p>This object is always present and interacting with the user.</p>
<p>I want to create a button on the page which, if pressed, should retrieve this object, make some changes to the object and call some methods.</p>
<p>If this were a DOM object, I could have used any of getElementById() or getElementByTagName() etc. However, this object is created in the script and I need to access it in another part on user intervention. Further, making the object global is not an option. Does anybody know how it may be done?</p>
| javascript | [3] |
4,425,965 | 4,425,966 | Javascript content rotator? | <p>I’ve got the basics of a content rotator done, the only problem is it doesn’t loop itself back to the beginning and I cannot figure out why! It is a very simple javascript script:</p>
<pre><code>window.onload = function() { setInterval("transition()", 5000); }
function transition()
{
var y = document.getElementById("featured").getElementsByTagName("li");
for (var i=0;i<y.length;i++)
{
if (y[i].className == "current")
{
y[(i+1)].className = "current";
y[i].className = "";
break;
}
}
}
</code></pre>
<p>It keeps stopping at the end of the list, basically I just want it to loop. Any help?</p>
| javascript | [3] |
618,655 | 618,656 | C++ compile error | <pre><code>#include<string>
using namespace std;
int main(){
const int SIZE=50;
int count=0;
ifstream fin("phoneData.txt");
ofstream fout("phoneList.txt");
string firstName, lastName, phoneNumber;
if (!fin){
cout<<"Error opening file. program ending."<<endl;
return 0;
}
while (count<SIZE && fin>>phoneNumber[count]){
fin.ignore();
getline (fin, firstName[count], '\n');
fin>>lastName[count];
count++;
}
return 0;
</code></pre>
<p>Here is my code so far. in my while loop, something is wrong with the getline, i keep getting an error message like this:</p>
<pre><code>error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files\microsoft visual studio 9.0\vc\include\string(475) : see declaration of 'std::getline'
</code></pre>
<p>please help!!! i can't figure it out!</p>
| c++ | [6] |
3,461,067 | 3,461,068 | declaring the document root when in sub folder | <p>Can anyone help me use the correct way of doing includes. Rather than:
<code>include('header.php');</code></p>
<p>It's a multi page site and i want to add files into other folders for example an Information folder.</p>
<p>In this information folder i have a file called <code>aboutus.php</code> which has includes to the header in the previous directory.</p>
<p>I thought about using the <code>$_SERVER['DOCUMENT_ROOT']</code> method, but it seems a bit bulky and my site is in a sub folder from the root. So I would have to manually hard code the sub directory. Is there an easier way?</p>
| php | [2] |
4,662,833 | 4,662,834 | If vs. while in specific JavaScript code | <p>Why does the author of <em>Test-Driven JavaScript Development</em> (Christian Johansen) use the <code>while</code> statement instead of the <code>if</code> statement in the code below?</p>
<pre><code>function getEventTarget(event) {
var target = event.target || event.srcElement;
while (target && target.nodeType != 1) {
target = target.parentNode;
}
return target;
}
</code></pre>
| javascript | [3] |
3,459,590 | 3,459,591 | Dyanamic Execution of javascript code | <p>I have the following JavaScript: </p>
<pre><code>var djs = function (ob) {
return {
remove: function () { //removes element
if (is_array(ob)) {
for (var i = 0; i < ob.length; i++)
ob[i].parentNode.removeChild(ob[i]);
} else {
ob.parentNode.removeChild(ob);
}
},
empty: function () { //makes element empty
if (is_array(ob)) {
for (var i = 0; i < ob.length; i++)
ob[i].innerHTML = "";
} else {
ob.innerHTML = ""
}
},
html: function (str) { //gets or sets innerHTML
if (str) {
if (is_array(ob)) {
for (var i = 0; i < ob.length; i++)
ob[i].innerHTML = str;
} else {
ob.innerHTML = str;
}
} else {
if (is_array(ob)) {
for (var i = 0; i < ob.length; i++)
rob += ob[i].innerHTML;
return rob;
} else {
return ob.innerHTML;
}
}
}
}
}
</code></pre>
<p>Here every time I am checking whether <code>ob</code> is an array or not and executing code. I want to minimize this, like instead of:</p>
<pre><code>if (is_array(ob)) {
for (var i = 0; i < ob.length; i++)
ob[i].parentNode.removeChild(ob[i]);
} else {
ob.parentNode.removeChild(ob);
}
</code></pre>
<p>I want to use a function like, <code>doEval(ob,code,return)</code>, in this case,</p>
<pre><code>doEval(ob,"parentNode.removeChild("+ob+")",NULL);
</code></pre>
<p>"return" parameter will return if I specify any like <code>innerHTML</code>. Can any one help?</p>
| javascript | [3] |
2,066,295 | 2,066,296 | Array.length problem in JavaScript | <p>I've written this sample code to print the length of x. But for some reason, I am not getting anything! Help! </p>
<pre><code><html>
<head>
<script type = "text/javascript">
function myF()
{
var x = [1,2,3,4];
var y = document.getElementById("thing");
y.innerHtml = x.length;
}
</script>
</head>
<body onload = "myF();" >
<div id = "thing" >
PRINT TEST
</div>
</body>
</html>
</code></pre>
| javascript | [3] |
196,008 | 196,009 | How to get Requirement ID filed value by workitem collection? | <p>i am trying to get the TFS task information through below code but when i am trying to fetch the value of Requirement ID column for a task then it is throwing FieldDefinitionNotExistException exception.</p>
<pre><code> if (teamProjectCollection == null)
{
teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServer));
}
var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
//var project = workItemStore.Projects["SmartPracticeAids"];
string iterationPath = @"SmartPracticeAids\2013 SPA Lite";
string querystring = @"Select [System.Id], [TRTA.Common.RequirementID], [System.Title], [System.AssignedTo], [Microsoft.VSTS.Scheduling.OriginalEstimate], [System.IterationPath], [System.AreaPath], [System.State], [TRTA.Common.AlternateAssignedTo] from WorkItems where [System.TeamProject] = 'SmartPracticeAids' and [System.IterationPath] under '" + iterationPath + "' order by [System.IterationPath], [System.AssignedTo], [System.AreaPath]";
var wiCollection = workItemStore.Query(querystring);
CreateExcelDoc excell_app = new CreateExcelDoc();
CreateHearders(excell_app);
int i = 2;
foreach (WorkItem workItem in wiCollection)
{
foreach (Field item in workItem.Fields)
{
Console.WriteLine(item.Name);
char c = 'A';
excell_app.addData(i, 1, workItem.Id.ToString(), c.ToString() + i, c.ToString() + i, "");
excell_app.addData(i, 2, workItem.Fields["Requirement ID"].OriginalValue.ToString(), c.ToString() + i, c.ToString() + i, "");
excell_app.addData(i, 3, workItem.Title, c.ToString() + i, c.ToString() + i, "");
</code></pre>
| c# | [0] |
370,969 | 370,970 | Jquery division between two numbers | <p>Can you guys please help me in this matter :</p>
<p>I have two variable in jquery x and y , and I am doing a division between those two , and I let's say the result is 2.5 , but I only want to show 2 from 2.5 , how do I do that?</p>
| javascript | [3] |
413,326 | 413,327 | In jQuery, want to remove all HTML inside of a div | <p>I have a div, and I want to remove all the HTML inside of that div.</p>
<p>How can I do this?</p>
| jquery | [5] |
2,531,126 | 2,531,127 | Working with Java | <p>How do I read an array from a text file in java?</p>
| java | [1] |
3,339,418 | 3,339,419 | C# - Best way to handle saving multiple configurations (and accessing data live) | <p>So I've seen many questions that talk about the best method to store settings but haven't really seen any that deal with my situation.</p>
<p>Basically my app today has one settings tab with about 75 options/settings. A user is able to basically have different "copies" of these settings (think: dropdown that when you select it, all 75 options are set to whatever was in that associated .xml file).</p>
<p>Right now I just store settings using XML. The problem is that when my application needs to ACCESS a setting, it is literally accessing the UI directly (checkboxes, etc...)</p>
<p>My question: Should I basically created a "has changed" event for every control, and then update the appropriate setting structure (and only save when the user hits save)?</p>
<p>I'm worried that I shouldn't be accessing the UI directly, and it's doing that today ALL over the app. I want to be sure that my new solution is appropriate/how C# was designed.</p>
<p>Thanks in advance!
~ Josh</p>
| c# | [0] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.