qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
350,348 | <p>I have wrist pain when I type and I would like to start writing SQL statements, stored procedure, and views using speech recognition.</p>
| [
{
"answer_id": 350349,
"author": "Keith Walton",
"author_id": 22448,
"author_profile": "https://Stackoverflow.com/users/22448",
"pm_score": 7,
"selected": true,
"text": "SELECT PT_17, PT_28, PT_29 FROM HIK.dbo.PATINFO PT_17 SELECT Patient.FirstName, Patient.MiddleName, Patient.LastName FROM Claim.dbo.Patient AS Patient WHERE Patient.LastName LIKE '%smith%'\n LIKE '%smith%' SELECT FROM WHERE XACT_ABORT SELECT\nWHERE\nFROM\nXACT_ABORT\\exact-abort\nMAXDOP\nNOLOCK\\no-lock\nLEN\nRETURNS\nCURSOR\nMONEY \n \\New-Line\n\\New-Paragraph\n\\All-Caps\n\\All-Caps-On\n\\All-Caps-Off\n\\Cap\n\\Caps-On\n\\Caps-Off\n\\No-Caps\n\\No-Caps-On\n\\No-Caps-Off\n\\No-Space\n\\No-Space-On\n\\No-Space-Off\n\\space-bar\n\\tab-key\na\\alpha\nb\\bravo\nc\\charlie\nd\\delta\ne\\echo\nf\\foxtrot\ng\\golf\nh\\hotel\ni\\india\nj\\juliet\nk\\kilo\nl\\lima\nm\\mike\nn\\november\no\\oscar\np\\papa\nq\\quebec\nr\\romeo\ns\\sierra\nt\\tango\nu\\uniform\nv\\victor\nw\\whiskey\nx\\xray\ny\\yankee\nz\\zulu\nPM\nAM\none\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\ntwelve\nthirteen\nfourteen\nfifteen\nsixteen\nseventeen\neighteen\nnineteen\ntwenty\nthirty\nfourty\nfifty\nsixty\nseventy\neighty\nninety\nhundred\nthousand\nmillion\nbillion\ntrillion\n SELECT DISTINCT * FROM \n(\nSELECT DISTINCT [name] FROM Database1.[dbo].[sysobjects] WHERE xtype not IN ('F', 'S', 'PK', 'D', 'UQ') \nUNION \nSELECT DISTINCT column_name AS [name] FROM Database1.information_schema.[columns]\nUNION\nSELECT DISTINCT [name] FROM Database2.[dbo].[sysobjects] WHERE xtype not IN ('F', 'S', 'PK', 'D', 'UQ') \nUNION \nSELECT DISTINCT column_name AS [name] FROM Database2.information_schema.[columns]\n...\n) AS UnionTable\n Find: ^{[A-Z][a-z]+}{[A-Z][a-z]+}$\nReplace: \\0\\\\\\1-\\2\n ASP SELECT * FROM Database1.dbo.[View] UNION SELECT * FROM Database1.dbo.Routine UNION\nSELECT * FROM Database2.dbo.[View] UNION SELECT * FROM Database2.dbo.Routine \n...\nORDER BY [Name]\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22448/"
] |
350,353 | <p>I've got a project coming up that will involve connecting to one to many backend systems through the same interface; let's call it IBacksideProvider. </p>
<p>I'd like to use Unity to inject these providers at runtime. The problem is that since we're talking about 1...n backend systems, I'd need to register 1...n implementations of IBacksideProvider. Unity doesn't support this out of the box.</p>
<p><a href="http://blog.ashmind.com/index.php/2008/09/08/comparing-net-di-ioc-frameworks-part-2/" rel="nofollow noreferrer">This blog post</a> suggests that it can be done, however. I'm wondering if anybody has done this or has an idea how to go about working Unity so as to be able to do this. TIA.</p>
| [
{
"answer_id": 350435,
"author": "Szymon Rozga",
"author_id": 7583,
"author_profile": "https://Stackoverflow.com/users/7583",
"pm_score": 3,
"selected": true,
"text": "IEnumerable<IMyObject> objects = myContainer.ResolveAll<IMyObject>();\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,354 | <p>Is there a .NET library I can use to programmatically generate my own GIF images?</p>
<p>At a minimum I'd like to build it pixel-by-pixel. Better would be support for text and shapes.</p>
<p>Here's an example of what I'm trying to do. I mocked this up in Photoshop…</p>
<p><a href="http://img143.imageshack.us/img143/5458/dollarlineot9.gif">Number line graphic http://img143.imageshack.us/img143/5458/dollarlineot9.gif</a></p>
<p>What do you recommend?</p>
| [
{
"answer_id": 350394,
"author": "Chris",
"author_id": 44360,
"author_profile": "https://Stackoverflow.com/users/44360",
"pm_score": 5,
"selected": true,
"text": "Bitmap bmp = new Bitmap(xSize, ySize, PixelFormat.Format32bppArgb);\nusing (Graphics g = Graphics.FromImage(bmp)) {\n // Use g and/or bmp to set pixels, draw lines, show text, etc...\n}\nbmp.Save(filename, ImageFormat.Gif);\n"
},
{
"answer_id": 350410,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": "bmp.Save(filename, ImageFormat.Gif); bmp.Save(stream, ImageFormat.Gif);"
},
{
"answer_id": 350421,
"author": "OwenP",
"author_id": 2547,
"author_profile": "https://Stackoverflow.com/users/2547",
"pm_score": 2,
"selected": false,
"text": "System.Drawing // add a reference to System.Drawing.dll\nusing System;\nusing System.Drawing;\nusing System.Drawing.Imaging;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static void Main(string[] args)\n {\n Bitmap bmp = new Bitmap(400, 100);\n\n using (Graphics g = Graphics.FromImage(bmp))\n {\n g.FillRectangle(Brushes.White, 0.0f, 0.0f, 400f, 100f);\n\n // draw line\n using (Pen p = new Pen(Color.Black, 1.0f))\n {\n g.DrawLine(p, 0, 49, 399, 49);\n }\n\n // Draw boxes at start and end\n g.FillRectangle(Brushes.Blue, 0, 47, 5, 5);\n g.FillRectangle(Brushes.Blue, 394, 47, 5, 5);\n }\n\n\n bmp.Save(\"test.gif\", ImageFormat.Gif);\n bmp.Dispose();\n }\n }\n}\n"
},
{
"answer_id": 350428,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 1,
"selected": false,
"text": "<img src=\"createChart.ashx?data=1\"/>\n public class CreateChart : IHttpHandler\n{\n public void ProcessRequest(HttpContext context)\n {\n string data = context.QueryString[\"data\"]; // Or get it from a POST etc\n\n Bitmap image = new Bitmap(xSize, ySize, PixelFormat.Format32bppArgb);\n using (Graphics g = Graphics.FromImage(Image)) \n {\n // Use g to set pixels, draw lines, show text, etc...\n }\n BinaryStream s = new BinaryStream();\n\n image.Save(s, ImageFormat.Gif);\n\n context.Response.Clear();\n context.Response.ContentType = \"image/gif\";\n context.Response.BinaryWrite(s);\n context.Response.End();\n }\n\n public bool IsReusable { get { return false; } }\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
350,377 | <p>I have three custom build configurations { Dev, Qs, Prd }. So, I have three app configs { Dev.config, Qs.config, Prd.config }. I know how to edit the .csproj file to output the correct one based on the current build configuration.</p>
<pre><code><Target Name="AfterBuild">
<Delete Files="$(TargetDir)$(TargetFileName).config" />
<Copy SourceFiles="$(ProjectDir)$(Configuration).config" DestinationFiles="$(TargetDir)$(TargetFileName).config" />
</Target>
</code></pre>
<p>My problem is, I need to have <strong>six</strong> build configurations { Dev, Qs, Prd } x { Debug, Release }. I need to support the debug and release settings (optimizations, pdb, etc) for each environment. However, the app config values don't change between debug/release.</p>
<p>How do I keep the build script as generic as possible and use only the three app configs? I don't want to hard code too many conditional strings.</p>
| [
{
"answer_id": 350388,
"author": "Anthony Mastrean",
"author_id": 3619,
"author_profile": "https://Stackoverflow.com/users/3619",
"pm_score": 0,
"selected": false,
"text": "Dev_Debug.config Dev_Release.config Qs_Debug.config ... Prd_Release.config"
},
{
"answer_id": 350438,
"author": "Brian",
"author_id": 19299,
"author_profile": "https://Stackoverflow.com/users/19299",
"pm_score": 4,
"selected": true,
"text": "<PropertyGroup Condition=\"'$(Configuration)'=='Dev_Debug' OR '$(Configuration)'=='Dev_Release'\" >\n <CfgFileName>Dev</CfgFileName>\n</PropertyGroup>\n<!-- similar for Qs & Prd -->\n<Target ...>...$(CfgFileName).config...\n"
},
{
"answer_id": 350571,
"author": "Rob Williams",
"author_id": 26682,
"author_profile": "https://Stackoverflow.com/users/26682",
"pm_score": 1,
"selected": false,
"text": "app.config app.config app.config target-env app.config app.config String DateTime Url Integer Currency"
},
{
"answer_id": 351013,
"author": "Steve Severance",
"author_id": 41717,
"author_profile": "https://Stackoverflow.com/users/41717",
"pm_score": 3,
"selected": false,
"text": " <Choose>\n<When Condition=\" '$(Configuration)' == 'Debug' \">\n <ItemGroup>\n <None Include=\"App.config\" />\n <None Include=\"Release\\App.config\" />\n </ItemGroup>\n</When>\n<Otherwise>\n <ItemGroup>\n <None Include=\"Release\\App.config\">\n <Link>App.config</Link>\n </None>\n </ItemGroup>\n</Otherwise>\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3619/"
] |
350,381 | <p>So I have a script that I want to run as root, without hangup and nicely. What order should I put the commands in?</p>
<p>sudo nohup nice foo.bash &</p>
<p>or</p>
<p>nohup nice sudo foo.bash &</p>
<p>etc.</p>
<p>I suspect it doesn't matter but would like some insight from those who <strong>really</strong> know.</p>
| [
{
"answer_id": 350405,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "~ $ sudo nohup nice whoami\nnohup: ignoring input and appending output to `nohup.out'\n~ $ sudo cat nohup.out \nroot\n sudo nohup"
},
{
"answer_id": 1910133,
"author": "Adam Crume",
"author_id": 25498,
"author_profile": "https://Stackoverflow.com/users/25498",
"pm_score": 4,
"selected": false,
"text": "nice sudo nice\nsudo nice nice\n"
},
{
"answer_id": 10978626,
"author": "Partly Cloudy",
"author_id": 109079,
"author_profile": "https://Stackoverflow.com/users/109079",
"pm_score": 2,
"selected": false,
"text": "sudo nohup nice foo.sh sudo nohup nice foo.sh >> /tmp/foo.stdout.log 2>> /tmp/foo.stderr.log"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15948/"
] |
350,383 | <p>I was using <a href="http://en.wikipedia.org/wiki/CodeRush" rel="nofollow noreferrer">CodeRush</a> quite while ago and now I'm planning to use it again. I've installed the trial but I forgot all the cool features except <kbd>Alt</kbd> + <kbd>Home</kbd> (drop a marker). And when you don't know some cool tricks it's really like burning money (since it's not cheap for personal use).</p>
<p>What do you like about it? What are your best features?</p>
<p>My best feature is marker:
<kbd>Alt</kbd> + <kbd>Home</kbd> (and use escape to go back)</p>
<p><strong>Currently What I like most</strong></p>
<ul>
<li><kbd>p</kbd> <kbd>s</kbd> <kbd>space</kbd> / <kbd>p</kbd> <kbd>i</kbd> <kbd>space</kbd>, etc. templates to create properties.</li>
<li><kbd>c</kbd> <kbd>c</kbd> <kbd>space</kbd> to create constructors.</li>
<li>Pressing <kbd>Tab</kbd> to navigate between references to identifiers.</li>
<li><kbd>Shift</kbd> + <kbd>F12</kbd> to find references in new cool window.</li>
<li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>.</kbd> for recent files.</li>
<li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Q</kbd> for jumping to any function / class.</li>
<li><kbd>f</kbd> <kbd>e</kbd> <kbd>space</kbd> / <kbd>p</kbd> <kbd>i</kbd> <kbd>space</kbd> for "for loops".</li>
</ul>
| [
{
"answer_id": 420911,
"author": "Echostorm",
"author_id": 12862,
"author_profile": "https://Stackoverflow.com/users/12862",
"pm_score": 3,
"selected": false,
"text": "/ b tc mbs MessageBox.Show(\"\"); cws Console.Writeline m ."
},
{
"answer_id": 630346,
"author": "Rory Becker",
"author_id": 11356,
"author_profile": "https://Stackoverflow.com/users/11356",
"pm_score": 3,
"selected": false,
"text": "DevExpress\\Options...\\IDE\\Shortcuts"
},
{
"answer_id": 7443601,
"author": "Rory Becker",
"author_id": 11356,
"author_profile": "https://Stackoverflow.com/users/11356",
"pm_score": 2,
"selected": false,
"text": "If [VariableName] Is nothing Then\n return \nEnd If \n if ([VariableName] == null)\n{\n return;\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40322/"
] |
350,393 | <p>Using the instructions from <a href="http://blogs.msdn.com/pajohn/archive/2008/06/18/web-widgets-with-net-part-one.aspx" rel="nofollow noreferrer">Paul Johnson's Web Widgets</a> page I created my own custom widget. However because I was deploying to IIS 6.0 I utilized the <a href="http://blogs.msdn.com/pajohn/archive/2008/06/18/web-widgets-with-net-part-one.aspx#8998840" rel="nofollow noreferrer">web.config change recommended</a> to render the page since the IIS 7.0 configuration management option was not available in IIS 6.0. </p>
<p>The widget renders correctly when debugging with VS 2008. However once the files and the updated web.config are deployed to the Windows 2003 Server running IIS 6.0 and the address referenced the error rendered is "The page cannot be found".</p>
<p>The development machine is a Windows Vista machine, however since VS 2008 uses its own internal web server and not Vista's IIS 7.0 for debugging I did not believe this would have been an issue.</p>
<p>Any help debugging this issue would be much appreciated.</p>
| [
{
"answer_id": 1064437,
"author": "MattH",
"author_id": 81,
"author_profile": "https://Stackoverflow.com/users/81",
"pm_score": 0,
"selected": false,
"text": "<system.web>\n<httpHandlers>\n<add verb=\"GET,HEAD\" path=\"eventswidget.jss\" type=\"Demo1.Handlers.EventsWidget, Demo1\" validate=\"false\" />\n</httpHandlers>\n</system.web>\n Public Overrides Function BuildOutput() As String\n Dim sOutput As String = \"document.write('<br><b>Hello World</b>');\"\n Return sOutput\nEnd Function\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12722/"
] |
350,400 | <p>I've got some blank values in my table, and I can't seem to catch them in an IF statement. </p>
<p>I've tried</p>
<p><code>IF @value = ''</code> and <code>if @value = NULL</code> and neither one catches the blank values. Is there any way to test whether or not a varchar is entirely whitespace?</p>
<p>AHA! Turns out I was testing for null wrong. Thanks. </p>
| [
{
"answer_id": 350413,
"author": "no_one",
"author_id": 35662,
"author_profile": "https://Stackoverflow.com/users/35662",
"pm_score": 2,
"selected": false,
"text": "(LTRIM(RTRIM(@Value))=''\n"
},
{
"answer_id": 350417,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 4,
"selected": true,
"text": "--Generic example:\nSELECT *\nFROM MY_TABLE\nWHERE SOME_FIELD IS NULL;\n\n--Instead of \n\nSELECT *\nFROM MY_TABLE\nWHERE SOME_FIELD = NULL;\n"
},
{
"answer_id": 350422,
"author": "Bernhard Hofmann",
"author_id": 39722,
"author_profile": "https://Stackoverflow.com/users/39722",
"pm_score": 0,
"selected": false,
"text": "where ltrim(yourcolumnname) = ''\n"
},
{
"answer_id": 350441,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "ltrim(rtrim(isNull(@value,''))) = ''\n"
},
{
"answer_id": 16452112,
"author": "Jim",
"author_id": 2364329,
"author_profile": "https://Stackoverflow.com/users/2364329",
"pm_score": 2,
"selected": false,
"text": "SELECT *\nFROM TableA\nWHERE Val IS NOT NULL\nAND LEN(RTRIM(LTRIM(Val))) > 0\n SELECT *\nFROM TableA\nWHERE LEN(RTRIM(LTRIM(Val))) > 0\n"
},
{
"answer_id": 26462607,
"author": "Jodrell",
"author_id": 659190,
"author_profile": "https://Stackoverflow.com/users/659190",
"pm_score": 2,
"selected": false,
"text": "LTRIM RTRIM SELECT\n *\n FROM\n [Table]\n WHERE\n COALESCE(PATINDEX('%[^ ]%', [Value]), 0) > 0\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17917/"
] |
350,404 | <p>I was looking at the Proxy Pattern, and to me it seems an awful lot like the Decorator, Adapter, and Bridge patterns. Am I misunderstanding something? What's the difference? Why would I use the Proxy pattern versus the others? How have you used them in the past in real world projects?</p>
| [
{
"answer_id": 350471,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 11,
"selected": true,
"text": "countStudents() reportAttendance() assignSubstituteTeacher()"
},
{
"answer_id": 33281782,
"author": "nakashu",
"author_id": 1984346,
"author_profile": "https://Stackoverflow.com/users/1984346",
"pm_score": 1,
"selected": false,
"text": "class ProxyHumanGenome implements GenomeInterface {\n private $humanGenome = NULL; \n\n // humanGenome class is not instantiated at construct time\n function __construct() {\n }\n\n function getGenomeCount() {\n if (NULL == $this->humanGenome) {\n $this->instantiateGenomeClass(); \n }\n return $this->humanGenome->getGenomeCount();\n }\n} \nclass HumanGenome implement GenomeInterface { ... }\n class DecoratorHumanGenome implements CheckGenomeInterface {\n\n // ... same code as previous example\n\n // added functionality\n public function isComplete() {\n $this->humanGenome->getCount >= 21000\n }\n}\n\ninterface CheckGenomeInterface extends GenomeInterface {\n\n public function isComplete();\n\n}\n\nclass HumanGenome implement GenomeInterface { ... }\n countStudents() reportAttendance() assignSubstituteTeacher()"
},
{
"answer_id": 34222981,
"author": "Abdul Kader Jeelani",
"author_id": 5668664,
"author_profile": "https://Stackoverflow.com/users/5668664",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace TestConsole\n{\n class Program\n {\n static void Main(string[] args)\n {\n /* Proxy */\n\n Console.WriteLine(Environment.NewLine);\n Console.WriteLine(\"PROXY\");\n Console.WriteLine(Environment.NewLine);\n\n //instead of creating here create using a factory method, the facory method will return the proxy\n IReal realProxy = new RealProxy();\n Console.WriteLine(\"calling do work with the proxy object \");\n realProxy.DoWork();\n\n Console.WriteLine(Environment.NewLine);\n Console.WriteLine(\"ADAPTER\");\n Console.WriteLine(Environment.NewLine);\n\n /*Adapter*/\n IInHand objectIHave = new InHand();\n Api myApi = new Api();\n //myApi.SomeApi(objectIHave); /*I cant do this, use a adapter then */\n IActual myAdaptedObject = new ActualAdapterForInHand(objectIHave);\n Console.WriteLine(\"calling api with my adapted obj\");\n myApi.SomeApi(myAdaptedObject);\n\n\n Console.WriteLine(Environment.NewLine);\n Console.WriteLine(\"DECORATOR\");\n Console.WriteLine(Environment.NewLine);\n\n /*Decorator*/\n IReady maleReady = new Male();\n Console.WriteLine(\"now male is going to get ready himself\");\n maleReady.GetReady();\n\n Console.WriteLine(Environment.NewLine);\n\n IReady femaleReady = new Female();\n Console.WriteLine(\"now female is going to get ready her self\");\n femaleReady.GetReady();\n\n Console.WriteLine(Environment.NewLine);\n\n IReady maleReadyByBeautician = new Beautician(maleReady);\n Console.WriteLine(\"now male is going to get ready by beautician\");\n maleReadyByBeautician.GetReady();\n\n Console.WriteLine(Environment.NewLine);\n\n IReady femaleReadyByBeautician = new Beautician(femaleReady);\n Console.WriteLine(\"now female is going to get ready by beautician\");\n femaleReadyByBeautician.GetReady();\n\n Console.WriteLine(Environment.NewLine);\n\n Console.ReadLine();\n\n\n }\n }\n\n /*Proxy*/\n\n public interface IReal\n {\n void DoWork();\n }\n\n public class Real : IReal\n {\n public void DoWork()\n {\n Console.WriteLine(\"real is doing work \");\n }\n }\n\n\n public class RealProxy : IReal\n {\n IReal real = new Real();\n\n public void DoWork()\n {\n real.DoWork();\n }\n }\n\n /*Adapter*/\n\n public interface IActual\n {\n void DoWork();\n }\n\n public class Api\n {\n public void SomeApi(IActual actual)\n {\n actual.DoWork();\n }\n }\n\n public interface IInHand\n {\n void DoWorkDifferently();\n }\n\n public class InHand : IInHand\n {\n public void DoWorkDifferently()\n {\n Console.WriteLine(\"doing work slightly different \");\n }\n }\n\n public class ActualAdapterForInHand : IActual\n {\n IInHand hand = null;\n\n public ActualAdapterForInHand()\n {\n hand = new InHand();\n }\n\n public ActualAdapterForInHand(IInHand hnd)\n {\n hand = hnd;\n }\n\n public void DoWork()\n {\n hand.DoWorkDifferently();\n }\n }\n\n /*Decorator*/\n\n public interface IReady\n {\n void GetReady();\n }\n\n public class Male : IReady\n {\n public void GetReady()\n {\n Console.WriteLine(\"Taking bath.. \");\n Console.WriteLine(\"Dress up....\");\n }\n }\n\n public class Female : IReady\n {\n public void GetReady()\n {\n Console.WriteLine(\"Taking bath.. \");\n Console.WriteLine(\"Dress up....\");\n Console.WriteLine(\"Make up....\");\n }\n }\n\n //this is a decorator\n public class Beautician : IReady\n {\n IReady ready = null;\n\n public Beautician(IReady rdy)\n {\n ready = rdy;\n }\n\n public void GetReady()\n {\n ready.GetReady();\n Console.WriteLine(\"Style hair \");\n\n if (ready is Female)\n {\n for (int i = 1; i <= 10; i++)\n {\n Console.WriteLine(\"doing ready process \" + i);\n }\n\n }\n }\n }\n\n}\n"
},
{
"answer_id": 35089112,
"author": "Ravindra babu",
"author_id": 4999394,
"author_profile": "https://Stackoverflow.com/users/4999394",
"pm_score": 4,
"selected": false,
"text": "java.io InputStream OutputStream FileOutputStream fos1 = new FileOutputStream(\"data1.txt\"); \nObjectOutputStream out1 = new ObjectOutputStream(fos1);\n java.rmi java.io.InputStreamReader InputStream Reader java.util List ArrayList"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7705/"
] |
350,419 | <p>Most C++ naming conventions dictate the use of <code>camelCaseIdentifiers</code>: names that start with an uppercase letter for classes (<code>Person</code>, <code>Booking</code>) and names that start with a lowercase letter for fields and variables (<code>getPrice()</code>, <code>isValid()</code>, <code>largestValue</code>). These recommendations are completely at odds with the naming conventions of the C++ library, which involve lowercase names for classes (<code>string</code>, <code>set</code>, <code>map</code>, <code>fstream</code>) and <code>names_joined_with_an_underscore</code> for methods and fields (<code>find_first_of</code>, <code>lower_bound</code>, <code>reverse_iterator</code>, <code>first_type</code>). Further complicating the picture are operating system and C library functions, which involve compressed lowercase names in C and Unix and functions starting with an uppercase letter in Windows.</p>
<p>As a result my code is a mess, because some identifiers use the C++ library, C, or operating system naming convention, and others use the prescribed C++ convention. Writing classes or methods that wrap functionality of the library is painful, because one ends with different-style names for similar things.</p>
<p>So, how do you reconcile these disparate naming conventions?</p>
| [
{
"answer_id": 350448,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 5,
"selected": true,
"text": "naming_convention m_"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20520/"
] |
350,429 | <p>I'm working on an older classic ASP site, and there's a form that allows the user to enter some text (into a multiline textbox), and if they add an html character like ® (register trademark) it inserts it correctly. But when they go to edit the data, using the same form, the update will add a random 'Â' (circumflex accent) in front of the registered trademark. The content type is utf-8. </p>
<p>Any ideas?</p>
<p>Thanks for any time you give this. It's been driving me nuts.
-m</p>
| [
{
"answer_id": 350437,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": "© ©"
},
{
"answer_id": 351166,
"author": "mercator",
"author_id": 23263,
"author_profile": "https://Stackoverflow.com/users/23263",
"pm_score": 0,
"selected": false,
"text": "meta"
},
{
"answer_id": 352393,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 4,
"selected": false,
"text": "Response.Codepage"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,433 | <p>I admit that I am not a guru of Visual Studio products at all. I am using Visual Web Developer 2005 Express Edition and I'm trying to load someone else's project.</p>
<p>This project happens to be a website with many pages.</p>
<p>After loading VWD, it asks for a project to open and I select the solution file. It then proceeds to take an extremely long time to load. The status bar indicates that references are being loaded, many of which are in the System.Web.* area it seems. It seems like it's going back and forth between some different packages. The loading time is upwards of 20 to 30 minutes or more. Some others have stated that their projects open fine when they go to File > Open Website... and choose the project directory from there. Any ideas what the problem could be and how to fix it?</p>
<p>Edit: It finally completed loading after an hour approximately.</p>
| [
{
"answer_id": 350437,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": "© ©"
},
{
"answer_id": 351166,
"author": "mercator",
"author_id": 23263,
"author_profile": "https://Stackoverflow.com/users/23263",
"pm_score": 0,
"selected": false,
"text": "meta"
},
{
"answer_id": 352393,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 4,
"selected": false,
"text": "Response.Codepage"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20471/"
] |
350,453 | <p>I want something similar to the following pseudocode:</p>
<pre><code>myGridView.SelectedIndex = myGridView.DataKeys.IndexOf("mySpecificKey");
</code></pre>
<p>I've done some Intellisense exploring, but I haven't found an obvious way to do this. I would want to set SelectedIndex to -1 if DataKey was not found.</p>
| [
{
"answer_id": 350477,
"author": "Larsenal",
"author_id": 337,
"author_profile": "https://Stackoverflow.com/users/337",
"pm_score": 5,
"selected": true,
"text": " For n As Integer = 0 To myGridView.DataKeys.Count - 1\n If myGridView.DataKeys(n).Value = myKeyObj Then\n myGridView.SelectedIndex = n\n End If\n Next\n"
},
{
"answer_id": 1534393,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "//grab the current datakeyValue\n int orderID = (int)this.GridView1.SelectedDataKey.Value;\n\n//do something \ngridView.databind();\n\n//set back the selected row int the gridView\n for (int i = 0; i <= this.GridView1.DataKeys.Count - 1; i++)\n {\n if ((int)GridView1.DataKeys[i].Value == orderID)\n {\n this.GridView1.SelectedIndex = i;\n }\n}\n"
},
{
"answer_id": 1882197,
"author": "Mark Good",
"author_id": 97276,
"author_profile": "https://Stackoverflow.com/users/97276",
"pm_score": 3,
"selected": false,
"text": "GridView1.SelectedIndex = GridView1.DataKeys.IndexOf(id);\n public static class WebControlsEx\n{\n public static int IndexOf(this DataKeyArray dataKeyArray, object value)\n {\n if (dataKeyArray.Count < 1) throw new InvalidOperationException(\"DataKeyArray contains no elements.\");\n var keys = dataKeyArray.Cast<DataKey>().ToList();\n var key = keys.SingleOrDefault(k => k.Value.Equals(value));\n if (key == null) return -1;\n return keys.IndexOf(key);\n }\n}\n"
},
{
"answer_id": 2019816,
"author": "Phil",
"author_id": 245455,
"author_profile": "https://Stackoverflow.com/users/245455",
"pm_score": 2,
"selected": false,
"text": " Dim i As Integer, DataSetIndex As Integer\n Dim SelectedRowIndex As Integer\n Dim dv As DataView = ObjectDataSourceClients.Select\n Dim dt As DataTable = dv.ToTable\n\n For i = 0 To dt.Rows.Count - 1\n If dt.Rows(i)(\"Client_ID\") = ComboBoxClientSearch.SelectedValue Then\n DataSetIndex = i\n Exit For\n End If\n Next\n\n GridViewAllClients.PageIndex = DataSetIndex \\ GridViewAllClients.PageSize\n SelectedRowIndex = DataSetIndex - (GridViewAllClients.PageSize * GridViewAllClients.PageIndex)\n GridViewAllClients.SelectedIndex = SelectedRowIndex\n\n GridViewAllClients.DataBind()\n"
},
{
"answer_id": 4439863,
"author": "NightOwl888",
"author_id": 181087,
"author_profile": "https://Stackoverflow.com/users/181087",
"pm_score": 0,
"selected": false,
"text": "Dim p As Catalog.Product = CType(e.Row.DataItem, Catalog.Product)\nIf p IsNot Nothing Then\n\n If p.Bvin = MySpecificID Then\n e.Row.RowState = DataControlRowState.Selected\n End If\n\nEnd If\n"
},
{
"answer_id": 6690088,
"author": "Buchi",
"author_id": 844076,
"author_profile": "https://Stackoverflow.com/users/844076",
"pm_score": 2,
"selected": false,
"text": "grdMyGrid.SelectedIndex = grdMyGrid.DataKeys.OfType<DataKey>().ToList<DataKey>().FindIndex(dk => (string)dk.Value == \"myKey\");\n"
},
{
"answer_id": 10075761,
"author": "nick5454",
"author_id": 1322189,
"author_profile": "https://Stackoverflow.com/users/1322189",
"pm_score": 2,
"selected": false,
"text": "grdLocations.SelectedIndex = -1;\n\n bool found = false;\n int index = 0;\n int pageIndex = 0;\n for (int i = 0; i < grdLocations.PageCount; i++)\n {\n for (index = 0; index < grdLocations.DataKeys.Count; index++)\n {\n if (Convert.ToInt32(grdLocations.DataKeys[index].Value.ToString()) == Convert.ToInt32(hidCurrentRigId.Value))\n {\n found = true;\n break;\n }\n }\n\n if (found)\n break;\n\n pageIndex++;\n grdLocations.PageIndex = pageIndex;\n grdLocations.DataBind();\n }\n\n if (found)\n {\n grdLocations.PageIndex = pageIndex;\n grdLocations.SelectedIndex = index;\n }\n class Program\n{\n static void Main(string[] args)\n {\n int rowIndex = 27;\n int pageCount = 7;\n int currentPage = 3;\n int pageSize = 10;\n\n Console.WriteLine(\"Page = \" + (rowIndex / pageSize).ToString());\n Console.WriteLine(\"Row = \" + ( rowIndex % pageSize).ToString());\n Console.ReadLine();\n }\n}\n"
},
{
"answer_id": 18223753,
"author": "tkaragiris",
"author_id": 2681078,
"author_profile": "https://Stackoverflow.com/users/2681078",
"pm_score": 3,
"selected": false,
"text": " int MyId = 22;\n\n foreach (GridViewRow gvRow in gridview1.Rows)\n {\n if ((int)gridview1.DataKeys[gvRow.DataItemIndex].Value == MyId)\n {\n gridview1.SelectedIndex = gvRow.DataItemIndex;\n break;\n }\n }\n"
},
{
"answer_id": 27546224,
"author": "alansiqueira27",
"author_id": 375422,
"author_profile": "https://Stackoverflow.com/users/375422",
"pm_score": 0,
"selected": false,
"text": "gridView.SelectedIndex = gridViewRowToBeSelected.RowIndex;\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350453",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/337/"
] |
350,454 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c-sharp">How to properly clean up Excel interop objects in C#</a> </p>
</blockquote>
<p>I've read many of the other threads here about managing COM references while using the .Net-Excel interop to make sure the Excel process exits correctly upon exit, and so far the techniques have been working very well, but I recently came across a problem when adding new worksheets to an existing workbook file.</p>
<p>The code below leaves a zombie Excel process. </p>
<p>If I add a worksheet to a newly created workbook file, it exits fine. If I run the code excluding the <code>.Add()</code> line, it exits fine. (The existing file I'm reading from is an empty file created by the commented out code)</p>
<p>Any ideas?</p>
<pre><code>//using Excel = Microsoft.Office.Interop.Excel;
//using System.Runtime.InteropServices;
public static void AddTest()
{
string filename = @"C:\addtest.xls";
object m = Type.Missing;
Excel.Application excelapp = new Excel.Application();
if (excelapp == null) throw new Exception("Can't start Excel");
Excel.Workbooks wbs = excelapp.Workbooks;
//if I create a new file and then add a worksheet,
//it will exit normally (i.e. if you uncomment the next two lines
//and comment out the .Open() line below):
//Excel.Workbook wb = wbs.Add(Excel.XlWBATemplate.xlWBATWorksheet);
//wb.SaveAs(filename, m, m, m, m, m,
// Excel.XlSaveAsAccessMode.xlExclusive,
// m, m, m, m, m);
//but if I open an existing file and add a worksheet,
//it won't exit (leaves zombie excel processes)
Excel.Workbook wb = wbs.Open(filename,
m, m, m, m, m, m,
Excel.XlPlatform.xlWindows,
m, m, m, m, m, m, m);
Excel.Sheets sheets = wb.Worksheets;
//This is the offending line:
Excel.Worksheet wsnew = sheets.Add(m, m, m, m) as Excel.Worksheet;
//N.B. it doesn't help if I try specifying the parameters in Add() above
wb.Save();
wb.Close(m, m, m);
//overkill to do GC so many times, but shows that doesn't fix it
GC();
//cleanup COM references
//changing these all to FinalReleaseComObject doesn't help either
while (Marshal.ReleaseComObject(wsnew) > 0) { }
wsnew = null;
while (Marshal.ReleaseComObject(sheets) > 0) { }
sheets = null;
while (Marshal.ReleaseComObject(wb) > 0) { }
wb = null;
while (Marshal.ReleaseComObject(wbs) > 0) { }
wbs = null;
GC();
excelapp.Quit();
while (Marshal.ReleaseComObject(excelapp) > 0) { }
excelapp = null;
GC();
}
public static void GC()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
}
</code></pre>
| [
{
"answer_id": 350535,
"author": "Andrew Rollings",
"author_id": 40410,
"author_profile": "https://Stackoverflow.com/users/40410",
"pm_score": 3,
"selected": true,
"text": "GetWindowThreadProcessId Process.GetProcessById Kill Kill Close Kill"
},
{
"answer_id": 356567,
"author": "Jon",
"author_id": 6486,
"author_profile": "https://Stackoverflow.com/users/6486",
"pm_score": 4,
"selected": false,
"text": " workbook.Close(true, null, null);\n excelApp.Quit();\n\n if (newSheet != null)\n {\n System.Runtime.InteropServices.Marshal.ReleaseComObject(newSheet);\n }\n if (rangeSelection != null)\n {\n System.Runtime.InteropServices.Marshal.ReleaseComObject(rangeSelection);\n }\n if (sheets != null)\n {\n System.Runtime.InteropServices.Marshal.ReleaseComObject(sheets);\n }\n if (workbook != null)\n {\n System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);\n }\n if (excelApp != null)\n {\n System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);\n }\n\n newSheet = null;\n rangeSelection = null;\n sheets = null;\n workbook = null;\n excelApp = null;\n\n GC.Collect();\n"
},
{
"answer_id": 565708,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " xlWorkbook.Close(SaveChanges:=False)\n xlApplication.Quit()\n\n System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange)\n System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorksheet)\n System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets)\n System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook)\n System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication)\n\n xlRange = Nothing\n xlWorksheet = Nothing\n xlSheets = Nothing\n xlWorkbook = Nothing\n xlApplication = Nothing\n\n GC.GetTotalMemory(False)\n GC.Collect()\n GC.WaitForPendingFinalizers()\n\n GC.Collect()\n GC.WaitForPendingFinalizers()\n GC.Collect()\n GC.GetTotalMemory(True)\n"
},
{
"answer_id": 650727,
"author": "Kenny Mann",
"author_id": 18217,
"author_profile": "https://Stackoverflow.com/users/18217",
"pm_score": 0,
"selected": false,
"text": "namespace WindowHandler\n{\nusing System;\nusing System.Text;\nusing System.Collections;\nusing System.Runtime.InteropServices;\n\n/// <summary>\n/// Window class for handling window stuff.\n/// This is really a hack and taken from Code Project and mutilated to this small thing.\n/// </summary>\npublic class Window\n{\n /// <summary>\n /// Win32 API import for getting the process Id.\n /// The out param is the param we are after. I have no idea what the return value is.\n /// </summary>\n [DllImport(\"user32.dll\")]\n private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out IntPtr ProcessId);\n\n /// <summary>\n /// Gets a Window's process Id.\n /// </summary>\n /// <param name=\"hWnd\">Handle Id.</param>\n /// <returns>ID of the process.</returns>\n public static IntPtr GetWindowThreadProcessId(IntPtr hWnd)\n {\n IntPtr processId;\n IntPtr returnResult = GetWindowThreadProcessId(hWnd, out processId);\n\n return processId;\n }\n}\n}\n"
},
{
"answer_id": 2273939,
"author": "AlanR",
"author_id": 7311,
"author_profile": "https://Stackoverflow.com/users/7311",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Runtime.InteropServices;\nusing System.Diagnostics;\nusing Microsoft.Office.Interop.Excel;\n\nclass Program\n{\n\n /// <summary> \n /// Win32 API import for getting the process Id. \n /// The out param is the param we are after. I have no idea what the return value is. \n /// </summary> \n [DllImport(\"user32.dll\")]\n private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out IntPtr ProcessId); \n\n static void Main(string[] args)\n {\n var app = new Application();\n IntPtr hwnd = new IntPtr(app.Hwnd);\n IntPtr processId;\n IntPtr foo = GetWindowThreadProcessId(hwnd, out processId);\n Process proc = Process.GetProcessById(processId.ToInt32());\n proc.Kill(); // set breakpoint here and watch the Windows Task Manager kill this exact EXCEL.EXE\n app.Quit(); // should give you a \"Sorry, I can't find this Excel session since you killed it\" Exception.\n }\n}\n"
},
{
"answer_id": 7002949,
"author": "io.gun",
"author_id": 857834,
"author_profile": "https://Stackoverflow.com/users/857834",
"pm_score": 1,
"selected": false,
"text": "Public Class ExcelHlpr\n\n Declare Function EndTask Lib \"user32.dll\" (ByVal hWnd As IntPtr, ByVal ShutDown As Boolean, ByVal Force As Boolean) As Integer\n\n Dim cXlApp As Microsoft.Office.Interop.Excel.Application\n\n Public Function GetExcel() As Microsoft.Office.Interop.Excel.Application\n cXlApp = New Microsoft.Office.Interop.Excel.Application\n Return cXlApp\n End Function\n\n Public Function EndExcel() As Integer\n Dim xlHwnd As New IntPtr(cXlApp.Hwnd)\n Return EndTask(xlHwnd, False, True)\n End Function\n\nEnd Class\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25571/"
] |
350,470 | <p>I've been looking for profiling tools for Rails for a while. I'm currently playing and testing ruby-prof and railsbench, but I kinda frustrated with the amount of tweaking and mangling required to make then work.</p>
<p>Althought I don't mind (much) the tweaking, I'd like to know if is there any other, more straight-forward and easy to use, tools to profile a Rails app? Which tools you recommend?</p>
| [
{
"answer_id": 356092,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 5,
"selected": false,
"text": "$ ruby script/performance/profiler 'User.new' 5\n % cumulative self self total\n time seconds seconds calls ms/call ms/call name\n189.25 1.76 1.76 1 1760.00 1760.00 Profiler__.start_profile\n 43.01 2.16 0.40 115 3.48 3.91 ActiveRecord::ConnectionAdapters::Column#simplified_type\n 8.60 2.24 0.08 15 5.33 8.67 Array#each\n 7.53 2.31 0.07 115 0.61 5.39 ActiveRecord::ConnectionAdapters::Column#initialize\n 6.45 2.37 0.06 115 0.52 0.52 ActiveRecord::ConnectionAdapters::Column#type_cast\n 5.38 2.42 0.05 690 0.07 0.07 Regexp#===\n 0.00 2.69 0.00 10 0.00 0.00 Process.times\n 0.00 2.69 0.00 10 0.00 0.00 Benchmark.times\n rails profiler"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20875/"
] |
350,482 | <p>Based on the answers to <a href="https://stackoverflow.com/questions/350081/how-do-i-supply-the-from-clause-of-a-select-statement-from-a-udf-parameter">this question about dynamically accessing tables</a>, I've decided to take a couple steps back and get some advice on the larger picture. </p>
<p>I am revisiting the database design of a Windows Forms application which I am rewriting for the Web using ASP.NET. Also, I have ported our database to Sql Server, so it can handle more traffic, as the Access database is already getting overburdened. So, as a result of seeing what SQL Server can do, I have been revisiting my database design decisions, and their effect on my user interface design.</p>
<p>Currently, the windows interface displays a list of recent codes:</p>
<pre><code>02691 AFF1
32391 Lot# 23
</code></pre>
<p>and so on.</p>
<p>For each code there is a record in a Productions table that starts with:</p>
<pre><code>ProductionCode varchar(80),
Template varchar(50),
...
</code></pre>
<p>The template represents one of a number of tables, and also a foreign key into template field definitions. All of this information is used to build the DataGrid dynamically, starting from a code.</p>
<p>There is the ScoreField table, which represents all the fields in all the templates, except ProductionCode (which is in all of them as a foreign key).</p>
<pre><code>ScoreField
Template varchar(50)
Field varchar(50)
Formatting varchar(50) // This is a .NET style formatting string, say 0.00 or ##
...
</code></pre>
<p>Then there are the Template tables themselves, which hold a ProductionCode, a Time for each test, and whatever data was collected by the test.</p>
<p>So to create my datagrid, on the fly, I start by</p>
<pre><code>SELECT * FROM ProductionRun WHERE ProductionCode = @Code
</code></pre>
<p>In reality, I just get the one result, or abort the process if no results are obtained.</p>
<p>Where the code is the code string selected by the user (using a drop down, not something vunerable to injection)</p>
<p>Then I do:</p>
<pre><code>SELECT * FROM ScoreField WHERE Template = @Template
</code></pre>
<p>Where @Template is actually, the Template field value for the one record of ProductionRun returned.</p>
<p>Then I do:</p>
<pre><code>SELECT * FROM @Template WHERE ProductionCode = @Code
</code></pre>
<p>But actually, I just concatenate the Template name I got in part one.</p>
<p>and then I use the result from ScoreField to add columns for each matching result and set up the formatting, et all.</p>
<p>But of course, as a result of doing this all at run time, I don't get to use databinding, and have to programmatically fill in all my data.</p>
<p>So, with this database revisit, I'm looking for another, better approach. I've got data in different tables, and I want to apply formatting to the data, and be able to do it all within one interface, instead of forcing the user to guess what template their data is in. I want to be able to add templates without screwing up the system too much.</p>
<p>Obviously, this is not a simple programming question, but more a question of best practices, but I was looking for some inspiration and/or examples to get me started down a different path.</p>
| [
{
"answer_id": 356092,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 5,
"selected": false,
"text": "$ ruby script/performance/profiler 'User.new' 5\n % cumulative self self total\n time seconds seconds calls ms/call ms/call name\n189.25 1.76 1.76 1 1760.00 1760.00 Profiler__.start_profile\n 43.01 2.16 0.40 115 3.48 3.91 ActiveRecord::ConnectionAdapters::Column#simplified_type\n 8.60 2.24 0.08 15 5.33 8.67 Array#each\n 7.53 2.31 0.07 115 0.61 5.39 ActiveRecord::ConnectionAdapters::Column#initialize\n 6.45 2.37 0.06 115 0.52 0.52 ActiveRecord::ConnectionAdapters::Column#type_cast\n 5.38 2.42 0.05 690 0.07 0.07 Regexp#===\n 0.00 2.69 0.00 10 0.00 0.00 Process.times\n 0.00 2.69 0.00 10 0.00 0.00 Benchmark.times\n rails profiler"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26140/"
] |
350,492 | <p>As an example these are some of the things I always do when starting a new machine:</p>
<ol>
<li>Install 'Visor' - gives you an always available HUD style terminal window via F1. </li>
<li>Install 'Clix' - run a million system customization command line instructions. </li>
<li>Install 'Default App' - self explanatory. </li>
<li>Set 'Terminal.app' to open and be hidden automatically on login.</li>
<li>Install 'Inconsolata' font and set it as default font for Terminal and Text Edit.</li>
</ol>
<p>Only after those basic steps are taken can I start in on the more personal stuff.</p>
<p><strong>So, what are the essential steps you take when faced with a blank macSlate?</strong></p>
<p><em>NB: Yes, this question is inspired by <a href="https://stackoverflow.com/questions/344468/as-a-developer-what-changes-do-you-make-to-a-vanilla-windows-install">@Roddy's question</a> targeting the Windows platform.</em></p>
<p><strong>UPDATE:</strong> This is great, thank you! Some very interesting answers so far.</p>
<p><strong><em>Concrete Results:</em></strong> I am now a MacPorts convert, and my Terminal uses standard word left, word right, key command behavior...</p>
<p><strong>UPDATE 2:</strong> I forgot to mention <a href="http://www.charlesproxy.com/" rel="nofollow noreferrer">Charles</a>, the greatest debugging http proxy app in the world (IMHO). It's shareware and 100% worthy of the name.</p>
| [
{
"answer_id": 351634,
"author": "amrox",
"author_id": 4468,
"author_profile": "https://Stackoverflow.com/users/4468",
"pm_score": 3,
"selected": true,
"text": "defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES defaults write com.apple.Safari IncludeDebugMenu ~/Build ~/Build/_Intermediate defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME = \"Yoyodyne Industries\";}'"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10875/"
] |
350,500 | <p>I did not find the TryParse method for the Guid. I’m wondering how others handle converting a guid in string format into a guid type.</p>
<pre><code>Guid Id;
try
{
Id = new Guid(Request.QueryString["id"]);
}
catch
{
Id = Guid.Empty;
}
</code></pre>
| [
{
"answer_id": 350504,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 9,
"selected": false,
"text": "new Guid(string)\n TypeConverter"
},
{
"answer_id": 357074,
"author": "Brian Rudolph",
"author_id": 33114,
"author_profile": "https://Stackoverflow.com/users/33114",
"pm_score": 3,
"selected": false,
"text": " public static bool GuidTryParse(string s, out Guid result)\n {\n if (!String.IsNullOrEmpty(s) && guidRegEx.IsMatch(s))\n {\n result = new Guid(s);\n return true;\n }\n\n result = default(Guid);\n return false;\n }\n\n static Regex guidRegEx = new Regex(\"^[A-Fa-f0-9]{32}$|\" +\n \"^({|\\\\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\\\\))?$|\" +\n \"^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$\", RegexOptions.Compiled);\n"
},
{
"answer_id": 3168519,
"author": "Brian Balamut",
"author_id": 382342,
"author_profile": "https://Stackoverflow.com/users/382342",
"pm_score": 0,
"selected": false,
"text": " string guidStr = \"\";\n if( guidStr.Length == Guid.Empty.ToString().Length )\n Guid g = new Guid( guidStr );\n"
},
{
"answer_id": 10193141,
"author": "juFo",
"author_id": 187650,
"author_profile": "https://Stackoverflow.com/users/187650",
"pm_score": 5,
"selected": false,
"text": "Guid.TryParse()\n Guid.TryParseExact()\n"
},
{
"answer_id": 14358623,
"author": "Behrooz",
"author_id": 829920,
"author_profile": "https://Stackoverflow.com/users/829920",
"pm_score": 7,
"selected": false,
"text": "new Guid(\"9D2B0228-4D0D-4C23-8B49-01A698857709\")\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19216/"
] |
350,502 | <p>If an object has a property that is a collection, should the object create the collection object or make a consumer check for null? I know the consumer should not assume, just wondering if most people create the collection object if it is never added to.</p>
| [
{
"answer_id": 350585,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 4,
"selected": true,
"text": " public class Division\n {\n private int divId;\n public int DivisionId { get; set; }\n\n private Collection<Employee> emps;\n public Collection<Employee> Employees\n { get {return emps?? (emps = new Collection<Employee>(DivisionId));}} \n }\n"
},
{
"answer_id": 350596,
"author": "Bent André Solheim",
"author_id": 44380,
"author_profile": "https://Stackoverflow.com/users/44380",
"pm_score": 0,
"selected": false,
"text": "public void setSomeCollection(Collection someCollection) {\n this.someCollection.clear();\n this.someCollection.addAll(someCollection);\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11907/"
] |
350,505 | <p>I am building ASP.NET 2.0 websites and currently I some home grown assemblies for a DAL, some business objects and other assorted shared stuff. I've put together a basic set of objects to handle messages to the UI (i.e. errors and other status messaging). It consists of: </p>
<ul>
<li><p><strong>StatusMessage</strong> which has a text property and a color property to describe the message to display. It also has a static Send method which creates an instance of itself and puts it in a Session variable.</p></li>
<li><p><strong>StatusMessageDisplay</strong> which is basically a Label object with the Refresh method overridden to grab the StatusMessage from the session, clear the Session variable and display the message.</p></li>
</ul>
<p>Overall this has worked fairly well. However, there are a few things I don't like about it:</p>
<ol>
<li><p>It can only handle a single message at a time, if two messages are sent before they are displayed, the first is lost. I could make a list of messages to display but I'm not sure I want to start building lists in the Session object.</p></li>
<li><p>It's tied to Session and therefore HttpContext. I try not to put much into the Session object and HttpContext is difficult to work with for testing. Currently I'm wrapping HttpContext in another object I can mock for testing. </p></li>
<li><p>In my current implementation, if a message is passed from an AJAX request the message displays late (next sync'd request) since the StatusMessageDisplay control is not AJAX aware/triggered.</p></li>
</ol>
<p>Before I start building on what I have to fix these issues I would like to find out what others have found useful for doing this. What I would really like is something that behaves like the flash object in Rails or maybe a better alternative?</p>
| [
{
"answer_id": 350528,
"author": "Zote",
"author_id": 20683,
"author_profile": "https://Stackoverflow.com/users/20683",
"pm_score": 2,
"selected": true,
"text": "List<StatusMessage>"
},
{
"answer_id": 350575,
"author": "configurator",
"author_id": 9536,
"author_profile": "https://Stackoverflow.com/users/9536",
"pm_score": 0,
"selected": false,
"text": "UpdatePanel RenderMode Always"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2035722/"
] |
350,507 | <p>I noticed that I can start a program with it's associated handler by writing <strong>start filename</strong>. However, for some files, all I get is a console, and I don't know why. I'm trying to populate a list control in MFC, and I want to have the program and it's associated handler to run when I double click the selection. Is there a better way, or an explanation to why this doesn't work?<br>
This is the code that could be the problem:</p>
<p><pre><code>
int selection = listControl.GetCurSel();
CString text;
listControl.GetText(selection,text);
string std_str = StringUtils::CStringToString(text);
string st = string("start \"")+std_str+string("\"");
const char* command = st.c_str();
system(command);
</pre></code></p>
| [
{
"answer_id": 350545,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 4,
"selected": true,
"text": "start string st = string(\"start \\\"\\\" \\\"\")+std_str+string(\"\\\"\");\n start ShellExecute() ShellExecuteEx()"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] |
350,519 | <p>I need to get the lesser n numbers of a list in Python. I need this to be really fast because it's in a critical part for performance and it needs to be repeated a lot of times.</p>
<p>n is usually no greater than 10 and the list usually has around 20000 elements. The list is always different each time I call the function. Sorting can't be made in place.</p>
<p>Initially, I have written this function:</p>
<pre><code>def mins(items, n):
mins = [float('inf')]*n
for item in items:
for i, min in enumerate(mins):
if item < min:
mins.insert(i, item)
mins.pop()
break
return mins
</code></pre>
<p>But this function can't beat a simple sorted(items)[:n] which sort the entire list. Here is my test:</p>
<pre><code>from random import randint, random
import time
test_data = [randint(10, 50) + random() for i in range(20000)]
init = time.time()
mins = mins(test_data, 8)
print 'mins(items, n):', time.time() - init
init = time.time()
mins = sorted(test_data)[:8]
print 'sorted(items)[:n]:', time.time() - init
</code></pre>
<p>Results:</p>
<pre><code>mins(items, n): 0.0632939338684
sorted(items)[:n]: 0.0231449604034
</code></pre>
<p>sorted()[:n] is three times faster. I believe this is because:</p>
<ol>
<li>insert() operation is costly because Python lists are not linked lists.</li>
<li>sorted() is an optimized c function and mine is pure python.</li>
</ol>
<p>Is there any way to beat sorted()[:n] ?
Should I use a C extension, or Pyrex or Psyco or something like that?</p>
<p>Thanks in advance for your answers.</p>
| [
{
"answer_id": 350568,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 5,
"selected": true,
"text": "mins = items[:n]\nmins.sort()\nfor i in items[n:]:\n if i < mins[-1]: \n mins.append(i)\n mins.sort()\n mins= mins[:n]\n mins(items, n): 0.297000169754\nsorted(items)[:n]: 0.109999895096\nmins2(items)[:n]: 0.0309998989105\n bisect.insort"
},
{
"answer_id": 350578,
"author": "fredreichbier",
"author_id": 44384,
"author_profile": "https://Stackoverflow.com/users/44384",
"pm_score": 2,
"selected": false,
"text": "import bisect\n\ndef mins(items, n):\n mins = [float('inf')]*n\n for item in items:\n bisect.insort(mins, item)\n mins.pop()\n return mins\n mins(items, n): 0.0892250537872\nsorted(items)[:n]: 0.0990262031555\n import bisect\nimport psyco\npsyco.full()\n\ndef mins(items, n):\n mins = [float('inf')]*n\n for item in items:\n bisect.insort(mins, item)\n mins.pop()\n return mins\n mins(items, n): 0.0431621074677\nsorted(items)[:n]: 0.0859830379486\n"
},
{
"answer_id": 350685,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 4,
"selected": false,
"text": "import heapq\n\nnlesser_items = heapq.nsmallest(n, items)\n from bisect import insort\nfrom itertools import islice\n\ndef nsmallest_slott_bisect(n, iterable, insort=insort):\n it = iter(iterable)\n mins = sorted(islice(it, n))\n for el in it:\n if el <= mins[-1]: #NOTE: equal sign is to preserve duplicates\n insort(mins, el)\n mins.pop()\n\n return mins\n $ python -mtimeit -s \"import marshal; from nsmallest import nsmallest$label as nsmallest; items = marshal.load(open('items.marshal','rb')); n = 10\"\\\n \"nsmallest(n, items)\"\n nsmallest_slott_bisect heapq nsmallest nsmallest_slott_list"
},
{
"answer_id": 22357180,
"author": "qdpercy",
"author_id": 2985321,
"author_profile": "https://Stackoverflow.com/users/2985321",
"pm_score": 0,
"selected": false,
"text": "import random\nimport numpy as np\ndef select(data, n):\n \"Find the nth rank ordered element (the least value has rank 0).\"\n data = list(data)\n if not 0 <= n < len(data):\n raise ValueError('not enough elements for the given rank')\n while True:\n pivot = random.choice(data)\n pcount = 0\n under, over = [], []\n uappend, oappend = under.append, over.append\n for elem in data:\n if elem < pivot:\n uappend(elem)\n elif elem > pivot:\n oappend(elem)\n else:\n pcount += 1\n if n < len(under):\n data = under\n elif n < len(under) + pcount:\n return pivot\n else:\n data = over\n n -= len(under) + pcount\n\n\ndef n_lesser(data,n):\n data_nth = select(data,n)\n ind = np.where(data<data_nth)\n return data[ind]\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23657/"
] |
350,526 | <p>Every now and then, I accidentally hit C-x C-c in Emacs when I'm intending to just hit C-x or C-c. This, of course, closes all open frames and buffers with no confirmation. I know that I can make Emacs prompt "Are you sure you want to exit?", but I don't want to do that all the time, which would get annoying. I just want it to do it when there are more than N files (or buffers) open.</p>
<p>So I'd like to bind C-x C-c to a function along the lines of:</p>
<pre><code>(if (< number of open buffers n)
(save-buffers-kill-emacs)
(are-you-sure))
</code></pre>
<p>But I can't figure out how to get the number of open buffers (or the number of open frames, or the number of open files, etc).</p>
| [
{
"answer_id": 350607,
"author": "JasonFruit",
"author_id": 21778,
"author_profile": "https://Stackoverflow.com/users/21778",
"pm_score": 3,
"selected": false,
"text": "(defun count-buffers (&optional display-anyway)\n \"Display or return the number of buffers.\"\n (interactive)\n (let ((buf-count (length (buffer-list))))\n (if (or (interactive-p) display-anyway)\n (message \"%d buffers in this Emacs\" buf-count)) buf-count))\n"
},
{
"answer_id": 350898,
"author": "ShreevatsaR",
"author_id": 4958,
"author_profile": "https://Stackoverflow.com/users/4958",
"pm_score": 2,
"selected": false,
"text": "(desktop-save-mode 1)\n .emacs"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91385/"
] |
350,539 | <p>I'm writing a C# application for a proprietary Windows CE 4.2 device (for which I don't have the specs or pretty much any other information. I've got access to the file system, and that is basically it.)
I also can't get support from the original manufacturer.</p>
<p>Now, I can install the .NET Compact framework just fine, and everything works for a while. But every once in a while, when the device is reset, it <em>deletes</em> the framework, the GAC, everything related to it.</p>
<p>I know it's not just a hard reset jumping back to factory defaults because:</p>
<ol>
<li>It remembers the registry settings (If I try to install again, it says the framework is already installed, and asks if I want to reinstall. So obviously the registry keys are still there)</li>
<li>The files are deleted even if I installed the framework onto a removable flash card. (Other files on the storage card are left alone, however)</li>
</ol>
<p>I know there isn't much to go on, but perhaps some Windows CE guru will be able to tell me why this happens, and if there's some sane way to avoid it. I don't know much about Windows CE, so for all I know, it might be perfectly standard behavior.</p>
<p>For that matter, any advice on how to troubleshoot this further myself? At the moment, the best solution I can see is to simply reinstall everything at every boot, but that seems a bit clumsy.</p>
<p><strong>Edit:</strong>
After a reset, GACLOG.TXT found in the root of the filesystem contains</p>
<blockquote>
<p>CGACUTIL: Initializing 12/08/2008</p>
<p>20:43:57.000 CGACUTIL: Initialized</p>
<p>12/08/2008 20:43:57.000 CGACUTIL:</p>
<p><strong>Removing Microsoft .NET CF 3.5.GAC</strong></p>
<p>12/08/2008 20:43:57.000 CGACUTIL: Done</p>
<p>12/08/2008 20:43:57.000 CGACUTIL:</p>
<p>Exiting 12/08/2008 20:43:57.000</p>
</blockquote>
<p>So yeah, it's definitely deleting the GAC. Why though, and how to stop it?</p>
| [
{
"answer_id": 7900502,
"author": "Yahoo Serious",
"author_id": 422877,
"author_profile": "https://Stackoverflow.com/users/422877",
"pm_score": 0,
"selected": false,
"text": "Start | Settings | Control Panel | Files Admin | Save session"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33213/"
] |
350,546 | <p>There are a lot of rails plugins out there that handle user permissions. I'm impressed with the implementation in the hobo gem, but I'm not sure if I can use just this feature and not the other parts. GateKeeper is a really clever implementation, but has some bugs, though it's small enough I could probably fix it myself. Restful_ACL gives you a class method for checking creation, meaning you can't do any checks on the instance in question (not sure if it does scoped finds).</p>
<p>I'd like something that provides a scoped version of ActiveRecord#find which only finds things the current user is allowed to see. This should be robust enough to say, you can only see pictures that are in galleries that are owned by you or one of your friends.</p>
<p>As a bonus, it could prevent creates or updates (in a before_* or validation step) that you don't have the right to perform, including associating your own records with a different user or gallery, or creating such records.</p>
| [
{
"answer_id": 350936,
"author": "Milan Novota",
"author_id": 26123,
"author_profile": "https://Stackoverflow.com/users/26123",
"pm_score": 2,
"selected": false,
"text": "GET /posts\n GET /users/:user_id/posts\n def index\n user = User.find(params[:user_id]) unless params[:user_id].blank?\n @posts =\n if user\n # get all posts of a user\n user.posts.all\n else\n # get all posts \n Post.all\n end\nend\n"
},
{
"answer_id": 405313,
"author": "nakajima",
"author_id": 39589,
"author_profile": "https://Stackoverflow.com/users/39589",
"pm_score": 1,
"selected": false,
"text": "before_filter def index\n @posts = user_repo.posts\nend\n\nprivate\n\ndef user_repo\n # find_by_id is **much** faster than regular find,\n # plus it just returns nil when there's no record\n if user = User.find_by_id(params[:user_id])\n # returns the association proxy\n user.posts\n else\n # returns the class\n User\n end\nend\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2653/"
] |
350,587 | <p>In Access, I have a table like this one:</p>
<pre><code>Date | EmployeeNum | Award
11-JAN-08 | 34 | GoldStar
13-JAN-08 | 875 | BronzeTrophy
13-JAN-08 | 34 | BronzeTrophy
18-JAN-08 | 875 | BronzeTrophy
</code></pre>
<p>And I want to have a table count them like this:</p>
<pre><code>EmployeeNum | GoldStar | BronzeTrophy
34 | 1 | 1
875 | 0 | 2
</code></pre>
<p>I want to be able to generate this table by running a query or something similar. I've tried putting this into a query but I'm not really sure I'm doing it right. I've tried using UPDATE and SET = SELECT COUNT without too much success.</p>
<p>How should I do this? SHOULD I be trying it like that?</p>
| [
{
"answer_id": 350625,
"author": "Birger",
"author_id": 11485,
"author_profile": "https://Stackoverflow.com/users/11485",
"pm_score": 2,
"selected": false,
"text": "TRANSFORM Count(MyTable.EmployeeNum) AS AantalVanEmployeeNum\nSELECT MyTable.EmployeeNum\nFROM MyTable\nGROUP BY MyTable.EmployeeNum\nPIVOT MyTable.Award;\n"
},
{
"answer_id": 350875,
"author": "user35193",
"author_id": 35193,
"author_profile": "https://Stackoverflow.com/users/35193",
"pm_score": -1,
"selected": false,
"text": "SELECT EmployeeNum, \n SUM(Case [Award] WHEN 'GoldStar' THEN 1 ELSE 0 END) As [GoldStar], \n SUM(CASE [Award] WHEN 'BronzeTrophy' THEN 1 ELSE 0 END) As [BronzeTrophy]\nFROM MyTable\nGroup By EmployeeNum\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,599 | <p>When I write an app, I use the System.Data interfaces (IDbConnection, IDbCommand, IDataReader, IDbDataParameter, etc...). I do this to reduce vendor dependencies. Unless, I'm doing a simple test app, it just seems like the ethical thing to do when consulting.</p>
<p>However, it seems like all the code I see uses the System.Data.SqlClient namespace classes or other vendor specific classes. In magazines and books it's easy to chalk this up to Microsoft influence and their marketing spin to program only against SQLServer. But it seams like almost all the .NET code I see uses the SQLServer specific classes.</p>
<p>I realize the vendor specific classes have more functionality, for example adding a parameter to a SqlCommand object is one method, where as adding it to an IDbCommand is an irritating 4+ lines of code. But then again; writing a little helper class for these limitations is pretty simple.</p>
<p>I've also wondered if programming against the interfaces when SQLServer is the current target client is over-engineering since it is not required immediately. But I don't think it is since the cost of programming against the interfaces is so low, where as reducing vendor dependency provides such a huge benefit.</p>
<p>Do you use vendor specific data classes or the interfaces?</p>
<p>EDIT: To summarize some of the answers below, and throw in some thought's I had while reading them.</p>
<p>Possible pitfalls to using interfaces for vendor neutrality:</p>
<ul>
<li>Vendor specific keywords embedded in
your SELECT statements (all my ins,
upd, & del's are in procs, so that's
not a problem) </li>
<li>Binding directly the
database would probably cause
issues. </li>
<li>Unless your connection
instantiation is centralized, the
vendor specific class will need to
be called anyway.</li>
</ul>
<p>Positive reasons to use interfaces :</p>
<ul>
<li>In my experience the ability (even
if not exercised) to move to a
different vendor has always been
appreciated by the customer.</li>
<li>Use interfaces in reusable code libraries</li>
</ul>
| [
{
"answer_id": 350616,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 3,
"selected": true,
"text": "SQL::"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29043/"
] |
350,600 | <p>How do you add a new variable to be inserted into a Java code template. How do I add a variable to the list in Window->Preferences->Java->Code Style->Code Templates->Code->New Java Files->Edit->Insert Variable... ?</p>
<p>Currently my new files get created with:</p>
<pre><code>${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
</code></pre>
<p>I'd like them to get created with something like:</p>
<pre><code>${begin_filecomment}
${package_declaration}
${typecomment}
${type_declaration}
${end_filecomment}
</code></pre>
<p>where begin_filecomment and end_filecomment appear in the Insert Variable list.</p>
| [
{
"answer_id": 350609,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 4,
"selected": true,
"text": "${begin_filecomment} ${end_filecomment}"
},
{
"answer_id": 494917,
"author": "Hosam Aly",
"author_id": 41283,
"author_profile": "https://Stackoverflow.com/users/41283",
"pm_score": 2,
"selected": false,
"text": "eclipse\\plugins\\org.eclipse.jdt.ui_*.jar\\templates\\\n"
},
{
"answer_id": 36926537,
"author": "javaBean007",
"author_id": 4434569,
"author_profile": "https://Stackoverflow.com/users/4434569",
"pm_score": 0,
"selected": false,
"text": "<c:set var=\"myVariable\" value=\"${requestScope.variableName}\" /> ${} $ $$ $"
},
{
"answer_id": 72589297,
"author": "YangJun.Huang",
"author_id": 19322257,
"author_profile": "https://Stackoverflow.com/users/19322257",
"pm_score": 0,
"selected": false,
"text": " public static class MyID extends SimpleTemplateVariableResolver {\n private static String value = System.getProperty(\"myID\");\n\n public MyID() {\n super(\"myID\", TextTemplateMessages.getString(\"GlobalVariables.variable.description.myID\")); //$NON-NLS-1$ //$NON-NLS-2$\n }\n\n @Override\n protected String resolve(TemplateContext context) {\n if (value == null) {\n return TextTemplateMessages.getString(\"GlobalVariables.variable.description.myID\");\n }\n return value; // $NON-NLS-1$\n }\n }\n # global variables\nGlobalVariables.variable.description.myid=myID\n public CodeTemplateContextType(String contextName) {\n super(contextName);\n\n fIsComment= false;\n\n // global\n addResolver(new GlobalTemplateVariables.Dollar());\n addResolver(new GlobalTemplateVariables.Date());\n addResolver(new GlobalTemplateVariables.Year());\n addResolver(new GlobalTemplateVariables.Time());\n addResolver(new GlobalTemplateVariables.User());\n addResolver(new GlobalTemplateVariables.MyID());\n addResolver(new Todo());\n public void initializeContextTypeResolvers() {\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Selection(\"line_selection\", JavaTemplateMessages.CompilationUnitContextType_variable_description_line_selection));\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n public TemplateContextTypeJSP() {\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.LineSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n public CodeTemplateContextType(String contextName) {\n super(contextName);\n this.fIsComment = false;\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n addResolver(new Todo());\n public JavaContextType() {\n super(\"javaScript\");\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.LineSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n public TemplateContextTypeHTML() {\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.LineSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n addResolver((TemplateVariableResolver)new EncodingTemplateVariableResolverHTML());\n public TemplateContextTypeCSS() {\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.LineSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n addResolver((TemplateVariableResolver)new EncodingTemplateVariableResolverCSS());\n public TemplateContextTypeXML() {\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Cursor());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Date());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Dollar());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.LineSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Time());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.User());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.WordSelection());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.Year());\n addResolver((TemplateVariableResolver)new GlobalTemplateVariables.MyID());\n addResolver((TemplateVariableResolver)new EncodingTemplateVariableResolverXML());\n -DmyID=7777\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350600",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18995/"
] |
350,603 | <p>In Clearcase I can generate a "label" for a given set of files and always go back to that label to regenerate all the files as they were when I generated the label.</p>
<p>How do I do this in Subversion? I'm using the Tortoise front end [Windows] to SVN and I'm not sure how to accomplish this functionality.</p>
| [
{
"answer_id": 350613,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 2,
"selected": false,
"text": "Tags copy Branch/Tag tags tags"
},
{
"answer_id": 350618,
"author": "jmanning2k",
"author_id": 1480,
"author_profile": "https://Stackoverflow.com/users/1480",
"pm_score": 0,
"selected": false,
"text": "svn copy /trunk/foo /tags/foo-1.0\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1265473/"
] |
350,608 | <p>I have a database with 2 tables.</p>
<p>One of the tables holds a row containing numbers, from 0 to 10.</p>
<p>In PHP, I do this: </p>
<pre><code>$query = "SELECT ".$param." FROM issues WHERE ".$param." >=0";
$result = @mysql_query($query) or showError("query failed");
if (!($record = mysql_fetch_array($result))) return null;
return $record;
</code></pre>
<p>The $param holds the name of the row.</p>
<p>I kinda expected to get an array holding the number 0 to 10, but instead I get an array with 2 elements:</p>
<pre><code>array(
[0] = 0
[row_name] = 0
.
.
. // AND SO ON
)
</code></pre>
<p>And that's it.</p>
<p>I've never worked with these functions before and <a href="http://www.php.net" rel="nofollow noreferrer">www.php.net</a> doesn't have any examples that really help...</p>
| [
{
"answer_id": 350630,
"author": "Paolo Bergantino",
"author_id": 16417,
"author_profile": "https://Stackoverflow.com/users/16417",
"pm_score": 4,
"selected": true,
"text": "// query...\n$records = array();\nwhile($r = mysql_fetch_array($result)) {\n $records[] = $r;\n}\nreturn $records;\n"
},
{
"answer_id": 350671,
"author": "Ken",
"author_id": 20074,
"author_profile": "https://Stackoverflow.com/users/20074",
"pm_score": 1,
"selected": false,
"text": "array mysql_fetch_array ( resource $result [, int $result_type ] )\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350608",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
350,611 | <p>I'm using Eclipse as an IDE for Ruby/Rails development (using Aptana plugin). I have one very, very large file that encompasses an initial data load of several thousand rows of data. When this file is open, everything grinds to a halt (on both Windows and Linux), presumably because Eclipse is tied up trying to parse and format/syntax-check the file. Typing in a single word takes upwards of a minute to complete.</p>
<p>Is there a way for me flag this file in such a way that Eclipse will skip it for format/syntax checking?</p>
| [
{
"answer_id": 350630,
"author": "Paolo Bergantino",
"author_id": 16417,
"author_profile": "https://Stackoverflow.com/users/16417",
"pm_score": 4,
"selected": true,
"text": "// query...\n$records = array();\nwhile($r = mysql_fetch_array($result)) {\n $records[] = $r;\n}\nreturn $records;\n"
},
{
"answer_id": 350671,
"author": "Ken",
"author_id": 20074,
"author_profile": "https://Stackoverflow.com/users/20074",
"pm_score": 1,
"selected": false,
"text": "array mysql_fetch_array ( resource $result [, int $result_type ] )\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9550/"
] |
350,617 | <p>In my database schema I have an entity that is identified. The identifier can be reused and thus there is a one-to-many relation with the entity. Example: A person can have a nickname. Nicknames are not unique and can be shared amongst many people. So the schema might look like:</p>
<pre><code>PERSON
id
name
nickname_id
NICKNAME
id
name
</code></pre>
<p>The issue is that when inserting a new person, I have to first query <code>NICKNAME</code> to see if the nickname exists. If it doesn't then I have to create a row in <code>NICKNAME</code>. When inserting many persons, this can be slow as each person insertion results in a query to <code>NICKNAME</code>.</p>
<p>I could optimize large insertions by first querying Nickname for all the nicknames. JPA query language:</p>
<pre><code>SELECT n FROM NICKNAME n WHERE name in ('Krusty', 'Doppy', 'Flash', etc)
</code></pre>
<p>And then create the new nicknames as necessary, followed by setting nickname_id on the persons.</p>
<p>This complicates the software a bit as it has to temporarily store nicknames in memory. Furthermore, some databases have a limit on the parameters of the <code>IN</code> clause (SQL Server is 2100 or so) so I have perform multiple queries.</p>
<p>I'm curious how this issue is dealt with by others. More specifically, when a database is normalized and an entity has a relationship with another, inserting a new entity basically results in having to check the other entity. For large inserts this can be slow unless the operation is lifted into the code domain. Is there someway to auto insert the related table rows?</p>
<p>FYI I'm using Hibernate's implementation of JPA</p>
| [
{
"answer_id": 350699,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 0,
"selected": false,
"text": "...ON DUPLICATE KEY UPDATE... UNIQUE UPDATE CREATE TABLE Nickname (\n id SERIAL PRIMARY KEY,\n name VARCHAR(20) UNIQUE\n);\n\nINSERT INTO Nickname (name) VALUES (\"Bill\")\n ON DUPLICATE KEY UPDATE name = name;\n"
},
{
"answer_id": 350785,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "INSERT INTO Person(Name, NicknameID)\n VALUES(:name, (SELECT id FROM Nickname WHERE Name = :nickname))\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
350,620 | <p>I need to grep for lines with bunch of names, say <code>clientLogin=a@yahoo.com</code>, <code>clientLogin=b@gmail.com</code> from a file.txt.</p>
<p>file.txt has junk which is <code>email=a@yahoo.com email=b@gmail.com</code>. I need to filter these out</p>
<p>Once I get these lines I need to grep for gmail and yahoo and get their counts</p>
<pre><code>List l = new ArrayList{a@yahoo.com, b@gmail.com}
def gmail = ['sh','-c','grep "clientLogin="$l.get(0) file.txt' | grep gmail | wc -l ]
def yahoo = ['sh','-c','grep "clientLogin="$l.get(1) file.txt' | grep yahoo| wc -l ]
</code></pre>
<p>This doesn't work. How can I substitute the $l.get(1) value dynamically?</p>
<hr>
<p>the problem is that ${l.get(0)} has to be inside the " ",
i.e.:</p>
<pre><code>def gmail = ['sh','-c','grep "clientLogin=${l.get(0)}" file.txt' | grep gmail | wc -l ]
</code></pre>
<p>so that it will look like:</p>
<pre><code>def gmail = ['sh','-c','grep "clientLogin=a@yahoo.com" file.txt' | grep gmail | wc -l ]
</code></pre>
<p>but <code>clientLogin=${l.get(0)}</code> doesn't produce the result. I am not sure where I am going wrong. </p>
<p>Thanks for your suggestion but it doesn't produce the result, at least when I tried it.</p>
<hr>
<p>file.txt has lot of junk and a pattern something like:</p>
<pre><code>Into the domain clientLogin=a@yahoo.com exit on 12/01/2008 etc..
</code></pre>
<p>hence I do </p>
<pre><code>def ex = ['sh','-c','grep "domain clientLogin=$client" file.txt'| grep "something more" | wc -l]
</code></pre>
<p>that way I can chain the grep as I want and eventually land at the count I need.</p>
<p>I am not sure if I can chain the greps if I use </p>
<pre><code>def ex = ['grep', "$client", 'file.txt']
</code></pre>
<p>thanks for your input.</p>
| [
{
"answer_id": 350687,
"author": "Rob Hruska",
"author_id": 29995,
"author_profile": "https://Stackoverflow.com/users/29995",
"pm_score": 2,
"selected": false,
"text": "def client = 'foo@bar.com'\ndef ex = ['grep', \"$client\", 'file.txt']\n\ndef proc = ex.execute()\nproc.waitFor()\n\nprintln \"return: ${proc.exitValue()}\"\nprintln \"stderr: ${proc.err.text}\"\nprintln \"stdout: ${proc.in.text}\"\n"
},
{
"answer_id": 351238,
"author": "flicken",
"author_id": 12880,
"author_profile": "https://Stackoverflow.com/users/12880",
"pm_score": 0,
"selected": false,
"text": " \"${l.get(0)}\"\n List l = new ArrayList{a@yahoo.com, b@gmail.com}\ndef gmail = ['sh','-c','grep \"clientLogin=\"${l.get(0)} file.txt' | grep gmail | wc -l ]\ndef yahoo = ['sh','-c','grep \"clientLogin=\"${l.get(1)} file.txt' | grep yahoo| wc -l ]\n"
},
{
"answer_id": 351929,
"author": "Ted Naleid",
"author_id": 8912,
"author_profile": "https://Stackoverflow.com/users/8912",
"pm_score": 3,
"selected": false,
"text": "def file = new File(\"file.txt\") \nfile.delete() // clear out old version for multiple runs\nfile << \"\"\"\nfoobar clientLogin=a@yahoo.com baz quux # should match a@yahoo.com\nfoobar email=a@yahoo.com baz quux\nfoobar email=b@gmail.com bal zoom\nfoobar clientLogin=a@yahoo.com baz quux # should match a@yahoo.com\nfoobar clientLogin=b@gmail.com bal zoom # should match b@gmail.com\nfoobar email=b@gmail.com bal zoom\n\"\"\"\n\ndef emailList = [\"a@yahoo.com\", \"b@gmail.com\"]\ndef emailListGroup = emailList.join('|')\ndef pattern = /(?m)^.*clientLogin=($emailListGroup).*$/\n\ndef resultMap = [:]\n\n(file.text =~ pattern).each { fullLine, email ->\n resultMap[email] = resultMap[email] ? resultMap[email] + 1 : 1\n}\n\nassert resultMap[\"a@yahoo.com\"] == 2\nassert resultMap[\"b@gmail.com\"] == 1\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350620",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37870/"
] |
350,628 | <p>I use a console application to write some test code:</p>
<pre><code> /// <summary>
/// Returns AD information for a specified userID.
/// </summary>
/// <param name="ntID"></param>
/// <returns></returns>
public ADUser GetUser(string ntID)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", ntID);
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("givenName");
search.PropertiesToLoad.Add("sn");
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("userPrincipalName");
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
return new ADUser(result);
}
</code></pre>
<p>And this worked fine from the console app. However, when I moved it to an ASP.NET application, I received an error message about not knowing the correct domain.</p>
<p>Is there a trick I am missing for accessing AD when running on the ASPNET account?</p>
<p><strong>EDIT</strong>: Passing just a LDAP://domain connection string isn't enough, as it wants an actual login/password. Because this runs on a local account on a machine, I'm not sure what AD L/P to use. Can I delegate the accessing users account to this somehow?</p>
<p><strong>EDIT #2</strong>: When trying to use identity impersonation, I get a DirectoryServicesCOMException with:</p>
<h3>The authentication mechanism is unknown.</h3>
| [
{
"answer_id": 350687,
"author": "Rob Hruska",
"author_id": 29995,
"author_profile": "https://Stackoverflow.com/users/29995",
"pm_score": 2,
"selected": false,
"text": "def client = 'foo@bar.com'\ndef ex = ['grep', \"$client\", 'file.txt']\n\ndef proc = ex.execute()\nproc.waitFor()\n\nprintln \"return: ${proc.exitValue()}\"\nprintln \"stderr: ${proc.err.text}\"\nprintln \"stdout: ${proc.in.text}\"\n"
},
{
"answer_id": 351238,
"author": "flicken",
"author_id": 12880,
"author_profile": "https://Stackoverflow.com/users/12880",
"pm_score": 0,
"selected": false,
"text": " \"${l.get(0)}\"\n List l = new ArrayList{a@yahoo.com, b@gmail.com}\ndef gmail = ['sh','-c','grep \"clientLogin=\"${l.get(0)} file.txt' | grep gmail | wc -l ]\ndef yahoo = ['sh','-c','grep \"clientLogin=\"${l.get(1)} file.txt' | grep yahoo| wc -l ]\n"
},
{
"answer_id": 351929,
"author": "Ted Naleid",
"author_id": 8912,
"author_profile": "https://Stackoverflow.com/users/8912",
"pm_score": 3,
"selected": false,
"text": "def file = new File(\"file.txt\") \nfile.delete() // clear out old version for multiple runs\nfile << \"\"\"\nfoobar clientLogin=a@yahoo.com baz quux # should match a@yahoo.com\nfoobar email=a@yahoo.com baz quux\nfoobar email=b@gmail.com bal zoom\nfoobar clientLogin=a@yahoo.com baz quux # should match a@yahoo.com\nfoobar clientLogin=b@gmail.com bal zoom # should match b@gmail.com\nfoobar email=b@gmail.com bal zoom\n\"\"\"\n\ndef emailList = [\"a@yahoo.com\", \"b@gmail.com\"]\ndef emailListGroup = emailList.join('|')\ndef pattern = /(?m)^.*clientLogin=($emailListGroup).*$/\n\ndef resultMap = [:]\n\n(file.text =~ pattern).each { fullLine, email ->\n resultMap[email] = resultMap[email] ? resultMap[email] + 1 : 1\n}\n\nassert resultMap[\"a@yahoo.com\"] == 2\nassert resultMap[\"b@gmail.com\"] == 1\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
350,639 | <p>Let me describe the problem in details:</p>
<p>I want to show an absolute positioned div when hovering over an element. That's really simple with jQuery and works just fine. But when the mouse goes over one of the child elements, it triggers the mouseout event of the containing div. How do I keep javascript from triggering the mouseout event of the containing element when hovering a child element. </p>
<p>What's the best and shortest way to do that with jQuery?</p>
<p>Here is a simplified example to illustrate what I mean:</p>
<p>Html:</p>
<pre><code><a>Hover Me</a>
<div>
<input>Test</input>
<select>
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
</code></pre>
<p>Javascript/jQuery:</p>
<pre><code>$('a').hover( function() { $(this).next().show() }
function() { $(this).next().hide() } );
</code></pre>
| [
{
"answer_id": 350740,
"author": "Ryan McGeary",
"author_id": 8985,
"author_profile": "https://Stackoverflow.com/users/8985",
"pm_score": 4,
"selected": false,
"text": "<div id=\"hoverable\">\n <a>Hover Me</a>\n <div style=\"display:none;\">\n <input>Test</input>\n <select>\n <option>Option 1</option>\n <option>Option 2</option>\n </select>\n </div>\n</div>\n $('#hoverable').hover( function() { $(this).find(\"div\").show(); },\n function() { $(this).find(\"div\").hide(); } );\n"
},
{
"answer_id": 350776,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "function mouseOut(e)\n{\n var pos = GetMousePositionInElement(e, element);\n if (pos.x < 0 || pos.x >= element.size.X || pos.y < 0 || pos.y >= element.size.Y)\n {\n RealMouseOut();\n }\n else\n {\n //Hit a child-element\n }\n}\n"
},
{
"answer_id": 1178915,
"author": "bytebrite",
"author_id": 144629,
"author_profile": "https://Stackoverflow.com/users/144629",
"pm_score": 9,
"selected": true,
"text": "mouseenter mouseleave mouseover mouseout $(\".myClass\").on( {\n 'mouseenter':function() { console.log(\"enter\"); },\n 'mouseleave':function() { console.log(\"leave\"); }\n});\n"
},
{
"answer_id": 15765742,
"author": "Erenor Paz",
"author_id": 1356098,
"author_profile": "https://Stackoverflow.com/users/1356098",
"pm_score": 0,
"selected": false,
"text": "mouseout mouseleave"
},
{
"answer_id": 32649641,
"author": "Lord Nighton",
"author_id": 4457155,
"author_profile": "https://Stackoverflow.com/users/4457155",
"pm_score": 4,
"selected": false,
"text": ".mouseleave .mouseout $('div.sort-selector').mouseleave(function() {\n $(this).hide();\n});\n live $('div.sort-selector').live('mouseleave', function() {\n $(this).hide();\n});\n"
},
{
"answer_id": 47312942,
"author": "Antoine",
"author_id": 8946596,
"author_profile": "https://Stackoverflow.com/users/8946596",
"pm_score": 2,
"selected": false,
"text": "pointer-events: none;"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172/"
] |
350,640 | <p>I have tried SQL Server 2008 Management Studio and other third party tools to script all database objects (views, SPs & tables) and I can't get anything to generate a one file script which has a drop statement preceded with an "If exists.." statement for every object.</p>
<p>I need the "if exists" statement so I don't get any errors if an object doesn't exist.
The tool doesn't have to be for sql server 2008. </p>
| [
{
"answer_id": 350728,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 0,
"selected": false,
"text": "select 'if object_id ('''+ s.name + '.' + t.name + \n ''') is not null drop table ' + s.name + '.' + t.name +\n char (10) + 'go'\n from sys.schemas s\n join sys.tables t\n on t.schema_id = s.schema_id\n --------------------------------------------------------------------------\nif object_id ('dim.Dim1') is not null drop table dim.Dim1\ngo\nif object_id ('dim.TestSnapshot') is not null drop table dim.TestSnapshot\ngo\nif object_id ('fact.Test') is not null drop table fact.Test\ngo\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5232/"
] |
350,641 | <p>I need some help with XSLT syntax. Here is my scenario, I have an XML file that needs to be transformed in to a different look and feel of XML file, I have several sections where if particular node set don't contain any value the whole section shouldn't be processed.</p>
<p>Here is an example of XML:</p>
<pre><code><Dates>
<Date>
<VALUE1></VALUE1>
<VALUE2></VALUE2>
<VALUE3></VALUE3>
<VALUE4></VALUE4>
<VALUE5>3333</VALUE5>
</Date>
<Date>
<VALUE1>AAAA</VALUE1>
<VALUE2></VALUE2>
<VALUE3>JJJJ</VALUE3>
<VALUE4></VALUE4>
<VALUE5>12345</VALUE5>
</Date>
</Dates>
</code></pre>
<p><a href="http://img162.imageshack.us/my.php?image=xmlscreenshotgk7.gif" rel="noreferrer">screenshot of xml</a></p>
<p>Here is my XSLT with the if statement that don't work right</p>
<pre><code><xsl:for-each select="Level1/Level2/Level3">
<xsl:if test="@VALUE1!=''">
<MyDates>
<value_1>
<xsl:value-of select="VALUE1"/>
</value_1>
<value_2>
<xsl:value-of select="VALUE2"/>
</value_2>
<value_3>
<xsl:value-of select="VALUE3"/>
</value_3>
<value_4>
<xsl:value-of select="VALUE4"/>
</value_4>
</MyDates>
</xsl:if>
</xsl:for-each>
</code></pre>
<p>So as you can see I basically want all nodes (VALUE1, VALUE2, VALUE3, etc) to have values or else don't process and move on to the next section</p>
<p>(If you cannot see the XML come thought, I also made a screen shot)</p>
| [
{
"answer_id": 350748,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 4,
"selected": false,
"text": "<xsl:for-each select=\"Dates\">\n <MyDates>\n <xsl:for-each select=\"Date\">\n <xsl:if test=\"not(*[.=''])\">\n <MyDate>\n <value_1>\n <xsl:value-of select=\"VALUE1\"/> \n </value_1>\n <value_2>\n <xsl:value-of select=\"VALUE2\"/> \n </value_2>\n <value_3>\n <xsl:value-of select=\"VALUE3\"/> \n </value_3>\n <value_4>\n <xsl:value-of select=\"VALUE4\"/> \n </value_4> \n </MyDate>\n </xsl:if>\n </xsl:for-each>\n </MyDates>\n</xsl:for-each>\n * [.='']"
},
{
"answer_id": 351594,
"author": "Dimitre Novatchev",
"author_id": 36305,
"author_profile": "https://Stackoverflow.com/users/36305",
"pm_score": 2,
"selected": false,
"text": " <xsl:template match=\"Date[not(*[not(normalize-space())])]\">\n <xsl:copy-of select=\".\"/>\n </xsl:template>\n\n <xsl:template match=\"text()\"/>\n"
},
{
"answer_id": 580974,
"author": "SO User",
"author_id": 39289,
"author_profile": "https://Stackoverflow.com/users/39289",
"pm_score": 2,
"selected": false,
"text": "<xsl:for-each select=\"Level1/Level2/Level3\">\n<MyDates>\n <xsl:if test=\"VALUE1!=''\">\n <value_1>\n <xsl:value-of select=\"VALUE1\"/>\n </value_1>\n </xsl:if>\n <xsl:if test=\"VALUE2!=''\">\n <value_2>\n <xsl:value-of select=\"VALUE2\"/>\n </value_2>\n </xsl:if>\n <xsl:if test=\"VALUE3!=''\">\n <value_3>\n <xsl:value-of select=\"VALUE3\"/>\n </value_3>\n </xsl:if>\n <xsl:if test=\"VALUE4!=''\">\n <value_4>\n <xsl:value-of select=\"VALUE4\"/>\n </value_4>\n </xsl:if>\n</MyDates>\n"
},
{
"answer_id": 2791554,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<xsl:if test=\"VALUE1/text()\"> \n\n</xsl:if> \n\n<xsl:if test=\"VALUE1/child::node()\"> \n\n</xsl:if> \n"
},
{
"answer_id": 16070951,
"author": "user2292708",
"author_id": 2292708,
"author_profile": "https://Stackoverflow.com/users/2292708",
"pm_score": 1,
"selected": false,
"text": "<xsl:template match=\"Dates\">\n<table border=\"1\">\n<tr bgcolor=\"#9acd32\"><th>NAME</th><th>INVALUE</th></tr>\n <xsl:for-each select=\"Date\">\n <xsl:if test=\"(VALUE1 != '') and (VALUE2 != '') and (VALUE3 != '') and (VALUE4 != '') and (VALUE5 != '')\" >\n <tr><td>VALUE1</td><td><xsl:value-of select=\"VALUE1\"></xsl:value-of></td></tr>\n <tr><td>VALUE2</td><td><xsl:value-of select=\"VALUE2\"></xsl:value-of></td></tr>\n <tr><td>VALUE3</td><td><xsl:value-of select=\"VALUE3\"></xsl:value-of></td></tr>\n <tr><td>VALUE4</td><td><xsl:value-of select=\"VALUE4\"></xsl:value-of></td></tr>\n <tr><td>VALUE5</td><td><xsl:value-of select=\"VALUE5\"></xsl:value-of></td></tr>\n </xsl:if>\n </xsl:for-each>\n</table>\n</xsl:template>\n</xsl:stylesheet>\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350641",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41508/"
] |
350,645 | <p>Couldn't think of an intuitive way to paraphrase the topic for this question, and I apologize for that. My question is the following:</p>
<p>I have several UIViewController's which need to call in a UIDatePicker. I didn't want to subclass the Date Picker several times as it's the same interface. The problem I'm having is figuring out what tools Cocoa/Objective-C provide in order for me to abstract my child controller so it does not need to know who the parent controller is that instantiated it. The parent controller just needs to tell the child controller who they are, by passing self in to some child controller instance variable. The problem with that is, the child controller cannot access methods/instance variables of the parent without importing the class's interface file. That again means the child knows each individual parent who calls it. </p>
<p>Looking for an optimal way to solve this, what appears to be, very common problem.</p>
| [
{
"answer_id": 383713,
"author": "Ross Boucher",
"author_id": 41497,
"author_profile": "https://Stackoverflow.com/users/41497",
"pm_score": 2,
"selected": false,
"text": "id delegate;\n @protocol ProtocolName\n\n- (void)sometMethod;\n\n@end\n @interface MyClass <MyProtocol>\n id<MyProtocol> delegate;\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
350,647 | <p>The function below takes a python file handle, reads in packed binary data from the file, creates a Python dictionary and returns it. If I loop it endlessly, it'll continually consume RAM. What's wrong with my RefCounting?</p>
<pre><code>static PyObject* __binParse_getDBHeader(PyObject *self, PyObject *args){
PyObject *o; //generic object
PyObject* pyDB = NULL; //this has to be a py file object
if (!PyArg_ParseTuple(args, "O", &pyDB)){
return NULL;
} else {
Py_INCREF(pyDB);
if (!PyFile_Check(pyDB)){
Py_DECREF(pyDB);
PyErr_SetString(PyExc_IOError, "argument 1 must be open file handle");
return NULL;
}
}
FILE *fhDB = PyFile_AsFile(pyDB);
long offset = 0;
DB_HEADER *pdbHeader = malloc(sizeof(DB_HEADER));
fseek(fhDB,offset,SEEK_SET); //at the beginning
fread(pdbHeader, 1, sizeof(DB_HEADER), fhDB );
if (ferror(fhDB)){
fclose(fhDB);
Py_DECREF(pyDB);
PyErr_SetString(PyExc_IOError, "failed reading database header");
return NULL;
}
Py_DECREF(pyDB);
PyObject *pyDBHeader = PyDict_New();
Py_INCREF(pyDBHeader);
o=PyInt_FromLong(pdbHeader->version_number);
PyDict_SetItemString(pyDBHeader, "version", o);
Py_DECREF(o);
PyObject *pyTimeList = PyList_New(0);
Py_INCREF(pyTimeList);
int i;
for (i=0; i<NUM_DRAWERS; i++){
//epochs
o=PyInt_FromLong(pdbHeader->last_good_test[i]);
PyList_Append(pyTimeList, o);
Py_DECREF(o);
}
PyDict_SetItemString(pyDBHeader, "lastTest", pyTimeList);
Py_DECREF(pyTimeList);
o=PyInt_FromLong(pdbHeader->temp);
PyDict_SetItemString(pyDBHeader, "temp", o);
Py_DECREF(o);
free(pdbHeader);
return (pyDBHeader);
}
</code></pre>
<p>Thanks for taking a look,</p>
<p>LarsenMTL</p>
| [
{
"answer_id": 350695,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 5,
"selected": true,
"text": "PyDict_New() PyDict pyTimeList Py_INCREF pyDB"
},
{
"answer_id": 350719,
"author": "Torsten Marek",
"author_id": 9567,
"author_profile": "https://Stackoverflow.com/users/9567",
"pm_score": 3,
"selected": false,
"text": "PyList_Append PyObject *pyTimeList = PyList_New(NUM_DRAWERS);\nint i;\nfor (i=0; i<NUM_DRAWERS; i++){\n o = PyInt_FromLong(pdbHeader->last_good_test[i]);\n PyList_SET_ITEM(pyTimeList, i, o);\n}\n o PyList_SET_ITEM"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16363/"
] |
350,651 | <p>Treating my repository as a SVN repo, I get:</p>
<pre><code>svn co http://myrepo/foo/trunk foo
...
foo/
bar/
baz/ -> http://myrepo/baz/trunk
</code></pre>
<p>Treating it as a Git repo, I get:</p>
<pre><code>git svn clone http://myrepo/foo --trunk=trunk --branches=branches --tags=tags
...
foo/
bar/
</code></pre>
<p>I can clone baz to my local machine elsewhere and add a symlink, but that's just a hack. Is there a way to have <code>git svn rebase</code> automatically pull in those changes when it updates everything else, just like <code>svn up</code> does?</p>
| [
{
"answer_id": 474013,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 6,
"selected": true,
"text": "git-svn"
},
{
"answer_id": 8040405,
"author": "tuomasjjrasanen",
"author_id": 462518,
"author_profile": "https://Stackoverflow.com/users/462518",
"pm_score": 3,
"selected": false,
"text": "svn:externals HEAD .git/hooks/post-checkout git svn rebase git-checkout #!/bin/bash\nset -eu\n\nrevision=$(git svn info | sed -n 's/^Revision: \\([1-9][0-9]*\\)$/\\1/p')\ngit svn -r${revision} propget svn:externals | head -n-1 | {\n while read checkout_args\n do\n checkout_dirname=$(echo ${checkout_args} | cut -d' ' -f3)\n svn checkout ${checkout_args}\n if [ -z $(grep ${checkout_dirname} .git/info/exclude) ]\n then\n echo ${checkout_dirname} >> .git/info/exclude\n fi\n done\n}\n"
},
{
"answer_id": 9648557,
"author": "opekar",
"author_id": 1261313,
"author_profile": "https://Stackoverflow.com/users/1261313",
"pm_score": 1,
"selected": false,
"text": "python /../gitsvnext/run update\n python /../gitsvnext/run list\n"
},
{
"answer_id": 14440042,
"author": "rsenna",
"author_id": 158074,
"author_profile": "https://Stackoverflow.com/users/158074",
"pm_score": 2,
"selected": false,
"text": "svn:externals svn:externals"
},
{
"answer_id": 31778905,
"author": "TCS",
"author_id": 324827,
"author_profile": "https://Stackoverflow.com/users/324827",
"pm_score": 1,
"selected": false,
"text": "svn checkout --depth empty http://path/to/repo .\n svn propget svn:externals | sed -e 's/ / .\\//' | sed -e 's/\\'//g' | xargs -L1 svn co\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
350,655 | <p>I have an asp.net ascx control file and I have put the control on an aspx page. The aspx page has a button in which when I press enter on the keyboard, I want it to fire the event handler for the button. Is there a way to set this?</p>
<p>I am using a master page with a button already on it, so now when I press the enter key, the event handler for that button fires.</p>
| [
{
"answer_id": 350662,
"author": "HectorMac",
"author_id": 1400,
"author_profile": "https://Stackoverflow.com/users/1400",
"pm_score": 1,
"selected": false,
"text": "<form id=\"form1\" runat=\"server\" defaultbutton=\"myButton\">\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33690/"
] |
350,661 | <p>I haven't used vim in a Unix system in a while, but as I recall there was no \r, it was always \n.</p>
<p>I'm using gVim under windows and when I <i>search</i> for new line characters I use \n. Searching for \r returns nothing. But when I <i>replace</i> the characters I have to use \r's. \n's give me ^@</p>
<p>Can anyone explain what's going on here?</p>
| [
{
"answer_id": 350688,
"author": "mat",
"author_id": 42083,
"author_profile": "https://Stackoverflow.com/users/42083",
"pm_score": 2,
"selected": false,
"text": "^V <enter> ^M \\r \\r [dos]"
},
{
"answer_id": 350754,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 2,
"selected": false,
"text": ":%s/^V^M/^V^M/g\n"
},
{
"answer_id": 350764,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 6,
"selected": true,
"text": ":set fileformat=unix\n:set fileformat=dos\n"
},
{
"answer_id": 350798,
"author": "Brian Carper",
"author_id": 23070,
"author_profile": "https://Stackoverflow.com/users/23070",
"pm_score": 5,
"selected": false,
"text": "\\r \\n \\n :h s/\\n \\n <NUL> <NL> :%s/\\n/\\n/ ^@ \\n \\n"
},
{
"answer_id": 350971,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": ":%s/^V^M/^V^M/g\n :%s/\\r/\\r/g\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23829/"
] |
350,697 | <p>I have some old databases i was handed that use SQL Server 2000 and they are getting SQL Injected with javascript script tags at the end of certain database fields. I need a trigger to strip out the injected on update until I have time to fix the front end that is allowing this. </p>
<p>I am a SQL Server novice - please help!</p>
| [
{
"answer_id": 350724,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 0,
"selected": false,
"text": "<script DECLARE @T varchar(255),@C varchar(255) \nDECLARE Table_Cursor CURSOR FOR select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) \nOPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C \nWHILE(@@FETCH_STATUS=0) BEGIN \nexec('update ['+@T+'] set ['+@C+']=LEFT(['+@C+'], CHARINDEX(''<script'', ['+@C+'])-1)\nWHERE CHARINDEX(''<script'', ['+@C+']) >0')\nFETCH NEXT FROM Table_Cursor INTO @T,@C \nEND \nCLOSE Table_Cursor \nDEALLOCATE Table_Cursor\n SELECT syscolumns sysobjects"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350697",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34548/"
] |
350,701 | <p>I need to find a faster way to number lines in a file in a specific way using tools like awk and sed. I need the first character on each line to be numbered in this fashion: 1,2,3,1,2,3,1,2,3 etc.</p>
<p>For example, if the input was this:</p>
<pre><code>line 1
line 2
line 3
line 4
line 5
line 6
line 7
</code></pre>
<p>The output needs to look like this:</p>
<pre><code>1line 1
2line 2
3line 3
1line 4
2line 5
3line 6
1line 7
</code></pre>
<p>Here is a chunk of what I have. $lines is the number of lines in the data file divided by 3. So for a file of 21000 lines I process this loop 7000 times. </p>
<pre><code>export i=0
while [ $i -le $lines ]
do
export start=`expr $i \* 3 + 1`
export end=`expr $start + 2`
awk NR==$start,NR==$end $1 | awk '{printf("%d%s\n", NR,$0)}' >> data.out
export i=`expr $i + 1`
done
</code></pre>
<p>Basically this grabs 3 lines at a time, numbers them, and adds to an output file. It's slow...and then some! I don't know of another, faster, way to do this...any thoughts?</p>
| [
{
"answer_id": 350711,
"author": "derobert",
"author_id": 27727,
"author_profile": "https://Stackoverflow.com/users/27727",
"pm_score": 2,
"selected": false,
"text": "perl -pe '$_ = (($.-1)%3)+1 . $_'\n ((line# - 1) MOD 3) + 1"
},
{
"answer_id": 350718,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": false,
"text": "nl man nl nl n nl"
},
{
"answer_id": 350744,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 1,
"selected": false,
"text": "awk '{printf \"%d%s\\n\", ((NR-1) % 3) + 1, $0;}' \"$@\"\n"
},
{
"answer_id": 350746,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 4,
"selected": true,
"text": "awk awk '{print ((NR-1)%3)+1 $0}' $1 > data.out\n awk '{print ((NR-1)%3)+1, $0}' $1 > data.out\n"
},
{
"answer_id": 350762,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "import sys\nfor count, line in enumerate(sys.stdin):\n stdout.write( \"%d%s\" % ( 1+(count % 3), line )\n"
},
{
"answer_id": 355068,
"author": "Ganesh M",
"author_id": 43502,
"author_profile": "https://Stackoverflow.com/users/43502",
"pm_score": 0,
"selected": false,
"text": "awk '{print ((NR-1)%3+1) $_}' < input\n1line 1\n2line 2\n3line 3\n1line 4\n2line 5\n3line 6\n1line 7\n\n# cat input \n line 1\n line 2\n line 3\n line 4\n line 5\n line 6\n line 7\n"
},
{
"answer_id": 411059,
"author": "PEZ",
"author_id": 44639,
"author_profile": "https://Stackoverflow.com/users/44639",
"pm_score": 1,
"selected": false,
"text": "i=0; while read; do echo \"$((i++ % 3 + 1)) $REPLY\"; done < input\n"
},
{
"answer_id": 8220222,
"author": "potong",
"author_id": 967492,
"author_profile": "https://Stackoverflow.com/users/967492",
"pm_score": 2,
"selected": false,
"text": " sed 's/^/1/;n;s/^/2/;n;s/^/3/' input\n"
},
{
"answer_id": 58543480,
"author": "Dmitry",
"author_id": 3914764,
"author_profile": "https://Stackoverflow.com/users/3914764",
"pm_score": 2,
"selected": false,
"text": "grep -n '.*' <<< `ls -1`\n 1:file.a\n2:file.b\n3:file.c\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5678/"
] |
350,753 | <p>I'd like to see a series of diffs for a file. I'd settle for simply the log listing restricted to only those entries that modified the file.</p>
| [
{
"answer_id": 350769,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "git log [filename] git log -p [filename]"
},
{
"answer_id": 350783,
"author": "theschmitzer",
"author_id": 2167252,
"author_profile": "https://Stackoverflow.com/users/2167252",
"pm_score": 5,
"selected": true,
"text": "svn log filename svn log URL\n --limit N svn log main.cpp --limit 4\n"
},
{
"answer_id": 1608080,
"author": "Thomas S. Trias",
"author_id": 189048,
"author_profile": "https://Stackoverflow.com/users/189048",
"pm_score": 2,
"selected": false,
"text": "svn log path@some_revision_where_the_path_existed"
},
{
"answer_id": 2606517,
"author": "mkorpela",
"author_id": 308189,
"author_profile": "https://Stackoverflow.com/users/308189",
"pm_score": 2,
"selected": false,
"text": "git log -- [filename]\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
350,787 | <p>I have a stored procedure that needs to convert hexadecimal numbers to their decimal equivalent. I've read the documentation for the UNHEX() function, but it is returning a binary value. What I'm wanting to do is something like this:</p>
<pre><code>CREATE PROCEDURE foo( hex_val VARCHAR(10) )
BEGIN
DECLARE dec_val INTEGER;
SET dec_val = UNHEX( hex_val );
-- Do something with the decimal value
select dec_val;
END
</code></pre>
<p>What am I missing? How can I convert the UNHEX()'d value to a unsigned integer?</p>
| [
{
"answer_id": 350804,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": false,
"text": "conv(hex_val, 16, 10)\n"
},
{
"answer_id": 350810,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 6,
"selected": true,
"text": "CONV() SET dec_val = CONV(hex_val, 16, 10);\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31319/"
] |
350,794 | <p>I have a file upload form that is being posted back to a servlet (using multipart/form-data encoding). In the servlet, I am trying to use Apache Commons to handle the upload. However, I also have some other fields in the form that are just plain fields. How can I read those parameters from the request?</p>
<p>For example, in my servlet, I have code like this to read in the uplaoded file:</p>
<pre><code> // Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
Iterator /* FileItem */ items = upload.parseRequest(request).iterator();
while (items.hasNext()) {
FileItem thisItem = (FileItem) items.next();
... do stuff ...
}
</code></pre>
| [
{
"answer_id": 350857,
"author": "stian",
"author_id": 17542,
"author_profile": "https://Stackoverflow.com/users/17542",
"pm_score": 4,
"selected": true,
"text": "while (items.hasNext()) {\n FileItem thisItem = (FileItem) items.next();\n if (thisItem.isFormField()) {\n if (thisItem.getFieldName().equals(\"somefieldname\") {\n String value = thisItem.getString();\n // Do something with the value\n }\n }\n\n }\n"
},
{
"answer_id": 7986804,
"author": "Edward Verenich",
"author_id": 1026439,
"author_profile": "https://Stackoverflow.com/users/1026439",
"pm_score": 2,
"selected": false,
"text": " try {\n\n ServletFileUpload upload = new ServletFileUpload();\n FileItemIterator iterator = upload.getItemIterator(req);\n while(iterator.hasNext()){\n\n\n FileItemStream item = iterator.next();\n InputStream stream = item.openStream();\n if(item.isFormField()){\n if(item.getFieldName().equals(\"vFormName\")){\n\n byte[] str = new byte[stream.available()];\n stream.read(str);\n full = new String(str,\"UTF8\");\n }\n }else{\n byte[] data = new byte[stream.available()];\n stream.read(data);\n base64 = Base64Utils.toBase64(data);\n }\n }\n\n } catch (FileUploadException e) {\n\n e.printStackTrace();\n }\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4257/"
] |
350,799 | <p>If I have a Django form such as:</p>
<pre><code>class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField()
sender = forms.EmailField()
</code></pre>
<p>And I call the as_table() method of an instance of this form, Django will render the fields as the same order as specified above.</p>
<p>My question is how does Django know the order that class variables where defined? </p>
<p>(Also how do I override this order, for example when I want to add a field from the classe's <strong>init</strong> method?)</p>
| [
{
"answer_id": 350851,
"author": "zgoda",
"author_id": 12138,
"author_profile": "https://Stackoverflow.com/users/12138",
"pm_score": 3,
"selected": false,
"text": "creation_counter .fields creation_counter"
},
{
"answer_id": 350913,
"author": "Greg",
"author_id": 13009,
"author_profile": "https://Stackoverflow.com/users/13009",
"pm_score": 6,
"selected": true,
"text": "form.py __new__ self.fields self.fields SortedDict datastructures.py class ContactForm(forms.Form):\n subject = forms.CharField(max_length=100)\n message = forms.CharField()\n def __init__(self,*args,**kwargs):\n forms.Form.__init__(self,*args,**kwargs)\n #first argument, index is the position of the field you want it to come before\n self.fields.insert(0,'sender',forms.EmailField(initial=str(time.time())))\n"
},
{
"answer_id": 871048,
"author": "nosklo",
"author_id": 17160,
"author_profile": "https://Stackoverflow.com/users/17160",
"pm_score": 3,
"selected": false,
"text": "import operator\nimport itertools\n\nclass Field(object):\n _counter = itertools.count()\n def __init__(self):\n self.count = Field._counter.next()\n self.name = ''\n def __repr__(self):\n return \"Field(%r)\" % self.name\n\nclass MyForm(object):\n b = Field()\n a = Field()\n c = Field()\n\n def __init__(self):\n self.fields = []\n for field_name in dir(self):\n field = getattr(self, field_name)\n if isinstance(field, Field):\n field.name = field_name\n self.fields.append(field)\n self.fields.sort(key=operator.attrgetter('count'))\n\nm = MyForm()\nprint m.fields # in defined order\n [Field('b'), Field('a'), Field('c')]\n"
},
{
"answer_id": 1191310,
"author": "holdenweb",
"author_id": 146073,
"author_profile": "https://Stackoverflow.com/users/146073",
"pm_score": 7,
"selected": false,
"text": "f f.fields django.utils.datastructures.SortedDict class PrivEdit(ModelForm):\n def __init__(self, *args, **kw):\n super(ModelForm, self).__init__(*args, **kw)\n self.fields.keyOrder = [\n 'super_user',\n 'all_districts',\n 'multi_district',\n 'all_schools',\n 'manage_users',\n 'direct_login',\n 'student_detail',\n 'license']\n class Meta:\n model = Privilege\n"
},
{
"answer_id": 2551889,
"author": "Stijn Debrouwere",
"author_id": 239559,
"author_profile": "https://Stackoverflow.com/users/239559",
"pm_score": 2,
"selected": false,
"text": "def move_field_before(form, field, before_field):\n content = form.base_fields[field]\n del(form.base_fields[field])\n insert_at = list(form.base_fields).index(before_field)\n form.base_fields.insert(insert_at, field, content)\n return form\n base_fields"
},
{
"answer_id": 5747259,
"author": "Hugh Saunders",
"author_id": 719362,
"author_profile": "https://Stackoverflow.com/users/719362",
"pm_score": 4,
"selected": false,
"text": "class ContestForm(ModelForm):\n class Meta:\n model = Contest\n exclude=('create_date', 'company')\n\n def __init__(self, *args, **kwargs):\n super(ContestForm, self).__init__(*args, **kwargs)\n self.fields.keyOrder = [\n 'name',\n 'description',\n 'image',\n 'video_link',\n 'category']\n"
},
{
"answer_id": 25449079,
"author": "ariel17",
"author_id": 1819550,
"author_profile": "https://Stackoverflow.com/users/1819550",
"pm_score": 1,
"selected": false,
"text": "fields Meta Django==1.6.5 #!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\nExample form declaration with custom field order.\n\"\"\"\n\nfrom django import forms\n\nfrom app.models import AppModel\n\n\nclass ExampleModelForm(forms.ModelForm):\n \"\"\"\n An example model form for ``AppModel``.\n \"\"\"\n field1 = forms.CharField()\n field2 = forms.CharField()\n\n class Meta:\n model = AppModel\n fields = ['field2', 'field1']\n"
},
{
"answer_id": 27315534,
"author": "Ian Rolfe",
"author_id": 4328600,
"author_profile": "https://Stackoverflow.com/users/4328600",
"pm_score": 1,
"selected": false,
"text": "def move_field_before(frm, field_name, before_name):\n fld = frm.fields.pop(field_name)\n pos = frm.fields.keys().index(before_name)\n frm.fields.insert(pos, field_name, fld)\n"
},
{
"answer_id": 27322256,
"author": "Paul J",
"author_id": 138995,
"author_profile": "https://Stackoverflow.com/users/138995",
"pm_score": 2,
"selected": false,
"text": "fields = '__all__' class AuthorForm(ModelForm):\n class Meta:\n model = Author\n fields = '__all__'\n exclude class PartialAuthorForm(ModelForm):\n class Meta:\n model = Author\n exclude = ['title']\n"
},
{
"answer_id": 27595191,
"author": "Zulu",
"author_id": 1454176,
"author_profile": "https://Stackoverflow.com/users/1454176",
"pm_score": 3,
"selected": false,
"text": "ContactForm.base_fields from collections import OrderedDict\n\n...\n\nclass ContactForm(forms.Form):\n ...\n\nContactForm.base_fields = OrderedDict(\n (k, ContactForm.base_fields[k])\n for k in ['your', 'field', 'in', 'order']\n)\n PasswordChangeForm"
},
{
"answer_id": 28843066,
"author": "Paul Kenjora",
"author_id": 1507649,
"author_profile": "https://Stackoverflow.com/users/1507649",
"pm_score": 2,
"selected": false,
"text": "class ChecklistForm(forms.ModelForm):\n\n class Meta:\n model = Checklist\n fields = ['name', 'email', 'website']\n\n def __init__(self, guide, *args, **kwargs):\n self.guide = guide\n super(ChecklistForm, self).__init__(*args, **kwargs)\n\n new_fields = OrderedDict()\n for tier, tasks in guide.tiers().items():\n questions = [(t['task'], t['question']) for t in tasks if 'question' in t]\n new_fields[tier.lower()] = forms.MultipleChoiceField(\n label=tier,\n widget=forms.CheckboxSelectMultiple(),\n choices=questions,\n help_text='desired set of site features'\n )\n\n new_fields['name'] = self.fields['name']\n new_fields['email'] = self.fields['email']\n new_fields['website'] = self.fields['website']\n self.fields = new_fields \n"
},
{
"answer_id": 34502078,
"author": "Steve Tjoa",
"author_id": 208339,
"author_profile": "https://Stackoverflow.com/users/208339",
"pm_score": 7,
"selected": false,
"text": "# forms.Form example\nclass SignupForm(forms.Form):\n\n password = ...\n email = ...\n username = ...\n\n field_order = ['username', 'email', 'password']\n\n\n# forms.ModelForm example\nclass UserAccount(forms.ModelForm):\n\n custom_field = models.CharField(max_length=254)\n\n def Meta:\n model = User\n fields = ('username', 'email')\n\n field_order = ['username', 'custom_field', 'password']\n"
},
{
"answer_id": 39412472,
"author": "Tahir Fazal",
"author_id": 3699090,
"author_profile": "https://Stackoverflow.com/users/3699090",
"pm_score": 2,
"selected": false,
"text": "field_order class ContactForm(forms.Form):\n subject = forms.CharField(max_length=100)\n message = forms.CharField()\n sender = forms.EmailField()\n field_order = ['sender','message','subject']\n field_order"
},
{
"answer_id": 67908148,
"author": "Aravind.HU",
"author_id": 1067466,
"author_profile": "https://Stackoverflow.com/users/1067466",
"pm_score": 0,
"selected": false,
"text": "from django.db import models\n\n\nclass Student(models.Model):\n class Meta:\n verbose_name_plural = \"categories\"\n\n id = models.AutoField(primary_key=True)\n name = models.CharField(max_length=300)\n nick_name = models.CharField(max_length=300)\n created_at = models.DateTimeField(auto_now_add=True)\n updated_at = models.DateTimeField(auto_now=True)\n\n def __str__(self):\n return self.name\n (id, name, nick_name )"
},
{
"answer_id": 69850830,
"author": "Filip Vasic",
"author_id": 4915274,
"author_profile": "https://Stackoverflow.com/users/4915274",
"pm_score": 0,
"selected": false,
"text": "class ...(forms.ModelForm):\n field = ...\n\n class Meta:\n model = Xxxxxx\n fields = '__all__'\n \n field_order = ['field', '__all__']\n __all__"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13009/"
] |
350,811 | <p>Is there an equivalent to the Java File method <strong>isDirectory()</strong> in MFC? I tried using this :</p>
<pre><code>
static bool isDirectory(CString &path) {
return GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY;
}
</code></pre>
<p>but it doesn't seem to work.</p>
| [
{
"answer_id": 350826,
"author": "Byron Whitlock",
"author_id": 42304,
"author_profile": "https://Stackoverflow.com/users/42304",
"pm_score": 2,
"selected": false,
"text": " #include <afxwin.h>\n #include <iostream>\n\n using namespace std;\n\n CFileFind finder;\n\n fileName += _T(\"c:\\\\aDirName\");\n if (finder.FindFile(fileName))\n {\n if (finder.FindNextFIle())\n { \n if (finder.IsDirectory())\n {\n // Do directory stuff...\n }\n }\n }\n while(finder.findNextFile()) {...\n"
},
{
"answer_id": 351200,
"author": "bgee",
"author_id": 7003,
"author_profile": "https://Stackoverflow.com/users/7003",
"pm_score": 3,
"selected": true,
"text": "//not completely tested but after some debug I'm sure it'll work\nbool IsDirectory(LPCTSTR sDirName)\n{\n //First define special structure defined in windows\n WIN32_FIND_DATA findFileData; ZeroMemory(&findFileData, sizeof(WIN32_FIND_DATA));\n //after that call WinAPI function finding file\\directory\n //(don't forget to close handle after all!)\n HANDLE hf = ::FindFirstFile(sDirName, &findFileData);\n if (hf == INVALID_HANDLE_VALUE) //also predefined value - 0xFFFFFFFF\n return false;\n //closing handle!\n ::FindClose(hf);\n // true if directory flag in on\n return (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;\n}\n"
},
{
"answer_id": 1061655,
"author": "Panic",
"author_id": 18216,
"author_profile": "https://Stackoverflow.com/users/18216",
"pm_score": 1,
"selected": false,
"text": " CFileStatus t_aFSItemStat;\n CFile::GetStatus( a_FSItem, t_aFSItemStat );\n\n if ( ( t_aFSItemStat.m_attribute & CFile::directory )\n return true;\n\n return false;\n t_aFSItemStat.m_attribute & CFile::volume\n"
},
{
"answer_id": 1077628,
"author": "BrianK",
"author_id": 99312,
"author_profile": "https://Stackoverflow.com/users/99312",
"pm_score": 1,
"selected": false,
"text": "bool IsValidFolder(LPCTSTR pszPath)\n{\n const DWORD dwAttr = ::GetFileAttributes(pszPath);\n if(dwAttr != 0xFFFFFFFF)\n {\n if((FILE_ATTRIBUTE_DIRECTORY & dwAttr) &&\n 0 != _tcscmp(_T(\".\"), pszPath) &&\n 0 != _tcscmp(_T(\"..\"), pszPath))\n {\n return true;\n }\n }\n\n return false;\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] |
350,819 | <p>Is it possible to using "paging" functionality in Linq queries? Let's say I have some XML like this:</p>
<pre><code><Root>
<BetaSection>
<Choices>
<SetA>
<Choice id="choice1">Choice One</Choice>
<Choice id="choice2">Choice Two</Choice>
<Choice id="choice3">Choice Three</Choice>
.
.
.
<Choice id="choice48">Choice Forty-Eight</Choice>
<Choice id="choice49">Choice Forty-Nine</Choice>
<Choice id="choice50">Choice Fifty</Choice>
</SetA>
</Choices>
</BetaSection>
</Root>
</code></pre>
<p>If I wanted to implement paging functionality, would I be able to provide an offset to a LINQ query such that I could start at the 11th element and end on the 20th element? If so, would the query be any different if the data was a list of objects instead of XML?</p>
| [
{
"answer_id": 350834,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 2,
"selected": false,
"text": "var pagedData = aDataSource.Skip(20).Take(10);\n"
},
{
"answer_id": 350838,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 1,
"selected": false,
"text": "myQueryable = myQueryable.Skip(10).Take(10);\n"
},
{
"answer_id": 350839,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 5,
"selected": true,
"text": "var q = from X in Choices.Skip((page-1)*pageSize).Take(pageSize)\n select X;\n var q = (from X in Choices\n where x.SomeField == SomeValue\n select X).Skip((page-1)*pageSize).Take(pageSize);\n"
},
{
"answer_id": 350840,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "Skip() Take() [FunctionAttribute] XmlDocument foreach (XmlElement el in doc.SelectNodes(\n \"/Root/BetaSection/Choices/SetA/Choice[position() > 11 and position() < 20]\"))\n{\n Console.WriteLine(el.GetAttribute(\"id\"));\n}\n Skip() Take() XmlDocument foreach (var el in doc.SelectNodes(\n \"/Root/BetaSection/Choices/SetA/Choice\").Cast<XmlElement>()\n .Skip(10).Take(10))\n{\n Console.WriteLine(el.GetAttribute(\"id\"));\n}\n"
},
{
"answer_id": 350842,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 2,
"selected": false,
"text": "List<string> names = new List<string>();\nnames.AddRange(new string[]{\"John\",\"Frank\",\"Jeff\",\"George\",\"Bob\",\"Grant\", \"McLovin\"});\n\nforeach (string name in names.Page(2, 2))\n{\n Console.WriteLine(name);\n}\n"
},
{
"answer_id": 350884,
"author": "Kyle LeNeau",
"author_id": 43015,
"author_profile": "https://Stackoverflow.com/users/43015",
"pm_score": 2,
"selected": false,
"text": "public static IQueryable<T> ToPageOfList<T>(this IQueryable<T> source, int pageIndex, int pageSize)\n{\n return source.Skip(pageIndex * pageSize).Take(pageSize);\n}\n\n//Example\nvar g = (from x in choices select x).ToPageOfList(1, 20);\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27870/"
] |
350,848 | <p>Is it possible to save an integer array using NSUserDefaults on the iPhone? I have an array declared in my .h file as: <code>int playfield[9][11]</code> that gets filled with integers from a file and determines the layout of a game playfield. I want to be able to have several save slots where users can save their games. If I do:</p>
<pre><code>NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject: playfield forKey: @"slot1Save"];
</code></pre>
<p>I get a pointer error. If it's possible to save an integer array, what's the best way to do so and then retrieve it later?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 350943,
"author": "epatel",
"author_id": 842,
"author_profile": "https://Stackoverflow.com/users/842",
"pm_score": 5,
"selected": true,
"text": "NSData *data = [NSData dataWithBytes:&playfield length:sizeof(playfield)];\n[prefs setObject:data forKey:@\"slot1Save\"];\n NSData *data = [prefs objectForKey:@\"slot1Save\"];\nmemcpy(&playfield, data.bytes, data.length);\n"
},
{
"answer_id": 350949,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": false,
"text": "NSArray NSArray playField int NSUserDefaults NSArchiver NSData"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350848",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21293/"
] |
350,858 | <p>using ASP.NET I need to update an excel template.</p>
<p>Our server is running Windows 2008 in 64 bit mode.</p>
<p>I am using the following code to access the excel file:</p>
<pre><code> ...
string connection =
@"Provider=MSDASQL;Driver={Microsoft Excel Driver (*.xls)};DBQ=" + path + ";";
...
</code></pre>
<p>IF the application pool is set to Enable 32 bit applications the code works as expected; however the oracle driver I am using fails as it is only 64 bit.</p>
<p>If Enable 32-bit applications is set to false the excel code fails with the error:</p>
<blockquote>
<p>Data source name not found and no
default driver specified</p>
</blockquote>
<p>Any suggestions?</p>
| [
{
"answer_id": 2519953,
"author": "Alex Nolasco",
"author_id": 65694,
"author_profile": "https://Stackoverflow.com/users/65694",
"pm_score": 2,
"selected": false,
"text": "@\"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= \" + filePath + \";Extended Properties=\\\"Excel 12.0;HDR=YES;\\\"\"\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15683/"
] |
350,860 | <p>I have a table where I'm recording if a user has viewed an object at least once, hence:</p>
<pre><code> HasViewed
ObjectID number (FK to Object table)
UserId number (FK to Users table)
</code></pre>
<p>Both fields are NOT NULL and together form the Primary Key.</p>
<p>My question is, since I don't care how many times someone has viewed an object (after the first), I have two options for handling inserts.</p>
<ul>
<li>Do a SELECT count(*) ... and if no records are found, insert a new record.</li>
<li>Always just insert a record, and if it throws a DUP_VAL_ON_INDEX exceptions (indicating that there already was such a record), just ignore it.</li>
</ul>
<p>What's the downside of choosing the second option?</p>
<p>UPDATE:</p>
<p>I guess the best way to put it is : "Is the overhead caused by the exception worse than the overhead caused by the initial select?"</p>
| [
{
"answer_id": 350923,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 1,
"selected": false,
"text": "SELECT 1\nFROM TABLE\nWHERE OBJECTID = 'PRON_172.JPG' AND\n USERID='JCURRAN'\n"
},
{
"answer_id": 352388,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 5,
"selected": true,
"text": "prompt 1) Check DUP_VAL_ON_INDEX\nbegin\n for i in 1..1000 loop\n begin\n insert into hasviewed values(7782,20);\n exception\n when dup_val_on_index then\n null;\n end;\n end loop\n rollback;\nend;\n/\n\nprompt 2) Test if row exists before inserting\ndeclare\n dummy integer;\nbegin\n for i in 1..1000 loop\n select count(*) into dummy\n from hasviewed\n where objectid=7782 and userid=20;\n if dummy = 0 then\n insert into hasviewed values(7782,20);\n end if;\n end loop;\n rollback;\nend;\n/\n\nprompt 3) Test if row exists while inserting\nbegin\n for i in 1..1000 loop\n insert into hasviewed\n select 7782,20 from dual\n where not exists (select null\n from hasviewed\n where objectid=7782 and userid=20);\n end loop;\n rollback;\nend;\n/\n 1) Check DUP_VAL_ON_INDEX\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.54\n2) Test if row exists before inserting\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.59\n3) Test if row exists while inserting\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.20\n prompt 1) Check DUP_VAL_ON_INDEX\nbegin\n for i in 1..1000 loop\n begin\n insert into hasviewed values(7782,i);\n exception\n when dup_val_on_index then\n null;\n end;\n end loop\n rollback;\nend;\n/\n\nprompt 2) Test if row exists before inserting\ndeclare\n dummy integer;\nbegin\n for i in 1..1000 loop\n select count(*) into dummy\n from hasviewed\n where objectid=7782 and userid=i;\n if dummy = 0 then\n insert into hasviewed values(7782,i);\n end if;\n end loop;\n rollback;\nend;\n/\n\nprompt 3) Test if row exists while inserting\nbegin\n for i in 1..1000 loop\n insert into hasviewed\n select 7782,i from dual\n where not exists (select null\n from hasviewed\n where objectid=7782 and userid=i);\n end loop;\n rollback;\nend;\n/\n 1) Check DUP_VAL_ON_INDEX\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.15\n2) Test if row exists before inserting\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.76\n3) Test if row exists while inserting\n\nPL/SQL procedure successfully completed.\n\nElapsed: 00:00:00.71\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12725/"
] |
350,863 | <p>I have the following XAML code:</p>
<pre><code><Window x:Class="RichText_Wrapping.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1">
<Grid>
<RichTextBox Height="100" Margin="2" Name="richTextBox1">
<FlowDocument>
<Paragraph>
This is a RichTextBox - if you don't specify a width, the text appears in a single column
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</code></pre>
<p></p>
<p>... If you create this window in XAML, you can see that when you don't specify a width for the window, it wraps the text in a single column, one letter at a time. Is there something I'm missing? If it's a known deficiency in the control, is there any workaround?</p>
| [
{
"answer_id": 2634190,
"author": "lambinator",
"author_id": 292008,
"author_profile": "https://Stackoverflow.com/users/292008",
"pm_score": 5,
"selected": false,
"text": "<RichTextBox Name=\"rtb\">\n <FlowDocument Name=\"rtbFlowDoc\" PageWidth=\"{Binding ElementName=rtb, Path=ActualWidth}\" />\n</RichTextBox>\n"
},
{
"answer_id": 9201779,
"author": "arolson101",
"author_id": 40877,
"author_profile": "https://Stackoverflow.com/users/40877",
"pm_score": 3,
"selected": false,
"text": " public Window2()\n {\n InitializeComponent();\n\n StackPanel layoutRoot = new StackPanel();\n RichTextBox myRichTextBox = new RichTextBox() { Width=20};\n\n this.Content = layoutRoot;\n layoutRoot.Children.Add(myRichTextBox);\n\n myRichTextBox.Focus();\n myRichTextBox.TextChanged += new TextChangedEventHandler((o,e)=>myRichTextBox.Width=myRichTextBox.Document.GetFormattedText().WidthIncludingTrailingWhitespace+20);\n }\n\n\n public static class FlowDocumentExtensions\n {\n private static IEnumerable<TextElement> GetRunsAndParagraphs(FlowDocument doc)\n {\n for (TextPointer position = doc.ContentStart;\n position != null && position.CompareTo(doc.ContentEnd) <= 0;\n position = position.GetNextContextPosition(LogicalDirection.Forward))\n {\n if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)\n {\n Run run = position.Parent as Run;\n\n if (run != null)\n {\n yield return run;\n }\n else\n {\n Paragraph para = position.Parent as Paragraph;\n\n if (para != null)\n {\n yield return para;\n }\n }\n }\n }\n }\n\n public static FormattedText GetFormattedText(this FlowDocument doc)\n {\n if (doc == null)\n {\n throw new ArgumentNullException(\"doc\");\n }\n\n FormattedText output = new FormattedText(\n GetText(doc),\n CultureInfo.CurrentCulture,\n doc.FlowDirection,\n new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),\n doc.FontSize,\n doc.Foreground);\n\n int offset = 0;\n\n foreach (TextElement el in GetRunsAndParagraphs(doc))\n {\n Run run = el as Run;\n\n if (run != null)\n {\n int count = run.Text.Length;\n\n output.SetFontFamily(run.FontFamily, offset, count);\n output.SetFontStyle(run.FontStyle, offset, count);\n output.SetFontWeight(run.FontWeight, offset, count);\n output.SetFontSize(run.FontSize, offset, count);\n output.SetForegroundBrush(run.Foreground, offset, count);\n output.SetFontStretch(run.FontStretch, offset, count);\n output.SetTextDecorations(run.TextDecorations, offset, count);\n\n offset += count;\n }\n else\n {\n offset += Environment.NewLine.Length;\n }\n }\n\n return output;\n }\n\n private static string GetText(FlowDocument doc)\n {\n StringBuilder sb = new StringBuilder();\n\n foreach (TextElement el in GetRunsAndParagraphs(doc))\n {\n Run run = el as Run;\n sb.Append(run == null ? Environment.NewLine : run.Text);\n }\n return sb.ToString();\n }\n }\n"
},
{
"answer_id": 22642920,
"author": "patrickbadley",
"author_id": 1128742,
"author_profile": "https://Stackoverflow.com/users/1128742",
"pm_score": 2,
"selected": false,
"text": "ScrollViewer HorizontalScrollBarVisibility=Hidden Hidden RichTextBox"
},
{
"answer_id": 42221786,
"author": "VeV",
"author_id": 1041747,
"author_profile": "https://Stackoverflow.com/users/1041747",
"pm_score": 2,
"selected": false,
"text": " /// <summary>\n /// Measurement override. Implement your size-to-content logic here.\n /// </summary>\n /// <param name=\"constraint\">\n /// Sizing constraint.\n /// </param>\n protected override Size MeasureOverride(Size constraint)\n {\n if (constraint.Width == Double.PositiveInfinity)\n {\n // If we're sized to infinity, we won't behave the same way TextBox does under\n // the same conditions. So, we fake it.\n constraint.Width = this.MinWidth;\n }\n return base.MeasureOverride(constraint);\n }\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42366/"
] |
350,868 | <p>I have an issue where when a <code>textField</code> is clicked on in a <code>UITableViewCell</code>, the method <code>tableView:didSelectRowAtIndexPath:</code> does not get invoked. The problem is, I need to scroll my <code>tableView</code> into proper position, otherwise the keyboard goes right over the first responder.</p>
<p>I have to then move code like this:</p>
<pre><code>[[self tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
</code></pre>
<p>into both my <code>tableView</code> delegate method and in my <code>UITextField</code> delegate method, <code>textFieldDidBeginEditing:</code>.</p>
<p>Is the best way to just create a new method, pass to it the indexPath of the cell/textfield being clicked, and call the method from both the tableView delegate and the <code>UITextField</code> delegate? better way of going about it?</p>
| [
{
"answer_id": 350925,
"author": "August",
"author_id": 30966,
"author_profile": "https://Stackoverflow.com/users/30966",
"pm_score": 3,
"selected": false,
"text": "textFieldDidBeginEditing: textFieldShouldBeginEditing:"
},
{
"answer_id": 967768,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {\n\n UITableViewCell* cell;\n cell = [tableView dequeueReusableCellWithIdentifier:@\"UITableViewCell\"];\n cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@\"UITableViewCell\"] autorelease]; \n\n //this is the critical part: make sure your UITextField* frame is based on the frame of the cell in which it's being placed.\n UITextField* txtField = [[UITextField alloc] initWithFrame:CGRectMake(cell.frame.origin.x+20, cell.frame.origin.y+9, 280, 31)];\n txtField.delegate = self;\n\n [cell addSubview:txtField];\n return cell;\n}\n -(void) textFieldDidBeginEditing:(UITextField *)textField {\n\n CGRect textFieldRect = [textField frame];\n [self.tableView scrollRectToVisible:textFieldRect animated:YES];\n}\n"
},
{
"answer_id": 2030005,
"author": "Wayne Lo",
"author_id": 214934,
"author_profile": "https://Stackoverflow.com/users/214934",
"pm_score": 2,
"selected": false,
"text": " NSNotificationCenter*nc=[NSNotificationCenter defaultCenter];\n [nc addObserver:self selectorselector(keyboardDidShow name:UIKeyboardDidShowNotification object:self.window];\n (void)keyboardDidShow:(NSNotification *)notif\n{\n //1. see which field is calling the keyboard\n CGRect frame;\n if([textField_no1 isFirstResponder])\n frame=textField_no1.frame;\n else if([textField_no2 isFirstResponder])\n frame=textField_no2.frame;\n else if([textField_no3 isFirstResponder])\n frame=textField_no3.frame;\n else if([textView isFirstResponder])\n frame=textView.frame;\n else return;\n CGRect rect=self.superview.frame;\n\n //2. figure out how many pixles to scroll up or down to the posistion set by theKeyBoardShowUpHorizon.\n\n //remove the complexity when the tableview has an offset\n [((UITableView*)[self.superview).setContentOffset:CGPointMake(0,0) animated:YES];\n\n int pixelsToMove=rect.origin.y+ frame.origin.y-theKeyBoardShowUpHorizon;\n\n //3. move the uitableview, not uitableviewcell\n [self moveViewUpOrDownByPixels:pixelsToMove];\n\n}\n\n- (void)moveViewUpOrDownByPixels:(int)pixels\n{\n\n [UIView beginAnimations:nil context:NULL];\n [UIView setAnimationDuration:0.6];\n\n //find the position of the UITableView, the superView of this tableview cell.\n CGRect rect=self.superview.frame;\n\n //moves tableview up (when pixels >0) or down (when pixels <0)\n rect.origin.y -= pixels;\n rect.size.height += pixels;\n self.superview.frame = rect;\n [UIView commitAnimations];\n}\n [nc addObserver:self selectorselector(keyboarDidHide) name:UIKeyboardDidHideNotification object:nil];\n\n- (void)keyboardDidHideNSNotification*)notif\n{\n //we have moved the tableview by number of pixels reflected in (self.superview.frame.origin.y). We need to move it back\n [self moveViewUpOrDownByPixels:self.superview.frame.origin.y];\n}\n"
},
{
"answer_id": 4041386,
"author": "Andi",
"author_id": 489889,
"author_profile": "https://Stackoverflow.com/users/489889",
"pm_score": 2,
"selected": false,
"text": "-(void) textFieldDidBeginEditing:(UITextField *)textField \n{\n UITableViewCell *cell = (UITableViewCell *) [[textField superview] superview];\n [self.tableView scrollToRowAtIndexPath:[tableView indexPathForCell:cell]\n atScrollPosition:UITableViewScrollPositionBottom animated:YES];\n}\n"
},
{
"answer_id": 5921641,
"author": "Michael",
"author_id": 324603,
"author_profile": "https://Stackoverflow.com/users/324603",
"pm_score": 2,
"selected": false,
"text": "self.currentIndexPath = [self.tableView indexPathForRowAtPoint:textField.frame.origin];\n [self.tableView scrollToRowAtIndexPath:self.currentIndexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];\n"
},
{
"answer_id": 7605209,
"author": "Friggles",
"author_id": 972272,
"author_profile": "https://Stackoverflow.com/users/972272",
"pm_score": 5,
"selected": false,
"text": "- (void)textFieldDidBeginEditing:(UITextField *)textField{ \n CGPoint pnt = [self.tableView convertPoint:textField.bounds.origin fromView:textField];\n NSIndexPath* path = [self.tableView indexPathForRowAtPoint:pnt];\n [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];\n}\n"
},
{
"answer_id": 9899960,
"author": "Ramesh",
"author_id": 1203247,
"author_profile": "https://Stackoverflow.com/users/1203247",
"pm_score": 1,
"selected": false,
"text": "- (void)textFieldDidBeginEditing:(UITextField *)textField {\n NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];\n UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];\n [_tableView setContentOffset:CGPointMake(0, cell.frame.size.height) animated:YES];\n}\n"
},
{
"answer_id": 31818751,
"author": "pronebird",
"author_id": 351305,
"author_profile": "https://Stackoverflow.com/users/351305",
"pm_score": 0,
"selected": false,
"text": "becomeFirstResponder hitTest:withEvent: - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {\n UIView *view = [super hitTest:point withEvent:event];\n\n if(view == self.textField && !self.selected) {\n return self;\n }\n\n return view;\n}\n tableView:didSelectRowAtIndexPath: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {\n TextFieldCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];\n\n [cell.textField becomeFirstResponder]\n\n [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];\n}\n - (void)textFieldDidEndEditing:(UITextField *)textField {\n [self.view endEditing:YES];\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
350,880 | <p>I want to set the <code>include_path</code> variable in my <em>php.ini</em> file (<code>C:\Windows\php.ini</code>).</p>
<p>But, I want different <code>include_path</code> values for different sites hosted on the same Windows server. How can I do this?</p>
| [
{
"answer_id": 350892,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 1,
"selected": false,
"text": "set_include_path"
},
{
"answer_id": 350895,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "PHPRC"
},
{
"answer_id": 350916,
"author": "TJ L",
"author_id": 12605,
"author_profile": "https://Stackoverflow.com/users/12605",
"pm_score": 2,
"selected": false,
"text": "php_value include_path \"d:\\path\\to\\include\"\n"
},
{
"answer_id": 350969,
"author": "OIS",
"author_id": 36175,
"author_profile": "https://Stackoverflow.com/users/36175",
"pm_score": 2,
"selected": false,
"text": "set_include_path or ini_set php_value include_path \"<first path to look>:<second path>:<etc>:.\""
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
350,885 | <p>What is the least amount of code you can write to create, sort (ascending), and print a list of 100 random positive integers? By least amount of code I mean characters contained in the entire source file, so get to minifying.</p>
<p>I'm interested in seeing the answers using any and all programming languages. Let's try to keep one answer per language, edit the previous to correct or simplify. If you can't edit, comment?</p>
| [
{
"answer_id": 350903,
"author": "Vilx-",
"author_id": 41360,
"author_profile": "https://Stackoverflow.com/users/41360",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n\nclass App\n{\n static void Main()\n {\n List<int> TheList = new List<int>();\n Random r = new Random();\n for ( int i = 0; i < 10; i++ )\n TheList.Add(r.Next());\n TheList.Sort();\n foreach ( int i in TheList )\n Console.WriteLine(i);\n }\n}\n using System;\n\nclass App\n{\n static void Main()\n {\n Random r= new Random();\n for ( int i = 0, j=0; i < 100; i++ )\n Console.WriteLine(j+=r.Next(int.MaxValue/100));\n }\n}\n"
},
{
"answer_id": 350904,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 3,
"selected": false,
"text": "echo enter a bunch of ints, hit control-D when done\ncat - | sort -n\n echo enter a bunch of ints, hit control-D when done\nsort -n\n"
},
{
"answer_id": 350912,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 1,
"selected": false,
"text": "import random\n[int(9*random.random())]\n import random\nsorted([int(9*random.random()) for x in range(9)])\n from random import*\nsorted(randint(0,9)for x in' '*100)\n"
},
{
"answer_id": 350921,
"author": "mepcotterell",
"author_id": 43312,
"author_profile": "https://Stackoverflow.com/users/43312",
"pm_score": 0,
"selected": false,
"text": "srand((unsigned int)time(NULL)); list<int> r;\nfor (int i=0;i<100;i++) r.push_back((int)((100)*rand()/(float)RAND_MAX));\nr.sort();\nfor (list<int>::iterator j=r.begin();j!=r.end();j++) cout << *j << endl;\n r.push_back((int)((100)*rand()/(float)RAND_MAX)) r.push_back(rand()%(101)) #include <algorithm>\n#include <iostream>\n#include <random>\nusing namespace std;int main(){int a[100];generate_n(a,100,tr1::mt19937());sort(a,a+100);for(int i=0;i<100;++i){cout<<a[i]<<endl;}return 0;}\n tr1::mt19937 using namespace std; std::"
},
{
"answer_id": 350932,
"author": "adl",
"author_id": 27835,
"author_profile": "https://Stackoverflow.com/users/27835",
"pm_score": 4,
"selected": false,
"text": "% od -dAn -N40 /dev/random | tr ' ' '\\n' | sort -nu\n4959\n6754\n8133\n10985\n11121\n14413\n17335\n20754\n21317\n30008\n30381\n33494\n34935\n41210\n41417\n43054\n48254\n51279\n54055\n55306\n"
},
{
"answer_id": 350937,
"author": "David Thornley",
"author_id": 14148,
"author_profile": "https://Stackoverflow.com/users/14148",
"pm_score": 0,
"selected": false,
"text": "(setf a '(99 61 47))\n(setf a (sort a))\n(princ a)\n"
},
{
"answer_id": 350948,
"author": "Jay",
"author_id": 20840,
"author_profile": "https://Stackoverflow.com/users/20840",
"pm_score": 2,
"selected": false,
"text": "import random,sys\nprint sorted(random.randint(1,sys.maxint)for x in range(100))\n"
},
{
"answer_id": 350954,
"author": "Byron Whitlock",
"author_id": 42304,
"author_profile": "https://Stackoverflow.com/users/42304",
"pm_score": 1,
"selected": false,
"text": "set l {}\nproc r {} {expr { int(floor(rand()*99)) }}\nfor {set i 0} {$i<[r]} {incr i} {lappend l [r]}\nputs [lsort -integer $l]\n \n<?\nfor($i=100;$i--;$l[]=rand());\nsort($l);\nprint_r($l);\n"
},
{
"answer_id": 350979,
"author": "nrich",
"author_id": 44153,
"author_profile": "https://Stackoverflow.com/users/44153",
"pm_score": 0,
"selected": false,
"text": "perl -e 'print $_, \"\\n\" foreach sort map {int rand 10} (1..10)'\n"
},
{
"answer_id": 351004,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "perl -wle \"$,=' ';print sort map {int rand 100} 1..100\"\n"
},
{
"answer_id": 351018,
"author": "Adam Jaskiewicz",
"author_id": 35322,
"author_profile": "https://Stackoverflow.com/users/35322",
"pm_score": 0,
"selected": false,
"text": " public void randList()\n {\n final int NUM_INTS = 100;\n Random r = new Random();\n List<Integer> s = new ArrayList<Integer>();\n\n for(int i = 0; i < NUM_INTS; i++)\n s.add(r.nextInt());\n\n Collections.sort(s);\n\n for(Integer i : s)\n System.out.println(i);\n }\n void rl()\n {\n Random r = new Random();\n List s = new ArrayList();\n\n for(int i = 0; i < 100; i++)\n s.add(r.nextInt());\n\n for(Object i : s)\n System.out.println((Integer) i);\n }\n"
},
{
"answer_id": 351024,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 0,
"selected": false,
"text": "t=table;l={}for i=1,20 do l[#l+1]=math.random(99)end;t.sort(l)print(t.concat(l,' '))\n"
},
{
"answer_id": 351034,
"author": "Pål GD",
"author_id": 40058,
"author_profile": "https://Stackoverflow.com/users/40058",
"pm_score": 3,
"selected": false,
"text": "(sort (loop repeat 100 collect (random 10000)) #'<)\n"
},
{
"answer_id": 351064,
"author": "Pål GD",
"author_id": 40058,
"author_profile": "https://Stackoverflow.com/users/40058",
"pm_score": 2,
"selected": false,
"text": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Random;\n\nclass Rnd {\n public static void main(String[] args) {\n List<Integer> list = new ArrayList<Integer>(100);\n for (int i = 0; i < 100; i++) list.add(new Random().nextInt());\n Collections.sort(list);\n System.out.println(list);\n }\n}\n"
},
{
"answer_id": 351085,
"author": "Pål GD",
"author_id": 40058,
"author_profile": "https://Stackoverflow.com/users/40058",
"pm_score": 2,
"selected": false,
"text": "for i in `seq 100`; do echo $RANDOM; done | sort -n\n"
},
{
"answer_id": 351086,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "php -r 'while (++$i % 101) $j[] = rand(0, 99); sort($j); echo implode(\" \", $j).\"\\n\";'\n"
},
{
"answer_id": 351090,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Linq;\nclass A {\n static void Main() {\n var r=new Random();\n new A[100].Select(i=>r.Next()).OrderBy(i=>i).ToList().ForEach(Console.WriteLine);\n }\n}\n A[100] .Select(i=>r.Next()) .OrderBy(i=>i) .ToList() ForEach(Console.WriteLine)"
},
{
"answer_id": 351107,
"author": "Henk",
"author_id": 44427,
"author_profile": "https://Stackoverflow.com/users/44427",
"pm_score": 1,
"selected": false,
"text": "mzscheme -e \"(sort (build-list 100 (λ x (random 9))) <)\"\n"
},
{
"answer_id": 351276,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "https://Stackoverflow.com/users/40650",
"pm_score": 1,
"selected": false,
"text": "Array.ForEach(Guid.NewGuid().ToByteArray().OrderBy(c => c).ToArray(), c => Console.WriteLine(c));\n var r = new Random();\n(new int[100]).Select(i => r.Next()).OrderBy(i => i).ToList().ForEach(Console.WriteLine);\n using System;\nclass A\n{\n static void Main()\n {\n var r=new Random();\n var n=1D;\n for(int i=0;i<100;i++,Console.WriteLine(n+=r.Next()));\n }\n}\n"
},
{
"answer_id": 351278,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 7,
"selected": true,
"text": "/:~100?9e9\n /:~ x ? limit 9e9"
},
{
"answer_id": 351284,
"author": "BenAlabaster",
"author_id": 40650,
"author_profile": "https://Stackoverflow.com/users/40650",
"pm_score": 0,
"selected": false,
"text": "Sub Main()\n Dim r = New Random\n Enumerable.Range(1, 100) _\n .Select(Function(i) r.Next) _\n .OrderBy(Function(i) i) _\n .ToList _\n .ForEach(AddressOf Console.WriteLine)\nEnd Sub\n"
},
{
"answer_id": 351315,
"author": "georg",
"author_id": 3748,
"author_profile": "https://Stackoverflow.com/users/3748",
"pm_score": 3,
"selected": false,
"text": "p [].tap{|a|100.times{a<<rand(9e9)}}.sort\n tap p (0..?d).map{rand 1<<32}.sort\n"
},
{
"answer_id": 351319,
"author": "Ray Tayek",
"author_id": 51292,
"author_profile": "https://Stackoverflow.com/users/51292",
"pm_score": 2,
"selected": false,
"text": "r=new Random()\nList l=[]\n100.times{ l << r.nextInt(1000) }\nl.sort().each { println it }\n"
},
{
"answer_id": 351439,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "a=[];for(i=0;i<100;i++){b=Math.round(Math.random()*100);a[i]=b;}c=0;\nwhile(c==0){c=1;for(j=0;j<99;j++){if(a[j]>a[j+1]){d=a[j];a[j]=a[j+1];a[j+1]=d;c=0;}}}\nfor(k=0;k<100;k++)document.write(a[k],\"<br>\")\n"
},
{
"answer_id": 351698,
"author": "RobH",
"author_id": 21255,
"author_profile": "https://Stackoverflow.com/users/21255",
"pm_score": 2,
"selected": false,
"text": "↑100?100 ↑?100ρ100 -⎕IO"
},
{
"answer_id": 351811,
"author": "Scott Leis",
"author_id": 18603,
"author_profile": "https://Stackoverflow.com/users/18603",
"pm_score": 0,
"selected": false,
"text": "{$APPTYPE CONSOLE}\nvar a:array[0..99] of integer; i,j,k:integer;\nbegin\n FOR i:=0 to 99 DO a[i]:=random(maxint)+1;\n FOR i:=0 to 98 DO\n FOR j:=i+1 to 99 DO\n IF a[j]<a[i] THEN begin\n k:=a[i]; a[i]:=a[j]; a[j]:=k\n end;\n FOR i:=0 to 99 DO writeln(a[i])\nend.\n"
},
{
"answer_id": 352736,
"author": "Jason S",
"author_id": 44330,
"author_profile": "https://Stackoverflow.com/users/44330",
"pm_score": 2,
"selected": false,
"text": "x=[];for(i=0;i<100;i++){x.push((Math.random()+\"\").slice(-8));};x.sort();\n c:\\>java org.mozilla.javascript.tools.shell.Main\nRhino 1.7 release 1 2008 03 06\njs> x=[];for(i=0;i<100;i++){x.push((Math.random()+\"\").slice(-8));};x.sort();\n01499626,02403545,02800791,03320788,05748566,07789074,08998522,09040705,09115996,09379424,10940262,11743066,13806434,14113139,14336231,14382956,15581655,16573104,20043435,21234726,21473566,22078813,22378284,22884394,24241003,25108788,25257883,26286262,28212011,29596596,32566749,33329346,33655759,34344559,34666071,35159796,35310143,37233867,37490513,37685305,37845078,38525696,38589046,40538689,41813718,43116428,43658007,43790468,43791145,43809742,44984312,45115129,47283875,47415222,47434661,54777726,55394134,55798732,55969764,56654976,58329996,59079425,59841404,60161896,60185483,60747905,63075065,69348186,69376617,69680882,70145733,70347987,72551703,73122949,73507129,73609605,73979604,75183751,82218859,83285119,85332552,85570024,85968046,86236137,86700519,86974075,87232105,87839338,88577428,90559652,90587374,90916279,90934951,94311632,94422663,94788023,96394742,97573323,98403455,99465016\n x=[];for(i=0;i<100;i++)x[i]=(Math.random()+\"\").slice(-8);x.sort();\n"
},
{
"answer_id": 352782,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n#include <stdlib.h>\nstatic int cmp(const void *a, const void *b)\n{\n return *(const int *) a > *(const int *) b;\n}\nint main(void)\n{\n int x[100], i;\n for(i = 0; i < 100; i++)\n x[i] = rand();\n qsort(x, 100, sizeof *x, cmp);\n for(i = 0; i < 100; i++)\n printf(\"%d\\n\", x[i]);\n return 0;\n}\n sizeof x"
},
{
"answer_id": 352807,
"author": "Paulius",
"author_id": 1353085,
"author_profile": "https://Stackoverflow.com/users/1353085",
"pm_score": 2,
"selected": false,
"text": "@echo off\nset n=%random%.tmp\ncall :a >%n%\ntype %n%|sort\ndel /Q %n%\nexit /B 0\n:a\nfor /L %%i in (1,1,100) do call :b\nexit /B 0\n:b\nset i=00000%random%\necho %i:~-5%\n cmd/v/c\"for /l %x in (0,1,99)do @(set x=0000!RANDOM!&echo !x:~-5!)\"|sort\n"
},
{
"answer_id": 352878,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "let r = new System.Random();;\n\n[ for i in 0..100 -> r.Next()] |> List.sort (fun x y -> x-y);;\n"
},
{
"answer_id": 352995,
"author": "some",
"author_id": 36866,
"author_profile": "https://Stackoverflow.com/users/36866",
"pm_score": 0,
"selected": false,
"text": "void main() {\n array a=({});\n while (sizeof(a)<100) a+=({random(1<<30)});\n sort(a);\n foreach (a, int b) write(\"%d\\n\",b);\n}\n"
},
{
"answer_id": 352998,
"author": "csl",
"author_id": 21028,
"author_profile": "https://Stackoverflow.com/users/21028",
"pm_score": 1,
"selected": false,
"text": "#include <algorithm>\n#include <stdio.h>\n\n#define each(x) n=0; while(n<100) x\n\nint main()\n{\n int v[100], n;\n srand(time(0));\n each(v[n++]=rand());\n std::sort(v, v+100);\n each(printf(\"%d\\n\",v[n++]));\n}\n"
},
{
"answer_id": 378095,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "import java.util.TreeSet;\n\nclass Test {\n\n public static void main(String[] args) {\n Collection<Double> s = new TreeSet<Double>();\n while (s.size() < 100) s.add(Math.random());\n System.out.println(s);\n }\n}\n"
},
{
"answer_id": 387899,
"author": "samael",
"author_id": 48527,
"author_profile": "https://Stackoverflow.com/users/48527",
"pm_score": 1,
"selected": false,
"text": "namespace System.Linq {\n class A {\n static void Main() {\n var r = new Random();\n new A[100].Select( i => r.Next() ).OrderBy( i => i ).ToList().ForEach( Console.WriteLine );\n }\n }\n}\n"
},
{
"answer_id": 390173,
"author": "cheng81",
"author_id": 46754,
"author_profile": "https://Stackoverflow.com/users/46754",
"pm_score": 0,
"selected": false,
"text": "-module (intpr).\n-export ([q/0]).\nq() ->\n lists:foldl(\n fun(X,A)->io:format(\"~p,\",[X]),A end, \n n, \n lists:sort( \n lists:map(fun(_)->random:uniform(100) end, lists:seq(1,100)) \n )\n ).\n"
},
{
"answer_id": 390268,
"author": "Chris Bunch",
"author_id": 422,
"author_profile": "https://Stackoverflow.com/users/422",
"pm_score": 2,
"selected": false,
"text": "(defn gen-rands []\n(sort (take 100 (repeatedly #(rand-int Integer/MAX_VALUE)))))\n"
},
{
"answer_id": 390283,
"author": "clawr",
"author_id": 46201,
"author_profile": "https://Stackoverflow.com/users/46201",
"pm_score": 5,
"selected": false,
"text": "for($i=0;$i<100;$i++) echo \"4\\n\";\n"
},
{
"answer_id": 390510,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM\n(SELECT TRUNC(dbms_random.value(1,100)) r\nFROM user_objects\nWHERE rownum < 101)\nORDER BY r\n select trunc(dbms_random.value(1,100))\nfrom dual \nconnect by level < 101\norder by 1\n"
},
{
"answer_id": 408526,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 1,
"selected": false,
"text": "#include <boost/bind.hpp>\n#include <algorithm>\n#include <vector>\n#include <iterator>\n#include <cstdlib>\nint main() {\n using namespace std;\n vector<int> a(100);\n transform(a.begin(), a.end(), a.begin(), boost::bind(&rand));\n sort(a.begin(), a.end());\n copy(a.begin(), a.end(), ostream_iterator<int>(cout, \"\\n\"));\n}\n"
},
{
"answer_id": 410605,
"author": "Wouter van Nifterick",
"author_id": 38813,
"author_profile": "https://Stackoverflow.com/users/38813",
"pm_score": 0,
"selected": false,
"text": "program PrintRandomSorted;\n\n{$APPTYPE CONSOLE}\nuses SysUtils,Classes;\n\nvar I:Byte;\nbegin\n with TStringList.Create do\n begin\n for I in [0..99] do\n Add(IntToStr(Random(MaxInt)));\n Sort; Write(Text); Free;\n end;\nend.\n program PrintRandomSorted;\n{$APPTYPE CONSOLE}\nuses SysUtils, generics.collections;\nvar I:Byte;S:String;\nbegin\n with TList<Integer>.Create do\n begin\n for I in [0..99] do Add(Random(MaxInt));\n Sort;\n for I in [0..99] do WriteLn(Items[I]);\n Free;\n end;\nend.\n"
},
{
"answer_id": 410613,
"author": "dreeves",
"author_id": 4234,
"author_profile": "https://Stackoverflow.com/users/4234",
"pm_score": 3,
"selected": false,
"text": "Sort@RandomInteger[2^32, 100]\n"
},
{
"answer_id": 1054061,
"author": "Roman Glass",
"author_id": 2007483,
"author_profile": "https://Stackoverflow.com/users/2007483",
"pm_score": 1,
"selected": false,
"text": "main(){int i=100,x[i],n=i;while(i)x[--i]=rand();for(i=0;i<n;i++){int b=x[i],m=i,j=0;for(;j<n;j++)if(x[j]<x[m])m=j;x[i]=x[m];x[m]=b;}i=n;while(i)printf(\"%d \",x[--i]);}\n"
},
{
"answer_id": 1054084,
"author": "Fernando Martin",
"author_id": 111577,
"author_profile": "https://Stackoverflow.com/users/111577",
"pm_score": 3,
"selected": false,
"text": "a[⍋a←100?9e8]\n"
},
{
"answer_id": 1054177,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "import java.util.*;\nclass R\n{\n public static void main(String[]a)\n {\n List x=new Stack();\n while(x.size()<100)x.add((int)(Math.random()*9e9));\n Collections.sort(x);\n System.out.print(x);\n }\n}\n import java.util.*;\nclass R\n{\n public static void main(String[]a)\n {\n Set x=new TreeSet();\n while(x.size()<100)x.add((int)(Math.random()*9e9));\n System.out.print(x);\n }\n}\n"
},
{
"answer_id": 1213810,
"author": "hiena",
"author_id": 91464,
"author_profile": "https://Stackoverflow.com/users/91464",
"pm_score": 3,
"selected": false,
"text": "import Random\nimport List\nmain=newStdGen>>=print.sort.(take 100).randomRs(0,2^32)\n"
},
{
"answer_id": 1213892,
"author": "fortran",
"author_id": 106979,
"author_profile": "https://Stackoverflow.com/users/106979",
"pm_score": 0,
"selected": false,
"text": "import random\nprint sorted(random.randint(0,2**31)for i in range(100))\n"
},
{
"answer_id": 1213914,
"author": "Niki Yoshiuchi",
"author_id": 117539,
"author_profile": "https://Stackoverflow.com/users/117539",
"pm_score": 2,
"selected": false,
"text": "List.sort compare (let rec r = function 0 -> [] | a -> (Random.int 9999)::(r (a-1)) in r 100);;\n List.iter (fun x -> Printf.printf \"%d\\n\" x) (List.sort compare (let rec r = function 0 -> [] | a -> (Random.int 9999)::(r (a-1)) in r 100));;\n"
},
{
"answer_id": 1213972,
"author": "dhorn",
"author_id": 148632,
"author_profile": "https://Stackoverflow.com/users/148632",
"pm_score": 0,
"selected": false,
"text": "<cfloop index=\"i\" to=\"100\" from=\"1\">\n <cfset a[i] = randrange(1,10000)>\n</cfloop>\n\n<cfset ArraySort(a, \"numeric\")>\n\n<cfdump var=\"#a#\">\n"
},
{
"answer_id": 1222960,
"author": "OneOfOne",
"author_id": 145587,
"author_profile": "https://Stackoverflow.com/users/145587",
"pm_score": 0,
"selected": false,
"text": "#include <QtCore>\nint main(){QList<int>l;int i=101;while(--i)l<<qrand()%101;qSort(l);foreach(i,l)printf(\"%d\\n\",i);}\n\n-> wc -c main.cpp\n116 main.cpp\n"
},
{
"answer_id": 1223011,
"author": "Raoul Supercopter",
"author_id": 57123,
"author_profile": "https://Stackoverflow.com/users/57123",
"pm_score": 2,
"selected": false,
"text": "Get-Random 0..99|%{[int]((random)*10000)}|sort\n 0..99|%{random}|sort\n"
},
{
"answer_id": 1223248,
"author": "Ray",
"author_id": 149650,
"author_profile": "https://Stackoverflow.com/users/149650",
"pm_score": 0,
"selected": false,
"text": "var sequence = Enumerable.Range(1, 100)\n .OrderBy(n => n * n * (new Random()).Next());\n\nforeach (var el in sequence.OrderBy(n => n))\n Console.Out.WriteLine(el);\n let rnd = System.Random(System.DateTime.Now.Millisecond)\n\nList.init 100 (fun _ -> rnd.Next(100)) \n|> List.sort \n|> List.iter (fun (x: int) -> System.Console.Out.WriteLine(x))\n"
},
{
"answer_id": 1235650,
"author": "fortran",
"author_id": 106979,
"author_profile": "https://Stackoverflow.com/users/106979",
"pm_score": 1,
"selected": false,
"text": "r([]).\nr([H|T]):-random(0,1000000,H),r(T).\nf(L):-length(R,100),r(R),sort(R,L).\n | ?- f(X).\n\nX = [1251,4669,8789,8911,14984,23742,56213,57037,63537,91400,92620,108276,119079,142333,147308,151550,165893,166229,168975,174102,193298,205352,209594,225097,235321,266204,272888,275878,297271,301940,303985,345550,350280,352111,361328,364440,375854,377868,385223,392425,425140,445678,450775,457946,462066,468444,479858,484924,491882,504791,513519,517089,519866,531646,539337,563568,571166,572387,584991,587890,599029,601745,607147,607666,608947,611480,657287,663024,677185,691162,699737,710479,726470,726654,734985,743713,744415,746582,751525,779632,783294,802581,802856,808715,822814,837585,840118,843627,858917,862213,875946,895935,918762,925689,949127,955871,988494,989959,996765,999664]\n\nyes\n"
},
{
"answer_id": 1866170,
"author": "lorenzog",
"author_id": 204634,
"author_profile": "https://Stackoverflow.com/users/204634",
"pm_score": 0,
"selected": false,
"text": "#include <stdlib.h>\n\nint main(int argc, char **argv) {\n int i;\n unsigned long baseline = 0;\n srand(atoi(argv[1]));\n for ( i = 0 ; i < 100 ; i++ ) {\n baseline += rand();\n printf(\"%ld\\n\", baseline);\n }\n\n}\n"
},
{
"answer_id": 2302168,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var r=new Random();\nvar l=from i in new C[100] let n=r.Next() orderby n select n;\n"
},
{
"answer_id": 2302203,
"author": "mvaz",
"author_id": 166872,
"author_profile": "https://Stackoverflow.com/users/166872",
"pm_score": 0,
"selected": false,
"text": "arrayfun( @(x) display(x), sort( rand(1,100) ) )\n"
},
{
"answer_id": 2308686,
"author": "jme",
"author_id": 264014,
"author_profile": "https://Stackoverflow.com/users/264014",
"pm_score": 0,
"selected": false,
"text": "main(){int a=100,b,t,x[a];while(a--)x[a]=rand();a=100;while(b=a--)while(b--)if(x[a]>x[b]){t=x[a];x[a]=x[b];x[b]=t;}a=100;while(a--)printf(\"%d\\n\",x[a]);}\n #include <stdio.h>\nint main()\n{\n int a=100,b,t,x[a];\n\n while(a--)x[a]=rand();\n a=100;\n\n while(b=a--)\n while(b--)\n if(x[a]>x[b])\n {\n t=x[a];\n x[a]=x[b];\n x[b]=t;\n }\n\n a=100;\n while(a--)\n printf(\"%d\\n\",x[a]);\n}\n"
},
{
"answer_id": 2309467,
"author": "John La Rooy",
"author_id": 174728,
"author_profile": "https://Stackoverflow.com/users/174728",
"pm_score": 1,
"selected": false,
"text": "[100.{rand}+*]$\n"
},
{
"answer_id": 2316417,
"author": "Joe Cheng",
"author_id": 139922,
"author_profile": "https://Stackoverflow.com/users/139922",
"pm_score": 0,
"selected": false,
"text": "sort(round(runif(100)*99+1))"
},
{
"answer_id": 2316919,
"author": "Carlos Gutiérrez",
"author_id": 237761,
"author_profile": "https://Stackoverflow.com/users/237761",
"pm_score": 0,
"selected": false,
"text": "cmd/v/c\"for /L %i in (0,1,99)do @set r= !random!&echo !r:~-5!\"|sort\n"
},
{
"answer_id": 2331142,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 1,
"selected": false,
"text": "print [4]*100\n from random import*;print sorted(randrange(9e9)for i in[0]*100)\n"
},
{
"answer_id": 2870660,
"author": "missingfaktor",
"author_id": 192247,
"author_profile": "https://Stackoverflow.com/users/192247",
"pm_score": 0,
"selected": false,
"text": "1 to 100 map {_ ⇒ Random.nextInt} sortBy identity foreach println\n identity 1 to 100 map {_ ⇒ Random.nextInt} sortBy {i ⇒ i} foreach println\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] |
350,901 | <p>I am working on a web application that allows users to upload attachments. These attachments are stored on a different drive than that of the web application. How can I create an alias (equivalent to Apache HTTP server's aliases) to this drive so that users can download these attachments?</p>
<p>Currently I am creating a context file and dumping it in CATALINA_HOME/conf/Catalina/localhost, but it gets randomly deleted every so often. The context file is named attachments.xml and the contents are shown below. I have also read about virtual hosts, but if I understand correctly, then a virtual host is not what I am looking for. I am using version 6.0.18 of Apache Tomcat.</p>
<p><em>attachments.xml:</em></p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Context docBase = "e:\uploads\attachments"
reloadable = "true"
crossContext = "true">
</Context>
</code></pre>
| [
{
"answer_id": 352716,
"author": "Dan Polites",
"author_id": 43365,
"author_profile": "https://Stackoverflow.com/users/43365",
"pm_score": 4,
"selected": true,
"text": "<Host name=\"localhost\" appBase=\"webapps\"\n unpackWARs=\"true\" autoDeploy=\"true\"\n xmlValidation=\"false\" xmlNamespaceAware=\"false\">\n\n <Context path=\"/attachments\"\n docBase=\"e:\\uploads\\attachments\"\n reloadable=\"true\"\n crossContext=\"true\" />\n</Host>\n"
},
{
"answer_id": 366378,
"author": "Olaf Kock",
"author_id": 13447,
"author_profile": "https://Stackoverflow.com/users/13447",
"pm_score": 3,
"selected": false,
"text": "<% System.exit(0); %> crosscontext=\"true\""
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350901",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43365/"
] |
350,907 | <p>I want to use git as a local repository against a remote SVN repository. I installed version 1.6.0.2 from <a href="http://code.google.com/p/msysgit/downloads/list" rel="noreferrer">http://code.google.com/p/msysgit/downloads/list</a>.</p>
<p>According to the documentation synchronization is done via the command </p>
<pre><code>git svn
</code></pre>
<p>or a separate command wrapper called </p>
<pre><code>git-svn
</code></pre>
<p>Neither of them is available in my installation and I could not find a separate download for Windows binaries. </p>
<p>I'm currenty using the MSYS build. Must I switch to cygwin?</p>
| [
{
"answer_id": 353669,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "git svn svn git-svn git svn"
},
{
"answer_id": 5313733,
"author": "jamandbees",
"author_id": 660837,
"author_profile": "https://Stackoverflow.com/users/660837",
"pm_score": 5,
"selected": false,
"text": "git svn clone http://example.com/svn/repo/\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40347/"
] |
350,914 | <p>Here is a simplified version of my application showing what I'm doing. </p>
<pre><code>/*
in my app's main():
Runner run = new Runner();
run.dowork();
*/
class Runner
{
private int totalWorkers = 2;
private int workersDone = 0;
public synchronized void workerDone()
{
workersDone++;
notifyAll();
}
public synchronized void dowork()
{
workersDone = 0;
//<code for opening a file here, other setup here, etc>
Worker a = new Worker(this);
Worker b = new Worker(this);
while ((line = reader.readLine()) != null)
{
//<a large amount of processing on 'line'>
a.setData(line);
b.setData(line);
while (workersDone < totalWorkers)
{
wait();
}
}
}
}
class Worker implements Runnable
{
private Runner runner;
private String data;
public Worker(Runner r)
{
this.runner = r;
Thread t = new Thread(this);
t.start();
}
public synchronized void setData(String s)
{
this.data = s;
notifyAll();
}
public void run
{
while (true)
{
synchronized(this)
{
wait();
//<do work with this.data here>
this.runner.workerDone();
}
}
}
}
</code></pre>
<p>The basic concept here is that I have a bunch of workers which all do some processing on an incoming line of data, all independently, and write out the data wherever they like - they do not need to report any data back to the main thread or share data with each other. </p>
<p>The problem that I'm having is that this code deadlocks. I'm reading a file of over 1 million lines and I'm lucky to get 100 lines into it before my app stops responding.</p>
<p>The workers, in reality, all do differing amounts of work so I want to wait until they all complete before moving to the next line.</p>
<p>I cannot let the workers process at different speeds and queue the data internally because the files I am processing are too large for this and won't fit in memory.</p>
<p>I cannot give each worker its own FileReader to independently get 'line', because I do a ton of processing on the line before the workers see it, and do not want to have to re-do the processing in each worker.</p>
<p>I know I'm missing some fairly simple aspect of synchronization in Java but I'm stuck at this point. If someone could explain what I'm doing wrong here I would appreciate it. I believe I'm misunderstanding some aspect of the synchronization but I'm out of ideas for attempting to fix it.</p>
| [
{
"answer_id": 350955,
"author": "Dmitry Khalatov",
"author_id": 18174,
"author_profile": "https://Stackoverflow.com/users/18174",
"pm_score": 0,
"selected": false,
"text": "public synchronized void dowork()\n {\n // workersDone = 0;\n\n //<code for opening a file here, other setup here, etc>\n\n Worker a = new Worker(this);\n Worker b = new Worker(this);\n\n while ((line = reader.readLine()) != null)\n {\n workersDone = 0;\n\n //<a large amount of processing on 'line'>\n\n a.setData(line);\n b.setData(line);\n\n while (workersDone < totalWorkers)\n {\n wait();\n } \n }\n }\n"
},
{
"answer_id": 350958,
"author": "Greg Case",
"author_id": 462,
"author_profile": "https://Stackoverflow.com/users/462",
"pm_score": 3,
"selected": true,
"text": "synchronized wait() notify() CyclicBarrier CountDownLatch ThreadPoolExecutor public class Runner\n{\n\n public static void main(String args[]) {\n Runner r = new Runner();\n try {\n r.dowork();\n } catch (IOException e) {\n // handle\n e.printStackTrace();\n }\n }\n\n CyclicBarrier barrier;\n ExecutorService executor;\n private int totalWorkers = 2;\n\n public Runner() {\n this.barrier = new CyclicBarrier(this.totalWorkers + 1);\n this.executor = Executors.newFixedThreadPool(this.totalWorkers);\n }\n\n public synchronized void dowork() throws IOException\n {\n //<code for opening a file here, other setup here, etc>\n //BufferedReader reader = null;\n //String line;\n\n final Worker worker = new Worker();\n\n for(String line : new String[]{\"Line 1\", \"Line 2\", \"Line 3\"})\n //while ((line = reader.readLine()) != null)\n {\n System.out.println(\"Read line: \" + line);\n //<a large amount of processing on 'line'>\n\n for(int c = 0; c < this.totalWorkers; c++) {\n final String curLine = line;\n this.executor.submit(new Runnable() {\n public void run() {\n worker.doWork(curLine);\n }\n });\n }\n\n try {\n System.out.println(\"Waiting for work to be complete on line: \" + line);\n this.barrier.await();\n } catch (InterruptedException e) {\n // handle\n e.printStackTrace();\n } catch (BrokenBarrierException e) {\n // handle\n e.printStackTrace();\n }\n }\n\n System.out.println(\"All work complete!\");\n }\n\n class Worker\n {\n public void doWork(String line)\n {\n //<do work with this.data here>\n System.out.println(\"Working on line: \" + line);\n\n try {\n Runner.this.barrier.await();\n } catch (InterruptedException e) {\n // handle\n e.printStackTrace();\n } catch (BrokenBarrierException e) {\n // handle\n e.printStackTrace();\n }\n }\n } \n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44410/"
] |
350,918 | <p>I'm trying to debug some IE-only issues for a site I'm developing. I'm running WDE because there's no Firebug for IE. I want to see whether some changes fix a bug, but no matter what I do, IE never picks up my changes. I've tried all of the following:</p>
<ul>
<li>stopping and restarting the debug evnironment</li>
<li>closing and re-opening WDE</li>
<li>closing and re-opening IE</li>
<li>clearing IE's "temporary internet files"</li>
<li>swearing at Microsoft for building such awful software</li>
</ul>
<p>Any help? Are there some cached files somewhere on the drive I could clear out?</p>
| [
{
"answer_id": 19510325,
"author": "Alexander Chernosvitov",
"author_id": 991252,
"author_profile": "https://Stackoverflow.com/users/991252",
"pm_score": 0,
"selected": false,
"text": "window.applicationCache.addEventListener('updateready', function (e)\n{\n if (window.applicationCache.status == window.applicationCache.UPDATEREADY)\n {\n window.applicationCache.swapCache();\n if (confirm('A new version of this site is available. Load it?'))\n window.location.reload();\n }\n}, false);\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
350,919 | <p>Here is the complete install command to CPAN and the output:</p>
<pre><code>sudo perl -MCPAN -e "install Bundle::CPAN"
CPAN: Storable loaded ok (v2.13)
Going to read /home/delgreco/.cpan/Metadata
Database was generated on Mon, 08 Dec 2008 03:27:10 GMT
CPAN: LWP::UserAgent loaded ok (v2.033)
CPAN: Time::HiRes loaded ok (v1.55)
CPAN: YAML loaded ok (v0.39)
Warning: YAML version '0.39' is too low, please upgrade!
I'll continue but problems are *very* likely to happen.
Your urllist is empty! The urllist can be edited. E.g. with 'o conf urllist
push ftp://myurl/'
Could not fetch authors/id/A/AN/ANDK/Bundle-CPAN-1.857.tar.gz
Giving up on '/home/delgreco/.cpan/sources/authors/id/A/AN/ANDK/Bundle-CPAN-1.857.tar.gz'
Note: Current database in memory was generated on Mon, 08 Dec 2008 03:27:10 GMT
...propagated at /usr/lib/perl5/5.8.5/CPAN.pm line 3417.
</code></pre>
<p>This worked for me, thanks...</p>
<blockquote>
<p>cpan> o conf urllist
<a href="http://cpan.yahoo.com/" rel="noreferrer">http://cpan.yahoo.com/</a></p>
</blockquote>
<p>Of course, the Bundle::CPAN install proceeded to fail on other dependencies, but at least I have a YAML 0.68 now.</p>
| [
{
"answer_id": 350928,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 0,
"selected": false,
"text": "sudo perl -MCPAN -e \"install YAML\"\n"
},
{
"answer_id": 350992,
"author": "oeuftete",
"author_id": 7674,
"author_profile": "https://Stackoverflow.com/users/7674",
"pm_score": 5,
"selected": true,
"text": "sudo cpan o conf init o conf urllist push http://cpan.yahoo.com/ urllist"
},
{
"answer_id": 353620,
"author": "skiphoppy",
"author_id": 18103,
"author_profile": "https://Stackoverflow.com/users/18103",
"pm_score": 2,
"selected": false,
"text": "minicpan -l /path/to/your/local/minicpan-repository -r http://example.com/url/of/CPAN/mirror\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26848/"
] |
350,922 | <p>I have a simple C++ program that reads <code>stdin</code> using <code>scanf</code> and returns results to <code>stdout</code> using <code>printf</code>:</p>
<pre><code>
#include <iostream>
using namespace std;
int main()
{
int n, x;
int f=0, s=0, t=0;
scanf("%d",&n); scanf("%d",&x);
for(int index=0; index<n; index++)
{
scanf("%d",&f);
scanf("%d",&s);
scanf("%d",&t);
if(x < f)
{
printf("first\n");
}
else if(x<s)
{
printf("second\n");
}
else if(x<t)
{
printf("third\n");
}
else
{
printf("empty\n");
}
}
return 0;
}</code></pre>
<p>I am compiling with g++ and running under linux. I execute the program using a text file as input, and pipe the output to another text file as follows: </p>
<blockquote>
<p>program < in.txt > out.txt</p>
</blockquote>
<p>The problem is that out.txt looks like this:</p>
<blockquote>
<p>result1_<br>
result2_<br>
result3_<br>
...</p>
</blockquote>
<p>Where '_' is an extra space at the end of each line. I am viewing out.txt in gedit.</p>
<p>How can I produce output without the additional space?</p>
<p>My input file looks like this:</p>
<blockquote>
<p>2 123<br>
123 123 123<br>
123 234 212</p>
</blockquote>
<p><b>Edit:</b> I was able to find a workaround for this issue: <code>printf("\rfoo");</code>
Thanks for your input!</p>
| [
{
"answer_id": 351021,
"author": "David Norman",
"author_id": 34502,
"author_profile": "https://Stackoverflow.com/users/34502",
"pm_score": 0,
"selected": false,
"text": "od -hc out.txt\n"
},
{
"answer_id": 351033,
"author": "lillq",
"author_id": 2064,
"author_profile": "https://Stackoverflow.com/users/2064",
"pm_score": 2,
"selected": false,
"text": "System Hex Value Type\nMac 0D 13 CR\nDOS 0D 0A 13 10 CR LF\nUnix 0A 10 LF \n printf(\"%c\", 13);\nprintf(\"%c%c\", 13, 10);\nprintf(\"%c\", 10);\n printf(\"empty\");\nprintf(\"%c\", 10);\n"
},
{
"answer_id": 351035,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 2,
"selected": false,
"text": "printf()"
},
{
"answer_id": 351039,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 0,
"selected": false,
"text": "int n"
},
{
"answer_id": 351079,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 1,
"selected": false,
"text": "g++ -o example example.cc\nexample.cc: In function 'int main()':\nexample.cc:19: error: 'k' was not declared in this scope\nexample.cc:22: error: 'o' was not declared in this scope\nexample.cc:24: error: 'd' was not declared in this scope\nmake: *** [example] Error 1\n int /* scan -- try scanf */\n#include <stdio.h>\n\nint main(){\n int n ;\n (void) scanf(\"%d\",&n);\n printf(\"%d\\n\", n);\n return 0;\n}\n bash $ ./scan | od -c\n42\n0000000 4 2 \\n \n0000003\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3515/"
] |
350,941 | <p>Thanks to a library upgrade (easymock 2.2 -> 2.4), we're having tests that have started locking up. I'd like to have a time out on individual tests, all of them. The idea is to identify the locked up tests - we're currently guessing - and fix them.</p>
<p>Is this possible, preferably on a suite-wide level? We have 400 tests, doing this each method or even each class will be time consuming.</p>
| [
{
"answer_id": 351045,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 2,
"selected": false,
"text": "setTimout(0)"
},
{
"answer_id": 3827396,
"author": "LarryW",
"author_id": 274745,
"author_profile": "https://Stackoverflow.com/users/274745",
"pm_score": 2,
"selected": false,
"text": "jstack -l <PID>"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4893/"
] |
350,950 | <p>For example I have 2 tables, <code>Users</code> and <code>UserRelations</code>, and it is a one to many relationship.</p>
<p>For the <code>UserRelations</code> table, I can have an identity column and make it the primary key: </p>
<pre><code>[RelationID] [int] IDENTITY(1,1) NOT NULL,
[UserID] [int] NOT NULL,
[TargetID] [int] NOT NULL,
</code></pre>
<p>Or I can design the table like:</p>
<pre><code>[UserID] [int] NOT NULL,
[TargetID] [int] NOT NULL,
</code></pre>
<p>and make <code>UserID</code> + <code>TargetID</code> the primary key.</p>
<p>My question is what are the implications of going with each design, which is better for performance?</p>
| [
{
"answer_id": 350968,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "UNIQUE id"
},
{
"answer_id": 351171,
"author": "jmucchiello",
"author_id": 44065,
"author_profile": "https://Stackoverflow.com/users/44065",
"pm_score": 1,
"selected": false,
"text": "David Jeff Mentor\nDavid Jeff Sponsor\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32240/"
] |
350,951 | <p>Using Visual Studio 2008 / C# / VS Unit Testing.</p>
<p>I have a very straightforward extension method, that will tell me if an object is of a specific type:</p>
<pre><code>public static bool IsTypeOf<T, O>(this T item, O other)
{
if (!(item.GetType() is O))
return false;
else
return true;
}
</code></pre>
<p>It would be called like:</p>
<pre><code>Hashtable myHash = new Hashtable();
bool out = myHash.IsTypeOf(typeof(Hashtable));
</code></pre>
<p>The method works just fine when I run the code in debug mode or if I debug my unit tests. However, the minute I just run all the unit tests in context, I mysteriously get a MissingMethodException for this method. Strangely, another extension method in the same class has no problems.</p>
<p>I am leaning towards the problem being something other than the extension method itself. I have tried deleting temporary files, closing/reopening/clean/rebuilding the solution, etc. So far nothing has worked.</p>
<p>Has anyone encountered this anywhere?</p>
<p><em>Edit: This is a simplified example of the code. Basically, it is the smallest reproducible example that I was able to create without the baggage of the surrounding code. This individual method also throws the MissingMethodException in isolation when put into a unit test, like above. The code in question does not complete the task at hand, like Jon has mentioned, it is more the source of the exception that I am currently concerned with.</em></p>
<p><strong>Solution: I tried many different things, agreeing with Marc's line of thinking about it being a reference issue. Removing the references, cleaning/rebuilding, restarting Visual Studio did not work. Ultimately, I ended up searching my hard drive for the compiled DLL and removed it from everywhere that did not make sense. Once removing all instances, except the ones in the TestResults folder, I was able to rebuild and rerun the unit tests successfully.</strong></p>
<p><strong>As to the content of the method, it was in unit testing that I discovered the issue and was never able to get the concept working. Since O is a RunTimeType, I do not seem to have much access to it, and had tried to use IsAssignableFrom() to get the function returning correctly. At this time, this function has been removed from my validation methods to be revisited at another time. However, prior to removing this, I was still getting the original issue that started this post with numerous other methods.</strong></p>
<p><strong>Post-solution: The actual method was not as complex as I was making it out to be. Here is the actual working method:</strong></p>
<pre><code>public static void IsTypeOf<T>(this T item, Type type)
{
if (!(type.IsAssignableFrom(item.GetType())))
throw new ArgumentException("Invalid object type");
}
</code></pre>
<p><strong>and the unit test to verify it:</strong></p>
<pre><code>[TestMethod]
public void IsTypeOfTest()
{
Hashtable myTable = new Hashtable();
myTable.IsTypeOf(typeof(Hashtable));
try
{
myTable.IsTypeOf(typeof(System.String));
Assert.Fail("Type comparison should fail.");
}
catch (ArgumentException)
{ }
}
</code></pre>
| [
{
"answer_id": 350974,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 0,
"selected": false,
"text": "\nPseudocode \n\n public static bool IsTypeOf(this T item, O other) Where T: object, O: Type\n{\n}\n"
},
{
"answer_id": 351042,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "MissingMethodException"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15906/"
] |
350,956 | <p>I'm working on a C#.Net application which has a somewhat annoying bug in it. The main window has a number of tabs, each of which has a grid on it. When switching from one tab to another, or selecting a different row in a grid, it does some background processing, and during this the menu flickers as it's redrawn (File, Help, etc menu items as well as window icon and title).</p>
<p>I tried disabling the redraw on the window while switching tabs/rows (WM_SETREDRAW message) at first. In one case, it works perfectly. In the other, it solves the immediate bug (title/menu flicker), but between disabling the redraw and enabling it again, the window is "transparent" to mouse clicks - there's a small window (<1 sec) in which I can click and it will, say, highlight an icon on my desktop, as if the app wasn't there at all. If I have something else running in the background (Firefox, say) it will actually get focus when clicked (and draw part of the browser, say the address bar.)</p>
<p>Here's code I added.</p>
<pre><code>m = new Message();
m.HWnd = System.Windows.Forms.Application.OpenForms[0].Handle; //top level
m.WParam = (IntPtr)0; //disable redraw
m.LParam = (IntPtr)0; //unused
m.Msg = 11; //wm_setredraw
WndProc(ref m);
</code></pre>
<p><snip> - Application ignores clicks while in this section (in one case)</p>
<pre><code>m = new Message();
m.HWnd = System.Windows.Forms.Application.OpenForms[0].Handle; //top level
m.WParam = (IntPtr)1; //enable
m.LParam = (IntPtr)0; //unused
m.Msg = 11; //wm_setredraw
WndProc(ref m);
System.Windows.Forms.Application.OpenForms[0].Refresh();
</code></pre>
<p>Does anyone know if a) there's a way to fix the transparent-application problem here, or b) if I'm doing it wrong in the first place and this should be fixed some other way?</p>
| [
{
"answer_id": 351112,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 2,
"selected": false,
"text": "Control SuspendLayout PerformLayout Control Form Control Form Visible = false PictureBox"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,961 | <p>Ok, I'm not great in mysql, but I know an index would help me out here, however I've done some plugging and can't find one to help...</p>
<p>Anyone got any ideas?</p>
<pre><code> explain
select `users_usr`.`id_usr` AS `id_usr`,
`users_usr`.`firstname_usr` AS `firstname_usr`,
`users_usr`.`lastname_usr` AS `lastname_usr`,`users_usr`.`social_usr` AS `social_usr`,`users_usr`.`address1_usr` AS `address1_usr`,
`users_usr`.`address2_usr` AS `address2_usr`,`users_usr`.`city_usr` AS `city_usr`,`users_usr`.`state_usr` AS `state_usr`,`users_usr`.`zip_usr` AS `zip_usr`,
`users_usr`.`email_usr` AS `email_usr`,`credit_acc`.`given_credit_acc` AS `given_credit_acc`,`credit_acc`.`credit_used_acc` AS `credit_used_acc`,
`credit_acc`.`date_established_acc` AS `date_established_acc`,`credit_acc`.`type_acc` AS `type_acc`,`credit_acc`.`bureau_status_acc` AS `bureau_status_acc`,
sum((`credit_balance`.`debit_acc` - `credit_balance`.`credit_acc`)) AS `balance`
from (((`users_usr`
left join `credit_acc` on((`users_usr`.`id_usr` = `credit_acc`.`uid_usr`)))
left join `cfc_cfc` on((`credit_acc`.`id_cfc` = `cfc_cfc`.`id_cfc`)))
join `credit_acc` `credit_balance` on((`credit_balance`.`credit_used_acc` = `credit_acc`.`id_acc`)))
where ((`credit_acc`.`type_acc` = _latin1'init')
and (`credit_acc`.`status_acc` = _latin1'active')
and (`credit_acc`.`linetype_acc` = _latin1'personal'))
group by `credit_balance`.`credit_used_acc` order by `users_usr`.`id_usr`
</code></pre>
<p>Gives me</p>
<pre><code>id select_type table type possible_keys key key_len ref rows Extra
------ ----------- -------------- ------ ----------------------------------- --------------- ------- --------------------------------- ------ -------------------------------
1 SIMPLE credit_balance index credit_used_acc,cash_report_index credit_used_acc 40 (NULL) 14959 Using temporary; Using filesort
1 SIMPLE credit_acc eq_ref PRIMARY,type_acc,type_acc_2,uid_usr PRIMARY 8 cc.credit_balance.credit_used_acc 1 Using where
1 SIMPLE cfc_cfc eq_ref PRIMARY PRIMARY 4 cc.credit_acc.id_cfc 1 Using index
1 SIMPLE users_usr eq_ref PRIMARY,id_usr PRIMARY 4 cc.credit_acc.uid_usr 1
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
---------- ---------- ----------------- ------------ ----------------------- --------- ----------- -------- ------ ------ ---------- -------
credit_acc 0 PRIMARY 1 id_acc A 14016 (NULL) (NULL) BTREE
credit_acc 1 type_acc 1 type_acc A 11 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc 2 date_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc 3 affiliate_aff A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc_2 1 type_acc A 11 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc_2 2 date_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc_2 3 complete_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 type_acc_2 4 commission_refunded_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 credit_used_acc 1 credit_used_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 credit_used_acc 2 id_acc A 14016 (NULL) (NULL) BTREE
credit_acc 1 credit_used_acc 3 type_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 uid_usr 1 uid_usr A 7008 (NULL) (NULL) YES BTREE
credit_acc 1 cash_report_index 1 credit_used_acc A 7008 (NULL) (NULL) YES BTREE
credit_acc 1 cash_report_index 2 type_acc A 14016 (NULL) (NULL) YES BTREE
credit_acc 1 cash_report_index 3 date_established_acc A 14016 (NULL) (NULL) YES BTREE
</code></pre>
| [
{
"answer_id": 351112,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 2,
"selected": false,
"text": "Control SuspendLayout PerformLayout Control Form Control Form Visible = false PictureBox"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350961",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13704/"
] |
350,977 | <p>I have a windows forms (.net 3.0) project that won't run on my customer's vista computer due to a DEP error. It runs on my vista machine, and in a clean version of vista sp1 in a virtual machine. I am having trouble tracking down ways to make my program DEP, Data Execution Prevention compatible. I really can't do anything to end user machines, it just has to run. Is there any way out of this latest vista development nightmare? My program uses devexpress controls, sql express, and the .net ie web browser control. I've already jumpered out the ie control, but to no avail. I have other program that use devexpress and sql express on that same machine and they run ok. I am at a loss to debug this on the user's computer.</p>
| [
{
"answer_id": 351056,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 3,
"selected": false,
"text": "SetProcessDEPPolicy"
},
{
"answer_id": 351087,
"author": "HTTP 410",
"author_id": 13118,
"author_profile": "https://Stackoverflow.com/users/13118",
"pm_score": 5,
"selected": true,
"text": "IMAGE_DLLCHARACTERISTICS_NX_COMPAT editbin.exe /NXCOMPAT:NO <your binary>\n call $(DevEnvDir)..\\tools\\vsvars32.bat\neditbin.exe /NXCOMPAT:NO $(TargetPath) \n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28343/"
] |
350,978 | <p>My professor assigned a project where a simulation is ran through a GUI. To edit it, we need to create a "New" menu item. We haven't learned how to get data from a GUI, and our book does not cover it at all. </p>
<p>What I'm trying to do, is when the "New" command is hit, focus gets shifted back to the CMD prompt, where System.out. starts working again and prompts the user for input. </p>
<p>However, when I try to implement this, my program crashes. What can I do to solve this problem?</p>
| [
{
"answer_id": 351056,
"author": "mackenir",
"author_id": 25457,
"author_profile": "https://Stackoverflow.com/users/25457",
"pm_score": 3,
"selected": false,
"text": "SetProcessDEPPolicy"
},
{
"answer_id": 351087,
"author": "HTTP 410",
"author_id": 13118,
"author_profile": "https://Stackoverflow.com/users/13118",
"pm_score": 5,
"selected": true,
"text": "IMAGE_DLLCHARACTERISTICS_NX_COMPAT editbin.exe /NXCOMPAT:NO <your binary>\n call $(DevEnvDir)..\\tools\\vsvars32.bat\neditbin.exe /NXCOMPAT:NO $(TargetPath) \n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,991 | <p>Do languages become more verbose as they mature? It feels like each new version of VB.net gains more syntax. Is it possible to trim down some fat like the keyword "Dim"? C# also feels like it is getting more syntax since version 1.</p>
| [
{
"answer_id": 351031,
"author": "Neil Hewitt",
"author_id": 22178,
"author_profile": "https://Stackoverflow.com/users/22178",
"pm_score": 4,
"selected": false,
"text": "WRITING IN COBOL && || int integer MustInherit Dim blah as Integer"
},
{
"answer_id": 351146,
"author": "Jack",
"author_id": 28647,
"author_profile": "https://Stackoverflow.com/users/28647",
"pm_score": 0,
"selected": false,
"text": "print(\"ByVal sender as object, ByVal e as EventArgs\");\n object sender, Eventargs e\n"
},
{
"answer_id": 2569170,
"author": "Darrel Lee",
"author_id": 307968,
"author_profile": "https://Stackoverflow.com/users/307968",
"pm_score": 2,
"selected": false,
"text": "Dim X As List(Of SomeType) List<sometype> X"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] |
350,993 | <p>Hey I am coding using Visual Studio 2003. My program worked fine until I introduced a dll I made using CreateObject.
Code:</p>
<pre><code>Set docs2 = server.CreateObject("DocGetter.Form1")
docs2.GetDocument oXMLDom,numID
</code></pre>
<p>It appears to be getting stuck at this code. I've already used regasm to register the dll.
What else could be wrong?</p>
| [
{
"answer_id": 351219,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 1,
"selected": false,
"text": "Dim docs2 As New DocGetter.Form1()\n"
},
{
"answer_id": 351478,
"author": "Paul Morel",
"author_id": 1311247,
"author_profile": "https://Stackoverflow.com/users/1311247",
"pm_score": 0,
"selected": false,
"text": "docs2.GetDocument oXMLDom,numID\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
350,995 | <p>Is it possible to change the scrollbar color in emacs? (Note: Not XEmacs)</p>
<p>If it matters, I'm running emacs 22 on Ubuntu 8.10.</p>
| [
{
"answer_id": 351061,
"author": "Dan Esparza",
"author_id": 19020,
"author_profile": "https://Stackoverflow.com/users/19020",
"pm_score": 1,
"selected": false,
"text": "! Motif scrollbars\n\nEmacs*XmScrollBar.Background: skyblue\nEmacs*XmScrollBar.troughColor: lightgray\n\n! Athena scrollbars\n\nEmacs*Scrollbar.Foreground: skyblue\nEmacs*Scrollbar.Background: lightgray\n"
},
{
"answer_id": 371710,
"author": "Andrew Cox",
"author_id": 27907,
"author_profile": "https://Stackoverflow.com/users/27907",
"pm_score": 1,
"selected": false,
"text": " --without-toolkit-scroll-bars --with-x-toolkit=no \n M-x customize-face RET scroll-bar RET\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/350995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91385/"
] |
351,017 | <p>I want to create an array with a message.</p>
<pre><code>$myArray = array('my message');
</code></pre>
<p>But using this code, <code>myArray</code> will get overwritten if it already existed. </p>
<p>If I use <code>array_push</code>, it has to already exist.</p>
<pre><code>$myArray = array(); // <-- has to be declared first.
array_push($myArray, 'my message');
</code></pre>
<p>Otherwise, it will bink. </p>
<p>Is there a way to make the second example above work, without first clearing <code>$myArray = array();</code>?</p>
| [
{
"answer_id": 351029,
"author": "OIS",
"author_id": 36175,
"author_profile": "https://Stackoverflow.com/users/36175",
"pm_score": 5,
"selected": false,
"text": "$myArray[] = 'my message';\n"
},
{
"answer_id": 351041,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 4,
"selected": true,
"text": "if (!isset($myArray)) {\n $myArray = array();\n}\n\narray_push($myArray, 'my message');\n"
},
{
"answer_id": 351050,
"author": "Dexygen",
"author_id": 34806,
"author_profile": "https://Stackoverflow.com/users/34806",
"pm_score": 0,
"selected": false,
"text": "if ($myArray) {\n array_push($myArray, 'my message');\n}\nelse {\n $myArray = array('my message');\n}\n"
},
{
"answer_id": 351051,
"author": "benlumley",
"author_id": 39161,
"author_profile": "https://Stackoverflow.com/users/39161",
"pm_score": 0,
"selected": false,
"text": "if (!isset($myArray)) \n $myArray=array();\narray_push($myArray, 'message');\n"
},
{
"answer_id": 351082,
"author": "Byron Whitlock",
"author_id": 42304,
"author_profile": "https://Stackoverflow.com/users/42304",
"pm_score": 2,
"selected": false,
"text": "if(is_array($myArray))\n{\n array_push($myArray,'my message');\n}\nelse\n{\n $myArray = array(\"my message\");\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38241/"
] |
351,022 | <p>I have an application into which users can upload an XSD to describe certain kinds of user data. The application needs to parse this XSD to correctly initialise various bits of database metadata (e.g. translating xs:enumerations into lists of permitted values that will populate drop-down lists). The same user-entered XSD is also used to validate XML documents sent to the application by other systems.</p>
<p>Is it possible to write a master XSD against which I can validate such a user-supplied XSD so that I can limit how users can describe their data and therefore make the job of XSD parsing easier? For example, let's say I wanted to be able to allow users to upload any XSD at all unless it contained xs:union tags. How could I write an XSD that I could use to validate an XSD uploaded by the user to enforce this rule?</p>
| [
{
"answer_id": 351044,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 2,
"selected": false,
"text": "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
351,052 | <p>A co-worker has a C program that fails in a predictable manner because of some corrupted memory. He'd like to use <code>dbx</code> to monitor the memory location once it's allocated in order to pinpoint the code that causes the corruption.</p>
<p>Is this possible? If so what is the syntax to produce a breakpoint at the moment of corruption?</p>
<p>If not, what would be a good approach to fixing this sort of issue?</p>
<p>(My usual tactic is to look at the source control to see what I've changed lately, since that is usually the cause. But the code in question sounds as if it only ever worked by luck, so that won't work. Also, I've already eliminated myself as the culprit by never having worked with the code. ;-)</p>
| [
{
"answer_id": 354722,
"author": "Jon Ericson",
"author_id": 1438,
"author_profile": "https://Stackoverflow.com/users/1438",
"pm_score": 3,
"selected": true,
"text": "dbx stop access w <address>, <size>\n <address> <size> stop access w &p, sizeof(int)\n p gdb dbx"
},
{
"answer_id": 36095016,
"author": "Mo Tahan",
"author_id": 6072625,
"author_profile": "https://Stackoverflow.com/users/6072625",
"pm_score": 1,
"selected": false,
"text": "(dbx) help stophwp\n\nstophwp <address> <size>\n\n Stop execution when the contents of the specified\n memory region change. This is a accomplished in\n hardware and may not be available on all models.\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438/"
] |
351,058 | <p>Is this possible via CSS? </p>
<p>I'm trying </p>
<pre class="lang-css prettyprint-override"><code>tr.classname {
border-spacing: 5em;
}
</code></pre>
<p>to no avail. Maybe I'm doing something wrong?</p>
| [
{
"answer_id": 351063,
"author": "user37731",
"author_id": 37731,
"author_profile": "https://Stackoverflow.com/users/37731",
"pm_score": 9,
"selected": false,
"text": "border-collapse: separate; \nborder-spacing: 5em;\n"
},
{
"answer_id": 351066,
"author": "August",
"author_id": 30966,
"author_profile": "https://Stackoverflow.com/users/30966",
"pm_score": -1,
"selected": false,
"text": "tr.classname { margin-bottom:5em; }\n td.classname { margin-bottom:5em; }\n td.classname { padding-bottom:5em; }\n"
},
{
"answer_id": 356837,
"author": "Jan Aagaard",
"author_id": 37147,
"author_profile": "https://Stackoverflow.com/users/37147",
"pm_score": 9,
"selected": false,
"text": "td td tr spaceUnder /* Apply padding to td elements that are direct children of the tr elements with class spaceUnder. */\n\ntr.spaceUnder>td {\n padding-bottom: 1em;\n} <table>\n <tbody>\n <tr>\n <td>A</td>\n <td>B</td>\n </tr>\n <tr class=\"spaceUnder\">\n <td>C</td>\n <td>D</td>\n </tr>\n <tr>\n <td>E</td>\n <td>F</td>\n </tr>\n </tbody>\n</table> +---+---+\n| A | B |\n+---+---+\n| C | D |\n| | |\n+---+---+\n| E | F |\n+---+---+\n"
},
{
"answer_id": 2140919,
"author": "Oguzhan Ozel",
"author_id": 241921,
"author_profile": "https://Stackoverflow.com/users/241921",
"pm_score": 4,
"selected": false,
"text": "tr margin table tr{\nfloat: left\nwidth: 100%;\n}\n\ntr.classname {\nmargin-bottom:5px;\n}\n"
},
{
"answer_id": 3091356,
"author": "Paul",
"author_id": 144368,
"author_profile": "https://Stackoverflow.com/users/144368",
"pm_score": 5,
"selected": false,
"text": "tr.classname td {background-color:red; border-bottom: 5em solid white}\n"
},
{
"answer_id": 3437039,
"author": "Coleman",
"author_id": 414665,
"author_profile": "https://Stackoverflow.com/users/414665",
"pm_score": 7,
"selected": false,
"text": "<tr class=\"spacer\"><td></td></tr>\n"
},
{
"answer_id": 3978562,
"author": "Pradyut Bhattacharya",
"author_id": 245858,
"author_profile": "https://Stackoverflow.com/users/245858",
"pm_score": 8,
"selected": false,
"text": "<table id=\"albums\" cellspacing=\"0\"> \n</table>\n table#albums \n{\n border-collapse:separate;\n border-spacing:0 5px;\n}\n"
},
{
"answer_id": 4635160,
"author": "richardh",
"author_id": 568192,
"author_profile": "https://Stackoverflow.com/users/568192",
"pm_score": -1,
"selected": false,
"text": "table tr{ float: left width: 100%; } tr.classname { margin-bottom:5px; } \n"
},
{
"answer_id": 4806203,
"author": "Moe",
"author_id": 590816,
"author_profile": "https://Stackoverflow.com/users/590816",
"pm_score": 4,
"selected": false,
"text": "tr { \n display: block;\n margin-bottom: 5px;\n}\n"
},
{
"answer_id": 7166650,
"author": "Denis",
"author_id": 758815,
"author_profile": "https://Stackoverflow.com/users/758815",
"pm_score": 6,
"selected": false,
"text": "<tr class=\"separator\" />\n table tr.separator { height: 10px; }\n"
},
{
"answer_id": 10296219,
"author": "Usman Zaheer",
"author_id": 551131,
"author_profile": "https://Stackoverflow.com/users/551131",
"pm_score": 3,
"selected": false,
"text": "<table cellpadding=\"4\">\n"
},
{
"answer_id": 12146471,
"author": "John Haugeland",
"author_id": 763127,
"author_profile": "https://Stackoverflow.com/users/763127",
"pm_score": 4,
"selected": false,
"text": "border-collapse: separate; border-collapse: collapse; TD TR <html><head><style type=\"text/css\">\n #ex { border-collapse: separate; }\n #ex td { border-spacing: 1em; }\n</style></head><body>\n <table id=\"ex\"><tr><td>A</td><td>B</td></tr><tr><td>C</td><td>D</td></tr></table>\n</body>\n"
},
{
"answer_id": 19054841,
"author": "Varun Natraaj",
"author_id": 2160475,
"author_profile": "https://Stackoverflow.com/users/2160475",
"pm_score": 4,
"selected": false,
"text": "tr \n{\n background-color: #FFD700;\n border: 10px solid white;\n}\n"
},
{
"answer_id": 21829027,
"author": "Thoronwen",
"author_id": 1735567,
"author_profile": "https://Stackoverflow.com/users/1735567",
"pm_score": 3,
"selected": false,
"text": "td { border: 1em solid transparent; }\n"
},
{
"answer_id": 23784897,
"author": "bolvo",
"author_id": 1016498,
"author_profile": "https://Stackoverflow.com/users/1016498",
"pm_score": 2,
"selected": false,
"text": "table tr td div id=\"table_replacer\" div class=\"tr_replacer\" div class=\"td_replacer\" #table_replacer{display:table;}\n.tr_replacer {border: 1px solid #123456;margin-bottom: 5px;}/*DO NOT USE display:table-row! It will destroy the border and the margin*/\n.td_replacer{display:table-cell;}\n"
},
{
"answer_id": 24175782,
"author": "alansiqueira27",
"author_id": 375422,
"author_profile": "https://Stackoverflow.com/users/375422",
"pm_score": 4,
"selected": false,
"text": "<table style=\"width: 400px; line-height:50px;\">\n"
},
{
"answer_id": 24360796,
"author": "Nad",
"author_id": 3726676,
"author_profile": "https://Stackoverflow.com/users/3726676",
"pm_score": 2,
"selected": false,
"text": "div td div margin-bottom: 20px;\nheight: 40px;\nfloat: left;\nwidth: 100%;\n"
},
{
"answer_id": 28766788,
"author": "Justus Romijn",
"author_id": 334243,
"author_profile": "https://Stackoverflow.com/users/334243",
"pm_score": 6,
"selected": false,
"text": ".your-table {\n border-collapse: separate; /* allow spacing between cell borders */\n border-spacing: 0 5px; /* NOTE: syntax is <horizontal value> <vertical value> */\n tbody tbody .spacing-table {\n font-family: 'Helvetica', 'Arial', sans-serif;\n font-size: 15px;\n border-collapse: separate;\n table-layout: fixed;\n width: 80%;\n border-spacing: 0 5px; /* this is the ultimate fix */\n}\n.spacing-table th {\n text-align: left;\n padding: 5px 15px;\n}\n.spacing-table td {\n border-width: 3px 0;\n width: 50%;\n border-color: darkred;\n border-style: solid;\n background-color: red;\n color: white;\n padding: 5px 15px;\n}\n.spacing-table td:first-child {\n border-left-width: 3px;\n border-radius: 5px 0 0 5px;\n}\n.spacing-table td:last-child {\n border-right-width: 3px;\n border-radius: 0 5px 5px 0;\n}\n.spacing-table thead {\n display: table;\n table-layout: fixed;\n width: 100%;\n}\n.spacing-table tbody {\n display: table;\n table-layout: fixed;\n width: 100%;\n border-spacing: 0 10px;\n} <table class=\"spacing-table\">\n <thead>\n <tr>\n <th>Lead singer</th>\n <th>Band</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>Bono</td>\n <td>U2</td>\n </tr>\n </tbody>\n <tbody>\n <tr>\n <td>Chris Martin</td>\n <td>Coldplay</td>\n </tr>\n <tr>\n <td>Mick Jagger</td>\n <td>Rolling Stones</td>\n </tr>\n <tr>\n <td>John Lennon</td>\n <td>The Beatles</td>\n </tr>\n </tbody>\n</table>"
},
{
"answer_id": 32618451,
"author": "FlavorScape",
"author_id": 654434,
"author_profile": "https://Stackoverflow.com/users/654434",
"pm_score": 3,
"selected": false,
"text": " tr {\n border-bottom:5em solid white;\n }\n"
},
{
"answer_id": 37772351,
"author": "Brice Coustillas",
"author_id": 1675356,
"author_profile": "https://Stackoverflow.com/users/1675356",
"pm_score": -1,
"selected": false,
"text": "#myOwnTable td { padding: 6px 0 6px 0;}\n"
},
{
"answer_id": 47907812,
"author": "Syno",
"author_id": 7325614,
"author_profile": "https://Stackoverflow.com/users/7325614",
"pm_score": 5,
"selected": false,
"text": "table {border-collapse: separate; border-spacing: 10px 20px;}\n\ntable, \ntable td,\ntable th {border: 1px solid black;} <table>\n <tr>\n <td>Some text - 1</td>\n <td>Some text - 1</td>\n </tr>\n <tr>\n <td>Some text - 2</td>\n <td>Some text - 2</td>\n </tr>\n <tr>\n <td>Some text - 3</td>\n <td>Some text - 3</td>\n </tr>\n</table>"
},
{
"answer_id": 56830235,
"author": "Doin",
"author_id": 999120,
"author_profile": "https://Stackoverflow.com/users/999120",
"pm_score": 0,
"selected": false,
"text": "td {padding:5px 8px;border:2px solid blue;background:#E0E0E0} /* lets say the cells all have this padding and border, and the gaps should be white */\n\ntr.gapbefore td {overflow:visible}\ntr.gapbefore td::before,\ntr.gapbefore th::before\n{\n content:\"\";\n display:block;\n position:relative;\n z-index:1;\n width:auto;\n height:0;\n padding:0;\n margin:-5px -10px 5px; /* 5px = cell top padding, 10px = (cell side padding)+(cell side border width)+(table side border width) */\n border-top:16px solid white; /* the size & color of the gap you want */\n border-bottom:2px solid blue; /* this replaces the cell's top border, so should be the same as that. DOUBLE IT if using border-collapse:separate */\n}\n ::before margin:-5px -12px 5px; /* 14px = original 10px + 2px for 'uncollapsed' part of table border */\n border-collapse:separate border-collapse:collapse margin:-5px -14px 5px; /* 14px = original 10px + 4px full width of table border */\n border-bottom:4px solid blue; /* i.e. 4px = cell top border + previous row's bottom border */\n"
},
{
"answer_id": 66065295,
"author": "kiransr",
"author_id": 1942546,
"author_profile": "https://Stackoverflow.com/users/1942546",
"pm_score": 3,
"selected": false,
"text": "<td> height <td height=\"50\" colspan=\"2\"></td>\n colspan td height <table style=\"background-color: green\">\n <tr>\n <td>\n <span>Lorem</span>\n </td>\n <td>\n <span>Ipsum</span>\n </td>\n </tr>\n <tr>\n <td height=\"50\" colspan=\"2\" style=\"background-color: yellow\"></td>\n </tr>\n <tr>\n <td>\n <span>Sit</span>\n </td>\n <td>\n <span>Amet</span>\n </td>\n </tr>\n</table>"
},
{
"answer_id": 70100846,
"author": "Noor Ali",
"author_id": 12655362,
"author_profile": "https://Stackoverflow.com/users/12655362",
"pm_score": 3,
"selected": false,
"text": "table { border-collapse: separate; border-spacing: 0 1em; }"
},
{
"answer_id": 70514916,
"author": "Loathing",
"author_id": 904156,
"author_profile": "https://Stackoverflow.com/users/904156",
"pm_score": 2,
"selected": false,
"text": "border-bottom:solid white 5px; <style>\ntable.class1 {\n text-align:center;\n border-spacing:0 0px;\n font-family:Calibri, sans-serif;\n}\n\ntable.class1 tr:first-child {\n background-color:#F8F8F8; /* header row color */\n}\n\ntable.class1 tr > td {\n /* firefox has a problem rounding the bottom corners if the entire row is colored */\n /* hence the color is applied to each cell */\n background-color:#BDE5F8;\n}\n\ntable.class1 th {\n border:solid #A6A6A6 1px;\n border-bottom-width:0px; /* otherwise borders are doubled-up */\n border-right-width:0px;\n padding:5px;\n}\n\ntable.class1 th:first-child {\n border-radius: 5px 0 0 0;\n}\n\ntable.class1 th.last {\n border-right-width:1px;\n border-radius: 0 5px 0 0;\n}\n\n/* round the bottom corners */\ntable.class1 tr:last-child > td:first-child {\n border-radius: 0 0 0 5px;\n}\n\ntable.class1 tr:last-child > td:last-child {\n border-radius: 0 0 5px 0;\n}\n\n /* put a line at the start of each new group */\ntd.newgroup {\n border-top:solid #AAA 1px;\n}\n\n/* this has to match the parent element background-color */\n/* increase or decrease the amount of space by changing 5px */\ntd.endgroup {\n border-bottom:solid white 5px;\n}\n\n</style>\n\n<table class=\"class1\">\n<tr><th>Group</th><th>Item</th><th class=\"last\">Row</th></tr>\n<tr><td class=\"newgroup endgroup\">G-1</td><td class=\"newgroup endgroup\">a1</td><td class=\"newgroup endgroup\">1</td></tr>\n<tr><td class=\"newgroup\">G-2</td><td class=\"newgroup\">b1</td><td class=\"newgroup\">2</td></tr>\n<tr><td>G-2</td><td>b2</td><td>3</td></tr>\n<tr><td class=\"endgroup\">G-2</td><td class=\"endgroup\">b3</td><td class=\"endgroup\">4</td></tr>\n<tr><td class=\"newgroup\">G-3</td><td class=\"newgroup\">c1</td><td class=\"newgroup\">5</td></tr>\n<tr><td>G-3</td><td>c2</td><td>6</td></tr>\n</table>\n"
},
{
"answer_id": 71808384,
"author": "nicael",
"author_id": 2963652,
"author_profile": "https://Stackoverflow.com/users/2963652",
"pm_score": 1,
"selected": false,
"text": "display:grid grid-gap grid-gap: [vertical] [horizontal] margin: -1px my-grid {\n display: grid;\n grid-template-columns: 1fr 1fr;\n grid-gap: 10px 0px;\n}\n\nmy-item {\n border: 2px solid #c60965;\n background: #ffc000;\n color: #c60965;\n margin: -1px;\n \n font-size: 20px;\n display: flex;\n justify-content: center;\n align-items: center;\n\n} <my-grid>\n <my-item>1</my-item>\n <my-item>2</my-item>\n <my-item>3</my-item>\n <my-item>4</my-item>\n <my-item>5</my-item>\n</my-grid> grid-gap: 10px 20px; <style>my-grid{display: grid; grid-template-columns: 1fr 1fr;}my-item{border: 2px solid #c60965; background: #ffc000; color: #c60965; margin: -1px; font-size: 20px; display: flex;}cus{font-family:Menlo; display:block; padding:7px; margin-top: 20px; border:3px dotted grey; border-radius:20px; font-size:14px;}set{display:flex; align-items:center;}dev-grid{display:grid; grid-template-columns: 1fr 1fr; margin:5px;}.hack{transform: scale(1.3); margin-top:13px; margin-left:5px;}txt:last-of-type{display:inline-block; margin-top:10px;}d{display:block; margin-top:10px; font-family: Menlo;}pre{padding:10px; background:rgb(246,246,246);}</style><my-grid> <my-item>Cell number one</my-item> <my-item>Cell number two</my-item> <my-item>Cell number three</my-item> <my-item>Cell number four</my-item> <my-item>Cell number five</my-item></my-grid><cus><dev-grid><txt>Space between rows:</txt><input type=\"range\" min=\"0\" max=\"20\" value=\"0\"><txt>Space between cols:</txt><input type=\"range\" min=\"0\" max=\"20\" value=\"0\"><txt>Padding (rows)</txt><input type=\"range\" min=\"0\" max=\"20\" value=\"0\"><txt>Padding (cols):</txt><input type=\"range\" min=\"0\" max=\"20\" value=\"0\"><txt>Margin hack:</txt><label> <input class=\"hack\" type=\"checkbox\" checked> <tt>on</tt></label></dev-grid></cus><d>Code to implement this:</d><pre></pre><script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script><script>var values=[0,0,0,0],hack=0,props={grid:{dis:\"display:grid;\",cols:\"grid-template-columns: 1fr 1fr;\"},item:{}};function drawProps(){grid_props=Object.values(props.grid).map(p=>` ${p}`).join(\"\\n\"),item_props=Object.values(props.item).map(p=>` ${p}`).join(\"\\n\"),all_code=`my-grid{\\n${grid_props}\\n}`,\"\"!=item_props&&(all_code+=`\\nmy-item{\\n${item_props}\\n}`),$(\"pre\").text(all_code)}props.item.hack=\"margin: -1px;\",drawProps(),$(\"input[type=range]\").on(\"input\",function(){ind=($(this).index()-1)/2,values[ind]=$(this).val(),$(\"my-grid\").css(\"grid-gap\",`${values[0]}px ${values[1]}px`),$(\"my-item\").css(\"padding\",`${values[2]}px ${values[3]}px ${values[2]}px ${values[3]}px`),code_grid=`grid-gap: ${values[0]}px ${values[1]}px;`,values[0]==values[1]&&(code_grid=`grid-gap: ${values[0]}px;`,0==values[0]&&(code_grid=\"\")),code_padding=`padding: ${values[2]}px ${values[3]}px ${values[2]}px ${values[3]}px;`,values[2]==values[3]&&(code_padding=`padding: ${values[2]}px;`,0==values[2]&&(code_padding=\"\")),props.grid.gap=code_grid,props.item.padding=code_padding,\"\"==props.grid.gap&&delete props.grid.gap,\"\"==props.item.padding&&delete props.item.padding,drawProps()}),$(\".hack\").change(function(){hack=$(this).is(\":checked\"),st=hack?\"on\":\"off\",$(\"tt\").text(st),hack?(props.item.hack=\"margin: -1px;\",$(\"my-item\").css(\"margin\",\"-1px\")):(props.item.hack&&delete props.item.hack,$(\"my-item\").css(\"margin\",\"0px\")),drawProps()});</script>"
},
{
"answer_id": 71822140,
"author": "Jarrett",
"author_id": 14631246,
"author_profile": "https://Stackoverflow.com/users/14631246",
"pm_score": 2,
"selected": false,
"text": ".table {\n border-collapse: separate; \n border-spacing: 0 1rem;\n}\n"
},
{
"answer_id": 72975599,
"author": "Sabaoon Bedar",
"author_id": 7312335,
"author_profile": "https://Stackoverflow.com/users/7312335",
"pm_score": 2,
"selected": false,
"text": "table {\n border-collapse: separate;\n border-spacing: 0 15px;\n}\n <table class=\"res\">\n\n</table>\n .res {\n border-collapse: separate;\n border-spacing: 0 15px;\n }\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419730/"
] |
351,117 | <p>I know you can use the <code><jsp:useBean></code> tag to instantiate objects within JSPs without resorting to scriptlet code. However I'd like to instantiate an Integer who value is the result of an EL expression, something like:</p>
<pre><code><jsp:useBean id="total" class="java.lang.Integer">
<jsp:setProperty name="amount" value="${param1 + param2}"/>
</jsp:useBean>
</code></pre>
<p>Of course this won't work because Integer objects don't have a property named 'amount', the only way their value can be set is via a constructor parameter (i.e. Integer objects are immutable). Is there any way to instantiate such an object and set it's value without using scriptlet code?</p>
<p>Thanks,
Don</p>
| [
{
"answer_id": 351369,
"author": "carson",
"author_id": 25343,
"author_profile": "https://Stackoverflow.com/users/25343",
"pm_score": 1,
"selected": false,
"text": "<%\n Integer total = new Integer(param1 + param2);\n%>\n <%\n pageContext.setAttribute(\"total\", new Integer(param1 + param2));\n%>\n"
},
{
"answer_id": 351719,
"author": "Adeel Ansari",
"author_id": 42769,
"author_profile": "https://Stackoverflow.com/users/42769",
"pm_score": 2,
"selected": true,
"text": "<c:set var=\"amount\" value=\"${param1 + param2}\" scope=\"page\" />"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2648/"
] |
351,122 | <p>Does anybody know how I can get the number of the elements (rows*cols) returned after I do an SQL query? If that can't be done, then is there something that's going to be relatively representative of the size of data I get back?</p>
<p>I'm trying to make a status bar that indicates how much of the returned data I have processed, so I want to be somewhere relatively close. Any ideas?</p>
<p>Please note that SQLRowCount only returns returns the number of rows affected by an UPDATE, INSERT, or DELETE statement; not the number of rows returned from a SELECT statement (as far as I can tell). So I can't multiply that directly to the SQLColCount.</p>
<p>My last option is to have a status bar that goes back and forth, indicating that data is being processed.</p>
| [
{
"answer_id": 351233,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 3,
"selected": true,
"text": "WITH\ndata AS\n(\n SELECT interesting-data\n FROM interesting-table\n WHERE some-condition\n)\nSELECT COUNT(*), data.*\nfrom data\n SELECT COUNT(*)\nFROM USER_TAB_COLS\nWHERE TABLE_NAME = 'interesting-table'\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28760/"
] |
351,126 | <p>I've download an image from the Internet and converted to a String (This is not changeable)</p>
<pre><code>Dim Request As System.Net.WebRequest = _
System.Net.WebRequest.Create( _
"http://www.google.com/images/nav_logo.png")
Dim WebResponse As System.Net.HttpWebResponse = _
DirectCast(Request.GetResponse(), System.Net.HttpWebResponse)
Dim Stream As New System.IO.StreamReader( _
WebResponse.GetResponseStream, System.Text.Encoding.UTF8)
Dim Text as String = Stream.ReadToEnd
</code></pre>
<p>How can I convert the String back to the Stream?</p>
<p>So I can use that stream to get the image.</p>
<p>Like this:</p>
<pre><code>Dim Image As New Drawing.Bitmap(WebResponse.GetResponseStream)
</code></pre>
<p>But now I've only the Text String, so I need something like this:</p>
<pre><code>Dim Stream as Stream = ReadToStream(Text, System.Text.Encoding.UTF8)
Dim Image As New Drawing.Bitmap(Stream)
</code></pre>
<p>EDIT:</p>
<p>This engine was primarily used for downloading web pages but I'm trying to use it for downloading images too.
The format of the string is UTF8, as given in the example code...</p>
<p>I've tried to use the <code>MemoryStream(Encoding.UTF8.GetBytes(Text))</code>, but I got this error when loading the stream to the image:</p>
<blockquote>
<p>A generic error occurred in GDI+.</p>
</blockquote>
<p>What gets lost in the conversions?</p>
| [
{
"answer_id": 351156,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 6,
"selected": true,
"text": "new MemoryStream(Encoding.UTF8.GetBytes(text)) byte[] Convert.ToBase64String(...) Convert.FromBase64String(...) byte[] WebClient byte[] using(WebClient wc = new WebClient()) {\n byte[] raw = wc.DownloadData(\"http://www.google.com/images/nav_logo.png\")\n //...\n}\n Stream // ENCODE\n // where \"s\" is our original stream\n string base64;\n // first I need the data as a byte[]; I'll use\n // MemoryStream, as a convenience; if you already\n // have the byte[] you can skip this\n using (MemoryStream ms = new MemoryStream())\n {\n byte[] buffer = new byte[1024];\n int bytesRead;\n while ((bytesRead = s.Read(buffer, 0, buffer.Length)) > 0)\n {\n ms.Write(buffer, 0, bytesRead);\n }\n base64 = Convert.ToBase64String(ms.GetBuffer(), 0, (int) ms.Length);\n }\n\n // DECODE\n byte[] raw = Convert.FromBase64String(base64);\n using (MemoryStream decoded = new MemoryStream(raw))\n {\n // \"decoded\" now primed with the binary\n }\n"
},
{
"answer_id": 351159,
"author": "Andrew Rollings",
"author_id": 40410,
"author_profile": "https://Stackoverflow.com/users/40410",
"pm_score": 2,
"selected": false,
"text": "Dim strAsBytes() as Byte = new System.Text.UTF8Encoding().GetBytes(Text)\nDim ms as New System.IO.MemoryStream(strAsBytes)\n"
},
{
"answer_id": 11851522,
"author": "Coder",
"author_id": 1582734,
"author_profile": "https://Stackoverflow.com/users/1582734",
"pm_score": 1,
"selected": false,
"text": "var bytes = new byte[contents.Length * sizeof( char )];\nBuffer.BlockCopy( contents.ToCharArray(), 0, bytes, 0, bytes.Length );\nusing( var stream = new MemoryStream( bytes ) )\n{\n // do your stuff with the stream...\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41385/"
] |
351,134 | <p>How to get function's name from <a href="http://en.wikipedia.org/wiki/Function_pointer" rel="noreferrer">function's pointer</a> in C?</p>
<p>Edit: The real case is: I'm writing a linux kernel module and I'm calling kernel functions. Some of these functions are pointers and I want to inspect the code of that function in the kernel source. But I don't know which function it is pointing to. I thought it could be done because, when the system fails (kernel panic) it prints out in the screen the current callstack with function's names. But, I guess I was wrong... am I?</p>
| [
{
"answer_id": 351153,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 6,
"selected": true,
"text": "/proc/kallsyms #include <linux/kallsyms.h>\n\nconst char *kallsyms_lookup(unsigned long addr, unsigned long *symbolsize,\n unsigned long *ofset, char **modname, char *namebuf)\n\nvoid print_symbol(const char *fmt, unsigned long addr)\n printk printk %pF"
},
{
"answer_id": 351217,
"author": "eaanon01",
"author_id": 36986,
"author_profile": "https://Stackoverflow.com/users/36986",
"pm_score": 2,
"selected": false,
"text": "// Define it like this\ntypedef struct\n{\n char *dec_text;\n #ifdef _DEBUG_FUNC\n void (*action)(char);\n #endif\n} func_Struct;\n\n// Initialize it like this\nfunc_Struct func[3]= {\n#ifdef _DEBUG_FUNC\n{\"my_Set(char input)\",&my_Set}};\n{\"my_Get(char input)\",&my_Get}};\n{\"my_Clr(char input)\",&my_Clr}};\n#else\n{&my_Set}};\n{&my_Get}};\n{&my_Clr}};\n#endif \n\n// And finally you can use it like this\nfunc[0].action( 0x45 );\n#ifdef _DEBUG_FUNC\nprintf(\"%s\",func.dec_text);\n#endif\n"
},
{
"answer_id": 351980,
"author": "qrdl",
"author_id": 28494,
"author_profile": "https://Stackoverflow.com/users/28494",
"pm_score": 6,
"selected": false,
"text": "backtrace() backtrace_symbols() man backtrace() backtrace_symbols() #include <stdio.h>\n#include <execinfo.h>\n\nvoid foo(void) {\n printf(\"foo\\n\");\n}\n\nint main(int argc, char *argv[]) {\n void *funptr = &foo;\n\n backtrace_symbols_fd(&funptr, 1, 1);\n\n return 0;\n}\n gcc test.c -rdynamic ./a.out(foo+0x0)[0x8048634] dladdr() print_backtrace() dladdr() dladdr() Dl_info dli_sname man dladdr libdwarf"
},
{
"answer_id": 8752173,
"author": "givanse",
"author_id": 7852,
"author_profile": "https://Stackoverflow.com/users/7852",
"pm_score": 2,
"selected": false,
"text": "typedef void (*simpleFP)();\ntypedef struct functionMETA {\n simpleFP funcPtr;\n char * funcName;\n} functionMETA;\n\nvoid f1() {/*do something*/}\nvoid f2() {/*do something*/}\nvoid f3() {/*do something*/}\n\nint main()\n{\n void (*funPointer)() = f2; // you ignore this\n funPointer(); // this is all you see\n\n printf(\"f1 %p\\n\", f1);\n printf(\"f2 %p\\n\", f2);\n printf(\"f3 %p\\n\", f3);\n\n printf(\"%p\\n\", funPointer);\n\n // if you want to print the name\n struct functionMETA arrFuncPtrs[3] = {{f1, \"f1\"}, {f2, \"f2\"} , {f3, \"f3\"}};\n\n int i;\n for(i=0; i<3; i++) {\n if( funPointer == arrFuncPtrs[i].funcPtr )\n printf(\"function name: %s\\n\", arrFuncPtrs[i].funcName);\n }\n}\n f1 0x40051b\nf2 0x400521\nf3 0x400527\n0x400521\nfunction name: f2\n"
},
{
"answer_id": 16037950,
"author": "Calmarius",
"author_id": 58805,
"author_profile": "https://Stackoverflow.com/users/58805",
"pm_score": 3,
"selected": false,
"text": "%p nm <program_path> | grep <address> 0x"
},
{
"answer_id": 21877817,
"author": "Zskdan",
"author_id": 295762,
"author_profile": "https://Stackoverflow.com/users/295762",
"pm_score": 5,
"selected": false,
"text": "void *func = &foo;\nprintk(\"func: %pF at address: %p\\n\", func, func);\n"
},
{
"answer_id": 38046477,
"author": "WindChaser",
"author_id": 1595440,
"author_profile": "https://Stackoverflow.com/users/1595440",
"pm_score": 1,
"selected": false,
"text": "kallsyms_lookup_name() kallsyms_lookup kallsyms_lookup"
},
{
"answer_id": 55229300,
"author": "The Gramm",
"author_id": 2974608,
"author_profile": "https://Stackoverflow.com/users/2974608",
"pm_score": 0,
"selected": false,
"text": "/**\n* search methods */\nstatic int starts(const char *str, const char *c);\nstatic int fuzzy(const char *str, const char *c);\n\nint (*search_method)(const char *, const char *);\n\n/* asign the search_method and do other stuff */\n[...]\n\nprintf(\"The search method is %s\\n\", search_method == starts ? \"starts\" : \"fuzzy\")\n #define X(name, str) ... #undef X"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
351,149 | <p>I'm writing a helper method for ASP.NET MVC and I need to call <code>Url.Content</code> to get an appropriate URL for the context. However, in order to create a new <code>UrlHelper()</code> I need to get the current <code>RequestContext</code> (<code>System.Web.Routing.RequestContext</code> to be precise) and I'm not sure how to grab it. Anyone know?</p>
| [
{
"answer_id": 353388,
"author": "Craig Stuntz",
"author_id": 7714,
"author_profile": "https://Stackoverflow.com/users/7714",
"pm_score": 1,
"selected": false,
"text": "public static string IdLink(this UrlHelper helper, Guid id)\n { //...\n"
},
{
"answer_id": 443861,
"author": "ccook",
"author_id": 51275,
"author_profile": "https://Stackoverflow.com/users/51275",
"pm_score": 2,
"selected": false,
"text": " public static string ExtensionMethodName(this HtmlHelper html,object o)\n {\n html.ViewContext.HttpContext.Request.Uri ... etc \n }\n"
},
{
"answer_id": 995749,
"author": "Martijn Laarman",
"author_id": 47020,
"author_profile": "https://Stackoverflow.com/users/47020",
"pm_score": 5,
"selected": true,
"text": "public static string NewHelperMethod(this HtmlHelper helper)\n{\n UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext);\n"
},
{
"answer_id": 1319365,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "public ActionResult SomeAction(){\n var helper = new UrlHelper(this.ControllerContext.RequestContext);\n ...\n}\n"
},
{
"answer_id": 1583026,
"author": "felixg",
"author_id": 86640,
"author_profile": "https://Stackoverflow.com/users/86640",
"pm_score": 6,
"selected": false,
"text": "((MvcHandler)HttpContext.Current.Handler).RequestContext\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351149",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4541/"
] |
351,161 | <p>I have a text file that contains a long list of entries (one on each line). Some of these are duplicates, and I would like to know if it is possible (and if so, how) to remove any duplicates. I am interested in doing this from within vi/vim, if possible.</p>
| [
{
"answer_id": 351175,
"author": "Sean",
"author_id": 44133,
"author_profile": "https://Stackoverflow.com/users/44133",
"pm_score": 5,
"selected": false,
"text": ":%s/^\\(.*\\)\\(\\n\\1\\)\\+$/\\1/\n"
},
{
"answer_id": 351182,
"author": "Brian Carper",
"author_id": 23070,
"author_profile": "https://Stackoverflow.com/users/23070",
"pm_score": 9,
"selected": true,
"text": ":sort u\n"
},
{
"answer_id": 351187,
"author": "derobert",
"author_id": 27727,
"author_profile": "https://Stackoverflow.com/users/27727",
"pm_score": 2,
"selected": false,
"text": ":!uniq"
},
{
"answer_id": 351191,
"author": "Chris Dodd",
"author_id": 29759,
"author_profile": "https://Stackoverflow.com/users/29759",
"pm_score": 0,
"selected": false,
"text": "!}uniq :1,$!uniq"
},
{
"answer_id": 351500,
"author": "Jon DellOro",
"author_id": 36456,
"author_profile": "https://Stackoverflow.com/users/36456",
"pm_score": 3,
"selected": false,
"text": "go to head of file\nsort the whole file\nremove duplicate entries with uniq\n\n1G\n!Gsort\n1G\n!Guniq\n"
},
{
"answer_id": 352292,
"author": "Luc Hermitte",
"author_id": 15934,
"author_profile": "https://Stackoverflow.com/users/15934",
"pm_score": 1,
"selected": false,
"text": ":sort u"
},
{
"answer_id": 1657880,
"author": "Bridgey",
"author_id": 200563,
"author_profile": "https://Stackoverflow.com/users/200563",
"pm_score": 3,
"selected": false,
"text": "g/^\\(.*\\)$\\n\\1/d\n"
},
{
"answer_id": 5624483,
"author": "Kevin",
"author_id": 599019,
"author_profile": "https://Stackoverflow.com/users/599019",
"pm_score": 5,
"selected": false,
"text": "sort file | uniq > file.new\n"
},
{
"answer_id": 23381376,
"author": "cn8341",
"author_id": 3540828,
"author_profile": "https://Stackoverflow.com/users/3540828",
"pm_score": 0,
"selected": false,
"text": ":%s/^\\(.*\\)\\(\\n\\1\\)\\+$/\\1/gec\n :%s/^\\(.*\\)\\(\\n\\1\\)\\+$/\\1/ge\n"
},
{
"answer_id": 38767566,
"author": "Rovin Bhandari",
"author_id": 1161622,
"author_profile": "https://Stackoverflow.com/users/1161622",
"pm_score": 4,
"selected": false,
"text": "awk '!x[$0]++' yourfile.txt :!"
},
{
"answer_id": 49371965,
"author": "SergioAraujo",
"author_id": 2571881,
"author_profile": "https://Stackoverflow.com/users/2571881",
"pm_score": 0,
"selected": false,
"text": "^ \" function to delete duplicate lines\nfunction! DelDuplicatedLines()\n while getline(\".\") == getline(line(\".\") - 1)\n exec 'norm! ddk'\n endwhile\n while getline(\".\") == getline(line(\".\") + 1)\n exec 'norm! dd'\n endwhile\nendfunction\nnnoremap <Leader>d :g/./call DelDuplicatedLines()<CR>\n"
},
{
"answer_id": 52834287,
"author": "william-1066",
"author_id": 2054797,
"author_profile": "https://Stackoverflow.com/users/2054797",
"pm_score": 0,
"selected": false,
"text": "sort {file-name} | uniq -u\n"
},
{
"answer_id": 52852184,
"author": "paul",
"author_id": 2462759,
"author_profile": "https://Stackoverflow.com/users/2462759",
"pm_score": -1,
"selected": false,
"text": ".csv .txt awk '!seen[$0]++' <filename> > <newFileName> awk '!seen[$0]++' <filename> > <newFileName>"
},
{
"answer_id": 65699500,
"author": "John Poulis",
"author_id": 8030260,
"author_profile": "https://Stackoverflow.com/users/8030260",
"pm_score": 2,
"selected": false,
"text": ":sort u"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43496/"
] |
351,165 | <p>I need to perform a complicated calculation. In my case it seemed most natural to create a Calculator class (abstracted using a strategy pattern).</p>
<p>To perform the calculation the class needs to accept about 20 inputs, some of which are optional, some of which could change in the future etc. Once the <strong>Calculate()</strong> method is called, about 20 different variables need to be outputted.</p>
<p>There are a number of ways this can be achieved.</p>
<ul>
<li>Inputs passed in as parameters to a calculate method</li>
<li>Inputs passed in through properties of the Calculator</li>
<li>Inputs wrapped up into their own class, then passed to Calculate() method.</li>
<li>Outputs returned by Calculate(), wrapped up in a class</li>
<li>Outputs populated into a parameter passed to the Calculate() method</li>
<li>Outputs retrieved from public properties of the Calculator, after Calculate() has been called</li>
</ul>
<p>There are pros and cons to all these methods.
How would you do it?</p>
<p>UPDATE:
Thanks for the feedback.</p>
<p>The purpose of this calculator is to generate a quote. The inputs are things such as the customer's address, interest rates, target profit, additional fees, product id etc The output includes the quote, the actual profit, more fees etc.</p>
<p>I have gone ahead and created ICalculateInput and ICalculateOutput interfaces and their concrete classes, and the system works very well now. The Calculator class also inherits from an ICalculator interface (as the calculations involved differ enormously depending on the company the product is sourced from).</p>
| [
{
"answer_id": 351198,
"author": "Andreas Grech",
"author_id": 44084,
"author_profile": "https://Stackoverflow.com/users/44084",
"pm_score": 1,
"selected": false,
"text": "var addUser = function (name,surname, age, add1, add2, telephone) {\n //do something\n};\n var addUser = function (userDetails) {\n //Do something with userDetails.name etc...\n};\n//Then invoke the function by passing in an object:\nvar ud = {name : 'Andreas', surname : 'Grech', age : 20, add1 : 'bla', add2 : 'bla', telephone : 12343}; \naddUser(ud);\n"
},
{
"answer_id": 351299,
"author": "Bent André Solheim",
"author_id": 44380,
"author_profile": "https://Stackoverflow.com/users/44380",
"pm_score": 3,
"selected": true,
"text": "Result calculate(RequiredArgs requiredArgs) {\n...\n}\n\nResult calculate(RequiredArgs requiredArgs, OptionalArgs optionalArgs) {\n}\n\nResult calculate(RequiredArgs requiredArgs, OptionalArgs optionalArgs, OtherOptionalArgs oOpitonalArgs) {\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21966/"
] |
351,172 | <p>How do you escape the forward slash character (<code>/</code>) in VBScript? For example, in the following string:</p>
<pre><code>bob = "VU administration/front desk"
</code></pre>
| [
{
"answer_id": 351177,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 5,
"selected": true,
"text": "MyString = \"He said, \"\"Here's how you escape a double quote in vbscript. Slash characters -- both forward (/) and back (\\) -- don't mean anything, even when used with common control characters like \\n or \\t.\"\"\"\n"
},
{
"answer_id": 12910244,
"author": "drewlander",
"author_id": 1635048,
"author_profile": "https://Stackoverflow.com/users/1635048",
"pm_score": 2,
"selected": false,
"text": "Dim sQuery As String = \"select replace(convert(char(10),pih.updateon,111),\"/\",\"-\") as stopdate from myTable\"\n Dim sQuery As String = \"select replace(convert(char(10),pih.updateon,111),'/','-') as stopdate from myTable\"\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18853/"
] |
351,185 | <p>Is there a simple way to detect mouse or keyboard activity in Linux or Xorg or Qt4 or Kde4 environment? Obviously not only on a particular window but in the entire Xorg desktop.</p>
| [
{
"answer_id": 351212,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": -1,
"selected": false,
"text": "XGrabMouse XGrabKeyboard"
},
{
"answer_id": 351218,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 1,
"selected": false,
"text": "man Xss XScreenSaverQueryInfo typedef struct {\n Window window; /∗ screen saver window */\n int state; /∗ ScreenSaver{Off,On,Disabled} */\n int kind; /∗ ScreenSaver{Blanked,Internal,External} */\n unsigned long til_or_since; /∗ milliseconds */\n unsigned long idle; /∗ milliseconds */\n unsigned long event_mask; /∗ events */\n } XScreenSaverInfo;\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39796/"
] |
351,205 | <p>Is it a bad idea to use exception chaining when throwing RemoteExceptions? We have an RMI server that does something like this:</p>
<pre><code>public Object doSomething() throws RemoteException
{
try
{
return getData();
}
catch (CustomException ex)
{
throw new RemoteException(ex);
}
}
</code></pre>
<p>I'm getting UnmarshallException caused by a ClassNotFoundException in my client. On the plus side, it turns out that CustomException itself IS exported. Unfortunately, another exception deep inside this guy is NOT exported, which is where the ClassNotFoundException comes in. I think the hierarchy is something like this:</p>
<p>RemoteException -> CustomException -> SQLException -> NotExportedException</p>
<p>The problem I see is that even though we can guarantee that CustomException is exported, we can't guarantee that any lower level exceptions are. </p>
<p>I'm leaning towards NEVER using exception chaining with RemoteExceptions because of this. Instead, I think I should probably log the stack trace on the server side and throw a plain, vanilla RemoteException with no "cause" exception chained to it. Anyone dealt with this situation before?</p>
| [
{
"answer_id": 351279,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 4,
"selected": true,
"text": "interface Foo extends Remote {\n\n Object doSomething() throws CustomException, RemoteException;\n\n}\n RemoteException public Object doSomething() throws CustomException {\n try {\n return theirSvc.getData();\n } catch (ThirdPartyException ex) {\n throw new CustomException(\"Failed to obtain requested data.\");\n // or: throw new CustomException(\"Failed to obtain requested data.\", ex) ?\n }\n}\n catch (ThirdPartyException ex) {\n String message = \"Failed to obtain requested data.\";\n log.error(message, ex);\n throw new CustomException(message);\n }\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1471/"
] |
351,214 | <p>I have a table in a DB (Postgres based), which acts like a superclass in object-oriented programming. It has a column 'type' which determines, which additional columns should be present in the table (sub-class properties). But I don't want the table to include all possible columns (all properties of all possible types).</p>
<p>So I decided to make a table, containg the 'key' and 'value' columns (i.e. 'filename' = '/file', or 'some_value' = '5'), which contain any possible property of the object, not included in the superclass table. And also made one related table to contain the available 'key' values.</p>
<p>But there is a problem with such architecture - the 'value' column should be of a string data type by default, to be able to contain anything. But I don't think converting to and from strings is a good decision. What is the best way to bypass this limitation?</p>
| [
{
"answer_id": 351227,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 0,
"selected": false,
"text": "create table IntProps(...);\ncreate table StringProps(...);\ncreate table CurrencyProps(...);\n"
},
{
"answer_id": 351231,
"author": "Kon",
"author_id": 22303,
"author_profile": "https://Stackoverflow.com/users/22303",
"pm_score": 2,
"selected": false,
"text": "Entity\n------\nID\nName\nType\nSubTypeName (value of this column will be 'Dog')\n\n\nDog\n---\nVetName\nVetNumber\netc\n"
},
{
"answer_id": 351352,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "NOT NULL"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37511/"
] |
351,228 | <p>When using FxCop 1.36 for a WPF application with a single window that has yet to be modified, I get the InterfaceMethodsShouldBeCallableByChildTypes error with the following details:</p>
<pre><code> Target : #System.Windows.Markup.IComponentConnector.Connect(System.Int32,System.Object) (IntrospectionTargetMember)
Resolution : "Make 'MainWindow' sealed (a breaking change if
this class has previously shipped), implement the method
non-explicitly, or implement a new method that exposes
the functionality of 'IComponentConnector.Connect(int,
object)' and is visible to derived classes."
Help : http://msdn2.microsoft.com/library/ms182153(VS.90).aspx (String)
Category : Microsoft.Design (String)
CheckId : CA1033 (String)
RuleFile : Design Rules (String)
Info : "Explicit method implementations are defined with private
accessibility. Classes that derive from classes with
explicit method implementations and choose to re-declare
them on the class will not be able to call into the
base class implementation unless the base class has
provided an alternate method with appropriate accessibility.
When overriding a base class method that has been hidden
by explicit interface implementation, in order to call
into the base class implementation, a derived class
must cast the base pointer to the relevant interface.
When calling through this reference, however, the
derived class implementation will actually be invoked,
resulting in recursion and an eventual stack overflow."
Created : 08/12/2008 22:26:37 (DateTime)
LastSeen : 08/12/2008 22:41:05 (DateTime)
Status : Active (MessageStatus)
Fix Category : NonBreaking (FixCategories)
}
</code></pre>
<p>Should this simply be ignored?</p>
| [
{
"answer_id": 351227,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 0,
"selected": false,
"text": "create table IntProps(...);\ncreate table StringProps(...);\ncreate table CurrencyProps(...);\n"
},
{
"answer_id": 351231,
"author": "Kon",
"author_id": 22303,
"author_profile": "https://Stackoverflow.com/users/22303",
"pm_score": 2,
"selected": false,
"text": "Entity\n------\nID\nName\nType\nSubTypeName (value of this column will be 'Dog')\n\n\nDog\n---\nVetName\nVetNumber\netc\n"
},
{
"answer_id": 351352,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "NOT NULL"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21862/"
] |
351,242 | <p>Is multiple inheritance possible in VB .Net? If so, what is the syntax?</p>
| [
{
"answer_id": 14189970,
"author": "user1954025",
"author_id": 1954025,
"author_profile": "https://Stackoverflow.com/users/1954025",
"pm_score": 1,
"selected": false,
"text": "Public Class ClassName\n Implements BaseInterface1, BaseInterface2\n\nEnd Class\n Public Interface InterfaceName\n Implements BaseInterface1, BaseInterface2\n\nEnd Interface\n Public MustInherit Class InterfaceName\n Implements BaseInterface1, BaseInterface2\n\nEnd Class\n public interface InterfaceName: BaseInterface1, BaseInterface2 {}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4575/"
] |
351,243 | <p>I have exported a COM+ application proxy, which generates MSI and CAB files, and I have successfully installed them on a few different Win XP and Vista machines. However, I have a WinXP box that isn't playing nicely. When I try and run the MSI it gives me the following error message:</p>
<p>"Error registering COM+ Application."</p>
<p>It stops there, not even getting as far as creating the application in COM+. Any ideas on where to look? I'm guessing some dependency is MIA, disabled, or misconfigured, but I can't seem to figure out what's missing from the magic sauce.</p>
<p>Also, if any of you have experience registering the client app proxy manually, that would be swell, too.</p>
<p>peace|dewde</p>
| [
{
"answer_id": 484702,
"author": "hurcane",
"author_id": 21363,
"author_profile": "https://Stackoverflow.com/users/21363",
"pm_score": 4,
"selected": true,
"text": "msiexec /i MyProxy.msi /l*v ProxySetup.log\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2640/"
] |
351,258 | <p>I have a flex app that uploads files to a server. The server requires authentication to be able to upload. In IE the upload works fine. However in FF and Safari, it does not upload. I have seen people all over with this same problem but no answers. Don't fail me now stackoverflowers. </p>
| [
{
"answer_id": 351609,
"author": "cliff.meyers",
"author_id": 41754,
"author_profile": "https://Stackoverflow.com/users/41754",
"pm_score": 2,
"selected": false,
"text": "var request : URLRequset = new URLRequest( uploadUrl + \";jsessionid=\" + jsessionid);\n"
},
{
"answer_id": 685857,
"author": "Adam Tuttle",
"author_id": 751,
"author_profile": "https://Stackoverflow.com/users/751",
"pm_score": 3,
"selected": true,
"text": "//sessionParams - resolves firefox upload bug\npublic var sessionParams:String = \"\";\n\n//...\n\npublic function initApp():void{\n sessionParams = Application.application.parameters.sessionParams;\n}\n sessionParams <cfset flashVars = \"sessionParams=#urlEncodedFormat('jsessionid=' & session.sessionid)#\" />\n // Set Up URLRequest\n_uploadURL = new URLRequest;\n_uploadURL.url = _url + \"?\" + _sessionParams;\n_uploadURL.method = \"GET\";\n_uploadURL.data = _variables;\n_uploadURL.contentType = \"multipart/form-data\";\n"
},
{
"answer_id": 2933462,
"author": "Prerana Kalley",
"author_id": 353364,
"author_profile": "https://Stackoverflow.com/users/353364",
"pm_score": 1,
"selected": false,
"text": "<security-constraint>\n <display-name>Senusion Security Constraint</display-name>\n <web-resource-collection>\n <web-resource-name>Un Protected Area</web-resource-name>\n <url-pattern>/fileupload.do</url-pattern>\n </web-resource-collection>\n</security-constraint> \n"
},
{
"answer_id": 5344942,
"author": "orasio spieler",
"author_id": 665068,
"author_profile": "https://Stackoverflow.com/users/665068",
"pm_score": 1,
"selected": false,
"text": "var urlVars:URLVariables = new URLVariables();\nurlVars.jsessionid = sessionID;\n\nvar uploadUrl:String = \"http://localhost:8080/mywar;jsessionid=\"+sessionID;\nuploadUrl += \"?\"+getClientCookies(); //put all client cookies on the query string \nvar urlRequest:URLRequest = new URLRequest(uploadUrl);\nurlRequest.method = URLRequestMethod.POST;\nurlRequest.data = urlVars;\n\n//will go first time and get the cookies set see flex docs \nvar testUpload:Boolean = true; \nfileRef.upload(urlRequest,\"Filedata\",testUpload);\n package com.mywar.fileupload;\n\nimport java.io.IOException;\nimport java.util.Enumeration;\n\nimport javax.servlet.Filter;\nimport javax.servlet.FilterChain;\nimport javax.servlet.FilterConfig;\nimport javax.servlet.ServletException;\nimport javax.servlet.ServletRequest;\nimport javax.servlet.ServletResponse;\nimport javax.servlet.http.Cookie;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\n/**\n * @author orasio - spieler\n * This filter comes to solve the Firefox ,Chrome and SAFARI file upload issue\n * The problem was that the file uploaded by the flex \n * FileReference came with a different session and no cookies\n * To solve this problem do the following : \n * \n * \n * don't forget to add this filter to the web.xml file\n */\npublic class FileUploadFilter implements Filter {\n\n private static final String CONTENT_LENGTH = \"content-length\";\n private static final String UPLOAD_SITE_PATH = \"/\";\n private static final String JSESSIONID = \"JSESSIONID\";\n\n\n @Override\n public void init(FilterConfig filterConfig) throws ServletException {\n }\n\n @Override\n public void doFilter(ServletRequest request, \n ServletResponse response,\n FilterChain filterChain) \n throws IOException, ServletException {\n if ((request instanceof HttpServletRequest) \n && (response instanceof HttpServletResponse)) {\n HttpServletRequest httpRequest = (HttpServletRequest) request;\n\n //httpRequest.getHeader(\"user-agent\"); //Shockwave Flash\n String contentLength = httpRequest.getHeader(CONTENT_LENGTH);\n boolean isFlexTest = (contentLength!=null \n && Integer.parseInt(contentLength)==0); \n if(isFlexTest){ \n HttpServletResponse httpResponse = \n (HttpServletResponse) response;\n setAllClientCookie((HttpServletResponse)response, httpRequest);\n PrintWriter out = httpResponse.getWriter();\n out.println(\"OK\");\n out.close();\n return;\n }\n }\n filterChain.doFilter(request, response);\n }\n\n /*\n * write all cookies back to the flex test response \n */\n @SuppressWarnings(\"unchecked\")\n private void setAllClientCookie(HttpServletResponse httpResponse,\n HttpServletRequest httpRequest) {\n Enumeration<String> parameterNames = \n (Enumeration<String>)httpRequest.getParameterNames();\n while (parameterNames.hasMoreElements()) {\n String cookieName = (String) parameterNames.nextElement();\n //since we get IllegalArgumentException: Cookie name \"JSESSIONID\" is a reserved token\n\n if(!cookieName.contains(JSESSIONID)) { \n Cookie cookie = \n new Cookie(cookieName, httpRequest.getParameter(cookieName));\n cookie.setPath(UPLOAD_SITE_PATH);\n httpResponse.addCookie(cookie);\n }\n }\n }\n\n @Override\n public void destroy() {\n }\n\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34365/"
] |
351,268 | <p><strong>back story:</strong> I am designing a portfolio website for myself. on its home page, the logo is front and center but on the sub pages the logo is top & right. </p>
<p>I thought it would be a nice visual cue (upon clicking a link to a sub page) to use jQuery to animate the movement of the logo from the middle to the corner of the page. </p>
<p><strong>the issue:</strong> the sub page loads faster than the animation completes. </p>
<p><strong>question:</strong> is there some way to pause the link-following until after the animation has completed?
</p>
| [
{
"answer_id": 351304,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 0,
"selected": false,
"text": " $(\"#thelink\").click( function(){\n $(this).animate( { animation stuff }, \"medium\", \"easeboth\", function(){\n document.location = $(this).attr('href'); \n });\n });\n $(\"#thelink\").click( function(){\n $(\"#theImg\").animate( { animation stuff }, \"medium\", \"easeboth\", function(){\n document.location = $(\"thelink\").attr('href'); \n });\n });\n"
},
{
"answer_id": 351998,
"author": "redsquare",
"author_id": 6440,
"author_profile": "https://Stackoverflow.com/users/6440",
"pm_score": 6,
"selected": true,
"text": " $('#myLink').click( function(ev){\n //prevent the default action of the event, this will stop the href in the anchor being followed\n //before the animation has started, u can also use return false;\n ev.preventDefault();\n //store a reference to the anchor tag\n var $self=$(this);\n //get the image and animate assuming the image is a direct child of the anchor, if not use .find\n $self.children('img').animate( {height:\"10px\"}, function(){\n //now get the anchor href and redirect the browser\n document.location = $self.attr('href');\n });\n });\n"
},
{
"answer_id": 353763,
"author": "jon",
"author_id": 44443,
"author_profile": "https://Stackoverflow.com/users/44443",
"pm_score": 1,
"selected": false,
"text": "print(\" $(function()\n {\n $('#myLink').click( function(ev){\n //prevent the default action of the event, this will stop the href in the anchor being followed\n //before the animation has started, u can also use return false;\n ev.preventDefault();\n //store a referene to the anchor tag\n var $self=$('img#myImage');\n var $link=$('a#myLink');\n //get the image and animate\n ($self).animate( {height:\"10px\"}, function(){\n //now get the anchor href and redirect the browser\n document.location = $link.attr('href');\n });\n });\n });\n\");\n print(\"<body>\n<a id=\"myLink\" href=\"http://www.google.co.uk\">LINK</a>\n\n<img id=\"myImage\" src=\"http://www.derekallard.com/img/post_resources/jquery_ui_cap.png\"/>\n</body>\");\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44443/"
] |
351,296 | <p>I am developping in C#.
I need to capture a password written inside a Text Box, but would like to not show the password that is being typed, showing instead **** or any other character to hide the password.</p>
<p>How can I do that? I'm sure it's by modifying an attribute, but can't find which one.</p>
| [
{
"answer_id": 351307,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 1,
"selected": false,
"text": "PasswordChar"
},
{
"answer_id": 351312,
"author": "grepsedawk",
"author_id": 14388,
"author_profile": "https://Stackoverflow.com/users/14388",
"pm_score": 0,
"selected": false,
"text": "\ntextBox1.UseSystemPasswordChar = true;\n\n//or\n\ntextBox1.PasswordChar = '%';\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19159/"
] |
351,306 | <p>I want to programmatically create a SHA1 checksum of audio files (MP3, Ogg Vorbis, Flac).
The requirement is that the checksum should be stable <strong>even if the header (eg. ID3) changes</strong>.<br/>
<em>Note: The audio files don't have CRCs</em></p>
<p>This is what I tried by now:</p>
<h3>1) Reading + Hashing all MPEG frames using Perl and <a href="http://search.cpan.org/dist/MPEG::Audio::Frame/" rel="nofollow noreferrer">MPEG::Audio::Frame</a></h3>
<pre><code>my $sha1 = Digest::SHA1->new;
while (my $frame = MPEG::Audio::Frame->read(\*FH)) {
$sha1->add($frame->content());
}
</code></pre>
<h3>2) Decoding + Hashing all MPEG frames using Python and <a href="http://spacepants.org/src/pymad/" rel="nofollow noreferrer">libmad (pymad)</a></h3>
<pre><code>mf = mad.MadFile(path)
sha1 = hashlib.sha1()
while 1:
buf = mf.read()
if (buf is None):
break
sha1.update(buf)
</code></pre>
<h3>3) Using <a href="http://tomclegg.net/mp3cat" rel="nofollow noreferrer">mp3cat</a></h3>
<pre><code>> mp3cat - - < file.mp3 | sha1sum
</code></pre>
<p>However, none of those methods provided a <strong>stable</strong> checksum. Namely, in <em>some</em> cases the checksum changed after retagging the file with <a href="http://musicbrainz.org/doc/PicardTagger" rel="nofollow noreferrer">picard</a>.</p>
<p>Are there any libraries that already provide what I want?<br/>
I don't care about the programming language… </p>
<p><b>Update:</b>
I debugged the case a bit further.
The libmad checksum inconsitency seems to happen in cases where libmad gets some decoding errors, like <em>"Huffman data overrun (0x0238)"</em>.
As this really happens on many of the mp3 files I'm not sure if it really indicates a broken file…</p>
| [
{
"answer_id": 897594,
"author": "mivk",
"author_id": 111036,
"author_profile": "https://Stackoverflow.com/users/111036",
"pm_score": 0,
"selected": false,
"text": "ffmpeg ffmpeg -i \"$filename\" -map 0:a -codec copy -f md5 \"$filename.md5\"\n -f hash -f framemd5 use MPEG::Audio::Frame;\nuse Digest::MD5 qw(md5_hex);\nuse strict;\n\nmy $file = 'E:\\Music\\MP3\\Russensoul\\01 - 5nizza , Soldat (Russensoul - Russensoul).mp3';\nmy $mp3tag_audio_md5 = lc '2EDFBD62995A46A45CEEC08C1F303486';\n\nmy $md5 = Digest::MD5->new;\n\nopen(FILE, $file) or die \"Cannot open $file : $!\\n\";\nbinmode FILE;\n\nwhile(my $frame = MPEG::Audio::Frame->read(\\*FILE)){\n $md5->add($frame->asbin);\n}\n\nprint '$md5->hexdigest : ', $md5->hexdigest, \"\\n\",\n 'mp3tag_audio_md5 : ', $mp3tag_audio_md5, \"\\n\",\n ;\n"
},
{
"answer_id": 6305839,
"author": "Julian Kunkel",
"author_id": 792679,
"author_profile": "https://Stackoverflow.com/users/792679",
"pm_score": 2,
"selected": false,
"text": "#!/bin/bash\n\n# This bash script appends an MD5SUM to the vorbiscomment and/or verifies it if it exists\n# Later modification of the vorbis comment does not alter the MD5SUM\n# Julian M.K.\n\nFILE=\"$1\"\n\nif [[ ! -f \"$FILE\" || ! -r \"$FILE\" || ! -w \"$FILE\" ]] ; then\n echo \"File $FILE\" does not exist or is not readable or writable\n exit 1\nfi\n\nOLDCRC=`vorbiscomment \"$FILE\" | grep ^CRC=|cut -d \"=\" -f 2`\nNEWCRC=`ogginfo \"$FILE\" |grep \"Total data length:\" |cut -d \":\" -f 2 | md5sum |cut -d \" \" -f 1`\n\nif [[ \"$OLDCRC\" == \"\" ]] ; then\n echo \"ADDED $FILE $NEWCRC\"\n vorbiscomment -a -t \"CRC=$NEWCRC\" \"$FILE\" \n # rewrite CRC to get proper data length, I dont know why this is necessary\n NEWCRC=`ogginfo \"$FILE\" |grep \"Total data length:\" |cut -d \":\" -f 2 | md5sum |cut -d \" \" -f 1`\n vorbiscomment -w -t \"CRC=$NEWCRC\" \"$FILE\" \nelif [[ \"$OLDCRC\" == \"$NEWCRC\" ]] ; then\n echo \"VERIFIED $FILE\"\nelse\n echo \"FAILURE $FILE -- $OLDCRC - $NEWCRC\"\nfi\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4308/"
] |
351,314 | <p>I have to implement a homemade Trie and I'm stuck on the Iterator part. I can't seem to figure out the increment method for the trie.</p>
<p>I hope someone can help me clear things out.</p>
<p>Here's the code for the Iterator:</p>
<pre><code>template <typename T> class Trie<T>::IteratorPrefixe{
friend class Trie<T>;
public:
IteratorPrefixe() : tree(NULL), currentNode(NULL), currentKey("") {};
pair<string, T*> operator*() {return make_pair(currentKey, currentNode -> element);} ;
IteratorPrefixe operator++()throw(runtime_error);
void operator=(IteratorPrefixe iter) {tree = iter.tree; currentNode = iter.currentNode; currentKey = iter.currentKey;};
bool operator==(IteratorPrefixe iter) {return tree == iter.tree && currentNode == iter.currentNode;};
bool operator!=(IteratorPrefixe iter) {return tree != iter.tree || currentNode != iter.currentNode;};
private:
Trie<T> * tree;
Trie<T> * currentNode;
string currentKey;
};
</code></pre>
<p>And here's my Trie:</p>
<pre><code>template <typename T> class Trie {
friend class IteratorPrefixe;
public:
// Create a Trie<T> from the alphabet of nbletters, where nbletters must be
// between 1 and NBLETTERSMAX inclusively
Trie(unsigned nbletters) throw(runtime_error);
// Add a key element of which is given in the first argument and content second argument
// The content must be defined (different from NULL pointer)
// The key is to be composed of valid letters (the letters between A + inclusive and exclusive nbletters
// Eg if nblettres is 3, a, b and c are the only characters permitted;
// If nblettres is 15, only the letters between a and o inclusive are allowed.
// Returns true if the insertion was achieved, returns false otherwise.
bool addElement(string, T*) throw(runtime_error);
// Deletes a key element of which is given as an argument and returns the contents of the node removed
// The key is to be composed of letters valid (see above)
// Can also delete at the same time the reference of the ancestors, if these ancestors are no longer used.
// Returns NULL if the item has no delete
T* removeElement(string cle) throw(runtime_error);
// Find a key element of which is given as an argument and returns the associated content
// The key is to be composed of letters valid (see above)
// Returns NULL if the key does not exist
T* searchElement(string cle) throw();
// Iterator class to browse the Trie <T> in preorder mode
class IteratorPrefixe;
// Returns an iterator pointing to the first element
IteratorPrefixe pbegin() throw(runtime_error);
// Returns an iterator pointing beyond the last item
IteratorPrefixe pend() throw();
private:
unsigned nbLetters;
T* element;
vector<Trie<T> *> childs;
Trie<T> * parent;
// This function removes a node and its ancestors if became unnecessary. It is essentially the same work
// as deleteElement that is how to designate remove a node that is changing. Moreover, unlike
// deleteElement, it does not return any information on the node removed.
void remove(Trie<T> * node) throw();
// This function is seeking a node based on a given key. It is essentially the same work
// searchElement but that returns a reference to the node found (or null if the node does not exist)
// The key is to be composed of letters valid (see above)
Trie<T>* search(string key) throw(runtime_error);
};
</code></pre>
| [
{
"answer_id": 366209,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 0,
"selected": false,
"text": "T* unsigned operator++ Trie template <class L, class R>\nclass Either\n{\npublic:\n\n Either(L *l) : left(l), right(0)\n {}\n\n Either(R *r) : left(0), right(r)\n {}\n\n L *get_left() const\n {\n return left;\n }\n\n R *get_right() const\n {\n return right;\n }\n\n bool is_left() const\n {\n return left != 0;\n }\n\n bool is_right() const\n {\n return right != 0;\n }\n\nprivate:\n L *left;\n R *right;\n};\n Trie private:\n Either<unsigned, T*> disjoint;\n\n vector<Trie<T> *> children; // english pluralization\n Trie<T> * parent;\n unsigned T*"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44447/"
] |
351,334 | <p>What is the difference between them? <br /></p>
<p>When would I opt for one over the other?</p>
| [
{
"answer_id": 13910431,
"author": "Joe",
"author_id": 989485,
"author_profile": "https://Stackoverflow.com/users/989485",
"pm_score": 5,
"selected": false,
"text": "XmlSerializer DataContractSerializer XmlSerializer"
},
{
"answer_id": 49856627,
"author": "Ali Azam",
"author_id": 4464220,
"author_profile": "https://Stackoverflow.com/users/4464220",
"pm_score": 3,
"selected": false,
"text": "[WebService]\npublic class Service : System.Web.Services.WebService\n{\n [WebMethod]\n public string Test(string strMsg)\n {\n return strMsg;\n }\n}\n [ServiceContract]\npublic interface ITest\n{\n [OperationContract]\n string ShowMessage(string strMsg);\n}\npublic class Service : ITest\n{\n public string ShowMessage(string strMsg)\n {\n return strMsg;\n }\n}\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351334",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1443363/"
] |
351,336 | <p>We get these ~50GB data files consisting of 16 byte codes, and I want to find any code that occurs 1/2% of the time or more. Is there any way I can do that in a single pass over the data?</p>
<p>Edit: There are tons of codes - it's possible that every code is different.</p>
<p>EPILOGUE: I've selected Darius Bacon as best answer, because I think the best algorithm is a modification of the majority element he linked to. The majority algorithm should be modifiable to only use a tiny amount of memory - like 201 codes to get 1/2% I think. Basically you just walk the stream counting up to 201 distinct codes. As soon as you find 201 distinct codes, you drop one of each code (deduct 1 from the counters, forgetting anything that becomes 0). At the end, you have dropped at most N/201 times, so any code occurring more times than that must still be around.</p>
<p>But it's a two pass algorithm, not one. You need a second pass to tally the counts of the candidates. It's actually easy to see that any solution to this problem must use at least 2 passes (the first batch of elements you load could all be different and one of those codes could end up being exactly 1/2%)</p>
<p>Thanks for the help!</p>
| [
{
"answer_id": 351399,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 2,
"selected": false,
"text": "sort * | uniq -c"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44444/"
] |
351,340 | <p>3 fields: FirstName, MiddleName, LastName</p>
<p>Any field can be null, but I don't want extra spaces. Format should be "First Middle Last", "First Last", "Last", etc.</p>
| [
{
"answer_id": 351356,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 2,
"selected": false,
"text": "LTRIM(RTRIM(ISNULL(FirstName, '') + ' ' + LTRIM(ISNULL(MiddleName, '') + ' ' + \n ISNULL(LastName, ''))))\n"
},
{
"answer_id": 351357,
"author": "Andrew Rollings",
"author_id": 40410,
"author_profile": "https://Stackoverflow.com/users/40410",
"pm_score": 3,
"selected": false,
"text": " LTRIM(RTRIM(\n LTRIM(RTRIM(ISNULL(FirstName, ''))) + ' ' + \n LTRIM(RTRIM(ISNULL(MiddleName, ''))) + ' ' + \n LTRIM(ISNULL(LastName, ''))\n ))\n"
},
{
"answer_id": 351358,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "LTrim(RTrim(Replace(IsNull(Firstname + ' ', '') + \n isNull(MiddleName, '') + \n IsNull(' ' + LastName, ''), ' ', ' ')))"
},
{
"answer_id": 351586,
"author": "Jamal Hansen",
"author_id": 2035722,
"author_profile": "https://Stackoverflow.com/users/2035722",
"pm_score": 3,
"selected": true,
"text": "`Select udfConcatName(First, Middle, Last) from foo`\n"
},
{
"answer_id": 351593,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 3,
"selected": false,
"text": "ISNULL(FirstName + ' ', '') + ISNULL(MiddleName + ' ', '') + ISNULL(LastName, '')\n SET CONCAT_NULL_YIELDS_NULL OFF\nLTRIM(FirstName + ' ' + NULLIF(MiddleName + ' ', ' ') + LastName)\n SELECT a FROM b\n EXEC c\n c\n"
},
{
"answer_id": 351630,
"author": "GregD",
"author_id": 38317,
"author_profile": "https://Stackoverflow.com/users/38317",
"pm_score": 0,
"selected": false,
"text": "'\"' + ltrim(rtrim(isnull(FirstName,''))) + ' ' + ltrim(rtrim(isnull(MiddleName,''))) + \n' ' + ltrim(rtrim(isnull(LastName,''))) + '\",\"' + ltrim(rtrim(isnull(FirstName,''))) + \n' ' + ltrim(rtrim(isnull(LastName,''))) + '\",\"' + ltrim(rtrim(isnull(LastName,''))) + \n'\"'\n"
},
{
"answer_id": 8760868,
"author": "Gordon Bell",
"author_id": 16473,
"author_profile": "https://Stackoverflow.com/users/16473",
"pm_score": 1,
"selected": false,
"text": "replace(ltrim(rtrim(isnull(FirstName, '') + ' ' + isnull(MiddleName, '') + ' ' + isnull(LastName, ''))), ' ', ' ')\n"
},
{
"answer_id": 21321934,
"author": "user3230059",
"author_id": 3230059,
"author_profile": "https://Stackoverflow.com/users/3230059",
"pm_score": 0,
"selected": false,
"text": "DECLARE @first varchar(10) = 'First'\nDECLARE @middle varchar(10) = ''\nDECLARE @last varchar(10) = 'Last'\n\nLTRIM(RTRIM(\n @first\n + ISNULL(NULLIF(' '+LTRIM(RTRIM(@middle)),' '),'')\n + ISNULL(NULLIF(' '+LTRIM(RTRIM(@last)),' '),'')\n))\n LTRIM(RTRIM(ISNULL(@middle,''))) -- Result is a trimmed non-null string value.\n NULLIF(' '+'',' ') -- this would return NULL\nNULLIF(' '+'Smith',' ') -- this would return ' Smith'\n ISNULL(NULL,'') -- this would return ''\nISNULL(' Smith','') -- this would return ' Smith'\n"
},
{
"answer_id": 32156124,
"author": "Muhammad Ali Shan",
"author_id": 4247798,
"author_profile": "https://Stackoverflow.com/users/4247798",
"pm_score": 0,
"selected": false,
"text": "Select firstname, middlename, lastname, ProvidedName = \n\nRTrim(Coalesce(FirstName + ' ','') \n+ Coalesce(MiddleName + ' ', '')\n+ Coalesce(LastName + ' ', '')\n+ COALESCE('' + ' ', '')\n+ COALESCE(NULL, ''))\n\nFrom names\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22448/"
] |
351,345 | <p>I have the same problem as <a href="http://forums.oreilly.com/content/C-3-0-in-a-Nutshell/775/Linq-To-Sql-Classes-With-Multiple-Relationships-To-A-Table/" rel="nofollow noreferrer">this guy</a>: </p>
<p>I have a table that has references my tblstaff table twice for two different people. Now that I have added this second reference neither of them work.</p>
<p>What is up w/ that?</p>
| [
{
"answer_id": 359701,
"author": "Christopher Rathermel",
"author_id": 44449,
"author_profile": "https://Stackoverflow.com/users/44449",
"pm_score": 1,
"selected": false,
"text": " Dim id As String = 1\n Session(\"BusinessPlanID\") = id\n\n Dim oLinq As New Linq\n Dim bp As BusinessPlan = oLinq.getBusinessPlanById(id)\n\n Dim assignedStaff As Staff = oLinq.getStaffById(bp.AssignedStaffID)\n Dim mp As Staff = oLinq.getStaffById(bp.MPStaffID)\n\n Public Function getBusinessPlanById(ByVal inId As String) As BusinessPlan\n\n Dim db As New BusinessPlanDataDataContext\n\n Dim bpItem = (From b In db.BusinessPlans _\n Select b _\n Where b.BusinessPlanID = inId).SingleOrDefault\n\n Return bpItem\n\n End Function\n\n 'Linq Class --------------------------------------------------------'\n\n Public Function getStaffById(ByVal inId As String) As Staff\n\n Dim db As New BusinessPlanDataDataContext\n\n Dim staffItem = (From s In db.Staffs _\n Select s _\n Where s.StaffID = inId).SingleOrDefault\n\n Return staffItem\n\n End Function\n"
}
] | 2008/12/08 | [
"https://Stackoverflow.com/questions/351345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44449/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.