qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
363,596 | <p>What is the best way to unit test a method that calls into multiple methods, for example:</p>
<pre><code>modify(string value)
{
if(value.Length > 5) replaceit(value);
else changeit(value);
}
</code></pre>
<p>This pseudo code has a modify method that (currently) calls either <code>replaceit()</code> or <code>changeit()</code>. I have already wrote tests for <code>replaceit</code> and <code>changeit</code>, so writing a new test for modify will be 99% the same set of code. I need to test it thought because it may change in the future. </p>
<p>So do I copy paste the existing test code? Move the test code to a common function? Any other ideas? I'm not sure of the best practice here.</p>
| [
{
"answer_id": 363615,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 4,
"selected": false,
"text": "replaceit() changeit() modify() null Strings"
},
{
"answer_id": 363649,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 4,
"selected": false,
"text": "modify Modify replaceit changeit modify modify replaceit changeit"
},
{
"answer_id": 363673,
"author": "Justin Standard",
"author_id": 92,
"author_profile": "https://Stackoverflow.com/users/92",
"pm_score": 2,
"selected": false,
"text": "replaceit(...) changeit(...) testLongValue() {\n string testValue = \"A value longer than 5 chars\";\n string expected = \"Replaced!\";\n string actual = modify(testValue);\n assertEqual(expected, actual);\n}\n\ntestShortValue() {\n string testValue = \"len4\";\n string expected = \"Changed!\";\n string actual = modify(testValue);\n assertEqual(expected, actual);\n}\n"
},
{
"answer_id": 363678,
"author": "Brian Matthews",
"author_id": 1969,
"author_profile": "https://Stackoverflow.com/users/1969",
"pm_score": 2,
"selected": false,
"text": "if (value.length > 5) value 4 5 6"
},
{
"answer_id": 363736,
"author": "Olivier",
"author_id": 43585,
"author_profile": "https://Stackoverflow.com/users/43585",
"pm_score": 0,
"selected": false,
"text": "null"
},
{
"answer_id": 363861,
"author": "Ilja Preuß",
"author_id": 11765,
"author_profile": "https://Stackoverflow.com/users/11765",
"pm_score": 4,
"selected": false,
"text": "modify replaceit changeit replaceit changeit replaceit changeit modify"
},
{
"answer_id": 434589,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 3,
"selected": false,
"text": "public TestModifyIfValueLength..()\n {\n string expectedValue = .. ;// literal result of replaceit(value)\n Assert.Equals( expectedValue, modify(\"asd\") );\n }\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3291/"
] |
363,655 | <p>I'm using C# on Framework 3.5. I'm looking to quickly group a Generic List<> by two properties. For the sake of this example lets say I have a List of an Order type with properties of CustomerId, ProductId, and ProductCount. How would I get the sum of ProductCounts grouped by CustomerId and ProductId using a lambda expression?</p>
| [
{
"answer_id": 363756,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 7,
"selected": true,
"text": "var sums = Orders.GroupBy(x => new { x.CustomerID, x.ProductID })\n .Select(group => group.Sum(x => x.ProductCount));\n"
},
{
"answer_id": 367168,
"author": "Klas Mellbourn",
"author_id": 46194,
"author_profile": "https://Stackoverflow.com/users/46194",
"pm_score": 3,
"selected": false,
"text": "var customerAndProductGroups =\n from order in Orders\n orderby order.CustomerID, order.ProductID // orderby not necessary, but neater\n group order by new { order.CustomerID, order.ProductID };\n\nforeach (var customerAndProductGroup in customerAndProductGroups)\n{\n Console.WriteLine(\"Customer {0} has ordered product {1} for a total count of {2}\",\n customerAndProductGroup.Key.CustomerID,\n customerAndProductGroup.Key.ProductID,\n customerAndProductGroup.Sum(item => item.ProductCount));\n}\n"
},
{
"answer_id": 2868951,
"author": "Todd Langdon",
"author_id": 97125,
"author_profile": "https://Stackoverflow.com/users/97125",
"pm_score": 4,
"selected": false,
"text": "var sums = Orders\n .GroupBy(x => new { x.CustomerID, x.ProductID })\n .Select(group =>new {group.Key, ProductCount = group.Sum(x => x.ProductCount)});\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7215/"
] |
363,660 | <p>I have a collection of orders. I would like to hit the database once, retrieve the orders, store them and then be able to access this collection over multiple forms. I know in asp.net, you can use things like Application Object or Session Object but how do you do it in a win form app? I was thinking of creating a static collection that could be accessed through multiple forms, classes, or wherever. Does this sound right and is it even feasible?</p>
<p>thanks</p>
| [
{
"answer_id": 363733,
"author": "Vyas Bharghava",
"author_id": 28413,
"author_profile": "https://Stackoverflow.com/users/28413",
"pm_score": 2,
"selected": true,
"text": "\nCacheList.OrderCache[orderNo].Customer.Address.City = \"Las Vegas\"; \n\nclass static CacheList\n{\n public static Cache OrderCache {get; internal set;}\n\n}\n\npublic class Cache : CollectionBase where T : Entity\n{\n .....\n\n }\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45429/"
] |
363,680 | <p>We mostly tend to following the above best practice.</p>
<p>Have a look at <a href="https://stackoverflow.com/questions/73883/string-vs-stringbuilder">String vs StringBuilder</a></p>
<p>But StringBuilder could throw <strong>OutOfMemoryException even when there is sufficient memory available</strong>. It throws OOM exception because it needs "continuous block of memory".</p>
<p>Some links for reference
<a href="http://bytes.com/groups/net-c/501231-stringbuilder-outofmemory" rel="nofollow noreferrer">StringBuilder OutOfMemoryException</a></p>
<p>and there are many more.....</p>
<p>How many of you faced this problem or aware and what did you do to resolve it?</p>
<p>Is there anything I am missing?</p>
<p><strong>P.S: I wasn't aware of this.</strong></p>
<p>I have rephrased the question.</p>
<p>*** The same thing worked with manual concatenation(I'll verify this and update SO). The other thing that caused me concern was that there is enough memory in the system. That's the reason I raised this question here to check whether any one faced this problem or there was something drastically wrong with the code. </p>
| [
{
"answer_id": 363877,
"author": "Brian Rasmussen",
"author_id": 38206,
"author_profile": "https://Stackoverflow.com/users/38206",
"pm_score": 2,
"selected": false,
"text": "StringBuilder String String StringBuilder StringBuilder"
},
{
"answer_id": 8609950,
"author": "archangel76",
"author_id": 1106463,
"author_profile": "https://Stackoverflow.com/users/1106463",
"pm_score": 0,
"selected": false,
"text": "myStringBuilder.Append(\"1,\"\"{0}\"\"\", someVeryLargeIntVariable)\n myStringBuilder.Append(String.Format(\"1,\"\"{0}\"\"\", someVeryLargeIntVariable))\n myStringBuilder.Append('a', 1564544656);\n myStringBuilder.Append(string.Format(\"1,\\\"{0}\\\"\", 1564544656));\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34644/"
] |
363,681 | <p>How do I generate a random <code>int</code> value in a specific range?</p>
<p>The following methods have bugs related to integer overflow:</p>
<pre class="lang-java prettyprint-override"><code>randomNum = minimum + (int)(Math.random() * maximum);
// Bug: `randomNum` can be bigger than `maximum`.
</code></pre>
<pre class="lang-java prettyprint-override"><code>Random rn = new Random();
int n = maximum - minimum + 1;
int i = rn.nextInt() % n;
randomNum = minimum + i;
// Bug: `randomNum` can be smaller than `minimum`.
</code></pre>
| [
{
"answer_id": 363691,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 8,
"selected": false,
"text": "minValue + rn.nextInt(maxValue - minValue + 1)\n"
},
{
"answer_id": 363692,
"author": "Greg Case",
"author_id": 462,
"author_profile": "https://Stackoverflow.com/users/462",
"pm_score": 12,
"selected": false,
"text": "import java.util.concurrent.ThreadLocalRandom;\n\n// nextInt is normally exclusive of the top value,\n// so add 1 to make it inclusive\nint randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);\n import java.util.Random;\n\n/**\n * Returns a pseudo-random number between min and max, inclusive.\n * The difference between min and max can be at most\n * <code>Integer.MAX_VALUE - 1</code>.\n *\n * @param min Minimum value\n * @param max Maximum value. Must be greater than min.\n * @return Integer between min and max, inclusive.\n * @see java.util.Random#nextInt(int)\n */\npublic static int randInt(int min, int max) {\n\n // NOTE: This will (intentionally) not run as written so that folks\n // copy-pasting have to think about how to initialize their\n // Random instance. Initialization of the Random instance is outside\n // the main scope of the question, but some decent options are to have\n // a field that is initialized once and then re-used as needed or to\n // use ThreadLocalRandom (if using at least Java 1.7).\n // \n // In particular, do NOT do 'Random rand = new Random()' here or you\n // will get not very good / not very random results.\n Random rand;\n\n // nextInt is normally exclusive of the top value,\n // so add 1 to make it inclusive\n int randomNum = rand.nextInt((max - min) + 1) + min;\n\n return randomNum;\n}\n"
},
{
"answer_id": 363693,
"author": "Michael Myers",
"author_id": 13531,
"author_profile": "https://Stackoverflow.com/users/13531",
"pm_score": 5,
"selected": false,
"text": " rand.nextInt((max+1) - min) + min;\n"
},
{
"answer_id": 363703,
"author": "Chinnery",
"author_id": 31892,
"author_profile": "https://Stackoverflow.com/users/31892",
"pm_score": 5,
"selected": false,
"text": "RandomDataGenerator.nextInt RandomDataGenerator.nextLong"
},
{
"answer_id": 363708,
"author": "user2427",
"author_id": 1356709,
"author_profile": "https://Stackoverflow.com/users/1356709",
"pm_score": 4,
"selected": false,
"text": "int random = minimum + Double.valueOf(Math.random()*(maximum-minimum )).intValue();\n"
},
{
"answer_id": 363713,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 7,
"selected": false,
"text": "Random rn = new Random();\nint range = maximum - minimum + 1;\nint randomNum = rn.nextInt(range) + minimum;\n"
},
{
"answer_id": 363732,
"author": "TJ_Fischer",
"author_id": 10007,
"author_profile": "https://Stackoverflow.com/users/10007",
"pm_score": 11,
"selected": false,
"text": "nextInt Min + (int)(Math.random() * ((Max - Min) + 1))\n [0,1) Math.random() * ( Max - Min )\n [0,Max-Min) [5,10) Math.random() * 5\n [0,5) Min + (Math.random() * (Max - Min))\n [Min,Max) [5,10) 5 + (Math.random() * (10 - 5))\n Max Max (Max - Min) Min + (int)(Math.random() * ((Max - Min) + 1))\n [Min,Max] [5,10] 5 + (int)(Math.random() * ((10 - 5) + 1))\n"
},
{
"answer_id": 424548,
"author": "Matt R",
"author_id": 4298,
"author_profile": "https://Stackoverflow.com/users/4298",
"pm_score": 6,
"selected": false,
"text": "Math.Random Random rand = new Random();\nint x = rand.nextInt(10);\n x 0-9 25 0 array.length String[] i = new String[25];\nRandom rand = new Random();\nint index = 0;\n\nindex = rand.nextInt( i.length );\n i.length 25 nextInt( i.length ) 0-24 Math.Random index = (int) Math.floor(Math.random() * i.length);\n"
},
{
"answer_id": 1377218,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": false,
"text": "Random ran = new Random();\nint x = ran.nextInt(6) + 5;\n x 5-10"
},
{
"answer_id": 2271563,
"author": "sam",
"author_id": 274198,
"author_profile": "https://Stackoverflow.com/users/274198",
"pm_score": 4,
"selected": false,
"text": "face = 1 + randomNumbers.nextInt(6);\n"
},
{
"answer_id": 2310610,
"author": "ganesh",
"author_id": 278646,
"author_profile": "https://Stackoverflow.com/users/278646",
"pm_score": 4,
"selected": false,
"text": "rand.nextInt((max+1) - min) + min;\n"
},
{
"answer_id": 4647255,
"author": "Joel Sjöstrand",
"author_id": 2081215,
"author_profile": "https://Stackoverflow.com/users/2081215",
"pm_score": 6,
"selected": false,
"text": "min + rng.nextInt(max - min + 1)) rng.nextInt(n) Integer.MAX_VALUE (max - min) min min <= max Integer.MIN_VALUE Integer.MAX_VALUE int nextIntInRange(int min, int max, Random rng) {\n if (min > max) {\n throw new IllegalArgumentException(\"Cannot draw random int from invalid range [\" + min + \", \" + max + \"].\");\n }\n int diff = max - min;\n if (diff >= 0 && diff != Integer.MAX_VALUE) {\n return (min + rng.nextInt(diff + 1));\n }\n int i;\n do {\n i = rng.nextInt();\n } while (i < min || i > max);\n return i;\n}\n while"
},
{
"answer_id": 6678179,
"author": "AZ_",
"author_id": 185022,
"author_profile": "https://Stackoverflow.com/users/185022",
"pm_score": 4,
"selected": false,
"text": "public static Random RANDOM = new Random(System.nanoTime());\n\npublic static final float random(final float pMin, final float pMax) {\n return pMin + RANDOM.nextFloat() * (pMax - pMin);\n}\n"
},
{
"answer_id": 8913481,
"author": "gerardw",
"author_id": 697099,
"author_profile": "https://Stackoverflow.com/users/697099",
"pm_score": 4,
"selected": false,
"text": "import org.apache.commons.math.random.RandomData;\nimport org.apache.commons.math.random.RandomDataImpl;\n\npublic void method() {\n RandomData randomData = new RandomDataImpl();\n int number = randomData.nextInt(5, 10);\n // ...\n }\n"
},
{
"answer_id": 9297051,
"author": "Garrett Hall",
"author_id": 554988,
"author_profile": "https://Stackoverflow.com/users/554988",
"pm_score": 4,
"selected": false,
"text": "ints import java.util.Random;\n\npublic class RandomRange extends Random {\n public int nextIncInc(int min, int max) {\n return nextInt(max - min + 1) + min;\n }\n\n public int nextExcInc(int min, int max) {\n return nextInt(max - min) + 1 + min;\n }\n\n public int nextExcExc(int min, int max) {\n return nextInt(max - min - 1) + 1 + min;\n }\n\n public int nextIncExc(int min, int max) {\n return nextInt(max - min) + min;\n }\n}\n"
},
{
"answer_id": 10930164,
"author": "Hospes",
"author_id": 767519,
"author_profile": "https://Stackoverflow.com/users/767519",
"pm_score": 4,
"selected": false,
"text": "import java.util.Random;\n\n/** Generate random integers in a certain range. */\npublic final class RandomRange {\n\n public static final void main(String... aArgs){\n log(\"Generating random integers in the range 1..10.\");\n\n int START = 1;\n int END = 10;\n Random random = new Random();\n for (int idx = 1; idx <= 10; ++idx){\n showRandomInteger(START, END, random);\n }\n\n log(\"Done.\");\n }\n\n private static void showRandomInteger(int aStart, int aEnd, Random aRandom){\n if ( aStart > aEnd ) {\n throw new IllegalArgumentException(\"Start cannot exceed End.\");\n }\n //get the range, casting to long to avoid overflow problems\n long range = (long)aEnd - (long)aStart + 1;\n // compute a fraction of the range, 0 <= frac < range\n long fraction = (long)(range * aRandom.nextDouble());\n int randomNumber = (int)(fraction + aStart); \n log(\"Generated : \" + randomNumber);\n }\n\n private static void log(String aMessage){\n System.out.println(aMessage);\n }\n} \n Generating random integers in the range 1..10.\nGenerated : 9\nGenerated : 3\nGenerated : 3\nGenerated : 9\nGenerated : 4\nGenerated : 1\nGenerated : 3\nGenerated : 9\nGenerated : 10\nGenerated : 10\nDone.\n"
},
{
"answer_id": 11923174,
"author": "Luke Taylor",
"author_id": 1297445,
"author_profile": "https://Stackoverflow.com/users/1297445",
"pm_score": 4,
"selected": false,
"text": "public static int getRandomNumberBetween(int min, int max) {\n Random foo = new Random();\n int randomNumber = foo.nextInt(max - min) + min;\n if (randomNumber == min) {\n // Since the random number is between the min and max values, simply add 1\n return min + 1;\n } else {\n return randomNumber;\n }\n}\n public static int getRandomNumberFrom(int min, int max) {\n Random foo = new Random();\n int randomNumber = foo.nextInt((max + 1) - min) + min;\n\n return randomNumber;\n}\n"
},
{
"answer_id": 13098409,
"author": "sachit",
"author_id": 1534027,
"author_profile": "https://Stackoverflow.com/users/1534027",
"pm_score": 3,
"selected": false,
"text": "Random r = new Random();\nint myRandomNumber = 0;\nmyRandomNumber = r.nextInt(maxValue - minValue + 1) + minValue;\n"
},
{
"answer_id": 13098451,
"author": "jatin3893",
"author_id": 1348139,
"author_profile": "https://Stackoverflow.com/users/1348139",
"pm_score": 2,
"selected": false,
"text": "i i = x + (i % (y - x));\n i"
},
{
"answer_id": 13728977,
"author": "Arun Abraham",
"author_id": 448005,
"author_profile": "https://Stackoverflow.com/users/448005",
"pm_score": 2,
"selected": false,
"text": "private static float getRandomNumberBetween(float numberOne, float numberTwo) throws Exception{\n\n if (numberOne == numberTwo){\n throw new Exception(\"Both the numbers can not be equal\");\n }\n\n float rand = (float) Math.random();\n float highRange = Math.max(numberOne, numberTwo);\n float lowRange = Math.min(numberOne, numberTwo);\n\n float lowRand = (float) Math.floor(rand-1);\n float highRand = (float) Math.ceil(rand+1);\n\n float genRand = (highRange-lowRange)*((rand-lowRand)/(highRand-lowRand))+lowRange;\n\n return genRand;\n}\n System.out.println( getRandomNumberBetween(1,-1));\n"
},
{
"answer_id": 14843702,
"author": "andrew",
"author_id": 1693143,
"author_profile": "https://Stackoverflow.com/users/1693143",
"pm_score": 7,
"selected": false,
"text": "ThreadLocalRandom java.util.Random int rand = ThreadLocalRandom.current().nextInt(x,y);\n x y"
},
{
"answer_id": 16987468,
"author": "A Gupta",
"author_id": 1660192,
"author_profile": "https://Stackoverflow.com/users/1660192",
"pm_score": 1,
"selected": false,
"text": "org.apache.commons.lang.RandomStringUtils while (true)\n {\n int abc = Integer.valueOf(RandomStringUtils.randomNumeric(1));\n int cd = Integer.valueOf(RandomStringUtils.randomNumeric(2));\n if ((cd-abc) >= 5 && (cd-abc) <= 15)\n {\n System.out.println(cd-abc);\n break;\n }\n }\n"
},
{
"answer_id": 18554758,
"author": "Abel Callejo",
"author_id": 1121841,
"author_profile": "https://Stackoverflow.com/users/1121841",
"pm_score": 6,
"selected": false,
"text": "Randomizer.generate(0, 10); // Minimum of zero and maximum of ten\n public class Randomizer {\n public static int generate(int min, int max) {\n return min + (int)(Math.random() * ((max - min) + 1));\n }\n}\n"
},
{
"answer_id": 18955785,
"author": "Akash Malhotra",
"author_id": 1632187,
"author_profile": "https://Stackoverflow.com/users/1632187",
"pm_score": 2,
"selected": false,
"text": "import java.util.Random;\npublic final class RandomNumber {\n\n public static final void main(String... aArgs) {\n log(\"Generating 10 random integers in range 1..10.\");\n int START = 1;\n int END = 10;\n Random randomGenerator = new Random();\n for (int idx=1; idx<=10; ++idx) {\n\n // int randomInt=randomGenerator.nextInt(100);\n // log(\"Generated : \" + randomInt);\n showRandomInteger(START,END,randomGenerator);\n }\n log(\"Done\");\n }\n\n private static void log(String aMessage) {\n System.out.println(aMessage);\n }\n\n private static void showRandomInteger(int aStart, int aEnd, Random aRandom) {\n if (aStart > aEnd) {\n throw new IllegalArgumentException(\"Start cannot exceed End.\");\n }\n long range = (long)aEnd - (long)aStart + 1;\n long fraction = (long) (range * aRandom.nextDouble());\n int randomNumber = (int) (fraction + aStart);\n log(\"Generated\" + randomNumber);\n }\n}\n"
},
{
"answer_id": 20175547,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "x a b public static void main(String[] args) {\n int a = 100;\n int b = 1000;\n int lowest = b;\n int highest = a;\n int count = 100000;\n Random random = new Random();\n for (int i = 0; i < count; i++) {\n int nextNumber = (int) ((Math.abs(random.nextDouble()) * (b - a))) + a;\n if (nextNumber < a || nextNumber > b) {\n System.err.println(\"number not in range :\" + nextNumber);\n }\n else {\n System.out.println(nextNumber);\n }\n if (nextNumber < lowest) {\n lowest = nextNumber;\n }\n if (nextNumber > highest) {\n highest = nextNumber;\n }\n }\n System.out.println(\"Produced \" + count + \" numbers from \" + lowest\n + \" to \" + highest);\n}\n"
},
{
"answer_id": 20761900,
"author": "Prof Mo",
"author_id": 565179,
"author_profile": "https://Stackoverflow.com/users/565179",
"pm_score": 4,
"selected": false,
"text": "Random ran = new Random();\n// Assumes max and min are non-negative.\nint randomInt = min + ran.nextInt(max - min + 1);\n"
},
{
"answer_id": 21127158,
"author": "Jorge",
"author_id": 2271536,
"author_profile": "https://Stackoverflow.com/users/2271536",
"pm_score": 3,
"selected": false,
"text": "randomNum = minimum + (int)(Math.random()*maximum); \n Math.random() randomNum = minimum + (int)(Math.random()*(maximum-minimum+1))\n Math.random() Random rn = new Random();\nint n = maximum - minimum + 1;\nint i = rn.nextInt() % n;\nrandomNum = minimum + i;\n rn.nextInt() Random rn = new Random();\nint n = maximum - minimum + 1;\nint i = rn.nextInt(n);\nrandomNum = minimum + i;\n"
},
{
"answer_id": 23850587,
"author": "f3d0r",
"author_id": 3147737,
"author_profile": "https://Stackoverflow.com/users/3147737",
"pm_score": 2,
"selected": false,
"text": "Random r = new Random();\nint i = r.nextInt();\n Math.random() * (max - min) + min;\n"
},
{
"answer_id": 24216407,
"author": "yottabrain",
"author_id": 1734143,
"author_profile": "https://Stackoverflow.com/users/1734143",
"pm_score": 3,
"selected": false,
"text": "import java.util.Random; \n\npublic class RandomUtil {\n // Declare as class variable so that it is not re-seeded every call\n private static Random random = new Random();\n\n /**\n * Returns a psuedo-random number between min and max (both inclusive)\n * @param min Minimim value\n * @param max Maximim value. Must be greater than min.\n * @return Integer between min and max (both inclusive)\n * @see java.util.Random#nextInt(int)\n */\n public static int nextInt(int min, int max) {\n // nextInt is normally exclusive of the top value,\n // so add 1 to make it inclusive\n return random.nextInt((max - min) + 1) + min;\n }\n}\n"
},
{
"answer_id": 25101263,
"author": "Sunil Chawla",
"author_id": 3589614,
"author_profile": "https://Stackoverflow.com/users/3589614",
"pm_score": 5,
"selected": false,
"text": "int max = 10;\nint min = 5;\nint diff = max - min;\nRandom rn = new Random();\nint i = rn.nextInt(diff + 1);\ni += min;\nSystem.out.print(\"The Random Number is \" + i);\n"
},
{
"answer_id": 27156435,
"author": "Alexis C.",
"author_id": 1587046,
"author_profile": "https://Stackoverflow.com/users/1587046",
"pm_score": 8,
"selected": false,
"text": "ints(int randomNumberOrigin, int randomNumberBound) Random Random r = new Random();\nint[] fiveRandomNumbers = r.ints(5, 0, 11).toArray();\nint randomNumber = r.ints(1, 0, 11).findFirst().getAsInt();\n IntStream IntStream public final class IntRandomNumberGenerator {\n\n private PrimitiveIterator.OfInt randomIterator;\n\n /**\n * Initialize a new random number generator that generates\n * random numbers in the range [min, max]\n * @param min - the min value (inclusive)\n * @param max - the max value (inclusive)\n */\n public IntRandomNumberGenerator(int min, int max) {\n randomIterator = new Random().ints(min, max + 1).iterator();\n }\n\n /**\n * Returns a random number in the range (min, max)\n * @return a random number in the range (min, max)\n */\n public int nextInt() {\n return randomIterator.nextInt();\n }\n}\n double long"
},
{
"answer_id": 27180520,
"author": "Yakiv Mospan",
"author_id": 1805989,
"author_profile": "https://Stackoverflow.com/users/1805989",
"pm_score": 4,
"selected": false,
"text": "[min, max] min <= max is true Random.class RandomUtils random = new RandomUtils();\nrandom.nextInt(0, 0); // returns 0\nrandom.nextInt(10, 10); // returns 10\nrandom.nextInt(-10, 10); // returns numbers from -10 to 10 (-10, -9....9, 10)\nrandom.nextInt(10, -10); // throws assert\n import junit.framework.Assert;\nimport java.util.Random;\n\npublic class RandomUtils extends Random {\n\n /**\n * @param min generated value. Can't be > then max\n * @param max generated value\n * @return values in closed range [min, max].\n */\n public int nextInt(int min, int max) {\n Assert.assertFalse(\"min can't be > then max; values:[\" + min + \", \" + max + \"]\", min > max);\n if (min == max) {\n return max;\n }\n\n return nextInt(max - min + 1) + min;\n }\n}\n"
},
{
"answer_id": 28453447,
"author": "Muhammad Aamir Talib",
"author_id": 1025230,
"author_profile": "https://Stackoverflow.com/users/1025230",
"pm_score": 3,
"selected": false,
"text": "private static Random random = new Random(); \n\npublic static int getRandomInt(int min, int max){\n return random.nextInt(max - min + 1) + min;\n}\n public static int getRandomInt(Random random, int min, int max)\n{\n return random.nextInt(max - min + 1) + min;\n}\n"
},
{
"answer_id": 29021708,
"author": "hexabunny",
"author_id": 4146952,
"author_profile": "https://Stackoverflow.com/users/4146952",
"pm_score": 7,
"selected": false,
"text": "Random rand = new Random();\nrandomNum = minimum + rand.nextInt((maximum - minimum) + 1);\n Random"
},
{
"answer_id": 29279143,
"author": "grep",
"author_id": 2590960,
"author_profile": "https://Stackoverflow.com/users/2590960",
"pm_score": 4,
"selected": false,
"text": "public static int generateRandomInteger(int min, int max) {\n SecureRandom rand = new SecureRandom();\n rand.setSeed(new Date().getTime());\n int randomNum = rand.nextInt((max - min) + 1) + min;\n return randomNum;\n}\n"
},
{
"answer_id": 29517198,
"author": "thangaraj",
"author_id": 2095604,
"author_profile": "https://Stackoverflow.com/users/2095604",
"pm_score": 2,
"selected": false,
"text": "import java.awt.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Test {\n\n public static void main(String[] args) {\n int first, second;\n\n Scanner myScanner = new Scanner(System.in);\n\n System.out.println(\"Enter first integer: \");\n int numOne;\n numOne = myScanner.nextInt();\n System.out.println(\"You have keyed in \" + numOne);\n\n System.out.println(\"Enter second integer: \");\n int numTwo;\n numTwo = myScanner.nextInt();\n System.out.println(\"You have keyed in \" + numTwo);\n\n Random generator = new Random();\n int num = (int)(Math.random()*numTwo);\n System.out.println(\"Random number: \" + ((num>numOne)?num:numOne+num));\n }\n}\n"
},
{
"answer_id": 30480195,
"author": "gifpif",
"author_id": 2093934,
"author_profile": "https://Stackoverflow.com/users/2093934",
"pm_score": 5,
"selected": false,
"text": "Random rn = new Random();\nint result = rn.nextInt(max - min + 1) + min;\nSystem.out.println(result);\n"
},
{
"answer_id": 33424282,
"author": "Andrew",
"author_id": 2079831,
"author_profile": "https://Stackoverflow.com/users/2079831",
"pm_score": 2,
"selected": false,
"text": "int randomFromMinToMaxInclusive = ThreadLocalRandom.current()\n .nextInt(min, max + 1);\n"
},
{
"answer_id": 39711614,
"author": "Hiren Patel",
"author_id": 4233197,
"author_profile": "https://Stackoverflow.com/users/4233197",
"pm_score": 2,
"selected": false,
"text": "generateRandomListNoDuplicate(1000, 8000, 500);\n private void generateRandomListNoDuplicate(int min, int max, int totalNoRequired) {\n Random rng = new Random();\n Set<Integer> generatedList = new LinkedHashSet<>();\n while (generatedList.size() < totalNoRequired) {\n Integer radnomInt = rng.nextInt(max - min + 1) + min;\n generatedList.add(radnomInt);\n }\n}\n"
},
{
"answer_id": 40854699,
"author": "user_3380739",
"author_id": 3380739,
"author_profile": "https://Stackoverflow.com/users/3380739",
"pm_score": 2,
"selected": false,
"text": "final long mod = max- min + 1L;\nfinal int next = (int) (Math.abs(rand.nextLong() % mod) + min);\n"
},
{
"answer_id": 40938597,
"author": "false9striker",
"author_id": 649451,
"author_profile": "https://Stackoverflow.com/users/649451",
"pm_score": 3,
"selected": false,
"text": "RandomStringUtils.randomNumeric(int count)\n"
},
{
"answer_id": 41273686,
"author": "firephil",
"author_id": 449946,
"author_profile": "https://Stackoverflow.com/users/449946",
"pm_score": 3,
"selected": false,
"text": "import java.util.stream.IntStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n IntStream range = IntStream.rangeClosed(5,10);\n ArrayList<Integer> ls = new ArrayList<Integer>();\n\n //populate the ArrayList\n range.forEach(i -> ls.add(new Integer(i)) );\n\n //perform a random shuffle using the Collections Fisher-Yates shuffle\n Collections.shuffle(ls);\n System.out.println(ls);\n }\n}\n import scala.util.Random\n\nobject RandomRange extends App{\n val x = Random.shuffle(5 to 10)\n println(x)\n}\n"
},
{
"answer_id": 41735301,
"author": "Zar E Ahmer",
"author_id": 3496570,
"author_profile": "https://Stackoverflow.com/users/3496570",
"pm_score": 2,
"selected": false,
"text": "/*\n * minNum is the minimum possible random number\n * maxNum is the maximum possible random number\n * numbersNeeded is the quantity of random number required\n * the give method provides you with unique random number between min & max range\n*/\npublic static Set<Integer> getUniqueRandomNumbers( int minNum , int maxNum ,int numbersNeeded ){\n\n if(minNum >= maxNum)\n throw new IllegalArgumentException(\"maxNum must be greater than minNum\");\n\n if(! (numbersNeeded > (maxNum - minNum + 1) ))\n throw new IllegalArgumentException(\"numberNeeded must be greater then difference b/w (max- min +1)\");\n\n Random rng = new Random(); // Ideally just create one instance globally\n\n // Note: use LinkedHashSet to maintain insertion order\n Set<Integer> generated = new LinkedHashSet<Integer>();\n while (generated.size() < numbersNeeded)\n {\n Integer next = rng.nextInt((maxNum - minNum) + 1) + minNum;\n\n // As we're adding to a set, this will automatically do a containment check\n generated.add(next);\n }\n return generated;\n}\n"
},
{
"answer_id": 43634278,
"author": "Jake O",
"author_id": 7884494,
"author_profile": "https://Stackoverflow.com/users/7884494",
"pm_score": 0,
"selected": false,
"text": "public static List<Integer> generateNumbers(int initialCapacity, int randomBound, Boolean sorted, Random random) {\n\n List<Integer> numbers = random.ints(initialCapacity, 1, randomBound).boxed().collect(Collectors.toList());\n\n if (sorted)\n numbers.sort(null);\n\n return numbers;\n}\n"
},
{
"answer_id": 44202788,
"author": "Divyesh Kanzariya",
"author_id": 5246706,
"author_profile": "https://Stackoverflow.com/users/5246706",
"pm_score": 2,
"selected": false,
"text": "Commons Lang API 3.x RandomUtils public static int nextInt(int startInclusive, int endExclusive)\n int random = RandomUtils.nextInt(999,1000000);\n"
},
{
"answer_id": 44228421,
"author": "Simon",
"author_id": 7664765,
"author_profile": "https://Stackoverflow.com/users/7664765",
"pm_score": 5,
"selected": false,
"text": " /**\n * @param min - The minimum.\n * @param max - The maximum.\n * @return A random double between these numbers (inclusive the minimum and maximum).\n */\n public static double getRandom(double min, double max) {\n return (Math.random() * (max + 1 - min)) + min;\n }\n"
},
{
"answer_id": 44653324,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "Random random = new Random();\n\nint max = 10;\nint min = 5;\nint totalNumber = 10;\n\nIntStream stream = random.ints(totalNumber, min, max);\nstream.forEach(System.out::println);\n"
},
{
"answer_id": 45651198,
"author": "Gihan Chathuranga",
"author_id": 5213194,
"author_profile": "https://Stackoverflow.com/users/5213194",
"pm_score": 2,
"selected": false,
"text": "import java.util.Random;\nclass Example{\n public static void main(String args[]){\n /*-To test-\n for(int i = 1 ;i<20 ; i++){\n System.out.print(randomnumber()+\",\");\n }\n */\n\n int randomnumber = randomnumber();\n\n }\n\n public static int randomnumber(){\n Random rand = new Random();\n int randomNum = rand.nextInt(6) + 5;\n\n return randomNum;\n }\n}\n"
},
{
"answer_id": 46567228,
"author": "Sam2016",
"author_id": 6807980,
"author_profile": "https://Stackoverflow.com/users/6807980",
"pm_score": 0,
"selected": false,
"text": "Random r = new Random();\nfor(int i =0; i<20; i++){\n System.out.println(r.ints(90, 100).iterator().nextInt());\n}\n r.ints() IntStream"
},
{
"answer_id": 46642267,
"author": "namezhouyu",
"author_id": 8674497,
"author_profile": "https://Stackoverflow.com/users/8674497",
"pm_score": 3,
"selected": false,
"text": "Random random = new Random();\nint max = 10;\nint min = 3;\nint randomNum = random.nextInt(max) % (max - min + 1) + min;\n"
},
{
"answer_id": 47069053,
"author": "Lawakush Kurmi",
"author_id": 4485195,
"author_profile": "https://Stackoverflow.com/users/4485195",
"pm_score": 4,
"selected": false,
"text": "Random r = new Random();\nint lowerBound = 1;\nint upperBound = 11;\nint result = r.nextInt(upperBound-lowerBound) + lowerBound;\n"
},
{
"answer_id": 47602699,
"author": "ledlogic",
"author_id": 987044,
"author_profile": "https://Stackoverflow.com/users/987044",
"pm_score": 2,
"selected": false,
"text": "StochIntegerSelector randomIntegerSelector = new StochIntegerSelector();\nrandomIntegerSelector.setMin(-1);\nrandomIntegerSelector.setMax(1);\nInteger selectInteger = randomIntegerSelector.selectInteger();\n"
},
{
"answer_id": 48555591,
"author": "BMAM",
"author_id": 8985913,
"author_profile": "https://Stackoverflow.com/users/8985913",
"pm_score": 2,
"selected": false,
"text": "import java.util.Random import java.util.Random;\n\n// Six digits random number generation for OTP\nRandom rnd = new Random();\nlong longregisterOTP = 100000 + rnd.nextInt(900000);\nSystem.out.println(longregisterOTP);\n"
},
{
"answer_id": 48978108,
"author": "Sidd Thota",
"author_id": 6441370,
"author_profile": "https://Stackoverflow.com/users/6441370",
"pm_score": 2,
"selected": false,
"text": "public static void main(String[] args) {\n int b = randomNumberRange(0, 9);\n int d = randomNumberRange (100, 200);\n System.out.println(\"value of b is \" + b);\n System.out.println(\"value of d is \" + d);\n}\n\npublic static int randomNumberRange(int min, int max) {\n int n = (max + 1 - min) + min;\n return (int) (Math.random() * n);\n}\n"
},
{
"answer_id": 49784982,
"author": "Oleksandr Pyrohov",
"author_id": 2668232,
"author_profile": "https://Stackoverflow.com/users/2668232",
"pm_score": 5,
"selected": false,
"text": "Random ThreadLocalRandom SplittableRandom SplittableRandom Random int [0, 1_000]: int n = new SplittableRandom().nextInt(0, 1_001);\n int[100] [0, 1_000]: int[] a = new SplittableRandom().ints(100, 0, 1_001).parallel().toArray();\n IntStream stream = new SplittableRandom().ints(100, 0, 1_001);\n"
},
{
"answer_id": 50492122,
"author": "Sanjeev Singh",
"author_id": 2310053,
"author_profile": "https://Stackoverflow.com/users/2310053",
"pm_score": 2,
"selected": false,
"text": "int firstNum = 20;//Inclusive\nint lastNum = 50;//Exclusive\nint streamSize = 10;\nRandom num = new Random().ints(10, 20, 50).forEach(System.out::println);\n"
},
{
"answer_id": 50627635,
"author": "vaquar khan",
"author_id": 4812170,
"author_profile": "https://Stackoverflow.com/users/4812170",
"pm_score": 2,
"selected": false,
"text": "import java.util.Random;\n\npublic class RandomSSNTest {\n\n public static void main(String args[]) {\n generateDummySSNNumber();\n }\n\n\n //831-33-6049\n public static void generateDummySSNNumber() {\n Random random = new Random();\n\n int id1 = random.nextInt(1000);//3\n int id2 = random.nextInt(100);//2\n int id3 = random.nextInt(10000);//4\n\n System.out.print((id1+\"-\"+id2+\"-\"+id3));\n }\n\n}\n import java.util.concurrent.ThreadLocalRandom;\nRandom random = ThreadLocalRandom.current();\n"
},
{
"answer_id": 51841402,
"author": "monster",
"author_id": 7315895,
"author_profile": "https://Stackoverflow.com/users/7315895",
"pm_score": 2,
"selected": false,
"text": "randomNum = minimum + (int)(Math.random() * (maximum - minimum) );\n"
},
{
"answer_id": 51961141,
"author": "Alekya",
"author_id": 9169330,
"author_profile": "https://Stackoverflow.com/users/9169330",
"pm_score": 0,
"selected": false,
"text": "public static void main(String[] args) {\n\n Random ran = new Random();\n\n int min, max;\n Scanner sc = new Scanner(System.in);\n System.out.println(\"Enter min range:\");\n min = sc.nextInt();\n System.out.println(\"Enter max range:\");\n max = sc.nextInt();\n int num = ran.nextInt(min);\n int num1 = ran.nextInt(max);\n System.out.println(\"Random Number between given range is \" + num1);\n\n}\n"
},
{
"answer_id": 53349281,
"author": "Prakhar Nigam",
"author_id": 8704849,
"author_profile": "https://Stackoverflow.com/users/8704849",
"pm_score": 2,
"selected": false,
"text": "Random rand=new Random();\nrand.nextInt((max+1) - min) + min;\n"
},
{
"answer_id": 53994407,
"author": "Anjali Pavithra",
"author_id": 6039920,
"author_profile": "https://Stackoverflow.com/users/6039920",
"pm_score": -1,
"selected": false,
"text": "import java.util.Random;\npublic class RandomTestClass {\n\n public static void main(String[] args) {\n Random r = new Random();\n int max, min;\n Scanner scanner = new Scanner(System.in);\n System.out.println(\"Enter maximum value : \");\n max = scanner.nextInt();\n System.out.println(\"Enter minimum value : \");\n min = scanner.nextInt();\n int randomNum;\n randomNum = r.nextInt(max) + min;\n System.out.println(\"Random Number : \" + randomNum);\n }\n\n}\n"
},
{
"answer_id": 56109005,
"author": "Anshul Singhal",
"author_id": 4398100,
"author_profile": "https://Stackoverflow.com/users/4398100",
"pm_score": 3,
"selected": false,
"text": "ThreadLocalRandom.current().nextInt(rangeStart, rangeEndExclusive)\n"
},
{
"answer_id": 56912649,
"author": "Kaplan",
"author_id": 11199879,
"author_profile": "https://Stackoverflow.com/users/11199879",
"pm_score": 0,
"selected": false,
"text": "lowerBoundIncluded upperBoundIncluded SplittableRandom splittableRandom = new SplittableRandom(); BiFunction<Integer,Integer,Integer> randomInt = (lowerBoundIncluded, upperBoundIncluded)\n -> splittableRandom.nextInt(lowerBoundIncluded, upperBoundIncluded + 1);\n randomInt.apply( …, … ); // gets the random number new SplittableRandom().nextInt(lowerBoundIncluded, upperBoundIncluded + 1);\n"
},
{
"answer_id": 61595029,
"author": "Lokesh Sharma",
"author_id": 10401370,
"author_profile": "https://Stackoverflow.com/users/10401370",
"pm_score": 2,
"selected": false,
"text": "int func(int max, int min){\n\n int range = max - min + 1;\n \n // Math.random() function will return a random no between [0.0,1.0).\n int res = (int) ( Math.random()*range)+min;\n\n return res;\n}\n"
},
{
"answer_id": 62078915,
"author": "Anand",
"author_id": 1343090,
"author_profile": "https://Stackoverflow.com/users/1343090",
"pm_score": 2,
"selected": false,
"text": "Integer.parseInt(RandomStringUtils.randomNumeric(6, 6));\n"
},
{
"answer_id": 64256226,
"author": "Hasee Amarathunga",
"author_id": 7484853,
"author_profile": "https://Stackoverflow.com/users/7484853",
"pm_score": 3,
"selected": false,
"text": "int range = 10;\nint min = 5\nRandom r = new Random();\nint = r.nextInt(range) + min;\n"
},
{
"answer_id": 65924896,
"author": "dreamcrash",
"author_id": 1366871,
"author_profile": "https://Stackoverflow.com/users/1366871",
"pm_score": 2,
"selected": false,
"text": "Random SecureRandom random = new SecureRandom(); \n min max public static int generate(SecureRandom secureRandom, int min, int max) {\n return min + secureRandom.nextInt((max - min) + 1);\n}\n min max return min + secureRandom.nextInt((max - min));\n public class Main {\n\n public static int generate(SecureRandom secureRandom, int min, int max) {\n return min + secureRandom.nextInt((max - min) + 1);\n }\n\n public static void main(String[] arg) {\n SecureRandom random = new SecureRandom();\n System.out.println(generate(random, 0, 2 ));\n }\n}\n Random SecureRandom"
},
{
"answer_id": 68163344,
"author": "Shital Ghimire",
"author_id": 15748687,
"author_profile": "https://Stackoverflow.com/users/15748687",
"pm_score": 3,
"selected": false,
"text": "Random rng = new Random();\nint min = 3;\nint max = 11;\nint upperBound = max - min + 1; // upper bound is exclusive, so +1\nint num = min + rng.nextInt(upperBound);\nSystem.out.println(num);\n"
},
{
"answer_id": 68901424,
"author": "Musfiq Shanta",
"author_id": 10227261,
"author_profile": "https://Stackoverflow.com/users/10227261",
"pm_score": 3,
"selected": false,
"text": "int randomNum = 5 + (int)(Math.random()*5);\n"
},
{
"answer_id": 70529176,
"author": "M. Justin",
"author_id": 1108305,
"author_profile": "https://Stackoverflow.com/users/1108305",
"pm_score": 3,
"selected": false,
"text": "RandomGenerator int nextInt(int origin, int bound) // Returns a random int between minimum (inclusive) & maximum (exclusive)\nint randomInt = RandomGenerator.getDefault().nextInt(minimum, maximum);\n Random SecureRandom SplittableRandom ThreadLocalRandom nextInt new Random().nextInt(minimum, maximum);\nnew SecureRandom().nextInt(minimum, maximum);\nnew SplittableRandom().nextInt(minimum, maximum);\nnew ThreadLocalRandom().nextInt(minimum, maximum);\n Random SecureRandom ThreadLocalRandom SplittableRandom"
},
{
"answer_id": 73305526,
"author": "saran3h",
"author_id": 3520404,
"author_profile": "https://Stackoverflow.com/users/3520404",
"pm_score": 0,
"selected": false,
"text": "RandomStringUtils.randomNumeric(count); // Where count is the number of digits you want in the random number.\n"
},
{
"answer_id": 74646697,
"author": "Mahozad",
"author_id": 8583692,
"author_profile": "https://Stackoverflow.com/users/8583692",
"pm_score": 0,
"selected": false,
"text": "val r = (0..10).random() // A random integer between 0 and 10 inclusive\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42155/"
] |
363,706 | <p>This error should be a simple one but I cant seem to make it work. The problem lies in the fact that this very same code works earlier in the program. I don's see any reason for it to be sending an error on this instance and not the four previous ones. Reference the code below, and feel free to provide any criticism you may have as it should make me better. If it matters, I am using Sharp Develop 2.2.</p>
<p>Here is an example of the code that works:</p>
<pre><code>void calc2Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text))
{
MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
}
if (!String.IsNullOrEmpty(tb2_kva.Text) & !String.IsNullOrEmpty(tb2_e.Text))
{
decimal x, y, z;
x = decimal.Parse(tb2_kva.Text);
y = decimal.Parse(tb2_e.Text);
z = (x * 1000) / (1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals
tb2_fla.Text = z.ToString();
tb2_fla.Text = Math.Round(z,2).ToString();
}
else
{
if (!String.IsNullOrEmpty(tb2_fla.Text) & !String.IsNullOrEmpty(tb2_e.Text))
{
decimal x, y, z;
x = decimal.Parse(tb2_fla.Text);
y = decimal.Parse(tb2_e.Text);
z = (x * y * 1.732050808m) / 1000; //the m at the end of the decimal allows for the multiplication of decimals
tb2_kva.Text = Math.Round(z,2).ToString();
}
</code></pre>
<p>Here is the example of the code that sends the error in the subject line of this post:</p>
<pre><code>void Calc4Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(tb4_fla.Text) && String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) & String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text))
{ //If values are entered improperly, the following message box will appear
MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK);
}
if (!String.IsNullOrEmpty(tb4_fla.Text)&& !String.IsNullOrEmpty(tb4_e.Text)&& String.IsNullOrEmpty(tb4_kw.Text))
{//If the user eneters FLA and Voltage calculate for kW
decimal x, y, z;
x = decimal.Parse(tb4_fla.Text);
y = decimal.Parse(tb4_e.Text);
z = (x*y)*(.8 * 1.732050808m);
tb4_kw.Text = Math.Round(z,0).ToString();
}
if (!String.IsNullOrEmpty(tb4_kw.Text) && !String.IsNullOrEmpty(tb4_e.Text) && String.IsNullOrEmpty(tb4_fla.Text))
{;//If the user enters kW and Voltage calculate for FLA
decimal x, y, z;
x = decimal.Parse(tb4_kw.Text);
y = decimal.Parse(tb4_e.Text);
z = (1000 * x)/(y * 1.732050808m)* .8;
tb4_fla.Text = Math.Round(z,0).ToString();
}
}
</code></pre>
<p>I appreciate any help that I can get.
Thank you.</p>
| [
{
"answer_id": 363714,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 6,
"selected": true,
"text": ".8m instead of .8\n"
},
{
"answer_id": 363719,
"author": "Harper Shelby",
"author_id": 21196,
"author_profile": "https://Stackoverflow.com/users/21196",
"pm_score": 2,
"selected": false,
"text": "z = (x*y)*(.8 * 1.732050808m);\n z = (1000 * x)/(y * 1.732050808m)* .8;\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45151/"
] |
363,718 | <p>My designer handed me a design I'm not 100% sure how to do with jquery and css.
I am basicly trying to allow a user to "slide" the footer up to reveal more conent.</p>
<p>My html..</p>
<pre><code> <div id="footer">
<div id="expandingFooter"> hidden content</div>
content that is always visible
</div>
</code></pre>
<p>I have a toggle button that onclick</p>
<pre><code>$('#expandingFooter').slideToggle();
</code></pre>
<p>This slides the expanding footer content open downward, then slides back up to close.
I would like it to slide up and then close down.</p>
<p>Thanks</p>
| [
{
"answer_id": 363759,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": 1,
"selected": false,
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html>\n<head>\n <title>Untitled</title>\n <script type=\"text/javascript\" src=\"shared-scripts/jquery-1.2.4b.js\"></script>\n <script type=\"text/javascript\">\n <!--\n $(document).ready(function(){\n $(\"#footer\").click(function () {\n if ($(\"#expandingFooter\").is(\":hidden\")) {\n $(\"#expandingFooter\").show(\"slow\");\n } else {\n $(\"#expandingFooter\").slideUp();\n }\n });\n $(\"#expandingFooter\").hide();\n });\n //--></script>\n\n</head>\n\n<body>\n <div id=\"footer\">\n <div id=\"expandingFooter\"> hidden content</div>\n content that is always visible\n </div>\n</body>\n</html>\n"
},
{
"answer_id": 363777,
"author": "Sander Versluys",
"author_id": 2172,
"author_profile": "https://Stackoverflow.com/users/2172",
"pm_score": 1,
"selected": false,
"text": "<a id=\"toggle\">Toggle()</a>\n\n<div id=\"slide\" style=\"position:relative; height: 100px\">\n\n <div id=\"slideInner\" style=\"position:absolute; bottom: 0; background: lightblue\"\">\n <p>Suspendisse potenti. Vivamus libero. Dummy Text</p>\n </div>\n\n</div>\n\n\n<script type=\"text/javascript\">\n $('.hoverable').hover( function() { $(this).find(\"div\").show(); },\n function() { $(this).find(\"div\").hide(); } );\n\n $('#toggle').click(function () {\n $('#slideInner').slideToggle();\n });\n</script>\n"
},
{
"answer_id": 363821,
"author": "Manik",
"author_id": 41381,
"author_profile": "https://Stackoverflow.com/users/41381",
"pm_score": 4,
"selected": true,
"text": "$('#toggleButton').bind('click', function(e) {\n $('#expandingFooter').toggle(\n 'slide', \n { easing: 'easeOutQuint', direction: 'down' }, \n 1000\n );\n});\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363718",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4568/"
] |
363,720 | <p>I have a slow custom data source in a SSIS Dataa Flow Task.I have to run the package with multiple parameters</p>
<p>If I want to upload data to a DB using SQL Data Destination(Bulk Insert) the connection times out</p>
<p>If I write the data to a flat file I cannot run multiple instances of the package, since they will write to the same file. Can I pass the file name as a parameter somewhere?</p>
<p>Do I need to write a custom Script Destination as the last resort?</p>
| [
{
"answer_id": 363759,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": 1,
"selected": false,
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html>\n<head>\n <title>Untitled</title>\n <script type=\"text/javascript\" src=\"shared-scripts/jquery-1.2.4b.js\"></script>\n <script type=\"text/javascript\">\n <!--\n $(document).ready(function(){\n $(\"#footer\").click(function () {\n if ($(\"#expandingFooter\").is(\":hidden\")) {\n $(\"#expandingFooter\").show(\"slow\");\n } else {\n $(\"#expandingFooter\").slideUp();\n }\n });\n $(\"#expandingFooter\").hide();\n });\n //--></script>\n\n</head>\n\n<body>\n <div id=\"footer\">\n <div id=\"expandingFooter\"> hidden content</div>\n content that is always visible\n </div>\n</body>\n</html>\n"
},
{
"answer_id": 363777,
"author": "Sander Versluys",
"author_id": 2172,
"author_profile": "https://Stackoverflow.com/users/2172",
"pm_score": 1,
"selected": false,
"text": "<a id=\"toggle\">Toggle()</a>\n\n<div id=\"slide\" style=\"position:relative; height: 100px\">\n\n <div id=\"slideInner\" style=\"position:absolute; bottom: 0; background: lightblue\"\">\n <p>Suspendisse potenti. Vivamus libero. Dummy Text</p>\n </div>\n\n</div>\n\n\n<script type=\"text/javascript\">\n $('.hoverable').hover( function() { $(this).find(\"div\").show(); },\n function() { $(this).find(\"div\").hide(); } );\n\n $('#toggle').click(function () {\n $('#slideInner').slideToggle();\n });\n</script>\n"
},
{
"answer_id": 363821,
"author": "Manik",
"author_id": 41381,
"author_profile": "https://Stackoverflow.com/users/41381",
"pm_score": 4,
"selected": true,
"text": "$('#toggleButton').bind('click', function(e) {\n $('#expandingFooter').toggle(\n 'slide', \n { easing: 'easeOutQuint', direction: 'down' }, \n 1000\n );\n});\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30546/"
] |
363,725 | <p>I have the following property in a custom control:</p>
<pre><code>List<myClass> _items;
public List<myClass> Items{
get { return _items; }
set { _items= value; }
}
</code></pre>
<p>In my codebehind, I add items to the collection as in...</p>
<pre><code>myCustomControl.items.Add(new myClass());
</code></pre>
<p>However, these are not persisted across postbacks. What is the proper way to allow persistance in custom controls?</p>
| [
{
"answer_id": 382388,
"author": "Corey Downie",
"author_id": 44861,
"author_profile": "https://Stackoverflow.com/users/44861",
"pm_score": 1,
"selected": false,
"text": "public List<myClass> Items{\n get { return this.ViewState[\"itemsKey\"] }\n set { this.ViewState[\"itemsKey\"]= value; }\n}\n"
},
{
"answer_id": 551846,
"author": "andleer",
"author_id": 64262,
"author_profile": "https://Stackoverflow.com/users/64262",
"pm_score": 1,
"selected": false,
"text": "protected List<myClass> Items\n{\n get\n {\n if (ViewState[\"myClass\"] == null)\n ViewState[\"myClass\"] = new List<myClass>();\n\n return (List<myClass>)ViewState[\"myClass\"];\n }\n}\n"
},
{
"answer_id": 566279,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "protected List<string> Items \n{ \n get \n { \n if (ViewState[\"Items\"] == null)\n ViewState[\"Items\"] = new string[0];\n return new List<string>((string[])ViewState[\"Items\"]);\n }\n set\n {\n ViewState[\"Items\"] = value.ToArray();\n }\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/337/"
] |
363,729 | <p>Is there a way to say something like:</p>
<p>sizeof(type)? Or type.Size? </p>
<p>Right now I am looking at using code like:</p>
<pre><code>if (type.Equals(typeof(int)))
return sizeof(int);
else if (type.Equals(typeof(long)))
return sizeof(long);
</code></pre>
<p>etc, etc, for every single data type. </p>
<p>There must be an cleaner solution, no?</p>
| [
{
"answer_id": 2652040,
"author": "Stupid Girl",
"author_id": 318374,
"author_profile": "https://Stackoverflow.com/users/318374",
"pm_score": -1,
"selected": false,
"text": "Convert.ToString(type.MaxValue, 2).Length / 8"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
363,730 | <pre><code> public sealed class UserLoginSingleton
{
UserLoginCollection _userLoginCol = new UserLoginCollection();
UserLoginSingleton()
{
}
public static UserLoginSingleton Instance
{
get
{
IDictionary items = HttpContext.Current.Items;
if (!items.Contains("TheInstance"))
{
items["TheInstance"] = new UserLoginSingleton();
}
return items["TheInstance"] as UserLoginSingleton;
}
}
public void CreateUserObj(string xmlData)
{
_userLoginCol = (UserLoginCollection)_xmlUtil.Deserialize(xmlData, typeof(UserLoginCollection));
}
public UserLoginCollection getUserObj()
{
return _userLoginCol;
}
}
</code></pre>
<p>Usage:</p>
<p>Page 1.aspx</p>
<pre><code>UserLoginSingleton.Instance.CreateUserObj(xml);
</code></pre>
<p>Pase2.aspx:</p>
<blockquote>
<p>UserLoginCollection
userLoginCollection =
UserLoginSingleton.Instance.getUserObj();</p>
</blockquote>
<p>Followed the article here:
<a href="https://stackoverflow.com/questions/194999/are-static-class-instances-unique-to-a-request-or-a-server-in-aspnet">link text</a></p>
<p>I set my collection object in page 1 and then do a response.redirect or click on link to get me to page 2.aspx. However, my singleton instance has no collection object i set. How do i persist my collection object across diff pages per each session?</p>
<p>I know static's wont work as every instance will see the object and i want that to specific per each user.</p>
| [
{
"answer_id": 363763,
"author": "Mike Powell",
"author_id": 205,
"author_profile": "https://Stackoverflow.com/users/205",
"pm_score": 2,
"selected": false,
"text": "HttpContext.Items HttpContext.Session"
},
{
"answer_id": 364031,
"author": "Chris Marisic",
"author_id": 37055,
"author_profile": "https://Stackoverflow.com/users/37055",
"pm_score": 0,
"selected": false,
"text": "public sealed class Singleton\n{\n static readonly Singleton instance=new Singleton();\n\n // Explicit static constructor to tell C# compiler\n // not to mark type as beforefieldinit\n static Singleton()\n {\n }\n\n Singleton()\n {\n }\n\n public static Singleton Instance\n {\n get\n {\n return instance;\n }\n }\n}\n"
},
{
"answer_id": 365592,
"author": "Juliet",
"author_id": 40516,
"author_profile": "https://Stackoverflow.com/users/40516",
"pm_score": 0,
"selected": false,
"text": "\npublic class UserLoginController\n{\n public static UserLoginController Instance\n {\n get\n {\n HttpSession session = HttpContext.Current.Session;\n if (session[\"UserLoginController\"] == null)\n {\n session[\"UserLoginController\"] = new UserLoginController();\n }\n return session[\"UserLoginController\"] as UserLoginController;\n }\n }\n}\n\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38230/"
] |
363,740 | <p>I want to try PartCover for code coverage. I'm running Visual Studio 2008 Professional with MSTest. The Professional Edition does not include the Team Testing tools, like Code Coverage.</p>
<p>So, I'm trying PartCover, but I can't get it to work. In the PartCover.Browser I've selected the MSTest executable, I've pointed the working arguments to my tests.dll, and I've tried pointing my Working Directory to the TestResults folder, but I get an error:</p>
<p>"Report is empty. Check settings and run target again."</p>
<p>I don't know what to try next.</p>
<p><strong>Edit</strong></p>
<p>It turns out I had two problems. First, I wasn't putting my Rules right. Second, I had spaces in my working arguments. The spaces were giving an error, but not showing up anywhere.</p>
| [
{
"answer_id": 363771,
"author": "Hamish Smith",
"author_id": 15572,
"author_profile": "https://Stackoverflow.com/users/15572",
"pm_score": 5,
"selected": true,
"text": "+[MyNamespace.MyAssemblyName]* +[*]* --include=[MyNamespace.MyAssembly]*"
},
{
"answer_id": 1902164,
"author": "pelazem",
"author_id": 140761,
"author_profile": "https://Stackoverflow.com/users/140761",
"pm_score": 4,
"selected": false,
"text": "<property name=\"PartCoverExePath\" value=\"c:\\Program Files (x86)\\PartCover .NET 2\\PartCover.exe\" />\n<property name=\"PartCoverWorkPath\" value=\"c:\\Projects\\MyProject\\trunk\\CI\\\" />\n<property name=\"PartCoverSettingsFileName\" value=\"PartCover.Settings.xml\" />\n<property name=\"PartCoverReportFileName\" value=\"PartCover.Report.xml\" />\n\n<target name=\"MyTarget\">\n<exec program=\"${PartCoverExePath}\">\n<arg value=\"--settings "${PartCoverWorkPath}${PartCoverSettingsFileName}"\" />\n<arg value=\"--output "${PartCoverWorkPath}${PartCoverReportFileName}"\" />\n</exec>\n</target>\n <PartCoverSettings>\n<Target>C:\\CI\\Binaries\\NUnit2.5.2\\bin\\net-2.0\\nunit-console-x86.exe</Target>\n<TargetWorkDir>c:\\Projects\\MyProject\\trunk\\MyProject.Test\\bin\\Debug</TargetWorkDir>\n<TargetArgs>MyProject.Test.dll</TargetArgs>\n<Rule>+[*]*</Rule>\n<Rule>-[log4net*]*</Rule>\n<Rule>-[nunit*]*</Rule>\n<Rule>-[MyProject.Test*]*</Rule>\n</PartCoverSettings>\n"
},
{
"answer_id": 2099778,
"author": "yeyeyerman",
"author_id": 110466,
"author_profile": "https://Stackoverflow.com/users/110466",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxml=\"urn:schemas-microsoft-com:xslt\">\n <xsl:output method=\"html\" indent=\"yes\"/>\n <xsl:template match=\"/\">\n\n <xsl:variable name=\"cov0style\" select=\"'background:#E79090;text-align:right;'\"/>\n <xsl:variable name=\"cov20style\" select=\"'background:#D79797;text-align:right;'\"/>\n <xsl:variable name=\"cov40style\" select=\"'background:#D7A0A0;text-align:right;'\"/>\n <xsl:variable name=\"cov60style\" select=\"'background:#C7A7A7;text-align:right;'\"/>\n <xsl:variable name=\"cov80style\" select=\"'background:#C0B0B0;text-align:right;'\"/>\n <xsl:variable name=\"cov100style\" select=\"'background:#D7D7D7;text-align:right;'\"/>\n\n<table style=\"border-collapse: collapse;\">\n <tr style=\"font-weight:bold; background:whitesmoke;\">\n <td colspan=\"2\">Coverage by assembly</td>\n </tr>\n\n <xsl:variable name=\"asms\" select=\"/PartCoverReport/Assembly\"/>\n <xsl:for-each select=\"$asms\">\n <xsl:variable name=\"current-asm-node\" select=\".\"/>\n <tr>\n\n <xsl:element name=\"td\">\n <xsl:attribute name=\"style\">background:ghostwhite; padding: 5px 30px 5px 5px;</xsl:attribute>\n <xsl:value-of select=\"$current-asm-node/@name\"/>\n </xsl:element>\n\n <xsl:variable name=\"codeSize\" select=\"sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt/@len)+0\"/>\n <xsl:variable name=\"coveredCodeSize\" select=\"sum(/PartCoverReport/Type[@asmref=$current-asm-node/@id]/Method/pt[@visit>0]/@len)+0\"/>\n\n <xsl:element name=\"td\">\n <xsl:if test=\"$codeSize=0\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov0style\"/>\n </xsl:attribute>\n 0%\n </xsl:if>\n <xsl:if test=\"$codeSize > 0\">\n <xsl:variable name=\"coverage\" select=\"ceiling(100 * $coveredCodeSize div $codeSize)\"/>\n <xsl:if test=\"$coverage >= 0 and $coverage < 20\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov20style\"/>\n </xsl:attribute>\n </xsl:if>\n <xsl:if test=\"$coverage >= 20 and $coverage < 40\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov40style\"/>\n </xsl:attribute>\n </xsl:if>\n <xsl:if test=\"$coverage >= 40 and $coverage < 60\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov60style\"/>\n </xsl:attribute>\n </xsl:if>\n <xsl:if test=\"$coverage >= 60 and $coverage < 80\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov80style\"/>\n </xsl:attribute>\n </xsl:if>\n <xsl:if test=\"$coverage >= 80\">\n <xsl:attribute name=\"style\">\n <xsl:value-of select=\"$cov100style\"/>\n </xsl:attribute>\n </xsl:if>\n <xsl:value-of select=\"$coverage\"/>%\n </xsl:if>\n </xsl:element>\n </tr>\n </xsl:for-each>\n</table>\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxml=\"urn:schemas-microsoft-com:xslt\">\n<xsl:output method=\"html\" indent=\"no\"/>\n\n<xsl:template match=\"/\">\n\n<xsl:variable name=\"cov0style\" select=\"'background:#FF4040;text-align:right;'\"/>\n<xsl:variable name=\"cov20style\" select=\"'background:#F06060;text-align:right;'\"/>\n<xsl:variable name=\"cov40style\" select=\"'background:#E78080;text-align:right;'\"/>\n<xsl:variable name=\"cov60style\" select=\"'background:#E0A0A0;text-align:right;'\"/>\n<xsl:variable name=\"cov80style\" select=\"'background:#D7B0B0;text-align:right;'\"/>\n<xsl:variable name=\"cov100style\" select=\"'background:#E0E0E0;text-align:right;'\"/>\n\n<table style=\"border-collapse: collapse;\">\n <tr style=\"font-weight:bold; background:whitesmoke;\"><td colspan=\"2\">Coverage by class</td></tr>\n\n <xsl:for-each select=\"/PartCoverReport/Type\">\n <tr>\n\n <xsl:element name=\"td\">\n <xsl:attribute name=\"style\">background:ghostwhite; padding: 5px 30px 5px 5px;</xsl:attribute>\n <xsl:value-of select=\"@name\"/>\n </xsl:element>\n\n <xsl:variable name=\"codeSize\" select=\"sum(./Method/pt/@len)+0\"/>\n <xsl:variable name=\"coveredCodeSize\" select=\"sum(./Method/pt[@visit>0]/@len)+0\"/>\n\n <xsl:element name=\"td\">\n <xsl:if test=\"$codeSize=0\">\n <xsl:attribute name=\"style\"><xsl:value-of select=\"$cov0style\"/></xsl:attribute>\n 0%\n </xsl:if>\n\n <xsl:if test=\"$codeSize > 0\">\n <xsl:variable name=\"coverage\" select=\"ceiling(100 * $coveredCodeSize div $codeSize)\"/>\n\n <xsl:if test=\"$coverage >= 0 and $coverage < 20\"><xsl:attribute name=\"style\"><xsl:value-of select=\"$cov20style\"/></xsl:attribute></xsl:if>\n <xsl:if test=\"$coverage >= 20 and $coverage < 40\"><xsl:attribute name=\"style\"><xsl:value-of select=\"$cov40style\"/></xsl:attribute></xsl:if>\n <xsl:if test=\"$coverage >= 40 and $coverage < 60\"><xsl:attribute name=\"style\"><xsl:value-of select=\"$cov60style\"/></xsl:attribute></xsl:if>\n <xsl:if test=\"$coverage >= 60 and $coverage < 80\"><xsl:attribute name=\"style\"><xsl:value-of select=\"$cov80style\"/></xsl:attribute></xsl:if>\n <xsl:if test=\"$coverage >= 80\"><xsl:attribute name=\"style\"><xsl:value-of select=\"$cov100style\"/></xsl:attribute></xsl:if>\n <xsl:value-of select=\"$coverage\"/>%\n </xsl:if>\n\n </xsl:element>\n </tr>\n </xsl:for-each>\n</table> \n</xsl:template>\n</xsl:stylesheet>\n"
},
{
"answer_id": 4166415,
"author": "David Laing",
"author_id": 13238,
"author_profile": "https://Stackoverflow.com/users/13238",
"pm_score": 1,
"selected": false,
"text": "<!-- Runs unit tests through PartCover to calculate unit test covereage-->\n<!-- Use %2a instead of * and %3f instead of ? to prevent expansion -->\n<!-- %40 = @ %25 = % %24 = $ -->\n<Target Name=\"RunTests\">\n <ItemGroup>\n <pc4_settings Include=\"--target "$(NUnitEXE)"\"/>\n <pc4_settings Include=\"--target-work-dir "$(RootDirectory)\\src"\"/>\n <pc4_settings Include=\"--include [%2a]%2a\"/>\n <pc4_settings Include=\"--exclude [nunit%2a]%2a\"/>\n <pc4_settings Include=\"--exclude [log4net%2a]%2a\"/>\n <pc4_settings Include=\"--exclude [MetadataProcessor.Tests%2a]%2a\"/>\n </ItemGroup>\n\n <CreateItem Include=\"$(RootDirectory)\\src\\**\\bin\\$(Configuration)\\*.Tests.dll\">\n <Output TaskParameter=\"Include\" ItemName=\"TestAssemblies\" />\n </CreateItem>\n\n <Exec Command=\""$(PartCover4Directory)\\PartCover.exe" --register @(pc4_settings,' ') --target-args "%(TestAssemblies.Identity) $(NUnitArgs) /xml:%(TestAssemblies.Identity).NUnitResults.xml" --output $(BuildDirectory)\\PartCover-results.xml\"\n ContinueOnError=\"true\"\n WorkingDirectory=\"$(BuildDirectory)\">\n <Output TaskParameter=\"ExitCode\" ItemName=\"ExitCodes\"/>\n </Exec>\n\n <XslTransformation XslInputPath=\"$(RootDirectory)\\tools\\partcover4\\xslt\\PartCoverFullReport.xslt\"\n XmlInputPaths=\"$(BuildDirectory)\\PartCover-results.xml\"\n OutputPaths=\"$(BuildDirectory)\\PartCover-results-PartCoverFullReport.html\" />\n\n <Error Text=\"Test error occurred\" Condition=\"'%(ExitCodes.Identity)'>0\"/>\n </Target>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1204/"
] |
363,760 | <p>I have been investigating for some time now a way to prevent my user from accidently entering a data directory of my application.</p>
<p>My application uses a folder to store a structured project. The folder internal structure is critic and should not be messed up. I would like my user to see this folder as a whole and not be able to open it (like a Mac bundle).</p>
<p>Is there a way to do that on Windows?</p>
<p><strong>Edit from current answers</strong></p>
<p>Of course I am not trying to prevent my users from accessing their data, just protecting them from accidentally destroying the data integrity. So encryption or password protection are not needed. </p>
<p>Thank you all for your .Net answers but unfortunately, this is mainly a C++ project without any dependency to the .Net framework.</p>
<p>The data I am mentioning are not light, they are acquired images from an electronic microscope. These data can be huge (~100 MiB to ~1 GiB) so loading everything in memory is not an option. These are huge images so the storage must provide a way to read the data incrementally by accessing one file at a time without loading the whole archive in memory.</p>
<p>Besides, the application is mainly legacy with some components we are not even responsible of. A solution that allows me to keep the current IO code is preferable.</p>
<p>Shell Extension looks interesting, I will investigate the solution further.</p>
<p>LarryF, can you elaborate on Filter Driver or DefineDOSDevice ? I am not familiar with these concepts.</p>
| [
{
"answer_id": 370046,
"author": "LarryF",
"author_id": 18518,
"author_profile": "https://Stackoverflow.com/users/18518",
"pm_score": 0,
"selected": false,
"text": "DefineDOSDevice() #define MARC_FILE_MAGIC 0x4352414D // In Little Endian\n#define MARC_FILENAME_LEN 56 //(You'll notice this is rather small)\n#define MARC_HEADER_SIZE 12\n#define MARC_FILE_ENT_SIZE 68\n\n#define MARC_DATA_SIZE 1024 * 128 // 128k Read Buffer should be enough.\n\n#define MARC_ERR_OK 0 // No error\n#define MARC_ERR_OOD 314 // Out of data error\n#define MARC_ERR_OS 315 // Error returned by the OS\n#define MARC_ERR_CRC 316 // CRC error\n\nstruct marc_file_hdr\n{\n ULONG h_magic;\n ULONG h_version;\n ULONG h_files;\n int h_fd;\n struct marc_dir *h_dir;\n};\n\nstruct marc_file\n{\n char f_filename[MARC_FILENAME_LEN];\n long f_filesize;\n unsigned long f_checksum;\n long f_offset;\n};\n\nstruct marc_dir\n{\n struct marc_file *dir_file;\n ULONG dir_filenum;\n struct marc_dir *dir_next;\n};\n struct marc_file_hdr *marc_open(char *filename)\n{\n struct marc_file_hdr *fhdr = (struct marc_file_hdr*)malloc(sizeof(marc_file_hdr));\n fhdr->h_dir = NULL;\n\n#if defined(_sopen_s)\n int errno = _sopen_s(fhdr->h_fd, filename, _O_BINARY | _O_RDONLY, _SH_DENYWR, _S_IREAD | _S_IWRITE);\n#else\n fhdr->h_fd = open(filename, _O_BINARY | _O_RDONLY);\n#endif\n if(fhdr->h_fd < 0)\n {\n marc_close(fhdr);\n return NULL;\n }\n\n //Once we have the file open, read all the file headers, and populate our main headers linked list.\n if(read(fhdr->h_fd, fhdr, MARC_HEADER_SIZE) != MARC_HEADER_SIZE)\n {\n errmsg(\"MARC: Could not read MARC header from file %s.\\n\", filename);\n marc_close(fhdr);\n return NULL;\n }\n\n // Verify the file magic\n if(fhdr->h_magic != MARC_FILE_MAGIC)\n {\n errmsg(\"MARC: Incorrect file magic %x found in MARC file.\", fhdr->h_magic);\n marc_close(fhdr);\n return NULL;\n }\n\n if(fhdr->h_files <= 0)\n {\n errmsg(\"MARC: No files found in archive.\\n\");\n marc_close(fhdr);\n return NULL;\n }\n\n // Get all the file headers from this archive, and link them to the main header.\n struct marc_dir *lastdir = NULL, *curdir = NULL;\n curdir = (struct marc_dir*)malloc(sizeof(marc_dir));\n fhdr->h_dir = curdir;\n\n for(int x = 0;x < fhdr->h_files;x++)\n {\n if(lastdir)\n {\n lastdir->dir_next = (struct marc_dir*)malloc(sizeof(marc_dir));\n lastdir->dir_next->dir_next = NULL;\n curdir = lastdir->dir_next;\n }\n\n curdir->dir_file = (struct marc_file*)malloc(sizeof(marc_file));\n curdir->dir_filenum = x + 1;\n\n if(read(fhdr->h_fd, curdir->dir_file, MARC_FILE_ENT_SIZE) != MARC_FILE_ENT_SIZE)\n {\n errmsg(\"MARC: Could not read file header for file %d\\n\", x);\n marc_close(fhdr);\n return NULL;\n }\n // LEF: Just a little extra insurance...\n curdir->dir_file->f_filename[MARC_FILENAME_LEN] = NULL;\n\n lastdir = curdir;\n }\n lastdir->dir_next = NULL;\n\n return fhdr;\n}\n bool marc_extract(struct marc_file_hdr *marc, struct marc_file *marcfile, char *file, int &err)\n{\n // Create the file from marcfile, in *file's location, return any errors.\n int ofd = 0;\n#if defined(_sopen_s)\n err = _sopen_s(ofd, filename, _O_CREAT | _O_SHORT_LIVED | _O_BINARY | _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);\n#else\n ofd = open(file, _O_CREAT | _O_SHORT_LIVED | _O_BINARY | _O_RDWR);\n#endif\n\n // Seek to the offset of the file to extract\n if(lseek(marc->h_fd, marcfile->f_offset, SEEK_SET) != marcfile->f_offset)\n {\n errmsg(\"MARC: Could not seek to offset 0x%04x for file %s.\\n\", marcfile->f_offset, marcfile->f_filename);\n close(ofd);\n err = MARC_ERR_OS; // Get the last error from the OS.\n return false;\n }\n\n unsigned char *buffer = (unsigned char*)malloc(MARC_DATA_SIZE);\n\n long bytesleft = marcfile->f_filesize;\n long readsize = MARC_DATA_SIZE >= marcfile->f_filesize ? marcfile->f_filesize : MARC_DATA_SIZE;\n unsigned long crc = 0;\n\n while(bytesleft)\n {\n if(read(marc->h_fd, buffer, readsize) != readsize)\n {\n errmsg(\"MARC: Failed to extract data from MARC archive.\\n\");\n free(buffer);\n close(ofd);\n err = MARC_ERR_OOD;\n return false;\n }\n\n crc = marc_checksum(buffer, readsize, crc);\n\n if(write(ofd, buffer, readsize) != readsize)\n {\n errmsg(\"MARC: Failed to write data to file.\\n\");\n free(buffer);\n close(ofd);\n err = MARC_ERR_OS; // Get the last error from the OS.\n return false;\n }\n bytesleft -= readsize;\n readsize = MARC_DATA_SIZE >= bytesleft ? bytesleft : MARC_DATA_SIZE;\n }\n\n // LEF: I can't quite figure out how the checksum is computed, but I think it has to do with the file header, PLUS the data in the file, or it's checked on the data in the file\n // minus any BOM's at the start... So, we'll just rem out this code for now, but I wrote it anyways.\n //if(crc != marcfile->f_checksum)\n //{\n // warningmsg(\"MARC: File CRC does not match. File could be corrupt, or altered. CRC=0x%08X, expected 0x%08X\\n\", crc, marcfile->f_checksum);\n // err = MARC_ERR_CRC;\n //}\n\n free(buffer);\n close(ofd);\n\n return true;\n}\n static unsigned long marc_checksum(void *pv, UINT cb, unsigned long seed)\n{\n int count = cb / 4;\n unsigned long csum = seed;\n BYTE *p = (BYTE*)pv;\n unsigned long ul;\n\n while(count-- > 0)\n {\n ul = *p++;\n ul |= (((unsigned long)(*p++)) << 8);\n ul |= (((unsigned long)(*p++)) << 16);\n ul |= (((unsigned long)(*p++)) << 24);\n csum ^= ul;\n }\n\n ul = 0;\n switch(cb % 4)\n {\n case 3: ul |= (((unsigned long)(*p++)) << 16);\n case 2: ul |= (((unsigned long)(*p++)) << 8);\n case 1: ul |= *p++;\n default: break;\n }\n csum ^= ul;\n\n return csum;\n} \n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/268/"
] |
363,768 | <p>I'm using <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29#Releases" rel="noreferrer">Eclipse Ganymede</a>. Everything works fine, but I have an anal-retentive yearning for a warning-free Problems tab. Right now it (correctly) complains about my <a href="http://en.wikipedia.org/wiki/Apache_Ant" rel="noreferrer">Ant</a> scripts: "No grammar constraints (DTD or XML schema) detected for the document." Is there any way to turn that off for just those files? Ideally I'd like it to still warn me if my other schema-constrained files were missing the schema declarations.</p>
| [
{
"answer_id": 483260,
"author": "David Pierre",
"author_id": 18296,
"author_profile": "https://Stackoverflow.com/users/18296",
"pm_score": 8,
"selected": true,
"text": "<!DOCTYPE project>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/409/"
] |
363,770 | <p>Let's say I have the following component called <strong><em>Base</em></strong>:</p>
<pre><code><cfcomponent output="false">
<cffunction name="init" access="public" returntype="Any" output="false">
<cfset variables.metadata = getmetadata(this)>
<cfreturn this>
</cffunction>
<cffunction name="getmeta" access="public" returntype="Any" output="false">
<cfreturn variables.metadata>
</cffunction>
</cfcomponent>
</code></pre>
<p>and I want to extend base in another component called <strong><em>Admin</em></strong>:</p>
<pre><code><cfcomponent output="false" extends="Base">
</cfcomponent>
</code></pre>
<p>Now within my application if I do the following when creating the object:</p>
<pre><code><cfset obj = createobject("component", "Admin").init()>
<cfdump var="#obj.getmeta()#">
</code></pre>
<p>The metadata I get back tells me that the name of the component is <strong><em>Admin</em></strong> and it's extending my <strong><em>Base</em></strong> component. That's all good, but I don't want to have to call the <strong><em>init()</em></strong> method explicitly when creating the object.</p>
<p>I would be nice if I could do something like this in my <strong><em>Base</em></strong> component:</p>
<pre><code><cfcomponent output="false">
<cfset init()>
<cffunction name="init" access="public" returntype="Any" output="false">
<cfset variables.metadata = getmetadata(this)>
<cfreturn this>
</cffunction>
<cffunction name="getmeta" access="public" returntype="Any" output="false">
<cfreturn variables.metadata>
</cffunction>
</cfcomponent>
</code></pre>
<p>However then the metadata returned by the getmeta() method telling me that the component name is <strong><em>Base</em></strong> even though it's still being extended. Any thoughts on how to accomplish this?</p>
| [
{
"answer_id": 483260,
"author": "David Pierre",
"author_id": 18296,
"author_profile": "https://Stackoverflow.com/users/18296",
"pm_score": 8,
"selected": true,
"text": "<!DOCTYPE project>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31278/"
] |
363,776 | <p>Is there any way that I can reference a var or const as the default value for a function argument in actionscript 3.</p>
<p>I can define default values like null, string, int.</p>
<pre>function a( b = null ) {
blah...
}</pre>
<p>But what I want to do is <pre>function a( b = function(){} ) {
blah...
}</pre></p>
<p>which it seems like there would be a way to do. Presumably through a const</p>
| [
{
"answer_id": 365120,
"author": "grapefrukt",
"author_id": 914,
"author_profile": "https://Stackoverflow.com/users/914",
"pm_score": 4,
"selected": true,
"text": "public function myFunction(functionArgument:Function = null):void {\n if (functionArgument != null) {\n functionArgument();\n } else {\n defaultFunction();\n }\n}\n public static const STATICFUNC:Function = function():void { trace(\"i'm static!\") };\n"
},
{
"answer_id": 558039,
"author": "Theo.T",
"author_id": 64223,
"author_profile": "https://Stackoverflow.com/users/64223",
"pm_score": 1,
"selected": false,
"text": "function myFunction(f:Function = null):void\n{\n f = (f != null) ? f : function():void{ trace('new function'); }\n}\n function myFunction(f:Function = null):void\n{\n f = (f != null) ? f : defaultFunction; \n}\n\nfunction defaultFunction():void\n{\n trace('default function invoked')\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40397/"
] |
363,784 | <p>I want my JTextPane to insert spaces whenever I press Tab. Currently it inserts the tab character (ASCII 9). </p>
<p>Is there anyway to customize the tab policy of JTextPane (other than catching "tab-key" events and inserting the spaces myself seems an)?</p>
| [
{
"answer_id": 363967,
"author": "Kai Mechel",
"author_id": 39893,
"author_profile": "https://Stackoverflow.com/users/39893",
"pm_score": 4,
"selected": true,
"text": "import java.awt.Dimension;\n\nimport javax.swing.JFrame;\nimport javax.swing.JTextPane;\nimport javax.swing.text.AttributeSet;\nimport javax.swing.text.BadLocationException;\nimport javax.swing.text.DefaultStyledDocument;\n\npublic class Tester {\n\n public static void main(String[] args) {\n JTextPane textpane = new JTextPane();\n textpane.setDocument(new TabDocument());\n JFrame frame = new JFrame();\n frame.getContentPane().add(textpane);\n frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n frame.setSize(new Dimension(200, 200));\n frame.setVisible(true);\n }\n\n static class TabDocument extends DefaultStyledDocument {\n @Override\n public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {\n str = str.replaceAll(\"\\t\", \" \");\n super.insertString(offs, str, a);\n }\n }\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27198/"
] |
363,819 | <p>I have been trying to extract last six numbers of an URL in each line of the original text and add it to another code that must be added to the result text. There also need to remove some code of each line from the original text and replace it with new code in the result text.</p>
<p>input
<a href="http://riyajr.googlepages.com/original.txt" rel="nofollow noreferrer">http://riyajr.googlepages.com/original.txt</a></p>
<p>output
<a href="http://riyajr.googlepages.com/result.txt" rel="nofollow noreferrer">http://riyajr.googlepages.com/result.txt</a></p>
<p>Is there any software that can do the above task? Please help me with any other options available. It would be great if someone could provide me with the full script code that could do above task.</p>
| [
{
"answer_id": 363883,
"author": "Byron Whitlock",
"author_id": 42304,
"author_profile": "https://Stackoverflow.com/users/42304",
"pm_score": 0,
"selected": false,
"text": "$infile = \"in.txt\";\n$outfile = \"out.txt\";\n\nforeach (file($url) as $line)\n{\n\n //extract last 6 chars\n $chars = substr($line, -6);\n\n // append the last 6 chars to a outfile\n file_put_contents($outfile, \"$chars\\n\", FILE_APPEND);\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45614/"
] |
363,833 | <p>I have implemented a session timeout warning using javascript that simply asks the user if they want to extend their session or logout. The problem is that this is for an intranet portal where power users will often have several browser windows or tabs open at the same time to the application. Currently, they will be prompted that they are about to be logged out from every browser window. How can I make the code smarter to detect that they are actively using another browser session?</p>
| [
{
"answer_id": 58095998,
"author": "ajay hariyal",
"author_id": 5746644,
"author_profile": "https://Stackoverflow.com/users/5746644",
"pm_score": 0,
"selected": false,
"text": "npm install --save @ng-idle/core @ng-idle/keepalive angular2-moment\n import { BrowserModule } from '@angular/platform-browser';\nimport { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { HttpModule } from '@angular/http';\n\nimport { NgIdleKeepaliveModule } from '@ng-idle/keepalive'; // this includes the core NgIdleModule but includes keepalive providers for easy wireup\n\nimport { MomentModule } from 'angular2-moment'; // optional, provides moment-style pipes for date formatting\n\nimport { AppComponent } from './app.component';\n\n@NgModule({\n declarations: [\n AppComponent\n ],\n imports: [\n BrowserModule,\n FormsModule,\n HttpModule,\n MomentModule,\n NgIdleKeepaliveModule.forRoot()\n ],\n providers: [],\n bootstrap: [AppComponent]\n})\nexport class AppModule { }\n import { Component } from '@angular/core';\n\nimport {Idle, DEFAULT_INTERRUPTSOURCES} from '@ng-idle/core';\nimport {Keepalive} from '@ng-idle/keepalive';\n\n@Component({\n selector: 'app-root',\n templateUrl: './app.component.html',\n styleUrls: ['./app.component.css']\n})\nexport class AppComponent {\n\n currentPath: String;\n\n idleState = 'Not started.';\n timedOut = false;\n lastPing?: Date = null;\n\n constructor(private idle: Idle, private keepalive: Keepalive, location: Location, router: Router) {\n\n // sets an idle timeout of 5 seconds, for testing purposes.\n idle.setIdle(5);\n\n // sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out.\n idle.setTimeout(5);\n\n // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document\n idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);\n\n idle.onIdleEnd.subscribe(() => this.idleState = 'No longer idle.');\n\n idle.onTimeout.subscribe(() => {\n this.idleState = 'Timed out!';\n this.timedOut = true;\n });\n\n idle.onIdleStart.subscribe(() => this.idleState = 'You\\'ve gone idle!');\n idle.onTimeoutWarning.subscribe((countdown) => this.idleState = 'You will time out in ' + countdown + ' seconds!');\n\n // Sets the ping interval to 15 seconds\n keepalive.interval(15);\n\n keepalive.onPing.subscribe(() => this.lastPing = new Date());\n\n // Lets check the path everytime the route changes, stop or start the idle check as appropriate.\n router.events.subscribe((val) => {\n\n this.currentPath = location.path();\n if(this.currentPath.search(/authentication\\/login/gi) == -1)\n idle.watch();\n else\n idle.stop();\n\n });\n }\n\n reset() {\n this.idle.watch();\n this.idleState = 'Started.';\n this.timedOut = false;\n }\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45814/"
] |
363,838 | <p>I have a user defined function in SQL called getBuisnessDays it takes @startdate and @enddate and returns the number of business days between the two dates. How can I call that function within my select?</p>
<p>Here's what I'd like to do.. </p>
<pre><code>SELECT getBusinessDays(a.opendate,a.closedate)
FROM account a
WHERE ...
</code></pre>
| [
{
"answer_id": 363857,
"author": "user17670",
"author_id": 17670,
"author_profile": "https://Stackoverflow.com/users/17670",
"pm_score": 8,
"selected": true,
"text": "SELECT dbo.GetBusinessDays(a.opendate,a.closedate) as BusinessDays\nFROM account a\nWHERE...\n"
},
{
"answer_id": 363875,
"author": "jerryhung",
"author_id": 37568,
"author_profile": "https://Stackoverflow.com/users/37568",
"pm_score": 4,
"selected": false,
"text": "SELECT * FROM dbo.udf_generate_inlist_to_table('1,2,3,4')\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13954/"
] |
363,845 | <p>I have an element that is similar to a tag (because it has word-wrap: pre;) to display code on a website. The only problem is that the tab size is too large and causes the element to horizontally scroll often because it is of fixed width.</p>
<p>Is it possible to change the tab size?</p>
| [
{
"answer_id": 363888,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": 0,
"selected": false,
"text": "text-indent <style type=\"text/css\">\np {\n text-indent: 40px;\n}\n</style>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29595/"
] |
363,848 | <p>Due to the packaged nature of the release, a SQL Server script (well more of a statement) needs to be created that can execute correctly on SQL Server 7.0 thru 2008 which can essentially achieve this:</p>
<pre><code>if exists(select * from sys.databases where name = 'Blah')
</code></pre>
<p>Reasons this is difficult:</p>
<p>SQL 7 'sys.databases' is not valid</p>
<p>SQL 2008 'sysdatabases' is not valid</p>
<p>I stupidly parsed out the version number using serverproperty, to allow an IF depending on the version:</p>
<pre><code>if (select CONVERT(int,replace(CONVERT(char(3),serverproperty ('productversion')),'.',''))) >= 80
</code></pre>
<p>Then discovered serverproperty does not exist under SQL 7.</p>
<p>Note that the SQL can be remote from the install, so no futzing around on the local machine - reg entries/file versions etc is of any use. </p>
<p>SQL Server error handling (especially 7.0) is poor, or maybe I don't understand it well enough to make it do a kind of try/catch.</p>
<p>I am now getting problem blindness to this, so any pointers would be appreciated.</p>
<p>Thanks,</p>
<p>Gareth</p>
| [
{
"answer_id": 364049,
"author": "George Mastros",
"author_id": 1408129,
"author_profile": "https://Stackoverflow.com/users/1408129",
"pm_score": 0,
"selected": false,
"text": "sp_helpDB\n"
},
{
"answer_id": 364124,
"author": "aristippus303",
"author_id": 45822,
"author_profile": "https://Stackoverflow.com/users/45822",
"pm_score": 1,
"selected": false,
"text": "create table #dwch_temp\n(\nname sysname\n,db_size nvarchar(13)\n,owner sysname\n,dbid smallint\n,created nvarchar(11)\n,status nvarchar(600)\n,compatibility_level tinyint\n)\ngo\n\n\n\ninsert into #dwch_temp\nexec sp_helpdb\n\nif exists(select name from #dwch_temp where name = 'DWCHServer')\n\n\n-- run the code\n\n\ndrop table #dwch_temp \n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
363,864 | <p>This code throws up the compile error given in the title, can anyone tell me what to change?</p>
<pre><code>#include <iostream>
using namespace std;
int main(){
int myArray[10][10][10];
for (int i = 0; i <= 9; ++i){
for (int t = 0; t <=9; ++t){
for (int x = 0; x <= 9; ++x){
for (int y = 0; y <= 9; ++y){
myArray[i][t][x][y] = i+t+x+y; //This will give each element a value
}
}
}
}
for (int i = 0; i <= 9; ++i){
for (int t = 0; t <=9; ++t){
for (int x = 0; x <= 9; ++x){
for (int y = 0; y <= 9; ++y){
cout << myArray[i][t][x][y] << endl;
}
}
}
}
system("pause");
}
</code></pre>
<p>thanks in advance</p>
| [
{
"answer_id": 363873,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 5,
"selected": true,
"text": "myArray[10][10][10] myArray[i][t][x][y]"
},
{
"answer_id": 363874,
"author": "DShook",
"author_id": 370,
"author_profile": "https://Stackoverflow.com/users/370",
"pm_score": 2,
"selected": false,
"text": "int myArray[10][10][10][10];"
},
{
"answer_id": 363878,
"author": "Cadoo",
"author_id": 42583,
"author_profile": "https://Stackoverflow.com/users/42583",
"pm_score": 2,
"selected": false,
"text": "int myArray[10][10][10];\n int myArray[10][10][10][10];\n"
},
{
"answer_id": 363960,
"author": "jmucchiello",
"author_id": 44065,
"author_profile": "https://Stackoverflow.com/users/44065",
"pm_score": 3,
"selected": false,
"text": "const int DIM_SIZE = 10;\nint myArray[DIM_SIZE][DIM_SIZE][DIM_SIZE];\n\nfor (int i = 0; i < DIM_SIZE; ++i){\n for (int t = 0; t < DIM_SIZE; ++t){ \n for (int x = 0; x < DIM_SIZE; ++x){\n"
},
{
"answer_id": 59924654,
"author": "Vishal Gupta",
"author_id": 12788480,
"author_profile": "https://Stackoverflow.com/users/12788480",
"pm_score": 2,
"selected": false,
"text": "int a[10]; // a global scope\n\nvoid f(int a) // a declared in local scope, overshadows a in global scope\n{\n printf(\"%d\", a[0]); // you trying to access the array a, but actually addressing local argument a\n}\n"
},
{
"answer_id": 72033216,
"author": "Amir2mi",
"author_id": 15172167,
"author_profile": "https://Stackoverflow.com/users/15172167",
"pm_score": 0,
"selected": false,
"text": "[] void addToDB(int arr) {\n // code\n}\n void addToDB(int arr[]) {\n // code\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] |
363,884 | <p>I've seen the <code>@</code> symbol used in PowerShell to initialise arrays.</p>
<p>What exactly does the <code>@</code> symbol denote and where can I read more about it?</p>
| [
{
"answer_id": 363894,
"author": "Cadoo",
"author_id": 42583,
"author_profile": "https://Stackoverflow.com/users/42583",
"pm_score": 4,
"selected": false,
"text": "$strComputers = @(\"Server1\", \"Server2\", \"Server3\")<enter>\n"
},
{
"answer_id": 363927,
"author": "Don Jones",
"author_id": 40405,
"author_profile": "https://Stackoverflow.com/users/40405",
"pm_score": 8,
"selected": true,
"text": "\"server1\",\"server2\"\n @{\"Key\"=\"Value\";\"Key2\"=\"Value2\"}\n"
},
{
"answer_id": 364087,
"author": "Mike Shepard",
"author_id": 36429,
"author_profile": "https://Stackoverflow.com/users/36429",
"pm_score": 5,
"selected": false,
"text": "@() $results = @( dir c:\\autoexec.bat)\n @()"
},
{
"answer_id": 574388,
"author": "Jeffrey Snover - MSFT",
"author_id": 69339,
"author_profile": "https://Stackoverflow.com/users/69339",
"pm_score": 7,
"selected": false,
"text": "PS> # First use it to create a hashtable of parameters:\nPS> $params = @{path = \"c:\\temp\"; Recurse= $true}\nPS> # Then use it to SPLAT the parameters - which is to say to expand a hash table \nPS> # into a set of command line parameters.\nPS> dir @params\nPS> # That was the equivalent of:\nPS> dir -Path c:\\temp -Recurse:$true\n"
},
{
"answer_id": 32915159,
"author": "Michael Sorens",
"author_id": 115690,
"author_profile": "https://Stackoverflow.com/users/115690",
"pm_score": 7,
"selected": false,
"text": "$a = @(ps | where name -like 'foo') $HashArguments = @{ Path = \"test.txt\"; Destination = \"test2.txt\"; WhatIf = $true } Copy-Item @HashArguments $data = @\"\nline one\nline two\nsomething \"quoted\" here\n\"@\n"
},
{
"answer_id": 71654166,
"author": "Brendan Harris",
"author_id": 9688181,
"author_profile": "https://Stackoverflow.com/users/9688181",
"pm_score": 0,
"selected": false,
"text": "$array = @{\na = \"test1\";\nb = \"test2\";\nc = \"test3\"\n}\n\nforeach($elem in $array.GetEnumerator()){\n if ($elem.key -eq \"a\"){\n $key = $elem.key\n $value = $elem.value\n }\n elseif ($elem.key -eq \"b\"){\n $key = $elem.key\n $value = $elem.value\n }\n elseif ($elem.key -eq \"c\"){\n $key = $elem.key\n $value = $elem.value\n }\n else{\n Write-Host \"No other value\"\n }\n\n Write-Host \"Key: \" $key \"Value: \" $value \n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45817/"
] |
363,889 | <p>I've written a screen saver that displays a web page. It works exactly as I want it to on my main display, but in the preview and secondary displays, the web view is hanging off the top of the screen.</p>
<p>Example (from preview):</p>
<a href="http://skitch.com/dlsspy/6mds/screen-saver-bug" rel="nofollow noreferrer">screen saver bug http://img.skitch.com/20081212-nk5cqrgfds1funr1a3p72aw25q.preview.jpg</a><br />Uploaded with <a href="http://plasq.com/" rel="nofollow noreferrer">plasq</a>'s <a href="http://skitch.com" rel="nofollow noreferrer">Skitch</a>!
<p>My code is pretty straightforward. From within <code>initWithFrame:isPreview:</code> I have the following code:</p>
<pre><code>webview = [[WebView alloc] initWithFrame:frame
frameName:@"main"
groupName:@"main"];
[self addSubview:webview];
</code></pre>
<p>Does anyone have any idea what's happening?</p>
<p>If anyone wants to play with the project, <a href="http://github.com/dustin/websaver" rel="nofollow noreferrer">the code</a> is on github.</p>
| [
{
"answer_id": 363894,
"author": "Cadoo",
"author_id": 42583,
"author_profile": "https://Stackoverflow.com/users/42583",
"pm_score": 4,
"selected": false,
"text": "$strComputers = @(\"Server1\", \"Server2\", \"Server3\")<enter>\n"
},
{
"answer_id": 363927,
"author": "Don Jones",
"author_id": 40405,
"author_profile": "https://Stackoverflow.com/users/40405",
"pm_score": 8,
"selected": true,
"text": "\"server1\",\"server2\"\n @{\"Key\"=\"Value\";\"Key2\"=\"Value2\"}\n"
},
{
"answer_id": 364087,
"author": "Mike Shepard",
"author_id": 36429,
"author_profile": "https://Stackoverflow.com/users/36429",
"pm_score": 5,
"selected": false,
"text": "@() $results = @( dir c:\\autoexec.bat)\n @()"
},
{
"answer_id": 574388,
"author": "Jeffrey Snover - MSFT",
"author_id": 69339,
"author_profile": "https://Stackoverflow.com/users/69339",
"pm_score": 7,
"selected": false,
"text": "PS> # First use it to create a hashtable of parameters:\nPS> $params = @{path = \"c:\\temp\"; Recurse= $true}\nPS> # Then use it to SPLAT the parameters - which is to say to expand a hash table \nPS> # into a set of command line parameters.\nPS> dir @params\nPS> # That was the equivalent of:\nPS> dir -Path c:\\temp -Recurse:$true\n"
},
{
"answer_id": 32915159,
"author": "Michael Sorens",
"author_id": 115690,
"author_profile": "https://Stackoverflow.com/users/115690",
"pm_score": 7,
"selected": false,
"text": "$a = @(ps | where name -like 'foo') $HashArguments = @{ Path = \"test.txt\"; Destination = \"test2.txt\"; WhatIf = $true } Copy-Item @HashArguments $data = @\"\nline one\nline two\nsomething \"quoted\" here\n\"@\n"
},
{
"answer_id": 71654166,
"author": "Brendan Harris",
"author_id": 9688181,
"author_profile": "https://Stackoverflow.com/users/9688181",
"pm_score": 0,
"selected": false,
"text": "$array = @{\na = \"test1\";\nb = \"test2\";\nc = \"test3\"\n}\n\nforeach($elem in $array.GetEnumerator()){\n if ($elem.key -eq \"a\"){\n $key = $elem.key\n $value = $elem.value\n }\n elseif ($elem.key -eq \"b\"){\n $key = $elem.key\n $value = $elem.value\n }\n elseif ($elem.key -eq \"c\"){\n $key = $elem.key\n $value = $elem.value\n }\n else{\n Write-Host \"No other value\"\n }\n\n Write-Host \"Key: \" $key \"Value: \" $value \n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39975/"
] |
363,892 | <p>I am using My.Settings in visual studio 2008 to store information, for when the user runs the program again.</p>
<p>I have that working fine... but as I am using 12 textboxes I don't want to write...</p>
<p>my.settings.grade1 = textbox1.text</p>
<p>for each one, and I am also making calculations using the stored information, so I dont want to be writing my.settings.grade1 + my.settings.grade2 etc..</p>
<p>Any help welcome</p>
<p>Thanks =)</p>
| [
{
"answer_id": 363915,
"author": "Jayden",
"author_id": 44873,
"author_profile": "https://Stackoverflow.com/users/44873",
"pm_score": 1,
"selected": false,
"text": "For Each c as Control in Me.Controls\n\n If c.Tag.ToString() = \"Grade\" Then\n ' Add Items to collection here '\n End If\n\nNext c\n"
},
{
"answer_id": 363938,
"author": "Jim Anderson",
"author_id": 42439,
"author_profile": "https://Stackoverflow.com/users/42439",
"pm_score": -1,
"selected": false,
"text": " Dim sum As Long\n Dim grades(11) As Long\n\n Dim i As Integer = 0\n For Each ctr In Controls\n If TypeOf (ctr) Is TextBox Then\n grades(i) = CLng(ctr.Text)\n sum = sum + grades(i)\n i = i + 1\n End If\n Next\n"
},
{
"answer_id": 363942,
"author": "Victor",
"author_id": 42518,
"author_profile": "https://Stackoverflow.com/users/42518",
"pm_score": 0,
"selected": false,
"text": "((TextBox)form.findControl(\"Grade\" + i.ToString())).Text = Grade(i)\n"
},
{
"answer_id": 364160,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 0,
"selected": false,
"text": "'at the class level'\nPublic GradeBoxes(11) As TextBox\nConst grade As String = \"GRADE\"\n\n'when the form is created'\nDim i As Integer = 0\nFor Each ctr As Control In Controls\n If TypeOf (ctr) Is TextBox AndAlso ctr.Name.ToUpper.StartsWith(grade) Then\n i = CInt(ctr.Name.SubString(grade.Length))\n If i >= 0 AndAlso i < GradeBoxes.Length Then GradeBoxes(i) = ctrl\n End If\nNext ctr\n\nFor Each box As TextBox in GradeBoxes\n If box IsNot Nothing AndAlso My.Settings(box.Name) IsNot Nothing Then\n box.Text = My.Settings(box.Name)\n End If\nNext box\n For Each box As TextBox in GradeBoxes\n If box IsNot Nothing AndAlso My.Settings(box.Name) IsNot Nothing Then\n My.Settings(box.Name) = box.Text\n End If\nNext box\nMy.Settings.Save()\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
363,899 | <p>I've several web user controls on my asp.net page and I wanna pass values between them. For example :</p>
<p>There is a dropDownList in one of them and when user selects any item from dropDownList, it can pass the selected value to the other user control which includes GridView to show related data of selected item value from the user control which contains the dropdownlist. (woow pretty awkward sentence tho) </p>
<p>Thanks and Regards..</p>
<p>P.s : Can we use User controls as class in the way to return values ?</p>
| [
{
"answer_id": 363912,
"author": "Victor",
"author_id": 42518,
"author_profile": "https://Stackoverflow.com/users/42518",
"pm_score": 3,
"selected": true,
"text": "public string needData { \nget { return MyData; }\nset { \n MyData = value;\n //do whatever you need to do with that data here\n}\n myControl2.needData = myDropDownList.SelectedValue;\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363899",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44852/"
] |
363,908 | <p>Here's an example:</p>
<pre><code>>git status
# On branch master
nothing to commit (working directory clean)
>git checkout -b test-branch
>vi test.c
>git add test.c
>git commit -m "modified test.c"
>vi README
>git add README
>git commit -m "modified README"
</code></pre>
<p>Now I want to do a '<code>git rebase -i</code>' that will let me rebase all commits for this branch. Is there something like '<code>git rebase -i HEAD~MASTER</code>' or similar. I figure I could do '<code>git rebase -i HEAD~2</code>', but I really don't want to have to count how many commits have been made. I could also do '<code>git rebase -i sha1</code>' but I don't want to comb through git log to find the first commit sha1. Any ideas?</p>
| [
{
"answer_id": 364065,
"author": "ididak",
"author_id": 28888,
"author_profile": "https://Stackoverflow.com/users/28888",
"pm_score": 7,
"selected": true,
"text": "git rebase -i master"
},
{
"answer_id": 364646,
"author": "Otto",
"author_id": 9594,
"author_profile": "https://Stackoverflow.com/users/9594",
"pm_score": 4,
"selected": false,
"text": "git rebase -i <the SHA hash of the root commit>\n git rebase -i 38965ed29d89a4136e47b688ca10b522b6bc335f\n pick 50b2cff File 1 changes.\npick 345df08 File 2 changes.\npick 9894931 File 3 changes.\npick 9a62b92 File 4 changes.\npick 640b1f8 File 5 changes.\npick 1c437f7 File 6 changes.\npick b014597 File 7 changes.\npick b1f52bc File 8 changes.\npick 40ae0fc File 9 changes.\n\n# Rebase 38965ed..40ae0fc onto 38965ed\n#\n# Commands:\n# pick = use commit\n# edit = use commit, but stop for amending\n# squash = use commit, but meld into previous commit\n#\n# If you remove a line here THAT COMMIT WILL BE LOST.\n# However, if you remove everything, the rebase will be aborted.\n#\n git log master..other_feature | cat\n git rebase -i `git log master..other_feature --pretty=format:\"%h\" | tail -n 1`~\n"
},
{
"answer_id": 4207357,
"author": "DanNetwalker",
"author_id": 511103,
"author_profile": "https://Stackoverflow.com/users/511103",
"pm_score": 7,
"selected": false,
"text": "git merge-base feature master\n git rebase -i `git merge-base feature master`\n"
},
{
"answer_id": 12202253,
"author": "Alex Brown",
"author_id": 121332,
"author_profile": "https://Stackoverflow.com/users/121332",
"pm_score": 2,
"selected": false,
"text": "git rebase -i @{upstream}\n git rebase -i `git merge-base --all HEAD @{upstream}`\n"
},
{
"answer_id": 24368667,
"author": "bbex",
"author_id": 3767884,
"author_profile": "https://Stackoverflow.com/users/3767884",
"pm_score": 1,
"selected": false,
"text": "git rebase -i --onto @{u}... @{u}\n"
},
{
"answer_id": 30045340,
"author": "Matthieu Moy",
"author_id": 4830165,
"author_profile": "https://Stackoverflow.com/users/4830165",
"pm_score": 2,
"selected": false,
"text": "git rebase git pull"
},
{
"answer_id": 30536600,
"author": "Joost den Boer",
"author_id": 3309859,
"author_profile": "https://Stackoverflow.com/users/3309859",
"pm_score": 6,
"selected": false,
"text": "git rebase -i XYZ\n git rebase -i --root\n"
},
{
"answer_id": 31036645,
"author": "Seth Flowers",
"author_id": 444610,
"author_profile": "https://Stackoverflow.com/users/444610",
"pm_score": 3,
"selected": false,
"text": "git rebase -i master rbi = !sh -c \\\"git rebase -i `git merge-base $1 HEAD`\\\" -\n git rbi parentBranch\n git merge-base"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45824/"
] |
363,930 | <p>Anyone done this and can share? I see an option or two but want to know what others have accomplished.</p>
| [
{
"answer_id": 13262628,
"author": "Carlos D. Garza",
"author_id": 1094641,
"author_profile": "https://Stackoverflow.com/users/1094641",
"pm_score": 1,
"selected": false,
"text": "public static Calendar parseCalendar(DateTime dt){\n return dt.toGregorianCalendar();\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
363,944 | <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return <code>None</code>. This code works:</p>
<pre class="lang-py prettyprint-override"><code>def main():
my_list = get_list()
if len(my_list) > 0:
return my_list[0]
return None
</code></pre>
<p>but it seems to me that there should be a simple one-line idiom for doing this. Is there?</p>
| [
{
"answer_id": 363955,
"author": "recursive",
"author_id": 44743,
"author_profile": "https://Stackoverflow.com/users/44743",
"pm_score": 7,
"selected": false,
"text": "(get_list() or [None])[0]\n list list()"
},
{
"answer_id": 363995,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 8,
"selected": false,
"text": "a = get_list()\nreturn a[0] if a else None\n return (get_list()[:1] or [None])[0]\n"
},
{
"answer_id": 364048,
"author": "limscoder",
"author_id": 45476,
"author_profile": "https://Stackoverflow.com/users/45476",
"pm_score": -1,
"selected": false,
"text": "try:\n return a[0]\nexcept IndexError:\n return None\n"
},
{
"answer_id": 364249,
"author": "A. Coady",
"author_id": 36433,
"author_profile": "https://Stackoverflow.com/users/36433",
"pm_score": 2,
"selected": false,
"text": "for item in get_list():\n return item\n"
},
{
"answer_id": 364274,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": -1,
"selected": false,
"text": "cond and true_expr or false_expr\n list = get_list()\nreturn list and list[0] or None\n"
},
{
"answer_id": 364405,
"author": "gotgenes",
"author_id": 38140,
"author_profile": "https://Stackoverflow.com/users/38140",
"pm_score": 4,
"selected": false,
"text": "if list:\n some_list = get_list()\nif some_list:\n def does_nothing():\n pass\n\nfoo = does_nothing()\nprint foo\n some_list = get_list()\nif some_list:\n return list[0]\n def get_first_item(some_list): \n if some_list:\n return list[0]\n\nmy_list = get_list()\nfirst_item = get_first_item(my_list)\n"
},
{
"answer_id": 364470,
"author": "rob",
"author_id": 43927,
"author_profile": "https://Stackoverflow.com/users/43927",
"pm_score": 2,
"selected": false,
"text": "if len(list) > 0: if list:"
},
{
"answer_id": 364511,
"author": "titaniumdecoy",
"author_id": 18091,
"author_profile": "https://Stackoverflow.com/users/18091",
"pm_score": -1,
"selected": false,
"text": "a = get_list()\nreturn a and a[0] or None"
},
{
"answer_id": 364570,
"author": "Clint Miller",
"author_id": 38226,
"author_profile": "https://Stackoverflow.com/users/38226",
"pm_score": -1,
"selected": false,
"text": "list = get_list()\nreturn list and list[0] or None\n"
},
{
"answer_id": 365934,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 9,
"selected": true,
"text": "next(iter(your_list), None)\n your_list None next(iter(your_list or []), None)\n def get_first(iterable, default=None):\n if iterable:\n for item in iterable:\n return item\n return default\n x = get_first(get_first_list())\nif x:\n ...\ny = get_first(get_second_list())\nif y:\n ...\n for x in get_first_list() or []:\n # process x\n break # process at most one item\nfor y in get_second_list() or []:\n # process y\n break\n break for x in yield_first(get_first_list()):\n x # process x\nfor y in yield_first(get_second_list()):\n y # process y\n def yield_first(iterable):\n for item in iterable or []:\n yield item\n return\n"
},
{
"answer_id": 370621,
"author": "gotgenes",
"author_id": 38140,
"author_profile": "https://Stackoverflow.com/users/38140",
"pm_score": 1,
"selected": false,
"text": "import random\nimport timeit\n\ndef index_first_item(some_list):\n if some_list:\n return some_list[0]\n\n\ndef return_first_item(some_list):\n for item in some_list:\n return item\n\n\nempty_lists = []\nfor i in range(10000):\n empty_lists.append([])\n\nassert empty_lists[0] is not empty_lists[1]\n\nfull_lists = []\nfor i in range(10000):\n full_lists.append(list([random.random() for i in range(10)]))\n\nmixed_lists = empty_lists[:50000] + full_lists[:50000]\nrandom.shuffle(mixed_lists)\n\nif __name__ == '__main__':\n ENV = 'import firstitem'\n test_data = ('empty_lists', 'full_lists', 'mixed_lists')\n funcs = ('index_first_item', 'return_first_item')\n for data in test_data:\n print \"%s:\" % data\n for func in funcs:\n t = timeit.Timer('firstitem.%s(firstitem.%s)' % (\n func, data), ENV)\n times = t.repeat()\n avg_time = sum(times) / len(times)\n print \" %s:\" % func\n for time in times:\n print \" %f seconds\" % time\n print \" %f seconds avg.\" % avg_time\n"
},
{
"answer_id": 371270,
"author": "ttepasse",
"author_id": 46657,
"author_profile": "https://Stackoverflow.com/users/46657",
"pm_score": 0,
"selected": false,
"text": "def head(iterable):\n try:\n return iter(iterable).next()\n except StopIteration:\n return None\n\nprint head(xrange(42, 1000) # 42\nprint head([]) # None\n lists = [\n [\"first\", \"list\"],\n [\"second\", \"list\"],\n [\"third\", \"list\"]\n]\n\ndef do_something(element):\n if not element:\n return\n else:\n # do something\n pass\n\nfor li in lists:\n do_something(head(li))\n"
},
{
"answer_id": 21560637,
"author": "Eric Marcos",
"author_id": 1075189,
"author_profile": "https://Stackoverflow.com/users/1075189",
"pm_score": -1,
"selected": false,
"text": "dict(enumerate(get_list())).get(0)\n get_list() None dict(enumerate(get_list() or [])).get(0)\n get_list()"
},
{
"answer_id": 25398201,
"author": "Devy",
"author_id": 416394,
"author_profile": "https://Stackoverflow.com/users/416394",
"pm_score": 5,
"selected": false,
"text": "next(iter(the_list), None) the_list the_list iter(the_list).next()"
},
{
"answer_id": 31097387,
"author": "VitalyB",
"author_id": 126574,
"author_profile": "https://Stackoverflow.com/users/126574",
"pm_score": -1,
"selected": false,
"text": "(my_list and my_list[0]) or None"
},
{
"answer_id": 31487813,
"author": "Russia Must Remove Putin",
"author_id": 541136,
"author_profile": "https://Stackoverflow.com/users/541136",
"pm_score": 3,
"selected": false,
"text": "def get_first(l): \n return l[0] if l else None\n get_list l = get_list()\nreturn l[0] if l else None\n := return l[0] if (l := get_list()) else None\n if l := get_list():\n return l[0]\nreturn None\n for for item in get_list():\n return item\n None get_list for item in get_list():\n return item\nreturn None\n if some_list None return None some_list = get_list()\nif some_list:\n return some_list[0]\n or [None] return (get_list()[:1] or [None])[0]\n or False get_list 0 return (get_list() or [None])[0]\n True my_list = get_list() \nreturn (my_list and my_list[0]) or None\n next next iter return next(iter(get_list()), None)\n iter .next .__next__ next .next None a if b else c get_list return None if not get_list() else get_list()[0]\n return get_list()[0] if get_list() else None\n get_list l = get_list()\nreturn l[0] if l else None\n"
},
{
"answer_id": 31510450,
"author": "bkowshik",
"author_id": 3453958,
"author_profile": "https://Stackoverflow.com/users/3453958",
"pm_score": -1,
"selected": false,
"text": "items = [10, 20]\ntry: first_item = items[0]\nexcept IndexError: first_item = None\nprint first_item\n items = [10, 20]\nfirst_item = (items[:1] or [None, ])[0]\nprint first_item\n"
},
{
"answer_id": 35702414,
"author": "Aidan Kane",
"author_id": 171450,
"author_profile": "https://Stackoverflow.com/users/171450",
"pm_score": 4,
"selected": false,
"text": "next((x for x in blah if cond), None)\n"
},
{
"answer_id": 40236811,
"author": "PrabhuPrakash",
"author_id": 7064294,
"author_profile": "https://Stackoverflow.com/users/7064294",
"pm_score": -1,
"selected": false,
"text": "if mylist != []:\n\n print(mylist[0])\n\n else:\n\n print(None)\n"
},
{
"answer_id": 45886316,
"author": "pylang",
"author_id": 4531270,
"author_profile": "https://Stackoverflow.com/users/4531270",
"pm_score": 3,
"selected": false,
"text": "nth def nth(iterable, n, default=None):\n \"Returns the nth item or a default value\"\n return next(islice(iterable, n, None), default)\n more_itertools import more_itertools as mit\n\nmit.nth([3, 2, 1], 0)\n# 3\n\nmit.nth([], 0) # default is `None`\n# None\n more_itertools.first mit.first([3, 2, 1])\n# 3\n\nmit.first([], default=None)\n# None\n"
},
{
"answer_id": 57958979,
"author": "Nicholas Hamilton",
"author_id": 1834057,
"author_profile": "https://Stackoverflow.com/users/1834057",
"pm_score": 2,
"selected": false,
"text": "my_list[0] if len(my_list) else None"
},
{
"answer_id": 60735676,
"author": "laktak",
"author_id": 52817,
"author_profile": "https://Stackoverflow.com/users/52817",
"pm_score": 1,
"selected": false,
"text": "first = lambda l, default=None: next(iter(l or []), default)\n"
},
{
"answer_id": 64849063,
"author": "mirekphd",
"author_id": 9962007,
"author_profile": "https://Stackoverflow.com/users/9962007",
"pm_score": 0,
"selected": false,
"text": "def first_true(iterable, default=None, pred=None):\n return next(filter(pred, iterable), default)\n\ndef get_first_non_default(items_list, default=None):\n return first_true(items_list, default, pred=lambda x: x!=default)\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19403/"
] |
363,969 | <p>I have the following code</p>
<pre><code>Try
'Some code that causes exception
Catch ex as ExceptionType1
'Handle Section - 1
Catch ex as ExceptionType2
'Handle section - 2
Catch ex as ExceptionType3
'Handle section - 3
Finally
' Clean up
End Try
</code></pre>
<p>Suppose ExceptionType1 is thrown by the code which is handled by section - 1. After handling that in section-1, can I have control passed to section-2/section-3? Is that possible?</p>
| [
{
"answer_id": 363986,
"author": "acrosman",
"author_id": 24215,
"author_profile": "https://Stackoverflow.com/users/24215",
"pm_score": 2,
"selected": false,
"text": "Try\n'Some code that causes exception'\nCatch ex as ExceptionType1\n handler_1()\n handler_2()\n handler_3()\nCatch ex as ExceptionType2\n handler_2()\n handler_3()\nCatch ex as ExceptionType3\n handler_3()\nFinally\n handler_4() \nEnd Try\n"
},
{
"answer_id": 364000,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "finally class ThrowingException {\n public static void main(String... args) {\n try {\n try {\n throw new RuntimeException();\n } catch(RuntimeException e) {\n System.out.println(\"Hi 1, handling RuntimeException..\");\n throw e;\n } finally {\n System.out.println(\"finally 1\");\n }\n } catch(Exception e) {\n System.out.println(\"Hi 2, handling Exception..\");\n } finally {\n System.out.println(\"finally 2\");\n }\n }\n}\n Hi 1, handling RuntimeException..\nfinally 1\nHi 2, handling Exception..\nfinally 2\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38997/"
] |
363,998 | <p>I have this:</p>
<pre><code>template <typename T>
class myList
{
...
class myIterator
{
...
T& operator*();
}
}
...
template<typename T>
T& myList<T>::myIterator::operator*()
{
...
}
</code></pre>
<p>That is giving me the following error: "expected initializer before '&' token". What exactly am I supposed to do? I already tried adding "template myList::myIterator" before it, but that didn't work.</p>
| [
{
"answer_id": 364013,
"author": "David Norman",
"author_id": 34502,
"author_profile": "https://Stackoverflow.com/users/34502",
"pm_score": 2,
"selected": false,
"text": "template <typename T>\nclass myList\n{\npublic:\n class myIterator\n {\n public:\n T& operator*();\n };\n};\n"
},
{
"answer_id": 364423,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 0,
"selected": false,
"text": "template <typename T>\nclass myList\n{\n public:\n class myIterator\n {\n public:\n T& operator*();\n };\n};\n\ntemplate<typename T>\nT& myList<T>::myIterator::operator*()\n{\n static T x;\n return x;\n}\n\nint main()\n{\n myList<int> a;\n myList<int>::myIterator b;\n int& c= *b;\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/363998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,001 | <p>My goal is to make a Button that has two Content values. </p>
<p>Imagine a Scrabble tile as a button: it has the large letter in the center and a small number in the lower right. This is the effect I am going for.</p>
<p>I made a button that has two ContentPresenter objects in it, and I have given each of the ContentPresenters a different style. However, I have not found a way to give each of the presenters a separate value (ie, if I set the Content of the button to "X" then both ContentPresenters show "X", albeit in different styles).</p>
<p>How can I achieve my objective? I'm guessing my approach is completely wrong....</p>
| [
{
"answer_id": 1034123,
"author": "Tomáš Kafka",
"author_id": 38729,
"author_profile": "https://Stackoverflow.com/users/38729",
"pm_score": 0,
"selected": false,
"text": "<Window x:Class=\"TkMVVMContainersSample.Services.TaskEditDialog.ItemEditView\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n xmlns:Common=\"clr-namespace:TkMVVMContainersSample.Views.Common\"\n Title=\"ItemEditView\"\n >\n <Common:DialogControl>\n <Common:DialogControl.Heading>\n <!-- Heading string goes here -->\n </Common:DialogControl.Heading>\n <Common:DialogControl.Control>\n <!-- Concrete dialog's content goes here -->\n </Common:DialogControl.Control>\n <Common:DialogControl.Buttons>\n <!-- Concrete dialog's buttons go here -->\n </Common:DialogControl.Buttons>\n </Common:DialogControl>\n\n</Window>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364001",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42620/"
] |
364,007 | <p>I'm learning WPF, and seem to have found something a little odd, which I can't find the reason to anywhere I've searched.</p>
<p>I have a window with one checkbox on it called "chkTest". I have it set to be true by default.</p>
<p>The following code is what I don't understand. Basically I'm trying to set the "chkTest" control to a control I create on the fly. The message box displays the value I set in code, but the control on the window is still set to be true.</p>
<p>Can someone explain the process behind this?</p>
<pre><code>public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
CheckBox chk = new CheckBox();
chk.IsChecked = false;
this.chkTest = chk;
MessageBox.Show(chk.IsChecked.Value.ToString());
}
}
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 1034123,
"author": "Tomáš Kafka",
"author_id": 38729,
"author_profile": "https://Stackoverflow.com/users/38729",
"pm_score": 0,
"selected": false,
"text": "<Window x:Class=\"TkMVVMContainersSample.Services.TaskEditDialog.ItemEditView\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n xmlns:Common=\"clr-namespace:TkMVVMContainersSample.Views.Common\"\n Title=\"ItemEditView\"\n >\n <Common:DialogControl>\n <Common:DialogControl.Heading>\n <!-- Heading string goes here -->\n </Common:DialogControl.Heading>\n <Common:DialogControl.Control>\n <!-- Concrete dialog's content goes here -->\n </Common:DialogControl.Control>\n <Common:DialogControl.Buttons>\n <!-- Concrete dialog's buttons go here -->\n </Common:DialogControl.Buttons>\n </Common:DialogControl>\n\n</Window>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,009 | <pre><code>Regex.IsMatch( "foo", "[\U00010000-\U0010FFFF]" )
</code></pre>
<p>Throws: System.ArgumentException: parsing "[-]" - [x-y] range in reverse order.</p>
<p>Looking at the hex values for \U00010000 and \U0010FFF I get: 0xd800 0xdc00 for the first character and 0xdbff 0xdfff for the second.</p>
<p>So I guess I have really have one problem. Why are the Unicode characters formed with \U split into two chars in the string?</p>
| [
{
"answer_id": 14326180,
"author": "Andriy K",
"author_id": 307584,
"author_profile": "https://Stackoverflow.com/users/307584",
"pm_score": 3,
"selected": false,
"text": "\"[\\U010000-\\U10FFFF]\" [\\uD800-\\uDBFF][\\uDC00-\\uDFFF] [\\U011DEF-\\U013E07] (?:\\uD807[\\uDDEF-\\uDFFF])|(?:[\\uD808-\\uD80E][\\uDC00-\\uDFFF])|(?:\\uD80F[\\uDC00-uDE07])"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1455/"
] |
364,014 | <p>I wonder if there is a way to use ungreedy matching in JavaScript? I tried the U modifer, but it doesn't seem to work.</p>
<p>I want to write a small BBCode parser in JavaScript, but without ungreedy matching it isn't possible (at least as far as I see it) to do something like this:</p>
<pre><code>'[b]one[/b] two [b]three[/b]'.replace( /\[b\](.*)\[\/b\]/, '<b>$1</b>' );
</code></pre>
<p>But such a replacement would be nice since there is no need to check for HTML validity then. Unclosed markups will stay simple text.</p>
| [
{
"answer_id": 364029,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 7,
"selected": true,
"text": "? * + (.*?)"
},
{
"answer_id": 364051,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": 2,
"selected": false,
"text": "'[b]one[/b] two [b]three[/b]'.replace( /\\[b\\](.+?)\\[\\/b\\]/g, '<b>$1</b>' );\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35903/"
] |
364,017 | <p>I have a file of about 30000 lines of data that I want to load into a sqlite3 database. Is there a faster way than generating insert statements for each line of data?</p>
<p>The data is space-delimited and maps directly to an sqlite3 table. Is there any sort of bulk insert method for adding volume data to a database?</p>
<p>Has anyone devised some deviously wonderful way of doing this if it's not built in?</p>
<p>I should preface this by asking, is there a C++ way to do it from the API?</p>
| [
{
"answer_id": 364156,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "PRAGMA synchronous = OFF;"
},
{
"answer_id": 364557,
"author": "oz10",
"author_id": 14069,
"author_profile": "https://Stackoverflow.com/users/14069",
"pm_score": 4,
"selected": false,
"text": "PRAGMA cache_size cache_size PRAGMA synchronous = OFF;"
},
{
"answer_id": 370184,
"author": "pestophagous",
"author_id": 10278,
"author_profile": "https://Stackoverflow.com/users/10278",
"pm_score": 2,
"selected": false,
"text": "sqlite3_open"
},
{
"answer_id": 759866,
"author": "ramanujan",
"author_id": 72994,
"author_profile": "https://Stackoverflow.com/users/72994",
"pm_score": 5,
"selected": false,
"text": ".import $ cat demotab.txt\n44 92\n35 94\n43 94\n195 49\n66 28\n135 93\n135 91\n67 84\n135 94\n\n$ echo \"create table mytable (col1 int, col2 int);\" | sqlite3 foo.sqlite\n$ echo \".import demotab.txt mytable\" | sqlite3 foo.sqlite\n\n$ sqlite3 foo.sqlite\n-- Loading resources from /Users/ramanujan/.sqliterc\nSQLite version 3.6.6.2\nEnter \".help\" for instructions\nEnter SQL statements terminated with a \";\"\nsqlite> select * from mytable;\ncol1 col2\n44 92\n35 94\n43 94\n195 49\n66 28\n135 93\n135 91\n67 84\n135 94\n echo sqlite3 COPY FROM LOAD DATA LOCAL INFILE .separator sqlite> .show .separator\n echo: off\n explain: off\n headers: on\n mode: list\nnullvalue: \"\"\n output: stdout\nseparator: \"\\t\"\n width:\n .import"
},
{
"answer_id": 3059968,
"author": "Hannes de Jager",
"author_id": 45390,
"author_profile": "https://Stackoverflow.com/users/45390",
"pm_score": 4,
"selected": false,
"text": "create virtual table vtYourDataset using yourModule;\n-- Bulk insert\ninsert into yourTargetTable (x, y, z)\nselect x, y, z from vtYourDataset;\n"
},
{
"answer_id": 7346176,
"author": "Flavien Volken",
"author_id": 532695,
"author_profile": "https://Stackoverflow.com/users/532695",
"pm_score": 3,
"selected": false,
"text": "BEGIN;\nINSERT INTO table VALUES ();\nINSERT INTO table VALUES ();\n...\nEND;\n"
},
{
"answer_id": 33775913,
"author": "maazza",
"author_id": 1342402,
"author_profile": "https://Stackoverflow.com/users/1342402",
"pm_score": 2,
"selected": false,
"text": ".echo ON\n\n.read create_table_without_pk.sql\n\nPRAGMA cache_size = 400000; PRAGMA synchronous = OFF; PRAGMA journal_mode = OFF; PRAGMA locking_mode = EXCLUSIVE; PRAGMA count_changes = OFF; PRAGMA temp_store = MEMORY; PRAGMA auto_vacuum = NONE;\n\n.separator \"\\t\" .import a_tab_seprated_table.txt mytable\n\nBEGIN; .read add_indexes.sql COMMIT;\n\n.exit\n"
},
{
"answer_id": 58547438,
"author": "astef",
"author_id": 1943849,
"author_profile": "https://Stackoverflow.com/users/1943849",
"pm_score": 5,
"selected": false,
"text": "synchronous = OFF journal_mode = WAL journal_mode = OFF locking_mode = EXCLUSIVE synchronous = OFF locking_mode = EXCLUSIVE journal_mode = OFF journal_mode=WAL"
},
{
"answer_id": 63550699,
"author": "Michael Uhlenberg",
"author_id": 4657914,
"author_profile": "https://Stackoverflow.com/users/4657914",
"pm_score": 0,
"selected": false,
"text": "colnames = ['col1', 'col2', 'col3'] \nnrcols = len(colnames) \nqmarks = \",\".join([\"?\" for i in range(nrcols)]) \nstmt = \"INSERT INTO tablename VALUES(\" + qmarks + \")\" \nvals = [[val11, val12, val13], [val21, val22, val23], ..., [valn1, valn2, valn3]] \nconn.executemany(stmt, vals)\n\ncolnames must be in the order of the column names in the table \nvals is a list of db rows\neach row must have the same length, and\ncontain the values in the correct order \nNote that we use executemany, not execute\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9450/"
] |
364,019 | <p>I'd like to have revision number of source code to Delphi's source code and exe version. What is the best way to do this automatically?</p>
<p>I'd like to display the revision number in "About" screen and in the version info of the project.</p>
<p>I'm using currently Delphi IDE (2006/2007) and Tortoise SVN.</p>
| [
{
"answer_id": 364046,
"author": "ieure",
"author_id": 45224,
"author_profile": "https://Stackoverflow.com/users/45224",
"pm_score": 1,
"selected": false,
"text": "$Revision$ version"
},
{
"answer_id": 364195,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 3,
"selected": false,
"text": "svn info initialization"
},
{
"answer_id": 364355,
"author": "mghie",
"author_id": 30568,
"author_profile": "https://Stackoverflow.com/users/30568",
"pm_score": 4,
"selected": true,
"text": "@echo off\n\nsetlocal\nrem determine project top level directory from command file name\nset PRJDIR=%~dp0\ncd %PRJDIR%\n\nset SVNREVFILE=src\\SvnRev.inc\n\nrem execute \"svn info\", extract \"Revision: 1234\" line, and take SVN rev from there\nsvn update\nfor /F \" usebackq tokens=1,2 delims=: \" %%i in (`svn info`) do set key=%%i&set value=%%j&call :read-svn-rev\n@echo SVN revision \"%SVNREV%\"\n\nrem extract \"const SVN_REVISION = 1234;\" line, and take header SVN rev from there\nfor /F \" usebackq tokens=2,4 \" %%i in (%SVNREVFILE%) do set name=%%i&set value=%%j&call :read-file-rev\n@echo Include file revision \"%FILEREV%\"\n\nrem check for valid SVN rev\nif \"%SVNREV%\" EQU \"\" goto :no-svn-ref\nrem do not write file if SVN ref is equal\nif \"%FILEREV%\" EQU \"%SVNREV%\" goto :EOF\n\n@echo Writing svn revision %SVNREV% to %SVNREVFILE%\n@echo const SVN_REVISION = %SVNREV% ; > %SVNREVFILE%\ngoto :EOF\n\n:no-svn-ref\nif not exist %SVNREVFILE% goto :no-header-file\nrem do not write file if SVN ref is already unset\nif \"%FILEREV%\" EQU \"0\" goto :EOF\n@echo Writing svn revision 0 to %SVNREVFILE%\ngoto :write-no-version\n\n:no-header-file\n@echo Creating %SVNREVFILE% with svn revision 0\n:write-no-version\n@echo const SVN_REVISION = 0 ; > %SVNREVFILE%\ngoto :EOF\n\nendlocal\ngoto :EOF\n\n:read-svn-rev\nif \"%key%\" EQU \"Revision\" set SVNREV=%value%&\ngoto :EOF\n\n:read-file-rev\nif \"%name%\" EQU \"SVN_REVISION\" set FILEREV=%value%&\ngoto :EOF\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7735/"
] |
364,055 | <p>Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why?</p>
<pre><code>[TestFixture]
public class AttributeValueModelTest
{
public class HasDate
{
public DateTime? DateValue
{
get
{
DateTime value;
return DateTime.TryParse(ObjectValue.ToString(), out value) ? value : new DateTime?();
}
}
public object ObjectValue { get; set; }
}
[Test]
public void TwoDates()
{
DateTime actual = DateTime.Now;
var date = new HasDate {ObjectValue = actual};
Assert.IsTrue(date.DateValue.Value.Equals(actual));
}
}
</code></pre>
| [
{
"answer_id": 364075,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 0,
"selected": false,
"text": "\npublic DateTime? DateValue\n {\n get\n {\n DateTime value;\n bool isDate = DateTime.TryParse(ObjectValue.ToString(), out value); \n return isDate ? new DateTime?(value) : new DateTime?();\n }\n }\n"
},
{
"answer_id": 364092,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 5,
"selected": true,
"text": "Console.WriteLine(date.DateValue.Value.Ticks);\nConsole.WriteLine(actual.Ticks);\n 633646934930000000\n633646934936763185\n"
},
{
"answer_id": 364166,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": "\"yyyy-MM-dd HH:mm:ss.ffffff\""
},
{
"answer_id": 364394,
"author": "Don Kirkby",
"author_id": 4794,
"author_profile": "https://Stackoverflow.com/users/4794",
"pm_score": 1,
"selected": false,
"text": "String.Format(\"{0:yyyy-MM-dd HH:mm:ss.ffffff}\", ObjectValue);\n public DateTime? DateValue\n {\n get\n {\n DateTime value = ObjectValue as DateTime;\n if (value != null) return value;\n return DateTime.TryParse(ObjectValue.ToString(), out value) ? value : new DateTime?();\n }\n }\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/470/"
] |
364,066 | <p>When Internet Explorers AutoComplete is turned on for Forms the entries for each field in the HTML form should be cached and displayed as a prompt when the user starts entering content into the form the second time around. </p>
<p>On my website the AutoComplete feature is never displayed for any forms that exist on that site. But yet other websites retain and deliver that content without problem.</p>
<p>My site is using PHP as the scripting language and all content is delivered over SSL.</p>
| [
{
"answer_id": 364076,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": 1,
"selected": false,
"text": "autocomplete=\"off\""
},
{
"answer_id": 364094,
"author": "dgavey",
"author_id": 10350,
"author_profile": "https://Stackoverflow.com/users/10350",
"pm_score": 3,
"selected": false,
"text": "session_cache_limiter ('private, must-revalidate');\n"
},
{
"answer_id": 364186,
"author": "scunliffe",
"author_id": 6144,
"author_profile": "https://Stackoverflow.com/users/6144",
"pm_score": 2,
"selected": false,
"text": "YOU HAVE TO SUBMIT YOUR FORMS WITH A SUBMIT BUTTON\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10350/"
] |
364,073 | <p>I have a table "A" with 2 columns "Foo" and "Bar". I have a formula with the structured reference A[Foo]. When I fill this formula horizontally I want the reference to stay A[Foo] but now, in the second column, the reference turns to A[Bar]. Is there a way to make this structured reference absolute? </p>
<p>It'd be shocking that this isn't supported if not.</p>
<p>Example Formula:</p>
<p>=A[Foo]</p>
<p>Drag that horizontally and Foo changes if the table has multiple columns</p>
| [
{
"answer_id": 8650635,
"author": "tekNorah",
"author_id": 1118446,
"author_profile": "https://Stackoverflow.com/users/1118446",
"pm_score": 1,
"selected": false,
"text": " A B C D\n1 Item Base Price 5% 10%\n\n\n2 Pencil $0.50 =[Base Price]-([Base Price]* =[5%]-([5%]*\n DiscountPricing[[#Headers],[5%]]) *DiscountPricing[[#Headers],[10%]])\n\n3 Pen $1 =$B3-($B3* =$B3-($B3*\n *DiscountPricing[[#Headers],[5%]]) *DiscountPricing[[#Headers],[10%]])\n"
},
{
"answer_id": 8985917,
"author": "SimonH",
"author_id": 1166846,
"author_profile": "https://Stackoverflow.com/users/1166846",
"pm_score": 2,
"selected": false,
"text": "drag"
},
{
"answer_id": 28637426,
"author": "Abraham Kuriakose",
"author_id": 4589548,
"author_profile": "https://Stackoverflow.com/users/4589548",
"pm_score": 1,
"selected": false,
"text": "INDIRECT(\"Table Name[Column Heading]\")\n INDIRECT(\"A[Foo]\")"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1946/"
] |
364,083 | <p>What would be the bast way to change the orientation of the WPF treeview. I would like to work the expand-collapse-functionality to work left to right instead of top to down. I.e. when I click on on the expand button of a treenode I would its subnode to appear right of the parent and the indent should work top-down instead. Also the vertical lines that connect the node must now be horizontal.</p>
| [
{
"answer_id": 42860839,
"author": "Matt Thomas",
"author_id": 3063273,
"author_profile": "https://Stackoverflow.com/users/3063273",
"pm_score": 2,
"selected": false,
"text": "ItemsPanel TreeViewItem StackPanel ItemContainerStyle HierarchicalDataTemplate <ItemsPanelTemplate\n x:Key=\"ItemsPanelForHorizontalItems\">\n <StackPanel\n Orientation=\"Horizontal\"/>\n</ItemsPanelTemplate>\n\n<HierarchicalDataTemplate\n x:Key=\"DataTemplateForLayerAboveHorizontalItems\"\n DataType=\"{x:Type viewModel:ThingHavingHorizontalItems}\"\n ItemsSource=\"{Binding HorizontalItems}\"\n ItemTemplate=\"{StaticResource DataTemplateForLayerWithHorizontalItems}\">\n <HierarchicalDataTemplate.ItemContainerStyle>\n <Style\n TargetType=\"TreeViewItem\">\n <Setter\n Property=\"ItemsPanel\"\n Value=\"{StaticResource ItemsPanelForHorizontalItems}\"/>\n </Style>\n </HierarchicalDataTemplate.ItemContainerStyle>\n <ContentControl\n Content=\"{Binding}\"\n ContentTemplate=\"{StaticResource DataTemplateForThingHavingHorizontalItems}\"/>\n</HierarchicalDataTemplate>\n ItemsPanel TreeView StackPanel"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364083",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4227/"
] |
364,096 | <p>I’m attempting to check the rights on a particular file for a specific
trustee and am using the win32 API GetEffectiveRightsFromAcl(). When
the file is accessible by a domain group, the function
returns 5 (Access Denied) when a local account (admin or other) is
used to execute the function.</p>
<p>These three statements summarize the behavior I am seeing with
GetEffectiveRightsFromAcl():</p>
<ul>
<li>When domain group has rights to the file and the program runs under a
local account: Access Denied.</li>
<li>When domain group has rights to the file and the program runs
under a domain account or Local System: Success</li>
<li>When domain group doesn't have rights to the file and the
program runs under any account: Success</li>
</ul>
<p>Does anyone know the reason behind this? It looks to me like this is
related to Active Directory security. What settings could affect this
and what would be a good way to debug this? </p>
<p>Also, I've heard that GetEffectiveRightsFromAcl() may be generally problematic and to use AccessCheck() instead. However I need to be able to take an arbitrary SID and check it's access against a file and since AccessCheck() requires an impersonation token I don't know how I could greate a token out of an arbitrary SID... Any ideas? Thanks</p>
<p>Bob</p>
| [
{
"answer_id": 688912,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Runtime.InteropServices;\nusing System.Security.Principal;\nusing System.Security.AccessControl;\n\nnamespace DACL\n{\n class Class1\n {\n private enum MULTIPLE_TRUSTEE_OPERATION\n {\n NO_MULTIPLE_TRUSTEE,\n TRUSTEE_IS_IMPERSONATE\n }\n\n private enum TRUSTEE_FORM\n {\n TRUSTEE_IS_SID,\n TRUSTEE_IS_NAME,\n TRUSTEE_BAD_FORM,\n TRUSTEE_IS_OBJECTS_AND_SID,\n TRUSTEE_IS_OBJECTS_AND_NAME\n }\n\n private enum TRUSTEE_TYPE\n {\n TRUSTEE_IS_UNKNOWN,\n TRUSTEE_IS_USER,\n TRUSTEE_IS_GROUP,\n TRUSTEE_IS_DOMAIN,\n TRUSTEE_IS_ALIAS,\n TRUSTEE_IS_WELL_KNOWN_GROUP,\n TRUSTEE_IS_DELETED,\n TRUSTEE_IS_INVALID,\n TRUSTEE_IS_COMPUTER\n }\n\n private struct TRUSTEE\n {\n public IntPtr pMultipleTrustee;\n public MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;\n public TRUSTEE_FORM TrusteeForm;\n public TRUSTEE_TYPE TrusteeType;\n public IntPtr ptstrName;\n }\n\n [DllImport(\"advapi32.dll\", SetLastError = true)]\n private static extern void BuildTrusteeWithSid(\n ref TRUSTEE pTrustee,\n byte[] sid\n );\n\n [DllImport(\"advapi32.dll\")]\n private static extern uint GetEffectiveRightsFromAcl(byte[] pacl, ref TRUSTEE pTrustee, ref uint pAccessRights);\n\n public bool HasAccess(SecurityIdentifier sid)\n {\n DiscretionaryAcl dacl = <DACL from somewhere>;\n\n byte[] daclBuffer = new byte[dacl.BinaryLength];\n dacl.GetBinaryForm(daclBuffer, 0);\n\n byte[] sidBuffer = new byte[sid.BinaryLength];\n sid.GetBinaryForm(sidBuffer, 0);\n\n TRUSTEE t = new TRUSTEE();\n BuildTrusteeWithSid(ref t, sidBuffer);\n\n uint access = 0;\n uint hr = GetEffectiveRightsFromAcl(daclBuffer, ref t, ref access);\n\n int i = Marshal.Release(t.ptstrName);\n\n return ((access & <Desired Access>) == <Desired Access>) ? true : false;\n }\n }\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,105 | <p>I'm trying to use grep with -v for invert-match along with -e for regular expression. I'm having trouble getting the syntax right. </p>
<p>I'm trying something like</p>
<pre><code>tail -f logFile | grep -ve "string one|string two"
</code></pre>
<p>If I do it this way it doesn't filter
If I change it to</p>
<pre><code>tail -f logFile | grep -ev "string one|string two"
</code></pre>
<p>I get </p>
<pre><code>grep: string one|string two: No such file or directory
</code></pre>
<p>I have tried using () or quotes, but haven't been able to find anything that works.</p>
<p>How can I do this?</p>
| [
{
"answer_id": 364113,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 8,
"selected": true,
"text": "tail -f logFile | grep -vE 'string one|string two'\n tail -f logFile | egrep -v 'string one|string two'\n"
},
{
"answer_id": 364115,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 3,
"selected": false,
"text": "tail -f logFile | grep -ve \"string one\\|string two\"\n tail -f logFile | grep -vE \"string one|string two\"\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16584/"
] |
364,114 | <p>Maven 2 is driving me crazy during the experimentation / quick and dirty mock-up phase of development.</p>
<p>I have a <code>pom.xml</code> file that defines the dependencies for the web-app framework I want to use, and I can quickly generate starter projects from that file. However, sometimes I want to link to a 3rd party library that doesn't already have a <code>pom.xml</code> file defined, so rather than create the <code>pom.xml</code> file for the 3rd party lib by hand and install it, and add the dependency to my <code>pom.xml</code>, I would just like to tell Maven: "In addition to my defined dependencies, include any jars that are in <code>/lib</code> too."</p>
<p>It seems like this ought to be simple, but if it is, I am missing something.</p>
<p>Any pointers on how to do this are greatly appreciated. Short of that, if there is a simple way to point maven to a <code>/lib</code> directory and easily create a <code>pom.xml</code> with all the enclosed jars mapped to a single dependency which I could then name / install and link to in one fell swoop would also suffice.</p>
| [
{
"answer_id": 364188,
"author": "Pyrolistical",
"author_id": 21838,
"author_profile": "https://Stackoverflow.com/users/21838",
"pm_score": 9,
"selected": false,
"text": "<dependency>\n <groupId>org.swinglabs</groupId>\n <artifactId>swingx</artifactId>\n <version>0.9.2</version>\n <scope>system</scope>\n <systemPath>${project.basedir}/lib/swingx-0.9.3.jar</systemPath>\n</dependency>\n"
},
{
"answer_id": 4958434,
"author": "Praneel PIDIKITI",
"author_id": 410693,
"author_profile": "https://Stackoverflow.com/users/410693",
"pm_score": 4,
"selected": false,
"text": " <dependency>\n <groupId>org.example</groupId>\n <artifactId>iamajar</artifactId>\n <version>1.0</version>\n <scope>system</scope>\n <systemPath>${project.basedir}/lib/iamajar.jar</systemPath>\n </dependency>\n"
},
{
"answer_id": 5741365,
"author": "Alex Lehmann",
"author_id": 27069,
"author_profile": "https://Stackoverflow.com/users/27069",
"pm_score": 2,
"selected": false,
"text": "#! /usr/bin/perl\n\nforeach my $n (@ARGV) {\n\n $n=~s@.*/@@;\n\n print \"<dependency>\n <groupId>local.dummy</groupId>\n <artifactId>$n</artifactId>\n <version>0.0.1</version>\n <scope>system</scope>\n <systemPath>\\${project.basedir}/lib/$n</systemPath>\n</dependency>\n\";\n"
},
{
"answer_id": 6592740,
"author": "Martín Schonaker",
"author_id": 368544,
"author_profile": "https://Stackoverflow.com/users/368544",
"pm_score": 2,
"selected": false,
"text": "systemPath"
},
{
"answer_id": 7623805,
"author": "Nikita Volkov",
"author_id": 485115,
"author_profile": "https://Stackoverflow.com/users/485115",
"pm_score": 9,
"selected": false,
"text": "pom pom <repository>\n <id>repo</id>\n <releases>\n <enabled>true</enabled>\n <checksumPolicy>ignore</checksumPolicy>\n </releases>\n <snapshots>\n <enabled>false</enabled>\n </snapshots>\n <url>file://${project.basedir}/repo</url>\n</repository>\n x.y.z repo/\n| - x/\n| | - y/\n| | | - z/\n| | | | - ${artifactId}/\n| | | | | - ${version}/\n| | | | | | - ${artifactId}-${version}.jar\n repo mvn install:install-file -DlocalRepositoryPath=repo -DcreateChecksum=true -Dpackaging=jar -Dfile=[your-jar] -DgroupId=[...] -DartifactId=[...] -Dversion=[...]\n pom <repository>\n <id>repo</id>\n <url>file://${project.basedir}/repo</url>\n</repository>\n lib pom"
},
{
"answer_id": 7748177,
"author": "Archimedes Trajano",
"author_id": 242042,
"author_profile": "https://Stackoverflow.com/users/242042",
"pm_score": 4,
"selected": false,
"text": "repo src/repo <dependency>\n <groupId>com.dovetail</groupId>\n <artifactId>zoslog4j</artifactId>\n <version>1.0.1</version>\n <scope>runtime</scope>\n</dependency>\n repo/com/dovetail/zoslog4j/1.0.1 <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n <groupId>com.dovetail</groupId>\n <artifactId>zoslog4j</artifactId>\n <packaging>jar</packaging>\n <version>1.0.1</version>\n <name>z/OS Log4J Appenders</name>\n <url>http://dovetail.com/downloads/misc/index.html</url>\n <description>Apache Log4j Appender for z/OS Logstreams, files, etc.</description>\n</project>\n shasum -b < repo/com/dovetail/zoslog4j/1.0.1/zoslog4j-1.0.1.jar \\\n > repo/com/dovetail/zoslog4j/1.0.1/zoslog4j-1.0.1.jar.sha1\n\nshasum -b < repo/com/dovetail/zoslog4j/1.0.1/zoslog4j-1.0.1.pom \\\n > repo/com/dovetail/zoslog4j/1.0.1/zoslog4j-1.0.1.pom.sha1\n <repositories>\n <repository>\n <id>project</id>\n <url>file:///${basedir}/repo</url>\n </repository>\n</repositories>\n"
},
{
"answer_id": 9533639,
"author": "Łukasz Klich",
"author_id": 628302,
"author_profile": "https://Stackoverflow.com/users/628302",
"pm_score": 0,
"selected": false,
"text": " <mirror>\n <id>nexus</id>\n <mirrorOf>*</mirrorOf>\n <url>http://url_to_our_repository</url>\n </mirror>\n"
},
{
"answer_id": 12746819,
"author": "Dmytro Boichenko",
"author_id": 616290,
"author_profile": "https://Stackoverflow.com/users/616290",
"pm_score": 6,
"selected": false,
"text": "libs libs /groupId/artifactId/version/artifactId-version.jar <repository>\n <id>ProjectRepo</id>\n <name>ProjectRepo</name>\n <url>file://${project.basedir}/libs</url>\n </repository>\n <dependency>\n <groupId>groupId</groupId>\n <artifactId>artifactId</artifactId>\n <version>version</version>\n </dependency>\n"
},
{
"answer_id": 14377305,
"author": "Simeon Angelov",
"author_id": 1101647,
"author_profile": "https://Stackoverflow.com/users/1101647",
"pm_score": 3,
"selected": false,
"text": " <build>\n <plugins>\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-install-plugin</artifactId>\n <version>2.3.1</version>\n <executions>\n <execution>\n <id>image-util-id</id>\n <phase>install</phase>\n <goals>\n <goal>install-file</goal>\n </goals>\n <configuration>\n <file>${basedir}/file-you-want-to-include.jar</file>\n <groupId>${project.groupId}</groupId>\n <artifactId>${project.artifactId}</artifactId>\n <version>${project.version}</version>\n <packaging>jar</packaging>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n</build>\n"
},
{
"answer_id": 16473926,
"author": "Jesse Glick",
"author_id": 12916,
"author_profile": "https://Stackoverflow.com/users/12916",
"pm_score": 3,
"selected": false,
"text": "<scope>system</scope> <url>file://${project.basedir}/repo</url> file"
},
{
"answer_id": 16904771,
"author": "samxiao",
"author_id": 618563,
"author_profile": "https://Stackoverflow.com/users/618563",
"pm_score": 3,
"selected": false,
"text": "repo pom.xml <repositories>\n <!--other repositories if any-->\n <repository>\n <id>project.local</id>\n <name>project</name>\n <url>file:${project.basedir}/repo</url>\n </repository>\n</repositories>\n\n\n<dependency>\n <groupId>com.example</groupId>\n <artifactId>mylib</artifactId>\n <version>1.0</version> \n</dependency>\n"
},
{
"answer_id": 21738885,
"author": "Paul",
"author_id": 2816571,
"author_profile": "https://Stackoverflow.com/users/2816571",
"pm_score": 1,
"selected": false,
"text": "def AddJars(jarList):\n s1 = ''\n for elem in jarList:\n s1+= \"\"\"\n <dependency>\n <groupId>local.dummy</groupId>\n <artifactId>%s</artifactId>\n <version>0.0.1</version>\n <scope>system</scope>\n <systemPath>${project.basedir}/manual_jars/%s</systemPath>\n </dependency>\\n\"\"\"%(elem, elem)\n return s1\n"
},
{
"answer_id": 33349540,
"author": "boumbh",
"author_id": 1722982,
"author_profile": "https://Stackoverflow.com/users/1722982",
"pm_score": 0,
"selected": false,
"text": "lib groupId artifactId #!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nopen(my $fh, '>', 'dependencies.xml') or die \"Could not open file 'dependencies.xml' $!\";\nforeach my $file (glob(\"lib/*.jar\")) {\n print \"$file\\n\";\n my $groupId = \"my.mess\";\n my $artifactId = \"\";\n my $version = \"0.1-SNAPSHOT\";\n if ($file =~ /\\/([^\\/]*?)(-([0-9v\\._]*))?\\.jar$/) {\n $artifactId = $1;\n if (defined($3)) {\n $version = $3;\n }\n `mvn install:install-file -Dfile=$file -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=jar`;\n print $fh \"<dependency>\\n\\t<groupId>$groupId</groupId>\\n\\t<artifactId>$artifactId</artifactId>\\n\\t<version>$version</version>\\n</dependency>\\n\";\n print \" => $groupId:$artifactId:$version\\n\";\n } else {\n print \"##### BEUH...\\n\";\n }\n}\nclose $fh;\n"
},
{
"answer_id": 35210338,
"author": "realgt",
"author_id": 46459,
"author_profile": "https://Stackoverflow.com/users/46459",
"pm_score": 3,
"selected": false,
"text": " <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <configuration>\n <includes>\n <include>lib/*.jar</include>\n </includes>\n </configuration>\n </plugin>\n"
},
{
"answer_id": 37221449,
"author": "lmiguelmh",
"author_id": 2692914,
"author_profile": "https://Stackoverflow.com/users/2692914",
"pm_score": 2,
"selected": false,
"text": "@ECHO OFF\nFOR %%I IN (*.jar) DO (\necho ^<dependency^>\necho ^<groupId^>local.dummy^</groupId^>\necho ^<artifactId^>%%I^</artifactId^>\necho ^<version^>0.0.1^</version^>\necho ^<scope^>system^</scope^>\necho ^<systemPath^>${project.basedir}/lib/%%I^</systemPath^>\necho ^</dependency^>\n)\n libs.bat > libs.txt libs.txt"
},
{
"answer_id": 39905292,
"author": "atr",
"author_id": 1436698,
"author_profile": "https://Stackoverflow.com/users/1436698",
"pm_score": 2,
"selected": false,
"text": " <dependency> \n <groupId>uk.org.simonsite</groupId>\n <artifactId>log4j-rolling-appender</artifactId>\n <version>20150607-2059</version> \n </dependency>\n"
},
{
"answer_id": 39922969,
"author": "Donovan",
"author_id": 1084306,
"author_profile": "https://Stackoverflow.com/users/1084306",
"pm_score": 2,
"selected": false,
"text": "target/${PROJECT_NAME}-${VERSION}-jar-with-dependencies.jar <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-assembly-plugin</artifactId>\n <version>2.4.1</version>\n <configuration>\n <!-- get all project dependencies -->\n <descriptorRefs>\n <descriptorRef>jar-with-dependencies</descriptorRef>\n </descriptorRefs>\n <!-- MainClass in mainfest make a executable jar -->\n <archive>\n <manifest>\n <mainClass>my.package.mainclass</mainClass>\n </manifest>\n </archive>\n\n </configuration>\n <executions>\n <execution>\n <id>make-assembly</id>\n <!-- bind to the packaging phase -->\n <phase>package</phase> \n <goals>\n <goal>single</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n"
},
{
"answer_id": 59565386,
"author": "Oleksii Kyslytsyn",
"author_id": 1851286,
"author_profile": "https://Stackoverflow.com/users/1851286",
"pm_score": 0,
"selected": false,
"text": "public static void main(String[] args) {\n String filepath = \"/Users/Downloads/lib/\";\n try (Stream<Path> walk = Files.walk(Paths.get(filepath))) {\n\n List<String> result = walk.filter(Files::isRegularFile)\n .map(x -> x.toString()).collect(Collectors.toList());\n\n String indentation = \" \";\n for (String s : result) {\n System.out.println(indentation + indentation + \"<dependency>\");\n System.out.println(indentation + indentation + indentation + \"<groupId>\"\n + s.replace(filepath, \"\").replace(\".jar\", \"\")\n + \"</groupId>\");\n System.out.println(indentation + indentation + indentation + \"<artifactId>\"\n + s.replace(filepath, \"\").replace(\".jar\", \"\")\n + \"</artifactId>\");\n System.out.println(indentation + indentation + indentation + \"<version>\"\n + s.replace(filepath, \"\").replace(\".jar\", \"\")\n + \"</version>\");\n System.out.println(indentation + indentation + indentation + \"<scope>system</scope>\");\n System.out.println(indentation + indentation + indentation + \"<systemPath>\" + s + \"</systemPath>\");\n System.out.println(indentation + indentation + \"</dependency>\");\n }\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,141 | <p>If I have, say, a table of films which amongs other things has a int FilmTypeId field and a table of film types, with the id and a meaningful description along the lines of:</p>
<ul>
<li>1 - horror</li>
<li>2 - comedy</li>
<li>...</li>
</ul>
<p>Whats the best way of using that information in a C# class?</p>
<p>currently I would have them as Constants in a helper class (unsuprisingly air code):</p>
<pre><code>public class FilmHelper
{
public const int HorrorFilmType = 1;
public const int ComedyFilmType = 2;
...
}
</code></pre>
<p>but this doesn't seem that maintainable. But I would like to avoid a database call everytime I came to use the constant or an additional db call everytime I used either the helper or the main entity.</p>
| [
{
"answer_id": 364154,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "public enum FilmType {\n Horror = 1,\n Comedy = 2\n}\n"
},
{
"answer_id": 364158,
"author": "Chris Marisic",
"author_id": 37055,
"author_profile": "https://Stackoverflow.com/users/37055",
"pm_score": 1,
"selected": false,
"text": "public enum ReportStatus\n{\n [Description(\"Reports that are running\")] Running,\n [Description(\"Reports that are pending to run\")] Pending,\n [Description(\"Reports that have errored while running\")] Error,\n [Description(\"Report completed successfully.\")] Finished\n}\n"
},
{
"answer_id": 364222,
"author": "harpo",
"author_id": 4525,
"author_profile": "https://Stackoverflow.com/users/4525",
"pm_score": 2,
"selected": false,
"text": "class FilmType : Dictionary<int, string> {}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39643/"
] |
364,148 | <p>I'm trying to use the Kowalski graph algorithm for resolution theorem
proving. The description of the algorithm at
<a href="http://www.doc.ic.ac.uk/~rak/" rel="nofollow noreferrer">http://www.doc.ic.ac.uk/~rak/</a> is silent on what to do about the large
number of duplicate clauses it generates. I'm wondering if there's a
well-known technique for dealing with them?</p>
<p>In particular, you can't simply suppress the generation of duplicate
clauses, because the links that come with them are relevant.</p>
<p>It seems to me that it's probably necessary to track the set of all
clauses generated thus far, and when a duplicate is generated, add the
new links to the existing instance instead. This probably needs to be
maintained even when a clause is nominally deleted, for when it is
regenerated.</p>
<p>Duplication probably needs to be defined in terms of textual
representation, rather than object equality, because literals of
different clauses are distinct objects even when they are identical.</p>
<p>Can anyone confirm whether I'm on the right track here? Also, the only
significant online reference I could find to this algorithm was the
link above, does anyone know of any others, or any existing code
implementing it?</p>
| [
{
"answer_id": 364154,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "public enum FilmType {\n Horror = 1,\n Comedy = 2\n}\n"
},
{
"answer_id": 364158,
"author": "Chris Marisic",
"author_id": 37055,
"author_profile": "https://Stackoverflow.com/users/37055",
"pm_score": 1,
"selected": false,
"text": "public enum ReportStatus\n{\n [Description(\"Reports that are running\")] Running,\n [Description(\"Reports that are pending to run\")] Pending,\n [Description(\"Reports that have errored while running\")] Error,\n [Description(\"Report completed successfully.\")] Finished\n}\n"
},
{
"answer_id": 364222,
"author": "harpo",
"author_id": 4525,
"author_profile": "https://Stackoverflow.com/users/4525",
"pm_score": 2,
"selected": false,
"text": "class FilmType : Dictionary<int, string> {}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45843/"
] |
364,159 | <p>I have a table with 3 columns. I want to write a formula that, given a structured reference, returns the index of the column. This will help me write VLookup formulas using the structured reference.</p>
<p>So, for example, for the table <code>MyTable</code> with columns <code>A</code>, <code>B</code>, <code>C</code> I'd like to be able to write:</p>
<pre><code>=GetIndex(MyTable[C])
</code></pre>
<p>and have it return 3.</p>
<p>Right now I just make sure the table range starts on the sheet's first column and I write</p>
<pre><code>=Column(MyTable[C])
</code></pre>
<p>but I want something a more robust.</p>
| [
{
"answer_id": 364264,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 0,
"selected": false,
"text": "=COLUMN(MyTable[*]) - COLUMN(MyTable[A]) + 1 * *"
},
{
"answer_id": 364314,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 1,
"selected": false,
"text": "Dim r As Range\nMyLetter =\"AA\"\nSet r = Range(MyLetter & \"1\")\nMyIndex= r.Column\n Function GetRelativeColumn(Letter, RangeName)\nDim r As Range\nDim ColStart, ColRequired, ColTemp\nSet r = Range(RangeName)\n\nColStart = r.Column\nColRequired = Range(Letter & \"1\").Column\nColTemp = ColRequired - ColStart + 1\nIf ColTemp < 1 Or ColTemp > r.Columns.Count Then\n MsgBox \"Ooutside range\"\nElse\n GetRelativeColumn = ColTemp\nEnd If\nEnd Function\n"
},
{
"answer_id": 1534833,
"author": "Robert Mearns",
"author_id": 5050,
"author_profile": "https://Stackoverflow.com/users/5050",
"pm_score": 4,
"selected": true,
"text": "=COLUMN(MyTable[C])-COLUMN(MyTable)+1\n COLUMN(MyTable[C])"
},
{
"answer_id": 7098500,
"author": "Brian Camire",
"author_id": 669883,
"author_profile": "https://Stackoverflow.com/users/669883",
"pm_score": 3,
"selected": false,
"text": "=MATCH(\"C\",MyTable[#Headers],0) =INDEX(MyTable[C],MATCH(2,MyTable[A],0))"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1946/"
] |
364,172 | <p>I decided to use the GC for memory management for my latest Cocoa project, and I discovered something interesting--if I create a brand new Cocoa app project in Xcode, turn GC to supported or required (I tried both), build, and run it it leaks, it shows memory leaks!</p>
<p>Mostly large numbers of tiny leaks of objects of type NSCFData, GeneralBlock, CGEvent, CFDictionary, CGSRegion, etc.</p>
<p>Steps to reproduce:</p>
<ol>
<li>File->new project->Cocoa app</li>
<li>Project->Edit Project settings->GC Required (or supported, either one)</li>
<li>Build->Build</li>
<li>Run->Run with performance tool->Leaks</li>
<li>Wait for leak detection to trigger (I have it set to 10 secs, it defaults to 30)</li>
</ol>
<p>80% of the time or so I get a leak of around 2-20 Kb of various objects of the sort listed above.</p>
<p>Does anybody else have this same behavior?</p>
<hr>
<p>EDIT: I tested the below circumstance by renaming the InputManagers folder (at which point the log messages went away, so they were definitely no longer being loaded) and am still getting the memory leaks. So it doesn't seem likely that had anything to do with it. I'm leaving the text there so Ashley Clark's answer still makes sense. </p>
<p>The only odd circumstance I know if is I'm getting the following message in the console any time I run an app with GC enabled:</p>
<pre><code>2008-12-12 13:03:09.829 MemLeakTest[41819:813] Error loading /Library/InputManagers/Inquisitor/Inquisitor.bundle/Contents/MacOS/Inquisitor: dlopen(/Library/InputManagers/Inquisitor/Inquisitor.bundle/Contents/MacOS/Inquisitor, 265): no suitable image found. Did find:
/Library/InputManagers/Inquisitor/Inquisitor.bundle/Contents/MacOS/Inquisitor: GC capability mismatch
2008-12-12 13:03:09.840 MemLeakTest[41819:813] Error loading /Library/InputManagers/Saft/SaftLoader.bundle/Contents/MacOS/SaftLoader: dlopen(/Library/InputManagers/Saft/SaftLoader.bundle/Contents/MacOS/SaftLoader, 265): no suitable image found. Did find:
/Library/InputManagers/Saft/SaftLoader.bundle/Contents/MacOS/SaftLoader: GC capability mismatch
</code></pre>
<p>which I'm guessing has something to do with those two plug-ins trying to load into every single program that starts, not just Safari (which they're plug-ins for). I'm not sure if that has anything do do with this or not, but it definitely seems like a possibility. I don't have convenient access to a clean instead of OS X 10.5 with Dev tools to test whether or not this same thing happens on a virgin install without SAFT or Inquisitor.</p>
| [
{
"answer_id": 364994,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 4,
"selected": true,
"text": "leaks leaks info gc-references info gc-roots"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512/"
] |
364,178 | <p>I have ANOTHER serialization question, but this time it is in regards to Java's native serialization import when serializing to binary. I have to serialize a random tree that is generated in another java file. I know how serialization and deserialization works, but the example I followed when using binary serialization with java.io.Serializable did not work in the same fashion as when I did it with, say a simple object. Here is my code segment:</p>
<pre><code>import java.io.*;
import java.io.FileInputStream;
public class BinaryS
{
public static void main(String[] args) {
Tree randomTree = RandomTreeBuilder.randomTree(10);
FileOutputStream fOut=null;
ObjectOutputStream oOut=null;
try{
fOut= new FileOutputStream("/Users/Pat/programs/binaryfile.txt");
oOut = new ObjectOutputStream(fOut);
oOut.writeObject(randomTree); //serializing randomTree
System.out.println("An employee is serialized into /Users/Pat/binaryfile.txt");
}catch(IOException e){
e.printStackTrace();
}finally{
try {
oOut.flush();
oOut.close();
fOut.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
});
</code></pre>
<p>I believe the problem is when I use writeObject(randomTree). I get some terminal exceptions when this happens... they are below:</p>
<p>java.io.NotSerializableException: GeneralTree
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
at BinaryS.main(BinaryS.java:24)</p>
<p>edit: I know it says GeneralTree, but at the start of the class it was in I put </p>
<pre><code>print("public class RandomTreeBuilder implements java.io.Serializable");
</code></pre>
<p>then, GeneralTree is found below it</p>
<pre><code>print(" protected static Tree tree;
protected static ArrayList names;
//e6.1
/**
*Builds a random tree. The build method does the work.
*/
//b6.2
public static Tree randomTree(int n) {
// Create a random binary tree with n external nodes
tree = new GeneralTree();
names = NameGenerator.getNames();
build(tree.getRoot(), n); // auxiliary recursive method
return tree;
</code></pre>
<p>");</p>
<p>Update: Hey guys, I figured out my own problem, turns out I am an idiot and didn't realize I had to download an additional .java file, an easy fix now! Thanks for your help!</p>
| [
{
"answer_id": 365195,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 0,
"selected": false,
"text": "print(\"public class RandomTreeBuilder implements java.io.Serializable\");\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36268/"
] |
364,184 | <p>In my Delphi7 this code</p>
<pre><code>var MStr: TMemoryStream;
...
FreeAndNil(MStr);
MStr.Size:=0;
</code></pre>
<p>generates an AV: Access violation at address 0041D6D1 in module 'Project1.exe'. Read of address 00000000.
But somebody insists that it should not raise any exception, no matter what. He also says that his Delphi 5 indeed raises no exceptions. He calls this a “stale pointer bug”.
In other words he says that FreeAndNil cannot be used as debugger to detect a double attempt to free an object or to use a freed object. </p>
<p>Can anybody enlighten me? Should this raise and error (always/randomly) or the program should run over this bug without problems? </p>
<p>Thanks</p>
<hr>
<p>I ask this because I believe I have a "double free object" or "free and re-access" bug in my program. How can I fill the memory allocated to an object with zeros AFTER I freed the object? I want this way to detect where the bug is, by getting and AV.
Initially, I hoped that if I set the object to FreeAndNil, I will ALWAYS get an AV when trying to re-access it. </p>
| [
{
"answer_id": 364231,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 4,
"selected": false,
"text": "FreeAndNil FreeAndNil MStr := TMemoryStream.Create;\nMStr.Free;\nMStr.Size := 0;\n MStr := TMemoryStream.Create;\nOtherStr := MStr;\nFreeAndNil(MStr);\nOtherStr.Size := 0;\n MStr.Size MStr FreeAndNil TComponent.Owner"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,187 | <p>I found an example on registering DLLs, <em><a href="http://blogs.msdn.com/robmen/archive/2004/04/28/122491.aspx" rel="noreferrer">Registering an Assembly for COM Interop in a MSI file with the Windows Installer XML toolset.</a></em>, and WiX complains about the "AssemblyRegisterComInterop" attribute.</p>
<p>I removed that and changed the "Assembly" attribute to win32, and it says I need to specify the AssemblyManifest attribute, but what should I put there?</p>
| [
{
"answer_id": 364210,
"author": "Troy Howard",
"author_id": 19258,
"author_profile": "https://Stackoverflow.com/users/19258",
"pm_score": 6,
"selected": true,
"text": "SelfRegCost=1 heat.exe"
},
{
"answer_id": 364544,
"author": "Rob Mensching",
"author_id": 23852,
"author_profile": "https://Stackoverflow.com/users/23852",
"pm_score": 5,
"selected": false,
"text": "<Component Id=\"Component\" Guid=\"*\">\n <File Source=\"ComServer.dll\">\n <Class Id=\"PUT-CLSID-HERE\" Context=\"InprocServer32\" ThreadingModel=\"apartment\" Description=\"Your server description\">\n <ProgId Id=\"Your.Server.1\" Description=\"Your ProgId description\">\n <ProgId Id=\"Your.Server\" Description=\"Your ProgId description\" />\n </ProgId>\n </Class>\n\n <Class Id=\"PUT-PROXY-CLSID-HERE\" Context=\"InprocServer32\" ThreadingModel=\"both\" Description=\"Your server Proxies, assuming you have them\">\n <Interface Id=\"PUT-INTERFACEID-HERE\" Name=\"IInterface1\" />\n <Interface Id=\"PUT-INTERFACEID-HERE\" Name=\"IInterface2\" />\n <Interface Id=\"PUT-INTERFACEID-HERE\" Name=\"IInterface3\" />\n <Interface Id=\"PUT-INTERFACEID-HERE\" Name=\"IInterface4\" />\n </Class>\n </File>\n</Component>\n"
},
{
"answer_id": 597099,
"author": "Adam Tegen",
"author_id": 4066,
"author_profile": "https://Stackoverflow.com/users/4066",
"pm_score": 4,
"selected": false,
"text": " heat.exe file <filename> -out <output wxs file>\n heat.exe file my.dll -out my.wxs\n <Component> <Component> <File> <File>"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23822/"
] |
364,193 | <p>Erm - what the question said. It's something I keep hearing about, but I've not got round to looking into it yet.</p>
<hr>
<p>(updated) I could look up the definition... but why not (as pointed out by @erikson) get insight into your real experiences and anecdotes. Community Wiki'd incase that helps folks vote up the most insightful answer. Interesting reading so far, thanks!</p>
| [
{
"answer_id": 364234,
"author": "Bob Cross",
"author_id": 5812,
"author_profile": "https://Stackoverflow.com/users/5812",
"pm_score": 5,
"selected": true,
"text": " _\n ( ) \nA --> B --> C\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2362/"
] |
364,194 | <p>We currently have an application that works with Outlook 2003. In order to get the owner of a shared contact folder, we simply call:
Redemption.RDOSessionClass.GetFolderFromID() and then took that folder and got the RDOFolder.Store.Name property.</p>
<p>However, when trying this with a shared contact folder in Outlook 2007, the RDOFolder.Store.Name is null.</p>
<p>Everything still works fine for normal contacts and for contacts in "Additional Mailboxes" that I've added to my account.</p>
<p>The approach mentioned in <a href="http://blogs.msdn.com/mstehle/archive/2006/09/07/744798.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/mstehle/archive/2006/09/07/744798.aspx</a> appears to work, but I would prefer to not release a new version of our application unless I have to.</p>
<p>Basically I want to understand why this is working differently and what I can do, if anything, to fix this from the server end.</p>
| [
{
"answer_id": 364234,
"author": "Bob Cross",
"author_id": 5812,
"author_profile": "https://Stackoverflow.com/users/5812",
"pm_score": 5,
"selected": true,
"text": " _\n ( ) \nA --> B --> C\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32518/"
] |
364,206 | <p>Our company is considering using the <a href="http://msdn.microsoft.com/en-us/vsx2008/products/bb933751.aspx" rel="nofollow noreferrer">Visual Studio Shell</a> for one of our products.</p>
<p>Does anyone have any experience using it? Was it easy to work with? Did it save time? Are there any things that you weren't able to get it to do? Have you shipped anything with it?</p>
| [
{
"answer_id": 54887999,
"author": "SherlockSpreadsheets",
"author_id": 5335644,
"author_profile": "https://Stackoverflow.com/users/5335644",
"pm_score": 0,
"selected": false,
"text": "Visual Studio Community SQL Server Data Tools (14.0.61021.0) Visual Studio Shell 2015"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34502/"
] |
364,209 | <p>I have a function called:</p>
<pre><code>void initializeJSP(string Experiment)
</code></pre>
<p>And in my MyJSP.h file I have:</p>
<pre><code>2: void initializeJSP(string Experiment);
</code></pre>
<p>And when I compile I get this error:</p>
<blockquote>
<p>MyJSP.h:2 error: variable or field initializeJSP declared void</p>
</blockquote>
<p>Where is the problem?</p>
| [
{
"answer_id": 364224,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": true,
"text": "void initializeJSP(unknownType Experiment);\n std::string string <string> std::"
},
{
"answer_id": 7551394,
"author": "Paul Price",
"author_id": 834250,
"author_profile": "https://Stackoverflow.com/users/834250",
"pm_score": 5,
"selected": false,
"text": "std::string string"
},
{
"answer_id": 43958921,
"author": "Daniel Montaña",
"author_id": 8008583,
"author_profile": "https://Stackoverflow.com/users/8008583",
"pm_score": -1,
"selected": false,
"text": "initializeJSP(Experiment);\n"
},
{
"answer_id": 50971822,
"author": "RSSB",
"author_id": 9153443,
"author_profile": "https://Stackoverflow.com/users/9153443",
"pm_score": -1,
"selected": false,
"text": "#include<iostream>\n#include<vector>\n#include<utility>\n#include<map>\nusing namespace std;\nvoid fun(int x);\nmain()\n{\n int q=9;\n void fun(q); //line no 10\n}\nvoid fun(int x)\n{\n if (x==9)\n cout<<\"yes\";\n else\n cout<<\"no\";\n}\n C:\\Users\\ACER\\Documents\\C++ programs\\exp1.cpp|10|error: variable or field 'fun' declared void|\n||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|\n"
},
{
"answer_id": 55658538,
"author": "user11353491",
"author_id": 11353491,
"author_profile": "https://Stackoverflow.com/users/11353491",
"pm_score": -1,
"selected": false,
"text": "void something(int x){\n logic..\n}\n\nint main() {\n\n **void** something();\n\n return 0;\n\n}\n"
},
{
"answer_id": 70337667,
"author": "barpe",
"author_id": 17667099,
"author_profile": "https://Stackoverflow.com/users/17667099",
"pm_score": 0,
"selected": false,
"text": "main.cpp function.cpp #include\"header.h\" //instead of \"function.cpp\"\nint main() \n function.cpp #include\"header.h\"\nvoid ()\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39160/"
] |
364,219 | <p>I have an app that creates a couple of WebView instances and I'd like to have them operate as independently as possible.</p>
<p>At the very least, I don't want them sharing cookies. A quick google search gave me results liking "you can't." I'm hoping someone has a better answer.</p>
| [
{
"answer_id": 365080,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 5,
"selected": true,
"text": "-webView:resource:willSendRequest:redirectResponse:fromDataSource: HTTPShouldHandleCookies -webView:resource:didReceiveResponse:fromDataSource: NSHTTPCookieStorage"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39975/"
] |
364,230 | <p>I have three tables. This query will write down the right answer (x-lines for btv.id_user with appropriate btv.cas and race.id_zavod</p>
<pre><code>SELECT `btv.id_user`, `btv.id_zavod`,`btv.cas`
FROM `btv`
JOIN `btu` ON `btv.id_user` = `btu.id_user`
JOIN `race` ON 'btv.id_zavod' = `race.id_zavod`
WHERE `race.type` = '8' AND `btv.id_user` = '607'
</code></pre>
<p>Result:</p>
<pre><code>| 607 | 512 | 03:15:58 |
| 607 | 730 | 03:01:18 |
| 607 | 164 | 03:07:26 |
| 607 | 767 | 02:58:31 |
| 607 | 1147 | 03:06:47 |
| 607 | 1149 | 03:09:41 |
| 607 | 1178 | 03:24:20 |
</code></pre>
<p>But when I try to aggregate it to one row by the id_user it return correct min btv.cas but wrong join wrong race.id_zavod</p>
<pre><code>SELECT `btv.id_user`, `btv.id_zavod`, MIN( `btv.cas` )
FROM `btv`
JOIN `btu` ON `btv.id_user` = `btu.id_user`
JOIN `race` ON 'btv.id_zavod' = `race.id_zavod`
WHERE `race.type` = '8' AND `btv.id_user` = '607'
GROUP BY `btv.id_user`
</code></pre>
<p>Result:</p>
<pre><code>| 607 | 512 | 02:58:31 |
</code></pre>
| [
{
"answer_id": 364260,
"author": "user12861",
"author_id": 12861,
"author_profile": "https://Stackoverflow.com/users/12861",
"pm_score": 1,
"selected": false,
"text": "SELECT `btv.id_user`, `btv.id_zavod`, MIN( `btv.cas` )\nFROM `btv`\nJOIN `btu` ON `btv.id_user` = `btu.id_user`\nJOIN `race` ON 'btv.id_zavod' = `race.id_zavod`\nWHERE `race.type` = '8' AND `btv.id_user` = '607'\nGROUP BY `btv.id_user`"
},
{
"answer_id": 364267,
"author": "Jason Michael",
"author_id": 40409,
"author_profile": "https://Stackoverflow.com/users/40409",
"pm_score": 0,
"selected": false,
"text": "SELECT `btv.id_user`, `btv.id_zavod`, MIN( `btv.cas` )\nFROM `btv`\nInner JOIN `btu` ON `btv.id_user` = `btu.id_user`\nInner JOIN `race` ON 'btv.id_zavod' = `race.id_zavod`\nWHERE `btv.id_user` = '607'\nGROUP BY `btv.id_user` having `race.type` = '8'\n"
},
{
"answer_id": 364324,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 1,
"selected": true,
"text": "btv.id_user MIN( btv.cas ) btv.id_zavod btv.id_user id_zavod id_user btv.cas id_user btv.id_zavod SELECT b1.id_user, b1.id_zavod, b1.cas\nFROM btv AS b1\n JOIN btu ON (b1.id_user = btu.id_user)\n JOIN race ON (b1.id_zavod = race.id_zavod)\n LEFT OUTER JOIN btv AS b2 ON (b1.id_user = bt2.id_user AND \n (b1.cas > b2.cas OR (b1.cas = b2.cas AND b1.primarykey > b2.primarykey))\nWHERE race.type = '8' AND b1.id_user = '607'\n AND b2.id_user IS NULL;\n btv id_user cas b2.id_user IS NULL"
},
{
"answer_id": 364643,
"author": "Pianosaurus",
"author_id": 44680,
"author_profile": "https://Stackoverflow.com/users/44680",
"pm_score": 0,
"selected": false,
"text": "SELECT `btv.id_user`, `btv.id_zavod`,`btv.cas`\nFROM `btv`\nJOIN `btu` ON `btv.id_user` = `btu.id_user`\nJOIN `race` ON 'btv.id_zavod' = `race.id_zavod`\nWHERE `race.type` = '8' AND `btv.id_user` = '607'\nORDER BY `btv.cas` LIMIT 1"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364230",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45846/"
] |
364,240 | <p>How do YOU reduce compile time, and linking time for VC++ projects (native C++)?</p>
<p>Please specify if each suggestion applies to debug, release, or both.</p>
| [
{
"answer_id": 364257,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": true,
"text": "// Forward declaration stuff\nnamespace plotter { namespace logic { class Plotter; } }\n\n// Real stuff\nnamespace plotter {\n namespace samples {\n class Window {\n logic::Plotter * mPlotter;\n // ...\n };\n }\n}\n"
},
{
"answer_id": 364467,
"author": "Drew Dormann",
"author_id": 16287,
"author_profile": "https://Stackoverflow.com/users/16287",
"pm_score": 3,
"selected": false,
"text": "the_world.h the_world_defs.h the_world_defs.h"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] |
364,253 | <p>How do I Deserialize this XML document:</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<Cars>
<Car>
<StockNumber>1020</StockNumber>
<Make>Nissan</Make>
<Model>Sentra</Model>
</Car>
<Car>
<StockNumber>1010</StockNumber>
<Make>Toyota</Make>
<Model>Corolla</Model>
</Car>
<Car>
<StockNumber>1111</StockNumber>
<Make>Honda</Make>
<Model>Accord</Model>
</Car>
</Cars>
</code></pre>
<p>I have this:</p>
<pre><code>[Serializable()]
public class Car
{
[System.Xml.Serialization.XmlElementAttribute("StockNumber")]
public string StockNumber{ get; set; }
[System.Xml.Serialization.XmlElementAttribute("Make")]
public string Make{ get; set; }
[System.Xml.Serialization.XmlElementAttribute("Model")]
public string Model{ get; set; }
}
</code></pre>
<p>.</p>
<pre><code>[System.Xml.Serialization.XmlRootAttribute("Cars", Namespace = "", IsNullable = false)]
public class Cars
{
[XmlArrayItem(typeof(Car))]
public Car[] Car { get; set; }
}
</code></pre>
<p>.</p>
<pre><code>public class CarSerializer
{
public Cars Deserialize()
{
Cars[] cars = null;
string path = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data/") + "cars.xml";
XmlSerializer serializer = new XmlSerializer(typeof(Cars[]));
StreamReader reader = new StreamReader(path);
reader.ReadToEnd();
cars = (Cars[])serializer.Deserialize(reader);
reader.Close();
return cars;
}
}
</code></pre>
<p>that don't seem to work :-(</p>
| [
{
"answer_id": 364325,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 5,
"selected": false,
"text": "[Serializable()]\n[System.Xml.Serialization.XmlRootAttribute(\"Cars\", Namespace = \"\", IsNullable = false)]\npublic class Cars\n{\n [XmlArrayItem(typeof(Car))]\n public Car[] Car { get; set; }\n}\n [Serializable()]\npublic class Car\n{\n [System.Xml.Serialization.XmlElement()]\n public string StockNumber{ get; set; }\n\n [System.Xml.Serialization.XmlElement()]\n public string Make{ get; set; }\n\n [System.Xml.Serialization.XmlElement()]\n public string Model{ get; set; }\n}\n"
},
{
"answer_id": 364401,
"author": "Kevin Tighe",
"author_id": 39461,
"author_profile": "https://Stackoverflow.com/users/39461",
"pm_score": 10,
"selected": true,
"text": "XmlElementAttribute XmlElement reader.ReadToEnd(); Deserialize() [Serializable()]\npublic class Car\n{\n [System.Xml.Serialization.XmlElement(\"StockNumber\")]\n public string StockNumber { get; set; }\n\n [System.Xml.Serialization.XmlElement(\"Make\")]\n public string Make { get; set; }\n\n [System.Xml.Serialization.XmlElement(\"Model\")]\n public string Model { get; set; }\n}\n\n\n[Serializable()]\n[System.Xml.Serialization.XmlRoot(\"CarCollection\")]\npublic class CarCollection\n{\n [XmlArray(\"Cars\")]\n [XmlArrayItem(\"Car\", typeof(Car))]\n public Car[] Car { get; set; }\n}\n CarCollection cars = null;\nstring path = \"cars.xml\";\n\nXmlSerializer serializer = new XmlSerializer(typeof(CarCollection));\n\nStreamReader reader = new StreamReader(path);\ncars = (CarCollection)serializer.Deserialize(reader);\nreader.Close();\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<CarCollection>\n<Cars>\n <Car>\n <StockNumber>1020</StockNumber>\n <Make>Nissan</Make>\n <Model>Sentra</Model>\n </Car>\n <Car>\n <StockNumber>1010</StockNumber>\n <Make>Toyota</Make>\n <Model>Corolla</Model>\n </Car>\n <Car>\n <StockNumber>1111</StockNumber>\n <Make>Honda</Make>\n <Model>Accord</Model>\n </Car>\n</Cars>\n</CarCollection>\n"
},
{
"answer_id": 364410,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 9,
"selected": false,
"text": "xsd foo.xml xsd foo.xsd /classes XmlSerializer XmlSerializer ser = new XmlSerializer(typeof(Cars));\n Cars cars;\n using (XmlReader reader = XmlReader.Create(path))\n {\n cars = (Cars) ser.Deserialize(reader);\n }\n"
},
{
"answer_id": 387566,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 7,
"selected": false,
"text": "public class Car\n{\n public string StockNumber { get; set; }\n public string Make { get; set; }\n public string Model { get; set; }\n}\n\n[XmlRootAttribute(\"Cars\")]\npublic class CarCollection\n{\n [XmlElement(\"Car\")]\n public Car[] Cars { get; set; }\n}\n using (TextReader reader = new StreamReader(path))\n{\n XmlSerializer serializer = new XmlSerializer(typeof(CarCollection));\n return (CarCollection) serializer.Deserialize(reader);\n}\n"
},
{
"answer_id": 9017882,
"author": "janbak",
"author_id": 1171214,
"author_profile": "https://Stackoverflow.com/users/1171214",
"pm_score": 4,
"selected": false,
"text": "<Root> <-- well, the root\n <Cars> <-- an element (not a root), it being an array\n <Car> <-- an element, it being an array item\n ...\n </Car>\n </Cars>\n</Root>\n"
},
{
"answer_id": 19223202,
"author": "sheetal nainwal",
"author_id": 2568516,
"author_profile": "https://Stackoverflow.com/users/2568516",
"pm_score": 3,
"selected": false,
"text": "List<T> //deserialization\n\nXmlSerializer xmlser = new XmlSerializer(typeof(List<Item>));\nStreamReader srdr = new StreamReader(@\"C:\\serialize.xml\");\nList<Item> p = (List<Item>)xmlser.Deserialize(srdr);\nsrdr.Close();`\n C:\\serialize.xml"
},
{
"answer_id": 19613934,
"author": "Damian Drygiel",
"author_id": 2865050,
"author_profile": "https://Stackoverflow.com/users/2865050",
"pm_score": 8,
"selected": false,
"text": "C:\\path\\to\\xml\\file.xml Start Menu > Programs > Microsoft Visual Studio 2012 > Visual Studio Tools cd /D \"C:\\path\\to\\xml\" xsd file.xml xsd /c file.xsd C:\\path\\to\\xml\\file.cs Edit > Paste special > Paste XML As Classes using System;\nusing System.IO;\nusing System.Web.Script.Serialization; // Add reference: System.Web.Extensions\nusing System.Xml;\nusing System.Xml.Serialization;\n\nnamespace Helpers\n{\n internal static class ParseHelpers\n {\n private static JavaScriptSerializer json;\n private static JavaScriptSerializer JSON { get { return json ?? (json = new JavaScriptSerializer()); } }\n\n public static Stream ToStream(this string @this)\n {\n var stream = new MemoryStream();\n var writer = new StreamWriter(stream);\n writer.Write(@this);\n writer.Flush();\n stream.Position = 0;\n return stream;\n }\n\n\n public static T ParseXML<T>(this string @this) where T : class\n {\n var reader = XmlReader.Create(@this.Trim().ToStream(), new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });\n return new XmlSerializer(typeof(T)).Deserialize(reader) as T;\n }\n\n public static T ParseJSON<T>(this string @this) where T : class\n {\n return JSON.Deserialize<T>(@this.Trim());\n }\n }\n}\n public class JSONRoot\n {\n public catalog catalog { get; set; }\n }\n // ...\n\n string xml = File.ReadAllText(@\"D:\\file.xml\");\n var catalog1 = xml.ParseXML<catalog>();\n\n string json = File.ReadAllText(@\"D:\\file.json\");\n var catalog2 = json.ParseJSON<JSONRoot>();\n"
},
{
"answer_id": 26413513,
"author": "goku_da_master",
"author_id": 151325,
"author_profile": "https://Stackoverflow.com/users/151325",
"pm_score": 1,
"selected": false,
"text": "using System.Xml;\nusing System.Xml.Schema;\n\n[TestMethod]\npublic void GenerateXsdFromXmlTest()\n{\n string folder = @\"C:\\mydir\\mydata\\xmlToCSharp\";\n XmlReader reader = XmlReader.Create(folder + \"\\some_xml.xml\");\n XmlSchemaSet schemaSet = new XmlSchemaSet();\n XmlSchemaInference schema = new XmlSchemaInference();\n\n schemaSet = schema.InferSchema(reader);\n\n\n foreach (XmlSchema s in schemaSet.Schemas())\n {\n XmlWriter xsdFile = new XmlTextWriter(folder + \"\\some_xsd.xsd\", System.Text.Encoding.UTF8);\n s.Write(xsdFile);\n xsdFile.Close();\n }\n}\n\n// now from the visual studio command line type: xsd some_xsd.xsd /classes\n"
},
{
"answer_id": 26966027,
"author": "XU Weijiang",
"author_id": 966979,
"author_profile": "https://Stackoverflow.com/users/966979",
"pm_score": 1,
"selected": false,
"text": "[System.Xml.Serialization.XmlRootAttribute(\"Cars\", Namespace = \"\", IsNullable = false)]\npublic class Cars\n{\n [XmlArrayItem(typeof(Car))]\n public Car[] Car { get; set; }\n}\n [System.Xml.Serialization.XmlRootAttribute(\"Cars\", Namespace = \"\", IsNullable = false)]\npublic class Cars\n{\n [XmlElement(\"Car\")]\n public Car[] Car { get; set; }\n}\n"
},
{
"answer_id": 32857129,
"author": "makdu",
"author_id": 2778651,
"author_profile": "https://Stackoverflow.com/users/2778651",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" ?> \n <TRANSACTION_RESPONSE>\n <TRANSACTION>\n <TRANSACTION_ID>25429</TRANSACTION_ID> \n <MERCHANT_ACC_NO>02700701354375000964</MERCHANT_ACC_NO> \n <TXN_STATUS>F</TXN_STATUS> \n <TXN_SIGNATURE>a16af68d4c3e2280e44bd7c2c23f2af6cb1f0e5a28c266ea741608e72b1a5e4224da5b975909cc43c53b6c0f7f1bbf0820269caa3e350dd1812484edc499b279</TXN_SIGNATURE> \n <TXN_SIGNATURE2>B1684258EA112C8B5BA51F73CDA9864D1BB98E04F5A78B67A3E539BEF96CCF4D16CFF6B9E04818B50E855E0783BB075309D112CA596BDC49F9738C4BF3AA1FB4</TXN_SIGNATURE2> \n <TRAN_DATE>29-09-2015 07:36:59</TRAN_DATE> \n <MERCHANT_TRANID>150929093703RUDZMX4</MERCHANT_TRANID> \n <RESPONSE_CODE>9967</RESPONSE_CODE> \n <RESPONSE_DESC>Bank rejected transaction!</RESPONSE_DESC> \n <CUSTOMER_ID>RUDZMX</CUSTOMER_ID> \n <AUTH_ID /> \n <AUTH_DATE /> \n <CAPTURE_DATE /> \n <SALES_DATE /> \n <VOID_REV_DATE /> \n <REFUND_DATE /> \n <REFUND_AMOUNT>0.00</REFUND_AMOUNT> \n </TRANSACTION>\n </TRANSACTION_RESPONSE> \n [XmlType(\"TRANSACTION_RESPONSE\")]\npublic class TransactionResponse\n{\n [XmlElement(\"TRANSACTION\")]\n public BankQueryResponse Response { get; set; }\n\n}\n public class BankQueryResponse\n{\n [XmlElement(\"TRANSACTION_ID\")]\n public string TransactionId { get; set; }\n\n [XmlElement(\"MERCHANT_ACC_NO\")]\n public string MerchantAccNo { get; set; }\n\n [XmlElement(\"TXN_SIGNATURE\")]\n public string TxnSignature { get; set; }\n\n [XmlElement(\"TRAN_DATE\")]\n public DateTime TranDate { get; set; }\n\n [XmlElement(\"TXN_STATUS\")]\n public string TxnStatus { get; set; }\n\n\n [XmlElement(\"REFUND_DATE\")]\n public DateTime RefundDate { get; set; }\n\n [XmlElement(\"RESPONSE_CODE\")]\n public string ResponseCode { get; set; }\n\n\n [XmlElement(\"RESPONSE_DESC\")]\n public string ResponseDesc { get; set; }\n\n [XmlAttribute(\"MERCHANT_TRANID\")]\n public string MerchantTranId { get; set; }\n\n}\n car as array"
},
{
"answer_id": 37178692,
"author": "Hasan Javaid",
"author_id": 5022474,
"author_profile": "https://Stackoverflow.com/users/5022474",
"pm_score": 3,
"selected": false,
"text": "public class SerializeConfig<T> where T : class\n{\n public static void Serialize(string path, T type)\n {\n var serializer = new XmlSerializer(type.GetType());\n using (var writer = new FileStream(path, FileMode.Create))\n {\n serializer.Serialize(writer, type);\n }\n }\n\n public static T DeSerialize(string path)\n {\n T type;\n var serializer = new XmlSerializer(typeof(T));\n using (var reader = XmlReader.Create(path))\n {\n type = serializer.Deserialize(reader) as T;\n }\n return type;\n }\n}\n"
},
{
"answer_id": 45588918,
"author": "haiduong87",
"author_id": 971481,
"author_profile": "https://Stackoverflow.com/users/971481",
"pm_score": 1,
"selected": false,
"text": "Edit > Past Special > Paste XML As Classes List<class1 XmlSerializer xml deserialize StreamReader sr = new StreamReader(@\"C:\\Users\\duongngh\\Desktop\\Newfolder\\abc.txt\");\nXmlSerializer xml = new XmlSerializer(typeof(Class1[]));\nvar a = xml.Deserialize(sr);\nsr.Close();\n"
},
{
"answer_id": 47604773,
"author": "David C Fuchs",
"author_id": 5719295,
"author_profile": "https://Stackoverflow.com/users/5719295",
"pm_score": 3,
"selected": false,
"text": "//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n// Generic class to load any xml into a class\n// used like this ...\n// YourClassTypeHere InfoList = LoadXMLFileIntoClass<YourClassTypeHere>(xmlFile);\n\nusing System.IO;\nusing System.Xml.Serialization;\n\npublic static T LoadXMLFileIntoClass<T>(string xmlFile)\n{\n T returnThis;\n XmlSerializer serializer = new XmlSerializer(typeof(T));\n if (!FileAndIO.FileExists(xmlFile))\n {\n Console.WriteLine(\"FileDoesNotExistError {0}\", xmlFile);\n }\n returnThis = (T)serializer.Deserialize(new StreamReader(xmlFile));\n return (T)returnThis;\n}\n"
},
{
"answer_id": 48240681,
"author": "Kim Homann",
"author_id": 5773733,
"author_profile": "https://Stackoverflow.com/users/5773733",
"pm_score": 3,
"selected": false,
"text": "[XmlRoot(\"Cars\")]\npublic class XmlData\n{\n [XmlElement(\"Car\")]\n public List<Car> Cars{ get; set; }\n}\n\npublic class Car\n{\n public string StockNumber { get; set; }\n public string Make { get; set; }\n public string Model { get; set; }\n}\n var ser = new XmlSerializer(typeof(XmlData));\nvar data = (XmlData)ser.Deserialize(XmlReader.Create(PathToCarsXml));\n"
},
{
"answer_id": 50464396,
"author": "SlowLearner",
"author_id": 3451115,
"author_profile": "https://Stackoverflow.com/users/3451115",
"pm_score": 3,
"selected": false,
"text": "path using System.Xml.Serialization; // Added\n\npublic class Car\n{\n public string StockNumber { get; set; }\n public string Make { get; set; }\n public string Model { get; set; }\n}\n\n[XmlRootAttribute(\"Cars\")]\npublic class CarCollection\n{\n [XmlElement(\"Car\")]\n public Car[] Cars { get; set; }\n}\n using (TextReader reader = new StreamReader(path))\n{\n XmlSerializer serializer = new XmlSerializer(typeof(CarCollection));\n return (CarCollection) serializer.Deserialize(reader);\n}\n static CarCollection XCar() using System;\nusing System.IO;\nusing System.Xml.Serialization;\n\nnamespace ConsoleApp2\n{\n class Program\n {\n\n public static void Main()\n {\n var c = new CarCollection();\n\n c = XCar();\n\n foreach (var k in c.Cars)\n {\n Console.WriteLine(k.Make + \" \" + k.Model + \" \" + k.StockNumber);\n }\n c = null;\n Console.ReadLine();\n\n }\n static CarCollection XCar()\n {\n using (TextReader reader = new StreamReader(@\"C:\\Users\\SlowLearner\\source\\repos\\ConsoleApp2\\ConsoleApp2\\Class1.xml\"))\n {\n XmlSerializer serializer = new XmlSerializer(typeof(CarCollection));\n return (CarCollection)serializer.Deserialize(reader);\n }\n }\n }\n}\n"
},
{
"answer_id": 58028540,
"author": "Andre M",
"author_id": 12095505,
"author_profile": "https://Stackoverflow.com/users/12095505",
"pm_score": 3,
"selected": false,
"text": "var object = (Cars)new XmlSerializer(typeof(Cars)).Deserialize(new StringReader(xmlString));\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41508/"
] |
364,292 | <p>I have a table for which I want to select top the 5 rows by some column A. I also want to have a 6th row titled 'Other' which sums the values in column A for all but the top 5 rows.</p>
<p>Is there an easy way to do this? I'm starting with:</p>
<pre><code>select top 5
columnB, columnA
from
someTable t
order by
columnA desc
</code></pre>
| [
{
"answer_id": 364310,
"author": "D'Arcy Rittich",
"author_id": 39430,
"author_profile": "https://Stackoverflow.com/users/39430",
"pm_score": 3,
"selected": true,
"text": "select * from (\n select top 5 \n columnB, columnA \n from \n someTable t\n order by\n columnA desc\n union all\n select \n null, sum(columnA) \n from \n someTable t\n where primaryKey not in (\n select top 5 \n primaryKey\n from \n someTable t\n order by\n columnA desc\n ) \n) a\n"
},
{
"answer_id": 364317,
"author": "FallenAvatar",
"author_id": 36965,
"author_profile": "https://Stackoverflow.com/users/36965",
"pm_score": 0,
"selected": false,
"text": "SELECT TOP 5 columnB, columnA\nFROM comTable t\nORDER BY columnA desc\n\nUNION\n\nSELECT 'Other', (A.Sum - B.Sum) AS Summary\nFROM (SELECT SUM(columnA) FROM someTable) A\nJOIN (SELECT SUM(One) FROM \n (SELECT TOP 5 columnA FROM someTable ORDER BY columnA DESC)) B\n"
},
{
"answer_id": 364329,
"author": "Tom",
"author_id": 13219,
"author_profile": "https://Stackoverflow.com/users/13219",
"pm_score": 0,
"selected": false,
"text": "select top 5 \n columnB, columnA \nfrom \n someTable t\norder by\n columnA desc\nUNION ALL\nSELECT 'OTHER' ColumnB, SUM(ColumnA)\nFROM\n(SELECT ColumnB, ColumnA \nFROM someTable t\nEXCEPT\nselect top 5 \n columnB, columnA \nfrom \n someTable t\norder by\n columnA desc\n) others\n"
},
{
"answer_id": 364348,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 1,
"selected": false,
"text": "select top 5 columnB, columnA\nfrom someTable \norder by columnA desc\n\nselect SUM(columnA) as Total\nfrom someTable\n"
},
{
"answer_id": 364457,
"author": "Tom H",
"author_id": 5696608,
"author_profile": "https://Stackoverflow.com/users/5696608",
"pm_score": 1,
"selected": false,
"text": "WITH CTE AS\n (\n SELECT\n ColumnB,\n ColumnA,\n ROW_NUMBER() OVER (ORDER BY ColumnB) AS RowNumber\n FROM\n dbo.SomeTable\n )\n SELECT\n CASE WHEN RowNumber <= 5 THEN ColumnB ELSE 'Other' END AS ColumnB,\n SUM(ColumnA) AS ColumnA\n FROM\n CTE\n GROUP BY\n CASE WHEN RowNumber <= 5 THEN ColumnB ELSE 'Other' END\n ORDER BY\n MIN(RowNumber)\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34942/"
] |
364,301 | <p>I posted this message to the Solr mailing list, but I'm trying here too in case there's a Solr expert lurking around.</p>
<p>I am trying to use the regex fragmenter and am having a hard time getting the results I want. I am trying to get fragments that start on a word character and end on punctuation, but for some reason the fragments being returned to me seem to be very inflexible, despite that I've provided a large slop. Here are the relevant parameters I'm using, maybe someone can help point out where I've gone wrong:</p>
<pre><code><str name="hl.fragsize">500</str>
<str name="hl.fragmenter">regex</str>
<str name="hl.regex.slop">0.8</str>
<str name="hl.regex.pattern">[\w].*{400,600}[.!?]</str>
<str name="hl">true</str>
<str name="q">chinese</str>
</code></pre>
<p>This should be matching between 400-600 characters, beginning with a word character and ending with one of .!?. Here is an example of a typical result:</p>
<blockquote>
<p>. Check these pictures out. Nine panda
cubs on display for the first time
Thursday in southwest China. They're
less than a year old. They just
recently stopped nursing. There are
only 1,600 of these guys left in the
mountain forests of central China,
another 120 in Chinese breeding
facilities and zoos. And they're about
20 that live outside China in zoos.
They exist almost entirely on bamboo.
They can live to be 30 years old. And
these little guys will eventually get
much bigger. They'll grow</p>
</blockquote>
<p>As you can see, it is starting with a period and ending on a word character! It's almost as if the fragments are just coming out as they will and the regex isn't doing anything at all, but the results are different when I use the gap fragmenter. In the above result I don't see any reason why it shouldn't have stripped out the preceding period and the last two words, there is plenty of room in the slop and in the regex pattern. Please help me figure out what I'm doing wrong...</p>
<p>Thanks a lot,</p>
<p>Mark</p>
| [
{
"answer_id": 364342,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": true,
"text": "\\w[^\\.!\\?]{400,600}[\\.!\\?]\n \\w .* {400,600} .{400,600} ? . [^\\.!\\?]"
},
{
"answer_id": 365180,
"author": "Jan Goyvaerts",
"author_id": 33358,
"author_profile": "https://Stackoverflow.com/users/33358",
"pm_score": 1,
"selected": false,
"text": "\\w.{400,600}[.!?]\n \\w.{400,600}?[.!?]\n \\w[^.!?]{400,600}[.!?]\n"
},
{
"answer_id": 6504025,
"author": "raymi",
"author_id": 310731,
"author_profile": "https://Stackoverflow.com/users/310731",
"pm_score": 0,
"selected": false,
"text": "WordDelimiterFilterFactory preserveOriginal=\"1\" WordDelimiterFilterFactory"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45856/"
] |
364,327 | <p>I want to get myself into programming some serious GUI based applications, but when I look at things like Swing/SWT from Java, I can't help but HATE programming a GUI interface by creating "widget" objects and populating them and calling methods on them. </p>
<p>I think GUI design should be done in a separate text-based file in some markup format, which is read and rendered (e.g. HTML), so that the design of the interface is not tightly coupled with the rest of the code.</p>
<p>I've seen <a href="http://www.terrainformatica.com/htmlayout/" rel="nofollow noreferrer">HTMLayout</a> and I love the idea, but so far it seems be only in C++. </p>
<p>I'm looking for a python library (or even a WIP project) for doing markup-based gui.</p>
<p><strong>UPDATE</strong></p>
<p>The reason I can't accept QT's xml is the same reason I hate the programatic approach; you're assembling each widget separately, and specifying each property of it on a separate line. It doesn't provide any advantage over doing it the programatic way.</p>
| [
{
"answer_id": 768777,
"author": "Bryan Oakley",
"author_id": 7432,
"author_profile": "https://Stackoverflow.com/users/7432",
"pm_score": 2,
"selected": false,
"text": "menubar {\n File => {\n Open => cmd.open\n Save => cmd.save\n Exit => cmd.exit\n }\n Edit => {\n Cut => cmd.cut\n Copy => cmd.copy\n Paste => cmd.paste\n }\n}\n form PropertiesForm {\n Font: [fontchooser]\n Foreground: [foregroundChooser]\n Background: [backgroundChooser]\n}\nform NewUserForm {\n username [_____________________]\n [] administrator\n enable the following features:\n () feature 1\n () feature 2\n () feature 3\n}\nnotebook {\n Properties => PropertiesForm\n New User => NewUserForm\n}\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35364/"
] |
364,336 | <p>I am getting a strange error on a remote windows clients (WinForm application using C# 2.0)</p>
<p>Error Message: Access to the path 'c:\ApplicationFolder' is denied.</p>
<p>Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)</p>
<p>Let me say I know I should not put the application folder directly off the c:\ folder. This an old application that I have no control over. </p>
| [
{
"answer_id": 402075,
"author": "Dour High Arch",
"author_id": 22437,
"author_profile": "https://Stackoverflow.com/users/22437",
"pm_score": 0,
"selected": false,
"text": "System.IO.FileStream.Init"
},
{
"answer_id": 10764280,
"author": "techno",
"author_id": 848968,
"author_profile": "https://Stackoverflow.com/users/848968",
"pm_score": 0,
"selected": false,
"text": "Executable: IsUserAdmin.exe \nManifest:IsUserAdmin.exe.manifest\nSample application manifest file:\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"> \n <assemblyIdentity version=\"1.0.0.0\"\n processorArchitecture=\"X86\"\n name=\"IsUserAdmin\"\n type=\"win32\"/> \n <description>Description of your application</description> \n <!-- Identify the application security requirements. -->\n <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">\n <security>\n <requestedPrivileges>\n <requestedExecutionLevel\n level=\"requireAdministrator\"\n uiAccess=\"false\"/>\n </requestedPrivileges>\n </security>\n </trustInfo>\n</assembly>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,347 | <p>One example is described <strong><a href="http://sujitmanolikar.blogspot.com/2007/07/generic-statemanagedcollection.html" rel="nofollow noreferrer">here</a></strong>. But the author apparently forgot to include the code for download.</p>
<p>Another example is shown <strong><a href="http://blog.spontaneouspublicity.com/child-collections-in-asp-net-custom-controls" rel="nofollow noreferrer">here</a></strong>. However, this one doesn't quite work (as described in comments).</p>
<p>How do you do this correctly?</p>
| [
{
"answer_id": 500077,
"author": "Dan Herbert",
"author_id": 392,
"author_profile": "https://Stackoverflow.com/users/392",
"pm_score": 2,
"selected": false,
"text": "AppointmentControl.cs protected override object SaveViewState()\n{\n if (appointments != null)\n return appointments.SaveViewState();\n return null;\n}\n\nprotected override void LoadViewState(object savedState)\n{\n appointments = new AppointmentCollection();\n appointments.LoadViewState(savedState);\n}\n"
},
{
"answer_id": 500106,
"author": "davogones",
"author_id": 59631,
"author_profile": "https://Stackoverflow.com/users/59631",
"pm_score": 3,
"selected": true,
"text": "using System;\nusing System.Collections;\nusing System.Collections.Specialized;\nusing System.Security.Permissions;\nusing System.Web;\nusing System.Collections.Generic;\nusing System.Web.UI;\n\nnamespace Web\n{\n public abstract class StateManagedCollection<T> : StateManagedCollection, IList<T>, ICollection<T>, IEnumerable<T>\n where T : class, IStateManagedItem, new()\n {\n\n protected override object CreateKnownType(int index)\n {\n return Activator.CreateInstance<T>();\n }\n\n protected override Type[] GetKnownTypes()\n {\n return new Type[] { typeof(T) };\n }\n\n protected override void SetDirtyObject(object o)\n {\n ((IStateManagedItem)o).SetDirty();\n }\n\n #region IList<T> Members\n\n public int IndexOf(T item)\n {\n return ((IList)this).IndexOf(item);\n }\n\n public void Insert(int index, T item)\n {\n ((IList)this).Insert(index, item);\n if (((IStateManager)this).IsTrackingViewState)\n {\n this.SetDirty();\n }\n }\n\n public void RemoveAt(int index)\n {\n ((IList)this).RemoveAt(index);\n if (((IStateManager)this).IsTrackingViewState)\n {\n this.SetDirty();\n }\n }\n\n public T this[int index]\n {\n get { return (T)this[index]; }\n set { this[index] = value; }\n }\n\n #endregion\n\n #region ICollection<T> Members\n\n public void Add(T item)\n {\n ((IList)this).Add(item);\n this.SetDirty();\n }\n\n public bool Contains(T item)\n {\n return ((IList)this).Contains(item);\n }\n\n public void CopyTo(T[] array, int arrayIndex)\n {\n ((IList)this).CopyTo(array, arrayIndex);\n }\n\n public bool IsReadOnly\n {\n get { return false; }\n }\n\n public bool Remove(T item)\n {\n if (((IList)this).Contains(item))\n {\n ((IList)this).Remove(item);\n return true;\n }\n return false;\n }\n\n #endregion\n\n\n #region IEnumerable<T> Members\n\n IEnumerator<T> IEnumerable<T>.GetEnumerator()\n {\n throw new NotImplementedException();\n }\n\n #endregion\n\n #region IEnumerable Members\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return ((IList)this).GetEnumerator();\n\n }\n\n #endregion\n }\n}\n"
},
{
"answer_id": 2473600,
"author": "Radoslav Minchev",
"author_id": 1148678,
"author_profile": "https://Stackoverflow.com/users/1148678",
"pm_score": 0,
"selected": false,
"text": " IEnumerator IEnumerable.GetEnumerator()\n {\n return ((IList)this).GetEnumerator();\n\n }\n IEnumerator IEnumerable.GetEnumerator()\n {\n // return ((IList)this).GetEnumerator();\n return this.GetEnumerator();\n\n } \n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/337/"
] |
364,360 | <pre><code>test[_nObjectives].pool[j].feedbackCorrect =
oQuestions[j].getElementsByTagName("feedbackCorrect")[0].firstChild.data;
</code></pre>
<p>and the XML in this case contains this: </p>
<pre><code> <feedbackCorrect>
</feedbackCorrect>
</code></pre>
<p>When executing that line of code the following error occurs: Message: Object required</p>
<p>I don't get it. The tag is there, if it is empty the error occurs and even has spaces chars it doesn't work.</p>
| [
{
"answer_id": 364366,
"author": "FallenAvatar",
"author_id": 36965,
"author_profile": "https://Stackoverflow.com/users/36965",
"pm_score": 1,
"selected": false,
"text": "oQuestions[j].getElementsByTagName(\"feedbackCorrect\")[0]\n oQuestions[j].getElementsByTagName(\"feedbackCorrect\")[0].data\n"
},
{
"answer_id": 364386,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<feedbackCorrect>any value</feedbackCorrect>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,367 | <p>I want to <strong>move about 800gb of data from an NTFS storage device to a FAT32 device</strong> (both are external hard drives), on a Windows System.</p>
<p>What is the best way to achieve this?</p>
<ol>
<li>Simply using cut-paste?</li>
<li>Using the command prompt ? (<code>move</code>)</li>
<li>Writing a batch file to copy a small chunks of data on a given interval ?</li>
<li>Use some specific application that does the job for me?</li>
<li>Or any better idea...?</li>
</ol>
<p>What is the most safe, efficient and fast way to achieve such a time consuming process?</p>
| [
{
"answer_id": 45422837,
"author": "kumar chandraketu",
"author_id": 7008922,
"author_profile": "https://Stackoverflow.com/users/7008922",
"pm_score": 1,
"selected": false,
"text": "powershell \"robocopy 'Source' 'destination' /E /R:3 /W:10 /FP /MT:25 /V\" \n\n/E - Copy subdirectory including empty ones.\n/R - Retry 3 times if failed.\n/W - wait for 10 seconds between retries.\n/FP - include full path name in output.\n/MT - Multi thread.\n/V - verbose output.\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44084/"
] |
364,412 | <p>In a previous life, I might have done something like this:</p>
<pre><code><a href="#" onclick="f(311);return false;">Click</a><br/>
<a href="#" onclick="f(412);return false;">Click</a><br/>
<a href="#" onclick="f(583);return false;">Click</a><br/>
<a href="#" onclick="f(624);return false;">Click</a><br/>
</code></pre>
<p>Now with jQuery, I might do something like this:</p>
<pre><code><a class="clicker" alt="311">Click</a><br/>
<a class="clicker" alt="412">Click</a><br/>
<a class="clicker" alt="583">Click</a><br/>
<a class="clicker" alt="624">Click</a><br/>
<script language="javascript" type="text/javascript">
$(".clicker").bind("click", function(e) {
e.preventDefault();
f($(this).attr("alt"));
});
</script>
</code></pre>
<p>Except that using the alt attribute to pass the data from the DOM to jQuery feels like a hack, since that's not its intended purpose. What's the best practice here for storing/hiding data in the DOM for jQuery to access?</p>
| [
{
"answer_id": 364462,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 3,
"selected": true,
"text": "<a class=\"clicker\">Click</a><br/>\n<a class=\"clicker\">Click</a><br/>\n<a class=\"clicker\">Click</a><br/>\n<a class=\"clicker\">Click</a><br/>\n\n<script language=\"javascript\" type=\"text/javascript\">\n var values = new Array(\"311\", \"412\", \"583\", \"624\");\n $(\".clicker\").each(function(i, e) {\n $(this).data('value', values[i]).click(function(e) { \n f($(this).data('value'));\n });\n });\n</script>\n <a class=\"clicker\" data-value=\"311\">Click</a><br/>\n<a class=\"clicker\" data-value=\"412\">Click</a><br/>\n<a class=\"clicker\" data-value=\"583\">Click</a><br/>\n<a class=\"clicker\" data-value=\"624\">Click</a><br/>\n\n<script language=\"javascript\" type=\"text/javascript\">\n $(\".clicker\").click(function(e) { \n f($(this).data('value'));\n });\n</script>\n"
},
{
"answer_id": 2709594,
"author": "edwin",
"author_id": 211422,
"author_profile": "https://Stackoverflow.com/users/211422",
"pm_score": 2,
"selected": false,
"text": "data-... <a class=\"clicker\" data-mynumber=\"311\">Click</a>\n el.attr('data-mynumber')"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3420/"
] |
364,428 | <p>The project I am working on were are trying to come up with a solution for having the database and code be agile and be able to be built and deployed together.</p>
<p>Since the application is a combination of code plus the database schema, and database code tables, you can not truly have a full build of the application unless you have a database that is versioned along with the code.</p>
<p>We have not yet been able to come up with a good agile method of doing the database development along with the code in an agile/scrum environment.</p>
<p>Here are some of my requirements:</p>
<ol>
<li>I want to be able to have a svn revision # that corresponds to a complete build of the system.</li>
<li>I do not want to check in binary files into source control for the database.</li>
<li>Developers need to be able to commit code to the continuous integration server and build the entire system and database together.</li>
<li>Must be able to automate deployment to different environments without doing a rebuild other than the original build on the build server.</li>
</ol>
<p>(Update)
I'll add some more info here to explain a bit further.</p>
<p>No OR/M tool, since its a legacy project with a huge amount of code.
I have read the agile database design information, and that process in isolation seems to work, but I am talking about combining it with active code development.</p>
<p>Here are two scenario's</p>
<ol>
<li><p>Developer checks in a code change, that requires a database change. The developer should be able to check in a database change at the same time, so that the automated build doesn't fail.</p></li>
<li><p>Developer checks in a DB change, that should break code. The automated build needs to run and fail.</p></li>
</ol>
<p>The biggest problem is, how do these things synch up. There is no such thing as "checking in a database change". Right now the application of the DB changes is a manual process someone has to do, while code change are constantly being made. They need to be made together and checked together, the build system needs to be able to build the entire system.</p>
<p>(Update 2)
One more add here:</p>
<p>You can't bring down production, you must patch it. Its not acceptable to rebuild the entire production database.</p>
| [
{
"answer_id": 364458,
"author": "Tom",
"author_id": 40620,
"author_profile": "https://Stackoverflow.com/users/40620",
"pm_score": 3,
"selected": true,
"text": "db/\ndb/Makefile (run `make` to rebuild db from scratch, `make clean` to close db)\ndb/01_type.sql\ndb/02_table.sql\ndb/03_function.sql\ndb/04_view.sql\ndb/05_index.sql\ndb/06_data.sql\n *.sql"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45365/"
] |
364,440 | <p>I have 2 objects, both from different Model classes, and want to show a form containing some fields from each one. How can I do this?</p>
| [
{
"answer_id": 364527,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": -1,
"selected": false,
"text": "Form __init__ ModelForm class DualForm(forms.Form):\n def __init__(self, *args, **kwargs):\n model1 = Model1Form(**kwargs)\n model2 = Model2Form(**kwargs)\n\n for f in model1.fields:\n self.fields[f] = model1.fields[f]\n\n for f in model2.fields:\n self.fields[f] = model2.fields[f]\n\nclass Model1Form(forms.ModelForm):\n ... your model form...\n\nclass Model2Form(forms.ModelForm):\n ... your other model form...\n ModelForms"
},
{
"answer_id": 365300,
"author": "ayaz",
"author_id": 23191,
"author_profile": "https://Stackoverflow.com/users/23191",
"pm_score": 3,
"selected": false,
"text": "ModelForm fields"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364440",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45870/"
] |
364,448 | <p>Does anyone know how to show a asp:TreeView always expanded to the leaves? So if I have a 2-level tree, I want it to be expanded at all times. Is there a property on TreeView that does this or could you show the code snippet on how to do this?</p>
<p>Thank you very much!
Ray.</p>
| [
{
"answer_id": 364487,
"author": "maxnk",
"author_id": 45862,
"author_profile": "https://Stackoverflow.com/users/45862",
"pm_score": 3,
"selected": true,
"text": "protected void Page_Load(object sender, EventArgs e)\n{\n TreeView1.ExpandAll();\n}\n <asp:TreeView ID=\"TreeView1\" runat=\"server\" ShowExpandCollapse=\"false\">\n</asp:TreeView>\n"
},
{
"answer_id": 2034747,
"author": "C Stahl",
"author_id": 247211,
"author_profile": "https://Stackoverflow.com/users/247211",
"pm_score": 0,
"selected": false,
"text": " protected void Page_Load(object sender, EventArgs e)\n {\n TreeView1.ExpandDepth = 1;\n }\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32240/"
] |
364,454 | <p>When running FindBugs on my project, I got a few instances of the error described above.</p>
<p>Namely, my overriding versions of equals cast the RHS object into the same type as the object in which the overriding version is defined.</p>
<p>However, I'm not sure whether a better design is possible, since AFAIK Java does not allow variance in method parameters, so it is not possible to define any other type for the equals parameter.</p>
<p>Am I doing something very wrong, or is FindBugs too eager? </p>
<p>A different way to phrase this question is: what is the correct behavior if the object passed to equals is not the same type as an LHS: Is this a false, or should there be an exception?</p>
<p>For example:</p>
<pre><code>public boolean equals(Object rhs)
{
MyType rhsMyType = (MyType)rhs; // Should throw exception
if(this.field1().equals(rhsMyType.field1())... // Or whatever
}
</code></pre>
| [
{
"answer_id": 364464,
"author": "Dave L.",
"author_id": 3093,
"author_profile": "https://Stackoverflow.com/users/3093",
"pm_score": 7,
"selected": true,
"text": "if (getClass() != obj.getClass())\n return false;\nMyObj myObj = (MyObj) obj;\n instanceof getClass instanceof equals instanceof"
},
{
"answer_id": 364471,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 3,
"selected": false,
"text": "public class Foo {\n // some code\n\n public void equals(Object o) {\n Foo other = (Foo) o;\n // the real equals code\n }\n}\n public void equals(Object o) {\n if (!(o instanceof Foo)) {\n return false;\n }\n Foo other = (Foo) o;\n // the real equals code\n}\n getClass() != o.getClass() Integer i = new Integer(42);\nString s = \"fourtytwo\";\nboolean b = i.equals(s);\n ClassCastException b false ClassCastException .equals() false"
},
{
"answer_id": 364473,
"author": "Bombe",
"author_id": 43582,
"author_profile": "https://Stackoverflow.com/users/43582",
"pm_score": 0,
"selected": false,
"text": "if ((object == null) || !(object instaceof ThisClass)) {\n return false;\n}\n false equals(Object)"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23072/"
] |
364,472 | <p>Is there an easy or straightforward way in Java to output the results of a DB Query to a file (either csv, tab, etc). Perhaps even in Hibernate?</p>
<p>I know that a query results can be dumped to a flat file on the DB Server. I am looking for a way that an application can run a query and get those results into a file.</p>
<p>I realize one option is to just iterate over the result set and output the records one row at a time separating with a delimiter. But if there is a built in way, or a Hibernate way - that would be much better!</p>
<p>What I am really looking for was a way to do this in code (like - when an application is running). That way a server could take a query, run it against the database, send the output to a flat-file.</p>
<p>The server sending the query doesn't really need the file itself, just to know it worked. So if there is SQL (for an Oracle DB) that could redirect the output to a flat-file in a directory that the Oracle DB Server has access to - that would work too. I don't really have to actually write the file in the Java Server - just trigger the file creation based on the query it has.</p>
<p>Hopefully that makes sense.</p>
| [
{
"answer_id": 372338,
"author": "cliff.meyers",
"author_id": 41754,
"author_profile": "https://Stackoverflow.com/users/41754",
"pm_score": 1,
"selected": false,
"text": "xmlSession = session.getSession(EntityMode.DOM4J);\nElement elem = (Element) xmlSession.load(SomePersistentClass.class, id);\nSystem.out.println(elem.asXML());\n"
},
{
"answer_id": 422835,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 0,
"selected": false,
"text": " public void printToFile( ResultSet rs, String path ) throws IOException { \n\n PrintStream out = new FileOutputStream( path );\n\n int cols = rs.getMetaData().getColumnCount();\n\n while( rs.next() ) { \n for( int i = 0; i < cols ; i++ ) { \n out.printf(\"%s,\", rs.getObject( i ) );\n } \n out.println();\n }\n\n // add exception handling and such...\n // or move the from here.\n out.close();\n rs.close();\n\n }\n ResultSet rs = stmt.executeQuery(\"SELECT a, b, c FROM TABLE2\");\n printToFile( rs, \"/some/file\" );\n"
},
{
"answer_id": 16449173,
"author": "arti",
"author_id": 2363836,
"author_profile": "https://Stackoverflow.com/users/2363836",
"pm_score": 0,
"selected": false,
"text": "for( int i = 1; i < cols ; i++ ) { \n out.printf(\"%s,\", rs.getObject( i ) );\n } \n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,478 | <p>I asked a related question about findbugs, but let's ask a more general question.</p>
<p>Suppose that I am working with an object-oriented language in which polymorphism is possible.</p>
<p>Suppose that the language supports static type checking (e.g., Java, C++)</p>
<p>Suppose that the language does not allow variance in parameters (e.g., Java, again...)</p>
<p>If I am overriding the equality operation, which takes Object as a parameter, what should I do in a situation where the parameter is not the same type or a subtype as the LHS that equals had been called upon?</p>
<p>Option 1 - Return false because the objects are clearly not equals</p>
<p>Option 2 - Throw a casting exception because if the language actually supported variance (which would have been preferable), this would have been caught at compile time as an error; thus, detecting this error at runtime makes sense since a situation where another type is sent should have been illegal.</p>
| [
{
"answer_id": 364484,
"author": "Daniel Schaffer",
"author_id": 2596,
"author_profile": "https://Stackoverflow.com/users/2596",
"pm_score": 0,
"selected": false,
"text": "SomeClass obj1 = new SomeClass();\nobject other = (object)obj1;\n\nreturn obj1.Equals(other); // should return \"true\", since they are really the same reference.\n SomeClass obj1 = new SomeClass();\nobject other = new object();\n\nreturn obj1.Equals(other); // should return \"false\", because they're different reference objects.\n class SomeClass { }\nclass OtherClass { }\n\nSomeClass obj1 = new SomeClass();\nOtherClass obj2 = new OtherClass();\n\nreturn obj1.Equals(obj2); // should return \"false\", because they're different reference objects.\n"
},
{
"answer_id": 364485,
"author": "Joachim Sauer",
"author_id": 40342,
"author_profile": "https://Stackoverflow.com/users/40342",
"pm_score": 1,
"selected": false,
"text": "ClassCastException Collection List"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23072/"
] |
364,483 | <p>Can the alignment of a structure type be found if the alignments of the structure members are known? </p>
<p>Eg. for:</p>
<pre><code>struct S
{
a_t a;
b_t b;
c_t c[];
};
</code></pre>
<p>is the alignment of S = max(alignment_of(a), alignment_of(b), alignment_of(c))?</p>
<p>Searching the internet I found that "for structured types the largest alignment requirement of any of its elements determines the alignment of the structure" (in <a href="http://people.redhat.com/drepper/cpumemory.pdf" rel="noreferrer">What Every Programmer Should Know About Memory</a>) but I couldn't find anything remotely similar in the standard (latest draft more exactly). </p>
<hr>
<p><strong>Edited:</strong>
Many thanks for all the answers, especially to Robert Gamble who provided a really good answer to the original question and the others who contributed.</p>
<p>In short:</p>
<p><strong><em>To ensure alignment requirements for structure members, the alignment of a structure must be at least as strict as the alignment of its strictest member.</em></strong></p>
<p>As for determining the alignment of structure a few options were presented and with a bit of research this is what I found:</p>
<ul>
<li>c++ std::tr1::alignment_of
<ul>
<li>not standard yet, but close (technical report 1), should be in the C++0x</li>
<li>the following restrictions are present in the latest draft: Precondition:T shall be a complete type, a reference type, or an array of
unknown bound, but shall not be a function type or (possibly
cv-qualified) void.
<ul>
<li>this means that my presented use case with the C99 flexible array won't work (this is not that surprising since flexible arrays are not standard c++) </li>
</ul></li>
<li>in the latest c++ draft it is defined in the terms of a new keyword - alignas (this has the same complete type requirement)</li>
<li>in my opinion, should c++ standard ever support C99 flexible arrays, the requirement could be relaxed (the alignment of the structure with the flexible array should not change based on the number of the array elements)</li>
</ul></li>
<li>c++ boost::alignment_of
<ul>
<li>mostly a tr1 replacement</li>
<li>seems to be specialized for void and returns 0 in that case (this is forbidden in the c++ draft)</li>
<li>Note from developers: strictly speaking you should only rely on the value of ALIGNOF(T) being a multiple of the true alignment of T, although in practice it does compute the correct value in all the cases we know about.</li>
<li>I don't know if this works with flexible arrays, it should (might not work in general, this resolves to compiler intrinsic on my platform so I don't know how it will behave in the general case)</li>
</ul></li>
<li>Andrew Top presented a simple template solution for calculating the alignment in the answers
<ul>
<li>this seems to be very close to what boost is doing (boost will additionally return the object size as the alignment if it is smaller than the calculated alignment as far as I can see) so probably the same notice applies</li>
<li>this works with flexible arrays</li>
</ul></li>
<li>use Windbg.exe to find out the alignment of a symbol
<ul>
<li>not compile time, compiler specific, didn't test it</li>
</ul></li>
<li>using offsetof on the anonymous structure containing the type
<ul>
<li>see the answers, not reliable, not portable with c++ non-POD</li>
</ul></li>
<li>compiler intrinsics, eg. MSVC __alignof
<ul>
<li>works with flexible arrays</li>
<li>alignof keyword is in the latest c++ draft</li>
</ul></li>
</ul>
<hr>
<p>If we want to use the "standard" solution we're limited to std::tr1::alignment_of, but that won't work if you mix your c++ code with c99's flexible arrays.</p>
<p>As I see it there is only 1 solution - use the old struct hack: </p>
<pre><code>struct S
{
a_t a;
b_t b;
c_t c[1]; // "has" more than 1 member, strictly speaking this is undefined behavior in both c and c++ when used this way
};
</code></pre>
<p>The diverging c and c++ standards and their growing differences are unfortunate in this case (and every other case).</p>
<hr>
<p>Another interesting question is (if we can't find out the alignment of a structure in a portable way) what is the most strictest alignment requirement possible. There are a couple of solutions I could find:</p>
<ul>
<li>boost (internally) uses a union of variety of types and uses the boost::alignment_of on it</li>
<li>the latest c++ draft contains std::aligned_storage
<ul>
<li>The value of default-alignment shall be the most stringent alignment requirement for any C++ object type whose size is no greater than Len
<ul>
<li>so the <code>std::alignment_of< std::aligned_storage<BigEnoughNumber>>::value</code> should give us the maximum alignment </li>
<li>draft only, not standard yet (if ever), <code>tr1::aligned_storage</code> does not have this property</li>
</ul></li>
</ul></li>
</ul>
<p>Any thoughts on this would also be appreciated. </p>
<p><em>I have temporarily unchecked the accepted answer to get more visibility and input on the new sub-questions</em></p>
| [
{
"answer_id": 364562,
"author": "Andrew Top",
"author_id": 30036,
"author_profile": "https://Stackoverflow.com/users/30036",
"pm_score": 4,
"selected": false,
"text": "template <class T>\nclass Traits\n{\npublic:\n struct AlignmentFinder\n {\n char a; \n T b;\n };\n\n enum {AlignmentOf = sizeof(AlignmentFinder) - sizeof(T)};\n};\n std::cout << \"The alignment of structure S is: \" << Traits<S>::AlignmentOf << std::endl;\n"
},
{
"answer_id": 364653,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": false,
"text": "#define TYPE_ALIGNMENT( t ) offsetof( struct { char x; t test; }, test )\n __alignof()"
},
{
"answer_id": 364668,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 2,
"selected": false,
"text": "Windbg.exe -z \\path\\to\\somemodule.dll -y \\path\\to\\symbols\n dt somemodule!CSomeType\n"
},
{
"answer_id": 12991134,
"author": "carmin",
"author_id": 1673606,
"author_profile": "https://Stackoverflow.com/users/1673606",
"pm_score": 1,
"selected": false,
"text": "struct blah1 {\n char x ;\n char y[2] ;\n};\n struct blah1plusShort {\n char x ;\n char y[2] ;\n // <<< hidden one byte inserted by the compiler here\n // <<< z will start on a 2 byte boundary (if beginning of struct is aligned).\n short z ;\n char w ;\n // <<< hidden one byte tail pad inserted by the compiler.\n // <<< the total struct size is a multiple of the biggest element.\n // <<< This ensures alignment if used in an array.\n};\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45875/"
] |
364,495 | <p>So, i'm running emacs over a crappy ssh connection and I have it set up to use cscope. I can not use X because of this...hence I'm running emacs inside putty. However, when I search for something with cscope and it opens up the other buffer, I can not
follow the links where cscope tells me which file and line number the item is on. When I go t a line number and hit enter, emacs tells me 'buffer is read-only' (it is trying to actually put in a new line instead of following the link). anyone know how I can follow those links?</p>
| [
{
"answer_id": 7285012,
"author": "जलजनक",
"author_id": 835145,
"author_profile": "https://Stackoverflow.com/users/835145",
"pm_score": 0,
"selected": false,
"text": "GNU find version 4.2 -L find -L . -name *.[ch] > cscope.files\ncscope -b -R -q -i cscope.files\n"
},
{
"answer_id": 21122987,
"author": "Peng",
"author_id": 3195561,
"author_profile": "https://Stackoverflow.com/users/3195561",
"pm_score": 1,
"selected": false,
"text": "-(define-key cscope-list-entry-keymap [return] 'cscope-select-entry-other-window)\n+(define-key cscope-list-entry-keymap (kbd \"RET\") 'cscope-select-entry-other-window)\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/440177/"
] |
364,501 | <p>We've got a few pages in our web systems that use the .net system.net.mail control to send emails. The thing has been working great, except it's now starting to look like the smptclient class may not actually be disconnecting from the server, such that the SMTP server leaves that connection open, and we ended up maxing out the number of connections we were allowed to have open at a time on the SMTP server, despite only sending one email at a time.</p>
<p>(For the record, this is a .net 2.0 asp.net application written in VB, and we're fairly confident this isn't some kind of security / virus / spam passthrough situation.)</p>
<p>Google and MSDN didn't turn up anything conclusive, but just enough heresy in blog entries to confirm that we might not be hallucinating.</p>
<p>Any one else out there ever have this problem? (And manage to fix it?)</p>
<p>Of course, if it does work fine, and we <em>are</em> hallucinating, that would be nice to know too. ;)</p>
| [
{
"answer_id": 364576,
"author": "Chris",
"author_id": 34942,
"author_profile": "https://Stackoverflow.com/users/34942",
"pm_score": 3,
"selected": true,
"text": "var smtp = new SmtpClient();\nsmtp.ServicePoint.MaxIdleTime = 1;\nsmtp.ServicePoint.ConnectionLimit = 1;\nsmtp.Send(message);\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19074/"
] |
364,505 | <pre><code><% using (Html.BeginForm() { %>
<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { onchange="[???]" })%>
<% } %>
</code></pre>
<p>In the above example, what value should you set onchange to? Or, how do you get the correct form?</p>
<p>Is there any difference with Ajax.BeginFrom?</p>
| [
{
"answer_id": 364508,
"author": "maxnk",
"author_id": 45862,
"author_profile": "https://Stackoverflow.com/users/45862",
"pm_score": 7,
"selected": true,
"text": "<%=Html.DropDownList(\"TopItemsList\", ViewData[\"ListData\"], new { onchange=\"this.form.submit();\" })%>\n"
},
{
"answer_id": 1946592,
"author": "Lee Smith",
"author_id": 180329,
"author_profile": "https://Stackoverflow.com/users/180329",
"pm_score": 3,
"selected": false,
"text": "$(\"#TopItemsList\").change(function () {\n\n $(\"input[type=submit]\").click();\n\n});\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,514 | <p>I know that -applicationWillResignActive gets called upon an incoming call, but is there a standard method that gets called if the user hits the "exit" button (the only button on the front of the iPhone)? </p>
| [
{
"answer_id": 364520,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 4,
"selected": true,
"text": "- (void)applicationWillTerminate:(UIApplication *)application"
},
{
"answer_id": 3288414,
"author": "Noya",
"author_id": 376288,
"author_profile": "https://Stackoverflow.com/users/376288",
"pm_score": 0,
"selected": false,
"text": "(void)applicationWillResignActive:(UIApplication *)application\n(void)applicationDidEnterBackground:(UIApplication *)application\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21293/"
] |
364,519 | <p>There's an existing function that ends in the following, where <code>d</code> is a dictionary:</p>
<pre><code>return d.iteritems()
</code></pre>
<p>that returns an unsorted iterator for a given dictionary. I would like to return an iterator that goes through the items sorted <em>by key</em>. How do I do that?</p>
| [
{
"answer_id": 364521,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 6,
"selected": false,
"text": "sorted() return sorted(dict.iteritems())\n sorted() return iter(sorted(dict.iteritems()))\n"
},
{
"answer_id": 364524,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 5,
"selected": false,
"text": "sorted(dict.items())\n iteritems"
},
{
"answer_id": 364588,
"author": "Peter Rowell",
"author_id": 17017,
"author_profile": "https://Stackoverflow.com/users/17017",
"pm_score": 5,
"selected": false,
"text": "foo = {\n 'a': 1,\n 'b': 2,\n 'c': 3,\n }\n\nprint foo\n>>> {'a': 1, 'c': 3, 'b': 2}\n\nprint foo.items()\n>>> [('a', 1), ('c', 3), ('b', 2)]\n\nprint sorted(foo.items())\n>>> [('a', 1), ('b', 2), ('c', 3)]\n for k,v in sorted(foo.items()):\n print k, v\n for k in sorted(foo.keys()):\n print k, foo[k]\n"
},
{
"answer_id": 364599,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 9,
"selected": true,
"text": ">>> d = {\"x\":2, \"h\":15, \"a\":2222}\n>>> it = iter(sorted(d.iteritems()))\n>>> it.next()\n('a', 2222)\n>>> it.next()\n('h', 15)\n>>> it.next()\n('x', 2)\n>>>\n for key, value in d.iteritems(): ... >>> d = {\"x\":2, \"h\":15, \"a\":2222}\n>>> for key, value in sorted(d.iteritems()):\n>>> print(key, value)\n('a', 2222)\n('h', 15)\n('x', 2)\n>>>\n d.items() d.iteritems()"
},
{
"answer_id": 364627,
"author": "pcn",
"author_id": 42590,
"author_profile": "https://Stackoverflow.com/users/42590",
"pm_score": 2,
"selected": false,
"text": "return iter(sorted(dict.iteritems()))\n {'a':1,'c':3,'b':2} [('a',1),('b',2),('c',3)]\n"
},
{
"answer_id": 11080546,
"author": "Anthon",
"author_id": 1307905,
"author_profile": "https://Stackoverflow.com/users/1307905",
"pm_score": 2,
"selected": false,
"text": "sorteddict"
},
{
"answer_id": 15257786,
"author": "pythonlarry",
"author_id": 902825,
"author_profile": "https://Stackoverflow.com/users/902825",
"pm_score": 3,
"selected": false,
"text": "for k in sorted(d):\n print k, d[k]\n def sortdict(d, **opts):\n # **opts so any currently supported sorted() options can be passed\n for k in sorted(d, **opts):\n yield k, d[k]\n return dict.iteritems()\n return sortdict(dict)\n return sortdict(dict, reverse = True)\n"
},
{
"answer_id": 15940903,
"author": "jamylak",
"author_id": 1219006,
"author_profile": "https://Stackoverflow.com/users/1219006",
"pm_score": 3,
"selected": false,
"text": ">>> import heapq\n>>> d = {\"c\": 2, \"b\": 9, \"a\": 4, \"d\": 8}\n>>> def iter_sorted(d):\n keys = list(d)\n heapq.heapify(keys) # Transforms to heap in O(N) time\n while keys:\n k = heapq.heappop(keys) # takes O(log n) time\n yield (k, d[k])\n\n\n>>> i = iter_sorted(d)\n>>> for x in i:\n print x\n\n\n('a', 4)\n('b', 9)\n('c', 2)\n('d', 8)\n"
},
{
"answer_id": 17532913,
"author": "Caumons",
"author_id": 955619,
"author_profile": "https://Stackoverflow.com/users/955619",
"pm_score": 3,
"selected": false,
"text": "OrderedDict >>> from collections import OrderedDict\n>>> d = OrderedDict([('first', 1),\n... ('second', 2),\n... ('third', 3)])\n>>> d.items()\n[('first', 1), ('second', 2), ('third', 3)]\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91385/"
] |
364,522 | <p>How do you correct use frame on a asp.net page, so I have a left frame and a right frame, when I click the links on the page presented in the left frame, it loads the according page in the right frame? On top of this, I need to have a master page on all the right frame's pages.</p>
<p>How do I do this? or is there another way to achieve the same effect?</p>
<p>Thanks,
Ray.</p>
| [
{
"answer_id": 364536,
"author": "Dan Herbert",
"author_id": 392,
"author_profile": "https://Stackoverflow.com/users/392",
"pm_score": 2,
"selected": false,
"text": "#main #main{height:600px}\n #main <div />"
},
{
"answer_id": 364732,
"author": "seanb",
"author_id": 3354,
"author_profile": "https://Stackoverflow.com/users/3354",
"pm_score": 3,
"selected": false,
"text": "<html>\n<frameset cols=\"25%,75%\">\n <frame name=\"_left\" src=\"nav.aspx\" />\n <frame name=\"_right\" src=\"foo.aspx\" />\n</frameset>\n</html>\n"
},
{
"answer_id": 17121534,
"author": "Magfar Uddin Mony",
"author_id": 2488427,
"author_profile": "https://Stackoverflow.com/users/2488427",
"pm_score": 0,
"selected": false,
"text": "<iframe width=\"100%\" height=\"600px\" scrolling=\"no\" seamless=\"yes\" src=\"https://facebook.com\"></iframe>\n"
}
] | 2008/12/12 | [
"https://Stackoverflow.com/questions/364522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32240/"
] |
364,523 | <p>I'm currently working with a specialized, interpreted, programming language implemented in Java. As a very small part of the language, I'd like to add the ability to make calls into Java. Before I dive into all of the nitty-gritty of reflection, I was wondering if anyone knew of a general library for doing the "back-end" part of invoking Java code reflectively.</p>
<p>That is, I parse a string (I define the grammar) into some data structure that represents a Java method call (or constructor, or field access) and then pass that data structure to this library that invokes the call and returns the result. In particular, I'd like it to already handle all the edge cases that I don't want to figure out:</p>
<ul>
<li>Automagically pick the right method based on the types of arguments (like an intelligent Class.getDeclaredMethod())</li>
<li>Handle distinction between arrays and normal object references</li>
<li>etc</li>
</ul>
<p>I've spent a little time looking at the implementations of dynamic languages on the JVM, but these are generally much more complicated than I'm looking for, or highly optimized for the particular language.</p>
<p>Another option is to convert my grammar into a string in some dynamic language and invoke it with Rhino or something, but that's a little more overhead than I'm looking for.</p>
| [
{
"answer_id": 365724,
"author": "flicken",
"author_id": 12880,
"author_profile": "https://Stackoverflow.com/users/12880",
"pm_score": 3,
"selected": false,
"text": " String name = method(\"get\").withReturnType(String.class)\n .withParameterTypes(int.class)\n .in(names)\n .invoke(8);\n"
},
{
"answer_id": 365786,
"author": "Dave Ray",
"author_id": 40310,
"author_profile": "https://Stackoverflow.com/users/40310",
"pm_score": 0,
"selected": false,
"text": "private ScriptEngine engine = ... initialize with JavaScript engine ...\n\nprivate Object invoke(Object object, String methodName, Object[] args) \n throws RhsFunctionException\n{\n // build up \"o.method(arg0, arg1, arg2, ...)\"\n StringBuilder exp = new StringBuilder(\"o.\" + methodName);\n engine.put(\"o\", object);\n buildArgs(arguments, exp);\n\n try {\n return engine.eval(exp.toString());\n }\n catch (ScriptException e) {\n throw new RhsFunctionException(e.getMessage(), e);\n }\n}\n\nprivate void buildArgs(Object[] args, StringBuilder exp)\n{\n // Use bindings to avoid having to escape arguments\n exp.append('(');\n int i = 0;\n for(Symbol arg : args) {\n String argName = \"arg\" + i;\n engine.put(argName, arg);\n if(i != 0) {\n exp.append(',');\n }\n exp.append(argName);\n ++i;\n }\n exp.append(')');\n}\n"
},
{
"answer_id": 2967645,
"author": "Hexren",
"author_id": 322986,
"author_profile": "https://Stackoverflow.com/users/322986",
"pm_score": 1,
"selected": false,
"text": "invoke(Object object, String methodName, Object[] args) \n"
},
{
"answer_id": 8033416,
"author": "yclian",
"author_id": 36397,
"author_profile": "https://Stackoverflow.com/users/36397",
"pm_score": 0,
"selected": false,
"text": "Predicate"
},
{
"answer_id": 8589222,
"author": "lexicalscope",
"author_id": 72810,
"author_profile": "https://Stackoverflow.com/users/72810",
"pm_score": 1,
"selected": false,
"text": "forEach(\n object(subject).methods(annotatedWith(PostConstruct.class)),\n ReflectedMethod.class).call();\n"
},
{
"answer_id": 8672357,
"author": "Lukas Eder",
"author_id": 521799,
"author_profile": "https://Stackoverflow.com/users/521799",
"pm_score": 3,
"selected": false,
"text": "String world = \non(\"java.lang.String\") // Like Class.forName()\n.create(\"Hello World\") // Call the most specific matching constructor\n.call(\"substring\", 6) // Call the most specific matching substring() method\n.call(\"toString\") // Call toString()\n.get() // Get the wrapped object, in this case a String\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40310/"
] |
364,539 | <p>I'm not sure if Vim makes me more productive compared to other editors/ide's like Eclipse for example.</p>
<p>But somehow I get an empowering feeling when using Vim and noticed resistance to trying others editors.</p>
<p>Example: As soon a I see some cool feature in an other editor I'm thinking "<em>Vi can do that</em> (i just have to find the keystroke or configure a plugin)"</p>
<p>How can I benchmark editor productivity objectively?</p>
<p>My ideal editor would be: <a href="https://netbeans.org" rel="nofollow noreferrer">Netbeans</a> feature set and ease of use, but with SublimeText's performance and slick looks.</p>
<p><strong>Update</strong><br>
<a href="https://code.visualstudio.com" rel="nofollow noreferrer">Visual Studio Code</a> is now my primary code editor.<br>
<a href="http://sublimetext.com/" rel="nofollow noreferrer">Sublime Text</a> for config files and quick edits.<br>
<a href="http://vim.org/" rel="nofollow noreferrer">Vim</a> for ssh sessions or editing with macros.</p>
| [
{
"answer_id": 16605610,
"author": "Mikko Rantalainen",
"author_id": 334451,
"author_profile": "https://Stackoverflow.com/users/334451",
"pm_score": 0,
"selected": false,
"text": "V E V E diff dd if=/dev/urandom bs=1M count=1 > code.cpp"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19165/"
] |
364,558 | <p>It's been a while since I was in college and knew how to calculate a best fit line, but I find myself needing to. Suppose I have a set of points, and I want to find the line that is the best of those points.</p>
<p>What is the equation to determine a best fit line?
How would I do that with PHP?</p>
| [
{
"answer_id": 364571,
"author": "Tim Whitcomb",
"author_id": 24895,
"author_profile": "https://Stackoverflow.com/users/24895",
"pm_score": 2,
"selected": false,
"text": "a b y = a + bx (x,y)"
},
{
"answer_id": 364585,
"author": "FryGuy",
"author_id": 28776,
"author_profile": "https://Stackoverflow.com/users/28776",
"pm_score": 2,
"selected": false,
"text": "$sx = 0;\n$sy = 0;\n$sxy = 0;\n$sx2 = 0;\n$n = count($data);\nforeach ($data as $x => $y)\n{\n $sx += $x;\n $sy += $y;\n $sxy += $x * $y;\n $sx2 += $x * $x;\n}\n$beta = ($n*$sxy - $sx*$sy) / ($n*$sx2 - $sx*$sx);\n$alpha = $sy/$n - $sx*$beta/$n;\n\necho \"y = $alpha + $beta x\";\n"
},
{
"answer_id": 364590,
"author": "david",
"author_id": 27600,
"author_profile": "https://Stackoverflow.com/users/27600",
"pm_score": 3,
"selected": true,
"text": "/**\n * returns the pearson correlation coefficient (least squares best fit line)\n * \n * @param array $x array of all x vals\n * @param array $y array of all y vals\n */\n\nfunction pearson(array $x, array $y)\n{\n // number of values\n $n = count($x);\n $keys = array_keys(array_intersect_key($x, $y));\n\n // get all needed values as we step through the common keys\n $x_sum = 0;\n $y_sum = 0;\n $x_sum_sq = 0;\n $y_sum_sq = 0;\n $prod_sum = 0;\n foreach($keys as $k)\n {\n $x_sum += $x[$k];\n $y_sum += $y[$k];\n $x_sum_sq += pow($x[$k], 2);\n $y_sum_sq += pow($y[$k], 2);\n $prod_sum += $x[$k] * $y[$k];\n }\n\n $numerator = $prod_sum - ($x_sum * $y_sum / $n);\n $denominator = sqrt( ($x_sum_sq - pow($x_sum, 2) / $n) * ($y_sum_sq - pow($y_sum, 2) / $n) );\n\n return $denominator == 0 ? 0 : $numerator / $denominator;\n}\n"
},
{
"answer_id": 57292416,
"author": "mgroat",
"author_id": 2393763,
"author_profile": "https://Stackoverflow.com/users/2393763",
"pm_score": 0,
"selected": false,
"text": "function mathTrend($data) {\n $sx = 0;\n $sy = 0;\n $sxy = 0;\n $sx2 = 0;\n $yTotal = 0;\n $n = count($data);\n if($n <= 1) {\n return false;\n }\n foreach ($data as $row)\n {\n $row = array_values($row);\n $x = $row[0];\n $y = $row[1];\n $yTotal += $y;\n $sx += $x;\n $sy += $y;\n $sxy += $x * $y;\n $sx2 += $x * $x;\n }\n $yAvg = $yTotal / $n;\n $m = ($n*$sxy - $sx*$sy) / ($n*$sx2 - $sx*$sx);\n $b = $sy/$n - $sx*$m/$n;\n\n //Go through again to determine rSquared\n //Using method from https://www.youtube.com/watch?v=w2FKXOa0HGA\n $diffActual = 0;\n $diffEstimated = 0;\n foreach($data as $row) {\n $row = array_values($row);\n $x = $row[0];\n $y = $row[1];\n\n $expectedY = $m*$x+$b;\n $diffActual += ($y - $yAvg)**2;\n $diffEstimated += ($expectedY-$yAvg)**2;\n }\n $rSquared = $diffEstimated / $diffActual;\n\n $result = ['m'=> $m, 'b' => $b, 'rSquared' => $rSquared];\n return $result;\n}\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12930/"
] |
364,564 | <p>I am writing a Cocoa application with Mono embedded. I want to run and see my debug output in Terminal. On the Cocoa side I am using <code>NSLog()</code>, and on the Mono side I am using <code>Debug.Write()</code>. I can see my debug output in Xcode's console, but not in Terminal. This is what I tried: </p>
<pre>
$: open /path/build/Debug/MyProgram.app
$: open /path/build/Debug/MyProgram.app > output
$: open /path/build/Debug/MyProgram.app 2> output
</pre>
<p>in a terminal but I do not my output on the console or in 'ouput'.</p>
<p>What's the correct command?</p>
<p>PS. My ultimate goal is to write a vim plugin to manage, build, run, debug the xcode project. You can save me this hassle if you can get this <a href="http://www.corsofamily.net/jcorso/vi/" rel="noreferrer">vi input manager</a> to work with xcode.</p>
| [
{
"answer_id": 365000,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 4,
"selected": false,
"text": "open /path/to/MyApp.app stdout stderr stdout stderr asl"
},
{
"answer_id": 365062,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 7,
"selected": true,
"text": "/path/debug/build/MyProgram.app/Contents/MacOS/MyProgram\n"
},
{
"answer_id": 31155807,
"author": "abbood",
"author_id": 766570,
"author_profile": "https://Stackoverflow.com/users/766570",
"pm_score": 0,
"selected": false,
"text": "\nios-deploy --debug --bundle\n \nios-deploy --debug --bundle path/to/your/applicationName.app\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45890/"
] |
364,621 | <p>I am iterating over a list and I want to print out the index of the item if it meets a certain condition. How would I do this?</p>
<p>Example: </p>
<pre><code>testlist = [1,2,3,5,3,1,2,1,6]
for item in testlist:
if item == 1:
print position
</code></pre>
| [
{
"answer_id": 364638,
"author": "jakber",
"author_id": 29812,
"author_profile": "https://Stackoverflow.com/users/29812",
"pm_score": 3,
"selected": false,
"text": "for i in xrange(len(testlist)):\n if testlist[i] == 1:\n print i\n"
},
{
"answer_id": 364641,
"author": "zdan",
"author_id": 4304,
"author_profile": "https://Stackoverflow.com/users/4304",
"pm_score": 5,
"selected": false,
"text": "testlist = [1,2,3,5,3,1,2,1,6]\nfor position, item in enumerate(testlist):\n if item == 1:\n print position\n"
},
{
"answer_id": 364742,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "lookingFor = 1\ni = 0\nindex = 0\ntry:\n while i < len(testlist):\n index = testlist.index(lookingFor,i)\n i = index + 1\n print index\nexcept ValueError: #testlist.index() cannot find lookingFor\n pass\n"
},
{
"answer_id": 364769,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 9,
"selected": true,
"text": " [i for i,x in enumerate(testlist) if x == 1]\n >>> testlist\n[1, 2, 3, 5, 3, 1, 2, 1, 6]\n>>> [i for i,x in enumerate(testlist) if x == 1]\n[0, 5, 7]\n >>> for i in [i for i,x in enumerate(testlist) if x == 1]:\n... print i\n... \n0\n5\n7\n >>> (i for i,x in enumerate(testlist) if x == 1)\n<generator object at 0x6b508>\n>>> for i in (i for i,x in enumerate(testlist) if x == 1):\n... print i\n... \n0\n5\n7\n >>> gen = (i for i,x in enumerate(testlist) if x == 1)\n>>> for i in gen: print i\n... \n0\n5\n7\n"
},
{
"answer_id": 1799718,
"author": "Leonardo",
"author_id": 191472,
"author_profile": "https://Stackoverflow.com/users/191472",
"pm_score": -1,
"selected": false,
"text": "testlist = [1,2,3,5,3,1,2,1,6]\nfor id, value in enumerate(testlist):\n if id == 1:\n print testlist[id]\n"
},
{
"answer_id": 10125837,
"author": "Phil Rankin",
"author_id": 1329409,
"author_profile": "https://Stackoverflow.com/users/1329409",
"pm_score": 3,
"selected": false,
"text": "try:\n id = testlist.index('1')\n print testlist[id]\nexcept ValueError:\n print \"Not Found\"\n"
},
{
"answer_id": 10266829,
"author": "mmj",
"author_id": 694360,
"author_profile": "https://Stackoverflow.com/users/694360",
"pm_score": 8,
"selected": false,
"text": "print testlist.index(element)\n if element in testlist:\n print testlist.index(element)\n print(testlist.index(element) if element in testlist else None)\n try:\n print testlist.index(element)\nexcept ValueError:\n pass\n"
},
{
"answer_id": 12731878,
"author": "malekcellier",
"author_id": 1713952,
"author_profile": "https://Stackoverflow.com/users/1713952",
"pm_score": 2,
"selected": false,
"text": "[x for x in range(len(testlist)) if testlist[x]==1]\n"
},
{
"answer_id": 17224675,
"author": "xXAngelJinXx",
"author_id": 2499048,
"author_profile": "https://Stackoverflow.com/users/2499048",
"pm_score": 0,
"selected": false,
"text": "from Tkinter import * \nlistbox.curselection()\n"
},
{
"answer_id": 44213602,
"author": "Abhishek",
"author_id": 3670532,
"author_profile": "https://Stackoverflow.com/users/3670532",
"pm_score": 0,
"selected": false,
"text": "testlist = [1,2,3,5,3,1,2,1,6]\nfor position, item in enumerate(testlist):\n if item == 1:\n print position\n"
},
{
"answer_id": 56072087,
"author": "B Prashantkumar",
"author_id": 11479535,
"author_profile": "https://Stackoverflow.com/users/11479535",
"pm_score": 2,
"selected": false,
"text": "testlist = [1,2,3,5,3,1,2,1,6] \nposition=0\nfor i in testlist:\n if i == 1:\n print(position)\n position=position+1\n"
},
{
"answer_id": 62587909,
"author": "ravibeli",
"author_id": 3412033,
"author_profile": "https://Stackoverflow.com/users/3412033",
"pm_score": 0,
"selected": false,
"text": "input_list searies1 series2 certain condition input_list = [[1,2,3,4,5,6,7],[1,3,7]]\nseries1 = input_list[0]\nseries2 = input_list[1]\nidx_list = list(map(lambda item: series1.index(item) if item in series1 else None, series2))\nprint(idx_list)\n [0, 2, 6]\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44133/"
] |
364,631 | <p>Given the following code snippet from inside a method; </p>
<pre><code>NSBezierPath * tempPath = [NSBezierPath bezierPathWithOvalInRect:pathRect];
[tempPath retain];
[path release];
[self setPath:tempPath];
</code></pre>
<p>Am I responsible for releasing <code>tempPath</code> or will it be done for me?
<br />The setPath is <code>@synthesize</code>d so I probably would be able to leave out the <code>[path release]</code> as well?</p>
<p>I know the better way of doing this is simply;</p>
<pre><code>[path appendBezierPathWithOvalInRect:pathRect];
</code></pre>
<p>But, being new to Objective C and Cocoa, I'm trying to understand how things stick together.
<br />
<br />
---ADDED CONTENT<br /><br />
Leaving out the <code>[tempPath retain]</code> results in a crash in the <code>NSView</code> object that uses the paths. <br />The result from the debugger:<br /></p>
<blockquote>
<pre><code>(gdb) po [0x145dc0 path]
Program received signal EXC_BAD_ACCESS, Could not access
</code></pre>
<p>memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000021
0x93c56688 in objc_msgSend ()</p>
</blockquote>
<p><br /><br />
<strong>CONFESSION OF GUILT</strong> - my mistake. Hope someone else will get something useful from my mistake. I had used <code>assign</code> in place of <code>retain</code> in the <code>@property</code> declaration. Fixing those made the code work as expected.</p>
<p>THANKS FOR THE HELP GUYS</p>
| [
{
"answer_id": 364647,
"author": "Max Stewart",
"author_id": 18338,
"author_profile": "https://Stackoverflow.com/users/18338",
"pm_score": 1,
"selected": false,
"text": "[tempPath retain] [path release]"
},
{
"answer_id": 364649,
"author": "Ashley Clark",
"author_id": 4556,
"author_profile": "https://Stackoverflow.com/users/4556",
"pm_score": 3,
"selected": true,
"text": "path -setPath: -dealloc tempPath -setPath: -init -dealloc -retain -release NSBezierPath *tempPath = [NSBezierPath bezierPathWithOvalInRect:pathRect];\n[self setPath:tempPath];\n -bezierPathWithOvalInRect:"
},
{
"answer_id": 364667,
"author": "Abizern",
"author_id": 41116,
"author_profile": "https://Stackoverflow.com/users/41116",
"pm_score": 1,
"selected": false,
"text": "- (NSBezierPath *) path {\n return path;\n}\n\n- (void)setPath:(NSBezierPath *)newPath {\n if (path == newPath) {\n // both objects have the same pointer so are the same.\n return;\n }\n\n [path release];\n path = [newPath retain];\n}\n self.path = [NSBezierPath bezierPathWithOvalInRect:pathRect];\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41880/"
] |
364,642 | <p>I want to know the basic principle used for WYSIWYG pages on the web. I started coding it and made it using a text area, but very soon I realized that I cannot add or show images or any HTML in the text area. So I made it using DIV, but I did not understand how I could make it editable.</p>
<p>So, in gist, <strong>I want to know how(in principle) to make an editable DIV section on a web page, something similar to Google docs or FCKEditor or TinyMCE.</strong></p>
<p>I would be very grateful for any pointers and info.</p>
<p>Thanks!</p>
| [
{
"answer_id": 364651,
"author": "coobird",
"author_id": 17172,
"author_profile": "https://Stackoverflow.com/users/17172",
"pm_score": 2,
"selected": false,
"text": "form textarea tiny_mce.js iframe tiny_mce/jscripts/tiny_mce/classes/Editor.js iframe"
},
{
"answer_id": 364689,
"author": "olliej",
"author_id": 784,
"author_profile": "https://Stackoverflow.com/users/784",
"pm_score": 3,
"selected": true,
"text": "contentEditable <div contentEditable>I am editable!!!!</div>\n"
},
{
"answer_id": 364716,
"author": "Marcus Downing",
"author_id": 1000,
"author_profile": "https://Stackoverflow.com/users/1000",
"pm_score": 2,
"selected": false,
"text": "tinyMCE.init({\n mode: 'textareas',\n theme: 'advanced',\n theme_advanced_buttons1 : '',\n theme_advanced_buttons2 : '',\n theme_advanced_buttons3 : '',\n theme_advanced_statusbar_location : \"none\",\n});\n .mceLayout {\n background: none !important;\n border: none !important;\n}\n var editor = tinyMCE.get('editorid');\nvar stuff = editor.getContent();\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,655 | <p>I'm trying to run Python scripts using Xcode's User Scripts menu.</p>
<p>The issue I'm having is that my usual os.sys.path (taken from ~/.profile) does not seem to be imported when running scripts from XCode the way it is when running them at the Terminal (or with IPython). All I get is the default path, which means I can't do things like</p>
<pre><code>#!/usr/bin/python
import myScript
myScript.foo()
</code></pre>
<p>Where myScript is a module in a folder I've added to my path.</p>
<p>I can append a specific path to os.sys.path manually easily enough, but I have to do it in every single script for every single path I want to use modules from</p>
<p>Is there a way to set this up so it uses the same path I use everywhere else?</p>
<p>EDIT: After looking into things a bit more, it seems like scripts executed from Xcode use a completely different PATH than normal. The path I get by running a script in Xcode is:</p>
<pre><code>PATH=/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
</code></pre>
<p>and I'm sure my regular path doesn't have /Developer/usr/bin in it. Does anybody have any idea where this path is coming from?</p>
| [
{
"answer_id": 364691,
"author": "Toby White",
"author_id": 45891,
"author_profile": "https://Stackoverflow.com/users/45891",
"pm_score": 1,
"selected": false,
"text": "cat > $HOME/bin/mypython << EOF\n#!/usr/bin/python\nimport os\nos.path = ['/list/of/paths/you/want']\nEOF\n #!/Users/you/bin/mypython\n"
},
{
"answer_id": 364746,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 1,
"selected": false,
"text": ">>> import sys\n>>> sys.path\n['', ... lots of stuff deleted....]\n>>> for i in sys.path:\n... print i\n... \n\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages\n/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload\n/Library/Python/2.5/site-packages\n/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC\n>>> sys.path.append(\"/Users/crm/lib\")\n>>> for i in sys.path:\n... print i\n... \n\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/lib-scriptpackages\n/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk\n/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload\n/Library/Python/2.5/site-packages\n/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/PyObjC\n/Users/crm/lib\n>>> \n"
},
{
"answer_id": 364759,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "PYTHONPATH = /Somewhere\n"
},
{
"answer_id": 1685231,
"author": "rh0dium",
"author_id": 75888,
"author_profile": "https://Stackoverflow.com/users/75888",
"pm_score": 1,
"selected": false,
"text": "echo \"/some/path/I/want/to/add\" > /Library/Python/2.5/site-packages/custom.pth\n"
},
{
"answer_id": 8054281,
"author": "user3.1415927",
"author_id": 2662176,
"author_profile": "https://Stackoverflow.com/users/2662176",
"pm_score": 0,
"selected": false,
"text": ".profile .cshrc plist"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512/"
] |
364,664 | <p>I would like to restrict access to my <code>/admin</code> URL to internal IP addresses only. Anyone on the open Internet should not be able to login to my web site. Since I'm using Lighttpd my first thought was to use <code>mod_rewrite</code> to redirect any outside request for the <code>/admin</code> URL back to my home page, but I don't know much about Lighty and the docs don't say much about detecting a 192.168.0.0 IP range.</p>
| [
{
"answer_id": 364991,
"author": "Patryk Kordylewski",
"author_id": 30927,
"author_profile": "https://Stackoverflow.com/users/30927",
"pm_score": 2,
"selected": true,
"text": "$HTTP[\"remoteip\"] == \"192.168.0.0/16\" {\n /* your rules here */\n}\n # deny the access to www.example.org to all user which \n # are not in the 10.0.0.0/8 network\n $HTTP[\"host\"] == \"www.example.org\" {\n $HTTP[\"remoteip\"] != \"10.0.0.0/8\" {\n url.access-deny = ( \"\" )\n }\n }\n"
},
{
"answer_id": 15464922,
"author": "Adam Matthews",
"author_id": 1916670,
"author_profile": "https://Stackoverflow.com/users/1916670",
"pm_score": 0,
"selected": false,
"text": "$HTTP[\"remoteip\"] != \"192.168.1.1/254\" {\n $HTTP[\"url\"] =~ \"^/intranet/\" {\n url.access-deny = ( \"\" )\n }\n }\n != =="
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21512/"
] |
364,671 | <p>I have a problem with a many-to-many relation in my tables, which is between an employee and instructor who work in a training centre. I cannot find the link between them, and I don't know how to get it. The employee fields are:</p>
<ul>
<li>employee no.</li>
<li>employee name</li>
<li>company name</li>
<li>department job title</li>
<li>business area</li>
<li>mobile number</li>
<li>ext </li>
<li>ranking</li>
</ul>
<p>The Instructors fields are</p>
<ul>
<li>instructor name</li>
<li>institute</li>
<li>mobile number</li>
<li>email address</li>
<li>fees</li>
</ul>
| [
{
"answer_id": 364677,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 3,
"selected": false,
"text": "table EmployeeInstructor \n EmployeeID\n InstructorID\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364671",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,676 | <p>I have an array filled with values (twitter ids) and I would like to find the missing data between the lowest id and the highest id? Any care to share a simple function or idea on how to do this?</p>
<p>Also, I was wondering if I can do the same with mySQL? I have the key indexed. The table contains 250k rows right now, so a temporary table and then a join wouldn't be very fast or efficient. I could do a PHP loop to loop through the data, but that would also take a long time, and a great deal of memory. Is there a specific mysql query I can run? or can I somehow use the function from above with this?</p>
<p>Thanks,
James Hartig
<a href="http://twittertrend.net" rel="nofollow noreferrer">http://twittertrend.net</a></p>
| [
{
"answer_id": 364677,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 3,
"selected": false,
"text": "table EmployeeInstructor \n EmployeeID\n InstructorID\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45530/"
] |
364,687 | <p>so i have a winforms apps that downloads a set of data syncronously on startup. This obviously takes a while but then when any of the services or GUI classes load, they all have this data. I could change this to put on a background thread but then every component that needs access to this data would continuously have to get notified when this data was ready. This seems like bad design for every one of my classes that depends on this data to be loaded to have a If (Loaded) check or have to subscribe to a loaded event . . . any ideas?</p>
<p>Any other ideas?</p>
| [
{
"answer_id": 365456,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 1,
"selected": false,
"text": "DataManager.LoadDataAsync(dataCommandPatternObject, CallBackFunction);\n\n...\n\npublic void CallbackFunction(SomeDataObjectClass data)\n{\n //load data into UI\n}\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
364,730 | <p>Screenshot of the problem:</p>
<p><img src="https://i.stack.imgur.com/qutvW.jpg" alt="http://i36.tinypic.com/dfxdmd.jpg"></p>
<p>The yellow block is the logo and the blue box is the nav links (I have blanked them out). I would like to align the links at the bottom so they are stuck to the top of the body content (white box). How would I do this?
Here is the relevant CSS and HTML.</p>
<pre><code>#header {
height: 42px;
}
#logo {
width: 253px;
height: 42px;
background-image:url(logo.png);
float: left;
}
#nav {
width: 100%;
border-bottom: 2px solid #3edff2;
vertical-align: bottom;
}
#nav ul {
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 4px;
text-align: right;
font-size: 1.25em;
}
#nav ul li {
display: inline;
background-color: #3edff2;
padding: 5px;
}
<div id="header">
<div id="logo"><a href="/"></a></div>
<div id="nav">
<ul>
<li><a href="#">*****</a></li>
[...]
</ul>
</div>
</div>
</code></pre>
<p>Thanks in advance.</p>
| [
{
"answer_id": 364737,
"author": "John Dunagan",
"author_id": 28939,
"author_profile": "https://Stackoverflow.com/users/28939",
"pm_score": 0,
"selected": false,
"text": "clear: both;"
},
{
"answer_id": 364772,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": "#header {\n height: 42px;\n}\n#logo {\n width: 253px;\n height: 42px;\n background: #00ffff;\n float: left;\n}\n#nav {\n width: 100%;\n border-bottom: 2px solid #3edff2;\n height: 42px;\n}\n#nav ul {\n list-style-type: none;\n margin: 0;\n padding-top: 18px;\n margin-bottom: 4px;\n text-align: right;\n font-size: 1.25em;\n}\n#nav ul li {\n display: inline;\n background-color: #3edff2;\n padding: 5px;\n}\n"
},
{
"answer_id": 367906,
"author": "Ata",
"author_id": 46110,
"author_profile": "https://Stackoverflow.com/users/46110",
"pm_score": 0,
"selected": false,
"text": "#header {\n position: relative;\n\n height: 42px;\n}\n#nav {\n position: absolute;\n bottom: 0px;\n\n width: 100%;\n border-bottom: 2px solid #3edff2;\n height: 42px;\n}\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
364,731 | <p>I have this code that generates markets I want to be clickable with a pop up info window. </p>
<pre><code>for (i = 0; i < marker_array.length; i++) {
var point = new GLatLng(marker_array[i][0], marker_array[i][1]);
var marker = new GMarker(point, markerOptions);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html_data);
});
map.addOverlay(marker);
}
</code></pre>
<p>The problem is that only one market ends up clickable. No matter which one gets clicked, an info window with the one clickable marker's data pops up over that one clickable marker. All of the markers load and are in the correct locations, so the problem is only with getting the pop up window data to appear for each one. </p>
<p>I've checked out the section about "unrolling" the marker function <a href="http://mapki.com/wiki/Read_This_First" rel="nofollow noreferrer">here</a> and it seems like that's probably where I'm going wrong, but I have not been able to get this to work through testing the changes they suggest.</p>
| [
{
"answer_id": 365560,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 0,
"selected": false,
"text": "function createMarker(posn, title, icon, i) {\n var marker = new GMarker(posn, {title: title, icon: icon, draggable:false});\n GEvent.addListener(marker, 'mouseover', function() { \n map.closeInfoWindow()\n marker.openInfoWindowHtml(infoText[i])\n\n } ); \n return marker;\n}\n"
},
{
"answer_id": 1816267,
"author": "Garibaldy",
"author_id": 220934,
"author_profile": "https://Stackoverflow.com/users/220934",
"pm_score": 0,
"selected": false,
"text": "public class StoreSpot extends Marker\n{ \n public var infoWindow:InfoWindowOptions;\n public var store_id:String;\n public var address:String;\n public var name:String;\n ...\n}\n tempMarker = new StoreSpot(\n tempLatlng,\n new MarkerOptions({\n icon:new spotStore(), \n iconAlignment:MarkerOptions.ALIGN_HORIZONTAL_CENTER,\n iconOffset:new Point(0,-50)\n }),\n temp.store_id,\n temp.name,\n temp.address,\n temp.detail\n);\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30098/"
] |
364,740 | <p>I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development.</p>
<p>I am also doing some research into ADO.net data services.</p>
| [
{
"answer_id": 365041,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "IUpdatable"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45909/"
] |
364,757 | <p>I am restricted to C (cannot use C++). I wish C had stricter type checking.</p>
<p>Is there a way to get compile errors on the commented lines? If it helps, the enum values cannot overlap.</p>
<hr>
<pre><code>enum hundred {
VALUE_HUNDRED_A = 100,
VALUE_HUNDRED_B
};
enum thousand {
VALUE_THOUSAND_A = 1000,
VALUE_THOUSAND_B
};
void print_hundred(enum hundred foo)
{
switch (foo) {
case VALUE_HUNDRED_A: printf("hundred:a\n"); break;
case VALUE_HUNDRED_B: printf("hundred:b\n"); break;
default: printf("hundred:error(%d)\n", foo); break;
}
}
void print_thousand(enum thousand bar)
{
switch (bar) {
case VALUE_THOUSAND_A: printf("thousand:a\n"); break;
case VALUE_THOUSAND_B: printf("thousand:b\n"); break;
default: printf("thousand:error(%d)\n", bar); break;
}
}
int main(void)
{
print_hundred(VALUE_HUNDRED_A);
print_hundred(VALUE_THOUSAND_A); /* Want a compile error here */
print_thousand(VALUE_THOUSAND_A);
print_thousand(VALUE_HUNDRED_A); /* Want a compile error here */
return 0;
}
</code></pre>
| [
{
"answer_id": 364781,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": -1,
"selected": false,
"text": "assert()"
},
{
"answer_id": 364784,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 0,
"selected": false,
"text": "-Wall -Werror"
},
{
"answer_id": 364919,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 3,
"selected": false,
"text": "#include <stdio.h>\nenum hundred_e {\n VALUE_HUNDRED_A = 100,\n VALUE_HUNDRED_B\n};\n\nenum thousand_e {\n VALUE_THOUSAND_A = 1000,\n VALUE_THOUSAND_B\n};\n\nstruct hundred { enum hundred_e n; };\nstruct thousand { enum thousand_e n; };\n\nconst struct hundred struct_hundred_a = { VALUE_HUNDRED_A }; \nconst struct hundred struct_hundred_b = { VALUE_HUNDRED_B }; \nconst struct thousand struct_thousand_a = { VALUE_THOUSAND_A }; \nconst struct thousand struct_thousand_b = { VALUE_THOUSAND_B }; \n\nvoid print_hundred(struct hundred foo)\n{\n switch (foo.n) {\n case VALUE_HUNDRED_A: printf(\"hundred:a\\n\"); break;\n case VALUE_HUNDRED_B: printf(\"hundred:b\\n\"); break;\n default: printf(\"hundred:error(%d)\\n\", foo.n); break;\n }\n}\n\nvoid print_thousand(struct thousand bar)\n{\n switch (bar.n) {\n case VALUE_THOUSAND_A: printf(\"thousand:a\\n\"); break;\n case VALUE_THOUSAND_B: printf(\"thousand:b\\n\"); break;\n default: printf(\"thousand:error(%d)\\n\", bar.n); break;\n }\n}\n\nint main(void)\n{\n\n print_hundred(struct_hundred_a);\n print_hundred(struct_thousand_a); /* Want a compile error here */\n\n print_thousand(struct_thousand_a);\n print_thousand(struct_hundred_a); /* Want a compile error here */\n\n return 0;\n}\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45908/"
] |
364,775 | <p>We are using Maven for a large build process (> 100 modules). We have been storing our external dependencies in source control, and using that to update a local repo.</p>
<p>However, we are ready to graduate to a local repo that can cache central so that we don't have to proactively download all 3rd parties (but we can still have a local repo to pull from). In addition we want to publish our internal build artifacts from a nightly build so that developers don't have to build the world.</p>
<p>We are considering Nexus and Artifactory. What are the reasons for preferring one over the other? Are there others we should be considering?</p>
| [
{
"answer_id": 4092349,
"author": "Evgeny Goldin",
"author_id": 472153,
"author_profile": "https://Stackoverflow.com/users/472153",
"pm_score": 7,
"selected": false,
"text": "mvn deploy mvn deploy mvn deploy"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5874/"
] |
364,788 | <p>Is there an easier way to achieve the following?</p>
<pre><code>var obj = from row in table.AsEnumerable()
select row["DOUBLEVALUE"];
double[] a = Array.ConvertAll<object, double>(obj.ToArray(), o => (double)o);
</code></pre>
<p>I'm extracting a column from a <code>DataTable</code> and storing the column in an array of <code>double</code>s.</p>
<p>Assume that <code>table</code> is a <code>DataTable</code> containing a column called "DOUBLEVALUE" of type <code>typeof(Double)</code>.</p>
| [
{
"answer_id": 4092349,
"author": "Evgeny Goldin",
"author_id": 472153,
"author_profile": "https://Stackoverflow.com/users/472153",
"pm_score": 7,
"selected": false,
"text": "mvn deploy mvn deploy mvn deploy"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45914/"
] |
364,791 | <p>Consider the following HTML:</p>
<pre><code><div class="foo" id="obj">
I should be changed red
<div class="bar" style="color:black;">
I should not be changed red.
<div class="foo">I should be changed red.</div>
</div>
</div>
</code></pre>
<p>Given a DOM element <code>obj</code> and an expression, how do I go about selecting any children and possibly <code>obj</code>? I'm looking for something similar to "select descendants" but also including the parent, if it matches the expression.</p>
<pre><code>var obj = $("#obj")[0];
//wrong, may include siblings of 'obj'
$(".foo", $(obj).parent()).css("color", "red");
//wrong -- excludes 'obj'
$(".foo", obj).css("color", "red");
//correct way, but it's annoying
var matches = $(".foo", obj);
if ($(obj).is(".foo")) matches = matches.add(obj);
matches.css("color", "red");
</code></pre>
<p>Is there a more elegant solution to this?</p>
| [
{
"answer_id": 364798,
"author": "rz.",
"author_id": 7407,
"author_profile": "https://Stackoverflow.com/users/7407",
"pm_score": -1,
"selected": false,
"text": " $('div.foo, div.foo > *').css('color','red');\n"
},
{
"answer_id": 364800,
"author": "Sam",
"author_id": 43005,
"author_profile": "https://Stackoverflow.com/users/43005",
"pm_score": 1,
"selected": false,
"text": "var _$ = function(expr, parent){ \n return $(parent).is(expr) ? $(expr, parent).add(parent) : $(expr, parent); \n}\n"
},
{
"answer_id": 364806,
"author": "cLFlaVA",
"author_id": 45109,
"author_profile": "https://Stackoverflow.com/users/45109",
"pm_score": -1,
"selected": false,
"text": "$(document).ready(function(){\n $(\"div.foo\").css(\"color\", \"red\");\n});\n"
},
{
"answer_id": 364807,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "$(currentDiv).contents().addBack('.foo').css('color','red');\n foo foo $(currentDiv).find('.foo').addBack('.foo').css('color','red');\n $(currentDiv).find('.foo').andSelf().filter('.foo').css('color','red');\n"
},
{
"answer_id": 7167680,
"author": "Nik Orfanos",
"author_id": 908525,
"author_profile": "https://Stackoverflow.com/users/908525",
"pm_score": 0,
"selected": false,
"text": "$(\"#obj\").css(\"color\", \"red\").find(\".foo\").css(\"color\", \"red\");\n"
},
{
"answer_id": 16867505,
"author": "Andrew",
"author_id": 718050,
"author_profile": "https://Stackoverflow.com/users/718050",
"pm_score": 3,
"selected": false,
"text": "$(currentDiv).find(\".foo\").addBack(\".foo\").css(\"color\", \"red\");\n $(currentDiv).find(\".foo\").add(currentDiv.filter(\".foo\")).css(\"color\", \"red\");\n"
},
{
"answer_id": 24058350,
"author": "Gone Coding",
"author_id": 201078,
"author_profile": "https://Stackoverflow.com/users/201078",
"pm_score": 2,
"selected": false,
"text": "jQuery.fn.findAndSelf = function (selector){\n return this.find(selector).addBack(selector);\n};\n $(function(){\n $('#obj').findAndSelf('.foo').css('color', 'red');\n});\n addBack()"
},
{
"answer_id": 34209867,
"author": "Josh Crozier",
"author_id": 2680216,
"author_profile": "https://Stackoverflow.com/users/2680216",
"pm_score": 0,
"selected": false,
"text": "$('*', '#parent').addBack();\n $('#parent').find('*').addBack();\n $('*', '#parent').addBack().css('border', '1px solid #f00'); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n<div id=\"parent\">\n <span>Child</span>\n <span>Another child</span>\n</div> $('.foo', '#parent').addBack();\n $('#parent').find('.foo').addBack();\n"
}
] | 2008/12/13 | [
"https://Stackoverflow.com/questions/364791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43005/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.