qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
88,651
<p>Is it possible to get notifications using <a href="http://www.microsoft.com/sql/technologies/reporting/default.mspx" rel="nofollow noreferrer">SQL Server Reporting Services</a>? Say for example I have a report that I want by mail if has for example suddenly shows more than 10 rows or if a specific value drop below 100 000. Do I need to tie Notification Services into it and how do I do that?</p> <p>Please provide as much technical details as possible as I've never used <a href="http://www.microsoft.com/sql/technologies/notification/default.mspx" rel="nofollow noreferrer">Notification Services</a> before.</p> <p>Someone also told me that Notifications Services is replaced by new functionality in Reporting Services in Sql Server 2008 - is this the case?</p>
[ { "answer_id": 239482, "author": "James Green", "author_id": 31736, "author_profile": "https://Stackoverflow.com/users/31736", "pm_score": 3, "selected": true, "text": "exec ReportServer.dbo.AddEvent @EventType='TimedSubscription', @EventData='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx'\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/298/" ]
88,710
<p>I need to create a repeatable process for deploying SQL Server Reporting Services reports. I am not in favor of using Visual Studio and or Business Development Studio to do this. The rs.exe method of scripting deployments also seems rather clunky. Does anyone have a very elegant way that they have been able to deploy reports. The key here is that I want the process to be completely automated.</p>
[ { "answer_id": 91077, "author": "Lukáš Rampa", "author_id": 10560, "author_profile": "https://Stackoverflow.com/users/10560", "pm_score": 6, "selected": true, "text": "'=====================================================================\n' File: PublishReports.rss\n'\n' Summary: Script that can be used with RS.exe to \n' publish the reports.\n'\n' Rss file spans from beginnig of this comment to end of module\n' (except of \"End Module\").\n'=====================================================================\n\nDim langPaths As String() = {\"en\", \"cs\", \"pl\", \"de\"}\nDim filePath As String = Environment.CurrentDirectory\n\nPublic Sub Main()\n\n rs.Credentials = System.Net.CredentialCache.DefaultCredentials\n\n 'Create parent folder\n Try\n rs.CreateFolder(parentFolder, \"/\", Nothing)\n Console.WriteLine(\"Parent folder created: {0}\", parentFolder)\n Catch e As Exception\n Console.WriteLine(e.Message)\n End Try\n\n PublishLanguagesFromFolder(filePath)\n\nEnd Sub\n\nPublic Sub PublishLanguagesFromFolder(ByVal folder As String)\n Dim Lang As Integer\n Dim langPath As String\n\n For Lang = langPaths.GetLowerBound(0) To langPaths.GetUpperBound(0)\n langPath = langPaths(Lang)\n\n 'Create the lang folder\n Try\n rs.CreateFolder(langPath, \"/\" + parentFolder, Nothing)\n Console.WriteLine(\"Parent lang folder created: {0}\", parentFolder + \"/\" + langPath)\n Catch e As Exception\n Console.WriteLine(e.Message)\n End Try\n\n 'Create the shared data source\n CreateDataSource(\"/\" + parentFolder + \"/\" + langPath)\n\n 'Publish reports and images\n PublishFolderContents(folder + \"\\\" + langPath, \"/\" + parentFolder + \"/\" + langPath)\n Next 'Lang\nEnd Sub\n\nPublic Sub CreateDataSource(ByVal targetFolder As String)\n Dim name As String = \"data source\"\n\n 'Data source definition.\n Dim definition As New DataSourceDefinition\n definition.CredentialRetrieval = CredentialRetrievalEnum.Store\n definition.ConnectString = \"data source=\" + dbServer + \";initial catalog=\" + db\n definition.Enabled = True\n definition.EnabledSpecified = True\n definition.Extension = \"SQL\"\n definition.ImpersonateUser = False\n definition.ImpersonateUserSpecified = True\n 'Use the default prompt string.\n definition.Prompt = Nothing\n definition.WindowsCredentials = False\n 'Login information\n definition.UserName = \"user\"\n definition.Password = \"password\"\n\n Try\n 'name, folder, overwrite, definition, properties \n rs.CreateDataSource(name, targetFolder, True, definition, Nothing)\n Catch e As Exception\n Console.WriteLine(e.Message)\n End Try\n\nEnd Sub\n\nPublic Sub PublishFolderContents(ByVal sourceFolder As String, ByVal targetFolder As String)\n Dim di As New DirectoryInfo(sourceFolder)\n Dim fis As FileInfo() = di.GetFiles()\n Dim fi As FileInfo\n\n Dim fileName As String\n\n For Each fi In fis\n fileName = fi.Name\n Select Case fileName.Substring(fileName.Length - 4).ToUpper\n Case \".RDL\"\n PublishReport(sourceFolder, fileName, targetFolder)\n Case \".JPG\", \".JPEG\"\n PublishResource(sourceFolder, fileName, \"image/jpeg\", targetFolder)\n Case \".GIF\", \".PNG\", \".BMP\"\n PublishResource(sourceFolder, fileName, \"image/\" + fileName.Substring(fileName.Length - 3).ToLower, targetFolder)\n End Select\n Next fi\nEnd Sub\n\nPublic Sub PublishReport(ByVal sourceFolder As String, ByVal reportName As String, ByVal targetFolder As String)\n Dim definition As [Byte]() = Nothing\n Dim warnings As Warning() = Nothing\n\n Try\n Dim stream As FileStream = File.OpenRead(sourceFolder + \"\\\" + reportName)\n definition = New [Byte](stream.Length) {}\n stream.Read(definition, 0, CInt(stream.Length))\n stream.Close()\n Catch e As IOException\n Console.WriteLine(e.Message)\n End Try\n\n Try\n 'name, folder, overwrite, definition, properties \n warnings = rs.CreateReport(reportName.Substring(0, reportName.Length - 4), targetFolder, True, definition, Nothing)\n\n If Not (warnings Is Nothing) Then\n Dim warning As Warning\n For Each warning In warnings\n Console.WriteLine(warning.Message)\n Next warning\n Else\n Console.WriteLine(\"Report: {0} published successfully with no warnings\", targetFolder + \"/\" + reportName)\n End If\n Catch e As Exception\n Console.WriteLine(e.Message)\n End Try\nEnd Sub\n\nPublic Sub PublishResource(ByVal sourceFolder As String, ByVal resourceName As String, ByVal resourceMIME As String, ByVal targetFolder As String)\n Dim definition As [Byte]() = Nothing\n Dim warnings As Warning() = Nothing\n\n Try\n Dim stream As FileStream = File.OpenRead(sourceFolder + \"\\\" + resourceName)\n definition = New [Byte](stream.Length) {}\n stream.Read(definition, 0, CInt(stream.Length))\n stream.Close()\n Catch e As IOException\n Console.WriteLine(e.Message)\n End Try\n\n Try\n 'name, folder, overwrite, definition, MIME, properties \n rs.CreateResource(resourceName, targetFolder, True, definition, resourceMIME, Nothing)\n Console.WriteLine(\"Resource: {0} with MIME {1} created successfully\", targetFolder + \"/\" + resourceName, resourceMIME)\n Catch e As Exception\n Console.WriteLine(e.Message)\n End Try\nEnd Sub\n" }, { "answer_id": 2759212, "author": "fretje", "author_id": 101371, "author_profile": "https://Stackoverflow.com/users/101371", "pm_score": 3, "selected": false, "text": "Dim dataSourceRefs(0) As DataSource\n" }, { "answer_id": 52931504, "author": "SherlockSpreadsheets", "author_id": 5335644, "author_profile": "https://Stackoverflow.com/users/5335644", "pm_score": 0, "selected": false, "text": "ReportServer DEV" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88710", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16980/" ]
88,711
<p>I want to use <a href="http://alistapart.com/articles/sprites" rel="noreferrer">CSS sprites</a> on a web site instead of separate image files, for a large collection of small icons that are all the same size. How can I concatenate (tile) them into one big image using <a href="http://www.imagemagick.org/" rel="noreferrer">ImageMagick</a>?</p>
[ { "answer_id": 8187638, "author": "Alexander M.", "author_id": 1044587, "author_profile": "https://Stackoverflow.com/users/1044587", "pm_score": 5, "selected": false, "text": "montage -background transparent -geometry +4+4 *.png sprite.gif\n" }, { "answer_id": 10655028, "author": "Simon Ernst", "author_id": 709467, "author_profile": "https://Stackoverflow.com/users/709467", "pm_score": 6, "selected": false, "text": "convert *.png -append sprites.png (append vertically)\nconvert *.png +append sprites.png (append horizontally)\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2670/" ]
88,717
<p>I want to load one or more DLLs dynamically so that they run with a different security or basepath than my main application. How do I load these DLLs into a separate AppDomain and instantiate objects from them?</p>
[ { "answer_id": 93045, "author": "Jon Turner", "author_id": 16979, "author_profile": "https://Stackoverflow.com/users/16979", "pm_score": 6, "selected": true, "text": "AppDomain domain = AppDomain.CreateDomain(\"New domain name\");\n//Do other things to the domain like set the security policy\n\nstring pathToDll = @\"C:\\myDll.dll\"; //Full path to dll you want to load\nType t = typeof(TypeIWantToLoad);\nTypeIWantToLoad myObject = (TypeIWantToLoad)domain.CreateInstanceFromAndUnwrap(pathToDll, t.FullName);\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16979/" ]
88,743
<p>I'm using jmockit for unit testing (with TestNG), and I'm having trouble using the Expectations class to mock out a method that takes a primitive type (boolean) as a parameter, using a matcher. Here's some sample code that illustrates the problem.</p> <pre><code>/******************************************************/ import static org.hamcrest.Matchers.is; import mockit.Expectations; import org.testng.annotations.Test; public class PrimitiveMatcherTest { private MyClass obj; @Test public void testPrimitiveMatcher() { new Expectations(true) { MyClass c; { obj = c; invokeReturning(c.getFoo(with(is(false))), "bas"); } }; assert "bas".equals(obj.getFoo(false)); Expectations.assertSatisfied(); } public static class MyClass { public String getFoo(boolean arg) { if (arg) { return "foo"; } else { return "bar"; } } } } /******************************************************/ </code></pre> <p>The line containing the call to invokeReturning(...) throws a NullPointerException.</p> <p>If I change this call to not use a matcher, as in:</p> <pre><code>invokeReturning(c.getFoo(false), "bas"); </code></pre> <p>it works just fine. This is no good for me, because in my real code I'm actually mocking a multi-parameter method and I need to use a matcher on another argument. In this case, the Expectations class requires that <strong>all</strong> arguments use a matcher.</p> <p>I'm pretty sure this is a bug, or perhaps it's not possible to use Matchers with primitive types (that would make me sad). Has anyone encountered this issue, and know how to get around it?</p>
[ { "answer_id": 90136, "author": "Kris Pruden", "author_id": 16977, "author_profile": "https://Stackoverflow.com/users/16977", "pm_score": 3, "selected": true, "text": " protected final <T> T with(Matcher<T> argumentMatcher)\n {\n argMatchers.add(argumentMatcher);\n\n TypeVariable<?> typeVariable = argumentMatcher.getClass().getTypeParameters()[0];\n\n return (T) Utilities.defaultValueForType(typeVariable.getClass());\n }\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16977/" ]
88,773
<p>There must be a generic way to transform some hierachical XML such as:</p> <pre><code>&lt;element1 A="AValue" B="BValue"&gt; &lt;element2 C="DValue" D="CValue"&gt; &lt;element3 E="EValue1" F="FValue1"/&gt; &lt;element3 E="EValue2" F="FValue2"/&gt; &lt;/element2&gt; ... &lt;/element1&gt; </code></pre> <p>into the flattened XML (html) picking up selected attributes along the way and providing different labels for the attributes that become column headers.</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;A_Label&lt;/th&gt; &lt;th&gt;D_Label&lt;/th&gt; &lt;th&gt;E_Label&lt;/th&gt; &lt;th&gt;F_Label&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;AValue&lt;/td&gt; &lt;td&gt;DValue&lt;/td&gt; &lt;td&gt;EValue1&lt;/td&gt; &lt;td&gt;FValue1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;AValue&lt;/td&gt; &lt;td&gt;DValue&lt;/td&gt; &lt;td&gt;EValue2&lt;/td&gt; &lt;td&gt;FValue2&lt;/td&gt; &lt;/tr&gt; &lt;table&gt; </code></pre> <p>OK, so there's not generic solution due to the attribute re-labelling but you get what I mean hopefully. I've just started on all the XSLT/XPATH stuff so I'll work it out in good time but any clues would be useful.</p>
[ { "answer_id": 88875, "author": "Darrel Miller", "author_id": 6819, "author_profile": "https://Stackoverflow.com/users/6819", "pm_score": 4, "selected": true, "text": "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" exclude-result-prefixes=\"msxsl\">\n <xsl:output method=\"xml\" indent=\"yes\"/>\n\n <xsl:template match=\"/\">\n <table>\n <xsl:apply-templates select=\"//element3\"></xsl:apply-templates>\n </table>\n </xsl:template>\n\n <xsl:template match=\"element3\">\n <tr>\n <td><xsl:value-of select=\"../../@A\"/></td>\n <td><xsl:value-of select=\"../../@B\"/></td>\n <td><xsl:value-of select=\"../@C\"/></td>\n <td><xsl:value-of select=\"../@D\"/></td>\n <td><xsl:value-of select=\"@E\"/></td>\n <td><xsl:value-of select=\"@F\"/></td>\n </tr>\n <xsl:apply-templates select=\"*\"></xsl:apply-templates>\n </xsl:template>\n\n</xsl:stylesheet>\n" }, { "answer_id": 91278, "author": "Confusion", "author_id": 16784, "author_profile": "https://Stackoverflow.com/users/16784", "pm_score": 0, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<!-- XSL template to flatten structured XML, before converting to CSV. -->\n<xsl:stylesheet version=\"1.0\"\n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\n <xsl:output method=\"xml\" indent=\"yes\" encoding=\"UTF-8\"/>\n\n <xsl:strip-space elements=\"*\" /> \n\n <xsl:template match=\"/\">\n <xsl:apply-templates select=\"//yourElementsToFlatten\"/>\n </xsl:template>\n\n <xsl:template match=\"//yourElementsToFlatten\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:template>\n\n <xsl:template match=\"@*|node()\">\n <xsl:choose>\n <!-- If the element has multiple childs, call this template \n on its children to flatten it-->\n <xsl:when test=\"count(child::*) > 0\">\n <xsl:apply-templates select=\"@*|node()\"/>\n </xsl:when>\n <xsl:otherwise>\n <xsl:copy>\n <xsl:value-of select=\"text()\" />\n </xsl:copy>\n </xsl:otherwise>\n </xsl:choose>\n </xsl:template>\n\n</xsl:stylesheet>\n" }, { "answer_id": 11780518, "author": "Édouard Lopez", "author_id": 802365, "author_profile": "https://Stackoverflow.com/users/802365", "pm_score": 1, "selected": false, "text": "<xsl:element name=\"div\">\n <xsl:attribute name=\"class\" select=\"puke\" />\n <xsl:apply-templates select=\"$notice\" mode=\"puke\" />\n</xsl:element> \n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
88,775
<p>I work at a college and have been developing an ASP.NET site with many, many reports about students, attendance stats... The basis for the data is an MSSQL server DB which is the back end to our student management system. This has a regular maintenance period on Thursday mornings for an unknown length of time (dependent on what has to be done). </p> <p>Most of the staff are aware of this but the less regular users seem to be forever ringing me up. What is the easiest way to disable the site during maintenance obviously I can just try a DB query to test if it is up but am unsure of the best way to for instance redirect all users to a "The website is down for maintenance" message, bearing in mind they could have started a session prior to the website going down.</p> <p>Hopefully, something can be implemented globally rather than per page.</p>
[ { "answer_id": 88854, "author": "Matt Blaine", "author_id": 16272, "author_profile": "https://Stackoverflow.com/users/16272", "pm_score": 1, "selected": false, "text": "protected void Application_Error(object sender, EventArgs e)\n{\n Exception e = Server.GetLastError().GetBaseException();\n if(e is SqlException)\n { \n Server.ClearError();\n Server.Transfer(\"~/offline.aspx\");\n }\n} \n" }, { "answer_id": 88894, "author": "PeteT", "author_id": 16989, "author_profile": "https://Stackoverflow.com/users/16989", "pm_score": 0, "selected": false, "text": "HttpContext context = HttpContext.Current;\n if (!isOnline())\n {\n context.Response.ClearContent();\n context.Response.Write(\"<script language='javascript'>\" + \n\"top.location='\" + Request.ApplicationPath + \"/public/Offline.aspx';</scr\" + \"ipt>\");\n } \n" }, { "answer_id": 88958, "author": "James", "author_id": 2719, "author_profile": "https://Stackoverflow.com/users/2719", "pm_score": 2, "selected": true, "text": "void Application_PreRequestHandlerExecute(Object sender, EventArgs e)\n{\n string sPage = Request.ServerVariables[\"SCRIPT_NAME\"];\n if (!sPage.EndsWith(\"Maintenance.aspx\", StringComparison.OrdinalIgnoreCase))\n {\n //test the database connection\n //if it fails then redirect the user to Maintenance.aspx\n string connStr = ConfigurationManager.ConnectionString[\"ConnectionString\"].ConnectionString;\n SqlConnection conn = new SqlConnection(connStr);\n try\n {\n conn.Open();\n }\n catch(Exception ex)\n {\n Session[\"DBException\"] = ex;\n Response.Redirect(\"Maintenance.aspx\");\n }\n finally\n {\n conn.Close();\n }\n }\n}\n" }, { "answer_id": 89001, "author": "Dr8k", "author_id": 6014, "author_profile": "https://Stackoverflow.com/users/6014", "pm_score": 0, "selected": false, "text": "try\n{\n conn.Open();\n}\ncatch(Exception ex)\n{\n Session[\"DBException\"] = ex;\n Response.Redirect(\"Maintenance.aspx\");\n}\nfinally\n{\n conn.Close();\n}\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16989/" ]
88,791
<p>I was wondering what people thought of using properties as object initializers in C#. For some reason it seems to break the fundamentals of what constructors are used for.</p> <p>An example...</p> <pre><code>public class Person { string firstName; string lastName; public string FirstName { get { return firstName; } set { firstName = value; } } public string LastName { get { return lastName; } set { lastName= value; } } } </code></pre> <p>Then doing object intialization with.....</p> <pre><code>Person p = new Person{ FirstName = "Joe", LastName = "Smith" }; Person p = new Person{ FirstName = "Joe" }; </code></pre>
[ { "answer_id": 88807, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 4, "selected": true, "text": "Person _p$1 = new Person();\n_p$1.FirstName = \"Joe\";\n_p$1.LastName = \"Smith\";\nPerson p = _p$1;\n" }, { "answer_id": 88821, "author": "Tim Jarvis", "author_id": 10387, "author_profile": "https://Stackoverflow.com/users/10387", "pm_score": 0, "selected": false, "text": "var qry = from something in listofsomething\n select new {\n Firstname = something.FirstName,\n Lastname = something.Surname\n }\n" }, { "answer_id": 88841, "author": "Hallgrim", "author_id": 15454, "author_profile": "https://Stackoverflow.com/users/15454", "pm_score": 3, "selected": false, "text": "var v = new { Foo = 1, Bar = \"Hi\" };\nConsole.WriteLine(v.Bar);\n" }, { "answer_id": 88857, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 2, "selected": false, "text": "string firstName;\n\npublic string FirstName\n{\n get { return firstName; }\n set { firstName = value; }\n}\n" }, { "answer_id": 88908, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 0, "selected": false, "text": "public class SomeObject\n{\n private SomeObject()\n {}\n\n public SomeObject(string someString) //enforced constructor\n {}\n\n public string MyProperty { get; set; }\n }\n" }, { "answer_id": 88967, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 1, "selected": false, "text": "public class Person\n{\n public string FirstName { get; set; }\n public string LastName {get; set; }\n}\n" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/342514/" ]
88,800
<p>How can I restore a mysql database that was dropped using a "drop database" command? I have access to binary logs which should make this type of rollback possible.</p>
[ { "answer_id": 28412669, "author": "melloc", "author_id": 2817739, "author_profile": "https://Stackoverflow.com/users/2817739", "pm_score": 0, "selected": false, "text": "drop database" } ]
2008/09/17
[ "https://Stackoverflow.com/questions/88800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17002/" ]
88,831
<p>Anyone has ever programmed a PHP (or Perl) function to get the ceiling value Excel style?</p>
[ { "answer_id": 88888, "author": "Jacob", "author_id": 8119, "author_profile": "https://Stackoverflow.com/users/8119", "pm_score": 3, "selected": false, "text": "function excel_ceil($num){\n return ($num>0)?ceil($num):floor($num);\n}\n" }, { "answer_id": 10091498, "author": "Superbiji", "author_id": 1305919, "author_profile": "https://Stackoverflow.com/users/1305919", "pm_score": 3, "selected": false, "text": "// MS Excel function: Ceiling( number, significance ) \n\n\n// duplicates m$ excel's ceiling function\nif( !function_exists('ceiling') )\n{\n function ceiling($number, $significance = 1)\n {\n return ( is_numeric($number) && is_numeric($significance) ) ? (ceil($number/$significance)*$significance) : false;\n }\n}\n\necho ceiling(0, 1000); // 0\necho ceiling(1, 1); // 1000\necho ceiling(1001, 1000); // 2000\necho ceiling(1.27, 0.05); // 1.30\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
88,838
<p>In Java, I have a String and I want to encode it as a byte array (in UTF8, or some other encoding). Alternately, I have a byte array (in some known encoding) and I want to convert it into a Java String. How do I do these conversions?</p>
[ { "answer_id": 88847, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 4, "selected": false, "text": "String original = \"hello world\";\nbyte[] utf8Bytes = original.getBytes(\"UTF-8\");\n" }, { "answer_id": 88863, "author": "mcherm", "author_id": 14570, "author_profile": "https://Stackoverflow.com/users/14570", "pm_score": 10, "selected": true, "text": "String" }, { "answer_id": 2293195, "author": "savio", "author_id": 276570, "author_profile": "https://Stackoverflow.com/users/276570", "pm_score": -1, "selected": false, "text": "private static String removeNonUtf8CompliantCharacters( final String inString ) {\n if (null == inString ) return null;\n byte[] byteArr = inString.getBytes();\n for ( int i=0; i < byteArr.length; i++ ) {\n byte ch= byteArr[i]; \n // remove any characters outside the valid UTF-8 range as well as all control characters\n // except tabs and new lines\n if ( !( (ch > 31 && ch < 253 ) || ch == '\\t' || ch == '\\n' || ch == '\\r') ) {\n byteArr[i]=' ';\n }\n }\n return new String( byteArr );\n}\n" }, { "answer_id": 3386646, "author": "M. Leonhard", "author_id": 1736338, "author_profile": "https://Stackoverflow.com/users/1736338", "pm_score": 7, "selected": false, "text": "import java.nio.charset.Charset;\n\nprivate final Charset UTF8_CHARSET = Charset.forName(\"UTF-8\");\n\nString decodeUTF8(byte[] bytes) {\n return new String(bytes, UTF8_CHARSET);\n}\n\nbyte[] encodeUTF8(String string) {\n return string.getBytes(UTF8_CHARSET);\n}\n" }, { "answer_id": 11488296, "author": "Pacerier", "author_id": 632951, "author_profile": "https://Stackoverflow.com/users/632951", "pm_score": 1, "selected": false, "text": "for (byte b : new byte[] { 43, 45, (byte) 215, (byte) 247 }) {\n char c = (char) b;\n System.out.print(c);\n}\n" }, { "answer_id": 17401223, "author": "Ran Adler", "author_id": 2447599, "author_profile": "https://Stackoverflow.com/users/2447599", "pm_score": -1, "selected": false, "text": "//query is your json \n\n DefaultHttpClient httpClient = new DefaultHttpClient();\n HttpPost postRequest = new HttpPost(\"http://my.site/test/v1/product/search?qy=\");\n\n StringEntity input = new StringEntity(query, \"UTF-8\");\n input.setContentType(\"application/json\");\n postRequest.setEntity(input); \n HttpResponse response=response = httpClient.execute(postRequest);\n" }, { "answer_id": 19470896, "author": "paiego", "author_id": 491066, "author_profile": "https://Stackoverflow.com/users/491066", "pm_score": 4, "selected": false, "text": "byte[] b1 = szP1.getBytes(\"ISO-8859-1\");\nSystem.out.println(b1.toString());\n\nString szUT8 = new String(b1, \"UTF-8\");\nSystem.out.println(szUT8);\n" }, { "answer_id": 30170431, "author": "vtor", "author_id": 1534407, "author_profile": "https://Stackoverflow.com/users/1534407", "pm_score": 3, "selected": false, "text": " byte[] bytes = {(byte) 1};\n String convertedString = StringUtils.newStringUtf8(bytes);\n" }, { "answer_id": 30190990, "author": "Макс Даниленко", "author_id": 2200271, "author_profile": "https://Stackoverflow.com/users/2200271", "pm_score": 0, "selected": false, "text": "Reader reader = new BufferedReader(\n new InputStreamReader(\n new ByteArrayInputStream(\n string.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));\n" }, { "answer_id": 30198440, "author": "jschober", "author_id": 1610193, "author_profile": "https://Stackoverflow.com/users/1610193", "pm_score": 3, "selected": false, "text": "byte[] b = new byte[]{ 0, 0, 0, -127 }; // 0x00000081\nString s = new String(b,StandardCharsets.UTF_8); // UTF8 = 0x0000, 0x0000, 0x0000, 0xfffd\nb = s.getBytes(StandardCharsets.UTF_8); // [0, 0, 0, -17, -65, -67] 0x000000efbfbd != 0x00000081\n" }, { "answer_id": 34810953, "author": "Nitish Raj", "author_id": 2598888, "author_profile": "https://Stackoverflow.com/users/2598888", "pm_score": 1, "selected": false, "text": "Charset UTF8_CHARSET = Charset.forName(\"UTF-8\");\nString strISO = \"{\\\"name\\\":\\\"א\\\"}\";\nSystem.out.println(strISO);\nbyte[] b = strISO.getBytes();\nfor (byte c: b) {\n System.out.print(\"[\" + c + \"]\");\n}\nString str = new String(b, UTF8_CHARSET);\nSystem.out.println(str);\n" }, { "answer_id": 38139228, "author": "Bouke Woudstra", "author_id": 3184700, "author_profile": "https://Stackoverflow.com/users/3184700", "pm_score": 2, "selected": false, "text": "/* Convert a list of UTF-8 numbers to a normal String\n * Usefull for decoding a jms message that is delivered as a sequence of bytes instead of plain text\n */\npublic String convertUtf8NumbersToString(String[] numbers){\n int length = numbers.length;\n byte[] data = new byte[length];\n\n for(int i = 0; i< length; i++){\n data[i] = Byte.parseByte(numbers[i]);\n }\n return new String(data, Charset.forName(\"UTF-8\"));\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14570/" ]
88,850
<p>Is there a polynomial time algorithm for finding a Hamiltonian walk in a graph?</p> <p>My algorithm is N factorial and is really slow.</p>
[ { "answer_id": 3949267, "author": "user477959", "author_id": 477959, "author_profile": "https://Stackoverflow.com/users/477959", "pm_score": 1, "selected": false, "text": "SR={ x : R(x) ≠ ∅ }" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13813/" ]
88,904
<p>We're working on a very large .NET WinForms composite application - not CAB, but a similar home grown framework. We're running in a Citrix and RDP environment running on Windows Server 2003. </p> <p>We're starting to run into random and difficult to reproduct "Error creating window handle" error that seems to be an old fashion handle leak in our application. We're making heavy use of 3rd Party controls (Janus GridEX, Infralution VirtualTree, and .NET Magic docking) and we do a lot of dynamic loading and rendering of content based on metadata in our database.</p> <p>There's a lot of info on Google about this error, but not a lot of solid guidance about how to avoid issues in this area.</p> <p>Does the stackoverflow community have any good guidance for me for building handle-friendly winforms apps?</p>
[ { "answer_id": 39303696, "author": "Sudhakar Mallu", "author_id": 6789962, "author_profile": "https://Stackoverflow.com/users/6789962", "pm_score": 2, "selected": false, "text": "For k = 1 To Panel.Controls.Count\n Panel.Controls.Item(0).Dispose()\nNext\n" }, { "answer_id": 39669459, "author": "GrayDwarf", "author_id": 2744310, "author_profile": "https://Stackoverflow.com/users/2744310", "pm_score": 0, "selected": false, "text": "private void Dialog_SendEmailSummary_Button_Click(object sender, EventArgs e)\n{\n SendSummaryEmail();\n DialogResult = DialogResult.OK;\n}\n\nprivate void SendSummaryEmail()\n{\n var t = new Thread(() => SendSummaryThread(Textbox_Subject.Text, Textbox_Body.Text, Checkbox_IncludeDetails.Checked));\n t.Start();\n}\n\nprivate void SendSummaryThread(string subject, string comment, bool includeTestNames)\n{\n // ... Create and send the email.\n}\n" }, { "answer_id": 40232021, "author": "Jeremy Thompson", "author_id": 495455, "author_profile": "https://Stackoverflow.com/users/495455", "pm_score": 4, "selected": false, "text": "If Me.Controls.ContainsKey(comboName) Then\n cbo = CType(Me.Controls(comboName), ComboBox)\n With cbo\n .Location = New System.Drawing.Point(cumulativeWidth, 0)\n .Width = Me.Columns(i).Width\n End With\n 'Explicitly cleaning up fixed the issue of releasing USER objects.\n cbo.Dispose()\n cbo = Nothing \nEnd If\n" }, { "answer_id": 55940991, "author": "Abubakar Riaz", "author_id": 4401676, "author_profile": "https://Stackoverflow.com/users/4401676", "pm_score": 0, "selected": false, "text": " this.Invoke((MethodInvoker)delegate\n{\n //call your method here\n});\n" }, { "answer_id": 64030714, "author": "Vapid", "author_id": 2829397, "author_profile": "https://Stackoverflow.com/users/2829397", "pm_score": 0, "selected": false, "text": "WndProc(ref Message m)" }, { "answer_id": 74008948, "author": "YUT", "author_id": 2034362, "author_profile": "https://Stackoverflow.com/users/2034362", "pm_score": 0, "selected": false, "text": "while (mGridPanel.Controls.Count > 0)\n mGridPanel.Controls[0].Dispose();\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8133/" ]
88,918
<p>This is my first experience using the Zend Framework. I am attempting to follow the <a href="http://framework.zend.com/docs/quickstart/introduction" rel="nofollow noreferrer">Quick Start</a> tutorial. Everything was working as expected until I reached the section on the <a href="http://framework.zend.com/docs/quickstart/create-an-error-controller-and-view" rel="nofollow noreferrer">Error Controller and View</a>. When I navigate to a page that does not exist, instead of receiving the error page I get the Fatal Error screen dump (in all it's glory):</p> <blockquote> <p>Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php:249 Stack trace: #0 /home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 /home/.fantasia/bcnewman/foo.com/public/index.php(42): Zend_Controller_Front->dispatch() #2 {main} thrown in /home/.fantasia/bcnewman/foo.com/library/Zend/Controller/Dispatcher/Standard.php on line 249</p> </blockquote> <p>I do not believe this is caused by a syntax error on my part (a copied and pasted the example file's content from the tutorial) and I believe I have the application directory structure correct:</p> <pre><code>./application ./application/controllers ./application/controllers/IndexController.php ./application/controllers/ErrorHandler.php ./application/views ./application/views/scripts ./application/views/scripts/index ./application/views/scripts/index/index.phtml ./application/views/scripts/error ./application/views/scripts/error/error.phtml ./application/bootstrap.php ./public ./public/index.php </code></pre> <p>And finally, the <code>IndexController</code> and <code>index.phtml</code> view does work.</p>
[ { "answer_id": 89347, "author": "dragonmantank", "author_id": 204, "author_profile": "https://Stackoverflow.com/users/204", "pm_score": 2, "selected": false, "text": "$frontController->throwExceptions(true);\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3210/" ]
88,929
<p>Is there a command that would allow me to check if the string <code>"xyz"</code> was ever in file <code>foo.c</code> in the repository and print which revisions they were found in? </p>
[ { "answer_id": 89008, "author": "CaptainPicard", "author_id": 15203, "author_profile": "https://Stackoverflow.com/users/15203", "pm_score": 6, "selected": true, "text": "git log -Sxyz foo.c\n" }, { "answer_id": 51486627, "author": "Nwyfiant", "author_id": 9020923, "author_profile": "https://Stackoverflow.com/users/9020923", "pm_score": 3, "selected": false, "text": "--" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
88,931
<p>When defining or calling functions with enough arguments to span multiple lines, I want vim to line them up. For example,</p> <pre><code>def myfunction(arg1, arg2, arg, ... argsN-1, argN) </code></pre> <p>The idea is for argsN-1 to have its 'a' lined up with args1.</p> <p>Does anyone have a way to have this happen automatically in vim? I've seen the align plugin for lining equal signs (in assignment statements) and such, but I'm not sure if it can be made to solve this problem?</p>
[ { "answer_id": 89119, "author": "solinent", "author_id": 13852, "author_profile": "https://Stackoverflow.com/users/13852", "pm_score": 3, "selected": false, "text": ":set cino=(0\n" }, { "answer_id": 89169, "author": "rampion", "author_id": 9859, "author_profile": "https://Stackoverflow.com/users/9859", "pm_score": 4, "selected": false, "text": "set" }, { "answer_id": 97527, "author": "hakamadare", "author_id": 17597, "author_profile": "https://Stackoverflow.com/users/17597", "pm_score": 1, "selected": false, "text": ":!/path/to/tidy -config /path/to/configfile\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7706/" ]
88,957
<p>When <code>{0}</code> is used to initialize an object, what does it mean? I can't find any references to <code>{0}</code> anywhere, and because of the curly braces Google searches are not helpful.</p> <p>Example code:</p> <pre><code>SHELLEXECUTEINFO sexi = {0}; // what does this do? sexi.cbSize = sizeof(SHELLEXECUTEINFO); sexi.hwnd = NULL; sexi.fMask = SEE_MASK_NOCLOSEPROCESS; sexi.lpFile = lpFile.c_str(); sexi.lpParameters = args; sexi.nShow = nShow; if(ShellExecuteEx(&amp;sexi)) { DWORD wait = WaitForSingleObject(sexi.hProcess, INFINITE); if(wait == WAIT_OBJECT_0) GetExitCodeProcess(sexi.hProcess, &amp;returnCode); } </code></pre> <p>Without it, the above code will crash on runtime.</p>
[ { "answer_id": 88960, "author": "Don Neufeld", "author_id": 13097, "author_profile": "https://Stackoverflow.com/users/13097", "pm_score": 9, "selected": true, "text": "{0}" }, { "answer_id": 89093, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 3, "selected": false, "text": "char mytext[100] = {0};\n" }, { "answer_id": 89462, "author": "Harold Ekstrom", "author_id": 8429, "author_profile": "https://Stackoverflow.com/users/8429", "pm_score": 7, "selected": false, "text": "struct foo\n{\n char c;\n int i;\n};\n\nfoo a = {0};\n" }, { "answer_id": 153599, "author": "dalle", "author_id": 19100, "author_profile": "https://Stackoverflow.com/users/19100", "pm_score": 4, "selected": false, "text": "SHELLEXECUTEINFO sexi = {};\nchar mytext[100] = {};\n" }, { "answer_id": 734171, "author": "snowcrash09", "author_id": 89036, "author_profile": "https://Stackoverflow.com/users/89036", "pm_score": 4, "selected": false, "text": "ShellExecuteEx()" }, { "answer_id": 16534600, "author": "Ingo Blackman", "author_id": 1917520, "author_profile": "https://Stackoverflow.com/users/1917520", "pm_score": 2, "selected": false, "text": "struct foo bar = { 0 };\n" }, { "answer_id": 25693435, "author": "Keith Thompson", "author_id": 827263, "author_profile": "https://Stackoverflow.com/users/827263", "pm_score": 3, "selected": false, "text": "{0}" }, { "answer_id": 62515907, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 0, "selected": false, "text": "SHELLEXECUTEINFO sexi;\nsexi.cbSize = 0;\nsexi.fMask = 0;\nsexi.hwnd = NULL;\nsexi.lpVerb = NULL;\nsexi.lpFile = NULL;\nsexi.lpParameters = NULL;\nsexi.lpDirectory = NULL;\nsexi.nShow = nShow;\nsexi.hInstApp = 0;\nsexi.lpIDList = NULL;\nsexi.lpClass = NULL;\nsexi.hkeyClass = 0;\nsexi.dwHotKey = 0;\nsexi.hMonitor = 0;\nsexi.hProcess = 0;\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88957", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17027/" ]
88,971
<p>I'm building a toy database in C# to learn more about compiler, optimizer, and indexing technology.</p> <p>I want to maintain maximum parallelism between (at least read) requests for bringing pages into the buffer pool, but I am confused about how best to accomplish this in .NET.</p> <p>Here are some options and the problems I've come across with each:</p> <ol> <li><p>Use <code>System.IO.FileStream</code> and the <code>BeginRead</code> method</p> <p>But, the position in the file isn't an argument to <code>BeginRead</code>, it is a property of the <code>FileStream</code> (set via the <code>Seek</code> method), so I can only issue one request at a time and have to lock the stream for the duration. (Or do I? The documentation is unclear on what would happen if I held the lock only between the <code>Seek</code> and <code>BeginRead</code> calls but released it before calling <code>EndRead</code>. Does anyone know?) I know how to do this, I'm just not sure it is the best way.</p> </li> <li><p>There seems to be another way, centered around the <code>System.Threading.Overlapped</code> structure and P\Invoke to the <code>ReadFileEx</code> function in kernel32.dll.</p> <p>Unfortunately, there is a dearth of samples, especially in managed languages. This route (if it can be made to work at all) apparently also involves the <code>ThreadPool.BindHandle</code> method and the IO completion threads in the thread pool. I get the impression that this is the sanctioned way of dealing with this scenario under windows, but I don't understand it and I can't find an entry point to the documentation that is helpful to the uninitiated.</p> </li> <li><p>Something else?</p> </li> <li><p>In a comment, jacob suggests creating a new <code>FileStream</code> for each read in flight.</p> </li> <li><p>Read the whole file into memory.</p> <p>This would work if the database was small. The codebase is small, and there are plenty of other inefficiencies, but the database itself isn't. I also want to be sure I am doing all the bookkeeping needed to deal with a large database (which turns out to be a huge part of the complexity: paging, external sorting, ...) and I'm worried it might be too easy to accidentally cheat.</p> </li> </ol> <p><strong>Edit</strong></p> <p>Clarification of why I'm suspicious with solution 1: holding a single lock all the way from BeginRead to EndRead means I need to block anyone who wants to initiate a read just because another read is in progress. That feels wrong, because the thread initiating the new read might be able (in general) to do some more work before the results become available. (Actually, just writing this has led me to think up a new solution, I put as a new answer.)</p>
[ { "answer_id": 89123, "author": "Doug McClean", "author_id": 11173, "author_profile": "https://Stackoverflow.com/users/11173", "pm_score": 0, "selected": false, "text": "Seek" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11173/" ]
88,991
<p>I do not mean the compile errors because I made a syntax mistake or whatever. In C++ we can create compile time errors based on conditions as in the following example:</p> <pre><code>template&lt;int&gt; struct CompileTimeError; template&lt;&gt; struct CompileTimeError&lt;true&gt; {}; #define STATIC_CHECK(expr, msg) { CompileTimeError&lt;((expr) != 0)&gt; ERROR_##msg; (void)ERROR_##msg; } int main(int argc, char* argv[]) { STATIC_CHECK(false, Compile_Time_Failure); return 0; } </code></pre> <p>In VS 2005 this will output:</p> <pre><code>------ Build started: Project: Test, Configuration: Debug Win32 ------ Compiling... Test.cpp f:\temp\test\test\test.cpp(17) : error C2079: 'ERROR_Compile_Time_Failure' uses undefined struct 'CompileTimeError&lt;__formal&gt;' with [ __formal=0 ] Build log was saved at "file://f:\temp\Test\Test\Debug\BuildLog.htm" Test - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== </code></pre> <p>Is there any way to achieve this in Java?</p>
[ { "answer_id": 90563, "author": "Matt Quail", "author_id": 15790, "author_profile": "https://Stackoverflow.com/users/15790", "pm_score": 3, "selected": true, "text": "@MyStaticCheck(false, \"Compile Time Error, kind-of\")\npublic static void main(String[] args) {\n return;\n}\n" }, { "answer_id": 11138683, "author": "Stan", "author_id": 1102014, "author_profile": "https://Stackoverflow.com/users/1102014", "pm_score": 0, "selected": false, "text": "public static final boolean" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/88991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6508/" ]
89,051
<p>What I'd like to know is if there is a nice way to queue jQuery functions to execute after a set amount of time. This wouldn't pause the execution of other functions, just the ones following in the chain. Perhaps an example of what I'd envisage it would look like would illustrate:</p> <pre><code>$('#alert') .show() .wait(5000) // &lt;-- this bit .hide() ; </code></pre> <p>I know that it's possible by using timeouts, but it seems like that's a messy way to do it, especially compared to the above example (if it were real).</p> <p>So, is something like this already built-in to jQuery, and if not, what is the best way to emulate it?</p>
[ { "answer_id": 89076, "author": "Prestaul", "author_id": 5628, "author_profile": "https://Stackoverflow.com/users/5628", "pm_score": 4, "selected": true, "text": "var el = $('#alert');\nel.show()\nsetTimeout(function() { el.hide() }, 5000);\n" }, { "answer_id": 89792, "author": "dansays", "author_id": 1923, "author_profile": "https://Stackoverflow.com/users/1923", "pm_score": 1, "selected": false, "text": "$('#element').fadeOut({\n speed: 'fast',\n preDelay: 5000\n});\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
89,056
<p>I have heard of some methods, but none of them have stuck. Personally I try to avoid complex types in C and try to break them into component typedef.</p> <p>I'm now faced with maintaining some legacy code from a so called 'three star programmer', and I'm having a hard time reading some of the ***code[][].</p> <p>How do you read complex C declarations? </p>
[ { "answer_id": 89100, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 5, "selected": false, "text": "cdecl" }, { "answer_id": 90549, "author": "Friedrich", "author_id": 15068, "author_profile": "https://Stackoverflow.com/users/15068", "pm_score": 2, "selected": false, "text": "cdecl> explain int ***c[][]\ndeclare c as array of array of pointer to pointer to pointer to int\n" }, { "answer_id": 90664, "author": "Sundar R", "author_id": 8127, "author_profile": "https://Stackoverflow.com/users/8127", "pm_score": 5, "selected": false, "text": "*" }, { "answer_id": 1851428, "author": "outis", "author_id": 90527, "author_profile": "https://Stackoverflow.com/users/90527", "pm_score": 1, "selected": false, "text": "int i, *pi, **ppi;" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4319/" ]
89,112
<p>What are the steps and techniques to debug an apparent hang due to a deadlock in a Win32 production process. I heard that WinDbg can be used for this purpose but could you please provide clear hints on how this can be accomplished?</p>
[ { "answer_id": 89164, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "WaitForSingleObject" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6508/" ]
89,118
<p>I am getting an 403 access forbidden when attempting to open a page under a vhost where the document root is sitting on a different drive than where apache is sitting. I installed using the apachefriends release. This is my httpd-vhosts.conf file: </p> <p><pre><code> NameVirtualHost 127.0.0.1</p> <p>&lt;VirtualHost 127.0.0.1> ServerName foo.localhost DocumentRoot "C:/xampp/htdocs/foo/public" &lt;/VirtualHost></p> <p>&lt;VirtualHost 127.0.0.1> ServerName bar.localhost DocumentRoot "F:/bar/public" &lt;/VirtualHost> </pre></code></p> <p>When opening bar.localhost in my browser, Apache is giving me 403 Access Forbidden. I tried setting lots of different access rights, even full rights to everyone, but nothing I tried helped.</p> <p>Edit: Thanks! For future reference, add 'Options indexes' within to show directory indexes.</p>
[ { "answer_id": 91885, "author": "Mark Embling", "author_id": 6844, "author_profile": "https://Stackoverflow.com/users/6844", "pm_score": 6, "selected": false, "text": "<Directory \"F:/bar/public\">\n Order Allow,Deny\n Allow from All\n # Any other directory-specific stuff\n</Directory>\n" }, { "answer_id": 12519708, "author": "cloudwhale", "author_id": 356824, "author_profile": "https://Stackoverflow.com/users/356824", "pm_score": 5, "selected": false, "text": "<Directory \"C:/wamp/www\">\n Options Indexes FollowSymLinks MultiViews Includes ExecCGI\n AllowOverride All\n Order Allow,Deny\n Allow from all\n Require all granted\n</Directory>\n" }, { "answer_id": 12545200, "author": "Michael Klink", "author_id": 1691095, "author_profile": "https://Stackoverflow.com/users/1691095", "pm_score": 7, "selected": true, "text": "Options Indexes FollowSymLinks MultiViews Includes ExecCGI\nAllowOverride All\nOrder Allow,Deny\nAllow from all\nRequire all granted\n" }, { "answer_id": 27319355, "author": "mujaffars", "author_id": 2520185, "author_profile": "https://Stackoverflow.com/users/2520185", "pm_score": 0, "selected": false, "text": "<VirtualHost *:80>\n ServerAdmin webmaster@dummy-host.example.com\n DocumentRoot \"c:/Apache24/docs/dummy-host.example.com\"\n ServerName dummy-host.example.com\n ServerAlias www.dummy-host.example.com\n ErrorLog \"logs/dummy-host.example.com-error.log\"\n CustomLog \"logs/dummy-host.example.com-access.log\" common\n </VirtualHost>\n\n<VirtualHost *:80>\n ServerAdmin webmaster@dummy-host2.example.com\n DocumentRoot \"c:/Apache24/docs/dummy-host2.example.com\"\n ServerName dummy-host2.example.com\n ErrorLog \"logs/dummy-host2.example.com-error.log\"\n CustomLog \"logs/dummy-host2.example.com-access.log\" common\n</VirtualHost>\n" }, { "answer_id": 59900172, "author": "Dupls", "author_id": 5494550, "author_profile": "https://Stackoverflow.com/users/5494550", "pm_score": 0, "selected": false, "text": "DocumentRoot \"C:/web\"\n<Directory \"C:/web\">\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6752/" ]
89,154
<pre><code>boolean a = false, b = true; if ( a &amp;&amp; b ) { ... }; </code></pre> <p>In most languages, <code>b</code> will not get evaluated because <code>a</code> is false so <code>a &amp;&amp; b</code> cannot be true. My question is, wouldn't short circuiting be slower in terms of architecture? In a pipeline, do you just stall while waiting to get the result of a to determine if b should be evaluated or not? Would it be better to do nested ifs instead? Does that even help?</p> <p>Also, does anyone know what short-circuit evaluation is typically called? This question arose after I found out that my programming friend had never heard of short-circuit evaluation and stated that it is not common, nor found in many languages, and is inefficient in pipeline. I am not certain about the last one, so asking you folks!</p> <p>Okay, I think a different example to perhaps explain where my friend might be coming from. He believes that since evaluating a statement like the following in parallel:</p> <pre><code>(a) if ( ( a != null ) &amp;&amp; ( a.equals(b) ) ) { ... } </code></pre> <p>will crash the system, an architecture that doesn't have short-circuiting (and thereby not allowing statements like the above) would be faster in processing statements like these:</p> <pre><code>(b) if ( ( a == 4 ) &amp;&amp; ( b == 5 ) ) </code></pre> <p>since if it couldn't do (a) in parallel, it can't do (b) in parallel. In this case, a language that allows short-circuiting is slower than one that does not.</p> <p>I don't know if that's true or not.</p> <p>Thanks</p>
[ { "answer_id": 89179, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 3, "selected": false, "text": "if ( ConfirmAction() && DestroyAllData() )\n Reboot();\n" }, { "answer_id": 89180, "author": "scubabbl", "author_id": 9450, "author_profile": "https://Stackoverflow.com/users/9450", "pm_score": 1, "selected": false, "text": "if (a != null && a.equals(somevalue)) {\n ... do something.\n}\n" }, { "answer_id": 89182, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 1, "selected": false, "text": "if (someObject.isActive() && someOtherObject.isActive() && CollisionDetection.collides(someObject, someOtherObject) {\n doSomething();\n}\n" }, { "answer_id": 89204, "author": "RobbieGee", "author_id": 6752, "author_profile": "https://Stackoverflow.com/users/6752", "pm_score": 0, "selected": false, "text": "a = obj.somethingQuickToTest() && obj.somethingSlowToTest();" }, { "answer_id": 89234, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 2, "selected": false, "text": "IF A And B THEN\n ...\nEND IF\n" }, { "answer_id": 89313, "author": "Steve Jessop", "author_id": 13005, "author_profile": "https://Stackoverflow.com/users/13005", "pm_score": 4, "selected": true, "text": "open($filename) or die(\"couldn't open file\");\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12682/" ]
89,178
<p>For example:</p> <pre><code>&gt;&gt;&gt; x = [1, 1, 2, 'a', 'a', 3] &gt;&gt;&gt; unique(x) [1, 2, 'a', 3] </code></pre> <p>Assume list elements are hashable.</p> <p><strong>Clarification:</strong> The result should keep the first duplicate in the list. For example, [1, 2, 3, 2, 3, 1] becomes [1, 2, 3].</p>
[ { "answer_id": 89198, "author": "Matthew Schinckel", "author_id": 188, "author_profile": "https://Stackoverflow.com/users/188", "pm_score": -1, "selected": false, "text": "x = [1, 1, 2, 'a', 'a', 3]\ny = []\nfor each in x:\n if each not in y:\n y.append(each)\n" }, { "answer_id": 89202, "author": "ctcherry", "author_id": 10322, "author_profile": "https://Stackoverflow.com/users/10322", "pm_score": 3, "selected": false, "text": "def f5(seq, idfun=None): \n # order preserving \n if idfun is None: \n def idfun(x): return x \n seen = {} \n result = [] \n for item in seq: \n marker = idfun(item) \n # in old Python versions: \n # if seen.has_key(marker) \n # but in new ones: \n if marker in seen: continue \n seen[marker] = 1 \n result.append(item) \n return result\n" }, { "answer_id": 89208, "author": "etchasketch", "author_id": 14640, "author_profile": "https://Stackoverflow.com/users/14640", "pm_score": 0, "selected": false, "text": ">>> def unique(list):\n... y = []\n... for x in list:\n... if x not in y:\n... y.append(x)\n... return y\n" }, { "answer_id": 89218, "author": "Allen", "author_id": 6043, "author_profile": "https://Stackoverflow.com/users/6043", "pm_score": 4, "selected": false, "text": "def unique(items):\n seen = set()\n for i in xrange(len(items)-1, -1, -1):\n it = items[i]\n if it in seen:\n del items[i]\n else:\n seen.add(it)\n" }, { "answer_id": 89230, "author": "Wesley Tarle", "author_id": 17057, "author_profile": "https://Stackoverflow.com/users/17057", "pm_score": 1, "selected": false, "text": "def unique(x): \n output = []\n y = {}\n for item in x:\n y[item] = \"\"\n\n for item in x:\n if item in y:\n output.append(item)\n\n return output\n" }, { "answer_id": 89250, "author": "Terhorst", "author_id": 8062, "author_profile": "https://Stackoverflow.com/users/8062", "pm_score": 5, "selected": false, "text": "def unique(items):\n found = set()\n keep = []\n\n for item in items:\n if item not in found:\n found.add(item)\n keep.append(item)\n \n return keep\n\nprint unique([1, 1, 2, 'a', 'a', 3])\n" }, { "answer_id": 89260, "author": "Jake", "author_id": 10675, "author_profile": "https://Stackoverflow.com/users/10675", "pm_score": 2, "selected": false, "text": " # remove duplicates...\n def unique(my_list):\n return [x for x in my_list if x not in locals()['_[1]'].__self__]\n" }, { "answer_id": 89308, "author": "Kevin Little", "author_id": 14028, "author_profile": "https://Stackoverflow.com/users/14028", "pm_score": -1, "selected": false, "text": ">>> x=[1,1,2,'a','a',3]\n>>> y = [ _x for _x in x if not _x in locals()['_[1]'] ]\n>>> y\n[1, 2, 'a', 3]\n" }, { "answer_id": 89331, "author": "Tyler", "author_id": 3561, "author_profile": "https://Stackoverflow.com/users/3561", "pm_score": 3, "selected": false, "text": "new_list = reduce(lambda x,y: x+[y][:1-int(y in x)], my_list, [])\n" }, { "answer_id": 89373, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 2, "selected": false, "text": ">>> x = []\n>>> y = set()\n>>> def add_to_x(val):\n... if val not in y:\n... x.append(val)\n... y.add(val)\n... print x\n... print y\n... \n>>> add_to_x(1)\n[1]\nset([1])\n>>> add_to_x(1)\n[1]\nset([1])\n>>> add_to_x(1)\n[1]\nset([1])\n>>> \n" }, { "answer_id": 89917, "author": "etchasketch", "author_id": 14640, "author_profile": "https://Stackoverflow.com/users/14640", "pm_score": 1, "selected": false, "text": "def unique(list):\n s = {}\n output = []\n for x in list:\n count = 1\n if(s.has_key(x)):\n count = s[x] + 1\n\n s[x] = count\n for x in list:\n count = s[x]\n if(count > 0):\n s[x] = 0\n output.append(x)\n return output\n" }, { "answer_id": 90191, "author": "Sergey Stolyarov", "author_id": 15958, "author_profile": "https://Stackoverflow.com/users/15958", "pm_score": -1, "selected": false, "text": "a = [1,1,'a','b','c','c']\n\nnew_list = []\nprev = None\n\nwhile 1:\n try:\n i = a.pop(0)\n if i != prev:\n new_list.append(i)\n prev = i\n except IndexError:\n break\n" }, { "answer_id": 90225, "author": "John Fouhy", "author_id": 15154, "author_profile": "https://Stackoverflow.com/users/15154", "pm_score": 4, "selected": false, "text": "lst = [8, 8, 9, 9, 7, 15, 15, 2, 20, 13, 2, 24, 6, 11, 7, 12, 4, 10, 18, 13, 23, 11, 3, 11, 12, 10, 4, 5, 4, 22, 6, 3, 19, 14, 21, 11, 1, 5, 14, 8, 0, 1, 16, 5, 10, 13, 17, 1, 16, 17, 12, 6, 10, 0, 3, 9, 9, 3, 7, 7, 6, 6, 7, 5, 14, 18, 12, 19, 2, 8, 9, 0, 8, 4, 5]\n" }, { "answer_id": 91028, "author": "Franck Mesirard", "author_id": 16070, "author_profile": "https://Stackoverflow.com/users/16070", "pm_score": -1, "selected": false, "text": "def unique(container):\n return list(set(container))\n" }, { "answer_id": 91430, "author": "James Hopkin", "author_id": 11828, "author_profile": "https://Stackoverflow.com/users/11828", "pm_score": 3, "selected": false, "text": "def unique(l):\n s = set(); n = 0\n for x in l:\n if x not in s: s.add(x); l[n] = x; n += 1\n del l[n:]\n" }, { "answer_id": 92486, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 1, "selected": false, "text": "O(n)" }, { "answer_id": 100784, "author": "user18695", "author_id": 18695, "author_profile": "https://Stackoverflow.com/users/18695", "pm_score": 0, "selected": false, "text": "def unique(items):\n keep = []\n\n for item in items:\n if item not in keep:\n keep.append(item)\n\n return keep\n" }, { "answer_id": 143883, "author": "Constantin", "author_id": 20310, "author_profile": "https://Stackoverflow.com/users/20310", "pm_score": 3, "selected": false, "text": "def unique(seq):\n seen = set()\n for x in seq:\n if x not in seen:\n seen.add(x)\n yield x\n" }, { "answer_id": 279674, "author": "aboSamoor", "author_id": 35062, "author_profile": "https://Stackoverflow.com/users/35062", "pm_score": -1, "selected": false, "text": "a=[1,2,3,4,5,7,7,8,8,9,9,3,45]\n\ndef unique(l):\n\n ids={}\n for item in l:\n if not ids.has_key(item):\n ids[item]=item\n return ids.keys()\nprint a\n\nprint unique(a)\n" }, { "answer_id": 282589, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 4, "selected": false, "text": ">>> list(dict.fromkeys('abracadabra'))\n['a', 'b', 'r', 'c', 'd']\n" }, { "answer_id": 2607669, "author": "Mario Ruggier", "author_id": 2185854, "author_profile": "https://Stackoverflow.com/users/2185854", "pm_score": 2, "selected": false, "text": ">>> x = [1, 1, 2, 'a', 'a', 3]\n>>> [ item for pos,item in enumerate(x) if x.index(item)==pos ]\n[1, 2, 'a', 3]\n" }, { "answer_id": 4556143, "author": "Scot", "author_id": 557383, "author_profile": "https://Stackoverflow.com/users/557383", "pm_score": 2, "selected": false, "text": "x = [1, 1, 2, 'a', 'a', 3]\n\ntmpUniq = {} # temp variable used below \nresults = [tmpUniq.setdefault(i,i) for i in x if i not in tmpUniq]\n\nprint results\n[1, 2, 'a', 3]\n" }, { "answer_id": 7843997, "author": "Raymond Hettinger", "author_id": 424499, "author_profile": "https://Stackoverflow.com/users/424499", "pm_score": 1, "selected": false, "text": "def unique_everseen(iterable, key=None):\n \"List unique elements, preserving order. Remember all elements ever seen.\"\n # unique_everseen('AAAABBBCCDAABBB') --> A B C D\n # unique_everseen('ABBCcAD', str.lower) --> A B C D\n seen = set()\n seen_add = seen.add\n if key is None:\n for element in ifilterfalse(seen.__contains__, iterable):\n seen_add(element)\n yield element\n else:\n for element in iterable:\n k = key(element)\n if k not in seen:\n seen_add(k)\n yield element\n\ndef unique_justseen(iterable, key=None):\n \"List unique elements, preserving order. Remember only the element just seen.\"\n # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B\n # unique_justseen('ABBCcAD', str.lower) --> A B C A D\n return imap(next, imap(itemgetter(1), groupby(iterable, key)))\n" }, { "answer_id": 7844011, "author": "Raymond Hettinger", "author_id": 424499, "author_profile": "https://Stackoverflow.com/users/424499", "pm_score": 3, "selected": false, "text": "list(OrderedDict.fromkeys(iterable))\n" }, { "answer_id": 20787336, "author": "Michael", "author_id": 715042, "author_profile": "https://Stackoverflow.com/users/715042", "pm_score": 2, "selected": false, "text": "f8" }, { "answer_id": 25958705, "author": "BigDataGuy", "author_id": 4063267, "author_profile": "https://Stackoverflow.com/users/4063267", "pm_score": 0, "selected": false, "text": "x = [] # Your list of items that includes Duplicates\n\n# Assuming that your list contains items of only immutable data types\n\ndict_x = {} \n\ndict_x = {item : item for i, item in enumerate(x) if item not in dict_x.keys()}\n# Average t.c. = O(n)* O(1) ; furthermore the dict comphrehension and generator like behaviour of enumerate adds a certain efficiency and pythonic feel to it.\n\nx = dict_x.keys() # if you want your output in list format \n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16976/" ]
89,181
<p>How do i check out a specific directory from CVS and omit the tree leading up to that directory?</p> <p>EX. </p> <p>Id like to checkout to this directory C:/WebHost/MyWebApp/www</p> <p>My CVS Project directory structure is MyWebApp/Trunk/www</p> <p>How do i omit the Trunk and MyWebApp directories?</p>
[ { "answer_id": 89269, "author": "Alex M", "author_id": 9652, "author_profile": "https://Stackoverflow.com/users/9652", "pm_score": 6, "selected": true, "text": "-d/cvsroot checkout -d directory project/path/directory" }, { "answer_id": 89299, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": ".CVS" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16703/" ]
89,188
<p>Is it possible to get the x,y coordinates of a Flex app within an HTML page? I know you can use ExternalInterface.ObjecID to get the "id attribute of the object tag in Internet Explorer, or the name attribute of the embed tag in Netscape" but I can't seem to get past that step. It seems like it should be possible to get a handle on that embed object. Any suggestions? </p> <p>Thanks.</p>
[ { "answer_id": 91732, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 3, "selected": true, "text": "var jsCode : String = \"function( id ) { return $('#' + id).offset(); }\";\n\nvar offset : Object = ExternalInterface.call(jsCode, ExternalObject.objectID);\n\ntrace(offset.left, offset.top);\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15899/" ]
89,193
<p>Speaking as a non-C# savvy programmer, I'm curious as to the evaluation semantics of LINQ queries like the following:</p> <pre><code>var people = from p in Person where p.age &lt; 18 select p var otherPeople = from p in people where p.firstName equals "Daniel" select p </code></pre> <p>Assuming that <code>Person</code> is an ADO entity which defines the <code>age</code> and <code>firstName</code> fields, what would this do from a database standpoint? Specifically, would the <code>people</code> query be run to produce an in-memory structure, which would then be queried by the <code>otherPeople</code> query? Or would the construction of <code>otherPeople</code> merely pull the data regarding the query from <code>people</code> and then produce a new database-peered query? So, if I iterated over both of these queries, how many SQL statements would be executed?</p>
[ { "answer_id": 89211, "author": "David Thibault", "author_id": 5903, "author_profile": "https://Stackoverflow.com/users/5903", "pm_score": 1, "selected": false, "text": "people" }, { "answer_id": 89982, "author": "Ant", "author_id": 3709, "author_profile": "https://Stackoverflow.com/users/3709", "pm_score": 2, "selected": false, "text": "var people = from p in Person\n where p.age < 18\n select p\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9815/" ]
89,203
<p>What is the difference in C# between <code>Convert.ToDecimal(string)</code> and <code>Decimal.Parse(string)</code>?</p> <p>In what scenarios would you use one over the other?</p> <p>What impact does it have on performance?</p> <p>What other factors should I be taking into consideration when choosing between the two?</p>
[ { "answer_id": 89231, "author": "dimarzionist", "author_id": 10778, "author_profile": "https://Stackoverflow.com/users/10778", "pm_score": 2, "selected": false, "text": "TryParse()" }, { "answer_id": 89235, "author": "David J. Sokol", "author_id": 1390, "author_profile": "https://Stackoverflow.com/users/1390", "pm_score": 4, "selected": false, "text": "Decimal.TryParse" }, { "answer_id": 90274, "author": "James Newton-King", "author_id": 11829, "author_profile": "https://Stackoverflow.com/users/11829", "pm_score": 6, "selected": false, "text": "Convert.ToDecimal" }, { "answer_id": 24951885, "author": "Taran", "author_id": 1504072, "author_profile": "https://Stackoverflow.com/users/1504072", "pm_score": 1, "selected": false, "text": "Convert.ToDecimal(string)" }, { "answer_id": 42213973, "author": "tony95", "author_id": 1623174, "author_profile": "https://Stackoverflow.com/users/1623174", "pm_score": 0, "selected": false, "text": "var query = from c in dc.DataContext.vw_WebOrders\nselect new CisStoreData()\n{\n Discount = Convert.ToDecimal(c.Discount)\n};\n" }, { "answer_id": 55168143, "author": "Nandostyle", "author_id": 3142999, "author_profile": "https://Stackoverflow.com/users/3142999", "pm_score": 0, "selected": false, "text": "'object should be a string or a number\nFunction ConvertStringToDecimal(ByVal ValueToConvertToDecimal As Object) As Decimal\n If String.IsNullOrEmpty(ValueToConvertToDecimal.ToString) = False Then\n Return Convert.ToDecimal(ValueToConvertToDecimal)\n Else\n Return Convert.ToDecimal(0)\n End If\nEnd Function\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3821/" ]
89,212
<p>I'm familiar with object-oriented architecture, including use of design patterns and class diagrams for visualization, and I know of service-oriented architecture with its contracts and protocol bindings, but <strong>is there anything characteristic about a software architecture for a system written in a functional programming language?</strong></p> <p>I know that FP has been used for medium-size to large scale projects. Paul Graham wrote the first incarnation of Yahoo! Store in Common Lisp. Some lisp development systems are complex. Artifical intelligence and financial systems written in functional languages can get pretty big. They all have at least some kind of inherent architecture, though, I'm wondering if they have anything in common?</p> <p>What does an architecture based on the evaluation of expressions look like? Are FP architectures more composable?</p> <p><strong>Update:</strong> Kyle reminded me that <a href="http://mitpress.mit.edu/sicp/" rel="noreferrer">SICP</a> is a good resource for this subject.</p> <p><strong>Update 2:</strong> I found a good post on the subject: <em><a href="http://lorgonblog.spaces.live.com/Blog/cns!701679AD17B6D310!511.entry" rel="noreferrer">How does functional programming affect the structure of your code?</a></em></p>
[ { "answer_id": 89276, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 2, "selected": false, "text": "(define (make-counter)\n (let ((count 0))\n (lambda ()\n (set! count (+ count 1))\n count)))\n\n(define x (make-counter))\n\n(x) returns 1\n\n(x) returns 2\n\n...etc...\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1659/" ]
89,228
<p>How do I call an external command within Python as if I'd typed it in a shell or command prompt?</p>
[ { "answer_id": 89237, "author": "nimish", "author_id": 3926, "author_profile": "https://Stackoverflow.com/users/3926", "pm_score": 8, "selected": false, "text": "import os\nos.system(\"your command\")\n" }, { "answer_id": 89238, "author": "Alexandra Franks", "author_id": 16203, "author_profile": "https://Stackoverflow.com/users/16203", "pm_score": 7, "selected": false, "text": "import os\ncmd = 'ls -al'\nos.system(cmd)\n" }, { "answer_id": 89243, "author": "David Cournapeau", "author_id": 11465, "author_profile": "https://Stackoverflow.com/users/11465", "pm_score": 13, "selected": true, "text": "subprocess" }, { "answer_id": 89255, "author": "sirwart", "author_id": 6222, "author_profile": "https://Stackoverflow.com/users/6222", "pm_score": 7, "selected": false, "text": "subprocess.call(['ping', 'localhost'])\n" }, { "answer_id": 89262, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 6, "selected": false, "text": "import os\nos.system('cat testfile')\n" }, { "answer_id": 89304, "author": "Martin W", "author_id": 14199, "author_profile": "https://Stackoverflow.com/users/14199", "pm_score": 5, "selected": false, "text": "os.system" }, { "answer_id": 92395, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 12, "selected": false, "text": "os.system" }, { "answer_id": 95246, "author": "EmmEff", "author_id": 9188, "author_profile": "https://Stackoverflow.com/users/9188", "pm_score": 9, "selected": false, "text": "import subprocess\n\np = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\nfor line in p.stdout.readlines():\n print line,\nretval = p.wait()\n" }, { "answer_id": 2030768, "author": "Atinc Delican", "author_id": 246735, "author_profile": "https://Stackoverflow.com/users/246735", "pm_score": 5, "selected": false, "text": "subprocess.Popen" }, { "answer_id": 2251026, "author": "newtover", "author_id": 68998, "author_profile": "https://Stackoverflow.com/users/68998", "pm_score": 8, "selected": false, "text": "import subprocess\nimport sys\n\n# Some code here\n\npid = subprocess.Popen([sys.executable, \"longtask.py\"]) # Call subprocess\n\n# Some more code here\n" }, { "answer_id": 3879406, "author": "athanassis", "author_id": 463023, "author_profile": "https://Stackoverflow.com/users/463023", "pm_score": 6, "selected": false, "text": "child = pexpect.spawn('ftp 192.168.0.24')\n\nchild.expect('(?i)name .*: ')\n\nchild.sendline('anonymous')\n\nchild.expect('(?i)password')\n" }, { "answer_id": 4728086, "author": "cdunn2001", "author_id": 263998, "author_profile": "https://Stackoverflow.com/users/263998", "pm_score": 5, "selected": false, "text": "subprocess.check_call" }, { "answer_id": 5824565, "author": "Facundo Casco", "author_id": 181337, "author_profile": "https://Stackoverflow.com/users/181337", "pm_score": 6, "selected": false, "text": ">>> subprocess.check_output([\"ls\", \"-l\", \"/dev/null\"])\n'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\\n'\n" }, { "answer_id": 9676642, "author": "Jorge E. Cardona", "author_id": 361023, "author_profile": "https://Stackoverflow.com/users/361023", "pm_score": 6, "selected": false, "text": "fabric" }, { "answer_id": 10988365, "author": "Saurabh Bangad", "author_id": 1449929, "author_profile": "https://Stackoverflow.com/users/1449929", "pm_score": 5, "selected": false, "text": "os.system" }, { "answer_id": 11507283, "author": "kanghyojmun", "author_id": 1417123, "author_profile": "https://Stackoverflow.com/users/1417123", "pm_score": 4, "selected": false, "text": "from subprocess import Popen\n\nproc = Popen(['ls', '-l'])\nif proc.poll() is None:\n proc.kill()\n" }, { "answer_id": 11644161, "author": "Garfield", "author_id": 789213, "author_profile": "https://Stackoverflow.com/users/789213", "pm_score": 4, "selected": false, "text": "from commands import getstatusoutput\n\ntry:\n return getstatusoutput(\"ls -ltr\")\nexcept Exception, e:\n return None\n" }, { "answer_id": 13106558, "author": "Usman Khan", "author_id": 1755213, "author_profile": "https://Stackoverflow.com/users/1755213", "pm_score": 6, "selected": false, "text": "from subprocess import Popen, PIPE\ncmd = \"ls -l ~/\"\np = Popen(cmd , shell=True, stdout=PIPE, stderr=PIPE)\nout, err = p.communicate()\nprint \"Return code: \", p.returncode\nprint out.rstrip(), err.rstrip()\n" }, { "answer_id": 13402722, "author": "Joe", "author_id": 233098, "author_profile": "https://Stackoverflow.com/users/233098", "pm_score": 6, "selected": false, "text": "subprocess.run" }, { "answer_id": 15954964, "author": "Honza Javorek", "author_id": 325365, "author_profile": "https://Stackoverflow.com/users/325365", "pm_score": 6, "selected": false, "text": "import subprocess\nsubprocess.run(['ls', '-l'])\n" }, { "answer_id": 16089689, "author": "Colonel Panic", "author_id": 284795, "author_profile": "https://Stackoverflow.com/users/284795", "pm_score": 3, "selected": false, "text": ">>> subprocess.run([\"ls\", \"-l\"]) # doesn't capture output\nCompletedProcess(args=['ls', '-l'], returncode=0)\n\n>>> subprocess.run(\"exit 1\", shell=True, check=True)\nTraceback (most recent call last):\n ...\nsubprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1\n\n>>> subprocess.run([\"ls\", \"-l\", \"/dev/null\"], capture_output=True)\nCompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,\nstdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\\n', stderr=b'')\n" }, { "answer_id": 17202916, "author": "imagineerThat", "author_id": 1119779, "author_profile": "https://Stackoverflow.com/users/1119779", "pm_score": 4, "selected": false, "text": "In [9]: mylist = !ls\n\nIn [10]: mylist\nOut[10]:\n['file1',\n 'file2',\n 'file3',]\n" }, { "answer_id": 22395328, "author": "Jake W", "author_id": 746837, "author_profile": "https://Stackoverflow.com/users/746837", "pm_score": 3, "selected": false, "text": "stdout_result = 1\nstderr_result = 1\n\n\ndef stdout_thread(pipe):\n global stdout_result\n while True:\n out = pipe.stdout.read(1)\n stdout_result = pipe.poll()\n if out == '' and stdout_result is not None:\n break\n\n if out != '':\n sys.stdout.write(out)\n sys.stdout.flush()\n\n\ndef stderr_thread(pipe):\n global stderr_result\n while True:\n err = pipe.stderr.read(1)\n stderr_result = pipe.poll()\n if err == '' and stderr_result is not None:\n break\n\n if err != '':\n sys.stdout.write(err)\n sys.stdout.flush()\n\n\ndef exec_command(command, cwd=None):\n if cwd is not None:\n print '[' + ' '.join(command) + '] in ' + cwd\n else:\n print '[' + ' '.join(command) + ']'\n\n p = subprocess.Popen(\n command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd\n )\n\n out_thread = threading.Thread(name='stdout_thread', target=stdout_thread, args=(p,))\n err_thread = threading.Thread(name='stderr_thread', target=stderr_thread, args=(p,))\n\n err_thread.start()\n out_thread.start()\n\n out_thread.join()\n err_thread.join()\n\n return stdout_result + stderr_result\n" }, { "answer_id": 23030076, "author": "andruso", "author_id": 950708, "author_profile": "https://Stackoverflow.com/users/950708", "pm_score": 3, "selected": false, "text": "from subprocess import call\n\n# Using list\ncall([\"echo\", \"Hello\", \"world\"])\n\n# Single string argument varies across platforms so better split it\ncall(\"echo Hello world\".split(\" \"))\n" }, { "answer_id": 23391049, "author": "Emil Stenström", "author_id": 117268, "author_profile": "https://Stackoverflow.com/users/117268", "pm_score": 5, "selected": false, "text": ">>> import subprocess, shlex\n>>> command = 'ls -l \"/your/path/with spaces/\"'\n>>> call_params = shlex.split(command)\n>>> print call_params\n[\"ls\", \"-l\", \"/your/path/with spaces/\"]\n>>> subprocess.call(call_params)\n" }, { "answer_id": 23416345, "author": "houqp", "author_id": 929095, "author_profile": "https://Stackoverflow.com/users/929095", "pm_score": 4, "selected": false, "text": "ex('echo hello shell.py') | \"awk '{print $2}'\"\n" }, { "answer_id": 25476624, "author": "amehta", "author_id": 658247, "author_profile": "https://Stackoverflow.com/users/658247", "pm_score": 4, "selected": false, "text": "import os\nos.system('ls')\n" }, { "answer_id": 26305089, "author": "stuckintheshuck", "author_id": 394370, "author_profile": "https://Stackoverflow.com/users/394370", "pm_score": 5, "selected": false, "text": ">>> from plumbum import local\n>>> ls = local[\"ls\"]\n>>> ls\nLocalCommand(<LocalPath /bin/ls>)\n>>> ls()\nu'build.py\\ndist\\ndocs\\nLICENSE\\nplumbum\\nREADME.rst\\nsetup.py\\ntests\\ntodo.txt\\n'\n>>> notepad = local[\"c:\\\\windows\\\\notepad.exe\"]\n>>> notepad() # Notepad window pops up\nu'' # Notepad window is closed by user, command returns\n" }, { "answer_id": 31114625, "author": "Priyankara", "author_id": 2781812, "author_profile": "https://Stackoverflow.com/users/2781812", "pm_score": 5, "selected": false, "text": "import os\n\ncmd = 'ls -al'\n\nos.system(cmd)\n" }, { "answer_id": 31618111, "author": "Asif Hasnain", "author_id": 4527213, "author_profile": "https://Stackoverflow.com/users/4527213", "pm_score": 2, "selected": false, "text": "Popen" }, { "answer_id": 33118899, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "pass, stdout, stderr = execute([\"ls\",\"-la\"],\"/home/user/desktop\")\n" }, { "answer_id": 36058314, "author": "chtenb", "author_id": 1546844, "author_profile": "https://Stackoverflow.com/users/1546844", "pm_score": 3, "selected": false, "text": "CompletedProcess" }, { "answer_id": 36913076, "author": "Viswesn", "author_id": 527813, "author_profile": "https://Stackoverflow.com/users/527813", "pm_score": 2, "selected": false, "text": " def run (cmd):\n print \"+ DEBUG exec({0})\".format(cmd)\n p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)\n (out, err) = p.communicate()\n ret = p.wait()\n out = filter(None, out.split('\\n'))\n err = filter(None, err.split('\\n'))\n ret = True if ret == 0 else False\n return dict({'output': out, 'error': err, 'status': ret})\n #end\n" }, { "answer_id": 37877635, "author": "Swadhikar", "author_id": 5397845, "author_profile": "https://Stackoverflow.com/users/5397845", "pm_score": 4, "selected": false, "text": "subprocess" }, { "answer_id": 38012358, "author": "David Okwii", "author_id": 547050, "author_profile": "https://Stackoverflow.com/users/547050", "pm_score": 3, "selected": false, "text": "import subprocess\n\np = subprocess.Popen(\"df -h\", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]\nprint p.split(\"\\n\")\n" }, { "answer_id": 38477871, "author": "IRSHAD", "author_id": 3089950, "author_profile": "https://Stackoverflow.com/users/3089950", "pm_score": 4, "selected": false, "text": "#!/usr/bin/python\nimport os\nnetid = \"nova net-list | awk '/ External / { print $2 }'\"\ntemp = os.popen(netid).read() /* Here temp also contains new line (\\n) */\nnetworkId = temp.rstrip()\nprint(networkId)\n" }, { "answer_id": 39447501, "author": "liuyip", "author_id": 5771451, "author_profile": "https://Stackoverflow.com/users/5771451", "pm_score": 2, "selected": false, "text": "and.exe" }, { "answer_id": 39969619, "author": "Rajiv Sharma", "author_id": 2679465, "author_profile": "https://Stackoverflow.com/users/2679465", "pm_score": 3, "selected": false, "text": "import subprocess\nproc = subprocess.check_output('ipconfig /all')\nprint proc\n" }, { "answer_id": 40319875, "author": "Tom Fuller", "author_id": 5177604, "author_profile": "https://Stackoverflow.com/users/5177604", "pm_score": 7, "selected": false, "text": "ls -l" }, { "answer_id": 40824514, "author": "Yuval Atzmon", "author_id": 2476373, "author_profile": "https://Stackoverflow.com/users/2476373", "pm_score": 4, "selected": false, "text": "import os\nos.system('ts <your-command>')\n" }, { "answer_id": 46815111, "author": "Russia Must Remove Putin", "author_id": 541136, "author_profile": "https://Stackoverflow.com/users/541136", "pm_score": 6, "selected": false, "text": "subprocess.run" }, { "answer_id": 46921537, "author": "Asav Patel", "author_id": 2260553, "author_profile": "https://Stackoverflow.com/users/2260553", "pm_score": 2, "selected": false, "text": "import shlex\nimport psutil\nimport subprocess\n\ndef call_cmd(cmd, stdout=sys.stdout, quiet=False, shell=False, raise_exceptions=True, use_shlex=True, timeout=None):\n \"\"\"Exec command by command line like 'ln -ls \"/var/log\"'\n \"\"\"\n if not quiet:\n print(\"Run %s\", str(cmd))\n if use_shlex and isinstance(cmd, (str, unicode)):\n cmd = shlex.split(cmd)\n if timeout is None:\n process = subprocess.Popen(cmd, stdout=stdout, stderr=sys.stderr, shell=shell)\n retcode = process.wait()\n else:\n process = subprocess.Popen(cmd, stdout=stdout, stderr=sys.stderr, shell=shell)\n p = psutil.Process(process.pid)\n finish, alive = psutil.wait_procs([p], timeout)\n if len(alive) > 0:\n ps = p.children()\n ps.insert(0, p)\n print('waiting for timeout again due to child process check')\n finish, alive = psutil.wait_procs(ps, 0)\n if len(alive) > 0:\n print('process {} will be killed'.format([p.pid for p in alive]))\n for p in alive:\n p.kill()\n if raise_exceptions:\n print('External program timeout at {} {}'.format(timeout, cmd))\n raise CalledProcessTimeout(1, cmd)\n retcode = process.wait()\n if retcode and raise_exceptions:\n print(\"External program failed %s\", str(cmd))\n raise subprocess.CalledProcessError(retcode, cmd)\n" }, { "answer_id": 48548332, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "import subprocess\nsubprocess.run('mkdir test.dir', shell=True)\n" }, { "answer_id": 49441486, "author": "am5", "author_id": 4521562, "author_profile": "https://Stackoverflow.com/users/4521562", "pm_score": 4, "selected": false, "text": "import subprocess,sys\n\ndef exec_long_running_proc(command, args):\n cmd = \"{} {}\".format(command, \" \".join(str(arg) if ' ' not in arg else arg.replace(' ','\\ ') for arg in args))\n print(cmd)\n process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n\n # Poll process for new output until finished\n while True:\n nextline = process.stdout.readline().decode('UTF-8')\n if nextline == '' and process.poll() is not None:\n break\n sys.stdout.write(nextline)\n sys.stdout.flush()\n\n output = process.communicate()[0]\n exitCode = process.returncode\n\n if (exitCode == 0):\n return output\n else:\n raise Exception(command, exitCode, output)\n" }, { "answer_id": 49644672, "author": "rashok", "author_id": 596370, "author_profile": "https://Stackoverflow.com/users/596370", "pm_score": 3, "selected": false, "text": "os.system(...)" }, { "answer_id": 50101887, "author": "Samadi Salahedine", "author_id": 6634322, "author_profile": "https://Stackoverflow.com/users/6634322", "pm_score": 5, "selected": false, "text": "import os\ncmd = \"your command\"\nos.system(cmd)\n" }, { "answer_id": 50242060, "author": "dportman", "author_id": 7812314, "author_profile": "https://Stackoverflow.com/users/7812314", "pm_score": 3, "selected": false, "text": "!" }, { "answer_id": 52339862, "author": "Valery Ramusik", "author_id": 5992385, "author_profile": "https://Stackoverflow.com/users/5992385", "pm_score": 4, "selected": false, "text": ">>> from invoke import run\n>>> cmd = \"pip install -r requirements.txt\"\n>>> result = run(cmd, hide=True, warn=True)\n>>> print(result.ok)\nTrue\n>>> print(result.stdout.splitlines()[-1])\nSuccessfully installed invocations-0.13.0 pep8-1.5.7 spec-1.3.1\n" }, { "answer_id": 53063521, "author": "Cédric", "author_id": 4045907, "author_profile": "https://Stackoverflow.com/users/4045907", "pm_score": 4, "selected": false, "text": "pip install citizenshell\n" }, { "answer_id": 54414217, "author": "Farzad Vertigo", "author_id": 3939318, "author_profile": "https://Stackoverflow.com/users/3939318", "pm_score": 3, "selected": false, "text": "subprocess" }, { "answer_id": 55440842, "author": "geckos", "author_id": 652528, "author_profile": "https://Stackoverflow.com/users/652528", "pm_score": 3, "selected": false, "text": "from os import getcwd\nfrom subprocess import check_output\nfrom shlex import quote\n\ndef sh(command):\n return check_output(quote(command), shell=True, cwd=getcwd(), universal_newlines=True).strip()\n" }, { "answer_id": 56842257, "author": "Zach Valenta", "author_id": 6813490, "author_profile": "https://Stackoverflow.com/users/6813490", "pm_score": 1, "selected": false, "text": "from sultan.api import Sultan\n\nwith Sultan.load(sudo=True, hostname=\"myserver.com\") as sultan:\n sultan.yum(\"install -y tree\").run()\n" }, { "answer_id": 57696996, "author": "noɥʇʎԀʎzɐɹƆ", "author_id": 1459669, "author_profile": "https://Stackoverflow.com/users/1459669", "pm_score": 3, "selected": false, "text": "!ls\nfilelist = !ls\n" }, { "answer_id": 58212263, "author": "Vishal", "author_id": 197473, "author_profile": "https://Stackoverflow.com/users/197473", "pm_score": 2, "selected": false, "text": "import subprocess\n\np = subprocess.run([\"ls\", \"-ltr\"], capture_output=True)\nprint(p.stdout.decode(), p.stderr.decode())\n" }, { "answer_id": 58297652, "author": "Vishal", "author_id": 197473, "author_profile": "https://Stackoverflow.com/users/197473", "pm_score": 3, "selected": false, "text": "import subprocess\n\np = subprocess.run([\"ls\", \"-ltr\"], capture_output=True)\nprint(p.stdout.decode(), p.stderr.decode())\n" }, { "answer_id": 59050139, "author": "Trect", "author_id": 9789097, "author_profile": "https://Stackoverflow.com/users/9789097", "pm_score": 2, "selected": false, "text": "os.popen()" }, { "answer_id": 59090212, "author": "N.Nonkovic", "author_id": 7221283, "author_profile": "https://Stackoverflow.com/users/7221283", "pm_score": 4, "selected": false, "text": "import subprocess\nimport shlex\n\nsource = \"test.txt\"\ndestination = \"test_copy.txt\"\n\nbase = \"cp {source} {destination}'\"\ncmd = base.format(source=source, destination=destination)\nsubprocess.check_call(shlex.split(cmd))\n" }, { "answer_id": 60427071, "author": "Kashif Iftikhar", "author_id": 12598819, "author_profile": "https://Stackoverflow.com/users/12598819", "pm_score": 2, "selected": false, "text": "subprocess" }, { "answer_id": 61307412, "author": "ivanmara", "author_id": 6195439, "author_profile": "https://Stackoverflow.com/users/6195439", "pm_score": -1, "selected": false, "text": "import subprocess\ndef execute(cmd):\n \"\"\"\n Purpose : To execute a command and return exit status\n Argument : cmd - command to execute\n Return : result, exit_code\n \"\"\"\n process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n (result, error) = process.communicate()\n rc = process.wait()\n if rc != 0:\n print (\"Error: failed to execute command: \", cmd)\n print (error.rstrip().decode(\"utf-8\"))\n return result.rstrip().decode(\"utf-8\"), serror.rstrip().decode(\"utf-8\")\n# def\n" }, { "answer_id": 64341833, "author": "fameman", "author_id": 6685358, "author_profile": "https://Stackoverflow.com/users/6685358", "pm_score": 5, "selected": false, "text": "os.system(...)" }, { "answer_id": 69012133, "author": "Bilal Ahmed Yaseen", "author_id": 1846656, "author_profile": "https://Stackoverflow.com/users/1846656", "pm_score": 2, "selected": false, "text": "from subprocess import Popen\n" }, { "answer_id": 70789418, "author": "Badr Elmers", "author_id": 3020379, "author_profile": "https://Stackoverflow.com/users/3020379", "pm_score": 2, "selected": false, "text": "def _run(command, timeout_s=False, shell=False):\n ### run a process, capture the output and wait for it to finish. if timeout is specified then Kill the subprocess and its children when the timeout is reached (if parent did not detach)\n ## usage: _run(arg1, arg2, arg3)\n # arg1: command + arguments. Always pass a string; the function will split it when needed\n # arg2: (optional) timeout in seconds before force killing\n # arg3: (optional) shell usage. default shell=False\n ## return: a list containing: exit code, output, and if timeout was reached or not\n\n # - Tested on Python 2 and 3 on Windows XP, Windows 7, Cygwin and Linux.\n # - preexec_fn=os.setsid (py2) is equivalent to start_new_session (py3) (works on Linux only), in Windows and Cygwin we use TASKKILL\n # - we use stderr=subprocess.STDOUT to merge standard error and standard output\n import sys, subprocess, os, signal, shlex, time\n\n def _runPY3(command, timeout_s=None, shell=False):\n # py3.3+ because: timeout was added to communicate() in py3.3.\n new_session=False\n if sys.platform.startswith('linux'): new_session=True\n p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, start_new_session=new_session, shell=shell)\n\n try:\n out = p.communicate(timeout=timeout_s)[0].decode('utf-8')\n is_timeout_reached = False\n except subprocess.TimeoutExpired:\n print('Timeout reached: Killing the whole process group...')\n killAll(p.pid)\n out = p.communicate()[0].decode('utf-8')\n is_timeout_reached = True\n return p.returncode, out, is_timeout_reached\n\n def _runPY2(command, timeout_s=0, shell=False):\n preexec=None\n if sys.platform.startswith('linux'): preexec=os.setsid\n p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=preexec, shell=shell)\n\n start_time = time.time()\n is_timeout_reached = False\n while timeout_s and p.poll() == None:\n if time.time()-start_time >= timeout_s:\n print('Timeout reached: Killing the whole process group...')\n killAll(p.pid)\n is_timeout_reached = True\n break\n time.sleep(1)\n out = p.communicate()[0].decode('utf-8')\n return p.returncode, out, is_timeout_reached\n\n def killAll(ParentPid):\n if sys.platform.startswith('linux'):\n os.killpg(os.getpgid(ParentPid), signal.SIGTERM)\n elif sys.platform.startswith('cygwin'):\n # subprocess.Popen(shlex.split('bash -c \"TASKKILL /F /PID $(</proc/{pid}/winpid) /T\"'.format(pid=ParentPid)))\n winpid=int(open(\"/proc/{pid}/winpid\".format(pid=ParentPid)).read())\n subprocess.Popen(['TASKKILL', '/F', '/PID', str(winpid), '/T'])\n elif sys.platform.startswith('win32'):\n subprocess.Popen(['TASKKILL', '/F', '/PID', str(ParentPid), '/T'])\n\n # - In Windows, we never need to split the command, but in Cygwin and Linux we need to split if shell=False (default), shlex will split the command for us\n if shell==False and (sys.platform.startswith('cygwin') or sys.platform.startswith('linux')):\n command=shlex.split(command)\n\n if sys.version_info >= (3, 3): # py3.3+\n if timeout_s==False:\n returnCode, output, is_timeout_reached = _runPY3(command, timeout_s=None, shell=shell)\n else:\n returnCode, output, is_timeout_reached = _runPY3(command, timeout_s=timeout_s, shell=shell)\n else: # Python 2 and up to 3.2\n if timeout_s==False:\n returnCode, output, is_timeout_reached = _runPY2(command, timeout_s=0, shell=shell)\n else:\n returnCode, output, is_timeout_reached = _runPY2(command, timeout_s=timeout_s, shell=shell)\n\n return returnCode, output, is_timeout_reached\n" }, { "answer_id": 72216447, "author": "Mr. Day", "author_id": 18147761, "author_profile": "https://Stackoverflow.com/users/18147761", "pm_score": 3, "selected": false, "text": "os.system()" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17085/" ]
89,233
<p>Using Windows Server 2003 in a multi-user environment (via Remote Desktop, using it as an application server), how to mount a (preferably encrypted) volume in a way, that won't show up on any other user's desktop?</p> <p>Tried, and failed approaches:</p> <ul> <li><p>tweaking user rights -display of mounted volume can not be changed.</p></li> <li><p>Bestcrypt / truecrypt. Both of them displays the volume for a local administrator</p></li> </ul>
[ { "answer_id": 89249, "author": "Robit", "author_id": 17026, "author_profile": "https://Stackoverflow.com/users/17026", "pm_score": 0, "selected": false, "text": "A 1 00 00 00\nB 2 00 00 00\nC 4 00 00 00\nD 8 00 00 00\nE 16 00 00 00\nF 32 00 00 00\nG 64 00 00 00\nH 128 00 00 00\nI 00 1 00 00\nJ 00 2 00 00\nK 00 4 00 00\nL 00 8 00 00\nM 00 16 00 00\nN 00 32 00 00\nO 00 64 00 00\nP 00 128 00 00\nQ 00 00 1 00\nR 00 00 2 00\nS 00 00 4 00\nT 00 00 8 00\nU 00 00 16 00\nV 00 00 32 00\nW 00 00 64 00\nX 00 00 128 00\nY 00 00 00 1\nZ 00 00 00 2\n" }, { "answer_id": 89321, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 0, "selected": false, "text": "D:" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9440/" ]
89,245
<p>Suppose a large composite application built on several foundation components packaged in their own assemblies: (database reading, protocol handlers, etc.). For some deployments, this can include over 20 assemblies. Each of these assemblies has settings or configuration information. Our team tends to like the VS settings editor (and the easy-to-use code it generates!), and the application vs. user distinction meets most of our needs.</p> <p>BUT....</p> <p>It is very tedious to copy &amp; paste the many configuration sections into our application's .xml. Furthermore, for shared components that tend to have similar configurations across applications, this means we need to maintain duplicate settings in multiple .config files.</p> <p>Microsoft's EntLib solves this problem with an external tool to generate the monster .config file, but this feels klunky as well.</p> <p>What techniques do you use to manage large .NET .config files with sections from multiple shared assemblies? Some kind of include mechanism? Custom configuration readers?</p> <p>FOLLOWUP:</p> <p>Will's <a href="https://stackoverflow.com/questions/89245/how-do-you-manage-net-appconfig-files-for-large-applications#89618">answer</a> was exactly what I was getting at, and looks elegant for flat key/value pair sections. Is there a way to combine this approach with <a href="https://stackoverflow.com/questions/89245/how-do-you-manage-net-appconfig-files-for-large-applications#89618">custom configuration sections</a> ? </p> <p>Thanks also for the suggestions about managing different .configs for different build targets. That's also quite useful.</p> <p>Dave </p>
[ { "answer_id": 89261, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 5, "selected": true, "text": "<pages configSource=\"pages.config\"/>\n" }, { "answer_id": 90118, "author": "sontek", "author_id": 17176, "author_profile": "https://Stackoverflow.com/users/17176", "pm_score": 3, "selected": false, "text": "<Target Name=\"AfterBuild\">\n <Delete Files=\"$(TargetDir)$(TargetFileName).config\" />\n <Copy SourceFiles=\"$(ProjectDir)$(Configuration).config\" DestinationFiles=\"$(TargetDir)$(TargetFileName).config\" />\n</Target>\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6996/" ]
89,246
<p>I’m trying to run this SQL using get external.</p> <p>It works, but when I try to rename the sub-queries or anything for that matter it remove it.</p> <p>I tried <code>as</code>, <code>as</code> and the name in <code>''</code>, <code>as</code> then the name in <code>""</code>, and the same with space. What is the right way to do that? </p> <p>Relevant SQL:</p> <pre><code>SELECT list_name, app_name, (SELECT fname + ' ' + lname FROM dbo.d_agent_define map WHERE map.agent_id = tac.agent_id) as agent_login, input, CONVERT(varchar,DATEADD(ss,TAC_BEG_tstamp,'01/01/1970')) FROM dbo.maps_report_list list JOIN dbo.report_tac_agent tac ON (tac.list_id = list.list_id) WHERE input = 'SYS_ERR' AND app_name = 'CHARLOTT' AND convert(VARCHAR,DATEADD(ss,day_tstamp,'01/01/1970'),101) = '09/10/2008' AND list_name LIKE 'NRBAD%' ORDER BY agent_login,CONVERT(VARCHAR,DATEADD(ss,TAC_BEG_tstamp,'01/01/1970')) </code></pre>
[ { "answer_id": 89314, "author": "jttraino", "author_id": 3203, "author_profile": "https://Stackoverflow.com/users/3203", "pm_score": 1, "selected": false, "text": "dbo.d_agent_define" }, { "answer_id": 89450, "author": "Brettski", "author_id": 5836, "author_profile": "https://Stackoverflow.com/users/5836", "pm_score": 0, "selected": false, "text": "SELECT list_name, app_name, map.fname + ' ' + map.lname as agent_login, input, convert(varchar,dateadd(ss, TAC_BEG_tstamp, '01/01/1970))\nFROM dbo.maps_report_list inner join\n (dbo.report_tac_agent as tac inner join dbo.d_agent_define as map ON (tac.agent_id=map.agent_id)) ON list.list_id = tac.list_id\nWHERE input = 'SYS_ERR' and app_name = 'CHARLOTT' and convert(varchar,dateadd(ss,day_tstamp,'01/01/1970'),101) = '09/10/2008' \n and list_name LIKE 'NRBAD%' order by agent_login,convert(varchar,dateadd(ss,TAC_BEG_tstamp,'01/01/1970'))\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13122/" ]
89,257
<p>I've run into what appears to be a variable scope issue I haven't encountered before. I'm using Perl's CGI module and a call to DBI's do() method. Here's the code structure, simplified a bit:</p> <pre><code>use DBI; use CGI qw(:cgi-lib); &amp;ReadParse; my $dbh = DBI-&gt;connect(...............); my $test = $in{test}; $dbh-&gt;do(qq{INSERT INTO events VALUES (?,?,?)},undef,$in{test},"$in{test}",$test); </code></pre> <p>The #1 placeholder variable evaluates as if it is uninitialized. The other two placeholder variables work.</p> <p><strong>The question: Why is the %in hash not available within the context of do(), unless I wrap it in double quotes (#2 placeholder) or reassign the value to a new variable (#3 placeholder)?</strong></p> <p>I think it's something to do with how the CGI module's ReadParse() function assigns scope to the %in hash, but I don't know Perl scoping well enough to understand why %in is available at the top level but not from within my do() statement.</p> <p>If someone does understand the scoping issue, is there a better way to handle it? Wrapping all the %in references in double quotes seems a little messy. Creating new variables for each query parameter isn't realistic.</p> <p>Just to be clear, my question is about the variable scoping issue. I realize that ReadParse() isn't the recommended method to grab query params with CGI.</p> <p>I'm using Perl 5.8.8, CGI 3.20, and DBI 1.52. Thank you in advance to anyone reading this.</p> <p>@Pi &amp; @Bob, thanks for the suggestions. Pre-declaring the scope for %in has no effect (and I always use strict). The result is the same as before: in the db, col1 is null while cols 2 &amp; 3 are set to the expected value.</p> <p>For reference, here's the ReadParse function (see below). It's a standard function that's part of CGI.pm. The way I understand it, I'm not meant to initialize the %in hash (other than satisfying strict) for purposes of setting scope, since the function appears to me to handle that:</p> <pre><code>sub ReadParse { local(*in); if (@_) { *in = $_[0]; } else { my $pkg = caller(); *in=*{"${pkg}::in"}; } tie(%in,CGI); return scalar(keys %in); } </code></pre> <p>I guess my question is what is the best way to get the %in hash within the context of do()? Thanks again! I hope this is the right way to provide additional info to my original question.</p> <p>@Dan: I hear ya regarding the &amp;ReadParse syntax. I'd normally use CGI::ReadParse() but in this case I thought it was best to stick to how <a href="http://search.cpan.org/src/LDS/CGI.pm-3.42/cgi-lib_porting.html" rel="nofollow noreferrer">the CGI.pm documentation has it</a> exactly.</p>
[ { "answer_id": 89282, "author": "Alex M", "author_id": 9652, "author_profile": "https://Stackoverflow.com/users/9652", "pm_score": 2, "selected": false, "text": "use strict;" }, { "answer_id": 89573, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 0, "selected": false, "text": "use strict" }, { "answer_id": 89598, "author": "Michael Carman", "author_id": 8233, "author_profile": "https://Stackoverflow.com/users/8233", "pm_score": 2, "selected": false, "text": "$in{test}" }, { "answer_id": 89703, "author": "Michael Carman", "author_id": 8233, "author_profile": "https://Stackoverflow.com/users/8233", "pm_score": 2, "selected": false, "text": "$in{test}" }, { "answer_id": 89883, "author": "Michael Carman", "author_id": 8233, "author_profile": "https://Stackoverflow.com/users/8233", "pm_score": 0, "selected": false, "text": "tie()" }, { "answer_id": 91229, "author": "ysth", "author_id": 17389, "author_profile": "https://Stackoverflow.com/users/17389", "pm_score": 2, "selected": false, "text": "$ perl -MDBI -we'sub TIEHASH { bless {} } sub FETCH { \"42\" } tie %x, \"main\" or die; my $dbh = DBI->connect(\"dbi:SQLite:dbname=dbfile\",\"\",\"\"); $dbh->do(\"create table foo (bar char(80))\"); $dbh->do(\"insert into foo values (?)\", undef, $x{foo}); print \"got: \" . $dbh->selectrow_array(\"select bar from foo\") . \"\\n\"; $dbh->do(\"drop table foo\")'\ngot: 42\n" }, { "answer_id": 132107, "author": "Peter Stuifzand", "author_id": 1633, "author_profile": "https://Stackoverflow.com/users/1633", "pm_score": 0, "selected": false, "text": "...\nuse CGI qw/-debug/;\n...\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17092/" ]
89,266
<p>I'm designing a language. First, I want to decide what code to generate. The language will have lexical closures and prototype based inheritance similar to javascript. But I'm not a fan of gc and try to avoid as much as possible. So the question: Is there an elegant way to implement closures without resorting to allocate the stack frame on the heap and leave it to garbage collector?</p> <p>My first thoughts:</p> <ol> <li>Use reference counting and garbage collect the cycles (I don't really like this)</li> <li>Use spaghetti stack (looks very inefficient)</li> <li>Limit forming of closures to some contexts such a way that, I can get away with a return address stack and a locals' stack.</li> </ol> <p>I won't use a high level language or follow any call conventions, so I can smash the stack as much as I like.</p> <p>(Edit: I know reference counting is a form of garbage collection but I am using gc in its more common meaning)</p>
[ { "answer_id": 89346, "author": "Allen", "author_id": 6043, "author_profile": "https://Stackoverflow.com/users/6043", "pm_score": 4, "selected": false, "text": "gcc" }, { "answer_id": 89386, "author": "Daniel Spiewak", "author_id": 9815, "author_profile": "https://Stackoverflow.com/users/9815", "pm_score": 2, "selected": false, "text": "(int)=>int create_lambda(int a)\n{\n return { (int x) => x + a }\n}\n\ncreate_lambda(5)(4) // undefined result\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89266", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7988/" ]
89,275
<p>What is the best C++ IDE or editor for using on Windows? I use Notepad++, but am missing IntelliSense from Visual Studio.</p>
[ { "answer_id": 2640588, "author": "pyon", "author_id": 46571, "author_profile": "https://Stackoverflow.com/users/46571", "pm_score": 1, "selected": false, "text": "msdev.exe" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2039/" ]
89,320
<p>The scenario is this</p> <p>We have two applications A and B, both which are running in separate database (Oracle 9i ) transactions</p> <p>Application A - inserts some data into the database, then calls Application B Application B - inserts some data into the database, related (via foreign keys) to A's data. Returns an &quot;ID&quot; to Application A Application A - uses ID to insert further data, including the ID from B</p> <p>Now, because these are separate transactions, but both rely on data from each others transactions, we need to commit between the calls to each application. This of course makes it very difficult to rollback if anything goes wrong.</p> <p>How would you approach this problem, with minimal refactoring of the code. Surely this kind of this is a common problem in the SOA world?</p> <p>------ Update --------</p> <p>I have not been able to find anything in Oracle 9i, however Oracle 11g provides <a href="http://www.morganslibrary.org/reference/dbms_xa.html" rel="nofollow noreferrer">DBMS_XA</a>, which does exactly what I was after.</p>
[ { "answer_id": 89819, "author": "Brad Gilbert", "author_id": 1337, "author_profile": "https://Stackoverflow.com/users/1337", "pm_score": 0, "selected": false, "text": "App_A =={0}=> database # App_A stores information for App_B\nApp_A ------> App_B # App_A starts App_B\n App_B <={0}== database # App_B retrieves the information\n App_B =={1}=> database # App_B stores more informaion\nApp_A <={2}== App_B # App_B returns 'ID' to App_A\nApp_A ={2,3}> database # App_A stores 'ID' and additional data\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3839/" ]
89,332
<p>I frequently use <code>git stash</code> and <code>git stash pop</code> to save and restore changes in my working tree. Yesterday, I had some changes in my working tree that I had stashed and popped, and then I made more changes to my working tree. I'd like to go back and review yesterday's stashed changes, but <code>git stash pop</code> appears to remove all references to the associated commit.</p> <p>I know that if I use <code>git stash</code> then <em>.git/refs/stash contains</em> the reference of the commit used to create the stash. And <em>.git/logs/refs/stash contains</em> the whole stash. But those references are gone after <code>git stash pop</code>. I know that the commit is still in my repository somewhere, but I don't know what it was.</p> <p>Is there an easy way to recover yesterday's stash commit reference?</p>
[ { "answer_id": 89388, "author": "Nathan Jones", "author_id": 5848, "author_profile": "https://Stackoverflow.com/users/5848", "pm_score": 6, "selected": false, "text": "git fsck --unreachable | grep commit" }, { "answer_id": 89394, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 7, "selected": false, "text": "for ref in `find .git/objects | sed -e 's#.git/objects/##' | grep / | tr -d /`; do if [ `git cat-file -t $ref` = \"commit\" ]; then git show --summary $ref; fi; done | less\n" }, { "answer_id": 91795, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 13, "selected": true, "text": "git stash apply $stash_hash\n" }, { "answer_id": 608033, "author": "Wade", "author_id": 1871, "author_profile": "https://Stackoverflow.com/users/1871", "pm_score": 8, "selected": false, "text": "$ git stash apply ad38abbf76e26c803b27a6079348192d32f52219\n" }, { "answer_id": 5879550, "author": "Senthil A Kumar", "author_id": 289715, "author_profile": "https://Stackoverflow.com/users/289715", "pm_score": 8, "selected": false, "text": "git fsck --unreachable | grep commit | cut -d\" \" -f3 | xargs git log --merges --no-walk --grep=WIP\n" }, { "answer_id": 6455586, "author": "Colin Hebert", "author_id": 422597, "author_profile": "https://Stackoverflow.com/users/422597", "pm_score": 6, "selected": false, "text": "git fsck" }, { "answer_id": 7844566, "author": "Dolda2000", "author_id": 134252, "author_profile": "https://Stackoverflow.com/users/134252", "pm_score": 10, "selected": false, "text": "git stash pop" }, { "answer_id": 14157278, "author": "Phil", "author_id": 1129712, "author_profile": "https://Stackoverflow.com/users/1129712", "pm_score": 4, "selected": false, "text": "git fsck --no-reflog | awk '/dangling commit/ {print $3}' > tmp_commits\n\nfor h in `cat tmp_commits`; do git show $h | less; done\n" }, { "answer_id": 14203376, "author": "Shaheen Ghiassy", "author_id": 1179897, "author_profile": "https://Stackoverflow.com/users/1179897", "pm_score": 5, "selected": false, "text": "git show $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' ) > ~/stash_recovery.diff\n" }, { "answer_id": 19839165, "author": "Ben", "author_id": 874660, "author_profile": "https://Stackoverflow.com/users/874660", "pm_score": 2, "selected": false, "text": "git stash" }, { "answer_id": 34666995, "author": "emragins", "author_id": 219072, "author_profile": "https://Stackoverflow.com/users/219072", "pm_score": 6, "selected": false, "text": "gitk --all $(git fsck --no-reflog | Select-String \"(dangling commit )(.*)\" | %{ $_.Line.Split(' ')[2] })" }, { "answer_id": 37267192, "author": "Brad Feehan", "author_id": 1077375, "author_profile": "https://Stackoverflow.com/users/1077375", "pm_score": 4, "selected": false, "text": "git fsck --no-reflog | \\\nawk '/dangling commit/ {print $3}' | \\\nxargs git log --no-walk --format=\"%H\" \\\n --grep=\"WIP on\" --min-parents=3 --max-parents=3\n" }, { "answer_id": 37727162, "author": "Can Tecim", "author_id": 3294680, "author_profile": "https://Stackoverflow.com/users/3294680", "pm_score": 4, "selected": false, "text": "$ git fsck --unreachable | grep commit | cut -c 20- | xargs git show | grep -B 6 -A 2 <name of the stash>" }, { "answer_id": 42386983, "author": "Koen", "author_id": 1581660, "author_profile": "https://Stackoverflow.com/users/1581660", "pm_score": 4, "selected": false, "text": "awk" }, { "answer_id": 49150866, "author": "Vivek Kumar", "author_id": 5163085, "author_profile": "https://Stackoverflow.com/users/5163085", "pm_score": 5, "selected": false, "text": "git fsck --unreachable\n" }, { "answer_id": 57654136, "author": "Adrian W", "author_id": 2311167, "author_profile": "https://Stackoverflow.com/users/2311167", "pm_score": 5, "selected": false, "text": "git log --oneline $( git fsck --no-reflogs | awk '/dangling commit/ {print $3}' )\n" }, { "answer_id": 66249225, "author": "Treviño", "author_id": 210151, "author_profile": "https://Stackoverflow.com/users/210151", "pm_score": 3, "selected": false, "text": "git log --oneline --all --grep=\"^WIP on .*: [a-f0-9]\\+\" --grep=\"^On [^ ]*:\" --grep=\"^index on [^ ]*:\" $( env LANG=C git fsck --no-reflog | awk '/dangling commit/ {print $3}' )\n" }, { "answer_id": 70871838, "author": "minTwin", "author_id": 8046535, "author_profile": "https://Stackoverflow.com/users/8046535", "pm_score": 3, "selected": false, "text": "git fsck --no-reflogs | find \"dangling commit\"" }, { "answer_id": 71327982, "author": "anapsix", "author_id": 1633804, "author_profile": "https://Stackoverflow.com/users/1633804", "pm_score": 1, "selected": false, "text": "for i in $(git fsck --no-reflogs | awk '/dangling commit/ {print $3}'); do\n if git log -5 --name-only -u $i | grep -q \"<path-to-files>/.*<partial-file-name>.*\"; then\n echo \"found something in commit $i\";\n fi;\ndone\n" }, { "answer_id": 73544681, "author": "Changdae Park", "author_id": 10694438, "author_profile": "https://Stackoverflow.com/users/10694438", "pm_score": 1, "selected": false, "text": "Checking object directories: 100% (256/256), done.\n2022-08-31 10:20:46 +0900 8d02f61 WIP on master: 243b594 add css\nA favicon.ico\n" }, { "answer_id": 74139296, "author": "askepott", "author_id": 9288939, "author_profile": "https://Stackoverflow.com/users/9288939", "pm_score": 0, "selected": false, "text": "branch_a" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/893/" ]
89,350
<p>quick question: my customer has a situation where he has his database with a varchar field and the corresponding jdbc code is storing/retrieving a boolean.</p> <p>I guess that the boolean values false and true are going to be translated to "0" and "1" but I would like to have a confirmation of this (I can't find the precise behavior specification online, maybe it depends on each driver, Oracle in this case).</p> <p>I know I could experiment by myself, but I want to have a try at stackoverflow.com!</p> <p>Thanks for your answer,</p> <p>Eric.</p>
[ { "answer_id": 89405, "author": "Daniel Spiewak", "author_id": 9815, "author_profile": "https://Stackoverflow.com/users/9815", "pm_score": 0, "selected": false, "text": "BOOLEAN" }, { "answer_id": 89533, "author": "Joe Skora", "author_id": 14057, "author_profile": "https://Stackoverflow.com/users/14057", "pm_score": 1, "selected": false, "text": "123 => true\n456 => false\n" }, { "answer_id": 89789, "author": "user7611", "author_id": 7611, "author_profile": "https://Stackoverflow.com/users/7611", "pm_score": 1, "selected": false, "text": "boolean" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7611/" ]
89,372
<p>Has anyone been able to get a variable record length text file (CSV) into SQL Server via SSIS?</p> <p>I have tried time and again to get a CSV file into a SQL Server table, using SSIS, where the input file has varying record lengths. For this question, the two different record lengths are 63 and 326 bytes. All record lengths will be imported into the same 326 byte width table.</p> <p>There are over 1 million records to import.<br> I have no control of the creation of the import file.<br> I must use SSIS.<br> I have confirmed with MS that this has been reported as a bug. I have tried several workarounds. Most have been where I try to write custom code to intercept the record and I cant seem to get that to work as I want.</p>
[ { "answer_id": 9721041, "author": "Chris H", "author_id": 1271693, "author_profile": "https://Stackoverflow.com/users/1271693", "pm_score": 1, "selected": false, "text": "1" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14728/" ]
89,387
<p>Since Rails is not multithreaded (yet), it seems like a threaded web framework would be a better choice for a Facebook application. (reason being is cuz each Rails process can only handle one request at a time, and facebook actions tend to be slow, because there is a lot of network communication between your app and facebook)</p> <p>Has anyone used Merb to write a Facebook application? Is there a port of Facebooker (the Facebook plugin for Rails) to Merb?</p>
[ { "answer_id": 90716, "author": "Zach", "author_id": 9128, "author_profile": "https://Stackoverflow.com/users/9128", "pm_score": 2, "selected": false, "text": "gem install facebooker\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17076/" ]
89,402
<p>I need a very fast algorithm for the following task. I have already implemented several algorithms that complete it, but they're all too slow for the performance I need. It should be fast enough that the algorithm can be run at least 100,000 times a second on a modern CPU. It will be implemented in C++.</p> <p>I am working with spans/ranges, a structure that has a start and an end coordinate on a line.</p> <p>I have two vectors (dynamic arrays) of spans and I need to merge them. One vector is src and the other dst. The vectors are sorted by span start coordinates, and the spans do not overlap within one vector.</p> <p>The spans in the src vector must be merged with the spans in the dst vector, such that the resulting vector is still sorted and has no overlaps. Ie. if overlaps are detected during the merging, the two spans are merged into one. (Merging two spans is just a matter of changing the coordinates in the structure.)</p> <p>Now, there is one more catch, the spans in the src vector must be "widened" during the merge. This means that a constant will be added to the start and another (larger) constant to the end coordinate of every span in src. This means that after the src spans are widened they might overlap.</p> <hr> <p>What I have arrived at so far is that it cannot be done fully in-place, some kind of temporary storage is needed. I think it should be doable in linear time over the number of elements of src and dst summed.</p> <p>Any temporary storage can probably be shared between multiple runs of the algorithm.</p> <p>The two primary approaches I have tried, which are too slow, are:</p> <ol> <li><p>Append all elements of src to dst, widening each element before appending it. Then run an in-place sort. Finally iterate over the resulting vector using a "read" and "write" pointer, with the read pointer running ahead of the write pointer, merging spans as they go. When all elements have been merged (the read pointer reaches end) dst is truncated.</p></li> <li><p>Create a temporary work-vector. Do a naive merge as described above by repeatedly picking the next element from either src or dst and merging into the work-vector. When done, copy the work-vector to dst, replacing it.</p></li> </ol> <p>The first method has the problem that sorting is O((m+n)*log(m+n)) instead of O(m+n) and has somewhat overhead. It also means the dst vector has to grow much larger than it really needs.</p> <p>The second has the primary problem of a lot of copying around and again allocation/deallocation of memory.</p> <p>The data structures used for storing/managing the spans/vectors can be altered if you think that's needed.</p> <p>Update: Forgot to say how large the datasets are. The most common cases are between 4 and 30 elements in either vector, and either dst is empty or there is a large amount of overlap between the spans in src and dst.</p>
[ { "answer_id": 89424, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 0, "selected": false, "text": "if(src1[x] < src2[x])\n dst[x] = src1[x];\nelse\n dst[x] = src2[x];\n" }, { "answer_id": 89688, "author": "jfs", "author_id": 6223, "author_profile": "https://Stackoverflow.com/users/6223", "pm_score": 0, "selected": false, "text": "class SpanBuffer {\nprivate:\n int *data;\n size_t allocated_size;\n size_t count;\n\n inline void EnsureSpace()\n {\n if (count == allocated_size)\n Reserve(count*2);\n }\n\npublic:\n struct Span {\n int start, end;\n };\n\npublic:\n SpanBuffer()\n : data(0)\n , allocated_size(24)\n , count(0)\n {\n data = new int[allocated_size];\n }\n\n SpanBuffer(const SpanBuffer &src)\n : data(0)\n , allocated_size(src.allocated_size)\n , count(src.count)\n {\n data = new int[allocated_size];\n memcpy(data, src.data, sizeof(int)*count);\n }\n\n ~SpanBuffer()\n {\n delete [] data;\n }\n\n inline void AddIntersection(int x)\n {\n EnsureSpace();\n data[count++] = x;\n }\n\n inline void AddSpan(int s, int e)\n {\n assert((count & 1) == 0);\n assert(s >= 0);\n assert(e >= 0);\n EnsureSpace();\n data[count] = s;\n data[count+1] = e;\n count += 2;\n }\n\n inline void Clear()\n {\n count = 0;\n }\n\n inline size_t GetCount() const\n {\n return count;\n }\n\n inline int GetIntersection(size_t i) const\n {\n return data[i];\n }\n\n inline const Span * GetSpanIteratorBegin() const\n {\n assert((count & 1) == 0);\n return reinterpret_cast<const Span *>(data);\n }\n\n inline Span * GetSpanIteratorBegin()\n {\n assert((count & 1) == 0);\n return reinterpret_cast<Span *>(data);\n }\n\n inline const Span * GetSpanIteratorEnd() const\n {\n assert((count & 1) == 0);\n return reinterpret_cast<const Span *>(data+count);\n }\n\n inline Span * GetSpanIteratorEnd()\n {\n assert((count & 1) == 0);\n return reinterpret_cast<Span *>(data+count);\n }\n\n inline void MergeOrAddSpan(int s, int e)\n {\n assert((count & 1) == 0);\n assert(s >= 0);\n assert(e >= 0);\n\n if (count == 0)\n {\n AddSpan(s, e);\n return;\n }\n\n int *lastspan = data + count-2;\n\n if (s > lastspan[1])\n {\n AddSpan(s, e);\n }\n else\n {\n if (s < lastspan[0])\n lastspan[0] = s;\n if (e > lastspan[1])\n lastspan[1] = e;\n }\n }\n\n inline void Reserve(size_t minsize)\n {\n if (minsize <= allocated_size)\n return;\n\n int *newdata = new int[minsize];\n\n memcpy(newdata, data, sizeof(int)*count);\n\n delete [] data;\n data = newdata;\n\n allocated_size = minsize;\n }\n\n inline void SortIntersections()\n {\n assert((count & 1) == 0);\n std::sort(data, data+count, std::less<int>());\n assert((count & 1) == 0);\n }\n\n inline void Swap(SpanBuffer &other)\n {\n std::swap(data, other.data);\n std::swap(allocated_size, other.allocated_size);\n std::swap(count, other.count);\n }\n};\n\n\nstruct ShapeWidener {\n // How much to widen in the X direction\n int widen_by;\n // Half of width difference of src and dst (width of the border being produced)\n int xofs;\n\n // Temporary storage for OverlayScanline, so it doesn't need to reallocate for each call\n SpanBuffer buffer;\n\n inline void OverlayScanline(const SpanBuffer &src, SpanBuffer &dst);\n\n ShapeWidener(int _xofs) : xofs(_xofs) { }\n};\n\n\ninline void ShapeWidener::OverlayScanline(const SpanBuffer &src, SpanBuffer &dst)\n{\n if (src.GetCount() == 0) return;\n if (src.GetCount() + dst.GetCount() == 0) return;\n\n assert((src.GetCount() & 1) == 0);\n assert((dst.GetCount() & 1) == 0);\n\n assert(buffer.GetCount() == 0);\n\n dst.Swap(buffer);\n\n const int widen_s = xofs - widen_by;\n const int widen_e = xofs + widen_by;\n\n size_t resta = src.GetCount()/2;\n size_t restb = buffer.GetCount()/2;\n const SpanBuffer::Span *spa = src.GetSpanIteratorBegin();\n const SpanBuffer::Span *spb = buffer.GetSpanIteratorBegin();\n\n while (resta > 0 || restb > 0)\n {\n if (restb == 0)\n {\n dst.MergeOrAddSpan(spa->start+widen_s, spa->end+widen_e);\n --resta, ++spa;\n }\n else if (resta == 0)\n {\n dst.MergeOrAddSpan(spb->start, spb->end);\n --restb, ++spb;\n }\n else if (spa->start < spb->start)\n {\n dst.MergeOrAddSpan(spa->start+widen_s, spa->end+widen_e);\n --resta, ++spa;\n }\n else\n {\n dst.MergeOrAddSpan(spb->start, spb->end);\n --restb, ++spb;\n }\n }\n\n buffer.Clear();\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6223/" ]
89,418
<p>Assume I have an "images" folder directory under the root of my application. How can I, from within a .css file, reference an image in this directory using an ASP.NET app relative path. </p> <p>Example:</p> <p>When in development, the path of <strong>~/Images/Test.gif</strong> might resolve to <strong>/MyApp/Images/Test.gif</strong> while, in production, it might resolve to <strong>/Images/Test.gif</strong> (depending on the virtual directory for the application). I, obviously, want to avoid having to modify the .css file between environments.</p> <p>I know you can use Page.ResolveClientUrl to inject a url into a control's Style collection dynamically at render time. I would like to avoid doing this.</p>
[ { "answer_id": 89431, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 3, "selected": false, "text": "background-image: url(../images/test.gif);\n" }, { "answer_id": 442383, "author": "Marcel Popescu", "author_id": 31793, "author_profile": "https://Stackoverflow.com/users/31793", "pm_score": 4, "selected": false, "text": " <compilation debug=\"true\">\n <!-- Run CSS files through the ASPX handler so we can write code in them. -->\n <buildProviders>\n <add extension=\".css\" type=\"System.Web.Compilation.PageBuildProvider\" />\n </buildProviders>\n </compilation>\n\n <httpHandlers>\n <add path=\"*.css\" verb=\"GET\" type=\"System.Web.UI.PageHandlerFactory\" validate=\"true\" />\n </httpHandlers>\n" }, { "answer_id": 3094751, "author": "Snarf", "author_id": 307712, "author_profile": "https://Stackoverflow.com/users/307712", "pm_score": 2, "selected": false, "text": "background-image: url(<%= Page.ResolveUrl(\"~/images/bg_content.gif\") %>);\n" }, { "answer_id": 4319947, "author": "JohnB", "author_id": 287311, "author_profile": "https://Stackoverflow.com/users/287311", "pm_score": 3, "selected": false, "text": "/css/" }, { "answer_id": 9004534, "author": "Andrew Weitzen", "author_id": 1169429, "author_profile": "https://Stackoverflow.com/users/1169429", "pm_score": 2, "selected": false, "text": "<%@ Control %>\n<style type=\"text/css>\ndiv.content\n{\nbackground-image:(url(<%= Page.ResolveUrl(\"~/images/image.png\") %>);\n}\n</style>\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10834/" ]
89,441
<p>I have Visual Studio web test attached nicely to a data source, but I need to be able to iterate over each entry in the data source. How should I do this?</p>
[ { "answer_id": 89492, "author": "Ola Karlsson", "author_id": 10696, "author_profile": "https://Stackoverflow.com/users/10696", "pm_score": 2, "selected": true, "text": "[DataSource(\"System.Data.SqlClient\",\n \"Data Source=VSTS;Initial Catalog=ContactManagerWebTest;\n Integrated Security=True\", \"ValidContactInfo\",\n DataAccessMethod.Sequential), TestMethod()]\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13813/" ]
89,465
<p>Currently, WScript pops up message box when there is a script error. These scripts are called by other processes, and are ran on a server, so there is nobody to dismiss the error box. </p> <p>What I'd like is for the error message to be dumped to STDOUT, and execution to return the calling process. Popping as a MSGBox just hangs the entire thing.</p> <p>Ideas?</p>
[ { "answer_id": 89804, "author": "Jay Michaud", "author_id": 8613, "author_profile": "https://Stackoverflow.com/users/8613", "pm_score": 2, "selected": false, "text": "cscript //?" }, { "answer_id": 96124, "author": "aphoria", "author_id": 2441, "author_profile": "https://Stackoverflow.com/users/2441", "pm_score": 1, "selected": false, "text": "WScript.Echo" }, { "answer_id": 207756, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "cscript //b scriptname.vbs\n" }, { "answer_id": 7267143, "author": "Joe", "author_id": 13087, "author_profile": "https://Stackoverflow.com/users/13087", "pm_score": 0, "selected": false, "text": "DoWork" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
89,480
<p>For reasons I won't go into, I wish to ban an entire company from accessing my web site. Checking the remote hostname in php using gethostbyaddr() works, but this slows down the page load too much. Large organizations (eg. hp.com or microsoft.com) often have blocks of IP addresses. Is there anyway I get the full list, or am I stuck with the slow reverse-DNS lookup? If so, can I speed it up?</p> <p>Edit: Okay, now I know I can use the .htaccess file to ban a range. Now, how can I figure out what that range should be for a given organization?</p>
[ { "answer_id": 89495, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 5, "selected": true, "text": "Deny from x.x.x.x\n" }, { "answer_id": 89522, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 2, "selected": false, "text": "gethostbyaddr()" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15947/" ]
89,487
<p>I suppose it allows for moving changes from one branch to the next but that's what cherry picking is for and if you're not making a commit of your changes, perhaps you shouldn't be moving them around?</p> <p>I have on occasion applied the wrong stash at the wrong branch, which left me wondering about this question.</p>
[ { "answer_id": 89572, "author": "Patrick_O", "author_id": 11084, "author_profile": "https://Stackoverflow.com/users/11084", "pm_score": 4, "selected": false, "text": "git checkout -b new_stash\ngit commit -a -m \"stashed changes\"\n" }, { "answer_id": 11389081, "author": "Igbanam", "author_id": 393021, "author_profile": "https://Stackoverflow.com/users/393021", "pm_score": 4, "selected": false, "text": "git stash branch name_of_new_branch\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2108922/" ]
89,488
<p>I've been trying to implement a C#-like event system in C++ with the tr1 function templates used to store a function that handles the event. </p> <p>I created a vector so that multiple listeners can be attached to this event, i.e.:</p> <pre><code>vector&lt; function&lt;void (int)&gt; &gt; listenerList; </code></pre> <p>I'd like to be able to remove a handler from the list to stop a listener receiving events.</p> <p>So, how can I find the entry in this list that corresponds to a given listener? Can I test if a 'function' object in the list refers to a particular function?</p> <p>Thanks!</p> <p>EDIT: Having looked into the boost::signal approach, it seems it's probably implemented using a token system as some of you have suggested. <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/signals/tutorial.html" rel="nofollow noreferrer">Here's some info on this</a>. An observer retains a "Connection" object when they attach to an event, and this connection object is used to disconnect if needed. So it looks like whether you use Boost or roll your own with tr1, the basic principle's the same. i.e. it will be a bit clumsy :) </p>
[ { "answer_id": 89595, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 0, "selected": false, "text": "typeid" }, { "answer_id": 89693, "author": "Flame", "author_id": 5387, "author_profile": "https://Stackoverflow.com/users/5387", "pm_score": 0, "selected": false, "text": "map<key-type, function<void (int)> > listeners;\n" }, { "answer_id": 90115, "author": "Matt Cruikshank", "author_id": 8643, "author_profile": "https://Stackoverflow.com/users/8643", "pm_score": 2, "selected": false, "text": "#include \"stdafx.h\"\n#include <iostream>\n#include <string>\n#include <list>\n#include <algorithm>\n#include <boost/tr1/functional.hpp>\n#include <boost/tr1/memory.hpp>\n\nusing namespace std;\nusing namespace std::tr1;\n\ntemplate <typename T>\nclass ObserverHandle\n{\npublic:\n typedef boost::function<void (T*)> const UnderlyingFunction;\n\n ObserverHandle(UnderlyingFunction underlying)\n : _underlying(new UnderlyingFunction(underlying))\n {\n }\n\n void operator()(T* data) const\n {\n (*_underlying)(data);\n }\n\n bool operator==(ObserverHandle<T> const& other) const\n {\n return (other._underlying == _underlying);\n }\n\nprivate:\n shared_ptr<UnderlyingFunction> const _underlying;\n};\n\nclass BaseDelegate\n{\npublic:\n virtual bool operator==(BaseDelegate const& other)\n {\n return false;\n }\n\n virtual void operator() () const = 0;\n};\n\ntemplate <typename T>\nclass Delegate : public BaseDelegate\n{\npublic:\n Delegate(T* observer, ObserverHandle<T> handle)\n : _observer(observer),\n _handle(handle)\n {\n }\n\n virtual bool operator==(BaseDelegate const& other)\n {\n BaseDelegate const * otherPtr = &other;\n Delegate<T> const * otherDT = dynamic_cast<Delegate<T> const *>(otherPtr);\n return ((otherDT) &&\n (otherDT->_observer == _observer) &&\n (otherDT->_handle == _handle));\n }\n\n virtual void operator() () const\n {\n _handle(_observer);\n }\n\nprivate:\n T* _observer;\n ObserverHandle<T> _handle;\n};\n\nclass Event\n{\npublic:\n template <typename T>\n void add(T* observer, ObserverHandle<T> handle)\n {\n _observers.push_back(shared_ptr<BaseDelegate>(new Delegate<T>(observer, handle)));\n }\n\n template <typename T>\n void remove(T* observer, ObserverHandle<T> handle)\n {\n // I should be able to come up with a bind2nd(equals(dereference(_1))) kind of thing, but I can't figure it out now\n Observers::iterator it = find_if(_observers.begin(), _observers.end(), Compare(Delegate<T>(observer, handle)));\n if (it != _observers.end())\n {\n _observers.erase(it);\n }\n }\n\n void operator()() const\n {\n for (Observers::const_iterator it = _observers.begin();\n it != _observers.end();\n ++it)\n {\n (*(*it))();\n }\n }\n\nprivate:\n typedef list<shared_ptr<BaseDelegate>> Observers;\n Observers _observers;\n\n class Compare\n {\n public:\n Compare(BaseDelegate const& other)\n : _other(other)\n {\n }\n\n bool operator() (shared_ptr<BaseDelegate> const& other) const\n {\n return (*other) == _other;\n }\n\n private:\n BaseDelegate const& _other;\n };\n};\n\n// Example usage:\n\nclass SubjectA\n{\npublic:\n Event event;\n\n void do_event()\n {\n cout << \"doing event\" << endl;\n event();\n cout << \"done\" << endl;\n }\n};\n\nclass ObserverA\n{\npublic:\n void test(SubjectA& subject)\n {\n subject.do_event();\n cout << endl;\n\n subject.event.add(this, _observe);\n subject.do_event();\n subject.event.remove(this, _observe);\n cout << endl;\n\n subject.do_event();\n cout << endl;\n\n subject.event.add(this, _observe);\n subject.event.add(this, _observe);\n subject.do_event();\n subject.event.remove(this, _observe);\n subject.do_event();\n subject.event.remove(this, _observe);\n cout << endl;\n\n }\n\n void observe()\n {\n cout << \"..observed!\" << endl;\n }\n\nprivate:\n static ObserverHandle<ObserverA> _observe;\n};\n\n// Here's the trick: make a static object for each method you might want to turn into a Delegate\nObserverHandle<ObserverA> ObserverA::_observe(boost::bind(&ObserverA::observe, _1));\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n SubjectA sa;\n ObserverA oa;\n oa.test(sa);\n\n return 0;\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17136/" ]
89,489
<p>I was following along with the railscast regarding the restful_authentication plugin.</p> <p>He recommended running the command:</p> <p>script/generate authenticated user session</p> <p>Which I did, and everything generated "fine", but then sessions wouldn't work. Checking the site again, he mentions a naming standard and listed updated code which stated:</p> <p>script/generate authenticated user sessions</p> <p>With sessions being pluralized.</p> <p>So now I have session_controller.rb with a SessionController in it, but I guess by naming standards, it is looking for SessionsController, causing the code to fail out with the error "NameError in SessionsController#create "</p> <p>I see the problem, which is pretty obvious, but what I don't know is, how do I fix this without regenerating the content? Is there a way to reverse the generation process to clear out all changes made by the generation?</p> <p>I tried just renaming the files to sessions_controller with e SessionsController class, but that failed.</p> <p>While writing this, I solved my own problem. I had to rename session to sessions in the routes file as a map.resource and rename the view directory from session to sessions, and update session_path in the html.erb file to sessions_path.</p> <p>So I solved my problem, but my answer regarding removing generated content still remains. Is it possible to ungenerate content?</p>
[ { "answer_id": 89525, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 1, "selected": false, "text": "script/destroy" }, { "answer_id": 90044, "author": "Misplaced", "author_id": 13710, "author_profile": "https://Stackoverflow.com/users/13710", "pm_score": 2, "selected": false, "text": "script/destroy" }, { "answer_id": 90952, "author": "Ben Scofield", "author_id": 6478, "author_profile": "https://Stackoverflow.com/users/6478", "pm_score": 5, "selected": true, "text": "script/destroy" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9450/" ]
89,490
<p>How do I set the symbol for the <em>angle</em> or <em>annuity</em> operation in LaTeX? Specifically, this is the actuarial <em>a</em> angle <em>s</em> = (1-v<sup>s</sup>)/i.</p>
[ { "answer_id": 89851, "author": "Joseph Holsten", "author_id": 16981, "author_profile": "https://Stackoverflow.com/users/16981", "pm_score": 3, "selected": false, "text": "\\DeclareRobustCommand{\\lcroof}[1]{\n \\hbox{\\vtop{\\vbox{%\n \\hrule\\kern 1pt\\hbox{%\n $\\scriptstyle #1$%\n \\kern 1pt}}\\kern1pt}%\n \\vrule\\kern1pt}}\n\\DeclareRobustCommand{\\angle}[1]{\n _{\\lcroof{#1}}}\n" }, { "answer_id": 43643797, "author": "David Beauchemin", "author_id": 7927776, "author_profile": "https://Stackoverflow.com/users/7927776", "pm_score": 2, "selected": false, "text": "\\usepackage{actuarialsymbol}\n" }, { "answer_id": 45383016, "author": "Francesco", "author_id": 4569100, "author_profile": "https://Stackoverflow.com/users/4569100", "pm_score": 2, "selected": false, "text": "\\documentclass{article}\n\\usepackage{siunitx}\n\n\\makeatletter\n\\newcommand*{\\NegationLike}[1]{%\n \\mathop{%\n \\mathpalette\\@NegationLike{#1}%\n }%\n % A little space is added automatically,\n % if a math ord atom follows.\n}\n\\newdimen\\BarLineWidth\n\\newcommand*{\\@NegationLike}[2]{%\n % #1: math style\n % #2: argument\n \\vbox{%\n % The rule thickness of \\overline or \\underline\n % is available in the font dimen register 8\n % of the math family 3 of the current size.\n \\BarLineWidth=%\n \\the\\fontdimen8%\n \\ifx\\displaystyle#1\\textfont\n \\else\\ifx\\textstyle#1\\textfont\n \\else\\ifx\\scriptstyle#1\\scriptfont\n \\else\\scriptscriptfont\n \\fi\\fi\\fi\n 3\\relax\n % The rule at the top\n \\hrule height\\BarLineWidth\n % Move the box with the vertical line\n % as height as the top of the upper line\n % to get a better corner.\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16981/" ]
89,504
<p>I've got a standard Rails app with Nginx and Mongrel running at <a href="http://mydomain" rel="noreferrer">http://mydomain</a>. I need to run a Wordpress blog at <a href="http://mydomain.com/blog" rel="noreferrer">http://mydomain.com/blog</a>. My preference would be to host the blog in Apache running on either the same server or a separate box but I don't want the user to see a different server in the URL. Is that possible and if not, what would you recommend to accomplish the goal?</p>
[ { "answer_id": 89530, "author": "joelhardi", "author_id": 11438, "author_profile": "https://Stackoverflow.com/users/11438", "pm_score": 3, "selected": false, "text": "server {\n listen example.com:80;\n server_name example.com;\n charset utf-8;\n error_log /www/example.com/log/error.log;\n access_log /www/example.com/log/access.log main;\n root /www/example.com/htdocs;\n\n include /www/etc/nginx/fastcgi.conf;\n fastcgi_index index.php;\n\n # Send *.php to PHP FastCGI on :9001\n location ~ \\.php$ {\n fastcgi_pass 127.0.0.1:9001;\n }\n\n # You could put another \"location\" section here to match some URLs and send\n # them to Rails. Or do it the opposite way and have \"/blog/*\" go to PHP\n # first and then everything else go to Rails. Whatever regexes you feel like\n # putting into \"location\" sections!\n\n location / {\n index index.html index.php;\n # URLs that don't exist go to WordPress /index.php PHP FastCGI\n if (!-e $request_filename) {\n rewrite ^.* /index.php break;\n fastcgi_pass 127.0.0.1:9001;\n }\n\n }\n}\n" }, { "answer_id": 90896, "author": "Patrick McKenzie", "author_id": 15046, "author_profile": "https://Stackoverflow.com/users/15046", "pm_score": 4, "selected": true, "text": "upstream myBlogVPS {\n server 127.0.0.2:80; #fix me to point to your blog VPS\n}\n\n server {\n listen 80;\n\n\n #You'll have plenty of things for Rails compatibility here\n\n #Make sure you don't accidentally step on this with the Rails config!\n\n location /blog {\n proxy_pass http://myBlogVPS;\n proxy_redirect off;\n\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n }\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14619/" ]
89,543
<p>I want to set something up so that if an Account within my app is disabled, I want all requests to be redirected to a "disabled" message.</p> <p>I've set this up in my ApplicationController:</p> <pre><code>class ApplicationController &lt; ActionController::Base before_filter :check_account def check_account redirect_to :controller =&gt; "main", :action =&gt; "disabled" and return if !$account.active? end end </code></pre> <p>Of course, this doesn't quite work as it goes into an infinite loop if the Account is not active. I was hoping to use something like:</p> <pre><code>redirect_to :controller =&gt; "main", :action =&gt; "disabled" and return if !$account.active? &amp;&amp; @controller.controller_name != "main" &amp;&amp; @controller.action_name != "disabled" </code></pre> <p>but I noticed that in Rails v2.1 (what I'm using), @controller is now controller and this doesn't seem to work in ApplicationController.</p> <p>What would be the best way to implement something like this?</p>
[ { "answer_id": 89647, "author": "Ian Terrell", "author_id": 9269, "author_profile": "https://Stackoverflow.com/users/9269", "pm_score": 3, "selected": false, "text": "before_filter :check_account, :except => :disabled\n" }, { "answer_id": 90149, "author": "Tony Pitale", "author_id": 1167846, "author_profile": "https://Stackoverflow.com/users/1167846", "pm_score": 3, "selected": true, "text": "skip_before_filter" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14530/" ]
89,576
<p>I am trying to connect to a Microsoft SQL 2005 server which is not on port 1433. How do I indicate a different port number when connecting to the server using SQL Management Studio?</p>
[ { "answer_id": 89583, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 11, "selected": true, "text": "127.0.0.1,6283" }, { "answer_id": 89677, "author": "James", "author_id": 2719, "author_profile": "https://Stackoverflow.com/users/2719", "pm_score": 6, "selected": false, "text": "tcp:192.168.1.21\\SQL2K5,1443" }, { "answer_id": 19951852, "author": "guest", "author_id": 2987361, "author_profile": "https://Stackoverflow.com/users/2987361", "pm_score": -1, "selected": false, "text": "netstat -a -b\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5836/" ]
89,588
<p>You do <code>AssignProcessToJobObject</code> and it fails with "access denied" but only when you are running in the debugger. Why is this?</p>
[ { "answer_id": 89589, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 6, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n <assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n <!-- Identify the application security requirements. -->\n <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\">\n <security>\n <requestedPrivileges>\n <requestedExecutionLevel\n level=\"asInvoker\"\n uiAccess=\"false\"/>\n </requestedPrivileges>\n </security>\n </trustInfo>\n </assembly>\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
89,603
<p>When writing C/C++ code, in order to debug the binary executable the debug option must be enabled on the compiler/linker. In the case of GCC, the option is -g. When the debug option is enabled, how does the affect the binary executable? What additional data is stored in the file that allows the debugger function as it does?</p>
[ { "answer_id": 89669, "author": "Bernard", "author_id": 61, "author_profile": "https://Stackoverflow.com/users/61", "pm_score": 2, "selected": false, "text": "-g" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89603", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10216/" ]
89,606
<p>I have a table that got into the "db_owner" schema, and I need it in the "dbo" schema.</p> <p>Is there a script or command to run to switch it over?</p>
[ { "answer_id": 89635, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 6, "selected": false, "text": "ALTER SCHEMA [NewSchema] TRANSFER [OldSchema].[Table1]\n" }, { "answer_id": 89658, "author": "Craig", "author_id": 13988, "author_profile": "https://Stackoverflow.com/users/13988", "pm_score": -1, "selected": false, "text": "sp_MSforeachtable @command1=\"sp_changeobjectowner \"\"?\"\",'dbo'\"\n" }, { "answer_id": 89664, "author": "Jeremy", "author_id": 8557, "author_profile": "https://Stackoverflow.com/users/8557", "pm_score": 3, "selected": false, "text": "sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'\n" }, { "answer_id": 2175349, "author": "sAeid mOhammad hAshem", "author_id": 263323, "author_profile": "https://Stackoverflow.com/users/263323", "pm_score": 4, "selected": false, "text": "TABLE_SCHEMA" }, { "answer_id": 6284546, "author": "Oliver", "author_id": 19017, "author_profile": "https://Stackoverflow.com/users/19017", "pm_score": 2, "selected": false, "text": "declare @sql varchar(8000)\n;\n\nselect\n @sql = coalesce( @sql, ';', '') + 'alter schema dbo transfer [' + s.name + '].[' + t.name + '];'\nfrom \n sys.tables t\n inner join\n sys.schemas s on t.[schema_id] = s.[schema_id]\nwhere \n s.name <> 'dbo'\n;\n\nexec( @sql )\n;\n" }, { "answer_id": 10502805, "author": "Lanceomagnifico", "author_id": 83673, "author_profile": "https://Stackoverflow.com/users/83673", "pm_score": 3, "selected": false, "text": "DECLARE cursore CURSOR FOR \n\n\nselect specific_schema as 'schema', specific_name AS 'name'\nFROM INFORMATION_SCHEMA.routines\nWHERE specific_schema <> 'dbo' \n\nUNION ALL\n\nSELECT TABLE_SCHEMA AS 'schema', TABLE_NAME AS 'name'\nFROM INFORMATION_SCHEMA.TABLES \nWHERE TABLE_SCHEMA <> 'dbo' \n\n\n\nDECLARE @schema sysname, \n @tab sysname, \n @sql varchar(500) \n\n\nOPEN cursore \nFETCH NEXT FROM cursore INTO @schema, @tab \n\nWHILE @@FETCH_STATUS = 0 \nBEGIN \n SET @sql = 'ALTER SCHEMA dbo TRANSFER [' + @schema + '].[' + @tab +']' \n PRINT @sql \n exec (@sql) \n FETCH NEXT FROM cursore INTO @schema, @tab \nEND \n\nCLOSE cursore \nDEALLOCATE cursore\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1220/" ]
89,607
<p>I have added some code which compiles cleanly and have just received this Windows error:</p> <pre><code>--------------------------- (MonTel Administrator) 2.12.7: MtAdmin.exe - Application Error --------------------------- The exception Privileged instruction. (0xc0000096) occurred in the application at location 0x00486752. </code></pre> <p>I am about to go on a bug hunt, and I am expecting it to be something silly that I have done which just happens to produce this message. The code compiles cleanly with no errors or warnings. The size of the EXE file has grown to 1,454,132 bytes and includes links to <code>ODCS.lib</code>, but it is otherwise pure C to the Win32 API, with DEBUG on (running on a P4 on Windows&nbsp;2000).</p>
[ { "answer_id": 89643, "author": "Tim Williscroft", "author_id": 2789, "author_profile": "https://Stackoverflow.com/users/2789", "pm_score": 2, "selected": false, "text": "std::string" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3137/" ]
89,609
<p>I'm looking for the best way to take a simple input:</p> <pre><code>echo -n "Enter a string here: " read -e STRING </code></pre> <p>and clean it up by removing non-alphanumeric characters, lower(case), and replacing spaces with underscores.</p> <p>Does order matter? Is <code>tr</code> the best / only way to go about this?</p>
[ { "answer_id": 89642, "author": "Devin Reams", "author_id": 16248, "author_profile": "https://Stackoverflow.com/users/16248", "pm_score": 0, "selected": false, "text": "tr" }, { "answer_id": 89780, "author": "Axeman", "author_id": 11289, "author_profile": "https://Stackoverflow.com/users/11289", "pm_score": 0, "selected": false, "text": "export CLEANSTRING=$(perl -e 'print join( q//, map { s/\\\\s+/_/g; lc } split /[^\\\\s\\\\w]+/, \\$ENV{STRING} )')\n" }, { "answer_id": 89970, "author": "dj_segfault", "author_id": 14924, "author_profile": "https://Stackoverflow.com/users/14924", "pm_score": 5, "selected": false, "text": "CLEANSTRING=${STRING//[^a-zA-Z0-9]/}\n" }, { "answer_id": 94500, "author": "Thomee", "author_id": 12825, "author_profile": "https://Stackoverflow.com/users/12825", "pm_score": 7, "selected": true, "text": "# first, strip underscores\nCLEAN=${STRING//_/}\n# next, replace spaces with underscores\nCLEAN=${CLEAN// /_}\n# now, clean out anything that's not alphanumeric or an underscore\nCLEAN=${CLEAN//[^a-zA-Z0-9_]/}\n# finally, lowercase with TR\nCLEAN=`echo -n $CLEAN | tr A-Z a-z`\n" }, { "answer_id": 59919397, "author": "anon_stackoverflock", "author_id": 5800081, "author_profile": "https://Stackoverflow.com/users/5800081", "pm_score": 2, "selected": false, "text": "CLEAN=\"${STRING//_/}\" && \\\nCLEAN=\"${CLEAN// /_}\" && \\\nCLEAN=\"${CLEAN//[^a-zA-Z0-9]/}\" && \\\nCLEAN=\"${CLEAN,,}\"\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89609", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16248/" ]
89,650
<p>I would like to pass an argument(s) to a method being defined using define_method, how would I do that?</p>
[ { "answer_id": 89661, "author": "easeout", "author_id": 10906, "author_profile": "https://Stackoverflow.com/users/10906", "pm_score": 9, "selected": true, "text": "define_method(:say_hi) { |other| puts \"Hi, \" + other }\n" }, { "answer_id": 109379, "author": "Jörg W Mittag", "author_id": 2988, "author_profile": "https://Stackoverflow.com/users/2988", "pm_score": 6, "selected": false, "text": "# Works\ndef meth(default = :foo, *splat, &block) puts 'Bar'; end\n\n# Doesn't work\ndefine_method :meth { |default = :foo, *splat, &block| puts 'Bar' }\n\n# This works in Ruby 1.9 (modulo typos, I don't actually have it installed)\ndefine_method :meth, ->(default = :foo, *splat, &block) { puts 'Bar' }\n" }, { "answer_id": 11098487, "author": "equivalent8", "author_id": 473040, "author_profile": "https://Stackoverflow.com/users/473040", "pm_score": 7, "selected": false, "text": " class Bar\n define_method(:foo) do |arg=nil| \n arg \n end \n end\n\n a = Bar.new\n a.foo\n #=> nil\n a.foo 1\n # => 1\n" }, { "answer_id": 37006132, "author": "akostadinov", "author_id": 520567, "author_profile": "https://Stackoverflow.com/users/520567", "pm_score": 3, "selected": false, "text": "define_method(:method) do |refresh: false|\n ..........\nend\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1681/" ]
89,672
<p>When you create a new content type in Drupal using the Content Creation Kit, you automatically get Title and Body fields in the generated form. Is there a way to remove them?</p>
[ { "answer_id": 1196442, "author": "Volomike", "author_id": 105539, "author_profile": "https://Stackoverflow.com/users/105539", "pm_score": 2, "selected": false, "text": "<?php echo $node->field_staff_email[0]['email']; ?>\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5808/" ]
89,696
<p>I have Oracle SQL Developer already installed and am able to connect to and query Oracle databases.</p> <p>Using Help -> Check for Updates I was able to install the Oracle MySQL Browser extension but there are no connection options for MySQL databases.</p>
[ { "answer_id": 26598840, "author": "codingknob", "author_id": 668624, "author_profile": "https://Stackoverflow.com/users/668624", "pm_score": 0, "selected": false, "text": "ntlmauth.dll" }, { "answer_id": 37999123, "author": "Ale", "author_id": 6505642, "author_profile": "https://Stackoverflow.com/users/6505642", "pm_score": 1, "selected": false, "text": " i. “PE d” it is 64.\n\nii. “PE L” it is 32.\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5808/" ]
89,705
<p>I'm going through the problems on projecteuler.net to learn how to program in Erlang, and I am having the hardest time creating a prime generator that can create all of the primes below 2 million, in less than a minute. Using the sequential style, I have already written three types of generators, including the Sieve of Eratosthenes, and none of them perform well enough.</p> <p>I figured a concurrent Sieve would work great, but I'm getting bad_arity messages, and I'm not sure why. Any suggestions on why I have the problem, or how to code it properly? </p> <p>Here's my code, the commented out sections are where I tried to make things concurrent:</p> <pre> -module(primeserver). -compile(export_all). start() -> register(primes, spawn(fun() -> loop() end)). is_prime(N) -> rpc({is_prime,N}). rpc(Request) -> primes ! {self(), Request}, receive {primes, Response} -> Response end. loop() -> receive {From, {is_prime, N}} -> if N From ! {primes, false}; N =:= 2 -> From ! {primes, true}; N rem 2 =:= 0 -> From ! {primes, false}; true -> Values = is_not_prime(N), Val = not(lists:member(true, Values)), From ! {primes, Val} end, loop() end. for(N,N,_,F) -> [F(N)]; for(I,N,S,F) when I + S [F(I)|for(I+S, N, S, F)]; for(I,N,S,F) when I + S =:= N -> [F(I)|for(I+S, N, S, F)]; for(I,N,S,F) when I + S > N -> [F(I)]. get_list(I, Limit) -> if I [I*A || A [] end. is_not_prime(N) -> for(3, N, 2, fun(I) -> List = get_list(I,trunc(N/I)), lists:member(N,lists:flatten(List)) end ). %%L = for(1,N, fun() -> spawn(fun(I) -> wait(I,N) end) end), %%SeedList = [A || A %% lists:foreach(fun(X) -> %% Pid ! {in_list, X} %% end, SeedList) %% end, L). %%wait(I,N) -> %% List = [I*A || A lists:member(X,List) %% end. </pre>
[ { "answer_id": 89726, "author": "theo", "author_id": 7870, "author_profile": "https://Stackoverflow.com/users/7870", "pm_score": -1, "selected": false, "text": "For Each NUMBER in LIST_OF_PRIMES\n If TEST_VALUE % NUMBER == 0\n Then FALSE\nEND\nTRUE\n\nif isPrime == TRUE add TEST_VALUE to your LIST_OF_PRIMES\n\niterate starting at 14 or so with a preset list of your beginning primes. \n" }, { "answer_id": 113878, "author": "uwiger", "author_id": 6834, "author_profile": "https://Stackoverflow.com/users/6834", "pm_score": 3, "selected": true, "text": "L = for(1, N, fun(I) -> spawn(fun() -> wait(I, N) end) end),\n" }, { "answer_id": 634799, "author": "dbasnett", "author_id": 66532, "author_profile": "https://Stackoverflow.com/users/66532", "pm_score": -1, "selected": false, "text": " 'Sieve of Eratosthenes \n'http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes \n'1. Create a contiguous list of numbers from two to some highest number n. \n'2. Strike out from the list all multiples of two (4, 6, 8 etc.). \n'3. The list's next number that has not been struck out is a prime number. \n'4. Strike out from the list all multiples of the number you identified in the previous step. \n'5. Repeat steps 3 and 4 until you reach a number that is greater than the square root of n (the highest number in the list). \n'6. All the remaining numbers in the list are prime. \nPrivate Function Sieve_of_Eratosthenes(ByVal MaxNum As Integer) As List(Of Integer)\n 'tested to MaxNum = 10,000,000 - on 1.8Ghz Laptop it took 1.4 seconds\n Dim thePrimes As New List(Of Integer)\n Dim toNum As Integer = MaxNum, stpw As New Stopwatch\n If toNum > 1 Then 'the first prime is 2\n stpw.Start()\n thePrimes.Capacity = toNum 'size the list\n Dim idx As Integer\n Dim stopAT As Integer = CInt(Math.Sqrt(toNum) + 1)\n '1. Create a contiguous list of numbers from two to some highest number n.\n '2. Strike out from the list all multiples of 2, 3, 5. \n For idx = 0 To toNum\n If idx > 5 Then\n If idx Mod 2 <> 0 _\n AndAlso idx Mod 3 <> 0 _\n AndAlso idx Mod 5 <> 0 Then thePrimes.Add(idx) Else thePrimes.Add(-1)\n Else\n thePrimes.Add(idx)\n End If\n Next\n 'mark 0,1 and 4 as non-prime\n thePrimes(0) = -1\n thePrimes(1) = -1\n thePrimes(4) = -1\n Dim aPrime, startAT As Integer\n idx = 7 'starting at 7 check for primes and multiples \n Do\n '3. The list's next number that has not been struck out is a prime number. \n '4. Strike out from the list all multiples of the number you identified in the previous step. \n '5. Repeat steps 3 and 4 until you reach a number that is greater than the square root of n (the highest number in the list). \n If thePrimes(idx) <> -1 Then ' if equal to -1 the number is not a prime\n 'not equal to -1 the number is a prime\n aPrime = thePrimes(idx)\n 'get rid of multiples \n startAT = aPrime * aPrime\n For mltpl As Integer = startAT To thePrimes.Count - 1 Step aPrime\n If thePrimes(mltpl) <> -1 Then thePrimes(mltpl) = -1\n Next\n End If\n idx += 2 'increment index \n Loop While idx < stopAT\n '6. All the remaining numbers in the list are prime. \n thePrimes = thePrimes.FindAll(Function(i As Integer) i <> -1)\n stpw.Stop()\n Debug.WriteLine(stpw.ElapsedMilliseconds)\n End If\n Return thePrimes\nEnd Function\n" }, { "answer_id": 1343326, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "-module(primes).\n-export([sprimes/1, wheel/3, fprimes/1, filter/2]). \n\nsieve([H|T], M) when H=< M -> [H|sieve([X || X<- T, X rem H /= 0], M)];\nsieve(L, _) -> L.\nsprimes(N) -> [2,3,5,7|sieve(wheel(11, [2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,8,6,4,6,2,4,6,2,6,6,4,2,4,6,2,6,4,2,4,2,10,2,10], N), math:sqrt(N))].\n\nwheel([X|Xs], _Js, M) when X > M ->\n lists:reverse(Xs);\nwheel([X|Xs], [J|Js], M) ->\n wheel([X+J,X|Xs], lazy:next(Js), M);\nwheel(S, Js, M) ->\n wheel([S], lazy:lazy(Js), M).\n\nfprimes(N) ->\n fprimes(wheel(11, [2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,8,6,4,6,2,4,6,2,6,6,4,2,4,6,2,6,4,2,4,2,10,2,10], N), [7,5,3,2], N).\nfprimes([H|T], A, Max) when H*H =< Max ->\n fprimes(filter(H, T), [H|A], Max);\nfprimes(L, A, _Max) -> lists:append(lists:reverse(A), L).\n\nfilter(N, L) ->\n filter(N, N*N, L, []).\nfilter(N, N2, [X|Xs], A) when X < N2 ->\n filter(N, N2, Xs, [X|A]);\nfilter(N, _N2, L, A) ->\n filter(N, L, A).\nfilter(N, [X|Xs], A) when X rem N /= 0 ->\n filter(N, Xs, [X|A]);\nfilter(N, [_X|Xs], A) ->\n filter(N, Xs, A);\nfilter(_N, [], A) ->\n lists:reverse(A).\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89705", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8040/" ]
89,708
<p>I am trying to extract a gif image embedded as a resource within my ISAPI dll using WebBroker technology. The resource has been added to the DLL using the following RC code:</p> <pre><code>LOGO_GIF RCDATA logo.gif </code></pre> <p>Using resource explorer I verified it is in the DLL properly.</p> <p>using the following code always throws an exception, "resource not found" (using Delphi 2009)</p> <pre><code>var rc : tResourceStream; begin rc := tResourceStream.Create(hInstance,'LOGO_GIF','RCDATA'); end; </code></pre>
[ { "answer_id": 90496, "author": "Tim Knipe", "author_id": 10493, "author_profile": "https://Stackoverflow.com/users/10493", "pm_score": 3, "selected": true, "text": "rc := tResourceStream.Create(hInstance,'LOGO_GIF', MakeIntResource(RT_RCDATA));\n" }, { "answer_id": 90742, "author": "Francesca", "author_id": 9842, "author_profile": "https://Stackoverflow.com/users/9842", "pm_score": 1, "selected": false, "text": "LOGO_GIF GIF logo.gif\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9217/" ]
89,741
<p>I'd like to know what the currently checked out revision number is for a file or directory. Is there a way to do this in TortoiseSVN on Windows ?</p>
[ { "answer_id": 89817, "author": "DevelopingChris", "author_id": 1220, "author_profile": "https://Stackoverflow.com/users/1220", "pm_score": 5, "selected": false, "text": "svn info\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5324/" ]
89,745
<p>I am trying to find the virtual file that contains the current users id. I was told that I could find it in the proc directory, but not quite sure which file.</p>
[ { "answer_id": 89763, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 2, "selected": false, "text": "/proc" }, { "answer_id": 89765, "author": "dreamlax", "author_id": 10320, "author_profile": "https://Stackoverflow.com/users/10320", "pm_score": 3, "selected": false, "text": "id -u" }, { "answer_id": 89778, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": 1, "selected": false, "text": "$USER" }, { "answer_id": 89788, "author": "jfs", "author_id": 6223, "author_profile": "https://Stackoverflow.com/users/6223", "pm_score": 2, "selected": false, "text": "/proc" }, { "answer_id": 89797, "author": "Thomas", "author_id": 14637, "author_profile": "https://Stackoverflow.com/users/14637", "pm_score": 1, "selected": false, "text": "/proc/process_id/status" }, { "answer_id": 89802, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 4, "selected": true, "text": "/proc/self/status" }, { "answer_id": 93156, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "*nix" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89745", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17162/" ]
89,752
<p>How can I get <strong>hierarchy recordset</strong> in ms access through <strong>select</strong> statement?</p>
[ { "answer_id": 89763, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 2, "selected": false, "text": "/proc" }, { "answer_id": 89765, "author": "dreamlax", "author_id": 10320, "author_profile": "https://Stackoverflow.com/users/10320", "pm_score": 3, "selected": false, "text": "id -u" }, { "answer_id": 89778, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": 1, "selected": false, "text": "$USER" }, { "answer_id": 89788, "author": "jfs", "author_id": 6223, "author_profile": "https://Stackoverflow.com/users/6223", "pm_score": 2, "selected": false, "text": "/proc" }, { "answer_id": 89797, "author": "Thomas", "author_id": 14637, "author_profile": "https://Stackoverflow.com/users/14637", "pm_score": 1, "selected": false, "text": "/proc/process_id/status" }, { "answer_id": 89802, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 4, "selected": true, "text": "/proc/self/status" }, { "answer_id": 93156, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "*nix" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
89,767
<p>I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console (using the PSPSDK toolchain), but I'm having too much trouble with the makefiles (making the proper changes and solving linking issues). </p> <p>Does anyone know a good text, book or something to get some insight on porting libraries?</p> <p>The only documentation this project offers on porting seems too dedicated to major OS's.</p>
[ { "answer_id": 414319, "author": "Paulo Lopes", "author_id": 51560, "author_profile": "https://Stackoverflow.com/users/51560", "pm_score": 2, "selected": false, "text": "LDFLAGS=\"-L$(psp-config --pspsdk-path)/lib -lc -lpspuser\" ./configure --host psp --prefix=$(pwd)/../target/psp\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89767", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2731698/" ]
89,791
<p>When I start my process from Visual Studio, it is always created inside a job object. I would like to know how to turn this behaviour off. Any ideas?</p> <p>I expect that it is created in a job object to be debugged. I want to place my program in a different job object.</p> <p>It's not the hosting process. I'm talking about a <a href="http://msdn.microsoft.com/en-us/library/ms684161(VS.85).aspx" rel="noreferrer">Job Object</a>. This is an unmanaged C++ application.</p>
[ { "answer_id": 4232259, "author": "Tom Minka", "author_id": 513835, "author_profile": "https://Stackoverflow.com/users/513835", "pm_score": 5, "selected": false, "text": "devenv.exe" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
89,796
<p>I've been using the YUI Components and want to begin using the Loader Utility to specify my dependencies on my page. From your experience, is the YUI Loader Utility a reliable way to load Javascript dependencies in web pages?</p>
[ { "answer_id": 3638698, "author": "Kreegr", "author_id": 296765, "author_profile": "https://Stackoverflow.com/users/296765", "pm_score": 1, "selected": false, "text": "var TheBase = function(oConfig){\nvar thisBase = this;\nvar EVENTS = {\n ON_SCRIPTS_LOADED : \"onScriptsLoaded\"\n , ON_SCRIPTS_PROGRESS : \"onScriptsProgress\"\n}\nfor(var eventName in EVENTS){\n thisBase.createEvent(EVENTS[eventName]); \n}\nvar _loader = new YAHOO.util.YUILoader({\n base: oConfig.yuiBasePath\n ,onSuccess:function(o){\n thisBase.fireEvent(EVENTS.ON_SCRIPTS_LOADED);\n }\n ,onProgress:function(o){\n thisBase.fireEvent(EVENTS.ON_SCRIPTS_PROGRESS,o.name);\n }\n})\n//optional\n thisBase.loader = _loader;\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89796", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3289/" ]
89,820
<p>I am using mssql and am having trouble using a subquery. The real query is quite complicated, but it has the same structure as this:</p> <pre><code>select customerName, customerId, ( select count(*) from Purchases where Purchases.customerId=customerData.customerId ) as numberTransactions from customerData </code></pre> <p>And what I want to do is order the table by the number of transactions, but when I use</p> <pre><code>order by numberTransactions </code></pre> <p>It tells me there is no such field. Is it possible to do this? Should I be using some sort of special keyword, such as <code>this</code>, or <code>self</code>?</p>
[ { "answer_id": 89831, "author": "Jonathan Rupp", "author_id": 12502, "author_profile": "https://Stackoverflow.com/users/12502", "pm_score": 4, "selected": true, "text": "order by 3\n" }, { "answer_id": 89834, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 2, "selected": false, "text": "select \ncustomerName,\ncustomerID,\ncount(*) as numberTransactions\nfrom\n customerdata c inner join purchases p on c.customerID = p.customerID\ngroup by customerName,customerID\norder by numberTransactions\n\n" }, { "answer_id": 89835, "author": "theo", "author_id": 7870, "author_profile": "https://Stackoverflow.com/users/7870", "pm_score": -1, "selected": false, "text": "select \n customerName, \n customerId,\n (\n select count(*) \n from Purchases p\n where p.customerId = c.customerId\n ) as numberTransactions\nfrom customerData c\norder by (select count(*) from purchases p where p.customerID = c.customerid)\n" }, { "answer_id": 89836, "author": "Thomas", "author_id": 14637, "author_profile": "https://Stackoverflow.com/users/14637", "pm_score": 0, "selected": false, "text": "GROUP BY" }, { "answer_id": 89842, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 3, "selected": false, "text": "SELECT *\nFROM\n(\nselect\n customerName,\n customerId,\n (\n select count(*)\n from Purchases\n where Purchases.customerId=customerData.customerId\n ) as numberTransactions\nfrom customerData\n) as sub\norder by sub.numberTransactions\n" }, { "answer_id": 90139, "author": "MotoWilliams", "author_id": 2730, "author_profile": "https://Stackoverflow.com/users/2730", "pm_score": 2, "selected": false, "text": "select\n customerName, \n customerId,\n (\n select count(*) \n from Purchases \n where Purchases.customerId=customerData.customerId\n ) as 'numberTransactions'\nfrom customerData\nORDER BY 'numberTransactions'\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6062/" ]
89,866
<p>We are creating a Real-Time Process in VxWorks 6.x, and we would like to limit the amount of memory which can be allocated to the heap. How do we do this?</p>
[ { "answer_id": 89911, "author": "Benoit", "author_id": 10703, "author_profile": "https://Stackoverflow.com/users/10703", "pm_score": 3, "selected": true, "text": "\n char * envp[] = {\"HEAP_INITIAL_SIZE=0x20000\", \"HEAP_MAX_SIZE=0x100000\", NULL);\n rtpSpawn (\"myrtp.vxe\", NULL, envp, 100, 0x10000, 0, 0);\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
89,873
<p>Is it possible to manipulate the components, such as <code>year</code>, <code>month</code>, <code>day</code> of a <code>date</code> in VBA? I would like a function that, given a day, a month, and a year, returns the corresponding date.</p>
[ { "answer_id": 89899, "author": "Swati", "author_id": 12682, "author_profile": "https://Stackoverflow.com/users/12682", "pm_score": 4, "selected": true, "text": "DateSerial(YEAR, MONTH, DAY)\n" }, { "answer_id": 89903, "author": "Prestaul", "author_id": 5628, "author_profile": "https://Stackoverflow.com/users/5628", "pm_score": 2, "selected": false, "text": "Dim someDate As Date = DateSerial(year, month, day)\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10439/" ]
89,891
<p>I just learned about how the Java Collections Framework implements data structures in linked lists. From what I understand, <code>Iterators</code> are a way of traversing through the items in a data structure such as a list. Why is this interface used? Why are the methods <code>hasNext()</code>, <code>next()</code> and <code>remove()</code> not directly coded to the data structure implementation itself?</p> <p>From the Java website: <a href="http://java.sun.com/javase/6/docs/api/" rel="noreferrer">link text</a></p> <blockquote> <p>public interface Iterator&lt;&#69;><p> An iterator over a collection. Iterator takes the place of Enumeration in the Java collections framework. Iterators differ from enumerations in two ways:</p> <p><ul><li>Iterators allow the caller to remove elements from the underlying collection during the iteration with well-defined semantics. <li>Method names have been improved.</ul> This interface is a member of the Java Collections Framework.</p> </blockquote> <p>I tried googling around and can't seem to find a definite answer. Can someone shed some light on why Sun chose to use them? Is it because of better design? Increased security? Good OO practice?</p> <p>Any help will be greatly appreciated. Thanks.</p>
[ { "answer_id": 90068, "author": "coobird", "author_id": 17172, "author_profile": "https://Stackoverflow.com/users/17172", "pm_score": 2, "selected": false, "text": "Iterator" }, { "answer_id": 90180, "author": "Dustman", "author_id": 16398, "author_profile": "https://Stackoverflow.com/users/16398", "pm_score": 5, "selected": true, "text": "Collection" }, { "answer_id": 90257, "author": "Alan", "author_id": 17205, "author_profile": "https://Stackoverflow.com/users/17205", "pm_score": 3, "selected": false, "text": "Iterable" }, { "answer_id": 33250629, "author": "TheArchon", "author_id": 4752024, "author_profile": "https://Stackoverflow.com/users/4752024", "pm_score": 0, "selected": false, "text": " private class Itr implements Iterator<E> {\n\n public E next() {\n return ArrayList.this.get(index++); //rough, not exact\n }\n\n //we have to use ArrayList.this.get() so the compiler will\n //know that we are referring to the methods in the \n //enclosing ArrayList class\n\n public void remove() {\n ArrayList.this.remove(prevIndex);\n }\n\n //checks for...co mod of the list\n final void checkForComodification() { //ListItr gets this method as well\n if (ArrayList.this.modCount != expectedModCount) { \n throw new ConcurrentModificationException();\n }\n }\n }\n\n private class ListItr extends Itr implements ListIterator<E> {\n //methods inherted....\n public void add(E e) {\n ArrayList.this.add(cursor, e);\n }\n\n public void set(E e) {\n ArrayList.this.set(cursor, e);\n }\n }\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17182/" ]
89,897
<p>Maybe the need to do this is a 'design smell' but thinking about another question, I was wondering what the cleanest way to implement the <strong>inverse</strong> of this:</p> <pre><code>foreach(ISomethingable somethingableClass in collectionOfRelatedObjects) { somethingableClass.DoSomething(); } </code></pre> <p>i.e. How to get/iterate through all the objects that <em>don't</em> implement a particular interface?</p> <p>Presumably you'd need to start by upcasting to the highest level:</p> <pre><code>foreach(ParentType parentType in collectionOfRelatedObjects) { // TODO: iterate through everything which *doesn't* implement ISomethingable } </code></pre> <p>Answer by solving the TODO: in the cleanest/simplest and/or most efficient way</p>
[ { "answer_id": 89933, "author": "J D OConal", "author_id": 17023, "author_profile": "https://Stackoverflow.com/users/17023", "pm_score": 3, "selected": false, "text": "foreach (ParentType parentType in collectionOfRelatedObjects) {\n if (!(parentType is ISomethingable)) {\n }\n}\n" }, { "answer_id": 89985, "author": "Tim Erickson", "author_id": 8787, "author_profile": "https://Stackoverflow.com/users/8787", "pm_score": 2, "selected": false, "text": "foreach (object obj in collectionOfRelatedObjects)\n{\n if (obj is ISomethingable) continue;\n\n //do something to/with the not-ISomethingable\n}\n" }, { "answer_id": 89993, "author": "sontek", "author_id": 17176, "author_profile": "https://Stackoverflow.com/users/17176", "pm_score": 0, "selected": false, "text": "foreach (ParentType parentType in collectionOfRelatedObjects) {\n var obj = (parentType as ISomethingable);\n if (obj == null) {\n }\n}\n" }, { "answer_id": 90466, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 3, "selected": true, "text": "collectionOfRelatedObjects.Where(o => !(o is ISomethingable))\n" }, { "answer_id": 943865, "author": "Max Galkin", "author_id": 2351099, "author_profile": "https://Stackoverflow.com/users/2351099", "pm_score": 0, "selected": false, "text": "using System.Linq;\n\n...\n\nforeach(ISomethingable s in collection.OfType<ISomethingable>())\n{\n s.DoSomething();\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12726/" ]
89,908
<p>I have three models:</p> <pre><code>class ReleaseItem &lt; ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =&gt; :pack_release_items end class Pack &lt; ActiveRecord::Base has_many :pack_release_items has_many :release_items, :through=&gt;:pack_release_items end class PackReleaseItem &lt; ActiveRecord::Base belongs_to :pack belongs_to :release_item end </code></pre> <p>The problem is that, during execution, if I add a pack to a release_item it is not aware that the pack is a pack. For instance:</p> <pre><code>Loading development environment (Rails 2.1.0) &gt;&gt; item = ReleaseItem.new(:filename=&gt;'MAESTRO.TXT') =&gt; #&lt;ReleaseItem id: nil, filename: "MAESTRO.TXT", created_by: nil, title: nil, sauce_author: nil, sauce_group: nil, sauce_comment: nil, filedate: nil, filesize: nil, created_at: nil, updated_at: nil, content: nil&gt; &gt;&gt; pack = Pack.new(:filename=&gt;'legion01.zip', :year=&gt;1998) =&gt; #&lt;Pack id: nil, filename: "legion01.zip", created_by: nil, filesize: nil, items: nil, year: 1998, month: nil, filedate: nil, created_at: nil, updated_at: nil&gt; &gt;&gt; item.pack = pack =&gt; #&lt;Pack id: nil, filename: "legion01.zip", created_by: nil, filesize: nil, items: nil, year: 1998, month: nil, filedate: nil, created_at: nil, updated_at: nil&gt; &gt;&gt; item.pack.filename NoMethodError: undefined method `filename' for #&lt;Class:0x2196318&gt; from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1667:in `method_missing_without_paginate' from /usr/local/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.3/lib/will_paginate/finder.rb:164:in `method_missing' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:285:in `send' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:285:in `method_missing_without_paginate' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1852:in `with_scope' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:168:in `send' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_proxy.rb:168:in `with_scope' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:281:in `method_missing_without_paginate' from /usr/local/lib/ruby/gems/1.8/gems/mislav-will_paginate-2.3.3/lib/will_paginate/finder.rb:164:in `method_missing' from (irb):5 &gt;&gt; </code></pre> <p>It seems that I should have access to item.pack, but it is unaware that the pack is a Pack item.</p>
[ { "answer_id": 90003, "author": "Misplaced", "author_id": 13710, "author_profile": "https://Stackoverflow.com/users/13710", "pm_score": 4, "selected": true, "text": "model_id" }, { "answer_id": 90055, "author": "Ian Terrell", "author_id": 9269, "author_profile": "https://Stackoverflow.com/users/9269", "pm_score": 2, "selected": false, "text": "ReleaseItem" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13179/" ]
89,909
<p>I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method.</p>
[ { "answer_id": 89915, "author": "easeout", "author_id": 10906, "author_profile": "https://Stackoverflow.com/users/10906", "pm_score": -1, "selected": false, "text": "([a-z][A-Z][0-9]\\_\\-)*\n" }, { "answer_id": 89919, "author": "Thomas", "author_id": 14637, "author_profile": "https://Stackoverflow.com/users/14637", "pm_score": 8, "selected": true, "text": "import re\n\n...\n\nif re.match(\"^[A-Za-z0-9_-]*$\", my_little_string):\n # do something here\n" }, { "answer_id": 89937, "author": "Javier", "author_id": 11649, "author_profile": "https://Stackoverflow.com/users/11649", "pm_score": 2, "selected": false, "text": " pat = re.compile ('[^\\w-]')\n\n def onlyallowed(s):\n return not pat.search (s)\n" }, { "answer_id": 89940, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": -1, "selected": false, "text": "all([c in string.letters + string.digits + [\"_\", \"-\"] for c in mystring])" }, { "answer_id": 89971, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 4, "selected": false, "text": "import string\nallowed = string.letters + string.digits + '_' + '-'\n\ndef check_naive(mystring):\n return all(c in allowed for c in mystring)\n" }, { "answer_id": 91564, "author": "Ber", "author_id": 11527, "author_profile": "https://Stackoverflow.com/users/11527", "pm_score": 2, "selected": false, "text": "from sets import Set\n\nallowed_chars = Set('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-')\n\nif Set(my_little_sting).issubset(allowed_chars):\n # your action\n print True\n" }, { "answer_id": 91572, "author": "Ber", "author_id": 11527, "author_profile": "https://Stackoverflow.com/users/11527", "pm_score": 4, "selected": false, "text": "my_little_string.isalnum()\n" }, { "answer_id": 92000, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 5, "selected": false, "text": "import string, re, timeit\n\npat = re.compile('[\\w-]*$')\npat_inv = re.compile ('[^\\w-]')\nallowed_chars=string.ascii_letters + string.digits + '_-'\nallowed_set = set(allowed_chars)\ntrans_table = string.maketrans('','')\n\ndef check_set_diff(s):\n return not set(s) - allowed_set\n\ndef check_set_all(s):\n return all(x in allowed_set for x in s)\n\ndef check_set_subset(s):\n return set(s).issubset(allowed_set)\n\ndef check_re_match(s):\n return pat.match(s)\n\ndef check_re_inverse(s): # Search for non-matching character.\n return not pat_inv.search(s)\n\ndef check_trans(s):\n return not s.translate(trans_table,allowed_chars)\n\ntest_long_almost_valid='a_very_long_string_that_is_mostly_valid_except_for_last_char'*99 + '!'\ntest_long_valid='a_very_long_string_that_is_completely_valid_' * 99\ntest_short_valid='short_valid_string'\ntest_short_invalid='/$%$%&'\ntest_long_invalid='/$%$%&' * 99\ntest_empty=''\n\ndef main():\n funcs = sorted(f for f in globals() if f.startswith('check_'))\n tests = sorted(f for f in globals() if f.startswith('test_'))\n for test in tests:\n print \"Test %-15s (length = %d):\" % (test, len(globals()[test]))\n for func in funcs:\n print \" %-20s : %.3f\" % (func, \n timeit.Timer('%s(%s)' % (func, test), 'from __main__ import pat,allowed_set,%s' % ','.join(funcs+tests)).timeit(10000))\n print\n\nif __name__=='__main__': main()\n" }, { "answer_id": 13649498, "author": "MB.", "author_id": 11961, "author_profile": "https://Stackoverflow.com/users/11961", "pm_score": -1, "selected": false, "text": "import string\nALLOWED = frozenset(string.ascii_letters + string.digits + '_' + '-')\n\ndef check(mystring):\n return all(c in ALLOWED for c in mystring)\n" }, { "answer_id": 19970696, "author": "Sravan K Ghantasala", "author_id": 1878063, "author_profile": "https://Stackoverflow.com/users/1878063", "pm_score": 0, "selected": false, "text": "import re\n\nstring = 'adsfg34wrtwe4r2_()' #your string that needs to be matched.\nregex = r'^[\\w\\d_()]*$' # you can also add a space in regex if u want to allow it in the string \nif re.match(regex,string):\n print 'yes'\nelse: \n print 'false'\n" }, { "answer_id": 54306902, "author": "Alston", "author_id": 1033591, "author_profile": "https://Stackoverflow.com/users/1033591", "pm_score": 2, "selected": false, "text": "import re;\nre.fullmatch(\"^[\\w-]+$\", target_string) # fullmatch looks also workable for python 3.4\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4527/" ]
89,959
<p>I am just starting out with DI &amp; unit testing and have hit a snag which I am sure is a no brainer for those more experienced devs :</p> <p>I have a class called MessageManager which receives data and saves it to a db. Within the same assembly (project in Visual Studio) I have created a repository interface with all the methods needed to access the db. The concrete implementation of this interface is in a separate assembly called DataAccess.</p> <p>So DataAccess needs a project reference to MessageManager to know about the repository interface. And MessageManager needs a project reference to DataAccess so that the client of MessageManager can inject a concrete implementation of the repository interface. This is of courser not allowed</p> <p>I could move the interface into the data access assembly but I believe the repository interface is meant to reside in the same assembly as the client that uses it</p> <p>So what have I done wrong?</p>
[ { "answer_id": 89983, "author": "user11087", "author_id": 11087, "author_profile": "https://Stackoverflow.com/users/11087", "pm_score": 1, "selected": false, "text": "Foo f = new Foo();\nBar b = new Bar();\nf.setBar(b);\nb.setFoo(f);\n" }, { "answer_id": 90045, "author": "Simon Fox", "author_id": 16861, "author_profile": "https://Stackoverflow.com/users/16861", "pm_score": -1, "selected": false, "text": "MessageManager" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17194/" ]
89,987
<p>My DataView is acting funny and it is sorting things alphabetically and I need it to sort things numerically. I have looked all across the web for this one and found many ideas on how to sort it with ICompare, but nothing really solid.</p> <p>So my questions are </p> <ol> <li>How do I implement ICompare on a DataView (Looking for code here).</li> <li>How to correctly decipher from a column full of strings that are actual strings and a column full of numbers(with commas).</li> </ol> <p>I need code to help me out with this one guys. I am more or less lost on the idea of ICompare and how to implement in different scenarios so an over all good explanation would be great.</p> <p>Also, Please don't hand me links. I am looking for solid answers on this one.</p> <p>Some Code that I use.</p> <pre><code> DataView dataView = (DataView)Session["kingdomData"]; dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection); gvAllData.DataSource = dataView; gvAllData.DataBind(); private string ConvertSortDirectionToSql(SortDirection sortDirection) { string newSortDirection = String.Empty; if (Session["SortDirection"] == null) { switch (sortDirection) { case SortDirection.Ascending: newSortDirection = "ASC"; break; case SortDirection.Descending: newSortDirection = "DESC"; break; } } else { newSortDirection = Session["SortDirection"].ToString(); switch (newSortDirection) { case "ASC": newSortDirection = "DESC"; break; case "DESC": newSortDirection = "ASC"; break; } } Session["SortDirection"] = newSortDirection; return newSortDirection; } </code></pre> <hr> <p>For the scenario, I build a datatable dynamically and shove it into a dataview where I put the dataview into a gridview while also remembering to put the dataview into a session object for sorting capabilities.</p> <p>When the user calls on the gridview to sort a column, I recall the dataview in the session object and build the dataview sorting expression like this:</p> <pre><code>dataview.sort = e.sortexpression + " " + e.Sortdirection; </code></pre> <p>Or something along those lines. So what ussually comes out is right for all real strings such as </p> <p>Car; Home; scott; zach etc...</p> <p>But when I do the same for number fields WITH comma seperated values it comes out something like</p> <p>900; 800; 700; 600; 200; 120; 1,200; 12,340; 1,000,000;</p> <p>See what I mean? It just sorts the items as an alpha sort instead of a Natural sort. I want to make my Dataview NATURALLY sort the numeric columns correctly like</p> <p>120; 200; 600; 700; 800; 900; 1,200; 12,340; 1,000,000;</p> <p>Let me know what you can do to help me out.<br> P.S. I have looked through countless articles on how to do this and all of them say to shove into a List/Array and do it that way, but is there a much more efficient way?</p>
[ { "answer_id": 90498, "author": "rslite", "author_id": 15682, "author_profile": "https://Stackoverflow.com/users/15682", "pm_score": 2, "selected": false, "text": "DataView dv = new DataView(dt);\nArrayList lst = new ArrayList();\nlst.AddRange(dv.Table.Rows);\nlst.Sort(new MyComparer());\nforeach (DataRow dr in lst)\n Debug.WriteLine(dr[0]);\n" }, { "answer_id": 1640846, "author": "srmark", "author_id": 41662, "author_profile": "https://Stackoverflow.com/users/41662", "pm_score": 1, "selected": false, "text": " DataView dv = GetDataViewSomewhere();\n\n //Naturally sort by COLUMN_TO_SORT_ON\n try\n {\n List<string> rowList = new List<string>();\n foreach (DataRowView drv in dv)\n rowList.Add((string)drv[\"COLUMN_TO_SORT_ON\"]);\n rowList.Sort(new NaturalComparer());\n Dictionary<string, int> sortValueHash = new Dictionary<string, int>();\n for (int i = 0; i < rowList.Count; i++)\n sortValueHash.Add(rowList[i], i); \n\n dv.Table.Columns.Add(\"NATURAL_SORT_ORDER\", typeof(int));\n foreach (DataRowView drv in dv)\n drv[\"NATURAL_SORT_ORDER\"] = sortValueHash[(string)drv[\"COLUMN_TO_SORT_ON\"]];\n dv.Sort = \"NATURAL_SORT_ORDER\"; \n }\n catch (Exception)\n { \n DEBUG_TRACE(\"Could not naturally sort\");\n dv.Sort = \"COLUMN_TO_SORT_ON\";\n }\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7644/" ]
89,989
<p>I want to download a lot of urls in a script but I do not want to save the ones that lead to HTTP errors.</p> <p>As far as I can tell from the man pages, neither <code>curl</code> or <code>wget</code> provide such functionality. Does anyone know about another downloader who does?</p>
[ { "answer_id": 90009, "author": "Thomas", "author_id": 14637, "author_profile": "https://Stackoverflow.com/users/14637", "pm_score": 5, "selected": false, "text": "-f" }, { "answer_id": 2327058, "author": "Oct", "author_id": 112514, "author_profile": "https://Stackoverflow.com/users/112514", "pm_score": 5, "selected": true, "text": "A=$$; ( wget -q \"http://foo.com/pipo.txt\" -O $A.d && mv $A.d pipo.txt ) || (rm $A.d; echo \"Removing temp file\")\n" }, { "answer_id": 8218688, "author": "Marc Queralt", "author_id": 950065, "author_profile": "https://Stackoverflow.com/users/950065", "pm_score": -1, "selected": false, "text": "\"-O -\"" }, { "answer_id": 29350043, "author": "sajal", "author_id": 135625, "author_profile": "https://Stackoverflow.com/users/135625", "pm_score": 2, "selected": false, "text": "if [ `curl -s -w \"%{http_code}\" --compress -o /tmp/something \\\n http://example.com/my/url/` = \"200\" ]; then \n echo \"yay\"; cp /tmp/something /path/to/destination/filename\nfi\n" }, { "answer_id": 36557153, "author": "vmonteco", "author_id": 3156085, "author_profile": "https://Stackoverflow.com/users/3156085", "pm_score": 0, "selected": false, "text": "wget -O <filename> <url/to/file>\nif [[ (du <filename> | cut -f 1) == 0 ]]; then\n rm <filename>;\nfi;\n" }, { "answer_id": 54956116, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "wget" }, { "answer_id": 60302046, "author": "Juan Lago", "author_id": 1641558, "author_profile": "https://Stackoverflow.com/users/1641558", "pm_score": 0, "selected": false, "text": "wget http://example.net/myfile.json -O myfile.json.tmp -t 3 -q && mv list.json.tmp list.json\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/89989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65724/" ]
90,002
<p>If you were to mandate a minimum percentage code-coverage for unit tests, perhaps even as a requirement for committing to a repository, what would it be?</p> <p>Please explain how you arrived at your answer (since if all you did was pick a number, then I could have done that all by myself ;)</p>
[ { "answer_id": 795683, "author": "Gary Kephart", "author_id": 17967, "author_profile": "https://Stackoverflow.com/users/17967", "pm_score": 2, "selected": false, "text": "<cobertura-check linerate=\"0\"\n branchrate=\"0\"\n totallinerate=\"70\"\n totalbranchrate=\"90\"\n failureproperty=\"build.failed\" />\n" }, { "answer_id": 34698711, "author": "killscreen", "author_id": 2040552, "author_profile": "https://Stackoverflow.com/users/2040552", "pm_score": 6, "selected": false, "text": "if" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16050/" ]
90,023
<h2>Update: giving a much more thorough example.</h2> <p>The first two solutions offered were right along the lines of what I was trying to say <em>not</em> to do. I can't know location, it needs to be able to look at the whole document tree. So a solution along these lines, with /Books/ specified as the context will not work:</p> <pre><code>SELECT x.query('.') FROM @xml.nodes('/Books/*[not(@ID) or @ID = 5]') x1(x) </code></pre> <h2>Original question with better example:</h2> <p>Using SQL Server 2005's XQuery implementation I need to select all nodes in an XML document, just once each and keeping their original structure, but only if they are missing a particular attribute, or that attribute has a specific value (passed in by parameter). The query also has to work on the whole XML document (descendant-or-self axis) rather than selecting at a predefined depth.</p> <p>That is to say, each individual node will appear in the resultant document only if it and every one of its ancestors are missing the attribute, or have the attribute with a single specific value.</p> <h2>For example:</h2> <p>If this were the XML:</p> <pre><code> DECLARE @Xml XML SET @Xml = N' &lt;Library&gt; &lt;Novels&gt; &lt;Novel category=&quot;1&quot;&gt;Novel1&lt;/Novel&gt; &lt;Novel category=&quot;2&quot;&gt;Novel2&lt;/Novel&gt; &lt;Novel&gt;Novel3&lt;/Novel&gt; &lt;Novel category=&quot;4&quot;&gt;Novel4&lt;/Novel&gt; &lt;/Novels&gt; &lt;Encyclopedias&gt; &lt;Encyclopedia&gt; &lt;Volume&gt;A-F&lt;/Volume&gt; &lt;Volume category=&quot;2&quot;&gt;G-L&lt;/Volume&gt; &lt;Volume category=&quot;3&quot;&gt;M-S&lt;/Volume&gt; &lt;Volume category=&quot;4&quot;&gt;T-Z&lt;/Volume&gt; &lt;/Encyclopedia&gt; &lt;/Encyclopedias&gt; &lt;Dictionaries category=&quot;1&quot;&gt; &lt;Dictionary&gt;Webster&lt;/Dictionary&gt; &lt;Dictionary&gt;Oxford&lt;/Dictionary&gt; &lt;/Dictionaries&gt; &lt;/Library&gt; ' </code></pre> <p>A parameter of 1 for category would result in this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Library&gt; &lt;Novels&gt; &lt;Novel category=&quot;1&quot;&gt;Novel1&lt;/Novel&gt; &lt;Novel&gt;Novel3&lt;/Novel&gt; &lt;/Novels&gt; &lt;Encyclopedias&gt; &lt;Encyclopedia&gt; &lt;Volume&gt;A-F&lt;/Volume&gt; &lt;/Encyclopedia&gt; &lt;/Encyclopedias&gt; &lt;Dictionaries category=&quot;1&quot;&gt; &lt;Dictionary&gt;Webster&lt;/Dictionary&gt; &lt;Dictionary&gt;Oxford&lt;/Dictionary&gt; &lt;/Dictionaries&gt; &lt;/Library&gt; </code></pre> <p>A parameter of 2 for category would result in this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;Library&gt; &lt;Novels&gt; &lt;Novel category=&quot;2&quot;&gt;Novel2&lt;/Novel&gt; &lt;Novel&gt;Novel3&lt;/Novel&gt; &lt;/Novels&gt; &lt;Encyclopedias&gt; &lt;Encyclopedia&gt; &lt;Volume&gt;A-F&lt;/Volume&gt; &lt;Volume category=&quot;2&quot;&gt;G-L&lt;/Volume&gt; &lt;/Encyclopedia&gt; &lt;/Encyclopedias&gt; &lt;/Library&gt; </code></pre> <p>I know XSLT is perfectly suited for this job, but it's not an option. We have to accomplish this entirely in SQL Server 2005. Any implementations not using XQuery are fine too, as long as it can be done entirely in T-SQL.</p>
[ { "answer_id": 90795, "author": "rslite", "author_id": 15682, "author_profile": "https://Stackoverflow.com/users/15682", "pm_score": 3, "selected": true, "text": "//Book[not(@ID) or @ID = 5]\n" }, { "answer_id": 91138, "author": "Jonas Lincoln", "author_id": 17436, "author_profile": "https://Stackoverflow.com/users/17436", "pm_score": 1, "selected": false, "text": "DECLARE @Xml AS XML\n SET @Xml =\n N'\n <Books>\n <Book ID=\"1\">Book1</Book>\n <Book ID=\"2\">Book2</Book>\n <Book ID=\"3\">Book3</Book>\n <Book>Book4</Book>\n <Book ID=\"5\">Book5</Book>\n <Book ID=\"6\">Book6</Book>\n <Book>Book7</Book>\n <Book ID=\"8\">Book8</Book>\n </Books>\n '\nDECLARE @BookID AS INT\nSET @BookID = 5\nDECLARE @Result AS XML\n\nSET @result = (SELECT @xml.query('//Book[not(@ID) or @ID = sql:variable(\"@BookID\")]'))\nSELECT @result\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507/" ]
90,029
<p>I'm trying to create a deployment tool that will install software based on the hardware found on a system. I'd like the tool to be able to determine if the optical drive is a writer (to determine if burning software sould be installed) or can read DVDs (to determine if a player should be installed). I tried uing the following code </p> <pre><code>strComputer = "." Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive") For Each objItem in colItems Wscript.Echo "MediaType: " &amp; objItem.MediaType Next </code></pre> <p>but it always respons with CD-ROM</p>
[ { "answer_id": 90072, "author": "blowdart", "author_id": 2525, "author_profile": "https://Stackoverflow.com/users/2525", "pm_score": 1, "selected": false, "text": "Win32_DiskDrive" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90029", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
90,049
<p>I'm using a table to design the layout of my web page. I want the table to fill the page even if it doesn't contain much content. Here's the CSS I'm using:</p> <pre class="lang-css prettyprint-override"><code>html, body { height: 100%; margin: 0; padding: 0; } #container { min-height: 100%; width: 100%; } </code></pre> <p>And I place something like this in the page code:</p> <pre><code>&lt;table id="container"&gt; &lt;tr&gt; &lt;td&gt; ... </code></pre> <p>This works for Opera 9, but not for Firefox 2 or Internet Explorer 7. Is there a simple way to make this solution work for all popular browsers?</p> <p>(Adding <code>id="container"</code> to <code>td</code> doesn't help.)</p>
[ { "answer_id": 90109, "author": "Vincent McNabb", "author_id": 16299, "author_profile": "https://Stackoverflow.com/users/16299", "pm_score": 4, "selected": true, "text": "height" }, { "answer_id": 6577742, "author": "deathlock", "author_id": 651170, "author_profile": "https://Stackoverflow.com/users/651170", "pm_score": 4, "selected": false, "text": "html, body {\n height: 100%;\n}\n" }, { "answer_id": 58386700, "author": "Priyanga", "author_id": 11769090, "author_profile": "https://Stackoverflow.com/users/11769090", "pm_score": 0, "selected": false, "text": "window_height = $(window).height();\n$('#container').css('min-height', window_height);\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17216/" ]
90,052
<p>Ok, so i'm working on a regular expression to search out all the header information in a site.</p> <p>I've compiled the regular expression:</p> <pre><code>regex = re.compile(r''' &lt;h[0-9]&gt;\s? (&lt;a[ ]href="[A-Za-z0-9.]*"&gt;)?\s? [A-Za-z0-9.,:'"=/?;\s]*\s? [A-Za-z0-9.,:'"=/?;\s]? ''', re.X) </code></pre> <p>When i run this in python reg ex. tester, it works out wonderfully.</p> <p>Sample data:</p> <pre><code>&lt;body&gt; &lt;h1&gt;Dog &lt;/h1&gt; &lt;h2&gt;Cat &lt;/h2&gt; &lt;h3&gt;Fancy &lt;/h3&gt; &lt;h1&gt;Tall cup of lemons&lt;/h1&gt; &lt;h1&gt;&lt;a href="dog.com"&gt;Dog thing&lt;/a&gt;&lt;/h1&gt; &lt;/body&gt; </code></pre> <p>Now, in the REDemo, it works wonderfully.</p> <p>When i put it in my python code, however, it only prints <code>&lt;a href="dog.com"&gt;</code></p> <p>Here's my python code, I'm not sure if i'm doing something wrong or if something is lost in translation. I appreciate your help.</p> <pre><code>stories=[] response = urllib2.urlopen('http://apricotclub.org/duh.html') html = response.read().lower() p = re.compile('&lt;h[0-9]&gt;\\s?(&lt;a href=\"[A-Za-z0-9.]*\"&gt;)?\\s?[A-Za-z0-9.,:\'\"=/?;\\s]*\\s?[A-Za-z0-9.,:\'\"=/?;\\s]?') stories=re.findall(p, html) for i in stories: if len(i) &gt;= 5: print i </code></pre> <p>I should also note, that when i take out the <code>(&lt;a href=\"[A-Za-z0-9.]*\"&gt;)?</code> from the regular expression it works fine for non-link <code>&lt;hN&gt;</code> lines.</p>
[ { "answer_id": 90206, "author": "molasses", "author_id": 11293, "author_profile": "https://Stackoverflow.com/users/11293", "pm_score": 1, "selected": false, "text": "import re\n\nhtml = '''\n<body>\n\n<h1>Dog </h1>\n<h2>Cat </h2>\n<h3>Fancy </h3>\n<h1>Tall cup of lemons</h1>\n<h1><a href=\"dog.com\">Dog thing</a></h1>\n</body>\n'''\n\np = re.compile(r'''\n <(?P<header>h[0-9])> # store header tag for later use\n \\s* # zero or more whitespace\n (<a\\shref=\"(?P<href>.*?)\">)? # optional link tag. store href portion\n \\s*\n (?P<title>.*?) # title\n \\s*\n (</a>)? # optional closing link tag\n \\s*\n </(?P=header)> # must match opening header tag\n''', re.IGNORECASE + re.VERBOSE)\n\nstories = p.finditer(html)\n\nfor match in stories:\n print '%(title)s [%(href)s]' % match.groupdict()\n" }, { "answer_id": 90894, "author": "rslite", "author_id": 15682, "author_profile": "https://Stackoverflow.com/users/15682", "pm_score": 2, "selected": false, "text": "p = re.compile(r'<(h[0-9])>(.+?)</\\1>', re.IGNORECASE | re.DOTALL)\nstories = re.findall(p, html)\nfor i in stories:\n print i\n" }, { "answer_id": 618080, "author": "aatifh", "author_id": 56183, "author_profile": "https://Stackoverflow.com/users/56183", "pm_score": 2, "selected": false, "text": "from BeautifulSoup import BeautifulSoup\n\n\nH_TAGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']\n\ndef extract_data():\n \"\"\"Extract the data from all headers\n in a HTML page.\"\"\"\n f = open('foo.html', 'r+')\n html = f.read()\n soup = BeautifulSoup(html)\n headers = [soup.findAll(h) for h in H_TAGS if soup.findAll(h)]\n lst = []\n for x in headers:\n for y in x:\n if y.string:\n lst.append(y.string)\n else:\n lst.append(y.contents[0].string)\n return lst\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
90,061
<p>The application I'm writing is almost complete and I'd like people who speak different languages to use it.</p> <p>I'm not sure where to start, what's the difference between globalisation and culture in regards to programming?</p> <p>How does one take uncommon phrases such as "this application was built to do this and that" instead of File, Open, Save etc...and turn them into say, Spanish?</p> <p>Many thanks :-)</p>
[ { "answer_id": 90133, "author": "easeout", "author_id": 10906, "author_profile": "https://Stackoverflow.com/users/10906", "pm_score": 0, "selected": false, "text": "save=Save\nclose=Close\nok=OK\nareYouSure=Are you sure?\n" }, { "answer_id": 90351, "author": "Francis B.", "author_id": 17067, "author_profile": "https://Stackoverflow.com/users/17067", "pm_score": 3, "selected": false, "text": "CultureInfo ci = new CultureInfo(\"fr\");\nThread.CurrentThread.CurrentUICulture = ci;\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17211/" ]
90,067
<p>I'm using the following html to load dojo from Google's hosting.</p> <pre><code>&lt;script src="http://www.google.com/jsapi"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;google.load("dojo", "1.1.1");&lt;/script&gt; &lt;script type="text/javascript"&gt; dojo.require("dojox.gfx"); ... </code></pre> <p>This errors out on the requre line with an error like dojox.gfx is undefined. Is there a way to make this work, or does Google not support the dojox extensions?</p> <p>Alternatively, is there another common host I can use for standard dojo releases?</p>
[ { "answer_id": 90088, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": 0, "selected": false, "text": "google.dojo.require" }, { "answer_id": 90169, "author": "Felipe", "author_id": 2333, "author_profile": "https://Stackoverflow.com/users/2333", "pm_score": 3, "selected": true, "text": "google.load(\"dojo\", \"1.1.1\", {callback: start});\n\nfunction start() {\n dojo.require(\"dojox.gfx\");\n ...\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17209/" ]
90,075
<p>Businesses Analyst from my team keeps sending us the updated Requirements documents often and I end up hunting the recent changes by comparing the old version. Is their a good way of comparing the Word documents? </p> <p>Note: We have the track changes option ON, but now the documents looks like a blood bath, complicating it much more :(</p>
[ { "answer_id": 3119456, "author": "Daenyth", "author_id": 350351, "author_profile": "https://Stackoverflow.com/users/350351", "pm_score": 1, "selected": false, "text": "diff" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90075", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4718/" ]
90,092
<p>I have a table in <code>MySQL</code> that has 3 fields and I want to enforce uniqueness among two of the fields. Here is the table <code>DDL</code>:</p> <pre><code>CREATE TABLE `CLIENT_NAMES` ( `ID` int(11) NOT NULL auto_increment, `CLIENT_NAME` varchar(500) NOT NULL, `OWNER_ID` int(11) NOT NULL, PRIMARY KEY (`ID`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code></pre> <p>The <code>ID</code> field is a surrogate key (this table is being loaded with ETL). The <code>CLIENT_NAME</code> is a field that contains names of clients The <code>OWNER_ID</code> is an id indicates a clients owner.</p> <p>I thought I could enforce this with a unique index on <code>CLIENT_NAME</code> and <code>OWNER_ID</code>, </p> <pre><code>ALTER TABLE `DW`.`CLIENT_NAMES` ADD UNIQUE INDEX enforce_unique_idx(`CLIENT_NAME`, `OWNER_ID`); </code></pre> <p>but MySQL gives me an error: </p> <blockquote> <p>Error executing SQL commands to update table. Specified key was too long; max key length is 765 bytes (error 1071)</p> </blockquote> <p>Anyone else have any ideas?</p>
[ { "answer_id": 90129, "author": "Terry G Lorber", "author_id": 809, "author_profile": "https://Stackoverflow.com/users/809", "pm_score": -1, "selected": false, "text": "CLIENT_NAME" }, { "answer_id": 90189, "author": "Aeon", "author_id": 13289, "author_profile": "https://Stackoverflow.com/users/13289", "pm_score": 0, "selected": false, "text": "CREATE TABLE `CLIENTS` (\n`ID` int(11) NOT NULL auto_increment,\n`CLIENT_NAME` varchar(500) NOT NULL,\n# other client fields - address, phone, whatever\nPRIMARY KEY (`ID`),\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n\nCREATE TABLE `CLIENTS_OWNERS` (\n`CLIENT_ID` int(11) NOT NULL,\n`OWNER_ID` int(11) NOT NULL,\nPRIMARY KEY (`CLIENT_ID`,`OWNER_ID`),\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4082/" ]
90,121
<p>The question is how to make the similar thing like symlink in windows like in *nix. It's really hard to write whole path to the file in console (even using [tab], it's not the way if you need to change language). Adding everything in PATH is tiring too. It'll be great to make a symlink running one command.</p> <p>Actually I'm looking for console app.</p>
[ { "answer_id": 90132, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": -1, "selected": false, "text": "mklink" }, { "answer_id": 90395, "author": "willson", "author_id": 11972, "author_profile": "https://Stackoverflow.com/users/11972", "pm_score": 3, "selected": false, "text": "junction Disk:\\path\\to\\mount\\point Disk:\\path\\to\\something\\to\\mount\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11972/" ]
90,151
<p>Anyone got a working example of using ruby to post to a presigned URL on s3</p>
[ { "answer_id": 98952, "author": "Dan Harper", "author_id": 14530, "author_profile": "https://Stackoverflow.com/users/14530", "pm_score": 1, "selected": false, "text": "AWS::S3::S3Object.url_for(self.full_filename,\n self.bucket_name, {\n :use_ssl => true,\n :expires_in => ttl_seconds\n })\n" }, { "answer_id": 14748463, "author": "CantGetANick", "author_id": 228589, "author_profile": "https://Stackoverflow.com/users/228589", "pm_score": 2, "selected": false, "text": "require 'rubygems'\nrequire 'aws-sdk'\nrequire 'right_aws'\nrequire 'net/http'\nrequire 'uri'\nrequire 'rack'\n\n\naccess_key_id = 'AAAAAAAAAAAAAAAAA'\nsecret_access_key = 'ASDFASDFAS4646ASDFSAFASDFASDFSADF'\n\n\ns3 = AWS::S3.new( :access_key_id => access_key_id, :secret_access_key => secret_access_key)\n\nright_s3 = RightAws::S3Interface.new(access_key_id, secret_access_key, {:multi_thread => true, :logger => nil} ) \n\n\n\nbucket_name = 'your-bucket-name'\nkey = \"your-file-name.ext\"\n\nright_url = right_s3.put_link(bucket_name, key)\nright_scan_command = \"curl -I --upload-file #{key} '#{right_url.to_s}'\"\nsystem(right_scan_command)\n\nbucket = s3.buckets[bucket_name]\nform = bucket.presigned_post(:key => key)\nuri = URI(form.url.to_s + '/' + key)\nuri.query = Rack::Utils.build_query(form.fields)\nscan_command = \"curl -I --upload-file #{key} '#{uri.to_s}'\"\nsystem(scan_command)\n" }, { "answer_id": 50590108, "author": "J. Lovell", "author_id": 9865885, "author_profile": "https://Stackoverflow.com/users/9865885", "pm_score": 1, "selected": false, "text": "require 'net/http'\n\nfile = \"somefile.ext\"\nurl = URI.parse(presigned_url)\nNet::HTTP.start(url.host) do |http|\n http.send_request(\"PUT\", url.request_uri, File.read(file), {\"content-type\" => \"\",})\nend\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17232/" ]
90,176
<p>I am writing a simple checkers game in Java. When I mouse over the board my processor ramps up to 50% (100% on a core).</p> <p>I would like to find out what part of my code(assuming its my fault) is executing during this.</p> <p>I have tried debugging, but step-through debugging doesn't work very well in this case.</p> <p>Is there any tool that can tell me where my problem lies? I am currently using Eclipse.</p>
[ { "answer_id": 90575, "author": "Rejeev Divakaran", "author_id": 10980, "author_profile": "https://Stackoverflow.com/users/10980", "pm_score": 1, "selected": false, "text": "while(true){\n if(status) break;\n // Thread.sleep(60000); // such a statement would have avoided busy wait\n}\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
90,178
<p>I am working on a web application where I want the content to fill the height of the entire screen.</p> <p>The page has a header, which contains a logo, and account information. This could be an arbitrary height. I want the content div to fill the rest of the page to the bottom.</p> <p>I have a header <code>div</code> and a content <code>div</code>. At the moment I am using a table for the layout like so:</p> <p>CSS and HTML</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#page { height: 100%; width: 100% } #tdcontent { height: 100%; } #content { overflow: auto; /* or overflow: hidden; */ }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table id="page"&gt; &lt;tr&gt; &lt;td id="tdheader"&gt; &lt;div id="header"&gt;...&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="tdcontent"&gt; &lt;div id="content"&gt;...&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;</code></pre> </div> </div> </p> <p>The entire height of the page is filled, and no scrolling is required.</p> <p>For anything inside the content div, setting <code>top: 0;</code> will put it right underneath the header. Sometimes the content will be a real table, with its height set to 100%. Putting <code>header</code> inside <code>content</code> will not allow this to work.</p> <p>Is there a way to achieve the same effect without using the <code>table</code>?</p> <p><strong>Update:</strong></p> <p>Elements inside the content <code>div</code> will have heights set to percentages as well. So something at 100% inside the <code>div</code> will fill it to the bottom. As will two elements at 50%.</p> <p><strong>Update 2:</strong></p> <p>For instance, if the header takes up 20% of the screen's height, a table specified at 50% inside <code>#content</code> would take up 40% of the screen space. So far, wrapping the entire thing in a table is the only thing that works.</p>
[ { "answer_id": 90414, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 4, "selected": false, "text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title>Test</title>\n<style type=\"text/css\">\nbody\n,html\n{\n height: 100%;\n margin: 0;\n padding: 0;\n color: #FFF;\n}\n\n#header\n{\n float: left;\n width: 100%;\n background: red;\n}\n\n#content\n{\n height: 100%;\n overflow: auto;\n background: blue;\n}\n\n</style>\n</head>\n<body>\n\n <div id=\"content\">\n <div id=\"header\">\n Header\n <p>Header stuff</p>\n </div>\n Content\n <p>Content stuff</p>\n </div>\n\n</body>\n</html>\n" }, { "answer_id": 90886, "author": "NICCAI", "author_id": 1629400, "author_profile": "https://Stackoverflow.com/users/1629400", "pm_score": 8, "selected": false, "text": "Element Height = Viewport height - element.offset.top - desired bottom margin\n" }, { "answer_id": 94925, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 3, "selected": false, "text": "#content" }, { "answer_id": 5623913, "author": "Chris", "author_id": 13700, "author_profile": "https://Stackoverflow.com/users/13700", "pm_score": 5, "selected": false, "text": "display:table" }, { "answer_id": 6409310, "author": "B_G", "author_id": 806386, "author_profile": "https://Stackoverflow.com/users/806386", "pm_score": 4, "selected": false, "text": "body {\n padding: 0;\n margin: 0;\n height: 100%;\n overflow: hidden;\n}\n\n#header {\n position: absolute;\n top: 0;\n left: 0;\n height: 50px;\n}\n\n#content {\n position: absolute;\n top: 0;\n left: 0;\n padding-top: 50px;\n height: 100%;\n}\n" }, { "answer_id": 6964558, "author": "STeN", "author_id": 384115, "author_profile": "https://Stackoverflow.com/users/384115", "pm_score": -1, "selected": false, "text": "<div>" }, { "answer_id": 7794900, "author": "Tonye - True Vine Productions", "author_id": 999297, "author_profile": "https://Stackoverflow.com/users/999297", "pm_score": 5, "selected": false, "text": "padding-bottom: 100%;\n" }, { "answer_id": 7851347, "author": "h--n", "author_id": 375230, "author_profile": "https://Stackoverflow.com/users/375230", "pm_score": 8, "selected": false, "text": "@media screen { \n \n /* start of screen rules. */ \n \n /* Generic pane rules */\n body { margin: 0 }\n .row, .col { overflow: hidden; position: absolute; }\n .row { left: 0; right: 0; }\n .col { top: 0; bottom: 0; }\n .scroll-x { overflow-x: auto; }\n .scroll-y { overflow-y: auto; }\n\n .header.row { height: 75px; top: 0; }\n .body.row { top: 75px; bottom: 50px; }\n .footer.row { height: 50px; bottom: 0; }\n \n /* end of screen rules. */ \n}" }, { "answer_id": 9358676, "author": "Thaoms", "author_id": 1220637, "author_profile": "https://Stackoverflow.com/users/1220637", "pm_score": 4, "selected": false, "text": "html, body {\n height: 100%;\n}\n\n#containerInput {\n background-image: url('../img/edit_bg.jpg');\n height: 40%;\n}\n\n#containerControl {\n background-image: url('../img/control_bg.jpg');\n height: 60%;\n}\n" }, { "answer_id": 16251731, "author": "Arun", "author_id": 161633, "author_profile": "https://Stackoverflow.com/users/161633", "pm_score": 3, "selected": false, "text": "var sizeFooter = function(){\n $(\".webfooter\")\n .css(\"padding-bottom\", \"0px\")\n .css(\"padding-bottom\", $(window).height() - $(\"body\").height())\n}\n$(window).resize(sizeFooter);\n" }, { "answer_id": 16357269, "author": "Mikko Rantalainen", "author_id": 334451, "author_profile": "https://Stackoverflow.com/users/334451", "pm_score": 5, "selected": false, "text": "display: flex" }, { "answer_id": 16960823, "author": "Danield", "author_id": 703717, "author_profile": "https://Stackoverflow.com/users/703717", "pm_score": 7, "selected": false, "text": "<body> \n <div>hello </div>\n <div>there</div>\n</body>\n" }, { "answer_id": 17496982, "author": "Greg", "author_id": 745250, "author_profile": "https://Stackoverflow.com/users/745250", "pm_score": 3, "selected": false, "text": "display: table" }, { "answer_id": 23323175, "author": "Mr. Alien", "author_id": 1542290, "author_profile": "https://Stackoverflow.com/users/1542290", "pm_score": 7, "selected": false, "text": "calc()" }, { "answer_id": 24979148, "author": "Pebbl", "author_id": 1490904, "author_profile": "https://Stackoverflow.com/users/1490904", "pm_score": 12, "selected": true, "text": "html,\nbody {\n height: 100%;\n margin: 0;\n}\n\n.box {\n display: flex;\n flex-flow: column;\n height: 100%;\n}\n\n.box .row {\n border: 1px dotted grey;\n}\n\n.box .row.header {\n flex: 0 1 auto;\n /* The above is shorthand for:\n flex-grow: 0,\n flex-shrink: 1,\n flex-basis: auto\n */\n}\n\n.box .row.content {\n flex: 1 1 auto;\n}\n\n.box .row.footer {\n flex: 0 1 40px;\n}" }, { "answer_id": 25838052, "author": "Ormoz", "author_id": 1600305, "author_profile": "https://Stackoverflow.com/users/1600305", "pm_score": 5, "selected": false, "text": "CSS" }, { "answer_id": 28634506, "author": "John Kurlak", "author_id": 55732, "author_profile": "https://Stackoverflow.com/users/55732", "pm_score": 5, "selected": false, "text": ".table {\n display: table;\n}\n\n.table-row {\n display: table-row;\n}\n\n.table-cell {\n display: table-cell;\n}\n\n.container {\n width: 400px;\n height: 300px;\n}\n\n.header {\n background: cyan;\n}\n\n.body {\n background: yellow;\n height: 100%;\n}\n\n.body-content-outer-wrapper {\n height: 100%;\n}\n\n.body-content-inner-wrapper {\n height: 100%;\n position: relative;\n overflow: auto;\n}\n\n.body-content {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n}" }, { "answer_id": 28771764, "author": "zok", "author_id": 795398, "author_profile": "https://Stackoverflow.com/users/795398", "pm_score": 6, "selected": false, "text": "html,\nbody {\n height: 100%;\n}\n\nbody {\n display: flex;\n flex-direction: column;\n}\n\n.content {\n flex-grow: 1;\n}" }, { "answer_id": 32182925, "author": "dev.meghraj", "author_id": 1435800, "author_profile": "https://Stackoverflow.com/users/1435800", "pm_score": 5, "selected": false, "text": "height: calc(100% - 10px); // 10px is height of your first div...\n" }, { "answer_id": 33439733, "author": "puiu", "author_id": 1727232, "author_profile": "https://Stackoverflow.com/users/1727232", "pm_score": 4, "selected": false, "text": "height: 100vh;" }, { "answer_id": 34579298, "author": "Michael P. Bazos", "author_id": 3120193, "author_profile": "https://Stackoverflow.com/users/3120193", "pm_score": 5, "selected": false, "text": "<body>\n <header>Header with an arbitrary height</header>\n <main>\n This container will grow so as to take the remaining height\n </main>\n</body>\n" }, { "answer_id": 37370197, "author": "nguyên", "author_id": 572180, "author_profile": "https://Stackoverflow.com/users/572180", "pm_score": 6, "selected": false, "text": "height: calc(100vh - 110px);" }, { "answer_id": 38153735, "author": "Pat M", "author_id": 4155124, "author_profile": "https://Stackoverflow.com/users/4155124", "pm_score": 3, "selected": false, "text": "<body>\n <header></header>\n <div class=\"content\"></div>\n <footer></footer>\n</body>\n" }, { "answer_id": 39150121, "author": "Anthony Brenelière", "author_id": 3433751, "author_profile": "https://Stackoverflow.com/users/3433751", "pm_score": 3, "selected": false, "text": " body{\n margin: 0;\n color: white;\n height: 100%;\n }\n div#myapp\n {\n display: flex;\n flex-direction: column;\n background-color: red; /* <-- painful color for your eyes ! */\n height: 100%; /* <-- if you remove this line, myapp has no limited height */\n }\n div#main /* parent div for sidebar and content */\n {\n display: flex;\n width: 100%;\n height: 90%; \n }\n div#header {\n background-color: #333;\n height: 5%;\n }\n div#footer {\n background-color: #222;\n height: 5%;\n }\n div#sidebar {\n background-color: #666;\n width: 20%;\n overflow-y: auto;\n }\n div#content {\n background-color: #888;\n width: 80%;\n overflow-y: auto;\n }\n div.fized_size_element {\n background-color: #AAA;\n display: block;\n width: 100px;\n height: 50px;\n margin: 5px;\n }\n" }, { "answer_id": 41984205, "author": "grinmax", "author_id": 7309671, "author_profile": "https://Stackoverflow.com/users/7309671", "pm_score": 3, "selected": false, "text": "<div class=\"container\">\n <div class=\"title\">Title</div>\n <div class=\"content\">Content</div>\n <div class=\"footer\">Footer</div>\n</div>\n" }, { "answer_id": 44607939, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 6, "selected": false, "text": "vh" }, { "answer_id": 44908512, "author": "Paulie_D", "author_id": 2802040, "author_profile": "https://Stackoverflow.com/users/2802040", "pm_score": 4, "selected": false, "text": "body" }, { "answer_id": 49447848, "author": "Zohab Ali", "author_id": 5361964, "author_profile": "https://Stackoverflow.com/users/5361964", "pm_score": 3, "selected": false, "text": " style=\"height:100vh\"\n" }, { "answer_id": 60403264, "author": "gadolf", "author_id": 5889767, "author_profile": "https://Stackoverflow.com/users/5889767", "pm_score": 5, "selected": false, "text": "html, body {\n height: 100%;\n}\n" }, { "answer_id": 61217322, "author": "Michael Schade", "author_id": 1236252, "author_profile": "https://Stackoverflow.com/users/1236252", "pm_score": 4, "selected": false, "text": "html {\n height: 100%;\n}\n\nbody {\n height: 100%;\n margin: 0;\n}\n\nsection {\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n\ndiv:first-child {\n background: gold;\n}\n\ndiv:last-child {\n background: plum;\n flex-grow: 1;\n}" }, { "answer_id": 64374418, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": ".root {\n display: grid;\n grid-template-rows: minmax(60px, auto) minmax(0, 100%);\n}\n" }, { "answer_id": 66466661, "author": "Chukwuemeka Maduekwe", "author_id": 12490386, "author_profile": "https://Stackoverflow.com/users/12490386", "pm_score": -1, "selected": false, "text": ".divName {\n height: stretch\n}\n" }, { "answer_id": 66524544, "author": "Just a coder", "author_id": 433073, "author_profile": "https://Stackoverflow.com/users/433073", "pm_score": 2, "selected": false, "text": ".the-container-div {\n display: grid;\n grid-template-columns: 1fr;\n grid-template-rows: auto min-content;\n height: 100vh;\n}\n.view-to-remain-small {\n grid-row: 2;\n}\n\n.view-to-be-stretched {\n grid-row: 1\n}\n" }, { "answer_id": 69921961, "author": "Chong Lip Phang", "author_id": 2435020, "author_profile": "https://Stackoverflow.com/users/2435020", "pm_score": 0, "selected": false, "text": "function observeMainResize(){\n const resizeObserver = new ResizeObserver(entries => {\n for (let entry of entries) {\n $(\"nav\").height(Math.max($(\"main\").height(),\n $(\"nav\") .height()));\n }\n });\n resizeObserver.observe(document.querySelector('main'));\n}\n" }, { "answer_id": 73698597, "author": "Chong Lip Phang", "author_id": 2435020, "author_profile": "https://Stackoverflow.com/users/2435020", "pm_score": -1, "selected": false, "text": "<!DOCTYPE html>\n<html><head>\n<style>\n#B {\n position:fixed;\n width: 100%;\n height: 100%;\n background-color: orange;\n}\n#B1 {\n position:fixed;\n top:0;\n bottom: 0;\n width: 100%;\n background-color: cyan; \n}\n#B2 {\n position:fixed;\n bottom: 0;\n height: 35px;\n width: 100%;\n background: green;\n}\n\n}</style></head>\n<body>\n <div id=\"B1\">B1</div>\n <div id=\"B2\">B2</div>\n</body>\n</html>" }, { "answer_id": 74304362, "author": "Nyi Nyi Hmue Aung", "author_id": 15247669, "author_profile": "https://Stackoverflow.com/users/15247669", "pm_score": 1, "selected": false, "text": " <div style={{\n display:grid,\n gridTemplateRows:'max-content 1fr',\n}}>\n <div>\n Header\n </div>\n <div style={{height:'100%',minHeight:'0'}}>\n Content\n </div>\n </div>\n\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16299/" ]
90,181
<p>I've just run into a display glitch in IE6 with the ExtJS framework. - Hopefully someone can point me in the right direction.</p> <p>In the following example, the bbar for the panel is displayed 2ems narrower than the panel it is attached to (it's left aligned) in IE6, where as in Firefox it is displayed as the same width as the panel.</p> <p>Can anyone suggest how to fix this?</p> <p>I seem to be able to work around either by specifying the width of the panel in ems or the padding in pixels, but I assume it would be expected to work as I have it below.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"/&gt; &lt;script type="text/javascript" src="ext/ext-base.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="ext/ext-all-debug.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; Ext.onReady(function(){ var main = new Ext.Panel({ renderTo: 'content', bodyStyle: 'padding: 1em;', width: 500, html: "Alignment issue in IE - The bbar's width is 2ems less than the main panel in IE6.", bbar: [ "-&gt;", {id: "continue", text: 'Continue'} ] }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
[ { "answer_id": 90414, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 4, "selected": false, "text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title>Test</title>\n<style type=\"text/css\">\nbody\n,html\n{\n height: 100%;\n margin: 0;\n padding: 0;\n color: #FFF;\n}\n\n#header\n{\n float: left;\n width: 100%;\n background: red;\n}\n\n#content\n{\n height: 100%;\n overflow: auto;\n background: blue;\n}\n\n</style>\n</head>\n<body>\n\n <div id=\"content\">\n <div id=\"header\">\n Header\n <p>Header stuff</p>\n </div>\n Content\n <p>Content stuff</p>\n </div>\n\n</body>\n</html>\n" }, { "answer_id": 90886, "author": "NICCAI", "author_id": 1629400, "author_profile": "https://Stackoverflow.com/users/1629400", "pm_score": 8, "selected": false, "text": "Element Height = Viewport height - element.offset.top - desired bottom margin\n" }, { "answer_id": 94925, "author": "Jerph", "author_id": 1701, "author_profile": "https://Stackoverflow.com/users/1701", "pm_score": 3, "selected": false, "text": "#content" }, { "answer_id": 5623913, "author": "Chris", "author_id": 13700, "author_profile": "https://Stackoverflow.com/users/13700", "pm_score": 5, "selected": false, "text": "display:table" }, { "answer_id": 6409310, "author": "B_G", "author_id": 806386, "author_profile": "https://Stackoverflow.com/users/806386", "pm_score": 4, "selected": false, "text": "body {\n padding: 0;\n margin: 0;\n height: 100%;\n overflow: hidden;\n}\n\n#header {\n position: absolute;\n top: 0;\n left: 0;\n height: 50px;\n}\n\n#content {\n position: absolute;\n top: 0;\n left: 0;\n padding-top: 50px;\n height: 100%;\n}\n" }, { "answer_id": 6964558, "author": "STeN", "author_id": 384115, "author_profile": "https://Stackoverflow.com/users/384115", "pm_score": -1, "selected": false, "text": "<div>" }, { "answer_id": 7794900, "author": "Tonye - True Vine Productions", "author_id": 999297, "author_profile": "https://Stackoverflow.com/users/999297", "pm_score": 5, "selected": false, "text": "padding-bottom: 100%;\n" }, { "answer_id": 7851347, "author": "h--n", "author_id": 375230, "author_profile": "https://Stackoverflow.com/users/375230", "pm_score": 8, "selected": false, "text": "@media screen { \n \n /* start of screen rules. */ \n \n /* Generic pane rules */\n body { margin: 0 }\n .row, .col { overflow: hidden; position: absolute; }\n .row { left: 0; right: 0; }\n .col { top: 0; bottom: 0; }\n .scroll-x { overflow-x: auto; }\n .scroll-y { overflow-y: auto; }\n\n .header.row { height: 75px; top: 0; }\n .body.row { top: 75px; bottom: 50px; }\n .footer.row { height: 50px; bottom: 0; }\n \n /* end of screen rules. */ \n}" }, { "answer_id": 9358676, "author": "Thaoms", "author_id": 1220637, "author_profile": "https://Stackoverflow.com/users/1220637", "pm_score": 4, "selected": false, "text": "html, body {\n height: 100%;\n}\n\n#containerInput {\n background-image: url('../img/edit_bg.jpg');\n height: 40%;\n}\n\n#containerControl {\n background-image: url('../img/control_bg.jpg');\n height: 60%;\n}\n" }, { "answer_id": 16251731, "author": "Arun", "author_id": 161633, "author_profile": "https://Stackoverflow.com/users/161633", "pm_score": 3, "selected": false, "text": "var sizeFooter = function(){\n $(\".webfooter\")\n .css(\"padding-bottom\", \"0px\")\n .css(\"padding-bottom\", $(window).height() - $(\"body\").height())\n}\n$(window).resize(sizeFooter);\n" }, { "answer_id": 16357269, "author": "Mikko Rantalainen", "author_id": 334451, "author_profile": "https://Stackoverflow.com/users/334451", "pm_score": 5, "selected": false, "text": "display: flex" }, { "answer_id": 16960823, "author": "Danield", "author_id": 703717, "author_profile": "https://Stackoverflow.com/users/703717", "pm_score": 7, "selected": false, "text": "<body> \n <div>hello </div>\n <div>there</div>\n</body>\n" }, { "answer_id": 17496982, "author": "Greg", "author_id": 745250, "author_profile": "https://Stackoverflow.com/users/745250", "pm_score": 3, "selected": false, "text": "display: table" }, { "answer_id": 23323175, "author": "Mr. Alien", "author_id": 1542290, "author_profile": "https://Stackoverflow.com/users/1542290", "pm_score": 7, "selected": false, "text": "calc()" }, { "answer_id": 24979148, "author": "Pebbl", "author_id": 1490904, "author_profile": "https://Stackoverflow.com/users/1490904", "pm_score": 12, "selected": true, "text": "html,\nbody {\n height: 100%;\n margin: 0;\n}\n\n.box {\n display: flex;\n flex-flow: column;\n height: 100%;\n}\n\n.box .row {\n border: 1px dotted grey;\n}\n\n.box .row.header {\n flex: 0 1 auto;\n /* The above is shorthand for:\n flex-grow: 0,\n flex-shrink: 1,\n flex-basis: auto\n */\n}\n\n.box .row.content {\n flex: 1 1 auto;\n}\n\n.box .row.footer {\n flex: 0 1 40px;\n}" }, { "answer_id": 25838052, "author": "Ormoz", "author_id": 1600305, "author_profile": "https://Stackoverflow.com/users/1600305", "pm_score": 5, "selected": false, "text": "CSS" }, { "answer_id": 28634506, "author": "John Kurlak", "author_id": 55732, "author_profile": "https://Stackoverflow.com/users/55732", "pm_score": 5, "selected": false, "text": ".table {\n display: table;\n}\n\n.table-row {\n display: table-row;\n}\n\n.table-cell {\n display: table-cell;\n}\n\n.container {\n width: 400px;\n height: 300px;\n}\n\n.header {\n background: cyan;\n}\n\n.body {\n background: yellow;\n height: 100%;\n}\n\n.body-content-outer-wrapper {\n height: 100%;\n}\n\n.body-content-inner-wrapper {\n height: 100%;\n position: relative;\n overflow: auto;\n}\n\n.body-content {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n}" }, { "answer_id": 28771764, "author": "zok", "author_id": 795398, "author_profile": "https://Stackoverflow.com/users/795398", "pm_score": 6, "selected": false, "text": "html,\nbody {\n height: 100%;\n}\n\nbody {\n display: flex;\n flex-direction: column;\n}\n\n.content {\n flex-grow: 1;\n}" }, { "answer_id": 32182925, "author": "dev.meghraj", "author_id": 1435800, "author_profile": "https://Stackoverflow.com/users/1435800", "pm_score": 5, "selected": false, "text": "height: calc(100% - 10px); // 10px is height of your first div...\n" }, { "answer_id": 33439733, "author": "puiu", "author_id": 1727232, "author_profile": "https://Stackoverflow.com/users/1727232", "pm_score": 4, "selected": false, "text": "height: 100vh;" }, { "answer_id": 34579298, "author": "Michael P. Bazos", "author_id": 3120193, "author_profile": "https://Stackoverflow.com/users/3120193", "pm_score": 5, "selected": false, "text": "<body>\n <header>Header with an arbitrary height</header>\n <main>\n This container will grow so as to take the remaining height\n </main>\n</body>\n" }, { "answer_id": 37370197, "author": "nguyên", "author_id": 572180, "author_profile": "https://Stackoverflow.com/users/572180", "pm_score": 6, "selected": false, "text": "height: calc(100vh - 110px);" }, { "answer_id": 38153735, "author": "Pat M", "author_id": 4155124, "author_profile": "https://Stackoverflow.com/users/4155124", "pm_score": 3, "selected": false, "text": "<body>\n <header></header>\n <div class=\"content\"></div>\n <footer></footer>\n</body>\n" }, { "answer_id": 39150121, "author": "Anthony Brenelière", "author_id": 3433751, "author_profile": "https://Stackoverflow.com/users/3433751", "pm_score": 3, "selected": false, "text": " body{\n margin: 0;\n color: white;\n height: 100%;\n }\n div#myapp\n {\n display: flex;\n flex-direction: column;\n background-color: red; /* <-- painful color for your eyes ! */\n height: 100%; /* <-- if you remove this line, myapp has no limited height */\n }\n div#main /* parent div for sidebar and content */\n {\n display: flex;\n width: 100%;\n height: 90%; \n }\n div#header {\n background-color: #333;\n height: 5%;\n }\n div#footer {\n background-color: #222;\n height: 5%;\n }\n div#sidebar {\n background-color: #666;\n width: 20%;\n overflow-y: auto;\n }\n div#content {\n background-color: #888;\n width: 80%;\n overflow-y: auto;\n }\n div.fized_size_element {\n background-color: #AAA;\n display: block;\n width: 100px;\n height: 50px;\n margin: 5px;\n }\n" }, { "answer_id": 41984205, "author": "grinmax", "author_id": 7309671, "author_profile": "https://Stackoverflow.com/users/7309671", "pm_score": 3, "selected": false, "text": "<div class=\"container\">\n <div class=\"title\">Title</div>\n <div class=\"content\">Content</div>\n <div class=\"footer\">Footer</div>\n</div>\n" }, { "answer_id": 44607939, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 6, "selected": false, "text": "vh" }, { "answer_id": 44908512, "author": "Paulie_D", "author_id": 2802040, "author_profile": "https://Stackoverflow.com/users/2802040", "pm_score": 4, "selected": false, "text": "body" }, { "answer_id": 49447848, "author": "Zohab Ali", "author_id": 5361964, "author_profile": "https://Stackoverflow.com/users/5361964", "pm_score": 3, "selected": false, "text": " style=\"height:100vh\"\n" }, { "answer_id": 60403264, "author": "gadolf", "author_id": 5889767, "author_profile": "https://Stackoverflow.com/users/5889767", "pm_score": 5, "selected": false, "text": "html, body {\n height: 100%;\n}\n" }, { "answer_id": 61217322, "author": "Michael Schade", "author_id": 1236252, "author_profile": "https://Stackoverflow.com/users/1236252", "pm_score": 4, "selected": false, "text": "html {\n height: 100%;\n}\n\nbody {\n height: 100%;\n margin: 0;\n}\n\nsection {\n display: flex;\n flex-direction: column;\n height: 100%;\n}\n\ndiv:first-child {\n background: gold;\n}\n\ndiv:last-child {\n background: plum;\n flex-grow: 1;\n}" }, { "answer_id": 64374418, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": ".root {\n display: grid;\n grid-template-rows: minmax(60px, auto) minmax(0, 100%);\n}\n" }, { "answer_id": 66466661, "author": "Chukwuemeka Maduekwe", "author_id": 12490386, "author_profile": "https://Stackoverflow.com/users/12490386", "pm_score": -1, "selected": false, "text": ".divName {\n height: stretch\n}\n" }, { "answer_id": 66524544, "author": "Just a coder", "author_id": 433073, "author_profile": "https://Stackoverflow.com/users/433073", "pm_score": 2, "selected": false, "text": ".the-container-div {\n display: grid;\n grid-template-columns: 1fr;\n grid-template-rows: auto min-content;\n height: 100vh;\n}\n.view-to-remain-small {\n grid-row: 2;\n}\n\n.view-to-be-stretched {\n grid-row: 1\n}\n" }, { "answer_id": 69921961, "author": "Chong Lip Phang", "author_id": 2435020, "author_profile": "https://Stackoverflow.com/users/2435020", "pm_score": 0, "selected": false, "text": "function observeMainResize(){\n const resizeObserver = new ResizeObserver(entries => {\n for (let entry of entries) {\n $(\"nav\").height(Math.max($(\"main\").height(),\n $(\"nav\") .height()));\n }\n });\n resizeObserver.observe(document.querySelector('main'));\n}\n" }, { "answer_id": 73698597, "author": "Chong Lip Phang", "author_id": 2435020, "author_profile": "https://Stackoverflow.com/users/2435020", "pm_score": -1, "selected": false, "text": "<!DOCTYPE html>\n<html><head>\n<style>\n#B {\n position:fixed;\n width: 100%;\n height: 100%;\n background-color: orange;\n}\n#B1 {\n position:fixed;\n top:0;\n bottom: 0;\n width: 100%;\n background-color: cyan; \n}\n#B2 {\n position:fixed;\n bottom: 0;\n height: 35px;\n width: 100%;\n background: green;\n}\n\n}</style></head>\n<body>\n <div id=\"B1\">B1</div>\n <div id=\"B2\">B2</div>\n</body>\n</html>" }, { "answer_id": 74304362, "author": "Nyi Nyi Hmue Aung", "author_id": 15247669, "author_profile": "https://Stackoverflow.com/users/15247669", "pm_score": 1, "selected": false, "text": " <div style={{\n display:grid,\n gridTemplateRows:'max-content 1fr',\n}}>\n <div>\n Header\n </div>\n <div style={{height:'100%',minHeight:'0'}}>\n Content\n </div>\n </div>\n\n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/797/" ]
90,184
<p>I need a pseudorandom number generator algorithm for a assembler program assigned in a course, and I would prefer a simple algorithm. However, I cannot use an external library. </p> <p>What is a good, simple pseudorandom number generator algorithm for assembly?</p>
[ { "answer_id": 92554, "author": "ICW", "author_id": 17664, "author_profile": "https://Stackoverflow.com/users/17664", "pm_score": 2, "selected": false, "text": "MOD 2^32" }, { "answer_id": 104462, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 2, "selected": false, "text": "#include <emmintrin.h>\n\nstatic __m128i LFSR;\n\nvoid InitRandom (int Seed)\n{\n LFSR = _mm_cvtsi32_si128 (Seed);\n}\n\nint GetRandom (int NumBits)\n{\n __m128i seed = LFSR;\n __m128i one = _mm_cvtsi32_si128(1);\n __m128i mask; \n int i;\n\n for (i=0; i<NumBits; i++)\n {\n\n // generate xor of adjecting bits\n __m128i temp = _mm_xor_si128(seed, _mm_srli_epi64(seed,1));\n\n // generate xor of feedback bits 5,6 and 62,61\n __m128i NewBit = _mm_xor_si128( _mm_srli_epi64(temp,5),\n _mm_srli_epi64(temp,61));\n\n // Mask out single bit: \n NewBit = _mm_and_si128 (NewBit, one);\n\n // Shift & insert new result bit:\n seed = _mm_or_si128 (NewBit, _mm_add_epi64 (seed,seed));\n }\n\n // Write back seed...\n LFSR = seed;\n\n // generate mask of NumBit ones.\n mask = _mm_srli_epi64 (_mm_cmpeq_epi8(seed, seed), 64-NumBits);\n\n // return random number:\n return _mm_cvtsi128_si32 (_mm_and_si128(seed,mask));\n}\n" }, { "answer_id": 8163217, "author": "jason", "author_id": 1051187, "author_profile": "https://Stackoverflow.com/users/1051187", "pm_score": 1, "selected": false, "text": "delay_function macro\n mov cx,0ffffh\n.repeat\n push cx\n mov cx,0f00h\n .repeat\n dec cx\n .until cx==0\n pop cx\n dec cx\n .until cx==0\nendm\n\nrandom_num macro\n mov cx,64 ;assum we want to get 64 random numbers\n mov si,0\n\nget_num: \n push cx\n delay_function ;since cpu clock is fast,so we use delay_function\n mov ah,2ch \n int 21h\n mov ax,dx ;get clock 1/100 sec\n div num ;assume we want to get a number from 0~num-1\n mov arry[si],ah ;save to array you set\n inc si\n pop cx\n loop get_num ;here we finish the get_random number \n" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10344/" ]
90,203
<p>What is the difference between different optimization levels in GCC? Assuming I don't care to have any debug hooks, why wouldn't I just use the highest level of optimization available to me? does a higher level of optimization necessarily (i.e. provably) generate a faster program?</p>
[ { "answer_id": 90228, "author": "Todd Gamblin", "author_id": 9122, "author_profile": "https://Stackoverflow.com/users/9122", "pm_score": 4, "selected": false, "text": "-O2" }, { "answer_id": 152710, "author": "Mihai Limbășan", "author_id": 14444, "author_profile": "https://Stackoverflow.com/users/14444", "pm_score": 1, "selected": false, "text": "-O" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17231/" ]
90,238
<p>As an example in pseudocode:</p> <pre><code>if ((a mod 2) == 0) { isEven = true; } else { isEven = false; } </code></pre>
[ { "answer_id": 90242, "author": "martinatime", "author_id": 1353, "author_profile": "https://Stackoverflow.com/users/1353", "pm_score": 7, "selected": false, "text": "boolean isEven = a % 2 == 0;\n" }, { "answer_id": 90244, "author": "J D OConal", "author_id": 17023, "author_profile": "https://Stackoverflow.com/users/17023", "pm_score": 3, "selected": false, "text": "if (a % 2 == 0) {\n} else {\n}\n" }, { "answer_id": 90247, "author": "Cody Hatch", "author_id": 17086, "author_profile": "https://Stackoverflow.com/users/17086", "pm_score": 10, "selected": true, "text": "%" }, { "answer_id": 90249, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 2, "selected": false, "text": "int a = 7;\nb = a % 2;\n" }, { "answer_id": 95946, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": -1, "selected": false, "text": "bool isEven = (a % 2) == 0;\n" }, { "answer_id": 2073758, "author": "Rob Rolnick", "author_id": 4798, "author_profile": "https://Stackoverflow.com/users/4798", "pm_score": 7, "selected": false, "text": "// Option 1: Clearest way for beginners\nboolean isEven;\nif ((a % 2) == 0)\n{\n isEven = true\n}\nelse\n{\n isEven = false\n}\n" }, { "answer_id": 2172061, "author": "Zom-B", "author_id": 262928, "author_profile": "https://Stackoverflow.com/users/262928", "pm_score": 5, "selected": false, "text": "private int mod(int x, int y)\n{\n int result = x % y;\n if (result < 0)\n {\n result += y;\n }\n return result;\n}\n" }, { "answer_id": 3354251, "author": "eljenso", "author_id": 30316, "author_profile": "https://Stackoverflow.com/users/30316", "pm_score": 2, "selected": false, "text": "%" }, { "answer_id": 3917066, "author": "michael", "author_id": 473599, "author_profile": "https://Stackoverflow.com/users/473599", "pm_score": 4, "selected": false, "text": "public boolean isEven(int a){\n return ( (a & 1) == 0 );\n}\n\npublic boolean isOdd(int a){\n return ( (a & 1) == 1 );\n}\n" }, { "answer_id": 4725976, "author": "kioto", "author_id": 578557, "author_profile": "https://Stackoverflow.com/users/578557", "pm_score": 2, "selected": false, "text": "// bad enough implementation of isEven method, for fun. so any worse?\nboolean isEven(int num)\n{\n num %= 10;\n if(num == 1)\n return false;\n else if(num == 0)\n return true;\n else\n return isEven(num + 2);\n}\nisEven = isEven(a);\n" }, { "answer_id": 18935194, "author": "Stefan T", "author_id": 2802543, "author_profile": "https://Stackoverflow.com/users/2802543", "pm_score": 4, "selected": false, "text": "(a % b + b) % b\n" }, { "answer_id": 23610743, "author": "brothers28", "author_id": 3122309, "author_profile": "https://Stackoverflow.com/users/3122309", "pm_score": 1, "selected": false, "text": "boolean isEven = false;\nif((a % 2) == 0)\n{\n isEven = true;\n}\n" }, { "answer_id": 49095157, "author": "Roland", "author_id": 480894, "author_profile": "https://Stackoverflow.com/users/480894", "pm_score": 3, "selected": false, "text": "%" }, { "answer_id": 56878005, "author": "Shant Dashjian", "author_id": 5614029, "author_profile": "https://Stackoverflow.com/users/5614029", "pm_score": 2, "selected": false, "text": "Java" }, { "answer_id": 57532749, "author": "m4110c", "author_id": 4338565, "author_profile": "https://Stackoverflow.com/users/4338565", "pm_score": 3, "selected": false, "text": "%" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17245/" ]
90,246
<p>I want to let users specify a date that may or may not include a day and month (but will have at least the year.) The problem is when it is stored as a datetime in the DB; the missing day/month will be saved as default values and I'll lose the original format and meaning of the date.</p> <p>My idea was to store the real format in a column as a string in addition to the datetime column. Then I could use the string column whenever I have to display the date and the datetime for everything else. The downside is an extra column for every date column in the table I want to display, and printing localized dates won't be as easy since I can't rely on the datetime value... I'll probably have to parse the string.</p> <p>I'm hoping I've overlooked something and there might be an easier way.</p> <p>(Note I'm using Rails if it matters for a solution.)</p>
[ { "answer_id": 90282, "author": "André Chalella", "author_id": 4850, "author_profile": "https://Stackoverflow.com/users/4850", "pm_score": 0, "selected": false, "text": "int" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9128/" ]
90,288
<p>If you have an 68K application written using CodeWarrior for Palm OS, how do you assign individual functions to different segments without manually moving files around in the segment tab in the IDE?</p>
[ { "answer_id": 90282, "author": "André Chalella", "author_id": 4850, "author_profile": "https://Stackoverflow.com/users/4850", "pm_score": 0, "selected": false, "text": "int" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1323/" ]
90,308
<p>This is probably too much to ask, but is there any language that does a really terrific job of representing time and date operations? I'll grant straight away that it's <b>really hard</b> to write a truly great time library. That said, are there any widespread languages that have one? Basically, I want something that handles time and date as comprehensively as modern regular expression libraries do their jobs. Everything I've seen so far in Python and Java omits one or more pretty important pieces, or makes too many things hard.</p> <p>At least this should be intuitive to do:</p> <ul> <li>find the number of days between two given dates, number of minutes between two given minute periods, etc. </li> <li>add and subtract intervals from timestamps </li> <li>allow simple conversion between timezones, with Daylight Saving Time changes by region automatically accounted for (given that there's an accurate supporting database of regional settings available) </li> <li>get the period that a given timestamp falls into, given period granularity ("what calendar day is this date in?") </li> <li>support very general string-to-date conversions (given a pattern)</li> </ul> <p>Further, if there's a Java-style Calendar/GregorianCalendar setup, the general Calendar class should be accommodating toward subclasses if I need to roll my own Hebrew, Babylonian, Tolkien, or MartianCalendar. (Java Calendars make this pointlessly hard, for example.)</p> <p>I am completely language-agnostic here. It's fine if the thing chokes on computing ambiguous stuff like "how many minutes are there between 2002 and next Valentine's Day?"</p>
[ { "answer_id": 90339, "author": "Redbeard", "author_id": 14977, "author_profile": "https://Stackoverflow.com/users/14977", "pm_score": 1, "selected": false, "text": "start_time = 5.months_ago.at_end_of_week \nend_time = 6.months.since(start_time)\n" }, { "answer_id": 90341, "author": "Shabbyrobe", "author_id": 15004, "author_profile": "https://Stackoverflow.com/users/15004", "pm_score": 2, "selected": false, "text": "<?php\necho strtotime(\"now\"), \"\\n\";\necho strtotime(\"10 September 2000\"), \"\\n\";\necho strtotime(\"+1 day\"), \"\\n\";\necho strtotime(\"+1 week\"), \"\\n\";\necho strtotime(\"+1 week 2 days 4 hours 2 seconds\"), \"\\n\";\necho strtotime(\"next Thursday\"), \"\\n\";\necho strtotime(\"last Monday\"), \"\\n\";\n?>\n" }, { "answer_id": 90409, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 2, "selected": false, "text": "// given two timestamps: $t1, and $t2:\n\n// find the number of days between two given dates, number of minutes\n// between two given minute periods, etc. \n$daysBetween = floor(($t2 - $t1) / 86400); // 86400 = 1 day in seconds\n$hoursBetween = floor(($t2 - $t1) / 3600); // 3600 = 1 hour in seconds\n\n// add and subtract intervals from timestamps \n$newDate = $t1 + $interval;\n\n// allow simple conversion between timezones, with Daylight Saving Time\n// changes by region automatically accounted for (given that there's an\n// accurate supporting database of regional settings available)\n\n// See PHP's Calendar functions for that\n// http://au2.php.net/manual/en/book.calendar.php\n// It not only supports basic stuff like timezones and DST, but also\n// different types of calendar: French, Julian, Gregorian and Jewish.\n\n// get the period that a given timestamp falls into, given period\n// granularity (\"what calendar day is this date in?\") \nif (date(\"d\", $t1) == 5) // check if the timestamp is the 5th of the month\nif (date(\"h\", $t1) == 16) // is it 4:00pm-4:59pm ?\n\n// support very general string-to-date conversions (given a pattern) \n\n// strtotime() is magic for this. you can just type in regular english\n// and it figures it out. If your dates are stored in a particular format\n// and you want to convert them, you can use strptime()\n" }, { "answer_id": 92551, "author": "Jörg W Mittag", "author_id": 2988, "author_profile": "https://Stackoverflow.com/users/2988", "pm_score": 2, "selected": false, "text": "# 2008-12-25 # - now[] -> days" }, { "answer_id": 55659927, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 2, "selected": false, "text": "Period" } ]
2008/09/18
[ "https://Stackoverflow.com/questions/90308", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]