qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
260,615
|
<p>I am trying this in my Form Load Event</p>
<p><pre><code>
cmdCancel.Attributes.Add("onClick", "document.forms[0].reset();return false;")
</pre></code></p>
<p>but it doesn't clear my form. My form is a "ContentPage", part of a masterpage.</p>
<p>Am I missing something?</p>
|
[
{
"answer_id": 260630,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": " cmdCancel.Attributes.Add(\"onClick\",\"document.getElementById('\" + this.Page.ClientId + \"').reset(); return false;\");\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
260,626
|
<p>What does "type-safe" mean?</p>
|
[
{
"answer_id": 260640,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 8,
"selected": false,
"text": "// Fails, Trying to put an integer in a string\nString one = 1;\n// Also fails.\nint foo = \"bar\";\n int AddTwoNumbers(int a, int b)\n{\n return a + b;\n}\n int Sum = AddTwoNumbers(5, \"5\");\n function AddTwoNumbers(a, b)\n{\n return a + b;\n}\n Sum = AddTwoNumbers(5, \"5\");\n function AddTwoNumbers(a, b)\n{\n return Number(a) + Number(b);\n}\n function AddOnlyTwoNumbers(a, b)\n{\n if (isNaN(a) || isNaN(b))\n return false;\n return Number(a) + Number(b);\n}\n Sum = AddTwoNumbers(5, \" dogs\");\n public class Foo : Bar\n {\n }\n void DoSomething(Bar myBar)\n void DoSomething(Foo myFoo)\n"
},
{
"answer_id": 260652,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 3,
"selected": false,
"text": " void foo(int arg)\n // call foo\n foo(\"hello world\")\n"
},
{
"answer_id": 260657,
"author": "rp.",
"author_id": 2536,
"author_profile": "https://Stackoverflow.com/users/2536",
"pm_score": 2,
"selected": false,
"text": "object x = 89;\nint y;\n y = x;\n y = Convert.ToInt32( x );\n Session[ \"x\" ] = 34;\n int i = Convert.ToInt32( Session[ \"x\" ] );\n"
},
{
"answer_id": 21144117,
"author": "Shivprasad Koirala",
"author_id": 993672,
"author_profile": "https://Stackoverflow.com/users/993672",
"pm_score": 3,
"selected": false,
"text": "<script>\nvar num = 5; // numeric\nvar str = \"5\"; // string\nvar z = num + str; // arthimetic or concat ????\nalert(z); // displays “55”\n</script>\n"
},
{
"answer_id": 25157350,
"author": "Nicolas Rinaudo",
"author_id": 1370349,
"author_profile": "https://Stackoverflow.com/users/1370349",
"pm_score": 6,
"selected": false,
"text": "X X y y(X) Object Consumer"
},
{
"answer_id": 48176188,
"author": "Gr3go",
"author_id": 3536926,
"author_profile": "https://Stackoverflow.com/users/3536926",
"pm_score": 5,
"selected": false,
"text": "char int char: |-|-|-|-|-|-|-|-| int : |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| int >> char: |-|-|-|-|-|-|-|-| |?|?|?|?|?|?|?|?| |?|?|?|?|?|?|?|?| |?|?|?|?|?|?|?|?| undefined |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| undefined"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,627
|
<p>This drop down list, displaying all the files from a folder, one of which will be selected for use. Is there a way to show which file is selected when you load the page? At the moment it says "select a file" every time.</p>
<pre><code><select name="image" type="text" class="box" id="image" value="<?=$image;?>">
<option value='empty'>Select a file</option>
<?php
$dirname = "images/";
$images = scandir($dirname);
// This is how you sort an array, see http://php.net/sort
natsort($images);
// There's no need to use a directory handler, just loop through your $images array.
foreach ($images as $file) {
if (substr($file, -4) == ".gif") {
print "<option value='$file'>$file</option>\n"; }
}
?>
</select>
</code></pre>
|
[
{
"answer_id": 260640,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 8,
"selected": false,
"text": "// Fails, Trying to put an integer in a string\nString one = 1;\n// Also fails.\nint foo = \"bar\";\n int AddTwoNumbers(int a, int b)\n{\n return a + b;\n}\n int Sum = AddTwoNumbers(5, \"5\");\n function AddTwoNumbers(a, b)\n{\n return a + b;\n}\n Sum = AddTwoNumbers(5, \"5\");\n function AddTwoNumbers(a, b)\n{\n return Number(a) + Number(b);\n}\n function AddOnlyTwoNumbers(a, b)\n{\n if (isNaN(a) || isNaN(b))\n return false;\n return Number(a) + Number(b);\n}\n Sum = AddTwoNumbers(5, \" dogs\");\n public class Foo : Bar\n {\n }\n void DoSomething(Bar myBar)\n void DoSomething(Foo myFoo)\n"
},
{
"answer_id": 260652,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 3,
"selected": false,
"text": " void foo(int arg)\n // call foo\n foo(\"hello world\")\n"
},
{
"answer_id": 260657,
"author": "rp.",
"author_id": 2536,
"author_profile": "https://Stackoverflow.com/users/2536",
"pm_score": 2,
"selected": false,
"text": "object x = 89;\nint y;\n y = x;\n y = Convert.ToInt32( x );\n Session[ \"x\" ] = 34;\n int i = Convert.ToInt32( Session[ \"x\" ] );\n"
},
{
"answer_id": 21144117,
"author": "Shivprasad Koirala",
"author_id": 993672,
"author_profile": "https://Stackoverflow.com/users/993672",
"pm_score": 3,
"selected": false,
"text": "<script>\nvar num = 5; // numeric\nvar str = \"5\"; // string\nvar z = num + str; // arthimetic or concat ????\nalert(z); // displays “55”\n</script>\n"
},
{
"answer_id": 25157350,
"author": "Nicolas Rinaudo",
"author_id": 1370349,
"author_profile": "https://Stackoverflow.com/users/1370349",
"pm_score": 6,
"selected": false,
"text": "X X y y(X) Object Consumer"
},
{
"answer_id": 48176188,
"author": "Gr3go",
"author_id": 3536926,
"author_profile": "https://Stackoverflow.com/users/3536926",
"pm_score": 5,
"selected": false,
"text": "char int char: |-|-|-|-|-|-|-|-| int : |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| int >> char: |-|-|-|-|-|-|-|-| |?|?|?|?|?|?|?|?| |?|?|?|?|?|?|?|?| |?|?|?|?|?|?|?|?| undefined |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| |-|-|-|-|-|-|-|-| undefined"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32972/"
] |
260,658
|
<p>Via command line, I usually do this:</p>
<pre><code>cp -rRp /path/to/a\_folder/. /path/to/another\_folder
</code></pre>
<p>This copies just the contents underneath <strong>a_folder</strong> to <strong>another_folder</strong>. In SVN I need to do the same thing, but can't figure it out. I always end up with this:</p>
<pre><code>/path/to/another\_folder/a\_folder
</code></pre>
<p>SVN throws up even when I try this:</p>
<pre><code>svn copy file:///path/to/a\_folder/* file:///path/to/another\_folder
</code></pre>
<p>It says it does not exist.</p>
<p><strong>EDIT:</strong></p>
<p>This would probably help. The directory structure for my project looks like this:</p>
<pre><code>my_project
/branches
/tags
/trunk
/vendor
/1.1
</code></pre>
<p>I need to get the contents of 1.1 under vendor into the trunk without it actually copying the 1.1 folder.</p>
|
[
{
"answer_id": 260706,
"author": "Jerub",
"author_id": 14648,
"author_profile": "https://Stackoverflow.com/users/14648",
"pm_score": 4,
"selected": true,
"text": "trunk/a_folder/foo\ntrunk/a_folder/bar\ntrunk/new_folder/baz\n cd trunk/new_folder\nsvn merge -r1:HEAD http://svn/repo/trunk/a_folder .\n"
},
{
"answer_id": 260737,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 0,
"selected": false,
"text": "svn copy -m\"Copy Directory\" file:///path/to/a_folder file:///path/to/another_folder\n /*"
},
{
"answer_id": 261055,
"author": "bendin",
"author_id": 33412,
"author_profile": "https://Stackoverflow.com/users/33412",
"pm_score": 5,
"selected": false,
"text": "trunk vendor/1.1"
},
{
"answer_id": 10020147,
"author": "Mike Wodarczyk",
"author_id": 1313982,
"author_profile": "https://Stackoverflow.com/users/1313982",
"pm_score": 2,
"selected": false,
"text": "/tags/version-1.0/ /trunk /tags/version-1.0/trunk/stuff /tags/version-1.0/stuff svn copy http://localhost/MyProject/trunk http://localhost/MyProject/tags/\n\n# now I have /MyProject/tags/trunk\n\nsvn rename http://localhost/MyProject/tags/trunk http://localhost/MyProject/tags/version-1.0\n"
},
{
"answer_id": 11315358,
"author": "dushshantha",
"author_id": 258115,
"author_profile": "https://Stackoverflow.com/users/258115",
"pm_score": 3,
"selected": false,
"text": "svn cp <URL>/HEAD/ <URL>/branches/07-03-2012 -m \"test\"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,663
|
<p>I started web programming with raw PHP, gradually moving on to its various frameworks, then to Django and Rails. In every framework I've used, pretty much everything I need to do with a database (even involving relatively complex things like many-to-many relationships) could be taken care of by the automatically generated database API without much work. Those few operations that were more complex could be done with straight SQL or by tying together multiple API calls.</p>
<p>Now I'm starting to learn Java, and it's confusing me that the language celebrated for being so robust for back-end infrastructure requires so much more code (doesn't that mean harder to maintain?) to do simple things. Example from a tutorial: say you want to search by last name. You write the method in the DAO using Hibernate query language, then you write a method in the Service to call it (couldn't that be automated?), then you call the Service method from the controller. Whereas in any other framework I've worked with, you could call something to the effect of</p>
<pre><code>Person.find_by_last_name(request.POST['last_name'])
</code></pre>
<p>Straight out of the controller - you don't have to write anything custom to do something like that.</p>
<p>Is there some kind of code generation I haven't found yet? Something in Eclipse? Just doesn't seem right to me that the language regraded as one of the best choices for complex back-ends is so much harder to work with. Is there something I'm missing?</p>
|
[
{
"answer_id": 260746,
"author": "CodingWithSpike",
"author_id": 28278,
"author_profile": "https://Stackoverflow.com/users/28278",
"pm_score": 2,
"selected": false,
"text": "Controller -> Service -> DAO\n"
},
{
"answer_id": 261063,
"author": "jb.",
"author_id": 7918,
"author_profile": "https://Stackoverflow.com/users/7918",
"pm_score": 1,
"selected": false,
"text": " #{PersonHome.instance.name} \n <h:commandLink action=\"#{PersonHome.delete(person}\">\n delete"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,664
|
<p>I have a PHP app that needs to run bash scripts, and provide a username & password (for remote systems).
I need to store these credentials somewhere that is accessible by my PHP (web) app.
The logical place is the database (currently MySQL, but will be agnostic).
The problem with the "standard" way of hashing and storing the credentials, is that it is not reversible. I <em>have</em> to be able to get the credentials out as unencrypted clear text, to be able to insert the data into bash scripts.</p>
<p>Does anyone have any suggestions for a secure way to go about this ?</p>
<p>I thought maybe PKI'ing the credentials, and storing the result in the DB. Then use the private key to unencrypt (PHP can do that). Store the scripts to do this outside the web root.</p>
<p>Any thoughts much appreciated.</p>
|
[
{
"answer_id": 260709,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 1,
"selected": false,
"text": "INSERT INTO tbl_passwords SET encoded_pw = ENCODE('r00t', 'my-salt-string');\n SELECT DECODE(encoded_pw, 'my-salt-string') FROM tbl_passwords;\n"
},
{
"answer_id": 313187,
"author": "Polsonby",
"author_id": 137,
"author_profile": "https://Stackoverflow.com/users/137",
"pm_score": 0,
"selected": false,
"text": "AES_ENCRYPT() AES_DECRYPT() SELECT AES_ENCRYPT('secret squirrel', '12345678') AS encoded\n\n=> ØA;J×ÍfOU»] É8\n\nSELECT AES_DECRYPT('ØA;J×ÍfOU»] É8', '12345678') AS decoded\n\n=> secret squirrel\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,666
|
<p>Can an abstract class have a constructor?</p>
<p>If so, how can it be used and for what purposes?</p>
|
[
{
"answer_id": 260686,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "abstract class Product { \n int value;\n public Product( int val ) {\n value= val;\n }\n abstract public int multiply();\n}\n\nclass TimesTwo extends Product {\n public int mutiply() {\n return value * 2;\n }\n}\n"
},
{
"answer_id": 260755,
"author": "Michael Rutherfurd",
"author_id": 33889,
"author_profile": "https://Stackoverflow.com/users/33889",
"pm_score": 11,
"selected": true,
"text": "abstract class Product { \n int multiplyBy;\n public Product( int multiplyBy ) {\n this.multiplyBy = multiplyBy;\n }\n\n public int mutiply(int val) {\n return multiplyBy * val;\n }\n}\n\nclass TimesTwo extends Product {\n public TimesTwo() {\n super(2);\n }\n}\n\nclass TimesWhat extends Product {\n public TimesWhat(int what) {\n super(what);\n }\n}\n Product TimesTwo TimesWhat"
},
{
"answer_id": 17714904,
"author": "jaideep",
"author_id": 2587223,
"author_profile": "https://Stackoverflow.com/users/2587223",
"pm_score": 2,
"selected": false,
"text": "public abstract class TestEngine\n{\n private String engineId;\n private String engineName;\n\n public TestEngine(String engineId , String engineName)\n {\n this.engineId = engineId;\n this.engineName = engineName;\n }\n //public gettors and settors\n public abstract void scheduleTest();\n}\n\n\npublic class JavaTestEngine extends TestEngine\n{\n\n private String typeName;\n\n public JavaTestEngine(String engineId , String engineName , String typeName)\n {\n super(engineId , engineName);\n this.typeName = typeName;\n }\n\n public void scheduleTest()\n {\n //do Stuff\n }\n}\n"
},
{
"answer_id": 29781391,
"author": "Ketan G",
"author_id": 4252869,
"author_profile": "https://Stackoverflow.com/users/4252869",
"pm_score": 3,
"selected": false,
"text": "abstract class Figure { \n\n double dim1; \n double dim2; \n\n Figure(double a, double b) { \n dim1 = a; \n dim2 = b; \n }\n\n // area is now an abstract method \n\n abstract double area(); \n\n}\n\n\nclass Rectangle extends Figure { \n Rectangle(double a, double b) { \n super(a, b); \n } \n // override area for rectangle \n double area() { \n System.out.println(\"Inside Area for Rectangle.\"); \n return dim1 * dim2; \n } \n}\n\nclass Triangle extends Figure { \n Triangle(double a, double b) { \n super(a, b); \n } \n // override area for right triangle \n double area() { \n System.out.println(\"Inside Area for Triangle.\"); \n return dim1 * dim2 / 2; \n } \n}\n\nclass AbstractAreas { \n public static void main(String args[]) { \n // Figure f = new Figure(10, 10); // illegal now \n Rectangle r = new Rectangle(9, 5); \n Triangle t = new Triangle(10, 8); \n Figure figref; // this is OK, no object is created \n figref = r; \n System.out.println(\"Area is \" + figref.area()); \n figref = t; \n System.out.println(\"Area is \" + figref.area()); \n } \n}\n"
},
{
"answer_id": 46075444,
"author": "Harshil",
"author_id": 1636874,
"author_profile": "https://Stackoverflow.com/users/1636874",
"pm_score": 3,
"selected": false,
"text": "public abstract class Abs{\n int i;\n int j;\n public Abs(int i,int j){\n this.i = i;\n this.j = j;\n System.out.println(i+\" \"+j);\n }\n}\n public class Imp extends Abs{\n\npublic Imp(int i, int j,int k, int l){\n System.out.println(\"2 arg\");\n}\n}\n public class Imp extends Abs{\n\npublic Imp(int i, int j,int k, int l){\n super(i,j);\n System.out.println(\"2 arg\");\n}\n}\n"
},
{
"answer_id": 46250908,
"author": "chamzz.dot",
"author_id": 5983136,
"author_profile": "https://Stackoverflow.com/users/5983136",
"pm_score": 2,
"selected": false,
"text": "// An abstract class with constructor\nabstract class Base {\nBase() { System.out.println(\"Base Constructor Called\"); }\nabstract void fun();\n }\nclass Derived extends Base {\nDerived() { System.out.println(\"Derived Constructor Called\"); }\nvoid fun() { System.out.println(\"Derived fun() called\"); }\n }\n\nclass Main {\npublic static void main(String args[]) { \n Derived d = new Derived();\n }\n\n}\n"
},
{
"answer_id": 48429852,
"author": "karto",
"author_id": 648608,
"author_profile": "https://Stackoverflow.com/users/648608",
"pm_score": 0,
"selected": false,
"text": "public abstract class Employee {\n private String EmpName;\n abstract double calcSalary();\n\n Employee(String name) {\n this.EmpName = name;// constructor of abstract class super class\n }\n}\n\nclass Manager extends Employee{\n Manager(String name) {\n super(name);// setting the name in the constructor of sub class\n }\ndouble calcSalary() {\n return 0;\n }\n}\n"
},
{
"answer_id": 57777918,
"author": "sachit",
"author_id": 8097510,
"author_profile": "https://Stackoverflow.com/users/8097510",
"pm_score": 0,
"selected": false,
"text": "package Test1;\n\npublic class AbstractClassConstructor {\n\n public AbstractClassConstructor() {\n \n }\n\n public static void main(String args[]) {\n Demo obj = new Test(\"Test of code has started\");\n obj.test1();\n }\n}\n\nabstract class Demo{\n protected final String demoValue;\n \n public Demo(String testName){\n this.demoValue = testName;\n }\n \n public abstract boolean test1();\n}\n\nclass Test extends Demo{\n \n public Test(String name){\n super(name);\n }\n\n @Override\n public boolean test1() {\n System.out.println( this.demoValue + \" Demo test started\");\n return true;\n }\n \n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33885/"
] |
260,668
|
<p>I'm curious about people's experiences using AR's to_xml() to build non-entity fields (as in, not an attribute of the model you are serializing, but perhaps, utilizing the attributes in the process) from a controller. </p>
<p>to_xml seems to supply a few options for doing this. </p>
<p>One is by passing in references to methods on the object being acted on: during the serialization process, these methods are invoked and their results are added to the generated document. I'd like to avoid this path because some of the generated data, while depending on the object's attributes, could be outside of the scope of the model itself -- e.g., building a URL to a particular items "show" action. Plus, it requires too much forethought. I'd like to just be able to change the resultant document by tweaking the to_xml code from the controller. I don't want the hassle of having to declare a method in the object as well. </p>
<p>The same goes for overriding to_xml in each object. </p>
<p>The other two options seem to fit the bill a little better: one is by passing in procs in the serialization options that generate these fields, and the other is by passing in a block that will yielded to after serialization the objects attributes. These provide the kind of at-the-point-of-invocation customizing that I'm looking for, and in addition, their declarations bind the scope to the controller so that they have access to the same stuff that the controller does, but these methods seem critically limited: AFAICT they contain no reference to the object being serialized. They contain references to the builder object, which, sure I guess you could parse within the block/proc and find the attributes that have already been serialized and use them, but that's a harangue, or at least uneasy and suboptimal. </p>
<p>Correct me if I'm wrong here, but what is the point of having procs/blocks available when serializing one or more objects if you have to access to the object itself.</p>
<p>Anyway, please tell me how I'm wrong, because it seems like I must be overlooking something here. </p>
<p>Oh and yeah, I know that I could write my own view. I'm trying to leverage respond_to and to_xml to achieve minimal extra files/lines. (Though, that is what I resorted to when I couldn't figure out how to do this with AR's serialization.)</p>
<p>**EDIT 3.29.09 -- I just submitted a patch for this to Rails. If you're interested, show some support :) <a href="https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2373-record-sensitive-procs-for-to_xml" rel="nofollow noreferrer">https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2373-record-sensitive-procs-for-to_xml</a></p>
|
[
{
"answer_id": 260686,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "abstract class Product { \n int value;\n public Product( int val ) {\n value= val;\n }\n abstract public int multiply();\n}\n\nclass TimesTwo extends Product {\n public int mutiply() {\n return value * 2;\n }\n}\n"
},
{
"answer_id": 260755,
"author": "Michael Rutherfurd",
"author_id": 33889,
"author_profile": "https://Stackoverflow.com/users/33889",
"pm_score": 11,
"selected": true,
"text": "abstract class Product { \n int multiplyBy;\n public Product( int multiplyBy ) {\n this.multiplyBy = multiplyBy;\n }\n\n public int mutiply(int val) {\n return multiplyBy * val;\n }\n}\n\nclass TimesTwo extends Product {\n public TimesTwo() {\n super(2);\n }\n}\n\nclass TimesWhat extends Product {\n public TimesWhat(int what) {\n super(what);\n }\n}\n Product TimesTwo TimesWhat"
},
{
"answer_id": 17714904,
"author": "jaideep",
"author_id": 2587223,
"author_profile": "https://Stackoverflow.com/users/2587223",
"pm_score": 2,
"selected": false,
"text": "public abstract class TestEngine\n{\n private String engineId;\n private String engineName;\n\n public TestEngine(String engineId , String engineName)\n {\n this.engineId = engineId;\n this.engineName = engineName;\n }\n //public gettors and settors\n public abstract void scheduleTest();\n}\n\n\npublic class JavaTestEngine extends TestEngine\n{\n\n private String typeName;\n\n public JavaTestEngine(String engineId , String engineName , String typeName)\n {\n super(engineId , engineName);\n this.typeName = typeName;\n }\n\n public void scheduleTest()\n {\n //do Stuff\n }\n}\n"
},
{
"answer_id": 29781391,
"author": "Ketan G",
"author_id": 4252869,
"author_profile": "https://Stackoverflow.com/users/4252869",
"pm_score": 3,
"selected": false,
"text": "abstract class Figure { \n\n double dim1; \n double dim2; \n\n Figure(double a, double b) { \n dim1 = a; \n dim2 = b; \n }\n\n // area is now an abstract method \n\n abstract double area(); \n\n}\n\n\nclass Rectangle extends Figure { \n Rectangle(double a, double b) { \n super(a, b); \n } \n // override area for rectangle \n double area() { \n System.out.println(\"Inside Area for Rectangle.\"); \n return dim1 * dim2; \n } \n}\n\nclass Triangle extends Figure { \n Triangle(double a, double b) { \n super(a, b); \n } \n // override area for right triangle \n double area() { \n System.out.println(\"Inside Area for Triangle.\"); \n return dim1 * dim2 / 2; \n } \n}\n\nclass AbstractAreas { \n public static void main(String args[]) { \n // Figure f = new Figure(10, 10); // illegal now \n Rectangle r = new Rectangle(9, 5); \n Triangle t = new Triangle(10, 8); \n Figure figref; // this is OK, no object is created \n figref = r; \n System.out.println(\"Area is \" + figref.area()); \n figref = t; \n System.out.println(\"Area is \" + figref.area()); \n } \n}\n"
},
{
"answer_id": 46075444,
"author": "Harshil",
"author_id": 1636874,
"author_profile": "https://Stackoverflow.com/users/1636874",
"pm_score": 3,
"selected": false,
"text": "public abstract class Abs{\n int i;\n int j;\n public Abs(int i,int j){\n this.i = i;\n this.j = j;\n System.out.println(i+\" \"+j);\n }\n}\n public class Imp extends Abs{\n\npublic Imp(int i, int j,int k, int l){\n System.out.println(\"2 arg\");\n}\n}\n public class Imp extends Abs{\n\npublic Imp(int i, int j,int k, int l){\n super(i,j);\n System.out.println(\"2 arg\");\n}\n}\n"
},
{
"answer_id": 46250908,
"author": "chamzz.dot",
"author_id": 5983136,
"author_profile": "https://Stackoverflow.com/users/5983136",
"pm_score": 2,
"selected": false,
"text": "// An abstract class with constructor\nabstract class Base {\nBase() { System.out.println(\"Base Constructor Called\"); }\nabstract void fun();\n }\nclass Derived extends Base {\nDerived() { System.out.println(\"Derived Constructor Called\"); }\nvoid fun() { System.out.println(\"Derived fun() called\"); }\n }\n\nclass Main {\npublic static void main(String args[]) { \n Derived d = new Derived();\n }\n\n}\n"
},
{
"answer_id": 48429852,
"author": "karto",
"author_id": 648608,
"author_profile": "https://Stackoverflow.com/users/648608",
"pm_score": 0,
"selected": false,
"text": "public abstract class Employee {\n private String EmpName;\n abstract double calcSalary();\n\n Employee(String name) {\n this.EmpName = name;// constructor of abstract class super class\n }\n}\n\nclass Manager extends Employee{\n Manager(String name) {\n super(name);// setting the name in the constructor of sub class\n }\ndouble calcSalary() {\n return 0;\n }\n}\n"
},
{
"answer_id": 57777918,
"author": "sachit",
"author_id": 8097510,
"author_profile": "https://Stackoverflow.com/users/8097510",
"pm_score": 0,
"selected": false,
"text": "package Test1;\n\npublic class AbstractClassConstructor {\n\n public AbstractClassConstructor() {\n \n }\n\n public static void main(String args[]) {\n Demo obj = new Test(\"Test of code has started\");\n obj.test1();\n }\n}\n\nabstract class Demo{\n protected final String demoValue;\n \n public Demo(String testName){\n this.demoValue = testName;\n }\n \n public abstract boolean test1();\n}\n\nclass Test extends Demo{\n \n public Test(String name){\n super(name);\n }\n\n @Override\n public boolean test1() {\n System.out.println( this.demoValue + \" Demo test started\");\n return true;\n }\n \n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33866/"
] |
260,672
|
<p>There are some tasks, especially the ones that involve deleting folders as SU, that I do thoughtfully and slowly before I press the Enter key. I think if others saw me do these at the careful pace that I do they would cringe. Are there critical programming tasks that you perform that you believe deserve this thoughtful and careful consideration?</p>
|
[
{
"answer_id": 263428,
"author": "Chris Burgess",
"author_id": 6624,
"author_profile": "https://Stackoverflow.com/users/6624",
"pm_score": 0,
"selected": false,
"text": "select * into myTable_backup from myTable"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,679
|
<p>If I have a table like:</p>
<pre><code>CREATE TABLE FRED
(
recordId number(18) primary key,
firstName varchar2(50)
);
</code></pre>
<p>Is there an easy way to clone it's structure (not it's data) into another table of a given name. Basically I want to create table with exactly the same structure, but a different name, so that I can perform some functionality on it. I want to do this in code obviously. Java preferably, but most other languages should be similar.</p>
|
[
{
"answer_id": 260771,
"author": "Salamander2007",
"author_id": 10629,
"author_profile": "https://Stackoverflow.com/users/10629",
"pm_score": 5,
"selected": true,
"text": "select dbms_metadata.get_ddl('TABLE', 'TABLE_NAME', 'SCHEMA_NAME') from dual\n"
},
{
"answer_id": 62470385,
"author": "Priya Ranjan Kumar",
"author_id": 6869840,
"author_profile": "https://Stackoverflow.com/users/6869840",
"pm_score": 0,
"selected": false,
"text": "SELECT INTO TARGET_TABLE FROM SOURCE_TABLE;\nOR\n\nCREATE TABLE TARGET_TABLE_NAME AS SELECT * FROM SOURCE_TABLE;\n WHERE 1=2"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
260,685
|
<p>I have been using <a href="http://www.plt-scheme.org/" rel="noreferrer">PLT Scheme</a>, but it has some issues. Does anyone know of a better implementation for working through SICP?</p>
|
[
{
"answer_id": 262886,
"author": "soegaard",
"author_id": 23567,
"author_profile": "https://Stackoverflow.com/users/23567",
"pm_score": 7,
"selected": false,
"text": "raco"
},
{
"answer_id": 39024828,
"author": "htanata",
"author_id": 4353,
"author_profile": "https://Stackoverflow.com/users/4353",
"pm_score": 2,
"selected": false,
"text": "chicken-install sicp (use sicp)"
},
{
"answer_id": 40561892,
"author": "Frederick Squid",
"author_id": 6778597,
"author_profile": "https://Stackoverflow.com/users/6778597",
"pm_score": 3,
"selected": false,
"text": "brew update brew cask install racket\nraco setup # might be optional\nraco pkg install sicp\n (require sicp) racket -l sicp --repl\n scheme alias scheme='racket -l sicp --repl'\n ~/.bashrc"
},
{
"answer_id": 47999936,
"author": "Isaac Rabinovitch",
"author_id": 1406641,
"author_profile": "https://Stackoverflow.com/users/1406641",
"pm_score": 0,
"selected": false,
"text": "brew chezscheme\nman chez\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25573/"
] |
260,701
|
<p>I'm looking for one line code examples in various languages for getting a valid MD5 result (as a string, not a bytehash or what have you). For instance:</p>
<p>PHP:
$token = md5($var1 . $var2);</p>
<p>I found VB especially troublesome to do in one line.</p>
|
[
{
"answer_id": 260715,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 2,
"selected": false,
"text": "token = __import__('md5').new(var1 + var2).hexdigest()\n md5 token = md5.new(var1 + var2).hexdigest()\n"
},
{
"answer_id": 260717,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 2,
"selected": false,
"text": "md5_in_one_line Md5InOneLine Md5InOneLine"
},
{
"answer_id": 260722,
"author": "Kibbee",
"author_id": 1862,
"author_profile": "https://Stackoverflow.com/users/1862",
"pm_score": 0,
"selected": false,
"text": "Dim MD5 As New System.Security.Cryptography.MD5CryptoServiceProvider() : Dim HashBytes() As Byte : Dim MD5Str As String = \"\" : HashBytes = MD5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(\"MyString\")) : For i As Integer = 0 To HashBytes.Length - 1 : MD5Str &= HashBytes(i).ToString(\"x\").PadLeft(2, \"0\") : Next\n"
},
{
"answer_id": 260725,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": "string hash = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(input, \"md5\");\n string hash = Convert.ToBase64String(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)));\n string hash =\n Convert.ToBase64String\n (new System.Security.Cryptography.MD5CryptoServiceProvider()\n .ComputeHash\n (System.Text.Encoding.UTF8.GetBytes\n (input)\n )\n );\n"
},
{
"answer_id": 260780,
"author": "Michal",
"author_id": 21672,
"author_profile": "https://Stackoverflow.com/users/21672",
"pm_score": 1,
"selected": false,
"text": "hash = (new MD5).hash(\"some value\")\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33886/"
] |
260,703
|
<p>Here is some simple Perl to count the number of times a value occurs in an array. This runs without any warnings.</p>
<pre><code>use warnings;
use strict;
my @data = qw(1 1 2 3 4 5 5 5 9);
my %histogram;
foreach (@data)
{
$histogram{$_}++;
}
</code></pre>
<p>When the loop body is changed to</p>
<pre><code>$histogram{$_} = $histogram{$_} + 1;
</code></pre>
<p>Perl warns "Use of uninitialized value in addition".</p>
<p>What is going on under the hood? Why is the value initialized when supplied as an operand to the ++ operator and uninitialized with the + operator?</p>
|
[
{
"answer_id": 260862,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 0,
"selected": false,
"text": "$histogram{$_} my $hash_ref = $hash_for{$key_level_1};\n$hash_ref->{$key_level_2} = $value;\n $hash_for{$key_level_1}{$key_level_2} = $value;\n a = a + 1 a++"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25164/"
] |
260,716
|
<p>I'm using a <code>RichTextBox</code> (.NET WinForms 3.5) and would like to override some of the standard ShortCut keys....
For example, I don't want <kbd>Ctrl</kbd>+<kbd>I</kbd> to make the text italic via the RichText method, but to instead run my own method for processing the text.</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 260821,
"author": "Jim Burger",
"author_id": 20164,
"author_profile": "https://Stackoverflow.com/users/20164",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Windows.Forms;\n\nnamespace WindowsFormsApplication1\n{\n public partial class Form1 : Form\n {\n public Form1()\n {\n InitializeComponent();\n this.textBox1.ShortcutsEnabled = false;\n this.textBox1.KeyUp += new KeyEventHandler(textBox1_KeyUp);\n }\n\n void textBox1_KeyUp(object sender, KeyEventArgs e)\n {\n if (e.Control == true && e.KeyCode == Keys.X)\n MessageBox.Show(\"Overriding ctrl+x\");\n }\n }\n}\n"
},
{
"answer_id": 260859,
"author": "sliderhouserules",
"author_id": 31385,
"author_profile": "https://Stackoverflow.com/users/31385",
"pm_score": 4,
"selected": true,
"text": "private void YourRichTextBox_KeyDown(object sender, KeyEventArgs e)\n{\n if ((Control.ModifierKeys & Keys.Control) == Keys.Control && e.KeyCode == Keys.I)\n {\n // do whatever you want to do here...\n e.SuppressKeyPress = true;\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/194/"
] |
260,723
|
<p>I have a Tapestry PropertyModel for gender. Right now the dropdown just shows Male and Female because those are the only values in my model. I'd like to add a "Choose an Option" option. Is there a standard way to do this without having to add a fake value to my model? I'd also like it to be smart enough to know that if the field is required, they can't leave it set to "Choose an Option".</p>
|
[
{
"answer_id": 260967,
"author": "Brian Deterling",
"author_id": 14619,
"author_profile": "https://Stackoverflow.com/users/14619",
"pm_score": 1,
"selected": false,
"text": "new LabeledPropertySelectionModel(new GenderModel(), \"Choose an Option\")\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14619/"
] |
260,729
|
<p>Are the two events the same or are there differences that we should take note when coding the keyboard presses?</p>
|
[
{
"answer_id": 262473,
"author": "Fry",
"author_id": 23553,
"author_profile": "https://Stackoverflow.com/users/23553",
"pm_score": 1,
"selected": false,
"text": "ctrlPressed=true ctrlPressed=false;"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26087/"
] |
260,738
|
<p>How can I play audio (it would be like a 1 second sound) from a Python script?</p>
<p>It would be best if it was platform independent, but firstly it needs to work on a Mac.</p>
<p>I know I could just execute the <code>afplay file.mp3</code> command from within Python, but is it possible to do it in raw Python? I would also be better if it didn't rely on external libraries.</p>
|
[
{
"answer_id": 260901,
"author": "TML",
"author_id": 33918,
"author_profile": "https://Stackoverflow.com/users/33918",
"pm_score": 6,
"selected": false,
"text": "pygame.mixer.init()\npygame.mixer.music.load(\"file.mp3\")\npygame.mixer.music.play()\n"
},
{
"answer_id": 14018627,
"author": "user1926182",
"author_id": 1926182,
"author_profile": "https://Stackoverflow.com/users/1926182",
"pm_score": 3,
"selected": false,
"text": "s = Sound() \ns.read('sound.wav') \ns.play()\n"
},
{
"answer_id": 20746883,
"author": "Jiaaro",
"author_id": 2908,
"author_profile": "https://Stackoverflow.com/users/2908",
"pm_score": 4,
"selected": false,
"text": "import subprocess\n\ndef play(audio_file_path):\n subprocess.call([\"ffplay\", \"-nodisp\", \"-autoexit\", audio_file_path])\n -nodisp -autoexit"
},
{
"answer_id": 28248604,
"author": "MikeiLL",
"author_id": 2223106,
"author_profile": "https://Stackoverflow.com/users/2223106",
"pm_score": 2,
"selected": false,
"text": "import subprocess\nsubprocess.call([\"afplay\", \"path/to/audio/file\"])\n"
},
{
"answer_id": 34179010,
"author": "Matthias",
"author_id": 500098,
"author_profile": "https://Stackoverflow.com/users/500098",
"pm_score": 4,
"selected": false,
"text": "pip install sounddevice --user\n import sounddevice as sd\nsd.play(myarray, 44100)\n"
},
{
"answer_id": 34568298,
"author": "Aaron",
"author_id": 5738607,
"author_profile": "https://Stackoverflow.com/users/5738607",
"pm_score": 2,
"selected": false,
"text": "import wave\nimport io\nfrom AppKit import NSSound\n\n\nwave_output = io.BytesIO()\nwave_shell = wave.open(wave_output, mode=\"wb\")\nfile_path = 'SINE.WAV'\ninput_audio = wave.open(file_path)\ninput_audio_frames = input_audio.readframes(input_audio.getnframes())\n\nwave_shell.setnchannels(input_audio.getnchannels())\nwave_shell.setsampwidth(input_audio.getsampwidth())\nwave_shell.setframerate(input_audio.getframerate())\n\nseconds_multiplier = input_audio.getnchannels() * input_audio.getsampwidth() * input_audio.getframerate()\n\nwave_shell.writeframes(input_audio_frames[second_multiplier:second_multiplier*5])\n\nwave_shell.close()\n\nwave_output.seek(0)\nwave_data = wave_output.read()\naudio_stream = NSSound.alloc()\naudio_stream.initWithData_(wave_data)\naudio_stream.play()\n"
},
{
"answer_id": 34984200,
"author": "ArtOfWarfare",
"author_id": 901641,
"author_profile": "https://Stackoverflow.com/users/901641",
"pm_score": 3,
"selected": false,
"text": "from AppKit import NSSound\n\nsound = NSSound.alloc()\nsound.initWithContentsOfFile_byReference_('/path/to/file.wav', True)\nsound.play()\n from time import sleep\n\nsleep(sound.duration())\n pip install playsound\n from playsound import playsound\nplaysound('/path/to/file.wav', block = False)\n"
},
{
"answer_id": 36115093,
"author": "pyAddict",
"author_id": 6085779,
"author_profile": "https://Stackoverflow.com/users/6085779",
"pm_score": -1,
"selected": false,
"text": "import os\nos.popen2(\"cvlc /home/maulo/selfProject/task.mp3 --play-and-exit\")\n"
},
{
"answer_id": 36284043,
"author": "Erwin Mayer",
"author_id": 541420,
"author_profile": "https://Stackoverflow.com/users/541420",
"pm_score": 4,
"selected": false,
"text": "> pip install simpleaudio\n import simpleaudio as sa\n\nwave_obj = sa.WaveObject.from_wave_file(\"path/to/file.wav\")\nplay_obj = wave_obj.play()\nplay_obj.wait_done()\n"
},
{
"answer_id": 37501920,
"author": "Stefan Balke",
"author_id": 4236224,
"author_profile": "https://Stackoverflow.com/users/4236224",
"pm_score": 2,
"selected": false,
"text": "from pysoundcard import Stream\n\n\"\"\"Loop back five seconds of audio data.\"\"\"\n\nfs = 44100\nblocksize = 16\ns = Stream(samplerate=fs, blocksize=blocksize)\ns.start()\nfor n in range(int(fs*5/blocksize)):\n s.write(s.read(blocksize))\ns.stop()\n"
},
{
"answer_id": 40557072,
"author": "Crawsome",
"author_id": 3059803,
"author_profile": "https://Stackoverflow.com/users/3059803",
"pm_score": 0,
"selected": false,
"text": "import subprocess\n f = './mySound.wav'\nsubprocess.Popen(['aplay','-q',f)\n f = 'mySound.wav'\nsubprocess.Popen(['aplay','-q', 'wav/' + f)\n man aplay\n"
},
{
"answer_id": 46595209,
"author": "n00p",
"author_id": 7909577,
"author_profile": "https://Stackoverflow.com/users/7909577",
"pm_score": 3,
"selected": false,
"text": "import soundfile as sf\nimport soundcard as sc\n\ndefault_speaker = sc.default_speaker()\nsamples, samplerate = sf.read('bell.wav')\n\ndefault_speaker.play(samples, samplerate=samplerate)\n"
},
{
"answer_id": 47512659,
"author": "yehan jaya",
"author_id": 6587830,
"author_profile": "https://Stackoverflow.com/users/6587830",
"pm_score": 6,
"selected": false,
"text": "$ pip install playsound\n from playsound import playsound\nplaysound('/path/to/a/sound/file/you/want/to/play.mp3')\n"
},
{
"answer_id": 48829602,
"author": "Kardi Teknomo",
"author_id": 8208481,
"author_profile": "https://Stackoverflow.com/users/8208481",
"pm_score": 1,
"selected": false,
"text": "# playNote.py \n# Demonstrates how to play a single note.\n\nfrom music import * # import music library\nnote = Note(C4, HN) # create a middle C half note \nPlay.midi(note) # and play it!\n"
},
{
"answer_id": 48928285,
"author": "amarVashishth",
"author_id": 1726847,
"author_profile": "https://Stackoverflow.com/users/1726847",
"pm_score": 1,
"selected": false,
"text": "from subprocess import call\ncall([\"cvlc\", \"--play-and-exit\", \"myNotificationTone.mp3\"])\n"
},
{
"answer_id": 53382739,
"author": "Captain Django",
"author_id": 8931089,
"author_profile": "https://Stackoverflow.com/users/8931089",
"pm_score": 2,
"selected": false,
"text": "import pygame\nimport time\npygame.mixer.init()\npygame.init()\npygame.mixer.music.load('fire alarm sound.mp3') *On my project folder*\ni = 0\nwhile i<10:\n pygame.mixer.music.play(loops=10, start=0.0)\n time.sleep(10)*to protect from closing*\n pygame.mixer.music.set_volume(10)\n i = i + 1\n"
},
{
"answer_id": 59418545,
"author": "Harish",
"author_id": 11616168,
"author_profile": "https://Stackoverflow.com/users/11616168",
"pm_score": 2,
"selected": false,
"text": "playsound pip install playsound\n from playsound import playsound\nplaysound(\"file location\\audio.p3\")\n"
},
{
"answer_id": 61161106,
"author": "Charlie Carrera",
"author_id": 13288564,
"author_profile": "https://Stackoverflow.com/users/13288564",
"pm_score": 1,
"selected": false,
"text": "pip install sounddevice import sounddevice as sd\n sd.play(audio, sr) pip install librosa\n\naudio, sr = librosa.load('wave_file.wav')\n"
},
{
"answer_id": 62307005,
"author": "Axel Bregnsbo",
"author_id": 155425,
"author_profile": "https://Stackoverflow.com/users/155425",
"pm_score": 1,
"selected": false,
"text": "from IPython.display import Audio\nAudio(waveform, Rate=16000)\n"
},
{
"answer_id": 64820911,
"author": "Aastha Varma",
"author_id": 7372453,
"author_profile": "https://Stackoverflow.com/users/7372453",
"pm_score": 2,
"selected": false,
"text": "from IPython.display import Audio\nfrom scipy.io.wavfile import read\n\nfs, data = read('StarWars60.wav', mmap=True) # fs - sampling frequency\ndata = data.reshape(-1, 1)\nAudio(data = data[:, 0], rate = fs)\n import IPython.display import Audio\n\nAudio('audio_file_name.mp3')\n"
},
{
"answer_id": 65461670,
"author": "gleitonfranco",
"author_id": 2466971,
"author_profile": "https://Stackoverflow.com/users/2466971",
"pm_score": 0,
"selected": false,
"text": "audioplayer from audioplayer import AudioPlayer\nAudioPlayer(\"path/to/somemusic.mp3\").play(block=True)\n"
},
{
"answer_id": 69143570,
"author": "mytja",
"author_id": 12900435,
"author_profile": "https://Stackoverflow.com/users/12900435",
"pm_score": 1,
"selected": false,
"text": "pip install libwinmedia import libwinmedia\n\nplayer = libwinmedia.Player(True)\n\nplayer.set_position_callback(lambda position: print(f\"{position} ms.\"))\nmedia = libwinmedia.Media(\"test.mp3\")\n\nplayer.open(media)\n"
},
{
"answer_id": 73038674,
"author": "garydavenport73",
"author_id": 14839886,
"author_profile": "https://Stackoverflow.com/users/14839886",
"pm_score": 1,
"selected": false,
"text": "from preferredsoundplayer import *\nsoundplay(\"audio.wav\")\n pip install preferredsoundplayer"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2592/"
] |
260,742
|
<p>I've got an embedded Windows Media player in an HTML page, and when the audio gets to the end, it just starts again from the beginning.</p>
<p>According to the documentation, there's an <code>autorewind</code> parameter/attribute and also a <code>loop</code>.</p>
<p>The problem is, I've set both of those to <code>false</code> (and/or zero) and it doesn't seem to make any difference.</p>
<p>Might this be a bug? My client is WMP 10.00.00.4058. Maybe there's some kind of setting on the <em>server</em> which tells files to loop, is that a crazy idea?</p>
|
[
{
"answer_id": 293467,
"author": "plan9assembler",
"author_id": 1710672,
"author_profile": "https://Stackoverflow.com/users/1710672",
"pm_score": 0,
"selected": false,
"text": "<object width=\"320\" height=\"290\"\nclassid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\"\nid=\"mediaplayer1\">\n<param name=\"Filename\" value=\"kids.mpg\">\n<param name=\"AutoStart\" value=\"True\">\n<param name=\"ShowControls\" value=\"True\">\n<param name=\"ShowStatusBar\" value=\"False\">\n<param name=\"ShowDisplay\" value=\"False\">\n<param name=\"AutoRewind\" value=\"True\">\n<embed\ntype=\"application/x-mplayer2\"\npluginspage=\"http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/\"\nwidth=\"320\" height=\"290\" src=\"/support/dreamweaver/ts/documents/kids.mpg\"\nfilename=\"kids.mpg\" autostart=\"True\"\nshowcontrols=\"True\" showstatusbar=\"False\"\nshowdisplay=\"False\" autorewind=\"True\">\n</embed>\n</object>\n"
},
{
"answer_id": 724308,
"author": "jerebear",
"author_id": 42979,
"author_profile": "https://Stackoverflow.com/users/42979",
"pm_score": 1,
"selected": false,
"text": "<object id=\"contentPlayer\" classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" width=\"300\" height=\"60\"><!-- <param name='fileName' value=''> -->\n<param name='animationatStart' value='false'>\n<param name='transparentatStart' value='true'>\n<param name='autoStart' value='true'>\n<param name='playState' VALUE='1'>\n<param name='loop' value='false'>\n</OBJECT>\n <object id=\"contentPlayer\" name='contentPlayer' type=\"application/x-ms-wmp\" data=\"\" width=\"300\" height=\"60\"><!-- <param name='fileName' value=''> -->\n<param name='animationatStart' value='false'>\n<param name='transparentatStart' value='true'>\n<param name='autoStart' value='true'>\n<param name='playState' VALUE='1'>\n<param name='loop' value='false'>\n</OBJECT>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/242241/"
] |
260,744
|
<p>An abstract class can only be used as a base class which is extended by some other class, right? The constructor(s) of an abstract class can have the usual access modifiers (public, protected, and private (for internal use)). Which of <code>protected</code> and <code>public</code> is the correct access modifier to use, since the abstract type seems to indicate that technically a public constructor will act very much protected? Should I just use protected on all my constructors?</p>
|
[
{
"answer_id": 260779,
"author": "Jordan Stewart",
"author_id": 33338,
"author_profile": "https://Stackoverflow.com/users/33338",
"pm_score": 6,
"selected": true,
"text": "public class Scratch\n{\n public static abstract class A\n {\n public A( int i ) {}\n }\n\n public static class B extends A\n {\n private B() { super(0); };\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260744",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15075/"
] |
260,745
|
<p>I have a menu with an animation going on, but I want to disable the click while the animation is happening.</p>
<pre><code><div></div>
<div></div>
<div></div>
$("div").click(function() {
$(this).animate({height: "200px"}, 2000);
return false;
});
</code></pre>
<p>However, I want to disable all the buttons while the event is happening, AND disable the div that was clicked. </p>
<p>I was thinking of adding a class to the div that's clicked and putting the click only on the divs without that class:</p>
<pre><code>$("div").not("clicked").click(function() {
$(this).animate({height: "200px"}, 2000).addClass("clicked");
return false;
});
</code></pre>
<p>But this doesn't appear to work (I think it does logically)?</p>
<p>Any help appreciated.</p>
<p>Cheers,<br />
Steve</p>
|
[
{
"answer_id": 260789,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 5,
"selected": true,
"text": "$(\"div\").click(function() {\n if (!$(this).parent().children().is(':animated')) {\n $(this).animate({height: \"200px\"}, 2000); \n }\n return false;\n});\n"
},
{
"answer_id": 260793,
"author": "hugoware",
"author_id": 17091,
"author_profile": "https://Stackoverflow.com/users/17091",
"pm_score": 0,
"selected": false,
"text": "$(function() { \n $(\"div\").click(function() { \n\n //check to see if any of the divs are animating\n if ($(\"div\").is(\":animated\")) { \n alert(\"busy\"); \n return; \n }\n\n //whatever your animation is \n var div = $(this);\n div.slideUp(3000, function(){ div.slideDown(1000); });\n\n });\n\n});\n"
},
{
"answer_id": 263756,
"author": "Steve Perks",
"author_id": 16124,
"author_profile": "https://Stackoverflow.com/users/16124",
"pm_score": 0,
"selected": false,
"text": "<div></div>\n<div class=\"active\"></div>\n<div></div>\n\n$(\"div\").not('active').click(function() {\n if (!$(this).parent().children().is(':animated')) {\n $(this).animate({height: \"200px\"}, 2000); \n }\n return false;\n});\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16124/"
] |
260,749
|
<p>I want to increment a cookie value every time a page is referenced even if the page is loaded from cache. What is the "best" or most concise way to implement this?</p>
|
[
{
"answer_id": 260866,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 3,
"selected": false,
"text": "var cookieName = \"increment\";\n\nif ($.cookie(cookieName) == null){\n $.cookie(cookieName, 1, { expires: 10 });\n}else{\n var newValue = Number($.cookie(cookieName)) + 1;\n $.cookie(cookieName, newValue, { expires: 10 });\n}\n"
},
{
"answer_id": 260880,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 6,
"selected": true,
"text": "function createCookie(name,value,days) {\n if (days) {\n var date = new Date();\n date.setTime(date.getTime()+(days*24*60*60*1000));\n var expires = \"; expires=\"+date.toUTCString();\n }\n else var expires = \"\";\n document.cookie = name+\"=\"+value+expires+\"; path=/\";\n}\n\nfunction readCookie(name) {\n var nameEQ = name + \"=\";\n var ca = document.cookie.split(';');\n for(var i=0;i < ca.length;i++) {\n var c = ca[i];\n while (c.charAt(0)==' ') c = c.substring(1,c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);\n }\n return null;\n}\n\nfunction eraseCookie(name) {\n createCookie(name,\"\",-1);\n}\n var oldCount = parseInt(readCookie('hitCount'), 10) || 0;\ncreateCookie('hitCount', oldCount + 1, 7);\n foo++ ++foo var x = \"5\"; // x = \"5\" (string)\nx += 1; // x = \"51\" (string!)\nx += 5; // x = \"515\" (string!)\n++x; // x = 516 (number)\n"
},
{
"answer_id": 16061433,
"author": "Eugene Kuzmenko",
"author_id": 584211,
"author_profile": "https://Stackoverflow.com/users/584211",
"pm_score": 2,
"selected": false,
"text": "function getCookie(name) {\n return (name = (document.cookie + ';').match(new RegExp(name + '=.*;'))) && name[0].split(/=|;/)[1];\n}\n\n// the default lifetime is 365 days\nfunction setCookie(name, value, days) {\n var e = new Date;\n e.setDate(e.getDate() + (days || 365));\n document.cookie = name + \"=\" + value + ';expires=' + e.toUTCString() + ';path=/;domain=.' + document.domain;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30099/"
] |
260,787
|
<p>I know that this question has already been asked <a href="https://stackoverflow.com/questions/41207/javascript-interactive-shell-with-completion">HERE</a> but sadly none of the answers suggest a javascript standalone shell that has auto completion. I am reopening this question again, in the hope that some new answers might be found.</p>
|
[
{
"answer_id": 4074233,
"author": "intuited",
"author_id": 192812,
"author_profile": "https://Stackoverflow.com/users/192812",
"pm_score": 3,
"selected": true,
"text": "node-repl"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28486/"
] |
260,804
|
<p>I'm looking for a dbm-like library that I can use in place of Berkeley DB, which I'm currently using. My main reason for switching is the licensing fees for BDB are pretty high (free for open source apps, but my employer does not want to open source this particular app for various reasons).</p>
<p>I've looked briefly at qdbm but it doesn't look like it will fill my needs -- lots of keys (several million) and large data items (> 1-5 megabytes). Before I continue my search I figured I'd ask because it seems there are tons of dbm-like libraries out there.</p>
|
[
{
"answer_id": 290551,
"author": "geocar",
"author_id": 37507,
"author_profile": "https://Stackoverflow.com/users/37507",
"pm_score": 3,
"selected": false,
"text": "data_dir/H(key)/"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
260,817
|
<p>I wanted to try a little design by contract in my latest C# application and wanted to have syntax akin to:</p>
<pre><code>public string Foo()
{
set {
Assert.IsNotNull(value);
Assert.IsTrue(value.Contains("bar"));
_foo = value;
}
}
</code></pre>
<p>I know I can get static methods like this from a unit test framework, but I wanted to know if something like this was already built-in to the language or if there was already some kind of framework floating around. I can write my own Assert functions, just don't want to reinvent the wheel.</p>
|
[
{
"answer_id": 260833,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 4,
"selected": false,
"text": "using System.Diagnostics\n\nDebug.Assert(value != null);\nDebug.Assert(value == true);\n"
},
{
"answer_id": 260837,
"author": "Jim Burger",
"author_id": 20164,
"author_profile": "https://Stackoverflow.com/users/20164",
"pm_score": 5,
"selected": false,
"text": " public static int BinarySearch(int[]! a, int key)\n requires forall{int i in (0: a.Length), int j in (i: a.Length); a[i] <= a[j]};\n ensures 0 <= result ==> a[result] == key;\n ensures result < 0 ==> forall{int i in (0: a.Length); a[i] != key};\n {\n int low = 0;\n int high = a.Length - 1;\n\n while (low <= high)\n invariant high+1 <= a.Length;\n invariant forall{int i in (0: low); a[i] != key};\n invariant forall{int i in (high+1: a.Length); a[i] != key};\n {\n int mid = (low + high) / 2;\n int midVal = a[mid];\n\n if (midVal < key) {\n low = mid + 1;\n } else if (key < midVal) {\n high = mid - 1;\n } else {\n return mid; // key found\n }\n }\n return -(low + 1); // key not found.\n }\n"
},
{
"answer_id": 260939,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing nVentive.Umbrella.Validation;\nusing nVentive.Umbrella.Extensions;\n\nnamespace Namespace\n{\n public static class StringValidationExtensionPoint\n {\n public static string Contains(this ValidationExtensionPoint<string> vep, string value)\n {\n if (vep.ExtendedValue.IndexOf(value, StringComparison.InvariantCultureIgnoreCase) == -1)\n throw new ArgumentException(String.Format(\"Must contain '{0}'.\", value));\n\n return vep.ExtendedValue;\n }\n }\n\n class Class\n {\n private string _foo;\n public string Foo\n {\n set\n {\n _foo = value.Validation()\n .NotNull(\"Foo\")\n .Validation()\n .Contains(\"bar\");\n }\n }\n }\n}\n _foo = value.Validation().NotNull(\"Foo\").Contains(\"bar\").Value;"
},
{
"answer_id": 260943,
"author": "Hamish Smith",
"author_id": 15572,
"author_profile": "https://Stackoverflow.com/users/15572",
"pm_score": 2,
"selected": false,
"text": "public void Foo(Bar param)\n{\n Guard.ArgumentNotNull(param);\n} \n"
},
{
"answer_id": 3155694,
"author": "ligaoren",
"author_id": 248524,
"author_profile": "https://Stackoverflow.com/users/248524",
"pm_score": 3,
"selected": false,
"text": "Contract.Requires(newNumber > 0, “Failed contract: negative”);\nContract.Ensures(list.Count == Contract.OldValue(list.Count) + 1);\n"
},
{
"answer_id": 5192802,
"author": "Richard C",
"author_id": 494701,
"author_profile": "https://Stackoverflow.com/users/494701",
"pm_score": 1,
"selected": false,
"text": "public string Foo()\n{\n set {\n if (value == null)\n throw new ArgumentNullException(\"value\");\n if (!value.Contains(\"bar\"))\n throw new ArgumentException(@\"value should contain \"\"bar\"\"\", \"value\");\n\n _foo = value;\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27613/"
] |
260,847
|
<p>I have written a few MSBuild custom tasks that work well and are use in our CruiseControl.NET build process.</p>
<p>I am modifying one, and wish to unit test it by calling the Task's Execute() method. </p>
<p>However, if it encounters a line containing </p>
<pre><code>Log.LogMessage("some message here");
</code></pre>
<p>it throws an InvalidOperationException:</p>
<p><em>Task attempted to log before it was initialized. Message was...</em></p>
<p>Any suggestions? (In the past I have mostly unit-tested Internal static methods on my custom tasks to avoid such problems.)</p>
|
[
{
"answer_id": 287704,
"author": "Tim Bailey",
"author_id": 1077232,
"author_profile": "https://Stackoverflow.com/users/1077232",
"pm_score": 4,
"selected": false,
"text": "private void LogFormat(string message, params object[] args)\n{\n if (this.BuildEngine != null)\n {\n this.Log.LogMessage(message, args);\n }\n else\n {\n Console.WriteLine(message, args);\n }\n}\n"
},
{
"answer_id": 305402,
"author": "Branstar",
"author_id": 39324,
"author_profile": "https://Stackoverflow.com/users/39324",
"pm_score": 6,
"selected": true,
"text": "Task myCustomTask = new CustomTask();\nmyCustomTask.BuildEngine = this.BuildEngine;\nmyCustomTask.Execute();\n"
},
{
"answer_id": 5611069,
"author": "Tim Murphy",
"author_id": 22941,
"author_profile": "https://Stackoverflow.com/users/22941",
"pm_score": 3,
"selected": false,
"text": "Imports System\nImports System.Collections.Generic\nImports Microsoft.Build.Framework\n\nPublic Class FakeBuildEngine\n Implements IBuildEngine\n\n // It's just a test helper so public fields is fine.\n Public LogErrorEvents As New List(Of BuildErrorEventArgs)\n Public LogMessageEvents As New List(Of BuildMessageEventArgs)\n Public LogCustomEvents As New List(Of CustomBuildEventArgs)\n Public LogWarningEvents As New List(Of BuildWarningEventArgs)\n\n Public Function BuildProjectFile(\n projectFileName As String, \n targetNames() As String, \n globalProperties As System.Collections.IDictionary, \n targetOutputs As System.Collections.IDictionary) As Boolean\n Implements IBuildEngine.BuildProjectFile\n\n Throw New NotImplementedException\n\n End Function\n\n Public ReadOnly Property ColumnNumberOfTaskNode As Integer \n Implements IBuildEngine.ColumnNumberOfTaskNode\n Get\n Return 0\n End Get\n End Property\n\n Public ReadOnly Property ContinueOnError As Boolean\n Implements IBuildEngine.ContinueOnError\n Get\n Throw New NotImplementedException\n End Get\n End Property\n\n Public ReadOnly Property LineNumberOfTaskNode As Integer\n Implements IBuildEngine.LineNumberOfTaskNode\n Get\n Return 0\n End Get\n End Property\n\n Public Sub LogCustomEvent(e As CustomBuildEventArgs)\n Implements IBuildEngine.LogCustomEvent\n LogCustomEvents.Add(e)\n End Sub\n\n Public Sub LogErrorEvent(e As BuildErrorEventArgs)\n Implements IBuildEngine.LogErrorEvent\n LogErrorEvents.Add(e)\n End Sub\n\n Public Sub LogMessageEvent(e As BuildMessageEventArgs)\n Implements IBuildEngine.LogMessageEvent\n LogMessageEvents.Add(e)\n End Sub\n\n Public Sub LogWarningEvent(e As BuildWarningEventArgs)\n Implements IBuildEngine.LogWarningEvent\n LogWarningEvents.Add(e)\n End Sub\n\n Public ReadOnly Property ProjectFileOfTaskNode As String\n Implements IBuildEngine.ProjectFileOfTaskNode\n Get\n Return \"fake ProjectFileOfTaskNode\"\n End Get\n End Property\n\nEnd Class\n using System;\nusing System.Collections.Generic;\nusing Microsoft.Build.Framework;\n\npublic class FakeBuildEngine : IBuildEngine\n{\n\n // It's just a test helper so public fields is fine.\n public List<BuildErrorEventArgs> LogErrorEvents = new List<BuildErrorEventArgs>();\n\n public List<BuildMessageEventArgs> LogMessageEvents = \n new List<BuildMessageEventArgs>();\n\n public List<CustomBuildEventArgs> LogCustomEvents = \n new List<CustomBuildEventArgs>();\n\n public List<BuildWarningEventArgs> LogWarningEvents =\n new List<BuildWarningEventArgs>();\n\n public bool BuildProjectFile(\n string projectFileName, string[] targetNames, \n System.Collections.IDictionary globalProperties, \n System.Collections.IDictionary targetOutputs)\n {\n throw new NotImplementedException();\n }\n\n public int ColumnNumberOfTaskNode\n {\n get { return 0; }\n }\n\n public bool ContinueOnError\n {\n get\n {\n throw new NotImplementedException();\n }\n }\n\n public int LineNumberOfTaskNode\n {\n get { return 0; }\n }\n\n public void LogCustomEvent(CustomBuildEventArgs e)\n {\n LogCustomEvents.Add(e);\n }\n\n public void LogErrorEvent(BuildErrorEventArgs e)\n {\n LogErrorEvents.Add(e);\n }\n\n public void LogMessageEvent(BuildMessageEventArgs e)\n {\n LogMessageEvents.Add(e);\n }\n\n public void LogWarningEvent(BuildWarningEventArgs e)\n {\n LogWarningEvents.Add(e);\n }\n\n public string ProjectFileOfTaskNode\n {\n get { return \"fake ProjectFileOfTaskNode\"; }\n }\n\n}\n"
},
{
"answer_id": 9559323,
"author": "Raymond Hallquist",
"author_id": 1248707,
"author_profile": "https://Stackoverflow.com/users/1248707",
"pm_score": 2,
"selected": false,
"text": "using Microsoft.Build.Framework;\nusing NUnit.Framework;\nusing Rhino.Mocks;\n\nnamespace NameSpace\n{\n [TestFixture]\n public class Tests\n {\n [Test]\n public void Test()\n {\n MockRepository mock = new MockRepository();\n IBuildEngine engine = mock.Stub<IBuildEngine>();\n\n var appSettings = new AppSettings();\n appSettings.BuildEngine = engine;\n appSettings.Execute();\n }\n }\n}\n"
},
{
"answer_id": 39265647,
"author": "Jan Hlavsa",
"author_id": 5922573,
"author_profile": "https://Stackoverflow.com/users/5922573",
"pm_score": 0,
"selected": false,
"text": "System.Web namespace System.Web.Compilation MockEngine IBuildEngine interface"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30183/"
] |
260,857
|
<p>I have a web application that's branded according to the user that's currently logged in. I'd like to change the favicon of the page to be the logo of the private label, but I'm unable to find any code or any examples of how to do this. Has anybody successfully done this before?</p>
<p>I'm picturing having a dozen icons in a folder, and the reference to which favicon.ico file to use is just generated dynamically along with the HTML page. Thoughts?</p>
|
[
{
"answer_id": 260873,
"author": "Jeff Sheldon",
"author_id": 33910,
"author_profile": "https://Stackoverflow.com/users/33910",
"pm_score": 4,
"selected": false,
"text": "<link rel=\"shortcut icon\" type=\"image/ico\" href=\"favicon.ico\">\n"
},
{
"answer_id": 260876,
"author": "keparo",
"author_id": 19468,
"author_profile": "https://Stackoverflow.com/users/19468",
"pm_score": 10,
"selected": true,
"text": "var link = document.querySelector(\"link[rel~='icon']\");\nif (!link) {\n link = document.createElement('link');\n link.rel = 'icon';\n document.getElementsByTagName('head')[0].appendChild(link);\n}\nlink.href = 'https://stackoverflow.com/favicon.ico';\n"
},
{
"answer_id": 260877,
"author": "fserb",
"author_id": 3702,
"author_profile": "https://Stackoverflow.com/users/3702",
"pm_score": 6,
"selected": false,
"text": "<link id=\"favicon\" rel=\"shortcut icon\" type=\"image/png\" href=\"favicon.png\" />\n $(\"#favicon\").attr(\"href\",\"favicon2.png\");\n"
},
{
"answer_id": 260878,
"author": "staticsan",
"author_id": 28832,
"author_profile": "https://Stackoverflow.com/users/28832",
"pm_score": 2,
"selected": false,
"text": "link head rel=\"icon\" <link rel=\"icon\" type=\"image/png\" href=\"/path/image.png\">\n"
},
{
"answer_id": 2919795,
"author": "cryo",
"author_id": 304185,
"author_profile": "https://Stackoverflow.com/users/304185",
"pm_score": 3,
"selected": false,
"text": "iframe var IE = navigator.userAgent.indexOf(\"MSIE\")!=-1\nvar favicon = {\n change: function(iconURL) {\n if (arguments.length == 2) {\n document.title = optionalDocTitle}\n this.addLink(iconURL, \"icon\")\n this.addLink(iconURL, \"shortcut icon\")\n\n // Google Chrome HACK - whenever an IFrame changes location \n // (even to about:blank), it updates the favicon for some reason\n // It doesn't work on Safari at all though :-(\n if (!IE) { // Disable the IE \"click\" sound\n if (!window.__IFrame) {\n __IFrame = document.createElement('iframe')\n var s = __IFrame.style\n s.height = s.width = s.left = s.top = s.border = 0\n s.position = 'absolute'\n s.visibility = 'hidden'\n document.body.appendChild(__IFrame)}\n __IFrame.src = 'about:blank'}},\n\n addLink: function(iconURL, relValue) {\n var link = document.createElement(\"link\")\n link.type = \"image/x-icon\"\n link.rel = relValue\n link.href = iconURL\n this.removeLinkIfExists(relValue)\n this.docHead.appendChild(link)},\n\n removeLinkIfExists: function(relValue) {\n var links = this.docHead.getElementsByTagName(\"link\");\n for (var i=0; i<links.length; i++) {\n var link = links[i]\n if (link.type == \"image/x-icon\" && link.rel == relValue) {\n this.docHead.removeChild(link)\n return}}}, // Assuming only one match at most.\n\n docHead: document.getElementsByTagName(\"head\")[0]}\n favicon.change(\"ICON URL\")"
},
{
"answer_id": 2995536,
"author": "Mathias Bynens",
"author_id": 96656,
"author_profile": "https://Stackoverflow.com/users/96656",
"pm_score": 7,
"selected": false,
"text": "/*!\n * Dynamically changing favicons with JavaScript\n * Works in all A-grade browsers except Safari and Internet Explorer\n * Demo: http://mathiasbynens.be/demo/dynamic-favicons\n */\n\n// HTML5™, baby! http://mathiasbynens.be/notes/document-head\ndocument.head = document.head || document.getElementsByTagName('head')[0];\n\nfunction changeFavicon(src) {\n var link = document.createElement('link'),\n oldLink = document.getElementById('dynamic-favicon');\n link.id = 'dynamic-favicon';\n link.rel = 'shortcut icon';\n link.href = src;\n if (oldLink) {\n document.head.removeChild(oldLink);\n }\n document.head.appendChild(link);\n}\n var btn = document.getElementsByTagName('button')[0];\nbtn.onclick = function() {\n changeFavicon('http://www.google.com/favicon.ico');\n};\n"
},
{
"answer_id": 6475913,
"author": "Dan",
"author_id": 815015,
"author_profile": "https://Stackoverflow.com/users/815015",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.IO;\nusing System.Web;\n\nnamespace FaviconOverrider\n{\n public class IcoHandler : IHttpHandler\n {\n public void ProcessRequest(HttpContext context)\n {\n context.Response.ContentType = \"image/x-icon\";\n byte[] imageData = imageToByteArray(context.Server.MapPath(\"/ear.ico\"));\n context.Response.BinaryWrite(imageData);\n }\n\n public bool IsReusable\n {\n get { return true; }\n }\n\n public byte[] imageToByteArray(string imagePath)\n {\n byte[] imageByteArray;\n using (FileStream fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read))\n {\n imageByteArray = new byte[fs.Length];\n fs.Read(imageByteArray, 0, imageByteArray.Length);\n }\n\n return imageByteArray;\n }\n }\n}\n"
},
{
"answer_id": 24223694,
"author": "vorillaz",
"author_id": 910701,
"author_profile": "https://Stackoverflow.com/users/910701",
"pm_score": 6,
"selected": false,
"text": "$(\"link[rel='shortcut icon']\").attr(\"href\", \"favicon.ico\");\n $(\"link[rel*='icon']\").attr(\"href\", \"favicon.ico\");\n document.querySelector(\"link[rel='shortcut icon']\").href = \"favicon.ico\";\n\ndocument.querySelector(\"link[rel*='icon']\").href = \"favicon.ico\";\n"
},
{
"answer_id": 35960429,
"author": "Michał Perłakowski",
"author_id": 3853934,
"author_profile": "https://Stackoverflow.com/users/3853934",
"pm_score": 5,
"selected": false,
"text": "const changeFavicon = link => {\n let $favicon = document.querySelector('link[rel=\"icon\"]')\n // If a <link rel=\"icon\"> element already exists,\n // change its href to the given link.\n if ($favicon !== null) {\n $favicon.href = link\n // Otherwise, create a new element and append it to <head>.\n } else {\n $favicon = document.createElement(\"link\")\n $favicon.rel = \"icon\"\n $favicon.href = link\n document.head.appendChild($favicon)\n }\n}\n changeFavicon(\"http://www.stackoverflow.com/favicon.ico\")\n"
},
{
"answer_id": 45302044,
"author": "MemeDeveloper",
"author_id": 661584,
"author_profile": "https://Stackoverflow.com/users/661584",
"pm_score": 2,
"selected": false,
"text": "<link rel=\"shortcut icon\" href=\"/favicon.ico?userId=someUserId\">\n"
},
{
"answer_id": 47785522,
"author": "Oscar Nevarez",
"author_id": 1028871,
"author_profile": "https://Stackoverflow.com/users/1028871",
"pm_score": 2,
"selected": false,
"text": "canvas base64"
},
{
"answer_id": 52138377,
"author": "Pepelegal",
"author_id": 9542596,
"author_profile": "https://Stackoverflow.com/users/9542596",
"pm_score": 2,
"selected": false,
"text": "$(\"link[rel*='icon']\").prop(\"href\",'https://www.stackoverflow.com/favicon.ico');\n"
},
{
"answer_id": 53703704,
"author": "max4ever",
"author_id": 579646,
"author_profile": "https://Stackoverflow.com/users/579646",
"pm_score": 3,
"selected": false,
"text": "var canvas = document.createElement(\"canvas\");\ncanvas.height = 64;\ncanvas.width = 64;\n\nvar ctx = canvas.getContext(\"2d\");\nctx.font = \"64px serif\";\nctx.fillText(\"☠️\", 0, 64); \n\n$(\"link[rel*='icon']\").prop(\"href\", canvas.toDataURL());\n"
},
{
"answer_id": 61786888,
"author": "Ruskin",
"author_id": 581414,
"author_profile": "https://Stackoverflow.com/users/581414",
"pm_score": 2,
"selected": false,
"text": "(function() {\n 'use strict';\n\n // play with https://codepen.io/elliz/full/ygvgay for getting it right\n // viewBox is required but does not need to be 16x16\n const svg = `\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n <circle cx=\"8\" cy=\"8\" r=\"7.2\" fill=\"gold\" stroke=\"#000\" stroke-width=\"1\" />\n <circle cx=\"8\" cy=\"8\" r=\"3.1\" fill=\"#fff\" stroke=\"#000\" stroke-width=\"1\" />\n </svg>\n `;\n\n var favicon_link_html = document.createElement('link');\n favicon_link_html.rel = 'icon';\n favicon_link_html.href = svgToDataUri(svg);\n favicon_link_html.type = 'image/svg+xml';\n\n try {\n let favicons = document.querySelectorAll('link[rel~=\"icon\"]');\n favicons.forEach(function(favicon) {\n favicon.parentNode.removeChild(favicon);\n });\n\n const head = document.getElementsByTagName('head')[0];\n head.insertBefore( favicon_link_html, head.firstChild );\n }\n catch(e) { }\n\n // functions -------------------------------\n function escapeRegExp(str) {\n return str.replace(/([.*+?^=!:${}()|\\[\\]\\/\\\\])/g, \"\\\\$1\");\n }\n\n function replaceAll(str, find, replace) {\n return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);\n }\n\n function svgToDataUri(svg) {\n // these may not all be needed - used to be for uri-encoded svg in old browsers\n var encoded = svg.replace(/\\s+/g, \" \")\n encoded = replaceAll(encoded, \"%\", \"%25\");\n encoded = replaceAll(encoded, \"> <\", \"><\"); // normalise spaces elements\n encoded = replaceAll(encoded, \"; }\", \";}\"); // normalise spaces css\n encoded = replaceAll(encoded, \"<\", \"%3c\");\n encoded = replaceAll(encoded, \">\", \"%3e\");\n encoded = replaceAll(encoded, \"\\\"\", \"'\"); // normalise quotes ... possible issues with quotes in <text>\n encoded = replaceAll(encoded, \"#\", \"%23\"); // needed for ie and firefox\n encoded = replaceAll(encoded, \"{\", \"%7b\");\n encoded = replaceAll(encoded, \"}\", \"%7d\");\n encoded = replaceAll(encoded, \"|\", \"%7c\");\n encoded = replaceAll(encoded, \"^\", \"%5e\");\n encoded = replaceAll(encoded, \"`\", \"%60\");\n encoded = replaceAll(encoded, \"@\", \"%40\");\n var dataUri = 'data:image/svg+xml;charset=UTF-8,' + encoded.trim();\n return dataUri;\n }\n\n})();\n"
},
{
"answer_id": 66503749,
"author": "ubershmekel",
"author_id": 177498,
"author_profile": "https://Stackoverflow.com/users/177498",
"pm_score": 4,
"selected": false,
"text": "function changeFavicon(text) {\n const canvas = document.createElement('canvas');\n canvas.height = 64;\n canvas.width = 64;\n const ctx = canvas.getContext('2d');\n ctx.font = '64px serif';\n ctx.fillText(text, 0, 64);\n\n const link = document.createElement('link');\n const oldLinks = document.querySelectorAll('link[rel=\"shortcut icon\"]');\n oldLinks.forEach(e => e.parentNode.removeChild(e));\n link.id = 'dynamic-favicon';\n link.rel = 'shortcut icon';\n link.href = canvas.toDataURL();\n document.head.appendChild(link);\n}\n\nchangeFavicon('❤️');\n"
},
{
"answer_id": 68466511,
"author": "yooneskh",
"author_id": 5202815,
"author_profile": "https://Stackoverflow.com/users/5202815",
"pm_score": 2,
"selected": false,
"text": "<link rel=\"icon\" href\"....\" />\n const linkElement = document.querySelector('link[rel=icon]');\n linkElement.href = 'url/to/any/picture/remote/or/relative';\n"
},
{
"answer_id": 70040223,
"author": "Gonzalo Odiard",
"author_id": 3969110,
"author_profile": "https://Stackoverflow.com/users/3969110",
"pm_score": 0,
"selected": false,
"text": "let oldFavicon = document.getElementById('favicon')\nvar link = document.createElement('link')\nlink.id = 'favicon';\nlink.type = 'image/x-icon'\nlink.rel = 'icon';\nlink.href = new_favicon_url +'?=' + Math.random();\nif (oldFavicon) {\n document.head.removeChild(oldFavicon);\n}\ndocument.head.appendChild(link);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8114/"
] |
260,869
|
<p>I want to convert a BYTE* into an gdi+ Image object.<p>
How can I do this?<p>
The BYTE* seems a Dib point.<p>
I found Image has a method named Image::FromStream() which may help,
But I can not find any reference about how to convert a BYTE* into a IStream object.
How can I do this?
<p>
Thanks in advance!</p>
<p><strong>Actually, it is hard to believe MS provide a IStream interface, but do not provide any c++ MemoryStream class which implements the interface.</strong></p>
|
[
{
"answer_id": 261189,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 0,
"selected": false,
"text": "BYTE"
},
{
"answer_id": 70470651,
"author": "SnzFor16Min",
"author_id": 10766083,
"author_profile": "https://Stackoverflow.com/users/10766083",
"pm_score": 0,
"selected": false,
"text": "SHCreateMemStream IStream* stream = ::SHCreateMemStream({your BYTE array}, {size of the array});\nGdiplus::Image *img = Gdiplus::Image::FromStream(stream);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
260,915
|
<p>I know how to create an array of structs but with a predefined size. However is there a way to create a dynamic array of structs such that the array could get bigger?</p>
<p>For example:</p>
<pre><code> typedef struct
{
char *str;
} words;
main()
{
words x[100]; // I do not want to use this, I want to dynamic increase the size of the array as data comes in.
}
</code></pre>
<p>Is this possible?</p>
<hr>
<p>I've researched this: <code>words* array = (words*)malloc(sizeof(words) * 100);</code></p>
<p>I want to get rid of the 100 and store the data as it comes in. Thus if 76 fields of data comes in, I want to store 76 and not 100. I'm assuming that I don't know how much data is coming into my program. In the struct I defined above I could create the first "index" as:</p>
<pre><code> words* array = (words*)malloc(sizeof(words));
</code></pre>
<p>However I want to dynamically add elements to the array after. I hope I described the problem area clearly enough. The major challenge is to dynamically add a second field, at least that is the challenge for the moment.</p>
<hr>
<p>I've made a little progress however:</p>
<pre><code> typedef struct {
char *str;
} words;
// Allocate first string.
words x = (words) malloc(sizeof(words));
x[0].str = "john";
// Allocate second string.
x=(words*) realloc(x, sizeof(words));
x[1].FirstName = "bob";
// printf second string.
printf("%s", x[1].str); --> This is working, it's printing out bob.
free(x); // Free up memory.
printf("%s", x[1].str); --> Not working since its still printing out BOB even though I freed up memory. What is wrong?
</code></pre>
<p>I did some error checking and this is what I found. If after I free up memory for x I add the following:</p>
<pre><code> x=NULL;
</code></pre>
<p>then if I try to print x I get an error which is what I want. So is it that the free function is not working, at least on my compiler? I'm using DevC??</p>
<hr>
<p>Thanks, I understand now due to:</p>
<blockquote>
<p>FirstName is a pointer to an array of char which is not being allocated by the malloc, only the pointer is being allocated and after you call free, it doesn't erase the memory, it just marks it as available on the heap to be over written later. – MattSmith</p>
</blockquote>
<h2>Update</h2>
<p>I'm trying to modularize and put the creation of my array of structs in a function but nothing seems to work. I'm trying something very simple and I don't know what else to do. It's along the same lines as before, just another function, loaddata that is loading the data and outside the method I need to do some printing. How can I make it work? My code is as follows:</p>
<pre><code> # include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
typedef struct
{
char *str1;
char *str2;
} words;
void LoadData(words *, int *);
main()
{
words *x;
int num;
LoadData(&x, &num);
printf("%s %s", x[0].str1, x[0].str2);
printf("%s %s", x[1].str1, x[1].str2);
getch();
}//
void LoadData(words *x, int * num)
{
x = (words*) malloc(sizeof(words));
x[0].str1 = "johnnie\0";
x[0].str2 = "krapson\0";
x = (words*) realloc(x, sizeof(words)*2);
x[1].str1 = "bob\0";
x[1].str2 = "marley\0";
*num=*num+1;
}//
</code></pre>
<p>This simple test code is crashing and I have no idea why. Where is the bug?</p>
|
[
{
"answer_id": 260932,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 4,
"selected": false,
"text": "malloc stdlib.h words words* array = (words*)malloc(sizeof(words) * 100);\n malloc void void* words* sizeof words free() free(array);\n realloc realloc realloc"
},
{
"answer_id": 260950,
"author": "ob1",
"author_id": 3961,
"author_profile": "https://Stackoverflow.com/users/3961",
"pm_score": 0,
"selected": false,
"text": "size = 64; i = 0;\nx = malloc(sizeof(words)*size); /* enough space for 64 words */\nwhile (read_words()) {\n if (++i > size) {\n size *= 2;\n x = realloc(sizeof(words) * size);\n }\n}\n/* done with x */\nfree(x);\n"
},
{
"answer_id": 260981,
"author": "Tom",
"author_id": 8969,
"author_profile": "https://Stackoverflow.com/users/8969",
"pm_score": 5,
"selected": false,
"text": "#include <stdio.h>\n#include <vector>\n\ntypedef std::vector<char*> words;\n\nint main(int argc, char** argv) {\n\n words myWords;\n\n myWords.push_back(\"Hello\");\n myWords.push_back(\"World\");\n\n words::iterator iter;\n for (iter = myWords.begin(); iter != myWords.end(); ++iter) {\n printf(\"%s \", *iter);\n }\n\n return 0;\n}\n #include <stdio.h>\n#include <stdlib.h>\n\ntypedef struct s_words {\n char* str;\n struct s_words* next;\n} words;\n\nwords* create_words(char* word) {\n words* newWords = malloc(sizeof(words));\n if (NULL != newWords){\n newWords->str = word;\n newWords->next = NULL;\n }\n return newWords;\n}\n\nvoid delete_words(words* oldWords) {\n if (NULL != oldWords->next) {\n delete_words(oldWords->next);\n }\n free(oldWords);\n}\n\nwords* add_word(words* wordList, char* word) {\n words* newWords = create_words(word);\n if (NULL != newWords) {\n newWords->next = wordList;\n }\n return newWords;\n}\n\nint main(int argc, char** argv) {\n\n words* myWords = create_words(\"Hello\");\n myWords = add_word(myWords, \"World\");\n\n words* iter;\n for (iter = myWords; NULL != iter; iter = iter->next) {\n printf(\"%s \", iter->str);\n }\n delete_words(myWords);\n return 0;\n}\n #include <stdio.h> \n#include <stdlib.h>\n\ntypedef struct {\n char** words;\n size_t nWords;\n size_t size;\n size_t block_size;\n} word_list;\n\nword_list* create_word_list(size_t block_size) {\n word_list* pWordList = malloc(sizeof(word_list));\n if (NULL != pWordList) {\n pWordList->nWords = 0;\n pWordList->size = block_size;\n pWordList->block_size = block_size;\n pWordList->words = malloc(sizeof(char*)*block_size);\n if (NULL == pWordList->words) {\n free(pWordList);\n return NULL; \n }\n }\n return pWordList;\n}\n\nvoid delete_word_list(word_list* pWordList) {\n free(pWordList->words);\n free(pWordList);\n}\n\nint add_word_to_word_list(word_list* pWordList, char* word) {\n size_t nWords = pWordList->nWords;\n if (nWords >= pWordList->size) {\n size_t newSize = pWordList->size + pWordList->block_size;\n void* newWords = realloc(pWordList->words, sizeof(char*)*newSize); \n if (NULL == newWords) {\n return 0;\n } else { \n pWordList->size = newSize;\n pWordList->words = (char**)newWords;\n }\n\n }\n\n pWordList->words[nWords] = word;\n ++pWordList->nWords;\n\n\n return 1;\n}\n\nchar** word_list_start(word_list* pWordList) {\n return pWordList->words;\n}\n\nchar** word_list_end(word_list* pWordList) {\n return &pWordList->words[pWordList->nWords];\n}\n\nint main(int argc, char** argv) {\n\n word_list* myWords = create_word_list(2);\n add_word_to_word_list(myWords, \"Hello\");\n add_word_to_word_list(myWords, \"World\");\n add_word_to_word_list(myWords, \"Goodbye\");\n\n char** iter;\n for (iter = word_list_start(myWords); iter != word_list_end(myWords); ++iter) {\n printf(\"%s \", *iter);\n }\n\n delete_word_list(myWords);\n\n return 0;\n}\n"
},
{
"answer_id": 261019,
"author": "Ryan",
"author_id": 29762,
"author_profile": "https://Stackoverflow.com/users/29762",
"pm_score": 3,
"selected": false,
"text": "// initial size\nint count = 100;\nwords *testWords = (words*) malloc(count * sizeof(words));\n// resize the array\ncount = 76;\ntestWords = (words*) realloc(testWords, count* sizeof(words));\n // Allocate a words struct\nwords* CreateWords(int size);\n// Assign a value\nvoid AssignWord(word* dest, char* str);\n// Clear a words structs (and possibly internal storage)\nvoid FreeWords(words* w);\n // Resize words (must know original and new size if shrinking\n// if you need to free internal storage first)\nvoid ResizeWords(words* w, size_t oldsize, size_t newsize);\n"
},
{
"answer_id": 266248,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "*x = (words*) realloc(*x, sizeof(words)*2);\n"
},
{
"answer_id": 6686206,
"author": "Adrian",
"author_id": 843590,
"author_profile": "https://Stackoverflow.com/users/843590",
"pm_score": 0,
"selected": false,
"text": "size_t size = 500;\nchar* dynamicAllocatedString = new char[ size ];\n"
},
{
"answer_id": 8011025,
"author": "zhanwu",
"author_id": 244031,
"author_profile": "https://Stackoverflow.com/users/244031",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <ctype.h>\n\ntypedef struct\n{\n char *str1;\n char *str2;\n} words;\n\nvoid LoadData(words**, int*);\n\nmain()\n{\n words **x;\n int num;\n\n LoadData(x, &num);\n\n printf(\"%s %s\\n\", (*x[0]).str1, (*x[0]).str2);\n printf(\"%s %s\\n\", (*x[1]).str1, (*x[1]).str2);\n}\n\nvoid LoadData(words **x, int *num)\n{\n *x = (words*) malloc(sizeof(words));\n\n (*x[0]).str1 = \"johnnie\\0\";\n (*x[0]).str2 = \"krapson\\0\";\n\n *x = (words*) realloc(*x, sizeof(words) * 2);\n (*x[1]).str1 = \"bob\\0\";\n (*x[1]).str2 = \"marley\\0\";\n\n *num = *num + 1;\n}\n"
},
{
"answer_id": 50156730,
"author": "Arul Girish",
"author_id": 9735737,
"author_profile": "https://Stackoverflow.com/users/9735737",
"pm_score": 1,
"selected": false,
"text": "// Dynamically sized array of structures\n\n#include <stdio.h>\n#include <stdlib.h>\n\nstruct book \n{\n char name[20];\n int p;\n}; //Declaring book structure\n\nint main () \n{\n int n, i; \n\n struct book *b; // Initializing pointer to a structure\n scanf (\"%d\\n\", &n);\n\n b = (struct book *) calloc (n, sizeof (struct book)); //Creating memory for array of structures dynamically\n\n for (i = 0; i < n; i++)\n {\n scanf (\"%s %d\\n\", (b + i)->name, &(b + i)->p); //Getting values for array of structures (no error check)\n } \n\n for (i = 0; i < n; i++)\n {\n printf (\"%s %d\\t\", (b + i)->name, (b + i)->p); //Printing values in array of structures\n }\n\n scanf (\"%d\\n\", &n); //Get array size to re-allocate \n b = (struct book *) realloc (b, n * sizeof (struct book)); //change the size of an array using realloc function\n printf (\"\\n\");\n\n for (i = 0; i < n; i++)\n {\n printf (\"%s %d\\t\", (b + i)->name, (b + i)->p); //Printing values in array of structures\n }\n\n return 0;\n} \n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31274/"
] |
260,945
|
<p>This should be easy, but I'm having a hard time finding the easiest solution.</p>
<p>I need an <code>NSString</code> that is equal to another string concatenated with itself a given number of times.</p>
<p>For a better explanation, consider the following python example:</p>
<pre><code>>> original = "abc"
"abc"
>> times = 2
2
>> result = original * times
"abcabc"
</code></pre>
<p>Any hints?</p>
<hr>
<p>EDIT:</p>
<p>I was going to post a solution similar to the one by <a href="https://stackoverflow.com/questions/260945/create-nsstring-by-repeating-another-string-a-given-number-of-times#260969">Mike McMaster's answer</a>, after looking at this implementation from the OmniFrameworks:</p>
<pre><code>// returns a string consisting of 'aLenght' spaces
+ (NSString *)spacesOfLength:(unsigned int)aLength;
{
static NSMutableString *spaces = nil;
static NSLock *spacesLock;
static unsigned int spacesLength;
if (!spaces) {
spaces = [@" " mutableCopy];
spacesLength = [spaces length];
spacesLock = [[NSLock alloc] init];
}
if (spacesLength < aLength) {
[spacesLock lock];
while (spacesLength < aLength) {
[spaces appendString:spaces];
spacesLength += spacesLength;
}
[spacesLock unlock];
}
return [spaces substringToIndex:aLength];
}
</code></pre>
<p>Code reproduced from the file:</p>
<pre><code>Frameworks/OmniFoundation/OpenStepExtensions.subproj/NSString-OFExtensions.m
</code></pre>
<p>on the OpenExtensions framework from the <a href="http://www.omnigroup.com/developer/" rel="noreferrer">Omni Frameworks</a> by <a href="http://www.omnigroup.com/" rel="noreferrer">The Omni Group</a>.</p>
|
[
{
"answer_id": 260969,
"author": "Mike McMaster",
"author_id": 544,
"author_profile": "https://Stackoverflow.com/users/544",
"pm_score": 3,
"selected": false,
"text": "NSString *original = @\"abc\";\nint times = 2;\n\n// Capacity does not limit the length, it's just an initial capacity\nNSMutableString *result = [NSMutableString stringWithCapacity:[original length] * times]; \n\nint i;\nfor (i = 0; i < times; i++)\n [result appendString:original];\n\nNSLog(@\"result: %@\", result); // prints \"abcabc\"\n"
},
{
"answer_id": 260979,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 1,
"selected": false,
"text": "NSString unicode n componentsJoinedByString: NSMutableArray *repetitions = [NSMutableArray arrayWithCapacity:n];\nfor (NSUInteger i = 0UL; i < n; ++i)\n [repetitions addObject:inputString];\noutputString = [repetitions componentsJoinedByString:@\"\"];\n NSMutableString n NSMutableString *temp = [NSMutableString stringWithCapacity:[inputString length] * n];\nfor (NSUInteger i = 0UL; i < n; ++i)\n [temp appendString:inputString];\noutputString = [NSString stringWithString:temp];\n stringWithString: stringWithString: componentsJoinedByString: …WithCapacity:"
},
{
"answer_id": 1181088,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "+ (NSString*)stringWithRepeatCharacter:(char)character times:(unsigned int)repetitions;\n{\n char repeatString[repetitions + 1];\n memset(repeatString, character, repetitions);\n\n // Set terminating null\n repeatString[repetitions] = 0;\n\n return [NSString stringWithCString:repeatString];\n}\n"
},
{
"answer_id": 1181162,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "+ (NSString*)stringWithRepeatString:(char*)characters times:(unsigned int)repetitions;\n{\n unsigned int stringLength = strlen(characters);\n unsigned int repeatStringLength = stringLength * repetitions + 1;\n\n char repeatString[repeatStringLength];\n\n for (unsigned int i = 0; i < repetitions; i++) {\n unsigned int pointerPosition = i * repetitions;\n memcpy(repeatString + pointerPosition, characters, stringLength); \n }\n\n // Set terminating null\n repeatString[repeatStringLength - 1] = 0;\n\n return [NSString stringWithCString:repeatString];\n}\n"
},
{
"answer_id": 4608137,
"author": "tig",
"author_id": 96823,
"author_profile": "https://Stackoverflow.com/users/96823",
"pm_score": 8,
"selected": true,
"text": "stringByPaddingToLength:withString:startingAtIndex: [@\"\" stringByPaddingToLength:100 withString: @\"abc\" startingAtIndex:0]\n 3 * [@\"abc\" length] @interface NSString (Repeat)\n\n- (NSString *)repeatTimes:(NSUInteger)times;\n\n@end\n\n@implementation NSString (Repeat)\n\n- (NSString *)repeatTimes:(NSUInteger)times {\n return [@\"\" stringByPaddingToLength:times * [self length] withString:self startingAtIndex:0];\n}\n\n@end\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2954/"
] |
260,962
|
<p>To trim the leading spaces we are using strmove. But we were advised to use strlmove instead of strmove. I have read and used strlcpy and strlcat. Whether strlmove does the similar functionality and what all are its advantages?</p>
<p>Edit 1: Thank you Mike B and Chris Young. This is how we use strlcpy.</p>
<pre><code>size_t strlcpy(char *dst, const char *src, size_t size)
{
strncpy(dst, src, size - 1);
dst[size - 1] = '\0';
return(strlen(src));
}
</code></pre>
<p>So I was just thinking of using strlmove() also in the same way. I want to confirm whether any specifications is defined regarding the implementation of strlmove(). I know this is one of the best place i can ask.</p>
<p>Edit 2: strlmove() is implemented the same way as strlcpy() and strlcat() using memmove().</p>
<pre><code>size_t strlmove(char *dst, const char *src, size_t size)
{
//Error if the size is 0
//If src length is greater than size;
// memmove(dst, src, size-1) and dst[size] = \0;
//Otherwise
// memmove(dst, src, length(src));
return source len;
}
</code></pre>
<p>Appreciate the help and support provided.</p>
<p>Thanks,
Mathew Liju</p>
|
[
{
"answer_id": 260972,
"author": "Chris Young",
"author_id": 9417,
"author_profile": "https://Stackoverflow.com/users/9417",
"pm_score": 2,
"selected": false,
"text": "char buf[4096];\nstrncpy(buf, \"Hello\", sizeof buf);\n char buf[5];\nstrncpy(buf, \"Hello\", sizeof buf);\n"
},
{
"answer_id": 260998,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": true,
"text": "strl() str() strl() str() strl() strn() str()"
},
{
"answer_id": 263125,
"author": "quinmars",
"author_id": 18687,
"author_profile": "https://Stackoverflow.com/users/18687",
"pm_score": 0,
"selected": false,
"text": "\nstrncpy(buffer, \"bla\", 1024);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18657/"
] |
260,986
|
<p>I have a text file which contains some data. I am trying to search for EA in <strong>ID column only</strong> and prints the whole row. But the code recognize all EA and prints all rows. What code I should add to satisfy the condition? Thanks Again:-)!</p>
<p>DATA: <br>
Name Age ID <br>
---------------------<br>
KRISTE,22,<strong>EA</strong>2008<br>
J<strong>EA</strong>N,21,ES4567<br>
JAK,45,<strong>EA</strong>2008<br><br>
The code prints:<br>
KRISTE,22,<strong>EA</strong>2008<br>
J<strong>EA</strong>N,21,ES4567<br>
JAK,45,<strong>EA</strong>2008<br></p>
<p>Desired output:<br>
KRIS,22,<strong>EA</strong>2008<br>
Kane,45,<strong>EA</strong>2008,<br></p>
<pre><code>file='save.txt';
open(F,$file)||die("Could not open $file");
while ($line=<F>){
if ($line=~ m/$EA/i) {
my @cells=($f1,$f2,$f3)= split ',',$line;
print "<TD>f1</TD>";
print "<TD>f2</TD>";
print "<TD>f3</TD>";
}
</code></pre>
|
[
{
"answer_id": 260995,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 2,
"selected": false,
"text": "file='save.txt';\nopen(F,$file)||die(\"Could not open $file\");\n\nwhile ($line=<F>){\n my @cells=($f1,$f2,$f3)= split ',',$line;\n if ($f3=~ m/$EA/i) {\n print \"<TD>f1</TD>\";\n print \"<TD>f2</TD>\";\n print \"<TD>f3</TD>\";\n }\n}\n"
},
{
"answer_id": 261141,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 3,
"selected": false,
"text": "use strict;\nuse warnings;\n\nuse CGI;\n\nmy $EA = param('keyword');\n\nmy $file = 'save.txt';\nopen my $fh, \"<\", $file or die \"Could not open $file: $!\";\n\nwhile( $line=<$fh> ) {\n if( $line=~ m/$EA/i ) {\n my( $f1, $f2, $f3 ) = split ',', $line;\n print \"<TD>$f1</TD>\";\n print \"<TD>$f2</TD>\";\n print \"<TD>$f3</TD>\";\n }\n }\n"
},
{
"answer_id": 261171,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": false,
"text": "use strict;\nuse warnings;\n\nmy $file = 'save.txt';\nopen my $fh, \"<\", $file or die \"Could not open $file: $!\";\n\nwhile ($line = <$fh>)\n{\n my($f1, $f2, $f3) = split ',', $line;\n if ($f3 =~ m/EA/i)\n {\n print \"<TD>$f1</TD>\";\n print \"<TD>$f2</TD>\";\n print \"<TD>$f3</TD>\";\n }\n}\n use CGI; my $EA = param('keyword');"
},
{
"answer_id": 262230,
"author": "Ben Doom",
"author_id": 12267,
"author_profile": "https://Stackoverflow.com/users/12267",
"pm_score": 1,
"selected": false,
"text": "/[^,]*,[^,]*,.*EA/\n"
},
{
"answer_id": 262571,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "\n$f = 'save.txt'; \n\nopen( F, $file );\n\n @matches = grep { /^.?,.?,.*EA/ } <F>;\n"
},
{
"answer_id": 267771,
"author": "Schwern",
"author_id": 14660,
"author_profile": "https://Stackoverflow.com/users/14660",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/perl -w\n\nuse Text::CSV_XS;\n\nmy $csv = Text::CSV_XS->new();\n\n# Skip to the data.\nwhile(<DATA>) {\n last if /^-{10,}$/;\n}\n\nwhile( my $row = $csv->getline(*DATA) ) {\n print \"@$row\\n\" if $row->[2] =~ /EA/;\n}\n\n\n__DATA__\nName Age ID\n---------------------\nKRISTE,22,EA2008\nJ**EA**N,21,ES4567\nJAK,45,EA2008\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28607/"
] |
260,987
|
<p>When we submit a job, the following steps are executed sequentially.</p>
<p>Then what is the importance of DPRTY?</p>
|
[
{
"answer_id": 370495,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "DPRTY IEAIPSxx"
},
{
"answer_id": 55945070,
"author": "Rohit Parab",
"author_id": 11430782,
"author_profile": "https://Stackoverflow.com/users/11430782",
"pm_score": 0,
"selected": false,
"text": "DPRTY DPRTY DPRTY(value1, value2) value1 = 0-15 value2 = 0-15 DPRTY DPRTY = (value1*16) + value2"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/260987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33392/"
] |
261,004
|
<p>I've got an old classic ASP site that connects to a local sql server 2000 instance. We're moving the db to a new box, and the port is non standard for sql (out of my control). .NET connection strings handle the port number fine by adding it with ,1999 after the server name/IP. The classic ASP connection string isn't working with the same syntax. I checked connectionstrings.com and couldn't find one that worked.</p>
<p>Current connection string (set to an Application variable in Global.asa):</p>
<pre><code>Driver={SQL Server};Server=xxx.xxx.xxx.xxx;Database=dbname;Uid=dbuser;Pwd=dbpassword
</code></pre>
<p>I've installed the SQL Native Client and couldn't get that working either (still working on this)</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 261077,
"author": "Sergey Kornilov",
"author_id": 10969,
"author_profile": "https://Stackoverflow.com/users/10969",
"pm_score": 0,
"selected": false,
"text": "cst = \"Provider=SQLOLEDB;\" & _ \n \"Data Source=<x.x.x.x>,<port number>;\" & _ \n \"Initial Catalog=<dbname>;\" & _ \n \"Network=DBMSSOCN;\" & _ \n \"User Id=<uid>;\" & _ \n \"Password=<pwd>\" \n\n set conn = CreateObject(\"ADODB.Connection\") \n conn.open cst \n"
},
{
"answer_id": 269951,
"author": "John Sheehan",
"author_id": 1786,
"author_profile": "https://Stackoverflow.com/users/1786",
"pm_score": 3,
"selected": true,
"text": "Driver={SQL Native Client};Server=xxx.xxx.xxx.xxx,port;Database=dbname;Uid=dbuser;Pwd=dbpassword\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1786/"
] |
261,013
|
<p>I work on a Fedora Linux box.</p>
<p>I have a whole host of binaries and libraries that I've installed locally under my home directory.</p>
<p>I'd like to set my system up so installing software there functions the same way (for me) as if the root user installed it without a prefix.</p>
<p>I can run binaries installed in ~/local/bin just fine by adding that dir to my PATH variable, but what about linking to libraries in ~/local/lib and ~/local/lib64?</p>
<p>Is there something akin to LD_LIBRARY_PATH variable but to find the library at compile rather than runtime? I don't want to worry about explicitly passing the path to the compiler via L~/local/lib or through flags in the ./configure script.</p>
|
[
{
"answer_id": 261048,
"author": "mipadi",
"author_id": 28804,
"author_profile": "https://Stackoverflow.com/users/28804",
"pm_score": 1,
"selected": false,
"text": "LIBRARY_PATH $HOME/local/lib:$HOME/local/lib64 C_INCLUDE_PATH CPLUS_INCLUDE_PATH $HOME/local/include"
},
{
"answer_id": 261172,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 1,
"selected": false,
"text": "$LD_LIBRARY_PATH /etc/ld.so.conf /etc/ld.so.conf.d ldconfig -rpath $LD_RUN_PATH ./configure $LD_RUN_PATH ./configure --prefix=${HOME}/local configure"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/109032/"
] |
261,015
|
<p>I want to have a look at how Java implements LinkedList. Where should I go to look at the source code?</p>
|
[
{
"answer_id": 261032,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 6,
"selected": false,
"text": "src.zip java/util/LinkedList.java"
},
{
"answer_id": 5308086,
"author": "fouding.zheng",
"author_id": 657306,
"author_profile": "https://Stackoverflow.com/users/657306",
"pm_score": 4,
"selected": false,
"text": "src/share/classes"
},
{
"answer_id": 51472372,
"author": "HA S",
"author_id": 9101688,
"author_profile": "https://Stackoverflow.com/users/9101688",
"pm_score": 0,
"selected": false,
"text": "public class LinkedListWatch{\n public static void main(String[] args){\n LinkedList linkedList = new LinkedList();\n\n }\n}\n ctrl + mouse left click LinkedList"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33203/"
] |
261,045
|
<p>I just upgraded to Eclipse 3.4 for the second time and I think its for good now. The first time (right when it was released) was too buggy for me to stomach (mainly the PDT 2.0 plug-in); but now it seems to be all worked out.</p>
<p>My problem is the Javascript validator. If I define a class in one JS file in my project, then try to use it in another, it tells me that the type is undefined. This is really annoying as some of my scripts are littered with red squigglys.</p>
<p>Another problem is that this code:</p>
<pre><code>var m_dialogFrame = document.getElementById(m_dialogId);
</code></pre>
<p>Makes a yellow squiggle saying "Type mismatch: cannot convert from Element to ___m_dialogBody5" I can fix it by adding</p>
<pre><code> /**
* @type Element
*/
</code></pre>
<p>Before it, but that, also, will be messy.</p>
<p>Also, both:</p>
<pre><code>new XMLHttpRequest();
</code></pre>
<p>And</p>
<pre><code>new ActiveXObject("Microsoft.XMLHTTP");
</code></pre>
<p>Get red squiggles saying "x cannot be resolved to a type"</p>
<p>The last problem is with:</p>
<p>if (m_options.width != "auto")</p>
<p>Gets a red squiggly because: "The operator != is undefined for the argument type(s) Number, String"</p>
<p>How can I fix these issues, or just scrap the entire Javascript validation tool? BTW: it looks frikin awesome if I can get it to work.</p>
|
[
{
"answer_id": 261760,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 3,
"selected": false,
"text": "Object String.split Array"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,050
|
<p>I'm having an issue with a standard ASP.NET page that has a TextBox and a RequiredFieldValidator. The steps to reproduce are quite simple:</p>
<ol>
<li>Place a TextBox on a page</li>
<li>Place a RequiredFieldValidator on the page</li>
<li>Point the RequiredFieldValidator at the TextBox</li>
<li>Run the app</li>
<li>Tab away from the TextBox the RequiredFieldValidator does not show</li>
<li>Enter text, then delete the text and THEN tab away, the RequiredFieldValidator does show</li>
</ol>
<p>The RequiredFieldValidator works fine in both cases after a postback, however it seems the client-side code isn't firing until something is entered into the textbox (and then deleted).</p>
<p>Does anyone have a solution to this without hacking away at JavaScript myself?</p>
|
[
{
"answer_id": 261100,
"author": "Jim Burger",
"author_id": 20164,
"author_profile": "https://Stackoverflow.com/users/20164",
"pm_score": 3,
"selected": true,
"text": "protected void Page_Load(object sender, EventArgs e)\n{\n Validate();\n}\n"
},
{
"answer_id": 261127,
"author": "sontek",
"author_id": 17176,
"author_profile": "https://Stackoverflow.com/users/17176",
"pm_score": 0,
"selected": false,
"text": "function blurred(sender) {\n var validator = sender.Validators[0]\n validator.evaluationfunction(validator);\n}\n <asp:TextBox runat=\"server\" ID=\"txt\" onBlur=\"blurred(this)\"></asp:TextBox>\n"
},
{
"answer_id": 261450,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 2,
"selected": false,
"text": "ScriptManager.RegisterStartupScript(this, GetType(), \"js\" + myTextBox.ClientID,\n \"ValidatorHookupEvent(document.getElementById(\\\"\" + myTextBox.ClientID + \n \"\\\"), \\\"onblur\\\", \\\"ValidatorOnChange(event);\\\");\", true);\n"
},
{
"answer_id": 16025429,
"author": "Faisal Salamah",
"author_id": 2265247,
"author_profile": "https://Stackoverflow.com/users/2265247",
"pm_score": 0,
"selected": false,
"text": " <asp:ScriptManager ID=\"ScriptManager1\" runat=\"server\" ValidateRequestMode=\"Enabled\" >\n <Scripts>\n <%--Framework Scripts--%>\n <%--<asp:ScriptReference Name=\"MsAjaxBundle\" />--%>\n <asp:ScriptReference Name=\"jquery\" />\n <asp:ScriptReference Name=\"jquery.ui.combined\" />\n <asp:ScriptReference Name=\"WebForms.js\" Path=\"~/Scripts/WebForms/WebForms.js\" />\n <asp:ScriptReference Name=\"WebUIValidation.js\" Path=\"~/Scripts/WebForms/WebUIValidation.js\" />\n <asp:ScriptReference Name=\"WebFormsBundle\" />\n <%--Site Scripts--%>\n\n </Scripts>\n </asp:ScriptManager>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1462735/"
] |
261,062
|
<p>Although I grasp the concept of Bitwise Operators, I can't say that I have come across many use cases during the webdevelopment process at which I had to resort to using Bitwise Operators.</p>
<ul>
<li>Do you use Bitwise Operators?</li>
<li>Why do you use them?</li>
<li>What are some example use cases?</li>
</ul>
<p>Please remember that this question is specifically intended for use of Bitwise Operators in web languages.</p>
|
[
{
"answer_id": 261073,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "& | if ((permissions & Permission.CreateUser) != 0)\n{\n ...\n}\n Permission requiredPermission = Permission.CreateUser\n | Permission.ChangePassword;\n"
},
{
"answer_id": 261227,
"author": "tyler",
"author_id": 25303,
"author_profile": "https://Stackoverflow.com/users/25303",
"pm_score": 6,
"selected": false,
"text": "// These are my masks\nprivate static final int MASK_DID_HOMEWORK = 0x0001;\nprivate static final int MASK_ATE_DINNER = 0x0002;\nprivate static final int MASK_SLEPT_WELL = 0x0004; \n\n// This is my current state\nprivate int m_nCurState;\n // Set state for'ate dinner' and 'slept well' to 'on'\nm_nCurState = m_nCurState | (MASK_ATE_DINNER | MASK_SLEPT_WELL);\n // Turn off the 'ate dinner' flag\nm_nCurState = (m_nCurState & ~MASK_ATE_DINNER);\n // Check if I did my homework\nif (0 != (m_nCurState & MASK_DID_HOMEWORK)) {\n // yep\n} else { \n // nope...\n}\n void setState( boolean bDidHomework, boolean bAteDinner, boolean bSleptWell);\n void setState( int nStateBits);\n"
},
{
"answer_id": 261925,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "boolean isFoo = ...\nboolean isBar = ...\n\nif (isFoo ^ isBar) {\n // Either isFoo is true or isBar is true, but not both.\n"
},
{
"answer_id": 655828,
"author": "Jayrox",
"author_id": 24802,
"author_profile": "https://Stackoverflow.com/users/24802",
"pm_score": 0,
"selected": false,
"text": "$color_red= 1;\n$color_blue = 2;\n$color_yellow = 8;\n\n$color_purple = 3;\n$color_orange = 9;\n$color_green = 10;\n $can_collect_200_dollars = 10;\n if($given_color & $can_collect_200_dollars)\n{\n $yay_i_got_200_dollars = true;\n}else{\n $bummer_i_am_going_to_jail = true;\n}\n"
},
{
"answer_id": 19968424,
"author": "RestInPeace",
"author_id": 1841956,
"author_profile": "https://Stackoverflow.com/users/1841956",
"pm_score": 3,
"selected": false,
"text": "& & && protected void btnSubmitClicked(...) {\n username = txtUsername.Text;\n email = txtEmail.Text;\n pass = txtPassword.Text;\n if (isUsernameValid(username) & isEmailValid(email) & isPasswordValid(pass)) {\n // form is valid\n } else {\n // form is invalid\n }\n ...\n}\n\nprivate bool isPasswordValid(string password) {\n bool valid = true;\n string msg = \"\";\n if (password.length < MIN_PASSWORD_SIZE) {\n valid = false;\n msg = \"Password must be at least \" + MIN_PASSWORD_SIZE + \" long.\";\n }\n\n highlightField(txtPassword, lblPassword, valid, msg);\n return valid;\n}\n\nprivate void highlightField(WebControl field, Label label, string valid, string msg) {\n if (isValid) {\n // de-highlight\n field.BorderColor = VALID_FIELD_COLOR;\n } else {\n // highlight the text field and focus on it\n field.BorderColor = INVALID_FIELD_COLOR;\n field.Focus();\n }\n\n label.Text = msg;\n}\n\n// and other similar functions for username and email\n && & btnSubmitClicked && &"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11568/"
] |
261,080
|
<p>I would like to have a Java component which has a resize icon on the bottom right of the component so that when I drag that icon, the component will automatically resize with it.</p>
<p>By resize icon, I mean the following:</p>
<p><img src="https://lh5.ggpht.com/_7dfPdX2BP6o/SQ_sPvvHpTI/AAAAAAAAAKU/vRWKb_pLVvc/s144/resize%20icon.jpg" alt="resize icon in Google Talk"></p>
<p>The above image contains the resize icon in the Google Talk messenger's main window. Is there any Java component which provides this facility?</p>
|
[
{
"answer_id": 717579,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "private void buttonMousePressed(java.awt.event.MouseEvent evt) {\n sx = evt.getX();\n sy = evt.getY();\n}\n\nprivate void buttonMouseDragged(java.awt.event.MouseEvent evt) {\n if(!evt.isMetaDown()){\n Point p = getLocation();\n\n locX = p.x + evt.getX()-sx;\n locY = p.y + evt.getY()-sy;\n setLocation(locX, locY);\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22550/"
] |
261,083
|
<p>How is it possible to identify that the browser's close button was clicked?</p>
|
[
{
"answer_id": 261111,
"author": "andyk",
"author_id": 26721,
"author_profile": "https://Stackoverflow.com/users/26721",
"pm_score": 2,
"selected": false,
"text": "$(window).unload( function () { alert(\"Bye now!\"); } );\n"
},
{
"answer_id": 262250,
"author": "northsouthwhat",
"author_id": 34213,
"author_profile": "https://Stackoverflow.com/users/34213",
"pm_score": 1,
"selected": false,
"text": "onbeforeunload onunload unload beforeunload window.onbeforeunload=function(){}\n Event.observe(window, 'beforeunload', function(){});\n"
},
{
"answer_id": 263252,
"author": "Joe Simes",
"author_id": 34394,
"author_profile": "https://Stackoverflow.com/users/34394",
"pm_score": 1,
"selected": false,
"text": "<body onunload=\"if(self.screenTop>9000){unloadFunction();}\">\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,086
|
<p>I am using a fictional example for this. Say, I have a Widget class like:</p>
<pre><code>abstract class Widget
{
Widget parent;
}
</code></pre>
<p>Now, my other classes would be derived from this Widget class, but suppose I want to put some constraint in the class while defining the derived types such that only a particular "type" of widget can be parent to a particular type of Widget.</p>
<p>For example, I have derived two more widgets from the Widget class, WidgetParent and WidgetChild. While defining the child class, I want to define the type of parent as WidgetParent, so that I dont have to type cast the parent every time I use it.</p>
<p>Precisely, what I would have liked to do is this:</p>
<pre><code>// This does not works!
class Widget<PType>: where PType: Widget
{
PType parent;
}
class WidgetParent<Widget>
{
public void Slap();
}
class WidgetChild<WidgetParent>
{
}
</code></pre>
<p>So that when I want to access the parent of WidgetChild, instead of using it this way:</p>
<pre><code>WidgetParent wp = wc.parent as WidgetParent;
if(wp != null)
{
wp.Slap();
}
else throw FakeParentException();
</code></pre>
<p>I want to use it this way(if I could use generics):</p>
<pre><code>wc.parent.Slap();
</code></pre>
|
[
{
"answer_id": 261104,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 0,
"selected": false,
"text": "class WidgetFactory\n{\n Widget CreateWidget()\n {\n return new Widget();\n }\n}\n class WidgetFactory<T> where T : Widget\n{\n T CreateWidget()\n {\n return new T();\n }\n}\n class WidgetFactory<T> where T : Widget\n{\n T CreateWidget()\n {\n if (/*check the type T inheritance here*/)\n return new T();\n else\n throw new Exception(\"Invalid inheritance\");\n }\n}\n"
},
{
"answer_id": 261146,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "Widget Widget<T> public abstract class Widget\n{\n}\n\npublic abstract class Widget<T> : Widget where T : Widget\n{\n}\n"
},
{
"answer_id": 261176,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "class Widget<PType> where PType :new()\n{\n public PType parent = new PType();\n}\n\nclass ParentType {}\n\nclass WidgetParent : Widget<ParentType> \n{ \n public void Slap() {Console.WriteLine(\"Slap\"); }\n}\n\nclass WidgetChild : Widget<WidgetParent>\n{\n}\npublic static void RunSnippet()\n{\n WidgetChild wc = new WidgetChild();\n wc.parent.Slap();\n}\n"
},
{
"answer_id": 261231,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 1,
"selected": false,
"text": "interface IContainerWidget { }\n\nclass Widget\n{\n private IContainerWidget Container;\n}\n\nclass ContainerWidget : Widget, IContainerWidget\n{\n}\n"
},
{
"answer_id": 269921,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "public interface IWidget\n{\n void Behave();\n IWidget Parent { get; }\n}\n\npublic class AWidget : IWidget\n{\n IWidget IWidget.Parent { get { return this.Parent; } }\n void IWidget.Behave() { this.Slap(); }\n\n public BWidget Parent { get; set; }\n public void Slap() { Console.WriteLine(\"AWidget is slapped!\"); }\n}\n\npublic class BWidget : IWidget\n{\n IWidget IWidget.Parent { get { return this.Parent; } }\n void IWidget.Behave() { this.Pay(); }\n\n public AWidget Parent { get; set; }\n public void Pay() { Console.WriteLine(\"BWidget is paid!\"); }\n}\n\npublic class WidgetTester\n{\n public void AWidgetTestThroughIWidget()\n {\n IWidget myWidget = new AWidget() { Parent = new BWidget() };\n myWidget.Behave();\n myWidget.Parent.Behave();\n }\n public void AWidgetTest()\n {\n AWidget myWidget = new AWidget() { Parent = new BWidget() };\n myWidget.Slap();\n myWidget.Parent.Pay();\n }\n\n public void BWidgetTestThroughIWidget()\n {\n IWidget myOtherWidget = new BWidget() { Parent = new AWidget() };\n myOtherWidget.Behave();\n myOtherWidget.Parent.Behave();\n }\n\n public void BWidgetTest()\n {\n BWidget myOtherWidget = new BWidget() { Parent = new AWidget() };\n myOtherWidget.Pay();\n myOtherWidget.Parent.Slap();\n }\n}\n"
},
{
"answer_id": 428354,
"author": "Tim Jarvis",
"author_id": 53365,
"author_profile": "https://Stackoverflow.com/users/53365",
"pm_score": 0,
"selected": false,
"text": "public class Parent<T>\n where T : Child<T>\n{\n public Parent() { }\n\n\n public T Get()\n {\n return Activator.CreateInstance(typeof(T), new object[] { this }) as T;\n }\n}\n\npublic class Child<T>\n where T : Child<T>\n{\n Parent<T> _parent;\n\n public Parent<T> Parent { get { return _parent; } }\n\n public Child(Parent<T> parent)\n {\n _parent = parent;\n }\n}\n\n\npublic class ItemCollection : Parent<Item>\n{\n\n}\n\npublic class Item : Child<Item>\n{\n public Item(Parent<Item> parent)\n : base(parent)\n {\n }\n}\n ItemCollection col = new ItemCollection();\nItem item = col.Get();\nitem.Parent.Slap();\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6621/"
] |
261,089
|
<p>how is it advisable to control the cpu utilization during run time ?</p>
<p>poll the cpu load and insert sleeps ?</p>
|
[
{
"answer_id": 261123,
"author": "artur02",
"author_id": 13937,
"author_profile": "https://Stackoverflow.com/users/13937",
"pm_score": 2,
"selected": false,
"text": "foreach (Process proc in Process.GetProcesses()) {\n using (PerformanceCounter pcProcess = new PerformanceCounter(\"Process\", \"% Processor Time\", proc.ProcessName)) {\n pcProcess.NextValue();\n System.Threading.Thread.Sleep(1000);\n Console.WriteLine(\"Process:{0} CPU% {1}\", proc.ProcessName, pcProcess.NextValue()); \n }\n}\n public string GetCPU()\n{\n decimal PercentProcessorTime=0;\n mObject_CPU.Get();\n\n ulong u_newCPU = \n (ulong)mObject_CPU.Properties[\"PercentProcessorTime\"].Value;\n ulong u_newNano = \n (ulong)mObject_CPU.Properties[\"TimeStamp_Sys100NS\"].Value;\n decimal d_newCPU = Convert.ToDecimal(u_newCPU);\n decimal d_newNano = Convert.ToDecimal(u_newNano);\n decimal d_oldCPU = Convert.ToDecimal(u_oldCPU);\n decimal d_oldNano = Convert.ToDecimal(u_oldNano);\n\n // Thanks to MSDN for giving me this formula !\n\n PercentProcessorTime = \n (1 - ((d_newCPU-d_oldCPU)/(d_newNano - d_oldNano)))*100m;\n\n // Save the values for the next run\n\n u_oldCPU = u_newCPU;\n u_oldNano = u_newNano;\n\n return PercentProcessorTime.ToString(\"N\",nfi);;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/195/"
] |
261,092
|
<p>What are all <a href="http://en.wikipedia.org/wiki/Hayes_command_set" rel="nofollow noreferrer">AT</a> commands required for <a href="http://en.wikipedia.org/wiki/General_Packet_Radio_Service" rel="nofollow noreferrer">GPRS</a> communication?</p>
|
[
{
"answer_id": 261144,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 2,
"selected": false,
"text": "MRESET:\nATZ\n MPROVIDERINIT:\nat+cgdcont=1,\"IP\",\"internet3.voicestream.com\",,0,0\n\nMIPINIT:\nat+wopen=1\n\nMPPPINIT:\nat#pppmode=1\n\nMCHECKPIN:\nat+cpin?\n\nMGSMREGISTER:\nat+creg=1\n MGPRSREGISTER:\nat+cgreg=1\n\nMGPRSATTACH:\nat+cgatt=1\n\nMGPRSMODE:\nat#gprsmode=1\n MSERVERINIT:\nAT#APNSERV=\"internet3.voicestream.com\"\n\nMUSERNAME:\nAT#APNUN=\"\"\n\nMPASSWORD:\nAT#APNPW=\"\"\n\nMSIGNAL:\nAT+CSQ\n\nMSTARTPPP:\nat#connectionstart\n MTCPSERVER:\nAT#TCPSERV=\"www.ubasics.com\"\n\nMTCPPORT:\nAT#TCPPORT=80\n\nMOPENSOCKET:\nat#otcp\n"
},
{
"answer_id": 742102,
"author": "hlovdal",
"author_id": 23118,
"author_profile": "https://Stackoverflow.com/users/23118",
"pm_score": 0,
"selected": false,
"text": "ATD*98*1#\n ATD*99***1#\n"
},
{
"answer_id": 58624899,
"author": "Stefan Ziegler",
"author_id": 12297053,
"author_profile": "https://Stackoverflow.com/users/12297053",
"pm_score": 0,
"selected": false,
"text": "AT+CGATT\nAT+CSTT\nAT+CIICR\nAT+CIFSR\nAT+CIPSTART\nAT+CIPSEND\nAT+CIPRXGET\nAT+CIPCLOSE\n"
},
{
"answer_id": 71136856,
"author": "Abdul Alim Shakir",
"author_id": 8504033,
"author_profile": "https://Stackoverflow.com/users/8504033",
"pm_score": 0,
"selected": false,
"text": "AT+GSLP=1500 AT+CWMODE=1 AT+CIPMUX=0 AT+CIPMODE=0 AT+CIPSTART = “TCP”,”182.65.89.118”, 8000 AT+CIPSEND = 47 AT+CIPCLOSE"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261092",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,098
|
<p>I am currently using the following javascript to create an expanding menu:</p>
<p><a href="http://demo.raibledesigns.com/struts-menu/scripts/menuExpandable.js.src" rel="nofollow noreferrer">http://demo.raibledesigns.com/struts-menu/scripts/menuExpandable.js.src</a></p>
<p>Currently, only the hyperlink text is clickable. What is the best way to have the icon next to the text respond to the click?</p>
|
[
{
"answer_id": 263365,
"author": "Chris MacDonald",
"author_id": 18146,
"author_profile": "https://Stackoverflow.com/users/18146",
"pm_score": 0,
"selected": false,
"text": "<a id=\"icon\" href=\"blah\">blah</a>\n #icon {\n background: transparent url(img.gif) no-repeat right center;\n padding-right: 10px;\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261098",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,125
|
<p>I launch a child process in Java as follows:</p>
<pre><code>final String[] cmd = {"<childProcessName>"};
Process process = Runtime.getRuntime().exec(cmd);
</code></pre>
<p>It now runs in the background. All good and fine. </p>
<p>If my program now crashes (it <em>is</em> still in dev :-)) the child process still seems to hang around. How can I make it automatically end when the parent Java process dies?</p>
<p>If it helps, I'm using Mac OS X 10.5</p>
|
[
{
"answer_id": 261133,
"author": "Steve McLeod",
"author_id": 2959,
"author_profile": "https://Stackoverflow.com/users/2959",
"pm_score": 3,
"selected": false,
"text": "final String[] cmd = {\"<childProcessName>\"};\nfinal Process process = Runtime.getRuntime().exec(cmd);\nRunnable runnable = new Runnable() {\n public void run() {\n process.destroy();\n }\n};\nRuntime.getRuntime().addShutdownHook(new Thread(runnable));\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2959/"
] |
261,139
|
<p>There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: <a href="https://xunit.net/docs/comparisons" rel="noreferrer">http://xunit.github.io/docs/comparisons.html</a></p>
<p>Now I am to choose the best one for us. But how? Does it matter? Which one is most future proof and has a decent momentum behind it? Should I care about the features? While xUnit seems to be most modern and specifically designed for .NET, NUnit again seems to be the one that is widely accepted. MSTest again is already integrated into Visual Studio ...</p>
|
[
{
"answer_id": 12611700,
"author": "Matt Crouch",
"author_id": 1670022,
"author_profile": "https://Stackoverflow.com/users/1670022",
"pm_score": 5,
"selected": false,
"text": "using Microsoft.VisualStudio.TestTools.UnitTesting;\nusing Assert = Xunit.Assert; // <-- Aliasing the Xunit namespace is key\n\nnamespace TestSample\n{\n [TestClass]\n public class XunitTestIntegrationSample\n {\n [TestMethod]\n public void TrueTest()\n {\n Assert.True(true); // <-- this is the Xunit.Assert class\n }\n\n [TestMethod]\n public void FalseTest()\n {\n Assert.False(true);\n }\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4227/"
] |
261,177
|
<p>[<em>Of course, the question is not restricted to a specific "friend" implementation, feel free though to point out implementation specifics if relevant</em>]</p>
<p>Reading through the unanswered questions, I stumbled upon the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx" rel="noreferrer"><code>InternalsVisibleTo</code></a> attribute:</p>
<blockquote>
<p>Specifies that types that are
ordinarily visible only within the
current assembly are visible to
another assembly.</p>
</blockquote>
<p>The <a href="http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx" rel="noreferrer">C# Programming Guide</a> on <a href="http://msdn.microsoft.com/en-us/library/" rel="noreferrer">MSDN</a> has a section <a href="http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx" rel="noreferrer">Friend Assemblies</a> describing how to use the attribute to allow the use of <code>internal</code> methods and types to another assembly.</p>
<p>I'm wondering whether it would be a Good Idea to use this to create a "hidden" interface for instrumenting a library for use by the unit testing assembly. It seems to increase coupling massively in both directions (testing code in the production assembly, intimate internal knowledge about the production assembly in testing code), but on the other hand it might help in creating fine-grained tests without cluttering the public interface.</p>
<p>What is your experience with using friend declarations when testing? Was it your Silver Bullet, or did it start the Death March? </p>
|
[
{
"answer_id": 261181,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": false,
"text": "InternalsVisibleTo"
},
{
"answer_id": 261217,
"author": "Bevan",
"author_id": 30280,
"author_profile": "https://Stackoverflow.com/users/30280",
"pm_score": 5,
"selected": true,
"text": "[InternalsVisibleTo] [InternalsVisibleTo] [InternalsVisibleTo]"
},
{
"answer_id": 270275,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 2,
"selected": false,
"text": "InternalsVisibleToAttribute internal private InternalsVisibleTo"
},
{
"answer_id": 270305,
"author": "Edward Kmett",
"author_id": 34707,
"author_profile": "https://Stackoverflow.com/users/34707",
"pm_score": 2,
"selected": false,
"text": "InternalsVisibleToAttribute"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4918/"
] |
261,190
|
<p>I am rendering a rails partial and I want to alternate the background color when it renders the partial. I know that is not super clear so here is an example of what I want to do:</p>
Row One grey Background
Row Two yellow background
Row Three grey Background
Row Four yellow background
<ul>
<li>sorry stackoverflow seams to prevent the background colors from being shown but I think this makes my idea clear</li>
</ul>
<p>This is the view code that I am using </p>
<pre><code><table>
<%= render :partial => 'row' :collection => @rows %>
</table>
</code></pre>
<p>the _row.html.erb partial looks like this</p>
<pre><code><tr bgcolor="#AAAAAA">
<td><%= row.name %></td>
</tr>
</code></pre>
<p>The problem is I do not know how to change the background color for every other row. Is there a way to do this?</p>
|
[
{
"answer_id": 261204,
"author": "Kristian",
"author_id": 23246,
"author_profile": "https://Stackoverflow.com/users/23246",
"pm_score": 5,
"selected": true,
"text": "<tr class=\"<%= cycle(\"even\", \"odd\") %>\">\n <td><%= row.name %></td>\n</tr>\n"
},
{
"answer_id": 14175375,
"author": "Brendan",
"author_id": 633523,
"author_profile": "https://Stackoverflow.com/users/633523",
"pm_score": 0,
"selected": false,
"text": "cycle('odd', 'even') << \" some other classes\"\n \"some other classes \" << cycle('odd', 'even')\n\"#{cycle('odd', 'even')} some other classes\"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5004/"
] |
261,202
|
<p>I've written a little web site in my effort to learn vb.net and asp.net, fairly happy with it so rented some space and uploaded it, it was written using asp.net express edition 2008 and sql server express .... I've uploaded it and I've found that it was written in .NET 3.5 and my host only deals with 2.01 ... I've sorted most of that out, and trimmed my web.config file back to basics, but my forms based authentication isn't working </p>
<pre><code><compilation debug="true" strict="false" explicit="true">
</compilation>
<authentication mode="Forms" />
<customErrors mode="Off"/>
</system.web>
</code></pre>
<p>And it keeps reporting that the sql server does not support remote access ...... not sure what to do next, I don't have to write my own security routines do i ? I have a sql server back end</p>
<p>Thanks for your time</p>
<p>Chris</p>
|
[
{
"answer_id": 263709,
"author": "spacemonkeys",
"author_id": 32336,
"author_profile": "https://Stackoverflow.com/users/32336",
"pm_score": 0,
"selected": false,
"text": "<?xml version=\"1.0\"?>\n<configuration>\n <appSettings/>\n <connectionStrings>\n <add name=\"DatebaseConnectionString\" connectionString=\"ohh wouldn't you like to know\" />\n </connectionStrings>\n <system.web>\n <roleManager enabled=\"true\" />\n <compilation debug=\"true\" strict=\"false\" explicit=\"true\">\n </compilation>\n <pages>\n <namespaces>\n <clear/>\n <add namespace=\"System\"/>\n <add namespace=\"System.Collections\"/>\n <add namespace=\"System.Collections.Generic\"/>\n <add namespace=\"System.Collections.Specialized\"/>\n <add namespace=\"System.Configuration\"/>\n <add namespace=\"System.Text\"/>\n <add namespace=\"System.Text.RegularExpressions\"/>\n <add namespace=\"System.Web\"/>\n <add namespace=\"System.Web.Caching\"/>\n <add namespace=\"System.Web.SessionState\"/>\n <add namespace=\"System.Web.Security\"/>\n <add namespace=\"System.Web.Profile\"/>\n <add namespace=\"System.Web.UI\"/>\n <add namespace=\"System.Web.UI.WebControls\"/>\n <add namespace=\"System.Web.UI.WebControls.WebParts\"/>\n <add namespace=\"System.Web.UI.HtmlControls\"/>\n </namespaces>\n </pages>\n <authentication mode=\"Forms\" />\n <membership defaultProvider=\"SqlProvider\">\n <providers>\n <add connectionStringName=\"DatebaseConnectionString\" applicationName=\"pedalpedalpuffpuff.com\"\n enablePasswordRetrieval=\"false\" enablePasswordReset=\"true\"\n requiresQuestionAndAnswer=\"true\" requiresUniqueEmail=\"true\"\n passwordFormat=\"Hashed\" maxInvalidPasswordAttempts=\"5\" passwordAttemptWindow=\"10\"\n name=\"SqlProvider\" type=\"System.Web.Security.SqlMembershipProvider\" />\n </providers>\n </membership>\n <customErrors mode=\"Off\"/>\n </system.web>\n</configuration>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32336/"
] |
261,215
|
<p>I need to write the content of a map (key is ID of int, value is of self-defined struct) into a file, and load it from the file later on. Can I do it in MFC with CArchive?</p>
<p>Thank you!</p>
|
[
{
"answer_id": 261239,
"author": "Pieter",
"author_id": 5822,
"author_profile": "https://Stackoverflow.com/users/5822",
"pm_score": 1,
"selected": false,
"text": "struct MapData {\n int m_int;\n std::string m_str;\n\n private: \n friend class boost::serialization::access; \n\n template<class Archive> \n void serialize(Archive &ar, const unsigned int version) \n { \n ar & m_int; \n ar & m_str; \n } \n};\n\nstd::map< int, MapData > theData;\n\ntemplate<class Archive>\nvoid serialize(Archive & ar, std::map< int, MapData > & data, const unsigned int version)\n{\n ar & data;\n}\n std::ofstream ofs(\"filename\"); \nboost::archive::binary_oarchive oa(ofs); \noa << theData; \n"
},
{
"answer_id": 261303,
"author": "Reunanen",
"author_id": 19254,
"author_profile": "https://Stackoverflow.com/users/19254",
"pm_score": 3,
"selected": false,
"text": "std::map CMap std::map void MyClass::Serialize(CArchive& archive)\n{\n CObject::Serialize(archive);\n if (archive.IsStoring()) {\n archive << m_map.size(); // save element count\n std::map<int, MapData>::const_iterator iter = m_map.begin(), \n iterEnd = m_map.end();\n for (; iter != iterEnd; iter++) {\n archive << iter->first << iter->second;\n }\n }\n else {\n m_map.clear();\n size_t mapSize = 0;\n archive >> mapSize; // read element count\n for (size_t i = 0; i < mapSize; ++i) {\n int key;\n MapData value;\n archive >> key;\n archive >> value;\n m_map[key] = value;\n }\n }\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261215",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26404/"
] |
261,219
|
<p>I'm having a bit of trouble trying to get class variables to work in javascript. </p>
<p>I thought that I understood the prototype inheritance model, but obviously not. I assumed that since prototypes will be shared between objects then so will their variables.</p>
<p>This is why this bit of code confuses me.</p>
<p>What is the correct way to implement class variables?</p>
<pre><code>function classA() {};
classA.prototype.shared = 0;
a = new classA;
//print both values to make sure that they are the same
classA.prototype.shared;
a.shared;
//increment class variable
classA.prototype.shared++;
//Verify that they are each 1 (Works)
classA.prototype.shared;
a.shared;
//now increment the other reference
a.shared++;
//Verify that they are each 2 (Doesn't Work)
classA.prototype.shared;
a.shared;
</code></pre>
<p>UPDATE:
So it seems that everyone is confirming the fact that by incrementing the instance's variable we don't affect the prototype. This is fine, this is what I have documented in my example, but doesn't this seem like an error in the design of the language? Why would this behavior be desirable? I find it weird that when the instance's var is undefined we follow the hidden link to the prototype where we get the value of the var, but we copy it into the instance object. </p>
<p>I also understand that this isn't java/c++/ruby/python, it's a different language. I'm just curious as to why this behavior might be good. </p>
|
[
{
"answer_id": 261241,
"author": "Chei",
"author_id": 11411,
"author_profile": "https://Stackoverflow.com/users/11411",
"pm_score": 1,
"selected": false,
"text": "a = new classA a classA classA.prototype a classA a1 = new classA a2 = new classA a1 a2 classA.prototype shared a classA.prototype.shared"
},
{
"answer_id": 261243,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 2,
"selected": false,
"text": "function ClassA(x) { this.x = x; }\nClassA.shared = \"\";\nClassA.prototype.foo = function() {\n return ClassA.shared + this.x;\n}\n\nvar inst1 = new ClassA(\"world\");\nvar inst2 = new ClassA(\"mars\");\n\nClassA.shared = \"Hello \";\nconsole.log(inst1.foo());\nconsole.log(inst2.foo());\nClassA.shared = \"Good bye \";\nconsole.log(inst1.foo());\nconsole.log(inst2.foo());\n"
},
{
"answer_id": 261356,
"author": "Chei",
"author_id": 11411,
"author_profile": "https://Stackoverflow.com/users/11411",
"pm_score": 3,
"selected": false,
"text": "Circle.PI = 3.14 Circle.PI c.PI shared classA classA classA.shared a.shared a.shared classA.shared"
},
{
"answer_id": 261568,
"author": "Daniel Beardsley",
"author_id": 13216,
"author_profile": "https://Stackoverflow.com/users/13216",
"pm_score": 4,
"selected": false,
"text": "function classA(){\n //initialize\n}\n\nclassA.prototype.method1 = function(){\n //accessible from anywhere\n classA.static_var = 1;\n //accessible only from THIS object\n this.instance_var = 2;\n}\n\nclassA.static_var = 1; //This is the same variable that is accessed in method1()\n var a = new classA();\nclassA.prototype.stat = 1;\n\n// checks a.stat which is undefined, then checks classA.prototype.stat which has a value\nalert(a.stat); // (a.stat = undefined, a.prototype.stat = 1)\n\n// after this a.stat will not check the prototype because it is defined in the object.\na.stat = 5; // (a.stat = 5, a.prototype.stat = 1)\n\n// this is essentially a.stat = a.stat + 1;\na.stat++; // (a.stat = 6, a.prototype.stat = 1) \n"
},
{
"answer_id": 261639,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 2,
"selected": false,
"text": "shared >>> function ConstructorA() {};\n>>> ConstructorA.prototype.shared = 0;\n>>> var a = new ConstructorA();\n>>> ConstructorA.prototype.shared++;\n>>> a.shared\n1\n>>> a.hasOwnProperty(\"shared\")\nfalse\n>>> a.shared++;\n>>> a.hasOwnProperty(\"shared\")\ntrue\n ConstructorA.shared new a.shared ConstructorA.shared"
},
{
"answer_id": 261779,
"author": "Vincent Robert",
"author_id": 268,
"author_profile": "https://Stackoverflow.com/users/268",
"pm_score": 0,
"selected": false,
"text": "function ClassA()\n{\n ClassA.countInstances = (ClassA.countInstances || 0) + 1;\n}\nvar a1 = new ClassA();\nalert(ClassA.countInstances);\nvar a2 = new ClassA();\nalert(ClassA.countInstances);\n"
},
{
"answer_id": 261948,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 4,
"selected": true,
"text": "I assumed that since prototypes will be shared between objects then so will their variables.\n a.shared++\n (a.shared= a.shared+1)-1\n classA.prototype.shared= 1;\na.shared= 2;\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28486/"
] |
261,223
|
<p>I am creating my application using Django, and am wondering how I can make Django use my CSS file? What settings do I need to do to make Django see the css file?</p>
<p>NB: On a local machine</p>
|
[
{
"answer_id": 617130,
"author": "Joe",
"author_id": 74474,
"author_profile": "https://Stackoverflow.com/users/74474",
"pm_score": 7,
"selected": true,
"text": "/site_media/images/foo.gif"
},
{
"answer_id": 12706373,
"author": "jacanterbury",
"author_id": 765827,
"author_profile": "https://Stackoverflow.com/users/765827",
"pm_score": 4,
"selected": false,
"text": "STATICFILES_DIRS STATICFILES_DIRS = (\n # Put strings here, like \"/home/html/static\" or \"C:/www/django/static\".\n # Always use forward slashes, even on Windows.\n # Don't forget to use absolute paths, not relative paths.\n os.path.join(os.path.dirname(__file__),'media').replace('\\\\','/'),\n)\n MEDIA_ROOT = ''\nMEDIA_URL = ''\nSTATIC_ROOT = ''\nSTATIC_URL = '/media/'\n / STATIC_URL <link href=\"{{ STATIC_URL }}css/ea_base.css\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\" />\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26143/"
] |
261,234
|
<p>Let's say I have an array of lots of values (C++ syntax, sorry):</p>
<pre><code>vector<double> x(100000);
</code></pre>
<p>This array is sorted such that <code>x[n] > x[n-1]</code>.</p>
<p>I would like a function to retrieve an array of all values in the range [a, b] (that's inclusive). Some interface like:</p>
<pre><code>void subarray(const double a, const double b, vector<double> &sub) {
...
}
</code></pre>
<p>When this function completes, <code>sub</code> will contain the <code>n</code> values that fell in the range [a, b].</p>
<p>Of course a linear search is easy:</p>
<pre><code>void subarray(const double a, const double b, vector<double> &sub) {
for (size_t i = 0; i < data.size(); i++) {
if (a <= data[i] && data[i] <= b) {
sub.push_back(data[i]);
}
}
}
</code></pre>
<p>However, because <code>data</code> is sorted, I should be able to do this much faster using a binary search. Who wants to take a stab at it? Any language is permitted!</p>
|
[
{
"answer_id": 261250,
"author": "Diomidis Spinellis",
"author_id": 20520,
"author_profile": "https://Stackoverflow.com/users/20520",
"pm_score": 3,
"selected": true,
"text": "void subarray(const double a, const double b, vector <double> &sub, vector <int> pn) {\n vector <int>::const_iterator begin, end;\n begin = lower_bound(pn.begin(), pn.end(), a);\n end = upper_bound(pn.begin(), pn.end(), b);\n sub.insert(sub.begin(), begin, end);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
261,237
|
<p>How do I create an Application Pool on IIS 6.0 using a PowerShell script?</p>
<p>This is what I have come up with so far ...</p>
<pre><code>$appPool = [wmiclass] "root\MicrosoftIISv2:IIsApplicationPool"
</code></pre>
<p>Thanks</p>
|
[
{
"answer_id": 263843,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 4,
"selected": true,
"text": "$AppPoolSettings = [wmiclass]'root\\MicrosoftIISv2:IISApplicationPoolSetting'\n$NewPool = $AppPoolSettings.CreateInstance()\n$NewPool.Name = 'W3SVC/AppPools/MyAppPool'\n$Result = $NewPool.Put()\n"
},
{
"answer_id": 264404,
"author": "Robert Wagner",
"author_id": 10784,
"author_profile": "https://Stackoverflow.com/users/10784",
"pm_score": 3,
"selected": false,
"text": "# Settings\n$newApplication = \"MaxSys.Services\"\n$poolUserName = \"BRISBANE\\svcMaxSysTest\"\n$poolPassword = \"ThisisforT3sting\"\n\n$newVDirName = \"W3SVC/1/ROOT/\" + $newApplication\n$newVDirPath = \"C:\\\" + $newApplication\n$newPoolName = $newApplication + \"Pool\"\n\n#Switch the Website to .NET 2.0\nC:\\windows\\Microsoft.NET\\Framework\\v2.0.50727\\aspnet_regiis.exe -sn W3SVC/\n\n# Create Application Pool\n$appPoolSettings = [wmiclass] \"root\\MicrosoftIISv2:IISApplicationPoolSetting\"\n$newPool = $appPoolSettings.CreateInstance()\n$newPool.Name = \"W3SVC/AppPools/\" + $newPoolName\n$newPool.PeriodicRestartTime = 0\n$newPool.IdleTimeout = 0\n$newPool.MaxProcesses = 2\n$newPool.WAMUsername = $poolUserName\n$newPool.WAMUserPass = $poolPassword\n$newPool.AppPoolIdentityType = 3\n$newPool.Put()\n# Do it again if it fails as there is a bug with Powershell/WMI\nif (!$?) \n{\n $newPool.Put() \n}\n\n# Create the virtual directory\nmkdir $newVDirPath\n\n$virtualDirSettings = [wmiclass] \"root\\MicrosoftIISv2:IIsWebVirtualDirSetting\"\n$newVDir = $virtualDirSettings.CreateInstance()\n$newVDir.Name = $newVDirName\n$newVDir.Path = $newVDirPath\n$newVDir.EnableDefaultDoc = $False\n$newVDir.Put()\n# Do it a few times if it fails as there is a bug with Powershell/WMI\nif (!$?) \n{\n $newVDir.Put() \n}\n\n# Create the application on the virtual directory\n$vdir = Get-WmiObject -namespace \"root\\MicrosoftIISv2\" -class \"IISWebVirtualDir\" -filter \"Name = '$newVDirName'\"\n$vdir.AppCreate3(2, $newPoolName)\n\n# Updated the Friendly Name of the application\n$newVDir.AppFriendlyName = $newApplication\n$newVDir.Put()\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10784/"
] |
261,271
|
<p>I'd like to compare two consecutive elements in a std::list while iterating through the list. What is the proper way to access element i+1 while my iterator is at element i?
Thanks
Cobe</p>
|
[
{
"answer_id": 261277,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "next prior *itr == *next(itr)\n adjacent_find"
},
{
"answer_id": 261287,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 3,
"selected": false,
"text": "std::list<int>::const_iterator second = list.begin(),\n end = list.end();\n\nif ( second != end ) // Treat empty list\n for(std::list<int>::const_iterator first = second++; // Post-increment \n second != end; \n ++first, ++second)\n {\n //...\n }\n first second first list.begin() list.begin()+1 next prior list template <class Iterator>\nIterator next(Iterator i) // Call by value, original is not changed\n{ \n return ++i;\n}\n// Implementing prior is left as an exercise to the reader ;o) \n next next(i) end() next"
},
{
"answer_id": 261413,
"author": "Nicola Bonelli",
"author_id": 19630,
"author_profile": "https://Stackoverflow.com/users/19630",
"pm_score": 4,
"selected": false,
"text": "template <class ForwardIterator>\n ForwardIterator adjacent_find ( ForwardIterator first, ForwardIterator last );\n\ntemplate <class ForwardIterator, class BinaryPredicate>\n ForwardIterator adjacent_find ( ForwardIterator first, ForwardIterator last,\n BinaryPredicate pred );\n"
},
{
"answer_id": 261733,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 1,
"selected": false,
"text": "if (!l.empty()) {\n for (list<T>::const_iterator i = l.begin();;) {\n const T &a = *i;\n ++i;\n if (i == l.end()) break;\n do_comparison(a, *i);\n }\n}\n"
},
{
"answer_id": 33833664,
"author": "Joe",
"author_id": 5587021,
"author_profile": "https://Stackoverflow.com/users/5587021",
"pm_score": 0,
"selected": false,
"text": "for (list<int>::iterator it = test.begin(); it!=test.end(); it++) {\n cout<<*it<<\":\\t\";\n list<int>::iterator copy = it;\n for( list<int>::iterator it2 = ++copy; it2!=test.end();it2++){\n cout<<*it2<<\"\\t\";\n }\n cout<<endl;\n }\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,290
|
<p>Does MSTest have standalone GUI similar to nUnit that lets me use it and run test without visual studio? What is the official site for MSTest where I can learn more about how to use it?</p>
|
[
{
"answer_id": 74107994,
"author": "Iván Kollár",
"author_id": 6281186,
"author_profile": "https://Stackoverflow.com/users/6281186",
"pm_score": 0,
"selected": false,
"text": "'dotnet test yourassembly.dll -l console -v detailed'\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4227/"
] |
261,296
|
<p>I have a batch file (in windows XP, with command extension activated) with the following line:</p>
<pre><code>for /f %%s in ('type version.txt') do set VERSION=%%s
</code></pre>
<p>On some computer, it works just fine (as illustrated by <a href="https://stackoverflow.com/questions/130116/dos-batch-commands-to-read-first-line-from-text-file">this SO question</a>), but on other <strong>it kills cmd</strong> (the console window just closes)</p>
<p>Why ?</p>
<hr>
<p>Note: the computers seem to have a similar configuration: XpSP2, the user has administrative right, no 'Command processor" defined in HKEY_CURRENT_USER\Software\Microsoft\Command Processor...</p>
|
[
{
"answer_id": 261299,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": true,
"text": "for /f %%s in (version.txt) do ...\n for /f for /f COMSPEC SET COMSPEC for dir ComSpec cmd HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\\ComSpec=\n%SystemRoot%\\system32\\cmd.exe\n"
},
{
"answer_id": 262599,
"author": "Keng",
"author_id": 730,
"author_profile": "https://Stackoverflow.com/users/730",
"pm_score": 0,
"selected": false,
"text": "for /F [\"usebackqParsingKeywords\"] {%% | %}variable in (\"filenameset\") do command [CommandLineOptions]\n\nfor /F [\"usebackqParsingKeywords\"] {%% | %}variable in ('LiteralString') do command [CommandLineOptions]\n\nfor /F [\"usebackqParsingKeywords\"] {%% | %}variable in (`command`) do command [CommandLineOptions]\n"
},
{
"answer_id": 271002,
"author": "Philibert Perusse",
"author_id": 7984,
"author_profile": "https://Stackoverflow.com/users/7984",
"pm_score": 2,
"selected": false,
"text": "VERIFY errors 2>nul\nSETLOCAL ENABLEEXTENSIONS\nIF ERRORLEVEL 1 echo Unable to enable extensions\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6309/"
] |
261,311
|
<p>In C I know about the recursive function but I heard about the re-entrant function.<p>What is that? And whats the difference between them? </p>
|
[
{
"answer_id": 261313,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 5,
"selected": true,
"text": "strtok()"
},
{
"answer_id": 314772,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "recursion-safe recursive"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31116/"
] |
261,316
|
<p>I have created a report in MS Access report and write some VBA code to retrive data and show the report in MS-Word format.
But while generate the report on runtime, the report first show or flash the report design view for few seconds and the report will get generated. </p>
<p>I would like to find a solution to avoid this flashing of design view while generate the report. Is it possible in this MS-Access or VBA coding. ??</p>
<p>I am posting the lines which i used to call the access report from access form code.</p>
<p>DoCmd.OpenReport rst![Argument], acPreview</p>
<p>this will generate the report but the design screen is flashing for few seconds while execution. </p>
<p>And there is no VBA code has been written in the access report.</p>
<p>The actual running is, i have prepare the data in a temp access table and generate the report from the table. </p>
<p>The problem here is, while launching the report in preview mode the design screen of the report shows of some few seconds. This looks bad from the users side. </p>
|
[
{
"answer_id": 271239,
"author": "David-W-Fenton",
"author_id": 9787,
"author_profile": "https://Stackoverflow.com/users/9787",
"pm_score": 1,
"selected": true,
"text": " Dim strReport As Report \n strReport = rst!Argument\n If SysCmd(acSysCmdGetObjectState, acReport, strReport) Then\n DoCmd.Close acReport, strReport\n End If\n DoCmd.OpenReport strReport, acPreview\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18792/"
] |
261,336
|
<p>If I declare a temporary auto deleted character buffer using</p>
<pre><code>std::auto_ptr<char> buffer(new char[n]);
</code></pre>
<p>then the buffer is automatically deleted when the buffer goes out of scope. I would assume that the buffer is deleted using delete.</p>
<p>However the buffer was created using new[], and so strictly speaking the buffer should be deleted using delete[].</p>
<p>What possibility is there that this mismatch might cause a memory leak?</p>
|
[
{
"answer_id": 261355,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 3,
"selected": false,
"text": "std::vector<char> boost::scoped_array<char> / boost::shared_array<char> std::auto_ptr<> std::vector"
},
{
"answer_id": 262779,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 3,
"selected": false,
"text": "std::vector<char> buffer(size);\n\nread(input,&buffer[0],size);\n (&buffer[0]) + size == (&buffer[size])\n"
},
{
"answer_id": 262930,
"author": "Paul Nathan",
"author_id": 26227,
"author_profile": "https://Stackoverflow.com/users/26227",
"pm_score": 0,
"selected": false,
"text": " char *c=new char[n] \n vector<char> c\n"
},
{
"answer_id": 279032,
"author": "Sanjaya R",
"author_id": 9353,
"author_profile": "https://Stackoverflow.com/users/9353",
"pm_score": 2,
"selected": false,
"text": "typedef< typename T_ >\nstruct auto_vec{\n T_* t_;\n auto_vec( T_* t ): t_( t ) {}\n ~auto_vec() { delete[] t_; }\n T_* get() const { return t_; }\n T_* operator->() const { return get(); }\n T_& operator*() const { return *get(); }\n /* you should also define operator=, reset and release, if you plan to use them */\n}\n\nauto_vec<char> buffer( new char[n] );\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/259/"
] |
261,338
|
<p>Talking from a 'best practice' point of view, what do you think is the best way to insert HTML using PHP. For the moment I use one of the following methods (mostly the latter), but I'm curious to know which you think is best.</p>
<pre><code><?php
if($a){
?>
[SOME MARKUP]
<?php
}
else{
?>
[SOME OTHER MARKUP]
<?php
}
?>
</code></pre>
<p>Opposed to:</p>
<pre><code><?php
unset($out);
if($a) $out = '[SOME MARKUP]';
else $out = '[OTHER MARKUP]';
print $out;
?>
</code></pre>
|
[
{
"answer_id": 261384,
"author": "neu242",
"author_id": 13365,
"author_profile": "https://Stackoverflow.com/users/13365",
"pm_score": 1,
"selected": false,
"text": "<html><head><title>%title%</title></head><body>\n%mainbody%\nBla bla bla <a href=\"%linkurl%\">%linkname%</a>.\n</body></html>\n <?php\n$title = getTitle();\n$mainbody = getMainBody();\n$linkurl = getLinkUrl();\n$linkname = getLinkName();\n$search = array(\"/%title%/\", \"/%mainbody%/\", \"/%linkurl%/\", \"/%linkname%/\");\n$replace = array($title, $mainbody, $linkurl, $linkname);\n$template = file_get_contents(\"template.inc\");\nprint preg_replace($search, $replace, $template);\n?>\n"
},
{
"answer_id": 261385,
"author": "monzee",
"author_id": 31003,
"author_profile": "https://Stackoverflow.com/users/31003",
"pm_score": 2,
"selected": false,
"text": "<?php if ($a) : ?>\n [MARKUP HERE]\n<?php else : ?>\n [SOME MORE MARKUP]\n<?php endif ?>\n"
},
{
"answer_id": 261402,
"author": "markus",
"author_id": 11995,
"author_profile": "https://Stackoverflow.com/users/11995",
"pm_score": 1,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n <head>\n <% base_tag %>\n $MetaTags\n <link rel=\"stylesheet\" type=\"text/css\" href=\"tutorial/css/layout.css\" />\n </head>\n <body>\n <div id=\"Main\">\n <ul id=\"Menu1\">\n <% control Menu(1) %>\n <li class=\"$LinkingMode\">\n <a href=\"$Link\" title=\"Go to the "{$Title}" page\">$MenuTitle</a>\n </li>\n <% end_control %>\n </ul>\n <div id=\"Header\">\n <h1>$Title</h1>\n </div>\n <div id=\"ContentContainer\">\n $Layout\n </div>\n <div id=\"Footer\">\n <span>Some Text</span>\n </div>\n </div>\n </body>\n</html>\n <?php\n unset($out);\n if($a) $out = '[SOME CONTENT TO INSERT INTO THE TEMPLATE]';\n else $out = '[SOME ALTERNATIVE CONTENT]';\n templateInsert($out);\n?>\n"
},
{
"answer_id": 261416,
"author": "adnam",
"author_id": 27886,
"author_profile": "https://Stackoverflow.com/users/27886",
"pm_score": 0,
"selected": false,
"text": "<?php if($a):?>\n[SOME MARKUP]\n<?php else: ?>\n[SOME OTHER MARKUP]\n<? endif; ?>\n"
},
{
"answer_id": 261549,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 6,
"selected": true,
"text": "<?php \n\n $pageData = (object)(array()); // Handy trick I learnt. \n\n /* Logic Goes here */\n\n\n $pageData->foo = SomeValue; \n\n ob_start(); \n require(\"layout.php\"); \n ob_end_flush();\n <html>\n <!-- etc -->\n <?php for ( $i = 1; $i < 10; $i++ ){ ?>\n <?php echo $pageData->foo[$i]; ?>\n <?php } ?>\n <!-- etc -->\n</html>\n {if $cond}\n {$dangerous_value}\n{else}\n {$equally_dangerous_value}\n{/if}\n {$code_gets_escaped} \n{{$code_gets_escaped_as_a_uri}}\n{{{$dangerous_bare_code}}}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20603/"
] |
261,345
|
<p>How do I get the complete request URL (including query string) in my controller? Is it a matter of concatenating my URL and form parameters or is there a better way.</p>
<p>I checked <a href="https://stackoverflow.com/questions/40680/how-do-i-get-the-full-url-of-the-page-i-am-on-in-c">this</a> question, but it seems not to be applicable to MVC. </p>
<p>Correct me if I'm wrong.</p>
<p>Some more detailed information:</p>
<p>My call to my <code>SearchController.AdvancedSearch()</code> originates from a form with about 15 optional parameters. Because of the number of parameters and no possible way (I think) to have optional parameters passed in a clean way, I went for a catchall string that is handled in the controller.</p>
<p>Now I want my controller to store its call in a breadcrumb component so that when the crumb is clicked the exact same result can be fetched (with all, but not more, of the arguments included). To do this I need the entire request.URL, <em>including the querystring</em>.</p>
<p>In <code>Request.RawURL</code>, <code>request.URL</code> etc this query string is not included. In fact currently I do a plain function.</p>
<pre><code>String.Format("{0}/{1}", request.Url, request.form)
</code></pre>
<p>This gives me some weird results (like submit button values etc), but it works. If there are suggestions on how to make this less of an ugly hack, please do tell.</p>
<p>I know where to find the current request, but I can't seem to find a raw URL anywhere though. They are all deprived from the querystring and I need that bit too.</p>
<p>My controller updates a collection of URLs in my <code>BreadCrumb</code> component. Therefore it needs the request URL. How do you suggest I take on this problem?</p>
|
[
{
"answer_id": 261411,
"author": "Roger Lipscombe",
"author_id": 8446,
"author_profile": "https://Stackoverflow.com/users/8446",
"pm_score": 2,
"selected": false,
"text": "HttpContext.Current.Request\n"
},
{
"answer_id": 261818,
"author": "Jeff Sheldon",
"author_id": 33910,
"author_profile": "https://Stackoverflow.com/users/33910",
"pm_score": 5,
"selected": false,
"text": "HttpContext.Current.Request.RawUrl\nHttpContext.Current.Request.QueryString\n"
},
{
"answer_id": 263872,
"author": "Haacked",
"author_id": 598,
"author_profile": "https://Stackoverflow.com/users/598",
"pm_score": 0,
"selected": false,
"text": "Request.RawUrl"
},
{
"answer_id": 6557831,
"author": "Serhiy",
"author_id": 246719,
"author_profile": "https://Stackoverflow.com/users/246719",
"pm_score": 7,
"selected": true,
"text": "Request.Url.PathAndQuery"
},
{
"answer_id": 26827583,
"author": "Dino Liu",
"author_id": 3986569,
"author_profile": "https://Stackoverflow.com/users/3986569",
"pm_score": 2,
"selected": false,
"text": "Request.RawUrl\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
261,348
|
<p>I want to share an object between my servlets and my webservice (JAX-WS) by storing it as a servlet context attribute. But how can I retrieve the servlet context from a web service?</p>
|
[
{
"answer_id": 261349,
"author": "Jens Bannmann",
"author_id": 7641,
"author_profile": "https://Stackoverflow.com/users/7641",
"pm_score": 7,
"selected": true,
"text": "import javax.annotation.Resource;\nimport javax.servlet.ServletContext;\nimport javax.xml.ws.WebServiceContext;\nimport javax.xml.ws.handler.MessageContext;\n\n...\n\n@Resource\nprivate WebServiceContext context;\n ServletContext servletContext =\n (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);\n"
},
{
"answer_id": 35776676,
"author": "Mirko Cianfarani",
"author_id": 1461682,
"author_profile": "https://Stackoverflow.com/users/1461682",
"pm_score": 2,
"selected": false,
"text": " <dependency>\n <groupId>javax.servlet</groupId>\n <artifactId>servlet-api</artifactId>\n <version>2.4</version>\n <scope>provided</scope>\n </dependency>\n @WebService(endpointInterface = \"choice.HelloWorld\")\npublic class HelloWorldImpl implements HelloWorld {\n @Resource\n private WebServiceContext context;\n public String sayHi(String text) {\n HttpServletRequest request =(HttpServletRequest) context.getMessageContext().get(MessageContext.SERVLET_REQUEST);\n System.out.println(request.getContextPath());\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7641/"
] |
261,351
|
<p>I have a web page <code>x.php</code> (in a password protected area of my web site) which has a form and a button which uses the <code>POST</code> method to send the form data and opens <code>x.php#abc</code>. This works pretty well.</p>
<p>However, if the users decides to navigate back in Internet Explorer 7, all the fields in the original <code>x.php</code> get cleared and everything must be typed in again. I cannot save the posted information in a session and I am trying to understand how I can get IE7 to behave the way I want.</p>
<p>I've searched the web and found answers which suggest that the HTTP header should contain explicit caching information. Currently, I've tried this :</p>
<pre><code>session_name("FOO");
session_start();
header("Pragma: public");
header("Expires: Fri, 7 Nov 2008 23:00:00 GMT");
header("Cache-Control: public, max-age=3600, must-revalidate");
header("Last-Modified: Thu, 30 Oct 2008 17:00:00 GMT");
</code></pre>
<p>and variations thereof. Without success. Looking at the returned headers with a tool such as <a href="http://www.wireshark.org/" rel="noreferrer">WireShark</a> shows me that Apache is indeed honouring my headers.</p>
<p>So my question is: what am I doing wrong?</p>
|
[
{
"answer_id": 261403,
"author": "mkoeller",
"author_id": 33433,
"author_profile": "https://Stackoverflow.com/users/33433",
"pm_score": 2,
"selected": false,
"text": "onload onload"
},
{
"answer_id": 261494,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/javascript\">//<!-- <![CDATA[\n(function(){\n if( document.location.hash === \"\" )\n {\n document.location.hash=\"_\";\n }\n else\n {\n var l = document.location;\n var myurl = ( l.protocol + \"//\" + l.hostname + l.pathname + l.search); \n document.location = myurl;\n }\n})();\n//]]> --></script>\n #_"
},
{
"answer_id": 262062,
"author": "Pierre Arnaud",
"author_id": 4597,
"author_profile": "https://Stackoverflow.com/users/4597",
"pm_score": 2,
"selected": false,
"text": "http://foo.com/page http://foo.com/page.htm Cache-Control Expires function emitConditionalGet($timestamp)\n{\n // See also http://www.mnot.net/cache_docs/\n // and code sample http://simonwillison.net/2003/Apr/23/conditionalGet/\n\n $gmdate_exp = gmdate('D, d M Y H:i:s', time() + 1) . ' GMT';\n $last_modified = gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';\n $etag = '\"'.md5($last_modified).'\"';\n\n // If the client provided any of the if-modified-since or if-none-match\n // infos, take them into account:\n\n $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])\n ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false;\n $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH'])\n ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false;\n\n if (!$if_modified_since && !$if_none_match)\n {\n return; // the client does not cache anything\n }\n\n if ($if_none_match && $if_none_match != $etag)\n {\n return; // ETag mismatch: the page changed!\n }\n if ($if_modified_since && $if_modified_since != $last_modified)\n {\n return; // if-modified-since mismatch: the page changed!\n }\n\n // Nothing changed since last time client visited this page.\n\n header(\"HTTP/1.0 304 Not Modified\");\n header(\"Last-Modified: $last_modified\");\n header(\"ETag: $etag\");\n header(\"Cache-Control: private, max-age=1, must-revalidate\");\n header(\"Expires: $gmdate_exp\");\n header(\"Pragma: private, cache\");\n header(\"Content-Type: text/html; charset=utf-8\");\n exit;\n}\n\nfunction emitDefaultHeaders($timestamp)\n{\n $gmdate_exp = gmdate('D, d M Y H:i:s', time() + 1) . ' GMT';\n $last_modified = gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';\n $etag = '\"'.md5($last_modified).'\"';\n\n header(\"Last-Modified: $last_modified\");\n header(\"ETag: $etag\");\n header(\"Cache-Control: private, max-age=1, must-revalidate\");\n header(\"Expires: $gmdate_exp\");\n header(\"Pragma: private, cache\");\n header(\"Content-Type: text/html; charset=utf-8\");\n}\n\nfunction getTimestamp()\n{\n // Find out when this page's contents last changed; in a static system,\n // this would be the file time of the backing HTML/PHP page. Add your\n // own logic here:\n return filemtime($SCRIPT_FILENAME);\n}\n\n// ...\n\n$timestamp = getTimestamp();\nemitConditionalGet($timestamp);\nemitDefaultHeaders($timestamp); //previously, this variable was mistyped as \"$timestaml\"\n"
},
{
"answer_id": 56979332,
"author": "MeSo2",
"author_id": 6500909,
"author_profile": "https://Stackoverflow.com/users/6500909",
"pm_score": 2,
"selected": false,
"text": "<table>\n <form>\n <tr>\n <td><input type=\"number\" value=\"0\"></td>\n </tr>\n </form>\n</table>\n <form> <table> <tr> <form>\n<table>\n <tr>\n <td><input type=\"number\" value=\"0\"></td>\n </tr>\n</table>\n</form>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4597/"
] |
261,362
|
<p>I've got an HTML "select" element which I'm updating dynamically with code something like this:</p>
<pre><code>var selector = document.getElementById('selectorId');
for (var i = 0; i < data.length; ++i)
{
var opt = document.createElement('option');
opt.value = data[i].id;
opt.text = data[i].name;
selector.appendChild(opt);
}
</code></pre>
<p>Works fine in Firefox, but IE7 doesn't resize the list box to fit the new data. If the list box is initially empty (which it is in my case), you can hardly see any of the options I've added. Is there a better way to do this? Or a way to patch it up to work in IE?</p>
|
[
{
"answer_id": 261409,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": true,
"text": "innerHTML text var selector = document.getElementById('selectorId'); \nfor (var i = 0; i < data.length; ++i)\n{\n var opt = document.createElement('option');\n opt.value = data[i].id;\n opt.innerHTML = data[i].name;\n selector.appendChild(opt);\n}\n"
},
{
"answer_id": 261469,
"author": "Marko Dumic",
"author_id": 5817,
"author_profile": "https://Stackoverflow.com/users/5817",
"pm_score": 2,
"selected": false,
"text": "var selector = document.getElementById('selectorId'); \nfor (var i = 0; i < data.length; ++i) {\n selector.options[selector.options.length] = new Option(data[i].name, data[i].id);\n}\n"
},
{
"answer_id": 9234333,
"author": "David Gimeno i Ayuso",
"author_id": 1202887,
"author_profile": "https://Stackoverflow.com/users/1202887",
"pm_score": 2,
"selected": false,
"text": "select.style.width auto auto select.style.width \"\" select.style.width auto select"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3974/"
] |
261,368
|
<p>How do you calculate the number of <code><td></code> elements in a particular <code><tr></code>?</p>
<p>I didn't specify id or name to access directly, we have to use the <code>document.getElementsByTagName</code> concept.</p>
|
[
{
"answer_id": 261383,
"author": "Aron Rotteveel",
"author_id": 11568,
"author_profile": "https://Stackoverflow.com/users/11568",
"pm_score": 4,
"selected": true,
"text": "var rowIndex = 0; // rowindex, in this case the first row of your table\nvar table = document.getElementById('mytable'); // table to perform search on\nvar row = table.getElementsByTagName('tr')[rowIndex];\nvar cells = row.getElementsByTagName('td');\nvar cellCount = cells.length;\nalert(cellCount); // will return the number of cells in the row\n"
},
{
"answer_id": 261391,
"author": "Davide Gualano",
"author_id": 28582,
"author_profile": "https://Stackoverflow.com/users/28582",
"pm_score": 1,
"selected": false,
"text": "var tot = 0;\nvar trs = document.getElementsByTagName(\"tr\");\nfor (i = 0; i < trs.length; i++) {\n tds = trs[i].getElementsByTagName(\"td\");\n tot += tds.length;\n}\n tot"
},
{
"answer_id": 261397,
"author": "Ian Oxley",
"author_id": 1904,
"author_profile": "https://Stackoverflow.com/users/1904",
"pm_score": 2,
"selected": false,
"text": "var totals = new Array();\n\nvar tbl = document.getElementById('yourTableId');\nvar rows = tbl.getElementsByTagName('tr');\nfor (var i = 0; i < rows.length; i++) {\n totals.push(rows[i].getElementsByTagName('td').length;\n}\n\n...\n\n// total cells in row 1\ntotals[0];\n// in row 2\ntotals[1];\n// etc.\n"
},
{
"answer_id": 261399,
"author": "philnash",
"author_id": 28376,
"author_profile": "https://Stackoverflow.com/users/28376",
"pm_score": 1,
"selected": false,
"text": "var trs = document.getElementsByTagName('tr');\nfor(var i=0;i<trs.length;i++){\n alert(\"Number of tds in row '+(i+1)+' is ' + tr[i].getElementsByTagName('td').length);\n}\n"
},
{
"answer_id": 261459,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 1,
"selected": false,
"text": "$(\"table tr:eq(0) > td\").length\n $(\"#mytableid tr\").eq(0).children(\"td\").length \n"
},
{
"answer_id": 261532,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 1,
"selected": false,
"text": "tr.cells.length\n"
},
{
"answer_id": 262698,
"author": "user34280",
"author_id": 34280,
"author_profile": "https://Stackoverflow.com/users/34280",
"pm_score": 2,
"selected": false,
"text": "table.rows[r].cells[c]\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,374
|
<p>What is the most efficient way to enumerate every cell in every sheet in a workbook?</p>
<p>The method below seems to work reasonably for a workbook with ~130,000 cells. On my machine it took ~26 seconds to open the file and ~5 seconds to enumerate the cells . However I'm no Excel expert and wanted to validate this code snippet with the wider community.</p>
<pre><code>DateTime timer = DateTime.Now;
Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();
try
{
exampleFile = new FileInfo(Path.Combine(System.Environment.CurrentDirectory, "Large.xlsx"));
excelApplication.Workbooks.Open(exampleFile.FullName, false, false, missing, missing, missing, true, missing, missing, true, missing, missing, missing, missing, missing);
Console.WriteLine(string.Format("Took {0} seconds to open file", (DateTime.Now - timer).Seconds.ToString()));
timer = DateTime.Now;
foreach(Workbook workbook in excelApplication.Workbooks)
{
foreach(Worksheet sheet in workbook.Sheets)
{
int i = 0, iRowMax, iColMax;
string data = String.Empty;
Object[,] rangeData = (System.Object[,]) sheet.UsedRange.Cells.get_Value(missing);
if (rangeData != null)
{
iRowMax = rangeData.GetUpperBound(0);
iColMax = rangeData.GetUpperBound(1);
for (int iRow = 1; iRow < iRowMax; iRow++)
{
for(int iCol = 1; iCol < iColMax; iCol++)
{
data = rangeData[iRow, iCol] != null ? rangeData[iRow, iCol].ToString() : string.Empty;
if (i % 100 == 0)
{
Console.WriteLine(String.Format("Processed {0} cells.", i));
}
i++;
}
}
}
}
workbook.Close(false, missing, missing);
}
Console.WriteLine(string.Format("Took {0} seconds to parse file", (DateTime.Now - timer).Seconds.ToString()));
}
finally
{
excelApplication.Workbooks.Close();
excelApplication.Quit();
}
</code></pre>
<p><strong>Edit</strong>:</p>
<p>Worth stating that I want to use PIA and interop in order to access properties of excel workbooks that are not exposed by API's that work directly with the Excel file.</p>
|
[
{
"answer_id": 261412,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 3,
"selected": true,
"text": "Worksheet.UsedRange get_Value() Value Value2 object[,] data = rangeData[iRow, iCol] != null ? rangeData[iRow, iCol].ToString() : string.Empty;\n data = Convert.ToString(rangeData[iRow, iCol]) ?? string.Empty;\n null"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5182/"
] |
261,375
|
<p>No doubt I'm missing something really simple here but I just can't see the problem with this query which is producing the following error:</p>
<pre><code>SQL query:
INSERT INTO ads(
ad_id, author, ad_date, category, title,
description, condition, price, fullname,
telephone, email, status, photo, photothumb
)
VALUES (
NULL , 'justal', '1225790938', 'Windsurf Boards',
'test', 'test', 'Excellent', '12', 'test',
'test', 'test', '', '', ''
);
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version
for the right syntax to use near ''ad_id', 'author',
'ad_date', 'category', 'title', 'description',
'condition', '' at line 1
</code></pre>
<p>Can someone with a fresh pair of eyes spot the problem?</p>
<p>Thanks,
Al. </p>
|
[
{
"answer_id": 261380,
"author": "Alexander Kojevnikov",
"author_id": 712,
"author_profile": "https://Stackoverflow.com/users/712",
"pm_score": 3,
"selected": true,
"text": "INSERT INTO ads( `ad_id`, `author`, `ad_date`, `category`, `title`, `description`, `condition`, `price`, `fullname`, `telephone`, `email`, `status`, `photo`, `photothumb` )\nVALUES (\nNULL , 'justal', '1225790938', 'Windsurf Boards', 'test', 'test', 'Excellent', '12', 'test', 'test', 'test', '', '', ''\n);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34019/"
] |
261,377
|
<p>I apologize in advance for the long post...</p>
<p>I used to be able to build our VC++ solutions (we're on VS 2008) when we listed the STLPort include and library directories under VS Menu > Tools > Options > VC++ Directories > Directories for Include and Library files. However, we wanted to transition to a build process that totally relies on .vcproj and .sln files. These can be checked into source control unlike VS Options which have to be configured on each development PC separately. We handled the transition for most libraries by adding the Include directories to each Project's Property Pages > Configuration Properties > C/C++ > General > Additional Include Directories, and Library directories to Linker > General > Additional Library Directories.</p>
<p>Unfortunately, this approach doesn't work for STLPort. We get LNK2019 and LNK2001 errors during linking:</p>
<pre><code>Error 1 error LNK2019: unresolved external symbol "public: virtual bool __thiscall MyClass::myFunction(class stlp_std::basic_istream<char,class stlp_std::char_traits<char> > &,class MyOtherClass &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > &)const " (?myFunction@MyClass@@UBE_NAAV?$basic_istream@DV?$char_traits@D@stlp_std@@@stlp_std@@AAVSbprobScenarioData@@AAV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@3@@Z) referenced in function _main MyLibrary.obj
Error 5 error LNK2001: unresolved external symbol "public: static void __cdecl MyClass::myFunction(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,long,enum MyClass::MessageType,int,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &)" (?myFunction@MyClass@@SAXABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@000JW4MessageType@1@H0@Z) MyLibrary.lib
</code></pre>
<p>This happens while linking and executable project to dependencies which are library projects. Curiously, this does not happen while linking the library projects themselves. Any ideas?</p>
|
[
{
"answer_id": 687185,
"author": "Aaron",
"author_id": 28950,
"author_profile": "https://Stackoverflow.com/users/28950",
"pm_score": 3,
"selected": false,
"text": "Error 1 error LNK2019: unresolved external symbol \"public: unsigned char __cdecl TiXmlComment::Accept(bool,class TiXmlVisitor *) \" (?Accept@TiXmlComment@@ZBE_NPAVTiXmlVisitor@@@Z) referenced in function _main MyLibrary.obj \n \n>dumpbin /linkermember tinyxml.lib\nMicrosoft (R) COFF/PE Dumper Version 8.00.50727.762\nCopyright (C) Microsoft Corporation. All rights reserved.\n\n\nDump of file tinyxml.lib\n\nFile Type: LIBRARY\n\nArchive member name at 8: /\n4992E7BC time/date Wed Feb 11 08:59:08 2009\n uid\n gid\n 0 mode\n B402 size\ncorrect header end\n\n 859 public symbols\n\n 16292 ??$_Allocate@D@std@@YAPADIPAD@Z\n 16292 ??$_Char_traits_cat@U?$char_traits@D@std@@@std@@YA?AU_Secure_char_traits_tag@0@XZ\n 16292 ??$copy_s@U?$char_traits@D@std@@@_Traits_helper@std@@YAPADPADIPBDI@Z\n 16292 ??$copy_s@U?$char_traits@D@std@@@_Traits_helper@std@@YAPADPADIPBDIU_Secure_char_traits_tag@1@@Z\n 16292 ??$move_s@U?$char_traits@D@std@@@_Traits_helper@std@@YAPADPADIPBDI@Z\n 16292 ??$move_s@U?$char_traits@D@std@@@_Traits_helper@std@@YAPADPADIPBDIU_Secure_char_traits_tag@1@@Z\n 16292 ??$use_facet@V?$ctype@D@std@@@std@@YAABV?$ctype@D@0@ABVlocale@0@@Z\n 16292 ??0?$_String_val@DV?$allocator@D@std@@@std@@IAE@V?$allocator@D@1@@Z\n 16292 ??0?$_String_val@DV?$allocator@D@std@@@std@@QAE@ABV01@@Z\n\n \n>dumpbin /linkermember tinyxml.lib | grep Accept\n 529AE ?Accept@TiXmlComment@@UBE_NPAVTiXmlVisitor@@@Z\n 529AE ?Accept@TiXmlDeclaration@@UBE_NPAVTiXmlVisitor@@@Z\n 529AE ?Accept@TiXmlDocument@@UBE_NPAVTiXmlVisitor@@@Z\n 529AE ?Accept@TiXmlElement@@UBE_NPAVTiXmlVisitor@@@Z\n 529AE ?Accept@TiXmlText@@UBE_NPAVTiXmlVisitor@@@Z\n 529AE ?Accept@TiXmlUnknown@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlComment@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlDeclaration@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlDocument@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlElement@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlText@@UBE_NPAVTiXmlVisitor@@@Z\n 3 ?Accept@TiXmlUnknown@@UBE_NPAVTiXmlVisitor@@@Z\n \n>undname ?Accept@TiXmlComment@@UBE_NPAVTiXmlVisitor@@@Z\nMicrosoft (R) C++ Name Undecorator\nCopyright (C) Microsoft Corporation. All rights reserved.\n\nUndecoration of :- \"?Accept@TiXmlComment@@UBE_NPAVTiXmlVisitor@@@Z\"\nis :- \"public: virtual bool __thiscall TiXmlComment::Accept(class TiXmlVisitor *)const \"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15515/"
] |
261,386
|
<p>I'm new to Flex, and I'm trying to write a simple application. I have a file with an image and I want to display this image on a Graphics. How do I do this? I tried [Embed]-ding it and adding as a child to the component owning the Graphics', but I'm getting a "Type Coercion failed: cannot convert ... to mx.core.IUIComponent" error.</p>
|
[
{
"answer_id": 261768,
"author": "hasseg",
"author_id": 4111,
"author_profile": "https://Stackoverflow.com/users/4111",
"pm_score": 4,
"selected": true,
"text": "source Class [Bindable]\n[Embed(source=\"assets/image.png\")]\nprivate var MyGfx:Class;\n\nmyImage.source = MyGfx;\n Graphics [Bindable]\n[Embed(source=\"assets/image.png\")]\nprivate var MyGfx:Class;\n\nvar myBitmap:BitmapData = new MyGfx().bitmapData;\nmyGraphics.beginBitmapFill(myBitmap);\nmyGraphics.endFill();\n"
},
{
"answer_id": 5192958,
"author": "Levon",
"author_id": 58038,
"author_profile": "https://Stackoverflow.com/users/58038",
"pm_score": 3,
"selected": false,
"text": "drawRect() [Embed(source='assets/land-field.png')] \nprivate var ImgField:Class; \nprivate var field:BitmapData = new ImgField().bitmapData;\n\npublic static function drawImage(g:Graphics, image:BitmapData, x:int, y:int):void {\n var mtx:Matrix = new Matrix();\n mtx.translate(x, y);\n g.beginBitmapFill(image, mtx, false, false);\n g.drawRect(x, y, image.width, image.height);\n g.endFill();\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6533/"
] |
261,387
|
<p>I've noticed in many places in Java (C# included), that many "getter" methods are prefixed with "get" while many other aren't. I never noticed any kind of pattern Sun seems to be following. What are some guidelines or rules for using "get" in getter method names?</p>
|
[
{
"answer_id": 261410,
"author": "David Arno",
"author_id": 7122,
"author_profile": "https://Stackoverflow.com/users/7122",
"pm_score": 2,
"selected": false,
"text": "obj.setX(10);\n obj.X = 10;\n"
},
{
"answer_id": 261425,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 1,
"selected": false,
"text": "get String.length() Buffer.capacity()"
},
{
"answer_id": 261435,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 0,
"selected": false,
"text": "value = [obj attr];\n\n[obj setAttr:value];\n\n[obj getAttr:&value];\n"
},
{
"answer_id": 261481,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 4,
"selected": true,
"text": "public Person CreatePerson(string firstName, string lastName) {...}\n public Person GetPerson(string firstName, string lastName) {...}\n"
},
{
"answer_id": 261504,
"author": "Serxipc",
"author_id": 34009,
"author_profile": "https://Stackoverflow.com/users/34009",
"pm_score": 2,
"selected": false,
"text": "public class User{\n private String name;\n public String getName(){ return name;}\n public void setName(String name){ this.name = name; }\n}\n user.name"
},
{
"answer_id": 377917,
"author": "Yang Meyer",
"author_id": 45018,
"author_profile": "https://Stackoverflow.com/users/45018",
"pm_score": 1,
"selected": false,
"text": "bool isEnabled() { return enabled; }"
},
{
"answer_id": 10568713,
"author": "mikera",
"author_id": 214010,
"author_profile": "https://Stackoverflow.com/users/214010",
"pm_score": 3,
"selected": false,
"text": "get set get String.length() ArrayList.size()"
},
{
"answer_id": 68985870,
"author": "Michal M",
"author_id": 1050787,
"author_profile": "https://Stackoverflow.com/users/1050787",
"pm_score": 0,
"selected": false,
"text": "* getX setX"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30323/"
] |
261,405
|
<p>There are two databases in SQL Server 2005: One called "A" and another one called "A_2".
"A" is a variable name to be entered by the user, the "_2" prefix for the second database is always known. (So databases could be "MyDB" and "MyDB_2", etc)<br><br>
How to access the other database from within a stored procedure without knowing the actual name and without using the 'exec' statement?</p>
|
[
{
"answer_id": 1024290,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "if object_id('view_Table1') is not null\n drop view view_Table1\n\ndim @cmd nvarchar(max)\n\nset @cmd = 'create view view_Table1 as select * from ' + @DbName + '.dbo.Table1'\n\nexec sp_executesql @cmd\n\nselect WhateverColumn from view_Table1\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34022/"
] |
261,407
|
<p>Currently I have a structure like this:</p>
<pre><code>A
|
+--B
|
+--C
</code></pre>
<p>It's mapped with one table per subclass using joined tables. For historic reasons I also use a discriminator, so the current situation is as described in <a href="http://www.hibernate.org/hib_docs/v3/reference/en-US/html/inheritance.html#inheritance-tablepersubclass-discriminator" rel="noreferrer">Section 9.1.3 of the Hibernate manual</a>.</p>
<p><strong>Question:</strong> How do I extend the mapping for a structure like this:</p>
<pre><code>A
|
+--B
| |
| D
|
+--C
</code></pre>
<p>Can I <code><subclass></code> a <code><subclass></code> in the hibernate mapping? What <code><key></code>s do I need?</p>
|
[
{
"answer_id": 262654,
"author": "shyam",
"author_id": 7616,
"author_profile": "https://Stackoverflow.com/users/7616",
"pm_score": 4,
"selected": true,
"text": "<hibernate-mapping>\n <class name=\"A\" table=\"A\">\n <id name=\"id\" type=\"long\" column=\"a_id\">\n <generator class=\"native\"/>\n </id>\n <discriminator column=\"discriminator_col\" type=\"string\"/>\n <property name=\"\" type=\"\"/>\n <!-- ... -->\n </class>\n <subclass name=\"B\" extends=\"A\" discriminator-value=\"B\">\n <!-- ... -->\n </subclass>\n <subclass name=\"D\" extends=\"B\" discriminator-value=\"D\">\n <!-- ... -->\n </subclass>\n <subclass name=\"C\" extends=\"A\" discriminator-value=\"C\">\n <!-- ... -->\n </subclass>\n</hibernate-mapping>\n"
},
{
"answer_id": 47792576,
"author": "KayV",
"author_id": 3956731,
"author_profile": "https://Stackoverflow.com/users/3956731",
"pm_score": 0,
"selected": false,
"text": "@Entity\n@Inheritance(strategy = InheritanceType.JOINED)\n@DiscriminatorColumn(name=\"LoanType\",discriminatorType=\"String\")\n@Table(name = \"A\")\npublic class A implements Serializable{\n}\n\n@Entity\n@Table(name= \"B\")\n@PrimaryKeyJoinColumn(name = \"B_ID\", referencedColumnName =\"A_ID\")\npublic class B extends A{\n}\n\n\n@Entity\n@Table(name= \"C\")\n@PrimaryKeyJoinColumn(name = \"C_ID\", referencedColumnName = \"B_ID\")\npublic class C extends B{}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29549/"
] |
261,419
|
<p>It's been a while since I last coded arm assembler and I'm a little rusty on the details. If I call a C function from arm, I only have to worry about saving r0-r3 and lr, right?</p>
<p>If the C function uses any other registers, is it responsible for saving those on the stack and restoring them? In other words, the compiler would generate code to do this for C functions. </p>
<p>For example if I use r10 in an assembler function, I don't have to push its value on the stack, or to memory, and pop/restore it after a C call, do I?</p>
<p>This is for arm-eabi-gcc 4.3.0.</p>
|
[
{
"answer_id": 18215803,
"author": "Sven",
"author_id": 1080389,
"author_profile": "https://Stackoverflow.com/users/1080389",
"pm_score": 3,
"selected": false,
"text": "void foo() {\n asm volatile ( \"nop\" : : : \"r0\", \"r1\", \"r2\", \"r3\", \"r4\", \"r5\", \"r6\", \"r7\", \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"r14\");\n}\n arm-eabi-gcc-4.7 -O2 -S -o - foo.c -mcpu=arm7tdmi foo:\n stmfd sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}\n nop\n ldmfd sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}\n bx lr\n -mcpu=arm7tdmi -mno-thumb-interwork -mcpu=cortex-m4 -mthumb foo:\n stmfd sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}\n nop\n ldmfd sp!, {r4, r5, r6, r7, r8, r9, sl, fp, pc}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4596/"
] |
261,422
|
<p>Does anyone know how to tell VS(2008) where to save the obj folder when building the solution? We have it save the bin folder to another path in order to keep the source file folders small (ie. emailable), but can't find any way to tell it to do the same with obj...</p>
|
[
{
"answer_id": 261445,
"author": "Sören Kuklau",
"author_id": 1600,
"author_profile": "https://Stackoverflow.com/users/1600",
"pm_score": 7,
"selected": true,
"text": "BaseIntermediateOutputPath .csproj .vbproj obj obj"
},
{
"answer_id": 3687173,
"author": "Dominik Antal",
"author_id": 342862,
"author_profile": "https://Stackoverflow.com/users/342862",
"pm_score": 5,
"selected": false,
"text": "<IntermediateOutputPath>..\\Whatever\\obj\\</IntermediateOutputPath>\n rd \"$(ProjectDir)obj\" /S /Q\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6091/"
] |
261,423
|
<p>How can we handel key pressed event in asp.net</p>
|
[
{
"answer_id": 261457,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 1,
"selected": false,
"text": "Enter <asp:TextBox \n runat=\"server\" \n onKeyPress=\"if (event.keyCode == 13) return false;\" />\n"
},
{
"answer_id": 261460,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 1,
"selected": false,
"text": "myTextBox.Attributes[\"OnKeyPress\"] = \"javascript function call;\";\n <asp:TextBox runat=\"server\" ID=\"ole\" ontextchanged=\"ole_TextChanged\" AutoPostBack=\"true\"></asp:TextBox>\n\nprotected void ole_TextChanged(object sender, EventArgs e)\n{\n // Do stuff\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,424
|
<p>I have a dialog where each entry in a JTree has its corresponding options in a different panel, which is updated when the selection changes. If options for one of the entries is set to an invalid state, when the user attempts to change to a different entry in the tree, I want there to be an error dialog and have the selection not change.</p>
<p>I tried doing this with a valueChangeListener on the JTree, but currently then have to have the valueChanged method call "setSelectionRow" to the old selection if there is an error. So that I don't get a StackOverflow, I set a boolean "isError" to true before I do this so that I can ignore the new valueChanged event. Somehow I have the gut feeling this is not the best solution. ;-)</p>
<p>How would I go about it instead? Is there a good design pattern for situations like this?</p>
|
[
{
"answer_id": 574109,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": " navTree.addTreeSelectionListener(new TreeSelectionListener() {\n\n boolean treeSelectionListenerEnabled = true;\n\n public void valueChanged(TreeSelectionEvent e) {\n if (treeSelectionListenerEnabled) {\n if (ok to change selection...) {\n ...\n } else {\n TreePath treePath = e.getOldLeadSelectionPath();\n treeSelectionListenerEnabled = false;\n try {\n // prevent from leaving the last visited node\n navTree.setSelectionPath(treePath);\n } finally {\n treeSelectionListenerEnabled = true;\n }\n }\n }\n }\n });\n private class VetoableTreeSelectionModel extends DefaultTreeSelectionModel {\n public void setSelectionPath(TreePath path){\n if (allow selection change?) {\n super.setSelectionPath(path);\n }\n }\n}\n{\n navTree.setSelectionModel(new VetoableTreeSelectionModel());\n}\n"
},
{
"answer_id": 611622,
"author": "lexicalscope",
"author_id": 72810,
"author_profile": "https://Stackoverflow.com/users/72810",
"pm_score": 0,
"selected": false,
"text": "public class VetoableTreeSelectionModel implements TreeSelectionModel\n{\n private final ListenerList<VetoableTreeSelectionListener> m_vetoableTreeSelectionListeners = new ListenerList<VetoableTreeSelectionListener>();\n\n private final DefaultTreeSelectionModel m_treeSelectionModel = new DefaultTreeSelectionModel();\n\n /**\n * {@inheritDoc}\n */\n public void addTreeSelectionListener(final TreeSelectionListener listener)\n {\n m_treeSelectionModel.addTreeSelectionListener(listener);\n }\n\n /**\n * {@inheritDoc}\n */\n public void removeTreeSelectionListener(final TreeSelectionListener listener)\n {\n m_treeSelectionModel.removeTreeSelectionListener(listener);\n }\n\n /**\n * Add a vetoable tree selection listener\n *\n * @param listener the listener\n */\n public void addVetoableTreeSelectionListener(final VetoableTreeSelectionListener listener)\n {\n m_vetoableTreeSelectionListeners.addListener(listener);\n }\n\n /**\n * Remove a vetoable tree selection listener\n *\n * @param listener the listener\n */\n public void removeVetoableTreeSelectionListener(final VetoableTreeSelectionListener listener)\n {\n m_vetoableTreeSelectionListeners.removeListener(listener);\n }\n\n /**\n * {@inheritDoc}\n */\n public void addPropertyChangeListener(final PropertyChangeListener listener)\n {\n m_treeSelectionModel.addPropertyChangeListener(listener);\n }\n\n /**\n * {@inheritDoc}\n */\n public void removePropertyChangeListener(final PropertyChangeListener listener)\n {\n m_treeSelectionModel.removePropertyChangeListener(listener);\n }\n\n /**\n * {@inheritDoc}\n */\n public void addSelectionPath(final TreePath path)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToAddSelectionPath(path);\n }});\n\n m_treeSelectionModel.addSelectionPath(path);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void addSelectionPaths(final TreePath[] paths)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToAddSelectionPaths(paths);\n }});\n\n m_treeSelectionModel.addSelectionPaths(paths);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void clearSelection()\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToClearSelection();\n }});\n\n m_treeSelectionModel.clearSelection();\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public TreePath getLeadSelectionPath()\n {\n return m_treeSelectionModel.getLeadSelectionPath();\n }\n\n /**\n * {@inheritDoc}\n */\n public int getLeadSelectionRow()\n {\n return m_treeSelectionModel.getLeadSelectionRow();\n }\n\n /**\n * {@inheritDoc}\n */\n public int getMaxSelectionRow()\n {\n return m_treeSelectionModel.getMaxSelectionRow();\n }\n\n /**\n * {@inheritDoc}\n */\n public int getMinSelectionRow()\n {\n return m_treeSelectionModel.getMinSelectionRow();\n }\n\n /**\n * {@inheritDoc}\n */\n public RowMapper getRowMapper()\n {\n return m_treeSelectionModel.getRowMapper();\n }\n\n /**\n * {@inheritDoc}\n */\n public int getSelectionCount()\n {\n return m_treeSelectionModel.getSelectionCount();\n }\n\n public int getSelectionMode()\n {\n return m_treeSelectionModel.getSelectionMode();\n }\n\n /**\n * {@inheritDoc}\n */\n public TreePath getSelectionPath()\n {\n return m_treeSelectionModel.getSelectionPath();\n }\n\n /**\n * {@inheritDoc}\n */\n public TreePath[] getSelectionPaths()\n {\n return m_treeSelectionModel.getSelectionPaths();\n }\n\n /**\n * {@inheritDoc}\n */\n public int[] getSelectionRows()\n {\n return m_treeSelectionModel.getSelectionRows();\n }\n\n /**\n * {@inheritDoc}\n */\n public boolean isPathSelected(final TreePath path)\n {\n return m_treeSelectionModel.isPathSelected(path);\n }\n\n /**\n * {@inheritDoc}\n */\n public boolean isRowSelected(final int row)\n {\n return m_treeSelectionModel.isRowSelected(row);\n }\n\n /**\n * {@inheritDoc}\n */\n public boolean isSelectionEmpty()\n {\n return m_treeSelectionModel.isSelectionEmpty();\n }\n\n /**\n * {@inheritDoc}\n */\n public void removeSelectionPath(final TreePath path)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutRemoveSelectionPath(path);\n }});\n\n m_treeSelectionModel.removeSelectionPath(path);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void removeSelectionPaths(final TreePath[] paths)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutRemoveSelectionPaths(paths);\n }});\n\n m_treeSelectionModel.removeSelectionPaths(paths);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void resetRowSelection()\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToResetRowSelection();\n }});\n\n m_treeSelectionModel.resetRowSelection();\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void setRowMapper(final RowMapper newMapper)\n {\n m_treeSelectionModel.setRowMapper(newMapper);\n }\n\n /**\n * {@inheritDoc}\n */\n public void setSelectionMode(final int mode)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToSetSelectionMode(mode);\n }});\n\n m_treeSelectionModel.setSelectionMode(mode);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void setSelectionPath(final TreePath path)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToSetSelectionPath(path);\n }});\n\n m_treeSelectionModel.setSelectionPath(path);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n public void setSelectionPaths(final TreePath[] paths)\n {\n try\n {\n m_vetoableTreeSelectionListeners.fireVetoableEvent(new VetoableAction<VetoableTreeSelectionListener>() {\n public void fireEvent(final VetoableTreeSelectionListener listener) throws EventVetoedException\n {\n listener.aboutToSetSelectionPaths(paths);\n }});\n\n m_treeSelectionModel.setSelectionPaths(paths);\n }\n catch (final EventVetoedException e)\n {\n return;\n }\n }\n\n /**\n * {@inheritDoc}\n */\n @Override\n public String toString()\n {\n return m_treeSelectionModel.toString();\n }\n public interface VetoableTreeSelectionListener\n{\n /**\n * About to add a path to the selection\n *\n * @param path the path to add\n *\n * @throws EventVetoedException\n */\n void aboutToAddSelectionPath(TreePath path) throws EventVetoedException;\n\n /**\n * About to add paths to the selection\n *\n * @param paths the paths to add\n *\n * @throws EventVetoedException\n */\n void aboutToAddSelectionPaths(TreePath[] paths) throws EventVetoedException;\n\n /**\n * About to clear selection\n *\n * @throws EventVetoedException\n */\n void aboutToClearSelection() throws EventVetoedException;\n\n /**\n * About to remove a selection path\n *\n * @param path the path\n *\n * @throws EventVetoedException\n */\n void aboutRemoveSelectionPath(TreePath path) throws EventVetoedException;\n\n /**\n * About to remove multiple selection paths\n *\n * @param paths the paths\n *\n * @throws EventVetoedException\n */\n void aboutRemoveSelectionPaths(TreePath[] paths) throws EventVetoedException;\n\n /**\n * About to reset the row selection\n *\n * @throws EventVetoedException\n */\n void aboutToResetRowSelection() throws EventVetoedException;\n\n /**\n * About to set the selection mode\n *\n * @param mode the selection mode\n *\n * @throws EventVetoedException\n */\n void aboutToSetSelectionMode(int mode) throws EventVetoedException;\n\n /**\n * About to set the selection path\n *\n * @param path the path\n *\n * @throws EventVetoedException\n */\n void aboutToSetSelectionPath(TreePath path) throws EventVetoedException;\n\n /**\n * About to set the selection paths\n *\n * @param paths the paths\n *\n * @throws EventVetoedException\n */\n void aboutToSetSelectionPaths(TreePath[] paths) throws EventVetoedException;\n}\n"
},
{
"answer_id": 3157215,
"author": "tinca",
"author_id": 381020,
"author_profile": "https://Stackoverflow.com/users/381020",
"pm_score": 2,
"selected": false,
"text": "protected void processMouseEvent(MouseEvent e) {\n TreePath selPath = getPathForLocation(e.getX(), e.getY());\n try {\n fireVetoableChange(LEAD_SELECTION_PATH_PROPERTY, getLeadSelectionPath(), selPath);\n }\n catch (PropertyVetoException ex) {\n // OK, we do not want change to happen\n return;\n }\n\n super.processMouseEvent(e);\n}\n VetoableChangeListener vcl = new VetoableChangeListener() {\n\n public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {\n if ( evt.getPropertyName().equals(JTree.LEAD_SELECTION_PATH_PROPERTY) ) {\n try {\n <some code logic that has to be satisfied>\n } catch (InvalidInputException e) {\n throw new PropertyVetoException(\"\", evt);\n }\n\n }\n }\n };\n tree.addVetoableChangeListener(vcl);\n"
},
{
"answer_id": 8770623,
"author": "Stefan",
"author_id": 169267,
"author_profile": "https://Stackoverflow.com/users/169267",
"pm_score": 0,
"selected": false,
"text": "public class MainTreeSelectionModel extends DefaultTreeSelectionModel {\npublic void addSelectionPath(TreePath path) {\n if (path.getLastPathComponent() instanceof DisplayRepoOwner) {\n return;\n }\n super.addSelectionPath(path);\n}\npublic void addSelectionPaths(TreePath[] paths) {\n for (TreePath tp : paths) {\n if (tp.getLastPathComponent() instanceof DisplayRepoOwner) {\n return;\n }\n }\n super.addSelectionPaths(paths);\n}\npublic void setSelectionPath(TreePath path) {\n if (path.getLastPathComponent() instanceof DisplayRepoOwner) {\n return;\n }\n super.setSelectionPath(path);\n}\npublic void setSelectionPaths(TreePath[] paths) {\n for (TreePath tp : paths) {\n if (tp.getLastPathComponent() instanceof DisplayRepoOwner) {\n return;\n }\n }\n super.setSelectionPaths(paths);\n}\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261424",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6583/"
] |
261,428
|
<p>So far I've been using <code>public void run() {}</code> methods to execute my code in Java. When/why might one want to use <code>main()</code> or <code>init()</code> instead of <code>run()</code>?</p>
|
[
{
"answer_id": 261436,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "main() run() run()"
},
{
"answer_id": 261447,
"author": "Matthew Schinckel",
"author_id": 188,
"author_profile": "https://Stackoverflow.com/users/188",
"pm_score": 2,
"selected": false,
"text": "public static void main(String[] args) { ... }\n $ java Class\n public void run() { ... }\n"
},
{
"answer_id": 261478,
"author": "Jegschemesch",
"author_id": 1586,
"author_profile": "https://Stackoverflow.com/users/1586",
"pm_score": 7,
"selected": true,
"text": "main() init() init() run() run() main()"
},
{
"answer_id": 261602,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 4,
"selected": false,
"text": "main java main public static void main(String[]) java String public static void main(String args[])\n run Thread Runnable java Thread Runnable Thread.start() Thread start main public class MyRunnable implements Runnable\n{\n public void run()\n {\n System.out.println(\"Hello World!\");\n }\n\n public static void main(String[] args)\n {\n new Thread(new MyRunnable()).start();\n }\n}\n Thread Runnable init Applet.init init start init"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29182/"
] |
261,430
|
<p>I want to detect whether adobe reader is installed using VB6. Also if detected that it's not installed, what would be the best solution?</p>
|
[
{
"answer_id": 553400,
"author": "Rob Haupt",
"author_id": 65388,
"author_profile": "https://Stackoverflow.com/users/65388",
"pm_score": 0,
"selected": false,
"text": "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\\n File = <PDF FILE HERE>\nSet WshShell = CreateObject(\"WScript.Shell\")\nWshShell.Run Chr(34) & File & Chr(34)\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,431
|
<p>I have a variable </p>
<pre><code>unsigned char* data = MyFunction();
</code></pre>
<p>how to find the length of data?</p>
|
[
{
"answer_id": 261437,
"author": "kenny",
"author_id": 3225,
"author_profile": "https://Stackoverflow.com/users/3225",
"pm_score": 3,
"selected": false,
"text": "string length = strlen( char* );\n"
},
{
"answer_id": 261451,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 3,
"selected": false,
"text": "MyFunction int MyFunction(unsigned char* data, size_t* datalen)\n"
},
{
"answer_id": 261508,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "unsigned int size;\nunsigned char* data = MyFunction(&size);\n unsigned char* data;\nunsigned int size = MyFunction(data);\n"
},
{
"answer_id": 261514,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 2,
"selected": false,
"text": "int strlen(unsigned char *string_start)\n{\n /* Initialize a unsigned char pointer here */\n /* A loop that starts at string_start and\n * is increment by one until it's value is zero,\n *e.g. while(*s!=0) or just simply while(*s) */\n /* Return the difference of the incremented pointer and the original pointer */\n}\n"
},
{
"answer_id": 261877,
"author": "plan9assembler",
"author_id": 1710672,
"author_profile": "https://Stackoverflow.com/users/1710672",
"pm_score": -1,
"selected": false,
"text": "#include <stdio.h>\n#include <limits.h> \nint lengthOfU(unsigned char * str)\n{\n int i = 0;\n\n while(*(str++)){\n i++;\n if(i == INT_MAX)\n return -1;\n }\n\n return i;\n}\n"
},
{
"answer_id": 2019859,
"author": "mch",
"author_id": 245461,
"author_profile": "https://Stackoverflow.com/users/245461",
"pm_score": 2,
"selected": false,
"text": "unsigned char *)"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,449
|
<p>I'm trying to do the classic Insert/Update scenario where I need to update existing rows in a database or insert them if they are not there.</p>
<p>I've found a <a href="https://stackoverflow.com/questions/13540/insert-update-stored-proc-on-sql-server">previous question on the subject</a>, but it deals with stored procedures, which I'm not using. I'd like to just use plain SQL SELECT, INSERT and UPDATE statements, unless there's something better available (the MERGE statement isn't available in SQL Server 2005).</p>
<p>I guess my general idea is this:</p>
<pre><code>If the row is found
update
else
insert
</code></pre>
<p>As for checking for a row's existence, how expensive is it to do a SELECT statement before calling an UPDATE or an INSERT? Or is it better to just try an UPDATE, check for the number of rows affected, and then do an INSERT if the rows affected is 0?</p>
|
[
{
"answer_id": 261466,
"author": "Sören Kuklau",
"author_id": 1600,
"author_profile": "https://Stackoverflow.com/users/1600",
"pm_score": 4,
"selected": true,
"text": "UPDATE INSERT @@rowcount"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30023/"
] |
261,455
|
<p>After reading a couple of answers and comments on some SQL questions here, and also hearing that a friend of mine works at a place which has a policy which bans them, I'm wondering if there's anything wrong with using backticks around field names in MySQL.</p>
<p>That is:</p>
<pre><code>SELECT `id`, `name`, `anotherfield` ...
-- vs --
SELECT id, name, anotherfield ...
</code></pre>
|
[
{
"answer_id": 261476,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 8,
"selected": true,
"text": "SELECT `id`, `my name`, `another field` , `field,with,comma` \n EXPLAIN EXTENDED Select foo,bar,baz \n"
},
{
"answer_id": 261484,
"author": "Christian Lescuyer",
"author_id": 341,
"author_profile": "https://Stackoverflow.com/users/341",
"pm_score": 3,
"selected": false,
"text": "SELECT some_fied, some_other_field FROM whatever WHERE id IS NULL;\n"
},
{
"answer_id": 3604070,
"author": "EllisGL",
"author_id": 344028,
"author_profile": "https://Stackoverflow.com/users/344028",
"pm_score": 2,
"selected": false,
"text": "event grep -r \"event\" * grep -r \"\\`event\\`\" *"
},
{
"answer_id": 29532205,
"author": "ysrtymz",
"author_id": 3711199,
"author_profile": "https://Stackoverflow.com/users/3711199",
"pm_score": 0,
"selected": false,
"text": "status status"
},
{
"answer_id": 45838759,
"author": "Sonpal singh Sengar",
"author_id": 5413872,
"author_profile": "https://Stackoverflow.com/users/5413872",
"pm_score": 2,
"selected": false,
"text": "i.e 1.-> use `model`; \n here `model` is database name not conflict with reserve keyword 'model'\n2- $age = 27;\ninsert into `tbl_people`(`name`,`age`,`address`) values ('Ashoka','$age',\"Delhi\");\n\nhere i used both quote for all type of requirement. If anything not clear let me know..\n"
},
{
"answer_id": 54352150,
"author": "Command",
"author_id": 10449301,
"author_profile": "https://Stackoverflow.com/users/10449301",
"pm_score": -1,
"selected": false,
"text": "SELECT CONCAT(Name, ' in ', city, ', ', statecode) AS `Publisher and Location`,\n COUNT(ISBN) AS \"# Books\",\n MAX(LENGTH(title)) AS \"Longest Title\",\n MIN(LENGTH(title)) AS \"Shortest Title\"\nFROM Publisher JOIN Book\nON Publisher.PublisherID = Book.PublisherID WHERE INSTR(name, 'read')>0\nGROUP BY `Publisher and Location`\nHAVING COUNT(ISBN) > 1;\n Publisher and Location GROUP BY Publisher and Location"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9021/"
] |
261,463
|
<p>We have a couple of web servers using load balancer. Machines are running IIS6 on port 81. Externally, site is accessable using port 80. External name and name of the machine are different.</p>
<p>We're getting </p>
<pre><code>System.ServiceModel.EndpointNotFoundException: The message with To '<url>' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
</code></pre>
<p>Relevant part of web.config is:</p>
<pre><code> <endpoint binding="ws2007HttpBinding" bindingConfiguration="MyServiceBinding"
contract="MyService.IMyService" listenUriMode="Explicit" />
</code></pre>
<p>We tried adding listenUri, but that didn't solve our problems.</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 482995,
"author": "bh213",
"author_id": 28912,
"author_profile": "https://Stackoverflow.com/users/28912",
"pm_score": 4,
"selected": true,
"text": "[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28912/"
] |
261,490
|
<p>I am building a small system administration web application (think Web-Min, but in RoR) and I need to be able to access system parameters from my Ruby code. For instance, I want to allow the user to change the hostname, time zone, or network config of the server. </p>
<p>My current thoughts are to have a separate setuid script (Perl, Ruby, ??) so that I can call it from my RoR code and it will perform the actions. That is quite cumbersome and not very elegant. I'm a Ruby newbie and would like to know if there is a better way to accomplish this type of thing.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 261698,
"author": "Richard Hurt",
"author_id": 21512,
"author_profile": "https://Stackoverflow.com/users/21512",
"pm_score": 0,
"selected": false,
"text": "result = %x[uptime]"
},
{
"answer_id": 261928,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 2,
"selected": false,
"text": "sudo hostname ifconfig sudo vim !bash /usr/bin/myapp_systemtasks root:root"
},
{
"answer_id": 265567,
"author": "csexton",
"author_id": 19839,
"author_profile": "https://Stackoverflow.com/users/19839",
"pm_score": 0,
"selected": false,
"text": "require 'starling'\nstarling = Starling.new('127.0.0.1:22122')\nstarling.set('my_queue', 12345)\n require 'starling'\nloop do\n starling.get('my_queue') # this will block until something gets added to the queue\n # do stuff\nend\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21512/"
] |
261,500
|
<p>Most of the documentation available for building Python extension modules
uses distutils, but I would like to achieve this by using the appropriate
python autoconf & automake macros instead.</p>
<p>I'd like to know if there is an open source project out there that does
exactly this. Most of the ones I've found end up relying on a setup.py file.
Using that approach works, but unfortunately ends up rebuilding the entire
source tree any time I make a modification to the module source files.</p>
|
[
{
"answer_id": 13711218,
"author": "clarete",
"author_id": 1336414,
"author_profile": "https://Stackoverflow.com/users/1336414",
"pm_score": 4,
"selected": false,
"text": "src SUBDIRS = src\n src myextdir = $(pkgpythondir)\nmyext_PYTHON = file1.py file2.py\n\npyexec_LTLIBRARIES = _myext.la\n\n_myext_la_SOURCES = myext.cpp\n_myext_la_CPPFLAGS = $(PYTHON_CFLAGS)\n_myext_la_LDFLAGS = -module -avoid-version -export-symbols-regex initmyext\n_myext_la_LIBADD = $(top_builddir)/lib/libhollow.la\n\nEXTRA_DIST = myext.h\n autoscan configure.scan configure.ac automake configure.ac dnl python checks (you can change the required python version bellow)\nAM_PATH_PYTHON(2.7.0)\nPY_PREFIX=`$PYTHON -c 'import sys ; print sys.prefix'`\nPYTHON_LIBS=\"-lpython$PYTHON_VERSION\"\nPYTHON_CFLAGS=\"-I$PY_PREFIX/include/python$PYTHON_VERSION\"\nAC_SUBST([PYTHON_LIBS])\nAC_SUBST([PYTHON_CFLAGS])\n automake configure.ac Makefile.am"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9589/"
] |
261,512
|
<p>I'm currently working with Db2 Enterprise Server V 8.2 with FixPak 10</p>
<p>And I want to retrieve list of all the open active connections with an instance.</p>
<p>In Oracle there is a utility program called "Top Session" which does the similar task. Is there any equivalent in DB2?</p>
|
[
{
"answer_id": 261578,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 2,
"selected": false,
"text": "LIST APPLICATIONS\n"
},
{
"answer_id": 265776,
"author": "Fuangwith S.",
"author_id": 24550,
"author_profile": "https://Stackoverflow.com/users/24550",
"pm_score": 3,
"selected": false,
"text": "db2 list applications\n SELECT * FROM SYSIBM.APPLICATIONS\nSELECT * FROM SYSIBM.SESSION\n"
},
{
"answer_id": 391667,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "db2 list applications for database {dbName} show detail\n grep db2 list applications for database {dbName} show detail | grep -i \"executing\"\n db2 list applications for database {dbName} show detail | grep -i \"lock\"\n"
},
{
"answer_id": 62642694,
"author": "Amrith Raj Herle",
"author_id": 5227954,
"author_profile": "https://Stackoverflow.com/users/5227954",
"pm_score": 2,
"selected": false,
"text": "SELECT\n AUTHID,\n APPL_NAME,\n CLIENT_NNAME,\n AGENT_ID,\n APPL_ID,\n APPL_STATUS\nFROM\n SYSIBMADM.APPLICATIONS\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34058/"
] |
261,515
|
<p>I have a large set of files, some of which contain special characters in the filename (e.g. ä,ö,%, and others). I'd like a script file to iterate over these files and rename them removing the special characters. I don't really mind what it does, but it could replace them with underscores for example e.g.</p>
<p>Störung%20.doc would be renamed to St_rung_20.doc</p>
<p>In order of preference:</p>
<ol>
<li>A Windiws batch file</li>
<li>A Windows script file to run with cscript (vbs)</li>
<li>A third party piece of software that can be run from the command-line (i.e. no user interaction required)</li>
<li>Another language script file, for which I'd have to install an additional script engine</li>
</ol>
<p>Background: I'm trying to encrypt these file with GnuPG on Windows but it doesn't seem to handle special characters in filenames with the --encrypt-files option.</p>
|
[
{
"answer_id": 261552,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "chcp 65001 Option Explicit\n\nDim fso: Set fso = CreateObject(\"Scripting.FileSystemObject\")\nDim invalidChars: Set invalidChars = New RegExp\n\n' put all characters that you want to strip inside the brackets\ninvalidChars.Pattern = \"[äöüß&%]\"\ninvalidChars.IgnoreCase = True\ninvalidChars.Global = True\n\nIf WScript.Arguments.Unnamed.Count = 0 Then\n WScript.Echo \"Please give folder name as argument 1.\"\n WScript.Quit 1\nEnd If\n\nRecurse fso.GetFolder(WScript.Arguments.Unnamed(0))\n\nSub Recurse(f)\n Dim item\n\n For Each item In f.SubFolders\n Recurse item\n Sanitize item\n Next\n For Each item In f.Files\n Sanitize item\n Next\nEnd Sub\n\nSub Sanitize(folderOrFile)\n Dim newName: newName = invalidChars.Replace(folderOrFile.Name, \"_\")\n If folderOrFile.Name = newName Then Exit Sub\n WScript.Echo folderOrFile.Name, \" -> \", newName\n folderOrFile.Name = newName \nEnd Sub\n cscript replace.vbs \"c:\\path\\to\\my\\files\"\n"
},
{
"answer_id": 261553,
"author": "Treb",
"author_id": 22114,
"author_profile": "https://Stackoverflow.com/users/22114",
"pm_score": 2,
"selected": false,
"text": "SET STRING=[ABCDEFG]\nSET STRING=%STRING:[=%\nSET STRING=%STRING:]=%\nECHO String: %STRING%\n\nwill display \nString: ABCDEFG\n\nSET STRING=[ABCDEFG]\nSET STRING=%STRING:[=(%\nSET STRING=%STRING:]=)%\nECHO String: %STRING%\n\nwill display \nString: (ABCDEFG)\n\nSET STRING=[ABCDEFG]\nSET STRING=%STRING:~1,7%\nECHO String: %STRING%\n\nwill display \nString: ABCDEFG\n"
},
{
"answer_id": 268812,
"author": "njr101",
"author_id": 9625,
"author_profile": "https://Stackoverflow.com/users/9625",
"pm_score": 3,
"selected": true,
"text": "chcp 1252\ndir /b /s /a-d MyFolder >filelist.txt\ngpg -r test@test.com --encrypt-files <filelist.txt\n"
},
{
"answer_id": 2428894,
"author": "Etienne URBAH",
"author_id": 291920,
"author_profile": "https://Stackoverflow.com/users/291920",
"pm_score": 2,
"selected": false,
"text": "#!/usr/bin/perl -w\n#=============================================================================\n#\n# Copyright 2010 Etienne URBAH\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n# GNU General Public License for more details at\n# http://www.gnu.org/licenses/gpl.html\n#\n# For usage and SPECIAL WARNING, see the 'Help' section below.\n#\n#=============================================================================\nuse 5.008_000; # For correct Unicode support\nuse warnings;\nuse strict;\nuse Encode;\n\n$| = 1; # Autoflush STDOUT\n\n#-----------------------------------------------------------------------------\n# Function ucRemoveEolUnderscoreDash :\n# Set Uppercase, remove End of line, Underscores and Dashes\n#-----------------------------------------------------------------------------\nsub ucRemoveEolUnderscoreDash\n{\n local $_ = uc($_[0]);\n chomp;\n tr/_\\-//d;\n $_;\n}\n\n#-----------------------------------------------------------------------------\n# Constants\n#-----------------------------------------------------------------------------\nmy $Encoding_Western = 'ISO-8859-1';\nmy $Encoding_Central = 'ISO-8859-2';\nmy $Encoding_Baltic = 'ISO-8859-4';\nmy $Encoding_Turkish = 'ISO-8859-9';\nmy $Encoding_W_Euro = 'ISO-8859-15';\nmy $Code_Page_OldWest = 850;\nmy $Code_Page_Central = 1250;\nmy $Code_Page_Western = 1252;\nmy $Code_Page_Turkish = 1254;\nmy $Code_Page_Baltic = 1257;\nmy $Code_Page_UTF8 = 65001;\n\nmy $HighBitSetChars = pack('C*', 0x80..0xFF);\n\nmy %SuperEncodings =\n ( &ucRemoveEolUnderscoreDash($Encoding_Western), 'cp'.$Code_Page_Western,\n &ucRemoveEolUnderscoreDash($Encoding_Central), 'cp'.$Code_Page_Central,\n &ucRemoveEolUnderscoreDash($Encoding_Baltic), 'cp'.$Code_Page_Baltic,\n &ucRemoveEolUnderscoreDash($Encoding_Turkish), 'cp'.$Code_Page_Turkish,\n &ucRemoveEolUnderscoreDash($Encoding_W_Euro), 'cp'.$Code_Page_Western,\n &ucRemoveEolUnderscoreDash('cp'.$Code_Page_OldWest),\n 'cp'.$Code_Page_Western );\n\nmy %EncodingNames = ( 'cp'.$Code_Page_Central, 'Central European',\n 'cp'.$Code_Page_Western, 'Western European',\n 'cp'.$Code_Page_Turkish, ' Turkish ',\n 'cp'.$Code_Page_Baltic, ' Baltic ' );\n\nmy %NonAccenChars = ( \n #--------------------------------#\n'cp'.$Code_Page_Central, # Central European (cp1250) #\n #--------------------------------#\n #€_‚_„…†‡_‰Š‹ŚŤŽŹ_‘’“”•–—_™š›śťžź#\n 'E_,_,.++_%S_STZZ_````.--_Ts_stzz'.\n\n # ˇ˘Ł¤Ą¦§¨©Ş«¬®Ż°±˛ł´µ¶·¸ąş»Ľ˝ľż#\n '_``LoAlS`CS_--RZ`+,l`uP.,as_L~lz'.\n\n #ŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢß#\n 'RAAAALCCCEEEEIIDDNNOOOOxRUUUUYTS'.\n\n #ŕáâăäĺćçčéęëěíîďđńňóôőö÷řůúűüýţ˙#\n 'raaaalccceeeeiiddnnoooo%ruuuuyt`',\n\n #--------------------------------#\n'cp'.$Code_Page_Western, # Western European (cp1252) #\n #--------------------------------#\n #€_‚ƒ„…†‡ˆ‰Š‹Œ_Ž__‘’“”•–—˜™š›œ_žŸ#\n 'E_,f,.++^%S_O_Z__````.--~Ts_o_zY'.\n\n # ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿#\n '_!cLoYlS`Ca_--R-`+23`uP.,10_qh3_'.\n\n #ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞß#\n 'AAAAAAACEEEEIIIIDNOOOOOxOUUUUYTS'.\n\n #àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ#\n 'aaaaaaaceeeeiiiidnooooo%ouuuuyty',\n\n #--------------------------------#\n'cp'.$Code_Page_Turkish, # Turkish (cp1254) #\n #--------------------------------#\n #€_‚ƒ„…†‡ˆ‰Š‹Œ____‘’“”•–—˜™š›œ__Ÿ#\n 'E_,f,.++^%S_O____````.--~Ts_o__Y'.\n\n # ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿#\n '_!cLoYlS`Ca_--R-`+23`uP.,10_qh3_'.\n\n #ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏĞÑÒÓÔÕÖרÙÚÛÜİŞß#\n 'AAAAAAACEEEEIIIIGNOOOOOxOUUUUISS'.\n\n #àáâãäåæçèéêëìíîïğñòóôõö÷øùúûüışÿ#\n 'aaaaaaaceeeeiiiignooooo%ouuuuisy',\n\n #--------------------------------#\n'cp'.$Code_Page_Baltic, # Baltic (cp1257) #\n #--------------------------------#\n #€_‚_„…†‡_‰_‹_¨ˇ¸_‘’“”•–—_™_›_¯˛_#\n 'E_,_,.++_%___``,_````.--_T___-,_'.\n\n # �¢£¤�¦§Ø©Ŗ«¬®Æ°±²³´µ¶·ø¹ŗ»¼½¾æ#\n '__cLo_lSOCR_--RA`+23`uP.o1r_qh3a'.\n\n #ĄĮĀĆÄÅĘĒČÉŹĖĢĶĪĻŠŃŅÓŌÕÖ×ŲŁŚŪÜŻŽß#\n 'AIACAAEECEZEGKILSNNOOOOxULSUUZZS'.\n\n #ąįāćäåęēčéźėģķīļšńņóōõö÷ųłśūüżž˙#\n 'aiacaaeecezegkilsnnoooo%ulsuuzz`' );\n\nmy %AccentedChars;\nmy $AccentedChars = '';\nmy $NonAccenChars = '';\nfor ( $Code_Page_Central, $Code_Page_Western,\n $Code_Page_Turkish, $Code_Page_Baltic )\n {\n $AccentedChars{'cp'.$_} = decode('cp'.$_, $HighBitSetChars);\n $AccentedChars .= $AccentedChars{'cp'.$_};\n $NonAccenChars .= $NonAccenChars{'cp'.$_};\n }\n#print \"\\n\", length($NonAccenChars), ' ', $NonAccenChars,\"\\n\";\n#print \"\\n\", length($AccentedChars), ' ', $AccentedChars,\"\\n\";\n\nmy $QuotedMetaNonAccenChars = quotemeta($NonAccenChars);\n\nmy $DiacriticalChars = '';\nfor ( 0x0300..0x036F, 0x1DC0..0x1DFF )\n { $DiacriticalChars .= chr($_) }\n\n#-----------------------------------------------------------------------------\n# Parse options and parameters\n#-----------------------------------------------------------------------------\nmy $b_Help = 0;\nmy $b_Interactive = 1;\nmy $b_UTF8 = 0;\nmy $b_Parameter = 0;\nmy $Folder;\n\nfor ( @ARGV )\n{\n if ( lc($_) eq '--' )\n { $b_Parameter = 1 }\n elsif ( (not $b_Parameter) and (lc($_) eq '--batch') )\n { $b_Interactive = 0 }\n elsif ( (not $b_Parameter) and (lc($_) eq '--utf8') )\n { $b_UTF8 = 1 }\n elsif ( $b_Parameter or (substr($_, 0, 1) ne '-') )\n {\n if ( defined($Folder) )\n { die \"$0 accepts only 1 parameter\\n\" }\n else\n { $Folder = $_ }\n }\n else\n { $b_Help = 1 }\n}\n\n#-----------------------------------------------------------------------------\n# Help\n#-----------------------------------------------------------------------------\nif ( $b_Help )\n {\n die << \"END_OF_HELP\"\n\n$0 [--help] [--batch] [--] [folder]\n\nThis script renames files with accented and diacritical Latin characters :\n\n- This PERL script starts from the folder given in parameter, or else from\n the current folder.\n- It recursively searches for files with characters belonging to 80 - FF of\n CP 1250, CP 1252, CP 1254 and CP 1257 (mostly accented Latin characters)\n or Latin characters having diacritical marks.\n- It calculates new file names by removing the accents and diacritical marks\n only from Latin characters (For example, Été --> Ete).\n- It displays all proposed renaming and perhaps conflicts, and asks the user\n for global approval.\n- If the user has approved, it renames all files having no conflict.\n\nOption '--batch' avoids interactive questions. Use with care.\n\nOption '--' avoids the next parameter to be interpreted as option.\n\nSPECIAL WARNING :\n- This script was originally encoded in UTF-8, and should stay so.\n- This script may rename a lot of files.\n- Files names are theoretically all encoded only with UTF-8. But some file\n names may be found to contain also some characters having legacy encoding.\n- The author has applied efforts for consistency checks, robustness, conflict\n detection and use of appropriate encoding.\n So this script should only rename files by removing accents and diacritical\n marks from Latin characters.\n- But this script has been tested only under a limited number of OS\n (Windows, Mac OS X, Linux) and a limited number of terminal encodings\n (CP 850, ISO-8859-1, UTF-8).\n- So, under weird circumstances, this script could rename many files with\n random names.\n- Therefore, this script should be used with care, and modified with extreme\n care (beware encoding of internal strings, inputs, outputs and commands)\nEND_OF_HELP\n }\n\n#-----------------------------------------------------------------------------\n# If requested, change current folder\n#-----------------------------------------------------------------------------\nif ( defined($Folder) )\n { chdir($Folder) or die \"Can NOT set '$Folder' as current folder\\n\" }\n\n#-----------------------------------------------------------------------------\n# Following instruction is MANDATORY.\n# The return value should be non-zero, but on some systems it is zero.\n#-----------------------------------------------------------------------------\nutf8::decode($AccentedChars);\n# or die \"$0: '\\$AccentedChars' should be UTF-8 but is NOT.\\n\";\n\n#-----------------------------------------------------------------------------\n# Check consistency on 'tr'\n#-----------------------------------------------------------------------------\n$_ = $AccentedChars;\neval \"tr/$AccentedChars/$QuotedMetaNonAccenChars/\";\nif ( $@ ) { warn $@ }\nif ( $@ or ($_ ne $NonAccenChars) )\n { die \"$0: Consistency check on 'tr' FAILED :\\n\\n\",\n \"Translated Accented Chars : \", length($_), ' : ', $_, \"\\n\\n\",\n \" Non Accented Chars : \", length($NonAccenChars), ' : ',\n $NonAccenChars, \"\\n\" }\n\n#-----------------------------------------------------------------------------\n# Constants depending on the OS\n#-----------------------------------------------------------------------------\nmy $b_Windows = ( defined($ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT') );\n\nmy ($Q, $sep, $sep2, $HOME, $Find, @List, $cwd, @Move);\n\nif ( $b_Windows )\n {\n $Q = '\"';\n $sep = '\\\\';\n $sep2 = '\\\\\\\\';\n $HOME = $ENV{'USERPROFILE'};\n $Find = 'dir /b /s';\n @List = ( ( (`ver 2>&1` =~ m/version\\s+([0-9]+)/i) and ($1 >= 6) ) ?\n ('icacls') :\n ( 'cacls') );\n $cwd = `cd`; chomp $cwd; $cwd = quotemeta($cwd);\n @Move = ('move');\n }\nelse\n {\n $Q = \"'\";\n $sep = '/';\n $sep2 = '/';\n $HOME = $ENV{'HOME'};\n $Find = 'find .';\n @List = ('ls', '-d', '--');\n @Move = ('mv', '--');\n if ( -w '/bin' ) { die \"$0: For safety reasons, \",\n \"usage is BLOCKED to administrators.\\n\"}\n }\n\nmy $Encoding;\nmy $ucEncoding;\nmy $InputPipe = '-|'; # Used as global variable\n\n#-----------------------------------------------------------------------------\n# Under Windows, associate input and output encodings to code pages :\n# - Get the original code page,\n# - If it is not UTF-8, try to set it to UTF-8,\n# - Define the input encoding as the one associated to the ACTIVE code page,\n# - If STDOUT is the console, encode output for the ORIGINAL code page.\n#-----------------------------------------------------------------------------\nmy $Code_Page_Original;\nmy $Code_Page_Active;\n\nif ( $b_Windows )\n {\n #-----------------------------------------------------------------------\n # Get the original code page\n #-----------------------------------------------------------------------\n $_ = `chcp`;\n m/([0-9]+)$/ or die \"Non numeric Windows code page : \", $_;\n $Code_Page_Original = $1;\n print 'Windows Original Code Page = ', $Code_Page_Original,\n ( $Code_Page_Original == $Code_Page_UTF8 ?\n ' = UTF-8, display is perhaps correct with a true type font.' :\n '' ), \"\\n\\n\";\n $Code_Page_Active = $Code_Page_Original ;\n\n #-----------------------------------------------------------------------\n # The input encoding must be the same as the ACTIVE code page\n #-----------------------------------------------------------------------\n $Encoding = ( $Code_Page_Active == $Code_Page_UTF8 ?\n 'utf8' :\n 'cp'.$Code_Page_Active ) ;\n $InputPipe .= \":encoding($Encoding)\";\n print \"InputPipe = '$InputPipe'\\n\\n\";\n\n #-----------------------------------------------------------------------\n # If STDOUT is the console, output encoding must be the same as the\n # ORIGINAL code page\n #-----------------------------------------------------------------------\n if ( $Code_Page_Original != $Code_Page_UTF8 )\n {\n no warnings 'unopened';\n @_ = stat(STDOUT);\n use warnings;\n if ( scalar(@_) and ($_[0] == 1) )\n { binmode(STDOUT, \":encoding(cp$Code_Page_Original)\") }\n else\n { binmode(STDOUT, \":encoding($Encoding)\") }\n }\n }\n\n#-----------------------------------------------------------------------------\n# Under *nix, if the 'LANG' environment variable contains an encoding,\n# verify that this encoding is supported by the OS and by PERL.\n#-----------------------------------------------------------------------------\nelsif ( defined($ENV{'LANG'}) and ($ENV{'LANG'} =~ m/\\.([^\\@]+)$/i) )\n {\n $Encoding = $1;\n\n my $Kernel = `uname -s`;\n chomp $Kernel;\n my $ucEncoding = &ucRemoveEolUnderscoreDash($Encoding);\n if ( (lc($Kernel) ne 'darwin') and not grep {$_ eq $ucEncoding}\n ( map { ($_, &ucRemoveEolUnderscoreDash($_)) }\n `locale -m` ) )\n { die \"Encoding = '$Encoding' or '$ucEncoding' NOT supported \".\n \"by the OS\\n\" }\n\n my $ucLocale = &ucRemoveEolUnderscoreDash($ENV{'LANG'});\n if ( not grep {$_ eq $ucLocale}\n ( map { ($_, &ucRemoveEolUnderscoreDash($_)) }\n `locale -a` ) )\n { die \"Locale = '$ENV{LANG}' or '$ucLocale' NOT supported \".\n \"by the OS\\n\" }\n\n if ( not defined(Encode::find_encoding($Encoding)) )\n { die \"Encoding = '$Encoding' or '$ucEncoding' NOT supported \".\n \"by PERL\\n\" }\n\n print \"Encoding = '$Encoding' is supported by the OS and PERL\\n\\n\";\n binmode(STDOUT, \":encoding($Encoding)\");\n }\n\n#-----------------------------------------------------------------------------\n# Check consistency between parameter of 'echo' and output of 'echo'\n#-----------------------------------------------------------------------------\nundef $_;\nif ( defined($Encoding) )\n {\n $ucEncoding = &ucRemoveEolUnderscoreDash($Encoding);\n if ( defined($SuperEncodings{$ucEncoding}) )\n { $_ = substr($AccentedChars{$SuperEncodings{$ucEncoding}},\n 0x20, 0x60) }\n elsif ( defined($AccentedChars{$Encoding}) )\n { $_ = $AccentedChars{$Encoding} }\n elsif ( $Encoding =~ m/^utf-?8$/i )\n { $_ = $AccentedChars }\n }\nif ( not defined($_) ) # Chosen chars are same in 4 code pages\n { $_ = decode('cp'.$Code_Page_Central,\n pack('C*', 0xC9, 0xD3, 0xD7, 0xDC, # ÉÓ×Ü\n 0xE9, 0xF3, 0xF7, 0xFC)) } # éó÷ü\n#print $_, \" (Parameter)\\n\\n\";\n#system 'echo', $_;\nutf8::decode($_);\n#print \"\\n\", $_, \" (Parameter after utf8::decode)\\n\\n\";\nmy @EchoCommand = ( $b_Windows ?\n \"echo $_\" :\n ('echo', $_) );\n#system @EchoCommand;\n\nopen(ECHO, $InputPipe, @EchoCommand) or die 'echo $_: ', $!;\nmy $Output = join('', <ECHO>);\nclose(ECHO);\nchomp $Output;\n#print \"\\n\", $Output, \" (Output of 'echo')\\n\";\nutf8::decode($Output);\n#print \"\\n\", $Output, \" (Output of 'echo' after utf8::decode)\\n\\n\";\n\nif ( $Output ne $_ )\n {\n warn \"$0: Consistency check between parameter \",\n \"of 'echo' and output of 'echo' FAILED :\\n\\n\",\n \"Parameter of 'echo' : \", length($_), ' : ', $_, \"\\n\\n\",\n \" Output of 'echo' : \", length($Output), ' : ', $Output, \"\\n\";\n exit 1;\n }\n\n#-----------------------------------------------------------------------------\n# Print the translation table\n#-----------------------------------------------------------------------------\nif ( defined($Encoding) )\n{\n undef $_;\n $ucEncoding = &ucRemoveEolUnderscoreDash($Encoding);\n if ( defined($SuperEncodings{$ucEncoding}) )\n {\n $_ = $SuperEncodings{$ucEncoding};\n print \"--------- $EncodingNames{$_} ---------\\n\",\n ' ', substr($AccentedChars{$_}, 0x20, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x20, 0x20), \"\\n\\n\",\n ' ', substr($AccentedChars{$_}, 0x40, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x40, 0x20), \"\\n\\n\",\n ' ', substr($AccentedChars{$_}, 0x60, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x60, 0x20), \"\\n\\n\" }\n else\n {\n for ( 'cp'.$Code_Page_Central, 'cp'.$Code_Page_Western,\n 'cp'.$Code_Page_Turkish, 'cp'.$Code_Page_Baltic )\n {\n if ( ('cp'.$Encoding eq $_) or ($Encoding =~ m/^utf-?8$/i) )\n { print \"--------- $EncodingNames{$_} ---------\\n\",\n ' ', substr($AccentedChars{$_}, 0, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0, 0x20), \"\\n\\n\",\n ' ', substr($AccentedChars{$_}, 0x20, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x20, 0x20), \"\\n\\n\",\n ' ', substr($AccentedChars{$_}, 0x40, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x40, 0x20), \"\\n\\n\",\n ' ', substr($AccentedChars{$_}, 0x60, 0x20), \"\\n\",\n '--> ', substr($NonAccenChars{$_}, 0x60, 0x20), \"\\n\\n\" }\n }\n }\n}\n\n#-----------------------------------------------------------------------------\n# Completely optional :\n# Inside the Unison file, find the accented file names to ignore\n#-----------------------------------------------------------------------------\nmy $UnisonFile = $HOME.$sep.'.unison'.$sep.'common.unison';\nmy @Ignores;\n\nif ( open(UnisonFile, '<', $UnisonFile) )\n {\n print \"\\nUnison File '\", $UnisonFile, \"'\\n\";\n while ( <UnisonFile> )\n {\n if ( m/^\\s*ignore\\s*=\\s*Name\\s*(.+)/ )\n {\n $_ = $1 ;\n if ( m/[$AccentedChars]/ )\n { push(@Ignores, $_) }\n }\n }\n close(UnisonFile);\n }\nprint map(\" Ignore: \".$_.\"\\n\", @Ignores);\n\n#-----------------------------------------------------------------------------\n# Function OutputAndErrorFromCommand :\n#\n# Execute the command given as array in parameter, and return STDOUT + STDERR\n#\n# Reads global variable $InputPipe\n#-----------------------------------------------------------------------------\nsub OutputAndErrorFromCommand\n{\n local $_;\n my @Command = @_; # Protects content of @_ from any modification\n #---------------------------------------------------------------------------\n # Under Windows, fork fails, so :\n # - Enclose into double quotes parameters containing blanks or simple\n # quotes,\n # - Use piped open with redirection of STDERR.\n #---------------------------------------------------------------------------\n if ( defined($ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT') )\n {\n for ( @Command )\n { s/^((-|.*(\\s|')).*)$/$Q$1$Q/ }\n my $Command = join(' ', @Command);\n #print \"\\n\", $Command;\n open(COMMAND, $InputPipe, \"$Command 2>&1\") or die '$Command: ', $!;\n }\n #---------------------------------------------------------------------------\n # Under Unix, quoting is too difficult, but fork succeeds\n #---------------------------------------------------------------------------\n else\n {\n my $pid = open(COMMAND, $InputPipe);\n defined($pid) or die \"Can't fork: $!\";\n if ( $pid == 0 ) # Child process\n {\n open STDERR, '>&=STDOUT';\n exec @Command; # Returns only on failure\n die \"Can't @Command\";\n }\n }\n $_ = join('', <COMMAND>); # Child's STDOUT + STDERR\n close COMMAND;\n chomp;\n utf8::decode($_);\n $_;\n}\n\n#-----------------------------------------------------------------------------\n# Find recursively all files inside the current folder.\n# Verify accessibility of files with accented names.\n# Calculate non-accented file names from accented file names.\n# Build the list of duplicates.\n#-----------------------------------------------------------------------------\nmy %Olds; # $Olds{$New} = [ $Old1, $Old2, ... ]\nmy $Old;\nmy $Dir;\nmy $Command;\nmy $ErrorMessage;\nmy $New;\nmy %News;\n\nprint \"\\n\\nFiles with accented name and the corresponding non-accented name \",\n \":\\n\";\n\nopen(FIND, $InputPipe, $Find) or die $Find, ': ', $!;\n\nFILE:\nwhile ( <FIND> )\n{\n chomp;\n #---------------------------------------------------------------------------\n # If the file path contains UTF-8, following instruction is MANDATORY.\n # If the file path does NOT contain UTF-8, it should NOT hurt.\n #---------------------------------------------------------------------------\n utf8::decode($_);\n\n if ( $b_Windows )\n { s/^$cwd$sep2// }\n else\n { s/^\\.$sep2// }\n\n #---------------------------------------------------------------------------\n # From now on : $_ = Dir/OldFilename\n #---------------------------------------------------------------------------\n push(@{$Olds{$_}}, $_);\n\n if ( m/([^$sep2]+)$/ and\n ($1 =~ m/[$AccentedChars]|([\\ -\\~][$DiacriticalChars])/) )\n {\n if ( $b_Windows and m/$Q/ )\n {\n print \"\\n $Q$_$Q\\n*** contains quotes.\\n\";\n next;\n }\n for my $Ignore ( @Ignores )\n {\n if ( m/$Ignore$/ )\n { next FILE }\n }\n $Old = $_ ;\n m/^(.*$sep2)?([^$sep2]+)$/;\n $Dir = ( defined($1) ? $1 : '');\n $_ = $2;\n\n #---------------------------------------------------------------------\n # From now on : $Old = Dir/OldFilename\n # $_ = OldFilename\n #---------------------------------------------------------------------\n print \"\\n $Q$Old$Q\\n\";\n $ErrorMessage = &OutputAndErrorFromCommand(@List, $Old);\n if ( $? != 0 )\n { print \"*** $ErrorMessage\\n\" }\n else\n {\n #---------------------------------------------------------------\n # Change accented Latin chars to non-accented chars.\n # Remove all diacritical marks after Latin chars.\n #---------------------------------------------------------------\n eval \"tr/$AccentedChars/$QuotedMetaNonAccenChars/\";\n s/([\\ -\\~])[$DiacriticalChars]+/$1/g;\n #---------------------------------------------------------------\n # From now on : $Old = Dir/OldFilename\n # $_ = NewFilename\n #---------------------------------------------------------------\n if ( $@ )\n { warn $@ }\n else\n {\n $New = $Dir.$_;\n if ( $b_Windows or (not utf8::is_utf8($Dir)) ) # Weird\n { utf8::decode($New) } # but necessary\n $News{$Old} = $New;\n push(@{$Olds{$New}}, $Old);\n }\n print \"--> $Q$Dir$_$Q\\n\";\n }\n }\n}\n\nclose(FIND);\n\n#-----------------------------------------------------------------------------\n# Print list of duplicate non-accented file names\n#-----------------------------------------------------------------------------\nmy $b_NoDuplicate = 1;\n\nfor my $New ( sort keys %Olds )\n{\n if ( scalar(@{$Olds{$New}}) > 1 )\n {\n if ( $b_NoDuplicate )\n {\n print \"\\n\\nFollowing files would have same non-accented name \",\n \":\\n\";\n $b_NoDuplicate = 0;\n }\n print \"\\n\", map(' '.$_.\"\\n\", @{$Olds{$New}}), '--> ', $New, \"\\n\";\n for ( @{$Olds{$New}} )\n { delete $News{$_} };\n }\n}\n\n#-----------------------------------------------------------------------------\n# If there are NO file to rename, then exit\n#-----------------------------------------------------------------------------\nmy $Number = scalar(keys %News);\n\nprint \"\\n\\n\";\nif ( $Number < 1 )\n {\n print \"There are NO file to rename\\n\";\n exit;\n }\n\n#-----------------------------------------------------------------------------\n# Ask the user for global approval of renaming\n#-----------------------------------------------------------------------------\nif ( $b_Interactive )\n {\n print \"In order to really rename the \", $Number,\n \" files which can safely be renamed, type 'rename' : \";\n $_ = <STDIN>;\n sleep 1; # Gives time to PERL to handle interrupts\n if ( not m/^rename$/i )\n { exit 1 }\n }\nelse\n { print $Number, \" files will be renamed\\n\\n\" }\n\n#-----------------------------------------------------------------------------\n# Rename accented file names sorted descending by name size\n#-----------------------------------------------------------------------------\n$Number = 0;\nmy $Move = join(' ', @Move);\n\nfor ( sort {length($b) <=> length($a)} keys %News )\n{\n $ErrorMessage = &OutputAndErrorFromCommand(@Move, $_, $News{$_});\n if ( $? == 0 )\n { $Number++ }\n else\n { print \"\\n$Move $Q$_$Q\\n\", (' ' x length($Move)),\n \" $Q$News{$_}$Q\\n\", ('*' x length($Move)), \" $ErrorMessage\\n\" }\n}\nprint \"\\n$Number files have been successfully renamed\\n\";\n\n__END__\n\n"
},
{
"answer_id": 2470001,
"author": "Manolo",
"author_id": 296527,
"author_profile": "https://Stackoverflow.com/users/296527",
"pm_score": 0,
"selected": false,
"text": "mode con codepage select=1252\n@echo off\nSetlocal enabledelayedexpansion\n::folder only (/D option)\nfor /R /D %%d in (*) do (\n\nset an=%%~nd\nset bn=!an:.=_!\nset cn=!bn:-=_!\nset dn=!cn: =_!\nset en=!dn:Á=A!\nset fn=!en:É=E!\nset gn=!fn:Í=I!\nset hn=!gn:Ó=O!\nset in=!hn:Ú=U!\nset jn=!in:Ü=U!\nset kn=!jn:á=a!\nset ln=!kn:é=e!\nset mn=!ln:í=i!\nset nn=!mn:ó=o!\nset on=!nn:ú=u!\nset pn=!on:ü=u!\nset qn=!pn:Ñ=N!\nset zn=!on:ñ=n!\n\nset ax=%%~xd\nset bx=!ax:.=_!\nset cx=!bx:-=_!\nset dx=!cx: =_!\nset bx=!ax:.=_!\nset cx=!bx:-=_!\nset dx=!cx: =_!\nset ex=!dx:Á=A!\nset fx=!ex:É=E!\nset gx=!fx:Í=I!\nset hx=!gx:Ó=O!\nset ix=!hx:Ú=U!\nset jx=!ix:Ü=U!\nset kx=!jx:á=a!\nset lx=!kx:é=e!\nset mx=!lx:í=i!\nset nx=!mx:ó=o!\nset ox=!nx:ú=u!\nset px=!ox:ü=u!\nset qx=!px:Ñ=N!\nset zx=!ox:ñ=n!\n\n\nif [!an!]==[] (set zn=)\nif [!ax!]==[] (set zx=)\n\nset newname=!zn!!zx!\n\nif /i not [%%~nd%%~xd]==[!newname!] rename \"%%d\" !newname!\n\n)\n\nendlocal\n\npause\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9625/"
] |
261,518
|
<p>Here's the situation:</p>
<p>I have one VS2005 solution with two projects: MyDll (DLL), MyDllUnitTest (console EXE).</p>
<p>In MyDll I have a class called MyClass which is internal to the DLL and should not be exported. I want to test it in MyDllUnitTest, so I added a test suite class called MyClassTest, where I create instances of MyClass and test them.</p>
<p>My question: how can I link the object file of MyClass, created by building MyDll, to the MyDllUnitTest EXE? I don't want to build MyClass in MyDllUnitTest and I don't want to export the class.</p>
<p>I tried using the same <em>Intermediate Directory</em> for both projects (so object files are in the same directory) and using the References feature of VS2005 (right click project --> References --> Add New Reference...), but it didn't work - I still get a linking error (LNK2001).</p>
<p><strong>Edit:</strong> I don't want to have the same source file in two projects - consider the face that I have many MyClass/MyClassTest, which means I have to duplicate each MyClass to a different project.
I know it is possible to use the same object file in two projects, I've seen it done before but forgot how.</p>
<p><strong>Edit:</strong> I've decided to put the files in both projects, so they are compiled twice. It turns out the "Reference" feature works automatically - but only for static lib projects.</p>
|
[
{
"answer_id": 261579,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 3,
"selected": true,
"text": "extern \"C\" MyClass *CreateMyClass();\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33982/"
] |
261,522
|
<p>What is the command to match brackets in Emacs (the equivalent of the <code>%</code> command in Vim)?</p>
|
[
{
"answer_id": 261545,
"author": "Alexander Kojevnikov",
"author_id": 712,
"author_profile": "https://Stackoverflow.com/users/712",
"pm_score": 7,
"selected": true,
"text": "show-paren-mode"
},
{
"answer_id": 261712,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 5,
"selected": false,
"text": "C-M-f M-x forward-sexp C-M-b M-x backward-sexp"
},
{
"answer_id": 275675,
"author": "wallyqs",
"author_id": 9082,
"author_profile": "https://Stackoverflow.com/users/9082",
"pm_score": 2,
"selected": false,
"text": "show-paren-mode C-M-n C-M-n"
},
{
"answer_id": 6014631,
"author": "Vineet",
"author_id": 755324,
"author_profile": "https://Stackoverflow.com/users/755324",
"pm_score": 3,
"selected": false,
"text": "C-M-n C-M-u C-M"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24508/"
] |
261,525
|
<p>We're using Perforce and Visual Studio. Whenever we create a branch, some projects will not be bound to source control unless we use "Open from Source Control", but other projects work regardless. From my investigations, I know some of the things involved:</p>
<p>In our .csproj files, there are these settings:</p>
<ul>
<li><SccProjectName></li>
<li><SccLocalPath></li>
<li><SccAuxPath></li>
<li><SccProvider></li>
</ul>
<p>Sometimes they are all set to "SAK", sometimes not. It seems things are more likely to work if these say "SAK".</p>
<p>In our .sln file, there are settings for many of the projects:</p>
<ul>
<li>SccLocalPath#</li>
<li>SccProjectFilePathRelativizedFromConnection#</li>
<li>SccProjectUniqueName#</li>
</ul>
<p>(The # is a number that identifies each project.) SccLocalPath is a path relative to the solution file. Often it is ".", sometimes it is the folder that the project is in, and sometimes it is ".." or "..\..", and it seems to be bad for it to point to a folder above the solution folder. The relativized one is a path <em>from</em> that folder to the project file. It will be missing entirely if SccLocalPath points to the project's folder. If the SccLocalPath has ".." in it, this path might include folder names that are not the same between branches, which I think causes problems.</p>
<p>So, to finally get to the specifics I'd like to know:</p>
<ul>
<li>What happens when you do "Change source control" and bind projects? How does Visual Studio decide what to put in the project and solution files?</li>
<li>What happens when you do "Open from source control"?</li>
<li>What's this "connection" folder that SccLocalPath and SccProjectFilePathRelativizedFromConnection refer to? How does Visual Studio/Perforce pick it?</li>
<li>Is there some recommended way to make the source control bindings continue to work even when you create a new branch of the solution?</li>
</ul>
<hr>
<p><em>Added June 2012:</em>
I don't use Perforce any more, so I can't vouch for it, but have a look at <a href="https://stackoverflow.com/a/11148342/2283">KCD's answer</a> below. Apparently there's <a href="http://forums.perforce.com/index.php?/topic/1585-new-perforce-plugin-for-visual-studio-20121-beta-available-now/" rel="nofollow noreferrer">a new P4 VS plugin</a> under development. Hopefully it should clear up all this mess!</p>
|
[
{
"answer_id": 268578,
"author": "Thomas L Holaday",
"author_id": 29403,
"author_profile": "https://Stackoverflow.com/users/29403",
"pm_score": 1,
"selected": false,
"text": "/Solution\n /library1\n /library2\n /product1\n /product2\n /subsolution\n /sublibrary1\n /subproduct1\n"
},
{
"answer_id": 529538,
"author": "Milan Gardian",
"author_id": 23843,
"author_profile": "https://Stackoverflow.com/users/23843",
"pm_score": 8,
"selected": true,
"text": "GlobalSection(SourceCodeControl) = preSolution\n SccNumberOfProjects = 1\n SccLocalPath0 = .\n SccProjectName0 = Tutorial\n SccProvider0 = MSSCCI:Perforce\\u0020SCM\nEndGlobalSection\n <PropertyGroup>\n ...\n <SccProjectName>Tutorial</SccProjectName>\n <SccLocalPath>..\\..</SccLocalPath>\n <SccProvider>MSSCCI:Perforce SCM</SccProvider>\n ...\n</PropertyGroup>\n"
},
{
"answer_id": 5184384,
"author": "Dave Andersen",
"author_id": 116311,
"author_profile": "https://Stackoverflow.com/users/116311",
"pm_score": 2,
"selected": false,
"text": "<PropertyGroup>\n <SccProjectName>SAK</SccProjectName>\n <SccProvider>SAK</SccProvider>\n <SccAuxPath>SAK</SccAuxPath>\n <SccLocalPath>SAK</SccLocalPath>\n</PropertyGroup>\n SccProjectName0 = Perforce\\u0020Project\nSccProvider0 = MSSCCI:Perforce\\u0020SCM\n"
},
{
"answer_id": 6592823,
"author": "Zoner",
"author_id": 804455,
"author_profile": "https://Stackoverflow.com/users/804455",
"pm_score": 3,
"selected": false,
"text": "SccProjectName0 = Perforce\\u0020Project\nSccProvider0 = MSSCCI:Perforce\\u0020SCM\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2283/"
] |
261,534
|
<p>I have an application I am writing in PHP5, using the CodeIgniter framework.
I have it running on both Windows (using Xampp) and Ubuntu (using standard Apache, PHP, MySQL stack).</p>
<p>I have a form, that takes XML, parses it (using simpleXML) and posts the results into a database.</p>
<p>On Windows - no problem, works as intended.</p>
<p>On Linux - big problem. It errors out.</p>
<p>I have double checked the XML, and it's fine.</p>
<p>I removed a large amount of the XML, and it seems that it is OK.</p>
<p>I think it's related to the size of the XML string being posted from the form, but am not sure. Again, on Windows it's OK - on Linux, it errors out.</p>
<p>The size of the data posted in the form is ~160k (yeah, that's a lot of text, but it's automated - AND it's gonna eventually be about 200k).</p>
<p>The error is below.</p>
<p>Any help much appreciated.</p>
<blockquote>
<p>Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/ci/system/application/controllers/system.php:49 Stack trace: #0 /var/www/ci/system/application/controllers/system.php(49): SimpleXMLElement->__construct('') #1 [internal function]: System->add_system() #2 /var/www/ci/system/codeigniter/CodeIgniter.php(233): call_user_func_array(Array, Array) #3 /var/www/ci/index.php(115): require_once('/var/www/ci/sys...') #4 {main} thrown in /var/www/ci/system/application/controllers/system.php on line 49</p>
</blockquote>
<p>Line 49 looks like this:</p>
<p><code>$xml = new SimpleXMLElement($this->input->post('form_systemXML'));</code></p>
<p>EDIT - FIXED</p>
<p>Found the issue. Suhosin is installed on Ubuntu. in the file /etc/php5/apache2/conf.d/suhosin.ini, I enabled the line <code>suhosin.post.max_value_length = 65000</code> and changed the value to 195000. Restarted Apache, and all good. Thanks for the pointers guys.</p>
|
[
{
"answer_id": 261575,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 1,
"selected": false,
"text": "print_r($_POST);\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34067/"
] |
261,535
|
<p>I'm by no means a sysadmin so please correct me if I'm wrong.</p>
<p>I want to run aspnet_regiis.exe -s.
This requires the metabase path of my website.</p>
<p>How do I find this metabase path?</p>
|
[
{
"answer_id": 18454482,
"author": "Slider345",
"author_id": 356544,
"author_profile": "https://Stackoverflow.com/users/356544",
"pm_score": 1,
"selected": false,
"text": "/W3SVC/<site id>/Root"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261535",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
261,536
|
<p>I'm getting the following error when my win32 (c#) app is calling web services.</p>
<pre><code>The request failed with HTTP status 504: Gateway timeout server response timeout.
</code></pre>
<p>I understand 'I think' that this is because the upstream request does not get a response in a timely fashion.</p>
<p>But my question is this? How do I change the <strong>app.config</strong> settings in my win32 application to allow more time to process its data. I assume I require these changes to be made on my app settings as the webservices and IIS hosting the ws are setup with extended times.</p>
<p>Look forward to a response and thank you in advance.</p>
|
[
{
"answer_id": 35071350,
"author": "dynamiclynk",
"author_id": 1427166,
"author_profile": "https://Stackoverflow.com/users/1427166",
"pm_score": 1,
"selected": false,
"text": " \"commands\": {\n \"web\": \"Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5090\"\n },\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26098/"
] |
261,539
|
<p>I've got a WCF service that uses a LinqToSql DataContext to fetch some information out of a database. The return type of the operation is IEnumerable<code><DomainObject</code>>, and I have a helper method that converts from the Table-derived LINQ object to a WCF data contract like so:</p>
<pre><code>[OperationContract]
public IEnumerable<DomainObjectDTO> RetrieveDomainObjects()
{
var context = CreateDataContext();
return from domainObject in context.DomainObjects
select ConvertDomainObject(domainObject);
}
private DomainObjectDTO ConvertDomainObject(DomainObject obj)
{
// etc...
}
</code></pre>
<p>This code exhibits a strange behaviour if I pass an invalid connection string to the DataContext. Being unable to find the correct database, presumably the above code throws a SqlException when enumerating the IEnumerable<code><DomainObjectDTO</code>> when serialization is happening. However, when I run this code in my debugger, I see no first-chance exception on the server side at all! I told the debugger in the Exceptions tab to break on all thrown CLR exceptions, and it simply doesn't. I also don't see the characteristic "First chance exception" message in the Output window.</p>
<p>On the client side, I get a CommunicationException with an error message along the lines of "The socket connection terminated unexpectedly". None of the inner exceptions provides any hint as to the underlying cause of the problem.</p>
<p>The only way I could figure this out was to rewrite the LINQ code in such a way that the query expression is evaluated inside of the OperationContract method. Incidentally, I get the same result if there is a permissions problem, or if I wrap the DataContext in a using statement, so this is not just isolated to SqlExceptions.</p>
<p>Disregarding the inadvisability of making the return type an IEnumerable<code><T</code>> and only enumerating the query somewhere in the depths of the serializer, is WCF suppressing or somehow preventing exceptions from being thrown in this case? And if so, why?</p>
|
[
{
"answer_id": 261556,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "IErrorHandler yield return yield return var context = CreateDataContext();\nvar query = from domainObject in context.DomainObjects\n select ConvertDomainObject(domainObject);\nforeach(var item in query) { yield return item; }\n"
},
{
"answer_id": 261587,
"author": "Darren",
"author_id": 6065,
"author_profile": "https://Stackoverflow.com/users/6065",
"pm_score": 1,
"selected": false,
"text": "try\n{\n DoSomething();\n}\ncatch ( Exception ex )\n{ \n throw new FaultException<CustomException>( new CustomException( ex ), ex.Message );\n}\n"
},
{
"answer_id": 262335,
"author": "kelsmj",
"author_id": 17001,
"author_profile": "https://Stackoverflow.com/users/17001",
"pm_score": 0,
"selected": false,
"text": "<system.diagnostics>\n<sources>\n <source name=\"System.ServiceModel\" switchValue=\"Verbose,ActivityTracing\"\n propagateActivity=\"true\">\n <listeners>\n <add type=\"System.Diagnostics.DefaultTraceListener\" name=\"Default\">\n <filter type=\"\" />\n </add>\n <add name=\"NewListener\">\n <filter type=\"\" />\n </add>\n </listeners>\n </source>\n</sources>\n<sharedListeners>\n <add initializeData=\"C:\\App_tracelog.svclog\"\n type=\"System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\n name=\"NewListener\" traceOutputOptions=\"LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack\">\n <filter type=\"\" />\n </add>\n</sharedListeners>\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32539/"
] |
261,543
|
<p>Is there a way to drop a validation that was set in Rails plugin (or included module)?
Let's say I have some model with module included in it:</p>
<pre><code>class User < ActiveRecord::Base
include SomeModuleWithValidations
# How to cancel validates_presence_of :something here?
end
module SomeModuleWithValidations
def self.included(base)
base.class_eval do
validates_presence_of :something
end
end
end
</code></pre>
<p>My only idea so far was to do something like:</p>
<pre><code>validates_presence_of :something, :if => Proc.new{1==2}
</code></pre>
<p>which would work, I think, but it isn't particulary pretty.</p>
|
[
{
"answer_id": 261713,
"author": "Kristian",
"author_id": 23246,
"author_profile": "https://Stackoverflow.com/users/23246",
"pm_score": 1,
"selected": false,
"text": "def self.validates_presence_of(*args)\n return if args.first == :foo\n super\nend\n def foo\n self[:foo] || \"\"\nend\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26123/"
] |
261,547
|
<p>This query is related to <a href="https://stackoverflow.com/questions/259850/javascript-multiple-client-side-validations-on-same-event">this</a> one I asked yesterday.
I have a radio button list on my asp.net page defined as follows: </p>
<pre><code><asp:RadioButtonList ID="rdlSortBy" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="True" >
<asp:ListItem Selected="True">Name</asp:ListItem>
<asp:ListItem>Staff No</asp:ListItem>
</asp:RadioButtonList>
</code></pre>
<p>On the client-side, am doing the following validations:</p>
<pre><code>rdlSortBy.Attributes("onclick") = "javascript:return prepareSave() && prepareSearch();"
</code></pre>
<p>The problem is that the Javascript validation runs as expected.
A message is displayed and I expect to remain on the page until user has saved the changes, instead the page is posted back and effectively I am loosing unsaved changes.</p>
<p>What could be going wrong?</p>
|
[
{
"answer_id": 261632,
"author": "Adrian Clark",
"author_id": 148,
"author_profile": "https://Stackoverflow.com/users/148",
"pm_score": 1,
"selected": false,
"text": "OnClick CustomValidator"
},
{
"answer_id": 271713,
"author": "Julius A",
"author_id": 13370,
"author_profile": "https://Stackoverflow.com/users/13370",
"pm_score": 3,
"selected": true,
"text": "rdlSortBy.Items(0).Attributes(\"onclick\") = \"javascript:return isDirtied() && prepareSearch();\"\n rdlSortBy.Items(1).Attributes(\"onclick\") = \"javascript:return isDirtied() && prepareSearch();\"\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261547",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13370/"
] |
261,559
|
<p>I was wondering how to make a toolbar in MFC that used 24bit or 256 colour bitmaps rather than the horrible 16 colour ones.</p>
<p>Can anyone point me in the direction of some simple code?</p>
<p>Thanks</p>
|
[
{
"answer_id": 261589,
"author": "Stu Mackellar",
"author_id": 28591,
"author_profile": "https://Stackoverflow.com/users/28591",
"pm_score": 5,
"selected": true,
"text": "HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),\n MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_BITMAP,\n 0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS);\nCBitmap bm;\nbm.Attach(hBitmap);\n CImageList m_imagelist.Create(20, 20, ILC_COLOR8, 4, 4);\nm_imagelist.Add(&bm, (CBitmap*) NULL);\n m_toolbar.GetToolBarCtrl().SetImageList(&m_imagelist);\n"
},
{
"answer_id": 1640564,
"author": "Victor",
"author_id": 198494,
"author_profile": "https://Stackoverflow.com/users/198494",
"pm_score": 0,
"selected": false,
"text": "CImageList m_imagelist;\nm_imagelist.Create(20, 20, ILC_COLOR8, 4, 4); \nm_imagelist.Add(&bm, (CBitmap*) NULL); \n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
261,567
|
<p>I'm kind of new to C++ and have some questions, this is one of them.</p>
<p>Is there ANY reason when you are using a function that takes in one or several parameters, parameters of which you know will always be stored in a variable before the function call, to pass a copy of the variable, rather than a pointer to the variable? </p>
<p>I'm talking in terms of performance. Seems to me that it would take a lot more resources to pass a copy of a whole struct than just a pointer(4 bytes).</p>
|
[
{
"answer_id": 261571,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 2,
"selected": false,
"text": "const"
},
{
"answer_id": 261598,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 3,
"selected": false,
"text": "void value_semantics(my_obj obj);\nvoid value_semantics(const my_obj& obj);\n &"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
261,572
|
<p>I am building a FAQ module for my site and I want to be able to control single elements on the page even though they all have the same class. I believe this comes under siblings which I am not yet familiar with.</p>
<p>Basically I want the user to be able to click the question div and then when they click it the answer div within the same div as the question div is set to show (if that makes sense!). Any help would be greatly appreciated.</p>
<pre><code><div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>
<div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>
<div class="set">
<div class="question">What is the airspeed velocity of an unladen swallow?</div>
<div class="answer">Although a definitive answer would of course require further measurements, published species-wide averages of wing length and body mass, initial Strouhal estimates based on those averages and cross-species comparisons, the Lund wind tunnel study of birds flying at a range of speeds, and revised Strouhal numbers based on that study all lead me to estimate that the average cruising airspeed velocity of an unladen European Swallow is roughly 11 meters per second, or 24 miles an hour. </div>
</div>
</code></pre>
|
[
{
"answer_id": 261596,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 3,
"selected": true,
"text": "$(document).ready ( function () {\n $('.question').click(function() {\n $(this).next('.answer').show();\n });\n});\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
261,573
|
<p>Is there an efficient algorithm for detecting cycles within a directed graph?</p>
<p>I have a directed graph representing a schedule of jobs that need to be executed, a job being a node and a dependency being an edge. I need to detect the error case of a cycle within this graph leading to cyclic dependencies.</p>
|
[
{
"answer_id": 261595,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 9,
"selected": true,
"text": "O(|E| + |V|)"
},
{
"answer_id": 261621,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 6,
"selected": false,
"text": "tsort O(|V| + |E|)"
},
{
"answer_id": 770690,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "n O(n) O(n^2)"
},
{
"answer_id": 4041983,
"author": "dharmendra singh",
"author_id": 489969,
"author_profile": "https://Stackoverflow.com/users/489969",
"pm_score": -1,
"selected": false,
"text": "|e| > |v| - 1\n"
},
{
"answer_id": 43361252,
"author": "Bhagwati Malav",
"author_id": 3572733,
"author_profile": "https://Stackoverflow.com/users/3572733",
"pm_score": 0,
"selected": false,
"text": "Topological sort direct acyclic graph dfs"
},
{
"answer_id": 53995651,
"author": "Kurt Peek",
"author_id": 995862,
"author_profile": "https://Stackoverflow.com/users/995862",
"pm_score": 6,
"selected": false,
"text": "DFS-VISIT v u GRAY if import collections\n\n\nclass Graph(object):\n def __init__(self, edges):\n self.edges = edges\n self.adj = Graph._build_adjacency_list(edges)\n\n @staticmethod\n def _build_adjacency_list(edges):\n adj = collections.defaultdict(list)\n for edge in edges:\n adj[edge[0]].append(edge[1])\n return adj\n\n\ndef dfs(G):\n discovered = set()\n finished = set()\n\n for u in G.adj:\n if u not in discovered and u not in finished:\n discovered, finished = dfs_visit(G, u, discovered, finished)\n\n\ndef dfs_visit(G, u, discovered, finished):\n discovered.add(u)\n\n for v in G.adj[u]:\n # Detect cycles\n if v in discovered:\n print(f\"Cycle detected: found a back edge from {u} to {v}.\")\n break\n\n # Recurse into DFS tree\n if v not in finished:\n dfs_visit(G, v, discovered, finished)\n\n discovered.remove(u)\n finished.add(u)\n\n return discovered, finished\n\n\nif __name__ == \"__main__\":\n G = Graph([\n ('u', 'v'),\n ('u', 'x'),\n ('v', 'y'),\n ('w', 'y'),\n ('w', 'z'),\n ('x', 'v'),\n ('y', 'x'),\n ('z', 'z')])\n\n dfs(G)\n time Cycle detected: found a back edge from x to v.\nCycle detected: found a back edge from z to z.\n"
}
] |
2008/11/04
|
[
"https://Stackoverflow.com/questions/261573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34080/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.