qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
63,206
<p>If Java application requires certain JRE version then how can I check its availability on Mac OS X during installation?</p>
[ { "answer_id": 63227, "author": "Stu Thompson", "author_id": 2961, "author_profile": "https://Stackoverflow.com/users/2961", "pm_score": 2, "selected": true, "text": "manoa:~ stu$ ll /System/Library/Frameworks/JavaVM.framework/Versions/\ntotal 56\n774077 lrwxr-xr-x 1 root wheel 5 Jul 23 15:31 1.3 -> 1.3.1\n167151 drwxr-xr-x 3 root wheel 102 Jan 14 2008 1.3.1\n167793 lrwxr-xr-x 1 root wheel 5 Feb 21 2008 1.4 -> 1.4.2\n774079 lrwxr-xr-x 1 root wheel 3 Jul 23 15:31 1.4.1 -> 1.4\n166913 drwxr-xr-x 8 root wheel 272 Feb 21 2008 1.4.2\n168494 lrwxr-xr-x 1 root wheel 5 Feb 21 2008 1.5 -> 1.5.0\n166930 drwxr-xr-x 8 root wheel 272 Feb 21 2008 1.5.0\n774585 lrwxr-xr-x 1 root wheel 5 Jul 23 15:31 1.6 -> 1.6.0\n747415 drwxr-xr-x 8 root wheel 272 Jul 23 10:24 1.6.0\n167155 drwxr-xr-x 8 root wheel 272 Jul 23 15:31 A\n776765 lrwxr-xr-x 1 root wheel 1 Jul 23 15:31 Current -> A\n774125 lrwxr-xr-x 1 root wheel 3 Jul 23 15:31 CurrentJDK -> 1.5\nmanoa:~ stu$ \n" }, { "answer_id": 63236, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 0, "selected": false, "text": "String javaVersion = System.getProperty(\"java.version\");\nif (javaVersion.startsWith(\"1.4\")) {\n // New features for 1.4\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7292/" ]
63,232
<p>How would you make the contents of Flex RIA applications accessible to Google, so that Google can index the content and shows links to the right items in your Flex RIA. Consider a online shop, created in Flex, where the offered items shall be indexed by Google. Then a link on Google should open the corresponding product in the RIA.</p>
[ { "answer_id": 64077, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 4, "selected": true, "text": "/items/345" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7524/" ]
63,291
<p>How do I select all the columns in a table that only contain NULL values for all the rows? I'm using <strong>MS SQL Server 2005</strong>. I'm trying to find out which columns are not used in the table so I can delete them.</p>
[ { "answer_id": 63312, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "SELECT cols\nFROM table\nWHERE cols IS NULL\n" }, { "answer_id": 63374, "author": "Charles Graham", "author_id": 7705, "author_profile": "https://Stackoverflow.com/users/7705", "pm_score": -1, "selected": false, "text": "for each col\nbegin\n @cmd = 'if not exists (select * from tablename where ' + col + ' is not null begin print ' + col + ' end'\nexec(@cmd)\nend\n" }, { "answer_id": 63412, "author": "Kevin Fairchild", "author_id": 3743, "author_profile": "https://Stackoverflow.com/users/3743", "pm_score": 3, "selected": false, "text": "SET NOCOUNT ON\nDECLARE @TableName Varchar(100)\nSET @TableName='YourTableName'\nCREATE TABLE #NullColumns (ColumnName Varchar(100), OnlyNulls BIT)\nINSERT INTO #NullColumns (ColumnName, OnlyNulls) SELECT c.name, 0 FROM syscolumns c INNER JOIN sysobjects o ON c.id = o.id AND o.name = @TableName AND o.xtype = 'U'\nDECLARE @DynamicSQL AS Nvarchar(2000)\nDECLARE @ColumnName Varchar(100)\nDECLARE @RC INT\n SELECT TOP 1 @ColumnName = ColumnName FROM #NullColumns WHERE OnlyNulls=0\n WHILE @@ROWCOUNT > 0\n BEGIN\n SET @RC=0\n SET @DynamicSQL = 'SELECT TOP 1 1 As HasNonNulls FROM ' + @TableName + ' (nolock) WHERE ''' + @ColumnName + ''' IS NOT NULL'\n EXEC sp_executesql @DynamicSQL\n set @RC=@@rowcount\n IF @RC=1\n BEGIN\n SET @DynamicSQL = 'UPDATE #NullColumns SET OnlyNulls=1 WHERE ColumnName=''' + @ColumnName + ''''\n EXEC sp_executesql @DynamicSQL\n END\n ELSE\n BEGIN\n SET @DynamicSQL = 'DELETE FROM #NullColumns WHERE ColumnName=''' + @ColumnName+ ''''\n EXEC sp_executesql @DynamicSQL\n END\n SELECT TOP 1 @ColumnName = ColumnName FROM #NullColumns WHERE OnlyNulls=0\n END\n\nSELECT * FROM #NullColumns\n\nDROP TABLE #NullColumns\nSET NOCOUNT OFF\n" }, { "answer_id": 63432, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 0, "selected": false, "text": "\nforeach $column ($cols) {\n query(\"SELECT count(*) FROM table WHERE $column IS NOT NULL\")\n if($result is zero) {\n # $column contains only null values\"\n push @onlyNullColumns, $column;\n } else {\n # $column contains non-null values\n }\n}\nreturn @onlyNullColumns;\n" }, { "answer_id": 63552, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 2, "selected": false, "text": "select \n count(<columnName>)\nfrom\n <tableName>\n select \n case(count(<columnName>)) when 0 then 'Nulls Only' else 'Some Values' end\nfrom \n <tableName>\n" }, { "answer_id": 63565, "author": "squadette", "author_id": 7754, "author_profile": "https://Stackoverflow.com/users/7754", "pm_score": 0, "selected": false, "text": "SELECT COUNT(DISTINCT field) FROM tableName\n" }, { "answer_id": 63641, "author": "MobyDX", "author_id": 3923, "author_profile": "https://Stackoverflow.com/users/3923", "pm_score": 3, "selected": false, "text": "DECLARE crs CURSOR LOCAL FAST_FORWARD FOR SELECT name FROM syscolumns WHERE id=OBJECT_ID('Person')\nOPEN crs\nDECLARE @name sysname\nFETCH NEXT FROM crs INTO @name\nWHILE @@FETCH_STATUS = 0\nBEGIN\n EXEC('SELECT ''' + @name + ''' WHERE NOT EXISTS (SELECT * FROM Person WHERE ' + @name + ' IS NOT NULL)')\n FETCH NEXT FROM crs INTO @name\nEND\nCLOSE crs\nDEALLOCATE crs\n" }, { "answer_id": 63772, "author": "Charles Graham", "author_id": 7705, "author_profile": "https://Stackoverflow.com/users/7705", "pm_score": 7, "selected": true, "text": "declare @col varchar(255), @cmd varchar(max)\n\nDECLARE getinfo cursor for\nSELECT c.name FROM sys.tables t JOIN sys.columns c ON t.Object_ID = c.Object_ID\nWHERE t.Name = 'ADDR_Address'\n\nOPEN getinfo\n\nFETCH NEXT FROM getinfo into @col\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SELECT @cmd = 'IF NOT EXISTS (SELECT top 1 * FROM ADDR_Address WHERE [' + @col + '] IS NOT NULL) BEGIN print ''' + @col + ''' end'\n EXEC(@cmd)\n\n FETCH NEXT FROM getinfo into @col\nEND\n\nCLOSE getinfo\nDEALLOCATE getinfo\n" }, { "answer_id": 63868, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "NULL COLLATE IS NULL SELECT * FROM MyTable WHERE COLLATE(Col1, Col2, Col3, Col4......) IS NULL\n columns primary key null" }, { "answer_id": 16550333, "author": "Jasmina Shevchenko", "author_id": 2370941, "author_profile": "https://Stackoverflow.com/users/2370941", "pm_score": 1, "selected": false, "text": "DECLARE @table VARCHAR(100) = 'dbo.table'\n\nDECLARE @sql NVARCHAR(MAX) = ''\n\nSELECT @sql = @sql + 'IF NOT EXISTS(SELECT 1 FROM ' + @table + ' WHERE ' + c.name + ' IS NOT NULL) PRINT ''' + c.name + ''''\nFROM sys.objects o\nJOIN sys.columns c ON o.[object_id] = c.[object_id]\nWHERE o.[type] = 'U'\n AND o.[object_id] = OBJECT_ID(@table)\n AND c.is_nullable = 1\n\nEXEC(@sql)\n" }, { "answer_id": 24685175, "author": "user2466387", "author_id": 2466387, "author_profile": "https://Stackoverflow.com/users/2466387", "pm_score": 3, "selected": false, "text": "SET NOCOUNT ON;\n\nDECLARE\n @ColumnName sysname\n,@DataType nvarchar(128)\n,@cmd nvarchar(max)\n,@TableSchema nvarchar(128) = 'dbo'\n,@TableName sysname = 'TableName';\n\nDECLARE getinfo CURSOR FOR\nSELECT\n c.COLUMN_NAME\n ,c.DATA_TYPE\nFROM\n INFORMATION_SCHEMA.COLUMNS AS c\nWHERE\n c.TABLE_SCHEMA = @TableSchema\n AND c.TABLE_NAME = @TableName;\n\nOPEN getinfo;\n\nFETCH NEXT FROM getinfo INTO @ColumnName, @DataType;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SET @cmd = N'IF NOT EXISTS (SELECT * FROM ' + @TableSchema + N'.' + @TableName + N' WHERE [' + @ColumnName + N'] IS NOT NULL) RAISERROR(''' + @ColumnName + N' (' + @DataType + N')'', 0, 0) WITH NOWAIT;';\n EXECUTE (@cmd);\n\n FETCH NEXT FROM getinfo INTO @ColumnName, @DataType;\nEND;\n\nCLOSE getinfo;\nDEALLOCATE getinfo;\n" }, { "answer_id": 24685590, "author": "user3827049", "author_id": 3827049, "author_profile": "https://Stackoverflow.com/users/3827049", "pm_score": 0, "selected": false, "text": "SELECT t.column_name\nFROM user_tab_columns t\nWHERE t.nullable = 'Y' AND t.table_name = 'table name here' AND t.num_distinct = 0;\n" }, { "answer_id": 43806546, "author": "Sylvain Bruyere", "author_id": 7969179, "author_profile": "https://Stackoverflow.com/users/7969179", "pm_score": 0, "selected": false, "text": "AND IS_NULLABLE = 'YES'\n SET NOCOUNT ON;\n\nDECLARE\n @ColumnName sysname\n,@DataType nvarchar(128)\n,@cmd nvarchar(max)\n,@TableSchema nvarchar(128) = 'dbo'\n,@TableName sysname = 'TableName';\n\nDECLARE getinfo CURSOR FOR\nSELECT\n c.COLUMN_NAME\n ,c.DATA_TYPE\nFROM\n INFORMATION_SCHEMA.COLUMNS AS c\nWHERE\n c.TABLE_SCHEMA = @TableSchema\n AND c.TABLE_NAME = @TableName\n AND IS_NULLABLE = 'YES';\n\nOPEN getinfo;\n\nFETCH NEXT FROM getinfo INTO @ColumnName, @DataType;\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n SET @cmd = N'IF NOT EXISTS (SELECT * FROM ' + @TableSchema + N'.' + @TableName + N' WHERE [' + @ColumnName + N'] IS NOT NULL) RAISERROR(''' + @ColumnName + N' (' + @DataType + N')'', 0, 0) WITH NOWAIT;';\n EXECUTE (@cmd);\n\n FETCH NEXT FROM getinfo INTO @ColumnName, @DataType;\nEND;\n\nCLOSE getinfo;\nDEALLOCATE getinfo;\n" }, { "answer_id": 44392513, "author": "user8120267", "author_id": 8120267, "author_profile": "https://Stackoverflow.com/users/8120267", "pm_score": 1, "selected": false, "text": "USE [DATABASE_NAME] -- !\nGO\n\nDECLARE @SQL NVARCHAR(MAX)\nDECLARE @TableName VARCHAR(255)\n\nSET @TableName = 'TABLE_NAME' -- !\n\nSELECT @SQL = \n(\n SELECT \n CHAR(10)\n +'DELETE FROM ['+t1.TABLE_CATALOG+'].['+t1.TABLE_SCHEMA+'].['+t1.TABLE_NAME+'] WHERE '\n +(\n SELECT \n CASE t2.ORDINAL_POSITION \n WHEN (SELECT MIN(t3.ORDINAL_POSITION) FROM INFORMATION_SCHEMA.COLUMNS t3 WHERE t3.TABLE_NAME=t2.TABLE_NAME) THEN ''\n ELSE 'AND '\n END\n +'['+COLUMN_NAME+'] IS NULL' AS 'data()'\n FROM INFORMATION_SCHEMA.COLUMNS t2 WHERE t2.TABLE_NAME=t1.TABLE_NAME FOR XML PATH('')\n ) AS 'data()'\n FROM INFORMATION_SCHEMA.TABLES t1 WHERE t1.TABLE_NAME = @TableName FOR XML PATH('')\n)\n\nSELECT @SQL -- EXEC(@SQL)\n" }, { "answer_id": 57849043, "author": "Akila Viduranga Liyanaarachchi", "author_id": 6885539, "author_profile": "https://Stackoverflow.com/users/6885539", "pm_score": 1, "selected": false, "text": "exec [dbo].[SP_RemoveNullValues] 'Your_Table_Name'\n GO\n/****** Object: StoredProcedure [dbo].[SP_RemoveNullValues] Script Date: 09/09/2019 11:26:53 AM ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\n-- akila liyanaarachchi\nCreate procedure [dbo].[SP_RemoveNullValues](@PTableName Varchar(50) ) as \nbegin\n\n\nDECLARE Cussor CURSOR FOR \nSELECT COLUMN_NAME,TABLE_NAME,DATA_TYPE\nFROM INFORMATION_SCHEMA.COLUMNS\nWHERE TABLE_NAME = @PTableName \n\nOPEN Cussor;\n\nDeclare @ColumnName Varchar(50)\nDeclare @TableName Varchar(50)\nDeclare @DataType Varchar(50)\nDeclare @Flage int \n\nFETCH NEXT FROM Cussor INTO @ColumnName,@TableName,@DataType\nWHILE @@FETCH_STATUS = 0\nBEGIN\n\nset @Flage=0\n\n\nIf(@DataType in('bigint','numeric','bit','smallint','decimal','smallmoney','int','tinyint','money','float','real'))\nbegin\nset @Flage=1\nend \nIf(@DataType in('date','atetimeoffset','datetime2','smalldatetime','datetime','time'))\nbegin\nset @Flage=2\nend \nIf(@DataType in('char','varchar','text','nchar','nvarchar','ntext'))\nbegin\nset @Flage=3\nend \n\nIf(@DataType in('binary','varbinary'))\nbegin\nset @Flage=4\nend \n\n\n\nDECLARE @SQL VARCHAR(MAX) \n\nif (@Flage in(1,4))\nbegin \n\nSET @SQL =' update ['+@TableName+'] set ['+@ColumnName+']=0 where ['+@ColumnName+'] is null'\nend \n\nif (@Flage =3)\nbegin \n\nSET @SQL =' update ['+@TableName+'] set ['+@ColumnName+'] = '''' where ['+@ColumnName+'] is null '\nend \n\nif (@Flage =2)\nbegin \n\nSET @SQL =' update ['+@TableName+'] set ['+@ColumnName+'] ='+'''1901-01-01 00:00:00.000'''+' where ['+@ColumnName+'] is null '\nend \n\n\nEXEC(@SQL)\n\n\n\nFETCH NEXT FROM Cussor INTO @ColumnName,@TableName,@DataType\nEND\n\nCLOSE Cussor\nDEALLOCATE Cussor\n\nEND\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/299/" ]
63,295
<p>I have Sun webserver iws6 (iplanet 6) proxying my bea cluster. My cluster is under /portal/yadda. I want anyone who goes to </p> <pre><code>http://the.domain.com/ </code></pre> <p>to be quickly redirected to </p> <pre><code>http://the.domain.com/portal/ </code></pre> <p>I have and index.html that does a post and redirect, but the user sometimes sees it. Does anyone have a better way?</p> <p>Aaron</p> <p>I have tried the 3 replies below. None of them worked for me. Back to the drawing board. A</p>
[ { "answer_id": 63398, "author": "Adam Davis", "author_id": 2915, "author_profile": "https://Stackoverflow.com/users/2915", "pm_score": -1, "selected": false, "text": "<?php\nheader(\"Location: http://www.example.com/\"); /* Redirect browser */\n\n/* Make sure that code below does not get executed when we redirect. */\nexit;\n?>\n Redirect 301 /oldpage.html http://www.example.com/newpage.html\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7659/" ]
63,303
<p>I have a System.Diagnostics.Process object in a program targeted at the .Net framework 3.5</p> <p>I have redirected both <code>StandardOutput</code> and <code>StandardError</code> pipes and I'm receiving data from them asynchronously. I've also set an event handler for the Exited event.</p> <p>Once I call <code>Process.Start()</code> I want to go off and do other work whilst I wait for events to be raised.</p> <p>Unfortunately it appears that, for a process which returns a large amount of information, the Exited event is fired before the last <code>OutputDataReceived</code> event.</p> <p>How do I know when the last <code>OutputDataReceived</code> has been received? Ideally I would like the <code>Exited</code> event to be the last event I receive.</p> <p>Here is an example program:</p> <pre><code>using System; using System.Diagnostics; using System.Threading; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string command = "output.exe"; string arguments = " whatever"; ProcessStartInfo info = new ProcessStartInfo(command, arguments); // Redirect the standard output of the process. info.RedirectStandardOutput = true; info.RedirectStandardError = true; // Set UseShellExecute to false for redirection info.UseShellExecute = false; Process proc = new Process(); proc.StartInfo = info; proc.EnableRaisingEvents = true; // Set our event handler to asynchronously read the sort output. proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived); proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived); proc.Exited += new EventHandler(proc_Exited); proc.Start(); // Start the asynchronous read of the sort output stream. Note this line! proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); proc.WaitForExit(); Console.WriteLine("Exited (Main)"); } static void proc_Exited(object sender, EventArgs e) { Console.WriteLine("Exited (Event)"); } static void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine("Error: {0}", e.Data); } static void proc_OutputDataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine("Output data: {0}", e.Data); } } } </code></pre> <p>When running this program you will notice that "Exited (Event)" appears in a completely variable location within the output. You may need to run it a few times and, obviously, you will need to replace "output.exe" with a program of your choice that produces a suitably large amount of output.</p> <p>So, the question again: How do I know when the last <code>OutputDataReceived</code> has been received? Ideally I would like the <code>Exited</code> event to be the last event I receive.</p>
[ { "answer_id": 1423665, "author": "csharptest.net", "author_id": 164392, "author_profile": "https://Stackoverflow.com/users/164392", "pm_score": 5, "selected": false, "text": "e.Data null static void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e)\n{\n if( e.Data == null ) _exited.Set();\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,343
<p>Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE and through the Tools -> Options I changed the homepage to iGoogle.com. Clicked okay and then clicked the homepage button. IE crashes.</p> <p>Now you'd think that I could just remove iGoogle as the homepage but when I open IE it immediately goes to that page and crashes on open.</p> <p>Obviously I'd prefer to find a solution to why IE is crashing on the iGoogle page but just to get IE running again I need to remove iGoogle as the homepage. Is there anyway to do this without opening IE?</p>
[ { "answer_id": 63367, "author": "Sietse", "author_id": 6400, "author_profile": "https://Stackoverflow.com/users/6400", "pm_score": 2, "selected": false, "text": "start » run » iexplore about:blank\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
63,379
<p>I have a case where a VB.Net winforms app needs to play WMV files from across the network. The user running the app cannot be given direct access to the network share. Through impersonation, I can see that the files exist (without impersonation, File.Exists returns false for the files on the network share). When I then try to load the file into a Windows Media Player control, the control just remains black. I have deduced that when the Windows Media Player control is loaded into memory, it is running on a separate unmanaged thread than the .Net managed thread. Is there any way to pass that security token from the managed thread to the unmanaged thread? Am I missing something completely?</p>
[ { "answer_id": 64630, "author": "Alvaro Rodriguez", "author_id": 1550, "author_profile": "https://Stackoverflow.com/users/1550", "pm_score": 0, "selected": false, "text": "[DllImport(\"advapi32.dll\", SetLastError=true)]\npublic static extern int LogonUser(string pszUsername, string pszDomain, string pszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); \n" }, { "answer_id": 1633464, "author": "Brett Veenstra", "author_id": 307, "author_profile": "https://Stackoverflow.com/users/307", "pm_score": 1, "selected": false, "text": "SetThreadPrincipal AppDomain IPrinicipal userPrincipal = new MyCustomPrincipal(); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.SetThreadPrincipal(userPrincipal);" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,399
<p>I need to do a dump of a table on a remote server, but I can't access the server directly. The only access I have is through PHP scripts.</p> <p>Is there some way in which MySQL will return an </p> <pre><code>INSERT INTO `table_name` (`field1`, `field2`) VALUES ('a', 'b'), ('c', 'd') </code></pre> <p>statement, like what <code>mysqldump</code> will return?</p> <p>I don't have access to phpMyAdmin, and I preferably don't want to use <code>exec</code>, <code>system</code> or <code>passthru</code>.</p> <p>See <a href="https://stackoverflow.com/questions/81934/easy-way-to-export-a-sql-table-without-access-to-the-server-or-phpmyadmin">this question</a> for another export method</p>
[ { "answer_id": 63431, "author": "agnul", "author_id": 6069, "author_profile": "https://Stackoverflow.com/users/6069", "pm_score": 0, "selected": false, "text": "select 'insert into table table_name (field1, field2) values'\n || table_name.field1 || ', ' || table_field2 || ');'\nfrom table_name\n" }, { "answer_id": 63468, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "$results = mysql_query(\"SELECT * FROM `table_name`\");\nwhile($row = mysql_fetch_assoc($results)) {\n\n $query = \"INSERT INTO `table_name` \";\n $fields = '(';\n $values = '('; \n\n foreach($row as $field=>$value) {\n $fields .= \"'\".$field.\"',\";\n $values .= \"'\".mysql_escape_string($value).\"',\";\n }\n\n //drop the last comma off\n $fields = substr($fields,0,-1);\n $values = substr($values,0,-1);\n\n $query .= $fields . \" VALUES \" . $values;\n\n //your final result\n echo $query;\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6681/" ]
63,421
<p>Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into two, the bottom being a shell which I use to type in compile or make commands, and the top is often some sort of documentation or README file that I want to consult while I am working. Now I know there are some pretty expert Emacs users out there, and I am curious what other Emacs functionally is useful if the intention is to use it as a complete IDE. Specifically, most IDEs usually fulfill these functions is some form or another:</p> <ul> <li>Source code editor</li> <li>Compiler</li> <li>Debugging</li> <li>Documentation Lookup</li> <li>Version Control</li> <li>OO features like class lookup and object inspector </li> </ul> <p>For a few of these, it's pretty obvious how Emacs can fit these functions, but what about the rest? Also, if a specific language must be focused on, I'd say it should be C++. </p> <p><strong>Edit:</strong> One user pointed out that I should have been more specific when I said 'what about the rest'. Mostly I was curious about efficient version control, as well as documentation lookup. For example, in SLIME it is fairly easy to do a quick hyperspec lookup on a Lisp function. Is there a quick way to look up something in C++ STL documentation (if I forgot the exact syntax of <a href="http://www.sgi.com/tech/stl/hash_map.html" rel="noreferrer">hash_map</a>, for example)?</p>
[ { "answer_id": 63511, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 7, "selected": true, "text": "M-x compile M-x compile M-x gdb" }, { "answer_id": 594533, "author": "Jonas Kölker", "author_id": 58668, "author_profile": "https://Stackoverflow.com/users/58668", "pm_score": 2, "selected": false, "text": "M-x man M-x info C-h f >>> help(<function, class, module>) BROWSER emacsclient -e \"(w3m-goto-url-new-session \\\"$@\\\")\"" }, { "answer_id": 1616958, "author": "Cheeso", "author_id": 48082, "author_profile": "https://Stackoverflow.com/users/48082", "pm_score": 2, "selected": false, "text": "(require 'tfs)\n(setq tfs/tf-exe \"c:\\\\vs2008\\\\common7\\\\ide\\\\tf.exe\")\n(setq tfs/login \"/login:domain\\\\userid,password\")\n -or-\n(setq tfs/login (getenv \"TFSLOGIN\")) ;; if you have this set\n (global-set-key \"\\C-xvo\" 'tfs/checkout)\n(global-set-key \"\\C-xvi\" 'tfs/checkin)\n(global-set-key \"\\C-xvp\" 'tfs/properties)\n(global-set-key \"\\C-xvr\" 'tfs/rename)\n(global-set-key \"\\C-xvg\" 'tfs/get)\n(global-set-key \"\\C-xvh\" 'tfs/history)\n(global-set-key \"\\C-xvu\" 'tfs/undo)\n(global-set-key \"\\C-xvd\" 'tfs/diff)\n(global-set-key \"\\C-xv-\" 'tfs/delete)\n(global-set-key \"\\C-xv+\" 'tfs/add)\n(global-set-key \"\\C-xvs\" 'tfs/status)\n(global-set-key \"\\C-xva\" 'tfs/annotate)\n(global-set-key \"\\C-xvw\" 'tfs/workitem)\n" }, { "answer_id": 4621015, "author": "Cheeso", "author_id": 48082, "author_profile": "https://Stackoverflow.com/users/48082", "pm_score": 2, "selected": false, "text": "compile-command compile (defun cheeso-guess-compile-command ()\n \"set `compile-command' intelligently depending on the\ncurrent buffer, or the contents of the current directory.\"\n (interactive)\n (set (make-local-variable 'compile-command)\n (cond\n ((or (file-expand-wildcards \"*.csproj\" t)\n (file-expand-wildcards \"*.vcproj\" t)\n (file-expand-wildcards \"*.vbproj\" t)\n (file-expand-wildcards \"*.shfbproj\" t)\n (file-expand-wildcards \"*.sln\" t))\n \"msbuild \")\n\n ;; sometimes, not sure why, the buffer-file-name is\n ;; not set. Can use it only if set.\n (buffer-file-name\n (let ((filename (file-name-nondirectory buffer-file-name)))\n (cond\n\n ;; editing a .wxs (WIX Soluition) file\n ((string-equal (substring buffer-file-name -4) \".wxs\")\n (concat \"nmake \"\n ;; (substring buffer-file-name 0 -4) ;; includes full path\n (file-name-sans-extension filename)\n \".msi\" ))\n\n ;; a javascript file - run jslint\n ((string-equal (substring buffer-file-name -3) \".js\")\n (concat (getenv \"windir\")\n \"\\\\system32\\\\cscript.exe c:\\\\users\\\\cheeso\\\\bin\\\\jslint-for-wsh.js \"\n filename))\n\n ;; something else - do a typical .exe build\n (t\n (concat \"nmake \"\n (file-name-sans-extension filename)\n \".exe\")))))\n (t\n \"nmake \"))))\n\n\n(defun cheeso-invoke-compile-interactively ()\n \"fn to wrap the `compile' function. This simply\nchecks to see if `compile-command' has been previously set, and\nif not, invokes `cheeso-guess-compile-command' to set the value.\nThen it invokes the `compile' function, interactively.\"\n (interactive)\n (cond\n ((not (boundp 'cheeso-local-compile-command-has-been-set))\n (cheeso-guess-compile-command)\n (set (make-local-variable 'cheeso-local-compile-command-has-been-set) t)))\n ;; local compile command has now been set\n (call-interactively 'compile))\n\n;; in lieu of binding to `compile', bind to my monkeypatched function\n(global-set-key \"\\C-x\\C-e\" 'cheeso-invoke-compile-interactively)\n compile" }, { "answer_id": 14636137, "author": "Muhammet Can", "author_id": 460281, "author_profile": "https://Stackoverflow.com/users/460281", "pm_score": 3, "selected": false, "text": "server mode emacs --daemon\n alias ec=\"emacsclient -t\"\nalias ecc=\"emacsclient -c &\"\n# some people also prefer this but no need to fight here;\nalias vi=\"emacsclient -t\"\n root tramp C-x C-f\n/sudo:root@localhost/some/file/that/has/root/access/permissions\n# on some linux distro it might be `/su:root@...` \n" }, { "answer_id": 53142784, "author": "sidharth arya", "author_id": 9204788, "author_profile": "https://Stackoverflow.com/users/9204788", "pm_score": 3, "selected": false, "text": "M-x gdb" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7545/" ]
63,439
<p>How can I programatically cause a control's tooltip to show in a Winforms app without needing the mouse to hover over the control? (P/Invoke is ok if necessary). </p>
[ { "answer_id": 63471, "author": "Mark D", "author_id": 7452, "author_profile": "https://Stackoverflow.com/users/7452", "pm_score": 0, "selected": false, "text": "static HWND hwndToolTip = NULL;\n\nvoid CreateToolTip( HWND hWndControl, TCHAR *tipText )\n{ \n BOOL success;\n\n if( hwndToolTip == NULL )\n {\n hwndToolTip = CreateWindow( TOOLTIPS_CLASS, \n NULL, \n WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, \n CW_USEDEFAULT, CW_USEDEFAULT, \n CW_USEDEFAULT, CW_USEDEFAULT, \n NULL, NULL,\n hInstResource, \n NULL ); \n }\n\n if( hwndToolTip )\n { \n TOOLINFO ti; \n\n ti.cbSize = sizeof(ti); \n ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS; \n ti.hwnd = hWndControl; \n ti.uId = 0; \n ti.hinst = NULL; \n ti.lpszText = tipText; \n\n GetClientRect( hWndControl, &ti.rect ); \n\n success = SendMessage( hwndToolTip, TTM_ADDTOOL, 0, (LPARAM) &ti ); \n }\n}\n" }, { "answer_id": 63482, "author": "Mark Ingram", "author_id": 986, "author_profile": "https://Stackoverflow.com/users/986", "pm_score": 3, "selected": false, "text": "System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();\nToolTip1.SetToolTip(this.textBox1, \"Hello\");\n" }, { "answer_id": 63592, "author": "Keithius", "author_id": 5956, "author_profile": "https://Stackoverflow.com/users/5956", "pm_score": 6, "selected": true, "text": "Tooltip ToolTip1.Show(\"Text to display\", Control)" }, { "answer_id": 15887382, "author": "Bruno Poulin", "author_id": 2259073, "author_profile": "https://Stackoverflow.com/users/2259073", "pm_score": 0, "selected": false, "text": "Public Class MyForm \nPrivate MyTooltip As New ToolTip \n... \nSub ApplyToolTips \n'For default \nApplyToolTips (1000) \nEnd Sub \n\nSub ApplyTooltips (ByVal Delay as Integer) \n\nMyTooltip .InitialDelay = Delay \nMyTooltip.AutoPopDelay = 5000 \n... \nMyTooltip.SetToolTip(Me.btnClose, \"Close the form\") \n\nEnd Sub \n\nPrivate Sub Btn_Click(sender As System.Object, e As System.EventArgs) Handles Btn.Click \n Dim PicBox As PictureBox = CType(sender, PictureBox) \n ApplyTooltips (0) \n ApplyTooltips (1000) \nEnd Sub \n" }, { "answer_id": 73280329, "author": "SteveCinq", "author_id": 5818981, "author_profile": "https://Stackoverflow.com/users/5818981", "pm_score": 0, "selected": false, "text": "OnClick Click ToolTip1.Show(\"Text to display\", Control);\n MouseLeave ToolTip1.Hide(Control);\n x y Point Click ToolTip1.Show(\"Text to display\", Control, Control.Width+20, 0, 2000);\n ToolTip1.Show(\"Text to display\", Control, new Point(Control.Width+20, 0), 2000);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2187/" ]
63,447
<p>How do I perform an <code>IF...THEN</code> in an <code>SQL SELECT</code> statement?</p> <p>For example:</p> <pre><code>SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product </code></pre>
[ { "answer_id": 63474, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 6, "selected": false, "text": "SELECT \n(CASE \n WHEN (Obsolete = 'N' OR InStock = 'Y') THEN 'YES'\n ELSE 'NO' \n END) as Salable\n, * \nFROM Product\n" }, { "answer_id": 63476, "author": "palehorse", "author_id": 312, "author_profile": "https://Stackoverflow.com/users/312", "pm_score": 6, "selected": false, "text": "SELECT Salable =\n CASE Obsolete\n WHEN 'N' THEN 1\n ELSE 0\n END\n" }, { "answer_id": 63477, "author": "Santiago Cepas", "author_id": 6547, "author_profile": "https://Stackoverflow.com/users/6547", "pm_score": 6, "selected": false, "text": " SELECT\n CASE \n WHEN OBSOLETE = 'N' or InStock = 'Y' THEN 'TRUE' \n ELSE 'FALSE' \n END AS Salable,\n * \nFROM PRODUCT\n" }, { "answer_id": 63480, "author": "Darrel Miller", "author_id": 6819, "author_profile": "https://Stackoverflow.com/users/6819", "pm_score": 12, "selected": true, "text": "CASE SELECT CAST(\n CASE\n WHEN Obsolete = 'N' or InStock = 'Y'\n THEN 1\n ELSE 0\n END AS bit) as Saleable, *\nFROM Product\n CAST int SELECT CASE\n WHEN Obsolete = 'N' or InStock = 'Y'\n THEN 1\n ELSE 0\n END as Saleable, *\nFROM Product\n CASE CASE SELECT IIF(Obsolete = 'N' or InStock = 'Y', 1, 0) as Saleable, * FROM Product\n" }, { "answer_id": 63498, "author": "sven", "author_id": 46, "author_profile": "https://Stackoverflow.com/users/46", "pm_score": 7, "selected": false, "text": "SELECT\n FirstName, LastName,\n Salary, DOB,\n CASE Gender\n WHEN 'M' THEN 'Male'\n WHEN 'F' THEN 'Female'\n END\nFROM Employees\n" }, { "answer_id": 63500, "author": "user7658", "author_id": 7658, "author_profile": "https://Stackoverflow.com/users/7658", "pm_score": 6, "selected": false, "text": "select select case when Obsolete = 'N' or InStock = 'Y' then 'YES' else 'NO' end\n where where 1 = case when Obsolete = 'N' or InStock = 'Y' then 1 else 0 end\n" }, { "answer_id": 63504, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "SELECT CASE\n WHEN (Obsolete = 'N' OR InStock = 'Y')\n THEN 'Y'\n ELSE 'N'\nEND as Available\n\netc...\n" }, { "answer_id": 63777, "author": "Jonathan", "author_id": 6910, "author_profile": "https://Stackoverflow.com/users/6910", "pm_score": 8, "selected": false, "text": "SELECT CASE <variable> WHEN <value> THEN <returnvalue>\n WHEN <othervalue> THEN <returnthis>\n ELSE <returndefaultcase>\n END AS <newcolumnname>\nFROM <table>\n SELECT CASE WHEN <test> THEN <returnvalue>\n WHEN <othertest> THEN <returnthis>\n ELSE <returndefaultcase>\n END AS <newcolumnname>\nFROM <table>\n" }, { "answer_id": 2010311, "author": "Ken", "author_id": 244385, "author_profile": "https://Stackoverflow.com/users/244385", "pm_score": 6, "selected": false, "text": "IF THEN ELSE IF EXISTS(SELECT *\n FROM Northwind.dbo.Customers\n WHERE CustomerId = 'ALFKI')\n PRINT 'Need to update Customer Record ALFKI'\nELSE\n PRINT 'Need to add Customer Record ALFKI'\n\nIF EXISTS(SELECT *\n FROM Northwind.dbo.Customers\n WHERE CustomerId = 'LARSE')\n PRINT 'Need to update Customer Record LARSE'\nELSE\n PRINT 'Need to add Customer Record LARSE' \n" }, { "answer_id": 6769805, "author": "Martin Smith", "author_id": 73226, "author_profile": "https://Stackoverflow.com/users/73226", "pm_score": 8, "selected": false, "text": "IIF SELECT IIF(Obsolete = 'N' OR InStock = 'Y', 1, 0) AS Salable, *\nFROM Product\n CASE CASE IIF() CASE IF IF @IncludeExtendedInformation = 1\n BEGIN\n SELECT A,B,C,X,Y,Z\n FROM T\n END\nELSE\n BEGIN\n SELECT A,B,C\n FROM T\n END\n" }, { "answer_id": 13089905, "author": "Robert B. Grossman", "author_id": 1777537, "author_profile": "https://Stackoverflow.com/users/1777537", "pm_score": 4, "selected": false, "text": "INSERT INTO customers (last_name, first_name, city)\n SELECT 'Doe', 'John', 'Chicago' FROM dual\n WHERE NOT EXISTS\n (SELECT '1' from customers\n where last_name = 'Doe'\n and first_name = 'John'\n and city = 'Chicago');\n" }, { "answer_id": 17004447, "author": "Tomasito", "author_id": 1296687, "author_profile": "https://Stackoverflow.com/users/1296687", "pm_score": 5, "selected": false, "text": "DECLARE @Product TABLE (\n id INT PRIMARY KEY IDENTITY NOT NULL\n ,Obsolote CHAR(1)\n ,Instock CHAR(1)\n)\n\nINSERT INTO @Product ([Obsolote], [Instock])\n VALUES ('N', 'N'), ('N', 'Y'), ('Y', 'Y'), ('Y', 'N')\n\n;\nWITH cte\nAS\n(\n SELECT\n 'CheckIfInstock' = CAST(ISNULL(NULLIF(ISNULL(NULLIF(p.[Instock], 'Y'), 1), 'N'), 0) AS BIT)\n ,'CheckIfObsolote' = CAST(ISNULL(NULLIF(ISNULL(NULLIF(p.[Obsolote], 'N'), 0), 'Y'), 1) AS BIT)\n ,*\n FROM\n @Product AS p\n)\nSELECT\n 'Salable' = c.[CheckIfInstock] & ~c.[CheckIfObsolote]\n ,*\nFROM\n [cte] c\n case true false for true: ISNULL(NULLIF(p.[Instock], 'Y'), 1)\nfor false: ISNULL(NULLIF(p.[Instock], 'N'), 0)\n" }, { "answer_id": 20992729, "author": "Dibin", "author_id": 1915236, "author_profile": "https://Stackoverflow.com/users/1915236", "pm_score": 3, "selected": false, "text": "SELECT IIF(Obsolete = 'N' OR InStock = 'Y', 1, 0) AS Salable, *\nFROM Product \n" }, { "answer_id": 32200662, "author": "Mohammad Atiour Islam", "author_id": 1077346, "author_profile": "https://Stackoverflow.com/users/1077346", "pm_score": 4, "selected": false, "text": "SELECT CASE WHEN profile.nrefillno = 0 THEN 'N' ELSE 'R'END as newref\nFrom profile\n" }, { "answer_id": 34178590, "author": "Chanukya", "author_id": 5093602, "author_profile": "https://Stackoverflow.com/users/5093602", "pm_score": 4, "selected": false, "text": "case statement some what similar to if in SQL server\n\nSELECT CASE \n WHEN Obsolete = 'N' or InStock = 'Y' \n THEN 1 \n ELSE 0 \n END as Saleable, * \nFROM Product\n" }, { "answer_id": 34340652, "author": "Ravi Anand", "author_id": 2444505, "author_profile": "https://Stackoverflow.com/users/2444505", "pm_score": 5, "selected": false, "text": "DECLARE @val INT;\nSET @val = 15;\n\nIF @val < 25\nPRINT 'Hi Ravi Anand';\nELSE\nPRINT 'By Ravi Anand.';\n\nGO\n DECLARE @val INT;\nSET @val = 15;\n\nIF @val < 25\nPRINT 'Hi Ravi Anand.';\nELSE\nBEGIN\nIF @val < 50\n PRINT 'what''s up?';\nELSE\n PRINT 'Bye Ravi Anand.';\nEND;\n\nGO\n" }, { "answer_id": 35350520, "author": "JustJohn", "author_id": 564810, "author_profile": "https://Stackoverflow.com/users/564810", "pm_score": 4, "selected": false, "text": " CASE orweb2.dbo.Inventory.RegulatingAgencyName\n WHEN 'Region 1'\n THEN orweb2.dbo.CountyStateAgContactInfo.ContactState\n WHEN 'Region 2'\n THEN orweb2.dbo.CountyStateAgContactInfo.ContactState\n WHEN 'Region 3'\n THEN orweb2.dbo.CountyStateAgContactInfo.ContactState\n WHEN 'DEPT OF AGRICULTURE'\n THEN orweb2.dbo.CountyStateAgContactInfo.ContactAg\n ELSE (\n CASE orweb2.dbo.CountyStateAgContactInfo.IsContract\n WHEN 1\n THEN orweb2.dbo.CountyStateAgContactInfo.ContactCounty\n ELSE orweb2.dbo.CountyStateAgContactInfo.ContactState\n END\n )\n END AS [County Contact Name]\n" }, { "answer_id": 36868923, "author": "sandeep rawat", "author_id": 6085803, "author_profile": "https://Stackoverflow.com/users/6085803", "pm_score": 5, "selected": false, "text": "SELECT IIF ( (Obsolete = 'N' OR InStock = 'Y'), 1, 0) AS Saleable, * FROM Product\n" }, { "answer_id": 37167739, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 4, "selected": false, "text": "SELECT 1 AS Saleable, *\n FROM @Product\n WHERE ( Obsolete = 'N' OR InStock = 'Y' )\nUNION\nSELECT 0 AS Saleable, *\n FROM @Product\n WHERE NOT ( Obsolete = 'N' OR InStock = 'Y' )\n" }, { "answer_id": 40886727, "author": "SURJEET SINGH Bisht", "author_id": 5081921, "author_profile": "https://Stackoverflow.com/users/5081921", "pm_score": 3, "selected": false, "text": " SELECT IIF(Obsolete = 'N' OR InStock = 'Y',1,0) AS Saleable, * FROM Product\n" }, { "answer_id": 45578381, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "SELECT CASE WHEN Obsolete = 'N' or InStock = 'Y' THEN 1 ELSE 0 \n END AS Saleable, * \nFROM Product\n" }, { "answer_id": 48541127, "author": "Serkan Arslan", "author_id": 8500110, "author_profile": "https://Stackoverflow.com/users/8500110", "pm_score": 3, "selected": false, "text": "CASE DECLARE @Product TABLE (ID INT, Obsolete VARCHAR(10), InStock VARCHAR(10))\nINSERT INTO @Product VALUES\n(1,'N','Y'),\n(2,'A','B'),\n(3,'N','B'),\n(4,'A','Y')\n\nSELECT P.* , ISNULL(Stmt.Saleable,0) Saleable\nFROM\n @Product P\n LEFT JOIN\n ( VALUES\n ( 'N', 'Y', 1 )\n ) Stmt (Obsolete, InStock, Saleable)\n ON P.InStock = Stmt.InStock OR P.Obsolete = Stmt.Obsolete\n ID Obsolete InStock Saleable\n----------- ---------- ---------- -----------\n1 N Y 1\n2 A B 0\n3 N B 1\n4 A Y 1\n" }, { "answer_id": 52696617, "author": "laplace", "author_id": 9822422, "author_profile": "https://Stackoverflow.com/users/9822422", "pm_score": 2, "selected": false, "text": "SELECT \n CAST(\n CASE WHEN Obsolete = 'N' \n or InStock = 'Y' THEN ELSE 0 END AS bit\n ) as Saleable, * \nFROM \n Product\n" }, { "answer_id": 53121744, "author": "David Cohn", "author_id": 10588302, "author_profile": "https://Stackoverflow.com/users/10588302", "pm_score": 3, "selected": false, "text": "SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product\n Select \n case when p.Obsolete = 'N' \n or p.InStock = 'Y' then 1 else 0 end as Saleable, \n p.* \nFROM \n Product p;\n p" }, { "answer_id": 54932658, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "SELECT IIF ( (Obsolete = 'N' OR InStock = 'Y'), 1, 0) AS Saleable, * FROM Product\n Select Case SELECT CASE\n WHEN Obsolete = 'N' or InStock = 'Y'\n THEN 1\n ELSE 0\n END as Saleable, *\n FROM Product\n" }, { "answer_id": 58643023, "author": "Muhammad Awais", "author_id": 3901944, "author_profile": "https://Stackoverflow.com/users/3901944", "pm_score": 2, "selected": false, "text": "SELECT OrderID, Quantity,\nCASE\n WHEN Quantity > 30 THEN \"The quantity is greater than 30\"\n WHEN Quantity = 30 THEN \"The quantity is 30\"\n ELSE \"The quantity is under 30\"\nEND AS QuantityText\nFROM OrderDetails;\n" }, { "answer_id": 59086460, "author": "Salman A", "author_id": 87015, "author_profile": "https://Stackoverflow.com/users/87015", "pm_score": 2, "selected": false, "text": "obsolete = 'N' OR instock = 'Y'\n | obsolete | instock | saleable |\n|----------|---------|----------|\n| Y | Y | true |\n| Y | N | false |\n| Y | null | null |\n| N | Y | true |\n| N | N | true |\n| N | null | true |\n| null | Y | true |\n| null | N | null |\n| null | null | null |\n SELECT CASE\n WHEN obsolete = 'N' OR instock = 'Y' THEN 'true'\n WHEN NOT (obsolete = 'N' OR instock = 'Y') THEN 'false'\n ELSE NULL\n END AS saleable\n SELECT CASE\n WHEN obsolete = 'N' OR instock = 'Y' THEN 'true'\n ELSE 'false' -- either false or null\n END AS saleable\n" }, { "answer_id": 60278997, "author": "Tharuka Madumal", "author_id": 12910157, "author_profile": "https://Stackoverflow.com/users/12910157", "pm_score": 3, "selected": false, "text": "SELECT\n CASE\n WHEN obsolete = 'N' OR InStock = 'Y'\n THEN 1\n ELSE 0\n END AS Salable\n , *\nFROM PRODUCT\n" }, { "answer_id": 61112581, "author": "Prashant Marathay", "author_id": 12046787, "author_profile": "https://Stackoverflow.com/users/12046787", "pm_score": 2, "selected": false, "text": "SELECT\n\n if(GENDER = \"M\",\"Male\",\"Female\") as Gender\n\nFROM ...\n if(condition, true, false)\n" }, { "answer_id": 61941630, "author": "The AG", "author_id": 8692957, "author_profile": "https://Stackoverflow.com/users/8692957", "pm_score": 2, "selected": false, "text": "Select\nCase WHEN (Obsolete = 'N' or InStock = 'Y') THEN 1 ELSE 0 END Saleable,\nProduct.*\nfrom Product\n" }, { "answer_id": 65006288, "author": "yusuf hayırsever", "author_id": 10238086, "author_profile": "https://Stackoverflow.com/users/10238086", "pm_score": 3, "selected": false, "text": "SELECT\nif((obsolete = 'N' OR instock = 'Y'), 1, 0) AS saleable, *\nFROM\nproduct;\n" }, { "answer_id": 71934110, "author": "durlove roy", "author_id": 1549783, "author_profile": "https://Stackoverflow.com/users/1549783", "pm_score": 1, "selected": false, "text": "SELECT\n\n(CASE\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1001' THEN 'DM'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1002' THEN 'GS'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1003' THEN 'MB'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1004' THEN 'MP'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1005' THEN 'PL'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1008' THEN 'DM-27'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1011' THEN 'PB'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1012' THEN 'UT-2'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1013' THEN 'JGC'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1014' THEN 'SB'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1015' THEN 'IR'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1016' THEN 'UT-3'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1017' THEN 'UT-4'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1019' THEN 'KR'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1020' THEN 'SYB-SB'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1021' THEN 'GR'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1022' THEN 'SYB-KP'\nWHEN RIGHT((LEFT(POSID,5)),4) LIKE '1026' THEN 'BNS'\n\n ELSE ''\nEND) AS OUTLET\n\nFROM matrixcrm.Transact\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6522/" ]
63,463
<p>Let's say I have a web page that currently accepts a single ID value via a url parameter:<br> <a href="http://example.com/mypage.aspx?ID=1234" rel="nofollow noreferrer">http://example.com/mypage.aspx?ID=1234</a></p> <p>I want to change it to accept a <em>list</em> of ids, like this:<br> <a href="http://example.com/mypage.aspx?IDs=1234,4321,6789" rel="nofollow noreferrer">http://example.com/mypage.aspx?IDs=1234,4321,6789</a></p> <p>So it's available to my code as a string via <em>context.Request.QueryString["IDs"].</em> What's the best way to turn that string value into a List&lt;int>?</p> <p><strong>Edit:</strong> I know how to do .split() on a comma to get a list of strings, but I ask because I don't know how to easily convert that string list to an int list. This is still in .Net 2.0, so no lambdas.</p>
[ { "answer_id": 63472, "author": "Grokys", "author_id": 6448, "author_profile": "https://Stackoverflow.com/users/6448", "pm_score": 0, "selected": false, "text": "string[] splitIds = ids.split(',');\n" }, { "answer_id": 63508, "author": "Mark Embling", "author_id": 6844, "author_profile": "https://Stackoverflow.com/users/6844", "pm_score": 2, "selected": false, "text": "int.TryParse() List<int>" }, { "answer_id": 63527, "author": "user7658", "author_id": 7658, "author_profile": "https://Stackoverflow.com/users/7658", "pm_score": 2, "selected": false, "text": "Dim lstIDs as new List(of Integer)(ids.split(','))\n" }, { "answer_id": 63544, "author": "Richard C", "author_id": 6389, "author_profile": "https://Stackoverflow.com/users/6389", "pm_score": 1, "selected": false, "text": "\nList<int> intList = new List<int>;\n\nforeach (string tempString in ids.split(',')\n{\n intList.add (convert.int32(tempString));\n}\n\n" }, { "answer_id": 63561, "author": "Compile This", "author_id": 4048, "author_profile": "https://Stackoverflow.com/users/4048", "pm_score": 4, "selected": false, "text": "public static IList<int> GetIdListFromString(string idList)\n{\n string[] values = idList.Split(',');\n\n List<int> ids = new List<int>(values.Length);\n\n foreach (string s in values)\n {\n int i;\n\n if (int.TryParse(s, out i))\n {\n ids.Add(i);\n }\n }\n\n return ids;\n}\n string intString = \"1234,4321,6789\";\n\nIList<int> list = GetIdListFromString(intString);\n\nforeach (int i in list)\n{\n Console.WriteLine(i);\n}\n" }, { "answer_id": 63578, "author": "dpollock", "author_id": 7884, "author_profile": "https://Stackoverflow.com/users/7884", "pm_score": 0, "selected": false, "text": "List<int> convertIDs = new List<int>;\nstring[] splitIds = ids.split(',');\nforeach(string s in splitIds)\n{\n convertIDs.Add(int.Parse(s));\n}\n List<int> convertIDs = new List<int>;\nstring[] splitIds = ids.split(',');\nforeach(string s in splitIds)\n{\n int i;\n int.TryParse(out i);\n if (i != 0)\n convertIDs.Add(i);\n}\n" }, { "answer_id": 63584, "author": "Philibert Perusse", "author_id": 7984, "author_profile": "https://Stackoverflow.com/users/7984", "pm_score": 0, "selected": false, "text": " string[] splitIds = stringIds.Split(',');\n\n int[] ids = new int[splitIds.Length];\n for (int i = 0; i < ids.Length; i++) {\n ids[i] = Int32.Parse(splitIds[i]);\n }\n" }, { "answer_id": 63601, "author": "Jesse Millikan", "author_id": 7526, "author_profile": "https://Stackoverflow.com/users/7526", "pm_score": 2, "selected": false, "text": " string ids = \"1,2,3,4,5\";\n\n List<int> l = new List<int>(Array.ConvertAll(\n ids.Split(','), new Converter<string, int>(int.Parse)));\n" }, { "answer_id": 63649, "author": "Magnus Akselvoll", "author_id": 4683, "author_profile": "https://Stackoverflow.com/users/4683", "pm_score": 0, "selected": false, "text": "class Program\n{\n static void Main(string[] args)\n {\n string queryString = \"1234,4321,6789\";\n\n int[] ids = ConvertCommaSeparatedStringToIntArray(queryString);\n }\n\n private static int[] ConvertCommaSeparatedStringToIntArray(string csString)\n {\n //splitting string to substrings\n string[] idStrings = csString.Split(',');\n\n //initializing int-array of same length\n int[] ids = new int[idStrings.Length];\n\n //looping all substrings\n for (int i = 0; i < idStrings.Length; i++)\n {\n string idString = idStrings[i];\n\n //trying to convert one substring to int\n int id;\n if (!int.TryParse(idString, out id))\n throw new FormatException(String.Format(\"Query string contained malformed id '{0}'\", idString));\n\n //writing value back to the int-array\n ids[i] = id;\n }\n\n return ids;\n }\n}\n" }, { "answer_id": 63686, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "Function GetIDs(ByVal IDList As String) As List(Of Integer)\n Dim SplitIDs() As String = IDList.Split(new Char() {\",\"c}, StringSplitOptions.RemoveEmptyEntries)\n GetIDs = new List(Of Integer)(SplitIDs.Length)\n Dim CurID As Integer\n For Each id As String In SplitIDs\n If Integer.TryParse(id, CurID) Then GetIDs.Add(CurID)\n Next id\nEnd Function\n" }, { "answer_id": 63836, "author": "Magnus Akselvoll", "author_id": 4683, "author_profile": "https://Stackoverflow.com/users/4683", "pm_score": 2, "selected": false, "text": "class Program\n{\n //Accepts one or more groups of one or more digits, separated by commas.\n private static readonly Regex CSStringPattern = new Regex(@\"^(\\d+,?)*\\d+$\");\n\n //A single ID inside the string. Must only be used after validation\n private static readonly Regex SingleIdPattern = new Regex(@\"\\d+\");\n\n static void Main(string[] args)\n {\n string queryString = \"1234,4321,6789\";\n\n int[] ids = ConvertCommaSeparatedStringToIntArray(queryString);\n }\n\n private static int[] ConvertCommaSeparatedStringToIntArray(string csString)\n {\n if (!CSStringPattern.IsMatch(csString))\n throw new FormatException(string.Format(\"Invalid comma separated string '{0}'\",\n csString));\n\n List<int> ids = new List<int>();\n foreach (Match match in SingleIdPattern.Matches(csString))\n {\n ids.Add(int.Parse(match.Value)); //No need to TryParse since string has been validated\n }\n return ids.ToArray();\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
63,494
<p>I discovered <a href="http://en.wikipedia.org/wiki/Template_metaprogramming" rel="noreferrer">template metaprogramming</a> more than 5 years ago and got a huge kick out of reading <a href="https://rads.stackoverflow.com/amzn/click/com/0201704315" rel="noreferrer" rel="nofollow noreferrer">Modern C++ Design</a> but I never found an opertunity to use it in real life.</p> <p>Have <em>you</em> ever used this technique in real code?</p> <blockquote> <p>Contributors to <a href="http://www.boost.org/" rel="noreferrer">Boost</a> need not apply ;o)</p> </blockquote>
[ { "answer_id": 3586490, "author": "deft_code", "author_id": 28817, "author_profile": "https://Stackoverflow.com/users/28817", "pm_score": 3, "selected": false, "text": "template< typename T >\nT& singleton();\n\ntemplate< typename T >\nT& zombie_singleton();\n\ntemplate< typename T >\nT& phoenix_singleton();\n" }, { "answer_id": 4312165, "author": "AntonLosev", "author_id": 524849, "author_profile": "https://Stackoverflow.com/users/524849", "pm_score": 2, "selected": false, "text": "vector<boost::any> #include <iostream>\n#include <vector>\n#include <string>\n#include <Loki/Typelist.h>\n#include <Loki/TypeTraits.h>\n#include <Loki/TypeManip.h>\n#include <boost/any.hpp>\n#define OTL_ORA10G_R2\n#define OTL_ORA_UTF8\n#include <otlv4.h>\n\nusing namespace Loki;\n\n/* Auxiliary structs */\ntemplate <int T1, int T2>\nstruct IsIntTemplateEqualsTo{\n static const int value = ( T1 == T2 );\n};\n\ntemplate <int T1>\nstruct ZeroIntTemplateWorkaround{\n static const int value = ( 0 == T1? 1 : T1 );\n};\n\n\n/* Wrapper class for data row */\ntemplate <class TList>\nclass T_DataRow;\n\n\ntemplate <>\nclass T_DataRow<NullType>{\nprotected:\n std::vector<boost::any> _data;\npublic:\n void Populate( otl_stream& ){};\n};\n\n\n/* Note the inheritance trick that enables to traverse Typelist */\ntemplate <class T, class U>\nclass T_DataRow< Typelist<T, U> >:public T_DataRow<U>{\npublic:\n void Populate( otl_stream& aInputStream ){\n T value;\n aInputStream >> value;\n boost::any anyValue = value;\n _data.push_back( anyValue );\n\n T_DataRow<U>::Populate( aInputStream );\n }\n\n template <int TIdx>\n /* return type */\n Select<\n IsIntTemplateEqualsTo<TIdx, 0>::value,\n typename T,\n typename TL::TypeAt<\n U,\n ZeroIntTemplateWorkaround<TIdx>::value - 1\n >::Result\n >::Result\n /* sig */\n GetValue(){\n /* body */\n return boost::any_cast<\n Select<\n IsIntTemplateEqualsTo<TIdx, 0>::value,\n typename T,\n typename TL::TypeAt<\n U,\n ZeroIntTemplateWorkaround<TIdx>::value - 1\n >::Result\n >::Result\n >( _data[ TIdx ] );\n }\n};\n\n\nint main(int argc, char* argv[])\n{\n db.rlogon( \"AMONRAWMS/[email protected]\" ); // connect to Oracle\n std::cout<<\"Connected to oracle DB\"<<std::endl;\n otl_stream o( 1, \"select * from blockstatuslist\", db );\n\n T_DataRow< TYPELIST_3( int, int, std::string )> c;\n c.Populate( o );\n typedef enum{ rcnum, id, name } e_fields; \n /* After declaring enum you can actually acess columns by name */\n std::cout << c.GetValue<rcnum>() << std::endl;\n std::cout << c.GetValue<id>() << std::endl;\n std::cout << c.GetValue<name>() << std::endl;\n return 0;\n};\n operator >> otl_stream o( 1, \"select * from blockstatuslist\", db );\nint rcnum; \nint id;\nstd::string name;\no >> rcnum >> id >> name; \n olt_stream::operator >>(T&) Typelist Typelist" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848/" ]
63,517
<p>I'm absolutely stunned by the fact that MS just couldn't get it right to navigate to the definition of a method, when you're combining C# and VB projects in one solution. If you're trying to navigate from VB to C#, it brings up the "Object Explorer", and if from C# to VB, it generates a metadata file.</p> <p>Honestly, what is so complicated about jumping between different languages, especially if they're supposedly using the same CLR?</p> <p>Does anyone know why this is, or if there's any workaround? Did they get it right in VS 2008?</p> <hr> <p>@Keith, I am afraid you may be right about your answer. I am truly stunned that Microsoft screwed this up so badly. Does anyone have any ideas for a workaround?</p> <hr> <p>@Mladen Mihajlovic - that's exactly the situation I'm describing. Try it out yourself; project references don't make a shred of difference.</p>
[ { "answer_id": 21877038, "author": "Giulio Caccin", "author_id": 1636173, "author_profile": "https://Stackoverflow.com/users/1636173", "pm_score": 0, "selected": false, "text": "ctrl+, F12" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7850/" ]
63,546
<p>Would like to programmically change the connecton string for a database which utilizes the membership provider of asp.net within a windows application. The system.configuration namespace allows changes to the user settings, however, we would like to adjust a application setting? Does one need to write a class with utilizes XML to modify the class? Does one need to delete the current connections (can one select a connection to clear) and add a new one? Can one adjust the existing connection string?</p>
[ { "answer_id": 63579, "author": "Joseph Daigle", "author_id": 507, "author_profile": "https://Stackoverflow.com/users/507", "pm_score": 3, "selected": false, "text": "Configuration myConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); myConfig.ConnectionStrings.ConnectionStrings .Save()" }, { "answer_id": 63674, "author": "dpollock", "author_id": 7884, "author_profile": "https://Stackoverflow.com/users/7884", "pm_score": 3, "selected": false, "text": "// Get the application configuration file.\nSystem.Configuration.Configuration config =\n ConfigurationManager.OpenExeConfiguration(\n ConfigurationUserLevel.None);\n\n// Create a connection string element and\n// save it to the configuration file.\n\n// Create a connection string element.\nConnectionStringSettings csSettings =\n new ConnectionStringSettings(\"My Connection\",\n \"LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;\" +\n \"Initial Catalog=aspnetdb\", \"System.Data.SqlClient\");\n\n// Get the connection strings section.\nConnectionStringsSection csSection =\n config.ConnectionStrings;\n\n// Add the new element.\ncsSection.ConnectionStrings.Add(csSettings);\n\n// Save the configuration file.\nconfig.Save(ConfigurationSaveMode.Modified);\n" }, { "answer_id": 8796298, "author": "Bradley Mountford", "author_id": 302103, "author_profile": "https://Stackoverflow.com/users/302103", "pm_score": 3, "selected": false, "text": "var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);\nvar connectionStringsSection = (ConnectionStringsSection)config.GetSection(\"connectionStrings\");\nconnectionStringsSection.ConnectionStrings[\"Blah\"].ConnectionString = \"Data Source=blah;Initial Catalog=blah;UID=blah;password=blah\";\nconfig.Save();\nConfigurationManager.RefreshSection(\"connectionStrings\");\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63546", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7950/" ]
63,556
<p>I have a class with a bunch of properties that look like this:</p> <pre><code>public string Name { get { return _name; } set { IsDirty = true; _name = value; } } </code></pre> <p>It would be a lot easier if I could rely on C# 3.0 to generate the backing store for these, but is there any way to factor out the IsDirty=true; so that I can write my properties something like this and still get the same behaviour:</p> <pre><code>[MakesDirty] public string Name { get; set; } </code></pre>
[ { "answer_id": 63623, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "class A\n{\n [Foo]\n public int Property1{get; set;}\n public int Property2{get {return variable;} set{ Property1 = value; variable = value; }\n}\n" }, { "answer_id": 63628, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 4, "selected": true, "text": "set\n{ \n _name = value; \n NotifyPropertyChanged(\"Name\"); \n}\n" }, { "answer_id": 63677, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 2, "selected": false, "text": "<T private void SetValue<T>(ref T backingField, T value)\n{\n if (backingField != value)\n {\n backingField = value;\n IsDirty = true;\n }\n}\n\npublic string Name\n{\n get\n {\n return _name;\n }\n set\n {\n SetValue(ref _name, value);\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1404/" ]
63,581
<p>I'm using <a href="http://www.c6software.com/Products/PopBox/" rel="nofollow noreferrer">PopBox</a> for magnifying thumbnails on my page. But I want my website to work even for users which turned javascript off.</p> <p>I tried to use the following HTML code:</p> <pre><code>&lt;a href="image.jpg"&gt; &lt;img src="thumbnail.jpg" pbsrc="image.jpg" onclick="Pop(...);"/&gt; &lt;/a&gt; </code></pre> <p>Now i need to disable the a-Tag using javascript, otherwise my PopBox won't work.</p> <p>How do I do that?</p>
[ { "answer_id": 63626, "author": "Chris Shaffer", "author_id": 6744, "author_profile": "https://Stackoverflow.com/users/6744", "pm_score": 3, "selected": true, "text": "<a href=\"image.jpg onclick=\"Pop()\"; return false;\"><img ...></a>\n false Pop <a>" }, { "answer_id": 63638, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 1, "selected": false, "text": "var anchors=$$('a.simple')\n" }, { "answer_id": 538993, "author": "system PAUSE", "author_id": 52963, "author_profile": "https://Stackoverflow.com/users/52963", "pm_score": 0, "selected": false, "text": "href <a> <a id=\"apic001\" href=\"pic001.png\"><img src=\"tn_pic001.png\"></a>\n\n <script type=\"text/javascript\">\n document.getElementById(\"apic001\").removeAttribute(\"href\");\n </script>\n onclick http://whatever/gallery.html#apic001 name=\"apic001\"" }, { "answer_id": 814735, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<a href=\"image.jpg\" onclick=\"return false;\">\n <img src=\"thumbnail.jpg\" pbsrc=\"image.jpg\" onclick=\"Pop(...);\">\n</a>\n <a>" }, { "answer_id": 2995911, "author": "Igor Zinov'yev", "author_id": 123564, "author_profile": "https://Stackoverflow.com/users/123564", "pm_score": 1, "selected": false, "text": "<div id=\"photo-container\">\n <a href=\"image1.jpg\">\n <img class=\"popup-image\" src=\"thumbnail1.jpg\" pbsrc=\"image1.jpg\" />\n </a>\n <a href=\"image2.jpg\">\n <img class=\"popup-image\" src=\"thumbnail2.jpg\" pbsrc=\"image2.jpg\" />\n </a>\n <a href=\"image3.jpg\">\n <img class=\"popup-image\" src=\"thumbnail3.jpg\" pbsrc=\"image3.jpg\"/>\n </a>\n</div>\n <script type=\"text/javascript\">\n$(document).ready(function(){\n var container = $('#photo-container');\n\n // let's bind our event handler\n container.bind('click', function(event){\n // thus we find (if any) the image the user has clicked on\n var target = $(event.target).closest('img.popup-image');\n\n // If the user has not hit any image, we do not handle the click\n if (!target.length) return;\n\n event.preventDefault(); // instead of return false;\n\n // And here you can do what you want to your image\n // which you can get from target\n Pop(target.get(0));\n });\n});\n</script>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4186/" ]
63,599
<p>We have an issue using the <code>PEAR</code> libraries on <code>Windows</code> from <code>PHP</code>.</p> <p>Pear contains many classes, we are making use of a fair few, one of which is the Mail class found in <code>Mail.php</code>. We use PEAR on the path, rather than providing the full explicit path to individual PEAR files:</p> <pre><code>require_once('Mail.php'); </code></pre> <p>Rather than:</p> <pre><code>require_once('/path/to/pear/Mail.php'); </code></pre> <p>This causes issues in the administration module of the site, where there is a <code>mail.php</code> file (used to send mails to users). If we are in an administrative screen that sends an email (such as the user administration screen that can generate and email new random passwords to users when they are approved from the moderation queue) and we attempt to include <code>Mail.php</code> we "accidentally" include mail.php.</p> <p>Without changing to prepend the full path to the PEAR install explicitly requiring the PEAR modules (non-standard, typically you install PEAR to your path...) is there a way to enforce PHP on Windows to require files case-sensitively?</p> <p>We are adding the PEAR path to the include path ourselves, so have control over the path order. We also recognize that we should avoid using filenames that clash with PEAR names regardless of case, and in the future will do so. This page however (which is not an include file, but a controller), has been in the repository for some years, and plugins specifically generate URLS to provide links/redirects to this page in their processing.</p> <blockquote> <p>(We support Apache, Microsoft IIS, LightHTTPD and Zeus, using PHP 4.3 or later (including PHP5))</p> </blockquote>
[ { "answer_id": 63627, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 2, "selected": false, "text": "include('Mail.php'); include('./Mail.php');" }, { "answer_id": 65937, "author": "farzad", "author_id": 9394, "author_profile": "https://Stackoverflow.com/users/9394", "pm_score": 2, "selected": true, "text": "<?php\n $path_to_pear = '/usr/share/php/pear';\n set_include_path( $path_to_pear . PATH_SEPARATOR . get_include_path() );\n?>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63599", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7106/" ]
63,618
<p>Shoes has some built in dump commands (Shoes.debug), but are there other tools that can debug the code without injecting debug messages throughout? Something like gdb would be great.</p>
[ { "answer_id": 63923, "author": "Brian Phillips", "author_id": 7230, "author_profile": "https://Stackoverflow.com/users/7230", "pm_score": 1, "selected": false, "text": "\n% sudo gem install ruby-debug\n \nclass Foo\n require 'ruby-debug'\n def some_method_somewhere\n debugger # acts like a breakpoint is set at this point\n end\nend\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7936/" ]
63,671
<p>I seem to remember reading something about how it is bad for structs to implement interfaces in CLR via C#, but I can't seem to find anything about it. Is it bad? Are there unintended consequences of doing so?</p> <pre><code>public interface Foo { Bar GetBar(); } public struct Fubar : Foo { public Bar GetBar() { return new Bar(); } } </code></pre>
[ { "answer_id": 63711, "author": "Joseph Daigle", "author_id": 507, "author_profile": "https://Stackoverflow.com/users/507", "pm_score": 0, "selected": false, "text": "IComparable IFormattable" }, { "answer_id": 1289537, "author": "ShuggyCoUk", "author_id": 12748, "author_profile": "https://Stackoverflow.com/users/12748", "pm_score": 8, "selected": false, "text": "class Foo<T> : IEquatable<Foo<T>> where T : IEquatable<T>\n{\n private readonly T a;\n\n public bool Equals(Foo<T> other)\n {\n return this.a.Equals(other.a);\n }\n}\n new() class Equals() Equals() IEquatable<T> IEquatable<T> T IComparable IConvertible IComparable<T> IEquatable<T> IEquatable IFormattable ICollection Add() IFormattable List<int> l = new List<int>();\nforeach(var x in l)\n ;//no-op\n IDisposable Dispose()" }, { "answer_id": 14322574, "author": "supercat", "author_id": 363751, "author_profile": "https://Stackoverflow.com/users/363751", "pm_score": 3, "selected": false, "text": "IEquatable<T> IEquatable<T> CompareTwoThings<T>(T thing1, T thing2) where T:IComparable<T> thing1.Compare(thing2) thing1 thing2 thing1 Int32 CompareTwoThings<Int32>(Int32 thing1, Int32 thing2) Object ValueType IEnumerator<T> List<String> myList = [list containing a bunch of strings]\nvar enumerator1 = myList.GetEnumerator(); // Struct of type List<String>.IEnumerator\nenumerator1.MoveNext(); // 1\nvar enumerator2 = enumerator1;\nenumerator2.MoveNext(); // 2\nIEnumerator<string> enumerator3 = enumerator2;\nenumerator3.MoveNext(); // 3\nIEnumerator<string> enumerator4 = enumerator3;\nenumerator4.MoveNext(); // 4\n enumerator1 enumerator2 enumerator1 enumerator3 enumerator3 enumerator4 enumerator3 enumerator4 enumerator3 enumerator4 Object Object List<String>.Enumerator IEnumerator<String> Object Equals ValueType System.Enum ValueType System.Enum ValueType System.Enum" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,687
<p>I would like to save the programs settings every time the user exits the program. So I need a way to call a function when the user quits the program. How do I do that?</p> <p>I am using Java 1.5.</p>
[ { "answer_id": 63701, "author": "Mat Mannion", "author_id": 6282, "author_profile": "https://Stackoverflow.com/users/6282", "pm_score": 6, "selected": true, "text": "Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {\n public void run() {\n // what you want to do\n }\n}));\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,690
<p>I work with embedded Linux systems that sometimes want to get their IP address from a DHCP server. The DHCP Client client we use (<a href="http://www.phystech.com/download/dhcpcd.html" rel="nofollow noreferrer" title="DHCPCD">dhcpcd</a>) has limited retry logic. If our device starts up without any DHCP server available and times out, dhcpcd will exit and the device will never get an IP address until it's rebooted with a DHCP server visible/connected. I can't be the only one that has this problem. The problem doesn't even seem to be specific to embedded systems (though it's worse there). How do you handle this? Is there a more robust client available? </p>
[ { "answer_id": 64746, "author": "jpbarto", "author_id": 8511, "author_profile": "https://Stackoverflow.com/users/8511", "pm_score": 1, "selected": false, "text": "rc.local" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7685/" ]
63,694
<p>Is there any feasible way of using generics to create a Math library that does not depend on the base type chosen to store data?</p> <p>In other words, let's assume I want to write a Fraction class. The fraction can be represented by two ints or two doubles or whatnot. The important thing is that the basic four arithmetic operations are well defined. So, I would like to be able to write <code>Fraction&lt;int&gt; frac = new Fraction&lt;int&gt;(1,2)</code> and/or <code>Fraction&lt;double&gt; frac = new Fraction&lt;double&gt;(0.1, 1.0)</code>.</p> <p>Unfortunately there is no interface representing the four basic operations (+,-,*,/). Has anybody found a workable, feasible way of implementing this?</p>
[ { "answer_id": 64142, "author": "fryguybob", "author_id": 4592, "author_profile": "https://Stackoverflow.com/users/4592", "pm_score": 6, "selected": true, "text": " abstract class MathProvider<T>\n {\n public abstract T Divide(T a, T b);\n public abstract T Multiply(T a, T b);\n public abstract T Add(T a, T b);\n public abstract T Negate(T a);\n public virtual T Subtract(T a, T b)\n {\n return Add(a, Negate(b));\n }\n }\n\n class DoubleMathProvider : MathProvider<double>\n {\n public override double Divide(double a, double b)\n {\n return a / b;\n }\n\n public override double Multiply(double a, double b)\n {\n return a * b;\n }\n\n public override double Add(double a, double b)\n {\n return a + b;\n }\n\n public override double Negate(double a)\n {\n return -a;\n }\n }\n\n class IntMathProvider : MathProvider<int>\n {\n public override int Divide(int a, int b)\n {\n return a / b;\n }\n\n public override int Multiply(int a, int b)\n {\n return a * b;\n }\n\n public override int Add(int a, int b)\n {\n return a + b;\n }\n\n public override int Negate(int a)\n {\n return -a;\n }\n }\n\n class Fraction<T>\n {\n static MathProvider<T> _math;\n // Notice this is a type constructor. It gets run the first time a\n // variable of a specific type is declared for use.\n // Having _math static reduces overhead.\n static Fraction()\n {\n // This part of the code might be cleaner by once\n // using reflection and finding all the implementors of\n // MathProvider and assigning the instance by the one that\n // matches T.\n if (typeof(T) == typeof(double))\n _math = new DoubleMathProvider() as MathProvider<T>;\n else if (typeof(T) == typeof(int))\n _math = new IntMathProvider() as MathProvider<T>;\n // ... assign other options here.\n\n if (_math == null)\n throw new InvalidOperationException(\n \"Type \" + typeof(T).ToString() + \" is not supported by Fraction.\");\n }\n\n // Immutable impementations are better.\n public T Numerator { get; private set; }\n public T Denominator { get; private set; }\n\n public Fraction(T numerator, T denominator)\n {\n // We would want this to be reduced to simpilest terms.\n // For that we would need GCD, abs, and remainder operations\n // defined for each math provider.\n Numerator = numerator;\n Denominator = denominator;\n }\n\n public static Fraction<T> operator +(Fraction<T> a, Fraction<T> b)\n {\n return new Fraction<T>(\n _math.Add(\n _math.Multiply(a.Numerator, b.Denominator),\n _math.Multiply(b.Numerator, a.Denominator)),\n _math.Multiply(a.Denominator, b.Denominator));\n }\n\n public static Fraction<T> operator -(Fraction<T> a, Fraction<T> b)\n {\n return new Fraction<T>(\n _math.Subtract(\n _math.Multiply(a.Numerator, b.Denominator),\n _math.Multiply(b.Numerator, a.Denominator)),\n _math.Multiply(a.Denominator, b.Denominator));\n }\n\n public static Fraction<T> operator /(Fraction<T> a, Fraction<T> b)\n {\n return new Fraction<T>(\n _math.Multiply(a.Numerator, b.Denominator),\n _math.Multiply(a.Denominator, b.Numerator));\n }\n\n // ... other operators would follow.\n }\n MathProvider<T> Fraction<T>" }, { "answer_id": 65107700, "author": "Mike Marynowski", "author_id": 612510, "author_profile": "https://Stackoverflow.com/users/612510", "pm_score": 1, "selected": false, "text": "[MethodImpl(MethodImplOptions.AggressiveInlining)]\npublic static T IncrementToMax(T value)\n{\n if (typeof(T) == typeof(char))\n return (char)(object)value! < char.MaxValue ? (T)(object)(char)((char)(object)value + 1) : value;\n \n if (typeof(T) == typeof(byte))\n return (byte)(object)value! < byte.MaxValue ? (T)(object)(byte)((byte)(object)value + 1) : value;\n\n // ...rest of the types\n}\n" }, { "answer_id": 74468046, "author": "Guru Stron", "author_id": 2501279, "author_profile": "https://Stackoverflow.com/users/2501279", "pm_score": 0, "selected": false, "text": "static abstract class Fraction<T> :\n IAdditionOperators<Fraction<T>, Fraction<T>, Fraction<T>>,\n ISubtractionOperators<Fraction<T>, Fraction<T>, Fraction<T>>,\n IDivisionOperators<Fraction<T>, Fraction<T>, Fraction<T>>\n where T : INumber<T>\n{\n public T Numerator { get; }\n public T Denominator { get; }\n\n public Fraction(T numerator, T denominator)\n {\n Numerator = numerator;\n Denominator = denominator;\n }\n\n public static Fraction<T> operator +(Fraction<T> left, Fraction<T> right) =>\n new(left.Numerator * right.Denominator + right.Numerator * left.Denominator,\n left.Denominator * right.Denominator);\n\n public static Fraction<T> operator -(Fraction<T> left, Fraction<T> right) =>\n new(left.Numerator * right.Denominator - right.Numerator * left.Denominator,\n left.Denominator * right.Denominator);\n\n public static Fraction<T> operator /(Fraction<T> left, Fraction<T> right) =>\n new(left.Numerator * right.Denominator, left.Denominator * right.Numerator);\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7028/" ]
63,723
<p>Is there a way I can configure the MidPointRounding enumeration default setting in a config file (I.e. web.config or app.config) I have a considerable source code base, and I need to configure at the application scope how rounding will occur, whether used in Math.Round or decimal type rounding... I would like to do this in order to get consistent rounding results throughout the application without changing every line that works with a decimal type or uses Math.Round....</p>
[ { "answer_id": 64271, "author": "rohancragg", "author_id": 5351, "author_profile": "https://Stackoverflow.com/users/5351", "pm_score": 0, "selected": false, "text": "MyEnum GetEnumValue(string enumString) {\n return (MyEnum)Enum.Parse(typeof(MyEnum),enumString);\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63723", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,741
<p>Why does the default IntelliJ default class javadoc comment use non-standard syntax? Instead of creating a line with "User: jstauffer" it could create a line with "@author jstauffer". The other lines that it creates (Date and Time) probably don't have javadoc syntax to use but why not use the javadoc syntax when available?</p> <p>For reference here is an example:</p> <pre>/** * Created by IntelliJ IDEA. * User: jstauffer * Date: Nov 13, 2007 * Time: 11:15:10 AM * To change this template use File | Settings | File Templates. */</pre>
[ { "answer_id": 63922, "author": "Rob Dickerson", "author_id": 7530, "author_profile": "https://Stackoverflow.com/users/7530", "pm_score": 6, "selected": false, "text": "@author File -> Settings -> File Templates File Header Includes File -> Settings -> Editor -> File and Code Templates -> Includes -> File Header" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6770/" ]
63,743
<p>I am developing a web page code, which fetches dynamically the content from the server and then places this content to container nodes using something like</p> <pre><code>container.innerHTML = content; </code></pre> <p>Sometimes I have to overwrite some previous content in this node. This works fine, until it happens that previous content occupied more vertical space then a new one would occupy AND a user scrolled the page down -- scrolled more than new content would allow, provided its height.</p> <p>In this case the page redraws incorrectly -- some artifacts of the old content remain. It works fine, and it is even possible to get rid of artifacts, by minimizing and restoring the browser (or force the window to be redrawn in an other way), however this does not seem very convenient.</p> <p>I am testing this only under Safari (this is a iPhone-optimized website).</p> <p>Does anybody have the idea how to deal with this?</p>
[ { "answer_id": 63811, "author": "palehorse", "author_id": 312, "author_profile": "https://Stackoverflow.com/users/312", "pm_score": 0, "selected": false, "text": "$('#container').html( content );\n" }, { "answer_id": 65912, "author": "Scott Swezey", "author_id": 9439, "author_profile": "https://Stackoverflow.com/users/9439", "pm_score": 3, "selected": true, "text": "<a> div <a name=\"ajax-div\"></a>\n div location.hash = 'ajax-div';\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3894/" ]
63,748
<p>I want to implement in Java a class for handling graph data structures. I have a Node class and an Edge class. The Graph class maintains two list: a list of nodes and a list of edges. Each node must have an unique name. How do I guard against a situation like this: </p> <pre><code>Graph g = new Graph(); Node n1 = new Node("#1"); Node n2 = new Node("#2"); Edge e1 = new Edge("e#1", "#1", "#2"); // Each node is added like a reference g.addNode(n1); g.addNode(n2); g.addEdge(e1); // This will break the internal integrity of the graph n1.setName("#3"); g.getNode("#2").setName("#4"); </code></pre> <p></p> <p>I believe I should clone the nodes and the edges when adding them to the graph and return a NodeEnvelope class that will maintain the graph structural integrity. Is this the right way of doing this or the design is broken from the beginning ?</p>
[ { "answer_id": 63795, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 1, "selected": false, "text": "Node" }, { "answer_id": 63846, "author": "Jim Kiley", "author_id": 7178, "author_profile": "https://Stackoverflow.com/users/7178", "pm_score": 2, "selected": false, "text": "public Edge(String, Node, Node) public Edge (String, String, String) IllegalOperationException" }, { "answer_id": 64847, "author": "Rob Dickerson", "author_id": 7530, "author_profile": "https://Stackoverflow.com/users/7530", "pm_score": 3, "selected": true, "text": "public final class Node {\n\n private final String name;\n\n public Node(String name) {\n this.name = name;\n }\n\n public String getName() { return name; }\n // note: no setter for name\n}\n public class Graph {\n Set<Node> nodes = new HashSet<Node>();\n public void addNode(Node n) {\n // note: this assumes you've properly overridden \n // equals and hashCode in Node to make Nodes with the \n // same name .equal() and hash to the same value.\n if(nodes.contains(n)) {\n throw new IllegalArgumentException(\"Already in graph: \" + node);\n }\n nodes.add(n);\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3885/" ]
63,752
<p>Semantically speaking, is there an appropriate place in today's websites (late 2008+) where using the bold <code>&lt;b&gt;</code> and italic <code>&lt;i&gt;</code> tags are more useful than the more widely used <code>&lt;strong&gt;</code> and <code>&lt;em&gt;</code> tags?</p>
[ { "answer_id": 63761, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 3, "selected": false, "text": "SPAN" }, { "answer_id": 63821, "author": "Chris Broadfoot", "author_id": 3947, "author_profile": "https://Stackoverflow.com/users/3947", "pm_score": 3, "selected": false, "text": "b i strong em b i b i stack<b>overflow</b> stack<span class=\"overflow-logo\">overflow</span> b b em" }, { "answer_id": 63913, "author": "Daniel Stockman", "author_id": 5707, "author_profile": "https://Stackoverflow.com/users/5707", "pm_score": 3, "selected": false, "text": "<b> <i> <em> <strong>" }, { "answer_id": 63962, "author": "Nathan Chase", "author_id": 8086, "author_profile": "https://Stackoverflow.com/users/8086", "pm_score": 2, "selected": false, "text": "<strong> <em> <b> <i> <strong> <em>" }, { "answer_id": 64005, "author": "Charles Roper", "author_id": 1944, "author_profile": "https://Stackoverflow.com/users/1944", "pm_score": 0, "selected": false, "text": "<i> <em> <span class=\"sci-name\"> <i>" }, { "answer_id": 27996049, "author": "unor", "author_id": 1591669, "author_profile": "https://Stackoverflow.com/users/1591669", "pm_score": 0, "selected": false, "text": "strong b em i b em i strong i strong em b i <b><i>…</i></b>" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8086/" ]
63,755
<p>Does anyone know a good way to do this? I need to have simple forms that submit to email without writing a lot of code. These forms will be hosted in content-viewer web parts or similar in MOSS 2007. I'd like to avoid using InfoPath.</p>
[ { "answer_id": 17395874, "author": "Ricksy", "author_id": 2537442, "author_profile": "https://Stackoverflow.com/users/2537442", "pm_score": 0, "selected": false, "text": "text boxes text areas select drop downs" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8033/" ]
63,758
<p>I have a Java application that launches another java application. The launcher has a watchdog timer and receives periodic notifications from the second VM. However, if no notifications are received then the second virtual machine should be killed and the launcher will perform some additional clean-up activities.</p> <p>The question is, is there any way to do this using only java? so far I have to use some native methods to perform this operation and it is somehow ugly.</p> <p>Thanks!</p>
[ { "answer_id": 63807, "author": "James A. N. Stauffer", "author_id": 6770, "author_profile": "https://Stackoverflow.com/users/6770", "pm_score": 0, "selected": false, "text": "java.lang.Runtime.exec" }, { "answer_id": 63909, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 4, "selected": true, "text": "destroy() Process Runtime.exec()" }, { "answer_id": 64062, "author": "Sean Reilly", "author_id": 8313, "author_profile": "https://Stackoverflow.com/users/8313", "pm_score": 2, "selected": false, "text": "Process nestedProcess = new ProcessBuilder(\"java mysubprocess\").start();\nInputStream nestedStdOut = nestedProcess.getInputStream(); //kinda backwards, I know\nInputStream nestedStdErr = nestedProcess.getErrorStream();\nwhile (true) {\n /*\n TODO: read from the std out or std err (or get notifications some other way)\n Then put the real \"kill-me\" logic here instead of if (false)\n */\n if (false) {\n nestedProcess.destroy();\n //perform post-destruction cleanup here\n return;\n }\n\n Thread.currentThread().sleep(1000L); //wait for a bit\n}\n" }, { "answer_id": 64114, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "java.lang.Process waitFor() destroy()" }, { "answer_id": 81137, "author": "Rob", "author_id": 15317, "author_profile": "https://Stackoverflow.com/users/15317", "pm_score": 2, "selected": false, "text": "Process.destroy()" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2309/" ]
63,764
<p>How can I find what databases I have a minimum of read access to in either basic SQL, MySQL specific or in PHP?</p>
[ { "answer_id": 63869, "author": "Jay Shepherd", "author_id": 7511, "author_profile": "https://Stackoverflow.com/users/7511", "pm_score": 1, "selected": false, "text": "SHOW DATABASES; SHOW DATABASES;" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
63,771
<p>As I build *nix piped commands I find that I want to see the output of one stage to verify correctness before building the next stage but I don't want to re-run each stage. Does anyone know of a program that will help with that? It would keep the output of the last stage automatically to use for any new stages. I usually do this by sending the result of each command to a temporary file (i.e. tee or run each command one at a time) but it would be nice for a program to handle this.</p> <p>I envision something like a tabbed interface where each tab is labeled with each pipe command and selecting a tab shows the output (at least a hundred lines) of applying that command to to the previous result.</p>
[ { "answer_id": 63783, "author": "pjz", "author_id": 8002, "author_profile": "https://Stackoverflow.com/users/8002", "pm_score": 3, "selected": false, "text": "cat /var/log/syslog | tee /tmp/syslog.out | grep something | tee /tmp/grep.out | sed 's/foo/bar/g' | tee /tmp/sed.out | cat >>/var/log/syslog.cleaned\n" }, { "answer_id": 63803, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "tee ls | tee /tmp/out1 | sort | tee /tmp/out2 | sed 's/foo/bar/g'\n" }, { "answer_id": 63838, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "mknod backpipe p\nnc -l -p 80 0<backpipe | tee -a inflow | nc localhost 81 | tee -a outflow 1>backpipe\n" }, { "answer_id": 63877, "author": "GodEater", "author_id": 6756, "author_profile": "https://Stackoverflow.com/users/6756", "pm_score": 1, "selected": false, "text": " cat file | pv -s 12345 | nc -w 1 somewhere.com 3000\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6770/" ]
63,776
<p>Given an integer typedef:</p> <pre><code>typedef unsigned int TYPE; </code></pre> <p>or</p> <pre><code>typedef unsigned long TYPE; </code></pre> <p>I have the following code to reverse the bits of an integer:</p> <pre><code>TYPE max_bit= (TYPE)-1; void reverse_int_setup() { TYPE bits= (TYPE)max_bit; while (bits &lt;&lt;= 1) max_bit= bits; } TYPE reverse_int(TYPE arg) { TYPE bit_setter= 1, bit_tester= max_bit, result= 0; for (result= 0; bit_tester; bit_tester&gt;&gt;= 1, bit_setter&lt;&lt;= 1) if (arg &amp; bit_tester) result|= bit_setter; return result; } </code></pre> <p>One just needs first to run reverse_int_setup(), which stores an integer with the highest bit turned on, then any call to reverse_int(<em>arg</em>) returns <em>arg</em> with its bits reversed (to be used as a key to a binary tree, taken from an increasing counter, but that's more or less irrelevant).</p> <p>Is there a platform-agnostic way to have in compile-time the correct value for max_int after the call to reverse_int_setup(); Otherwise, is there an algorithm you consider <em>better/leaner</em> than the one I have for reverse_int()?</p> <p>Thanks.</p>
[ { "answer_id": 63854, "author": "TK.", "author_id": 1816, "author_profile": "https://Stackoverflow.com/users/1816", "pm_score": 0, "selected": false, "text": "long temp = 0;\nint counter = 0;\nint number_of_bits = sizeof(value) * 8; // get the number of bits that represent value (assuming that it is aligned to a byte boundary)\n\nwhile(value > 0) // loop until value is empty\n{\n temp <<= 1; // shift whatever was in temp left to create room for the next bit\n temp |= (value & 0x01); // get the lsb from value and set as lsb in temp\n value >>= 1; // shift value right by one to look at next lsb\n\n counter++;\n}\n\nvalue = temp;\n\nif (counter < number_of_bits)\n{\n value <<= counter-number_of_bits;\n}\n while(value)\n" }, { "answer_id": 64626, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 3, "selected": false, "text": "#include <stdio.h>\n#include <stdint.h>\nint main(int argc, char**argv)\n{\n int32_t x;\n if ( argc != 2 ) \n {\n printf(\"Usage: %s hexadecimal\\n\", argv[0]);\n return 1;\n }\n\n sscanf(argv[1],\"%x\", &x);\n /* swap every neigbouring bit */\n x = (x&0xAAAAAAAA)>>1 | (x&0x55555555)<<1;\n /* swap every 2 neighbouring bits */\n x = (x&0xCCCCCCCC)>>2 | (x&0x33333333)<<2;\n /* swap every 4 neighbouring bits */\n x = (x&0xF0F0F0F0)>>4 | (x&0x0F0F0F0F)<<4;\n /* swap every 8 neighbouring bits */\n x = (x&0xFF00FF00)>>8 | (x&0x00FF00FF)<<8;\n /* and so forth, for say, 32 bit int */\n x = (x&0xFFFF0000)>>16 | (x&0x0000FFFF)<<16;\n printf(\"0x%x\\n\",x);\n return 0;\n}\n" }, { "answer_id": 64949, "author": "Sundar R", "author_id": 8127, "author_profile": "https://Stackoverflow.com/users/8127", "pm_score": 2, "selected": false, "text": "typedef unsigned long TYPE;\n\nTYPE reverser(TYPE n)\n{\n TYPE k = 1, nrev = 0, i, nrevbit1, nrevbit2;\n int count;\n\n for(i = 0; !i || (1 << i && (1 << i) != 1); i+=2)\n {\n /*In each iteration, we swap one bit \n on the 'right half' of the number with another \n on the left half*/\n\n k = 1<<i; /*this is used to find how many positions \n to the left (or right, for the other bit) \n we gotta move the bits in this iteration*/\n\n count = 0;\n\n while(k << 1 && k << 1 != 1)\n {\n k <<= 1;\n count++;\n }\n\n nrevbit1 = n & (1<<(i/2));\n nrevbit1 <<= count;\n\n nrevbit2 = n & 1<<((i/2) + count);\n nrevbit2 >>= count;\n\n nrev |= nrevbit1;\n nrev |= nrevbit2;\n }\n return nrev;\n}\n" }, { "answer_id": 70906, "author": "Sundar R", "author_id": 8127, "author_profile": "https://Stackoverflow.com/users/8127", "pm_score": 4, "selected": true, "text": "#include<stdio.h>\n#include<limits.h>\n\n#define TYPE_BITS sizeof(TYPE)*CHAR_BIT\n\ntypedef unsigned long TYPE;\n\nTYPE reverser(TYPE n)\n{\n TYPE nrev = 0, i, bit1, bit2;\n int count;\n\n for(i = 0; i < TYPE_BITS; i += 2)\n {\n /*In each iteration, we swap one bit on the 'right half' \n of the number with another on the left half*/\n\n count = TYPE_BITS - i - 1; /*this is used to find how many positions \n to the left (and right) we gotta move \n the bits in this iteration*/\n\n bit1 = n & (1<<(i/2)); /*Extract 'right half' bit*/\n bit1 <<= count; /*Shift it to where it belongs*/\n\n bit2 = n & 1<<((i/2) + count); /*Find the 'left half' bit*/\n bit2 >>= count; /*Place that bit in bit1's original position*/\n\n nrev |= bit1; /*Now add the bits to the reversal result*/\n nrev |= bit2;\n }\n return nrev;\n}\n\nint main()\n{\n TYPE n = 6;\n\n printf(\"%lu\", reverser(n));\n return 0;\n}\n" }, { "answer_id": 73999, "author": "Frosty", "author_id": 7476, "author_profile": "https://Stackoverflow.com/users/7476", "pm_score": 0, "selected": false, "text": "typedef unsigned long TYPE;\n#define TYPE_BITS sizeof(TYPE)*8\n\nTYPE reverser(TYPE t)\n{\n unsigned int i;\n TYPE return_val = 0\n for(i = 0; i < TYPE_BITS; i++)\n {/*foreach bit in TYPE*/\n /* shift the value of return_val to the left and add the rightmost bit from t */\n return_val = (return_val << 1) + (t & 1);\n /* shift off the rightmost bit of t */\n t = t >> 1;\n }\n return(return_val);\n}\n" }, { "answer_id": 74332, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 1, "selected": false, "text": "#include <stdio.h>\n#include <stdint.h>\ntypedef int32_t TYPE;\nTYPE reverse(TYPE x, int bits)\n{\n TYPE m=~0;\n switch(bits)\n {\n case 64:\n x = (x&0xFFFFFFFF00000000&m)>>16 | (x&0x00000000FFFFFFFF&m)<<16;\n case 32:\n x = (x&0xFFFF0000FFFF0000&m)>>16 | (x&0x0000FFFF0000FFFF&m)<<16;\n case 16:\n x = (x&0xFF00FF00FF00FF00&m)>>8 | (x&0x00FF00FF00FF00FF&m)<<8;\n case 8:\n x = (x&0xF0F0F0F0F0F0F0F0&m)>>4 | (x&0x0F0F0F0F0F0F0F0F&m)<<4;\n x = (x&0xCCCCCCCCCCCCCCCC&m)>>2 | (x&0x3333333333333333&m)<<2;\n x = (x&0xAAAAAAAAAAAAAAAA&m)>>1 | (x&0x5555555555555555&m)<<1;\n }\n return x;\n}\n\nint main(int argc, char**argv)\n{\n TYPE x;\n TYPE b = (TYPE)-1;\n int bits;\n if ( argc != 2 ) \n {\n printf(\"Usage: %s hexadecimal\\n\", argv[0]);\n return 1;\n }\n for(bits=1;b;b<<=1,bits++);\n --bits;\n printf(\"TYPE has %d bits\\n\", bits);\n sscanf(argv[1],\"%x\", &x);\n\n printf(\"0x%x\\n\",reverse(x, bits));\n return 0;\n}\n" }, { "answer_id": 1845062, "author": "The Neocompressionist", "author_id": 224525, "author_profile": "https://Stackoverflow.com/users/224525", "pm_score": 1, "selected": false, "text": "const unsigned char table[] = { \n0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, \n0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, \n0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, \n0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC, \n0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2, \n0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA, \n0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6, \n0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE, \n0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1, \n0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9, \n0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5, \n0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD, \n0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, \n0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, \n0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, \n0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF}; \n\n\nconst unsigned short masks[17] = \n{0,0,0,0,0,0,0,0,0,0X0100,0X0300,0X0700,0X0F00,0X1F00,0X3F00,0X7F00,0XFF00}; \n\n\nunsigned long codeword; // value to be reversed, occupying the low 1-24 bits \nunsigned char maxLength; // bit length of longest possible codeword (<= 24) \nunsigned char sc; // shift count in bits and index into masks array \n\n\nif (maxLength <= 8) \n{ \n codeword = table[codeword << (8 - maxLength)]; \n} \nelse \n{ \n sc = maxLength - 8; \n\n if (maxLength <= 16) \n {\n codeword = (table[codeword & 0X00FF] << sc) \n | table[codeword >> sc]; \n } \n else if (maxLength & 1) // if maxLength is 17, 19, 21, or 23 \n { \n codeword = (table[codeword & 0X00FF] << sc) \n | table[codeword >> sc] | \n (table[(codeword & masks[sc]) >> (sc - 8)] << 8); \n } \n else // if maxlength is 18, 20, 22, or 24 \n { \n codeword = (table[codeword & 0X00FF] << sc) \n | table[codeword >> sc] \n | (table[(codeword & masks[sc]) >> (sc >> 1)] << (sc >> 1)); \n } \n} \n" }, { "answer_id": 2489633, "author": "ivan", "author_id": 298718, "author_profile": "https://Stackoverflow.com/users/298718", "pm_score": 0, "selected": false, "text": "int BitReverse[Size]; // Size is power of 2\nvoid Init()\n{\n BitReverse[0] = 0;\n for(int i = 0; i < Size/2; i++)\n {\n BitReverse[2*i] = BitReverse[i]/2;\n BitReverse[2*i+1] = (BitReverse[i] + Size)/2;\n }\n} // end it's all\n" }, { "answer_id": 5036813, "author": "Bernd Jendrissek", "author_id": 117911, "author_profile": "https://Stackoverflow.com/users/117911", "pm_score": 0, "selected": false, "text": "#include <limits.h>\n#include <stdio.h>\n\ntypedef unsigned long foo_t;\n\nfoo_t reverse(foo_t x)\n{\n int shift = sizeof (x) * CHAR_BIT / 2;\n foo_t mask = (1 << shift) - 1;\n int i;\n\n for (i = 0; shift; i++) {\n x = ((x & mask) << shift) | ((x & ~mask) >> shift);\n shift >>= 1;\n mask ^= (mask << shift);\n }\n\n return x;\n} \n\nint main() {\n printf(\"reverse = 0x%08lx\\n\", reverse(0x12345678L));\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6899/" ]
63,800
<p>Does Java impose any extra restrictions of its own. Windows (upto Vista) does not allow names to include</p> <pre><code>\ / &lt; &gt; ? * : </code></pre> <p>I know HOW to validate names (a regular expression).</p> <p>I need to validate filenames entered by users. </p> <p>My application does not need to run on any other platform, though, of course, I would prefer to be platform independent!</p>
[ { "answer_id": 63861, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 2, "selected": false, "text": "File.separator\n" }, { "answer_id": 63963, "author": "Andrew", "author_id": 7613, "author_profile": "https://Stackoverflow.com/users/7613", "pm_score": 0, "selected": false, "text": "new File java.io.FileSystem File.separator" }, { "answer_id": 63993, "author": "Bill Michell", "author_id": 7938, "author_profile": "https://Stackoverflow.com/users/7938", "pm_score": 0, "selected": false, "text": "String Integer.MAX_VALUE String IOException" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8118/" ]
63,805
<p>How do I ask PowerShell where something is? </p> <p>For instance, "which notepad" and it returns the directory where the notepad.exe is run from according to the current paths.</p>
[ { "answer_id": 63831, "author": "Nicholas", "author_id": 8054, "author_profile": "https://Stackoverflow.com/users/8054", "pm_score": 2, "selected": false, "text": "Function Find-Path($Path, [switch]$All = $false, [Microsoft.PowerShell.Commands.TestPathType]$type = \"Any\")\n## You could comment out the function stuff and use it as a script instead, with this line:\n#param($Path, [switch]$All = $false, [Microsoft.PowerShell.Commands.TestPathType]$type = \"Any\")\n if($(Test-Path $Path -Type $type)) {\n return $path\n } else {\n [string[]]$paths = @($pwd);\n $paths += \"$pwd;$env:path\".split(\";\")\n\n $paths = Join-Path $paths $(Split-Path $Path -leaf) | ? { Test-Path $_ -Type $type }\n if($paths.Length -gt 0) {\n if($All) {\n return $paths;\n } else {\n return $paths[0]\n }\n }\n }\n throw \"Couldn't find a matching path of type $type\"\n}\nSet-Alias find Find-Path\n" }, { "answer_id": 63835, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 2, "selected": false, "text": "($Env:Path).Split(\";\") | Get-ChildItem -filter notepad.exe\n" }, { "answer_id": 63891, "author": "David Mohundro", "author_id": 4570, "author_profile": "https://Stackoverflow.com/users/4570", "pm_score": 7, "selected": false, "text": "gcm notepad\n gcm note*\n [27] » gcm note*\n\nCommandType Name Definition\n----------- ---- ----------\nApplication notepad.exe C:\\WINDOWS\\notepad.exe\nApplication notepad.exe C:\\WINDOWS\\system32\\notepad.exe\nApplication Notepad2.exe C:\\Utils\\Notepad2.exe\nApplication Notepad2.ini C:\\Utils\\Notepad2.ini\n" }, { "answer_id": 65148, "author": "halr9000", "author_id": 6637, "author_profile": "https://Stackoverflow.com/users/6637", "pm_score": 10, "selected": true, "text": "New-Alias which get-command\n \"`nNew-Alias which get-command\" | add-content $profile\n" }, { "answer_id": 8484635, "author": "Anonymous", "author_id": 1095069, "author_profile": "https://Stackoverflow.com/users/1095069", "pm_score": 2, "selected": false, "text": "where which" }, { "answer_id": 16949127, "author": "petrsnd", "author_id": 246826, "author_profile": "https://Stackoverflow.com/users/246826", "pm_score": 8, "selected": false, "text": "Get-Command <your command> | Select-Object -ExpandProperty Definition\n PS C:\\> Get-Command notepad.exe | Select-Object -ExpandProperty Definition\nC:\\Windows\\system32\\notepad.exe\n function which($name)\n{\n Get-Command $name | Select-Object -ExpandProperty Definition\n}\n PS C:\\> which notepad\nC:\\Windows\\system32\\notepad.exe\n" }, { "answer_id": 20728713, "author": "Jerome", "author_id": 1503073, "author_profile": "https://Stackoverflow.com/users/1503073", "pm_score": 0, "selected": false, "text": "function Which([string] $cmd) {\n $path = (($Env:Path).Split(\";\") | Select -uniq | Where { $_.Length } | Where { Test-Path $_ } | Get-ChildItem -filter $cmd).FullName\n if ($path) { $path.ToString() }\n}\n\n# Check if Chocolatey is installed\nif (Which('cinst.bat')) {\n Write-Host \"yes\"\n} else {\n Write-Host \"no\"\n}\n function which([string] $cmd) {\n $where = iex $(Join-Path $env:SystemRoot \"System32\\where.exe $cmd 2>&1\")\n $first = $($where -split '[\\r\\n]')\n if ($first.getType().BaseType.Name -eq 'Array') {\n $first = $first[0]\n }\n if (Test-Path $first) {\n $first\n }\n}\n\n# Check if Curl is installed\nif (which('curl')) {\n echo 'yes'\n} else {\n echo 'no'\n}\n" }, { "answer_id": 22776692, "author": "thesqldev", "author_id": 3483572, "author_profile": "https://Stackoverflow.com/users/3483572", "pm_score": 5, "selected": false, "text": "(Get-Command notepad.exe).Path\n" }, { "answer_id": 33754315, "author": "VortiFred", "author_id": 5571459, "author_profile": "https://Stackoverflow.com/users/5571459", "pm_score": 4, "selected": false, "text": "function which($cmd) { get-command $cmd | % { $_.Path } }\n\nPS C:\\> which devcon\n\nC:\\local\\code\\bin\\devcon.exe\n" }, { "answer_id": 43299243, "author": "Chris F Carroll", "author_id": 550314, "author_profile": "https://Stackoverflow.com/users/550314", "pm_score": 3, "selected": false, "text": "which New-Alias which where.exe\n function which {where.exe command | select -first 1}\n" }, { "answer_id": 43354653, "author": "js2010", "author_id": 6654942, "author_profile": "https://Stackoverflow.com/users/6654942", "pm_score": 3, "selected": false, "text": "Get-Command | Format-List powershell.exe gcm powershell | fl\n alias -definition Format-List\n gcm set-psreadlineoption -editmode emacs\n" }, { "answer_id": 49116772, "author": "Jeff Zeitlin", "author_id": 6083222, "author_profile": "https://Stackoverflow.com/users/6083222", "pm_score": 1, "selected": false, "text": "which function which {\n <#\n .SYNOPSIS\n Identifies the source of a PowerShell command.\n .DESCRIPTION\n Identifies the source of a PowerShell command. External commands (Applications) are identified by the path to the executable\n (which must be in the system PATH); cmdlets and functions are identified as such and the name of the module they are defined in\n provided; aliases are expanded and the source of the alias definition is returned.\n .INPUTS\n No inputs; you cannot pipe data to this function.\n .OUTPUTS\n .PARAMETER Name\n The name of the command to be identified.\n .EXAMPLE\n PS C:\\Users\\Smith\\Documents> which Get-Command\n \n Get-Command: Cmdlet in module Microsoft.PowerShell.Core\n \n (Identifies type and source of command)\n .EXAMPLE\n PS C:\\Users\\Smith\\Documents> which notepad\n \n C:\\WINDOWS\\SYSTEM32\\notepad.exe\n \n (Indicates the full path of the executable)\n #>\n param(\n [String]$name\n )\n \n $cmd = Get-Command $name\n $redirect = $null\n switch ($cmd.CommandType) {\n \"Alias\" { \"{0}: Alias for ({1})\" -f $cmd.Name, (. { which $cmd.Definition } ) }\n \"Application\" { $cmd.Source }\n \"Cmdlet\" { \"{0}: {1} {2}\" -f $cmd.Name, $cmd.CommandType, (. { if ($cmd.Source.Length) { \"in module {0}\" -f $cmd.Source} else { \"from unspecified source\" } } ) }\n \"Function\" { \"{0}: {1} {2}\" -f $cmd.Name, $cmd.CommandType, (. { if ($cmd.Source.Length) { \"in module {0}\" -f $cmd.Source} else { \"from unspecified source\" } } ) }\n \"Workflow\" { \"{0}: {1} {2}\" -f $cmd.Name, $cmd.CommandType, (. { if ($cmd.Source.Length) { \"in module {0}\" -f $cmd.Source} else { \"from unspecified source\" } } ) }\n \"ExternalScript\" { $cmd.Source }\n default { $cmd }\n }\n }\n" }, { "answer_id": 62127237, "author": "Amin", "author_id": 7910299, "author_profile": "https://Stackoverflow.com/users/7910299", "pm_score": 2, "selected": false, "text": "function which($name) {\n if ($name) { $input = $name }\n Get-Command $input | Select-Object -ExpandProperty Path\n}\n notepad $profile ❯ echo clang.exe | which\nC:\\Program Files\\LLVM\\bin\\clang.exe\n\n❯ which clang.exe\nC:\\Program Files\\LLVM\\bin\\clang.exe\n" }, { "answer_id": 62995766, "author": "George Ogden", "author_id": 12103577, "author_profile": "https://Stackoverflow.com/users/12103577", "pm_score": 0, "selected": false, "text": "which" }, { "answer_id": 69868490, "author": "blenderfreaky", "author_id": 7869744, "author_profile": "https://Stackoverflow.com/users/7869744", "pm_score": 0, "selected": false, "text": "scoop install which\nwhich notepad\n" }, { "answer_id": 71627691, "author": "rayiik", "author_id": 14073060, "author_profile": "https://Stackoverflow.com/users/14073060", "pm_score": -1, "selected": false, "text": "wsl -e which command \n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1220/" ]
63,870
<p>I have a rather large file (150 million lines of 10 chars). I need to split it in 150 files of 2 million lines, with each output line being alternatively the first 5 characters or the last 5 characters of the source line. I could do this in Perl rather quickly, but I was wondering if there was an easy solution using bash. Any ideas?</p>
[ { "answer_id": 63941, "author": "HD.", "author_id": 6525, "author_profile": "https://Stackoverflow.com/users/6525", "pm_score": 3, "selected": true, "text": "sed 's/\\(.....\\)\\(.....\\)/\\1\\n\\2/' input_file | split -l 2000000 - out-prefix-\n" }, { "answer_id": 63973, "author": "che", "author_id": 7806, "author_profile": "https://Stackoverflow.com/users/7806", "pm_score": 0, "selected": false, "text": "out_file=1\nout_pairs=0\ncat $in_file | while read line; do\n if [ $out_pairs -gt 1000000 ]; then\n out_file=$(($out_file + 1))\n out_pairs=0\n fi\n echo \"${line%?????}\" >> out${out_file}\n echo \"${line#?????}\" >> out${out_file}\n out_pairs=$(($out_pairs + 1))\ndone\n" }, { "answer_id": 72982898, "author": "lacostenycoder", "author_id": 3625433, "author_profile": "https://Stackoverflow.com/users/3625433", "pm_score": 0, "selected": false, "text": "split split -d -l 999999 input_filename\n x00 x01 x02... man split\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7028/" ]
63,881
<p>I have a strange problem with my cake (cake_1.2.0.7296-rc2). My start()-action runs twice, under certain circumstances, even though only one request is made.</p> <p>The triggers seem to be : - loading an object like: <code>$this-&gt;Questionnaire-&gt;read(null, $questionnaire_id);</code> - accessing $this-data </p> <p>If I disable the call to <code>loadAvertisement()</code> from the <code>start()</code>-action, this does not happen. If I disable the two calls inside <code>loadAdvertisement():</code></p> <pre><code>$questionnaire = $this-&gt;Questionnaire-&gt;read(null, $questionnaire_id); $question = $this-&gt;Questionnaire-&gt;Question-&gt;read(null, $question_id); </code></pre> <p>... then it doesn't happen either.</p> <p>Why?</p> <p>See my code below, the Controller is "questionnaires_controller".</p> <pre><code>function checkValidQuestionnaire($id) { $this-&gt;layout = 'questionnaire_frontend_layout'; if (!$id) { $id = $this-&gt;Session-&gt;read('Questionnaire.id'); } if ($id) { $this-&gt;data = $this-&gt;Questionnaire-&gt;read(null, $id); //echo "from ".$questionnaire['Questionnaire']['validFrom']." ".date("y.m.d"); //echo " - to ".$questionnaire['Questionnaire']['validTo']." ".date("y.m.d"); if ($this-&gt;data['Questionnaire']['isPublished'] != 1 //|| $this-&gt;data['Questionnaire']['validTo'] &lt; date("y.m.d") //|| $this-&gt;data['Questionnaire']['validTo'] &lt; date("y.m.d") ) { $id = 0; $this-&gt;flash(__('Ungültiges Quiz. Weiter zum Archiv...', true), array('action'=&gt;'archive')); } } else { $this-&gt;flash(__('Invalid Questionnaire', true), array('action'=&gt;'intro')); } return $id; } function start($id = null) { $this-&gt;log("start"); $id = $this-&gt;checkValidQuestionnaire($id); //$questionnaire = $this-&gt;Questionnaire-&gt;read(null, $id); $this-&gt;set('questionnaire', $this-&gt;data); // reset flow-controlling session vars $this-&gt;Session-&gt;write('Questionnaire',array('id' =&gt; $id)); $this-&gt;Session-&gt;write('Questionnaire'.$id.'currQuestion', null); $this-&gt;Session-&gt;write('Questionnaire'.$id.'lastAnsweredQuestion', null); $this-&gt;Session-&gt;write('Questionnaire'.$id.'correctAnswersNum', null); $this-&gt;loadAdvertisement($id, 0); $this-&gt;Session-&gt;write('Questionnaire'.$id.'previewMode', $this-&gt;params['named']['preview_mode']); if (!$this-&gt;Session-&gt;read('Questionnaire'.$id.'previewMode')) { $questionnaire['Questionnaire']['participiantStartCount']++; $this-&gt;Questionnaire-&gt;save($questionnaire); } } function loadAdvertisement($questionnaire_id, $question_id) { //$questionnaire = array(); $questionnaire = $this-&gt;Questionnaire-&gt;read(null, $questionnaire_id); //$question = array(); $question = $this-&gt;Questionnaire-&gt;Question-&gt;read(null, $question_id); if (isset($question['Question']['advertisement_id']) &amp;&amp; $question['Question']['advertisement_id'] &gt; 0) { $this-&gt;set('advertisement', $this-&gt;Questionnaire-&gt;Question-&gt;Advertisement-&gt;read(null, $question['Question']['advertisement_id'])); } else if (isset($questionnaire['Questionnaire']['advertisement_id']) &amp;&amp; $questionnaire['Questionnaire']['advertisement_id'] &gt; 0) { $this-&gt;set('advertisement', $this-&gt;Questionnaire-&gt;Question-&gt;Advertisement-&gt;read(null, $questionnaire['Questionnaire']['advertisement_id'])); } } </code></pre> <p>I really don't understand this... it don't think it's meant to be this way. Any help would be greatly appreciated! :)</p> <p>Regards, Stu</p>
[ { "answer_id": 12165162, "author": "Aloe", "author_id": 1631160, "author_profile": "https://Stackoverflow.com/users/1631160", "pm_score": 1, "selected": false, "text": "www file_put_contents(\"log-\" . date(\"Hms\") . \".txt\", $this->params['pass'] ); // CakePHP v1.3 \nfile_put_contents(\"log-\" . date(\"Hms\") . \".txt\", $this->request['pass'] ); //CakePHP v2.2.1\n" }, { "answer_id": 28416302, "author": "jtrumbull", "author_id": 3112730, "author_profile": "https://Stackoverflow.com/users/3112730", "pm_score": 0, "selected": false, "text": "<?php\n// other routes..\n$instructions = ['controller'=>'Questionnaires','action'=>'loadAvertisement'];\nRouter::connect('/questionnaires/loadavertisement', $instructions);\nRouter::connect('/QUESTIONNARIES/LOADADVERTISEMENT', $instructions);\n// ..etc\n" }, { "answer_id": 29075468, "author": "gdm", "author_id": 778508, "author_profile": "https://Stackoverflow.com/users/778508", "pm_score": 0, "selected": false, "text": "<something> <something> Error View AppController AppController" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,885
<p>I am trying to create a rather simple effect on a set of images. When an image doesn't have the mouse over it, I'd like it to have a simple, gray border. When it does have an image over it, I'd like it to have a different, "selected", border.</p> <p>The following CSS works great in Firefox:</p> <pre class="lang-css prettyprint-override"><code>.myImage a img { border: 1px solid grey; padding: 3px; } .myImage a:hover img { border: 3px solid blue; padding: 1px; } </code></pre> <p>However, in IE, borders do not appear when the mouse isn't hovered over the image. My Google-fu tells me there is a bug in IE that is causing this problem. Unfortunately, I can't seem to locate a way to fix that bug.</p>
[ { "answer_id": 64098, "author": "Eric DeLabar", "author_id": 7556, "author_profile": "https://Stackoverflow.com/users/7556", "pm_score": 0, "selected": false, "text": "<div class=\"myImage\"><a href=\"...\" class=\"image\"><img .../></a></div>\n .myImage a.image\n{\n border: 1px solid grey;\n padding: 3px;\n}\n.myImage a.image:hover\n{\n border: 3px solid blue;\n padding: 1px;\n}\n .myImage a img {\n border: none;\n}\n" }, { "answer_id": 64134, "author": "Mr. Shiny and New 安宇", "author_id": 7867, "author_profile": "https://Stackoverflow.com/users/7867", "pm_score": 1, "selected": false, "text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n <head>\n <title></title>\n <style type=\"text/css\">\n a, a:visited, a:link, a *, a:visited *, a:link * { border: 0; }\n .myImage a\n {\n float: left;\n clear: both;\n border: 0;\n margin: 3px;\n padding: 1px;\n }\n .myImage a:link:hover\n {\n float: left;\n clear: both;\n border: 3px solid blue;\n padding: 1px;\n margin: 0;\n display:block;\n }\n </style>\n </head>\n <body>\n <div class=\"myImage\"><a href=\"#\"><img src=\"http://stackoverflow.com/Content/Img/stackoverflow-logo-250.png\"></a></div>\n <div class=\"myImage\"><a href=\"#\"><img src=\"http://stackoverflow.com/Content/Img/stackoverflow-logo-250.png\"></a></div>\n </body>\n</html>\n" }, { "answer_id": 64150, "author": "Jamie", "author_id": 8391, "author_profile": "https://Stackoverflow.com/users/8391", "pm_score": 1, "selected": false, "text": ".standard_border\n{\n border: 1px solid grey;\n padding: 3px;\n}\n.hover_border\n{\n border: 3px solid blue;\n padding: 1px;\n}\n <img src=\"image.jpg\" alt=\"\" class=\"standard_border\" onmouseover=\"this.className='hover_border'\" onmouseout=\"this.className='standard_border'\" />\n" }, { "answer_id": 64178, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<!--[if lt IE 7]>\n<script src=\"http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js\" type=\"text/javascript\"></script>\n<![endif]-->\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7357/" ]
63,897
<p>I'm testing the VB function below that I got from a Google search. I plan to use it to generate hash codes for quick string comparison. However, there are occasions in which two different strings have the same hash code. For example, these strings</p> <p>"122Gen 1 heap size (.NET CLR Memory w3wp):mccsmtpteweb025.20833333333333E-02"</p> <p>"122Gen 2 heap size (.NET CLR Memory w3wp):mccsmtpteweb015.20833333333333E-02"</p> <p>have the same hash code of 237117279.</p> <p>Please tell me: - What is wrong with the function? - How can I fix it?</p> <p>Thank you</p> <p>martin</p> <hr> <pre><code>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, src As Any, ByVal bytes As Long) Private Function HashCode(Key As String) As Long On Error GoTo ErrorGoTo Dim lastEl As Long, i As Long ' copy ansi codes into an array of long' lastEl = (Len(Key) - 1) \ 4 ReDim codes(lastEl) As Long ' this also converts from Unicode to ANSI' CopyMemory codes(0), ByVal Key, Len(Key) ' XOR the ANSI codes of all characters' For i = 0 To lastEl - 1 HashCode = HashCode Xor codes(i) 'Xor' Next ErrorGoTo: Exit Function End Function </code></pre>
[ { "answer_id": 63964, "author": "Clinton Pierce", "author_id": 8173, "author_profile": "https://Stackoverflow.com/users/8173", "pm_score": 4, "selected": true, "text": "System.Security.Cryptography" }, { "answer_id": 64055, "author": "user7936", "author_id": 7936, "author_profile": "https://Stackoverflow.com/users/7936", "pm_score": 0, "selected": false, "text": "(a XOR b) XOR c = a XOR (b XOR c)\n" }, { "answer_id": 64168, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "Private Function HashCode(Key As String) As Long\n On Error GoTo ErrorGoTo\n\n Dim lastEl As Long, i As Long\n ' copy ansi codes into an array of long'\n lastEl = (Len(Key) - 1) \\ 4\n ReDim codes(lastEl) As Long\n ' this also converts from Unicode to ANSI'\n CopyMemory codes(0), ByVal Key, Len(Key)\n ' XOR the ANSI codes of all characters'\n\n For i = 0 To lastEl - 1\n HashCode = HashCode Xor (codes(i) + i) 'Xor'\n Next\n\nErrorGoTo:\n Exit Function\nEnd Function\n" }, { "answer_id": 64737, "author": "botismarius", "author_id": 4528, "author_profile": "https://Stackoverflow.com/users/4528", "pm_score": 1, "selected": false, "text": "\n\n unsigned int hash(const char* name) {\n unsigned mul=1;\n unsigned val=0;\n while(name[0]!=0) {\n val+=mul*((unsigned)name[0]);\n mul*=7; //you could use an arbitrary prime number, but test the hash dispersion afterwards\n name++;\n }\n return val;\n }\n\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8203/" ]
63,930
<p>Struts 1.3 application. Main website is NOT served by struts/Java. I need to forward the result of a struts action to a page in the website, that is outside of the struts context. Currently, I forward to a JSP in context and use a meta-refresh to forward to the real location. That seems kinda sucky. Is there a better way?</p>
[ { "answer_id": 64049, "author": "shrisha", "author_id": 6466, "author_profile": "https://Stackoverflow.com/users/6466", "pm_score": 4, "selected": true, "text": "sendRedirect() HttpServletResponse Action execute() return null setModule() ActionForward" }, { "answer_id": 1006703, "author": "Kevin Hakanson", "author_id": 22514, "author_profile": "https://Stackoverflow.com/users/22514", "pm_score": 0, "selected": false, "text": "RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);\nrd.forward(request, response);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63930", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3029/" ]
63,950
<p>I program with Emacs on Ubuntu (Hardy Heron at the moment), and I like the default text coloration in the Emacs GUI. However, the default text coloration when Emacs is run in the terminal is different and garish.</p> <p>How do I make the colors in the terminal match the colors in the GUI?</p>
[ { "answer_id": 64585, "author": "insipid", "author_id": 8649, "author_profile": "https://Stackoverflow.com/users/8649", "pm_score": 7, "selected": false, "text": "env TERM=xterm-256color emacs -nw\n .bashrc export TERM=xterm-256color\n M-x list-colors-display color-theme" }, { "answer_id": 60620286, "author": "Arseniy Alekseyev", "author_id": 8294974, "author_profile": "https://Stackoverflow.com/users/8294974", "pm_score": 0, "selected": false, "text": "(set 'xterm-standard-colors\n '((\"black\" 0 ( 0 0 0))\n (\"red\" 1 (255 0 0))\n (\"green\" 2 ( 0 255 0))\n (\"yellow\" 3 (255 255 0))\n (\"blue\" 4 ( 0 0 255))\n (\"magenta\" 5 (255 0 255))\n (\"cyan\" 6 ( 0 255 255))\n (\"white\" 7 (255 255 255))\n (\"brightblack\" 8 (127 127 127))\n (\"brightred\" 9 (255 0 0))\n (\"brightgreen\" 10 ( 0 255 0))\n (\"brightyellow\" 11 (255 255 0))\n (\"brightblue\" 12 (92 92 255))\n (\"brightmagenta\" 13 (255 0 255))\n (\"brightcyan\" 14 ( 0 255 255))\n (\"brightwhite\" 15 (255 255 255)))\n )\n list-colors-display" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
63,960
<p>I haven't programmed games for about 10 years (My last experience was DJGPP + Allegro), but I thought I'd check out XNA over the weekend to see how it was shaping up.</p> <p>I am fairly impressed, however as I continue to piece together a game engine, I have a (probably) basic question.</p> <p>How much should you rely on C#'s Delegates and Events to drive the game? As an application programmer, I use delegates and events heavily, but I don't know if there is a significant overhead to doing so.</p> <p>In my game engine, I have designed a "chase cam" of sorts, that can be attached to an object and then recalculates its position relative to the object. When the object moves, there are two ways to update the chase cam.</p> <ul> <li>Have an "UpdateCameras()" method in the main game loop.</li> <li>Use an event handler, and have the chase cam subscribe to object.OnMoved.</li> </ul> <p>I'm using the latter, because it allows me to chain events together and nicely automate large parts of the engine. Suddenly, what would be huge and complex get dropped down to a handful of 3-5 line event handlers...Its a beauty.</p> <p>However, if event handlers firing every nanosecond turn out to be a major slowdown, I'll remove it and go with the loop approach.</p> <p>Ideas?</p>
[ { "answer_id": 79886, "author": "Empyrean", "author_id": 14830, "author_profile": "https://Stackoverflow.com/users/14830", "pm_score": 2, "selected": false, "text": " private delegate void SpacialItemVisitor(ISpacialItem item);\n\n protected override void Update(GameTime gameTime)\n {\n m_quadTree.Visit(ref explosionCircle, ApplyExplosionEffects);\n }\n\n private void ApplyExplosionEffects(ISpacialItem item)\n {\n }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
63,974
<p>In my application I have a DataGridView control that displays data for the selected object. When I select a different object (in a combobox above), I need to update the grid. Unfortunately different objects have completely different data, even different columns, so I need to clear all the existing data and columns, create new columns and add all the rows. When this is done, the whole control flickers horribly and it takes ages. Is there a generic way to get the control in an update state so it doesn't repaint itself, and then repaint it after I finish all the updates? </p> <p>It is certainly possible with TreeViews:</p> <pre><code>myTreeView.BeginUpdate(); try { //do the updates } finally { myTreeView.EndUpdate(); } </code></pre> <p>Is there a generic way to do this with other controls, DataGridView in particular?</p> <p>UPDATE: Sorry, I am not sure I was clear enough. I see the "flickering", because after single edit the control gets repainted on the screen, so you can see the scroll bar shrinking, etc.</p>
[ { "answer_id": 65578, "author": "Ken Wootton", "author_id": 7357, "author_profile": "https://Stackoverflow.com/users/7357", "pm_score": 3, "selected": false, "text": "this.SuspendLayout();\n\n// Do something interesting.\n\nthis.ResumeLayout();\n" }, { "answer_id": 70281, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 4, "selected": true, "text": "DataGridView.Rows.AddRange DataGridView.Columns.AddRange" }, { "answer_id": 212197, "author": "Brian Hasden", "author_id": 28926, "author_profile": "https://Stackoverflow.com/users/28926", "pm_score": 2, "selected": false, "text": "SetStyle(ControlStyles.UserPaint, true);\nSetStyle(ControlStyles.AllPaintingInWmPaint, true); \nSetStyle(ControlStyles.DoubleBuffer, true); \n" }, { "answer_id": 10887964, "author": "Jon", "author_id": 1435997, "author_profile": "https://Stackoverflow.com/users/1435997", "pm_score": 3, "selected": false, "text": "Object.Visible = false;\n\n//do update work\n\nObject.Visible = true;\n begin end" }, { "answer_id": 45604941, "author": "Ramgy Borja", "author_id": 7978302, "author_profile": "https://Stackoverflow.com/users/7978302", "pm_score": 0, "selected": false, "text": "public static void DoubleBuffered(Control formControl, bool setting)\n{\n Type conType = formControl.GetType();\n PropertyInfo pi = conType.GetProperty(\"DoubleBuffered\", BindingFlags.Instance | BindingFlags.NonPublic);\n pi.SetValue(formControl, setting, null);\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5363/" ]
63,995
<p>I would like to give a class a unique ID every time a new one is instantiated. For example with a class named Foo i would like to be able to do the following</p> <pre><code>dim a as New Foo() dim b as New Foo() </code></pre> <p>and a would get a unique id and b would get a unique ID. The ids only have to be unique over run time so i would just like to use an integer. I have found a way to do this BUT (and heres the caveat) I do NOT want to be able to change the ID from anywhere. My current idea for a way to implement this is the following:</p> <pre><code>Public Class test Private Shared ReadOnly _nextId As Integer Private ReadOnly _id As Integer Public Sub New() _nextId = _nextId + 1 _id = _nextId End Sub End Class </code></pre> <p>However this will not compile because it throws an error on _nextId = _nextId + 1 I don't see why this would be an error (because _Id is also readonly you're supposed to be able to change a read only variable in the constructor.) I think this has something to do with it being shared also. Any solution (hopefully not kludgy hehe) or an explanation of why this won't work will be accepted. The important part is i want both of the variables (or if there is a way to only have one that would even be better but i don't think that is possible) to be immutable after the object is initialized. Thanks!</p>
[ { "answer_id": 64033, "author": "Magnus Akselvoll", "author_id": 4683, "author_profile": "https://Stackoverflow.com/users/4683", "pm_score": 0, "selected": false, "text": "Shared Sub New()\n _nextId = 0\nEnd Sub\n" }, { "answer_id": 64108, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 1, "selected": false, "text": "Public MustInherit Class Unique\n Private _UID As Guid = Guid.NewGuid()\n Public ReadOnly Property UID() As Guid\n Get\n Return _UID\n End Get\n End Property\nEnd Class\n" }, { "answer_id": 64115, "author": "Compile This", "author_id": 4048, "author_profile": "https://Stackoverflow.com/users/4048", "pm_score": 0, "selected": false, "text": "readonly" }, { "answer_id": 64199, "author": "Magnus Akselvoll", "author_id": 4683, "author_profile": "https://Stackoverflow.com/users/4683", "pm_score": 3, "selected": true, "text": "Public Class Foo \n Private ReadOnly _fooId As FooId \n\n Public Sub New() \n _fooId = New FooId() \n End Sub \n\n Public ReadOnly Property Id() As Integer \n Get \n Return _fooId.Id \n End Get \n End Property \nEnd Class \n\nPublic NotInheritable Class FooId \n Private Shared _nextId As Integer \n Private ReadOnly _id As Integer \n\n Shared Sub New() \n _nextId = 0 \n End Sub \n\n Public Sub New() \n SyncLock GetType(FooId) \n _id = System.Math.Max(System.Threading.Interlocked.Increment(_nextId),_nextId - 1) \n End SyncLock \n End Sub \n\n Public ReadOnly Property Id() As Integer \n Get \n Return _id \n End Get \n End Property \nEnd Class \n" }, { "answer_id": 64261, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 0, "selected": false, "text": "Public Class test\n Private Shared ReadOnly _nextId As Integer\n Private ReadOnly _id As Integer\n\n Public Shared Sub New()\n _nextId = _nextId + 1\n End Sub\n\n Public Sub New()\n _id = _nextId\n End Sub\nEnd Class\n public class Test\n{\n private static readonly int _nextId;\n private readonly int _id;\n\n static Test()\n {\n _nextId++;\n }\n\n public Test()\n {\n _id = _nextId;\n }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8054/" ]
63,998
<p>Continuing the "Hidden features of ..." meme, let's share the lesser-known but useful features of Ruby programming language.</p> <p>Try to limit this discussion with core Ruby, without any Ruby on Rails stuff.</p> <p>See also:</p> <ul> <li><a href="https://stackoverflow.com/questions/9033/hidden-features-of-c">Hidden features of C#</a></li> <li><a href="https://stackoverflow.com/questions/15496/hidden-features-of-java">Hidden features of Java</a></li> <li><a href="https://stackoverflow.com/questions/61088/hidden-features-of-javascript">Hidden features of JavaScript</a></li> <li><a href="https://stackoverflow.com/questions/709679/hidden-features-of-ruby-on-rails">Hidden features of Ruby on Rails</a></li> <li><a href="https://stackoverflow.com/questions/101268/hidden-features-of-python">Hidden features of Python</a></li> </ul> <p>(Please, just <em>one</em> hidden feature per answer.)</p> <p>Thank you</p>
[ { "answer_id": 64080, "author": "CodingWithoutComments", "author_id": 25, "author_profile": "https://Stackoverflow.com/users/25", "pm_score": 5, "selected": false, "text": "((0..9).each do |n|\n define_method \"press_#{n}\" do\n @number = @number.to_i * 10 + n\n end\n end\n" }, { "answer_id": 64099, "author": "CodingWithoutComments", "author_id": 25, "author_profile": "https://Stackoverflow.com/users/25", "pm_score": 3, "selected": false, "text": " %w(7 8 9 / 4 5 6 * 1 2 3 - 0 Clr = +).each do |btn|\n button btn, :width => 46, :height => 46 do\n method = case btn\n when /[0-9]/: 'press_'+btn\n when 'Clr': 'press_clear'\n when '=': 'press_equals'\n when '+': 'press_add'\n when '-': 'press_sub'\n when '*': 'press_times'\n when '/': 'press_div'\n end\n\n number.send(method)\n number_field.replace strong(number)\n end\n end\n" }, { "answer_id": 64124, "author": "manveru", "author_id": 8367, "author_profile": "https://Stackoverflow.com/users/8367", "pm_score": 5, "selected": false, "text": "make golf make golf\n\n./goruby -e 'h'\n# => Hello, world!\n\n./goruby -e 'p St'\n# => StandardError\n\n./goruby -e 'p 1.tf'\n# => 1.0\n\n./goruby19 -e 'p Fil.exp(\".\")'\n\"/home/manveru/pkgbuilds/ruby-svn/src/trunk\"\n golf_prelude.c" }, { "answer_id": 64427, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 4, "selected": false, "text": "===(obj) case foo\nwhen /baz/\n do_something_with_the_string_matching_baz\nwhen 12..15\n do_something_with_the_integer_between_12_and_15\nwhen lambda { |x| x % 5 == 0 }\n # only works in Ruby 1.9 or if you alias Proc#call as Proc#===\n do_something_with_the_integer_that_is_a_multiple_of_5\nwhen Bar\n do_something_with_the_instance_of_Bar\nwhen some_object\n do_something_with_the_thing_that_matches_some_object\nend\n Module Class Regexp Date Proc#call Proc#===" }, { "answer_id": 64458, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 6, "selected": false, "text": "[*items].each do |item|\n # ...\nend\n" }, { "answer_id": 64502, "author": "Scott Holden", "author_id": 8588, "author_profile": "https://Stackoverflow.com/users/8588", "pm_score": 3, "selected": false, "text": "readfile.rb: $<.each_line{|l| puts l}\n\nruby readfile.rb testfile.txt\n" }, { "answer_id": 64956, "author": "TALlama", "author_id": 5657, "author_profile": "https://Stackoverflow.com/users/5657", "pm_score": 4, "selected": false, "text": "attr_accessor attr_reader attr_writer has_one belongs_to class_eval class Wrapper\n attr_accessor :internal\n\n def self.forwards(*methods)\n methods.each do |method|\n define_method method do |*arguments, &block|\n internal.send method, *arguments, &block\n end\n end\n end\n\n forwards :to_i, :length, :split\nend\n\nw = Wrapper.new\nw.internal = \"12 13 14\"\nw.to_i # => 12\nw.length # => 8\nw.split('1') # => [\"\", \"2 \", \"3 \", \"4\"]\n Wrapper.forwards methods define_method" }, { "answer_id": 65015, "author": "Farrel", "author_id": 7889, "author_profile": "https://Stackoverflow.com/users/7889", "pm_score": 6, "selected": false, "text": "def multiple_of(factor)\n Proc.new{|product| product.modulo(factor).zero?}\nend\n\ncase number\n when multiple_of(3)\n puts \"Multiple of 3\"\n when multiple_of(7)\n puts \"Multiple of 7\"\nend\n" }, { "answer_id": 68037, "author": "olegueret", "author_id": 10421, "author_profile": "https://Stackoverflow.com/users/10421", "pm_score": 3, "selected": false, "text": "$\" << \"something\"\n bdrb_test_helper requires 'test/spec' $\" << \"test/spec\"\nrequire File.join(File.dirname(__FILE__) + \"/../bdrb_test_helper\")\n" }, { "answer_id": 68205, "author": "hoyhoy", "author_id": 3499, "author_profile": "https://Stackoverflow.com/users/3499", "pm_score": 5, "selected": false, "text": "Employee.collect { |emp| emp.name }\n Employee.collect(&:name)\n" }, { "answer_id": 70116, "author": "Farrel", "author_id": 7889, "author_profile": "https://Stackoverflow.com/users/7889", "pm_score": 5, "selected": false, "text": "it_is_day_of_week = lambda{ |day_of_week, date| date.wday == day_of_week }\nit_is_saturday = it_is_day_of_week.curry[6]\nit_is_sunday = it_is_day_of_week.curry[0]\n\ncase Time.now\nwhen it_is_saturday\n puts \"Saturday!\"\nwhen it_is_sunday\n puts \"Sunday!\"\nelse\n puts \"Not the weekend\"\nend\n" }, { "answer_id": 70203, "author": "astronautism", "author_id": 11424, "author_profile": "https://Stackoverflow.com/users/11424", "pm_score": 6, "selected": false, "text": "fruit = [\"apple\",\"red\",\"banana\",\"yellow\"]\n=> [\"apple\", \"red\", \"banana\", \"yellow\"]\n\nHash[*fruit] \n=> {\"apple\"=>\"red\", \"banana\"=>\"yellow\"}\n" }, { "answer_id": 70286, "author": "tomafro", "author_id": 7126, "author_profile": "https://Stackoverflow.com/users/7126", "pm_score": 6, "selected": false, "text": "* match, text, number = *\"Something 981\".match(/([A-z]*) ([0-9]*)/)\n a, b, c = *('A'..'Z')\n\nJob = Struct.new(:name, :occupation)\ntom = Job.new(\"Tom\", \"Developer\")\nname, occupation = *tom\n" }, { "answer_id": 85310, "author": "tomafro", "author_id": 7126, "author_profile": "https://Stackoverflow.com/users/7126", "pm_score": 6, "selected": false, "text": "Fixnum >> 1234567890.to_s(2)\n=> \"1001001100101100000001011010010\"\n\n>> 1234567890.to_s(8)\n=> \"11145401322\"\n\n>> 1234567890.to_s(16)\n=> \"499602d2\"\n\n>> 1234567890.to_s(24)\n=> \"6b1230i\"\n\n>> 1234567890.to_s(36)\n=> \"kf12oi\"\n >> \"kf12oi\".to_i(36)\n=> 1234567890\n" }, { "answer_id": 86238, "author": "tomafro", "author_id": 7126, "author_profile": "https://Stackoverflow.com/users/7126", "pm_score": 5, "selected": false, "text": "message = \"My message\"\ncontrived_example = \"<div id=\\\"contrived\\\">#{message}</div>\"\n contrived_example = %{<div id=\"contrived-example\">#{message}</div>}\ncontrived_example = %[<div id=\"contrived-example\">#{message}</div>]\n sql = %{\n SELECT strings \n FROM complicated_table\n WHERE complicated_condition = '1'\n}\n" }, { "answer_id": 116759, "author": "newtonapple", "author_id": 1376, "author_profile": "https://Stackoverflow.com/users/1376", "pm_score": 5, "selected": false, "text": "module M\n def not!\n 'not!'\n end\n module_function :not!\nend\n\nclass C\n include M\n\n def fun\n not!\n end\nend\n\nM.not! # => 'not!\nC.new.fun # => 'not!'\nC.new.not! # => NoMethodError: private method `not!' called for #<C:0x1261a00>\n module M\n module_function\n\n def not!\n 'not!'\n end\n\n def yea!\n 'yea!'\n end\nend\n\n\nclass C\n include M\n\n def fun\n not! + ' ' + yea!\n end\nend\nM.not! # => 'not!'\nM.yea! # => 'yea!'\nC.new.fun # => 'not! yea!'\n" }, { "answer_id": 224276, "author": "Justin Love", "author_id": 30203, "author_profile": "https://Stackoverflow.com/users/30203", "pm_score": 4, "selected": false, "text": "Class.new() const_set/const_get/const_defined? inspect" }, { "answer_id": 327208, "author": "Dustin", "author_id": 39975, "author_profile": "https://Stackoverflow.com/users/39975", "pm_score": 2, "selected": false, "text": "#!/usr/bin/env ruby\n\ndef rprod(k, rv, current, *nums)\n puts \"#{rv} * #{current}\"\n k.call(0) if current == 0 || rv == 0\n nums.empty? ? (rv * current) : rprod(k, rv * current, *nums)\nend\n\ndef prod(first, *rest)\n callcc { |k| rprod(k, first, *rest) }\nend\n\nputs \"Seq 1: #{prod(1, 2, 3, 4, 5, 6)}\"\nputs \"\"\nputs \"Seq 2: #{prod(1, 2, 0, 3, 4, 5, 6)}\"\n" }, { "answer_id": 474888, "author": "Bo Jeanes", "author_id": 56690, "author_profile": "https://Stackoverflow.com/users/56690", "pm_score": 6, "selected": false, "text": "class RandomSubclass < [Array, Hash, String, Fixnum, Float, TrueClass].sample\n\nend\n\nRandomSubclass.superclass # could output one of 6 different classes.\n Array#sample Array#choice def do_something_at(something, at = Time.now)\n # ...\nend\n do_something_at at" }, { "answer_id": 827932, "author": "Chirantan", "author_id": 45942, "author_profile": "https://Stackoverflow.com/users/45942", "pm_score": 2, "selected": false, "text": "class A\n\n private\n\n def my_private_method\n puts 'private method called'\n end\nend\n\na = A.new\na.my_private_method # Raises exception saying private method was called\na.send :my_private_method # Calls my_private_method and prints private method called'\n" }, { "answer_id": 1061004, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "(1..10).inject(:+)\n=> 55\n" }, { "answer_id": 1061835, "author": "August Lilleaas", "author_id": 26051, "author_profile": "https://Stackoverflow.com/users/26051", "pm_score": 5, "selected": false, "text": "parties = Hash.new {|hash, key| hash[key] = [] }\nparties[\"Summer party\"]\n# => []\n\nparties[\"Summer party\"] << \"Joe\"\nparties[\"Other party\"] << \"Jane\"\n" }, { "answer_id": 1140464, "author": "Ropez", "author_id": 137627, "author_profile": "https://Stackoverflow.com/users/137627", "pm_score": 3, "selected": false, "text": ">> class <<Object\n>> alias :old_const_missing :const_missing\n>> def const_missing(sym)\n>> ENV[sym.to_s] || old_const_missing(sym)\n>> end\n>> end\n=> nil\n\n>> puts SHELL\n/bin/zsh\n=> nil\n>> TERM == 'xterm'\n=> true\n" }, { "answer_id": 1224534, "author": "horseyguy", "author_id": 66725, "author_profile": "https://Stackoverflow.com/users/66725", "pm_score": 4, "selected": false, "text": "x = [*0..5]\n" }, { "answer_id": 1540615, "author": "Jordan Running", "author_id": 179125, "author_profile": "https://Stackoverflow.com/users/179125", "pm_score": 4, "selected": false, "text": "a = [:x, :y, :z]\nb = [123, 456, 789]\n\nHash[a.zip(b)]\n# => { :x => 123, :y => 456, :z => 789 }\n a.zip(b) # => [[:x, 123], [:y, 456], [:z, 789]]\n Hash[*a.zip(b).flatten] # unnecessary!\n" }, { "answer_id": 1817710, "author": "horseyguy", "author_id": 66725, "author_profile": "https://Stackoverflow.com/users/66725", "pm_score": 5, "selected": false, "text": "Inf = 1.0 / 0\n\n(1..Inf).take(5) #=> [1, 2, 3, 4, 5]\n" }, { "answer_id": 1941479, "author": "EmFi", "author_id": 186039, "author_profile": "https://Stackoverflow.com/users/186039", "pm_score": 5, "selected": false, "text": "&& || ||= &&= string &&= string + \"suffix\"\n if string\n string = string + \"suffix\"\nend\n" }, { "answer_id": 1992744, "author": "minaguib", "author_id": 241953, "author_profile": "https://Stackoverflow.com/users/241953", "pm_score": 2, "selected": false, "text": "irb(main):001:0> h = {:name => \"Bob\"}\n=> {:name=>\"Bob\"}\nirb(main):002:0> [*h]\n=> [[:name, \"Bob\"]]\n irb(main):003:0> h = {:name => \"Bob\"}\n=> {:name=>\"Bob\"}\nirb(main):004:0> [h].flatten\n=> [{:name=>\"Bob\"}]\n def process(*entries)\n [entries].flatten.each do |e|\n # do something with e\n end\nend\n" }, { "answer_id": 1992828, "author": "minaguib", "author_id": 241953, "author_profile": "https://Stackoverflow.com/users/241953", "pm_score": 4, "selected": false, "text": "put # Print each line with its number:\nruby -ne 'print($., \": \", $_)' < /etc/irbrc\n\n# Print each line reversed:\nruby -lne 'puts $_.reverse' < /etc/irbrc\n\n# Print the second column from an input CSV (dumb - no balanced quote support etc):\nruby -F, -ane 'puts $F[1]' < /etc/irbrc\n\n# Print lines that contain \"eat\"\nruby -ne 'puts $_ if /eat/i' < /etc/irbrc\n\n# Same as above:\nruby -pe 'next unless /eat/i' < /etc/irbrc\n\n# Pass-through (like cat, but with possible line-end munging):\nruby -p -e '' < /etc/irbrc\n\n# Uppercase all input:\nruby -p -e '$_.upcase!' < /etc/irbrc\n\n# Same as above, but actually write to the input file, and make a backup first with extension .bak - Notice that inplace edit REQUIRES input files, not an input STDIN:\nruby -i.bak -p -e '$_.upcase!' /etc/irbrc\n" }, { "answer_id": 2132820, "author": "Trevoke", "author_id": 234025, "author_profile": "https://Stackoverflow.com/users/234025", "pm_score": 4, "selected": false, "text": "def cnh # silly name \"create nested hash\"\n Hash.new {|h,k| h[k] = Hash.new(&h.default_proc)}\nend\nmy_hash = cnh\nmy_hash[1][2][3] = 4\nmy_hash # => { 1 => { 2 => { 3 =>4 } } }\n" }, { "answer_id": 2340767, "author": "sickill", "author_id": 264409, "author_profile": "https://Stackoverflow.com/users/264409", "pm_score": 3, "selected": false, "text": "Fixnum#to_s(base) rand(36**8).to_s(36) => \"fmhpjfao\"\nrand(36**8).to_s(36) => \"gcer9ecu\"\nrand(36**8).to_s(36) => \"krpm0h9r\"\n rand(36**6).to_s(36) => \"bvhl8d\"\nrand(36**6).to_s(36) => \"lb7tis\"\nrand(36**6).to_s(36) => \"ibwgeh\"\n" }, { "answer_id": 2379114, "author": "Fabiano Soriani", "author_id": 250019, "author_profile": "https://Stackoverflow.com/users/250019", "pm_score": 2, "selected": false, "text": "@user #=> nil (but I did't know)\[email protected] rescue \"Unknown\"\nlink_to( d.user.name, url_user( d.user.id, d.user.name)) rescue 'Account removed'\n" }, { "answer_id": 2792840, "author": "haoqi", "author_id": 131492, "author_profile": "https://Stackoverflow.com/users/131492", "pm_score": 1, "selected": false, "text": "@user #=> nil (but I did't know)\[email protected] rescue \"Unknown\"\n" }, { "answer_id": 2911455, "author": "Judson", "author_id": 349582, "author_profile": "https://Stackoverflow.com/users/349582", "pm_score": 3, "selected": false, "text": "%w{An Array of strings} #=> [\"An\", \"Array\", \"of\", \"Strings\"]\n" }, { "answer_id": 3054688, "author": "Konstantin Haase", "author_id": 302187, "author_profile": "https://Stackoverflow.com/users/302187", "pm_score": 6, "selected": false, "text": "1.upto(100) do |i|\n puts i if (i == 3)..(i == 15)\nend\n" }, { "answer_id": 3341493, "author": "mhd", "author_id": 38515, "author_profile": "https://Stackoverflow.com/users/38515", "pm_score": 2, "selected": false, "text": "myarray = [\"la\", \"li\", \"lu\"]\nmyarray.each_with_index{|v,idx| puts \"#{idx} -> #{v}\"}\n\n#result:\n#0 -> la\n#1 -> li\n#2 -> lu\n" }, { "answer_id": 3823852, "author": "horseyguy", "author_id": 66725, "author_profile": "https://Stackoverflow.com/users/66725", "pm_score": 4, "selected": false, "text": "(a, b), c, d = [ [:a, :b ], :c, [:d1, :d2] ]\n a #=> :a\nb #=> :b\nc #=> :c\nd #=> [:d1, :d2]\n" }, { "answer_id": 3834838, "author": "horseyguy", "author_id": 66725, "author_profile": "https://Stackoverflow.com/users/66725", "pm_score": 3, "selected": false, "text": "def hello(*)\n super\n puts \"hello!\"\nend\n hello puts \"hello\" super hello" }, { "answer_id": 4294367, "author": "Ramiz Uddin", "author_id": 134743, "author_profile": "https://Stackoverflow.com/users/134743", "pm_score": 2, "selected": false, "text": "def getCostAndMpg\n cost = 30000 # some fancy db calls go here\n mpg = 30\n return cost,mpg\nend\nAltimaCost, AltimaMpg = getCostAndMpg\nputs \"AltimaCost = #{AltimaCost}, AltimaMpg = #{AltimaMpg}\"\n i = 0\nj = 1\nputs \"i = #{i}, j=#{j}\"\ni,j = j,i\nputs \"i = #{i}, j=#{j}\"\n class Employee < Person\n def initialize(fname, lname, position)\n super(fname,lname)\n @position = position\n end\n def to_s\n super + \", #@position\"\n end\n attr_writer :position\n def etype\n if @position == \"CEO\" || @position == \"CFO\"\n \"executive\"\n else\n \"staff\"\n end\n end\nend\nemployee = Employee.new(\"Augustus\",\"Bondi\",\"CFO\")\nemployee.position = \"CEO\"\nputs employee.etype => executive\nemployee.position = \"Engineer\"\nputs employee.etype => staff\n class MathWiz\n def add(a,b) \n return a+b\n end\n def method_missing(name, *args)\n puts \"I don't know the method #{name}\"\n end\nend\nmathwiz = MathWiz.new\nputs mathwiz.add(1,4)\nputs mathwiz.subtract(4,2)\n" }, { "answer_id": 5333299, "author": "Aaa", "author_id": 636053, "author_profile": "https://Stackoverflow.com/users/636053", "pm_score": 2, "selected": false, "text": ":'class'\n define_method :\"#{name}=\" do |value|\n instance_variable_set :\"@#{name}\", value\nend\n" }, { "answer_id": 6037067, "author": "J-_-L", "author_id": 169793, "author_profile": "https://Stackoverflow.com/users/169793", "pm_score": 3, "selected": false, "text": "| Regexp.union /Ruby\\d/, /test/i, \"cheat\"\n /(Ruby\\d|[tT][eE][sS][tT]|cheat)/\n" }, { "answer_id": 6279466, "author": "Szymon Jeż", "author_id": 408011, "author_profile": "https://Stackoverflow.com/users/408011", "pm_score": 3, "selected": false, "text": "private unless Rails.env == 'test'\n# e.g. a bundle of methods you want to test directly\n" }, { "answer_id": 8933705, "author": "Alex D", "author_id": 960828, "author_profile": "https://Stackoverflow.com/users/960828", "pm_score": 2, "selected": false, "text": "> (a,b),c = [[1,2],3]\n=> [[1,2],3]\n> a\n=> 1\n" }, { "answer_id": 9214173, "author": "iblue", "author_id": 773690, "author_profile": "https://Stackoverflow.com/users/773690", "pm_score": 1, "selected": false, "text": "format_string % argument \"%04d\" % 1 # => \"0001\"\n\"%0.2f\" % Math::PI # => \"3.14\"\n format_string % array_of_arguments \"%.2f %.3f %.4f\" % ([Math::PI]*3) \n# => \"3.14 3.142 3.1416\"\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/63998", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7754/" ]
64,000
<p>When launching a process from Java, both stderr and stdout can block on output if I don't read from the pipes. Currently I have a thread that pro-actively reads from one and the main thread blocks on the other.</p> <p>Is there an easy way to join the two streams or otherwise cause the subprocess to continue while not losing the data in stderr? </p>
[ { "answer_id": 64183, "author": "Mat Mannion", "author_id": 6282, "author_profile": "https://Stackoverflow.com/users/6282", "pm_score": 3, "selected": true, "text": "ProcessBuilder builder = new ProcessBuilder(command);\nbuilder.redirectErrorStream(true);\n Process p = builder.start();\n\nInputHandler outHandler = new InputHandler(p.getInputStream());\n private static class InputHandler extends Thread {\n\n private final InputStream is;\n\n private final ByteArrayOutputStream os;\n\n public InputHandler(InputStream input) {\n this.is = input;\n this.os = new ByteArrayOutputStream();\n }\n\n public void run() {\n try {\n int c;\n while ((c = is.read()) != -1) {\n os.write(c);\n }\n } catch (Throwable t) {\n throw new IllegalStateException(t);\n }\n }\n\n public String getOutput() {\n try {\n os.flush();\n } catch (Throwable t) {\n throw new IllegalStateException(t);\n }\n return os.toString();\n }\n\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4926/" ]
64,003
<p>I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be outdated.</p> <p>How would I make the year update automatically with <a href="http://en.wikipedia.org/wiki/PHP#History" rel="noreferrer">PHP 4</a> or <a href="http://en.wikipedia.org/wiki/PHP#History" rel="noreferrer">PHP 5</a>?</p>
[ { "answer_id": 64009, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 9, "selected": false, "text": "<?php echo date(\"Y\"); ?>\n" }, { "answer_id": 64011, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 5, "selected": false, "text": "strftime(\"%Y\");\n" }, { "answer_id": 64016, "author": "chrisb", "author_id": 8262, "author_profile": "https://Stackoverflow.com/users/8262", "pm_score": 5, "selected": false, "text": "echo date('Y');\n" }, { "answer_id": 64027, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "print date('Y');\n" }, { "answer_id": 64087, "author": "Alexey Lebedev", "author_id": 8338, "author_profile": "https://Stackoverflow.com/users/8338", "pm_score": 4, "selected": false, "text": "$year = date('Y'); // 2008\n $year = gmdate('Y'); // 2008\n" }, { "answer_id": 64097, "author": "Erik van Brakel", "author_id": 909, "author_profile": "https://Stackoverflow.com/users/909", "pm_score": 11, "selected": true, "text": "<?php echo date(\"Y\"); ?>\n" }, { "answer_id": 67737, "author": "gregmac", "author_id": 7913, "author_profile": "https://Stackoverflow.com/users/7913", "pm_score": 8, "selected": false, "text": "&copy; <?php \n$copyYear = 2008; \n$curYear = date('Y'); \necho $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');\n?> Me, Inc.\n &copy; \n<?php call_user_func(function($y){$c=date('Y');echo $y.(($y!=$c)?'-'.$c:'');}, 2008); ?> \nMe, Inc.\n" }, { "answer_id": 12201484, "author": "PanicGrip", "author_id": 1469934, "author_profile": "https://Stackoverflow.com/users/1469934", "pm_score": 3, "selected": false, "text": "<?=date(\"Y\")?>\n" }, { "answer_id": 14126896, "author": "Thomas Kelley", "author_id": 266374, "author_profile": "https://Stackoverflow.com/users/266374", "pm_score": 6, "selected": false, "text": "DateTime $now = new DateTime();\n$year = $now->format(\"Y\");\n $year = (new DateTime)->format(\"Y\");\n" }, { "answer_id": 21190124, "author": "Abdul Rahman A Samad", "author_id": 2065804, "author_profile": "https://Stackoverflow.com/users/2065804", "pm_score": 4, "selected": false, "text": "<?php echo date(\"d-m-Y\") ?>\n d = day\nm = month\nY = year\n" }, { "answer_id": 23005793, "author": "kkarayat", "author_id": 1979400, "author_profile": "https://Stackoverflow.com/users/1979400", "pm_score": 3, "selected": false, "text": "echo date('Y') date()" }, { "answer_id": 26158785, "author": "Gaurav", "author_id": 4046430, "author_profile": "https://Stackoverflow.com/users/4046430", "pm_score": -1, "selected": false, "text": "<?php\n$time_now=mktime(date('h')+5,date('i')+30,date('s'));\n$dateTime = date('d_m_Y h:i:s A',$time_now);\n\necho $dateTime;\n?>\n" }, { "answer_id": 26399196, "author": "joan16v", "author_id": 1398876, "author_profile": "https://Stackoverflow.com/users/1398876", "pm_score": 4, "selected": false, "text": "<?php echo date('Y'); ?>\n <?php echo date('y'); ?>\n" }, { "answer_id": 40255730, "author": "saadk", "author_id": 2078007, "author_profile": "https://Stackoverflow.com/users/2078007", "pm_score": 3, "selected": false, "text": "date(\"Y\") // A full numeric representation of a year, 4 digits\n // Examples: 1999 or 2003\n date(\"y\"); // A two digit representation of a year Examples: 99 or 03\n" }, { "answer_id": 40836184, "author": "Milan", "author_id": 1438675, "author_profile": "https://Stackoverflow.com/users/1438675", "pm_score": 3, "selected": false, "text": "**Symbol, Year, Author/Owner and Rights statement.** \n <p id='copyright'>&copy; <?php echo date(\"Y\"); ?> Company Name All Rights Reserved</p>\n <p id='copyright'>&copy; <?php echo \"2010-\".date(\"Y\"); ?> Company Name All Rights Reserved</p\n" }, { "answer_id": 41317983, "author": "Ivan Barayev", "author_id": 6293599, "author_profile": "https://Stackoverflow.com/users/6293599", "pm_score": 3, "selected": false, "text": "<?php\n $current= new \\DateTime();\n $future = new \\DateTime('+ 1 years');\n\n echo $current->format('Y'); \n //For 4 digit ('Y') for 2 digit ('y')\n?>\n $year = (new DateTime)->format(\"Y\");\n <?PHP \n $now = new DateTime;\n $now->modify('-1 years'); //or +1 or +5 years \n echo $now->format('Y');\n //and here again For 4 digit ('Y') for 2 digit ('y')\n?>\n" }, { "answer_id": 42146098, "author": "Wael Assaf", "author_id": 6241797, "author_profile": "https://Stackoverflow.com/users/6241797", "pm_score": 3, "selected": false, "text": "date() <?php echo date(\"Y\"); ?>\n" }, { "answer_id": 42261996, "author": "Abdelkader Soudani", "author_id": 720104, "author_profile": "https://Stackoverflow.com/users/720104", "pm_score": 3, "selected": false, "text": "<?php echo date(\"Y\"); ?>\n" }, { "answer_id": 46127571, "author": "imtaher", "author_id": 6617609, "author_profile": "https://Stackoverflow.com/users/6617609", "pm_score": 2, "selected": false, "text": "<?php date_default_timezone_set(\"Asia/Kolkata\");?><?=date(\"Y\");?>\n" }, { "answer_id": 46232016, "author": "Ganesh Udmale", "author_id": 6790108, "author_profile": "https://Stackoverflow.com/users/6790108", "pm_score": 3, "selected": false, "text": " <?php \n echo $curr_year = date('Y'); // it will display full year ex. 2017\n?>\n <?php \n echo $curr_year = date('y'); // it will display short 2 digit year ex. 17\n?>\n" }, { "answer_id": 47216489, "author": "Sushank Pokharel", "author_id": 7599216, "author_profile": "https://Stackoverflow.com/users/7599216", "pm_score": 2, "selected": false, "text": "<p class=\"text-muted credit\">Copyright &copy;\n <?php\n $copyYear = 2017; // Set your website start date\n $curYear = date('Y'); // Keeps the second year updated\n echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');\n ?> \n</p> \n copyright @ 2017 //if $copyYear is 2017 \ncopyright @ 2017-201x //if $copyYear is not equal to Current Year.\n" }, { "answer_id": 53956475, "author": "Sanu0786", "author_id": 10143531, "author_profile": "https://Stackoverflow.com/users/10143531", "pm_score": 3, "selected": false, "text": "date() <?php echo date(\"Y\"); ?>\n" }, { "answer_id": 55187259, "author": "Omid Ahmadyani", "author_id": 7006183, "author_profile": "https://Stackoverflow.com/users/7006183", "pm_score": 2, "selected": false, "text": "<?= date(\"Y\"); ?>\n" }, { "answer_id": 56552509, "author": "andcl", "author_id": 3099449, "author_profile": "https://Stackoverflow.com/users/3099449", "pm_score": -1, "selected": false, "text": "<?php echo Carbon::now()->year; ?>" }, { "answer_id": 60972190, "author": "Hernán Eche", "author_id": 231382, "author_profile": "https://Stackoverflow.com/users/231382", "pm_score": 1, "selected": false, "text": "$year = date(\"Y\", strtotime($yourDateVar));\n" }, { "answer_id": 64936968, "author": "allenski", "author_id": 9132582, "author_profile": "https://Stackoverflow.com/users/9132582", "pm_score": 1, "selected": false, "text": "footer.php <div id=\"copyright\">\n <?php the_field('copyright_disclaimer', 'options'); ?>\n</div>\n Options Disclaimers Update footer.php <div id=\"copyright\">\n &copy;<?php echo date(\"Y\"); ?> <?php the_field('copyright_disclaimer', 'options'); ?>\n</div>\n" }, { "answer_id": 65932045, "author": "Billu", "author_id": 7186739, "author_profile": "https://Stackoverflow.com/users/7186739", "pm_score": 0, "selected": false, "text": "<?php echo date(\"M D Y\"); ?>\n" }, { "answer_id": 65989381, "author": "ephantus okumu", "author_id": 11665231, "author_profile": "https://Stackoverflow.com/users/11665231", "pm_score": 3, "selected": false, "text": "//Getting the current year using\n//PHP's date function.\n\n$year = date(\"Y\");\necho $year;\n $year = date(\"y\");\necho $year;\n1\n2\n$year = date(\"y\");\necho $year;\n" }, { "answer_id": 66439431, "author": "Pascal Tovohery", "author_id": 7751011, "author_profile": "https://Stackoverflow.com/users/7751011", "pm_score": 0, "selected": false, "text": "// This work when you get time as string\necho date('Y', strtotime(\"now\"));\n\n// Get next years\necho date('Y', strtotime(\"+1 years\"));\n\n// \necho strftime(\"%Y\", strtotime(\"now\"));\n echo (new DateTime)->format('Y');\n" }, { "answer_id": 68000321, "author": "Ayaz Khalid", "author_id": 16232615, "author_profile": "https://Stackoverflow.com/users/16232615", "pm_score": 1, "selected": false, "text": "$date = Carbon::now()->format('Y');\nreturn $date;\n echo date(\"Y\");\n" }, { "answer_id": 69104109, "author": "Md. Saifur Rahman", "author_id": 14350717, "author_profile": "https://Stackoverflow.com/users/14350717", "pm_score": 0, "selected": false, "text": "getCurrentYear();\n\nfunction getCurrentYear(){\n return now()->year;\n}\n" }, { "answer_id": 70568985, "author": "CodAIK", "author_id": 14585422, "author_profile": "https://Stackoverflow.com/users/14585422", "pm_score": 3, "selected": false, "text": "$dateYear = date('Y');\necho \"Current Year: $dateYear\";\n $dateYear = date('y');\necho $dateYear;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1661459/" ]
64,029
<p>I have a very specific problem using C# and a Windows MDI Form application. I want to display two (or more) images to the user, a 'left' and a 'right' image. The names of the images are concealed from the user, and then the user selects which image they prefer (this is part of a study involving medical image quality, so the user has to be blinded from possibly relevant capture parameters which might be revealed in the image name). Instead of showing the actual names, substitute names like 'image 0' and 'image 1' (etc) are shown to the user.</p> <p>Whenever I use the standard <code>MDILayout.TileVertical</code> or <code>TileHorizontal</code>, the images are loaded in reverse order. For example, if I have image 0 and image 1, they are displayed </p> <p>Image 1 Image 0</p> <p>Three or more images would be something like</p> <p>2 1 0</p> <p>or</p> <p>3 2</p> <p>1 0</p> <p>And so forth. The problem is, my users are confused by this right to leftness, and if I have another dialog box that asks them which image is better (or to rate the displayed images), they always confuse the order of images on the screen with the order of images in the dialog box. That is, if I just order the images 0 1 2 3 etc in a ratings dialog, they assume that image 3 as it's displayed is image 0 in the MDI parent window, image 2 is image 1, etc-- they read left to right, and the images are being displayed right to left. If I reorder the tabs in the ratings dialog box to reflect the order on the screen, that just confuses them further ("Why is image 3 before image 2?") and the results come out in the wrong order, and are generally unusable.</p> <p>So, how do I force the ordering of displayed windows using <code>MDILayout</code> in <code>C#</code>? Do I have to do it by hand, or is there some switch I can send to the layout manager?</p> <p>Thanks!</p>
[ { "answer_id": 64330, "author": "OwenP", "author_id": 2547, "author_profile": "https://Stackoverflow.com/users/2547", "pm_score": 0, "selected": false, "text": "ActivateMdiChild" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64029", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,036
<p>It's a bit difficult to implement a deep object copy function. What steps you take to ensure the original object and the cloned one share no reference? </p>
[ { "answer_id": 64611, "author": "user8690", "author_id": 8690, "author_profile": "https://Stackoverflow.com/users/8690", "pm_score": 6, "selected": false, "text": "org.apache.commons.lang3.SerializationUtils.clone(T)" }, { "answer_id": 228900, "author": "sankara", "author_id": 8286, "author_profile": "https://Stackoverflow.com/users/8286", "pm_score": 3, "selected": false, "text": "private static final XStream XSTREAM = new XStream();\n...\n\nObject newObject = XSTREAM.fromXML(XSTREAM.toXML(obj));\n" }, { "answer_id": 354504, "author": "Julien Chastang", "author_id": 32174, "author_profile": "https://Stackoverflow.com/users/32174", "pm_score": 6, "selected": false, "text": "Object.clone() Object.clone() Object.clone() String" }, { "answer_id": 7432044, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "import com.thoughtworks.xstream.XStream;\n\npublic class deepCopy {\n private static XStream xstream = new XStream();\n\n //serialize with Xstream them deserialize ...\n public static Object deepCopy(Object obj){\n return xstream.fromXML(xstream.toXML(obj));\n }\n}\n" }, { "answer_id": 7596565, "author": "Thargor", "author_id": 970985, "author_profile": "https://Stackoverflow.com/users/970985", "pm_score": 6, "selected": false, "text": "implement serializable ByteArrayOutputStream bos = new ByteArrayOutputStream();\nObjectOutputStream oos = new ObjectOutputStream(bos);\noos.writeObject(object);\noos.flush();\noos.close();\nbos.close();\nbyte[] byteData = bos.toByteArray();\n ByteArrayInputStream bais = new ByteArrayInputStream(byteData);\nObject object = new ObjectInputStream(bais).readObject();\n" }, { "answer_id": 7596965, "author": "Adriaan Koster", "author_id": 181336, "author_profile": "https://Stackoverflow.com/users/181336", "pm_score": 5, "selected": false, "text": "public class Order {\n\n private long number;\n\n public Order() {\n }\n\n /**\n * Copy constructor\n */\n public Order(Order source) {\n number = source.number;\n }\n}\n\n\npublic class Customer {\n\n private String name;\n private List<Order> orders = new ArrayList<Order>();\n\n public Customer() {\n }\n\n /**\n * Copy constructor\n */\n public Customer(Customer source) {\n name = source.name;\n for (Order sourceOrder : source.orders) {\n orders.add(new Order(sourceOrder));\n }\n }\n\n public String getName() {\n return name;\n }\n\n public void setName(String name) {\n this.name = name;\n }\n}\n" }, { "answer_id": 9170760, "author": "Ravi Chinoy", "author_id": 660029, "author_profile": "https://Stackoverflow.com/users/660029", "pm_score": 3, "selected": false, "text": "JsonFactory f = mapper.getFactory(); // may alternatively construct directly too\n\n// First: write simple JSON output\nFile jsonFile = new File(\"test.json\");\nJsonGenerator g = f.createGenerator(jsonFile);\n// write JSON: { \"message\" : \"Hello world!\" }\ng.writeStartObject();\ng.writeStringField(\"message\", \"Hello world!\");\ng.writeEndObject();\ng.close();\n\n// Second: read file back\nJsonParser p = f.createParser(jsonFile);\n\nJsonToken t = p.nextToken(); // Should be JsonToken.START_OBJECT\nt = p.nextToken(); // JsonToken.FIELD_NAME\nif ((t != JsonToken.FIELD_NAME) || !\"message\".equals(p.getCurrentName())) {\n // handle error\n}\nt = p.nextToken();\nif (t != JsonToken.VALUE_STRING) {\n // similarly\n}\nString msg = p.getText();\nSystem.out.printf(\"My message to you is: %s!\\n\", msg);\np.close();\n" }, { "answer_id": 22546839, "author": "CorayThan", "author_id": 1313268, "author_profile": "https://Stackoverflow.com/users/1313268", "pm_score": 5, "selected": false, "text": "Cloner cloner = new Cloner();\n\nMyClass clone = cloner.deepClone(o);\n// clone is a deep-clone of o\n" }, { "answer_id": 28195274, "author": "TheByeByeMan", "author_id": 3437443, "author_profile": "https://Stackoverflow.com/users/3437443", "pm_score": 4, "selected": false, "text": "My_Object object2= org.apache.commons.lang.SerializationUtils.clone(object1);\n" }, { "answer_id": 35429885, "author": "Alfergon", "author_id": 1308202, "author_profile": "https://Stackoverflow.com/users/1308202", "pm_score": 2, "selected": false, "text": "BeanUtils.cloneBean(obj);\n" }, { "answer_id": 40550518, "author": "Arun", "author_id": 3278943, "author_profile": "https://Stackoverflow.com/users/3278943", "pm_score": 1, "selected": false, "text": "public static Object deepClone(Object object) {\n try {\n ByteArrayOutputStream baos = new ByteArrayOutputStream();\n ObjectOutputStream oos = new ObjectOutputStream(baos);\n oos.writeObject(object);\n ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\n ObjectInputStream ois = new ObjectInputStream(bais);\n return ois.readObject();\n }\n catch (Exception e) {\n e.printStackTrace();\n return null;\n }\n }\n\n2)\n\n // (1) create a MyPerson object named Al\n MyAddress address = new MyAddress(\"Vishrantwadi \", \"Pune\", \"India\");\n MyPerson al = new MyPerson(\"Al\", \"Arun\", address);\n\n // (2) make a deep clone of Al\n MyPerson neighbor = (MyPerson)deepClone(al);\n" }, { "answer_id": 40859968, "author": "tiboo", "author_id": 280041, "author_profile": "https://Stackoverflow.com/users/280041", "pm_score": 4, "selected": false, "text": "transient StackOverflowError public static <T> T copy(T anObject, Class<T> classInfo) {\n Gson gson = new GsonBuilder().create();\n String text = gson.toJson(anObject);\n T newObject = gson.fromJson(text, classInfo);\n return newObject;\n}\npublic static void main(String[] args) {\n String originalObject = \"hello\";\n String copiedObject = copy(originalObject, String.class);\n}\n" }, { "answer_id": 45201944, "author": "Ihor Rybak", "author_id": 5810648, "author_profile": "https://Stackoverflow.com/users/5810648", "pm_score": 4, "selected": false, "text": "org.springframework.util.SerializationUtils @SuppressWarnings(\"unchecked\")\npublic static <T extends Serializable> T clone(T object) {\n return (T) SerializationUtils.deserialize(SerializationUtils.serialize(object));\n}\n" }, { "answer_id": 58967446, "author": "Karthik Rao", "author_id": 2164335, "author_profile": "https://Stackoverflow.com/users/2164335", "pm_score": 3, "selected": false, "text": " <T> T clone(T object, Class<T> clazzType) throws IOException {\n\n final ObjectMapper objMapper = new ObjectMapper();\n String jsonStr= objMapper.writeValueAsString(object);\n\n return objMapper.readValue(jsonStr, clazzType);\n\n }\n" }, { "answer_id": 63640212, "author": "mastercool", "author_id": 9604444, "author_profile": "https://Stackoverflow.com/users/9604444", "pm_score": 0, "selected": false, "text": "public class CSVTable implements Serializable{\n Table<Integer, Integer, String> table; \n public CSVTable() {\n this.table = HashBasedTable.create();\n }\n \n public CSVTable deepClone() {\n try {\n ByteArrayOutputStream baos = new ByteArrayOutputStream();\n ObjectOutputStream oos = new ObjectOutputStream(baos);\n oos.writeObject(this);\n\n ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\n ObjectInputStream ois = new ObjectInputStream(bais);\n return (CSVTable) ois.readObject();\n } catch (IOException e) {\n return null;\n } catch (ClassNotFoundException e) {\n return null;\n }\n }\n\n}\n CSVTable table = new CSVTable();\nCSVTable tempTable = table.deepClone();\n" }, { "answer_id": 65584955, "author": "Unmitigated", "author_id": 9513184, "author_profile": "https://Stackoverflow.com/users/9513184", "pm_score": 1, "selected": false, "text": "import java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\nimport java.io.ObjectInputStream;\nimport java.io.ObjectOutputStream;\nimport java.io.Serializable;\n\n@SuppressWarnings(\"unchecked\")\npublic static <T extends Serializable> T deepClone(T t) {\n try (ByteArrayOutputStream baos = new ByteArrayOutputStream();\n ObjectOutputStream oos = new ObjectOutputStream(baos);) {\n oos.writeObject(t);\n byte[] bytes = baos.toByteArray();\n try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {\n return (T) ois.readObject();\n }\n } catch (IOException | ClassNotFoundException e) {\n throw new RuntimeException(e);\n }\n}\n" }, { "answer_id": 71735351, "author": "Fahad Israr", "author_id": 9158840, "author_profile": "https://Stackoverflow.com/users/9158840", "pm_score": 0, "selected": false, "text": "ObjectMapper objectMapper = new ObjectMapper();\n\nMyClass deepCopyObject = objectMapper\n .readValue(objectMapper.writeValueAsString(originalObject), MyClass.class);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3885/" ]
64,038
<p>When I use the default java locale on my linux machine it comes out with the US locale settings, where do I change this so that it comes out with the correct locale?</p>
[ { "answer_id": 64096, "author": "Chris Broadfoot", "author_id": 3947, "author_profile": "https://Stackoverflow.com/users/3947", "pm_score": 6, "selected": false, "text": "user.language user.country user.variant java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass" }, { "answer_id": 9894836, "author": "cayhorstmann", "author_id": 375317, "author_profile": "https://Stackoverflow.com/users/375317", "pm_score": 5, "selected": false, "text": "java -Duser.language=en -Duser.country=US ...\n LC_ALL=en_US.UTF-8 java ...\n" }, { "answer_id": 10646947, "author": "Derzu", "author_id": 1178478, "author_profile": "https://Stackoverflow.com/users/1178478", "pm_score": 2, "selected": false, "text": "$ export LANG=en_US.utf8\n" }, { "answer_id": 24987464, "author": "hiroshi", "author_id": 338986, "author_profile": "https://Stackoverflow.com/users/338986", "pm_score": 4, "selected": false, "text": "jarsigner JAVA_TOOL_OPTIONS=-Duser.language=en jarsigner\n" }, { "answer_id": 29652154, "author": "aseychell", "author_id": 273673, "author_profile": "https://Stackoverflow.com/users/273673", "pm_score": 1, "selected": false, "text": "/etc/default/locale LANG=en.utf8\n source source /etc/default/locale\n" }, { "answer_id": 55067828, "author": "Matthew Buckett", "author_id": 244744, "author_profile": "https://Stackoverflow.com/users/244744", "pm_score": 4, "selected": false, "text": "java -XshowSettings -version\n LANG LC_*" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,041
<p>How do I change font size on the DataGridView?</p>
[ { "answer_id": 64167, "author": "psamwel", "author_id": 3089, "author_profile": "https://Stackoverflow.com/users/3089", "pm_score": 7, "selected": true, "text": " private void UpdateFont()\n {\n //Change cell font\n foreach(DataGridViewColumn c in dgAssets.Columns)\n {\n c.DefaultCellStyle.Font = new Font(\"Arial\", 8.5F, GraphicsUnit.Pixel);\n }\n }\n" }, { "answer_id": 11940259, "author": "Sylvio", "author_id": 1596209, "author_profile": "https://Stackoverflow.com/users/1596209", "pm_score": 0, "selected": false, "text": "' Cell style\n With .DefaultCellStyle\n .BackColor = Color.Black\n .ForeColor = Color.White \n .Font = New System.Drawing.Font(\"Microsoft Sans Serif\", 11.0!,\n System.Drawing.FontStyle.Regular,\n System.Drawing.GraphicsUnit.Point, CType(0, Byte))\n .Alignment = DataGridViewContentAlignment.MiddleRight\n End With\n" }, { "answer_id": 33985972, "author": "Ashraf Sada", "author_id": 2459714, "author_profile": "https://Stackoverflow.com/users/2459714", "pm_score": 5, "selected": false, "text": "this.dataGridView1.DefaultCellStyle.Font = new Font(\"Tahoma\", 15);\n" }, { "answer_id": 45228577, "author": "Niraj Trivedi", "author_id": 3839344, "author_profile": "https://Stackoverflow.com/users/3839344", "pm_score": 3, "selected": false, "text": "DataGridView.Columns[1].DefaultCellStyle.Font = new Font(\"Verdana\", 16, FontStyle.Bold);" }, { "answer_id": 50976003, "author": "Mahmut K.", "author_id": 4431768, "author_profile": "https://Stackoverflow.com/users/4431768", "pm_score": 3, "selected": false, "text": "yourDataGridView.Font = anyLabel.Font;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
64,046
<p>I have a strange problem when I publish my website. I inherited this project and the problem started before I arrived so I don't know what conditions lead to the creation of the problem.</p> <p>Basically, 3 folders below the website project fail to publish properly. When the PrecompiledWeb is transferred to the host these three folders have to be manually copied from the Visual Studio project (i.e. they are no longer the published versions) to the host for it to work.</p> <p>If the results of the publish operation are left, any page in the folder results in the following error:</p> <blockquote> <p>Server Error in '/' Application. Unable to cast object of type 'System.Web.Compilation.BuildResultNoCompilePage' to type 'System.Web.Compilation.BuildResultCompiledType'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p> <p>Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Web.Compilation.BuildResultNoCompilePage' to type 'System.Web.Compilation.BuildResultCompiledType'.</p> <p>Source Error:</p> <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p> <p>Stack Trace:</p> <p>[InvalidCastException: Unable to cast object of type 'System.Web.Compilation.BuildResultNoCompilePage' to type 'System.Web.Compilation.BuildResultCompiledType'.] System.Web.UI.PageParser.GetCompiledPageInstance(VirtualPath virtualPath, String inputFile, HttpContext context) +254<br> System.Web.UI.PageParser.GetCompiledPageInstance(String virtualPath, String inputFile, HttpContext context) +171<br> URLRewrite.URLRewriter.ProcessRequest(HttpContext context) +2183<br> System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +405 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +65</p> <p>Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832</p> </blockquote> <p>Does anyone have any idea what the possible causes of these pages not publishing correctly could be? Anything I can look at that may indicate the root of the problem?</p> <p><strong>Addition:</strong> It is a completely clean build each time, so there shouldn't be a problem with old bin files lying around. I've also checked the datestamp on the items in the bin folder and they are up-to-date.</p> <p><strong>Second Addition:</strong> The project was originally created as a <em>Web Site</em>, not a Web Application. Sorry for the ambiguity.</p>
[ { "answer_id": 1123019, "author": "Mircea Grelus", "author_id": 119138, "author_profile": "https://Stackoverflow.com/users/119138", "pm_score": 0, "selected": false, "text": "aspnet_compiler -errorstack" }, { "answer_id": 32035009, "author": "Abhilash Thomas", "author_id": 1716548, "author_profile": "https://Stackoverflow.com/users/1716548", "pm_score": 0, "selected": false, "text": "<compilation targetFramework=\"4.0\" debug=\"false\" batch=\"false\">\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8152/" ]
64,059
<p>I have some website which requires a logon and shows sensitive information.</p> <p>The person goes to the page, is prompted to log in, then gets to see the information.</p> <p>The person logs out of the site, and is redirected back to the login page.</p> <p>The person then can hit "back" and go right back to the page where the sensitive information is contained. Since the browser just thinks of it as rendered HTML, it shows it to them no problem.</p> <p>Is there a way to prevent that information from being displayed when the person hits the "back" button from the logged out screen? I'm not trying to disable the back button itself, I'm just trying to keep the sensitive information from being displayed again because the person is not logged into the site anymore.</p> <p>For the sake of argument, the above site/scenario is in ASP.NET with Forms Authentication (so when the user goes to the first page, which is the page they want, they're redirected to the logon page - in case that makes a difference).</p>
[ { "answer_id": 64079, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 2, "selected": false, "text": "Response.Cache.SetCacheability(HttpCacheability.NoCache)\n" }, { "answer_id": 64081, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 0, "selected": false, "text": "<META HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">\n" }, { "answer_id": 64086, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 0, "selected": false, "text": "POST" }, { "answer_id": 64091, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 0, "selected": false, "text": "header(\"Expires: Mon, 26 Jul 1997 05:00:00 GMT\");\nheader(\"Cache-Control: no-cache\");\nheader(\"Pragma: no-cache\");\n" }, { "answer_id": 64196, "author": "martin", "author_id": 8421, "author_profile": "https://Stackoverflow.com/users/8421", "pm_score": 0, "selected": false, "text": "Response.Cache.SetCacheability(HttpCacheability.NoCache);\nResponse.Cache.SetNoStore();\nResponse.Cache.SetExpires(DateTime.Now.AddMinutes(-1));\n" }, { "answer_id": 88467, "author": "Claus Thomsen", "author_id": 15555, "author_profile": "https://Stackoverflow.com/users/15555", "pm_score": 5, "selected": true, "text": "Response.Cache.SetCacheability(HttpCacheability.NoCache);\nResponse.Cache.SetExpires(Now.AddSeconds(-1));\nResponse.Cache.SetNoStore();\nResponse.AppendHeader(\"Pragma\", \"no-cache\");\n" }, { "answer_id": 217117, "author": "Kornel", "author_id": 27009, "author_profile": "https://Stackoverflow.com/users/27009", "pm_score": 3, "selected": false, "text": "Cache-Control: must-revalidate document.cookie" }, { "answer_id": 767611, "author": "User", "author_id": 62830, "author_profile": "https://Stackoverflow.com/users/62830", "pm_score": 0, "selected": false, "text": "<meta http-equiv=\"expires\" content=\"0\" />\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2577/" ]
64,061
<p>What Java library would you say is the best for consuming and parsing feeds? Requirements:</p> <ul> <li>Embeddable</li> <li>Supports Atom &amp; RSS</li> <li>Has caching architecture</li> <li>Should be able to deal with any feed format the same way</li> </ul> <p>(Please: <em>one</em> suggestion per answer.)</p>
[ { "answer_id": 4357661, "author": "so_mv", "author_id": 186858, "author_profile": "https://Stackoverflow.com/users/186858", "pm_score": 0, "selected": false, "text": "dormant" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2041950/" ]
64,117
<p>I had to delete all the rows from a log table that contained about 5 million rows. My initial try was to issue the following command in query analyzer:</p> <p>delete from client_log</p> <p>which took a very long time.</p>
[ { "answer_id": 64133, "author": "Martynnw", "author_id": 5466, "author_profile": "https://Stackoverflow.com/users/5466", "pm_score": 1, "selected": false, "text": "Truncate Table" }, { "answer_id": 64156, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 1, "selected": false, "text": "truncate table" }, { "answer_id": 65705, "author": "dar7yl", "author_id": 9505, "author_profile": "https://Stackoverflow.com/users/9505", "pm_score": 3, "selected": false, "text": "CREATE TABLE `new_table` LIKE `table`;\nRENAME TABLE `table` TO `old_table`, `new_table` TO `table`;\n" }, { "answer_id": 108984, "author": "Mark Stock", "author_id": 19737, "author_profile": "https://Stackoverflow.com/users/19737", "pm_score": -1, "selected": false, "text": "DELETE * FROM table_name;\n SELECT DbVendor_SuperFastDeleteAllFunction(tablename, BOZO_BIT) FROM dummy;\n DROP TABLE table_name;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64117", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4096/" ]
64,139
<p>I have a usercontrol that has several public properties. These properties automatically show up in the properties window of the VS2005 designer under the "Misc" category. Except two of the properties which are enumerations don't show up correctly.</p> <p>The first on uses the following enum:</p> <pre><code>public enum VerticalControlAlign { Center, Top, Bottom } </code></pre> <p>This does not show up in the designer <em>at all.</em></p> <p>The second uses this enum:</p> <pre><code>public enum AutoSizeMode { None, KeepInControl } </code></pre> <p>This one shows up, but the designer seems to think it's a bool and only shows True and False. And when you build a project using the controls it will say that it can't convert type bool to AutoSizeMode.</p> <p>Also, these enums are declared globably to the Namespace, so they are accessible everywhere.</p> <p>Any ideas?</p>
[ { "answer_id": 64188, "author": "Thunder3", "author_id": 2832, "author_profile": "https://Stackoverflow.com/users/2832", "pm_score": 0, "selected": false, "text": "batch=\"false\" <compilation> public enum VerticalControlAlign\n{\n Center = 0,\n Top = 1,\n Bottom = 2\n}\n" }, { "answer_id": 64326, "author": "Statement", "author_id": 2166173, "author_profile": "https://Stackoverflow.com/users/2166173", "pm_score": 2, "selected": false, "text": "using System.ComponentModel;\nusing System.Windows.Forms;\n\nnamespace SampleApplication\n{\n public partial class CustomUserControl : UserControl\n {\n public CustomUserControl()\n {\n InitializeComponent();\n }\n\n /// <summary>\n /// We're hiding AutoSizeMode in UserControl here.\n /// </summary>\n public new enum AutoSizeMode { None, KeepInControl }\n public enum VerticalControlAlign { Center, Top, Bottom }\n\n /// <summary>\n /// Note that you cannot have a property \n /// called VerticalControlAlign if it is \n /// already defined in the scope.\n /// </summary>\n [DisplayName(\"VerticalControlAlign\")]\n [Category(\"stackoverflow.com\")]\n [Description(\"Sets the vertical control align\")]\n public VerticalControlAlign VerticalControlAlign_Ugly\n {\n get { return m_align; }\n set { m_align = value; }\n }\n private VerticalControlAlign m_align; \n\n /// <summary>\n /// Note that you cannot have a property \n /// called AutoSizeMode if it is \n /// already defined in the scope.\n /// </summary>\n [DisplayName(\"AutoSizeMode\")]\n [Category(\"stackoverflow.com\")]\n [Description(\"Sets the auto size mode\")]\n public AutoSizeMode AutoSizeMode_Ugly\n {\n get { return m_autoSize; }\n set { m_autoSize = value; }\n }\n private AutoSizeMode m_autoSize; \n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/194/" ]
64,141
<p>In Python is there any way to make a class, then make a second version of that class with identical dat,a but which can be changed, then reverted to be the same as the data in the original class? </p> <p>So I would make a class with the numbers 1 to 5 as the data in it, then make a second class with the same names for sections (or very similar). Mess around with the numbers in the second class then with one function then reset them to be the same as in the first class. </p> <p>The only alternative I've found is to make one aggravatingly long class with too many separate pieces of data in it to be readily usable.</p>
[ { "answer_id": 64163, "author": "Teifion", "author_id": 1384652, "author_profile": "https://Stackoverflow.com/users/1384652", "pm_score": 4, "selected": true, "text": "class dog(object):\n def __init__(self, height, width, lenght):\n self.height = height\n self.width = width\n self.length = length\n\n def revert(self):\n self.height = 1\n self.width = 2\n self.length = 3\n\ndog1 = dog(5, 6, 7)\ndog2 = dog(2, 3, 4)\n\ndog1.revert()\n" }, { "answer_id": 64216, "author": "Drag0n", "author_id": 8433, "author_profile": "https://Stackoverflow.com/users/8433", "pm_score": 1, "selected": false, "text": "class ABC(self):\n numbers = [0,1,2,3]\n\nclass DEF(ABC):\n def __init__(self):\n self.new_numbers = super(ABC,self).numbers\n\n def setnums(self, numbers):\n self.new_numbers = numbers\n\n def getnums(self):\n return self.new_numbers\n\n def reset(self):\n __init__()\n" }, { "answer_id": 64399, "author": "pobk", "author_id": 7829, "author_profile": "https://Stackoverflow.com/users/7829", "pm_score": 1, "selected": false, "text": "class Resettable(object):\n base_dict = {}\n def reset(self):\n self.__dict__ = self.__class__.base_dict\n\n def __init__(self):\n self.__dict__ = self.__class__.base_dict.copy()\n\nclass SomeClass(Resettable):\n base_dict = {\n 'number_one': 1,\n 'number_two': 2,\n 'number_three': 3,\n 'number_four': 4,\n 'number_five': 5,\n }\n def __init__(self):\n Resettable.__init__(self)\n\n\np = SomeClass()\np.number_one = 100\nprint p.number_one\np.reset()\nprint p.number_one\n" }, { "answer_id": 82969, "author": "Steve Losh", "author_id": 13498, "author_profile": "https://Stackoverflow.com/users/13498", "pm_score": 2, "selected": false, "text": "class MyReset:\n def __init__(self, x, y):\n self.x = x\n self.y = y\n self.save()\n\n def save(self):\n self.saved = self.__dict__.copy()\n\n def reset(self):\n self.__dict__ = self.saved.copy()\n\na = MyReset(20, 30)\na.x = 50\nprint a.x\na.reset()\nprint a.x\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8324/" ]
64,146
<p>When a script is saved as a bundle, it can use the <code>localized string</code> command to find the appropriate string, e.g. in <code>Contents/Resources/English.lproj/Localizable.strings</code>. If this is a format string, what is the best way to fill in the placeholders? In other words, what is the AppleScript equivalent of <code>+[NSString stringWithFormat:]</code>?</p> <p>One idea I had was to use <code>do shell script</code> with <code>printf(1)</code>. Is there a better way?</p>
[ { "answer_id": 66899, "author": "nlanza", "author_id": 9373, "author_profile": "https://Stackoverflow.com/users/9373", "pm_score": 0, "selected": false, "text": "printf(1) call method call method \"stringWithFormat:\" of class \"NSString\" with parameters {formatString, arguments}\n" }, { "answer_id": 41405599, "author": "Minh Nguyễn", "author_id": 4585461, "author_profile": "https://Stackoverflow.com/users/4585461", "pm_score": 3, "selected": true, "text": "use framework \"Foundation\"\n\ntell the current application's NSWorkspace's sharedWorkspace to openFile:\"/Users/me/Desktop/filter.png\" withApplication:\"Preview\"\n true\n +[NSString stringWithFormat:] use framework \"Foundation\"\n\nthe current application's NSString's stringWithFormat:{\"%lu documents\", 8}\n error \"-[__NSArrayM length]: unrecognized selector sent to instance 0x7fd8d59f3bf0\" number -10000\n text use framework \"Foundation\"\n\nthe current application's NSString's stringWithFormat_(\"%lu documents\", 8) as text\n \"2087 documents\"\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6311/" ]
64,174
<p>Is there any way to change Firefox system icon (the one on the left top of the window)? </p> <p>Precision : I want to change the icon of a bundled version of Firefox with apache/php and my application. So manual operation on each computer is not a solution. I try Resource Hacker and it's the good solution. The add ons one is good too.</p>
[ { "answer_id": 9433191, "author": "studgeek", "author_id": 255961, "author_profile": "https://Stackoverflow.com/users/255961", "pm_score": 2, "selected": false, "text": "omni.ja omni.ja omni.ja.off icons/default chrome chrome/icons/default/main-window.ico main-window.ico downloadManager.ico bookmark-window.ico omni.ja omni.ja omni.ja" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8404/" ]
64,193
<p>I am using the AJAX Control Toolkit Popup Calendar Control in a datagrid. When it is in the footer it looks fine. When it is in the edit side of the datagrid it is inheriting the style from the datagrid and looks completely different (i.e. too big). </p> <p>Is there a way to alter the CSS so that it does not inherit the style from the datagrid?</p>
[ { "answer_id": 64317, "author": "user8456", "author_id": 8456, "author_profile": "https://Stackoverflow.com/users/8456", "pm_score": 2, "selected": true, "text": "body table tr td table tr {\n /*css goes here */\n\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7316/" ]
64,200
<p>How do I call MySQL stored procedures from Perl? Stored procedure functionality is fairly new to MySQL and the MySQL modules for Perl don't seem to have caught up yet.</p>
[ { "answer_id": 64283, "author": "aggergren", "author_id": 7742, "author_profile": "https://Stackoverflow.com/users/7742", "pm_score": 2, "selected": false, "text": "#!/usr/bin/perl\n#\nuse strict;\nuse DBI qw(:sql_types);\n\nmy $dbh = DBI->connect(\n $ConnStr,\n $User,\n $Password,\n {RaiseError => 1, AutoCommit => 0}\n ) || die \"Database connection not made: $DBI::errstr\";\nmy $sql = qq {CALL someProcedure(1);} } \n\nmy $sth = $dbh->prepare($sql);\neval {\n $sth->bind_param(1, $argument, SQL_VARCHAR);\n};\nif ($@) {\n warn \"Database error: $DBI::errstr\\n\";\n $dbh->rollback(); #just die if rollback is failing\n}\n\n$dbh->commit();\n" }, { "answer_id": 64718, "author": "apenwarr", "author_id": 42219, "author_profile": "https://Stackoverflow.com/users/42219", "pm_score": 3, "selected": false, "text": "mysql> delimiter //\nmysql> create procedure Foo(x int)\n -> begin\n -> select x*2;\n -> end\n -> //\n\nperl -e 'use DBI; DBI->connect(\"dbi:mysql:database=bonk\", \"root\", \"\")->prepare(\"call Foo(?)\")->execute(21)'\n DBD::mysql::st execute failed: PROCEDURE bonk.Foo can't return a result set in the given context at -e line 1.\n" }, { "answer_id": 10406264, "author": "Nexion", "author_id": 1368915, "author_profile": "https://Stackoverflow.com/users/1368915", "pm_score": 2, "selected": false, "text": "#!/usr/bin/perl\n# Stored Proc - Multiple Values In, Multiple Out\nuse strict;\nuse Data::Dumper;\nuse DBI;\nmy $dbh = DBI->connect('DBI:mysql:RTPC;host=db.server.com',\n 'user','password',{ RaiseError => 1 }) || die \"$!\\n\";\nmy $sth = $dbh->prepare('CALL storedProcedure(?,?,?,?,@a,@b);');\n$sth->bind_param(1, 2);\n$sth->bind_param(2, 1003);\n$sth->bind_param(3, 5000);\n$sth->bind_param(4, 100);\n$sth->execute();\nmy $response = $sth->fetchrow_hashref();\nprint Dumper $response . \"\\n\";\n while(my $response = $sth->fetchrow_hashref()) {\n print Dumper $response . \"\\n\";\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,202
<p>I am using SQL Server 2000 and I have two databases that both replicate (transactional push subscription) to a single database. I need to know which database the records came from.</p> <p>So I want to add a fixed column specified in the publication to my table so I can tell which database the row originated from.</p> <p>How do I go about doing this?</p> <p>I would like to avoid altering the main databases mostly due to the fact there are many tables I would need to do this to. I was hoping for some built in feature of replication that would do this for me some where. Other than that I would go with the view idea.</p>
[ { "answer_id": 65508, "author": "Chris Shaffer", "author_id": 6744, "author_profile": "https://Stackoverflow.com/users/6744", "pm_score": 1, "selected": false, "text": "\nALTER TABLE TableName ADD\n MyColumn AS 'Server1'\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2253/" ]
64,204
<p>I am creating a Windows Service in C# that processes messages from a queue. I want to give ops the flexibility of partitioning the service in production according to properties of the message. For example, they should be able to say that one instance processes web orders from Customer A, another batch orders from Customer A, a third web or batch orders from Customer B, and so on.</p> <p>My current solution is to assign separate queues to each customer\source combination. The process that puts orders into the queues has to make the right decision. My Windows Service can be configured to pull messages from one or more queues. It's messy, but it works.</p>
[ { "answer_id": 2133312, "author": "Árpád Varga", "author_id": 258533, "author_profile": "https://Stackoverflow.com/users/258533", "pm_score": 2, "selected": false, "text": "MessageEnumerator en = q.GetMessageEnumerator2();\n\nwhile (en.MoveNext())\n{\n if (en.Current.Label == label)\n {\n string body = ((XmlDocument)en.Current.Body).OuterXml;\n en.RemoveCurrent();\n return body;\n }\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7668/" ]
64,209
<p>I'm reading lines of text that can come in any order. The problem is that the output can actually be indentical to the previous output. How can I detect this, without sorting the output first?</p> <p>Is there some kind of hash function that can take identical input, but in any order, and still produce the same result?</p>
[ { "answer_id": 64236, "author": "Nicholas", "author_id": 8054, "author_profile": "https://Stackoverflow.com/users/8054", "pm_score": 0, "selected": false, "text": "A B C D\nD E F G\nC B A D\n" }, { "answer_id": 67573, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "A B C\nC B A\n HashSet set = new HashSet();\nforeach (item : string) {\n set.add(item);\n}\n O(N) O(NlogN)" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8406/" ]
64,214
<p>I read everywhere that business logic belongs in the models and not in controller but where is the limit? I am toying with a personnal accounting application. </p> <pre><code>Account Entry Operation </code></pre> <p>When creating an operation it is only valid if the corresponding entries are created and linked to accounts so that the operation is balanced for exemple buy a 6-pack :</p> <pre><code>o=Operation.new({:description=&gt;"b33r", :user=&gt;current_user, :date=&gt;"2008/09/15"}) o.entries.build({:account_id=&gt;1, :amount=&gt;15}) o.valid? #=&gt;false o.entries.build({:account_id=&gt;2, :amount=&gt;-15}) o.valid? #=&gt;true </code></pre> <p>Now the form shown to the user in the case of <em>basic operations</em> is simplified to hide away the entries details, the accounts are selected among 5 default by the kind of operation requested by the user (intialise account -> equity to accout, spend assets->expenses, earn revenues->assets, borrow liabilities->assets, pay debt assets->liabilities ...) I want the entries created from default values.</p> <p>I also want to be able to create more complex operations (more than 2 entries). For this second use case I will have a different form where the additional complexity is exposed.This second use case prevents me from including a debit and credit field on the Operation and getting rid of the Entry link. </p> <p>Which is the best form ? Using the above code in a SimpleOperationController as I do for the moment, or defining a new method on the Operation class so I can call Operation.new_simple_operation(params[:operation])</p> <p>Isn't it breaking the separation of concerns to actually create and manipulate Entry objects from the Operation class ?</p> <p>I am not looking for advice on my twisted accounting principles :)</p> <p>edit -- It seems I didn't express myself too clearly. I am not so concerned about the validation. I am more concerned about where the creation logic code should go : </p> <p>assuming the operation on the controller is called spend, when using spend, the params hash would contain : amount, date, description. Debit and credit accounts would be derived from the action which is called, but then I have to create all the objects. Would it be better to have </p> <pre><code>#error and transaction handling is left out for the sake of clarity def spend amount=params[:operation].delete(:amount)#remove non existent Operation attribute op=Operation.new(params[:operation]) #select accounts in some way ... #build entries op.entries.build(...) op.entries.build(...) op.save end </code></pre> <p>or to create a method on Operation that would make the above look like </p> <pre><code>def spend op=Operation.new_simple_operation(params) op.save end </code></pre> <p>this definitely give a much thinner controller and a fatter model, but then the model will create and store instances of other models which is where my problem is.</p>
[ { "answer_id": 64389, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "class Operation < ActiveRecord::Base\n has_many :entries\n validates_associated :entries\nend\n" }, { "answer_id": 66985, "author": "Sixty4Bit", "author_id": 1681, "author_profile": "https://Stackoverflow.com/users/1681", "pm_score": 2, "selected": false, "text": "class Operation\n has_many :entries\n\n def entry_attributes=(entry_attributes)\n entry_attributes.each do |entry|\n entries.build(entry)\n end\n end\n\nend\n\nclass OperationController < ApplicationController\n def create\n @operation = Operation.new(params[:opertaion])\n if @operation.save\n flash[:notice] = \"Successfully saved operation.\"\n redirect_to operations_path\n else\n render :action => 'new'\n end\n end\nend\n class Operation\n # methods from above\n protected\n def validate\n total = 0\n entries.each { |e| t += e.amount }\n errors.add(\"entries\", \"unbalanced transfers\") unless total == 0\n end\nend\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7898/" ]
64,272
<p>I want to create a custom control in C#. But every time I have to fully redraw my control, it flickers, even if I use double buffering (drawing to an Image first, and blitting that).</p> <p>How do I eliminate flicker when I have to fully redraw?</p>
[ { "answer_id": 64507, "author": "Shaun Austin", "author_id": 1120, "author_profile": "https://Stackoverflow.com/users/1120", "pm_score": 5, "selected": true, "text": "SetStyle(ControlStyles.OptimizedDoubleBuffer | \n ControlStyles.UserPaint |\n ControlStyles.AllPaintingInWmPaint, true);\n" }, { "answer_id": 80273, "author": "Eric W", "author_id": 14972, "author_profile": "https://Stackoverflow.com/users/14972", "pm_score": 1, "selected": false, "text": "SetStyle(ControlStyles::UserPaint | ControlStyles::AllDrawingInWmPaint, true);\n" }, { "answer_id": 358239, "author": "Brad Bruce", "author_id": 5008, "author_profile": "https://Stackoverflow.com/users/5008", "pm_score": 3, "selected": false, "text": "SetStyle(ControlStyles.OptimizedDoubleBuffer | \n ControlStyles.UserPaint |\n ControlStyles.AllPaintingInWmPaint, true);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7305/" ]
64,279
<p>We create new sites in IIS 6 (Windows Server 2003) using IIS Manager. When these sites are created in IIS 6, the ASP.NET version defaults to ASP.NET 1.1. We would like it to default to ASP.NET 2.0. The reason this is a problem for us is that when you take any site on the server and switch the ASP.NET version from ASP.NET 1.1 to ASP.NET 2.0, all web sites recycle.</p> <p>Is there a setting in the IIS metabase that controls this or a way to create a site via script that sets the ASP.Net version correctly so that we can avoid the IIS reset when setting up each site?</p>
[ { "answer_id": 68043, "author": "Tim", "author_id": 10363, "author_profile": "https://Stackoverflow.com/users/10363", "pm_score": 4, "selected": false, "text": "aspnet_regiis -lk W3SVC/ aspnet_regiis -sn W3SVC/<Identifier ID>/ROOT/ <Identifier ID> W3SVC/ aspnet_regiis -sn W3SVC/ aspnet_regiis -lk" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,284
<p>Let's say I have a list of categories for navigation on a web app. Rather than selecting from the database for every user, should I add a function call in the application_onStart of the global.asax to fetch that data into an array or collection that is re-used over and over. If my data does not change at all - (Edit - very often), would this be the best way?</p>
[ { "answer_id": 64361, "author": "Al.", "author_id": 7921, "author_profile": "https://Stackoverflow.com/users/7921", "pm_score": 1, "selected": false, "text": "// Create and load the profile object\nx_siteprofile thisprofile = new x_siteprofile(Server.MapPath(String.Concat(config.Path, \"templates/\")));\nApplication.Add(\"SiteProfileX\", thisprofile);\n" }, { "answer_id": 64840, "author": "ADB", "author_id": 3610, "author_profile": "https://Stackoverflow.com/users/3610", "pm_score": 3, "selected": true, "text": "application_onStart() public class Global : System.Web.HttpApplication\n{\n // The key to use in the rest of the web site to retrieve the list\n public const string ListItemKey = \"MyListItemKey\";\n // a class to hold your actual values. This can be use with databinding\n public class NameValuePair\n { \n public string Name{get;set;} \n public string Value{get;set;}\n public NameValuePair(string Name, string Value)\n {\n this.Name = Name;\n this.Value = Value;\n }\n }\n\n protected void Application_Start(object sender, EventArgs e)\n {\n InitializeApplicationVariables();\n }\n\n\n protected void InitializeApplicationVariables()\n {\n List<NameValuePair> listItems = new List<NameValuePair>();\n // replace the following code with your data access code and fill in the collection\n listItems.Add( new NameValuePair(\"Item1\", \"1\"));\n listItems.Add( new NameValuePair(\"Item2\", \"2\"));\n listItems.Add( new NameValuePair(\"Item3\", \"3\"));\n // load it in the application object\n Application[ListItemKey] = listItems;\n }\n }\n <asp:DropDownList runat=\"server\" ID=\"ddList\" DataTextField=\"Name\" DataValueField=\"Value\"></asp:DropDownList>\n protected override void OnPreInit(EventArgs e)\n{\n ddList.DataSource = Application[Global.ListItemKey];\n ddList.DataBind();\n base.OnPreInit(e);\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1115144/" ]
64,291
<p>I'm working on an application that needs to quickly render simple 3D scenes on the server, and then return them as a JPEG via HTTP. Basically, I want to be able to simply include a dynamic 3D scene in an HTML page, by doing something like:</p> <pre><code>&lt;img src="http://www.myserver.com/renderimage?scene=1&amp;x=123&amp;y=123&amp;z=123"&gt; </code></pre> <p>My question is about what technologies to use to do the rendering. In a desktop application I would quite naturally use DirectX, but I'm afraid it might not be ideal for a server-side application that would be creating images for dozens or even hundreds of users in tandem. Does anyone have any experience with this? Is there a 3D API (preferably freely available) that would be ideal for this application? Is it better to write a software renderer from scratch?</p> <p>My main concerns about using DirectX or OpenGL, is whether it will function well in a virtualized server environment, and whether it makes sense with typical server hardware (over which I have little control). </p>
[ { "answer_id": 12820722, "author": "Janus Troelsen", "author_id": 309483, "author_profile": "https://Stackoverflow.com/users/309483", "pm_score": 2, "selected": false, "text": "<?php\nchdir(\"/tmp\");\n@unlink(\"demo.png\");\nsystem(\"~janus/.wine/drive_c/POV-Ray-v3.7-RC6/bin/pvengine-sse2.exe /render demo.pov /exit\");\nheader(\"Content-type: image/png\");\nfpassthru($f = fopen(\"demo.png\",\"r\"));\nfclose($f);\n?>\n demo.pov" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8409/" ]
64,311
<p>The design for the website I am working on calls for a custom image on lists instead of a bullet. Using the image is fine, but I have been having difficulties ensuring that it is centered against the text of the list item across all browsers. Does anyone know of a standard solution for this?</p>
[ { "answer_id": 64340, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 0, "selected": false, "text": "li\n{\n background-image: URL('custom.png');\n background-repeat: no-repeat;\n background-position: center;\n}\n" }, { "answer_id": 64635, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": true, "text": "ul li {\n background: transparent url(/link/to/custom/bullet.gif) no-repeat 0 50%; \n padding-left: 18px; \n}\n" }, { "answer_id": 14220281, "author": "dottwatson", "author_id": 540283, "author_profile": "https://Stackoverflow.com/users/540283", "pm_score": 0, "selected": false, "text": "li { height: 150px; line-height: 150px; }\nli img { vertical-align: middle; }\n <li><img src=\"myimage.jpg\" /></li>\n li img { max-width: 150px; max-height: 150px; width: auto; height: auto; }\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4284/" ]
64,321
<p>You write a function and, looking at the resulting assembly, you see it can be improved.</p> <p>You would like to keep the function you wrote, for readability, but you would like to substitute your own assembly for the compiler's. Is there any way to establish a relationship between your high-livel language function and the new assembly?</p>
[ { "answer_id": 64460, "author": "spoulson", "author_id": 3347, "author_profile": "https://Stackoverflow.com/users/3347", "pm_score": 1, "selected": false, "text": "__asm { } extern \"C\"" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8522/" ]
64,333
<p>What do I lose by adopting test driven design?</p> <p>List only negatives; do not list benefits written in a negative form.</p>
[ { "answer_id": 64358, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": -1, "selected": false, "text": "private" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8509/" ]
64,351
<p>I'm trying to load a page that is basically an edit form inside a dialog (ui.dialog). I can load this page fine from an external (I'm using asp.net) page.</p> <p>The problem is that inside of my "popup" form, I need to <code>$(function() {my function here});</code> syntax to do some stuff when the page loads, along with registering some <code>.fn</code> extensions for some dynamic dropdowns using ajax calls.</p> <p>I have created my <code>&lt;script type="text/javascript" src="jquery.js"&gt;</code> but I don't think these are being included, and also my <code>$(function)</code> is not being called.</p> <p>Is this possible to do or do I need to find another way of accomplishing what I need to do? </p>
[ { "answer_id": 64515, "author": "Alexey Lebedev", "author_id": 8338, "author_profile": "https://Stackoverflow.com/users/8338", "pm_score": 3, "selected": true, "text": "$.ajax({\n //...\n success: function(text) {\n // insert text into container\n // the code from $(function() {});\n }\n});\n" }, { "answer_id": 164960, "author": "Ben Crouse", "author_id": 6705, "author_profile": "https://Stackoverflow.com/users/6705", "pm_score": 0, "selected": false, "text": "$()\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8534/" ]
64,360
<p>When I cut (kill) text in Emacs 22.1.1 (in its own window on X, in KDE, on Kubuntu), I can't paste (yank) it in any other application.</p>
[ { "answer_id": 64558, "author": "memius", "author_id": 8522, "author_profile": "https://Stackoverflow.com/users/8522", "pm_score": 8, "selected": true, "text": ".emacs (setq x-select-enable-clipboard t)\n" }, { "answer_id": 65473, "author": "Chris Conway", "author_id": 1412, "author_profile": "https://Stackoverflow.com/users/1412", "pm_score": 7, "selected": false, "text": "kill-ring-save yank (setq x-select-enable-clipboard t) .emacs META-X set-variable RET x-select-enable-clipboard RET t\n" }, { "answer_id": 69657, "author": "jfm3", "author_id": 11138, "author_profile": "https://Stackoverflow.com/users/11138", "pm_score": 4, "selected": false, "text": "(setq x-select-enable-clipboard t)\n(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)\n" }, { "answer_id": 19625063, "author": "RussellStewart", "author_id": 2237635, "author_profile": "https://Stackoverflow.com/users/2237635", "pm_score": 4, "selected": false, "text": "sudo apt-get install xsel (defun copy-to-clipboard ()\n (interactive)\n (if (display-graphic-p)\n (progn\n (message \"Yanked region to x-clipboard!\")\n (call-interactively 'clipboard-kill-ring-save)\n )\n (if (region-active-p)\n (progn\n (shell-command-on-region (region-beginning) (region-end) \"xsel -i -b\")\n (message \"Yanked region to clipboard!\")\n (deactivate-mark))\n (message \"No region active; can't yank to clipboard!\")))\n )\n\n(defun paste-from-clipboard ()\n (interactive)\n (if (display-graphic-p)\n (progn\n (clipboard-yank)\n (message \"graphics active\")\n )\n (insert (shell-command-to-string \"xsel -o -b\"))\n )\n )\n\n(global-set-key [f8] 'copy-to-clipboard)\n(global-set-key [f9] 'paste-from-clipboard)\n" }, { "answer_id": 28902747, "author": "cevaris", "author_id": 3538289, "author_profile": "https://Stackoverflow.com/users/3538289", "pm_score": 3, "selected": false, "text": "M-w (defun copy-from-osx ()\n (shell-command-to-string \"pbpaste\"))\n(defun paste-to-osx (text &optional push)\n (let ((process-connection-type nil))\n (let ((proc (start-process \"pbcopy\" \"*Messages*\" \"pbcopy\")))\n (process-send-string proc text)\n (process-send-eof proc))))\n\n(setq interprogram-cut-function 'paste-to-osx)\n(setq interprogram-paste-function 'copy-from-osx)\n" }, { "answer_id": 45417273, "author": "user1404316", "author_id": 1404316, "author_profile": "https://Stackoverflow.com/users/1404316", "pm_score": 1, "selected": false, "text": "region-active-p use-region-p (defun my-copy-to-xclipboard(arg)\n (interactive \"P\")\n (cond\n ((not (use-region-p))\n (message \"Nothing to yank to X-clipboard\"))\n ((and (not (display-graphic-p))\n (/= 0 (shell-command-on-region\n (region-beginning) (region-end) \"xsel -i -b\")))\n (error \"Is program `xsel' installed?\"))\n (t\n (when (display-graphic-p)\n (call-interactively 'clipboard-kill-ring-save))\n (message \"Yanked region to X-clipboard\")\n (when arg\n (kill-region (region-beginning) (region-end)))\n (deactivate-mark))))\n\n(defun my-cut-to-xclipboard()\n (interactive)\n (my-copy-to-xclipboard t))\n\n(defun my-paste-from-xclipboard()\n \"Uses shell command `xsel -o' to paste from x-clipboard. With\none prefix arg, pastes from X-PRIMARY, and with two prefix args,\npastes from X-SECONDARY.\"\n (interactive)\n (if (display-graphic-p)\n (clipboard-yank)\n (let*\n ((opt (prefix-numeric-value current-prefix-arg))\n (opt (cond\n ((= 1 opt) \"b\")\n ((= 4 opt) \"p\")\n ((= 16 opt) \"s\"))))\n (insert (shell-command-to-string (concat \"xsel -o -\" opt))))))\n\n(global-set-key (kbd \"C-c C-w\") 'my-cut-to-xclipboard)\n(global-set-key (kbd \"C-c M-w\") 'my-copy-to-xclipboard)\n(global-set-key (kbd \"C-c C-y\") 'my-paste-from-xclipboard)\n" }, { "answer_id": 56587135, "author": "asmeurer", "author_id": 161801, "author_profile": "https://Stackoverflow.com/users/161801", "pm_score": 2, "selected": false, "text": "C-x C-w C-x C-y ;; Commands to interact with the clipboard\n\n(defun osx-copy (beg end)\n (interactive \"r\")\n (call-process-region beg end \"pbcopy\"))\n\n(defun osx-paste ()\n (interactive)\n (if (region-active-p) (delete-region (region-beginning) (region-end)) nil)\n (call-process \"pbpaste\" nil t nil))\n\n(defun linux-copy (beg end)\n (interactive \"r\")\n (call-process-region beg end \"xclip\" nil nil nil \"-selection\" \"c\"))\n\n(defun linux-paste ()\n (interactive)\n (if (region-active-p) (delete-region (region-beginning) (region-end)) nil)\n (call-process \"xsel\" nil t nil \"-b\"))\n\n(cond\n ((string-equal system-type \"darwin\") ; Mac OS X\n (define-key global-map (kbd \"C-x C-w\") 'osx-copy)\n (define-key global-map (kbd \"C-x C-y\") 'osx-paste))\n ((string-equal system-type \"gnu/linux\") ; linux\n (define-key global-map (kbd \"C-x C-w\") 'linux-copy)\n (define-key global-map (kbd \"C-x C-y\") 'linux-paste)))\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8522/" ]
64,387
<p><strong>Emacs</strong>: <code>C-U (79) #</code> &raquo; a pretty 79 character length divider</p> <p><strong>VIM</strong>: <code>79-i-#</code> &raquo; see above</p> <p><strong><a href="http://macromates.com/" rel="nofollow noreferrer">Textmate</a></strong>: ????</p> <p>Or is it just assumed that we'll make a Ruby call or have a snippet somewhere?</p>
[ { "answer_id": 64975, "author": "pjbeardsley", "author_id": 6812, "author_profile": "https://Stackoverflow.com/users/6812", "pm_score": 2, "selected": false, "text": "python -c \"print '#' * $TM_SELECTED_TEXT\"\n" }, { "answer_id": 91221, "author": "Matt", "author_id": 15368, "author_profile": "https://Stackoverflow.com/users/15368", "pm_score": 1, "selected": false, "text": "python -c \"print '#' * $TM_SELECTED_TEXT\"\n tab trigger '--' `python -c \"print '_' * $TM_COLUMNS\"`\n --⇥" }, { "answer_id": 1676726, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "`python -c \"print ':'.join('$TM_SELECTED_TEXT'.split(':')[:-1]) * int('$TM_SELECTED_TEXT'.split(':')[-1])\"`\n -x:4 ::4" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,388
<p>I'm trying to use Visual Studio 2008's extensibility to write an addin that will create a project folder with various messages in it after parsing an interface. I'm having trouble at the step of creating/adding the folder, however. I've tried using </p> <pre><code>ProjectItem folder = item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty); </code></pre> <p>(item is my target file next to which I'm creating a folder with the same name but "Messages" appended to it) but it chokes when a folder already exists (no big surprise).</p> <p>I tried deleting it if it already exists, such as: </p> <pre><code>DirectoryInfo dirInfo = new DirectoryInfo(newDirectoryParent + newDirectoryName); if (dirInfo.Exists) { dirInfo.Delete(true); } ProjectItem folder = item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty); </code></pre> <p>I can SEE that the folder gets deleted when in debug, but it still seems to think the folder is still there and dies on a folder already exists exception. </p> <p>Any ideas??? </p> <p>Thanks. </p> <p>AK </p> <p>.... Perhaps the answer would lie in programmatically refreshing the project after the delete? How might this be done?</p>
[ { "answer_id": 64901, "author": "Andrew", "author_id": 8586, "author_profile": "https://Stackoverflow.com/users/8586", "pm_score": 2, "selected": false, "text": "DirectoryInfo dirInfo = new DirectoryInfo(newDirectoryParent + newDirectoryName);\n\nif (dirInfo.Exists)\n{\n dirInfo.Delete(true);\n item.DTE.ExecuteCommand(\"View.Refresh\", string.Empty);\n}\n\nProjectItem folder = item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty);\n" }, { "answer_id": 1209338, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<ItemGroup>\n <compile include=\"\\path\\rootFolderToInclude\\**\\*.cs\" />\n</ItemGroup>\n" }, { "answer_id": 5586467, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "ProjectItem pi = null;\nvar dir = Path.Combine(\n project.Properties.Item(\"LocalPath\").Value.ToString(), SubdirectoryName);\nif (Directory.Exists(dir))\n pi = target.ProjectItems.AddFromDirectory(dir);\nelse\n pi = target.ProjectItems.AddFolder(dir);\n" }, { "answer_id": 6512963, "author": "isaacfi", "author_id": 819963, "author_profile": "https://Stackoverflow.com/users/819963", "pm_score": 2, "selected": false, "text": "//Getting the current project\nprivate DTE2 _applicationObject;\nSystem.Array projs = (System.Array)_applicationObject.ActiveSolutionProjects;\nProject proy=(Project)projs.GetValue(0);\n//Getting the path\nstring path=proy.FullName.Substring(0,proy.FullName.LastIndexOf('\\\\'));\n//Valitating if the path exists\nbool existsDirectory= Directory.Exists(path + \"\\\\Directory\");\n//Deleting and creating the Directory\nif (existeClasses)\n Directory.Delete(path + \"\\\\Directory\", true);\nDirectory.CreateDirectory(path + \"\\\\Directory\");\n//Including in the project\nproy.ProjectItems.AddFromDirectory(path + \"\\\\Directory\");\n" }, { "answer_id": 64846113, "author": "Persian Brat", "author_id": 10132738, "author_profile": "https://Stackoverflow.com/users/10132738", "pm_score": 1, "selected": false, "text": "AddFolder(folderName) AddFolder(fullPath)" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64388", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8586/" ]
64,426
<p>I'm looking for a good server/client protocol supported in Python for making data requests/file transfers between one server and many clients. Security is also an issue - so secure login would be a plus. I've been looking into XML-RPC, but it looks to be a pretty old (and possibly unused these days?) protocol.</p>
[ { "answer_id": 64489, "author": "Will Harris", "author_id": 4702, "author_profile": "https://Stackoverflow.com/users/4702", "pm_score": 2, "selected": false, "text": "urllib" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8585/" ]
64,432
<p>I have inherited a large legacy ColdFusion app. There are hundreds of &lt;cfquery&gt;some sql here #variable#&lt;/cfquery&gt; statements that need to be parameterized along the lines of: &lt;cfquery&gt; some sql here &lt;cfqueryparam value="#variable#"/&gt; &lt;/cfquery&gt;</p> <p>How can I go about adding parameterization programmatically?</p> <p>I have thought about writing some regular expression or sed/awk'y sort of solution, but it seems like somebody somewhere has tackled such a problem. Bonus points awarded for inferring the sql type automatically.</p>
[ { "answer_id": 72772, "author": "betelgeuce", "author_id": 366182, "author_profile": "https://Stackoverflow.com/users/366182", "pm_score": 1, "selected": false, "text": "<cf_inputFilter\n scopes = \"FORM,COOKIE,URL\"\n chars = \"<,>,!,&,|,%,=,(,),',{,}\"\n tags=\"script,embed,applet,object,HTML\">\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8563/" ]
64,436
<p>I'm using Excel VBA to a write a UDF. I would like to overload my own UDF with a couple of different versions so that different arguments will call different functions. </p> <p>As VBA doesn't seem to support this, could anyone suggest a good, non-messy way of achieving the same goal? Should I be using Optional arguments or is there a better way?</p>
[ { "answer_id": 64494, "author": "theo", "author_id": 7870, "author_profile": "https://Stackoverflow.com/users/7870", "pm_score": 0, "selected": false, "text": "Foo_DescriptiveName1()\n\nFoo_DescriptiveName2()\n" }, { "answer_id": 70526, "author": "Joel Spolsky", "author_id": 4, "author_profile": "https://Stackoverflow.com/users/4", "pm_score": 7, "selected": true, "text": "Optional Variants IsMissing() TypeName() Public Function Foo(Optional v As Variant) As Variant\n\n If IsMissing(v) Then\n Foo = \"Missing argument\"\n ElseIf TypeName(v) = \"String\" Then\n Foo = v & \" plus one\"\n Else\n Foo = v + 1\n End If\n\nEnd Function\n" }, { "answer_id": 71162, "author": "Mike Woodhouse", "author_id": 1060, "author_profile": "https://Stackoverflow.com/users/1060", "pm_score": 3, "selected": false, "text": "Public Function Morph(ParamArray Args())\n\n Select Case UBound(Args)\n Case -1 '' nothing supplied\n Morph = Morph_NoParams()\n Case 0\n Morph = Morph_One_Param(Args(0))\n Case 1\n Morph = Two_Param_Morph(Args(0), Args(1))\n Case Else\n Morph = CVErr(xlErrRef)\n End Select\n\nEnd Function\n\nPrivate Function Morph_NoParams()\n Morph_NoParams = \"I'm parameterless\"\nEnd Function\n\nPrivate Function Morph_One_Param(arg)\n Morph_One_Param = \"I has a parameter, it's \" & arg\nEnd Function\n\nPrivate Function Two_Param_Morph(arg0, arg1)\n Two_Param_Morph = \"I is in 2-params and they is \" & arg0 & \",\" & arg1\nEnd Function\n Public Function MorphBySig(ParamArray args())\n\nDim sig As String\nDim idx As Long\nDim MorphInstance As MorphClass\n\n For idx = LBound(args) To UBound(args)\n sig = sig & TypeName(args(idx))\n Next\n\n Set MorphInstance = New MorphClass\n\n MorphBySig = CallByName(MorphInstance, \"Morph_\" & sig, VbMethod, args)\n\nEnd Function\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/69157/" ]
64,469
<p>I have a VB6 program that someone recently helped me convert to VB.NET</p> <p>In the program, when saving files, I stamp them with the date which I was getting by calling the Today() function. </p> <p>When I try to run the new VB.NET code in Vista it throws a permission exception for the Today() . If I run Visual Studio Express (this is the 2008 Express version) in Admin mode, then the problem doesn't occur, but clearly I want to end up with a stand-alone program which runs for all users without fancy permissions.</p> <p>So how can a normal VB.NET program in Vista get today's date?</p>
[ { "answer_id": 64521, "author": "David J. Sokol", "author_id": 1390, "author_profile": "https://Stackoverflow.com/users/1390", "pm_score": 4, "selected": true, "text": "DateTime.Now DateTime.Today Len() Left() Right() OpenFile() FreeFile()" }, { "answer_id": 64526, "author": "SqlRyan", "author_id": 8114, "author_profile": "https://Stackoverflow.com/users/8114", "pm_score": 0, "selected": false, "text": "Dim result As String = Today()\n Today() Dim result As String = Now()\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8482/" ]
64,498
<p>Can you specialize a template method within a template class without specializing the class template parameter?</p> <p>Please note that the specialization is on the <em>value</em> of the template parameter, not its type.</p> <p>This seems to compile under Visual Studio 2008 SP1 complier, but not GCC 4.2.4.</p> <pre><code>#include &lt;iostream&gt; using namespace std; template &lt;typename T&gt; class A { private: template &lt;bool b&gt; void testme(); template &lt;&gt; void testme&lt;true&gt;() { cout &lt;&lt; "true" &lt;&lt; endl; }; template &lt;&gt; void testme&lt;false&gt;() { cout &lt;&lt; "false" &lt;&lt; endl; }; public: void test(); }; template&lt;typename T&gt; struct select {}; template&lt;&gt; struct select&lt;int&gt; { static const bool value = true; }; template&lt;&gt; struct select&lt;double&gt; { static const bool value = false; }; template &lt;class T&gt; void A&lt;T&gt;::test() { testme&lt;select&lt;T&gt;::value&gt;(); } int main(int argc, const char* argv[]) { A&lt;int&gt; aInt; A&lt;double&gt; aDouble; aInt.test(); aDouble.test(); return 0; } </code></pre> <p>GCC tells me:"error: explicit specialization in non-namespace scope ‘class A’"</p> <p>If it is not supported in the standard, can anyone tell me why?</p>
[ { "answer_id": 64824, "author": "moswald", "author_id": 8368, "author_profile": "https://Stackoverflow.com/users/8368", "pm_score": 2, "selected": false, "text": "template<typename ty>\nclass A\n{\npublic:\n void foo(bool b);\n void foo(int i);\n};\n template<typename ty>\nclass A\n{\npublic:\n template<typename ty2>\n void foo(ty2);\n\n template<>\n void foo(bool b);\n\n template<>\n void foo(int i);\n};\n" }, { "answer_id": 67478, "author": "Bronek", "author_id": 10042, "author_profile": "https://Stackoverflow.com/users/10042", "pm_score": 2, "selected": true, "text": "template <typename T>\nstruct select;\n\ntemplate <bool B>\nstruct testme_helper\n{\n void operator()();\n};\n\ntemplate <typename T>\nclass A\n{\nprivate:\n template <bool B> void testme()\n {\n testme_helper<B>()();\n }\n\npublic:\n void test()\n {\n testme<select<T>::value>();\n }\n};\n\ntemplate<> void testme_helper<true>::operator()()\n{\n std::cout << \"true\" << std::endl;\n}\n\ntemplate<> void testme_helper<false>::operator()()\n{\n std::cout << \"false\" << std::endl;\n}\n" }, { "answer_id": 275212, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 2, "selected": false, "text": "template<typename A>\nstruct SomeTempl {\n template<bool C> typename enable_if<C>::type \n SomeOtherTempl() {\n std::cout << \"true!\";\n }\n\n template<bool C> typename enable_if<!C>::type \n SomeOtherTempl() {\n std::cout << \"false!\";\n }\n};\n enable_if enable_if enable_if_c" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8524/" ]
64,505
<p>I'm using the following method to send mail from Python using SMTP. Is it the right method to use or are there gotchas I'm missing ?</p> <pre><code>from smtplib import SMTP import datetime debuglevel = 0 smtp = SMTP() smtp.set_debuglevel(debuglevel) smtp.connect('YOUR.MAIL.SERVER', 26) smtp.login('USERNAME@DOMAIN', 'PASSWORD') from_addr = "John Doe &lt;[email protected]&gt;" to_addr = "[email protected]" subj = "hello" date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" ) message_text = "Hello\nThis is a mail from your server\n\nBye\n" msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr, subj, date, message_text ) smtp.sendmail(from_addr, to_addr, msg) smtp.quit() </code></pre>
[ { "answer_id": 64554, "author": "pjz", "author_id": 8002, "author_profile": "https://Stackoverflow.com/users/8002", "pm_score": 3, "selected": false, "text": ".login() .sendmail() .connect()" }, { "answer_id": 64890, "author": "Vincent Marchetti", "author_id": 8935, "author_profile": "https://Stackoverflow.com/users/8935", "pm_score": 8, "selected": true, "text": "#! /usr/local/bin/python\n\n\nSMTPserver = 'smtp.att.yahoo.com'\nsender = 'me@my_email_domain.net'\ndestination = ['recipient@her_email_domain.com']\n\nUSERNAME = \"USER_NAME_FOR_INTERNET_SERVICE_PROVIDER\"\nPASSWORD = \"PASSWORD_INTERNET_SERVICE_PROVIDER\"\n\n# typical values for text_subtype are plain, html, xml\ntext_subtype = 'plain'\n\n\ncontent=\"\"\"\\\nTest message\n\"\"\"\n\nsubject=\"Sent from Python\"\n\nimport sys\nimport os\nimport re\n\nfrom smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)\n# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)\n\n# old version\n# from email.MIMEText import MIMEText\nfrom email.mime.text import MIMEText\n\ntry:\n msg = MIMEText(content, text_subtype)\n msg['Subject']= subject\n msg['From'] = sender # some SMTP servers will do this automatically, not all\n\n conn = SMTP(SMTPserver)\n conn.set_debuglevel(False)\n conn.login(USERNAME, PASSWORD)\n try:\n conn.sendmail(sender, destination, msg.as_string())\n finally:\n conn.quit()\n\nexcept:\n sys.exit( \"mail failed; %s\" % \"CUSTOM_ERROR\" ) # give an error message\n" }, { "answer_id": 275124, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": false, "text": "...\nsmtp.connect('YOUR.MAIL.SERVER', 587)\nsmtp.ehlo()\nsmtp.starttls()\nsmtp.ehlo()\nsmtp.login('USERNAME@DOMAIN', 'PASSWORD')\n...\n" }, { "answer_id": 11228560, "author": "Satish", "author_id": 1159538, "author_profile": "https://Stackoverflow.com/users/1159538", "pm_score": 3, "selected": false, "text": "import smtplib\n\nSERVER = \"localhost\"\n\nFROM = \"[email protected]\"\nTO = [\"[email protected]\"] # must be a list\n\nSUBJECT = \"Hello!\"\n\nTEXT = \"This message was sent with Python's smtplib.\"\n\n# Prepare actual message\n\nmessage = \"\"\"\\\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n\"\"\" % (FROM, \", \".join(TO), SUBJECT, TEXT)\n\n# Send the mail\n\nserver = smtplib.SMTP(SERVER)\nserver.sendmail(FROM, TO, message)\nserver.quit()\n" }, { "answer_id": 17596848, "author": "madman2890", "author_id": 1813869, "author_profile": "https://Stackoverflow.com/users/1813869", "pm_score": 7, "selected": false, "text": "import smtplib\nfrom email.MIMEMultipart import MIMEMultipart\nfrom email.MIMEText import MIMEText\n\nmsg = MIMEMultipart()\nmsg['From'] = '[email protected]'\nmsg['To'] = '[email protected]'\nmsg['Subject'] = 'simple email in python'\nmessage = 'here is the email'\nmsg.attach(MIMEText(message))\n\nmailserver = smtplib.SMTP('smtp.gmail.com',587)\n# identify ourselves to smtp gmail client\nmailserver.ehlo()\n# secure our email with tls encryption\nmailserver.starttls()\n# re-identify ourselves as an encrypted connection\nmailserver.ehlo()\nmailserver.login('[email protected]', 'mypassword')\n\nmailserver.sendmail('[email protected]','[email protected]',msg.as_string())\n\nmailserver.quit()\n" }, { "answer_id": 26191922, "author": "Abdul Majeed", "author_id": 5629004, "author_profile": "https://Stackoverflow.com/users/5629004", "pm_score": 3, "selected": false, "text": "import smtplib\n \nto = '[email protected]'\ngmail_user = '[email protected]'\ngmail_pwd = 'yourpassword'\nsmtpserver = smtplib.SMTP(\"smtp.gmail.com\",587)\nsmtpserver.ehlo()\nsmtpserver.starttls()\nsmtpserver.ehlo()\nsmtpserver.login(gmail_user, gmail_pwd)\nheader = 'To:' + to + '\\n' + 'From: ' + gmail_user + '\\n' + 'Subject:testing \\n'\nprint header\nmsg = header + '\\n this is test msg from mkyong.com \\n\\n'\nsmtpserver.sendmail(gmail_user, to, msg)\nprint 'done!'\nsmtpserver.quit()\n" }, { "answer_id": 29720511, "author": "PascalVKooten", "author_id": 1575066, "author_profile": "https://Stackoverflow.com/users/1575066", "pm_score": 2, "selected": false, "text": "import yagmail\nyag = yagmail.SMTP('[email protected]', host = 'YOUR.MAIL.SERVER', port = 26)\n yag.send('[email protected]', 'hello', 'Hello\\nThis is a mail from your server\\n\\nBye\\n')\n yagmail" }, { "answer_id": 50230501, "author": "Skiller Dz", "author_id": 8808047, "author_profile": "https://Stackoverflow.com/users/8808047", "pm_score": 2, "selected": false, "text": "import smtplib\nfrom email.mime.text import MIMEText\nfrom email.header import Header\n\n\nserver = smtplib.SMTP('mail.servername.com', 25)\nserver.ehlo()\nserver.starttls()\n\nserver.login('username', 'password')\nfrom = '[email protected]'\nto = '[email protected]'\nbody = 'That A Message For My Girl Friend For tell Him If We will go to eat Something This Nigth'\nsubject = 'Invite to A Diner'\nmsg = MIMEText(body,'plain','utf-8')\nmsg['Subject'] = Header(subject, 'utf-8')\nmsg['From'] = Header(from, 'utf-8')\nmsg['To'] = Header(to, 'utf-8')\nmessage = msg.as_string()\nserver.sendmail(from, to, message)\n" }, { "answer_id": 51680874, "author": "Mark", "author_id": 622306, "author_profile": "https://Stackoverflow.com/users/622306", "pm_score": 1, "selected": false, "text": "#!/usr/bin/env python3\n\nfrom email.message import EmailMessage\nfrom getpass import getpass\nfrom smtplib import SMTP_SSL\nfrom sys import exit\n\nsmtp_server = 'smtp.gmail.com'\nusername = '[email protected]'\npassword = getpass('Enter Gmail password: ')\n\nsender = '[email protected]'\ndestination = '[email protected]'\nsubject = 'Sent from Python 3.x'\ncontent = 'Hello! This was sent to you via Python 3.x!'\n\n# Create a text/plain message\nmsg = EmailMessage()\nmsg.set_content(content)\n\nmsg['Subject'] = subject\nmsg['From'] = sender\nmsg['To'] = destination\n\ntry:\n s = SMTP_SSL(smtp_server)\n s.login(username, password)\n try:\n s.send_message(msg)\n finally:\n s.quit()\n\nexcept Exception as E:\n exit('Mail failed: {}'.format(str(E)))\n" }, { "answer_id": 55473040, "author": "Hariharan AR", "author_id": 8612590, "author_profile": "https://Stackoverflow.com/users/8612590", "pm_score": 2, "selected": false, "text": "import smtplib, ssl\n\nsmtp_server = \"smtp.gmail.com\"\nport = 587 # For starttls\nsender_email = \"sender@email\"\nreceiver_email = \"receiver@email\"\npassword = \"<your password here>\"\nmessage = \"\"\" Subject: Hi there\n\nThis message is sent from Python.\"\"\"\n\n\n# Create a secure SSL context\ncontext = ssl.create_default_context()\n\n# Try to log in to server and send email\nserver = smtplib.SMTP(smtp_server,port)\n\ntry:\n server.ehlo() # Can be omitted\n server.starttls(context=context) # Secure the connection\n server.ehlo() # Can be omitted\n server.login(sender_email, password)\n server.sendmail(sender_email, receiver_email, message)\nexcept Exception as e:\n # Print any error messages to stdout\n print(e)\nfinally:\n server.quit()\n" }, { "answer_id": 60511210, "author": "Robert Lujo", "author_id": 565525, "author_profile": "https://Stackoverflow.com/users/565525", "pm_score": 2, "selected": false, "text": "import smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\ndef send_email(host, port, user, pwd, recipients, subject, body, html=None, from_=None):\n \"\"\" copied and adapted from\n https://stackoverflow.com/questions/10147455/how-to-send-an-email-with-gmail-as-provider-using-python#12424439\n returns None if all ok, but if problem then returns exception object\n \"\"\"\n\n PORT_LIST = (25, 587, 465)\n\n FROM = from_ if from_ else user \n TO = recipients if isinstance(recipients, (list, tuple)) else [recipients]\n SUBJECT = subject\n TEXT = body.encode(\"utf8\") if isinstance(body, unicode) else body\n HTML = html.encode(\"utf8\") if isinstance(html, unicode) else html\n\n if not html:\n # Prepare actual message\n message = \"\"\"From: %s\\nTo: %s\\nSubject: %s\\n\\n%s\n \"\"\" % (FROM, \", \".join(TO), SUBJECT, TEXT)\n else:\n # https://stackoverflow.com/questions/882712/sending-html-email-using-python#882770\n msg = MIMEMultipart('alternative')\n msg['Subject'] = SUBJECT\n msg['From'] = FROM\n msg['To'] = \", \".join(TO)\n\n # Record the MIME types of both parts - text/plain and text/html.\n # utf-8 -> https://stackoverflow.com/questions/5910104/python-how-to-send-utf-8-e-mail#5910530\n part1 = MIMEText(TEXT, 'plain', \"utf-8\")\n part2 = MIMEText(HTML, 'html', \"utf-8\")\n\n # Attach parts into message container.\n # According to RFC 2046, the last part of a multipart message, in this case\n # the HTML message, is best and preferred.\n msg.attach(part1)\n msg.attach(part2)\n\n message = msg.as_string()\n\n\n try:\n if port not in PORT_LIST: \n raise Exception(\"Port %s not one of %s\" % (port, PORT_LIST))\n\n if port in (465,):\n server = smtplib.SMTP_SSL(host, port)\n else:\n server = smtplib.SMTP(host, port)\n\n # optional\n server.ehlo()\n\n if port in (587,): \n server.starttls()\n\n server.login(user, pwd)\n server.sendmail(FROM, TO, message)\n server.close()\n # logger.info(\"SENT_EMAIL to %s: %s\" % (recipients, subject))\n except Exception, ex:\n return ex\n\n return None\n body html body ex = send_email(\n host = 'smtp.gmail.com'\n #, port = 465 # OK\n , port = 587 #OK\n , user = \"[email protected]\"\n , pwd = \"xxx\"\n , from_ = '[email protected]'\n , recipients = ['[email protected]']\n , subject = \"Test from python\"\n , body = \"Test from python - body\"\n )\nif ex: \n print(\"Mail sending failed: %s\" % ex)\nelse:\n print(\"OK - mail sent\"\n" }, { "answer_id": 65853330, "author": "Milovan Tomašević", "author_id": 13155046, "author_profile": "https://Stackoverflow.com/users/13155046", "pm_score": 2, "selected": false, "text": "import smtplib\n \nfrom email.message import EmailMessage\nfrom getpass import getpass\n\n\npassword = getpass()\n\nmessage = EmailMessage()\nmessage.set_content('Message content here')\nmessage['Subject'] = 'Your subject here'\nmessage['From'] = \"USERNAME@DOMAIN\"\nmessage['To'] = \"[email protected]\"\n\ntry:\n smtp_server = None\n smtp_server = smtplib.SMTP(\"YOUR.MAIL.SERVER\", 587)\n smtp_server.ehlo()\n smtp_server.starttls()\n smtp_server.ehlo()\n smtp_server.login(\"USERNAME@DOMAIN\", password)\n smtp_server.send_message(message)\nexcept Exception as e:\n print(\"Error: \", str(e))\nfinally:\n if smtp_server is not None:\n smtp_server.quit()\n SMTP_SSL" }, { "answer_id": 72752742, "author": "miksus", "author_id": 13696660, "author_profile": "https://Stackoverflow.com/users/13696660", "pm_score": 0, "selected": false, "text": "pip install redmail\n from redmail import EmailSender\n\n# Configure the sender\nemail = EmailSender(\n host=\"YOUR.MAIL.SERVER\", \n port=26,\n username='[email protected]',\n password='<PASSWORD>'\n)\n\n# Send an email:\nemail.send(\n subject=\"An example email\",\n sender=\"[email protected]\",\n receivers=['[email protected]'],\n text=\"Hello!\",\n html=\"<h1>Hello!</h1>\"\n)\n" }, { "answer_id": 74403965, "author": "foodog123", "author_id": 19566293, "author_profile": "https://Stackoverflow.com/users/19566293", "pm_score": 0, "selected": false, "text": "import smtplib\nfrom email.mime.multipart import MIMEMultipart\nfrom email.mime.text import MIMEText\n\nmsg = MIMEMultipart()\nmsg['From'] = '[email protected]'\nmsg['To'] = '[email protected]'\nmsg['Subject'] = 'simple email in python'\nmessage = 'here is the email'\nmsg.attach(MIMEText(message))\n\nwith smtplib.SMTP('smtp-mail.outlook.com',587) as mail_server:\n # identify ourselves to smtp gmail client\n mail_server.ehlo()\n # secure our email with tls encryption\n mail_server.starttls()\n # re-identify ourselves as an encrypted connection\n mail_server.ehlo()\n mail_server.login('[email protected]', 'mypassword')\n mail_server.sendmail('[email protected]','[email protected]',msg.as_string())\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
64,508
<p>What does the following Guile scheme code do?</p> <pre><code>(eq? y '.) (cons x '.) </code></pre> <p>The code is not valid in MzScheme, is there a portable equivalent across scheme implementations?</p> <p>I am trying to port this code written by someone else. Guile seems to respond to '. with #{.}#, but I'm not sure what it means or how to do this in another scheme.</p>
[ { "answer_id": 15561595, "author": "NalaGinrut", "author_id": 259033, "author_profile": "https://Stackoverflow.com/users/259033", "pm_score": 1, "selected": false, "text": "#{.}#" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8689/" ]
64,518
<p>I have a Glade GUI description file with a <code>GtkTreeView</code> in a <code>GtkHBox</code> in a window; and there's a handler for the <code>row_activated</code> signal. Now, Glade has automatically set the "events" property (inherited from <code>GtkWidget</code>) of that treeview to some value (<code>GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</code>). And there are two strange things with this:</p> <ul> <li>removing the pre-set value (so that the property is empty) doesn't seem to break the application (at least not with the old GTK 2.10 I have atm).</li> <li>in fact, an annoying bug I has seen before (where the treeview items would not correctly react to expand or collapse clicks) is now gone!</li> </ul> <p>I have yet to test this with a newer GTK version, but the question is already there: exactly what is the purpose for this <code>events</code> property? And why does Glade automatically and unnecessarily set it to some value? Does this have some side effects I'm not aware of?</p>
[ { "answer_id": 65017, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "row_activated" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,537
<p>How do I use Perl to create graphs?</p> <p>I'm running scheduled job that creates text reports. I'd like to move this to the next step (for the management) and also create some graphs that go along with this. Is this possible / feasible? It'd be great if I could do this using Office some how.</p> <h2>update: solutions i'm going to investigate in this order</h2> <ul> <li>Spreadsheet::WriteExcel (this seems to now have changed from the last time i investigated this .... wait, this was suggested by the author of the module. cool.)</li> <li>GD Graph - this is now available for ActivePerl(wasn't last time i looked)</li> <li>SVG</li> <li>Open Charts look interesting.</li> <li>Chartdirector</li> </ul>
[ { "answer_id": 64556, "author": "user8456", "author_id": 8456, "author_profile": "https://Stackoverflow.com/users/8456", "pm_score": 2, "selected": false, "text": "Spreadsheet::WriteExcel::Chart\n" }, { "answer_id": 66276, "author": "Pat", "author_id": 238, "author_profile": "https://Stackoverflow.com/users/238", "pm_score": 3, "selected": false, "text": "use Google::Chart;\n\n my $chart = Google::Chart->new(\n type => \"Bar\",\n data => [ 1, 2, 3, 4, 5 ]\n );\n\n print $chart->as_uri, \"\\n\"; # or simply print $chart, \"\\n\"\n\n $chart->render_to_file( filename => 'filename.png' );\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64537", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8676/" ]
64,559
<p>I've started to work a bit with master pages for an ASP.net mvc site and I've come across a question. When I link in a stylesheet on the master page it seems to update the path to the sheet correctly. That is in the code I have</p> <pre><code>&lt;link href="../../Content/Site.css" rel="stylesheet" type="text/css" /&gt; </code></pre> <p>but looking at the source once the page is fed to a browser I get</p> <pre><code>&lt;link href="Content/Site.css" rel="stylesheet" type="text/css" /&gt; </code></pre> <p>which is perfect. However the same path translation doesn't seem to work for script files. </p> <pre><code>&lt;script src="../../Content/menu.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>just comes out as the same thing. It still seems to work on a top level page but I suspect that is just the browser/web server correcting my error. Is there a way to get the src path to be globbed too? </p>
[ { "answer_id": 64586, "author": "Iain Holder", "author_id": 1122, "author_profile": "https://Stackoverflow.com/users/1122", "pm_score": 0, "selected": false, "text": "<link href=\"~/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />\n" }, { "answer_id": 66376, "author": "Dane O'Connor", "author_id": 1946, "author_profile": "https://Stackoverflow.com/users/1946", "pm_score": 1, "selected": false, "text": "public static string ResolveUrl(this HtmlHelper helper, string virtualUrl)\n{\n HttpContextBase ctx = helper.ViewContext.HttpContext;\n string result = virtualUrl;\n\n if (virtualUrl.StartsWith(\"~/\"))\n {\n virtualUrl = virtualUrl.Remove(0, 2);\n\n //get the site root\n string siteRoot = ctx.Request.ApplicationPath;\n\n if (!siteRoot.EndsWith(\"/\"))\n siteRoot += \"/\";\n\n result = siteRoot + virtualUrl;\n }\n return result;\n}\n <script type=\"text/javascript\" src=\"<%= Html.ResolveUrl(\"~/Content/menu.js\")%>\"></script>\n" }, { "answer_id": 169158, "author": "Shawn Miller", "author_id": 247, "author_profile": "https://Stackoverflow.com/users/247", "pm_score": 3, "selected": true, "text": "<script src=\"<%= ResolveClientUrl(\"~/Content/menu.js\") %>\" type=\"text/javascript\"></script>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/361/" ]
64,570
<p>PHP's explode function returns an array of strings split on some provided substring. It will return empty strings when there are leading, trailing, or consecutive delimiters, like this:</p> <pre><code>var_dump(explode('/', '1/2//3/')); array(5) { [0]=&gt; string(1) &quot;1&quot; [1]=&gt; string(1) &quot;2&quot; [2]=&gt; string(0) &quot;&quot; [3]=&gt; string(1) &quot;3&quot; [4]=&gt; string(0) &quot;&quot; } </code></pre> <p>Is there some different function or option or anything that would return everything <em>except</em> the empty strings?</p> <pre><code>var_dump(different_explode('/', '1/2//3/')); array(3) { [0]=&gt; string(1) &quot;1&quot; [1]=&gt; string(1) &quot;2&quot; [2]=&gt; string(1) &quot;3&quot; } </code></pre>
[ { "answer_id": 64606, "author": "James Aylett", "author_id": 6302, "author_profile": "https://Stackoverflow.com/users/6302", "pm_score": 2, "selected": false, "text": "function not_empty_string($s) {\n return $s !== \"\";\n}\n\narray_filter(explode('/', '1/2//3/'), 'not_empty_string');\n" }, { "answer_id": 64608, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 7, "selected": true, "text": "$exploded = preg_split('@/@', '1/2//3/', -1, PREG_SPLIT_NO_EMPTY);" }, { "answer_id": 64619, "author": "Dave Gregory", "author_id": 5677, "author_profile": "https://Stackoverflow.com/users/5677", "pm_score": 5, "selected": false, "text": "print_r(explode('/', '1/2//3/'))\n Array\n(\n [0] => 1\n [1] => 2\n [2] =>\n [3] => 3\n [4] =>\n)\n php> print_r(array_filter(explode('/', '1/2//3/')))\n Array\n(\n [0] => 1\n [1] => 2\n [3] => 3\n)\n" }, { "answer_id": 64623, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 0, "selected": false, "text": "function MyExplode($sep, $str)\n{\n $arr = explode($sep, $str);\n foreach($arr as $item)\n if(item != \"\")\n $out[] = $item;\n return $out;\n}\n" }, { "answer_id": 64629, "author": "Bobby Jack", "author_id": 5058, "author_profile": "https://Stackoverflow.com/users/5058", "pm_score": -1, "selected": false, "text": "var_dump(array_filter(explode('/', '1/2//3/'))\n=>\narray(3) {\n [0]=>\n string(1) \"1\"\n [1]=>\n string(1) \"2\"\n [3]=>\n string(1) \"3\"\n}\n" }, { "answer_id": 64658, "author": "Bullines", "author_id": 27870, "author_profile": "https://Stackoverflow.com/users/27870", "pm_score": -1, "selected": false, "text": "$exploded_arr = split('/\\/+/', '1/2//3/');\n" }, { "answer_id": 64728, "author": "AntonioCS", "author_id": 8715, "author_profile": "https://Stackoverflow.com/users/8715", "pm_score": 0, "selected": false, "text": " function filter_empty(&$arrayvar) {\n $newarray = array();\n foreach ($arrayvar as $k => $value)\n if ($value !== \"\")\n $newarray[$k] = $value;\n\n $arrayvar = $newarray;\n }\n" }, { "answer_id": 64821, "author": "Glenn Moss", "author_id": 5726, "author_profile": "https://Stackoverflow.com/users/5726", "pm_score": 3, "selected": false, "text": "array_diff(explode('/', '1/2//3/'), array(''))\n" }, { "answer_id": 72886, "author": "Adam Hopkinson", "author_id": 12280, "author_profile": "https://Stackoverflow.com/users/12280", "pm_score": 0, "selected": false, "text": "// assuming $source = '1/2//3/';\n$source = str_replace('//', '/', $source);\n$source = trim($source);\n$parts = explode('/', $source);\n" }, { "answer_id": 23419614, "author": "Memochipan", "author_id": 826500, "author_profile": "https://Stackoverflow.com/users/826500", "pm_score": 1, "selected": false, "text": "$onlyNonEmptyValues function trimExplode($delim, $string, $onlyNonEmptyValues=0){\n $temp = explode($delim,$string);\n $newtemp=array();\n while(list($key,$val)=each($temp)) {\n if (!$onlyNonEmptyValues || strcmp(\"\",trim($val))) {\n $newtemp[]=trim($val);\n }\n }\n reset($newtemp);\n return $newtemp;\n}\n var_dump(trimExplode('/', '1/2//3/',1));\n array(3) {\n [0]=>\n string(1) \"1\"\n [1]=>\n string(1) \"2\"\n [2]=>\n string(1) \"3\"\n}\n" }, { "answer_id": 35928378, "author": "That Realty Programmer Guy", "author_id": 578023, "author_profile": "https://Stackoverflow.com/users/578023", "pm_score": 1, "selected": false, "text": "$result = array_deflate( explode( $delim, $array) );\n\nfunction array_deflate( $arr, $emptyval='' ){\n $ret=[];\n for($i=0,$L=count($arr); $i<$L; ++$i)\n if($arr[$i] !== $emptyval) $ret[]=$arr[$i];\n return $ret;\n}\n array_deflate( $objArray, new stdClass() ); array_deflate( $databaseArray, NULL ); array_deflate( $intArray, NULL ); array_deflate( $arrayArray, [] ); array_deflate( $assocArrayArray, [''=>NULL] ); array_deflate( $processedArray, new Exception('processing error') ); function array_deflate( $arr, $trigger='', $filter=NULL, $compare=NULL){\n $ret=[];\n if ($filter === NULL) $filter = function($el) { return $el; };\n if ($compare === NULL) $compare = function($a,$b) { return $a===$b; };\n\n for($i=0,$L=count($arr); $i<$L; ++$i)\n if( !$compare(arr[$i],$trigger) ) $ret[]=$arr[$i];\n else $filter($arr[$i]);\n return $ret;\n}\n function targetHandler($t){ /* .... */ } \narray_deflate( $haystack, $needle, targetHandler );\n array_inflate function array_inflate($dest,$src,$trigger='', $filter=NULL, $compare=NULL){\n if ($filter === NULL) $filter = function($el) { return $el; };\n if ($compare === NULL) $compare = function($a,$b) { return $a===$b; };\n\n for($i=0,$L=count($src); $i<$L; ++$i)\n if( $compare(src[$i],$trigger) ) $dest[]=$src[$i];\n else $filter($src[$i]);\n return $dest;\n}\n $smartppl=[]; \n$smartppl=array_inflate( $smartppl,\n $allppl,\n (object)['intelligence'=>110],\n cureStupid,\n isSmart);\n\nfunction isSmart($a,$threshold){\n if( isset($a->intellgence) ) //has intelligence?\n if( isset($threshold->intellgence) ) //has intelligence?\n if( $a->intelligence >= $threshold->intelligence )\n return true;\n else return INVALID_THRESHOLD; //error\n else return INVALID_TARGET; //error\n return false;\n}\n\nfunction cureStupid($person){\n $dangerous_chemical = selectNeurosteroid();\n applyNeurosteroid($person, $dangerous_chemical);\n\n if( isSmart($person,(object)['intelligence'=>110]) ) \n return $person;\n else \n lobotomize($person);\n\n return $person;\n}\n" }, { "answer_id": 36192965, "author": "Jeff", "author_id": 6107585, "author_profile": "https://Stackoverflow.com/users/6107585", "pm_score": 0, "selected": false, "text": "$interesting = array_values( \n array_filter(\n explode('/', '/1//2//3///4/0/false' ),\n function ($val) { return strlen($val); }\n ));\n\necho \"<pre>\", var_export( $interesting, true ), \"</pre>\";\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5726/" ]
64,581
<p>Any information on how to display the ODBC connections dialog and get the chosen ODBC back?</p>
[ { "answer_id": 65161, "author": "RyanBrady", "author_id": 2555, "author_profile": "https://Stackoverflow.com/users/2555", "pm_score": 2, "selected": false, "text": "// a_RootKey is Microsoft.Win32.RegistryKey \n// DSN is a class not provided in this code sample - you can see what properties are needed from the usage below.\n\nList<DSN> DsnList = new List<DSN>();\n\nMicrosoft.Win32.RegistryKey SearchKey = a_RootKey.OpenSubKey(\"SOFTWARE\\\\ODBC\\\\ODBC.INI\\\\ODBC Data Sources\");\n\nif (SearchKey != null)\n{\n\n foreach (string DsnName in SearchKey.GetValueNames() )\n { \n if ( (string)SearchKey.GetValue(DsnName) == \"SQL Server\" )\n {\n Microsoft.Win32.RegistryKey anotherkey = a_RootKey.OpenSubKey(\"SOFTWARE\\\\ODBC\\\\ODBC.INI\\\\\" + DSNName);\n DSN dsn = new DSN();\n dsn.Name = DSNName;\n dsn.Server = (string)anotherkey.GetValue(\"Server\");\n dsn.Database = (string)anotherkey.GetValue(\"Database\");\n dsn.Driver = (string)anotherkey.GetValue(\"Driver\");\n\n DsnList.Add(dsn);\n }\n\n }\n}\nreturn DsnList;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,602
<p>There are three assembly version attributes. What are differences? Is it ok if I use <code>AssemblyVersion</code> and ignore the rest?</p> <hr> <p>MSDN says:</p> <ul> <li><p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyversionattribute" rel="noreferrer">AssemblyVersion</a>:</p> <blockquote> <p>Specifies the version of the assembly being attributed. </p> </blockquote></li> <li><p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyfileversionattribute" rel="noreferrer">AssemblyFileVersion</a>:</p> <blockquote> <p>Instructs a compiler to use a specific version number for the Win32 file version resource. The Win32 file version is not required to be the same as the assembly's version number. </p> </blockquote></li> <li><p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyinformationalversionattribute" rel="noreferrer">AssemblyInformationalVersion</a>:</p> <blockquote> <p>Defines additional version information for an assembly manifest. </p> </blockquote></li> </ul> <hr> <p><em>This is a follow-up to <a href="https://stackoverflow.com/questions/62353/what-are-the-best-practices-for-using-assembly-attributes">What are the best practices for using Assembly Attributes?</a></em></p>
[ { "answer_id": 64634, "author": "Bob King", "author_id": 6897, "author_profile": "https://Stackoverflow.com/users/6897", "pm_score": 5, "selected": false, "text": "AssemblyVersion AssemblyFileVersion AssemblyFileVersion AssemblyInformationalVersion AssemblyVersion AssemblyFileVersion AssemblyInformationalVersion" }, { "answer_id": 64642, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 5, "selected": false, "text": "AssemblyInformationalVersion AssemblyFileVersion VERSION_INFO AssemblyInformationalVersion AssemblyFileVersion AssemblyVersion AssemblyVersion" }, { "answer_id": 65062, "author": "Remy van Duijkeren", "author_id": 8820, "author_profile": "https://Stackoverflow.com/users/8820", "pm_score": 11, "selected": true, "text": "AssemblyVersion [assembly: AssemblyVersion(\"1.3\")]\n AssemblyVersion [assembly: AssemblyFileVersion(\"1.3.2.42\")]\n major.minor.build.revision AssemblyInformationalVersion [assembly: AssemblyInformationalVersion(\"1.3 RC1\")]\n" }, { "answer_id": 802038, "author": "Daniel Fortunov", "author_id": 5975, "author_profile": "https://Stackoverflow.com/users/5975", "pm_score": 9, "selected": false, "text": "// Assembly mscorlib, Version 2.0.0.0\n[assembly: AssemblyFileVersion(\"2.0.50727.3521\")]\n[assembly: AssemblyInformationalVersion(\"2.0.50727.3521\")]\n[assembly: AssemblyVersion(\"2.0.0.0\")]\n AssemblyFileVersion AssemblyInformationalVersion AssemblyVersion AssemblyVersion AssemblyVersion .NET Framework Version: 2.0.50727.3521\n---\nAttempting to load assembly: Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f\nSuccessfully loaded assembly: Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f\n---\nAttempting to load assembly: Rhino.Mocks, Version=3.5.0.1336, Culture=neutral, PublicKeyToken=0b3305902db7183f\nAssembly binding for failed:\nSystem.IO.FileLoadException: Could not load file or assembly 'Rhino.Mocks, Version=3.5.0.1336, Culture=neutral, \nPublicKeyToken=0b3305902db7183f' or one of its dependencies. The located assembly's manifest definition \ndoes not match the assembly reference. (Exception from HRESULT: 0x80131040)\nFile name: 'Rhino.Mocks, Version=3.5.0.1336, Culture=neutral, PublicKeyToken=0b3305902db7183f'\n\n=== Pre-bind state information ===\nLOG: User = Phoenix\\Dani\nLOG: DisplayName = Rhino.Mocks, Version=3.5.0.1336, Culture=neutral, PublicKeyToken=0b3305902db7183f\n (Fully-specified)\nLOG: Appbase = [...]\nLOG: Initial PrivatePath = NULL\nCalling assembly : AssemblyBinding, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.\n===\nLOG: This bind starts in default load context.\nLOG: No application configuration file found.\nLOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\config\\machine.config.\nLOG: Post-policy reference: Rhino.Mocks, Version=3.5.0.1336, Culture=neutral, PublicKeyToken=0b3305902db7183f\nLOG: Attempting download of new URL [...].\nWRN: Comparing the assembly name resulted in the mismatch: Revision Number\nERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.\n AssemblyVersion // Assembly mscorlib, Version 2.0.0.0\n[assembly: AssemblyFileVersion(\"2.0.50727.3521\")]\n[assembly: AssemblyInformationalVersion(\"2.0.50727.3521\")]\n[assembly: AssemblyVersion(\"2.0.0.0\")]\n" }, { "answer_id": 37982586, "author": "KCD", "author_id": 516748, "author_profile": "https://Stackoverflow.com/users/516748", "pm_score": 3, "selected": false, "text": "AssemblyInformationalVersion dotnet pack --version-suffix ci-7 src/MyProject\n CustomAttributeExtensions.GetCustomAttribute<AssemblyInformationalVersionAttribute>(asm);\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2361/" ]
64,605
<p>Is it possible to use both JScript and VBScript in the same HTA? Can I call VBScript functions from JScript and vice-versa? Are there any "gotchas," like the JScript running first and the VBScript running second (classic ASP pages have this issue).</p>
[ { "answer_id": 64638, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 5, "selected": true, "text": "<script language=\"javascript\">\n // javascript code\n</script>\n\n<script language=\"vbscript\">\n ' vbscript code\n</script>\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5616/" ]
64,631
<p>I know next to nothing when it comes to the how and why of https connections. Obviously, when I'm transmitting secure data like passwords or especially credit card information, https is a critical tool. What do I need to know about it, though? What are the most common mistakes you see developers making when they implement it in their projects? Are there times when https is just a bad idea? Thanks!</p>
[ { "answer_id": 210279, "author": "JSchaefer", "author_id": 3676, "author_profile": "https://Stackoverflow.com/users/3676", "pm_score": 0, "selected": false, "text": "<link>" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
64,639
<p>What's the proper way to convert from a scientific notation string such as "1.234567E-06" to a floating point variable using C#?</p>
[ { "answer_id": 64662, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": true, "text": "Double.Parse(\"1.234567E-06\", System.Globalization.NumberStyles.Float);\n" }, { "answer_id": 221197, "author": "Jaymie Thomas", "author_id": 7703, "author_profile": "https://Stackoverflow.com/users/7703", "pm_score": 4, "selected": false, "text": "Double.TryParse(\"1.234567E-06\", System.Globalization.NumberStyles.Float, out MyFloat);\n MyFloat Double.Parse() Try..Catch MyFloat" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2488/" ]
64,640
<p>Someone please correct me if I'm wrong, but parsing a yyyy/MM/dd (or other specific formats) dates in C# <strong>should</strong> be as easy as </p> <pre><code>DateTime.ParseExact(theDate, "yyyy/MM/dd"); </code></pre> <p>but no, C# forces you to create an IFormatProvider.</p> <p>Is there an app.config friendly way of setting this so I don't need to do this each time?</p> <pre><code>DateTime.ParseExact(theDate, "yyyy/MM/dd", new CultureInfo("en-CA", true)); </code></pre>
[ { "answer_id": 64675, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 2, "selected": false, "text": "public static DateTime ParseExactDateTime(this string dateString, string formatString) {\n return DateTime.ParseExact(dateString, formatString, new CultureInfo(\"en-CA\", true));\n}\n" }, { "answer_id": 64701, "author": "David J. Sokol", "author_id": 1390, "author_profile": "https://Stackoverflow.com/users/1390", "pm_score": 3, "selected": false, "text": "DateTime.ParseExact(\"2008/12/05\", \"yyyy/MM/dd\", System.Globalization.CultureInfo.CurrentCulture);\n" }, { "answer_id": 64729, "author": "Xian", "author_id": 4642, "author_profile": "https://Stackoverflow.com/users/4642", "pm_score": 1, "selected": false, "text": "Convert.ToDateTime(\"2008/11/25\");\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7311/" ]
64,645
<p>I have an interface that I have defined in C++ which now needs to be implemented in C#. What is the best way to go about this? I don't want to use COM at all in my interface definition. The way I have solved this right now is to to have two interface definitions, one in C++ and one in C#. I then expose the C# interfaces as a COM server. This was my application which is written in C++ can call into C#. Is there anyway I can avoid having to define my implementation in C++ as well as C#?</p>
[ { "answer_id": 66930, "author": "mlbrock", "author_id": 9966, "author_profile": "https://Stackoverflow.com/users/9966", "pm_score": 0, "selected": false, "text": "public __gc class MyClass_Net {\npublic:\n MyClass_Net()\n :native_ptr_(new MyClass())\n {\n }\n ~MyClass_Net()\n {\n delete native_ptr_;\n }\n\nprivate:\n MyClass __nogc *native_ptr_;\n};\n" }, { "answer_id": 67891, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 1, "selected": false, "text": "extern \"C\" __stdcall __cdecl IRapiStream STG_E_UNIMPLEMENTEDFUNCTION" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8661/" ]
64,649
<p>If I issue the <a href="https://en.wikipedia.org/wiki/Find_(Unix)" rel="noreferrer">find</a> command as follows:</p> <pre><code>find . -name *.ear </code></pre> <p>It prints out:</p> <pre><code>./dir1/dir2/earFile1.ear ./dir1/dir2/earFile2.ear ./dir1/dir3/earFile1.ear </code></pre> <p>I want to 'print' the name and the size to the command line:</p> <pre><code>./dir1/dir2/earFile1.ear 5000 KB ./dir1/dir2/earFile2.ear 5400 KB ./dir1/dir3/earFile1.ear 5400 KB </code></pre>
[ { "answer_id": 64666, "author": "Jeremy Weathers", "author_id": 8794, "author_profile": "https://Stackoverflow.com/users/8794", "pm_score": 0, "selected": false, "text": "find . -name \"*.ear\" -exec ls -l {} \\;\n" }, { "answer_id": 64678, "author": "Yaba", "author_id": 7524, "author_profile": "https://Stackoverflow.com/users/7524", "pm_score": 1, "selected": false, "text": "find. -name *.ear -exec du {} \\;\n 5000 ./dir1/dir2/earFile1.ear\n5400 ./dir1/dir2/earFile2.ear\n5400 ./dir1/dir3/earFile1.ear\n" }, { "answer_id": 64683, "author": "killdash10", "author_id": 7621, "author_profile": "https://Stackoverflow.com/users/7621", "pm_score": 1, "selected": false, "text": "find . -name \"*.ear\" | xargs ls -sh\n" }, { "answer_id": 64684, "author": "Michael Cramer", "author_id": 1496728, "author_profile": "https://Stackoverflow.com/users/1496728", "pm_score": 5, "selected": false, "text": "find . -name \\*.ear -ls\n find . -name \\*.ear -printf \"%p\\t%k KB\\n\"\n" }, { "answer_id": 64691, "author": "Leigh Caldwell", "author_id": 3267, "author_profile": "https://Stackoverflow.com/users/3267", "pm_score": 7, "selected": false, "text": "find . -name *.ear -printf \"%p %k KB\\n\"\n" }, { "answer_id": 64699, "author": "shyam", "author_id": 7616, "author_profile": "https://Stackoverflow.com/users/7616", "pm_score": 8, "selected": true, "text": "find . -name '*.ear' -exec ls -lh {} \\;\n" }, { "answer_id": 64770, "author": "dmazzoni", "author_id": 7193, "author_profile": "https://Stackoverflow.com/users/7193", "pm_score": 5, "selected": false, "text": "find . -type f -printf '%p\\t%k KB\\n'\n find . -type f -exec ls -lh \\{\\} \\;\n find . -type f -exec wc -c \\{\\} \\;\n" }, { "answer_id": 244894, "author": "tpgould", "author_id": 32161, "author_profile": "https://Stackoverflow.com/users/32161", "pm_score": 2, "selected": false, "text": "% find . -name '*.ear' -ls | awk '{print $2, $11}'\n5400 ./dir1/dir2/earFile2.ear\n5400 ./dir1/dir2/earFile3.ear\n5400 ./dir1/dir2/earFile1.ear\n % find . -name '*.ear' -exec ls -lh {} \\; | awk '{print $5, $9}'\n5.3M ./dir1/dir2/earFile2.ear\n5.3M ./dir1/dir2/earFile3.ear\n5.3M ./dir1/dir2/earFile1.ear\n" }, { "answer_id": 8364384, "author": "Mike M", "author_id": 1078432, "author_profile": "https://Stackoverflow.com/users/1078432", "pm_score": 2, "selected": false, "text": "-printf ls -l -R | sed 's/\\(.*\\)staff *\\([0-9]*\\)..............\\(.*\\)/\\2 \\3/'\n 8071 sections.php\n54681 services.php\n37961 style.css\n13260 thumb.php\n70951 workshops.php\n" }, { "answer_id": 14184795, "author": "Andreas", "author_id": 1953201, "author_profile": "https://Stackoverflow.com/users/1953201", "pm_score": 2, "selected": false, "text": "find . -name \"*.ear\" -exec du -a {} \\;\n" }, { "answer_id": 21101734, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "find . -name '*.ear' -exec du -h {} \\;\n" }, { "answer_id": 22691385, "author": "adriano72", "author_id": 988044, "author_profile": "https://Stackoverflow.com/users/988044", "pm_score": 2, "selected": false, "text": "find . -type f -iname \"*.ear\" -exec du -ah {} \\; | awk '{print $2\"\\t\", $1}'\n -iname \"*.php\" ./plugins/bat/class.bat.inc.php 20K\n./plugins/quotas/class.quotas.inc.php 8.0K\n./plugins/dmraid/class.dmraid.inc.php 8.0K\n./plugins/updatenotifier/class.updatenotifier.inc.php 4.0K\n./index.php 4.0K\n./config.php 12K\n./includes/mb/class.hwsensors.inc.php 8.0K\n" }, { "answer_id": 35129844, "author": "kenorb", "author_id": 55075, "author_profile": "https://Stackoverflow.com/users/55075", "pm_score": 2, "selected": false, "text": "stat find . -type f -name *.ear -exec stat -c \"%n %s\" {} ';'\n stat find . -type f -name *.ear -exec stat -f \"%N %z\" {} ';'\n stat du wc find . -type f -name *.ear -exec sh -c 'echo \"{} $(wc -c < {})\"' ';'\n" }, { "answer_id": 62017923, "author": "Damien C", "author_id": 2261243, "author_profile": "https://Stackoverflow.com/users/2261243", "pm_score": 0, "selected": false, "text": "#!/bin/bash\ntotalSize=0\n\nallSizes=`find . -type f -name *.ear -exec stat -c \"%s\" {} \\;`\n\nfor fileSize in $allSizes; do\n totalSize=`echo \"$(($totalSize+$fileSize))\"`\ndone\necho \"Total size is $totalSize bytes\"\n" }, { "answer_id": 67577432, "author": "NILESH KUMAR", "author_id": 5036094, "author_profile": "https://Stackoverflow.com/users/5036094", "pm_score": -1, "selected": false, "text": "for i in `find . -iname \"*.ear\"`; do ls -lh $i; done\n" }, { "answer_id": 69855684, "author": "Craig", "author_id": 529256, "author_profile": "https://Stackoverflow.com/users/529256", "pm_score": 2, "selected": false, "text": "-type f -name '*.ear du -h sort -h find . -type f -name '*.ear' -exec du -h {} \\; | sort -h\n 5.0k ./dir1/dir2/earFile1.ear\n5.4k ./dir1/dir2/earFile2.ear\n5.4k ./dir1/dir3/earFile1.ear\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/700/" ]
64,653
<p>I am trying to delete several rows from a MySQL 5.0.45 database:</p> <pre><code>delete from bundle_inclusions; </code></pre> <p>The client works for a while and then returns the error:</p> <pre><code>Lock wait timeout exceeded; try restarting transaction </code></pre> <p>It's possible there is some uncommitted transaction out there that has a lock on this table, but I need this process to trump any such locks. How do I break the lock in MySQL?</p>
[ { "answer_id": 10704454, "author": "Lars Bohl", "author_id": 438960, "author_profile": "https://Stackoverflow.com/users/438960", "pm_score": 3, "selected": false, "text": "innodb_lock_wait_timeout = 50\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8344/" ]
64,689
<p>Is this function declaration in C#:</p> <pre><code>void foo(string mystring) </code></pre> <p>the same as this one in C:</p> <pre><code>void foo(char *) </code></pre> <p>i.e. In C#, does the called function receive a pointer behind the scenes?</p>
[ { "answer_id": 64713, "author": "user7116", "author_id": 7116, "author_profile": "https://Stackoverflow.com/users/7116", "pm_score": 5, "selected": true, "text": "void foo(const char *);\n" }, { "answer_id": 64727, "author": "David Thibault", "author_id": 5903, "author_profile": "https://Stackoverflow.com/users/5903", "pm_score": 2, "selected": false, "text": "ref public void Foo(ref int value) { value = 12 }\npublic void Bar()\n{\n int val = 3;\n Foo(ref val);\n // val == 12\n}\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
64,693
<p>Theres is a little problem I want to solve with Haskell: let substitute a function that change all of the wildcards in a string for one concrete parameter. The function has de signature of:</p> <pre><code>subs :: String -&gt; String -&gt; String -&gt; String -- example: -- subs 'x' "x^3 + x + sin(x)" "6.2" will generate -- "6.2^3 + 6.2 + sin(6.2)" </code></pre>
[ { "answer_id": 65479, "author": "Dan Dyer", "author_id": 5171, "author_profile": "https://Stackoverflow.com/users/5171", "pm_score": 4, "selected": true, "text": "import Text.Regex(mkRegex, subRegex)\n\nsubs :: String -> String -> String -> String\nsubs wildcard input value = subRegex (mkRegex wildcard) input value\n" }, { "answer_id": 65520, "author": "squadette", "author_id": 7754, "author_profile": "https://Stackoverflow.com/users/7754", "pm_score": 1, "selected": false, "text": "Text.Regex.Posix /\\Wx\\W/ x 6.2 x + quux" }, { "answer_id": 7175000, "author": "Dmitry Bespalov", "author_id": 905914, "author_profile": "https://Stackoverflow.com/users/905914", "pm_score": 2, "selected": false, "text": "import Text.Format\nformat \"{0}^3 + {0} + sin({0})\" [\"6.2\"]\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6766/" ]
64,723
<p>What is a <strong>non recursive</strong> algorithm for deciding whether a passed in amount can be built additively from a set of numbers.<br> In my case I'm determining whether a certain currency amount (such as $40) can be met by adding up some combination of a set of bills (such as $5, $10 and $20 bills). That is a simple example, but the algorithm needs to work for any currency set (some currencies use funky bill amounts and some bills may not be available at a given time).<br> So $50 can be met with a set of ($20 and $30), but cannot be met with a set of ($20 and $40). The non-recursive requirement is due to the target code base being for <code>SQL Server 2000</code> where the support of recursion is limited.<br> In addition this is for supporting a multi currency environment where the set of bills available may change (think a foreign currency exchange teller for example).</p>
[ { "answer_id": 64864, "author": "seanyboy", "author_id": 1726, "author_profile": "https://Stackoverflow.com/users/1726", "pm_score": 2, "selected": false, "text": "Denominations = [10,20,50,100]\nRequired = 570\n\nDenominations = sort(Denominations)\niBase = integer (Required / Denominations[1])\n\nBumpList = array [Denominations.count]\nBumpList.Clear\n\nrepeat \n iTotal = 0 \n for iAdd = 1 to Bumplist.size\n iTotal = iTotal + bumplist [iAdd] * Denominations[iAdd]\n loop\n if iTotal = Required then exit true\n\n //this bit should be like a mileometer. \n //We add 1 to each wheel, and trip over to the next wheel when it gets to iBase\n finished = true\n for iPos from bumplist.last to bumplist.first \n if bumplist[iPos] = (iBase-1) then bumplist[iPos] = 0 \n else begin\n finished = false\n bumplist[iPos] = bumplist[iPos]+1\n exit for\n end\n loop \nuntil (finished)\n\nexit false \n" }, { "answer_id": 405345, "author": "Gant", "author_id": 12460, "author_profile": "https://Stackoverflow.com/users/12460", "pm_score": 1, "selected": false, "text": " // Set of bills\n int[] unit = { 40,20,70};\n\n // Max amount of money\n int max = 100000;\n\n bool[] bucket = new bool[max];\n\n foreach (int t in unit)\n bucket[t] = true;\n\n for (int i = 0; i < bucket.Length; i++)\n if (bucket[i])\n foreach (int t in unit)\n if(i + t < bucket.Length)\n bucket[i + t] = true;\n\n // Check if the following amount of money\n // can be built additively\n Console.WriteLine(\"15 : \" + bucket[15]);\n Console.WriteLine(\"50 : \" + bucket[50]);\n Console.WriteLine(\"60 : \" + bucket[60]);\n Console.WriteLine(\"110 : \" + bucket[110]);\n Console.WriteLine(\"120 : \" + bucket[120]);\n Console.WriteLine(\"150 : \" + bucket[150]);\n Console.WriteLine(\"151 : \" + bucket[151]);\n 15 : False\n50 : False\n60 : True\n110 : True\n120 : True\n150 : True\n151 : False\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64723", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8852/" ]
64,745
<p>Coming from <code>J2ME</code> programming are there any similarities that would make it easy to adapt to <code>Android API</code>. Or is <code>Android API</code> completely different from the <code>J2ME</code> way of programming mobile apps. </p>
[ { "answer_id": 539260, "author": "haseman", "author_id": 62516, "author_profile": "https://Stackoverflow.com/users/62516", "pm_score": 4, "selected": false, "text": "postInvalidate invalidate drawRect drawImage" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/64745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]