qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
173,884
|
<p>When I am adding two textbox values that are <strong>1.001</strong> and <strong>0.001</strong> and then I do a <code>parseFloat</code> I get <strong>1.0019999999</strong>. I want it <strong>1.002</strong> . Can you help me?</p>
|
[
{
"answer_id": 174046,
"author": "17 of 26",
"author_id": 2284,
"author_profile": "https://Stackoverflow.com/users/2284",
"pm_score": 5,
"selected": false,
"text": "toFixed() parseFloat(\"1.0019999\").toFixed(3)"
},
{
"answer_id": 11399911,
"author": "Lorenzo Polidori",
"author_id": 885464,
"author_profile": "https://Stackoverflow.com/users/885464",
"pm_score": 3,
"selected": false,
"text": "Number.toFixed() Number.toPrecision() String var x = parseFloat(parseFloat(\"1.0019999999\").toPrecision(3));\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,886
|
<p>Please consider this example class:</p>
<pre><code>[Serializable]
public class SomeClass
{
private DateTime _SomeDateTime;
public DateTime SomeDateTime
{
get { return _SomeDateTime; }
set { _SomeDateTime = value; }
}
}
</code></pre>
<p>I would like to alter the serialization of any DateTime declared in the class according to my own rules. The members of this class will change frequently and I don't want to maintain a custom serializer for every change. Also I would like this behaviour to be inherited by subclasses and not code a custom serializer for every one. The serialization is being output by a web service. Thanks for any help!</p>
|
[
{
"answer_id": 173894,
"author": "Josh",
"author_id": 11702,
"author_profile": "https://Stackoverflow.com/users/11702",
"pm_score": 2,
"selected": false,
"text": "public DateTime? SomeDateTime {get; set;}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6651/"
] |
173,919
|
<p>When merging topic branch "B" into "A" using <code>git merge</code>, I get some conflicts. I know all the conflicts can be solved using the version in "B".</p>
<p>I am aware of <code>git merge -s ours</code>. But what I want is something like <code>git merge -s theirs</code>.</p>
<p>Why doesn't it exist? How can I achieve the same result after the conflicting merge with existing <code>git</code> commands? (<code>git checkout</code> every unmerged file from B)</p>
<p>The "solution" of just discarding anything from branch A (the merge commit point to B version of the tree) is not what I am looking for.</p>
|
[
{
"answer_id": 173954,
"author": "elmarco",
"author_id": 1277510,
"author_profile": "https://Stackoverflow.com/users/1277510",
"pm_score": 4,
"selected": false,
"text": "git checkout -m old\ngit checkout -b new B\ngit merge -s ours old\n"
},
{
"answer_id": 174283,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 7,
"selected": false,
"text": "git pull --strategy=theirs remote_branch\n git fetch origin\ngit reset --hard origin\n"
},
{
"answer_id": 3364506,
"author": "Alan W. Smith",
"author_id": 102401,
"author_profile": "https://Stackoverflow.com/users/102401",
"pm_score": 11,
"selected": true,
"text": "--strategy-option -X theirs git checkout branchA\ngit merge -X theirs branchB\n -X ours -s ours -X -s ours -X theirs -s theirs git rm git rm {DELETED-FILE-NAME}\n -X theirs git rm"
},
{
"answer_id": 4969679,
"author": "Paul Pladijs",
"author_id": 613109,
"author_profile": "https://Stackoverflow.com/users/613109",
"pm_score": 8,
"selected": false,
"text": "# in case branchA is not our current branch\ngit checkout branchA\n\n# make merge commit but without conflicts!!\n# the contents of 'ours' will be discarded later\ngit merge -s ours branchB \n\n# make temporary branch to merged commit\ngit branch branchTEMP \n\n# get contents of working tree and index to the one of branchB\ngit reset --hard branchB\n\n# reset to our merged commit but \n# keep contents of working tree and index\ngit reset --soft branchTEMP\n\n# change the contents of the merged commit\n# with the contents of branchB\ngit commit --amend\n\n# get rid off our temporary branch\ngit branch -D branchTEMP\n\n# verify that the merge commit contains only contents of branchB\ngit diff HEAD branchB\n git merge -s theirs branchB"
},
{
"answer_id": 10130264,
"author": "rafalmag",
"author_id": 252363,
"author_profile": "https://Stackoverflow.com/users/252363",
"pm_score": 4,
"selected": false,
"text": "git merge -s recursive -X theirs B\n"
},
{
"answer_id": 13209363,
"author": "musicmatze",
"author_id": 1391026,
"author_profile": "https://Stackoverflow.com/users/1391026",
"pm_score": 6,
"selected": false,
"text": "git checkout --theirs <file>\n git merge <branch> -s theirs\n"
},
{
"answer_id": 14562169,
"author": "Pawan Maheshwari",
"author_id": 648030,
"author_profile": "https://Stackoverflow.com/users/648030",
"pm_score": 0,
"selected": false,
"text": "git checkout <baseBranch> // this will checkout baseBranch\ngit merge -s ours <newBranch> // this will simple merge newBranch in baseBranch\ngit rm -rf . // this will remove all non references files from baseBranch (deleted in newBranch)\ngit checkout newBranch -- . //this will replace all conflicted files in baseBranch\n"
},
{
"answer_id": 16526138,
"author": "jthill",
"author_id": 1290731,
"author_profile": "https://Stackoverflow.com/users/1290731",
"pm_score": 3,
"selected": false,
"text": "git update-ref HEAD $(\n git commit-tree -m 'completely superseding with branchB content' \\\n -p HEAD -p branchB branchB:\n)\ngit reset --hard\n"
},
{
"answer_id": 18682314,
"author": "Gandalf458",
"author_id": 1894055,
"author_profile": "https://Stackoverflow.com/users/1894055",
"pm_score": 5,
"selected": false,
"text": "git checkout Branch\ngit merge master -s ours\n git checkout master\ngit merge Branch\n"
},
{
"answer_id": 19686137,
"author": "thoutbeckers",
"author_id": 2338613,
"author_profile": "https://Stackoverflow.com/users/2338613",
"pm_score": 3,
"selected": false,
"text": "git merge --strategy=ours ref-to-be-merged git diff --binary ref-to-be-merged | git apply --reverse --index git commit --amend"
},
{
"answer_id": 27338013,
"author": "siegi",
"author_id": 1347968,
"author_profile": "https://Stackoverflow.com/users/1347968",
"pm_score": 7,
"selected": false,
"text": "git merge -s ours git merge -X ours git merge -s recursive -X ours git checkout branchA\n# also uses -s recursive implicitly\ngit merge -X theirs branchB\n branchA branchB # Get the content you want to keep.\n# If you want to keep branchB at the current commit, you can add --detached,\n# else it will be advanced to the merge commit in the next step.\ngit checkout branchB\n\n# Do the merge an keep current (our) content from branchB we just checked out.\ngit merge -s ours branchA\n\n# Set branchA to current commit and check it out.\ngit checkout -B branchA\n branchB branchA git merge -s ours branchB branchA branchB git checkout branchA\n\n# Do a merge commit. The content of this commit does not matter,\n# so use a strategy that never fails.\n# Note: This advances branchA.\ngit merge -s ours branchB\n\n# Change working tree and index to desired content.\n# --detach ensures branchB will not move when doing the reset in the next step.\ngit checkout --detach branchB\n\n# Move HEAD to branchA without changing contents of working tree and index.\ngit reset --soft branchA\n\n# 'attach' HEAD to branchA.\n# This ensures branchA will move when doing 'commit --amend'.\ngit checkout branchA\n\n# Change content of merge commit to current index (i.e. content of branchB).\ngit commit --amend -C HEAD\n branchB branchA git merge git commit-tree"
},
{
"answer_id": 29806926,
"author": "Michael R",
"author_id": 428628,
"author_profile": "https://Stackoverflow.com/users/428628",
"pm_score": 2,
"selected": false,
"text": "git checkout <base-branch>\n\ngit merge --no-commit -s ours <their-branch>\ngit read-tree -u --reset <their-branch>\ngit commit\n\n# Check your work!\ngit diff <their-branch>\n"
},
{
"answer_id": 39251301,
"author": "briemers",
"author_id": 6148805,
"author_profile": "https://Stackoverflow.com/users/6148805",
"pm_score": 1,
"selected": false,
"text": "git checkout -B mergeBranch branchB\ngit merge -s ours branchA\ngit checkout branchA\ngit merge mergeBranch\ngit branch -D mergeBranch\n"
},
{
"answer_id": 43049246,
"author": "Trann",
"author_id": 613748,
"author_profile": "https://Stackoverflow.com/users/613748",
"pm_score": -1,
"selected": false,
"text": "Org/repository1 master Org/repository2 master repository2 master repository1 master -s theirs -X theirs repository2 repo1-merge git pull git@gitlab.com:Org/repository1 -s ours repository1 repo2-merge git pull git@gitlab.com:Org/repository2 repo1-merge repository1"
},
{
"answer_id": 46741538,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": false,
"text": "git merge -s theirs -X<option> -s theirs gitster gitster -s theirs -Xours -s ours -Xtheirs ours -s theirs -Xtheirs theirs theirs -s theirs mtheirs = !sh -c 'git merge -s ours --no-commit $1 && git read-tree -m -u $1' -\n checkout their-history && merge -s ours your-history -s ours -s theirs git merge -s ours <their-ref> <their-ref>"
},
{
"answer_id": 50334247,
"author": "Boaz Nahum",
"author_id": 1173533,
"author_profile": "https://Stackoverflow.com/users/1173533",
"pm_score": 2,
"selected": false,
"text": "git commit-tree -m \"take theirs\" -p HEAD -p branchB 'branchB^{tree}'\ngit reset --hard 36daf519952 # is the output of the prev command\n git commit-tree -m \"take theirs\" -p HEAD -p 'SOURCE^{commit}' 'SOURCE^{tree}'\n"
},
{
"answer_id": 52659754,
"author": "rubund",
"author_id": 5744809,
"author_profile": "https://Stackoverflow.com/users/5744809",
"pm_score": -1,
"selected": false,
"text": "git checkout branchB .\ngit commit -m \"Picked up the content from branchB\"\n git merge -s ours branchB\n"
},
{
"answer_id": 56368650,
"author": "Brain2000",
"author_id": 231839,
"author_profile": "https://Stackoverflow.com/users/231839",
"pm_score": 2,
"selected": false,
"text": "[alias]\n mergetheirs = \"!git merge -s ours \\\"$1\\\" && git branch temp_THEIRS && git reset --hard \\\"$1\\\" && git reset --soft temp_THEIRS && git commit --amend && git branch -D temp_THEIRS\"\n git checkout B (optional, just making sure we're on branch B)\ngit mergetheirs A\n"
},
{
"answer_id": 74070090,
"author": "Edgar Bonet",
"author_id": 463687,
"author_profile": "https://Stackoverflow.com/users/463687",
"pm_score": 0,
"selected": false,
"text": "git merge -s theirs # Start from the branch that is going to receive the merge.\ngit switch our_branch\n\n# Create the merge commit, albeit with the wrong tree.\ngit merge -s ours their_branch\n\n# Replace our working tree and our index with their tree.\ngit restore --source=their_branch --worktree --staged :/\n\n# Put their tree in the merge commit.\ngit commit --amend\n git restore git help restore"
},
{
"answer_id": 74643586,
"author": "tobylaroni",
"author_id": 3298457,
"author_profile": "https://Stackoverflow.com/users/3298457",
"pm_score": 0,
"selected": false,
"text": "<<<<<<< HEAD\\n[^•>]+\\n=======\\n([^•>]+)>>>>>>> .+\\n \\1"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1277510/"
] |
173,934
|
<p>I'm trying to create newspaper style columns using a block of text. I would like the text to be evenly spread out across 2 columns which could react to change of length in the text.</p>
<p>Is this possible using just HTML/CSS, if not could javascript be used?</p>
<p>Thanks</p>
|
[
{
"answer_id": 174684,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 1,
"selected": false,
"text": "function Newspaperize(elem)\n{\n var halflength = elem.innerText.length / 2; \n var col1 = elem.innerText.substring(0, halflength);\n var col2 = elem.innerText.substring(halflength);\n\n elem.innerHTML = '<TABLE WIDTH=100%><TR>' + \n '<TD WIDTH=50% VALIGN=TOP>' + col1 + '</TD>' +\n '<TD VALIGN=TOP>' + col2 + '</TD>' +\n '</TR></TABLE>';\n}\n"
},
{
"answer_id": 570708,
"author": "Ms2ger",
"author_id": 33466,
"author_profile": "https://Stackoverflow.com/users/33466",
"pm_score": 3,
"selected": false,
"text": "selector {\n -moz-column-count: 2;\n -webkit-column-count: 2;\n column-count: 2;\n}\n"
},
{
"answer_id": 2691360,
"author": "Quaze",
"author_id": 311850,
"author_profile": "https://Stackoverflow.com/users/311850",
"pm_score": 0,
"selected": false,
"text": "<p> <p>"
},
{
"answer_id": 12199259,
"author": "Dakota",
"author_id": 362042,
"author_profile": "https://Stackoverflow.com/users/362042",
"pm_score": 3,
"selected": false,
"text": "column-count column-gap #container {\n -moz-column-count: 2;\n -moz-column-gap: 20px;\n -webkit-column-count: 2;\n -webkit-column-gap: 20px;\n column-count: 2;\n column-gap: 20px;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
173,980
|
<p>There are numerous times you have an interface that accepts similar type arguments that have a separate domain logic meaning:</p>
<pre><code>public static class Database
{
public static bool HasAccess(string userId, string documentId) { return true; }
}
</code></pre>
<p>Now it's quite easy to have someone key documentId instead of userId and vice versa. One could prevent that by abstracting the data type of the arguments:</p>
<pre><code>public class UserId
{
public string Value { get; internal set; }
public static implicit operator string(UserId id) { return id.Value; }
}
public class DocumentId
{
public string Value { get; internal set; }
public static implicit operator string(DocumentId id) { return id.Value; }
}
public static class Database
{
public static bool HasAccess(UserId userId, DocumentId documentId) { return true; }
}
</code></pre>
<p>This way you get a nice compiler warning if you type in arguments out of order:</p>
<pre><code>UserId e = new UserId() { Value = "a" };
DocumentId d = new DocumentId() { Value = "b" };
Database.HasAccess(d, e);
</code></pre>
<p>You also get the ability to change abstracted type in without affecting the rest of the system but that's not very likely. Would abstracting type be a good idea to get more type safety?</p>
<p>The question relates to C# solutions but short descriptions in other languages is welcome.</p>
<p>EDIT: Removed the implicit cast from string and pointing finger at the C# tag.</p>
|
[
{
"answer_id": 173994,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": true,
"text": "string user = \"fred\";\nSomeMethodThatWantsADocument(user);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23164/"
] |
173,995
|
<p>As a function argument I get a <code>vector<double>& vec</code> (an output vector, hence non-const) with unknown length and values. I want to initialise this vector to a specific length n with all zeroes.</p>
<p>This will work </p>
<pre><code>vec.clear();
vec.resize( n, 0.0 );
</code></pre>
<p>And this will work as well:</p>
<pre><code>vec.resize( n );
vec.assign( n, 0.0 );
</code></pre>
<p>Is the second more efficient (because no memory deallocation/allocation is involved)? Is there a more efficient way to do this? </p>
|
[
{
"answer_id": 173998,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "std::vector<double>(n).swap(vec);\n clear()"
},
{
"answer_id": 174571,
"author": "James Hopkin",
"author_id": 11828,
"author_profile": "https://Stackoverflow.com/users/11828",
"pm_score": 5,
"selected": true,
"text": "std::vector<double>(n).swap(vec);\n vec.assign(n, 0.);\nvec.shrink_to_fit();\n vec n shrink_to_fit"
},
{
"answer_id": 176247,
"author": "Matt Price",
"author_id": 852,
"author_profile": "https://Stackoverflow.com/users/852",
"pm_score": 2,
"selected": false,
"text": "vec.swap(std::vector<double>(n));\nstd::vector<double>(n).swap(vec);\nstd::swap(vector<double>(n), vec);\nstd::swap(vec, vector<double>(n));\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/173995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19863/"
] |
174,005
|
<p>I have an xml file providing data for a datagrid in Flex 2 that includes an unformatted Price field (ie: it is just a number).
Can anyone tell me how I take that datafield and format it - add a currency symbol, put in thousand separators etc.
Thanks.
S.</p>
|
[
{
"answer_id": 174608,
"author": "JustLogic",
"author_id": 21664,
"author_profile": "https://Stackoverflow.com/users/21664",
"pm_score": 2,
"selected": true,
"text": "<mx:DataGridColumn id=\"dgc\" headerText=\"Money\" editable=\"false\">\n <mx:itemRenderer>\n <mx:Component>\n <mx:HBox horizontalAlign=\"right\">\n <mx:CurrencyFormatter id=\"cFormat\" precision=\"2\" currencySymbol=\"$\" useThousandsSeparator=\"true\"/>\n <mx:Label id=\"lbl\" text=\"{cFormat.format(data)}\" />\n </mx:HBox>\n </mx:Component>\n </mx:itemRenderer>\n</mx:DataGridColumn>\n"
},
{
"answer_id": 176415,
"author": "user25463",
"author_id": 25463,
"author_profile": "https://Stackoverflow.com/users/25463",
"pm_score": 2,
"selected": false,
"text": "<mx:DataGridColumn headerText=\"Price\" textAlign=\"right\" labelFunction=\"formatCcy\" width=\"60\"/>\n\npublic function formatCcy(item:Object, column:DataGridColumn):String\n {\n return euroPrice.format(item.price);\n }\n\n<mx:CurrencyFormatter id=\"euroPrice\" precision=\"0\" \n rounding=\"none\"\n decimalSeparatorTo=\".\"\n thousandsSeparatorTo=\",\"\n useThousandsSeparator=\"true\"\n useNegativeSign=\"true\"\n currencySymbol=\"€\"\n alignSymbol=\"left\"/>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25463/"
] |
174,013
|
<p>My colleagues and I have tried to build a project containing several thousand classes , but we're getting a LNK1102 error ( Linker out of memory ) . I've seen several tips on the internet , such as increasing the virtual memory . We tried but this didn't help . We've also seen some as enabling different warning levels when compiling the code . A guy suggested enabling level 4 for warnings .
How could that be done ? Are there other suggestions ?</p>
|
[
{
"answer_id": 8400618,
"author": "Gerrit",
"author_id": 1083582,
"author_profile": "https://Stackoverflow.com/users/1083582",
"pm_score": 3,
"selected": false,
"text": "\"*LINK : fatal error LNK1102: out of memory*\"\n"
},
{
"answer_id": 46573303,
"author": "Pablo H",
"author_id": 6655648,
"author_profile": "https://Stackoverflow.com/users/6655648",
"pm_score": 1,
"selected": false,
"text": "fatal error LNK1102: out of memory set PreferredToolArchitecture=x64\n"
},
{
"answer_id": 57462089,
"author": "Teivaz",
"author_id": 3344612,
"author_profile": "https://Stackoverflow.com/users/3344612",
"pm_score": 0,
"selected": false,
"text": "CMAKE_GENERATOR_TOOLSET host=x64 CMakeLists.txt set(CMAKE_GENERATOR_TOOLSET \"host=x64\")\n -T host=x64\n"
},
{
"answer_id": 74085941,
"author": "Matthias Kuhn",
"author_id": 2319028,
"author_profile": "https://Stackoverflow.com/users/2319028",
"pm_score": 0,
"selected": false,
"text": "clang-cl -T ClangCL"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11234/"
] |
174,024
|
<p>Consider the following method signatures:</p>
<pre><code>public fooMethod (Foo[] foos) { /*...*/ }
</code></pre>
<p>and</p>
<pre><code>public fooMethod (Foo... foos) { /*...*/ }
</code></pre>
<p><em>Explanation: The former takes an array of Foo-objects as an argument - <code>fooMethod(new Foo[]{..})</code> - while the latter takes an arbitrary amount of arguments of type Foo, and presents them as an array of Foo:s within the method - <code>fooMethod(fooObject1, fooObject2, etc...</code>).</em></p>
<p>Java throws a fit if both are defined, claiming that they are duplicate methods. I did some detective work, and found out that the first declaration really requires an explicit array of Foo objects, and that's the only way to call that method. The second way actually accepts both an arbitrary amount of Foo arguments AND also accepts an array of Foo objects.</p>
<p>So, the question is, since the latter method seems more flexible, are there any reasons to use the first example, or have I missed anything vital?</p>
|
[
{
"answer_id": 174060,
"author": "TToni",
"author_id": 20703,
"author_profile": "https://Stackoverflow.com/users/20703",
"pm_score": 0,
"selected": false,
"text": "string Format(string formatString, object... args)\n string Join(string[] substrings, char concatenationCharacter)\n"
},
{
"answer_id": 174067,
"author": "skaffman",
"author_id": 21234,
"author_profile": "https://Stackoverflow.com/users/21234",
"pm_score": 2,
"selected": false,
"text": "void myMethod(String... values, int num);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174024",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2238/"
] |
174,025
|
<p>How do you trigger a javascript function using actionscript in flash?</p>
<p>The goal is to trigger jQuery functionality from a flash movie</p>
|
[
{
"answer_id": 174034,
"author": "jochil",
"author_id": 23794,
"author_profile": "https://Stackoverflow.com/users/23794",
"pm_score": 5,
"selected": true,
"text": "ExternalInterface.addCallback(\"sendToActionScript\", receivedFromJavaScript);\nExternalInterface.call(\"sendToJavaScript\", input.text);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174025",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2908/"
] |
174,059
|
<p>I'm developing a little project plan and I came to a point when I need to decide what local databse system to use.</p>
<p>The input data is going to be stored on webserver (hosting - MySQL DB). The idea is to build a process to download all necessary data (for example at midnight) and process them. However, there are going to be many inputs and stages of processing, so I need to use some kind of local database to store the semi-product of the application</p>
<p>What local database system would you recommend to work with C# (.NET) application?</p>
<p>edit: The final product (information) should be easily being exported back to Hosting MySQL DB.</p>
<p>As Will mentioned in his answer - yes, I'm for a performance AND comfort of use.</p>
|
[
{
"answer_id": 174114,
"author": "Goran",
"author_id": 23164,
"author_profile": "https://Stackoverflow.com/users/23164",
"pm_score": 1,
"selected": false,
"text": "IList<Users> list = Persistence.Database.Query<Users>(u => u.Name == \"Admin\");\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21209/"
] |
174,069
|
<p>How can I, in Java or using some other programming language, add a new program group in the applications menu in both KDE and Gnome? </p>
<p>I am testing with Ubuntu and Kubuntu 8. Putting a simple .menu file in ~/.config/menus/applications-merged worked in Kubuntu, but the same procedure does nothing in Ubuntu.</p>
<p>The content of my file is as follows:</p>
<pre><code><!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
<Menu>
<Menu>
<Name>My Program Group</Name>
<Include>
<Filename>shortcut.desktop</Filename>
</Include>
</Menu>
</Menu>
</code></pre>
<p>Note that the .desktop file is correctly placed in ~/.local/share/applications.</p>
<p>Ps: The original question did not specify I wanted a solution in a programmatic way.</p>
|
[
{
"answer_id": 174087,
"author": "oliver",
"author_id": 2148773,
"author_profile": "https://Stackoverflow.com/users/2148773",
"pm_score": 2,
"selected": true,
"text": "man xdg-desktop-menu"
},
{
"answer_id": 175169,
"author": "Thiago Chaves",
"author_id": 16873,
"author_profile": "https://Stackoverflow.com/users/16873",
"pm_score": 1,
"selected": false,
"text": "<!DOCTYPE Menu PUBLIC \"-//freedesktop//DTD Menu 1.0//EN\" \n \"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd\">\n<Menu>\n <Name>Applications</Name>\n<Menu>\n <Name>My Program Group</Name>\n <Include>\n <Filename>shortcut.desktop</Filename>\n </Include>\n</Menu>\n</Menu>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16873/"
] |
174,093
|
<p>Assuming I have an ArrayList</p>
<pre><code>ArrayList<MyClass> myList;
</code></pre>
<p>And I want to call toArray, is there a performance reason to use</p>
<pre><code>MyClass[] arr = myList.toArray(new MyClass[myList.size()]);
</code></pre>
<p>over</p>
<pre><code>MyClass[] arr = myList.toArray(new MyClass[0]);
</code></pre>
<p>?</p>
<p>I prefer the second style, since it's less verbose, and I assumed that the compiler will make sure the empty array doesn't really get created, but I've been wondering if that's true.</p>
<p>Of course, in 99% of the cases it doesn't make a difference one way or the other, but I'd like to keep a consistent style between my normal code and my optimized inner loops...</p>
|
[
{
"answer_id": 174108,
"author": "Panagiotis Korros",
"author_id": 19331,
"author_profile": "https://Stackoverflow.com/users/19331",
"pm_score": 2,
"selected": false,
"text": "MyClass[] arr = myList.toArray(new MyClass[0]);\n public <T> T[] toArray(T[] a) {\n if (a.length < size)\n a = (T[])java.lang.reflect.Array.\n newInstance(a.getClass().getComponentType(), size);\nSystem.arraycopy(elementData, 0, a, 0, size);\n if (a.length > size)\n a[size] = null;\n return a;\n}\n"
},
{
"answer_id": 174146,
"author": "Georgi",
"author_id": 13209,
"author_profile": "https://Stackoverflow.com/users/13209",
"pm_score": 7,
"selected": false,
"text": "MyClass[] arr = myList.toArray(new MyClass[myList.size()]);\n MyClass[] arr = myList.toArray(new MyClass[0]);\n public <T> T[] toArray(T[] a) {\n if (a.length < size)\n // Make a new array of a's runtime type, but my contents:\n return (T[]) Arrays.copyOf(elementData, size, a.getClass());\n System.arraycopy(elementData, 0, a, 0, size);\n if (a.length > size)\n a[size] = null;\n return a;\n}\n"
},
{
"answer_id": 29444594,
"author": "assylias",
"author_id": 829571,
"author_profile": "https://Stackoverflow.com/users/829571",
"pm_score": 8,
"selected": true,
"text": "MyClass[] arr = myList.toArray(new MyClass[0]);\n Benchmark (n) Mode Samples Score Error Units\nc.a.p.SO29378922.preSize 1 avgt 30 0.025 ▒ 0.001 us/op\nc.a.p.SO29378922.preSize 100 avgt 30 0.155 ▒ 0.004 us/op\nc.a.p.SO29378922.preSize 1000 avgt 30 1.512 ▒ 0.031 us/op\nc.a.p.SO29378922.preSize 5000 avgt 30 6.884 ▒ 0.130 us/op\nc.a.p.SO29378922.preSize 10000 avgt 30 13.147 ▒ 0.199 us/op\nc.a.p.SO29378922.preSize 100000 avgt 30 159.977 ▒ 5.292 us/op\nc.a.p.SO29378922.resize 1 avgt 30 0.019 ▒ 0.000 us/op\nc.a.p.SO29378922.resize 100 avgt 30 0.133 ▒ 0.003 us/op\nc.a.p.SO29378922.resize 1000 avgt 30 1.075 ▒ 0.022 us/op\nc.a.p.SO29378922.resize 5000 avgt 30 5.318 ▒ 0.121 us/op\nc.a.p.SO29378922.resize 10000 avgt 30 10.652 ▒ 0.227 us/op\nc.a.p.SO29378922.resize 100000 avgt 30 139.692 ▒ 8.957 us/op\n @State(Scope.Thread)\n@BenchmarkMode(Mode.AverageTime)\npublic class SO29378922 {\n @Param({\"1\", \"100\", \"1000\", \"5000\", \"10000\", \"100000\"}) int n;\n private final List<Integer> list = new ArrayList<>();\n @Setup public void populateList() {\n for (int i = 0; i < n; i++) list.add(0);\n }\n @Benchmark public Integer[] preSize() {\n return list.toArray(new Integer[n]);\n }\n @Benchmark public Integer[] resize() {\n return list.toArray(new Integer[0]);\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] |
174,119
|
<p>I see this often in the build scripts of projects that use autotools (autoconf, automake). When somebody wants to check the value of a shell variable, they frequently use this idiom:</p>
<pre><code>if test "x$SHELL_VAR" = "xyes"; then
...
</code></pre>
<p>What is the advantage to this over simply checking the value like this:</p>
<pre><code>if test $SHELL_VAR = "yes"; then
...
</code></pre>
<p>I figure there must be some reason that I see this so often, but I can't figure out what it is.</p>
|
[
{
"answer_id": 174156,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "SHELLVAR=$(true)\nif test $SHELLVAR = \"yes\" ; then echo \"yep\" ; fi \n\n# bash: test: =: unary operator expected\n if test $UNDEFINEDED = \"yes\" ; then echo \"yep\" ; fi\n# bash: test: =: unary operator expected\n SHELLVAR=\" hello\" \nif test $SHELLVAR = \"hello\" ; then echo \"yep\" ; fi\n# yep \n SHELLVAR=\" hello\"\nif test \"$SHELLVAR\" = \"hello\" ; then echo \"yep\" ; fi \n#<no output>\n SHELLVAR=\" hello\"\nif test \"x$SHELLVAR\" = \"xhello\" ; then echo \"yep\" ; fi \n"
},
{
"answer_id": 174288,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 8,
"selected": true,
"text": "SHELL_VAR if test $SHELL_VAR = yes; then --> if test = yes; then\nif test x$SHELL_VAR = xyes; then --> if test x = xyes; then\n test if test \"x$SHELL_VAR\" = \"xyes\"; then --> if test \"x\" = \"xyes\"; then\n x"
},
{
"answer_id": 174331,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 4,
"selected": false,
"text": "if [ -z \"$SOME_VAR\" ]; then\n echo \"this variable is not defined\"\nfi\n"
},
{
"answer_id": 180630,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 5,
"selected": false,
"text": "if [ \"$1\" = \"abc\" ]; then ...\n -n -z test xargs"
},
{
"answer_id": 38114348,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 3,
"selected": false,
"text": "if test \"yes\" = \"$SHELL_VAR\"; then\n x $SHELL_VAR -"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/78437/"
] |
174,143
|
<p>In SQL Server 2005, is there a way of deleting rows and being told how many were <strong>actually</strong> deleted? </p>
<p>I could do a <code>select count(*)</code> with the same conditions, but I need this to be utterly trustworthy. </p>
<p>My first guess was to use the <code>@@ROWCOUNT</code> variables - but that isn't set, e.g. </p>
<pre><code>delete
from mytable
where datefield = '5-Oct-2008'
select @@ROWCOUNT
</code></pre>
<p>always returns a 0. </p>
<p>MSDN suggests the <a href="http://msdn.microsoft.com/en-us/library/ms189835.aspx" rel="noreferrer"><code>OUTPUT</code></a> construction, e.g. </p>
<pre><code>delete from mytable
where datefield = '5-Oct-2008'
output datefield into #doomed
select count(*)
from #doomed
</code></pre>
<p>this actually fails with a syntax error. </p>
<p>Any ideas? </p>
|
[
{
"answer_id": 174158,
"author": "wcm",
"author_id": 2173,
"author_profile": "https://Stackoverflow.com/users/2173",
"pm_score": 7,
"selected": true,
"text": "SET NOCOUNT OFF"
},
{
"answer_id": 174178,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 3,
"selected": false,
"text": "@@ROWCOUNT SET NOCOUNT ON SET NOCOUNT @@ROWCOUNT SET NOCOUNT ON"
},
{
"answer_id": 21060985,
"author": "Adly",
"author_id": 1205392,
"author_profile": "https://Stackoverflow.com/users/1205392",
"pm_score": 3,
"selected": false,
"text": "SET NOCOUNT off ;\nSELECT @p1 = @@ROWCOUNT\n"
},
{
"answer_id": 28995439,
"author": "James L.",
"author_id": 822072,
"author_profile": "https://Stackoverflow.com/users/822072",
"pm_score": 1,
"selected": false,
"text": "@@rowcount delete from mytable \nwhere datefield = '5-Oct-2008' \noutput deleted.datefield into #doomed\n\nselect count(distinct datefield)\nfrom #doomed\n output deleted datefield"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2902/"
] |
174,153
|
<p>In C#, does anybody know why the following will compile:</p>
<pre><code>int i = 1;
++i;
i++;
</code></pre>
<p>but this will not compile?</p>
<pre><code>int i = 1;
++i++;
</code></pre>
<p>(Compiler error: The operand of an increment or decrement operator must be a variable, property or indexer.)</p>
|
[
{
"answer_id": 174160,
"author": "steffenj",
"author_id": 15328,
"author_profile": "https://Stackoverflow.com/users/15328",
"pm_score": -1,
"selected": false,
"text": "i += 2;\n"
},
{
"answer_id": 174182,
"author": "fluffels",
"author_id": 12828,
"author_profile": "https://Stackoverflow.com/users/12828",
"pm_score": 2,
"selected": false,
"text": "++i (i = 2, returns 2)\n2++ (nothing can happen here, because you can't write a value back into '2')\n"
},
{
"answer_id": 174222,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 3,
"selected": false,
"text": "5++;\n f(i)++;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
] |
174,155
|
<p>Switch statement fallthrough is one of my personal major reasons for loving <code>switch</code> vs. <code>if/else if</code> constructs. An example is in order here:</p>
<pre><code>static string NumberToWords(int number)
{
string[] numbers = new string[]
{ "", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };
string[] tens = new string[]
{ "", "", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety" };
string[] teens = new string[]
{ "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen" };
string ans = "";
switch (number.ToString().Length)
{
case 3:
ans += string.Format("{0} hundred and ", numbers[number / 100]);
case 2:
int t = (number / 10) % 10;
if (t == 1)
{
ans += teens[number % 10];
break;
}
else if (t > 1)
ans += string.Format("{0}-", tens[t]);
case 1:
int o = number % 10;
ans += numbers[o];
break;
default:
throw new ArgumentException("number");
}
return ans;
}
</code></pre>
<p>The smart people are cringing because the <code>string[]</code>s should be declared outside the function: well, they are, this is just an example.</p>
<p>The compiler fails with the following error:</p>
<pre>
Control cannot fall through from one case label ('case 3:') to another
Control cannot fall through from one case label ('case 2:') to another
</pre>
<p>Why? And is there any way to get this sort of behaviour without having three <code>if</code>s?</p>
|
[
{
"answer_id": 174183,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 3,
"selected": false,
"text": "switch (whatever)\n{\n case 1:\n case 2:\n case 3: boo; break;\n}\n"
},
{
"answer_id": 174191,
"author": "Coincoin",
"author_id": 42,
"author_profile": "https://Stackoverflow.com/users/42",
"pm_score": 5,
"selected": false,
"text": "switch(value)\n{\n case 1:// this is still legal\n case 2:\n}\n"
},
{
"answer_id": 174210,
"author": "Marcus",
"author_id": 25428,
"author_profile": "https://Stackoverflow.com/users/25428",
"pm_score": -1,
"selected": false,
"text": "case 3: \n{\n ans += string.Format(\"{0} hundred and \", numbers[number / 100]);\n break;\n}\n\n\ncase 2: \n{\n int t = (number / 10) % 10; \n if (t == 1) \n { \n ans += teens[number % 10]; \n } \n else if (t > 1) \n {\n ans += string.Format(\"{0}-\", tens[t]); \n }\n break;\n}\n\ncase 1: \n{\n int o = number % 10; \n ans += numbers[o]; \n break; \n}\n\ndefault: \n{\n throw new ArgumentException(\"number\");\n}\n"
},
{
"answer_id": 174223,
"author": "Alex Lyman",
"author_id": 5897,
"author_profile": "https://Stackoverflow.com/users/5897",
"pm_score": 10,
"selected": true,
"text": "switch case case case 0 goto case case 1 goto default case 2 switch (/*...*/) {\n case 0: // shares the exact same code as case 1\n case 1:\n // do something\n goto case 2;\n case 2:\n // do something else\n goto default;\n default:\n // do something entirely different\n break;\n}\n"
},
{
"answer_id": 174228,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": false,
"text": "switch (number.ToString().Length)\n{\n case 3:\n ans += string.Format(\"{0} hundred and \", numbers[number / 100]);\n goto case 2;\n case 2:\n // Etc\n}\n"
},
{
"answer_id": 3357232,
"author": "Dai Tran",
"author_id": 405000,
"author_profile": "https://Stackoverflow.com/users/405000",
"pm_score": 0,
"selected": false,
"text": "switch(num)\n{\n case 1:\n goto case 3;\n case 2:\n goto case 3;\n case 3:\n //do something\n break;\n case 4:\n //do something else\n break;\n case default:\n break;\n}\n"
},
{
"answer_id": 20470441,
"author": "Jon Hanna",
"author_id": 400547,
"author_profile": "https://Stackoverflow.com/users/400547",
"pm_score": 5,
"selected": false,
"text": "switch if-else switch if-else switch break switch if-else switch switch(x)\n{\n case 1:\n foo();\n /* FALLTHRU */\n case 2:\n bar();\n break;\n}\n goto switch(x)\n{\n case 0:\n case 1:\n case 2:\n foo();\n goto below_six;\n case 3:\n bar();\n goto below_six;\n case 4:\n baz();\n /* FALLTHRU */\n case 5:\n below_six:\n qux();\n break;\n default:\n quux();\n}\n goto switch case below_six goto case 5 break default break goto case goto case GOTO (x AND 7) * 50 + 240 goto nop"
},
{
"answer_id": 26232895,
"author": "gm2008",
"author_id": 2197555,
"author_profile": "https://Stackoverflow.com/users/2197555",
"pm_score": 0,
"selected": false,
"text": "break; default"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
174,163
|
<p>Is entity framework just a fancy name for another CRUD code generator?</p>
<p>Or is there more to it?</p>
|
[
{
"answer_id": 174183,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 3,
"selected": false,
"text": "switch (whatever)\n{\n case 1:\n case 2:\n case 3: boo; break;\n}\n"
},
{
"answer_id": 174191,
"author": "Coincoin",
"author_id": 42,
"author_profile": "https://Stackoverflow.com/users/42",
"pm_score": 5,
"selected": false,
"text": "switch(value)\n{\n case 1:// this is still legal\n case 2:\n}\n"
},
{
"answer_id": 174210,
"author": "Marcus",
"author_id": 25428,
"author_profile": "https://Stackoverflow.com/users/25428",
"pm_score": -1,
"selected": false,
"text": "case 3: \n{\n ans += string.Format(\"{0} hundred and \", numbers[number / 100]);\n break;\n}\n\n\ncase 2: \n{\n int t = (number / 10) % 10; \n if (t == 1) \n { \n ans += teens[number % 10]; \n } \n else if (t > 1) \n {\n ans += string.Format(\"{0}-\", tens[t]); \n }\n break;\n}\n\ncase 1: \n{\n int o = number % 10; \n ans += numbers[o]; \n break; \n}\n\ndefault: \n{\n throw new ArgumentException(\"number\");\n}\n"
},
{
"answer_id": 174223,
"author": "Alex Lyman",
"author_id": 5897,
"author_profile": "https://Stackoverflow.com/users/5897",
"pm_score": 10,
"selected": true,
"text": "switch case case case 0 goto case case 1 goto default case 2 switch (/*...*/) {\n case 0: // shares the exact same code as case 1\n case 1:\n // do something\n goto case 2;\n case 2:\n // do something else\n goto default;\n default:\n // do something entirely different\n break;\n}\n"
},
{
"answer_id": 174228,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": false,
"text": "switch (number.ToString().Length)\n{\n case 3:\n ans += string.Format(\"{0} hundred and \", numbers[number / 100]);\n goto case 2;\n case 2:\n // Etc\n}\n"
},
{
"answer_id": 3357232,
"author": "Dai Tran",
"author_id": 405000,
"author_profile": "https://Stackoverflow.com/users/405000",
"pm_score": 0,
"selected": false,
"text": "switch(num)\n{\n case 1:\n goto case 3;\n case 2:\n goto case 3;\n case 3:\n //do something\n break;\n case 4:\n //do something else\n break;\n case default:\n break;\n}\n"
},
{
"answer_id": 20470441,
"author": "Jon Hanna",
"author_id": 400547,
"author_profile": "https://Stackoverflow.com/users/400547",
"pm_score": 5,
"selected": false,
"text": "switch if-else switch if-else switch break switch if-else switch switch(x)\n{\n case 1:\n foo();\n /* FALLTHRU */\n case 2:\n bar();\n break;\n}\n goto switch(x)\n{\n case 0:\n case 1:\n case 2:\n foo();\n goto below_six;\n case 3:\n bar();\n goto below_six;\n case 4:\n baz();\n /* FALLTHRU */\n case 5:\n below_six:\n qux();\n break;\n default:\n quux();\n}\n goto switch case below_six goto case 5 break default break goto case goto case GOTO (x AND 7) * 50 + 240 goto nop"
},
{
"answer_id": 26232895,
"author": "gm2008",
"author_id": 2197555,
"author_profile": "https://Stackoverflow.com/users/2197555",
"pm_score": 0,
"selected": false,
"text": "break; default"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,170
|
<p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<hr>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'email.base64MIME']</h2>
<p>The executable does not work. The referenced modules are not included. I researched this on the Internet and I found out that py2exe has a problem with the Lazy import used in the standard lib email module. Unfortunately I have not succeeded in finding a workaround for this problem. Can anyone help?</p>
<p>Thank you,</p>
<p>P.S.
Imports in the script look like this:</p>
<p>Code: Select all
import string,time,sys,os,smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders</p>
|
[
{
"answer_id": 176305,
"author": "Tony Meyer",
"author_id": 4966,
"author_profile": "https://Stackoverflow.com/users/4966",
"pm_score": 2,
"selected": false,
"text": "import string,time,sys,os,smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.base import MIMEBase\nfrom email.mime.text import MIMEText\nfrom email import Encoders\n"
},
{
"answer_id": 1194697,
"author": "AdrianB",
"author_id": 146476,
"author_profile": "https://Stackoverflow.com/users/146476",
"pm_score": 0,
"selected": false,
"text": "import email\nimport email.mime.text\nimport email.mime.base\nimport email.mime.multipart\nimport email.iterators\nimport email.generator\nimport email.utils\n\ntry: \n from email.MIMEText import MIMEText\nexcept: \n from email.mime import text as MIMEText\n import modulefinder\nmodulefinder.AddPackagePath(\"mail.mime\", \"base\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"multipart\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"nonmultipart\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"audio\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"image\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"message\")\nmodulefinder.AddPackagePath(\"mail.mime\", \"application\")\n"
},
{
"answer_id": 18602374,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "includes = [\"email\"]\n"
},
{
"answer_id": 25947245,
"author": "Arbin Bulaybulay",
"author_id": 1484790,
"author_profile": "https://Stackoverflow.com/users/1484790",
"pm_score": 0,
"selected": false,
"text": "from distutils.core import setup\n import py2exe, sys, os\n\n sys.argv.append('py2exe')\n\n EXTRA_INCLUDES = [\n \"email.iterators\", \"email.generator\", \"email.utils\", \"email.base64mime\", \"email\", \"email.mime\",\n \"email.mime.multipart\", \"email.mime.text\", \"email.mime.base\",\n \"lxml.etree\", \"lxml._elementpath\", \"gzip\"\n ]\n\n setup(\n options = {'py2exe': {'bundle_files': 1, 'compressed': True, 'includes': EXTRA_INCLUDES,\n 'dll_excludes': ['w9xpopen.exe','MSVCR71.dll']}},\n console = [{'script': \"project_name.py\"}],\n zipfile = None,\n )\n"
},
{
"answer_id": 31598698,
"author": "K246",
"author_id": 3990239,
"author_profile": "https://Stackoverflow.com/users/3990239",
"pm_score": 1,
"selected": false,
"text": "setup(console = ['main.py'])\n setup(console = ['main.py'], \n options={\"py2exe\":{\"includes\":[\"email.mime.multipart\",\"email.mime.text\"]}})\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15539/"
] |
174,174
|
<p>Is Oracle Application Express suitable for Intranet client/server application?
If so, what should I do to enable client access to application?</p>
<hr>
<p>Well, I am working as a PowerBuilder/Oracle developer, so I am familiar with client/server architecture. I have recently read an article about APEX so I would like to develop APEX variation of my PowerBuilder/Oracle app, which is pretty much HR app. It should not be Internet accessible app, just a couple of windows boxes in a small network. I have no problem with developing app in PL/SQL and SQL (will have to read and ask a lot, though). I would just like to know is APEX suitable for Intranet app - it should be as it is suitable for Internet app :) - and how should I enable client's browser to access an application since there would be nothing like http:/www.appdomain.com ? I know next to nothing about win networks :)</p>
|
[
{
"answer_id": 174420,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 0,
"selected": false,
"text": "http://www.mydomain.com/pls/mydad/f?p=MYAPP\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4235/"
] |
174,190
|
<p>I have a Rails application for project management where there are Project and Task models. A project can have many tasks, but a task can also have many tasks, ad infinitum.</p>
<p>Using nested resources, we can have /projects/1/tasks, /projects/1/tasks/new, /projects/1/tasks/3/edit etc.</p>
<p>However, how do you represent the recursive nature of tasks RESTfully? I don't want go another level deep, so perhaps the following would do:</p>
<pre><code>map.resources :tasks do |t|
t.resources :tasks
end
</code></pre>
<p>That would give me the following urls:</p>
<pre><code>/tasks/3/tasks/new
/tasks/3/tasks/45/edit
</code></pre>
<p>Or perhaps when it comes to an individual task I can just use /tasks/45/edit</p>
<p>Is this a reasonable design?</p>
<p>Cam</p>
|
[
{
"answer_id": 175449,
"author": "Steropes",
"author_id": 21872,
"author_profile": "https://Stackoverflow.com/users/21872",
"pm_score": 2,
"selected": false,
"text": "belongs_to :project\nbelongs_to :parent, :class_name => \"Task\"\nhas_many :children, :class_name => \"Task\", :foreign_key => \"parent_id\"\n def do_something(task)\n task.children.each do |child|\n puts \"Something!\"\n do_something(child)\n end\nend \n /project/:project_id/task/:task_id\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25484/"
] |
174,193
|
<p>I'm doing some architectural cleanup that involves moving a bunch of classes into different projects and/or namespaces. Currently I'm moving the files by hand, building, and then manually adding <em>using Foo</em> statements as needed to resolve compilation errors. Anyone know of a smarter way of doing this? (We're a CodeRush and Refactor! shop, but I'd be interested to hear if Resharper has support for this)</p>
|
[
{
"answer_id": 41238746,
"author": "Gusdor",
"author_id": 286976,
"author_profile": "https://Stackoverflow.com/users/286976",
"pm_score": 3,
"selected": false,
"text": "MyCorp.AppStuff.Api MyCorp.AppStuff.Api.Extensions"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23632/"
] |
174,198
|
<p>With the new approach of having the get/set within the attribut of the class like that :</p>
<pre><code>public string FirstName {
get; set;
}
</code></pre>
<p>Why simply not simply put the attribute FirstName public without accessor?</p>
|
[
{
"answer_id": 174221,
"author": "Phil Wright",
"author_id": 6276,
"author_profile": "https://Stackoverflow.com/users/6276",
"pm_score": 0,
"selected": false,
"text": "public string FirstName { }\n"
},
{
"answer_id": 205567,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 0,
"selected": false,
"text": "public class MyClass : IMyClass\n{\n public static IMyClass New(...)\n {\n return new MyClass(...);\n }\n}\n"
},
{
"answer_id": 208601,
"author": "Mathieu Garstecki",
"author_id": 22078,
"author_profile": "https://Stackoverflow.com/users/22078",
"pm_score": 2,
"selected": false,
"text": "public int Foo { get; private set; }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21386/"
] |
174,225
|
<p>I would like to write a small application that unlocks the workstation. To put the specs of what I need very simple: Have an exe that runs and at a defined time (let's say midnight) unlocks the workstation.
Of course the application knows the user and password of the logged on account.</p>
<p>I know of the LogonUser API and have tried using it but failed.
Does anyone have a solution, code excerpt that actually works for this issue?</p>
<p>I am targeting NT5 OSes.</p>
<hr>
<p>Well, since people started asking what is the reason: I am working on a desktop sharing application and I want to add the feature of unlocking the workstation. Having the very small and simple app to unlock the station at a defined time is in order to separate the problem and to avoid the integration details.</p>
|
[
{
"answer_id": 7934209,
"author": "zomf",
"author_id": 175269,
"author_profile": "https://Stackoverflow.com/users/175269",
"pm_score": 0,
"selected": false,
"text": "tscon.exe 0 /dest:console\n tscon.exe 1 /dest:console\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24873/"
] |
174,232
|
<p>Basically I'm trying to accomplish the same thing that "mailto:bgates@microsoft.com" does in Internet Explorer Mobile.</p>
<p>But I want to be able to do it from a managed Windows Mobile application. I don't want to send an email pro grammatically in the background.</p>
<p>I want to be able to create the email in Pocket Outlook and then let the user do the rest.</p>
<p>Hopefully that helps you hopefully help me!</p>
|
[
{
"answer_id": 174312,
"author": "Petros",
"author_id": 2812,
"author_profile": "https://Stackoverflow.com/users/2812",
"pm_score": 4,
"selected": true,
"text": "ProcessStartInfo psi = \n new ProcessStartInfo(\"mailto:bla@bla.com?subject=MySubject\", \"\");\nProcess.Start(psi);\n"
},
{
"answer_id": 302078,
"author": "Jake Stevenson",
"author_id": 22383,
"author_profile": "https://Stackoverflow.com/users/22383",
"pm_score": 2,
"selected": false,
"text": "OutlookSession sess = new OutlookSession();\nEmailAccountCollection accounts = sess.EmailAccounts;\n//Contains all accounts on the device \n//I'll just choose the first one -- you might want to ask them\nMessagingApplication.DisplayComposeForm(accounts[0], \n \"someone@somewhere.com\", \"The Subject\", \"The Body\");\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174232",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23294/"
] |
174,239
|
<p>I have inherited a c# class 'Button' (which I can't change) which clashes with the BCL class 'Windows.Forms.Button'. Normally, Id be very happy to go:</p>
<pre><code>MyPackage.MyClass.Button;
</code></pre>
<p>But there are a large number or references to this class which is a pain to have to re-type.</p>
<p>Is there any way to get the compiler (linker?) to default to using the customised version of Button over the BCL version?</p>
|
[
{
"answer_id": 174252,
"author": "Vincent McNabb",
"author_id": 16299,
"author_profile": "https://Stackoverflow.com/users/16299",
"pm_score": 2,
"selected": false,
"text": "using Windows.Forms;"
},
{
"answer_id": 174257,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 5,
"selected": true,
"text": "using MyButton = MyPackage.MyClass.Button;\n"
},
{
"answer_id": 174265,
"author": "Mr. Mark",
"author_id": 19274,
"author_profile": "https://Stackoverflow.com/users/19274",
"pm_score": 0,
"selected": false,
"text": "using MPMC = MyPackage.MyClass;\n MPMC.Button\n"
},
{
"answer_id": 174273,
"author": "Philip Rieck",
"author_id": 12643,
"author_profile": "https://Stackoverflow.com/users/12643",
"pm_score": 2,
"selected": false,
"text": "using Windows.Forms;\n using MyPackage.MyClass;\n using My = MyPackage.MyClass;\n//... then\nMy.Button b = ...\n using MyButton = MyPackage.MyClass.Button;\n"
},
{
"answer_id": 174293,
"author": "TK.",
"author_id": 1816,
"author_profile": "https://Stackoverflow.com/users/1816",
"pm_score": 0,
"selected": false,
"text": "using Button = MyPackage.MyClass.Button;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1816/"
] |
174,248
|
<p>Our customer would like to know <strong>who</strong> is online and currently using the custom application we wrote for them. I discussed it with them and this does not need to be <strong>exact</strong>, more of a guestimate will work. </p>
<p>So my thought is a 15 minute time interval to determine user activity. Some ideas I have for doing this are as follows:</p>
<ol>
<li><p>Stamp their user record with a date and time of their last activity every time they do something that hits the database, or requests a web page ... this though could be quite database intensive.</p></li>
<li><p>Send out a "who is online request" from our software, looking for responses, this could be done at a scheduled interval, and then stamp the user record with the current date and time for each response I received.</p></li>
</ol>
<p>What are your thoughts? And how would you handle this situation?</p>
<p><strong>Clarification</strong></p>
<p>I would like to use the same architecture for both Windows or the Web if possible. I have a single business logic layer that multiple user interfaces interact with, could be Windows or the Web.</p>
<p>By Windows I would mean client-server.</p>
<p><strong>Clarification</strong></p>
<p>I am using an n-tier architecture so my business objects handle all the interaction with the presentation layer. That presentation layer could be feeding a client-server Windows application, Web application, Web Service and so on. </p>
<p>It is not a high traffic application, as it was developed for a customer of ours, maybe 100 users at most.</p>
|
[
{
"answer_id": 174310,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 0,
"selected": false,
"text": "public class ActiveSessionsListener implements HttpSessionListener {\n public void sessionCreated(HttpSessionEvent e) {\n ServletContext ctx = e.getSession().getServletContext();\n synchronized (ctx) {\n Integer count = ctx.getAttribute(\"SESSION_COUNT\");\n if (count == null) { count = new Integer(0); }\n ctx.setAttribute(\"SESSION_COUNT\", new Integer(count.intValue() + 1);\n }\n }\n public void sessionDestroyed(HttpSessionEvent e) {\n ... similar for decrement ... \n }\n}\n <listener-class>com.acme.ActiveSessionsListener</listener-class>\n"
},
{
"answer_id": 55324300,
"author": "ArabianMaiden",
"author_id": 6266364,
"author_profile": "https://Stackoverflow.com/users/6266364",
"pm_score": 0,
"selected": false,
"text": "<?php\nfunction updateLastSeen($user_ref, $session_id, $db) { /*Parameters: The user's primary key, the user's session id, the connection to the database*/\n $timestamp = date('Y-m-d H:i:s');\n if ($session_id !== '') {\n /*logged in*/\n $sql_check = \"SELECT user_id FROM user_last_seen WHERE user_id = ?\";\n $stmt_check = $db->prepare($sql_check);\n $stmt_check->bind_param('s', $user_ref);\n $result_check = $stmt_check->execute();\n $stmt_result_check = $stmt_check->get_result();\n if ($stmt_result_check->num_rows > 0) { /*If the user's last seen was previously recorded, update his record*/\n $sql = \"UPDATE user_last_seen SET last_seen = ? WHERE user_id = ?\"; \n } else { /*Otherwise, insert a record for him*/\n $sql = \"INSERT INTO user_last_seen (last_seen, user_id) VALUES (?,?)\";\n }\n $stmt = $db->prepare($sql);\n $stmt->bind_param('ss', $timestamp, $user_ref);\n $result = $stmt->execute();\n }\n}\nif( !isset($_SESSION['lastSeen']) ){ /*User logs into the website or lands on the current page, create a lastSeen variable*/\n $_SESSION['lastSeen'] = time();\n updateLastSeen($user_ref, $session_id, $db);\n} else {\n $last_seen_time_difference = (time() - $_SESSION['lastSeen']) / 60;\n if ($last_seen_time_difference > 5) { //if the difference between now and the lastSeen is 5 minutes or more, record his last seen.\n updateLastSeen($user_ref, $session_id, $db); \n $_SESSION['lastSeen'] = time(); /*after updating the database, reset the lastSeen time to now.*/\n }/* else {\n //do nothing. Don't update database if lastSeen is less than 5 minutes ago. This prevents unnecessary database hits.\n }*/\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174248",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1768/"
] |
174,263
|
<p>This may be simple one, but 5 mins of Googling didn't give me the answer.
How do you save and load bitmaps using .Net librabries?</p>
<p>I have an Image object and I need to save it to disk in some format (preferably png) and load back in later.
A C# example would be great.</p>
|
[
{
"answer_id": 174279,
"author": "Vincent McNabb",
"author_id": 16299,
"author_profile": "https://Stackoverflow.com/users/16299",
"pm_score": 5,
"selected": true,
"text": "using System.Drawing;\n Image test = new Bitmap(\"picture.bmp\");\ntest.Save(\"picture.png\", System.Drawing.Imaging.ImageFormat.Png);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1660/"
] |
174,285
|
<p>When I open a solution in VS 2008, I don't want it to open all the files that I had open last time. I just want it to open the solution. Can't see a config option for this, is it possible?</p>
|
[
{
"answer_id": 174307,
"author": "Bob Dizzle",
"author_id": 9581,
"author_profile": "https://Stackoverflow.com/users/9581",
"pm_score": 1,
"selected": false,
"text": "Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing\n DTE.ExecuteCommand(\"Window.CloseAllDocuments\")\nEnd Sub\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,292
|
<p>The array has lots of data and I need to delete two elements. </p>
<p>Below is the code snippet I am using,</p>
<pre><code>my @array = (1,2,3,4,5,5,6,5,4,9);
my $element_omitted = 5;
@array = grep { $_ != $element_omitted } @array;
</code></pre>
|
[
{
"answer_id": 174313,
"author": "SquareCog",
"author_id": 15962,
"author_profile": "https://Stackoverflow.com/users/15962",
"pm_score": 7,
"selected": true,
"text": "my $index = 0;\n$index++ until $arr[$index] eq 'foo';\nsplice(@arr, $index, 1);\n my @del_indexes = grep { $arr[$_] eq 'foo' } 0..$#arr;\n"
},
{
"answer_id": 174860,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 2,
"selected": false,
"text": "splice sub array_remove ( \\@& ) { \n my ( $arr_ref, $test_block ) = @_;\n my $sp_start = 0;\n my $sp_len = 0;\n for ( my $inx = 0; $inx <= $#$arr_ref; $inx++ ) {\n local $_ = $arr_ref->[$inx];\n next unless $test_block->( $_ );\n if ( $sp_len > 0 && $inx > $sp_start + $sp_len ) {\n splice( @$arr_ref, $sp_start, $sp_len );\n $inx = $inx - $sp_len;\n $sp_len = 0;\n }\n $sp_start = $inx if ++$sp_len == 1;\n }\n splice( @$arr_ref, $sp_start, $sp_len ) if $sp_len > 0;\n return;\n}\n"
},
{
"answer_id": 11906012,
"author": "Tom Lime",
"author_id": 775159,
"author_profile": "https://Stackoverflow.com/users/775159",
"pm_score": 2,
"selected": false,
"text": "my @arr = ('1','2','3','4','3','2', '3','4','3');\nmy @dix = grep { $arr[$_] eq '4' } 0..$#arr;\nmy $o = 0;\nfor (@dix) {\n splice(@arr, $_-$o, 1);\n $o++;\n}\nprint join(\"\\n\", @arr);\n @arr $_-current_loop_step"
},
{
"answer_id": 14191738,
"author": "dean",
"author_id": 1954333,
"author_profile": "https://Stackoverflow.com/users/1954333",
"pm_score": 3,
"selected": false,
"text": "my @del_indexes = grep { $arr[$_] eq 'foo' } 0..$#arr;\n my @del_indexes = reverse(grep { $arr[$_] eq 'foo' } 0..$#arr);\n foreach $item (@del_indexes) {\n splice (@arr,$item,1);\n}\n"
},
{
"answer_id": 14766395,
"author": "Ariel Monaco",
"author_id": 445845,
"author_profile": "https://Stackoverflow.com/users/445845",
"pm_score": 2,
"selected": false,
"text": "delete $array[$index];\n"
},
{
"answer_id": 15381061,
"author": "BBT",
"author_id": 2164625,
"author_profile": "https://Stackoverflow.com/users/2164625",
"pm_score": 0,
"selected": false,
"text": "my @adoSymbols=('SB.1000','RT.10000','PC.10000');\n##Remove items from an array from backward\nfor(my $i=$#adoSymbols;$i>=0;$i--) { \n unless ($adoSymbols[$i] =~ m/^SB\\.1/) {splice(@adoSymbols,$i,1);}\n}\n"
},
{
"answer_id": 23017956,
"author": "Rich",
"author_id": 1222662,
"author_profile": "https://Stackoverflow.com/users/1222662",
"pm_score": 2,
"selected": false,
"text": "\nperl -le '@ar=(1 .. 20);@x=(8,10,3,17);$x=join(\"|\",@x);@ar=grep{!/^(?:$x)$/o} @ar;print \"@ar\"'\n"
},
{
"answer_id": 36719021,
"author": "Federico",
"author_id": 6225021,
"author_profile": "https://Stackoverflow.com/users/6225021",
"pm_score": 2,
"selected": false,
"text": "foreach $index ( @list_of_indexes_to_be_skiped ) {\n undef($array[$index]);\n}\n@array = grep { defined($_) } @array;\n"
},
{
"answer_id": 47399712,
"author": "oryan_dunn",
"author_id": 3362479,
"author_profile": "https://Stackoverflow.com/users/3362479",
"pm_score": 3,
"selected": false,
"text": "my @arr = ...;\n# run through each item.\nmy @indicesToKeep = grep { $arr[$_] ne 'foo' } 0..$#arr;\n@arr = @arr[@indicesToKeep];\n"
},
{
"answer_id": 54716603,
"author": "Gilles Maisonneuve",
"author_id": 3676932,
"author_profile": "https://Stackoverflow.com/users/3676932",
"pm_score": 1,
"selected": false,
"text": " use Benchmark;\n my @A=qw(A B C A D E A F G H A I J K L A M N);\n my @M1; my @G; my @M2;\n my @Ashrunk;\n timethese( 1000000, {\n 'map1' => sub {\n my $i=0;\n @M1 = map { $i++; $_ eq 'A' ? $i-1 : ();} @A;\n },\n 'map2' => sub {\n my $i=0;\n @M2 = map { $A[$_] eq 'A' ? $_ : () ;} 0..$#A;\n },\n 'grep' => sub {\n @G = grep { $A[$_] eq 'A' } 0..$#A;\n },\n 'grem' => sub {\n @Ashrunk = grep { $_ ne 'A' } @A;\n },\n });\n Benchmark: timing 1000000 iterations of grem, grep, map1, map2...\n grem: 4 wallclock secs ( 3.37 usr + 0.00 sys = 3.37 CPU) @ 296823.98/s (n=1000000)\n grep: 3 wallclock secs ( 2.95 usr + 0.00 sys = 2.95 CPU) @ 339213.03/s (n=1000000)\n map1: 4 wallclock secs ( 4.01 usr + 0.00 sys = 4.01 CPU) @ 249438.76/s (n=1000000)\n map2: 2 wallclock secs ( 3.67 usr + 0.00 sys = 3.67 CPU) @ 272702.48/s (n=1000000)\nM1 = 0 3 6 10 15\nM2 = 0 3 6 10 15\nG = 0 3 6 10 15\nAshrunk = B C D E F G H I J K L M N\n"
},
{
"answer_id": 57323341,
"author": "Chetan",
"author_id": 2486083,
"author_profile": "https://Stackoverflow.com/users/2486083",
"pm_score": 3,
"selected": false,
"text": "my $input_Color = 'Green';\nmy @array = qw(Red Blue Green Yellow Black);\n@array = grep {!/$input_Color/} @array;\nprint \"@array\";\n"
},
{
"answer_id": 67238432,
"author": "Jacques",
"author_id": 4814971,
"author_profile": "https://Stackoverflow.com/users/4814971",
"pm_score": 0,
"selected": false,
"text": "my @array = (1,2,3,4,5,5,6,5,4,9);\nmy $element_omitted = 5;\nfor( my $i = 0; $i < scalar( @array ); $i++ )\n{\n splice( @array, $i ), $i-- if( $array[$i] == $element_omitted );\n}\nsay \"@array\"; # 1 2 3 4 6 4 9\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21246/"
] |
174,308
|
<p>Eclipse is a really great editor, which I prefer to use, but the GUI design tools for Eclipse are lacking. On the other hand, NetBeans works really well for GUI design. </p>
<p>Are there any tips, tricks or pitfalls for using NetBeans for GUI design and Eclipse for everything else on the same project?</p>
<p><strong>EDIT:</strong> I tried Maven, and it does not seem to work (too complex for my needs).</p>
|
[
{
"answer_id": 1492065,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n <name>MyProject</name>\n <comment></comment>\n <projects>\n </projects>\n <buildSpec>\n <buildCommand>\n <name>org.eclipse.jdt.core.javabuilder</name>\n <arguments>\n </arguments>\n </buildCommand>\n </buildSpec>\n <natures>\n <nature>org.eclipse.jdt.core.javanature</nature>\n </natures>\n</projectDescription>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17712/"
] |
174,309
|
<p>I'm building an interface much like the built-in Weather application's flipside view, or the Alarms view of the Clock application in editing mode. The table view is always in editing mode, so the delete icon appears on the left side of each cell.</p>
<p>When the table view is in editing mode, my delegate doesn't receive <code>didSelectRowAtIndexPath</code> notifications. It receives <code>accessoryButtonTappedForRowWithIndexPath</code> notifications, but that's not what I want to do. I want my rows to stay selectable, even when the table view is in editing mode.</p>
<p>Any ideas on how I can accomplish this?</p>
<p>Thanks,</p>
<p>P.S. Hooray for the lifted NDA. =)</p>
|
[
{
"answer_id": 174603,
"author": "millenomi",
"author_id": 6061,
"author_profile": "https://Stackoverflow.com/users/6061",
"pm_score": 8,
"selected": true,
"text": "table.allowsSelectionDuringEditing YES"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2119/"
] |
174,319
|
<p>What's the difference between the Enabled and the ReadOnly-properties of an asp:TextBox control?</p>
|
[
{
"answer_id": 174328,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 7,
"selected": true,
"text": "disabled readonly"
},
{
"answer_id": 174338,
"author": "Corey Trager",
"author_id": 9328,
"author_profile": "https://Stackoverflow.com/users/9328",
"pm_score": 2,
"selected": false,
"text": "<html>\n<form action=foo.html method=get>\n<input name=dis type=text disabled value=\"dis\">\n<input name=read type=text readonly value=\"read\">\n<input name=normal type=text value=\"normal\">\n<input type=submit>\n</form>\n</html>\n"
},
{
"answer_id": 8902345,
"author": "rodrigocl",
"author_id": 1102773,
"author_profile": "https://Stackoverflow.com/users/1102773",
"pm_score": 4,
"selected": false,
"text": "readonly = 'true' click Enabled = False"
},
{
"answer_id": 30255127,
"author": "kavitha Reddy",
"author_id": 3073215,
"author_profile": "https://Stackoverflow.com/users/3073215",
"pm_score": 2,
"selected": false,
"text": "<asp:TextBox ID=\"t\" runat=\"server\" Style=\"margin-left: 20px; margin-top: 24px;\"\nWidth=\"335px\" Height=\"41px\" ReadOnly=\"true\"></asp:TextBox>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11682/"
] |
174,322
|
<p>I would like to know how much disk space a directory is going to consume before I bring it over from the Perforce server. I don't see any way to do this other than getting the files and looking at the size of the directory in a file manager. This, of course, defeats the purpose. </p>
<p>Is there a way to get file size info from Perforce without actually getting the files?</p>
|
[
{
"answer_id": 174335,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "p4 fstat"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174322",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4228/"
] |
174,348
|
<p>Will content requested over https still be cached by web browsers or do they consider this insecure behaviour? If this is the case is there anyway to tell them it's ok to cache?</p>
|
[
{
"answer_id": 174485,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 8,
"selected": true,
"text": "max-age Cache-Control Cache-Control: max-age=3600\n"
},
{
"answer_id": 174510,
"author": "MarkR",
"author_id": 13724,
"author_profile": "https://Stackoverflow.com/users/13724",
"pm_score": 8,
"selected": false,
"text": "cache-control:public"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21030/"
] |
174,349
|
<p>By default, in C++, a single-argument constructor can be used as an implicit conversion operator. This can be suppressed by marking the constructor as explicit.</p>
<p>I'd prefer to make "explicit" be the default, so that the compiler cannot silently use these constructors for conversion.</p>
<p>Is there a way to do this in standard C++? Failing that, is there a pragma (or similar) that'll work in Microsoft C++ to do this? What about g++ (we don't use it, but it might be useful information)?</p>
|
[
{
"answer_id": 174450,
"author": "MSalters",
"author_id": 15416,
"author_profile": "https://Stackoverflow.com/users/15416",
"pm_score": 1,
"selected": false,
"text": "<vector>"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8446/"
] |
174,352
|
<p>I currently have a DetailsView in ASP.NET that gets data from the database based on an ID passed through a QueryString. What I've been trying to do now is to then use that same ID in a new cookie that is created when a user clicks either a ButtonField or a HyperLinkField.</p>
<p>What I have in the .aspx is this:</p>
<pre><code><asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ArtID"
DataSourceID="AccessDataSource1" Height="50px" Width="125px">
<Fields>
<asp:ImageField DataAlternateTextField="Title" DataImageUrlField="FileLocation">
</asp:ImageField>
<asp:BoundField DataField="ArtID" HeaderText="ArtID" InsertVisible="False" ReadOnly="True"
SortExpression="ArtID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="ArtDate" HeaderText="ArtDate" SortExpression="ArtDate" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="FileLocation" HeaderText="FileLocation" SortExpression="FileLocation" />
<asp:BoundField DataField="Medium" HeaderText="Medium" SortExpression="Medium" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="PageViews" HeaderText="PageViews" SortExpression="PageViews" />
<asp:HyperLinkField DataNavigateUrlFields="ArtID" DataNavigateUrlFormatString="Purchase.aspx?ArtID={0}"
NavigateUrl="Purchase.aspx" Text="Add To Cart" />
<asp:ButtonField ButtonType="Button" DataTextField="ArtID" Text="Add to Cart" CommandName="btnAddToCart_Click" />
</Fields>
</asp:DetailsView>
</code></pre>
<p>When using a reguler asp.net button such as:</p>
<pre><code><asp:Button ID="btnAddArt" runat="server" Text="Add To Cart" />
</code></pre>
<p>I would have something like this in the VB:</p>
<pre><code>Protected Sub btnAddArt_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddArt.Click
Dim CartArtID As New HttpCookie("CartArtID")
CartArtID.Value = ArtID.DataField
CartArtID.Expires = Date.Today.AddDays(0.5)
Response.Cookies.Add(CartArtID)
Response.Redirect("Purchase.aspx")
End Sub
</code></pre>
<p>However, I can't figure out how I go about applying this to the ButtonField instead since the ButtonField does not allow me to give it an ID.</p>
<p>The ID that I need to add to the cookie is the ArtID in the first BoundField.</p>
<p>Any idea's/advice on how I would go about doing this are greatly appreciated!</p>
<p>Alternatively, if I could do it with the HyperLinkField or with the regular button, that would be just as good, but I'm having trouble using a regular button to access the ID within the DetailsView.</p>
<p>Thanks</p>
|
[
{
"answer_id": 174957,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 2,
"selected": true,
"text": "<asp:Button ID=\"btnAddArt\" CommandName=\"AddCard\" CommandArgument=\"[ArtID]\" runat=\"server\" Text=\"Add To Cart\" />\n Private Sub ProcessDetailsViewCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles DetailsView1.ItemCommand\n\n' Using Case statement makes it easy to add more custom commands later on.\nSelect Case e.CommandName\n\n Case \"AddCard\"\n Dim CartArtID As New HttpCookie(\"CartArtID\")\n CartArtID.Value = Integer.Parse(e.CommandArgument.ToString)\n CartArtID.Expires = Date.Today.AddDays(0.5)\n Response.Cookies.Add(CartArtID)\n Response.Redirect(\"Purchase.aspx\")\n\n End Select\nEnd Sub\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17020/"
] |
174,356
|
<p>I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I would like to use constants instead of these numbers to make the code somewhat more expressive (in fact they will map to the names/values used to document the registers).</p>
<p>However, I'm concerned that with the volume of changes I might break the magic numbers. Here is a simplified example (the register set is more complex):</p>
<pre><code>const short mode0 = 0;
const short mode1 = 1;
const short mode2 = 2;
const short state0 = 0;
const short state1 = 4;
const short state2 = 8;
</code></pre>
<p>so instead of :</p>
<pre><code>set_register(5);
</code></pre>
<p>we have:</p>
<pre><code>set_register(state1|mode1);
</code></pre>
<p>What I'm looking for is a <strong>build time</strong> version of:</p>
<pre><code>ASSERT(5==(state1|mode1));
</code></pre>
<p><strong>Update</strong></p>
<p>@Christian, thanks for the quick response, I'm interested on a C / non-boost environment answer too because this is driver/kernel code.</p>
|
[
{
"answer_id": 174378,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 4,
"selected": false,
"text": "#define STATIC_ASSERT(x) \\\n do { \\\n const static char dummy[(x)?1:-1] = {0};\\\n } while(0)\n"
},
{
"answer_id": 174413,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 2,
"selected": false,
"text": "#if 5 != (state1|mode1)\n# error \"aaugh!\"\n#endif\n #define BUILD_BUG_ON #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))\n condition ((void)sizeof(char[-1])) ((void)sizeof(char[1]))"
},
{
"answer_id": 174424,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 3,
"selected": false,
"text": "#define STATIC_ASSERT(x, error) \\\ndo { \\\n static const char error[(x)?1:-1];\\\n} while(0)\n STATIC_ASSERT(a == b, a_not_equal_to_b);\n"
},
{
"answer_id": 174441,
"author": "Kevin",
"author_id": 6386,
"author_profile": "https://Stackoverflow.com/users/6386",
"pm_score": 6,
"selected": true,
"text": "#ifdef __GNUC__\n#define STATIC_ASSERT_HELPER(expr, msg) \\\n (!!sizeof \\ (struct { unsigned int STATIC_ASSERTION__##msg: (expr) ? 1 : -1; }))\n#define STATIC_ASSERT(expr, msg) \\\n extern int (*assert_function__(void)) [STATIC_ASSERT_HELPER(expr, msg)]\n#else\n #define STATIC_ASSERT(expr, msg) \\\n extern char STATIC_ASSERTION__##msg[1]; \\\n extern char STATIC_ASSERTION__##msg[(expr)?1:2]\n#endif /* #ifdef __GNUC__ */\n STATIC_ASSERT(1==1, test_message); line 22: error: negative width in bit-field `STATIC_ASSERTION__test_message'\n test.c(22) : error C2369: 'STATIC_ASSERTION__test_message' : redefinition; different subscripts\n test.c(22) : see declaration of 'STATIC_ASSERTION__test_message'\n line 22: error: declaration is incompatible with\n \"char STATIC_ASSERTION__test_message[1]\" (declared at line 22)\n #define STATIC_ASSERT(expr, msg) \\\n{ \\\n char STATIC_ASSERTION__##msg[(expr)?1:-1]; \\\n (void)STATIC_ASSERTION__##msg[0]; \\\n}\n #define GLOBAL_STATIC_ASSERT(expr, msg) \\\n extern char STATIC_ASSERTION__##msg[1]; \\\n extern char STATIC_ASSERTION__##msg[(expr)?1:2]\n"
},
{
"answer_id": 174742,
"author": "jwfearn",
"author_id": 10559,
"author_profile": "https://Stackoverflow.com/users/10559",
"pm_score": 3,
"selected": false,
"text": "static_assert"
},
{
"answer_id": 175216,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": false,
"text": "BOOST_STATIC_ASSERT c_assert.h STATIC_ASSERT() STATIC_ASSERT_EX() STATIC_ASSERT() /*\n Define macros to allow compile-time assertions.\n\n If the expression is false, an error something like\n\n test.c(9) : error XXXXX: negative subscript\n\n will be issued (the exact error and its format is dependent\n on the compiler).\n\n The techique used for C is to declare an extern (which can be used in\n file or block scope) array with a size of 1 if the expr is TRUE and\n a size of -1 if the expr is false (which will result in a compiler error).\n A counter or line number is appended to the name to help make it unique. \n Note that this is not a foolproof technique, but compilers are\n supposed to accept multiple identical extern declarations anyway.\n\n This technique doesn't work in all cases for C++ because extern declarations\n are not permitted inside classes. To get a CPP_ASSERT(), there is an \n implementation of something similar to Boost's BOOST_STATIC_ASSERT(). Boost's\n approach uses template specialization; when expr evaluates to 1, a typedef\n for the type \n\n ::interslice::StaticAssert_test< sizeof( ::interslice::StaticAssert_failed<true>) >\n\n which boils down to \n\n ::interslice::StaticAssert_test< 1>\n\n which boils down to \n\n struct StaticAssert_test\n\n is declared. If expr is 0, the compiler will be unable to find a specialization for\n\n ::interslice::StaticAssert_failed<false>.\n\n STATIC_ASSERT() or C_ASSERT should work in either C or C++ code (and they do the same thing)\n\n CPP_ASSERT is defined only for C++ code.\n\n Since declarations can only occur at file scope or at the start of a block in \n standard C, the C_ASSERT() or STATIC_ASSERT() macros will only work there. For situations\n where you want to perform compile-time asserts elsewhere, use C_ASSERT_EX() or\n STATIC_ASSERT_X() which wrap an enum declaration inside it's own block.\n\n */\n\n#ifndef C_ASSERT_H_3803b949_b422_4377_8713_ce606f29d546\n#define C_ASSERT_H_3803b949_b422_4377_8713_ce606f29d546\n\n/* first some utility macros to paste a line number or counter to the end of an identifier\n * this will let us have some chance of generating names that are unique\n * there may be problems if a static assert ends up on the same line number in different headers\n * to avoid that problem in C++ use namespaces\n*/\n\n#if !defined( PASTE)\n#define PASTE2( x, y) x##y\n#define PASTE( x, y) PASTE2( x, y)\n#endif /* PASTE */\n\n#if !defined( PASTE_LINE)\n#define PASTE_LINE( x) PASTE( x, __LINE__)\n#endif /* PASTE_LINE */\n\n#if!defined( PASTE_COUNTER)\n#if (_MSC_VER >= 1300) /* __COUNTER__ introduced in VS 7 (VS.NET 2002) */\n #define PASTE_COUNTER( x) PASTE( x, __COUNTER__) /* __COUNTER__ is a an _MSC_VER >= 1300 non-Ansi extension */\n#else\n #define PASTE_COUNTER( x) PASTE( x, __LINE__) /* since there's no __COUNTER__ use __LINE__ as a more or less reasonable substitute */\n#endif\n#endif /* PASTE_COUNTER */\n\n\n\n#if __cplusplus\nextern \"C++\" { // required in case we're included inside an extern \"C\" block\n namespace interslice {\n template<bool b> struct StaticAssert_failed;\n template<> struct StaticAssert_failed<true> { enum {val = 1 }; };\n template<int x> struct StaticAssert_test { };\n }\n}\n #define CPP_ASSERT( expr) typedef ::interslice::StaticAssert_test< sizeof( ::interslice::StaticAssert_failed< (bool) (expr) >) > PASTE_COUNTER( IntersliceStaticAssertType_)\n #define STATIC_ASSERT( expr) CPP_ASSERT( expr)\n #define STATIC_ASSERT_EX( expr) CPP_ASSERT( expr)\n#else\n #define C_ASSERT_STORAGE_CLASS extern /* change to typedef might be needed for some compilers? */\n #define C_ASSERT_GUID 4964f7ac50fa4661a1377e4c17509495 /* used to make sure our extern name doesn't collide with something else */\n #define STATIC_ASSERT( expr) C_ASSERT_STORAGE_CLASS char PASTE( PASTE( c_assert_, C_ASSERT_GUID), [(expr) ? 1 : -1])\n #define STATIC_ASSERT_EX(expr) do { enum { c_assert__ = 1/((expr) ? 1 : 0) }; } while (0)\n#endif /* __cplusplus */\n\n#if !defined( C_ASSERT) /* C_ASSERT() might be defined by winnt.h */\n#define C_ASSERT( expr) STATIC_ASSERT( expr)\n#endif /* !defined( C_ASSERT) */\n#define C_ASSERT_EX( expr) STATIC_ASSERT_EX( expr)\n\n\n\n#ifdef TEST_IMPLEMENTATION\nC_ASSERT( 1 < 2);\nC_ASSERT( 1 < 2);\n\nint main( )\n{\n C_ASSERT( 1 < 2);\n C_ASSERT( 1 < 2);\n\n int x;\n\n x = 1 + 4;\n\n C_ASSERT_EX( 1 < 2);\n C_ASSERT_EX( 1 < 2);\n\n\n\n return( 0);\n}\n#endif /* TEST_IMPLEMENTATION */\n#endif /* C_ASSERT_H_3803b949_b422_4377_8713_ce606f29d546 */\n"
},
{
"answer_id": 333854,
"author": "pesche",
"author_id": 3686,
"author_profile": "https://Stackoverflow.com/users/3686",
"pm_score": 4,
"selected": false,
"text": "#define assert_static(e) \\\n do { \\\n enum { assert_static__ = 1/(e) }; \\\n } while (0)\n"
},
{
"answer_id": 6087420,
"author": "Danyluk Tamás",
"author_id": 764711,
"author_profile": "https://Stackoverflow.com/users/764711",
"pm_score": 3,
"selected": false,
"text": "#define static_assert(expr) \\\nint __static_assert(int static_assert_failed[(expr)?1:-1])\n"
},
{
"answer_id": 50047342,
"author": "Toby Speight",
"author_id": 4850040,
"author_profile": "https://Stackoverflow.com/users/4850040",
"pm_score": 1,
"selected": false,
"text": "gcc -std=c11 _Static_assert(state1|mode1 == 5, \"Unexpected change of bitflags\");\n"
},
{
"answer_id": 62394832,
"author": "rcpa0",
"author_id": 1707260,
"author_profile": "https://Stackoverflow.com/users/1707260",
"pm_score": 1,
"selected": false,
"text": "#define MODE0 0\n#define MODE1 1\n#define MODE2 2\n\n#define STATE0 0\n#define STATE1 4\n#define STATE2 8\n\nset_register(STATE1|STATE1); //set_register(5);\n#if (!(5==(STATE1|STATE1))) //MY_ASSERT(5==(state1|mode1)); note the !\n#error \"error blah blah\"\n#endif\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4071/"
] |
174,375
|
<p>I am using my own db for phpbb3 forum, and I wish to insert some data from the forum into my own tables. Now, I can make my own connection and it runs my query but in trying to use the $db variable(which I think is what you're meant to use??) it gives me an error.</p>
<p>I would like someone to show me the bare bones which i insert my query into to be able to run it.</p>
|
[
{
"answer_id": 174395,
"author": "Cetra",
"author_id": 15087,
"author_profile": "https://Stackoverflow.com/users/15087",
"pm_score": 1,
"selected": false,
"text": "include($phpbb_root_path . 'includes/db/mysql.' . $phpEx);\n\n$db = new dbal_mysql();\n// we're using bertie and bertiezilla as our example user credentials. You need to fill in your own ;D\n$db->sql_connect('localhost', 'bertie', 'bertiezilla', 'phpbb', '', false, false);\n\n$sql = \"INSERT INTO (rest of sql statement)\";\n\n$result = $db->sql_query($sql);\n"
},
{
"answer_id": 63653357,
"author": "Lakalash Binks",
"author_id": 14189632,
"author_profile": "https://Stackoverflow.com/users/14189632",
"pm_score": 0,
"selected": false,
"text": "$db = new dbal_mysql();\n// we're using bertie and bertiezilla as our example user credentials. You need to fill in your own ;D\n$db->sql_connect('localhost', 'bertie', 'bertiezilla', 'phpbb', '', false, false);\n\n$sql = \"INSERT INTO (rest of sql statement)\";\n$result = $db->sql_query($sql);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25491/"
] |
174,380
|
<p>Within a spring webflow, i need to implement a navigation bar that will allow to "step back" or resume the flow to one of the previous view.</p>
<p>For example :</p>
<ul>
<li>View 1 = login</li>
<li>View 2 = My informations</li>
<li>View 3 = My messages</li>
<li>View 4 = Close session</li>
</ul>
<p>For this example, i would like to return back to view 2 from the view 4 page.</p>
|
[
{
"answer_id": 175279,
"author": "MetroidFan2002",
"author_id": 8026,
"author_profile": "https://Stackoverflow.com/users/8026",
"pm_score": 2,
"selected": false,
"text": "<view-state id=\"loginView\" view=\"login.jsp\">\n <action-state bean=\"someBean\" method=\"login\" />\n <transition on=\"success\" to=\"informationView\" />\n</view-state> \n\n<view-state id=\"informationView\" view=\"information.jsp\">\n <render-actions>\n <action-state bean=\"someBean\" method=\"retrieveInformation\" />\n </render-actions>\n <transition on=\"forward\" to=\"messageView\" />\n <transition on=\"back\" to=\"loginView\" />\n</view-state>\n\n<view-state id=\"messageView\" view=\"message.jsp\">\n <render-actions>\n <action-state bean=\"someBean\" method=\"retrieveMessage\" />\n </render-actions>\n <transition on=\"forward\" to=\"closeView\" />\n <transition on=\"back\" to=\"informationView\" />\n</view-state>\n\n<view-state id=\"closeView\" view=\"logout.jsp\">\n <transition on=\"jumpBack\" to=\"informationView\" />\n</view-state>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25492/"
] |
174,381
|
<p>I am trying to match floating-point decimal numbers with a regular expression. There may or may not be a number before the decimal, and the decimal may or may not be present, and if it is present it may or may not have digits after it. (For this application, a leading +/- or a trailing "E123" is not allowed). I have written this regex:</p>
<pre><code>/^([\d]*)(\.([\d]*))?$/
</code></pre>
<p>Which correctly matches the following:</p>
<pre><code>1
1.
1.23
.23
</code></pre>
<p>However, this also matches empty string or a string of just a decimal point, which I do not want.</p>
<p>Currently I am checking after running the regex that $1 or $3 has length greater than 0. If not, it is not valid. Is there a way I can do this directly in the regex?</p>
|
[
{
"answer_id": 174392,
"author": "Andru Luvisi",
"author_id": 5922,
"author_profile": "https://Stackoverflow.com/users/5922",
"pm_score": 4,
"selected": true,
"text": "/^\\d+(\\.\\d*)?|\\.\\d+$/\n"
},
{
"answer_id": 174411,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 0,
"selected": false,
"text": "/^(\\d+(\\.\\d*)?)|(\\d*\\.\\d+)$/\n"
},
{
"answer_id": 26633757,
"author": "Suganthan Madhavan Pillai",
"author_id": 2534236,
"author_profile": "https://Stackoverflow.com/users/2534236",
"pm_score": 0,
"selected": false,
"text": "[-+]?[\\d]*\\.?[\\d]+?\n [\\d]*\\.?[\\d]+?|[\\d]+\\. 1."
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18511/"
] |
174,387
|
<p>I recently encountered an odd problem with <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.verifyhash.aspx" rel="noreferrer"><code>RSACryptoServiceProvider.VerifyHash</code></a>. </p>
<p>I have a web application using it for decryption. When users running the web service were doing so over our VPN it became very very slow. When they had no connection or a internet connection they were fine.</p>
<p>After much digging I found that every time <code>RSACryptoServiceProvider.VerifyHash</code> is called it makes an LDAP request to check <code>MyMachineName\ASPNET</code>.</p>
<p>This doesn't happen with our WebDev (cassini based) servers as they run as the current user, and it is only really slow over the VPN, but it shouldn't happen at all.</p>
<p>This seems wrong for a couple of reasons: </p>
<ul>
<li>Why is it checking the domain controller for a local machine user?</li>
<li>Why does it care? The encryption/decryption works regardless.</li>
</ul>
<p>Does anyone know why this occurs or how best to work around it?</p>
|
[
{
"answer_id": 174482,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 1,
"selected": false,
"text": "rsa.VerifyHash( hashedData, CryptoConfig.MapNameToOID( \"SHA1\" ), signature );\n rsa.VerifyHash( hashedData, null, signature );\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/905/"
] |
174,393
|
<p>This PHP code...</p>
<pre><code>207 if (getenv(HTTP_X_FORWARDED_FOR)) {
208 $ip = getenv('HTTP_X_FORWARD_FOR');
209 $host = gethostbyaddr($ip);
210 } else {
211 $ip = getenv('REMOTE_ADDR');
212 $host = gethostbyaddr($ip);
213 }
</code></pre>
<p>Throws this warning...</p>
<blockquote>
<p><strong>Warning:</strong> gethostbyaddr()
[function.gethostbyaddr]: Address is
not in a.b.c.d form in <strong>C:\inetpub...\filename.php</strong> on line <strong>212</strong></p>
</blockquote>
<p>It seems that <em>$ip</em> is blank.</p>
|
[
{
"answer_id": 174422,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 2,
"selected": false,
"text": "$_SERVER['REMOTE_ADDR'] \n $_SERVER['HTTP_X_FORWARDED_FOR']\n"
},
{
"answer_id": 174425,
"author": "fly.floh",
"author_id": 25442,
"author_profile": "https://Stackoverflow.com/users/25442",
"pm_score": 5,
"selected": true,
"text": "getenv getenv('REMOTE_ADDR') $_SERVER[\"REMOTE_ADDR\"] $_SERVER"
},
{
"answer_id": 174455,
"author": "Aron Rotteveel",
"author_id": 11568,
"author_profile": "https://Stackoverflow.com/users/11568",
"pm_score": 1,
"selected": false,
"text": "getenv('HTTP_X_FORWARDED_FOR')\n getenv(HTTP_X_FORWARDED_FOR)\n"
},
{
"answer_id": 3814138,
"author": "easyDaMan",
"author_id": 460372,
"author_profile": "https://Stackoverflow.com/users/460372",
"pm_score": 2,
"selected": false,
"text": "getenv('HTTP_X_FORWARD_FOR');\n getenv('HTTP_X_FORWARDED_FOR');\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
174,394
|
<p>I've got a question concerning fields in databases which are measures that might be displayed in different units but are stored only in one, such as "height", for example.</p>
<p>Where should the "pattern unit" be stated?. Of course, in the documentation, etc... But we all know nobody reads the documentation and that self-documented things are preferable.</p>
<p>From a practical point of view, what do you think of coding it in the database field (such as height_cm for example)?.</p>
<p>I find this weird at a first look, but I find it practical to avoid any mistakes when different people deal with the database directly and the "pattern unit" will never change.</p>
<p>What do you think?</p>
|
[
{
"answer_id": 174434,
"author": "Liam",
"author_id": 18333,
"author_profile": "https://Stackoverflow.com/users/18333",
"pm_score": 2,
"selected": false,
"text": "COMMENT ON COLUMN my_table.my_column IS 'cm';\n"
},
{
"answer_id": 174437,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 0,
"selected": false,
"text": "height_cm mm_width"
},
{
"answer_id": 2449727,
"author": "Juha Syrjälä",
"author_id": 1431,
"author_profile": "https://Stackoverflow.com/users/1431",
"pm_score": 0,
"selected": false,
"text": "amount_mk"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15546/"
] |
174,403
|
<p>In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread and raising an event to populate the WebBrowser.DocumentText with the HTML string I was returning.</p>
<p>Now I set it up to grab all of the information on the client, without ever having to hit the server, and I'm trying to raise the same event. I watch the code go through, and it has the HTML string correct and everything, but when I try to do</p>
<pre><code>browser.DocumentText = _emailHTML
</code></pre>
<p>the contents of DocumentText remain as "<code><HTML></HTML></code>"</p>
<p>I was just wondering why the DocumentText was not being set. Anyone have any suggestions?</p>
|
[
{
"answer_id": 174483,
"author": "David Mohundro",
"author_id": 4570,
"author_profile": "https://Stackoverflow.com/users/4570",
"pm_score": 7,
"selected": true,
"text": "browser.Navigate(\"about:blank\");\nHtmlDocument doc = browser.Document;\ndoc.Write(String.Empty);\nbrowser.DocumentText = _emailHTML;\n WebBrowser about:blank"
},
{
"answer_id": 3965190,
"author": "johnc",
"author_id": 5302,
"author_profile": "https://Stackoverflow.com/users/5302",
"pm_score": 1,
"selected": false,
"text": "_webBrowser.DocumentText = builder.WriteToString( ... );\n\nApplication.DoEvents();\n"
},
{
"answer_id": 7418458,
"author": "AVIDeveloper",
"author_id": 287109,
"author_profile": "https://Stackoverflow.com/users/287109",
"pm_score": 0,
"selected": false,
"text": "Application.DoEvents() webBrowser.Write( htmlContent ) webBrowser.DocumentText = htmlContent"
},
{
"answer_id": 7963984,
"author": "Prads",
"author_id": 413582,
"author_profile": "https://Stackoverflow.com/users/413582",
"pm_score": 0,
"selected": false,
"text": "using mshtml;\n\n\nprivate IHTMLDocument2 Document\n{\n get\n {\n if (Browser.Document != null)\n {\n return Browser.Document.DomDocument as IHTMLDocument2;\n }\n\n return null;\n }\n}\n\n\nif (Document == null)\n{\n Browser.DocumentText = Contents;\n}\nelse\n{\n Document.body.innerHTML = Contents;\n}\n"
},
{
"answer_id": 15209861,
"author": "Matthias",
"author_id": 2133221,
"author_profile": "https://Stackoverflow.com/users/2133221",
"pm_score": 5,
"selected": false,
"text": " webBrowser.Navigate(\"about:blank\");\n webBrowser.Document.OpenNew(false);\n webBrowser.Document.Write(html);\n webBrowser.Refresh();\n"
},
{
"answer_id": 16165355,
"author": "antgraf",
"author_id": 465062,
"author_profile": "https://Stackoverflow.com/users/465062",
"pm_score": 2,
"selected": false,
"text": "private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)\n{\n if(e.Url.OriginalString.StartsWith(\"about:\"))\n {\n return;\n }\n e.Cancel = true;\n // ...\n}\n"
},
{
"answer_id": 17809649,
"author": "FreddieH",
"author_id": 2610510,
"author_profile": "https://Stackoverflow.com/users/2610510",
"pm_score": 4,
"selected": false,
"text": "if (this.webBrowser1.Document == null)\n{\n this.webBrowser1.DocumentText = htmlSource;\n}\nelse\n{\n this.webBrowser1.Document.OpenNew(true);\n this.webBrowser1.Document.Write(htmlSource);\n}\n"
},
{
"answer_id": 40250353,
"author": "Interferank",
"author_id": 3353064,
"author_profile": "https://Stackoverflow.com/users/3353064",
"pm_score": 2,
"selected": false,
"text": "webBrowser.Navigate(\"about:blank\");\nwebBrowser.Document?.Write(htmlString);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13244/"
] |
174,412
|
<p>I'm having trouble figuring out how to access a cookie from a compiled object. I'm trying to make a compiled (DLL) object that will check the users cookie and then compare that to a database to confirm they have the correct access. </p>
<p>I can pass in the cookie info fine and the component will work, but I'm trying to have the component check the users cookie as well. I'm not even sure what object to use. I've been searching all weekend and I've seen references to httprequest, httpcookie, cookie, and cookiecollection. </p>
<p>I can look up cookie values on the page itself using Request.Cookies("inet")("user_id") but this doesn't work in the component. </p>
|
[
{
"answer_id": 174427,
"author": "martin",
"author_id": 8421,
"author_profile": "https://Stackoverflow.com/users/8421",
"pm_score": 3,
"selected": true,
"text": "HttpCookie cookie = HttpContext.Current.Request.Cookies[\"CookieName\"];\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9581/"
] |
174,418
|
<p>I've written a little script to iterate across files in folders to count lines of code.</p>
<p>The heart of the script is this function to count lines of whitespace, comments, and code. (Note that for the moment it is tailored to C# and doesn't know about multi-line comments).</p>
<p>It just doesn't look very nice to me - has anyone got a cleaner version?</p>
<pre><code>// from list of strings return tuple with count of (whitespace, comments, code)
let loc (arr:List<string>) =
let innerloc (whitesp, comment, code) (l:string) =
let s = l.Trim([|' ';'\t'|]) // remove leading whitespace
match s with
| "" -> (whitesp + 1, comment, code) //blank lines
| "{" -> (whitesp + 1, comment, code) //opening blocks
| "}" -> (whitesp + 1, comment, code) //closing blocks
| _ when s.StartsWith("#") -> (whitesp + 1, comment, code) //regions
| _ when s.StartsWith("//") -> (whitesp, comment + 1, code) //comments
| _ -> (whitesp, comment, code + 1)
List.fold_left innerloc (0,0,0) arr
</code></pre>
|
[
{
"answer_id": 174928,
"author": "Brian",
"author_id": 19299,
"author_profile": "https://Stackoverflow.com/users/19299",
"pm_score": 3,
"selected": true,
"text": "type Line =\n | Whitespace = 0\n | Comment = 1\n | Code = 2\nlet Classify (l:string) = \n let s = l.TrimStart([|' ';'\\t'|])\n match s with \n | \"\" | \"{\" | \"}\" -> Line.Whitespace\n | _ when s.StartsWith(\"#\") -> Line.Whitespace\n | _ when s.StartsWith(\"//\") -> Line.Comment\n | _ -> Line.Code\nlet Loc (arr:list<_>) = \n let sums = Array.create 3 0\n arr \n |> List.iter (fun line -> \n let i = Classify line |> int\n sums.[i] <- sums.[i] + 1)\n sums\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11410/"
] |
174,430
|
<p>I decided to use <a href="http://logging.apache.org/log4net/index.html" rel="noreferrer">log4net</a> as a logger for a new webservice project. Everything is working fine, but I get a lot of messages like the one below, for every log4net tag I am using in my <code>web.config</code>:</p>
<blockquote>
<p>Could not find schema information for
the element 'log4net'...</p>
</blockquote>
<p>Below are the relevant parts of my <code>web.config</code>:</p>
<pre class="lang-xml prettyprint-override"><code> <configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level: %message%newline" />
</layout>
</appender>
<logger name="TIMServerLog">
<level value="DEBUG" />
<appender-ref ref="RollingFileAppender" />
</logger>
</log4net>
</code></pre>
<p>Solved:</p>
<ol>
<li>Copy every log4net specific tag to a separate <code>xml</code>-file. Make sure to use <code>.xml</code> as file extension.</li>
<li>Add the following line to <code>AssemblyInfo.cs</code>:</li>
</ol>
<pre class="lang-cs prettyprint-override"><code>[assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlFile.xml", Watch = true)]
</code></pre>
<p><a href="https://stackoverflow.com/users/20774/nemo">nemo</a> added:</p>
<blockquote>
<p>Just a word of warning to anyone
follow the advice of the answers in
this thread. There is a possible
security risk by having the log4net
configuration in an xml off the root
of the web service, as it will be
accessible to anyone by default. Just
be advised if your configuration
contains sensitive data, you may want
to put it else where.</p>
</blockquote>
<hr>
<p>@wcm: I tried using a separate file. I added the following line to <code>AssemblyInfo.cs</code></p>
<pre class="lang-cs prettyprint-override"><code>[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
</code></pre>
<p>and put everything dealing with log4net in that file, but I still get the same messages.</p>
|
[
{
"answer_id": 176119,
"author": "steve_mtl",
"author_id": 178,
"author_profile": "https://Stackoverflow.com/users/178",
"pm_score": 5,
"selected": true,
"text": "[assembly: log4net.Config.XmlConfigurator(ConfigFile = \"log4net.xml\", Watch = true)]\n"
},
{
"answer_id": 177500,
"author": "xsl",
"author_id": 11387,
"author_profile": "https://Stackoverflow.com/users/11387",
"pm_score": 2,
"selected": false,
"text": ".config .xml xml .xml AssemblyInfo.cs [assembly: log4net.Config.XmlConfigurator(ConfigFile = \"xmlFile.xml\", Watch = true)]"
},
{
"answer_id": 275197,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": false,
"text": "log4net log4net <log4net \n xsi:noNamespaceSchemaLocation=\"http://csharptest.net/downloads/schema/log4net.xsd\" \n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
},
{
"answer_id": 1176561,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "[assembly: log4net.Config.XmlConfigurator(ConfigFile = \"log4net.config\", ConfigFileExtension=\".config\", Watch = true)]\n"
},
{
"answer_id": 1212011,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "web.config <?xml version=\"1.0\"?>\n<!-- \n Note: As an alternative to hand editing this file you can use the \n web admin tool to configure settings for your application. Use\n the Website->Asp.Net Configuration option in Visual Studio.\n A full list of settings and comments can be found in \n machine.config.comments usually located in \n \\Windows\\Microsoft.Net\\Framework\\v2.x\\Config \n-->\n<configuration>\n <configSections>\n\n\n <section name=\"log4net\" \n type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\"/>\n\n </configSections>\n <appSettings>\n\n </appSettings>\n <connectionStrings>\n\n </connectionStrings>\n <system.web>\n <trace enabled=\"true\" pageOutput=\"true\" />\n <!-- \n Set compilation debug=\"true\" to insert debugging \n symbols into the compiled page. Because this \n affects performance, set this value to true only \n during development.\n -->\n <compilation debug=\"true\" />\n <!--\n The <authentication> section enables configuration \n of the security authentication mode used by \n ASP.NET to identify an incoming user. \n -->\n <authentication mode=\"Windows\" />\n\n <customErrors mode=\"Off\"/>\n <!--\n <customErrors mode=\"Off\"/>\n\n The <customErrors> section enables configuration \n of what to do if/when an unhandled error occurs \n during the execution of a request. Specifically, \n it enables developers to configure html error pages \n to be displayed in place of a error stack trace.\n\n <customErrors mode=\"On\" defaultRedirect=\"GenericErrorPage.htm\">\n <error statusCode=\"403\" redirect=\"NoAccess.htm\" />\n <error statusCode=\"404\" redirect=\"FileNotFound.htm\" />\n </customErrors>\n -->\n\n\n\n\n\n </system.web>\n <log4net xsi:noNamespaceSchemaLocation=\"http://csharptest.net/downloads/schema/log4net.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <appender name=\"LogFileAppender\" type=\"log4net.Appender.FileAppender\">\n <!-- Please make shure the ..\\\\Logs directory exists! -->\n <param name=\"File\" value=\"Logs\\\\Log4Net.log\"/>\n <!--<param name=\"AppendToFile\" value=\"true\"/>-->\n <layout type=\"log4net.Layout.PatternLayout\">\n <param name=\"ConversionPattern\" value=\"%d [%t] %-5p %c %m%n\"/>\n </layout>\n </appender>\n <appender name=\"SmtpAppender\" type=\"log4net.Appender.SmtpAppender\">\n <to value=\"\" />\n <from value=\"\" />\n <subject value=\"\" />\n <smtpHost value=\"\" />\n <bufferSize value=\"512\" />\n <lossy value=\"true\" />\n <evaluator type=\"log4net.Core.LevelEvaluator\">\n <threshold value=\"WARN\"/>\n </evaluator>\n <layout type=\"log4net.Layout.PatternLayout\">\n <conversionPattern value=\"%newline%date [%thread] %-5level %logger [%property] - %message%newline%newline%newline\" />\n </layout>\n </appender>\n\n <logger name=\"File\">\n <level value=\"ALL\" />\n <appender-ref ref=\"LogFileAppender\" />\n </logger>\n <logger name=\"EmailLog\">\n <level value=\"ALL\" />\n <appender-ref ref=\"SmtpAppender\" />\n </logger>\n </log4net>\n</configuration>\n"
},
{
"answer_id": 11780781,
"author": "Kit",
"author_id": 64348,
"author_profile": "https://Stackoverflow.com/users/64348",
"pm_score": 2,
"selected": false,
"text": "xs:simpletype log4netAppenderTypes log4netAppenderTypes <xs:simpleType name=\"log4netAppenderTypes\">\n <xs:restriction base=\"xs:string\">\n <xs:pattern value=\"[A-Za-z_]\\w*(\\.[A-Za-z_]\\w*)+(\\s*,\\s*[A-Za-z_]\\w*(\\.[A-Za-z_]\\w*)+)?\"/>\n </xs:restriction>\n</xs:simpleType>\n <log4net\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:noNamespaceSchemaLocation=\"../../../Dependencies/log4net/log4net.xsd\">\n <!-- ... -->\n</log4net>\n"
},
{
"answer_id": 28528654,
"author": "Fysicus",
"author_id": 975748,
"author_profile": "https://Stackoverflow.com/users/975748",
"pm_score": 0,
"selected": false,
"text": "<!-- Register a section handler for the log4net section -->\n<configSections>\n <section name=\"log4net\" type=\"System.Configuration.IgnoreSectionHandler\" />\n</configSections>\n"
},
{
"answer_id": 42562811,
"author": "Volodymyr",
"author_id": 6139051,
"author_profile": "https://Stackoverflow.com/users/6139051",
"pm_score": 0,
"selected": false,
"text": "<xs:pattern value=\"[A-Za-z_]\\w*(\\.[A-Za-z_]\\w*)+(\\s*,\\s*[A-Za-z_]\\w*(\\.[A-Za-z_]\\w*)?+)?\"/>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11387/"
] |
174,438
|
<p>I have two tables, <strong>Book</strong> and <strong>Tag</strong>, and books are tagged using the association table <strong>BookTag</strong>. I want to create a report that contains a list of books, and for each book a list of the book's tags. Tag IDs will suffice, tag names are not necessary.</p>
<p>Example:</p>
<pre><code>Book table:
Book ID | Book Name
28 | Dracula
BookTag table:
Book ID | Tag ID
28 | 101
28 | 102
</code></pre>
<p>In my report, I'd like to show that book #28 has the tags 101 and 102:</p>
<pre><code>Book ID | Book Name | Tags
28 | Dracula | 101, 102
</code></pre>
<p>Is there a way to do this in-line, without having to resort to functions or stored procedures? I am using SQL Server 2005.</p>
<p><em>Please note that the same question already has been asked in <a href="https://stackoverflow.com/questions/111341/combine-multiple-results-in-a-subquery-into-a-single-comma-separated-value">Combine multiple results in a subquery into a single comma-separated value</a>, but the solution involves creating a function. I am asking if there is a way to solve this without having to create a function or a stored procedure.</em></p>
|
[
{
"answer_id": 174568,
"author": "Darrel Miller",
"author_id": 6819,
"author_profile": "https://Stackoverflow.com/users/6819",
"pm_score": 3,
"selected": true,
"text": "SELECT em.Code,\n (SELECT et.Name + ' ' AS 'data()'\n FROM tblEmployeeTag et\n JOIN tblEmployeeTagAssignment eta ON et.Id = eta.EmployeeTag_Id AND eta.Employee_Id = em.id\n FOR XML PATH('') ) AS Tags\nFROM tblEmployee em\n SELECT bk.Id AS BookId,\n bk.Name AS BookName,\n REPLACE((SELECT LTRIM(STR(bt.TagId)) + ', ' AS 'data()'\n FROM BookTag bt\n WHERE bt.BookId = bk.Id \n FOR XML PATH('') ) + 'x', ', x','') AS Tags\nFROM Book bk\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6120/"
] |
174,446
|
<p>I have about 200 Excel files that are in standard Excel 2003 format. </p>
<p>I need them all to be saved as Excel xml - basically the same as opening each file and choosing <strong>Save As...</strong> and then choosing <strong>Save as type:</strong> <em>XML Spreadsheet</em></p>
<p>Would you know any simple way of automating that task?</p>
|
[
{
"answer_id": 174587,
"author": "Duncan Smart",
"author_id": 1278,
"author_profile": "https://Stackoverflow.com/users/1278",
"pm_score": 2,
"selected": false,
"text": "Sub SaveAllAsXml()\n Dim wbk As Workbook\n For Each wbk In Application.Workbooks\n wbk.SaveAs FileFormat:=XlFileFormat.xlXMLSpreadsheet\n Next\nEnd Sub\n"
},
{
"answer_id": 176266,
"author": "BKimmel",
"author_id": 13776,
"author_profile": "https://Stackoverflow.com/users/13776",
"pm_score": 1,
"selected": false,
"text": "set xlapp = CreateObject(\"Excel.Application\")\nset fso = CreateObject(\"scripting.filesystemobject\")\nset myfolder = fso.GetFolder(\"YOURFOLDERPATHHERE\")\nset myfiles = myfolder.Files\nfor each f in myfiles\n set mybook = xlapp.Workbooks.Open(f.Path)\n mybook.SaveAs f.Name & \".xml\", 47\n mybook.Close\nnext\n"
},
{
"answer_id": 176608,
"author": "Robert Mearns",
"author_id": 5050,
"author_profile": "https://Stackoverflow.com/users/5050",
"pm_score": 4,
"selected": true,
"text": "Sub Convert_xls_Files()\n\nDim strFile As String\nDim strPath As String\n\n With Application\n .EnableEvents = False\n .DisplayAlerts = False\n .ScreenUpdating = False\n End With\n'Turn off events, alerts & screen updating\n\n strPath = \"C:\\temp\\excel\\\"\n strFile = Dir(strPath & \"*.xls\")\n'Change the path as required\n\n Do While strFile <> \"\"\n Workbooks.Open (strPath & strFile)\n strFile = Mid(strFile, 1, Len(strFile) - 4) & \".xlsx\"\n ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:=xlOpenXMLWorkbook\n ActiveWorkbook.Close True\n strFile = Dir\n Loop\n'Opens the Workbook, set the file name, save in new format and close workbook\n\n With Application\n .EnableEvents = True\n .DisplayAlerts = True\n .ScreenUpdating = True\n End With\n'Turn on events, alerts & screen updating\n\nEnd Sub\n"
},
{
"answer_id": 27525667,
"author": "Kishore Relangi",
"author_id": 1568699,
"author_profile": "https://Stackoverflow.com/users/1568699",
"pm_score": 0,
"selected": false,
"text": "Const xlXLSX = 51\n\nREM 51 = xlOpenXMLWorkbook (without macro's in 2007-2013, xlsx)\nREM 52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2013, xlsm)\nREM 50 = xlExcel12 (Excel Binary Workbook in 2007-2013 with or without macro's, xlsb)\nREM 56 = xlExcel8 (97-2003 format in Excel 2007-2013, xls)\n\ndim args\ndim file\ndim sFile\nset args=wscript.arguments\n\ndim wshell\nSet wshell = CreateObject(\"WScript.Shell\")\n\nSet objExcel = CreateObject(\"Excel.Application\")\n\nSet objWorkbook = objExcel.Workbooks.Open( wshell.CurrentDirectory&\"\\\"&args(0))\n\nobjExcel.DisplayAlerts = FALSE\n\nobjExcel.Visible = FALSE\n\nobjWorkbook.SaveAs wshell.CurrentDirectory&\"\\\"&args(1), xlXLSX\n\nobjExcel.Quit\n\nWscript.Quit\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3241/"
] |
174,449
|
<p>Unquestionably, I would choose to use the STL for most C++ programming projects. The question was presented to me recently however, "Are there any cases where you wouldn't use the STL?"...</p>
<p>The more I thought about it, the more I realized that perhaps there SHOULD be cases where I choose not to use the STL... For example, a really large, long term project whose codebase is expected to last years... Perhaps a custom container solution that precisely fits the projects needs is worth the initial overhead? What do you think, are there any cases where you would choose NOT to STL?</p>
|
[
{
"answer_id": 44783029,
"author": "Adrian Maire",
"author_id": 903651,
"author_profile": "https://Stackoverflow.com/users/903651",
"pm_score": 2,
"selected": false,
"text": "[] operator std::vector"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3886/"
] |
174,458
|
<p>There is <a href="https://stackoverflow.com/questions/134698/catching-exceptions-as-expected-program-execution-flow-control">an interesting post over here</a> about this, in relation to cross-application flow of control. </p>
<p>Well, recently, I've come across an interesting problem. Generating the nth value in a potentially (practically) endless recursive sequence. This particular algorithm WILL be in atleast 10-15 stack references deep at the point that it succeeds. My first thought was to throw a SuccessException that looked something like this (C#):</p>
<pre><code>class SuccessException : Exception
{
public string Value
{ get; set; }
public SuccessException(string value)
: base()
{
Value = value;
}
}
</code></pre>
<p>Then do something like this:</p>
<pre><code>try
{
Walk_r(tree);
}
catch (SuccessException ex)
{
result = ex.Value;
}
</code></pre>
<p>Then my thoughts wandered back here, where I've heard over and over to never use Exceptions for flow control. Is there ever an excuse? And how would you structure something like this, if you were to implement it?</p>
|
[
{
"answer_id": 174513,
"author": "Robin",
"author_id": 21925,
"author_profile": "https://Stackoverflow.com/users/21925",
"pm_score": 1,
"selected": false,
"text": "try\n{\n Walk_r(tree);\n}\ncatch (SuccessException ex)\n{\n result = ex.Value;\n}\n result = Walk_r(tree);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
174,472
|
<p>I have a bunch of java files from which I want to remove the javadoc lines with the license [am changing it on my code].</p>
<p>The pattern I am looking for is</p>
<p><code>^\* \* ProjectName .* USA\.$</code> </p>
<p>but matched across lines</p>
<p>Is there a way sed [or a commonly used editor in Windows/Linux] can do a search/replace for a multiline pattern?</p>
|
[
{
"answer_id": 174541,
"author": "Pete",
"author_id": 13472,
"author_profile": "https://Stackoverflow.com/users/13472",
"pm_score": 0,
"selected": false,
"text": "/\\*(?:.|[\\r\\n])*?\\*/\nperl -0777ne 'print m!/\\*(?:.|[\\r\\n])*?\\*/!g;' <file>\n"
},
{
"answer_id": 26301655,
"author": "pKrarup",
"author_id": 4129755,
"author_profile": "https://Stackoverflow.com/users/4129755",
"pm_score": 1,
"selected": false,
"text": "awk \"/^\\* \\* ProjectName /,/ USA\\.$/\" input.txt \\\n | diff - input.txt \\\n | sed -n -e\"s/^> //p\" \\\n >output.txt\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20386/"
] |
174,502
|
<p>Seeing as Java doesn't have nullable types, nor does it have a TryParse(),
how do you handle input validation without throwing an exceptions?</p>
<p>The usual way:</p>
<pre><code>String userdata = /*value from gui*/
int val;
try
{
val = Integer.parseInt(userdata);
}
catch (NumberFormatException nfe)
{
// bad data - set to sentinel
val = Integer.MIN_VALUE;
}
</code></pre>
<p>I could use a regex to check if it's parseable, but that seems like a lot of overhead as well.</p>
<p>What's the best practice for handling this situation?</p>
<p>EDIT: Rationale:
There's been a lot of talk on SO about exception handling, and the general attitude is that exceptions should be used for unexpected scenarios only. However, I think bad user input is EXPECTED, not rare. Yes, it really is an academic point.</p>
<p>Further Edits: </p>
<p>Some of the answers demonstrate exactly what is wrong with SO. You ignore the question being asked, and answer another question that has nothing to do with it. The question isn't asking about transition between layers. The question isn't asking what to return if the number is un-parseable. For all you know, val = Integer.MIN_VALUE; is exactly the right option for the application that this completely context free code snippet was take from.</p>
|
[
{
"answer_id": 174558,
"author": "Grant Wagner",
"author_id": 9254,
"author_profile": "https://Stackoverflow.com/users/9254",
"pm_score": 3,
"selected": false,
"text": "Utilities.tryParseInt(String value) Utilities.tryParseInt(String value, int defaultValue) parseInt() Utilities.tryParseInt(date, 19000101) Utilities.tryParseInt(date, 29991231);"
},
{
"answer_id": 174644,
"author": "mjlee",
"author_id": 2829,
"author_profile": "https://Stackoverflow.com/users/2829",
"pm_score": -1,
"selected": false,
"text": "// this is bad\nint val = Integer.MIN_VALUE;\ntry\n{\n val = Integer.parseInt(userdata);\n}\ncatch (NumberFormatException ignoreException) { }\n private boolean isUserValueAcceptable(String userData)\n{\n return ( isNumber(userData) \n && isInteger(userData) \n && isBetween(userData, Integer.MIN_VALUE, Integer.MAX_VALUE ) \n );\n}\n"
},
{
"answer_id": 174666,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 4,
"selected": false,
"text": "java.text try {\n NumberFormat format = NumberFormat.getIntegerInstance(locale);\n format.setParseIntegerOnly(true);\n format.setMaximumIntegerDigits(9);\n ParsePosition pos = new ParsePosition(0);\n int val = format.parse(str, pos).intValue();\n if (pos.getIndex() != str.length()) {\n // ... handle case of extraneous characters after digits ...\n }\n // ... use val ...\n} catch (java.text.ParseFormatException exc) {\n // ... handle this case appropriately ...\n}\n"
},
{
"answer_id": 174696,
"author": "noah",
"author_id": 12034,
"author_profile": "https://Stackoverflow.com/users/12034",
"pm_score": 2,
"selected": false,
"text": "public Integer parseInt(String data) {\n Integer val = null;\n try {\n val = Integer.parseInt(userdata);\n } catch (NumberFormatException nfe) { }\n return val;\n}\n public Integer parseInt(String data,int default) {\n Integer val = default;\n try {\n val = Integer.parseInt(userdata);\n } catch (NumberFormatException nfe) { }\n return val;\n}\n"
},
{
"answer_id": 175498,
"author": "extraneon",
"author_id": 24582,
"author_profile": "https://Stackoverflow.com/users/24582",
"pm_score": -1,
"selected": false,
"text": "loadCertainProperty(String propVal) {\n try\n {\n val = Integer.parseInt(userdata);\n return val;\n }\n catch (NumberFormatException nfe)\n { // RuntimeException need not be declared\n throw new RuntimeException(\"Property certainProperty in your configuration is expected to be \" +\n \" an integer, but was '\" + propVal + \"'. Please correct your \" +\n \"configuration and start again\");\n // After starting an enterprise application the sysadmin should always check availability\n // and can now correct the property value\n }\n}\n public int askValue() {\n // TODO add opt-out button; see Swing docs for standard dialog handling\n boolean valueOk = false;\n while(!valueOk) {\n try {\n String val = dialog(\"Please enter integer value for FOO\");\n val = Integer.parseInt(userdata);\n return val; \n } catch (NumberFormatException nfe) {\n // Ignoring this; I don't care how many typo's the customer makes\n }\n }\n}\n"
},
{
"answer_id": 13726535,
"author": "Zlosny",
"author_id": 186951,
"author_profile": "https://Stackoverflow.com/users/186951",
"pm_score": 1,
"selected": false,
"text": "org.apache.commons.lang.math.NumberUtils.createInteger(String s)"
},
{
"answer_id": 16699049,
"author": "Stephen Ostermiller",
"author_id": 1145388,
"author_profile": "https://Stackoverflow.com/users/1145388",
"pm_score": 5,
"selected": false,
"text": "// returns defaultValue if the string cannot be parsed.\nint i = org.apache.commons.lang.math.NumberUtils.toInt(s, defaultValue);\n // returns null if the string cannot be parsed\n// Will throw a NullPointerException if the string is null\nInteger i = com.google.common.primitives.Ints.tryParse(s);\n"
},
{
"answer_id": 45028739,
"author": "charles-allen",
"author_id": 2957169,
"author_profile": "https://Stackoverflow.com/users/2957169",
"pm_score": 0,
"selected": false,
"text": "public static OptionalInt toInt(final String input) {\n return input.matches(\"[+-]?\\\\d+\") \n ? OptionalInt.of(Integer.parseInt(input)) \n : OptionalInt.empty();\n}\n IntStream OptionalInt flatMap()"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18907/"
] |
174,516
|
<p>I have a table that records a sequence of actions with a field that records the sequence order:</p>
<pre><code>user data sequence
1 foo 0
1 bar 1
1 baz 2
2 foo 0
3 bar 0
3 foo 1
</code></pre>
<p>Selecting the first item for each user is easy enough with WHERE sequence = '0' but is there a way to select the last item for each user in SQL?</p>
<p>The result I am after should look like this:</p>
<pre><code>user data sequence
1 baz 2
2 foo 0
3 foo 1
</code></pre>
<p>I'm using MySQL if there are any implementation specific tricksters answering.</p>
|
[
{
"answer_id": 174537,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 4,
"selected": true,
"text": "select a.user, a.data, a.sequence\nfrom table as a\n inner join (\n select user, max(sequence) as 'last'\n from table \n group by user) as b\n on a.user = b.user and \n a.sequence = b.last\n"
},
{
"answer_id": 8088189,
"author": "plucka",
"author_id": 1040821,
"author_profile": "https://Stackoverflow.com/users/1040821",
"pm_score": 0,
"selected": false,
"text": "select top 1 \n user\n ,data\n ,sequence\n from table\norder\n by sequence\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11651/"
] |
174,531
|
<p>What is the simplest way (least error-prone, least lines of code, however you want to interpret it) to open a file in C and read its contents into a string (char*, char[], whatever)?</p>
|
[
{
"answer_id": 174552,
"author": "Nils Pipenbrinck",
"author_id": 15955,
"author_profile": "https://Stackoverflow.com/users/15955",
"pm_score": 8,
"selected": true,
"text": "char * buffer = 0;\nlong length;\nFILE * f = fopen (filename, \"rb\");\n\nif (f)\n{\n fseek (f, 0, SEEK_END);\n length = ftell (f);\n fseek (f, 0, SEEK_SET);\n buffer = malloc (length);\n if (buffer)\n {\n fread (buffer, 1, length, f);\n }\n fclose (f);\n}\n\nif (buffer)\n{\n // start to process your data / extract strings here...\n}\n"
},
{
"answer_id": 174743,
"author": "dmityugov",
"author_id": 3232,
"author_profile": "https://Stackoverflow.com/users/3232",
"pm_score": 4,
"selected": false,
"text": "char* buffer = NULL;\nsize_t len;\nssize_t bytes_read = getdelim( &buffer, &len, '\\0', fp);\nif ( bytes_read != -1) {\n /* Success, now the entire file is in the buffer */\n"
},
{
"answer_id": 174808,
"author": "Jeff Mc",
"author_id": 25521,
"author_profile": "https://Stackoverflow.com/users/25521",
"pm_score": 5,
"selected": false,
"text": "int fd = open(\"filename\", O_RDONLY);\nint len = lseek(fd, 0, SEEK_END);\nvoid *data = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);\n CreateFileMapping() MapViewOfFile()"
},
{
"answer_id": 184907,
"author": "selwyn",
"author_id": 16314,
"author_profile": "https://Stackoverflow.com/users/16314",
"pm_score": 2,
"selected": false,
"text": "char buffer[100];\nFILE *fp = fopen(\"filename\", \"r\"); // do not use \"rb\"\nwhile (fgets(buffer, sizeof(buffer), fp)) {\n... do something\n}\nfclose(fp);\n"
},
{
"answer_id": 20179997,
"author": "Jake",
"author_id": 498804,
"author_profile": "https://Stackoverflow.com/users/498804",
"pm_score": 3,
"selected": false,
"text": "#include <stdio.h>\n#include <unistd.h>\n#include <errno.h>\n#include <string.h>\n\nint main () {\n char buf[4096];\n ssize_t n;\n char *str = NULL;\n size_t len = 0;\n while (n = read(STDIN_FILENO, buf, sizeof buf)) {\n if (n < 0) {\n if (errno == EAGAIN)\n continue;\n perror(\"read\");\n break;\n }\n str = realloc(str, len + n + 1);\n memcpy(str + len, buf, n);\n len += n;\n str[len] = '\\0';\n }\n printf(\"%.*s\\n\", len, str);\n return 0;\n}\n"
},
{
"answer_id": 37241679,
"author": "Entalpi",
"author_id": 1548601,
"author_profile": "https://Stackoverflow.com/users/1548601",
"pm_score": 1,
"selected": false,
"text": "// Assumes the file exists and will seg. fault otherwise.\nconst GLchar *load_shader_source(char *filename) {\n FILE *file = fopen(filename, \"r\"); // open \n fseek(file, 0L, SEEK_END); // find the end\n size_t size = ftell(file); // get the size in bytes\n GLchar *shaderSource = calloc(1, size); // allocate enough bytes\n rewind(file); // go back to file beginning\n fread(shaderSource, size, sizeof(char), file); // read each char into ourblock\n fclose(file); // close the stream\n return shaderSource;\n}\n"
},
{
"answer_id": 39915037,
"author": "sleepycal",
"author_id": 1267398,
"author_profile": "https://Stackoverflow.com/users/1267398",
"pm_score": 2,
"selected": false,
"text": "glib gchar *contents;\nGError *err = NULL;\n\ng_file_get_contents (\"foo.txt\", &contents, NULL, &err);\ng_assert ((contents == NULL && err != NULL) || (contents != NULL && err == NULL));\nif (err != NULL)\n {\n // Report error to user, and free error\n g_assert (contents == NULL);\n fprintf (stderr, \"Unable to read file: %s\\n\", err->message);\n g_error_free (err);\n }\nelse\n {\n // Use file contents\n g_assert (contents != NULL);\n }\n}\n"
},
{
"answer_id": 47195924,
"author": "BaiJiFeiLong",
"author_id": 5254103,
"author_profile": "https://Stackoverflow.com/users/5254103",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n\nchar *readFile(char *filename) {\n FILE *f = fopen(filename, \"rt\");\n assert(f);\n fseek(f, 0, SEEK_END);\n long length = ftell(f);\n fseek(f, 0, SEEK_SET);\n char *buffer = (char *) malloc(length + 1);\n buffer[length] = '\\0';\n fread(buffer, 1, length, f);\n fclose(f);\n return buffer;\n}\n\nint main() {\n char *content = readFile(\"../hello.txt\");\n printf(\"%s\", content);\n}\n"
},
{
"answer_id": 54057690,
"author": "Joe Cool",
"author_id": 7428740,
"author_profile": "https://Stackoverflow.com/users/7428740",
"pm_score": 3,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n\n#define FILE_OK 0\n#define FILE_NOT_EXIST 1\n#define FILE_TOO_LARGE 2\n#define FILE_READ_ERROR 3\n\nchar * c_read_file(const char * f_name, int * err, size_t * f_size) {\n char * buffer;\n size_t length;\n FILE * f = fopen(f_name, \"rb\");\n size_t read_length;\n \n if (f) {\n fseek(f, 0, SEEK_END);\n length = ftell(f);\n fseek(f, 0, SEEK_SET);\n \n // 1 GiB; best not to load a whole large file in one string\n if (length > 1073741824) {\n *err = FILE_TOO_LARGE;\n \n return NULL;\n }\n \n buffer = (char *)malloc(length + 1);\n \n if (length) {\n read_length = fread(buffer, 1, length, f);\n \n if (length != read_length) {\n free(buffer);\n *err = FILE_READ_ERROR;\n\n return NULL;\n }\n }\n \n fclose(f);\n \n *err = FILE_OK;\n buffer[length] = '\\0';\n *f_size = length;\n }\n else {\n *err = FILE_NOT_EXIST;\n \n return NULL;\n }\n \n return buffer;\n}\n int err;\nsize_t f_size;\nchar * f_data;\n\nf_data = c_read_file(\"test.txt\", &err, &f_size);\n\nif (err) {\n // process error\n}\nelse {\n // process data\n free(f_data);\n}\n"
},
{
"answer_id": 56924271,
"author": "Erik Campobadal",
"author_id": 8280247,
"author_profile": "https://Stackoverflow.com/users/8280247",
"pm_score": 0,
"selected": false,
"text": "// Open the file in read mode.\nFILE *file = fopen(file_name, \"r\");\n// Check if there was an error.\nif (file == NULL) {\n fprintf(stderr, \"Error: Can't open file '%s'.\", file_name);\n exit(EXIT_FAILURE);\n}\n// Get the file length\nfseek(file, 0, SEEK_END);\nlong length = ftell(file);\nfseek(file, 0, SEEK_SET);\n// Create the string for the file contents.\nchar *buffer = malloc(sizeof(char) * (length + 1));\nbuffer[length] = '\\0';\n// Set the contents of the string.\nfread(buffer, sizeof(char), length, file);\n// Close the file.\nfclose(file);\n// Do something with the data.\n// ...\n// Free the allocated string space.\nfree(buffer);\n"
},
{
"answer_id": 57511398,
"author": "Ahmed Ibrahim El Gendy",
"author_id": 7396930,
"author_profile": "https://Stackoverflow.com/users/7396930",
"pm_score": -1,
"selected": false,
"text": "void read_whole_file(char fileName[1000], char buffer[10000])\n{\n FILE * file = fopen(fileName, \"r\");\n if(file == NULL)\n {\n puts(\"File not found\");\n exit(1);\n }\n char c;\n int idx=0;\n while (fscanf(file , \"%c\" ,&c) == 1)\n {\n buffer[idx] = c;\n idx++;\n }\n buffer[idx] = 0;\n}\n"
},
{
"answer_id": 70409447,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 3,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\n\n// Read the file into allocated memory.\n// Return NULL on error.\nchar* readfile(FILE *f) {\n // f invalid? fseek() fail?\n if (f == NULL || fseek(f, 0, SEEK_END)) {\n return NULL;\n }\n\n long length = ftell(f);\n rewind(f);\n // Did ftell() fail? Is the length too long?\n if (length == -1 || (unsigned long) length >= SIZE_MAX) {\n return NULL;\n }\n\n // Convert from long to size_t\n size_t ulength = (size_t) length;\n char *buffer = malloc(ulength + 1);\n // Allocation failed? Read incomplete?\n if (buffer == NULL || fread(buffer, 1, ulength, f) != ulength) {\n free(buffer);\n return NULL;\n }\n buffer[ulength] = '\\0'; // Now buffer points to a string\n\n return buffer;\n}\n char* readfile(FILE *f, size_t *ulength_ptr) {\n ...\n if (ulength_ptr) *ulength_ptr == *ulength;\n ...\n} \n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/422/"
] |
174,532
|
<p>I recently inherited a database on which one of the tables has the primary key composed of encoded values (Part1*1000 + Part2).<br>
I normalized that column, but I cannot change the old values.
So now I have</p>
<pre><code>select ID from table order by ID
ID
100001
100002
101001
...
</code></pre>
<p>I want to find the "holes" in the table (more precisely, the first "hole" after 100000) for new rows.<br>
I'm using the following select, but is there a better way to do that?</p>
<pre><code>select /* top 1 */ ID+1 as newID from table
where ID > 100000 and
ID + 1 not in (select ID from table)
order by ID
newID
100003
101029
...
</code></pre>
<p>The database is Microsoft SQL Server 2000. I'm ok with using SQL extensions.</p>
|
[
{
"answer_id": 174561,
"author": "Santiago Palladino",
"author_id": 12791,
"author_profile": "https://Stackoverflow.com/users/12791",
"pm_score": 4,
"selected": false,
"text": "SELECT (ID+1) FROM table AS t1\nLEFT JOIN table as t2\nON t1.ID+1 = t2.ID\nWHERE t2.ID IS NULL\n"
},
{
"answer_id": 176219,
"author": "Thorsten",
"author_id": 25320,
"author_profile": "https://Stackoverflow.com/users/25320",
"pm_score": 5,
"selected": true,
"text": "select ID +1 From Table t1\nwhere not exists (select * from Table t2 where t1.id +1 = t2.id);\n"
},
{
"answer_id": 210675,
"author": "Jeff Jones",
"author_id": 22391,
"author_profile": "https://Stackoverflow.com/users/22391",
"pm_score": 4,
"selected": false,
"text": "SELECT l.id + 1 start_id, MIN(fr.id) - 1 stop_id\nFROM (table l\nLEFT JOIN table r\nON l.id = r.id - 1)\nLEFT JOIN table fr\nON l.id < fr.id\nWHERE r.id IS NULL AND fr.id IS NOT NULL\nGROUP BY l.id, r.id\n ID\n1001\n1002\n1005\n1006\n1007\n1009\n1011\n start_id stop_id\n1003 1004\n1008 1008\n1010 1010\n"
},
{
"answer_id": 2317619,
"author": "Zeljko Vlasic",
"author_id": 279397,
"author_profile": "https://Stackoverflow.com/users/279397",
"pm_score": 2,
"selected": false,
"text": "select numb + 1 from temp\nminus\nselect numb from temp;\n"
},
{
"answer_id": 17432002,
"author": "Carter Medlin",
"author_id": 324479,
"author_profile": "https://Stackoverflow.com/users/324479",
"pm_score": 2,
"selected": false,
"text": "select\n MIN(ID)\nfrom (\n select\n 100001 ID\n union all\n select\n [YourIdColumn]+1\n from\n [YourTable]\n where\n --Filter the rest of your key--\n ) foo\nleft join\n [YourTable]\n on [YourIdColumn]=ID\n and --Filter the rest of your key--\nwhere\n [YourIdColumn] is null\n"
},
{
"answer_id": 20586130,
"author": "Fernando Reis Guimaraes",
"author_id": 2643058,
"author_profile": "https://Stackoverflow.com/users/2643058",
"pm_score": 2,
"selected": false,
"text": "declare @maxId int\nselect @maxId = max(YOUR_COLUMN_ID) from YOUR_TABLE_HERE\n\n\ndeclare @t table (id int)\n\ndeclare @i int\nset @i = 1\n\nwhile @i <= @maxId\nbegin\n insert into @t values (@i)\n set @i = @i +1\nend\n\nselect t.id\nfrom @t t\nleft join YOUR_TABLE_HERE x on x.YOUR_COLUMN_ID = t.id\nwhere x.YOUR_COLUMN_ID is null\n"
},
{
"answer_id": 20856776,
"author": "user3149203",
"author_id": 3149203,
"author_profile": "https://Stackoverflow.com/users/3149203",
"pm_score": 1,
"selected": false,
"text": " select *\n from \n ( \n (select <COL>+1 as id, 'Bottom' AS 'Pos' from <TABLENAME> /*where <CONDITION*/>\n except\n select <COL>, 'Bottom' AS 'Pos' from <TABLENAME> /*where <CONDITION>*/)\n union\n (select <COL>-1 as id, 'Top' AS 'Pos' from <TABLENAME> /*where <CONDITION>*/\n except\n select <COL>, 'Top' AS 'Pos' from <TABLENAME> /*where <CONDITION>*/)\n ) t\n order by t.id, t.Pos\n"
},
{
"answer_id": 33285657,
"author": "Denis Reznik",
"author_id": 3130226,
"author_profile": "https://Stackoverflow.com/users/3130226",
"pm_score": 2,
"selected": false,
"text": "SELECT TOP(@MaxNumber) ROW_NUMBER() OVER (ORDER BY t1.number) \nFROM master..spt_values t1 CROSS JOIN master..spt_values t2 \nEXCEPT\nSELECT Id FROM <your_table>\n"
},
{
"answer_id": 41195455,
"author": "pdenti",
"author_id": 993706,
"author_profile": "https://Stackoverflow.com/users/993706",
"pm_score": 1,
"selected": false,
"text": "select id + 1 as newid from\n (select 100000 as id union select id from tbl) t\n where (id + 1 not in (select id from tbl)) and\n (id >= 100000)\n order by id\n limit 1;\n"
},
{
"answer_id": 46884832,
"author": "Xavier Dury",
"author_id": 599011,
"author_profile": "https://Stackoverflow.com/users/599011",
"pm_score": 1,
"selected": false,
"text": "select a, b from (\n select ID + 1 a, max(ID) over (order by ID rows between current row and 1 following) - 1 b from MY_TABLE\n) where a <= b order by a desc;\n"
},
{
"answer_id": 73123361,
"author": "Luca Rinaldi",
"author_id": 19625026,
"author_profile": "https://Stackoverflow.com/users/19625026",
"pm_score": 1,
"selected": false,
"text": "WITH holes AS (\n SELECT \n IIF(c2.id IS NULL,c1.id+1,null) as start,\n IIF(c3.id IS NULL,c1.id-1,null) AS stop,\n ROW_NUMBER () OVER (\n ORDER BY c1.id ASC\n ) AS rowNum\n FROM |mytable| AS c1\n LEFT JOIN |mytable| AS c2 ON c1.id+1 = c2.id\n LEFT JOIN |mytable| AS c3 ON c1.id-1 = c3.id\n WHERE c2.id IS NULL OR c3.id IS NULL\n)\nSELECT h1.start AS start, h2.stop AS stop FROM holes AS h1\nLEFT JOIN holes AS h2 ON h1.rowNum+1 = h2.rowNum\nWHERE h1.start IS NOT NULL AND h2.stop IS NOT NULL\nUNION ALL \nSELECT 1 AS start, h1.stop AS stop FROM holes AS h1\nWHERE h1.rowNum = 1 AND h1.stop > 0\nORDER BY h1.start ASC\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25324/"
] |
174,560
|
<p>How can you depend on test code from another module in Maven? </p>
<p>Example, I have 2 modules:</p>
<ul>
<li>Base</li>
<li>Main</li>
</ul>
<p>I would like a test case in Main to extend a base test class in Base. Is this possible?</p>
<p>Update: Found an <a href="https://stackoverflow.com/questions/174560/sharing-test-code-in-maven#174670">acceptable answer</a>, which involves creating a test jar.</p>
|
[
{
"answer_id": 174572,
"author": "Steve Moyer",
"author_id": 17008,
"author_profile": "https://Stackoverflow.com/users/17008",
"pm_score": -1,
"selected": false,
"text": "<dependency>\n <groupId>BaseGroup</groupId>\n <artifactId>Base</artifactId>\n <version>0.1.0-SNAPSHOT</version>\n <scope>test</scope>\n</dependency>\n"
},
{
"answer_id": 174583,
"author": "sal",
"author_id": 13753,
"author_profile": "https://Stackoverflow.com/users/13753",
"pm_score": 4,
"selected": false,
"text": " <dependency>\n <groupId>foo</groupId>\n <artifactId>test-base</artifactId>\n <version>1</version>\n <scope>test</scope>\n </dependency>\n"
},
{
"answer_id": 174670,
"author": "flicken",
"author_id": 12880,
"author_profile": "https://Stackoverflow.com/users/12880",
"pm_score": 8,
"selected": false,
"text": "src/test/java <project>\n <build>\n <plugins>\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-jar-plugin</artifactId>\n <version>2.4</version>\n <executions>\n <execution>\n <goals>\n <goal>test-jar</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n</project>\n <project>\n ...\n <dependencies>\n <dependency>\n <groupId>com.myco.app</groupId>\n <artifactId>foo</artifactId>\n <version>1.0-SNAPSHOT</version>\n <type>test-jar</type>\n <scope>test</scope>\n </dependency>\n </dependencies>\n ...\n</project> \n"
},
{
"answer_id": 174937,
"author": "Ben",
"author_id": 24795,
"author_profile": "https://Stackoverflow.com/users/24795",
"pm_score": 9,
"selected": true,
"text": "<dependency>\n <groupId>com.myco.app</groupId>\n <artifactId>foo</artifactId>\n <version>1.0-SNAPSHOT</version>\n <type>test-jar</type>\n <scope>test</scope>\n</dependency>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12880/"
] |
174,570
|
<p>I have the following code in one of my aspx pages:</p>
<pre><code><% foreach (Dependency dep in this.Common.GetDependencies(this.Request.QueryString["Name"]))
{ %>
<ctl:DependencyEditor DependencyKey='<%= dep.Key %>' runat="server" />
<% } %>
</code></pre>
<p>When I run it, I get the following error: <pre><strong>Parser Error Message:</strong> Cannot create an object of type 'System.Guid' from its string representation '<%= dep.Key %>' for the 'DependencyKey' property.</pre></p>
<p>Is there any way that I can create a control and pass in a Guid in the aspx page? I'd really hate to have to loop through and create these controls in the code behind just because of that...</p>
<p>NOTE: The Key property on the Dependency object <em>is</em> a Guid.</p>
|
[
{
"answer_id": 464127,
"author": "CRice",
"author_id": 55693,
"author_profile": "https://Stackoverflow.com/users/55693",
"pm_score": 0,
"selected": false,
"text": " <ctl:DependencyEditor DependencyKey=\"<%= new Guid(dep.Key) %>\" runat=\"server\" />\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3226/"
] |
174,582
|
<p>If I wish to simply rename a column (not change its type or constraints, just its name) in an SQL database using SQL, how do I do that? Or is it not possible?</p>
<p>This is for any database claiming to support SQL, I'm simply looking for an SQL-specific query that will work regardless of actual database implementation.</p>
|
[
{
"answer_id": 174586,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 7,
"selected": false,
"text": "sp_rename USE AdventureWorks;\nGO\nEXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';\nGO\n"
},
{
"answer_id": 174632,
"author": "bortzmeyer",
"author_id": 15625,
"author_profile": "https://Stackoverflow.com/users/15625",
"pm_score": 8,
"selected": true,
"text": "ALTER TABLE => SELECT * FROM Test1;\n id | foo | bar \n----+-----+-----\n 2 | 1 | 2\n\n=> ALTER TABLE Test1 RENAME COLUMN foo TO baz;\nALTER TABLE\n\n=> SELECT * FROM Test1;\n id | baz | bar \n----+-----+-----\n 2 | 1 | 2\n"
},
{
"answer_id": 193190,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": false,
"text": "RENAME COLUMN TableName.OldName TO NewName;\n"
},
{
"answer_id": 193203,
"author": "Rob",
"author_id": 3542,
"author_profile": "https://Stackoverflow.com/users/3542",
"pm_score": 2,
"selected": false,
"text": "ALTER TABLE"
},
{
"answer_id": 19579861,
"author": "Shadow Man",
"author_id": 2167531,
"author_profile": "https://Stackoverflow.com/users/2167531",
"pm_score": 5,
"selected": false,
"text": "ALTER TABLE MyTable ADD MyNewColumn OLD_COLUMN_TYPE;\nUPDATE MyTable SET MyNewColumn = MyOldColumn;\n-- add all necessary triggers and constraints to the new column...\n-- update all foreign key usages to point to the new column...\nALTER TABLE MyTable DROP COLUMN MyOldColumn;\n"
},
{
"answer_id": 26906635,
"author": "Syed Uzair Uddin",
"author_id": 3006390,
"author_profile": "https://Stackoverflow.com/users/3006390",
"pm_score": 1,
"selected": false,
"text": "SQL"
},
{
"answer_id": 30655490,
"author": "jaspher chloe",
"author_id": 4508165,
"author_profile": "https://Stackoverflow.com/users/4508165",
"pm_score": 5,
"selected": false,
"text": "ALTER TABLE ... CHANGE ALTER TABLE <table_name> CHANGE <column_name> <new_column_name> <data_type> ...\n"
},
{
"answer_id": 31740124,
"author": "Kunal Relan",
"author_id": 3193919,
"author_profile": "https://Stackoverflow.com/users/3193919",
"pm_score": 5,
"selected": false,
"text": "SP_RENAME 'TABLE_NAME.OLD_COLUMN_NAME','NEW_COLUMN_NAME'\n"
},
{
"answer_id": 40019241,
"author": "Bimzee",
"author_id": 1729330,
"author_profile": "https://Stackoverflow.com/users/1729330",
"pm_score": 4,
"selected": false,
"text": "exec sp_rename '<TableName.OldColumnName>','<NewColumnName>','COLUMN'\n sp_rename '<TableName.OldColumnName>','<NewColumnName>','COLUMN'\n"
},
{
"answer_id": 43244867,
"author": "Prabhat Kumar Yadav",
"author_id": 7824141,
"author_profile": "https://Stackoverflow.com/users/7824141",
"pm_score": 3,
"selected": false,
"text": "exec sp_rename 'TableName.OldColumnName', 'New colunmName'\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8026/"
] |
174,595
|
<p>What is the difference between <code>ROWNUM</code> and <code>ROW_NUMBER</code> ? </p>
|
[
{
"answer_id": 174628,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 6,
"selected": true,
"text": "SQL> select rownum, ename, deptno\n 2 from emp;\n\n ROWNUM ENAME DEPTNO\n---------- ---------- ----------\n 1 SMITH 99\n 2 ALLEN 30\n 3 WARD 30\n 4 JONES 20\n 5 MARTIN 30\n 6 BLAKE 30\n 7 CLARK 10\n 8 SCOTT 20\n 9 KING 10\n 10 TURNER 30\n 11 FORD 20\n 12 MILLER 10\n SQL> select ename, deptno, row_number() over (partition by deptno order by ename) rn\n 2 from emp;\n\nENAME DEPTNO RN\n---------- ---------- ----------\nCLARK 10 1\nKING 10 2\nMILLER 10 3\nFORD 20 1\nJONES 20 2\nSCOTT 20 3\nALLEN 30 1\nBLAKE 30 2\nMARTIN 30 3\nTURNER 30 4\nWARD 30 5\nSMITH 99 1\n"
},
{
"answer_id": 174635,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 1,
"selected": false,
"text": "ORDER BY ROWNUM WHERE ROWNUM < 10 ORDER BY"
},
{
"answer_id": 11538632,
"author": "Lukas Eder",
"author_id": 521799,
"author_profile": "https://Stackoverflow.com/users/521799",
"pm_score": 1,
"selected": false,
"text": "ROWNUM ROW_NUMBER() OVER()"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9581/"
] |
174,598
|
<p>I am trying to get in place editing working but I am running into this error:</p>
<p>ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken)</p>
<p>I understand that rails now wants to protect against forgery and that I need to pass a form authenticity token but I am not clear on how to do this with the in_place_edit plugin.</p>
|
[
{
"answer_id": 174754,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 2,
"selected": false,
"text": ":with in_place_editor(\"my_element\", :with => \"form.serialize() + '&authenticity_token=#{form_authenticity_token}';\")\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6805/"
] |
174,600
|
<p>In SQL Server 2005, is there a way for a trigger to find out what object is responsible for firing the trigger? I would like to use this to disable the trigger for one stored procedure.</p>
<p>Is there any other way to disable the trigger only for the current transaction? I could use the following code, but if I'm not mistaken, it would affect concurrent transactions as well - which would be a bad thing.</p>
<pre><code>DISABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL } ON { object_name | DATABASE | ALL SERVER } [ ; ]
ENABLE TRIGGER { [ schema_name . ] trigger_name [ ,...n ] | ALL } ON { object_name | DATABASE | ALL SERVER } [ ; ]
</code></pre>
<p>If possible, I would like to avoid the technique of having a "NoTrigger" field in my table and doing a <code>NoTrigger = null</code>, because I would like to keep the table as small as possible.</p>
<p>The reason I would like to avoid the trigger is because it contains logic that is important for manual updates to the table, but my stored procedure will take care of this logic. Because this will be a highly used procedure, I want it to be fast.</p>
<blockquote>
<p>Triggers impose additional overhead on the server because they initiate an implicit transaction. As soon as a trigger is executed, a new implicit transaction is started, and any data retrieval within a transaction will hold locks on affected tables.</p>
</blockquote>
<p>From: <a href="http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1170220,00.html#trigger" rel="nofollow noreferrer">http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1170220,00.html#trigger</a></p>
|
[
{
"answer_id": 178192,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 7,
"selected": true,
"text": "USE AdventureWorks; \nGO \n-- creating the table in AdventureWorks database \nIF OBJECT_ID('dbo.Table1') IS NOT NULL \nDROP TABLE dbo.Table1 \nGO \nCREATE TABLE dbo.Table1(ID INT) \nGO \n-- Creating a trigger \nCREATE TRIGGER TR_Test ON dbo.Table1 FOR INSERT,UPDATE,DELETE \nAS \nDECLARE @Cinfo VARBINARY(128) \nSELECT @Cinfo = Context_Info() \nIF @Cinfo = 0x55555 \nRETURN \nPRINT 'Trigger Executed' \n-- Actual code goes here \n-- For simplicity, I did not include any code \nGO \n SET Context_Info 0x55555 \nINSERT dbo.Table1 VALUES(100)\n"
},
{
"answer_id": 5116718,
"author": "Steve",
"author_id": 634027,
"author_profile": "https://Stackoverflow.com/users/634027",
"pm_score": 2,
"selected": false,
"text": "IF OBJECT_ID('dbo.TriggerTest') IS NOT NULL\n DROP PROCEDURE dbo.TriggerTest\nGO\n\nCREATE PROCEDURE [dbo].[TriggerTest]\nAS\nBEGIN TRANSACTION trnInsertTable1s\n;\nDISABLE TRIGGER trg_tblTable1_IU ON tblTable1\n;\nBEGIN -- Procedure Code\n PRINT '@@trancount'\n PRINT @@TRANCOUNT\n -- Do Stuff\n\nEND -- Procedure Code\n;\nENABLE TRIGGER trg_tblTable1_IU ON tblTable1\n\nIF @@ERROR <> 0 ROLLBACK TRANSACTION\nELSE COMMIT TRANSACTION\n"
},
{
"answer_id": 13804699,
"author": "Nader Sghir",
"author_id": 1071859,
"author_profile": "https://Stackoverflow.com/users/1071859",
"pm_score": 0,
"selected": false,
"text": "EXEC ('ENABLE TRIGGER dbo.TriggerName on dbo.TriggeredTable')"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/357/"
] |
174,612
|
<p>On a cross platform c/c++ project (Win32, Linux, OSX), I need to use the *printf functions to print some variables of type size_t. In some environments size_t's are 8 bytes and on others they are 4. On glibc I have %zd, and on Win32 I can use <a href="http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx" rel="noreferrer">%Id</a>. Is there an elegant way to handle this?</p>
|
[
{
"answer_id": 174674,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 3,
"selected": false,
"text": "#ifdef __WIN32__ // or whatever\n#define SSIZET_FMT \"%ld\"\n#else\n#define SSIZET_FMT \"%zd\"\n#endif\n fprintf(stream, \"Your size_t var has value \" SSIZET_FMT \".\", your_var);\n"
},
{
"answer_id": 174716,
"author": "finnw",
"author_id": 12048,
"author_profile": "https://Stackoverflow.com/users/12048",
"pm_score": 4,
"selected": false,
"text": "PRIuPTR uintptr_t size_t fprintf(stream, \"Your size_t var has value %\" PRIuPTR \".\", (uintptr_t) your_var);\n"
},
{
"answer_id": 175361,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "size_t n;\n...\nprintf(\"%lu\", (unsigned long)n);\n"
},
{
"answer_id": 175794,
"author": "Lev",
"author_id": 7224,
"author_profile": "https://Stackoverflow.com/users/7224",
"pm_score": 2,
"selected": false,
"text": "boost::format size_t %d c_str() std::string %s"
},
{
"answer_id": 1324516,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "size_t %Iu %zu #ifdef"
},
{
"answer_id": 45422410,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": -1,
"selected": false,
"text": "size_t printf(\"%zu\\n\", some_size_t_object); // Standard since C99\n unsigned long // OK, yet insufficient with large sizes > ULONG_MAX\nprintf(\"%lu\\n\", (unsigned long) some_size_t_object); \n #ifdef ULLONG_MAX\n printf(\"%llu\\n\", (unsigned long long) some_size_t_object); \n#else\n printf(\"%lu\\n\", (unsigned long) some_size_t_object); \n#endif\n double double printf(\"%.0f\\n\", (double) some_size_t_object);\n"
},
{
"answer_id": 55943527,
"author": "Gabriel Staples",
"author_id": 4561887,
"author_profile": "https://Stackoverflow.com/users/4561887",
"pm_score": 0,
"selected": false,
"text": "PRIuPTR size_t size_t #include <inttypes.h>\n\n// Printf format strings for `size_t` variable types.\n#define PRIdSZT PRIdPTR\n#define PRIiSZT PRIiPTR\n#define PRIoSZT PRIoPTR\n#define PRIuSZT PRIuPTR\n#define PRIxSZT PRIxPTR\n#define PRIXSZT PRIXPTR\n size_t my_variable;\nprintf(\"%\" PRIuSZT \"\\n\", my_variable);\n %zu size_t size_t my_variable;\nprintf(\"%zu\\n\", my_variable);\n %z printf(\"%zu\\n\", my_size_t_num); size_t uint64_t #include <stdint.h> // for uint64_t\n#include <inttypes.h> // for PRIu64\n\nsize_t my_variable;\nprintf(\"%\" PRIu64 \"\\n\", (uint64_t)my_variable);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174612",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23524/"
] |
174,633
|
<p>My regular expression needs to be able to find the strings:</p>
<ol>
<li>Visual Studio 2008</li>
<li>Visual Studio Express 2008</li>
<li>Visual Basic 2008</li>
<li>Visual Basic Express 2008</li>
<li>Visual C++ 2008</li>
<li>Visual C++ Express 2008</li>
</ol>
<p>and a host of other similar variants, to be replaced with this one single string</p>
<blockquote>
<p>Visual Studio 2005</p>
</blockquote>
<p>I tried "Visual (Basic|C++|Studio) (Express)? 2008", but it is not working. Any ideas?</p>
<p><strong><em>Edit</strong>:
Now I have tried "Visual (Basic)|(C++)|(Studio) (Express )?2008", but the replaced line becomes "Visual Studio 2005 Express 2008" for the input "Visual Basic Express 2008".</em> </p>
|
[
{
"answer_id": 174660,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 2,
"selected": false,
"text": "\"Visual (Basic|C\\+\\+|Studio) (Express )?2008\"\n \"Visual [^ ]+ (Express )?2008\"\n"
},
{
"answer_id": 174665,
"author": "Matt Price",
"author_id": 852,
"author_profile": "https://Stackoverflow.com/users/852",
"pm_score": 2,
"selected": false,
"text": "Visual (Basic|C\\\\+\\\\+|Studio) (Express )?2008\n"
},
{
"answer_id": 174669,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": true,
"text": "\"Visual (Basic|C\\+\\+|Studio)( Express)? 2008\"\n\n>>> import re\n>>> repl = 'Visual Studio 2005'\n>>> regexp = re.compile('Visual (Studio|Basic|C\\+\\+)( Express)? 2008')\n>>> test1 = 'Visual Studio 2008'\n>>> test2 = 'Visual Studio Express 2008'\n>>> test3 = 'Visual C++ Express 2008'\n>>> test4 = 'Visual C++ Express 1008'\n>>> re.sub(regexp,repl,test1)\n'Visual Studio 2005'\n>>> re.sub(regexp,repl,test2)\n'Visual Studio 2005'\n>>> re.sub(regexp,repl,test3)\n'Visual Studio 2005'\n>>> re.sub(regexp,repl,test4)\n'Visual C++ Express 1008'\n"
},
{
"answer_id": 174680,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 0,
"selected": false,
"text": "Visual (Basic|C\\+\\+|Studio)( Express)? 2008\n Visual (?:Basic|C\\+\\+|Studio)(?: Express)? 2008\n"
},
{
"answer_id": 174683,
"author": "steve_c",
"author_id": 769,
"author_profile": "https://Stackoverflow.com/users/769",
"pm_score": 0,
"selected": false,
"text": "Visual\\s(Basic|C\\+\\+|Studio)(\\sExpress)?\\s2008\n"
},
{
"answer_id": 174701,
"author": "indiv",
"author_id": 19719,
"author_profile": "https://Stackoverflow.com/users/19719",
"pm_score": 1,
"selected": false,
"text": "Visual .+? 2008\n"
},
{
"answer_id": 174821,
"author": "Komang",
"author_id": 19463,
"author_profile": "https://Stackoverflow.com/users/19463",
"pm_score": 1,
"selected": false,
"text": "/visual (studio|basic|c\\+\\+)? (express)?\\s?2008/i\n"
},
{
"answer_id": 26632301,
"author": "Suganthan Madhavan Pillai",
"author_id": 2534236,
"author_profile": "https://Stackoverflow.com/users/2534236",
"pm_score": -1,
"selected": false,
"text": "/Visual.*2008/g\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3834/"
] |
174,659
|
<p>I'm writing a little tile-based game, for which I'd like to support light sources. But my algorithm-fu is too weak, hence I come to you for help.</p>
<p>The situation is like this: There is a tile-based map (held as a 2D array), containing a single light source and several items standing around. I want to calculate which tiles are lit up by the light source, and which are in shadow.</p>
<p>A visual aid of what it would look like, approximately. The L is the light source, the Xs are items blocking the light, the 0s are lit tiles, and the -s are tiles in shadow.</p>
<pre><code>0 0 0 0 0 0 - - 0
0 0 0 0 0 0 - 0 0
0 0 0 0 0 X 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 L 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 X X X X 0 0
0 0 0 - - - - - 0
0 0 - - - - - - -
</code></pre>
<p>A fractional system would be even better, of course, where a tile can be in half-shadow due to being partially obscured. The algorithm wouldn't have to be perfect - just not obviously wrong and reasonably fast.</p>
<p>(Of course, there would be multiple light sources, but that's just a loop.)</p>
<p>Any takers?</p>
|
[
{
"answer_id": 175004,
"author": "easeout",
"author_id": 10906,
"author_profile": "https://Stackoverflow.com/users/10906",
"pm_score": 2,
"selected": false,
"text": "- - - - -\n- X X X -\n- X X - -\n- X - - -\n- - - - L\n"
},
{
"answer_id": 497739,
"author": "DShook",
"author_id": 370,
"author_profile": "https://Stackoverflow.com/users/370",
"pm_score": 2,
"selected": false,
"text": "void Battle::CheckSensorRange(Unit* unit,bool fog){\n int sensorRange = 0;\n for(int i=0; i < unit->GetSensorSlots(); i++){\n if(unit->GetSensorSlot(i)->GetSlotEmpty() == false){\n sensorRange += unit->GetSensorSlot(i)->GetSensor()->GetRange()+1;\n }\n }\n int originX = unit->GetUnitX();\n int originY = unit->GetUnitY();\n\n float lineLength;\n vector <Place> maxCircle;\n\n //get a circle around the unit\n for(int i = originX - sensorRange; i < originX + sensorRange; i++){\n if(i < 0){\n continue;\n }\n for(int j = originY - sensorRange; j < originY + sensorRange; j++){\n if(j < 0){\n continue;\n }\n lineLength = sqrt( (float)((originX - i)*(originX - i)) + (float)((originY - j)*(originY - j)));\n if(lineLength < (float)sensorRange){\n Place tmp;\n tmp.x = i;\n tmp.y = j;\n maxCircle.push_back(tmp);\n }\n }\n }\n\n //if we're supposed to fog everything we don't have to do any fancy calculations\n if(fog){\n for(int circleI = 0; circleI < (int) maxCircle.size(); circleI++){\n Map->GetGrid(maxCircle[circleI].x,maxCircle[circleI].y)->SetFog(fog);\n }\n }else{\n\n bool LOSCheck = true;\n vector <bool> placeCheck;\n\n //have to check all of the tiles to begin with \n for(int circleI = 0; circleI < (int) maxCircle.size(); circleI++){\n placeCheck.push_back(true);\n }\n\n //for all tiles in the circle, check LOS\n for(int circleI = 0; circleI < (int) maxCircle.size(); circleI++){\n vector<Place> lineTiles;\n lineTiles = line(originX, originY, maxCircle[circleI].x, maxCircle[circleI].y);\n\n //check each tile in the line for LOS\n for(int lineI = 0; lineI < (int) lineTiles.size(); lineI++){\n if(false == CheckPlaceLOS(lineTiles[lineI], unit)){\n LOSCheck = false;\n\n //mark this tile not to be checked again\n placeCheck[circleI] = false;\n }\n if(false == LOSCheck){\n break;\n }\n }\n\n if(LOSCheck){\n Map->GetGrid(maxCircle[circleI].x,maxCircle[circleI].y)->SetFog(fog);\n }else{\n LOSCheck = true;\n }\n }\n }\n\n}\n"
},
{
"answer_id": 11635950,
"author": "pents90",
"author_id": 369833,
"author_profile": "https://Stackoverflow.com/users/369833",
"pm_score": 2,
"selected": false,
"text": "9876789\n8543458\n7421247\n6310136\n7421247\n8543458\n9876789\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174659",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15255/"
] |
174,662
|
<p>I hope this isn't considered a duplicate since it's more pointed than similar questions (I'm curious about a specific weakness in C# to VB.net conversion utilities).</p>
<p>I've been looking at using a tool like this <a href="http://www.developerfusion.com/tools/convert/csharp-to-vb/" rel="nofollow noreferrer">.net code converter</a> to convert a class library to VB since I'm the only one in my group comfortable with C#. The problem I've run into is that it doesn't generate proper VB for automatic properties. It creates empty get/set routines. </p>
<p>So this:</p>
<pre><code>public string TransactionType { get; private set; }
</code></pre>
<p>Becomes this:</p>
<pre><code>Public Property TransactionType() As String
Get
End Get
Private Set(ByVal value As String)
End Set
End Property
</code></pre>
<p>The tools linked <a href="https://stackoverflow.com/questions/102956/c-vbnet-conversion" title="here">here</a> and <a href="https://stackoverflow.com/questions/88359/what-is-the-best-c-to-vbnet-converter">here</a> have similar issues - some create valid properties, but they don't respect the access level of the set routine.</p>
<p>Side question - If you were going to fix the converter on DeveloperFusion, would you have it return something like this?</p>
<pre><code>Private _TransactionType As String
Public Property TransactionType() As String
Get
Return _TransactionType
End Get
Private Set(ByVal value As String)
_TransactionType = value
End Set
End Property
</code></pre>
|
[
{
"answer_id": 209425,
"author": "Jaykul",
"author_id": 8718,
"author_profile": "https://Stackoverflow.com/users/8718",
"pm_score": 2,
"selected": false,
"text": "Property TransactionType As String\n Public Get\n Private Set(ByVal value As String)\nEnd Property\n Property TransactionType As String\n Public Get\n Return Me.<TransactionType>k__BackingField\n End Get\n Private Set(ByVal value As String)\n Me.<TransactionType>k__BackingField = value\n End Set\nEnd Property\n\n<CompilerGenerated> _\nPrivate <TransactionType>k__BackingField As String\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8513/"
] |
174,664
|
<p>I need to evaluate a mathmatical expression that is presented to me as a string in C#. Example noddy but gets the point across that the string as the expression.</p>
<p>I need the evaluate to then populate an int.</p>
<p>There is no Eval() in C# like in others langugaes...</p>
<pre><code>String myString = "3*4";
</code></pre>
<p>Edit:</p>
<p>I am on VS2008 </p>
<p>Tried the Microsoft.JScript. = Its deprecated method (but still complies - warning)</p>
<p>However the Microsoft.JScript dll that I have doens work on </p>
<blockquote>
<p>public object InvokeMember(string
name, BindingFlags invokeAttr, Binder
binder, object target, object[] args);</p>
</blockquote>
<p>Complains that there is a missing ";" go figure...</p>
<p>EDIT 2</p>
<p>Solution - was the codeDom one - it worked for as there are no security issue - only me ever going to be running the code. Many thanks for the replies ...</p>
<p>And the link to the new Dragon Book awesome </p>
<p>EDIT 3</p>
<p>Matt dataTable.Compute() also works - even better for the security conscious. (parameter checking noted)</p>
|
[
{
"answer_id": 175262,
"author": "Matt Crouch",
"author_id": 1670022,
"author_profile": "https://Stackoverflow.com/users/1670022",
"pm_score": 5,
"selected": false,
"text": " DataTable dummy = new DataTable();\n Console.WriteLine(dummy.Compute(\"15 / 3\",string.Empty));\n Expression System.Data.DataColumn"
},
{
"answer_id": 176336,
"author": "Austin Salonen",
"author_id": 4068,
"author_profile": "https://Stackoverflow.com/users/4068",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Text.RegularExpressions;\n\nnamespace StackOverflow\n{\n class Start\n {\n public static void Main(string[] args)\n {\n Evaluator ev;\n string variableValue, eq;\n Console.Write(\"Enter equation: \");\n eq = Console.ReadLine();\n\n while (eq != \"quit\")\n {\n ev = new Evaluator(eq);\n foreach (Variable v in ev.Variables)\n {\n Console.Write(v.Name + \" = \");\n variableValue = Console.ReadLine();\n ev.SetVariable(v.Name, Convert.ToDecimal(variableValue));\n }\n\n Console.WriteLine(ev.Evaluate());\n\n Console.Write(\"Enter equation: \");\n eq = Console.ReadLine();\n }\n }\n}\n\nclass EvalNode\n{\n public virtual decimal Evaluate()\n {\n return decimal.Zero;\n }\n}\n\nclass ValueNode : EvalNode\n{\n decimal value;\n\n public ValueNode(decimal v)\n {\n value = v;\n }\n\n public override decimal Evaluate()\n {\n return value;\n }\n\n public override string ToString()\n {\n return value.ToString();\n }\n}\n\nclass FunctionNode : EvalNode\n{\n EvalNode lhs = new ValueNode(decimal.Zero);\n EvalNode rhs = new ValueNode(decimal.Zero);\n string op = \"+\";\n\n public string Op\n {\n get { return op; }\n set\n {\n op = value;\n }\n }\n\n internal EvalNode Rhs\n {\n get { return rhs; }\n set\n {\n rhs = value;\n }\n }\n\n internal EvalNode Lhs\n {\n get { return lhs; }\n set\n {\n lhs = value;\n }\n }\n\n public override decimal Evaluate()\n {\n decimal result = decimal.Zero;\n\n switch (op)\n {\n case \"+\":\n result = lhs.Evaluate() + rhs.Evaluate();\n break;\n\n case \"-\":\n result = lhs.Evaluate() - rhs.Evaluate();\n break;\n\n case \"*\":\n result = lhs.Evaluate() * rhs.Evaluate();\n break;\n\n case \"/\":\n result = lhs.Evaluate() / rhs.Evaluate();\n break;\n\n case \"%\":\n result = lhs.Evaluate() % rhs.Evaluate();\n break;\n\n case \"^\":\n double x = Convert.ToDouble(lhs.Evaluate());\n double y = Convert.ToDouble(rhs.Evaluate());\n\n result = Convert.ToDecimal(Math.Pow(x, y));\n break;\n\n case \"!\":\n result = Factorial(lhs.Evaluate());\n break;\n }\n\n return result;\n }\n\n private decimal Factorial(decimal factor)\n {\n if (factor < 1)\n return 1;\n\n return factor * Factorial(factor - 1);\n }\n\n public override string ToString()\n {\n return \"(\" + lhs.ToString() + \" \" + op + \" \" + rhs.ToString() + \")\";\n }\n}\n\npublic class Evaluator\n{\n string equation = \"\";\n Dictionary<string, Variable> variables = new Dictionary<string, Variable>();\n\n public string Equation\n {\n get { return equation; }\n set { equation = value; }\n }\n\n public Variable[] Variables\n {\n get { return new List<Variable>(variables.Values).ToArray(); }\n }\n\n public void SetVariable(string name, decimal value)\n {\n if (variables.ContainsKey(name))\n {\n Variable x = variables[name];\n x.Value = value;\n variables[name] = x;\n }\n }\n\n public Evaluator(string equation)\n {\n this.equation = equation;\n SetVariables();\n }\n\n public decimal Evaluate()\n {\n return Evaluate(equation, new List<Variable>(variables.Values));\n }\n\n public decimal Evaluate(string text)\n {\n decimal result = decimal.Zero;\n equation = text;\n EvalNode parsed;\n\n equation = equation.Replace(\" \", \"\");\n\n parsed = Parse(equation, \"qx\");\n\n if (parsed != null)\n result = parsed.Evaluate();\n\n return result;\n }\n\n public decimal Evaluate(string text, List<Variable> variables)\n {\n foreach (Variable v in variables)\n {\n text = text.Replace(v.Name, v.Value.ToString());\n }\n\n return Evaluate(text);\n }\n\n private static bool EquationHasVariables(string equation)\n {\n Regex letters = new Regex(@\"[A-Za-z]\");\n\n return letters.IsMatch(equation);\n }\n\n private void SetVariables()\n {\n Regex letters = new Regex(@\"([A-Za-z]+)\");\n Variable v;\n\n foreach (Match m in letters.Matches(equation, 0))\n {\n v = new Variable(m.Groups[1].Value, decimal.Zero);\n\n if (!variables.ContainsKey(v.Name))\n {\n variables.Add(v.Name, v);\n }\n }\n }\n\n #region Parse V2\n\n private Dictionary<string, string> parenthesesText = new Dictionary<string, string>();\n\n /*\n * 1. All the text in first-level parentheses is replaced with replaceText plus an index value.\n * (All nested parentheses are parsed in recursive calls)\n * 2. The simple function is parsed given the order of operations (reverse priority to \n * keep the order of operations correct when evaluating).\n * a. Addition (+), subtraction (-) -> left to right\n * b. Multiplication (*), division (/), modulo (%) -> left to right\n * c. Exponents (^) -> right to left\n * d. Factorials (!) -> left to right\n * e. No op (number, replaced parentheses) \n * 3. When an op is found, a two recursive calls are generated -- parsing the LHS and \n * parsing the RHS.\n * 4. An EvalNode representing the root node of the evaluations tree is returned.\n * \n * Ex. 3 + 5 (3 + 5) * 8\n * + *\n * / \\ / \\\n * 3 5 + 8\n * / \\ \n * 3 + 5 * 8 3 5\n * +\n * / \\\n * 3 *\n * / \\\n * 5 8\n */\n\n /// <summary>\n /// Parses the expression and returns the root node of a tree.\n /// </summary>\n /// <param name=\"eq\">Equation to be parsed</param>\n /// <param name=\"replaceText\">Text base that replaces text in parentheses</param>\n /// <returns></returns>\n private EvalNode Parse(string eq, string replaceText)\n {\n int randomKeyIndex = 0;\n\n eq = eq.Replace(\" \", \"\");\n if (eq.Length == 0)\n {\n return new ValueNode(decimal.Zero);\n }\n\n int leftParentIndex = -1;\n int rightParentIndex = -1;\n SetIndexes(eq, ref leftParentIndex, ref rightParentIndex);\n\n //remove extraneous outer parentheses\n while (leftParentIndex == 0 && rightParentIndex == eq.Length - 1)\n {\n eq = eq.Substring(1, eq.Length - 2);\n SetIndexes(eq, ref leftParentIndex, ref rightParentIndex);\n }\n\n //Pull out all expressions in parentheses\n replaceText = GetNextReplaceText(replaceText, randomKeyIndex);\n\n while (leftParentIndex != -1 && rightParentIndex != -1)\n {\n //replace the string with a random set of characters, stored extracted text in dictionary keyed on the random set of chars\n\n string p = eq.Substring(leftParentIndex, rightParentIndex - leftParentIndex + 1);\n eq = eq.Replace(p, replaceText);\n parenthesesText.Add(replaceText, p);\n\n leftParentIndex = 0;\n rightParentIndex = 0;\n\n replaceText = replaceText.Remove(replaceText.LastIndexOf(randomKeyIndex.ToString()));\n randomKeyIndex++;\n replaceText = GetNextReplaceText(replaceText, randomKeyIndex);\n\n SetIndexes(eq, ref leftParentIndex, ref rightParentIndex);\n }\n\n /*\n * Be sure to implement these operators in the function node class\n */\n char[] ops_order0 = new char[2] { '+', '-' };\n char[] ops_order1 = new char[3] { '*', '/', '%' };\n char[] ops_order2 = new char[1] { '^' };\n char[] ops_order3 = new char[1] { '!' };\n\n /*\n * In order to evaluate nodes LTR, the right-most node must be the root node\n * of the tree, which is why we find the last index of LTR ops. The reverse \n * is the case for RTL ops.\n */\n\n int order0Index = eq.LastIndexOfAny(ops_order0);\n\n if (order0Index > -1)\n {\n return CreateFunctionNode(eq, order0Index, replaceText + \"0\");\n }\n\n int order1Index = eq.LastIndexOfAny(ops_order1);\n\n if (order1Index > -1)\n {\n return CreateFunctionNode(eq, order1Index, replaceText + \"0\");\n }\n\n int order2Index = eq.IndexOfAny(ops_order2);\n\n if (order2Index > -1)\n {\n return CreateFunctionNode(eq, order2Index, replaceText + \"0\");\n }\n\n int order3Index = eq.LastIndexOfAny(ops_order3);\n\n if (order3Index > -1)\n {\n return CreateFunctionNode(eq, order3Index, replaceText + \"0\");\n }\n\n //no operators...\n eq = eq.Replace(\"(\", \"\");\n eq = eq.Replace(\")\", \"\");\n\n if (char.IsLetter(eq[0]))\n {\n return Parse(parenthesesText[eq], replaceText + \"0\");\n }\n\n return new ValueNode(decimal.Parse(eq));\n }\n\n private string GetNextReplaceText(string replaceText, int randomKeyIndex)\n {\n while (parenthesesText.ContainsKey(replaceText))\n {\n replaceText = replaceText + randomKeyIndex.ToString();\n }\n return replaceText;\n }\n\n private EvalNode CreateFunctionNode(string eq, int index, string randomKey)\n {\n FunctionNode func = new FunctionNode();\n func.Op = eq[index].ToString();\n func.Lhs = Parse(eq.Substring(0, index), randomKey);\n func.Rhs = Parse(eq.Substring(index + 1), randomKey);\n\n return func;\n }\n\n #endregion\n\n /// <summary>\n /// Find the first set of parentheses\n /// </summary>\n /// <param name=\"eq\"></param>\n /// <param name=\"leftParentIndex\"></param>\n /// <param name=\"rightParentIndex\"></param>\n private static void SetIndexes(string eq, ref int leftParentIndex, ref int rightParentIndex)\n {\n leftParentIndex = eq.IndexOf('(');\n rightParentIndex = eq.IndexOf(')');\n int tempIndex = eq.IndexOf('(', leftParentIndex + 1);\n\n while (tempIndex != -1 && tempIndex < rightParentIndex)\n {\n rightParentIndex = eq.IndexOf(')', rightParentIndex + 1);\n tempIndex = eq.IndexOf('(', tempIndex + 1);\n }\n }\n}\n\npublic struct Variable\n{\n public string Name;\n public decimal Value;\n\n public Variable(string n, decimal v)\n {\n Name = n;\n Value = v;\n }\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,702
|
<p>After Visual Studio 2005 displays the splash screen it locks up on me. No error, no cpu utilization, just a frozen splash screen. I've tried it in both /safemode and /resetsettings</p>
<p>I'm sure it's one of the services on my machine, just wonder if anyone else has had the problem and can help me with the hunt?</p>
<p>BTW, it's works in a VM in the same machine.</p>
<p>Update: I finally tried something new, I started VS2005 in Windows compatibility 2000 mode, it starts then shuts down immediately. I reset it to not run in compatibility mode and it starts right up. grrrrr</p>
<p>I think it might be a profile issue, but the root cause is still unresolved.</p>
|
[
{
"answer_id": 889430,
"author": "sean e",
"author_id": 103912,
"author_profile": "https://Stackoverflow.com/users/103912",
"pm_score": 0,
"selected": false,
"text": "devenv.exe /Log c:\\vs.log\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4230/"
] |
174,705
|
<p>We have TFS 2008 our build set up to checkout all AssemblyInfo.cs files in the project, update them with AssemblyInfoTask, and then either undo the checkout or checkin depending on whether the build passed or not. Unfortunately, when two builds are queued close together this results in a Partially completed build as the AssemblyInfo.cs files seem to be checked out at an earlier version to the previous checkin.</p>
<p>In order to get around this I thought that I could use the "Get" task to force the AssemblyInfo.cs files to the latest version before updating them, but this appears to have no effect. Any ideas?</p>
<pre><code><Target Name="AfterGet" Condition="'$(IsDesktopBuild)'!='true'">
<Message Text="SolutionRoot = $(SolutionRoot)" />
<Message Text="OutDir = $(OutDir)" />
<!-- Set the AssemblyInfoFiles items dynamically -->
<CreateItem Include="$(SolutionRoot)\Main\Source\InputApplicationSln\**\$(AssemblyInfoSpec)">
<Output ItemName="AssemblyInfoFiles" TaskParameter="Include" />
</CreateItem>
<Message Text="$(AssemblyInfoFiles)" />
<!-- When builds are queued up successively, it is possible for the next build to be set up before the AssemblyInfoSpec is checked in so we need to force
the latest these versions of these files to be got before a checkout -->
<Get Condition=" '$(SkipGet)'!='true' " TeamFoundationServerUrl="$(TeamFoundationServerUrl)" Workspace="$(WorkspaceName)" Filespec="$(AssemblyInfoSpec)" Recursive="$(RecursiveGet)" Force="$(ForceGet)" />
<Exec WorkingDirectory="$(SolutionRoot)\Main\Source\InputApplicationSln"
Command="$(TF) checkout /recursive $(AssemblyInfoSpec)"/>
</code></pre>
<p></p>
<p>
</p>
|
[
{
"answer_id": 889430,
"author": "sean e",
"author_id": 103912,
"author_profile": "https://Stackoverflow.com/users/103912",
"pm_score": 0,
"selected": false,
"text": "devenv.exe /Log c:\\vs.log\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12565/"
] |
174,719
|
<p>What is the best way to keep your configuration files (e.g httpd.conf, my.cnf, .bashrc ...) under version control?
In adition to the versioning benefit, I want the solution to work as backup as well, so that I can bring a brand new server and checkout (or export) the config files out of SVN directly</p>
<p>A good touch will be to store the config file`s original path as well.</p>
|
[
{
"answer_id": 174788,
"author": "Chris R",
"author_id": 23309,
"author_profile": "https://Stackoverflow.com/users/23309",
"pm_score": 0,
"selected": false,
"text": "<root>/common\n /.emacs.d\n /.bash_common\n /scripts # platform-independent binary tools\n\n<root>/linux\n .bashrc\n .emacs\n ...\n\n<root>/solaris\n .bashrc\n .emacs\n ...\n\n<root>/osx\n .bashrc\n .emacs\n ...\n"
},
{
"answer_id": 174791,
"author": "EfForEffort",
"author_id": 14113,
"author_profile": "https://Stackoverflow.com/users/14113",
"pm_score": 2,
"selected": false,
"text": "install.sh install.sh install.sh"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7370/"
] |
174,727
|
<p>Oracle FAQ defines temp table space as follows:</p>
<blockquote>
<p>Temporary tablespaces are used to
manage space for database sort
operations and for storing global
temporary tables. For example, if you
join two large tables, and Oracle
cannot do the sort in memory, space
will be allocated in a temporary
tablespace for doing the sort
operation.</p>
</blockquote>
<p>That's great, but I need more detail about what exactly is using the space. Due to quirks of the application design most queries do some kind of sorting, so I need to narrow it down to client executable, target table, or SQL statement.</p>
<p>Essentially, I'm looking for clues to tell me more precisely what might be wrong with this (rather large application). Any sort of clue might be useful, so long as it is more precise than "sorting".</p>
|
[
{
"answer_id": 174765,
"author": "Michael OShea",
"author_id": 13178,
"author_profile": "https://Stackoverflow.com/users/13178",
"pm_score": 5,
"selected": true,
"text": "SELECT b.TABLESPACE\n , b.segfile#\n , b.segblk#\n , ROUND ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb\n , a.SID\n , a.serial#\n , a.username\n , a.osuser\n , a.program\n , a.status\n FROM v$session a\n , v$sort_usage b\n , v$process c\n , v$parameter p\n WHERE p.NAME = 'db_block_size'\n AND a.saddr = b.session_addr\n AND a.paddr = c.addr\nORDER BY b.TABLESPACE\n , b.segfile#\n , b.segblk#\n , b.blocks;\n"
},
{
"answer_id": 28084107,
"author": "Najee Ghanim",
"author_id": 4481610,
"author_profile": "https://Stackoverflow.com/users/4481610",
"pm_score": 2,
"selected": false,
"text": "SELECT b.TABLESPACE\n , b.segfile#\n , b.segblk#\n , ROUND ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb\n , a.inst_ID\n , a.SID\n , a.serial#\n , a.username\n , a.osuser\n , a.program\n , a.status\n FROM gv$session a\n , gv$sort_usage b\n , gv$process c\n , gv$parameter p\n WHERE p.NAME = 'db_block_size'\n AND a.saddr = b.session_addr\n AND a.paddr = c.addr\n -- AND b.TABLESPACE='TEMP2'\nORDER BY a.inst_ID , b.TABLESPACE\n , b.segfile#\n , b.segblk#\n , b.blocks;\n SELECT b.TABLESPACE, a.username , a.osuser , a.program , a.status ,\n 'ALTER SYSTEM KILL SESSION '''||a.SID||','||a.SERIAL#||',@'||a.inst_ID||''' IMMEDIATE;'\n FROM gv$session a\n , gv$sort_usage b\n , gv$process c\n , gv$parameter p\n WHERE p.NAME = 'db_block_size'\n AND a.saddr = b.session_addr\n AND a.paddr = c.addr\n -- AND b.TABLESPACE='TEMP'\nORDER BY a.inst_ID , b.TABLESPACE\n , b.segfile#\n , b.segblk#\n , b.blocks;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13935/"
] |
174,730
|
<p>Given a credit card number and no additional information, what is the best way in PHP to determine whether or not it is a valid number?</p>
<p>Right now I need something that will work with American Express, Discover, MasterCard, and Visa, but it might be helpful if it will also work with other types.</p>
|
[
{
"answer_id": 174747,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 3,
"selected": false,
"text": "function validateCC($cc_num, $type) {\n\n if($type == \"American\") {\n $denum = \"American Express\";\n } elseif($type == \"Dinners\") {\n $denum = \"Diner's Club\";\n } elseif($type == \"Discover\") {\n $denum = \"Discover\";\n } elseif($type == \"Master\") {\n $denum = \"Master Card\";\n } elseif($type == \"Visa\") {\n $denum = \"Visa\";\n }\n\n if($type == \"American\") {\n $pattern = \"/^([34|37]{2})([0-9]{13})$/\";//American Express\n if (preg_match($pattern,$cc_num)) {\n $verified = true;\n } else {\n $verified = false;\n }\n\n\n } elseif($type == \"Dinners\") {\n $pattern = \"/^([30|36|38]{2})([0-9]{12})$/\";//Diner's Club\n if (preg_match($pattern,$cc_num)) {\n $verified = true;\n } else {\n $verified = false;\n }\n\n\n } elseif($type == \"Discover\") {\n $pattern = \"/^([6011]{4})([0-9]{12})$/\";//Discover Card\n if (preg_match($pattern,$cc_num)) {\n $verified = true;\n } else {\n $verified = false;\n }\n\n\n } elseif($type == \"Master\") {\n $pattern = \"/^([51|52|53|54|55]{2})([0-9]{14})$/\";//Mastercard\n if (preg_match($pattern,$cc_num)) {\n $verified = true;\n } else {\n $verified = false;\n }\n\n\n } elseif($type == \"Visa\") {\n $pattern = \"/^([4]{1})([0-9]{12,15})$/\";//Visa\n if (preg_match($pattern,$cc_num)) {\n $verified = true;\n } else {\n $verified = false;\n }\n\n }\n\n if($verified == false) {\n //Do something here in case the validation fails\n echo \"Credit card invalid. Please make sure that you entered a valid <em>\" . $denum . \"</em> credit card \";\n\n } else { //if it will pass...do something\n echo \"Your <em>\" . $denum . \"</em> credit card is valid\";\n }\n\n\n}\n echo validateCC(\"1738292928284637\", \"Dinners\");\n"
},
{
"answer_id": 174750,
"author": "Ray Hayes",
"author_id": 7093,
"author_profile": "https://Stackoverflow.com/users/7093",
"pm_score": 8,
"selected": true,
"text": "<?\n/* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org *\n * This code has been released into the public domain, however please *\n * give credit to the original author where possible. */\n\nfunction luhn_check($number) {\n\n // Strip any non-digits (useful for credit card numbers with spaces and hyphens)\n $number=preg_replace('/\\D/', '', $number);\n\n // Set the string length and parity\n $number_length=strlen($number);\n $parity=$number_length % 2;\n\n // Loop through each digit and do the maths\n $total=0;\n for ($i=0; $i<$number_length; $i++) {\n $digit=$number[$i];\n // Multiply alternate digits by two\n if ($i % 2 == $parity) {\n $digit*=2;\n // If the sum is two digits, add them together (in effect)\n if ($digit > 9) {\n $digit-=9;\n }\n }\n // Total up the digits\n $total+=$digit;\n }\n\n // If the total mod 10 equals 0, the number is valid\n return ($total % 10 == 0) ? TRUE : FALSE;\n\n}\n?>\n"
},
{
"answer_id": 174772,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 5,
"selected": false,
"text": "function check_cc($cc, $extra_check = false){\n $cards = array(\n \"visa\" => \"(4\\d{12}(?:\\d{3})?)\",\n \"amex\" => \"(3[47]\\d{13})\",\n \"jcb\" => \"(35[2-8][89]\\d\\d\\d{10})\",\n \"maestro\" => \"((?:5020|5038|6304|6579|6761)\\d{12}(?:\\d\\d)?)\",\n \"solo\" => \"((?:6334|6767)\\d{12}(?:\\d\\d)?\\d?)\",\n \"mastercard\" => \"(5[1-5]\\d{14})\",\n \"switch\" => \"(?:(?:(?:4903|4905|4911|4936|6333|6759)\\d{12})|(?:(?:564182|633110)\\d{10})(\\d\\d)?\\d?)\",\n );\n $names = array(\"Visa\", \"American Express\", \"JCB\", \"Maestro\", \"Solo\", \"Mastercard\", \"Switch\");\n $matches = array();\n $pattern = \"#^(?:\".implode(\"|\", $cards).\")$#\";\n $result = preg_match($pattern, str_replace(\" \", \"\", $cc), $matches);\n if($extra_check && $result > 0){\n $result = (validatecard($cc))?1:0;\n }\n return ($result>0)?$names[sizeof($matches)-2]:false;\n}\n $cards = array(\n \"4111 1111 1111 1111\",\n);\n\nforeach($cards as $c){\n $check = check_cc($c, true);\n if($check!==false)\n echo $c.\" - \".$check;\n else\n echo \"$c - Not a match\";\n echo \"<br/>\";\n}\n"
},
{
"answer_id": 27445765,
"author": "parkamark",
"author_id": 241812,
"author_profile": "https://Stackoverflow.com/users/241812",
"pm_score": 0,
"selected": false,
"text": ">>> not(sum(map(int, ''.join(str(n*(i%2+1)) for i, n in enumerate(map(int, reversed('1234567890123452'))))))%10)\nTrue\n>>> not(sum(map(int, ''.join(str(n*(i%2+1)) for i, n in enumerate(map(int, reversed('1234567890123451'))))))%10)\nFalse\n >>> (10-sum(map(int, ''.join(str(n*(i%2+1)) for i, n in enumerate(map(int, reversed('123456789012345')), start=1)))))%10\n2\n>>> (10-sum(map(int, ''.join(str(n*(i%2+1)) for i, n in enumerate(map(int, reversed('234567890123451')), start=1)))))%10\n1\n DROP FUNCTION IF EXISTS ccc;\nDROP FUNCTION IF EXISTS ccd;\n\nDELIMITER //\n\nCREATE FUNCTION ccc (n TINYTEXT) RETURNS BOOL\nBEGIN\n DECLARE x TINYINT UNSIGNED;\n DECLARE l TINYINT UNSIGNED DEFAULT length(n);\n DECLARE i TINYINT UNSIGNED DEFAULT l;\n DECLARE s SMALLINT UNSIGNED DEFAULT 0;\n WHILE i > 0 DO\n SET x = mid(n,i,1);\n IF (l-i) mod 2 = 1 THEN\n SET x = x * 2;\n END IF;\n SET s = s + x div 10 + x mod 10;\n SET i = i - 1;\n END WHILE;\n RETURN s != 0 && s mod 10 = 0;\nEND;\n\nCREATE FUNCTION ccd (n TINYTEXT) RETURNS TINYINT\nBEGIN\n DECLARE x TINYINT UNSIGNED;\n DECLARE l TINYINT UNSIGNED DEFAULT length(n);\n DECLARE i TINYINT UNSIGNED DEFAULT l;\n DECLARE s SMALLINT UNSIGNED DEFAULT 0;\n WHILE i > 0 DO\n SET x = mid(n,i,1);\n IF (l-i) mod 2 = 0 THEN\n SET x = x * 2;\n END IF;\n SET s = s + x div 10 + x mod 10;\n SET i = i - 1;\n END WHILE;\n RETURN ceil(s/10)*10-s;\nEND;\n mysql> SELECT ccc(1234567890123452);\n+-----------------------+\n| ccc(1234567890123452) |\n+-----------------------+\n| 1 |\n+-----------------------+\n1 row in set (0.00 sec)\n\nmysql> SELECT ccc(1234567890123451);\n+-----------------------+\n| ccc(1234567890123451) |\n+-----------------------+\n| 0 |\n+-----------------------+\n1 row in set (0.00 sec)\n\nmysql> SELECT ccd(123456789012345);\n+----------------------+\n| ccd(123456789012345) |\n+----------------------+\n| 2 |\n+----------------------+\n1 row in set (0.00 sec)\n\nmysql> SELECT ccd(234567890123451);\n+----------------------+\n| ccd(234567890123451) |\n+----------------------+\n| 1 |\n+----------------------+\n1 row in set (0.00 sec)\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18986/"
] |
174,748
|
<p>I have a table with one field that can point to a foreign key in one of 3 other tables based on what the descriminator value is (Project, TimeKeep, or CostCenter. Usually this is implemented with subclasses, and I am wondering if what I have below will work. <strong>Note the subclass name is the same as the parent class and the noteObject property is mapped to an instance variable of type java.lang.Object</strong> so it should accept either a Project, TimeKeep or CostCenter object as long as we cast to the correct type. Will hibernate allow this? Thanks.</p>
<pre><code><hibernate-mapping package="com.tlr.finance.mappings">
<class name="AdminNotes" table="admin_notes">
<id name="adminNoteId" column="admin_note_id" type="integer">
<generator class="identity" />
</id>
<discriminator column="note_type" type="string" />
<!-- make this property an enumerated type. It is the discriminator -->
<property name="adminNoteType" column="note_type" type="string" not-null="true" />
<property name="adminNote" column="note" type="string" not-null="true" />
<property name="adminNoteAdded" column="note_date" type="timestamp"
not-null="true" />
<subclass name="AdminNotes" discriminator-value="project" >
<many-to-one name="noteObject" column="object_id" class="PsData" /><!-- Project -->
</subclass>
<subclass name="AdminNotes" discriminator-value="user" >
<!-- rename timekeep to user -->
<many-to-one name="noteObject" column="object_id" class="Timekeep" /><!-- user -->
</subclass>
<subclass name="AdminNotes" discriminator-value="costCenter" >
<!-- rename timekeep to user -->
<many-to-one name="noteObject" column="object_id" class="CostCenter" /><!-- cost center -->
</subclass>
</class>
</hibernate-mapping>
</code></pre>
|
[
{
"answer_id": 1109321,
"author": "Anton",
"author_id": 110311,
"author_profile": "https://Stackoverflow.com/users/110311",
"pm_score": 0,
"selected": false,
"text": "<hibernate-mapping package=\"com.tlr.finance.mappings\">\n\n <class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\">\n <id name=\"adminNoteId\" column=\"admin_note_id\" type=\"integer\">\n <generator class=\"identity\" />\n </id>\n\n <discriminator column=\"note_type\" type=\"string\" />\n\n <!-- Make this property an enumerated type. It is the discriminator. -->\n <property name=\"adminNoteType\" column=\"note_type\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNote\" column=\"note\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNoteAdded\" column=\"note_date\" type=\"timestamp\"\n not-null=\"true\" />\n\n <subclass name=\"AdminNotes\" discriminator-value=\"project\" entity-name=\"project\">\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"PsData\" /><!-- Project -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"user\" entity-name=\"user\">\n <!-- rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"Timekeep\" /><!-- user -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"costCenter\" entity-name=\"costCenter\">\n <!-- rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"CostCenter\" /><!-- cost center -->\n </subclass>\n </class>\n</hibernate-mapping>\n"
},
{
"answer_id": 1349412,
"author": "iammichael",
"author_id": 43367,
"author_profile": "https://Stackoverflow.com/users/43367",
"pm_score": 0,
"selected": false,
"text": "<any/> note_type object_id noteObject <any/>"
},
{
"answer_id": 3194612,
"author": "Damian Leszczyński - Vash",
"author_id": 390695,
"author_profile": "https://Stackoverflow.com/users/390695",
"pm_score": 1,
"selected": false,
"text": "<class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\" discriminator-value= \"-1\">\n <hibernate-mapping package=\"com.tlr.finance.mappings\">\n\n <class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\" discriminator-value= \"-1\">\n <id name=\"adminNoteId\" column=\"admin_note_id\" type=\"integer\">\n <generator class=\"identity\" />\n </id>\n <discriminator column=\"note_type\" type=\"integer\" />\n\n <!-- Make this property an enumerated type. It is the discriminator. -->\n <property name=\"adminNoteType\" column=\"note_type\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNote\" column=\"note\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNoteAdded\" column=\"note_date\" type=\"timestamp\"\n not-null=\"true\" />\n\n <subclass name=\"AdminNotes\" discriminator-value=\"0\" entity-name=\"project\">\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"PsData\" /><!-- Project -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"1\" entity-name=\"user\">\n <!-- Rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"Timekeep\" /><!-- user -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"2\" entity-name=\"costCenter\">\n <!-- Rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"CostCenter\" /><!-- cost center -->\n </subclass>\n </class>\n</hibernate-mapping>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16404/"
] |
174,752
|
<p>I've got a lightbox textbox that is displayed using an AJAX call from an ASP.NET UpdatePanel. When the lightbox is displayed, I use the <code>focus()</code> method of a textbox that is in the lightbox to bring focus to the textbox right away.</p>
<p>When in Firefox, the text box gains focus with no problem. In IE, the text box does not gain focus unless I use </p>
<pre><code>setTimeout(function(){txtBx.focus()}, 500);
</code></pre>
<p>to make the focus method fire slightly later, after the DOM element has been loaded I'm assuming.</p>
<p>The problem is, immediately above that line, I'm already checking to see if the element is null/undefined, so the object already should exist if it hits that line, it just won't allow itself to gain focus right away for some reason.</p>
<p>Obviously setting a timer to "fix" this problem isn't the best or most elegant way to solve this. I'd like to be able to do something like the following: </p>
<pre><code>var txtBx = document.getElementById('txtBx');
if (txtPassword != null) {
txtPassword.focus();
while (txtPassword.focus === false) {
txtPassword.focus();
}
}
</code></pre>
<p>Is there any way to tell that a text box has focus so I could do something like above?</p>
<p>Or am I looking at this the wrong way?</p>
<p><strong>Edit</strong><br>
To clarify, I'm not calling the code on page load. The script <strong>is</strong> at the top of the page, however it is inside of a function that is called when ASP.NET's Asynchronous postback is complete, not when the page loads.</p>
<p>Because this is displayed after an Ajax update, the DOM should already be loaded, so I'm assuming that jQuery's <code>$(document).ready()</code> event won't be helpful here.</p>
|
[
{
"answer_id": 1109321,
"author": "Anton",
"author_id": 110311,
"author_profile": "https://Stackoverflow.com/users/110311",
"pm_score": 0,
"selected": false,
"text": "<hibernate-mapping package=\"com.tlr.finance.mappings\">\n\n <class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\">\n <id name=\"adminNoteId\" column=\"admin_note_id\" type=\"integer\">\n <generator class=\"identity\" />\n </id>\n\n <discriminator column=\"note_type\" type=\"string\" />\n\n <!-- Make this property an enumerated type. It is the discriminator. -->\n <property name=\"adminNoteType\" column=\"note_type\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNote\" column=\"note\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNoteAdded\" column=\"note_date\" type=\"timestamp\"\n not-null=\"true\" />\n\n <subclass name=\"AdminNotes\" discriminator-value=\"project\" entity-name=\"project\">\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"PsData\" /><!-- Project -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"user\" entity-name=\"user\">\n <!-- rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"Timekeep\" /><!-- user -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"costCenter\" entity-name=\"costCenter\">\n <!-- rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"CostCenter\" /><!-- cost center -->\n </subclass>\n </class>\n</hibernate-mapping>\n"
},
{
"answer_id": 1349412,
"author": "iammichael",
"author_id": 43367,
"author_profile": "https://Stackoverflow.com/users/43367",
"pm_score": 0,
"selected": false,
"text": "<any/> note_type object_id noteObject <any/>"
},
{
"answer_id": 3194612,
"author": "Damian Leszczyński - Vash",
"author_id": 390695,
"author_profile": "https://Stackoverflow.com/users/390695",
"pm_score": 1,
"selected": false,
"text": "<class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\" discriminator-value= \"-1\">\n <hibernate-mapping package=\"com.tlr.finance.mappings\">\n\n <class name=\"AdminNotes\" table=\"admin_notes\" abstract=\"true\" discriminator-value= \"-1\">\n <id name=\"adminNoteId\" column=\"admin_note_id\" type=\"integer\">\n <generator class=\"identity\" />\n </id>\n <discriminator column=\"note_type\" type=\"integer\" />\n\n <!-- Make this property an enumerated type. It is the discriminator. -->\n <property name=\"adminNoteType\" column=\"note_type\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNote\" column=\"note\" type=\"string\" not-null=\"true\" />\n <property name=\"adminNoteAdded\" column=\"note_date\" type=\"timestamp\"\n not-null=\"true\" />\n\n <subclass name=\"AdminNotes\" discriminator-value=\"0\" entity-name=\"project\">\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"PsData\" /><!-- Project -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"1\" entity-name=\"user\">\n <!-- Rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"Timekeep\" /><!-- user -->\n </subclass>\n\n <subclass name=\"AdminNotes\" discriminator-value=\"2\" entity-name=\"costCenter\">\n <!-- Rename timekeep to user -->\n <many-to-one name=\"noteObject\" column=\"object_id\" class=\"CostCenter\" /><!-- cost center -->\n </subclass>\n </class>\n</hibernate-mapping>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
174,762
|
<p>I have a form that I would like to style. specifcally I would like to chnage the background color of the form item's label. (the backgorundColor attribute changes both the label and the inputs background color)</p>
<p>i.e.</p>
<pre>
<code>
<mx:Form>
<mx:FormItem label="username:">
<mx:TextInput />
</mx:FormItem>
</mx:Form>
</code>
</pre>
<p>I would like to make the label with 'username:' have a different background color, but have the text input still be the default background color. </p>
<p>is this possible with a FormItem ?</p>
|
[
{
"answer_id": 175076,
"author": "Brandon",
"author_id": 23133,
"author_profile": "https://Stackoverflow.com/users/23133",
"pm_score": -1,
"selected": false,
"text": "TextArea {\n backgroundColor: #0000ff;\n}\n .formLabel {\n backgroundColor: #0000ff;\n}\n <FormItem label=\"Label\" styleName=\"formLabel\" />\n"
},
{
"answer_id": 176096,
"author": "JustLogic",
"author_id": 21664,
"author_profile": "https://Stackoverflow.com/users/21664",
"pm_score": 3,
"selected": true,
"text": "FormItemLabel {\n\n}\n FormItem {\n labelStyleName: newStyle;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
174,764
|
<p>I have a collection of ClickOnce packages in a publish folder on a network drive and need to move them all to another server (our DR machine). </p>
<p>After copy/pasting the whole directory and running the setups on the new machine I get an error message stating that it cannot find the old path:</p>
<blockquote>
<p>Activation of
...MyClickOnceApp.application resulted
in exception. Following failure
messages were detected:</p>
<p>+ Downloading file://oldMachine/c$/MyClickOnceApp.application did not succeed.</p>
<p>+ Could not find a part of the path '\\oldMachine\c$\MyClickOnceApp.application'.</p>
</blockquote>
<p>Once I change the installation <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator" rel="nofollow noreferrer">URL</a> to point at my new machine, I get another error:</p>
<blockquote>
<p>Manifest XML signature is not valid.</p>
<p>+ The digital signature of the object did not verify.</p>
</blockquote>
<p>I've tried using <a href="http://msdn.microsoft.com/en-us/library/xhctdw55.aspx" rel="nofollow noreferrer">MageUI.exe</a>, to modify the deployment URL, but it asks for a certificate, which I don't have.</p>
<p>What am I doing wrong and how do I successfully move published ClickOnce packages?</p>
|
[
{
"answer_id": 177899,
"author": "HAdes",
"author_id": 11989,
"author_profile": "https://Stackoverflow.com/users/11989",
"pm_score": 4,
"selected": true,
"text": "setup.exe myAppName.application Mage.exe"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11989/"
] |
174,773
|
<p>I have TurtoiseSVN and ankhSVN installed. I created a repository on my computer.. "C:\Documents and Settings\user1\My Documents\Subversion\Repository\"</p>
<p>I am trying to connect to this repository from my co-workers computer. What should this URL be?</p>
<p>Any help would be great. Thanks.</p>
|
[
{
"answer_id": 174809,
"author": "Jeffrey L Whitledge",
"author_id": 10174,
"author_profile": "https://Stackoverflow.com/users/10174",
"pm_score": 2,
"selected": false,
"text": "file:///\\\\COMPUTERNAME\\SharedFolderName\\\n"
},
{
"answer_id": 174818,
"author": "iainmcgin",
"author_id": 24068,
"author_profile": "https://Stackoverflow.com/users/24068",
"pm_score": 5,
"selected": true,
"text": "svn://<your_ip>/<repository_name>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174773",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1316/"
] |
174,774
|
<p>I created an <code>ObjectInputSteam</code> and <code>ObjectOutputStream</code> on a blocking <code>SocketChannel</code> and am trying to read and write concurrently. My code is something like this:</p>
<pre><code>socketChannel = SocketChannel.open(destNode);
objectOutputStream = new ObjectOutputStream(Channels.newOutputStream(socketChannel));
objectInputStream = new ObjectInputStream(Channels.newInputStream(socketChannel));
Thread replyThread = new Thread("SendRunnable-ReplyThread") {
@Override
public void run() {
try {
byte reply = objectInputStream.readByte();//(A)
//..process reply
} catch (Throwable e) {
logger.warn("Problem reading receive reply.", e);
}
}
};
replyThread.start();
objectOutputStream.writeObject(someObject);//(B)
//..more writing
</code></pre>
<p>Problem is the write at line (B) blocks until the read at line (A) completes (blocks on the object returned by <code>SelectableChannel#blockingLock()</code> ). But app logic dictates that the read will not complete until all the writes complete, so we have an effective deadlock.</p>
<p><code>SocketChannel</code> javadocs say that concurrent reads and writes are supported.</p>
<p>I experienced no such problem when I tried a regular Socket solution:</p>
<pre><code>Socket socket = new Socket();
socket.connect(destNode);
final OutputStream outputStream = socket.getOutputStream();
objectOutputStream = new ObjectOutputStream(outputStream);
objectInputStream = new ObjectInputStream(socket.getInputStream());
</code></pre>
<p>However, then I cannot take advantage of the performance benefits of <code>FileChannel#transferTo(...)</code></p>
|
[
{
"answer_id": 179104,
"author": "Kevin Wong",
"author_id": 4792,
"author_profile": "https://Stackoverflow.com/users/4792",
"pm_score": 3,
"selected": false,
"text": "java.nio.channels.Channels"
},
{
"answer_id": 546419,
"author": "Nick",
"author_id": 21399,
"author_profile": "https://Stackoverflow.com/users/21399",
"pm_score": 2,
"selected": false,
"text": "public InputStream getInputStream() throws IOException {\n return Channels.newInputStream(new ReadableByteChannel() {\n public int read(ByteBuffer dst) throws IOException {\n return socketChannel.read(dst);\n }\n public void close() throws IOException {\n socketChannel.close();\n }\n public boolean isOpen() {\n return socketChannel.isOpen();\n }\n });\n}\n\npublic OutputStream getOutputStream() throws IOException {\n return Channels.newOutputStream(socketChannel);\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4792/"
] |
174,800
|
<p>I'm scraping a static html site and moving the content into a database-backed CMS. I'd like to use Textile in the CMS. </p>
<p>Is there a tool out there that converts HTML into Textile, so I can scrape the existing site, convert the HTML to Textile, and insert that data into the database?</p>
|
[
{
"answer_id": 22592695,
"author": "Simmant",
"author_id": 2450403,
"author_profile": "https://Stackoverflow.com/users/2450403",
"pm_score": -1,
"selected": false,
"text": "import java.net.*;\nimport java.io.*;\n\nclass Crawle\n{\n\npublic static void main(String ar[])throws Exception\n{\n\n\nURL url = new URL(\"https://www.google.co.in/#q=i+am+happy\");\nInputStream io = url.openStream();\nBufferedReader br = new BufferedReader(new InputStreamReader(io));\nFileOutputStream fio = new FileOutputStream(\"crawler/file.txt\");\nPrintWriter pr = new PrintWriter(fio,true);\nString data = \"\";\nwhile((data=br.readLine())!=null)\n{\npr.println(data);\nSystem.out.println(data);\n}\n\n}\n}\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17076/"
] |
174,806
|
<p>I'm a big subversion fan and am just about to take over a big site (200mb approx.) I've trimmed down the main site from an original size of 500MB!!</p>
<p>I'm about to check this site into a new subversion repository. The problem is, my subversion repository is remotely hosted so that another colleague can also work on the site. </p>
<p>I'm concerned about having to check in and out 200MB every time I have to make updates to the site.</p>
<p>Development is quite active so there will be lots of things changing on an ongoing basis. </p>
<p>Assuming I get everything checked in ok, will subversion ensure it's only download new/amended files/folders each time I do a new checkout or will I be waiting for 200MB to download every time?</p>
|
[
{
"answer_id": 175051,
"author": "Ken",
"author_id": 20074,
"author_profile": "https://Stackoverflow.com/users/20074",
"pm_score": 3,
"selected": false,
"text": "svn checkout http://server/path/to/repos my_working_copy\ncp -a my_working_copy another_working_copy\nsvn status another_working_copy\n svn checkout http://server/path/to/trunk my_trunk\ncp -a my_trunk my_branch\ncd my_branch\nsvn switch http://server/path/to/branches/stable\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22837/"
] |
174,839
|
<p><strong>Is there an easy way of cloning entire installed debian/ubuntu system?</strong></p>
<p>I want to have identical installation in terms of installed packages and as much as possible of settings.</p>
<p>I've looked into options of aptitude, apt-get, synaptic but have found nothing. </p>
|
[
{
"answer_id": 1800060,
"author": "Patrick S. Roberts",
"author_id": 218950,
"author_profile": "https://Stackoverflow.com/users/218950",
"pm_score": 4,
"selected": false,
"text": "dpkg --get-selections > installed-software\nscp installed-software $targetsystem:.\n dpkg --set-selections < installed-software\ndselect\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20550/"
] |
174,841
|
<p>Why is it that when I use a converter in my binding expression in WPF, the value is not updated when the data is updated.</p>
<p>I have a simple Person data model:</p>
<pre><code>class Person : INotifyPropertyChanged
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
</code></pre>
<p>My binding expression looks like this:</p>
<pre><code><TextBlock Text="{Binding Converter={StaticResource personNameConverter}" />
</code></pre>
<p>My converter looks like this:</p>
<pre><code>class PersonNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Person p = value as Person;
return p.FirstName + " " + p.LastName;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
</code></pre>
<p>If I bind the data without a converter it works great:</p>
<pre><code><TextBlock Text="{Binding Path=FirstName}" />
<TextBlock Text="{Binding Path=LastName}" />
</code></pre>
<p>What am I missing?</p>
<p>EDIT:
Just to clarify a few things, both Joel and Alan are correct regarding the INotifyPropertyChanged interface that needs to be implemented. In reality I do actually implement it but it still doesn't work.</p>
<p>I can't use multiple TextBlock elements because I'm trying to bind the Window Title to the full name, and the Window Title does not take a template.</p>
<p>Finally, it is an option to add a compound property "FullName" and bind to it, but I'm still wondering why updating does not happen when the binding uses a converter. Even when I put a break point in the converter code, the debugger just doesn't get there when an update is done to the underlying data :-(</p>
<p>Thanks,
Uri</p>
|
[
{
"answer_id": 175050,
"author": "Joel B Fant",
"author_id": 22211,
"author_profile": "https://Stackoverflow.com/users/22211",
"pm_score": 5,
"selected": true,
"text": "Person FirstName LastName INotifyPropertyChanged using System.ComponentModel;\n\nclass Person : INotifyPropertyChanged {\n public event PropertyChangedEventHandler PropertyChanged;\n\n string _firstname;\n public string FirstName {\n get {\n return _firstname;\n }\n set {\n _firstname = value;\n onPropertyChanged( \"FirstName\", \"FullName\" );\n }\n }\n\n string _lastname;\n public string LastName {\n get {\n return _lastname;\n }\n set {\n _lastname = value;\n onPropertyChanged( \"LastName\", \"FullName\" );\n }\n }\n\n public string FullName {\n get {\n return _firstname + \" \" + _lastname;\n }\n }\n\n void onPropertyChanged( params string[] propertyNames ) {\n PropertyChangedEventHandler handler = PropertyChanged;\n\n if ( handler != null ) {\n foreach ( var pn in propertyNames ) {\n handler( this, new PropertyChangedEventArgs( pn ) );\n }\n }\n }\n}\n Path=FirstName TextBlocks Person DependencyObject FirstName LastName DependencyProperties FullName Person Title Person Window DataContext Title=\"{Binding Path=FullName, Mode=OneWay}\"\n TextBox TextBox <TextBox Name=\"FirstNameEdit\"\n Text=\"{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged}\" />\n FullName INotifyPropertyChanged Person Window Window PropertyChanged Window PropertyChanged Person InitializeComponent() PropertyChanged Person null InitializeComponent() Person <Window.Resources>\n <loc:PersonNameConverter\n x:Key=\"conv\" />\n</Window.Resources>\n<Window.Title>\n <Binding\n RelativeSource=\"{RelativeSource Self}\"\n Converter=\"{StaticResource conv}\"\n Path=\"Person\"\n Mode=\"OneWay\" />\n</Window.Title>\n"
},
{
"answer_id": 175121,
"author": "Alan Le",
"author_id": 1133,
"author_profile": "https://Stackoverflow.com/users/1133",
"pm_score": 1,
"selected": false,
"text": "using System.ComponentModel;\n\nnamespace INotifyPropertyChangeSample\n{\n public class Person : INotifyPropertyChanged\n {\n private string firstName;\n public string FirstName\n {\n get { return firstName; }\n set\n {\n if (firstName != value)\n {\n firstName = value;\n OnPropertyChanged(\"FirstName\");\n OnPropertyChanged(\"FullName\");\n }\n }\n }\n\n private string lastName;\n public string LastName\n {\n get { return lastName; }\n set\n {\n if (lastName != value)\n {\n lastName = value;\n OnPropertyChanged(\"LastName\");\n OnPropertyChanged(\"FullName\");\n }\n }\n }\n\n public string FullName\n {\n get { return firstName + \" \" + lastName; }\n } \n\n #region INotifyPropertyChanged Members\n\n public event PropertyChangedEventHandler PropertyChanged;\n\n protected void OnPropertyChanged(string name)\n {\n if (PropertyChanged != null)\n PropertyChanged(this, new PropertyChangedEventArgs(name));\n }\n\n #endregion\n }\n}\n <TextBlock Text=\"{Binding Person.FullName}\" />\n"
},
{
"answer_id": 177370,
"author": "rudigrobler",
"author_id": 5147,
"author_profile": "https://Stackoverflow.com/users/5147",
"pm_score": 0,
"selected": false,
"text": "<TextBlock Text=\"{Binding Path=/, Converter={StaticResource personNameConverter}}\" />\n"
},
{
"answer_id": 177888,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 4,
"selected": false,
"text": "<MultiBinding Converter=\"{IMultiValueConverter goes here..}\">\n <Binding />\n <Binding Path=\"FirstName\" />\n <Binding Path=\"LastName\" />\n</MultiBinding>\n <MultiBinding Converter=\"{IMultiValueConverter goes here..}\">\n <Binding Path=\"FirstName\" />\n <Binding Path=\"LastName\" />\n</MultiBinding>\n class PersonNameConverter : IMultiValueConverter\n{\n public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)\n {\n return values[0].ToString() + \" \" + values[1].ToString();\n }\n\n public object ConvertBack(object[] values, Type targetType, object parameter, CultureInfo culture)\n {\n throw new NotImplementedException();\n }\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/373/"
] |
174,849
|
<p>I've read <a href="http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/" rel="noreferrer">ASP.NET Routing… Goodbye URL rewriting?</a> and <a href="http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx" rel="noreferrer">Using Routing With WebForms</a> which are great articles, but limited to simple, illustrative, "hello world"-complexity examples.</p>
<p>Is anyone out there using ASP.NET routing with web forms in a non-trivial way? Any gotchas to be aware of? Performance issues? Further recommended reading I should look at before ploughing into an implementation of my own?</p>
<p><strong>EDIT</strong>
Found these additional useful URLs:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/cc668202.aspx" rel="noreferrer">How to: Use Routing with Web Forms (MSDN)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="noreferrer">ASP.NET Routing (MSDN)</a> </li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc668176.aspx" rel="noreferrer">How to: Construct a URL from a Route(MSDN)</a></li>
</ul>
|
[
{
"answer_id": 47417864,
"author": "fufuz9000",
"author_id": 8980836,
"author_profile": "https://Stackoverflow.com/users/8980836",
"pm_score": 3,
"selected": false,
"text": "protected void Button1_Click(object sender, EventArgs e)\n{\n Response.Redirect(\"Second.aspx\");\n}\n\nprotected void Button2_Click(object sender, EventArgs e)\n{\n Response.Redirect(\"Third.aspx?Name=Pants\");\n}\n\nprotected void Button3_Click(object sender, EventArgs e)\n{\n Response.Redirect(\"Third.aspx?Name=Shoes\");\n}\n protected void Page_Load(object sender, EventArgs e)\n{\n Response.Write(Request.QueryString[\"Name\"]);\n}\n protected void Application_Start(object sender, EventArgs e)\n{\n RegisterRoutes(RouteTable.Routes);\n}\nvoid RegisterRoutes(RouteCollection routes)\n{\n routes.MapPageRoute(\n \"HomeRoute\",\n \"Home\",\n \"~/Default.aspx\"\n );\n routes.MapPageRoute(\n \"SecondRoute\",\n \"Second\",\n \"~/Second.aspx\"\n );\n routes.MapPageRoute(\n \"ThirdRoute\",\n \"Third/{Name}\",\n \"~/Third.aspx\"\n );\n}\n protected void Button2_Click(object sender, EventArgs e)\n{\n //Response.Redirect(\"Third.aspx?Name=Pants\");\n Response.Redirect(GetRouteUrl(\"ThirdRoute\", new {Name = \"Pants\"}));\n}\n\nprotected void Button3_Click(object sender, EventArgs e)\n{\n // Response.Redirect(\"Third.aspx?Name=Shoes\");\n Response.Redirect(GetRouteUrl(\"ThirdRoute\", new { Name = \"Shoes\" }));\n}\n protected void Page_Load(object sender, EventArgs e)\n{\n //Response.Write(Request.QueryString[\"Name\"]);\n Response.Write(RouteData.Values[\"Name\"]);\n}\n protected void Button4_Click(object sender, EventArgs e)\n{\n Response.Redirect(GetRouteUrl(\"FourthRoute\", new { Name = \"Shoes\" , Gender = \"Male\"}));\n}\n routes.MapPageRoute(\n \"FourthRoute\",\n \"Fourth/{Name}-{Gender}\",\n \"~/Fourth.aspx\"\n );\n protected void Page_Load(object sender, EventArgs e)\n{\nResponse.Write(\"Name is: \" + RouteData.Values[\"Name\"] + \" and Gender is \" + RouteData.Values[\"Gender\"]);\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20377/"
] |
174,853
|
<p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice.
The parent process goes on processing the rest of the script after all kids are collected.</p>
<p>What is the best way to work it out? Thanks. </p>
|
[
{
"answer_id": 174989,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 1,
"selected": false,
"text": "select() select os.fork() os.kill()"
},
{
"answer_id": 175038,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 5,
"selected": true,
"text": "import os\nchidren = []\nfor job in jobs:\n child = os.fork()\n if child:\n children.append(child)\n else:\n pass # really should exec the job\nfor child in children:\n os.waitpid(child, 0)\n wait waitpid alarm SIGALRM"
},
{
"answer_id": 177237,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 3,
"selected": false,
"text": "import os, time\n\ndef doTheJob(job):\n for i in xrange(10):\n print job, i\n time.sleep(0.01*ord(os.urandom(1)))\n # random.random() would be the same for each process\n\njobs = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\"]\nimTheFather = True\nchildren = []\n\nfor job in jobs:\n child = os.fork()\n if child:\n children.append(child)\n else:\n imTheFather = False\n doTheJob(job)\n break\n\n# in the meanwhile \n# ps aux|grep python|grep -v grep|wc -l == 11 == 10 children + the father\n\nif imTheFather:\n for child in children:\n os.waitpid(child, 0)\n"
},
{
"answer_id": 52410335,
"author": "Radiumcola",
"author_id": 3987140,
"author_profile": "https://Stackoverflow.com/users/3987140",
"pm_score": 0,
"selected": false,
"text": "#!/usr/bin/env python3\nimport signal, traceback\nimport os, subprocess\nimport time\n#\n# sigchild handler for reaping dead children\n#\ndef handler(signum, frame):\n#\n# report stat of child tasks \n print(children)\n#\n# use waitpid to collect the dead task pid and status\n pid, stat = os.waitpid(-1, 0)\n term=(pid,stat)\n print('Reaped: pid=%d stat=%d\\n' % term)\n#\n# add pid and return code to dead kids list for post processing\n ripkids.append(term)\n print(ripkids)\n print('\\n')\n#\n# update children to remove pid just reaped\n index = children.index(pid)\n children.pop(index)\n print(children) \n print('\\n')\n\n# Set the signal handler \nsignal.signal(signal.SIGCHLD, handler)\n\ndef child():\n print('\\nA new child ', os.getpid())\n print('\\n')\n time.sleep(15)\n os._exit(0) \n\ndef parent():\n#\n# lists for started and dead children\n global children\n children = []\n global ripkids\n ripkids = []\n\n while True:\n newpid = os.fork()\n if newpid == 0:\n child()\n else:\n pidx = (os.getpid(), newpid)\n children = children+[newpid]\n print(\"parent: %d, child: %d\\n\" % pidx)\n print(children)\n print('\\n')\n reply = input(\"q for quit / c for new fork\")\n if reply == 'c': \n continue\n else:\n break\n\nparent()\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/140995/"
] |
174,881
|
<p>I'm using jmockit with my tests and with one class I wish to test, uses <code>InitialContext</code> directly. So I have the following:</p>
<pre><code>public class MyClass {
public void myMethod() {
InitialContext ic = new InitialContext();
javax.mail.Session mailSession = ic.lookup("my.mail.session");
// rest of method follows.....
}
</code></pre>
<p>In my test case, I call this to use my "mocked" <code>InitialContext</code> class:</p>
<pre><code>Mockit.redefineMethods(InitialContext.class, MockInitialContext.class);
</code></pre>
<p>What is the best way to mock the <code>InitialContext</code> class with jmockit.</p>
<p>I've already tried a few ways (such as using my own <code>MockInitialContextFactory</code>), but keeping stumbling into the same error:</p>
<pre><code>NoClassDefFoundError: my.class.MockInitialContext
</code></pre>
<p>From what I can see on Google, mocking with JNDI is quite nasty. Please can anyone provide me with some guidance, or point me to a solution? That would be much appreciated. Thank you.</p>
|
[
{
"answer_id": 1634106,
"author": "jc.",
"author_id": 197705,
"author_profile": "https://Stackoverflow.com/users/197705",
"pm_score": 2,
"selected": false,
"text": "@Mocked InitialContext mockedInitialContext;\n@Mocked javax.mail.Session mockedSession;\n public void testSendindMail(){\n new Expectations(){\n {\n mockedInitialContext.lookup(\"my.mail.session\");returns(mockedSession); \n }\n };\n MyClass cl = new MyClass ();\n cl.MyMethod();//This need JNDI Lookup\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,885
|
<p>I've got this code:</p>
<pre><code>rs1 = getResults(sSQL1)
rs2 = getResults(sSQL2)
</code></pre>
<p>rs1 and rs2 and 2D arrays. The first index represents the number of columns (static) and the second index represents the number of rows (dynamic).</p>
<p>I need to join the two arrays and store them in rs3. I don't know what type rs1 and rs2 are though.</p>
|
[
{
"answer_id": 174897,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 1,
"selected": false,
"text": "rs1 = getResults(sSQL1 & \" UNION \" sSQL2)\n"
},
{
"answer_id": 174974,
"author": "ilitirit",
"author_id": 9825,
"author_profile": "https://Stackoverflow.com/users/9825",
"pm_score": 2,
"selected": true,
"text": " aRS_RU = rowsQuery(sSQL & \", 'RU'\")\n aRS_KR = rowsQuery(sSQL & \", 'KR'\")\n\n uboundRU1 = UBound(aRS_RU, 1)\n uboundRU2 = UBound(aRS_RU, 2)\n uboundKR2 = Ubound(aRS_KR, 2)\n\n ' Redim original array\n ReDim Preserve aRS_RU(uboundRU1, uboundRU2 + uboundKR2 + 1 )\n uboundRU2 = UBound(aRS_RU, 2)\n\n ' Add the values from the second array \n For m = LBound(aRS_KR, 1) To UBound(aRS_KR, 1) 'Loop for 1st dimension\n For n = LBound(aRS_KR, 2) To UBound(aRS_KR, 2) 'Loop for 2nd dimension\n aRS_RU(m, uboundRU2 + n) = aRS_KR(m,n)\n Next\n Next \n"
},
{
"answer_id": 10805409,
"author": "Fred",
"author_id": 1424522,
"author_profile": "https://Stackoverflow.com/users/1424522",
"pm_score": 0,
"selected": false,
"text": "Sub ConcatRecordSets(ByRef avFirstRS As Variant, ByRef avSecondRS As Variant)\n\n Dim lIndex1 As Long, lIndex2 As Long\n Dim lFirstRSSize As Long, lSecondRSSize As Long\n\n ' Redim original array\n lFirstRSSize = UBound(avFirstRS, 2) - LBound(avFirstRS, 2) + 1\n lSecondRSSize = UBound(avSecondRS, 2) - LBound(avSecondRS, 2) + 1\n ReDim Preserve avFirstRS(LBound(avFirstRS, 1) To UBound(avFirstRS, 1), LBound(avFirstRS, 2) To UBound(avFirstRS, 2) + lSecondRSSize)\n\n ' Add the values from the second array\n For lIndex1 = LBound(avSecondRS, 1) To UBound(avSecondRS, 1) ' Loop for 1st dimension\n For lIndex2 = LBound(avSecondRS, 2) To UBound(avSecondRS, 2) ' Loop for 2nd dimension\n avFirstRS(lIndex1, lFirstRSSize + lIndex2) = avSecondRS(lIndex1, lIndex2)\n Next lIndex2\n Next lIndex1\n\nEnd Sub\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9825/"
] |
174,888
|
<p>i want to find the mime-type for a given file extension on an IIS ASP.NET web-server from the code-behind file.</p>
<p>i want to search the same list that the server itself uses when serving up a file. This means that any mime types a web-server administrator has added to the <em>Mime Map</em> will be included.</p>
<p>i could blindly use</p>
<pre><code>HKEY_CLASSES_ROOT\MIME\Database\Content Type
</code></pre>
<p>but that isn't documented as being the same list IIS uses, nor is it documented where the <em>Mime Map</em> is stored.</p>
<p>i could blindly call <a href="http://msdn.microsoft.com/en-us/library/ms775107(VS.85).aspx" rel="noreferrer">FindMimeFromData</a>, but that isn't documented as being the same list IIS uses, nor can i guarantee that the IIS <em>Mime Map</em> will also be returned from that call.</p>
|
[
{
"answer_id": 174988,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 4,
"selected": true,
"text": "public static string GetMimeTypeFromExtension(string extension)\n{\n using (DirectoryEntry mimeMap = \n new DirectoryEntry(\"IIS://Localhost/MimeMap\"))\n {\n PropertyValueCollection propValues = mimeMap.Properties[\"MimeMap\"];\n\n foreach (object value in propValues)\n {\n IISOle.IISMimeType mimeType = (IISOle.IISMimeType)value;\n\n if (extension == mimeType.Extension)\n {\n return mimeType.MimeType;\n }\n }\n\n return null;\n\n }\n}\n System.DirectoryServices Active DS IIS Namespace Provider .flv"
},
{
"answer_id": 2240821,
"author": "Goyuix",
"author_id": 243,
"author_profile": "https://Stackoverflow.com/users/243",
"pm_score": 4,
"selected": false,
"text": "using System.Collections.Specialized; //NameValueCollection\nusing System.DirectoryServices; //DirectoryEntry, PropertyValueCollection\nusing System.Reflection; //BindingFlags\n\nNameValueCollection map = new NameValueCollection();\nusing (DirectoryEntry entry = new DirectoryEntry(\"IIS://localhost/MimeMap\"))\n{\n PropertyValueCollection properties = entry.Properties[\"MimeMap\"];\n Type t = properties[0].GetType();\n\n foreach (object property in properties)\n {\n BindingFlags f = BindingFlags.GetProperty;\n string ext = t.InvokeMember(\"Extension\", f, null, property, null) as String;\n string mime = t.InvokeMember(\"MimeType\", f, null, property, null) as String;\n map.Add(ext, mime);\n }\n}\n Response.ContentType = map[ext] ?? \"binary/octet-stream\";\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12597/"
] |
174,890
|
<p>I've discovered that cElementTree is about 30 times faster than <code>xml.dom.minidom</code> and I'm rewriting my XML encoding/decoding code. However, I need to output XML that contains CDATA sections and there doesn't seem to be a way to do that with ElementTree.</p>
<p>Can it be done?</p>
|
[
{
"answer_id": 175101,
"author": "elifiner",
"author_id": 15109,
"author_profile": "https://Stackoverflow.com/users/15109",
"pm_score": 6,
"selected": true,
"text": "def Comment(text=None):\n element = Element(Comment)\n element.text = text\n return element\n _write if tag is Comment:\n file.write(\"<!-- %s -->\" % _escape_cdata(node.text, encoding))\n CDATA _write import elementtree.ElementTree as etree\n#~ import cElementTree as etree\n\ndef CDATA(text=None):\n element = etree.Element(CDATA)\n element.text = text\n return element\n\nclass ElementTreeCDATA(etree.ElementTree):\n def _write(self, file, node, encoding, namespaces):\n if node.tag is CDATA:\n text = node.text.encode(encoding)\n file.write(\"\\n<![CDATA[%s]]>\\n\" % text)\n else:\n etree.ElementTree._write(self, file, node, encoding, namespaces)\n\nif __name__ == \"__main__\":\n import sys\n\n text = \"\"\"\n <?xml version='1.0' encoding='utf-8'?>\n <text>\n This is just some sample text.\n </text>\n \"\"\"\n\n e = etree.Element(\"data\")\n cdata = CDATA(text)\n e.append(cdata)\n et = ElementTreeCDATA(e)\n et.write(sys.stdout, \"utf-8\")\n"
},
{
"answer_id": 320876,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "]]> ]]> data = data.replace(\"]]>\", \"]]]]><![CDATA[>\")"
},
{
"answer_id": 8915039,
"author": "Amaury",
"author_id": 644863,
"author_profile": "https://Stackoverflow.com/users/644863",
"pm_score": 4,
"selected": false,
"text": "import xml.etree.ElementTree as etree\n\ndef CDATA(text=None):\n element = etree.Element('![CDATA[')\n element.text = text\n return element\n\netree._original_serialize_xml = etree._serialize_xml\ndef _serialize_xml(write, elem, qnames, namespaces):\n if elem.tag == '![CDATA[':\n write(\"\\n<%s%s]]>\\n\" % (\n elem.tag, elem.text))\n return\n return etree._original_serialize_xml(\n write, elem, qnames, namespaces)\netree._serialize_xml = etree._serialize['xml'] = _serialize_xml\n\n\nif __name__ == \"__main__\":\n import sys\n\n text = \"\"\"\n <?xml version='1.0' encoding='utf-8'?>\n <text>\n This is just some sample text.\n </text>\n \"\"\"\n\n e = etree.Element(\"data\")\n cdata = CDATA(text)\n e.append(cdata)\n et = etree.ElementTree(e)\n et.write(sys.stdout.buffer.raw, \"utf-8\")\n"
},
{
"answer_id": 10440166,
"author": "Michael",
"author_id": 381493,
"author_profile": "https://Stackoverflow.com/users/381493",
"pm_score": 0,
"selected": false,
"text": "import xml.etree.cElementTree as ET\n\nclass ElementTreeCDATA(ET.ElementTree):\n \"\"\"Subclass of ElementTree which handles CDATA blocks reasonably\"\"\"\n\n def _write(self, file, node, encoding, namespaces):\n \"\"\"This method is for ElementTree <= 1.2.6\"\"\"\n\n if node.tag == '![CDATA[':\n text = node.text.encode(encoding)\n file.write(\"\\n<![CDATA[%s]]>\\n\" % text)\n else:\n ET.ElementTree._write(self, file, node, encoding, namespaces)\n\n def _serialize_xml(write, elem, qnames, namespaces):\n \"\"\"This method is for ElementTree >= 1.3.0\"\"\"\n\n if elem.tag == '![CDATA[':\n write(\"\\n<![CDATA[%s]]>\\n\" % elem.text)\n else:\n ET._serialize_xml(write, elem, qnames, namespaces)\n"
},
{
"answer_id": 13919169,
"author": "tom stratton",
"author_id": 1039039,
"author_profile": "https://Stackoverflow.com/users/1039039",
"pm_score": 0,
"selected": false,
"text": " parser = etree.XMLParser(encoding='utf-8') # my original xml was utf-8 and that was a lot of the problem\n tree = etree.parse(ppath, parser)\n\n for cdat in tree.findall('./ProjectXMPMetadata'): # the tag where my CDATA lives\n cdat.text = etree.CDATA(cdat.text)\n\n # other stuff here\n\n tree.write(opath, encoding=\"UTF-8\",)\n"
},
{
"answer_id": 14118042,
"author": "elwc",
"author_id": 1890474,
"author_profile": "https://Stackoverflow.com/users/1890474",
"pm_score": 1,
"selected": false,
"text": "xml.etree.ElementTree lxml CDATA"
},
{
"answer_id": 16944089,
"author": "zlalanne",
"author_id": 565219,
"author_profile": "https://Stackoverflow.com/users/565219",
"pm_score": 2,
"selected": false,
"text": "import xml.etree.ElementTree as ET\n\nET._original_serialize_xml = ET._serialize_xml\n\n\ndef _serialize_xml(write, elem, encoding, qnames, namespaces):\n if elem.tag == '![CDATA[':\n write(\"<%s%s]]>%s\" % (elem.tag, elem.text, elem.tail))\n return\n return ET._original_serialize_xml(\n write, elem, encoding, qnames, namespaces)\nET._serialize_xml = ET._serialize['xml'] = _serialize_xml\n"
},
{
"answer_id": 20894783,
"author": "user3155571",
"author_id": 3155571,
"author_profile": "https://Stackoverflow.com/users/3155571",
"pm_score": 2,
"selected": false,
"text": "node.append(etree.Comment(' --><![CDATA[' + data.replace(']]>', ']]]]><![CDATA[>') + ']]><!-- '))\n"
},
{
"answer_id": 30019607,
"author": "Kamil",
"author_id": 4833927,
"author_profile": "https://Stackoverflow.com/users/4833927",
"pm_score": 3,
"selected": false,
"text": "import xml.etree.ElementTree as ElementTree\n\ndef CDATA(text=None):\n element = ElementTree.Element('![CDATA[')\n element.text = text\n return element\n\nElementTree._original_serialize_xml = ElementTree._serialize_xml\ndef _serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs):\n if elem.tag == '![CDATA[':\n write(\"\\n<{}{}]]>\\n\".format(elem.tag, elem.text))\n if elem.tail:\n write(_escape_cdata(elem.tail))\n else:\n return ElementTree._original_serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs)\n\nElementTree._serialize_xml = ElementTree._serialize['xml'] = _serialize_xml\n\nif __name__ == \"__main__\":\n import sys\n\ntext = \"\"\"\n<?xml version='1.0' encoding='utf-8'?>\n<text>\nThis is just some sample text.\n</text>\n\"\"\"\n\ne = ElementTree.Element(\"data\")\ncdata = CDATA(text)\nroot.append(cdata)\n etree._original_serialize_xml = etree._serialize_xml\ndef _serialize_xml(write, elem, qnames, namespaces):\n if elem.tag == '![CDATA[':\n write(\"\\n<%s%s]]>\\n\" % (\n elem.tag, elem.text))\n return\n return etree._original_serialize_xml(\n write, elem, qnames, namespaces)\netree._serialize_xml = etree._serialize['xml'] = _serialize_xml\n <textContent>\n<![CDATA[this was the code I wanted to put inside of CDATA]]>\n<![CDATA[>this was the code I wanted to put inside of CDATA</![CDATA[>\n</textContent>\n return etree._original_serialize_xml(write, elem, qnames, namespaces)\n from xml.etree import ElementTree\nfrom xml import etree\n\n#in order to test it you have to create testing.xml file in the folder with the script\nxmlParsedWithET = ElementTree.parse(\"testing.xml\")\nroot = xmlParsedWithET.getroot()\n\ndef CDATA(text=None):\n element = ElementTree.Element('![CDATA[')\n element.text = text\n return element\n\nElementTree._original_serialize_xml = ElementTree._serialize_xml\n\ndef _serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs):\n\n if elem.tag == '![CDATA[':\n write(\"\\n<{}{}]]>\\n\".format(elem.tag, elem.text))\n if elem.tail:\n write(_escape_cdata(elem.tail))\n else:\n return ElementTree._original_serialize_xml(write, elem, qnames, namespaces,short_empty_elements, **kwargs)\n\nElementTree._serialize_xml = ElementTree._serialize['xml'] = _serialize_xml\n\n\ntext = \"\"\"\n<?xml version='1.0' encoding='utf-8'?>\n<text>\nThis is just some sample text.\n</text>\n\"\"\"\ne = ElementTree.Element(\"data\")\ncdata = CDATA(text)\nroot.append(cdata)\n\n#tests\nprint(root)\nprint(root.getchildren()[0])\nprint(root.getchildren()[0].text + \"\\n\\nyay!\")\n <Element 'Database' at 0x10062e228>\n<Element '![CDATA[' at 0x1021cc9a8>\n\n<?xml version='1.0' encoding='utf-8'?>\n<text>\nThis is just some sample text.\n</text>\n\n\nyay!\n"
},
{
"answer_id": 52262907,
"author": "Ryabchenko Alexander",
"author_id": 6515755,
"author_profile": "https://Stackoverflow.com/users/6515755",
"pm_score": 2,
"selected": false,
"text": "import xml.etree.ElementTree as ET\n\nET._original_serialize_xml = ET._serialize_xml\n\n\ndef serialize_xml_with_CDATA(write, elem, qnames, namespaces, short_empty_elements, **kwargs):\n if elem.tag == 'CDATA':\n write(\"<![CDATA[{}]]>\".format(elem.text))\n return\n return ET._original_serialize_xml(write, elem, qnames, namespaces, short_empty_elements, **kwargs)\n\n\nET._serialize_xml = ET._serialize['xml'] = serialize_xml_with_CDATA\n\n\ndef CDATA(text):\n element = ET.Element(\"CDATA\")\n element.text = text\n return element\n\n\nmy_xml = ET.Element(\"my_name\")\nmy_xml.append(CDATA(\"<p>some text</p>\")\n\ntree = ElementTree(my_xml)\n ET.tostring(tree)\n tostring() fake_file = BytesIO()\ntree.write(fake_file, encoding=\"utf-8\", xml_declaration=True)\nresult_xml_text = str(fake_file.getvalue(), encoding=\"utf-8\")\n <?xml version='1.0' encoding='utf-8'?>\n<my_name>\n <![CDATA[<p>some text</p>]]>\n</my_name>\n"
},
{
"answer_id": 58392720,
"author": "Stas Chabarov",
"author_id": 12219975,
"author_profile": "https://Stackoverflow.com/users/12219975",
"pm_score": 2,
"selected": false,
"text": "_escape_cdata import xml.etree.ElementTree as ET\n\ndef _escape_cdata(text, encoding):\n try:\n if \"&\" in text:\n text = text.replace(\"&\", \"&\")\n # if \"<\" in text:\n # text = text.replace(\"<\", \"<\")\n # if \">\" in text:\n # text = text.replace(\">\", \">\")\n return text\n except TypeError:\n raise TypeError(\n \"cannot serialize %r (type %s)\" % (text, type(text).__name__)\n )\n\nET._escape_cdata = _escape_cdata\n encoding obj.text root = ET.Element('root')\nbody = ET.SubElement(root, 'body')\nbody.text = '<![CDATA[perform extra angle brackets escape for this text]]>'\nprint(ET.tostring(root))\n <root>\n <body>\n <![CDATA[perform extra angle brackets escape for this text]]>\n </body>\n</root>\n"
},
{
"answer_id": 62664137,
"author": "Benjamin Smus",
"author_id": 8468377,
"author_profile": "https://Stackoverflow.com/users/8468377",
"pm_score": 0,
"selected": false,
"text": "import xml.etree.ElementTree as ET\nfrom xml.sax.saxutils import unescape\n\n# defining the tree structure\nelement1 = ET.Element('test1')\nelement1.text = '<![CDATA[Wired & Forbidden]]>'\n\n# & and <> are in a weird format\nstring1 = ET.tostring(element1).decode()\nprint(string1)\n\n# now they are not weird anymore\n# more formally, we unescape '&', '<', and '>' in a string of data\n# from https://docs.python.org/3.8/library/xml.sax.utils.html#xml.sax.saxutils.unescape\nstring1 = unescape(string1)\nprint(string1)\n\nelement2 = ET.Element('test2')\nelement2.text = '<![CDATA[Wired & Forbidden]]>'\nstring2 = unescape(ET.tostring(element2).decode())\nprint(string2)\n\n# make the xml file and open in append mode\nwith open('foo.xml', 'a') as f:\n f.write(string1 + '\\n')\n f.write(string2)\n <test1><![CDATA[Wired & Forbidden]]></test1>\n<test2><![CDATA[Wired & Forbidden]]></test2>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15109/"
] |
174,891
|
<p>Last week we released Omniture's analytics code onto a large volume of web sites after tinkering and testing for the last week or so.</p>
<p>On almost all of our site templates, it works just fine. In a few scattered, unpredictable situations, there is a <em>crippling, browser-crashing experience</em> that <em>may</em> turn away some users.</p>
<p>We're not able to see a relationship between the crashing templates at this time, and while there <em>are</em> many ways to troubleshoot, the one that's confuddling us is related to event listeners.</p>
<p>The sites crash when any anchor on these templates is clicked. There isn't any inline JS, and while we firebug'ed our way through the attributes of the HTML, we couldn't find a discernable loop or issue that would cause this. (while we troubleshoot, you can experience this for yourself <a href="http://dv1.gatehousemedia.com/dev/omniture/index.html" rel="nofollow noreferrer">here</a> [<strong>warning</strong>! clicking any link in the page will cause your browser to crash!])</p>
<p><strong>How do you determine if an object has a listener or not? How do you determine what will fire when event is triggered?</strong></p>
<blockquote>
<p>FYI, I'd love to set breakpoints, but
<em>between Omnitures miserably obfuscated code and repeated browser
crashes</em>, I'd like to research more
thoroughly how I can approach this.</p>
</blockquote>
|
[
{
"answer_id": 175146,
"author": "Victor",
"author_id": 14514,
"author_profile": "https://Stackoverflow.com/users/14514",
"pm_score": 3,
"selected": true,
"text": "alert(document.links[0].onclick)\n function anonymous(e) {\n var s = s_c_il[0], b = s.eh(this, \"onclick\");\n s.lnk = s.co(this);\n s.t();\n s.lnk = 0;\n if (b) {\n return this[b](e);\n }\n return true;\n}\n"
},
{
"answer_id": 175371,
"author": "Sergey Ilinsky",
"author_id": 23815,
"author_profile": "https://Stackoverflow.com/users/23815",
"pm_score": 0,
"selected": false,
"text": "(function(){\n var fAddEventListener = HTMLElement.prototype.addEventListener;\n HTMLElement.prototype.addEventListener = function() {\n if (!this._listeners)\n this._listeners = [];\n this._listeners.push(arguments);\n fAddEventListener.apply(this, arguments);\n }\n})();\n"
},
{
"answer_id": 177233,
"author": "J5.",
"author_id": 25380,
"author_profile": "https://Stackoverflow.com/users/25380",
"pm_score": 0,
"selected": false,
"text": "\n/* Link Tracking Config */\ns.trackDownloadLinks=true\ns.trackExternalLinks=true\ns.trackInlineStats=true\ns.linkDownloadFileTypes=\"exe,zip,wav,mp3,mov,mpg,avi,wmv,pdf,doc,docx,xls,xlsx,ppt,pptx\"\ns.linkInternalFilters=\"javascript:,gatehousemedia.com\"\ns.linkLeaveQueryString=false\ns.linkTrackVars=\"None\"\ns.linkTrackEvents=\"None\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22491/"
] |
174,912
|
<p>I am a bit confused about the uses of these words. I have a table with he following columns: SITE, LAT, LONG, NAME, ......</p>
<p>I want results with unique (or is it distinct) LAT, LONG.
How do I achieve this?</p>
|
[
{
"answer_id": 174954,
"author": "Michael OShea",
"author_id": 13178,
"author_profile": "https://Stackoverflow.com/users/13178",
"pm_score": 4,
"selected": false,
"text": "select unique colA, colB from atable\n\nselect distinct colA, colB from atable\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,914
|
<p>Is there a recommended way to upgrade Quartz in JBoss 4.2.x?</p>
<p>JBoss bundles quartz 1.5.2, but I have encountered issues (<a href="http://jira.opensymphony.com/browse/QUARTZ-399" rel="nofollow noreferrer">QUARTZ-399</a>, <a href="http://jira.opensymphony.com/browse/QUARTZ-520" rel="nofollow noreferrer">QUARTZ-520</a>) that I want to avoid.</p>
<p>I would not want to patch quartz.jar in JBoss just to resolve the errors, but instead provide a new quartz.jar (plus associated configuration artifacts). The <a href="http://www.opensymphony.com/quartz/wikidocs/Quartz%201.6.0.html#Quartz1.6.0-MigrationNotes" rel="nofollow noreferrer">Quartz 1.6 migration notes</a> only contain information specific to Quartz, and I could not find any additional information during my search.</p>
<p>It does not seem to work to just put the new quartz.jar into the EAR file, because the old version is loaded at the server level (in the server's lib directory).</p>
<p>I am quite sure somebody has already tried that, and hope that this person could share or provide some links.</p>
|
[
{
"answer_id": 174954,
"author": "Michael OShea",
"author_id": 13178,
"author_profile": "https://Stackoverflow.com/users/13178",
"pm_score": 4,
"selected": false,
"text": "select unique colA, colB from atable\n\nselect distinct colA, colB from atable\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12039/"
] |
174,916
|
<p>I'm specifying my doctype as xhtml strict, but it's being sent over the wire as a content type of text/html. I'd like to specify that the content type is application/xhtml+xm, but I can't figure out where, or if, I can configure this from within my application</p>
|
[
{
"answer_id": 174926,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 5,
"selected": true,
"text": "<%@ Page ContentType=\"application/xhtml+xm\" %>\n"
},
{
"answer_id": 174932,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 2,
"selected": false,
"text": "Response.Clear()\nResponse.ContentType = \"application/xhtml+xm\"\n"
},
{
"answer_id": 6932768,
"author": "apros",
"author_id": 157666,
"author_profile": "https://Stackoverflow.com/users/157666",
"pm_score": 0,
"selected": false,
"text": "<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"Default.aspx.cs\"\nInherits=\"_Default\" %>\n\n\n<asp:literal runat=\"server\" id=\"dt\"></asp:literal>\n\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n protected void Page_Load(object sender, EventArgs e)\n{\nthis.dt.Text= \"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0\nTransitional//EN\\\"\n\\\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\\">\";\n\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
174,933
|
<p>How can I get a single keyboard character from the terminal with Ruby without pressing enter?
I tried <code>Curses::getch</code>, but that didn't really work for me.</p>
|
[
{
"answer_id": 174967,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 6,
"selected": true,
"text": "#!/usr/bin/ruby\n\nbegin\n system(\"stty raw -echo\")\n str = STDIN.getc\nensure\n system(\"stty -raw echo\")\nend\np str.chr\n"
},
{
"answer_id": 3983726,
"author": "mit",
"author_id": 362951,
"author_profile": "https://Stackoverflow.com/users/362951",
"pm_score": 4,
"selected": false,
"text": "gem install highline\n require \"highline/system_extensions\"\ninclude HighLine::SystemExtensions\n\nprint \"Press any key:\"\nk = get_character\nputs k.chr\n"
},
{
"answer_id": 8274275,
"author": "AlexChaffee",
"author_id": 190135,
"author_profile": "https://Stackoverflow.com/users/190135",
"pm_score": 4,
"selected": false,
"text": "stty raw -echo Signal.trap(\"INT\") do # SIGINT = control-C\n exit\nend\n require 'io/wait'\n\ndef char_if_pressed\n begin\n system(\"stty raw -echo\") # turn raw input on\n c = nil\n if $stdin.ready?\n c = $stdin.getc\n end\n c.chr if c\n ensure\n system \"stty -raw echo\" # turn raw input off\n end\nend\n\nwhile true\n c = char_if_pressed\n puts \"[#{c}]\" if c\n sleep 1\n puts \"tick\"\nend\n"
},
{
"answer_id": 13653636,
"author": "lzap",
"author_id": 299204,
"author_profile": "https://Stackoverflow.com/users/299204",
"pm_score": 0,
"selected": false,
"text": "nocbreak\n"
},
{
"answer_id": 14527475,
"author": "Andrew",
"author_id": 421010,
"author_profile": "https://Stackoverflow.com/users/421010",
"pm_score": 4,
"selected": false,
"text": "-icanon isig def get_char\n state = `stty -g`\n `stty raw -echo -icanon isig`\n\n STDIN.getc.chr\nensure\n `stty #{state}`\nend\n"
},
{
"answer_id": 27021816,
"author": "iNecas",
"author_id": 457560,
"author_profile": "https://Stackoverflow.com/users/457560",
"pm_score": 6,
"selected": false,
"text": "require 'io/console'\nSTDIN.getch\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25017/"
] |
174,942
|
<p>A colleague once told me that the last option when everything has failed to debug on Linux was to use <a href="http://man7.org/linux/man-pages/man1/strace.1.html" rel="noreferrer">strace</a>.</p>
<p>I tried to learn the science behind this strange tool, but I am not a system admin guru and I didn’t really get results.</p>
<p>So,</p>
<ul>
<li>What is it exactly and what does it do?</li>
<li>How and in which cases should it be used?</li>
<li>How should the output be understood and processed?</li>
</ul>
<p>In brief, <em>in simple words</em>, how does this stuff work?</p>
|
[
{
"answer_id": 174991,
"author": "bltxd",
"author_id": 11892,
"author_profile": "https://Stackoverflow.com/users/11892",
"pm_score": 6,
"selected": false,
"text": "strace /usr/local/bin/cough <any required argument for cough here>\n strace -o <out_file> /usr/local/bin/cough <any required argument for cough here>\n man strace\n"
},
{
"answer_id": 30034030,
"author": "Jeff Sheffield",
"author_id": 1184492,
"author_profile": "https://Stackoverflow.com/users/1184492",
"pm_score": 4,
"selected": false,
"text": "$ strace -e trace=open,stat,read,write gnome-calculator\n gnome-calculator"
},
{
"answer_id": 52012215,
"author": "prosti",
"author_id": 5884955,
"author_profile": "https://Stackoverflow.com/users/5884955",
"pm_score": 1,
"selected": false,
"text": "strace strace ltrace $>strace -c cd\nDesktop Documents Downloads examples.desktop Music Pictures Public Templates Videos\n% time seconds usecs/call calls errors syscall\n------ ----------- ----------- --------- --------- ----------------\n 0.00 0.000000 0 7 read\n 0.00 0.000000 0 1 write\n 0.00 0.000000 0 11 close\n 0.00 0.000000 0 10 fstat\n 0.00 0.000000 0 17 mmap\n 0.00 0.000000 0 12 mprotect\n 0.00 0.000000 0 1 munmap\n 0.00 0.000000 0 3 brk\n 0.00 0.000000 0 2 rt_sigaction\n 0.00 0.000000 0 1 rt_sigprocmask\n 0.00 0.000000 0 2 ioctl\n 0.00 0.000000 0 8 8 access\n 0.00 0.000000 0 1 execve\n 0.00 0.000000 0 2 getdents\n 0.00 0.000000 0 2 2 statfs\n 0.00 0.000000 0 1 arch_prctl\n 0.00 0.000000 0 1 set_tid_address\n 0.00 0.000000 0 9 openat\n 0.00 0.000000 0 1 set_robust_list\n 0.00 0.000000 0 1 prlimit64\n------ ----------- ----------- --------- --------- ----------------\n100.00 0.000000 93 10 total\n ltrace $>ltrace -c cd\nDesktop Documents Downloads examples.desktop Music Pictures Public Templates Videos\n% time seconds usecs/call calls function\n------ ----------- ----------- --------- --------------------\n 15.52 0.004946 329 15 memcpy\n 13.34 0.004249 94 45 __ctype_get_mb_cur_max\n 12.87 0.004099 2049 2 fclose\n 12.12 0.003861 83 46 strlen\n 10.96 0.003491 109 32 __errno_location\n 10.37 0.003303 117 28 readdir\n 8.41 0.002679 133 20 strcoll\n 5.62 0.001791 111 16 __overflow\n 3.24 0.001032 114 9 fwrite_unlocked\n 1.26 0.000400 100 4 __freading\n 1.17 0.000372 41 9 getenv\n 0.70 0.000222 111 2 fflush\n 0.67 0.000214 107 2 __fpending\n 0.64 0.000203 101 2 fileno\n 0.62 0.000196 196 1 closedir\n 0.43 0.000138 138 1 setlocale\n 0.36 0.000114 114 1 _setjmp\n 0.31 0.000098 98 1 realloc\n 0.25 0.000080 80 1 bindtextdomain\n 0.21 0.000068 68 1 opendir\n 0.19 0.000062 62 1 strrchr\n 0.18 0.000056 56 1 isatty\n 0.16 0.000051 51 1 ioctl\n 0.15 0.000047 47 1 getopt_long\n 0.14 0.000045 45 1 textdomain\n 0.13 0.000042 42 1 __cxa_atexit\n------ ----------- ----------- --------- --------------------\n100.00 0.031859 244 total\n strace strace strace ltrace ptrace ptrace strace strace strace -c -c -e trace=open grep 2>&1 | grep etc strace"
},
{
"answer_id": 55397255,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 3,
"selected": false,
"text": ".text\n.global _start\n_start:\n /* write */\n mov $1, %rax /* syscall number */\n mov $1, %rdi /* stdout */\n mov $msg, %rsi /* buffer */\n mov $len, %rdx /* buffer len */\n syscall\n\n /* exit */\n mov $60, %rax /* exit status */\n mov $0, %rdi /* syscall number */\n syscall\nmsg:\n .ascii \"hello\\n\"\nlen = . - msg\n as -o hello.o hello.S\nld -o hello.out hello.o\n./hello.out\n hello\n env -i ASDF=qwer strace -o strace.log -s999 -v ./hello.out arg0 arg1\ncat strace.log\n env -i ASDF=qwer -s999 -v strace.log execve(\"./hello.out\", [\"./hello.out\", \"arg0\", \"arg1\"], [\"ASDF=qwer\"]) = 0\nwrite(1, \"hello\\n\", 6) = 6\nexit(0) = ?\n+++ exited with 0 +++\n execve strace hello.out man execve write 6 \"hello\\n\" = 6 man 2 write exit write #define _XOPEN_SOURCE 700\n#include <unistd.h>\n\nint main(void) {\n char *msg = \"hello\\n\";\n write(1, msg, 6);\n return 0;\n}\n gcc -std=c99 -Wall -Wextra -pedantic -o main.out main.c\n./main.out\n main strace.log write(1, \"hello\\n\", 6) = 6\nexit_group(0) = ?\n+++ exited with 0 +++\n write write return 0 exit_group exit strace man exit_group dlopen"
},
{
"answer_id": 57975436,
"author": "Kerwin Smith",
"author_id": 6106866,
"author_profile": "https://Stackoverflow.com/users/6106866",
"pm_score": 2,
"selected": false,
"text": "time php index.php > timeTrace.txt\n lstat fstat strace -s 200 -c php index.php > traceLstat.txt\n trace.txt strace -Tt -o Fulltrace.txt php index.php\n .1 .9 cat Fulltrace.txt | grep \"[<]0.[1-9]\" > traceSlowest.txt\n strace strace -vv php index.php 2>&1 | sed -n '/= -1/p' > traceFailures.txt\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
174,968
|
<p>Routines can have parameters, that's no news. You can define as many parameters as you may need, but too many of them will make your routine difficult to understand and maintain.</p>
<p>Of course, you could use a structured variable as a workaround: putting all those variables in a single struct and passing it to the routine. In fact, using structures to simplify parameter lists is one of the techniques described by Steve McConnell in <em>Code Complete</em>. But as he says:</p>
<blockquote>
<p><em>Careful programmers avoid bundling data any more than is logically necessary.</em></p>
</blockquote>
<p>So if your routine has too many parameters or you use a struct to disguise a big parameter list, you're probably doing something wrong. That is, you're not keeping coupling loose.</p>
<p>My question is, <strong>when can I consider a parameter list too big?</strong> I think that more than 5 parameters, are too many. What do you think?</p>
|
[
{
"answer_id": 175078,
"author": "Kirk Strauser",
"author_id": 32538,
"author_profile": "https://Stackoverflow.com/users/32538",
"pm_score": 3,
"selected": false,
"text": "void *\nmmap(void *addr, size_t len, int prot, int flags, int fildes, off_t offset);\n"
},
{
"answer_id": 175087,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 7,
"selected": false,
"text": "HWND CreateWindowEx\n(\n DWORD dwExStyle,\n LPCTSTR lpClassName,\n LPCTSTR lpWindowName,\n DWORD dwStyle,\n int x,\n int y,\n int nWidth,\n int nHeight,\n HWND hWndParent,\n HMENU hMenu,\n HINSTANCE hInstance,\n LPVOID lpParam\n);\n"
},
{
"answer_id": 1747033,
"author": "Jim Ferrans",
"author_id": 45935,
"author_profile": "https://Stackoverflow.com/users/45935",
"pm_score": 1,
"selected": false,
"text": "retries(1000, 2000, 3000)\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679/"
] |
174,986
|
<p>I create a TextArea in actionscript:</p>
<pre><code>var textArea:TextArea = new TextArea();
</code></pre>
<p>I want it to have a black background. I've tried</p>
<pre><code>textArea.setStyle("backgroundColor", 0x000000);
</code></pre>
<p>and I've tried</p>
<pre><code>textArea.opaqueBackground = 0x000000;
</code></pre>
<p>but the TextArea stays white. What should I do?</p>
|
[
{
"answer_id": 175914,
"author": "nerdabilly",
"author_id": 8349,
"author_profile": "https://Stackoverflow.com/users/8349",
"pm_score": 4,
"selected": true,
"text": "var textArea:TextArea = new TextArea()\ntextArea.textField.opaqueBackground = 0x000000;\n var myFormat:TextFormat = new TextFormat();\nmyFormat.color = 0xffffff;\ntextArea.setStyle(\"textFormat\",myFormat);\n textArea.text = \"hello\";\naddChild(textArea); \n"
},
{
"answer_id": 7822548,
"author": "Rama",
"author_id": 1003310,
"author_profile": "https://Stackoverflow.com/users/1003310",
"pm_score": 1,
"selected": false,
"text": "s:TextArea mx:TextArea <s:TextArea\nid=\"joy_text\"\ncolor=\"0xFF0000\"\ncontentBackgroundColor=\"0x000000\"\ntext = \"joy\"\n/>\n xmlns:s=\"library://ns.adobe.com/flex/spark\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/174986",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
175,036
|
<p>i need to be able to produce a "pretty" printout of an individual list item's values, with the goals being:</p>
<ul>
<li>get rid of all navigation</li>
<li>organize data as it would appear on a typical paper form (a customer requirement)</li>
</ul>
<p>i'm avoiding using InfoPath at this time due to other issues (which i'll post separate questions for...)</p>
<p><strong>for example</strong>, i have an individual list item that normally displays similar to the following <code>DispForm.aspx</code> <em>example</em>:</p>
<p><img src="https://farm4.static.flickr.com/3025/2919055776_bec7d520c9_o_d.png" alt="SharePoint - DispForm.aspx" title="SharePoint - DispForm.aspx"></p>
<p>i need a printed version (<em><code>PrintForm.aspx</code></em>??) that will display similar to the following <em>example</em>:</p>
<p><img src="https://farm4.static.flickr.com/3101/2918303785_ddfb28d32e_o_d.png" alt="SharePoint - PrintForm.aspx" title="SharePoint - PrintForm.aspx"></p>
<p>from what i can tell, i can't do this just by modifying/creating custom CSS.</p>
<p>it also seems that i can't quite do this just by creating my own "print" version of <code>DispForm.aspx</code>.</p>
<p>any suggestions, ideas, links would be very helpful.</p>
|
[
{
"answer_id": 175119,
"author": "roryf",
"author_id": 270,
"author_profile": "https://Stackoverflow.com/users/270",
"pm_score": 1,
"selected": false,
"text": "media=\"print\""
},
{
"answer_id": 184494,
"author": "just mike",
"author_id": 12293,
"author_profile": "https://Stackoverflow.com/users/12293",
"pm_score": 1,
"selected": false,
"text": "Announcements Calendar YOUR LIST NAME Attachments Items AllItems.aspx DispForm.aspx EditForm.aspx NewForm.aspx <tr>\n <td width=\"190px\" valign=\"top\" class=\"ms-formlabel\">\n <H3 class=\"ms-standardheader\">\n <nobr>Column name</nobr>\n </H3>\n </td>\n <td width=\"400px\" valign=\"top\" class=\"ms-formbody\">\n <xsl:value-of select=\"@Column_x0020_name\"/>\n </td>\n</tr> <xsl:value-of select=\"@Column_x0020_name\"/> this_x0020_is_x0020_a_x0020_long this_x0020_is_x0020_a_x0020_long0"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12293/"
] |
175,042
|
<p>I have this solution for a single button:</p>
<pre><code>myButton.Attributes.Add("onclick", "this.disabled=true;" + GetPostBackEventReference(myButton).ToString());
</code></pre>
<p>Which works pretty well for one button, any ideas on how to expand this to 2 buttons?</p>
|
[
{
"answer_id": 175060,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": "myButton.Attributes.Add(\"onclick\", \"this.disabled=true; document.getElementById('\" \n+ button2.ClientID + \"').disabled = true;\" \n+ GetPostBackEventReference(myButton).ToString());\n"
},
{
"answer_id": 175061,
"author": "Ian Jacobs",
"author_id": 22818,
"author_profile": "https://Stackoverflow.com/users/22818",
"pm_score": 0,
"selected": false,
"text": "myButton.Attributes.Add(\"onclick\", \"this.disabled=true;document.getElementbyID(\"Button2\").disabled=true;\" + GetPostBackEventReference(myButton).ToString());\n"
},
{
"answer_id": 175072,
"author": "EndangeredMassa",
"author_id": 106,
"author_profile": "https://Stackoverflow.com/users/106",
"pm_score": 1,
"selected": false,
"text": "var btn1 = document.GetElementById('btn1ID');\nvar btn2 = this;\n\nbtn1.disabled = true;\nbtn2.disabled = true;\n var btn1 = document.GetElementById('<%= btn1.ClientID %>');\n btn2.Attributes.Add(\"onclick\", \"handleClick();\")\n <script type=\"text/javascript\">\n function handleClick() {\n var btn1 = document.GetElementById('<%= btn1.ClientID %>');\n var btn2 = this;\n\n btn1.disabled = true;\n btn2.disabled = true;\n\n }\n</script>\n\n<asp:Button id=\"btn1\" runat=\"server\" text=\"Button 1\" />\n<asp:Button id=\"btn2\" runat=\"server\" text=\"Button 2\" />\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175042",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
] |
175,044
|
<p>I have done a little Django development, but it has all been in a text editor. I was curious what more advanced development tools others are using in their Django development.</p>
<p>I am used to using Visual Studio for development and really like the <a href="https://en.wikipedia.org/wiki/Intelligent_code_completion#IntelliSense" rel="noreferrer">IntelliSense</a>, code completion, and file organization it provides and would like to find something (or a combination of tools) that would provide some of this in the Django/Python environment.</p>
|
[
{
"answer_id": 175263,
"author": "Peter Shinners",
"author_id": 17209,
"author_profile": "https://Stackoverflow.com/users/17209",
"pm_score": 2,
"selected": false,
"text": "manage.py"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1405/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.