qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
322,070 | <p>I need to query for a list of available Wireless Access points. I only need their SSIDs.</p>
<p>The App is currently .Net CF 2.0, but it's not a problem going with 3.5 if we have to.</p>
| [
{
"answer_id": 322134,
"author": "Quibblesome",
"author_id": 1143,
"author_profile": "https://Stackoverflow.com/users/1143",
"pm_score": 1,
"selected": false,
"text": "Networking.GetAdapters()\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41152/"
] |
322,080 | <p>I need to validate an XML agaist a schema. </p>
<p>I tried XML::SAX::ParserFactory; XML::Validator::Schema and related modules but looks like they are limited.<br>
Limited in the sense that it didn't recognize schema elements such as xsd:unique, xsd:group, xsd:keyref, xsd:union and xsd:key. </p>
<p>Are these xsd:unique, etc. new additions?</p>
<p>Appreciate if you can point me to some Perl modules which are upto date and upto the task.</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 324084,
"author": "draegtun",
"author_id": 12195,
"author_profile": "https://Stackoverflow.com/users/12195",
"pm_score": 3,
"selected": false,
"text": "use XML::LibXML;\nuse XML::LibXML::Schema;\n\nmy $schema = XML::LibXML::Schema->new(location => 'file.xsd' );\nmy $parser = XML::LibXML->new;\n\nmy $xml = 'file.xml';\nmy $doc = $parser->parse_file( $xml );\n\neval { $schema->validate( $doc ) };\ndie $@ if $@;\n\nsay \"$xml is valid\\n\";\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41093/"
] |
322,086 | <p>I was wondering if it is possible to declare an array (size not known at this time), as a private member of a class and later set the size in the constructor of the class. For example:</p>
<pre><code>class Test {
int a[];
public:
Test(int size);
};
Test::Test(int size) {
a[size]; // this is wrong, but what can i do here?
}
</code></pre>
<p>Is this possible or should I use dynamic arrays? Thanks!</p>
| [
{
"answer_id": 322094,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 4,
"selected": false,
"text": "class Test\n{\n std::vector<int> a;\n public:\n Test(std::size_t size):\n a(size)\n {}\n};\n"
},
{
"answer_id": 322095,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 5,
"selected": true,
"text": "class Test { \n int *a;\npublic:\n Test(int size) {\n a = new int[size];\n }\n ~Test() { delete [] a; }\nprivate:\n Test(const Test& other);\n Test& operator=(const Test& other);\n};\n"
},
{
"answer_id": 322096,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 0,
"selected": false,
"text": "std::vector"
},
{
"answer_id": 322105,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "template <int N> class Test {\n int a[N];\npublic:\n Test() { }\n};\n\nTest<5> test;\nTest<40> biggertest;\n"
},
{
"answer_id": 322169,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 2,
"selected": false,
"text": "std::vector"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
322,089 | <p>I've written an experimental function evaluator that allows me to bind simple functions together such that when the variables change, all functions that rely on those variables (and the functions that rely on those functions, etc.) are updated simultaneously. The way I do this is instead of evaluating the function immediately as it's entered in, I store the function. Only when an output value is requested to I evaluate the function, and I evaluate it each and every time an output value is requested.</p>
<p>For example:</p>
<pre><code>pi = 3.14159
rad = 5
area = pi * rad * rad
perim = 2 * pi * rad
</code></pre>
<p>I define 'pi' and 'rad' as variables (well, functions that return a constant), and 'area' and 'perim' as functions. Any time either 'pi' or 'rad' change, I expect the results of 'area' and 'perim' to change in kind. Likewise, if there were any functions depending on 'area' or 'perim', the results of those would change as well.</p>
<p>This is all working as expected. The problem here is when the user introduces recursion - either accidental or intentional. There is no logic in my grammar - it's simply an evaluator - so I can't provide the user with a way to 'break out' of recursion. I'd like to prevent it from happening at all, which means I need a way to detect it and declare the offending input as invalid.</p>
<p>For example:</p>
<pre><code>a = b
b = c
c = a
</code></pre>
<p>Right now evaluating the last line results in a StackOverflowException (while the first two lines evaluate to '0' - an undeclared variable/function is equal to 0). What I would like to do is detect the circular logic situation and forbid the user from inputing such a statement. I want to do this regardless of how deep the circular logic is hidden, but I have no idea how to go about doing so.</p>
<p>Behind the scenes, by the way, input strings are converted to tokens via a simple scanner, then to an abstract syntax tree via a hand-written recursive descent parser, then the AST is evaluated. The language is C#, but I'm not looking for a code solution - logic alone will be fine.</p>
<p>Note: this is a personal project I'm using to learn about how parsers and compilers work, so it's not mission critical - however the knowledge I take away from this I do plan to put to work in real life at some point. Any help you guys can provide would be appreciated greatly. =)</p>
<p>Edit: In case anyone's curious, <a href="http://shadowcoding.blogspot.com/2008/11/recursive-descent-and-grander-ideas.html" rel="nofollow noreferrer">this post on my blog</a> describes why I'm trying to learn this, and what I'm getting out of it.</p>
| [
{
"answer_id": 322103,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 2,
"selected": false,
"text": "a = b"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16942/"
] |
322,098 | <p>Ok, this is working on windows. My Java app is running and functioning normally</p>
<pre><code>javac -classpath .;ojdbc14.jar -g foo.java
java -classpath .;ojdbc14.jar foo
</code></pre>
<p>However, when I do the same thing on Unix I get this error:
ojdbc14.jar: not found</p>
<p>What am I doing wrong? I know the ";" is telling my shell that ojdbc14.jar is a new command, but I'm not sure how to fix this.</p>
| [
{
"answer_id": 322102,
"author": "nsdel",
"author_id": 40807,
"author_profile": "https://Stackoverflow.com/users/40807",
"pm_score": 0,
"selected": false,
"text": "javac -classpath '.;ojdbc14.jar' -g foo.java\njava -classpath '.;ojdbc14.jar' foo\n"
},
{
"answer_id": 322460,
"author": "BIBD",
"author_id": 685,
"author_profile": "https://Stackoverflow.com/users/685",
"pm_score": 2,
"selected": false,
"text": "javac -classpath .:ojdbc14.jar -g foo.java\njava -classpath .:ojdbc14.jar foo\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/685/"
] |
322,107 | <p>I'm working on a java program, and I have several vectors defined and filled (from a file) inside a method. I need to return the contents of all the vectors from the method. I have heard you can put them all in one object to return them. Is that possible, and if so, how? If not, do you have any possible solutions for me? Thanks in advance for your help! </p>
<p>Here is a code snippet:</p>
<pre><code>Object getInventory()
{
Vector<String> itemID=new Vector<String>();
Vector<String> itemName=new Vector<String>();
Vector<Integer> pOrdered=new Vector<Integer>();
Vector<Integer> pInStore=new Vector<Integer>();
Vector<Integer> pSold=new Vector<Integer>();
Vector<Double> manufPrice=new Vector<Double>();
Vector<Double> sellingPrice=new Vector<Double>();
Object inventoryItem=new Object(); //object to store vectors in
try
{
Scanner infile= new Scanner(new FileReader("Ch10Ex16Data.txt"));
int i=0;
while (infile.hasNext())
{
itemID.addElement(infile.next());
itemName.addElement(infile.next()+infile.nextLine());
pOrdered.addElement(infile.nextInt());
pInStore.addElement(pOrdered.elementAt(i));
pSold.addElement(0);
manufPrice.addElement(infile.nextDouble());
sellingPrice.addElement(infile.nextDouble());
i++;
}
infile.close();
System.out.println(itemID);
System.out.println(itemName);
System.out.println(pOrdered);
System.out.println(pInStore);
System.out.println(pSold);
System.out.println(manufPrice);
System.out.println(sellingPrice);
}
catch (Exception f)
{
System.out.print(f);
}
return inventoryItem;
}
</code></pre>
| [
{
"answer_id": 322150,
"author": "Robin",
"author_id": 21925,
"author_profile": "https://Stackoverflow.com/users/21925",
"pm_score": 2,
"selected": false,
"text": "public class Item\n{\n String id;\n String name\n Integer pOrdered; \n Integer inStore;\n :\n :\n"
},
{
"answer_id": 322158,
"author": "Richard Walton",
"author_id": 15075,
"author_profile": "https://Stackoverflow.com/users/15075",
"pm_score": 4,
"selected": true,
"text": "public class Product {\n\n private String itemName;\n private int itemID;\n // etc etc\n\n public Product(String itemName, int itemID) {\n this.itemName = itemName;\n this.itemID = itemID;\n // etc etc\n }\n\n public String getItemName() {\n return itemName;\n }\n\n public int getItemID() {\n return itemID;\n } \n\n // etc etc\n}\n"
},
{
"answer_id": 322161,
"author": "Paul Fisher",
"author_id": 39808,
"author_profile": "https://Stackoverflow.com/users/39808",
"pm_score": 1,
"selected": false,
"text": "InventoryItem"
},
{
"answer_id": 322171,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 2,
"selected": false,
"text": "List<Item> getInventory(File input) throws IOException {\n}\n"
},
{
"answer_id": 322192,
"author": "James",
"author_id": 41039,
"author_profile": "https://Stackoverflow.com/users/41039",
"pm_score": 0,
"selected": false,
"text": "List<Vector<? extends Object>> inventoryItem = new ArrayList<Vector<? extends Object>>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26949/"
] |
322,110 | <p>I'd like to write a script that (under certain conditions) will execute gdb and automatically run some program X with some set of arguments Y. Once the program has finished executing the user should remain at gdb's prompt until s/he explicitly exits it.</p>
<p>One way to do this would be to have the script output the run command plus arguments Y to some file F and then have the script invoke gdb like this:</p>
<pre><code>gdb X < F
</code></pre>
<p>But is there a way to do this without introducing a temporary file?</p>
| [
{
"answer_id": 322120,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "cat F | gdb X"
},
{
"answer_id": 322133,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 6,
"selected": true,
"text": "echo commands | gdb X\n"
},
{
"answer_id": 478112,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 6,
"selected": false,
"text": "X"
},
{
"answer_id": 1123154,
"author": "RandomNickName42",
"author_id": 67819,
"author_profile": "https://Stackoverflow.com/users/67819",
"pm_score": 1,
"selected": false,
"text": "gdb target -e \"my-automation-commands\"\n"
},
{
"answer_id": 2717992,
"author": "mike v",
"author_id": 326453,
"author_profile": "https://Stackoverflow.com/users/326453",
"pm_score": 3,
"selected": false,
"text": "gdb -x gdb_commands exe_file\n"
},
{
"answer_id": 4118923,
"author": "sdaau",
"author_id": 277826,
"author_profile": "https://Stackoverflow.com/users/277826",
"pm_score": 1,
"selected": false,
"text": "bash"
},
{
"answer_id": 10830437,
"author": "selalerer",
"author_id": 481528,
"author_profile": "https://Stackoverflow.com/users/481528",
"pm_score": 1,
"selected": false,
"text": "#!/bin/sh\ngdb X <<GDB_INPUT\npwd\nrun X a b c\nquit\nGDB_INPUT\n"
},
{
"answer_id": 30242671,
"author": "crazy2be",
"author_id": 380725,
"author_profile": "https://Stackoverflow.com/users/380725",
"pm_score": 3,
"selected": false,
"text": "gdb -ex \"target remote localhost:1234\"\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41162/"
] |
322,128 | <p>I think I've declared a Vector with an object correctly. But, I don't know how to access it's members when looping with Iterator.</p>
<p>In my code, the line --->> cout << " " << *Iter;</p>
<p>How do I print the contents of the members? Like *Iter.m_PackLine ???</p>
<p>Not sure if I used the correct terminology, but appreciate the help! Thanks</p>
<pre><code>class CFileInfo
{
public:
std::string m_PackLine;
std::string m_FileDateTime;
int m_NumDownloads;
};
void main()
{
CFileInfo packInfo;
vector<CFileInfo, CFileInfo&> unsortedFiles;
vector<CFileInfo, CFileInfo&>::iterator Iter;
packInfo.m_PackLine = "Sample Line 1";
packInfo.m_FileDateTime = "06/22/2008 04:34";
packInfo.m_NumDownloads = 0;
unsortedFiles.push_back(packInfo);
packInfo.m_PackLine = "Sample Line 2";
packInfo.m_FileDateTime = "12/05/2007 14:54";
packInfo.m_NumDownloads = 1;
unsortedFiles.push_back(packInfo);
for (Iter = unsortedFiles.begin(); Iter != unsortedFiles.end(); Iter++ )
{
cout << " " << *Iter; // !!! THIS IS WHERE I GET STUMPED
// How do I output values of the object members?
}
} // end main
</code></pre>
| [
{
"answer_id": 322139,
"author": "Dave",
"author_id": 40495,
"author_profile": "https://Stackoverflow.com/users/40495",
"pm_score": 1,
"selected": false,
"text": "std::vector"
},
{
"answer_id": 322145,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "CFileInfo &fileInfo = *iter;\ncout << \" \" << fileInfo.myMember;\n"
},
{
"answer_id": 322146,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 1,
"selected": false,
"text": "vector<CFileInfo > unsortedFiles;\n"
},
{
"answer_id": 322148,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 1,
"selected": false,
"text": "iter->m_PackLine\n"
},
{
"answer_id": 322153,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 5,
"selected": true,
"text": "cout << \" \" << *Iter;\n"
},
{
"answer_id": 322296,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 0,
"selected": false,
"text": "vector<CFileInfo, CFileInfo&"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39360/"
] |
322,131 | <p>I'm new to ReSharper and am surprised that there isn't a template defined for</p>
<pre><code>public void MethodName(<params>)
{
}
</code></pre>
<p>I realize I could create one, but I would have thought this would have been part of the standard product. Perhaps I'm missing some other shortcut?</p>
| [
{
"answer_id": 322186,
"author": "Matt Campbell",
"author_id": 41110,
"author_profile": "https://Stackoverflow.com/users/41110",
"pm_score": 4,
"selected": true,
"text": "public void $METHODNAME$($PARAMS$)\n{\n $END$\n}\n"
},
{
"answer_id": 322229,
"author": "Howard Pinsley",
"author_id": 7961,
"author_profile": "https://Stackoverflow.com/users/7961",
"pm_score": 3,
"selected": false,
"text": "private $RETURN_TYPE$ $METHODNAME$($PARAMS$)\n{\n $END$\n}\n"
},
{
"answer_id": 19702058,
"author": "Brains",
"author_id": 2346621,
"author_profile": "https://Stackoverflow.com/users/2346621",
"pm_score": 1,
"selected": false,
"text": "//-----------------------------------------------------------------\nprivate $RETURN_TYPE$ $METHODNAME$($PARAMS$)\n{\n $CLIPBOARD$\n $END$\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7961/"
] |
322,144 | <p>I have recently started exploring Maven, but I feel a bit overwhelmed of all xml configuration in all the pom files. Are there any good tools i can use?</p>
| [
{
"answer_id": 353814,
"author": "Air",
"author_id": 44437,
"author_profile": "https://Stackoverflow.com/users/44437",
"pm_score": 3,
"selected": false,
"text": "<project\n xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11429/"
] |
322,147 | <p>Here's another problem with qt:
I extend a QAbstractTableModel, but I get a compiling error ( I'm using cmake)</p>
<pre><code>// file.h
#ifndef TABLEMODEL_H
#define TABLEMODEL_H
#include <QAbstractTableModel>
class TableModel : public QAbstractTableModel
{
Q_OBJECT
public:
TableModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
};
#endif
// file.c
#include "tableModel.h"
TableModel::TableModel(QObject *parent)
: QAbstractTableModel(parent){}
int TableModel::rowCount(const QModelIndex & ) const
{ return 1; }
int TableModel::columnCount(const QModelIndex & ) const
{ return 1;}
</code></pre>
<p>when I compile I get:</p>
<p>In function <code>TableModel':
/partd/unusedsvn/unusedpkg/iface/tableModel.cpp:4: undefined reference to</code>vtable for TableModel'
/partd/unusedsvn/unusedpkg/iface/tableModel.cpp:4: undefined reference to <code>vtable for TableModel'
collect2: ld returned 1 exit status</code></p>
<p>does anybody got the same trouble??</p>
| [
{
"answer_id": 333817,
"author": "JuanDeLosMuertos",
"author_id": 39339,
"author_profile": "https://Stackoverflow.com/users/39339",
"pm_score": 1,
"selected": true,
"text": "set(tutorial_SRCS app.cpp mainWin.cpp tableModel.cpp)\n"
},
{
"answer_id": 50335897,
"author": "Octoslav",
"author_id": 4420076,
"author_profile": "https://Stackoverflow.com/users/4420076",
"pm_score": -1,
"selected": false,
"text": "class TableModel : public QAbstractTableModel\n{\npublic:\n TableModel(QObject *parent = 0);\n // Some overrided functions\n int rowCount(const QModelIndex &parent = QModelIndex()) const override;\n int columnCount(const QModelIndex &parent = QModelIndex()) const override;\n QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;\n};\n\nclass TableModelController : public QObject\n{\nQ_OBJECT\npublic:\n explicit TableModelController(QObject *parent = nullptr);\n TableModelController(TableModel *m, QObject *parent = nullptr);\n\n TableModel *getModel() {\n return model;\n }\n\npublic slots:\n void addRow();\n void deleteRows();\nprivate:\n TableModel *model;\n};\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39339/"
] |
322,155 | <p>The top of my <code>web.xml</code> file looks like this:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">
</code></pre>
<p>But I still get the warning from Eclipse (Ganymede) that no XML schema is detected, and schema violations are not being warned about. Other XML files in my project (<a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="noreferrer">Spring Framework</a> configuration files for example) don't have the warning and do give correct warnings about schema violations.</p>
<p>How do I get the schema checking working and hopefully the warning to go away? The server does run correctly. It just appears to be an IDE issue.</p>
| [
{
"answer_id": 322185,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 6,
"selected": true,
"text": "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\n"
},
{
"answer_id": 1608977,
"author": "PHP-Rocks",
"author_id": 194795,
"author_profile": "https://Stackoverflow.com/users/194795",
"pm_score": -1,
"selected": false,
"text": "<!DOCTYPE ...>"
},
{
"answer_id": 10859104,
"author": "eckes",
"author_id": 13189,
"author_profile": "https://Stackoverflow.com/users/13189",
"pm_score": 2,
"selected": false,
"text": "xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee \n http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd\"\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409/"
] |
322,173 | <p>I have some Perl code that runs fine outside the debugger:</p>
<pre><code>% perl somefile.pl
</code></pre>
<p>but when I run it inside the debugger:</p>
<pre><code>% perl -d somefile.pl
</code></pre>
<p>it behaves differently.</p>
<p>The files in question (there are several) are part of the test suite for a large Perl module (~20K lines of code). The tests do a lot of setup work at compile time and use BEGIN blocks. Here's some minimal reproduction code:</p>
<pre><code>BEGIN
{
package MyEx;
sub new { bless {}, shift }
package main;
eval { die MyEx->new };
if($@)
{
die "Really die" unless($@->isa('MyEx'));
}
}
print "OK\n";
</code></pre>
<p>If you put that in <code>somefile.pl</code> and run it, it prints "OK" as expected. If you run it in the debugger with <code>perl -d somefile.pl</code>, it dies with this error:</p>
<pre><code>Can't call method "isa" without a package or object reference ...
</code></pre>
<p>The upshot is that <code>$@</code> is not an object when the code runs under the debugger. Instead, it's an unblessed scalar containing this string:</p>
<pre><code>" at somefile.pl line 9
eval {...} called at somefile.pl line 9
main::BEGIN() called at somefile.pl line 16
eval {...} called at somefile.pl line 16
"
</code></pre>
<p>(Internal newlines and spacing preserved. That's the literal text, even the "..."s.)</p>
<p>I need code like this to run in the debugger. Using the debugger in the test suite is an important part of my workflow. The module uses exception objects and does a lot of stuff at compile time and expects an object thrown to be an object when caught.</p>
<p>My question (finally) is this: How can I get this to work? Is there a workaround? Is this a bug in the perl debugger module? What's the best way to go about getting this resolved? (I know that's several questions, but they're all related.)</p>
<p>I'm using perl 5.10.0 on Mac OS X 10.5.5.</p>
<hr>
<p>The dieLevel thing suggested by Adam Bellaire looked promising, and indeed something (can't find out what) is setting it to 1 for me. But I set it to 0 using a <code>~/.perldb</code> file and the problem persists. In fact, I set all three of the related settings to 0. My <code>~/.perldb</code> file:</p>
<pre><code>parse_options('dieLevel=0 warnLevel=0 signalLevel=0');
</code></pre>
<p>I confirmed that the settings are in effect by running the <code>o</code> command in the debugger. I see them all set to 0 when I run <code>perl -de 0</code> and also when running the actual <code>somefile.pl</code> file.</p>
<hr>
<p>Thanks, brian. I used <code>perlbug</code> to file a bug (<a href="http://rt.perl.org/rt3/Ticket/Display.html?id=60890" rel="nofollow noreferrer">RT 60890</a>) and I've begun to sprinkle <code>local $SIG{'__DIE__'}</code> in all the appropriate places in my code. (I also noted in the bug that <code>perldoc perldebug</code> still seems to imply that the default <code>dieLevel</code> is 0.)</p>
| [
{
"answer_id": 322214,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 2,
"selected": false,
"text": "PERLDB_OPTS"
},
{
"answer_id": 322466,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 3,
"selected": false,
"text": "local"
},
{
"answer_id": 323788,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 5,
"selected": true,
"text": "__DIE__"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/164/"
] |
322,190 | <p>With ASP.NET 3.5 I can easily bind to an XML file by using an <code>XmlDataSource</code>.</p>
<p>How can I bind to an XML <em>string</em> instead of a <em>file</em>?</p>
| [
{
"answer_id": 322223,
"author": "Oppositional",
"author_id": 2029,
"author_profile": "https://Stackoverflow.com/users/2029",
"pm_score": 3,
"selected": true,
"text": "XmlDataSource dataSource = new XmlDataSource();\ndataSource.Data = \"<root><element>Item #1</element><element>Item #2</element></root>\";\ndataSource.XPath = \"root/element\";\ndataSource.DataBind();\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35061/"
] |
322,208 | <p>I'm reviewing some Spring code, and I see a few bean defs that do not have an id or a name.
The person who did it is not around to ask.
The application is working fine.
I am not familiar what this necessarily means.
Anybody know if this means anything in particular?</p>
| [
{
"answer_id": 322246,
"author": "Jacob Mattison",
"author_id": 1237,
"author_profile": "https://Stackoverflow.com/users/1237",
"pm_score": 3,
"selected": false,
"text": "<bean id=\"foo\" class=\"Foo\">\n <property name=\"bar\">\n <bean class=\"Bar\">\n </property>\n</bean>\n"
},
{
"answer_id": 325071,
"author": "Spencer Kormos",
"author_id": 8528,
"author_profile": "https://Stackoverflow.com/users/8528",
"pm_score": 6,
"selected": true,
"text": "<bean class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">\n <property name=\"location\" value=\"myapp.properties\" />\n</bean>\n"
},
{
"answer_id": 17639985,
"author": "Jarek Krochmalski",
"author_id": 962431,
"author_profile": "https://Stackoverflow.com/users/962431",
"pm_score": 1,
"selected": false,
"text": "<bean class=\"pl.finsys.initOrder.TestBeanImpl\">\n"
},
{
"answer_id": 23136753,
"author": "Krishna",
"author_id": 3545799,
"author_profile": "https://Stackoverflow.com/users/3545799",
"pm_score": 1,
"selected": false,
"text": "<bean class=\"com.ds.DemoBean\">\n <property name=\"msg\" value=\"Hello\"/>\n</bean>"
},
{
"answer_id": 43045306,
"author": "Tomasz Radziszewski",
"author_id": 7721712,
"author_profile": "https://Stackoverflow.com/users/7721712",
"pm_score": 0,
"selected": false,
"text": "No qualifying bean of type [your.class.Name] is defined: expected single matching bean but found 4\n"
},
{
"answer_id": 54127513,
"author": "swaroop",
"author_id": 3519301,
"author_profile": "https://Stackoverflow.com/users/3519301",
"pm_score": 2,
"selected": false,
"text": "<bean class=\"com.package.name.TestBean\">"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13143/"
] |
322,212 | <p>I'm starting my adventure with Ruby on Rails and as IDE I choose Netbeans. It has bundled server Webrick and it had worked good. But after some changes in my first application it gives me internal error 500 - but nothing shows in console. And older actions give the same result.</p>
<p>How can I find where the problem is?
I work on Ubuntu system.</p>
| [
{
"answer_id": 330804,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 1,
"selected": false,
"text": "tail -f log/development.log\n"
},
{
"answer_id": 335247,
"author": "Sebastian",
"author_id": 29909,
"author_profile": "https://Stackoverflow.com/users/29909",
"pm_score": 1,
"selected": true,
"text": "ActiveRecord::Base.logger = Logger.new(STDOUT)\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33093/"
] |
322,218 | <p>How can I modify the PDF document properties programmatically using .NET code?</p>
<p>I have purchased a number of eBooks in PDF format and unfortunately the publishers have not set the Title, Author and Subject properties. You can see this on a document by accessing the file Properties dialog and selecting the PDF tab. This is a real pain when attempting to use the PDF eBook on an eReader device.</p>
<p>I don't want to have to purchase a full PDF Writer product to do this so I'm hoping someone can point me to a simple free library that I can use to modify the properties programmatically.</p>
<p>If no .NET library is available I'd appreciate any other technique.</p>
| [
{
"answer_id": 322565,
"author": "Martin Hollingsworth",
"author_id": 29491,
"author_profile": "https://Stackoverflow.com/users/29491",
"pm_score": 3,
"selected": false,
"text": " using System.Diagnostics;\n using iTextSharp.text.pdf;\n using System.IO;\n using System.Collections;\n\n PdfReader pdfReader = new PdfReader(filePath);\n using (FileStream fileStream = new FileStream(newFilePath, FileMode.Create, FileAccess.Write))\n {\n string title = pdfReader.Info[\"Title\"] as string;\n Trace.WriteLine(\"Existing title: \" + title);\n\n PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);\n\n // The info property returns a copy of the internal HashTable\n Hashtable newInfo = pdfReader.Info;\n\n newInfo[\"Title\"] = \"New title\";\n\n pdfStamper.MoreInfo = newInfo;\n\n pdfReader.Close();\n pdfStamper.Close();\n }\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29491/"
] |
322,225 | <p>I have a requirement to send some 100 bytes data over internet .My machine is connected to internet.
I can do this with HTTP by sending requests and receiving responses.
But my requirement is just to send data not receive response.
I am thinking of doing this using UDP Client server program. But to do that I need to host UDP client on internet?</p>
<p>Is there any other way to do that?</p>
<p>any suggestions?</p>
| [
{
"answer_id": 322297,
"author": "call me Steve",
"author_id": 24334,
"author_profile": "https://Stackoverflow.com/users/24334",
"pm_score": 3,
"selected": true,
"text": "C:\\Windows\\system32>ping -n 1 -l 100 -4 google.com\n\nPinging google.com [209.85.171.99] with 100 bytes of data:\nReply from 209.85.171.99: bytes=56 (sent 100) time=174ms TTL=233\n\nPing statistics for 209.85.171.99:\n Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),\nApproximate round trip times in milli-seconds:\n Minimum = 174ms, Maximum = 174ms, Average = 174ms\n"
},
{
"answer_id": 322586,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 1,
"selected": false,
"text": "import socket\ndata = 100*'x'\naddress = ('192.168.0.123', 8080) # Host, port\nsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP \nsock.connect(address)\nsock.send(data)\nsock.close()\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33411/"
] |
322,254 | <p>I have a backup script that runs in the background daily on my linux (Fedora 9) computer. If the computer is shut down while the backup is in progress the backup may be damaged so I would like to write a small script that temporarily disables the ability of the user to reboot or shut the computer down. </p>
<p>It is not necessary that the script is uncirumventable, it's just to let the users of the system know that the backup is in progress and they shouldn't shut down. I've seen the Inhibit method on the DBus Free desktop power management spec:
<a href="http://people.freedesktop.org/~hughsient/temp/power-management-spec-0.3.html" rel="noreferrer">http://people.freedesktop.org/~hughsient/temp/power-management-spec-0.3.html</a>
but that only prevents shutdowns if the system is idle not explicitly at the users request.</p>
<p>Is there an easy way to do this in C/Python/Perl or bash?</p>
<p><strong>Update:</strong> To clarify the question above, it's a machine with multiple users, but who use it sequentially via the plugged in keyboard/mouse. I'm not looking for a system that would stop me "hacking" around it as root. But a script that would remind me (or another user) that the backup is still running when I choose shut down from the Gnome/GDM menus </p>
| [
{
"answer_id": 322309,
"author": "brabster",
"author_id": 2362,
"author_profile": "https://Stackoverflow.com/users/2362",
"pm_score": 1,
"selected": false,
"text": "#!/bin/sh\nps -ef|grep backupprocess|grep -v grep > /dev/null\nif [ \"$?\" -eq 0 ]; then\n echo Backup in progress: aborted shutdown\n exit 0\nelse\n echo Backup not in progress: shutting down\n shutdown-alias -h now\nfi\n"
},
{
"answer_id": 36663240,
"author": "reducing activity",
"author_id": 4130619,
"author_profile": "https://Stackoverflow.com/users/4130619",
"pm_score": 0,
"selected": false,
"text": "/etc/polkit-1/localauthority/50-local.d/restrict-login-powermgmt.pkla"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
322,260 | <p><a href="http://tomcat.apache.org/tomcat-5.5-doc/deployer-howto.html" rel="noreferrer">Tomcat documentation</a> says: </p>
<p>The locations for Context Descriptors are;</p>
<p>$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml<br>
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml</p>
<p>On my server, I have at least 3 files floating around:</p>
<pre><code>1 ...tomcat/conf/context.xml
2 ...tomcat/Catalina/localhost/myapp.xml
3 ...tomcat/webapps/myapp/META-INF/context.xml
</code></pre>
<p>What is the order of precedence? </p>
| [
{
"answer_id": 322321,
"author": "James Schek",
"author_id": 17871,
"author_profile": "https://Stackoverflow.com/users/17871",
"pm_score": 0,
"selected": false,
"text": "1 tomcat_home/conf/context.xml\n2 tomcat_home/webapps/myapp/META-INF/context.xml\n"
},
{
"answer_id": 322535,
"author": "netjeff",
"author_id": 41191,
"author_profile": "https://Stackoverflow.com/users/41191",
"pm_score": 6,
"selected": true,
"text": "...tomcat/conf/context.xml\n...tomcat/conf/Catalina/localhost/myapp.xml\n...tomcat/webapps/myapp/META-INF/context.xml\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28351/"
] |
322,294 | <p>What is the command-line equivalent of "Switch Port Client User" as found in the p4win gui client? </p>
<p>I am already logged under one port but now I am attempting to connect to a different port on the same server in order to access a separate source control file depot. I assume it would involve using:</p>
<pre><code>p4 login
</code></pre>
<p>However, reading the 'help' for 'login' does not show an option to specify the port #. Both user name and client name would remain the same but just need to change the port #.</p>
| [
{
"answer_id": 322332,
"author": "Commodore Jaeger",
"author_id": 4659,
"author_profile": "https://Stackoverflow.com/users/4659",
"pm_score": 4,
"selected": true,
"text": "p4 set P4PORT=perforce:1669\n"
},
{
"answer_id": 322365,
"author": "clayless",
"author_id": 37989,
"author_profile": "https://Stackoverflow.com/users/37989",
"pm_score": 2,
"selected": false,
"text": "p4 set P4PORT=1666\n"
},
{
"answer_id": 322497,
"author": "pd.",
"author_id": 19066,
"author_profile": "https://Stackoverflow.com/users/19066",
"pm_score": 2,
"selected": false,
"text": "P4PORT=hostname:1234\n"
},
{
"answer_id": 330805,
"author": "Greg Whitfield",
"author_id": 2102,
"author_profile": "https://Stackoverflow.com/users/2102",
"pm_score": 3,
"selected": false,
"text": "p4 -p <your port> login \n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
322,298 | <p>I'm trying to send an email in html format using JavaMail but it always seems to only display as a text email in Outlook. </p>
<p>Here is my code:</p>
<pre><code>try
{
Properties props = System.getProperties();
props.put("mail.smtp.host", mailserver);
props.put("mail.smtp.from", fromEmail);
props.put("mail.smtp.auth", authentication);
props.put("mail.smtp.port", port);
Session session = Session.getDefaultInstance(props, null);
// -- Create a new message --
MimeMessage message = new MimeMessage(session);
// -- Set the FROM and TO fields --
message.setFrom(new InternetAddress(fromEmail, displayName));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
MimeMultipart content = new MimeMultipart();
MimeBodyPart text = new MimeBodyPart();
MimeBodyPart html = new MimeBodyPart();
text.setText(textBody);
text.setHeader("MIME-Version" , "1.0" );
text.setHeader("Content-Type" , text.getContentType() );
html.setContent(htmlBody, "text/html");
html.setHeader("MIME-Version" , "1.0" );
html.setHeader("Content-Type" , html.getContentType() );
content.addBodyPart(text);
content.addBodyPart(html);
message.setContent( content );
message.setHeader("MIME-Version" , "1.0" );
message.setHeader("Content-Type" , content.getContentType() );
message.setHeader("X-Mailer", "My own custom mailer");
// -- Set the subject --
message.setSubject(subject);
// -- Set some other header information --
message.setSentDate(new Date());
// INFO: only SMTP protocol is supported for now...
Transport transport = session.getTransport("smtp");
transport.connect(mailserver, username, password);
message.saveChanges();
// -- Send the message --
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw e;
}
</code></pre>
<p>Any ideas why the html version of the email won't display in Outlook? </p>
| [
{
"answer_id": 322323,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 2,
"selected": false,
"text": "html.setContent(htmlBody, \"text/html\");\nhtml.setHeader(\"MIME-Version\" , \"1.0\" );\nhtml.setHeader(\"Content-Type\" , html.getContentType() );\n"
},
{
"answer_id": 322416,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 3,
"selected": false,
"text": "html.setHeader(\"Content-Type\", html.getContentType())"
},
{
"answer_id": 324608,
"author": "Stephane Grenier",
"author_id": 39371,
"author_profile": "https://Stackoverflow.com/users/39371",
"pm_score": 5,
"selected": true,
"text": "HtmlEmail email = new HtmlEmail();\n\nemail.setHostName(mailserver);\nemail.setAuthentication(username, password);\nemail.setSmtpPort(port);\nemail.setFrom(fromEmail);\nemail.addTo(to);\nemail.setSubject(subject);\n\nemail.setTextMsg(textBody);\nemail.setHtmlMsg(htmlBody);\n\nemail.setDebug(true);\n\nemail.send();\n"
},
{
"answer_id": 630742,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "message.setContent(sBuffer.toString(), \"text/html\");\n"
},
{
"answer_id": 2049912,
"author": "user225486",
"author_id": 225486,
"author_profile": "https://Stackoverflow.com/users/225486",
"pm_score": 2,
"selected": false,
"text": "message.setContent(new String(sBuffer.toString().getBytes(), \"iso-8859-1\"), \"text/html; charset=\\\"iso-8859-1\\\"\");\n"
},
{
"answer_id": 3706474,
"author": "Kuldeep",
"author_id": 447033,
"author_profile": "https://Stackoverflow.com/users/447033",
"pm_score": 1,
"selected": false,
"text": "message.setContent(new String(sBuffer.toString().getBytes(), \"iso-8859-1\"), \"text/html; charset=iso-8859-1\");\n"
},
{
"answer_id": 12507532,
"author": "AVA",
"author_id": 1143066,
"author_profile": "https://Stackoverflow.com/users/1143066",
"pm_score": 2,
"selected": false,
"text": "mimeBodyPart1.setDataHandler(new DataHandler(new ByteArrayDataSource(messageBody, \"text/html; charset=utf-8\")));\nmultiPart.addBodyPart(mimeBodyPart1);\nmessage.setContent(multiPart, \"text/html; charset=utf-8\");\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39371/"
] |
322,322 | <p>I have an iterator to a map element, and I would like gdb to show me the values of the "first" and "second" elements of that iterator.
For example:</p>
<pre><code>std::map<int,double> aMap;
...fill map...
std::map<int,double>::const_iterator p = aMap.begin();
</code></pre>
<p>I can use p.first and p.second in the code, but can't see them in gdb. For what it's worth, in dbx one could do something like "print p.node.second_", but I can find anything similar in gbd.</p>
<p>I am totally willing to have a function into which I pass the object types, but I've been unable to get that to work either.</p>
<p>Any ideas?
Thanks!</p>
| [
{
"answer_id": 322355,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": false,
"text": "This GDB was configured as \"i686-pc-linux-gnu\"...\n(gdb) list\n1 #include <iostream>\n2 #include <map>\n3\n4 int main()\n5 {\n6 std::map<int, int> a;\n7 a[10] = 9;\n8 std::map<int, int>::iterator it = a.begin();\n9 ++it;\n10 }\n(gdb) b test.cpp:9\nBreakpoint 1 at 0x8048942: file test.cpp, line 9.\n(gdb) r\nStarting program: /home/js/cpp/a.out\n\nBreakpoint 1, main () at test.cpp:9\n9 ++it;\n(gdb) set print pretty on\n(gdb) p it\n$1 = {\n _M_node = 0x94fa008\n}\n(gdb) p *it\n$2 = (class std::pair<const int, int> &) @0x94fa018: {\n first = 10,\n second = 9\n}\n(gdb)\n"
},
{
"answer_id": 322356,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 1,
"selected": false,
"text": "p"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39870/"
] |
322,333 | <p>I've got an NSColor, and I really want the 32-bit RGBA value that it represents. Is there any easy way to get this, besides extracting the float components, then multiplying and ORing and generally doing gross, endian-dependent things?</p>
<p>Edit: Thanks for the help. Really, what I was hoping for was a Cocoa function that already did this, but I'm cool with doing it myself.</p>
| [
{
"answer_id": 322455,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "NSColor *someColor = {whatever};\nuint8_t data[4];\n\nCGContextRef ctx = CGBitmapContextCreate((void*)data, 1, 1, 8, 4, colorSpace, kCGImageAlphaFirst | kCGBitmapByteOrder32Big);\n\nCGContextSetRGBFillColor(ctx, [someColor redComponent], [someColor greenComponent], [someColor blueComponent], [someColor alphaComponent]);\n\nCGContextFillRect(ctx, CGRectMake(0,0,1,1));\n\nCGContextRelease(ctx);\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3830/"
] |
322,361 | <p>In an ActionScript 2 project I can create a new MovieClip, right-click on it on the library and select "Component Definition" to add parameters that can be referenced inside the MovieClip. This parameters can be easily changed in the MovieClips's properties.</p>
<p>Now, I'm working on an ActionScript 3 project but haven't been able to figure out a way to obtain the values passed in those parameters.</p>
<p>I defined a parameter named "textToDisplay" but when I write the following in the Actions for the first frame I get an error:</p>
<pre><code>trace(textToDisplay);
</code></pre>
<p>This is the error:</p>
<pre><code>1120: Access of undefined property textToDisplay.
</code></pre>
<p>Do you know how to capture the value of that parameter?</p>
<p>Thanks</p>
<p>PS: I'm using Adobe Flash CS3 Professional on Windows XP</p>
| [
{
"answer_id": 329564,
"author": "aaaidan",
"author_id": 26331,
"author_profile": "https://Stackoverflow.com/users/26331",
"pm_score": 3,
"selected": true,
"text": "public var"
},
{
"answer_id": 708072,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "addEventListener(Event.INIT, onInit);\n"
},
{
"answer_id": 4354468,
"author": "Yu-Chung Chen",
"author_id": 530547,
"author_profile": "https://Stackoverflow.com/users/530547",
"pm_score": 2,
"selected": false,
"text": "[Inspectable]"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
322,378 | <p>Is there a way to detect if a mouse button is currently down in JavaScript?</p>
<p>I know about the "mousedown" event, but that's not what I need. Some time AFTER the mouse button is pressed, I want to be able to detect if it is still pressed down.</p>
<p>Is this possible?</p>
| [
{
"answer_id": 322630,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "function doStuff() {\n // does something when mouse is down in body for longer than 2 seconds\n}\n\nvar mousedownTimeout;\n\ndocument.body.onmousedown = function() { \n mousedownTimeout = window.setTimeout(doStuff, 2000);\n}\n\ndocument.body.onmouseup = function() {\n window.clearTimeout(mousedownTimeout);\n}\n"
},
{
"answer_id": 322650,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 5,
"selected": false,
"text": "var mouseDown = 0;\ndocument.body.onmousedown = function() { \n mouseDown = 1;\n}\ndocument.body.onmouseup = function() {\n mouseDown = 0;\n}\n"
},
{
"answer_id": 322658,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "var mousedownTimeout,\n mousedown = 0;\n\ndocument.body.onmousedown = function() {\n mousedown = 0; \n window.clearInterval(mousedownTimeout);\n mousedownTimeout = window.setInterval(function() { mousedown += 200 }, 200);\n}\n\ndocument.body.onmouseup = function() {\n mousedown = 0;\n window.clearInterval(mousedownTimeout);\n}\n"
},
{
"answer_id": 322827,
"author": "Eugene Lazutkin",
"author_id": 26394,
"author_profile": "https://Stackoverflow.com/users/26394",
"pm_score": 8,
"selected": true,
"text": "var mouseDown = 0;\ndocument.body.onmousedown = function() { \n ++mouseDown;\n}\ndocument.body.onmouseup = function() {\n --mouseDown;\n}\n"
},
{
"answer_id": 11922780,
"author": "Stanley",
"author_id": 1593517,
"author_profile": "https://Stackoverflow.com/users/1593517",
"pm_score": 2,
"selected": false,
"text": "onmouseup=\"down=0;\" onmousedown=\"down=1;\"\n"
},
{
"answer_id": 17473223,
"author": "user2550945",
"author_id": 2550945,
"author_profile": "https://Stackoverflow.com/users/2550945",
"pm_score": 0,
"selected": false,
"text": " var mousedown = 0;\n $(function(){\n document.onmousedown = function(e){\n mousedown = mousedown | getWindowStyleButton(e);\n e = e || window.event;\n console.log(\"Button: \" + e.button + \" Which: \" + e.which + \" MouseDown: \" + mousedown);\n }\n\n document.onmouseup = function(e){\n mousedown = mousedown ^ getWindowStyleButton(e);\n e = e || window.event;\n console.log(\"Button: \" + e.button + \" Which: \" + e.which + \" MouseDown: \" + mousedown);\n }\n\n document.oncontextmenu = function(e){\n // to suppress oncontextmenu because it blocks\n // a mouseup when two buttons are pressed and \n // the right-mouse button is released before\n // the other button.\n return false;\n }\n });\n\n function getWindowStyleButton(e){\n var button = 0;\n if (e) {\n if (e.button === 0) button = 1;\n else if (e.button === 1) button = 4;\n else if (e.button === 2) button = 2; \n }else if (window.event){\n button = window.event.button;\n }\n return button;\n }\n"
},
{
"answer_id": 20926181,
"author": "David",
"author_id": 553681,
"author_profile": "https://Stackoverflow.com/users/553681",
"pm_score": 2,
"selected": false,
"text": "$(document).mousedown(function(e) {\n mouseDown = true;\n}).mouseup(function(e) {\n mouseDown = false;\n}).mouseleave(function(e) {\n mouseDown = false;\n});\n"
},
{
"answer_id": 31041606,
"author": "Marcin Żurek",
"author_id": 5047253,
"author_profile": "https://Stackoverflow.com/users/5047253",
"pm_score": 0,
"selected": false,
"text": "var clicableArea = {\n init: function () {\n var self = this;\n ('.element').mouseover(function (e) {\n self.handlemouseClick(e, $(this));\n }).mousedown(function (e) {\n self.handlemouseClick(e, $(this));\n });\n },\n handlemouseClick: function (e, element) {\n if (e.buttons === 1) {//left button\n element.css('background', '#f00');\n }\n if (e.buttons === 2) { //right buttom\n element.css('background', 'none');\n }\n }\n};\n$(document).ready(function () {\n clicableArea.init();\n});\n"
},
{
"answer_id": 35213733,
"author": "Martin",
"author_id": 1695049,
"author_profile": "https://Stackoverflow.com/users/1695049",
"pm_score": 3,
"selected": false,
"text": "<style>\n div.myDiv:active {\n cursor: default;\n }\n</style>\n\n<script>\n function handleMove( div ) {\n var style = getComputedStyle( div );\n if (style.getPropertyValue('cursor') == 'default')\n {\n // You're down and moving here!\n }\n }\n</script>\n\n<div class='myDiv' onmousemove='handleMove(this);'>Click and drag me!</div>\n"
},
{
"answer_id": 46316752,
"author": "dreadcast",
"author_id": 1239761,
"author_profile": "https://Stackoverflow.com/users/1239761",
"pm_score": 1,
"selected": false,
"text": "mouseup"
},
{
"answer_id": 47930992,
"author": "Micah Engle-Eshleman",
"author_id": 1546808,
"author_profile": "https://Stackoverflow.com/users/1546808",
"pm_score": 3,
"selected": false,
"text": "addEventListener"
},
{
"answer_id": 48970682,
"author": "Jono Job",
"author_id": 4289902,
"author_profile": "https://Stackoverflow.com/users/4289902",
"pm_score": 6,
"selected": false,
"text": "mousedown"
},
{
"answer_id": 57181125,
"author": "NVRM",
"author_id": 2494754,
"author_profile": "https://Stackoverflow.com/users/2494754",
"pm_score": 2,
"selected": false,
"text": "// Mouse buttons\ndocument.addEventListener('mousedown', e => console.log(e.buttons))\n// Keyboard keys\ndocument.addEventListener('keydown', e => console.log(e.key))"
},
{
"answer_id": 67677092,
"author": "illogicalapple",
"author_id": 15778548,
"author_profile": "https://Stackoverflow.com/users/15778548",
"pm_score": 2,
"selected": false,
"text": ".matches"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12983/"
] |
322,379 | <p>I am about to define an interface in my application that plug-in writers can implement to provide user-defined "export" capabilities. It'll look something like this:</p>
<pre><code>public interface IFooExporter
{
void ExportFoo(Foo foo, string path);
}
</code></pre>
<p>However, I need to let the plug-in writers know (explicitly, not just in documentation) that "path" represents a folder, not a filename. It's their responsibility to create the files as part of the export process.</p>
<p>What's the best way to enforce that a path is a folder and not a filename? My best guess right now is to use DirectoryInfo instead of string:</p>
<pre><code>public interface IFooExporter
{
void ExportFoo(Foo foo, DirectoryInfo folder);
}
</code></pre>
<p>Is that a good solution, or are there pitfalls I'm not aware of with passing DirectoryInfo instances around?</p>
| [
{
"answer_id": 322630,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "function doStuff() {\n // does something when mouse is down in body for longer than 2 seconds\n}\n\nvar mousedownTimeout;\n\ndocument.body.onmousedown = function() { \n mousedownTimeout = window.setTimeout(doStuff, 2000);\n}\n\ndocument.body.onmouseup = function() {\n window.clearTimeout(mousedownTimeout);\n}\n"
},
{
"answer_id": 322650,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 5,
"selected": false,
"text": "var mouseDown = 0;\ndocument.body.onmousedown = function() { \n mouseDown = 1;\n}\ndocument.body.onmouseup = function() {\n mouseDown = 0;\n}\n"
},
{
"answer_id": 322658,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "var mousedownTimeout,\n mousedown = 0;\n\ndocument.body.onmousedown = function() {\n mousedown = 0; \n window.clearInterval(mousedownTimeout);\n mousedownTimeout = window.setInterval(function() { mousedown += 200 }, 200);\n}\n\ndocument.body.onmouseup = function() {\n mousedown = 0;\n window.clearInterval(mousedownTimeout);\n}\n"
},
{
"answer_id": 322827,
"author": "Eugene Lazutkin",
"author_id": 26394,
"author_profile": "https://Stackoverflow.com/users/26394",
"pm_score": 8,
"selected": true,
"text": "var mouseDown = 0;\ndocument.body.onmousedown = function() { \n ++mouseDown;\n}\ndocument.body.onmouseup = function() {\n --mouseDown;\n}\n"
},
{
"answer_id": 11922780,
"author": "Stanley",
"author_id": 1593517,
"author_profile": "https://Stackoverflow.com/users/1593517",
"pm_score": 2,
"selected": false,
"text": "onmouseup=\"down=0;\" onmousedown=\"down=1;\"\n"
},
{
"answer_id": 17473223,
"author": "user2550945",
"author_id": 2550945,
"author_profile": "https://Stackoverflow.com/users/2550945",
"pm_score": 0,
"selected": false,
"text": " var mousedown = 0;\n $(function(){\n document.onmousedown = function(e){\n mousedown = mousedown | getWindowStyleButton(e);\n e = e || window.event;\n console.log(\"Button: \" + e.button + \" Which: \" + e.which + \" MouseDown: \" + mousedown);\n }\n\n document.onmouseup = function(e){\n mousedown = mousedown ^ getWindowStyleButton(e);\n e = e || window.event;\n console.log(\"Button: \" + e.button + \" Which: \" + e.which + \" MouseDown: \" + mousedown);\n }\n\n document.oncontextmenu = function(e){\n // to suppress oncontextmenu because it blocks\n // a mouseup when two buttons are pressed and \n // the right-mouse button is released before\n // the other button.\n return false;\n }\n });\n\n function getWindowStyleButton(e){\n var button = 0;\n if (e) {\n if (e.button === 0) button = 1;\n else if (e.button === 1) button = 4;\n else if (e.button === 2) button = 2; \n }else if (window.event){\n button = window.event.button;\n }\n return button;\n }\n"
},
{
"answer_id": 20926181,
"author": "David",
"author_id": 553681,
"author_profile": "https://Stackoverflow.com/users/553681",
"pm_score": 2,
"selected": false,
"text": "$(document).mousedown(function(e) {\n mouseDown = true;\n}).mouseup(function(e) {\n mouseDown = false;\n}).mouseleave(function(e) {\n mouseDown = false;\n});\n"
},
{
"answer_id": 31041606,
"author": "Marcin Żurek",
"author_id": 5047253,
"author_profile": "https://Stackoverflow.com/users/5047253",
"pm_score": 0,
"selected": false,
"text": "var clicableArea = {\n init: function () {\n var self = this;\n ('.element').mouseover(function (e) {\n self.handlemouseClick(e, $(this));\n }).mousedown(function (e) {\n self.handlemouseClick(e, $(this));\n });\n },\n handlemouseClick: function (e, element) {\n if (e.buttons === 1) {//left button\n element.css('background', '#f00');\n }\n if (e.buttons === 2) { //right buttom\n element.css('background', 'none');\n }\n }\n};\n$(document).ready(function () {\n clicableArea.init();\n});\n"
},
{
"answer_id": 35213733,
"author": "Martin",
"author_id": 1695049,
"author_profile": "https://Stackoverflow.com/users/1695049",
"pm_score": 3,
"selected": false,
"text": "<style>\n div.myDiv:active {\n cursor: default;\n }\n</style>\n\n<script>\n function handleMove( div ) {\n var style = getComputedStyle( div );\n if (style.getPropertyValue('cursor') == 'default')\n {\n // You're down and moving here!\n }\n }\n</script>\n\n<div class='myDiv' onmousemove='handleMove(this);'>Click and drag me!</div>\n"
},
{
"answer_id": 46316752,
"author": "dreadcast",
"author_id": 1239761,
"author_profile": "https://Stackoverflow.com/users/1239761",
"pm_score": 1,
"selected": false,
"text": "mouseup"
},
{
"answer_id": 47930992,
"author": "Micah Engle-Eshleman",
"author_id": 1546808,
"author_profile": "https://Stackoverflow.com/users/1546808",
"pm_score": 3,
"selected": false,
"text": "addEventListener"
},
{
"answer_id": 48970682,
"author": "Jono Job",
"author_id": 4289902,
"author_profile": "https://Stackoverflow.com/users/4289902",
"pm_score": 6,
"selected": false,
"text": "mousedown"
},
{
"answer_id": 57181125,
"author": "NVRM",
"author_id": 2494754,
"author_profile": "https://Stackoverflow.com/users/2494754",
"pm_score": 2,
"selected": false,
"text": "// Mouse buttons\ndocument.addEventListener('mousedown', e => console.log(e.buttons))\n// Keyboard keys\ndocument.addEventListener('keydown', e => console.log(e.key))"
},
{
"answer_id": 67677092,
"author": "illogicalapple",
"author_id": 15778548,
"author_profile": "https://Stackoverflow.com/users/15778548",
"pm_score": 2,
"selected": false,
"text": ".matches"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/615/"
] |
322,390 | <p>I want to examine the contents of a std::vector in gdb but I don't have access to _M_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity.</p>
<p>There is a very nice answer <a href="https://stackoverflow.com/questions/253099/how-do-i-print-the-elements-of-a-c-vector-in-gdb">here</a> but this doesn't work if I use icc, the error message is "There is no member or method named _M_impl". There appears to be a nice debug toolset <a href="http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF" rel="noreferrer">here</a> but it also relies on _M_impl.</p>
| [
{
"answer_id": 322417,
"author": "Max Lybbert",
"author_id": 10593,
"author_profile": "https://Stackoverflow.com/users/10593",
"pm_score": 0,
"selected": false,
"text": "std::vector"
},
{
"answer_id": 322562,
"author": "Mic",
"author_id": 35656,
"author_profile": "https://Stackoverflow.com/users/35656",
"pm_score": 5,
"selected": true,
"text": "#include <string>\n#include <vector>\n\nint main() {\n std::vector<std::string> vec;\n vec.push_back(\"Hello\");\n vec.push_back(\"world\");\n vec.push_back(\"!\");\n return 0;\n}\n"
},
{
"answer_id": 322684,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 2,
"selected": false,
"text": "vector<WeirdStructure> myWeird;\n\n/* push back a lot of stuff into the vector */ \n\nsize_t z;\nfor (z = 0; z < myWeird.size(); z++)\n{\n WeirdStructure& weird = myWeird[z];\n\n /* at this point weird is directly observable by the debugger */ \n\n /* your code to manipulate weird goes here */ \n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26261/"
] |
322,392 | <p>I'm looking for a regular expression that will match all strings EXCEPT those that contain a certain string within. Can someone help me construct it?</p>
<p>For example, looking for all strings that <em>do not</em> have a, b, and c in them in that order.</p>
<p>So <br />
abasfaf3 would match, whereas <br />
asasdfbasc would not</p>
| [
{
"answer_id": 322400,
"author": "Alan",
"author_id": 37843,
"author_profile": "https://Stackoverflow.com/users/37843",
"pm_score": 3,
"selected": true,
"text": "if($str !~ /a.*?b.*?.*c/g)\n{\n print \"match\";\n}\n"
},
{
"answer_id": 322413,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 0,
"selected": false,
"text": "(?m)^a?(.(?!a[^b\\r\\n]*b[^\\r\\nc]*c))+$\n"
},
{
"answer_id": 322420,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 2,
"selected": false,
"text": ">>> r = re.compile(\"(?!^.*a.*b.*c.*$)\")\n>>> r.match(\"abc\")\n>>> r.match(\"xxabcxx\")\n>>> r.match(\"ab \")\n<_sre.SRE_Match object at 0xb7bee288>\n>>> r.match(\"abasfaf3\")\n<_sre.SRE_Match object at 0xb7bee288>\n>>> r.match(\"asasdfbasc\")\n>>>\n"
},
{
"answer_id": 322425,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 1,
"selected": false,
"text": "echo azyxbc | awk '{ exit ($0 !~ /a.*b.*c/); }' && echo matched\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40866/"
] |
322,401 | <p>I feel that it should be something very simple and obvious but just stuck on this for the last half an hour and can't move on.</p>
<p>All I need is to split an array of elements into N groups based on element index.</p>
<p>For example we have an array of 30 elements [e1,e2,...e30], that has to be divided into N=3 groups like this:</p>
<pre><code>group1: [e1, ..., e10]
group2: [e11, ..., e20]
group3: [e21, ..., e30]
</code></pre>
<p>I came up with nasty mess like this for N=3 (pseudo language, I left multiplication on 0 and 1 just for clarification):</p>
<pre><code>for(i=0;i<array_size;i++) {
if(i>=0*(array_size/3) && i<1*(array_size/3) {
print "group1";
} else if(i>=1*(array_size/3) && i<2*(array_size/3) {
print "group2";
} else if(i>=2*(array_size/3) && i<3*(array_size/3)
print "group3";
}
}
</code></pre>
<p>But what would be the proper general solution?</p>
<p>Thanks.</p>
| [
{
"answer_id": 322427,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 1,
"selected": false,
"text": " const int g = 3; // number of groups\n const int n = (array_size + g - 1)/g; // elements per group\n\n for (i=0,j=1; i<array_size; ++i) {\n if (i > j*n)\n ++j;\n printf(\"Group %d\\n\", j);\n }\n"
},
{
"answer_id": 322432,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 1,
"selected": false,
"text": "int group[3][10];\nint groupIndex = 0;\nint itemIndex = 0;\nfor(i = 0; i < array_size; i++)\n{\n group[groupIndex][itemIndex] = big_array[i];\n itemIndex++;\n if (itemIndex == 10)\n {\n itemIndex = 0;\n groupIndex++; \n }\n}"
},
{
"answer_id": 322438,
"author": "Nathaniel Reinhart",
"author_id": 41122,
"author_profile": "https://Stackoverflow.com/users/41122",
"pm_score": 4,
"selected": true,
"text": "for(i=0;i<array_size;i++) {\n print \"group\" + (Math.floor(i/(array_size/N)) + 1)\n}\n"
},
{
"answer_id": 322458,
"author": "Die in Sente",
"author_id": 40756,
"author_profile": "https://Stackoverflow.com/users/40756",
"pm_score": 1,
"selected": false,
"text": "struct group {foo * ptr; size_t count };\ngroup * pgroups = new group [ngroups];\nsize_t objects_per_group = array_size / ngroups;\nfor (unsigned u = 0; u < ngroups; ++u ) {\n group & g = pgroups[u];\n size_t index = u * objects_per_group;\n g.ptr = & array [index];\n g.count = min (objects_per_group, array_size - index); // last group may have less!\n}\n...`\nfor (unsigned u = 0; u < ngroups; ++u) {\n // group \"g\" is an array at pgroups[g].ptr, dimension pgroups[g].count\n group & g = pgroups[u];\n // enumerate the group:\n for (unsigned v = 0; v < g.count; ++v) {\n fprintf (stdout, \"group %u, item %u, %s\\n\",\n (unsigned) u, (unsigned) v, (const char *) g.ptr[v]->somestring);\n} }\n\ndelete[] pgroups;\n"
},
{
"answer_id": 322581,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "split:{[values;n] / define function split with two parameters\n enum:!n / ! does enumerate from 0 through n exclusive, : is assign\n floor:_(#values)%n / 33 for this sample, % is divide, _ floor, # count\n cut:floor*enum / 0 33 66 for this sample data, * multiplies atom * vector\n :cut _ values / cut the values at the given cutpoints, yielding #cut lists\n }\n\nvalues:1+!30 / generate values 1 through 30\nn:3 / how many groups to split into\ngroups:split[values;n] / set the groups\n"
},
{
"answer_id": 654830,
"author": "Ben Hull",
"author_id": 79068,
"author_profile": "https://Stackoverflow.com/users/79068",
"pm_score": 2,
"selected": false,
"text": "function arrayToGroups(source, groups) { \n\n //This is the array of groups to return:\n var grouped = [];\n\n //work out the size of the group\n var groupSize = Math.ceil(source.length/groups);\n\n //clone the source array so we can safely splice it (splicing modifies the array)\n var queue = source.slice(0);\n\n for (var r=0;r<groups;r++) {\n //Grab the next groupful from the queue, and append it to the array of groups\n grouped.push(queue.splice(0, groupSize)); \n } \n return grouped;\n}\n"
},
{
"answer_id": 4541680,
"author": "rocktronica",
"author_id": 555353,
"author_profile": "https://Stackoverflow.com/users/555353",
"pm_score": 2,
"selected": false,
"text": "function arrayToGroups($source, $pergroup) { \n $grouped = array();\n $groupCount = ceil(count($source)/$pergroup);\n $queue = $source;\n for ($r=0; $r<$groupCount; $r++) {\n array_push($grouped, array_splice($queue, 0, $pergroup)); \n } \n return $grouped;\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20128/"
] |
322,418 | <p>I've been always thinking that DOMNodeInsertedIntoDocument/DOMNodeRemovedFromDocument events should not bubble, and for me that made enough sence. However, just recently I looked into specification once again and found out that in one location it says these events should not bubble (<a href="http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-EventTypes-complete" rel="nofollow noreferrer">Complete list of event types</a>), while in other location is says they should (<a href="http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-DOMNodeInsertedIntoDocument" rel="nofollow noreferrer">DOMNodeInsertedIntoDocument</a> and <a href="http://www.w3.org/TR/DOM-Level-3-Events/events.html#event-DOMNodeRemovedFromDocument" rel="nofollow noreferrer">DOMNodeRemovedFromDocument</a>).</p>
<p>I've also looked up on the Internet and found several implementations, all of them are different in the behavior implemented.</p>
<p>The question is: Should these events actually bubble ot not? What do you think make more sence?</p>
<p><b>Update</b>: Found out that in <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html" rel="nofollow noreferrer">DOM-Level-2-Events</a> specification there is no ambiguity since it olny mentions these events in a single location.</p>
<p><b>Update 2</b>: This question was asked in order to validate the behavior of these events in the <a href="http://www.clientside.ru/" rel="nofollow noreferrer">Ample SDK</a> Ajax Framework that aims to implement all standards-based technologies.</p>
| [
{
"answer_id": 322427,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 1,
"selected": false,
"text": " const int g = 3; // number of groups\n const int n = (array_size + g - 1)/g; // elements per group\n\n for (i=0,j=1; i<array_size; ++i) {\n if (i > j*n)\n ++j;\n printf(\"Group %d\\n\", j);\n }\n"
},
{
"answer_id": 322432,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 1,
"selected": false,
"text": "int group[3][10];\nint groupIndex = 0;\nint itemIndex = 0;\nfor(i = 0; i < array_size; i++)\n{\n group[groupIndex][itemIndex] = big_array[i];\n itemIndex++;\n if (itemIndex == 10)\n {\n itemIndex = 0;\n groupIndex++; \n }\n}"
},
{
"answer_id": 322438,
"author": "Nathaniel Reinhart",
"author_id": 41122,
"author_profile": "https://Stackoverflow.com/users/41122",
"pm_score": 4,
"selected": true,
"text": "for(i=0;i<array_size;i++) {\n print \"group\" + (Math.floor(i/(array_size/N)) + 1)\n}\n"
},
{
"answer_id": 322458,
"author": "Die in Sente",
"author_id": 40756,
"author_profile": "https://Stackoverflow.com/users/40756",
"pm_score": 1,
"selected": false,
"text": "struct group {foo * ptr; size_t count };\ngroup * pgroups = new group [ngroups];\nsize_t objects_per_group = array_size / ngroups;\nfor (unsigned u = 0; u < ngroups; ++u ) {\n group & g = pgroups[u];\n size_t index = u * objects_per_group;\n g.ptr = & array [index];\n g.count = min (objects_per_group, array_size - index); // last group may have less!\n}\n...`\nfor (unsigned u = 0; u < ngroups; ++u) {\n // group \"g\" is an array at pgroups[g].ptr, dimension pgroups[g].count\n group & g = pgroups[u];\n // enumerate the group:\n for (unsigned v = 0; v < g.count; ++v) {\n fprintf (stdout, \"group %u, item %u, %s\\n\",\n (unsigned) u, (unsigned) v, (const char *) g.ptr[v]->somestring);\n} }\n\ndelete[] pgroups;\n"
},
{
"answer_id": 322581,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "split:{[values;n] / define function split with two parameters\n enum:!n / ! does enumerate from 0 through n exclusive, : is assign\n floor:_(#values)%n / 33 for this sample, % is divide, _ floor, # count\n cut:floor*enum / 0 33 66 for this sample data, * multiplies atom * vector\n :cut _ values / cut the values at the given cutpoints, yielding #cut lists\n }\n\nvalues:1+!30 / generate values 1 through 30\nn:3 / how many groups to split into\ngroups:split[values;n] / set the groups\n"
},
{
"answer_id": 654830,
"author": "Ben Hull",
"author_id": 79068,
"author_profile": "https://Stackoverflow.com/users/79068",
"pm_score": 2,
"selected": false,
"text": "function arrayToGroups(source, groups) { \n\n //This is the array of groups to return:\n var grouped = [];\n\n //work out the size of the group\n var groupSize = Math.ceil(source.length/groups);\n\n //clone the source array so we can safely splice it (splicing modifies the array)\n var queue = source.slice(0);\n\n for (var r=0;r<groups;r++) {\n //Grab the next groupful from the queue, and append it to the array of groups\n grouped.push(queue.splice(0, groupSize)); \n } \n return grouped;\n}\n"
},
{
"answer_id": 4541680,
"author": "rocktronica",
"author_id": 555353,
"author_profile": "https://Stackoverflow.com/users/555353",
"pm_score": 2,
"selected": false,
"text": "function arrayToGroups($source, $pergroup) { \n $grouped = array();\n $groupCount = ceil(count($source)/$pergroup);\n $queue = $source;\n for ($r=0; $r<$groupCount; $r++) {\n array_push($grouped, array_splice($queue, 0, $pergroup)); \n } \n return $grouped;\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23815/"
] |
322,423 | <p>I'm having some trouble uploading and getting my web app on the net with my chosen host. I built a war file in Net Beans and asked my host to deploy it for me. This worked fine but to access it I had to point my browser to:</p>
<pre><code>www.myDomain.co.uk/explodedWar
</code></pre>
<p>What of course I wanted was to be able to access it just by pointing my browser at:</p>
<pre><code>www.myDomain.co.uk
</code></pre>
<p>The war file contains the whole app, index.html, images, classes etc.</p>
<p>Is this possible or am I missing something ? ?</p>
| [
{
"answer_id": 322525,
"author": "Hates_",
"author_id": 3410,
"author_profile": "https://Stackoverflow.com/users/3410",
"pm_score": 2,
"selected": false,
"text": "<context path=\"\" docBase=\"explodedWar\" debug=\"0\"/>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16684/"
] |
322,440 | <p>Is there a free API or some other way to determine what carrier a cell phone number is registered with?</p>
<p>I'd like my application to broadcast text messages without them picking their carrier from a list.</p>
<p><strong>UPDATE:</strong>
Interestingly, a coworker found the answer: <a href="http://developer.whitepages.com/" rel="noreferrer">http://developer.whitepages.com/</a></p>
<p><strong>UPDATE2:</strong>
Well the whitepages license agreement is so restrictive that you can't build an app for it. Any other ideas?</p>
<p><strong>UPDATE3:</strong><br>
At some point, someone removed my Update 2. This puts it back. More importantly as of 10/19/2015 the <a href="http://pro.whitepages.com/terms-of-service/?_ga=1.260850253.1904530943.1445280336" rel="noreferrer">Terms of Service</a> is still in a state that it should be impossible to legally utilize their services. </p>
| [
{
"answer_id": 9641822,
"author": "Trey Brister",
"author_id": 1248484,
"author_profile": "https://Stackoverflow.com/users/1248484",
"pm_score": 2,
"selected": false,
"text": "http://www.fonefinder.net/findome.php?npa=817&nxx=683&thoublock=2926\n"
},
{
"answer_id": 18820770,
"author": "deadboy",
"author_id": 1822462,
"author_profile": "https://Stackoverflow.com/users/1822462",
"pm_score": 1,
"selected": false,
"text": "require 'FoneFinder'\nmyPhoneNumber = FoneFinder.new(\"123-456-7890\")\nputs myPhoneNumber.carrier\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2424/"
] |
322,441 | <p>How can I ignore accents (like ´, `, ~) in queries made to a SQL Server database using LINQ to SQL?</p>
<p><strong>UPDATE:</strong></p>
<p>Still haven't figured out how to do it in LINQ (or even if it's possible) but I managed to change the database to solve this issue.
Just had to change the collation on the fields I wanted to search on. The collation I had was:</p>
<pre><code>SQL_Latin1_General_CP1_CI_AS
</code></pre>
<p>The CI stans for "Case Insensitive" and AS for "Accent Sensitive". Just had to change the AS to AI to make it "Accent Insensitive".
The SQL statement is this:</p>
<pre><code>ALTER TABLE table_name ALTER COLUMN column_name column_type COLLATE collation_type
</code></pre>
| [
{
"answer_id": 8145058,
"author": "Dunc",
"author_id": 188926,
"author_profile": "https://Stackoverflow.com/users/188926",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE People ALTER COLUMN Name [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AI\n"
},
{
"answer_id": 9097297,
"author": "Jan",
"author_id": 1182870,
"author_profile": "https://Stackoverflow.com/users/1182870",
"pm_score": 1,
"selected": false,
"text": "CREATE FUNCTION [dbo].[func_ConcatWithoutCollation]\n(\n @param1 varchar(2000),\n @param2 varchar(2000)\n)\nRETURNS varchar(4000)\nAS\nBEGIN\n IF (@param1 IS NULL) SET @param1 = ''\n IF (@param2 IS NULL) SET @param2 = ''\n RETURN @param1 COLLATE Latin1_General_CS_AS + @param2 COLLATE Latin1_General_CS_AS\nEND\n"
},
{
"answer_id": 69662276,
"author": "João Neto",
"author_id": 12769651,
"author_profile": "https://Stackoverflow.com/users/12769651",
"pm_score": 0,
"selected": false,
"text": "CREATE FUNCTION [dbo].[RemoveDiacritics] (\n@input varchar(max)\n) RETURNS varchar(max)\n\nAS BEGIN\nDECLARE @result VARCHAR(max);\n\nselect @result = @input collate SQL_Latin1_General_CP1253_CI_AI\n\nreturn @result\nEND\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322441",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2841/"
] |
322,470 | <h3>Background:</h3>
<p>I have a module which declares a number of instance methods</p>
<pre><code>module UsefulThings
def get_file; ...
def delete_file; ...
def format_text(x); ...
end
</code></pre>
<p>And I want to call some of these methods from within a class. How you normally do this in ruby is like this:</p>
<pre><code>class UsefulWorker
include UsefulThings
def do_work
format_text("abc")
...
end
end
</code></pre>
<h3>Problem</h3>
<p><code>include UsefulThings</code> brings in <em>all</em> of the methods from <code>UsefulThings</code>. In this case I only want <code>format_text</code> and explicitly do not want <code>get_file</code> and <code>delete_file</code>.</p>
<p>I can see several possible solutions to this: </p>
<ol>
<li>Somehow invoke the method directly on the module without including it anywhere
<ul>
<li>I don't know how/if this can be done. (Hence this question)</li>
</ul></li>
<li>Somehow include <code>Usefulthings</code> and only bring in some of it's methods
<ul>
<li>I also don't know how/if this can be done</li>
</ul></li>
<li>Create a proxy class, include <code>UsefulThings</code> in that, then delegate <code>format_text</code> to that proxy instance
<ul>
<li>This would work, but anonymous proxy classes are a hack. Yuck.</li>
</ul></li>
<li>Split up the module into 2 or more smaller modules
<ul>
<li>This would also work, and is probably the best solution I can think of, but I'd prefer to avoid it as I'd end up with a proliferation of dozens and dozens of modules - managing this would be burdensome</li>
</ul></li>
</ol>
<p>Why are there lots of unrelated functions in a single module? It's <code>ApplicationHelper</code> from a rails app, which our team has de-facto decided on as the dumping ground for anything not specific enough to belong anywhere else. Mostly standalone utility methods that get used everywhere. I could break it up into seperate helpers, but there'd be 30 of them, all with 1 method each... this seems unproductive</p>
| [
{
"answer_id": 322501,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 3,
"selected": false,
"text": "module UsefulThings\n def a\n puts \"aaay\"\n end\n def b\n puts \"beee\"\n end\nend\n\ndef test\n ob = Class.new.send(:include, UsefulThings).new\n ob.a\nend\n\ntest\n"
},
{
"answer_id": 322505,
"author": "Raimonds Simanovskis",
"author_id": 16829,
"author_profile": "https://Stackoverflow.com/users/16829",
"pm_score": 5,
"selected": false,
"text": "module UsefulThings\n def self.get_file; ...\n def self.delete_file; ...\n\n def self.format_text(x); ...\nend\n"
},
{
"answer_id": 322515,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 7,
"selected": false,
"text": "module_function"
},
{
"answer_id": 322526,
"author": "dgtized",
"author_id": 34450,
"author_profile": "https://Stackoverflow.com/users/34450",
"pm_score": 8,
"selected": true,
"text": "module Mods\n def self.foo\n puts \"Mods.foo(self)\"\n end\nend\n"
},
{
"answer_id": 1411061,
"author": "dolzenko",
"author_id": 54247,
"author_profile": "https://Stackoverflow.com/users/54247",
"pm_score": 7,
"selected": false,
"text": "Class.new.extend(UsefulThings).get_file\n"
},
{
"answer_id": 21614315,
"author": "inger",
"author_id": 174284,
"author_profile": "https://Stackoverflow.com/users/174284",
"pm_score": 3,
"selected": false,
"text": "module UsefulThings\n def self.get_file; ...\n def self.delete_file; ...\n\n def self.format_text(x); ...\n\n # Or.. make all of the \"static\"\n class << self\n def write_file; ...\n def commit_file; ...\n end\n\nend\n"
},
{
"answer_id": 26154254,
"author": "renier",
"author_id": 3160958,
"author_profile": "https://Stackoverflow.com/users/3160958",
"pm_score": 4,
"selected": false,
"text": "class UsefulWorker\n def do_work\n UsefulThings.instance_method(:format_text).bind(self).call(\"abc\")\n ...\n end\nend\n"
},
{
"answer_id": 31982052,
"author": "Cary Swoveland",
"author_id": 256970,
"author_profile": "https://Stackoverflow.com/users/256970",
"pm_score": 3,
"selected": false,
"text": "UsefulThings"
},
{
"answer_id": 47275232,
"author": "thisismydesign",
"author_id": 2771889,
"author_profile": "https://Stackoverflow.com/users/2771889",
"pm_score": 1,
"selected": false,
"text": "module CreateModuleFunctions\n def self.included(base)\n base.instance_methods.each do |method|\n base.module_eval do\n module_function(method)\n public(method)\n end\n end\n end\nend\n\nRSpec.describe CreateModuleFunctions do\n context \"when included into a Module\" do\n it \"makes the Module's methods invokable via the Module\" do\n module ModuleIncluded\n def instance_method_1;end\n def instance_method_2;end\n\n include CreateModuleFunctions\n end\n\n expect { ModuleIncluded.instance_method_1 }.to_not raise_error\n end\n end\nend\n"
},
{
"answer_id": 58193621,
"author": "Vitaly ",
"author_id": 2270713,
"author_profile": "https://Stackoverflow.com/users/2270713",
"pm_score": 4,
"selected": false,
"text": "module UsefulThings\n def useful_thing_1\n \"thing_1\"\n end\n\n class << self\n include UsefulThings\n end\nend\n\nclass A\n include UsefulThings\nend\n\nclass B\n extend UsefulThings\nend\n\nUsefulThings.useful_thing_1 # => \"thing_1\"\nA.new.useful_thing_1 # => \"thing_1\"\nB.useful_thing_1 # => \"thing_1\"\n"
},
{
"answer_id": 73893583,
"author": "Long TRAN",
"author_id": 1764872,
"author_profile": "https://Stackoverflow.com/users/1764872",
"pm_score": 0,
"selected": false,
"text": "module MyModule\n def say\n 'I say'\n end\n\n def cheer\n 'I cheer'\n end\nend \n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] |
322,481 | <p>When editing an XML file in IntelliJ IDEA, if the document references a schema, IDEA will fetch the schema and use the information for auto-complete. It knows which tags are valid in which contexts, so when you hit CTRL-space, it suggests only those tags. It also highlights any tags that are invalid according to the schema.</p>
<p>Does anybody know of an extension for Vim that provides similar functionality?</p>
| [
{
"answer_id": 12036766,
"author": "lzap",
"author_id": 299204,
"author_profile": "https://Stackoverflow.com/users/299204",
"pm_score": 4,
"selected": false,
"text": "$ rpm -ql vim vim-common | grep xml\n/usr/share/vim/vim73/autoload/xml\n/usr/share/vim/vim73/autoload/xml/html32.vim\n/usr/share/vim/vim73/autoload/xml/html401f.vim\n/usr/share/vim/vim73/autoload/xml/html401s.vim\n/usr/share/vim/vim73/autoload/xml/html401t.vim\n/usr/share/vim/vim73/autoload/xml/html40f.vim\n/usr/share/vim/vim73/autoload/xml/html40s.vim\n/usr/share/vim/vim73/autoload/xml/html40t.vim\n/usr/share/vim/vim73/autoload/xml/xhtml10f.vim\n/usr/share/vim/vim73/autoload/xml/xhtml10s.vim\n/usr/share/vim/vim73/autoload/xml/xhtml10t.vim\n/usr/share/vim/vim73/autoload/xml/xhtml11.vim\n/usr/share/vim/vim73/autoload/xml/xsd.vim\n/usr/share/vim/vim73/autoload/xml/xsl.vim\n/usr/share/vim/vim73/autoload/xmlcomplete.vim\n/usr/share/vim/vim73/compiler/xmllint.vim\n/usr/share/vim/vim73/compiler/xmlwf.vim\n/usr/share/vim/vim73/ftplugin/xml.vim\n/usr/share/vim/vim73/indent/xml.vim\n/usr/share/vim/vim73/syntax/docbkxml.vim\n/usr/share/vim/vim73/syntax/xml.vim\n"
},
{
"answer_id": 18630589,
"author": "Soundararajan",
"author_id": 866670,
"author_profile": "https://Stackoverflow.com/users/866670",
"pm_score": 1,
"selected": false,
"text": "bar.xml"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5171/"
] |
322,488 | <p>This is always a pain, no matter what source control system I have used (<a href="https://en.wikipedia.org/wiki/Microsoft_Visual_SourceSafe" rel="nofollow noreferrer">Visual SourceSafe</a>, <a href="https://en.wikipedia.org/wiki/Concurrent_Versions_System" rel="nofollow noreferrer">CVS</a>, <a href="https://en.wikipedia.org/wiki/Rational_ClearCase" rel="nofollow noreferrer">ClearCase</a>, etc.). The binary .frx files always cause a problem when merging Visual Basic forms.</p>
<p>I know...I know...why are you using Visual Basic...because there are lots of legacy applications still written using it and although I hate to admit it, I actually like using it (<em>ducks tomatoes</em>).</p>
| [
{
"answer_id": 917155,
"author": "Thomas Corriol",
"author_id": 92401,
"author_profile": "https://Stackoverflow.com/users/92401",
"pm_score": 3,
"selected": false,
"text": "(...)\n\n# Match non-printable files by name\n\n(...)\n\nvb_form_compiled vb_derived compressed_file : !-printable & -name \"*.[fF][rR][xX]\" ;\n\n(...)\n\n# assumed to be binary\n\n(...)\n\nvb_form_compiled vb_derived compressed_file : -name \"*.[fF][rR][xX]\" ;\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41192/"
] |
322,493 | <p>What can I do to comprehensively validate an Australian Phone Number? I need this for an application I'm writing. You can assume it is dialed from within Australia. I want to use a white-list approach.</p>
<p>Here are my rules so far (after removing any whitespace):-</p>
<ol>
<li>Starts with 13 and is 6 digits long</li>
<li>Starts with 1300 and is 10 digits long</li>
<li>Starts with 0 (but not 0011 as this is international dialing) and is 10 digits long</li>
<li>Starts with +61 followed by 9 digits</li>
<li>Starts with (0_) followed by 8 digits (where _ is 1-9)</li>
</ol>
<p>Is there anything I have missed?</p>
<p>Area codes are required as we may be sending a fax from our fax server in one state when the user is in a different state.</p>
<p>(I'm not asking how to make a regexp out of the above rules, but if those rules are correct).</p>
<p>See also:<br>
<a href="https://stackoverflow.com/questions/32401/validate-a-uk-phone-number">UK Phone Numbers</a><br>
<a href="https://stackoverflow.com/questions/175488/us-phone-number-verification">US Phone Numbers</a></p>
| [
{
"answer_id": 322753,
"author": "Matthewd",
"author_id": 40159,
"author_profile": "https://Stackoverflow.com/users/40159",
"pm_score": 3,
"selected": false,
"text": "02[3-9]\\d{7} NSW/ACT\n03[4-9]\\d{7} VIC/TAS\n07[3-9]\\d{7} QLD\n08\\d{8} SA/NT/WA\n\n04[\\d]{8} Moblies 04x[123] = Optus, 04x[456] = Voda, 04x[0789] = Telstra\n\n0500[\\d]{6} Find me anywhere server\n0550[\\d]{6} VoIP\n059[\\d]{7} Enum\n\n13[\\d]{4} Local rate\n1300[\\d]{6} Local rate\n\n1800[\\d]{6} Free call\n\n0198[\\d]{2} Data networks (local call anyway I think)\n0198[\\d]{6}\n\n190[\\d]{7} Premium rate\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14663/"
] |
322,496 | <p>Short version: </p>
<p>Could anyone suggest or provide a sample in LINQ to XML for VB, or in an XSLT of how to change one XML element into another (without hardcoding an element-by-element copy of all the unchanged elements)?</p>
<p>Background:</p>
<p>I have an XML file, that I think is properly formed, that contains a root entry that is <code><collection</code>> and multiple <code><dvd</code>> elements. Within a DVD, there are Genres and Tags, as shown below. (I cut out a lot of the other elements for simplicity).</p>
<p>What I want to do is turn any <code><Tag</code>> elements that might be present into an additional <code><Genre</code>>. For example, in the entry below, I need to add <code><Genre</code>>Kids<code></Genre</code>>. (I realize that it is actually the NAME attribute of the TAG element that I'm looking to turn into the GENRE element, but if I could even figure out how to create a new GENRE called "Tag" I'd be much further ahead and could probably puzzle out the rest.)</p>
<p>I've never done anything much with XML. My understanding is that I could use an XSLT transform file and a XSLCompiledTransform or I could use LINQ to XML (I have Visual Basic 9, and would prefer to do it all inside of VB). [I'm sure there are a number of other approaches, too.]</p>
<p>Trouble is, I can't find any examples of XSLT or LINQ syntax that tell me how to turn one element into another. I could write out enough LINQ to copy all of the elements one by one, but there has got to be an easier way than hardcoding a copy of all the elements that don't change! (There has got to be!)</p>
<p>So, if someone who knows could point me to an example or give me a hand with a bit of starter code in LINQ or XSLT, I would be forever grateful (OK, maybe not forever, but at least for a long time!).</p>
<p>Thanks.</p>
<p>Sample XML:</p>
<pre><code><Collection>
<DVD>
<ID>0000502461</ID>
<Title>Cirque du Soleil: Alegría</Title>
<Released>2002-05-31</Released>
<RunningTime>90</RunningTime>
<Genres>
<Genre>Family</Genre>
<Genre>Music</Genre>
</Genres>
<Overview>What if anything were possible? What if ...
</Overview>
<Notes/>
<Tags>
<Tag Name="Kids" FullName="Kids"/>
</Tags>
</DVD>
</Collection>
</code></pre>
| [
{
"answer_id": 322520,
"author": "seanb",
"author_id": 3354,
"author_profile": "https://Stackoverflow.com/users/3354",
"pm_score": 0,
"selected": false,
"text": " <xsl:template match=\"Tag\">\n <xsl:element name=\"Genre\">\n <xsl:value-of select=\"@Name\"/> \n </xsl:element> \n </xsl:template>\n"
},
{
"answer_id": 322522,
"author": "phihag",
"author_id": 35070,
"author_profile": "https://Stackoverflow.com/users/35070",
"pm_score": 1,
"selected": false,
"text": "node()"
},
{
"answer_id": 322569,
"author": "Dimitre Novatchev",
"author_id": 36305,
"author_profile": "https://Stackoverflow.com/users/36305",
"pm_score": 2,
"selected": false,
"text": " <Genre>Kids</Genre>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41188/"
] |
322,498 | <p>I noticed methods marked optional in several protocols defined in the iPhone SDK, such as the <code>UIActionSheetDelegate</code> protocol for example.</p>
<p>How can I define a protocol of my own, and set a few of the methods as optional?</p>
| [
{
"answer_id": 322511,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 4,
"selected": false,
"text": "@optional"
},
{
"answer_id": 322512,
"author": "Matt Gallagher",
"author_id": 36103,
"author_profile": "https://Stackoverflow.com/users/36103",
"pm_score": 9,
"selected": true,
"text": "@protocol MyProtocol\n\n- (void)requiredMethod;\n\n@optional\n- (void)anOptionalMethod;\n- (void)anotherOptionalMethod;\n\n@required\n- (void)anotherRequiredMethod;\n\n@end\n"
},
{
"answer_id": 23511380,
"author": "user3540599",
"author_id": 3540599,
"author_profile": "https://Stackoverflow.com/users/3540599",
"pm_score": 3,
"selected": false,
"text": "@protocol myPrtocol<NSObject>\n\n-(void)someMethod1:(id)someArgument;\n-(void)someMethod2:(id)someArugument;\n\n@optional\n\n-(void)someMethod3:(id)someArgument;\n\n@required //by default\n\n-(void)someMethod4:(id)someArgument;\n\n@end\n\n// sampleClass.m\n@interface sampleClass : someSuperClass <myProtocol>\n//...\n@end\n"
},
{
"answer_id": 25647489,
"author": "Zephyr",
"author_id": 2368492,
"author_profile": "https://Stackoverflow.com/users/2368492",
"pm_score": 5,
"selected": false,
"text": "NSString *thisSegmentTitle;\nif ([self.dataSource respondsToSelector:@selector(titleForSegmentAtIndex:)]) {\n thisSegmentTitle = [self.dataSource titleForSegmentAtIndex:index];\n}\n"
},
{
"answer_id": 30508168,
"author": "Vikram Biwal",
"author_id": 4887505,
"author_profile": "https://Stackoverflow.com/users/4887505",
"pm_score": 4,
"selected": false,
"text": "@protocol TestProtocols <NSObject>\n @optional\n -(void)testMethodOptional;\n\n @required // by default\n -(void)testMethodRequired;\n@end\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35478/"
] |
322,510 | <p>I have been working on a script with PHP4 that relies on NuSOAP. Now, I'm trying to move this to PHP5, and use the buildin support for SOAP there.</p>
<pre><code>$wsdlPath = ""; // I have obviously set these variables to something meaningful, just hidden for the sake of security
$apiPath = "";
$username = "";
$password = "";
// PHP5 style
$client = new soapclient($wsdlPath, array('login'=>username,
'password'=> $password,
'soap_version'=> SOAP_1_2,
'location'=> $apiPath,
'trace'=> 1));
// PHP4/NuSOAP style
$client = new soapclient($wsdlPath, true);
client->setEndpoint($apiPath);
$client->setCredentials($username, $password);
$client ->loadWSD);
</code></pre>
<p>The PHP5-version throws the following exception stacktrace:</p>
<pre><code>EXCEPTION=SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://external-nbb.napi.norwegian.no.stage.osl.basefarm.net/api/napi1300?wsdl' in /home/eisebfog/public_html/database/norwegian.php:31
Stack trace:
#0 /home/eisebfog/public_html/database/norwegian.php(31): SoapClient->SoapClient('http://external...', Array)
#1 /home/eisebfog/public_html/database/index.php(53): require_once('/home/eisebfog/...')
#2 {main}
</code></pre>
<p>Now, as the NuSOAP version does work, and the pure PHP5 doesn't - it doesn't take a brain surgeon to figure out I'm doing something wrong. I have access to the .htaccess file, and through phpinfo() I have made sure that I'm running NuSOAP properly and running PHP5 when I should, and PHP4/Nusoap when I should.</p>
<p>Basically, I'm not very good with web services and soap - but if anyone has any ideas, i'd appreciate any input on what I'm doing wrong and how I can move to the native soap in PHP5. Btw, the reson I want this move in the first place is the assumed resource savings in native soap. I'd appreciate any links to benchmarks between these two solutions too.</p>
| [
{
"answer_id": 329366,
"author": "Dan Soap",
"author_id": 25253,
"author_profile": "https://Stackoverflow.com/users/25253",
"pm_score": 1,
"selected": false,
"text": "error_reporting( E_ALL );\n"
},
{
"answer_id": 339120,
"author": "qualbeen",
"author_id": 36975,
"author_profile": "https://Stackoverflow.com/users/36975",
"pm_score": 3,
"selected": true,
"text": "if(!extension_loaded('soap')){\n dl('soap.so'); // Actually a deprecated method. See \"notes\" at http://no.php.net/dl\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
322,561 | <p>If I click on a package and do control-shift-F10 it only looks for and runs JUnit tests in that package - but I really want it to recurse down into subpackages and run them. </p>
<p>UPDATE: looks like its something else wrong. When I run it on a package that has tests, it still complains there are none (yet if I open a JUnit test I can run it just fine).</p>
| [
{
"answer_id": 70524762,
"author": "Voy",
"author_id": 3508719,
"author_profile": "https://Stackoverflow.com/users/3508719",
"pm_score": 0,
"selected": false,
"text": "__init__.py"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/699/"
] |
322,580 | <p>I want to convert a string into a series of Keycodes, so that I can then send them via PostMessage to a control. I need to simulate actual keyboard input, and I'm wondering if a massive switch statement is the only way to convert a character into the correct keycode, or if there's a simpler method.</p>
<p>====</p>
<p>Got my solution - <a href="http://msdn.microsoft.com/en-us/library/ms646329(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms646329(VS.85).aspx</a></p>
<p>VkKeyScan will return the correct keycode for any character.</p>
<p>(And yes, I wouldn't do this in general, but when doing automated testing, and making sure that keyboard presses are responded to correctly, it works reliably enough).</p>
| [
{
"answer_id": 322615,
"author": "johnc",
"author_id": 5302,
"author_profile": "https://Stackoverflow.com/users/5302",
"pm_score": 0,
"selected": false,
"text": "string.Format(\"KEY_KEY_{0}\", char.ToString())"
},
{
"answer_id": 328093,
"author": "Stefan Rusek",
"author_id": 19704,
"author_profile": "https://Stackoverflow.com/users/19704",
"pm_score": 0,
"selected": false,
"text": " System.Windows.Forms.SendKeys(\"This is a test\");\n System.Windows.Forms.SendKeys(\"This is sends CTRL+J ^j\");\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26874/"
] |
322,597 | <p>It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an <code>#import</code> is a simple <code>ifndef</code> so that an include only happens once.</p>
<p>My inquiry is this: When does one use <code>#import</code> and when does one use <code>@class</code>? Sometimes if I use a <code>@class</code> declaration, I see a common compiler warning such as the following:</p>
<blockquote>
<p><code>warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.</code></p>
</blockquote>
<p>Would really love to understand this, versus just removing the <code>@class</code> forward-declaration and throwing an <code>#import</code> in to silence the warnings the compiler is giving me.</p>
| [
{
"answer_id": 322626,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 6,
"selected": false,
"text": "#import"
},
{
"answer_id": 322627,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 11,
"selected": true,
"text": "#import"
},
{
"answer_id": 1350029,
"author": "PeyloW",
"author_id": 165059,
"author_profile": "https://Stackoverflow.com/users/165059",
"pm_score": 8,
"selected": false,
"text": "#import"
},
{
"answer_id": 3674758,
"author": "vent",
"author_id": 335992,
"author_profile": "https://Stackoverflow.com/users/335992",
"pm_score": 5,
"selected": false,
"text": "@class name"
},
{
"answer_id": 8722935,
"author": "Anshuman Mishra",
"author_id": 980359,
"author_profile": "https://Stackoverflow.com/users/980359",
"pm_score": 3,
"selected": false,
"text": "@interface Class_B : Class_A\n"
},
{
"answer_id": 9188603,
"author": "justin",
"author_id": 191596,
"author_profile": "https://Stackoverflow.com/users/191596",
"pm_score": 4,
"selected": false,
"text": "#import"
},
{
"answer_id": 14195795,
"author": "IluTov",
"author_id": 1320374,
"author_profile": "https://Stackoverflow.com/users/1320374",
"pm_score": 2,
"selected": false,
"text": "#import"
},
{
"answer_id": 39726086,
"author": "Sujananth",
"author_id": 4146319,
"author_profile": "https://Stackoverflow.com/users/4146319",
"pm_score": 0,
"selected": false,
"text": "// DroneSearchField.h\n\n#import <UIKit/UIKit.h>\n@class DroneSearchField;\n@protocol DroneSearchFieldDelegate<UITextFieldDelegate>\n@optional\n- (void)DroneTextFieldButtonClicked:(DroneSearchField *)textField;\n@end\n@interface DroneSearchField : UITextField\n@end\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322597",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
322,601 | <p>This seems to me to be the kind of issue that would crop up all the time with SQL/database development, but then I'm new to all this, so forgive my ignorance.</p>
<p>I have 2 tables:</p>
<pre><code>CREATE TABLE [dbo].[Tracks](
[TrackStringId] [bigint] NOT NULL,
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Time] [datetime] NOT NULL,
CONSTRAINT [PK_Tracks] PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Tracks] CHECK CONSTRAINT [FK_Tracks_AudioStreams]
GO
ALTER TABLE [dbo].[Tracks] WITH CHECK ADD CONSTRAINT
[FK_Tracks_TrackStrings] FOREIGN KEY([TrackStringId])
REFERENCES [dbo].[TrackStrings] ([Id])
GO
ALTER TABLE [dbo].[Tracks] CHECK CONSTRAINT [FK_Tracks_TrackStrings]
GO
</code></pre>
<p>and</p>
<pre><code>CREATE TABLE [dbo].[TrackStrings](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[String] [nvarchar](512) NOT NULL,
CONSTRAINT [PK_Strings] PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
</code></pre>
<p>I want to insert a new entry into the tracks table. This will also involve inserting a new entry in the trackstrings table, and ensuring that the foreign key column trackstringid in tracks points to the new entry in trackstrings. What is the most efficient means of achieving this?</p>
| [
{
"answer_id": 322616,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": true,
"text": "TrackStrings"
},
{
"answer_id": 322625,
"author": "palehorse",
"author_id": 312,
"author_profile": "https://Stackoverflow.com/users/312",
"pm_score": 0,
"selected": false,
"text": "INSERT INTO trackstrings VALUES('myvalue')\n"
},
{
"answer_id": 322965,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 3,
"selected": false,
"text": "INSERT"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14357/"
] |
322,606 | <p>I'm managing an established site which is currently in the process of being upgraded (completely replaced anew), but I'm worried that I'll lose all my Google indexing (that is, there will be a lot of pages in Google's index which won't exist in that place any more).</p>
<p>The last time I upgraded a (different) site, someone told me I should have done <em>something</em> so that my SEO isn't adversely affected. The problem is, I can't remember what that <em>something</em> was.</p>
<hr>
<p><em>Update for some clarification:</em> Basically I'm looking for some way to map the old paths to the new ones. For example:</p>
<ul>
<li>User searches for "awesome page"</li>
<li>Google returns <code>mysite.com/old_awesome_page.php</code>, user clicks it.</li>
<li>My site takes them to <code>mysite.com/new_awesome_page.php</code></li>
</ul>
<p>And when Google gets around to crawling the site again...</p>
<ul>
<li>Google crawls my site, refreshing the existing indexes.</li>
<li>Requests <code>old_awesome_page.php</code></li>
<li>My site tells Google that the page has now moved to <code>new_awesome_page.php</code>.</li>
</ul>
<p>There won't be a simple 1:1 mapping like that, it'll be more like <code>(old) index.php?page=awesome --> (new) index.php/pages/awesome</code>, so I can't just replace the contents of the existing files with redirects.</p>
<p><em>I'm using PHP on Apache</em></p>
| [
{
"answer_id": 322662,
"author": "majelbstoat",
"author_id": 38812,
"author_profile": "https://Stackoverflow.com/users/38812",
"pm_score": 3,
"selected": true,
"text": "RewriteEngine on\nRewriteRule ^/~(.+) http://newserver/~$1 [R,L]\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
322,607 | <p>I run a small browser MMO, and I have a problem where a couple users are embedding scripts into their profile images, and using them to make attacks against said users, and my game in general. Is there a way to protect against this, or do I need to start blocking people from being able to use their own custom images?</p>
<p>If it helps any, it's done in PHP/MySQL.</p>
| [
{
"answer_id": 322865,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 3,
"selected": false,
"text": "<?php\n$image = imagecreatefrompng(\"http://stackoverflow.com/Content/Img/stackoverflow-logo-250.png\");\n$font_size = 12;\n$color = imagecolorallocate($image, 0,0,0);\nImageTTFText ($image, $font_size, 0, 55, 35, $color, \"arial.ttf\",$_SERVER['REMOTE_ADDR']);\nheader(\"Content-type: image/png\");\nimagepng($image);\nimagedestroy($image);\n?>\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2227/"
] |
322,612 | <p>This question intends to provide a list of solutions to common pitfalls, "gotcha's", or design issues when developing WPF applications. This can also include proper design-patterns as long as there is an explanation as to why it works best. Responses should be voted up or down based on how common the type of issue is. Here are the rules:</p>
<ul>
<li>One response per post. This will clearly give the most common issues the highest ranking.</li>
<li>It would be best to provide the link to the a related post or solution already living somewhere in SO land.</li>
</ul>
| [
{
"answer_id": 322647,
"author": "Micah",
"author_id": 17744,
"author_profile": "https://Stackoverflow.com/users/17744",
"pm_score": 1,
"selected": false,
"text": "<Window x:Name=\"MyWindow\"....>\n <TextBlock Text=\"{Binding Path=PropertyDefinedInMyWindow}\" />\n</Window>\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17744/"
] |
322,614 | <p>I have the following Linq to SQL query, in which I'm trying to do a multi-column GROUP BY:</p>
<pre><code>return from revision in dataContext.Revisions
where revision.BranchID == sourceBranch.BranchID-1
&& !revision.HasBeenMerged
group revision by new Task(revision.TaskSourceCode.ToUpper(),
revision.TaskSourceID)
into grouping
orderby grouping.Key ascending
select (ITask)grouping.Key;
</code></pre>
<p>This throws InvalidOperationException ("Cannot order by type 'Task'.").</p>
<p>Is there an interface that Task must implement (it <em>already</em> implements IComparable, IComparable<ITask>)? Does Task need to be a Linq to SQL Entity (it isn't, currently, since there's no corresponding table). Or is this just something that Linq to SQL doesn't support?</p>
<p>Note that I've already tried an anonymous type for the grouping, which failed with a similar InvalidOperationException:</p>
<pre><code>...
group revision by new { Code = revision.TaskSourceCode.ToUpper(),
Id = revision.TaskSourceID }
...
</code></pre>
<p>For what it's worth, note that the Task object is a composite of 2 fields; one is a single character (typically 'S' or 'B') and the other is an int (actually a cross-database "foreign key" if you like). The act of ordering by Tasks just compares their string representations; E.G. Task 'B101' < Task 'S999'</p>
| [
{
"answer_id": 322675,
"author": "Matt Campbell",
"author_id": 41110,
"author_profile": "https://Stackoverflow.com/users/41110",
"pm_score": 2,
"selected": false,
"text": "return from revision in dataContext.Revisions\n where revision.BranchID == sourceBranch.BranchID-1\n && !revision.HasBeenMerged\n group revision by new { revision.TaskSourceCode, \n revision.TaskSourceID }\n into grouping\n orderby grouping.Key.TaskSourceCode, \n grouping.Key.TaskSourceID ascending\n select (ITask)new Task(grouping.Key.TaskSourceCode, \n grouping.Key.TaskSourceID);\n"
},
{
"answer_id": 322744,
"author": "Lee Richardson",
"author_id": 40783,
"author_profile": "https://Stackoverflow.com/users/40783",
"pm_score": 2,
"selected": true,
"text": ".ToUpper()"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322614",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41110/"
] |
322,657 | <p>In jQuery, how do you select the <code><a></code> which href is pointing to the current URL</p>
<p>For example:<br>
URL = <a href="http://server/dir/script.aspx?id=1" rel="nofollow noreferrer">http://server/dir/script.aspx?id=1</a></p>
<p>I want to select this <code><a></code><br>
<code><a href="/dir/script.aspx">...</a></code></p>
<p>I tried this but it doesn't work:</p>
<pre><code>var url = window.location.href;
$('#ulTopMenu a["'+url+'"*=href]').addClass("selected");
</code></pre>
<p>Probably wrong syntax. Anyone know the right way of doing it?</p>
<p>Thanks in advance</p>
| [
{
"answer_id": 322667,
"author": "Danny",
"author_id": 26630,
"author_profile": "https://Stackoverflow.com/users/26630",
"pm_score": 1,
"selected": false,
"text": "'#ulTopMenu a[\"http://www.foo.com\"*=href]'\n"
},
{
"answer_id": 322680,
"author": "Remy Sharp",
"author_id": 22617,
"author_profile": "https://Stackoverflow.com/users/22617",
"pm_score": 2,
"selected": false,
"text": "var nav = location.pathname.substr(1).split('/', 2)[0] || '/';\nif (nav) {\n $('#ulTopMenu a[href$=\"' + nav + '\"]').parent().addClass('selected');\n}\n"
},
{
"answer_id": 322825,
"author": "Aximili",
"author_id": 36036,
"author_profile": "https://Stackoverflow.com/users/36036",
"pm_score": 1,
"selected": true,
"text": " var scriptname = GetUrlScriptname();\n $('#ulTopMenu a[href$=\"' + scriptname + '\"]').parent().addClass('selected');\n\nfunction GetUrlScriptname()\n{\n var rex = new RegExp(\"\\\\/[^\\\\/]+\\\\.\\\\w+($|\\\\?)\");\n var match = rex.exec(location.pathname);\n return match[0].substring(1);\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322657",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36036/"
] |
322,659 | <p>This is a problem I'm sure is easy to fix, but I've been banging my head on it all day.</p>
<p>I'm developing a new web site for a client. The web site resides at (this is an example) website.com. I have a PHP form script to email visitors' requests to requests@website.com.</p>
<p>When I coded this on a staging server on a different domain, all worked fine. When I moved it to website.com, the mail messages never arrived. The web server is on a virtual host with a major ISP.</p>
<p>Here's what I've learned since then: My client's mail server is Microsoft Exchange on a box physically in their office. Whenever someone on the outside world emails requests@website.com, the mail arrives. <em>But</em> if the web server sends to the same email address, it fails every time. This is <strong>not</strong> a PHP problem. I secure shell in to the web server and have tested this both with sendmail and the UNIX mail application. I've also tested it by emailing various email accounts from the shell. I can email myself, for example, just nobody at the website.com domain.</p>
<p>In short, when I'm logged in to website.com, mail to requests@website.com, user@website.com, another_user@website.com all fail. All other addresses work fine. What I've discovered is those dropped emails are routed to the web server's "catchall" account where they sit in its inbox.</p>
<p>I've done an MX lookup on website.com. The MX record points to mailsec.website.com. I can telnet to mailsec.website.com port 25 and see the SMTP server.</p>
<p>It appears to me that website.com isn't doing an MX lookup when it's sending mail to requests@website.com. My theory is that it recognizes the domain as local, sees that there's no "requests" user account to deliver it to, and drops the mail into the catchall account. What I want is to force sendmail to do the MX lookup and send the message on to the Exchange server. I'm at wit's end here. I can't figure out how to do this.</p>
<p>For that matter, I may be way off base here and have misdiagnosed this entirely. Internet mail and MX has always seemed a black art to me, and my ignorance is certainly showing in this question.</p>
| [
{
"answer_id": 705535,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "FEATURE(relay_entire_domain) \n"
},
{
"answer_id": 15247091,
"author": "AnFi",
"author_id": 2139766,
"author_profile": "https://Stackoverflow.com/users/2139766",
"pm_score": 2,
"selected": false,
"text": "define(`confDONT_PROBE_INTERFACES',`True')\n"
},
{
"answer_id": 30550473,
"author": "Glauco Cattalini Lins",
"author_id": 4956999,
"author_profile": "https://Stackoverflow.com/users/4956999",
"pm_score": 0,
"selected": false,
"text": "sudo yum install sendmail-cf\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32168/"
] |
322,689 | <p>I'm using Parsley IoC in my current Flex project. So I'd like to embed the container configuration XML onto the result SWF. </p>
<p>How could I load embedded XML file into action script XML object?</p>
| [
{
"answer_id": 705535,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "FEATURE(relay_entire_domain) \n"
},
{
"answer_id": 15247091,
"author": "AnFi",
"author_id": 2139766,
"author_profile": "https://Stackoverflow.com/users/2139766",
"pm_score": 2,
"selected": false,
"text": "define(`confDONT_PROBE_INTERFACES',`True')\n"
},
{
"answer_id": 30550473,
"author": "Glauco Cattalini Lins",
"author_id": 4956999,
"author_profile": "https://Stackoverflow.com/users/4956999",
"pm_score": 0,
"selected": false,
"text": "sudo yum install sendmail-cf\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2313/"
] |
322,699 | <p>Given an array of items, each of which has a <code>value</code> and <code>cost</code>, <strong>what's the best algorithm determine the items required to reach a minimum value at the minimum cost?</strong> eg:</p>
<pre><code>Item: Value -> Cost
-------------------
A 20 -> 11
B 7 -> 5
C 1 -> 2
MinValue = 30
naive solution: A + B + C + C + C. Value: 30, Cost 22
best option: A + B + B. Value: 34, Cost 21
</code></pre>
<p>Note that the overall value:cost ratio at the end is irrelevant (<code>A + A</code> would give you the best value for money, but <code>A + B + B</code> is a cheaper option which hits the minimum value).</p>
| [
{
"answer_id": 322714,
"author": "ShreevatsaR",
"author_id": 4958,
"author_profile": "https://Stackoverflow.com/users/4958",
"pm_score": 4,
"selected": true,
"text": "best[0] = 0\nbest[v] = min_(items i){cost[i] + best[v-value[i]]}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
322,701 | <p>I have a database of companies. My application receives data that references a company by name, but the name may not exactly match the value in the database. I need to match the incoming data to the company it refers to.</p>
<p>For instance, my database might contain a company with name "A. B. Widgets & Co Ltd." while my incoming data might reference "AB Widgets Limited", "A.B. Widgets and Co", or "A B Widgets".</p>
<p>Some words in the company name (A B Widgets) are more important for matching than others (Co, Ltd, Inc, etc). It's important to avoid false matches.</p>
<p>The number of companies is small enough that I can maintain a map of their names in memory, ie. I have the option of using Java rather than SQL to find the right name.</p>
<p>How would you do this in Java?</p>
| [
{
"answer_id": 2670818,
"author": "charpentier damien",
"author_id": 320764,
"author_profile": "https://Stackoverflow.com/users/320764",
"pm_score": 0,
"selected": false,
"text": "* LCS code\n* Example usage (guessing a category based on what people entered)\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37134/"
] |
322,709 | <p>We use memcache basically as an after thought to just cache query results.</p>
<p>Invalidation is a nightmare due to the way it was implemented. We since learned some techniques with memcache thru reading the mailing list, for example the trick to allow group invalidation of a bunch of keys. For those who know it, skip the next paragraph..</p>
<p>For those who don't know and are interested, the trick is adding a sequence number to your keys and storing that sequence number in memcache. Then every time before you do your "get" you grab the current sequence number and build your keys around that. Then, to invalidate the whole group you just increment that sequence number.</p>
<p>So anyway, I'm currently revising our model to implement this.</p>
<p>My question is..</p>
<p>We didn't know about this pattern, and I'm sure there are others we don't know about. I've searched and haven't been able to find any design patterns on the web for implementing memcache, best practices, etc.</p>
<p>Can someone point me to something like this or even just write up an example? I would like to make sure we don't make a beginners mistake in our new refactoring.</p>
| [
{
"answer_id": 322913,
"author": "Akeem",
"author_id": 35505,
"author_profile": "https://Stackoverflow.com/users/35505",
"pm_score": 2,
"selected": false,
"text": "public function getBySlug($ignoreCache = true)\n{\n if($ignoreCache || !$result = $this->cache->load('someKeyBasedOnQuery'))\n {\n $select = $this->select()\n ->where('slug = ?', $slug);\n $result = $this->fetchRow($select);\n\n try\n {\n $this->cache->save($result,'someKeyBasedOnQuery');\n }\n catch(Zend_Exception $error)\n {\n //log exception\n }\n }\n else\n {\n $this->registry->logger->info('someKeyBasedOnQuery came from cache');\n }\n return $result;\n\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
322,715 | <p>I've always been one to simply use:</p>
<pre><code>List<String> names = new ArrayList<>();
</code></pre>
<p>I use the interface as the type name for <em>portability</em>, so that when I ask questions such as this, I can rework my code.</p>
<p>When should <a href="https://docs.oracle.com/javase/9/docs/api/java/util/LinkedList.html" rel="noreferrer"><code>LinkedList</code></a> be used over <a href="https://docs.oracle.com/javase/9/docs/api/java/util/ArrayList.html" rel="noreferrer"><code>ArrayList</code></a> and vice-versa?</p>
| [
{
"answer_id": 322722,
"author": "dgtized",
"author_id": 34450,
"author_profile": "https://Stackoverflow.com/users/34450",
"pm_score": 6,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 322728,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 5,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 322729,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 4,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 322737,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 4,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 322742,
"author": "Jonathan Tran",
"author_id": 12887,
"author_profile": "https://Stackoverflow.com/users/12887",
"pm_score": 13,
"selected": true,
"text": "ArrayList"
},
{
"answer_id": 323889,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 8,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 324953,
"author": "Jesse Wilson",
"author_id": 40013,
"author_profile": "https://Stackoverflow.com/users/40013",
"pm_score": 5,
"selected": false,
"text": "add(0)"
},
{
"answer_id": 2496245,
"author": "Karussell",
"author_id": 194609,
"author_profile": "https://Stackoverflow.com/users/194609",
"pm_score": 3,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 2603253,
"author": "Michael Munsey",
"author_id": 284830,
"author_profile": "https://Stackoverflow.com/users/284830",
"pm_score": 7,
"selected": false,
"text": "Algorithm ArrayList LinkedList\nseek front O(1) O(1)\nseek back O(1) O(1)\nseek to index O(1) O(N)\ninsert at front O(N) O(1)\ninsert at back O(1) O(1)\ninsert after an item O(N) O(1)\n"
},
{
"answer_id": 7507740,
"author": "Ash",
"author_id": 890381,
"author_profile": "https://Stackoverflow.com/users/890381",
"pm_score": 6,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 7671021,
"author": "Numeron",
"author_id": 707399,
"author_profile": "https://Stackoverflow.com/users/707399",
"pm_score": 9,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 10977140,
"author": "Ilya Gazman",
"author_id": 1129332,
"author_profile": "https://Stackoverflow.com/users/1129332",
"pm_score": -1,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 13253191,
"author": "Rajith Delantha",
"author_id": 1490555,
"author_profile": "https://Stackoverflow.com/users/1490555",
"pm_score": 4,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 16099449,
"author": "Ajax",
"author_id": 1218010,
"author_profile": "https://Stackoverflow.com/users/1218010",
"pm_score": 5,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 16126564,
"author": "Ryan",
"author_id": 127859,
"author_profile": "https://Stackoverflow.com/users/127859",
"pm_score": 6,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 37768332,
"author": "pietz",
"author_id": 5197034,
"author_profile": "https://Stackoverflow.com/users/5197034",
"pm_score": 2,
"selected": false,
"text": "remove()"
},
{
"answer_id": 40375897,
"author": "Real73",
"author_id": 6168802,
"author_profile": "https://Stackoverflow.com/users/6168802",
"pm_score": 3,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 48894817,
"author": "Randhawa",
"author_id": 8638323,
"author_profile": "https://Stackoverflow.com/users/8638323",
"pm_score": 2,
"selected": false,
"text": "arraylist.get()"
},
{
"answer_id": 50739053,
"author": "Anjali Suman",
"author_id": 9902873,
"author_profile": "https://Stackoverflow.com/users/9902873",
"pm_score": 3,
"selected": false,
"text": "add()"
},
{
"answer_id": 51688647,
"author": "Jose Martinez",
"author_id": 1490322,
"author_profile": "https://Stackoverflow.com/users/1490322",
"pm_score": 2,
"selected": false,
"text": "LinkedList"
},
{
"answer_id": 52885253,
"author": "Lior Bar-On",
"author_id": 3834036,
"author_profile": "https://Stackoverflow.com/users/3834036",
"pm_score": 6,
"selected": false,
"text": "ArrayList"
},
{
"answer_id": 54181945,
"author": "Gayan",
"author_id": 3647002,
"author_profile": "https://Stackoverflow.com/users/3647002",
"pm_score": 5,
"selected": false,
"text": "|---------------------|---------------------|--------------------|------------|\n| Operation | ArrayList | LinkedList | Winner |\n|---------------------|---------------------|--------------------|------------|\n| get(index) | O(1) | O(n) | ArrayList |\n| | | n/4 steps in avg | |\n|---------------------|---------------------|--------------------|------------|\n| add(E) | O(1) | O(1) | LinkedList |\n| |---------------------|--------------------| |\n| | O(n) in worst case | | |\n|---------------------|---------------------|--------------------|------------|\n| add(index, E) | O(n) | O(n) | LinkedList |\n| | n/2 steps | n/4 steps | |\n| |---------------------|--------------------| |\n| | | O(1) if index = 0 | |\n|---------------------|---------------------|--------------------|------------|\n| remove(index, E) | O(n) | O(n) | LinkedList |\n| |---------------------|--------------------| |\n| | n/2 steps | n/4 steps | |\n|---------------------|---------------------|--------------------|------------|\n| Iterator.remove() | O(n) | O(1) | LinkedList |\n| ListIterator.add() | | | |\n|---------------------|---------------------|--------------------|------------|\n\n\n|--------------------------------------|-----------------------------------|\n| ArrayList | LinkedList |\n|--------------------------------------|-----------------------------------|\n| Allows fast read access | Retrieving element takes O(n) |\n|--------------------------------------|-----------------------------------|\n| Adding an element require shifting | o(1) [but traversing takes time] |\n| all the later elements | |\n|--------------------------------------|-----------------------------------|\n| To add more elements than capacity |\n| new array need to be allocated |\n|--------------------------------------|\n"
},
{
"answer_id": 58313753,
"author": "Sina Madani",
"author_id": 5870336,
"author_profile": "https://Stackoverflow.com/users/5870336",
"pm_score": 0,
"selected": false,
"text": "Collection"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322715",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41200/"
] |
322,719 | <p>Whenever I list the contents of a directory with a function like readdir, the returned file names also include "." and "..". I have the suspicion that these are just normal links in the file system and therefore indistinguishable from actual files, but I always have to filter them out because they are not actual objects in the directory I am listing. Is there a good reason for functions like readdir to include them? Do some operating systems or file systems contain more or different virtual file names? Is there a better way to filter them out other than by doing string comparison with "." and ".."?</p>
<p>Update: thank you all for answering. I suppose I always thought that things like ./ and ../ were mere conventions that could be handled by searching and replacing. I find it a bit surprising, though probably more efficient and transparent, to have them be part of the file system itself.</p>
<p>One question remains, though: since . and .. are arbitrary names for these links, are there file systems that use different ones?</p>
| [
{
"answer_id": 322734,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 2,
"selected": false,
"text": "./run_this\n"
},
{
"answer_id": 322736,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": ".."
},
{
"answer_id": 322741,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 5,
"selected": true,
"text": "."
},
{
"answer_id": 322745,
"author": "Adam Jaskiewicz",
"author_id": 35322,
"author_profile": "https://Stackoverflow.com/users/35322",
"pm_score": 0,
"selected": false,
"text": "grep { not /^.{1,2}\\z/ } readdir HANDLE"
},
{
"answer_id": 322773,
"author": "Svante",
"author_id": 31615,
"author_profile": "https://Stackoverflow.com/users/31615",
"pm_score": 2,
"selected": false,
"text": "."
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9454/"
] |
322,747 | <p>When I look at Amazon.com and I see their URL for pages, it does not have <code>.htm</code>, <code>.html</code> or <code>.php</code> at the end of the URL.</p>
<p>It is like:<br>
<a href="http://www.amazon.com/books-used-books-textbooks/b/ref=topnav_storetab_b?ie=UTF8&node=283155" rel="noreferrer">http://www.amazon.com/books-used-books-textbooks/b/ref=topnav_storetab_b?ie=UTF8&node=283155</a></p>
<p>Why and how? What kind of extension is that?</p>
| [
{
"answer_id": 322771,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": -1,
"selected": false,
"text": "/news/<number>/"
},
{
"answer_id": 322861,
"author": "Paul Fisher",
"author_id": 39808,
"author_profile": "https://Stackoverflow.com/users/39808",
"pm_score": 3,
"selected": false,
"text": "Content-type"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40091/"
] |
322,749 | <pre><code>public class doublePrecision {
public static void main(String[] args) {
double total = 0;
total += 5.6;
total += 5.8;
System.out.println(total);
}
}
</code></pre>
<p>The above code prints:</p>
<pre class="lang-none prettyprint-override"><code>11.399999999999
</code></pre>
<p>How would I get this to just print (or be able to use it as) 11.4?</p>
| [
{
"answer_id": 322853,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 4,
"selected": false,
"text": "java.util.Formatter"
},
{
"answer_id": 322875,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 8,
"selected": true,
"text": "BigDecimal"
},
{
"answer_id": 322897,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 3,
"selected": false,
"text": "System.out.printf(\"%.2f\\n\", total);\n"
},
{
"answer_id": 2466584,
"author": "Dark Castle",
"author_id": 277160,
"author_profile": "https://Stackoverflow.com/users/277160",
"pm_score": 0,
"selected": false,
"text": "term[number].coefficient.add(co);\n"
},
{
"answer_id": 2466914,
"author": "Stephen Canon",
"author_id": 142434,
"author_profile": "https://Stackoverflow.com/users/142434",
"pm_score": 7,
"selected": false,
"text": "33.33333333333333"
},
{
"answer_id": 2467007,
"author": "Vinny",
"author_id": 264669,
"author_profile": "https://Stackoverflow.com/users/264669",
"pm_score": 3,
"selected": false,
"text": "import java.math.BigDecimal;\n/**\n * Created by a wonderful programmer known as:\n * Vincent Stoessel\n * xaymaca@gmail.com\n * on Mar 17, 2010 at 11:05:16 PM\n */\npublic class BigUp {\n\n public static void main(String[] args) {\n BigDecimal first, second, result ;\n first = new BigDecimal(\"33.33333333333333\") ;\n second = new BigDecimal(\"100\") ;\n result = first.divide(second);\n System.out.println(\"result is \" + result);\n //will print : result is 0.3333333333333333\n\n\n }\n}\n"
},
{
"answer_id": 2467009,
"author": "Viral Shah",
"author_id": 228276,
"author_profile": "https://Stackoverflow.com/users/228276",
"pm_score": 5,
"selected": false,
"text": "public class Fraction {\n\nprivate int numerator;\nprivate int denominator;\n\npublic Fraction(int n, int d){\n numerator = n;\n denominator = d;\n}\n\npublic double toDouble(){\n return ((double)numerator)/((double)denominator);\n}\n\n\npublic static Fraction add(Fraction a, Fraction b){\n if(a.denominator != b.denominator){\n double aTop = b.denominator * a.numerator;\n double bTop = a.denominator * b.numerator;\n return new Fraction(aTop + bTop, a.denominator * b.denominator);\n }\n else{\n return new Fraction(a.numerator + b.numerator, a.denominator);\n }\n}\n\npublic static Fraction divide(Fraction a, Fraction b){\n return new Fraction(a.numerator * b.denominator, a.denominator * b.numerator);\n}\n\npublic static Fraction multiply(Fraction a, Fraction b){\n return new Fraction(a.numerator * b.numerator, a.denominator * b.denominator);\n}\n\npublic static Fraction subtract(Fraction a, Fraction b){\n if(a.denominator != b.denominator){\n double aTop = b.denominator * a.numerator;\n double bTop = a.denominator * b.numerator;\n return new Fraction(aTop-bTop, a.denominator*b.denominator);\n }\n else{\n return new Fraction(a.numerator - b.numerator, a.denominator);\n }\n}\n\n}\n"
},
{
"answer_id": 2881915,
"author": "Maciek D.",
"author_id": 724873,
"author_profile": "https://Stackoverflow.com/users/724873",
"pm_score": -1,
"selected": false,
"text": "System.out.printf(\"%.2f\\n\", total);\n"
},
{
"answer_id": 8416233,
"author": "sravan",
"author_id": 759012,
"author_profile": "https://Stackoverflow.com/users/759012",
"pm_score": 3,
"selected": false,
"text": "private void getRound() {\n // this is very simple and interesting \n double a = 5, b = 3, c;\n c = a / b;\n System.out.println(\" round val is \" + c);\n\n // round val is : 1.6666666666666667\n // if you want to only two precision point with double we \n // can use formate option in String \n // which takes 2 parameters one is formte specifier which \n // shows dicimal places another double value \n String s = String.format(\"%.2f\", c);\n double val = Double.parseDouble(s);\n System.out.println(\" val is :\" + val);\n // now out put will be : val is :1.67\n}\n"
},
{
"answer_id": 33710380,
"author": "Mr.Cat",
"author_id": 3570276,
"author_profile": "https://Stackoverflow.com/users/3570276",
"pm_score": 1,
"selected": false,
"text": "// The number of 0s determines how many digits you want after the floating point\n// (here one digit)\ntotal = (double)Math.round(total * 10) / 10;\nSystem.out.println(total); // prints 11.4\n"
},
{
"answer_id": 50212621,
"author": "user5734382",
"author_id": 5734382,
"author_profile": "https://Stackoverflow.com/users/5734382",
"pm_score": 0,
"selected": false,
"text": "public static double sumDouble(double value1, double value2) {\n double sum = 0.0;\n String value1Str = Double.toString(value1);\n int decimalIndex = value1Str.indexOf(\".\");\n int value1Precision = 0;\n if (decimalIndex != -1) {\n value1Precision = (value1Str.length() - 1) - decimalIndex;\n }\n\n String value2Str = Double.toString(value2);\n decimalIndex = value2Str.indexOf(\".\");\n int value2Precision = 0;\n if (decimalIndex != -1) {\n value2Precision = (value2Str.length() - 1) - decimalIndex;\n }\n\n int maxPrecision = value1Precision > value2Precision ? value1Precision : value2Precision;\n sum = value1 + value2;\n String s = String.format(\"%.\" + maxPrecision + \"f\", sum);\n sum = Double.parseDouble(s);\n return sum;\n}\n"
},
{
"answer_id": 58065988,
"author": "jackycflau",
"author_id": 5348990,
"author_profile": "https://Stackoverflow.com/users/5348990",
"pm_score": 2,
"selected": false,
"text": "public class doublePrecision {\n public static void main(String[] args) {\n BigDecimal total = new BigDecimal(\"0\");\n total = total.add(new BigDecimal(\"5.6\"));\n total = total.add(new BigDecimal(\"5.8\"));\n System.out.println(total);\n }\n}\n"
},
{
"answer_id": 63953941,
"author": "Harry Zhang",
"author_id": 2843451,
"author_profile": "https://Stackoverflow.com/users/2843451",
"pm_score": 2,
"selected": false,
"text": " /*\n 0.8 1.2\n 0.7 1.3\n 0.7000000000000002 2.3\n 0.7999999999999998 4.2\n */\n double adjust = fToInt + 1.0 - orgV;\n \n // The following two lines works for me. \n String s = String.format(\"%.2f\", adjust);\n double val = Double.parseDouble(s);\n\n System.out.println(val); // output: 0.8, 0.7, 0.7, 0.8\n"
},
{
"answer_id": 69608022,
"author": "Vimal Raj",
"author_id": 6286397,
"author_profile": "https://Stackoverflow.com/users/6286397",
"pm_score": 0,
"selected": false,
"text": "System.out.println(String.format(\"%.12f\", total));\n"
},
{
"answer_id": 72439165,
"author": "Hiro",
"author_id": 3545530,
"author_profile": "https://Stackoverflow.com/users/3545530",
"pm_score": 0,
"selected": false,
"text": "double"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5219/"
] |
322,769 | <p>Imagine you have an executable foo.rb, with libraries bar.rb layed out in the following manner:</p>
<pre><code><root>/bin/foo.rb
<root>/lib/bar.rb
</code></pre>
<p>In the header of foo.rb you place the following require to bring in functionality in bar.rb:</p>
<pre><code>require File.dirname(__FILE__)+"../lib/bar.rb"
</code></pre>
<p>This works fine so long as all calls to foo.rb are direct. If you put as say $HOME/project, and symlink foo.rb into <code>$HOME/usr/bin</code>, then <code><code>__FILE__</code></code> resolves to <code>$HOME/usr/bin/foo.rb</code>, and is thus unable to locate <code>bar.rb</code> in relation to the dirname for <code>foo.rb</code>.</p>
<p>I realize that packaging systems such as rubygems fix this by creating a namespace to search for the library, and that it is also possible to adjust the load_path using <code>$:</code> to include <code>$HOME/project/lib</code>, but it seems as if a more simple solution should exist. Has anyone had experience with this problem and found a useful solution or recipe?</p>
| [
{
"answer_id": 323455,
"author": "Phil Ross",
"author_id": 5981,
"author_profile": "https://Stackoverflow.com/users/5981",
"pm_score": 2,
"selected": false,
"text": "def follow_link(file)\n file = File.expand_path(file)\n\n while File.symlink?(file)\n file = File.expand_path(File.readlink(file), File.dirname(file))\n end\n\n file\nend\n\nputs follow_link(__FILE__)\n"
},
{
"answer_id": 769880,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": true,
"text": "require 'pathname'\nAPP_ROOT = File.join(File.dirname(Pathname.new(__FILE__).realpath),'..')\n"
},
{
"answer_id": 2673979,
"author": "dolzenko",
"author_id": 54247,
"author_profile": "https://Stackoverflow.com/users/54247",
"pm_score": 1,
"selected": false,
"text": "+"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34450/"
] |
322,781 | <p>I'm writing an HTML form generation library. There's a top-level Form class, and at the bottom there are classes for each type of HTML form input object (Select, Textfield, Radio, etc.). There's a class in between, that holds groupings of 1 or more semantically related input objects.</p>
<p>For example, one type of this class could be called 'Login', and would contain a Textfield input and a Password input. As another example, the primary usage of the form library will be to generate online surveys, so the intermediate classes will be survey questions of various sorts.</p>
<p>My question is what to generically call these intermediate level classes. Some of the things that have been suggested within our working group are 'Set', 'Fieldset', 'Group', 'Block', 'Chunk', and 'Conglomeration'. </p>
<p>Several of these suggestions are "okay", but none of them have tripped the "that's it!" interrupt. (The one that came closest is the latter, but that's (a) far too long and (b) too subject to mispeling.) Does anyone have any better suggestions?</p>
| [
{
"answer_id": 322873,
"author": "Dave K",
"author_id": 19864,
"author_profile": "https://Stackoverflow.com/users/19864",
"pm_score": 1,
"selected": false,
"text": "<input type=\"text\" /> <input type=\"password\"/>\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39933/"
] |
322,784 | <p>I'm playing with Java for the first time and need to be able to replace some words in a template. example template - </p>
<p>"Dear PUT_THEIR_NAME_HERE,</p>
<p>I'm contacting you ..... bla bla bla</p>
<p>Regards,</p>
<p>PUT_COMPANY_NAME_HERE"</p>
<p>What's the simplest way (preferably using the standard library) to make a copy of this template file and add the correct words at the correct place then save it to the file system? I have to do many such simple templates so a way that can be easily replicated would be nice.</p>
<p>I'm also accessing Java through JavaScript using Rhino, not sure if this makes any difference or not.</p>
<p>Regards,</p>
<p>Chris</p>
| [
{
"answer_id": 322810,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 2,
"selected": false,
"text": "C:\\oreyes\\samples\\java\\replace>type Simplistic.java\npublic class Simplistic{\n public static void main( String [] args ) {\n String template = \"Dear _NAME_HERE_. I'm glad you...\";\n System.out.println( template.replaceAll(\"_NAME_HERE_\",\"Oscar Reyes\"));\n }\n}\n\nC:\\oreyes\\samples\\java\\replace>java Simplistic\nDear Oscar Reyes. I'm glad you...\n"
},
{
"answer_id": 322820,
"author": "Nerdfest",
"author_id": 7855,
"author_profile": "https://Stackoverflow.com/users/7855",
"pm_score": 4,
"selected": false,
"text": " Object[] arguments = {\n new Integer(7),\n new Date(System.currentTimeMillis()),\n \"a disturbance in the Force\"\n };\n\n String result = MessageFormat.format(\n \"At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.\",\n arguments);\n\n output: At 12:30 PM on Jul 3, 2053, there was a disturbance\n in the Force on planet 7.\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37196/"
] |
322,792 | <p>I've been working on a program to read a dbf file, mess around with the data, and save it back to dbf. The problem that I am having is specifically to do with the writing portion.</p>
<pre><code> private const string constring = "Driver={Microsoft dBASE Driver (*.dbf)};"
+ "SourceType=DBF;"
+ "DriverID=277;"
+ "Data Source=¿;"
+ "Extended Properties=dBASE IV;";
private const string qrystring = "SELECT * FROM [¿]";
public static DataTable loadDBF(string location)
{
string filename = ConvertLongPathToShort(Path.GetFileName(location));
DataTable table = new DataTable();
using(OdbcConnection conn = new OdbcConnection(RTN(constring, filename)))
{
conn.Open();
table.Load(new OdbcCommand(RTN(qrystring, filename), conn).ExecuteReader());
conn.Close();
}
return table;
}
private static string RTN(string stmt, string tablename)
{ return stmt.Replace("¿", tablename); }
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(
String path, // input string
StringBuilder shortPath, // output string
Int32 shortPathLength); // StringBuilder.Capacity
public static string ConvertLongPathToShort(string longPathName)
{
StringBuilder shortNameBuffer;
int size;
shortNameBuffer = new StringBuilder();
size = GetShortPathName(longPathName, shortNameBuffer, shortNameBuffer.Capacity);
if (size >= shortNameBuffer.Capacity)
{
shortNameBuffer.Capacity = size + 1;
GetShortPathName(longPathName, shortNameBuffer, shortNameBuffer.Capacity);
}
return shortNameBuffer.ToString();
}
</code></pre>
<p>This is what I'm working with. I've tried a number of methods to write a new file, none of them productive. To be honest, while normally I would be an advocate of form and function, I just want the damn thing to work, this app is supposed to do one very specific thing, it's not going to simulate weather.</p>
<p>-=# Edit #=-</p>
<p>I've since discontinued the app due to time pressure, but before I scrapped it I realised that the particular format of dbf I was working with had no primary key information. This of course meant that I had to essentially read the data out to DataTable, mess with it, then wipe all the records in the dbf and insert everything from scratch.
Screw that for a lark.</p>
| [
{
"answer_id": 17930567,
"author": "HeyThereLameMan",
"author_id": 2124469,
"author_profile": "https://Stackoverflow.com/users/2124469",
"pm_score": 4,
"selected": true,
"text": " public static void DataSetIntoDBF(string fileName, DataSet dataSet)\n {\n ArrayList list = new ArrayList();\n\n if (File.Exists(Path + fileName + \".dbf\"))\n {\n File.Delete(Path + fileName + \".dbf\");\n }\n\n string createSql = \"create table \" + fileName + \" (\";\n\n foreach (DataColumn dc in dataSet.Tables[0].Columns)\n {\n string fieldName = dc.ColumnName;\n\n string type = dc.DataType.ToString();\n\n switch (type)\n {\n case \"System.String\":\n type = \"varchar(100)\";\n break;\n\n case \"System.Boolean\":\n type = \"varchar(10)\";\n break;\n\n case \"System.Int32\":\n type = \"int\";\n break;\n\n case \"System.Double\":\n type = \"Double\";\n break;\n\n case \"System.DateTime\":\n type = \"TimeStamp\";\n break;\n }\n\n createSql = createSql + \"[\" + fieldName + \"]\" + \" \" + type + \",\";\n\n list.Add(fieldName);\n }\n\n createSql = createSql.Substring(0, createSql.Length - 1) + \")\";\n\n OleDbConnection con = new OleDbConnection(GetConnection(Path));\n\n OleDbCommand cmd = new OleDbCommand();\n\n cmd.Connection = con;\n\n con.Open();\n\n cmd.CommandText = createSql;\n\n cmd.ExecuteNonQuery();\n\n foreach (DataRow row in dataSet.Tables[0].Rows)\n {\n string insertSql = \"insert into \" + fileName + \" values(\";\n\n for (int i = 0; i < list.Count; i++)\n {\n insertSql = insertSql + \"'\" + ReplaceEscape(row[list[i].ToString()].ToString()) + \"',\";\n }\n\n insertSql = insertSql.Substring(0, insertSql.Length - 1) + \")\";\n\n cmd.CommandText = insertSql;\n\n cmd.ExecuteNonQuery();\n }\n\n con.Close();\n }\n\n private static string GetConnection(string path)\n {\n return \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\" + path + \";Extended Properties=dBASE IV;\";\n }\n\n public static string ReplaceEscape(string str)\n {\n str = str.Replace(\"'\", \"''\");\n return str;\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41223/"
] |
322,797 | <p>I have an application that was developed for Linux x86 32 bits. There are lots of floating-point operations and a lot of tests depending on the results. Now we are porting it to x86_64, but the test results are different in this architecture. We don't want to keep a separate set of results for each architecture.</p>
<p>According to the article <em><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_70.html" rel="nofollow noreferrer">An Introduction to GCC - for the GNU compilers gcc and g++</a></em> the problem is that GCC in X86_64 assumes <strong>fpmath=sse</strong> while x86 assumes <strong>fpmath=387</strong>. The 387 FPU uses <strong>80 bit internal precision</strong> for all operations and only convert the result to a given floating-point type (float, double or long double) while SSE uses the type of the operands to determine its internal precision.</p>
<p>I can <strong>force -mfpmath=387</strong> when compiling my own code and all my operations work correctly, but whenever I call some library function (sin, cos, atan2, etc.) the results are wrong again. I assume it's because <strong>libm</strong> was compiled without the fpmath override.</p>
<p>I tried to build libm myself (glibc) using 387 emulation, but it caused a lot of crashes all around (don't know if I did something wrong).</p>
<p>Is there a way to force all code in a process to use the 387 emulation in x86_64? Or maybe some library that returns the same values as libm does on both architectures? Any suggestions?</p>
<p>Regarding the question of "Do you need the 80 bit precision", I have to say that this is not a problem for an individual operation. In this simple case the difference is really small and makes no difference. When compounding a lot of operations, though, the error propagates and the difference in the final result is not so small any more and makes a difference. So I guess I need the 80 bit precision.</p>
| [
{
"answer_id": 6512549,
"author": "R.. GitHub STOP HELPING ICE",
"author_id": 379897,
"author_profile": "https://Stackoverflow.com/users/379897",
"pm_score": 2,
"selected": false,
"text": "long double"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13459/"
] |
322,837 | <p>I want to do this, but haven't figured it quite out yet...</p>
<pre><code> $(document).ready(function() {
$("a.whateverclass").click(function() {
$("div.whateverclass").show();
return false;
});
</code></pre>
<p>Basically when a link with a certain class is clicked all divs with that class are shown. The classes can be any class. And I won't know the name(s) of the classes in the application.js file so I need to match equal classes.</p>
| [
{
"answer_id": 322844,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 1,
"selected": false,
"text": "$(\"a\").click(function() {\n $(\"div.\" + $(this).attr('class')).show();\n});\n"
},
{
"answer_id": 322856,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "$('a[class]').click(function() {\n $('div.' + $(this).attr('class')).show();\n return false;\n});\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34133/"
] |
322,839 | <p>How to query to get count of matching words in a field, specifically in MySQL.
simply i need to get how many times a "search terms"appear in the field value.</p>
<p>for example, the value is "one two one onetwo" so when i search for word "one" it should give me 3</p>
<p>is it possible? because currently i just extract the value out of database and do the counting with server side language.</p>
<p>Thank you</p>
| [
{
"answer_id": 323093,
"author": "Franck",
"author_id": 38072,
"author_profile": "https://Stackoverflow.com/users/38072",
"pm_score": 2,
"selected": true,
"text": "delimiter ||\nDROP FUNCTION IF EXISTS substrCount||\nCREATE FUNCTION substrCount(s VARCHAR(255), ss VARCHAR(255)) RETURNS TINYINT(3) UNSIGNED LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA\nBEGIN\nDECLARE count TINYINT(3) UNSIGNED;\nDECLARE offset TINYINT(3) UNSIGNED;\nDECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = NULL;\n\nSET count = 0;\nSET offset = 1;\n\nREPEAT\nIF NOT ISNULL(s) AND offset > 0 THEN\nSET offset = LOCATE(ss, s, offset);\nIF offset > 0 THEN\nSET count = count + 1;\nSET offset = offset + 1;\nEND IF;\nEND IF;\nUNTIL ISNULL(s) OR offset = 0 END REPEAT;\n\nRETURN count;\nEND;\n\n||\n\ndelimiter ;\n"
},
{
"answer_id": 323970,
"author": "Kaniu",
"author_id": 3236,
"author_profile": "https://Stackoverflow.com/users/3236",
"pm_score": 0,
"selected": false,
"text": "select (len(field)-len(replace,find,''))/len(find)\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19463/"
] |
322,842 | <p>OK, this is an odd request, and it might not even be fully true... but I'm upgrading someone's system ... and they are using OSCommerce (from a long time ago).</p>
<p>It appears their variables are referrenced without a dollar sign in front of them (which is new to me). I haven't done PHP in about 7 years, and I've always used dollar signs.</p>
<p>Is there a setting that I can throw in PHP 5 that says to assume these are variables?</p>
<p>Example:</p>
<pre><code>mysql_connect(DB_SERVER, DB_UserName, DB_Password);
</code></pre>
<p>in my day, that would be:</p>
<pre><code>mysql_connect($DB_Server, etc, etc);
</code></pre>
<p>Their site has THOUSANDS of files... no I don't want to go put dollar signs in front of everything.</p>
<p>HELP!</p>
<p>Thanks,</p>
| [
{
"answer_id": 326779,
"author": "Jay",
"author_id": 41690,
"author_profile": "https://Stackoverflow.com/users/41690",
"pm_score": 0,
"selected": false,
"text": "constant('MY_CONSTANT')\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11917/"
] |
322,846 | <p>I have some numeric code that I need to convert to C or C++. I tried using f2c, but it won't work on the Fortran code. f2c complains because the code uses C style preprocessor directives (#include).
The code's readme states that it is Fortran77, that works with the fort77 linker, that would expand those includes.</p>
<p>Does anyone know how to successfully convert this code?</p>
<p>My last resort is to write a simple preprocessor to expand those includes and then feed the code to f2c.</p>
<p>Note: I´m working in a Windows/Visual C++ environment here, so any gcc shenanigans would probably be more trouble than they are worth...</p>
| [
{
"answer_id": 322867,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 2,
"selected": false,
"text": "#include"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/78828/"
] |
322,895 | <p>I would like to pass an x amount of geo-locations to the Google Maps API and have it centered around these locations and set the appropriate zoom level so all locations are visible on the map. I.e. show all the markers that are currently on the map.</p>
<p>Is this possible with what the Google Maps API offers by default or do I need to resolve to build this myself?</p>
| [
{
"answer_id": 3822536,
"author": "gray",
"author_id": 446288,
"author_profile": "https://Stackoverflow.com/users/446288",
"pm_score": 3,
"selected": false,
"text": "var bounds = new google.maps.LatLngBounds();\n"
},
{
"answer_id": 10195324,
"author": "Nasser Al-Wohaibi",
"author_id": 1085495,
"author_profile": "https://Stackoverflow.com/users/1085495",
"pm_score": 1,
"selected": false,
"text": "function zoomToMarkers(map, markers)\n{\n if(markers[0]) // make sure at least one marker is there\n {\n // Get LatLng of the first marker\n var tempmark =markers[0].getPosition();\n\n // LatLngBounds needs two LatLng objects to be constructed\n var bounds = new google.maps.LatLngBounds(tempmark,tempmark);\n\n // loop thru all markers and extend the LatLngBounds object\n for (var i = 0; i < markers.length; i++) \n {\n bounds.extend(markers[i].getPosition());\n }\n\n // Set the map viewport \n map.fitBounds(bounds);\n }\n\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21406/"
] |
322,912 | <p>Using jQuery, <strong>how do you match elements that are prior to the current element in the DOM tree?</strong> Using <code>prevAll()</code> only matches previous siblings.</p>
<p>eg:</p>
<pre><code><table>
<tr>
<td class="findme">find this one</td>
</tr>
<tr>
<td><a href="#" class="myLinks">find the previous .findme</a></td>
</tr>
<tr>
<td class="findme">don't find this one</td>
</tr>
</table>
</code></pre>
<p>In my specific case, I'll be searching for the <em>first</em> <code>.findme</code> element prior to the link clicked.</p>
| [
{
"answer_id": 322979,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 1,
"selected": false,
"text": "$('.myLinks').click(function() {\n var findMe = '';\n\n $(this).parents().each(function() {\n var a = $(this).find('.findme').is('.findme');\n var b = $(this).find('.myLinks').is('.myLinks');\n if (a && b) { // look for first parent that\n // contains .findme and .myLinks\n $(this).find('*').each(function() {\n var name = $(this).attr('class');\n if ( name == 'findme') {\n findMe = $(this); // set element to last matching\n // .findme\n }\n if ( name == 'myLinks') {\n return false; // exit from the mess once we find\n // .myLinks\n }\n });\n return false;\n } \n });\n alert(findMe.text() ); // alerts \"find this one\"\n});\n"
},
{
"answer_id": 324159,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 6,
"selected": true,
"text": "prevALL"
},
{
"answer_id": 7009257,
"author": "Anze",
"author_id": 887685,
"author_profile": "https://Stackoverflow.com/users/887685",
"pm_score": 1,
"selected": false,
"text": "var num = $(this).attr(\"rel\");\n\nfor (var i = 1; i<=num; i++)\n{\n $('.class[rel=\"'+i+'\"]').addClass(\"newclass\");\n}\n"
},
{
"answer_id": 13673741,
"author": "lordvlad",
"author_id": 1568684,
"author_profile": "https://Stackoverflow.com/users/1568684",
"pm_score": 0,
"selected": false,
"text": "$.fn.findNext = function ( selector ) {\n var found, self = this.get(0);\n $( selector )\n .each( function () {\n if ( self.compareDocumentPosition( this ) === 4 ){ \n found = this; \n return false;\n } \n })\n return $(found);\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
322,926 | <p>How would you get a reference to an executing class several stack frames above the current one? For example, if you have:</p>
<pre><code>Class a {
foo() {
new b().bar();
}
}
Class b {
bar() {
...
}
}
</code></pre>
<p>
Is there a way to get the value that would be retrieved by using 'this' in foo() while the thread is executing bar()?</p>
| [
{
"answer_id": 322930,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 0,
"selected": false,
"text": "this"
},
{
"answer_id": 322933,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 2,
"selected": true,
"text": "Thread.getStackTrace()"
},
{
"answer_id": 322973,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 1,
"selected": false,
"text": "Class A { \n foo() {\n new b().bar(this);\n }\n}\n\nClass B {\n bar(A aInstance) {\n ...\n }\n}\n"
},
{
"answer_id": 323512,
"author": "Bill Michell",
"author_id": 7938,
"author_profile": "https://Stackoverflow.com/users/7938",
"pm_score": 1,
"selected": false,
"text": "Class A { \n foo() {\n new B().bar(this);\n }\n}\n\nClass B {\n bar(A caller) {\n ...\n }\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41241/"
] |
322,929 | <p>I'm looking for a cross-browser way of wrapping long portions of text that have no breaking spaces (e.g. long URLs) inside of divs with pre-determined widths.</p>
<p>Here are some solutions I've found around the web and why they <strong>don't</strong> work for me:</p>
<ul>
<li><strong>overflow : hidden / auto / scroll</strong> - I need the entire text to be visible without scrolling. The div can grow vertically, but not horizontally.</li>
<li><strong>Injecting &shy; into the string</strong> via js / server-side - &shy; is supported by FF3 now, but copying and pasting a URL with a &shy; in the middle will not work in Safari. Also, to my knowledge, there isn't a clean method of measuring text width to find out the best string offsets to add these characters to (there's one hacky way, see next item). Another problem is that zooming in Firefox and Opera can easily break this.</li>
<li><strong>dumping text into a hidden element and measuring offsetWidth</strong> - related to the item above, it requires adding extra characters into the string. Also, measuring the amount of breaks required in a long body of text could easily require thousands of expensive DOM insertions (one for every substring length), which could effectively freeze the site.</li>
<li><strong>using a monospace font</strong> - again, zooming can mess up width calculations, and the text can't be styled freely.</li>
</ul>
<p>Things that look promising but are not quite there:</p>
<ul>
<li><strong>word-wrap : break-word</strong> - it's now <a href="http://www.w3.org/TR/css3-text/#word-wrap" rel="noreferrer">part of CSS3 working draft</a>, but it's not supported by either Firefox, Opera or Safari yet. This would be the ideal solution if it worked across all browsers today :(</li>
<li><strong>injecting <wbr> tags into the string</strong> via js/ server-side - copying and pasting URLs works in all browsers, but I still don't have a good way of measuring where to put the breaks. Also, this tag invalidates HTML.</li>
<li><strong>adding breaks after every character</strong> - it's better than thousands of DOM insertions, but still not ideal (adding DOM elements to a document eats memory and slows downs selector queries, among other things).</li>
</ul>
<p>Does anyone have more ideas on how to tackle this problem?</p>
| [
{
"answer_id": 322991,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": false,
"text": "word-wrap"
},
{
"answer_id": 547911,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "function htmlspecialchars2($string = \"\", $maxWordLength = 0)\n{\n if($maxWordLength > 0)\n {\n $pattern = '/(\\S{'.$maxWordLength.',}?)/';\n $replacement = '$1­';\n $string = preg_replace($pattern, $replacement, $string);\n }\n\n //now encode special chars but dont encode ­\n $string = preg_replace(array('/\\&(?!shy\\;)/','/\\\"/',\"/\\'/\",'/\\</','/\\>/'), array('&','"',''','<','>'), $string);\n\n return $string;\n}\n"
},
{
"answer_id": 3360671,
"author": "superlogical",
"author_id": 52360,
"author_profile": "https://Stackoverflow.com/users/52360",
"pm_score": 5,
"selected": false,
"text": ".wordwrap {\n white-space: pre-wrap; /* css-3 */\n white-space: -moz-pre-wrap; /* Mozilla, since 1999 */\n white-space: -pre-wrap; /* Opera 4-6 */\n white-space: -o-pre-wrap; /* Opera 7 */\n word-wrap: break-word; /* Internet Explorer 5.5+ */ \n}\n"
},
{
"answer_id": 14198149,
"author": "waj",
"author_id": 775451,
"author_profile": "https://Stackoverflow.com/users/775451",
"pm_score": 0,
"selected": false,
"text": "return preg_replace_callback( '/\\w{10,}/', create_function( '$matches', 'return chunk_split( $matches[0], 5, \"​\" );' ), $value );\n"
},
{
"answer_id": 38321599,
"author": "haytham husni",
"author_id": 4324400,
"author_profile": "https://Stackoverflow.com/users/4324400",
"pm_score": 0,
"selected": false,
"text": "function htmlspecialchars2($string = \"\", $maxWordLength = 0){\n return wordwrap($string , $maxWordLength,\"\\n\", true);\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20689/"
] |
322,936 | <p>I'm trying to consolidate some build information by using a common makefile. My problem is that I want to use that makefile from different subdirectory levels, which makes the working directory value (<code>pwd</code>) unpredictable. For example:</p>
<pre><code># Makefile.common
TOP := $(shell pwd)
COMPONENT_DIR := $(TOP)/component
COMPONENT_INC := $(COMPONENT_DIR)/include
COMPONENT_LIB := $(COMPONENT_DIR)/libcomponent.a
</code></pre>
<p>If I include <code>Makefile.common</code> from a subdirectory, like so, the <code>$(TOP)</code> directory is incorrect and everything else follows suit:</p>
<pre><code># other_component/Makefile
include ../Makefile.common
# $(COMPONENT_LIB) is incorrectly other_component/component
</code></pre>
<p>What's the best way to get <code>Makefile.common</code> to use <em>its own</em> directory path instead of the more fickle <code>pwd</code>?</p>
| [
{
"answer_id": 322946,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": "# Makefile.common\nTOP ?= $(shell pwd)\nCOMPONENT_DIR := $(TOP)/component\nCOMPONENT_INC := $(COMPONENT_DIR)/include\nCOMPONENT_LIB := $(COMPONENT_DIR)/libcomponent.a\n\n# other_component/Makefile\nTOP ?= ..\ninclude ../Makefile.common\n"
},
{
"answer_id": 324782,
"author": "JesperE",
"author_id": 13051,
"author_profile": "https://Stackoverflow.com/users/13051",
"pm_score": 7,
"selected": true,
"text": "# This must be the first line in Makefile.common\nTOP := $(dir $(firstword $(MAKEFILE_LIST)))\n"
},
{
"answer_id": 2547973,
"author": "Bill",
"author_id": 305413,
"author_profile": "https://Stackoverflow.com/users/305413",
"pm_score": 4,
"selected": false,
"text": "ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))\n"
},
{
"answer_id": 10265204,
"author": "Robert H",
"author_id": 804023,
"author_profile": "https://Stackoverflow.com/users/804023",
"pm_score": 2,
"selected": false,
"text": "common.mk"
},
{
"answer_id": 28209829,
"author": "MegaSoft",
"author_id": 3473551,
"author_profile": "https://Stackoverflow.com/users/3473551",
"pm_score": 2,
"selected": false,
"text": "cwd := $(shell readlink -en $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))) \n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
322,938 | <p>I need a 'good' way to initialize the pseudo-random number generator in C++. I've found <a href="http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html" rel="noreferrer">an article</a> that states:</p>
<blockquote>
<p>In order to generate random-like
numbers, srand is usually initialized
to some distinctive value, like those
related with the execution time. For
example, the value returned by the
function time (declared in header
ctime) is different each second, which
is distinctive enough for most
randoming needs.</p>
</blockquote>
<p>Unixtime isn't distinctive enough for my application. What's a better way to initialize this? Bonus points if it's portable, but the code will primarily be running on Linux hosts.</p>
<p>I was thinking of doing some pid/unixtime math to get an int, or possibly reading data from <code>/dev/urandom</code>.</p>
<p>Thanks!</p>
<p><strong>EDIT</strong></p>
<p>Yes, I am actually starting my application multiple times a second and I've run into collisions.</p>
| [
{
"answer_id": 322961,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 4,
"selected": false,
"text": "/dev/random"
},
{
"answer_id": 322995,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 7,
"selected": true,
"text": "<random>"
},
{
"answer_id": 323223,
"author": "shoosh",
"author_id": 9611,
"author_profile": "https://Stackoverflow.com/users/9611",
"pm_score": 4,
"selected": false,
"text": "srand(GetTickCount());\n"
},
{
"answer_id": 323291,
"author": "user39307",
"author_id": 39307,
"author_profile": "https://Stackoverflow.com/users/39307",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <sys/time.h>\nmain()\n{\n struct timeval tv;\n gettimeofday(&tv,NULL);\n printf(\"%d\\n\", tv.tv_usec);\n return 0;\n}\n"
},
{
"answer_id": 323302,
"author": "Jonathan Wright",
"author_id": 28840,
"author_profile": "https://Stackoverflow.com/users/28840",
"pm_score": 6,
"selected": false,
"text": "unsigned long seed = mix(clock(), time(NULL), getpid());\n"
},
{
"answer_id": 323759,
"author": "Edouard A.",
"author_id": 41363,
"author_profile": "https://Stackoverflow.com/users/41363",
"pm_score": 3,
"selected": false,
"text": "struct timeb tp;\nftime(&tp); \nsrand(static_cast<unsigned int>(getpid()) ^ \nstatic_cast<unsigned int>(pthread_self()) ^ \nstatic_cast<unsigned int >(tp.millitm));\n"
},
{
"answer_id": 5945490,
"author": "R.. GitHub STOP HELPING ICE",
"author_id": 379897,
"author_profile": "https://Stackoverflow.com/users/379897",
"pm_score": 0,
"selected": false,
"text": "int foo(char *p);\n"
},
{
"answer_id": 13004555,
"author": "bames53",
"author_id": 365496,
"author_profile": "https://Stackoverflow.com/users/365496",
"pm_score": 3,
"selected": false,
"text": "random_device"
},
{
"answer_id": 14351644,
"author": "colin lamarre",
"author_id": 990618,
"author_profile": "https://Stackoverflow.com/users/990618",
"pm_score": 0,
"selected": false,
"text": "#include \"stdafx.h\"\n#include <time.h>\n#include <windows.h> \n\nconst __int64 DELTA_EPOCH_IN_MICROSECS= 11644473600000000;\n\nstruct timezone2 \n{\n __int32 tz_minuteswest; /* minutes W of Greenwich */\n bool tz_dsttime; /* type of dst correction */\n};\n\nstruct timeval2 {\n__int32 tv_sec; /* seconds */\n__int32 tv_usec; /* microseconds */\n};\n\nint gettimeofday(struct timeval2 *tv/*in*/, struct timezone2 *tz/*in*/)\n{\n FILETIME ft;\n __int64 tmpres = 0;\n TIME_ZONE_INFORMATION tz_winapi;\n int rez = 0;\n\n ZeroMemory(&ft, sizeof(ft));\n ZeroMemory(&tz_winapi, sizeof(tz_winapi));\n\n GetSystemTimeAsFileTime(&ft);\n\n tmpres = ft.dwHighDateTime;\n tmpres <<= 32;\n tmpres |= ft.dwLowDateTime;\n\n /*converting file time to unix epoch*/\n tmpres /= 10; /*convert into microseconds*/\n tmpres -= DELTA_EPOCH_IN_MICROSECS; \n tv->tv_sec = (__int32)(tmpres * 0.000001);\n tv->tv_usec = (tmpres % 1000000);\n\n\n //_tzset(),don't work properly, so we use GetTimeZoneInformation\n rez = GetTimeZoneInformation(&tz_winapi);\n tz->tz_dsttime = (rez == 2) ? true : false;\n tz->tz_minuteswest = tz_winapi.Bias + ((rez == 2) ? tz_winapi.DaylightBias : 0);\n\n return 0;\n}\n\n\nint main(int argc, char** argv) {\n\n struct timeval2 tv;\n struct timezone2 tz;\n\n ZeroMemory(&tv, sizeof(tv));\n ZeroMemory(&tz, sizeof(tz));\n\n gettimeofday(&tv, &tz);\n\n unsigned long seed = tv.tv_sec ^ (tv.tv_usec << 12);\n\n srand(seed);\n\n}\n"
},
{
"answer_id": 27594069,
"author": "Kevin",
"author_id": 4383443,
"author_profile": "https://Stackoverflow.com/users/4383443",
"pm_score": -1,
"selected": false,
"text": "srand(time(NULL));\n"
},
{
"answer_id": 29190957,
"author": "swalog",
"author_id": 1731448,
"author_profile": "https://Stackoverflow.com/users/1731448",
"pm_score": 2,
"selected": false,
"text": "c++11"
},
{
"answer_id": 47677317,
"author": "Dolda2000",
"author_id": 134252,
"author_profile": "https://Stackoverflow.com/users/134252",
"pm_score": 2,
"selected": false,
"text": "getauxval(AT_RANDOM)"
},
{
"answer_id": 58347785,
"author": "DarkJediNinja",
"author_id": 8872416,
"author_profile": "https://Stackoverflow.com/users/8872416",
"pm_score": 0,
"selected": false,
"text": "srand(time(NULL) + 1000 * getpid() + (uint) getCpuSerialNumber()); \n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2506/"
] |
322,941 | <p>Is there a particular scenario where a <code>WriteOnly</code> property makes more sense then a method? The method approach feels much more natural to me. </p>
<p>What is the right approach?</p>
<p><strong>Using Properties</strong>:</p>
<pre class="lang-vb prettyprint-override"><code>Public WriteOnly Property MyProperty As String
Set(ByVal value as String)
m_myField = value
End Set
End Property
</code></pre>
<pre class="lang-cs prettyprint-override"><code>public string MyProperty
{
set{ m_myField = value;}
}
</code></pre>
<p><strong>Using Methods</strong>:</p>
<pre class="lang-vb prettyprint-override"><code>Public Sub SetMyProperty(ByVal value as String)
m_myField = value
End Sub
</code></pre>
<pre class="lang-cs prettyprint-override"><code>public void SetMyProperty(string value)
{
m_myField = value;
}
</code></pre>
<p><strong>EDIT</strong>
Just to clarify I am referring to "WriteOnly" properties.</p>
| [
{
"answer_id": 322950,
"author": "Andrew Kennan",
"author_id": 22506,
"author_profile": "https://Stackoverflow.com/users/22506",
"pm_score": 5,
"selected": true,
"text": "public interface IWidgetSelector\n{\n void SetAvailableWidgets(string[] widgets);\n\n string SelectedWidget { get; set; }\n}\n"
},
{
"answer_id": 323007,
"author": "Corbin March",
"author_id": 7625,
"author_profile": "https://Stackoverflow.com/users/7625",
"pm_score": 1,
"selected": false,
"text": "public string Password { set; }\n"
},
{
"answer_id": 323138,
"author": "Mark Glorie",
"author_id": 952,
"author_profile": "https://Stackoverflow.com/users/952",
"pm_score": 0,
"selected": false,
"text": "System.Net.Mail.MailMessage.To\n"
},
{
"answer_id": 2332166,
"author": "RAL",
"author_id": 44844,
"author_profile": "https://Stackoverflow.com/users/44844",
"pm_score": 2,
"selected": false,
"text": "public class MyGraphicalObject\n {\n public double ScaleX { get; set; }\n public double ScaleY { get; set; }\n public double ScaleZ { get; set; }\n\n public double Scale { set { ScaleX = ScaleY = ScaleZ = value; } }\n\n // more...\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17744/"
] |
322,944 | <p>Given my new understanding of the power of "includes" with PHP, it is my guess that ALL of my pages on my site will be <code>.php</code> extension.</p>
<p>Would this be considered strange?</p>
<p>I used to think that most pages would be <code>.htm</code> or <code>.html</code>, but in looking around the net, I am noticing that there really isn't any "standard".</p>
<p>I don't really think I have a choice, if I want to call my menus from a php file. It is just going to be that way, far as I can see... so just bouncing off you all to get a feel for what "real programmers" feel about such issues.</p>
| [
{
"answer_id": 322947,
"author": "Harley Holcombe",
"author_id": 1057,
"author_profile": "https://Stackoverflow.com/users/1057",
"pm_score": 1,
"selected": false,
"text": ".php"
},
{
"answer_id": 323052,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 2,
"selected": false,
"text": "/questions/322944/uql-etiquette"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40091/"
] |
322,945 | <p>An interface is a 100% abstract class, so we can use an interface for efficient programming. Is there any situation where an abstract class is better than an interface?</p>
| [
{
"answer_id": 323054,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 3,
"selected": false,
"text": "CheckingAccount"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40933/"
] |
322,971 | <p>I want to cast both MenuItem objects and Button control objects to an object type of whose "Tag" property I can reference.</p>
<p>Is there such an object type?</p>
<p>E.g.</p>
<pre><code>void itemClick(object sender, EventArgs e)
{
Control c = (Control)sender;
MethodInvoker method = new MethodInvoker(c.Tag.ToString(), "Execute");
method.Invoke();
}
</code></pre>
<p>Except this fails - "Unable to cast object type 'System.Windows.Forms.MenuItem' to type 'System.Windows.Forms.Control'</p>
<p>What can replace Control in this example?</p>
| [
{
"answer_id": 323002,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 2,
"selected": false,
"text": "\nobject myControlOrMenu = sender as MenuItem ?? sender as Button;\nif (myControlOrMenu == null)\n// neither of button or menuitem\n"
},
{
"answer_id": 323016,
"author": "Michał Piaskowski",
"author_id": 1534,
"author_profile": "https://Stackoverflow.com/users/1534",
"pm_score": 3,
"selected": true,
"text": ""
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/322971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5019/"
] |
323,019 | <p>I'm at step 8 of the authentication overview found here: <a href="http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works" rel="noreferrer">http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works</a></p>
<p>In particular, the user has logged into facebook via Facebook Connect and their web session has been created. How do I use the facebook developer toolkit v2.0 (from clarity) to retrieve information about the user. For example, I'd like to get the user's first name and last name.</p>
<p>Examples in the documentation are geared towards facebook applications, which this is not.</p>
<h2>Update</h2>
<p>Facebook recently released the Graph API. Unless you are maintaining an application that is using Facebook Connect, you should check out the latest API: <a href="http://developers.facebook.com/docs/" rel="noreferrer">http://developers.facebook.com/docs/</a></p>
| [
{
"answer_id": 333267,
"author": "ckarbass",
"author_id": 67719,
"author_profile": "https://Stackoverflow.com/users/67719",
"pm_score": 4,
"selected": false,
"text": "api.SessionKey"
},
{
"answer_id": 369691,
"author": "calebt",
"author_id": 7525,
"author_profile": "https://Stackoverflow.com/users/7525",
"pm_score": 6,
"selected": true,
"text": "API api = new API();\napi.ApplicationKey = Utility.ApiKey();\napi.SessionKey = Utility.SessionKey();\napi.Secret = Utility.SecretKey();\napi.uid = Utility.GetUserID();\n\nfacebook.Schema.user user = api.users.getInfo();\nstring fullName = user.first_name + \" \" + user.last_name;\n\nforeach (facebook.Schema.user friend in api.friends.getUserObjects())\n{\n // do something with the friend\n}\n"
},
{
"answer_id": 942815,
"author": "nikmd23",
"author_id": 107289,
"author_profile": "https://Stackoverflow.com/users/107289",
"pm_score": 3,
"selected": false,
"text": "private bool IsValidFacebookSignature()\n{\n //keys must remain in alphabetical order\n string[] keyArray = { \"expires\", \"session_key\", \"ss\", \"user\" };\n string signature = \"\";\n\n foreach (string key in keyArray)\n signature += string.Format(\"{0}={1}\", key, GetFacebookCookie(key));\n\n signature += SecretKey; //your secret key issued by FB\n\n MD5 md5 = MD5.Create();\n byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(signature.Trim()));\n\n StringBuilder sb = new StringBuilder();\n foreach (byte hashByte in hash)\n sb.Append(hashByte.ToString(\"x2\", CultureInfo.InvariantCulture));\n\n return (GetFacebookCookie(\"\") == sb.ToString());\n }\n\n private string GetFacebookCookie(string cookieName)\n {\n //APIKey issued by FB\n string fullCookie = string.IsNullOrEmpty(cookieName) ? ApiKey : ApiKey + \"_\" + cookieName;\n\n return Request.Cookies[fullCookie].Value;\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67719/"
] |
323,022 | <p>When I create utility classes I typically create a class that has a private constructor and exposes all of it's methods and properties as static. What's the best approach for this? What's the difference between the way I do or creating a static class?</p>
| [
{
"answer_id": 323030,
"author": "Corbin March",
"author_id": 7625,
"author_profile": "https://Stackoverflow.com/users/7625",
"pm_score": 4,
"selected": false,
"text": "public class Utility\n{\n public static string Config1 { get { return \"Fourty Two\"; } }\n\n public static int Negate(int x) { return -x; }\n\n private Utility() { } \n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17744/"
] |
323,032 | <p>I want to generate a list in C#. I am missing python's list comprehensions. Is there a C# way to create collections on the fly like list comprehensions or generator expressions do in python?</p>
| [
{
"answer_id": 323039,
"author": "Matt Campbell",
"author_id": 41110,
"author_profile": "https://Stackoverflow.com/users/41110",
"pm_score": 6,
"selected": true,
"text": "List<Foo> fooList = new List<Foo>();\nIEnumerable<Foo> extract = from foo in fooList where foo.Bar > 10 select Foo.Name.ToUpper();\n"
},
{
"answer_id": 323058,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": false,
"text": "List<Foo> fooList = new List<Foo>();\nIEnumerable<string> extract = from foo in fooList where foo.Bar > 10 select foo.Name.ToUpper();\n"
},
{
"answer_id": 2739426,
"author": "Ray",
"author_id": 4872,
"author_profile": "https://Stackoverflow.com/users/4872",
"pm_score": 3,
"selected": false,
"text": "List<T>.ConvertAll"
},
{
"answer_id": 31141556,
"author": "Nachbars Lumpi",
"author_id": 382019,
"author_profile": "https://Stackoverflow.com/users/382019",
"pm_score": 1,
"selected": false,
"text": "new List<FooBar> { new Foo(), new Bar() }\n"
},
{
"answer_id": 42409780,
"author": "Sнаđошƒаӽ",
"author_id": 3375713,
"author_profile": "https://Stackoverflow.com/users/3375713",
"pm_score": 2,
"selected": false,
"text": "cb01, cb02, cb02, ... , cb50\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4491/"
] |
323,063 | <p>I have this html...</p>
<pre><code><select id="View" name="View">
<option value="1">With issue covers</option>
<option value="0">No issue covers</option>
</select>
</code></pre>
<p>It won't let me insert code like this...</p>
<pre><code><select id="View" name="View">
<option value="1" <% ..logic code..%> >With issue covers</option>
<option value="0" <% ..logic code..%> >No issue covers</option>
</select>
</code></pre>
<p>So whats the best way to set one to selected?</p>
<p>Update:
Without using the HTML Helpers.</p>
| [
{
"answer_id": 323164,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 3,
"selected": false,
"text": "var selectList = new SelectList(data, \"ValueProp\", \"TextProp\", data[1].ValueProp);\n... Html.DropDownList(\"foo\", selectList)\n"
},
{
"answer_id": 323177,
"author": "Todd Smith",
"author_id": 31624,
"author_profile": "https://Stackoverflow.com/users/31624",
"pm_score": 2,
"selected": true,
"text": "<select id=\"View\" name=\"View\">\n <option value=\"1\" <% if (something) { %> selected <% } %> >With issue covers</option>\n <option value=\"0\" <% if (!something) { %> selected <% } %> >No issue covers</option>\n</select>\n"
},
{
"answer_id": 323183,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 1,
"selected": false,
"text": "SelectList"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1231/"
] |
323,064 | <p>I am using <code>GridView</code> in my application for populating datas. </p>
<p>Is there any easy way to copy a gridview to datatable ?</p>
<p>Actually, in my <code>GridView</code> one of the control is textbox.<br>
So I can edit that control at any time... What I need is on the button click whatever changes I made in <code>GridView</code> has to copy in one datatable...</p>
<p>I did this using the code, </p>
<pre><code>dt = CType(Session("tempTable"), DataTable)
i = 0 For Each rows As GridViewRow In Grid1.Rows
Dim txt As TextBox
txt = CType(rows.FindControl("txt"), TextBox)
dt.Rows(i)(1) = txt.Text
i = i + 1
Next
</code></pre>
<p>Here I am traversing through grid with the help of "for each" loop.<br>
I am worrying whether it effects performance?<br>
Can you please tel me any other simple method to copy a <code>GridView</code> to a datatable</p>
| [
{
"answer_id": 367804,
"author": "sona",
"author_id": 41014,
"author_profile": "https://Stackoverflow.com/users/41014",
"pm_score": 1,
"selected": true,
"text": " <asp:GridView ID=\"Grid1\" runat=\"server\" AutoGenerateColumns=\"False\" GridLines=\"None\">\n <Columns>\n <asp:TemplateField HeaderText=\"ID\">\n <ItemTemplate>\n <asp:Label ID=\"lbl1\" runat=\"server\" Text='<%#Bind(\"ID\") %>' CssClass=\"rowHeader\"></asp:Label>\n </ItemTemplate>\n <FooterTemplate>\n <asp:TextBox ID=\"txt1\" runat=\"server\" Text='<%#Bind(\"ID\") %>'></asp:TextBox>\n </FooterTemplate>\n </asp:TemplateField>\n <asp:TemplateField HeaderText=\"Description\">\n <ItemTemplate>\n <asp:TextBox ID=\"txt\" runat=\"server\" Text='<%#Bind(\"Description\") %>'></asp:TextBox>\n </ItemTemplate>\n <FooterTemplate>\n <asp:TextBox ID=\"txt2\" runat=\"server\" Text='<%#Bind(\"Description\") %>'></asp:TextBox>\n </FooterTemplate>\n </asp:TemplateField>\n <asp:TemplateField HeaderText=\"Comments\">\n <ItemTemplate>\n <asp:Label ID=\"Comments\" runat=\"server\" Text='<%#Bind(\"Comments\") %>'></asp:Label>\n </ItemTemplate>\n <FooterTemplate>\n <asp:DropDownList ID=\"Drop1\" runat=\"server\">\n <asp:ListItem>v1</asp:ListItem>\n <asp:ListItem>v2</asp:ListItem>\n </asp:DropDownList>\n </FooterTemplate>\n </asp:TemplateField>\n </Columns>\n </asp:GridView>\n\n <asp:Button ID=\"btnAdd\" runat=\"server\" Text=\"Add\" />\n <asp:Button ID=\"btnSave\" runat=\"server\" Text=\"Save\" />\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41014/"
] |
323,065 | <p>Let's say that I have a record in the database and that both admin and normal users can do updates.</p>
<p>Can anyone suggest a good approach/architecture on how to version control every change in this table so it's possible to roll back a record to a previous revision?</p>
| [
{
"answer_id": 323109,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 9,
"selected": true,
"text": "FOO"
},
{
"answer_id": 13596781,
"author": "Adam Gent",
"author_id": 318174,
"author_profile": "https://Stackoverflow.com/users/318174",
"pm_score": 2,
"selected": false,
"text": "outer join"
},
{
"answer_id": 51678355,
"author": "Hassan Farid",
"author_id": 2558863,
"author_profile": "https://Stackoverflow.com/users/2558863",
"pm_score": 3,
"selected": false,
"text": "Audit table"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40939/"
] |
323,079 | <p>First time posting to a questions site, but I sort of have a complex problem i've been looking at for a few days.</p>
<p><b>Background</b>
At work we're implementing a new billing system. However, we want to take the unprecedented move of actually auditing the new billing system against the old one which is significantly more robust on an ongoing basis. The reason is the new billing system is alot more flexible for our new rate plans, so marketing is really on us to get this new billing system in place.</p>
<p>We had our IT group develop a report for a ridiculous amount of money that runs at 8AM each morning for yesterday's data, compares records for getting byte count discrepancies, and generates the report. This isn't very useful for us since for one it runs the next day, and secondly if it shows bad results, we don't have any indication why we may have had a problem the day before.</p>
<p>So we want to build our own system, that hooks into any possible data source (at first only the new and old systems User Data Records (UDR)) and compares the results in near real-time. </p>
<p>Just some notes on the scale, each billing system produces roughly 6 million records / day at a total file size of about 1 gig.</p>
<p><b>My Proposed set-up</b>
Essentially, buy some servers, we have budget for several 8 core / 32GB of RAM machines, so I'd like to do all the processing and storage in in-memory data structures. We can buy bigger server's if necessary, but after a couple days, I don't see any reason to keep the data in memory any longer (written out to persistent storage) and Aggregate statistics stored in a database.</p>
<p>Each record essentially contains a record-id from the platform, correlation-id, username, login-time, duration, bytes-in, bytes-out, and a few other fields. </p>
<p>I was thinking of using a fairly complex data structure for processing. Each record would be broken into a user object, and a record object belong to either platform a or platform b. At the top level, would be a binary search tree (self balancing) on the username. The next step would be sort of like a skip list based on date, so we would have next matched_record, next day, next hour, next month, next year, etc. Finally we would have our matched record object, essentially just a holder which references the udr_record object from system a, and the udr record object from system b.</p>
<p>I'd run a number of internal analytic as data is added to see if the new billing system has choked, started having large discrepancies compared to the old system, and send an alarm to our operations center to be investigated. I don't have any problem with this part myself.</p>
<p><b>Problem</b>
The problem I have is aggregate statistics are great, but I want to see if I can come up with a sort of query language where the user can enter a query, for say the top contributors to this alarm, and see what records contributed to the discrepancy, and dig in and investigate. Originally, I wanted to use a syntax similar to a filter in wireshark, with some added in SQL.</p>
<p>Example:</p>
<pre><code>udr.bytesin > 1000 && (udr.analysis.discrepancy > 100000 || udr.analysis.discrepency_percent > 100) && udr.started_date > '2008-11-10 22:00:44' order by udr.analysis.discrepancy DESC LIMIT 10
</code></pre>
<p>The other option would be to use DLINQ, but I've been out of the C# game for a year and a half now, so am not 100% up to speed on the .net 3.5 stuff. Also i'm not sure if it could handle the data structure I was planning on using. The real question, is can I get any feedback on how to approach the getting a query string from the user, parsing it, and applying it to the data structure (which has quite a few more attributes then outlined above), and getting the resulting list back. I can handle the rest on my own.</p>
<p>I am fully prepared to hard code much of the possible queries, and just have them more as reports that are run with some parameters, but if there is a nice clean way of doing this type of query syntax, I think it would be immensely cool feature to add. </p>
| [
{
"answer_id": 323084,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "class Udr { // formatted for space\n public int BytesIn { get; set; }\n public UdrAnalysis Analysis { get; set; }\n public DateTime StartedDate { get; set; }\n}\nclass UdrAnalysis {\n public int Discrepency { get; set; }\n public int DiscrepencyPercent { get; set; }\n} \nstatic class Program {\n static void Main() {\n Udr[] data = new [] {\n new Udr { BytesIn = 50000, StartedDate = DateTime.Today,\n Analysis = new UdrAnalysis { Discrepency = 50000, DiscrepencyPercent = 130}},\n new Udr { BytesIn = 500, StartedDate = DateTime.Today,\n Analysis = new UdrAnalysis { Discrepency = 50000, DiscrepencyPercent = 130}}\n };\n DateTime when = DateTime.Parse(\"2008-11-10 22:00:44\");\n var query = data.AsQueryable().Where(\n @\"bytesin > 1000 && (analysis.discrepency > 100000\n || analysis.discrepencypercent > 100)\n && starteddate > @0\",when)\n .OrderBy(\"analysis.discrepency DESC\")\n .Take(10);\n foreach(var item in query) {\n Console.WriteLine(item.BytesIn);\n }\n }\n}\n"
},
{
"answer_id": 323125,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": " static IEnumerable<Foo> ReadFoos(string path) {\n return from line in ReadLines(path)\n let parts = line.Split('|')\n select new Foo { Name = parts[0],\n Size = int.Parse(parts[1]) };\n }\n static IEnumerable<string> ReadLines(string path) {\n using (var reader = File.OpenText(path)) {\n string line;\n while ((line = reader.ReadLine()) != null) {\n yield return line;\n }\n }\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
323,088 | <p>I have the following code in my Site.Master page of an almost empty ASP.NET MVC Project. </p>
<pre><code><li>
<%= Html.ActionLink("Home", "Index", "Home")%>
</li>
<li>
<%= Html.ActionLink("Feed List", "FeedList", "Home")%>
</li>
<li>
<%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Home")%>
</li>
<li>
<%= Html.ActionLink("About", "About", "Home")%>
</li>
</code></pre>
<p>I haven't added anything more than a Folder to the Views Folder called Feeds. In the Feeds folder I have two Views; FeedList.aspx and MonitoredFeeds.aspx. I also added the following code to the HomeController as below.</p>
<pre><code> [HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Title"] = "The Reporter";
ViewData["Message"] = "Welcome to The Reporter.";
return View();
}
public ActionResult About()
{
ViewData["Title"] = "About Page";
return View();
}
public ActionResult FeedList()
{
ViewData["Title"] = "Feed List";
return View();
}
public ActionResult MonitoredFeeds()
{
ViewData["Title"] = "Monitored Feeds";
return View();
}
}
</code></pre>
<p>No matter what I do though, whenever I click on the links to the pages, the following error is displayed.</p>
<pre><code>Server Error in '/' Application.
--------------------------------------------------------------------------------
The view 'FeedList' or its master could not be found. The following locations were searched:
~/Views/Home/FeedList.aspx
~/Views/Home/FeedList.ascx
~/Views/Shared/FeedList.aspx
~/Views/Shared/FeedList.ascx
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view 'FeedList' or its master could not be found. The following locations were searched:
~/Views/Home/FeedList.aspx
~/Views/Home/FeedList.ascx
~/Views/Shared/FeedList.aspx
~/Views/Shared/FeedList.ascx
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The view 'FeedList' or its master could not be found. The following locations were searched:
~/Views/Home/FeedList.aspx
~/Views/Home/FeedList.ascx
~/Views/Shared/FeedList.aspx
~/Views/Shared/FeedList.ascx]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +493
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +199
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ActionResult actionResult) +105
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +39
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +385
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionResultWithFilters>b__12() +61
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ActionResult actionResult, IList`1 filters) +386
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +736
System.Web.Mvc.Controller.ExecuteCore() +180
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +96
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +36
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +377
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
</code></pre>
<p>Have I missed something? Do I need to add the Feeds folder somewhere? Does Feeds need to go where I have "Home" listed in the links? I've even tried that and still got the error.</p>
<p>Thanks.</p>
| [
{
"answer_id": 323187,
"author": "Todd Smith",
"author_id": 31624,
"author_profile": "https://Stackoverflow.com/users/31624",
"pm_score": 4,
"selected": true,
"text": "public ActionResult FeedList()\n{\n ViewData[\"Title\"] = \"Feed List\";\n return View();\n}\n\npublic ActionResult MonitoredFeeds()\n{\n ViewData[\"Title\"] = \"Monitored Feeds\";\n return View();\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29345/"
] |
323,094 | <p>I would like to know difference between static variables and global variables in terms of <strong>access speed</strong> and <strong>space consumption</strong>. (If you want to know my platform: gcc compiler on Windows. (I am using Cygwin with Triton IDE for ARM7 embedded programming on windows. Triton comes with gcc compiler on Java platform which can be run on Windows.))</p>
<p>(Obviously I know in terms of file and function scope from <a href="https://stackoverflow.com/questions/320461/why-main-cannot-be-declared-as-a-static-in-c">this question</a>)</p>
<p><strong>Edit:</strong> OK give me an answer on any micro controller / processor environment.</p>
| [
{
"answer_id": 323174,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 5,
"selected": true,
"text": ".c"
},
{
"answer_id": 323392,
"author": "eaanon01",
"author_id": 36986,
"author_profile": "https://Stackoverflow.com/users/36986",
"pm_score": 0,
"selected": false,
"text": "external char my_global_char_placed_else_where;"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31116/"
] |
323,131 | <p>I am using C# and trying to read a <code>CSV</code> by using this connection string;</p>
<blockquote>
<pre><code>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\rajesh.yadava\Desktop\orcad;Extended Properties="Text;HDR=YES;IMEX=1;FMT=Delimited"
</code></pre>
</blockquote>
<p>This works for tab delimited data.</p>
<p>I want a connection string which should for tab delimited as well as comma(,) and pipe(|).</p>
<p>How can I make a generic connection string for <code>CSV</code>.</p>
<p>Thanks
Rajesh</p>
| [
{
"answer_id": 323222,
"author": "hangy",
"author_id": 11963,
"author_profile": "https://Stackoverflow.com/users/11963",
"pm_score": 1,
"selected": false,
"text": "System.Data.IDataReader"
},
{
"answer_id": 17140487,
"author": "geryjuhasz",
"author_id": 2471815,
"author_profile": "https://Stackoverflow.com/users/2471815",
"pm_score": 0,
"selected": false,
"text": " class CSVFile extends SplFileObject\n{\n\nprivate $keys;\n\n public function __construct($file)\n {\n parent::__construct($file);\n $this->setFlags(SplFileObject::READ_CSV);\n }\n\n public function rewind()\n {\n parent::rewind();\n $this->keys = parent::current();\n parent::next();\n }\n\n public function current()\n {\n return array_combine($this->keys, parent::current());\n }\n\n public function getKeys()\n {\n return $this->keys;\n }\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
323,133 | <p>Searched stackoverflow for this and found no answer</p>
<p>Coming from Ruby On Rails and Rspec, I need a tool like rspec (easier transition). Installed it through PEAR and tried to run it but it's not working (yet)</p>
<p>Just wanna ask around if anyone's using it have the same problem, since it's not running at all</p>
<p>tried running it with an example from the manual - <a href="http://dev.phpspec.org/manual/en/before.writing.code.specify.its.required.behaviour.html#id569490" rel="nofollow noreferrer">http://dev.phpspec.org/manual/en/before.writing.code.specify.its.required.behaviour.html</a></p>
<pre><code>phpspec NewFileSystemLoggerSpec
</code></pre>
<p>returns nothing</p>
<p>even running</p>
<pre><code>phpspec some_dummy_value
</code></pre>
<p>returns nothing</p>
| [
{
"answer_id": 1620406,
"author": "andho",
"author_id": 170007,
"author_profile": "https://Stackoverflow.com/users/170007",
"pm_score": 0,
"selected": false,
"text": "$projectDir = realpath( dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' ) . DIRECTORY_SEPARATOR;\n\n$simdal_root = $projectDir . 'library';\n$phpspec_root = $projectDir . '..' . DIRECTORY_SEPARATOR . 'PHPSpec';\n$mockery_root = $projectDir . '..' . DIRECTORY_SEPARATOR . 'Mockery';\n\n$paths = array(\n 'SimDAL'=>$simdal_root,\n 'PHPSpec'=>$phpspec_root,\n 'Mockery'=>$mockery_root\n);\n\nset_include_path( implode( PATH_SEPARATOR, $paths ) . PATH_SEPARATOR . get_include_path() );\n\nrequire_once 'PHPSpec.php';\nrequire_once 'Mockery/Framework.php';\n\nclass Custom_Autoload\n{\n public static function autoload($class)\n {\n //$path = dirname(dirname(__FILE__));\n //include $path . '/' . str_replace('_', '/', $class) . '.php';\n if (preg_match('/^([^ _]*)?(_[^ _]*)*$/', $class, $matches)) {\n include str_replace('_', '/', $class) . '.php';\n return true;\n }\n\n return false;\n }\n\n}\n\nspl_autoload_register(array('Custom_Autoload', 'autoload'));\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33552/"
] |
323,140 | <p>I am trying to install a Windows service using InstallUtil.exe and am getting the error message</p>
<blockquote>
<p>System.BadImageFormatException: Could not load file or assembly '<code>{xxx.exe}</code>' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p>
</blockquote>
<p>What gives?</p>
<hr>
<p>EDIT: (Not by OP) Full message extracted from dup getting way more hits [for googleability]:</p>
<blockquote>
<p>C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\xxx.exe
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.</p>
<p>Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\xxx.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format..</p>
</blockquote>
| [
{
"answer_id": 2160932,
"author": "Ruben Bartelink",
"author_id": 11635,
"author_profile": "https://Stackoverflow.com/users/11635",
"pm_score": 7,
"selected": false,
"text": "/platform:x86"
},
{
"answer_id": 14475516,
"author": "James Crowther",
"author_id": 2003151,
"author_profile": "https://Stackoverflow.com/users/2003151",
"pm_score": 3,
"selected": false,
"text": "installutil.exe"
},
{
"answer_id": 51854142,
"author": "SohamC",
"author_id": 1603970,
"author_profile": "https://Stackoverflow.com/users/1603970",
"pm_score": 2,
"selected": false,
"text": "PlatformTarget"
},
{
"answer_id": 53964787,
"author": "Soleil",
"author_id": 1447389,
"author_profile": "https://Stackoverflow.com/users/1447389",
"pm_score": 0,
"selected": false,
"text": "$(SolutionDir)\\.vs\\$(SolutionName)\\lut\\0\\0\\x64\\Debug\\"
},
{
"answer_id": 55138049,
"author": "mabiyan",
"author_id": 6271132,
"author_profile": "https://Stackoverflow.com/users/6271132",
"pm_score": 1,
"selected": false,
"text": "AnyCPU"
},
{
"answer_id": 59203730,
"author": "rvnlord",
"author_id": 3783852,
"author_profile": "https://Stackoverflow.com/users/3783852",
"pm_score": 0,
"selected": false,
"text": "System.BadImageFormatException: Could not load file or assembly"
},
{
"answer_id": 65482147,
"author": "Ziggler",
"author_id": 1438112,
"author_profile": "https://Stackoverflow.com/users/1438112",
"pm_score": 2,
"selected": false,
"text": "cd\\\ncd \"C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\"\ninstallutil.exe \"C:\\XXX\\Bin\\ABC.exe\"\npause\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
323,146 | <p>You can use command <strong>lsof</strong> to get file descriptors for all running processes, but what I would like to do is to close some of those descriptors without being inside that process. This can be done on Windows, so you can easily unblock some application.</p>
<p>Is there any command or function for that?</p>
| [
{
"answer_id": 323160,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 2,
"selected": false,
"text": "stdout"
},
{
"answer_id": 323180,
"author": "Andreas",
"author_id": 41277,
"author_profile": "https://Stackoverflow.com/users/41277",
"pm_score": 6,
"selected": false,
"text": "$pidof cat\n7213\n\n$gdb -p 7213\n\n...\nlots of output\n...\n\n(gdb)\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/189/"
] |
323,147 | <p>In Flex I'm using the following code to allow sorting in a DataGrid (the data is paged and sorted serverside).</p>
<pre>
private function headerReleaseHandler(event:DataGridEvent):void
{
var column:DataGridColumn = DataGridColumn(event.currentTarget.columns[event.columnIndex]);
if(this.count>0)
{
if(this.query.SortField == column.dataField)
{
this.query.SortAscending = !this.query.SortAscending;
}
else
{
this.query.SortField = column.dataField;
this.query.SortAscending = true;
}
this.fill();
}
event.preventDefault();
}
</pre>
<p>This works perfectly, except that the arrows that indicate sorting isn't shown. How can I accomplish that?</p>
<p>Thanks!
/Niels </p>
| [
{
"answer_id": 5966359,
"author": "ili",
"author_id": 748933,
"author_profile": "https://Stackoverflow.com/users/748933",
"pm_score": 1,
"selected": false,
"text": "public class DataGridCustomSort extends DataGrid\n{\n\n public function DataGridCustomSort()\n {\n super();\n\n addEventListener(DataGridEvent.HEADER_RELEASE,\n headerReleaseHandlerCustomSort,\n false, EventPriority.DEFAULT_HANDLER);\n } \n\n public function headerReleaseHandlerCustomSort(event:DataGridEvent):void {\n mx_internal::sortIndex = event.columnIndex;\n if (mx_internal::sortDirection == null || mx_internal::sortDirection == \"DESC\")\n mx_internal::sortDirection = \"ASC\";\n else\n mx_internal::sortDirection = \"DESC\";\n placeSortArrow();\n }\n\n}\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40939/"
] |
323,148 | <p>I have a site with over 100 pages. We need to go live with products that are soon available, however, many site pages will not be prepared at the time of release.</p>
<p>In order to move forward, I would like to reference a "coming soon" page with links to pages that are current and available.</p>
<p>Is there an easy way to forward a URL to a Coming Soon page?
Is this valid, or is there a better way?</p>
<p>Found this at:
<a href="http://www.web-source.net/html_redirect.htm" rel="nofollow noreferrer">http://www.web-source.net/html_redirect.htm</a></p>
<p>"Place the following HTML redirect code between the and tags of your HTML code.</p>
<pre><code> meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"
</code></pre>
<p>Does this negatively affect you if the search engines crawl through your site?</p>
<p>Thank you!</p>
| [
{
"answer_id": 323166,
"author": "Henrik Paul",
"author_id": 2238,
"author_profile": "https://Stackoverflow.com/users/2238",
"pm_score": 2,
"selected": false,
"text": "<?php\nheader(\"Location: http://www.yourdomain.com/index.html\");\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40091/"
] |
323,161 | <p>I've implemented an object factory to lookup LDAP objects, but the supplied context does not return the DN (via nameCtx.getNameInNamespace()) from the LDAP. Am i doing it wrong in some way?</p>
<pre><code>public class LdapPersonFactory implements DirObjectFactory {
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable<?, ?> environment, Attributes attrs) throws Exception {
if (attrs == null)
return null;
Attribute oc = attrs.get("objectclass");
if (oc != null && oc.contains("inetOrgPerson")) {
String surname = (String) attrs.get("sn").get();
String givenName = (String) attrs.get("givenname").get();
String dn = nameCtx.getNameInNamespace();
return new LdapPerson(dn, givenName, surname);
}
return null;
}
}
</code></pre>
<p>nameCtx.getNameInNamespace() only returns an empty string.</p>
| [
{
"answer_id": 323188,
"author": "cagcowboy",
"author_id": 19629,
"author_profile": "https://Stackoverflow.com/users/19629",
"pm_score": 0,
"selected": false,
"text": "String dn = (String) attrs.get(\"dn\").get();\n"
},
{
"answer_id": 323475,
"author": "Oliver Michels",
"author_id": 20297,
"author_profile": "https://Stackoverflow.com/users/20297",
"pm_score": 1,
"selected": false,
"text": "String dn = (String) attrs.get(\"dn\").get();\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20297/"
] |
323,163 | <p>Please, I am new to webparts and I need help!!</p>
<p>I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:</p>
<p>Script controls may not be registered before PreRender</p>
<p>I do not use the OnPreRender event as what other posts suggest. Please, if anyone can give me advice it will be very much appreciated.</p>
<p>Thanks</p>
| [
{
"answer_id": 324414,
"author": "Pedrin",
"author_id": 36183,
"author_profile": "https://Stackoverflow.com/users/36183",
"pm_score": 1,
"selected": false,
"text": "protected override void OnLoad(EventArgs eventArgs)\n{\n base.OnLoad(eventArgs);\n\n // your code...\n}\n"
},
{
"answer_id": 325449,
"author": "Marian Polacek",
"author_id": 41545,
"author_profile": "https://Stackoverflow.com/users/41545",
"pm_score": 2,
"selected": false,
"text": " protected override void OnInit(EventArgs e)\n {\n base.OnInit(e);\n EnsureChildControls();\n }\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
323,189 | <p>I'm making a simple IRC Bot in C. And I finally got the bot connecting and receiving information. My code is supposed to be sending as well, but the server is acting as if it is not sending anything. When The bot connects, I receive this:</p>
<blockquote>
<p>Recieved: :roc.esper.net NOTICE AUTH
:*** Looking up your hostname...</p>
<p>Recieved: :roc.esper.net NOTICE AUTH
:*** Found your hostname</p>
</blockquote>
<p>at which point my code sends this:</p>
<p>Sent: NICK Goo</p>
<p>Sent: USER Goo * * :Goo</p>
<p>I determined from using wireshark that this is the registration you should send after the initial connect. However, I'm not sure the data is actually sending or maybe it is invalid somehow? Because after about 30 seconds of nothing i also receive this:</p>
<blockquote>
<p>Recieved: ERROR :Closing Link:
c-68-33-143-182.hsd1.md.comcast.net
(Registration timed out)</p>
</blockquote>
<p>And then my program closes.</p>
<p>Does anyone else know anything about the programatic auth/registration processes in irc? Or does anyone else have any helpful ideas at all?</p>
<p>Thanks</p>
<p>** EDIT ** Fixed. I needed to be sending line terminators at the end of each line. \r\n</p>
| [
{
"answer_id": 323195,
"author": "schnaader",
"author_id": 34065,
"author_profile": "https://Stackoverflow.com/users/34065",
"pm_score": 1,
"selected": false,
"text": "USER Goo * * :Goo\n"
},
{
"answer_id": 323217,
"author": "Tom",
"author_id": 26155,
"author_profile": "https://Stackoverflow.com/users/26155",
"pm_score": 2,
"selected": false,
"text": "\"\n> telnet irc.freenode.net 6667\nNOTICE AUTH :*** Looking up your hostname...\nNOTICE AUTH :*** Checking ident\nNOTICE AUTH :*** No identd (auth) response\nNOTICE AUTH :*** Couldn't look up your hostname\nUSER x x x x\nNICK hwjrh\n:kubrick.freenode.net 001 hwjrh :Welcome to the freenode IRC Network hwjrh\n:kubrick.freenode.net 002 hwjrh :Your host is kubrick.freenode.net[kubrick.freenode.net/6667], running version hyperion-1.0.2b\n\"\n"
},
{
"answer_id": 323246,
"author": "schnaader",
"author_id": 34065,
"author_profile": "https://Stackoverflow.com/users/34065",
"pm_score": 2,
"selected": false,
"text": "~$ telnet roc.esper.net 6667\nTrying 198.247.173.216...\nConnected to roc.esper.net.\nEscape character is '^]'.\n:roc.esper.net NOTICE AUTH :*** Looking up your hostname...\n:roc.esper.net NOTICE AUTH :*** Found your hostname\nNICK Goo\nUSER Goo * * :Goo\nPING :268966433\nPONG :268966433\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323189",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2128/"
] |
323,193 | <p>There is a SqlServer2000 Database we have to update during weekend.</p>
<p>It's size is almost 10G.</p>
<p>The updates range from Schema changes, primary keys updates to some Million Records updated, corrected or Inserted.</p>
<p>The weekend is hardly enough for the job.</p>
<p>We set up a dedicated server for the job,
turned the Database SINGLE_USER
made any optimizations we could think of: drop/recreate indexes, relations etc.</p>
<p>Can you propose anything to speedup the process?</p>
<p>SQL SERVER 2000 is not negatiable (not my decision). Updates are run through custom made program and not BULK INSERT.</p>
<p>EDIT:</p>
<p>Schema updates are done by Query analyzer TSQL scripts (one script per Version update)</p>
<p>Data updates are done by C# .net 3.5 app.</p>
<p>Data come from a bunch of Text files (with many problems) and written to local DB.</p>
<p>The computer is not connected to any Network.</p>
| [
{
"answer_id": 323198,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "SqlBulkCopy"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28207/"
] |
323,200 | <p>I am creating a secure web based API that uses HTTPS; however, if I allow the users to configure it (include sending password) using a query string will this also be secure or should I force it to be done via a POST?</p>
| [
{
"answer_id": 36257442,
"author": "Ruchira Randana",
"author_id": 1993577,
"author_profile": "https://Stackoverflow.com/users/1993577",
"pm_score": 6,
"selected": false,
"text": "https://example.com/login?username=alice&password=12345)\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33/"
] |
323,212 | <p>I am developing an .net application which heavely depends on plugins. The application itself contains an connection to a remote server.</p>
<p>Recently I digged into Application domains and see them as the ideal solution for isolating the plugin code from the rest of the application. </p>
<p>However there is one big disadvantage which makes me unable to implement the application domains for hosting the plugins. It seems there is no way to pass an object by reference to another application domain which is needed to pass an reference to the connection object. </p>
<p>I was hoping someone could give me a workaround so I can pass an reference to that object.</p>
<p>Note: Creating a proxy is out of the question, the connection layer already acts as a proxy since the classes are auto generated.</p>
<p>Note2: System.AddIn can not be used as it is not available on the compact framework.</p>
| [
{
"answer_id": 323234,
"author": "Brian Rasmussen",
"author_id": 38206,
"author_profile": "https://Stackoverflow.com/users/38206",
"pm_score": 1,
"selected": false,
"text": "MarshalByRefObject"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2090/"
] |
323,226 | <p>Two ways to normalize a Vector3 object; by calling Vector3.Normalize() and the other by normalizing from scratch:</p>
<pre><code>class Tester {
static Vector3 NormalizeVector(Vector3 v)
{
float l = v.Length();
return new Vector3(v.X / l, v.Y / l, v.Z / l);
}
public static void Main(string[] args)
{
Vector3 v = new Vector3(0.0f, 0.0f, 7.0f);
Vector3 v2 = NormalizeVector(v);
Debug.WriteLine(v2.ToString());
v.Normalize();
Debug.WriteLine(v.ToString());
}
}
</code></pre>
<p>The code above produces this:</p>
<pre><code>X: 0
Y: 0
Z: 1
X: 0
Y: 0
Z: 0.9999999
</code></pre>
<p>Why?</p>
<p>(Bonus points: Why Me?)</p>
| [
{
"answer_id": 323248,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 0,
"selected": false,
"text": "float f = 0.01f;\nConsole.WriteLine (\"{0:G}\", f);\nConsole.WriteLine (\"{0:G}\", (double) f);\n"
},
{
"answer_id": 323263,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 2,
"selected": false,
"text": " l = 1 / v.length();\n return new Vector3(v.X * l, v.Y * l, v.Z * l);\n"
}
] | 2008/11/27 | [
"https://Stackoverflow.com/questions/323226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45603/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.