qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
175,049
|
<p>I could write this, but before I do, I wanted to check to see if there are existing solutions out there since it seems a lot of websites already do this, so I was wondering if there was a quick way to do this.</p>
<p>Also, I am talking about "popout" windows, not "popup" windows. All JavaScript libraries support "popup" windows, but I want ones where they originally open as "popup" windows in the same browser window, but there is also a link to open them up in a brand new browser window.</p>
|
[
{
"answer_id": 175388,
"author": "Sergey Ilinsky",
"author_id": 23815,
"author_profile": "https://Stackoverflow.com/users/23815",
"pm_score": 1,
"selected": false,
"text": "var oDiv = document.getElementById('mydiv');\nvar oWindow = window.open(\"about:blank\");\n\noWindow.document.body.appendChild(oDiv.cloneNode(true))\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2484/"
] |
175,055
|
<p>I am running a series of JUnits using Apache ANT using JDK 1.5.</p>
<p>All JUnits that use an Oracle JDBC driver give the UnsatisfiedLinkError shown below.</p>
<p>What native library is it looking for and how do I solve this? What should the PATH variable contain?</p>
<pre><code>java.lang.UnsatisfiedLinkError: oracle/jdbc/driver/T2CConnection.t2cGetCharSet([CI[CI[CI[CII[SLoracle/jdbc/driver/GetCharSetError;)S
at oracle.jdbc.driver.T2CConnection.getCharSetIds(T2CConnection.java:2957)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:320)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:361)
at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:142)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:79)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:595)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:196)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:114)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:77)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:59)
at oracle.jdbc.pool.OracleConnectionCacheImpl.getNewPoolOrXAConnection(OracleConnectionCacheImpl.java:401)
at oracle.jdbc.pool.OracleConnectionCacheImpl.setMinLimit(OracleConnectionCacheImpl.java:752)
</code></pre>
|
[
{
"answer_id": 175902,
"author": "cagcowboy",
"author_id": 19629,
"author_profile": "https://Stackoverflow.com/users/19629",
"pm_score": 0,
"selected": false,
"text": "java [other java switches + runtime parameters] -Djava.library.path=YOUR_ORACLE_HOME\\bin run-classname\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175055",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,056
|
<p>In a project I am working on, we have an ongoing discussion amongst the dev team - should the production environment be deployed as a checkout from the SVN repository or as an export?</p>
<p>The development environment is obviously a checkout, since it is constantly updated.
For the production, I'm personally for checking out the main trunk, since it makes future updates easier (just run svn update). However some of the devs are against it, as svn creates files with the group/owner and permissions of the svn process (this is on a linux OS, so those things matter), and also having the .svn directories on the production seem to them to be somewhat dirty.</p>
<p>Also, if it is a checkout - how do you push individual features to the production without including in-development code? do you use tags or branch out for each feature? any alternatives?</p>
<p><strong>EDIT:</strong> I might not have been clear - one of the requirement is to be able to constantly be able to push fixes to the production environment. We want to avoid a complete build (which takes much longer than a simple update) just for pushing critical fixes.</p>
|
[
{
"answer_id": 1228320,
"author": "Chris",
"author_id": 150401,
"author_profile": "https://Stackoverflow.com/users/150401",
"pm_score": 5,
"selected": true,
"text": "# Disallow browsing of Subversion working copy administrative dirs.\n<DirectoryMatch \"^/.*/\\.svn/\">\n Order deny,allow\n Deny from all\n</DirectoryMatch>\n"
},
{
"answer_id": 3148532,
"author": "Michael Gerner Andreasen",
"author_id": 379959,
"author_profile": "https://Stackoverflow.com/users/379959",
"pm_score": 1,
"selected": false,
"text": "/var/www/www.my-prod-site.com/public/\n/var/www/www.my-prod-site.com/builds/Rev 1/\n/var/www/www.my-prod-site.com/builds/Rev 2/\n/var/www/www.my-prod-site.com/builds/Rev 3/\n/var/www/www.my-prod-site.com/builds/Rev 99/\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10585/"
] |
175,066
|
<p>My database contains three tables called <code>Object_Table</code>, <code>Data_Table</code> and <code>Link_Table</code>. The link table just contains two columns, the identity of an object record and an identity of a data record.</p>
<p>I want to copy the data from <code>DATA_TABLE</code> where it is linked to one given object identity and insert corresponding records into <code>Data_Table</code> and <code>Link_Table</code> for a different given object identity.</p>
<p>I <strong>can</strong> do this by selecting into a table variable and the looping through doing two inserts for each iteration.</p>
<p>Is this the best way to do it?</p>
<p><strong>Edit</strong> : I want to avoid a loop for two reason, the first is that I'm lazy and a loop/temp table requires more code, more code means more places to make a mistake and the second reason is a concern about performance.</p>
<p>I can copy all the data in one insert but how do get the link table to link to the new data records where each record has a new id?</p>
|
[
{
"answer_id": 175136,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 5,
"selected": false,
"text": "INSERT IDENTITY OUTPUT OUTPUT INTO"
},
{
"answer_id": 175138,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 8,
"selected": false,
"text": "BEGIN TRANSACTION\n DECLARE @DataID int;\n INSERT INTO DataTable (Column1 ...) VALUES (....);\n SELECT @DataID = scope_identity();\n INSERT INTO LinkTable VALUES (@ObjectID, @DataID);\nCOMMIT\n"
},
{
"answer_id": 175756,
"author": "tpower",
"author_id": 18107,
"author_profile": "https://Stackoverflow.com/users/18107",
"pm_score": 6,
"selected": true,
"text": "DECLARE @Object_Table TABLE\n(\n Id INT NOT NULL PRIMARY KEY\n)\n\nDECLARE @Link_Table TABLE\n(\n ObjectId INT NOT NULL,\n DataId INT NOT NULL\n)\n\nDECLARE @Data_Table TABLE\n(\n Id INT NOT NULL Identity(1,1),\n Data VARCHAR(50) NOT NULL\n)\n\n-- create two objects '1' and '2'\nINSERT INTO @Object_Table (Id) VALUES (1)\nINSERT INTO @Object_Table (Id) VALUES (2)\n\n-- create some data\nINSERT INTO @Data_Table (Data) VALUES ('Data One')\nINSERT INTO @Data_Table (Data) VALUES ('Data Two')\n\n-- link all data to first object\nINSERT INTO @Link_Table (ObjectId, DataId)\nSELECT Objects.Id, Data.Id\nFROM @Object_Table AS Objects, @Data_Table AS Data\nWHERE Objects.Id = 1\n -- now I want to copy the data from from object 1 to object 2 without looping\nINSERT INTO @Data_Table (Data)\nOUTPUT 2, INSERTED.Id INTO @Link_Table (ObjectId, DataId)\nSELECT Data.Data\nFROM @Data_Table AS Data INNER JOIN @Link_Table AS Link ON Data.Id = Link.DataId\n INNER JOIN @Object_Table AS Objects ON Link.ObjectId = Objects.Id \nWHERE Objects.Id = 1\n OUTPUT INTO"
},
{
"answer_id": 5507458,
"author": "Brion",
"author_id": 686671,
"author_profile": "https://Stackoverflow.com/users/686671",
"pm_score": -1,
"selected": false,
"text": "$qry = \"INSERT INTO table (one, two, three) VALUES('$one','$two','$three')\";\n\n$result = @mysql_query($qry);\n\n$qry2 = \"INSERT INTO table2 (one,two, three) VVALUES('$one','$two','$three')\";\n\n$result = @mysql_query($qry2);\n $qry = \"INSERT INTO table (one, two, three) VALUES('$one','$two','$three')\";\n\n\n $result = @mysql_query($qry);\n\n $qry2 = \"INSERT INTO table2 (two) VALUES('$two')\";\n\n $result = @mysql_query($qry2);\n \"$qry\"-number and number in @mysql_query($qry\"\")\n"
},
{
"answer_id": 30102560,
"author": "FakirPori",
"author_id": 4875185,
"author_profile": "https://Stackoverflow.com/users/4875185",
"pm_score": -1,
"selected": false,
"text": "-- ================================================\n-- Template generated from Template Explorer using:\n-- Create Procedure (New Menu).SQL\n--\n-- Use the Specify Values for Template Parameters \n-- command (Ctrl-Shift-M) to fill in the parameter \n-- values below.\n--\n-- This block of comments will not be included in\n-- the definition of the procedure.\n-- ================================================\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\n\nALTER PROCEDURE InsetIntoTwoTable\n\n(\n@name nvarchar(50),\n@Email nvarchar(50)\n)\n\nAS\nBEGIN\n\n SET NOCOUNT ON;\n\n\n insert into dbo.info(name) values (@name)\n insert into dbo.login(Email) values (@Email)\nEND\nGO\n"
},
{
"answer_id": 40353032,
"author": "Sergei Zinovyev",
"author_id": 5145258,
"author_profile": "https://Stackoverflow.com/users/5145258",
"pm_score": 4,
"selected": false,
"text": "SET XACT_ABORT ON;\n SET XACT_ABORT ON;\n\nBEGIN TRANSACTION\n DECLARE @DataID int;\n INSERT INTO DataTable (Column1 ...) VALUES (....);\n SELECT @DataID = scope_identity();\n INSERT INTO LinkTable VALUES (@ObjectID, @DataID);\nCOMMIT\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107/"
] |
175,091
|
<p>I'm trying to host a PHP web site that was given to me. I see this warning:</p>
<blockquote>
<p><strong>Warning:</strong> Unknown: Your script possibly
relies on a session side-effect which
existed until PHP 4.2.3. Please be
advised that the session extension
does not consider global variables as
a source of data, unless
register_globals is enabled. You can
disable this functionality and this
warning by setting
session.bug_compat_42 or
session.bug_compat_warn to off,
respectively. in <strong>Unknown</strong> on line <strong>0</strong></p>
</blockquote>
<p>What does this mean? How might I track down the source of this problem within the code?</p>
|
[
{
"answer_id": 175145,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 8,
"selected": true,
"text": "$_SESSION['var1'] = null;\n$var1 = 'something';\n ini_set('session.bug_compat_warn', 0);\nini_set('session.bug_compat_42', 0);\n"
},
{
"answer_id": 2262847,
"author": "Kzqai",
"author_id": 69993,
"author_profile": "https://Stackoverflow.com/users/69993",
"pm_score": 3,
"selected": false,
"text": "$_SESSION['firstname']=$_REQUEST['firstname'];\n //Start of script\n$_SESSION['bob'] = $bob;\n"
},
{
"answer_id": 10351371,
"author": "Praveen Kannan",
"author_id": 1361196,
"author_profile": "https://Stackoverflow.com/users/1361196",
"pm_score": 2,
"selected": false,
"text": "php_flag session.bug_compat_42 0\nphp_flag session.bug_compat_warn 0\n"
},
{
"answer_id": 10645071,
"author": "Ian",
"author_id": 755908,
"author_profile": "https://Stackoverflow.com/users/755908",
"pm_score": 3,
"selected": false,
"text": "$_SESSION[\"user\"]\n$user;\n $_SESSION[\"sessuser\"];\n"
},
{
"answer_id": 29036541,
"author": "TARA",
"author_id": 4370606,
"author_profile": "https://Stackoverflow.com/users/4370606",
"pm_score": 1,
"selected": false,
"text": "session.bug_compat_42 = off\nsession.bug_compat_warn = off\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175091",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
175,099
|
<p>Does anyone have a good algorithm for re-sorting an array of values (already pre-sorted) so that they can be displayed in multiple (N) columns and be read vertically? This would be implemented in .Net but I'd prefer something portable and not some magic function.</p>
<p>A good example of it working is the ASP.Net CheckBoxList control rendering as a table with the direction set to vertical. </p>
<p>Here's an example of the input and output:</p>
<p>Input: </p>
<p>Columns = 4<br>
Array = {"A", "B", "C", "D", "E", "F", "G"}</p>
<p>Output:</p>
<p>ACEG<br>
BDF</p>
<p>Thanks!</p>
<p><b>Updated (More Info):</b></p>
<p>I think I might have to give a little more information on what I'm trying to do... Mostly this problem came about from going from using a CheckBoxList's automatic binding (where you can specify the columns and direction to output and it would output a table of items in the correct order) to using jQuery/AJAX to create the checkbox grid. So I'm trying to duplicate that layout using css with div blocks with specified widths (inside a container div of a known width) so they wrap after N items (or columns.) This could also be rendered in a table (like how ASP.Net does it.) </p>
<p>Everything works great except the order is horizontal and when you get a large number of items in the list it's easier to read vertical columns.</p>
<p>If the array doesn't have enough items in it to make an even grid then it should output an empty spot in the correct row/column of the grid.</p>
<p>And if an array doesn't have enough items to make even a single row then just output the items in their original order in one row.</p>
<p>Some other input/ouput might be:</p>
<p>Columns = 3<br>
Array = {"A", "B", "C", "D"}</p>
<p>ACD<br>
B</p>
<p>Columns = 5<br>
Array = {"A", "B", "C", "D", "E", "F", "G", "H"}</p>
<p>ACEGH<br>
BDF</p>
<p>Columns = 5<br>
Array = {"A", "B", "C", "D"}</p>
<p>ABCD</p>
|
[
{
"answer_id": 175516,
"author": "Eric",
"author_id": 6367,
"author_profile": "https://Stackoverflow.com/users/6367",
"pm_score": 1,
"selected": false,
"text": "array<String^>^ sArray = {\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\"};\ndouble Columns = 4;\ndouble dRowCount = Convert::ToDouble(sArray->Length) / Columns;\nint rowCount = (int) Math::Ceiling(dRowCount);\nint i = 0;\nint shift = 0;\nint printed = 0;\nwhile (printed < sArray->Length){\n while (i < sArray->Length){\n if (i % rowCount == shift){\n Console::Write(sArray[i]);\n printed++;\n }\n i++;\n }\n Console::Write(\"\\n\");\n i = 0;\n shift++;\n}\n"
},
{
"answer_id": 175587,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 2,
"selected": false,
"text": "ACEG\nBDF\n OOOO\nOOO.\n OOO\nOO.\nOO.\nOO.\n ACEFG\nBD\n OOOOO\nOO...\n int Columns = 4;\nchar * Array[] = {\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\"};\n\nint main (\n int argc,\n char ** argv\n) {\n // This is hacky C for quickly get the number of entries\n // in a static array, where size is known at compile time\n int arraySize = sizeof(Array) / sizeof(Array[0]);\n\n // How many rows are we going to paint?\n int rowsToPaint = (arraySize / Columns) + 1;\n\n int col;\n int row;\n \n for (row = 0; row < rowsToPaint; row++) {\n for (col = 0; col < Columns; col++) {\n int index = col * rowsToPaint + row;\n \n if (index >= arraySize) {\n // Out of bounds\n continue;\n }\n\n printf(\"%s\", Array[index]);\n }\n printf(\"\\n\"); // next row\n }\n printf(\"\\n\");\n return 0;\n}\n ACEFG\nBD\n ADG\nBE\nCF\n AE\nBF\nCG\nD\n"
},
{
"answer_id": 177916,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 4,
"selected": true,
"text": "int Columns;\nchar * Array[] = {\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\"};\n\nint main (\n int argc,\n char ** argv\n) {\n // Lets thest this with all Column sizes from 1 to 7\n for (Columns = 1; Columns <= 7; Columns++) {\n\n printf(\"Output when Columns is set to %d\\n\", Columns);\n\n // This is hacky C for quickly get the number of entries\n // in a static array, where size is known at compile time\n int arraySize = sizeof(Array) / sizeof(Array[0]);\n\n // How many rows we will have\n int rows = arraySize / Columns;\n\n // Below code is the same as (arraySize % Columns != 0), but\n // it's almost always faster\n if (Columns * rows != arraySize) {\n // We might have lost one row by implicit rounding\n // performed for integer division\n rows++;\n }\n\n // Now we create a matrix large enough for rows * Columns\n // references. Note that this array could be larger than arraySize!\n char ** matrix = malloc(sizeof(char *) * rows * Columns);\n\n // Something you only need in C, C# and Java do this automatically:\n // Set all elements in the matrix to NULL(null) references\n memset(matrix, 0, sizeof(char *) * rows * Columns );\n\n // We fill up the matrix from top to bottom and then from\n // left to right; the order how we fill it up is very important\n int matrixX;\n int matrixY;\n int index = 0;\n for (matrixX = 0; matrixX < Columns; matrixX++) {\n for (matrixY = 0; matrixY < rows; matrixY++) {\n // In case we just have enough elements left to only\n // fill up the first row of the matrix and we are not\n // in this first row, do nothing.\n if (arraySize + matrixX + 1 - (index + Columns) == 0 &&\n matrixY != 0) {\n continue;\n }\n\n // We just copy the next element normally\n matrix[matrixY + matrixX * rows] = Array[index];\n index++;\n //arraySize--;\n }\n }\n\n // Print the matrix exactly like you'd expect a matrix to be\n // printed to screen, that is from left to right and top to bottom;\n // Note: That is not the order how we have written it,\n // watch the order of the for-loops!\n for (matrixY = 0; matrixY < rows; matrixY++) {\n for (matrixX = 0; matrixX < Columns; matrixX++) {\n // Skip over unset references\n if (matrix[matrixY + matrixX * rows] == NULL)\n continue;\n\n printf(\"%s\", matrix[matrixY + matrixX * rows]);\n }\n // Next row in output\n printf(\"\\n\");\n }\n printf(\"\\n\");\n\n // Free up unused memory\n free(matrix);\n } \n return 0;\n}\n Output when Columns is set to 1\nA\nB\nC\nD\nE\nF\nG\n\nOutput when Columns is set to 2\nAE\nBF\nCG\nD\n\nOutput when Columns is set to 3\nADG\nBE\nCF\n\nOutput when Columns is set to 4\nACEG\nBDF\n\nOutput when Columns is set to 5\nACEFG\nBD\n\nOutput when Columns is set to 6\nACDEFG\nB\n\nOutput when Columns is set to 7\nABCDEFG\n if (Columns <= 0) {\n // Having no column make no sense, we need at least one!\n Columns = 1;\n} else if (Columns > arraySize) {\n // We can't have more columns than elements in the array!\n Columns = arraySize;\n}\n char * Array[] = {\"A\", \"B\", \"C\", \"D\", \"E\", NULL, \"F\", \"G\", \"H\", \"I\"};\n ADFI\nBEG\nCH\n char hole = 0;\nchar * Array[] = {\"A\", \"B\", &hole, \"C\", \"D\", \"E\", &hole, \"F\", \"G\", \"H\", \"I\"};\n for (matrixY = 0; matrixY < rows; matrixY++) {\n for (matrixX = 0; matrixX < Columns; matrixX++) {\n // Skip over unset references\n if (matrix[matrixY + matrixX * rows] == NULL)\n continue;\n\n if (matrix[matrixY + matrixX * rows] == &hole) {\n printf(\" \");\n } else {\n printf(\"%s\", matrix[matrixY + matrixX * rows]);\n }\n }\n // Next row in output\n printf(\"\\n\");\n }\n printf(\"\\n\");\n Output when Columns is set to 2\nA \nBF\n G\nCH\nDI\nE\n\nOutput when Columns is set to 3\nADG\nBEH\n I\nCF\n\nOutput when Columns is set to 4\nAC H\nBDFI\n EG\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25549/"
] |
175,103
|
<p>I have a <a href="http://en.wikipedia.org/wiki/Uniform_resource_locator" rel="noreferrer">URL</a>, and I'm trying to match it to a regular expression to pull out some groups. The problem I'm having is that the URL can either end <em>or</em> continue with a "/" and more URL text. I'd like to match URLs like this:</p>
<ul>
<li><a href="http://server/xyz/2008-10-08-4" rel="noreferrer">http://server/xyz/2008-10-08-4</a></li>
<li><a href="http://server/xyz/2008-10-08-4/" rel="noreferrer">http://server/xyz/2008-10-08-4/</a></li>
<li><a href="http://server/xyz/2008-10-08-4/123/more" rel="noreferrer">http://server/xyz/2008-10-08-4/123/more</a></li>
</ul>
<p>But not match something like this:</p>
<ul>
<li><a href="http://server/xyz/2008-10-08-4-1" rel="noreferrer">http://server/xyz/2008-10-08-4-1</a></li>
</ul>
<p>So, I thought my best bet was something like this: </p>
<pre><code>/(.+)/(\d{4}-\d{2}-\d{2})-(\d+)[/$]
</code></pre>
<p>where the character class at the end contained either the "/" or the end-of-line. The character class doesn't seem to be happy with the "$" in there though. How can I best discriminate between these URLs while still pulling back the correct groups?</p>
|
[
{
"answer_id": 175141,
"author": "Adam Tegen",
"author_id": 4066,
"author_profile": "https://Stackoverflow.com/users/4066",
"pm_score": 7,
"selected": true,
"text": "/(.+)/(\\d{4}-\\d{2}-\\d{2})-(\\d+)(/.*)?$\n (.+) .+ + (\\d{4}-\\d{2}-\\d{2}) \\d{4} [0-9] {4} - - \\d{2} [0-9] {2} - - \\d{2} [0-9] {2} - - (\\d+) \\d+ [0-9] + (.*)? ? .* * $"
},
{
"answer_id": 175220,
"author": "Peter Boughton",
"author_id": 9360,
"author_profile": "https://Stackoverflow.com/users/9360",
"pm_score": 7,
"selected": false,
"text": "(/|\\z) /(\\S+?)/(\\d{4}-\\d{2}-\\d{2})-(\\d+)(/|\\z)\n \\S+? .*"
},
{
"answer_id": 176078,
"author": "Dave Sherohman",
"author_id": 18914,
"author_profile": "https://Stackoverflow.com/users/18914",
"pm_score": 6,
"selected": false,
"text": "$ ^ . / [/$] / $ / $"
},
{
"answer_id": 18995360,
"author": "Sparhawk",
"author_id": 1944384,
"author_profile": "https://Stackoverflow.com/users/1944384",
"pm_score": 5,
"selected": false,
"text": "$ /(\\S+?)/(\\d{4}-\\d{2}-\\d{2})-(\\d+)(/|$)\n $ \\z"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404/"
] |
175,109
|
<p>I'm doing some research into using log4net, and I found the <em>IObjectRenderer</em> interface interesting. It would allow us to control how types are logged and provide a different, possibly more user-friendly <code>ToString()</code> implementation. I just started looking at log4net though, and can't seem to find a logical way to programmatically set up the association between types and renderers.</p>
<p>I found that this can be set up in the XML configuration file by reading the <a href="http://logging.apache.org/log4net/release/manual/configuration.html#HC-13011608" rel="nofollow noreferrer">manual</a>, but it didn't give me any hints about programmatically adding these. It seems to me that you'd rather have a programmatic object renderer in some cases, so I'm curious how to do this.</p>
|
[
{
"answer_id": 175111,
"author": "OwenP",
"author_id": 2547,
"author_profile": "https://Stackoverflow.com/users/2547",
"pm_score": 4,
"selected": true,
"text": "using System.IO;\nusing log4net;\nusing log4net.Config;\nusing log4net.ObjectRenderer;\nusing log4net.Util;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n BasicConfigurator.Configure();\n\n ILog log = LogManager.GetLogger(typeof(Program));\n var repo = LogManager.GetRepository();\n repo.RendererMap.Put(typeof(Foo), new FooRenderer());\n\n var fooInstance = new Foo() { Name = \"Test Foo\" };\n log.Info(fooInstance);\n }\n }\n\n internal class Foo\n {\n public string Name { get; set; }\n }\n\n internal class FooRenderer : log4net.ObjectRenderer.IObjectRenderer\n {\n public void RenderObject(RendererMap rendererMap, object obj, TextWriter writer)\n {\n if (obj == null)\n {\n writer.Write(SystemInfo.NullText);\n }\n\n var fooInstance = obj as Foo;\n if (fooInstance != null)\n {\n writer.Write(\"\", fooInstance.Name);\n }\n else\n {\n writer.Write(SystemInfo.NullText);\n }\n }\n }\n}"
},
{
"answer_id": 11676271,
"author": "Axle",
"author_id": 1385801,
"author_profile": "https://Stackoverflow.com/users/1385801",
"pm_score": 2,
"selected": false,
"text": "<renderer renderingClass=\"ConsoleApplication1.FooRenderer\" renderedClass=\"ConsoleApplication1.Foo\" />\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2547/"
] |
175,115
|
<p>[edit]
So I used one of the javascript tooltips suggested below. I got the tips to show when you stop and hide if you move. The only problem is it works when I do this:</p>
<pre><code>document.onmousemove = (function() {
var onmousestop = function() {
Tip('Click to search here');
document.getElementById('MyDiv').onmousemove = function() {
UnTip();
};
}, thread;
return function() {
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
</code></pre>
<p>But I want the function to only apply to a specific div and if I change the first line to "document.getElementById('MyDiv').onmousemove = (function() {" I get a javascript error document.getElementById('MyDiv') is null What am I missing....??</p>
<p>[/edit]</p>
<p>I want to display a balloon style message when the users mouse stops on an element from more than say 1.5 seconds. And then if they move the mouse I would like to hide the balloon. I am trying to use some JavaScript code I found posted out in the wild. Here is the code I am using to detect when the mouse has stopped:</p>
<pre><code>document.onmousemove = (function() {
var onmousestop = function() {
//code to show the ballon
};
}, thread;
return function() {
clearTimeout(thread);
thread = setTimeout(onmousestop, 1500);
};
})();
</code></pre>
<p>So I have two questions. One, does anyone have a recommended lightweight javascript balloon that will display at the cursor location. And two, the detect mouse stopped code works ok but I am stumped on how to detect that the mouse has started moving again and hide the balloon. Thanks...</p>
|
[
{
"answer_id": 175188,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 1,
"selected": false,
"text": "document.onmousemove = (function() {\n if($('balloon').visible) {\n //mouse is moving again\n}....//your code follows\n"
},
{
"answer_id": 2381581,
"author": "Chauncey McAskill",
"author_id": 140357,
"author_profile": "https://Stackoverflow.com/users/140357",
"pm_score": 4,
"selected": true,
"text": "document.getElementById('MyDiv').onmousemove = (function() {\n var onmousestop = function() {\n Tip('Click to search here');\n }, thread;\n\n return function() {\n UnTip();\n clearTimeout(thread);\n thread = setTimeout(onmousestop, 1500);\n };\n})();\n $('div.video')[0].onmousemove = (function() {\n var onmousestop = function() {\n $('div.controls').fadeOut('fast');\n }, thread;\n\n return function() {\n $('div.controls').fadeIn('fast');\n clearTimeout(thread);\n thread = setTimeout(onmousestop, 1500);\n };\n})();\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5234/"
] |
175,116
|
<p>For obvious productivity reasons, I make an effort of learning and using as many of the keyboard shortcuts for the various Re# commands. </p>
<p>However, it seems that the unit test runner does not have any associated shortcut keys. I want to be able to select certain tests and be able to run or debug them without resorting to grabbing the mouse each time. Is using the mouse my only option?</p>
|
[
{
"answer_id": 870955,
"author": "Even Mien",
"author_id": 73794,
"author_profile": "https://Stackoverflow.com/users/73794",
"pm_score": 3,
"selected": false,
"text": "ReSharper.ReSharper_UnitTest_ContextDebug ReSharper.ReSharper_UnitTest_ContextProfile ReSharper.ReSharper_UnitTest_ContextRun ReSharper.ReSharper_UnitTest_RunSolution ReSharper.ReSharper_UnitTest_RunSolution"
},
{
"answer_id": 2423378,
"author": "Ray",
"author_id": 4872,
"author_profile": "https://Stackoverflow.com/users/4872",
"pm_score": 2,
"selected": false,
"text": "Spacebar Run Selected Tests Debug Selected Tests"
},
{
"answer_id": 19780309,
"author": "Robert Brooker",
"author_id": 654654,
"author_profile": "https://Stackoverflow.com/users/654654",
"pm_score": 2,
"selected": false,
"text": "Resharper > Unit Tests\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
175,131
|
<p>I am currently working on a project that will store specific financial information about our clients in a MS SQL database. Later, our users need to be able to query the database to return data from the clients based on certain criteria (eg. clients bigger then a certain size, clients in a certain geographical location) and total it to use as a benchmark. The database will be accessed by our financial software using a script.</p>
<p>I am currently writing the stored procedures for the database. What I am planning on doing is writing several different stored procedures based on the different types of criteria that can be used. They will return the client numbers.</p>
<p>The actual question I have is on the method of retrieving the data. I need to do several different calculations with the clients data. Is it better practice to have different stored procedures to do the calculation based on the client number and return the result or is it better to just have a stored procedure return all the information about the client and perform the calculations in the script?</p>
<p>Performance could be an issue because there will be a lot of clients in the database so I want the method to be reasonably efficient.</p>
|
[
{
"answer_id": 12914876,
"author": "Jom George",
"author_id": 1053355,
"author_profile": "https://Stackoverflow.com/users/1053355",
"pm_score": -1,
"selected": false,
"text": "Declare @SUMAmount decimal(12,3) \n Select @SUMAmount= SUM(ISNULL(@A,0)+ISNULL(@B,0)+ISNULL(@C,0)+ISNULL(@D,0))\n\nSelect @SUMAmount= SUM((ISNULL(@A,0)+ISNULL(@B,0))*(ISNULL(@C,0)-ISNULL(@D,0)))\n Select A,B,SUM(C),D From TableName\nWhere SUM(C)>0\nGroup By A,B,D\n Declare @TotalNoofDays int\n @TotalNoofDays = DATEDIFF(d, fromdate, todate) \n if @DueAmount >=0\nBEGIN\nIF @DiscountFlag = 1\nBEGIN\nSET @DueIntAmount = 0\nEND\nELSE\n BEGIN\n SET @DueIntAmount = ((@DueAmount*(@IntRateOnDue/100))/365)*@NoofDays\n END\n SET @ExcessInterestAmount = 0\nEND\nELSE\nBEGIN\nSET @DueIntAmount = 0\nSET @ExcessInterestAmount = ((@DueAmount*(@IntRateOnDeposit/100))/365)*@NoofDays\n END\n Create Proc NewLearningProcedure\n (\n @Name Varchar(50),\n @Date DateTime\n )\n AS\n Begin\n\nDeclare @Temp Table\n(\n ID int Identity(1,1),\n Name Varchar(50),\n Date DateTime\n)\n\nInsert Into @Temp\nSelect @Name,@Date\n\nDeclare @i int\nset @i=10\n\nWhile @i>0\nBegin\n Insert Into @Temp\n Select @Name+CAST(@i as varchar(50)),@Date\n\n Set @i=@i-1\n End\n\n\n Select * from @Temp\n\n\n End\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13846/"
] |
175,153
|
<p>I am using SimpleTest, a PHP-based unit testing framework. I am testing new code that will handle storing and retrieving website comments from a database. I am at a loss for how to structure the project to test the database access code.</p>
<p>I am looking for any suggestions as to best practices for testing db code in a PHP application. Examples are really great. Sites for further reading are great.</p>
<p>Thank you kindly. :)</p>
|
[
{
"answer_id": 175177,
"author": "Jason Cohen",
"author_id": 4926,
"author_profile": "https://Stackoverflow.com/users/4926",
"pm_score": 1,
"selected": false,
"text": "TRUNCATE"
},
{
"answer_id": 189107,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": 0,
"selected": false,
"text": "setUp tearDown"
},
{
"answer_id": 9549590,
"author": "colin",
"author_id": 1247299,
"author_profile": "https://Stackoverflow.com/users/1247299",
"pm_score": 2,
"selected": false,
"text": "tests/etc/schemas/table.sql Test_DbCase loadTables('foo', 'bar') foo.sql bar.sql table.sql"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175153",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3238/"
] |
175,170
|
<p>What function can I use in Excel VBA to slice an array?</p>
|
[
{
"answer_id": 175178,
"author": "Lance Roberts",
"author_id": 13295,
"author_profile": "https://Stackoverflow.com/users/13295",
"pm_score": 7,
"selected": true,
"text": "WorksheetFunction.Index array Public Function GetArraySlice2D(Sarray As Variant, Stype As String, Sindex As Integer, Sstart As Integer, Sfinish As Integer) As Variant\n\n' this function returns a slice of an array, Stype is either row or column\n' Sstart is beginning of slice, Sfinish is end of slice (Sfinish = 0 means entire\n' row or column is taken), Sindex is the row or column to be sliced\n' (NOTE: 1 is always the first row or first column)\n' an Sindex value of 0 means that the array is one dimensional 3/20/09 ljr\n\nDim vtemp() As Variant\nDim i As Integer\n\nOn Err GoTo ErrHandler\n\nSelect Case Sindex\n Case 0\n If Sfinish - Sstart = UBound(Sarray) - LBound(Sarray) Then\n vtemp = Sarray\n Else\n ReDim vtemp(1 To Sfinish - Sstart + 1)\n For i = 1 To Sfinish - Sstart + 1\n vtemp(i) = Sarray(i + Sstart - 1)\n Next i\n End If\n Case Else\n Select Case Stype\n Case \"row\"\n If Sfinish = 0 Or (Sstart = LBound(Sarray, 2) And Sfinish = UBound(Sarray, 2)) Then\n vtemp = Application.WorksheetFunction.Index(Sarray, Sindex, 0)\n Else\n ReDim vtemp(1 To Sfinish - Sstart + 1)\n For i = 1 To Sfinish - Sstart + 1\n vtemp(i) = Sarray(Sindex, i + Sstart - 1)\n Next i\n End If\n Case \"column\"\n If Sfinish = 0 Or (Sstart = LBound(Sarray, 1) And Sfinish = UBound(Sarray, 1)) Then\n vtemp = Application.WorksheetFunction.Index(Sarray, 0, Sindex)\n Else\n ReDim vtemp(1 To Sfinish - Sstart + 1)\n For i = 1 To Sfinish - Sstart + 1\n vtemp(i) = Sarray(i + Sstart - 1, Sindex)\n Next i\n End If\n End Select\nEnd Select\nGetArraySlice2D = vtemp\nExit Function\n\nErrHandler:\n Dim M As Integer\n M = MsgBox(\"Bad Array Input\", vbOKOnly, \"GetArraySlice2D\")\n\nEnd Function\n"
},
{
"answer_id": 175291,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 1,
"selected": false,
"text": "Set rng = Range(\"A1:E3\")\n Set rngSubset = rng.Rows(2).Offset(0, rng.Columns.Count - 3).Resize(1, 3)\n"
},
{
"answer_id": 937942,
"author": "Oorang",
"author_id": 102270,
"author_profile": "https://Stackoverflow.com/users/102270",
"pm_score": 3,
"selected": false,
"text": "Sub Test()\n 'All example return a 1 based 2D array.\n Dim myArr As Variant 'This var must be generic to work.\n 'Get whole range:\n myArr = ActiveSheet.UsedRange\n 'Get just column 1:\n myArr = WorksheetFunction.Index(ActiveSheet.UsedRange, 0, 1)\n 'Get just row 5\n myArr = WorksheetFunction.Index(ActiveSheet.UsedRange, 5, 0)\nEnd Sub\n"
},
{
"answer_id": 7504904,
"author": "BitCoinBetter",
"author_id": 805317,
"author_profile": "https://Stackoverflow.com/users/805317",
"pm_score": 2,
"selected": false,
"text": "Public Function GetSubTable(vIn As Variant, Optional ByVal iStartRow As Integer, Optional ByVal iStartCol As Integer, Optional ByVal iHeight As Integer, Optional ByVal iWidth As Integer) As Variant\n Dim vReturn As Variant\n Dim iInRowLower As Integer\n Dim iInRowUpper As Integer\n Dim iInColLower As Integer\n Dim iInColUpper As Integer\n Dim iEndRow As Integer\n Dim iEndCol As Integer\n Dim iRow As Integer\n Dim iCol As Integer\n\n iInRowLower = LBound(vIn, 1)\n iInRowUpper = UBound(vIn, 1)\n iInColLower = LBound(vIn, 2)\n iInColUpper = UBound(vIn, 2)\n\n If iStartRow = 0 Then\n iStartRow = iInRowLower\n End If\n If iStartCol = 0 Then\n iStartCol = iInColLower\n End If\n\n If iHeight = 0 Then\n iHeight = iInRowUpper - iStartRow + 1\n End If\n If iWidth = 0 Then\n iWidth = iInColUpper - iStartCol + 1\n End If\n\n iEndRow = iStartRow + iHeight - 1\n iEndCol = iStartCol + iWidth - 1\n\n ReDim vReturn(1 To iEndRow - iStartRow + 1, 1 To iEndCol - iStartCol + 1)\n\n For iRow = iStartRow To iEndRow\n For iCol = iStartCol To iEndCol\n vReturn(iRow - iStartRow + 1, iCol - iStartCol + 1) = vIn(iRow, iCol)\n Next\n Next\n\n GetSubTable = vReturn\nEnd Function\n"
},
{
"answer_id": 24843721,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "Option Explicit\n\n#If Win64 Then\n Public Const PTR_LENGTH As Long = 8\n Public Declare PtrSafe Function GetTickCount Lib \"kernel32\" () As Long\n Public Declare PtrSafe Sub Mem_Copy Lib \"kernel32\" Alias \"RtlMoveMemory\" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)\n Private Declare PtrSafe Function VarPtrArray Lib \"VBE7\" Alias \"VarPtr\" (ByRef Var() As Any) As LongPtr\n Private Declare PtrSafe Sub CopyMemory Lib \"kernel32\" Alias \"RtlMoveMemory\" (Destination As Any, Source As Any, ByVal Length As Long)\n Private Declare PtrSafe Sub FillMemory Lib \"kernel32\" Alias \"RtlFillMemory\" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte)\n#Else\n Public Const PTR_LENGTH As Long = 4\n Public Declare Function GetTickCount Lib \"kernel32\" () As Long\n Public Declare Sub Mem_Copy Lib \"kernel32\" Alias \"RtlMoveMemory\" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)\n Private Declare Function VarPtrArray Lib \"VBE7\" Alias \"VarPtr\" (ByRef Var() As Any) As LongPtr\n Private Declare Sub CopyMemory Lib \"kernel32\" Alias \"RtlMoveMemory\" (Destination As Any, Source As Any, ByVal Length As Long)\n Private Declare Sub FillMemory Lib \"kernel32\" Alias \"RtlFillMemory\" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte)\n#End If\n\nPrivate Type SAFEARRAYBOUND\n cElements As Long\n lLbound As Long\nEnd Type\n\nPrivate Type SAFEARRAY_VECTOR\n cDims As Integer\n fFeatures As Integer\n cbElements As Long\n cLocks As Long\n pvData As LongPtr\n rgsabound(0) As SAFEARRAYBOUND\nEnd Type\n\nSub SliceColumn(ByVal idx As Long, ByRef arrayToSlice() As Variant, ByRef slicedArray As Variant)\n'slicedArray can be passed as a 1d or 2d array\n'sliceArray can also be part bound, eg slicedArray(1 to 100) or slicedArray(10 to 100)\nDim ptrToArrayVar As LongPtr\nDim ptrToSafeArray As LongPtr\nDim ptrToArrayData As LongPtr\nDim ptrToArrayData2 As LongPtr\nDim uSAFEARRAY As SAFEARRAY_VECTOR\nDim ptrCursor As LongPtr\nDim cbElements As Long\nDim atsBound1 As Long\nDim elSize As Long\n\n 'determine bound1 of source array (ie row Count)\n atsBound1 = UBound(arrayToSlice, 1)\n 'get pointer to source array Safearray\n ptrToArrayVar = VarPtrArray(arrayToSlice)\n CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH\n CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)\n ptrToArrayData = uSAFEARRAY.pvData\n 'determine byte size of source elements\n cbElements = uSAFEARRAY.cbElements\n\n 'get pointer to destination array Safearray\n ptrToArrayVar = VarPtr(slicedArray) + 8 'Variant reserves first 8bytes\n CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH\n CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)\n ptrToArrayData2 = uSAFEARRAY.pvData\n\n 'determine elements size\n elSize = UBound(slicedArray, 1) - LBound(slicedArray, 1) + 1\n 'determine start position of data in source array\n ptrCursor = ptrToArrayData + (((idx - 1) * atsBound1 + LBound(slicedArray, 1) - 1) * cbElements)\n 'Copy source array to destination array\n CopyMemory ByVal ptrToArrayData2, ByVal ptrCursor, cbElements * elSize\n\nEnd Sub\n\nSub SliceRow(ByVal idx As Long, ByRef arrayToSlice() As Variant, ByRef slicedArray As Variant)\n'slicedArray can be passed as a 1d or 2d array\n'sliceArray can also be part bound, eg slicedArray(1 to 100) or slicedArray(10 to 100)\nDim ptrToArrayVar As LongPtr\nDim ptrToSafeArray As LongPtr\nDim ptrToArrayData As LongPtr\nDim ptrToArrayData2 As LongPtr\nDim uSAFEARRAY As SAFEARRAY_VECTOR\nDim ptrCursor As LongPtr\nDim cbElements As Long\nDim atsBound1 As Long\nDim i As Long\n\n 'determine bound1 of source array (ie row Count)\n atsBound1 = UBound(arrayToSlice, 1)\n 'get pointer to source array Safearray\n ptrToArrayVar = VarPtrArray(arrayToSlice)\n CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH\n CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)\n ptrToArrayData = uSAFEARRAY.pvData\n 'determine byte size of source elements\n cbElements = uSAFEARRAY.cbElements\n\n 'get pointer to destination array Safearray\n ptrToArrayVar = VarPtr(slicedArray) + 8 'Variant reserves first 8bytes\n CopyMemory ptrToSafeArray, ByVal ptrToArrayVar, PTR_LENGTH\n CopyMemory uSAFEARRAY, ByVal ptrToSafeArray, LenB(uSAFEARRAY)\n ptrToArrayData2 = uSAFEARRAY.pvData\n\n ptrCursor = ptrToArrayData + ((idx - 1) * cbElements)\n For i = LBound(slicedArray, 1) To UBound(slicedArray, 1)\n\n CopyMemory ByVal ptrToArrayData2, ByVal ptrCursor, cbElements\n ptrCursor = ptrCursor + (cbElements * atsBound1)\n ptrToArrayData2 = ptrToArrayData2 + cbElements\n Next i\n\nEnd Sub\n Sub exampleUsage()\nDim sourceArr() As Variant\nDim destArr As Variant\nDim sliceIndex As Long\n\n On Error GoTo Err:\n\n sourceArr = Sheet1.Range(\"A1:D10000\").Value2\n sliceIndex = 2 'Slice column 2 / slice row 2\n\n 'Build target array\n ReDim destArr(20 To 10000) '1D array from row 20 to 10000\n' ReDim destArr(1 To 10000) '1D array from row 1 to 10000\n' ReDim destArr(20 To 10000, 1 To 1) '2D array from row 20 to 10000\n' ReDim destArr(1 To 10000, 1 To 1) '2D array from row 1 to 10000\n\n 'Slice Column\n SliceColumn sliceIndex, sourceArr, destArr\n\n 'Slice Row\n ReDim destArr(1 To 4)\n SliceRow sliceIndex, sourceArr, destArr\n\nErr:\n 'Tidy Up See ' http://stackoverflow.com/questions/16323776/copy-an-array-reference-in-vba/16343887#16343887\n FillMemory destArr, 16, 0\n\nEnd Sub\n Sub timeMethods()\nConst trials As Long = 10\nConst rowsToCopy As Long = 1048576\nDim rng As Range\nDim Arr() As Variant\nDim newArr As Variant\nDim newArr2 As Variant\nDim t As Long, t1 As Long, t2 As Long, t3 As Long\nDim i As Long\n\n On Error GoTo Err\n\n 'Setup Conditions 1time only\n Sheet1.Cells.Clear\n Sheet1.Range(\"A1:D1\").Value = Split(\"A1,B1,C1,D1\", \",\") 'Strings\n' Sheet1.Range(\"A1:D1\").Value = Split(\"1,1,1,1\", \",\") 'Longs\n Sheet1.Range(\"A1:D1\").AutoFill Destination:=Sheet1.Range(\"A1:D\" & rowsToCopy), Type:=xlFillDefault\n\n 'Build source data\n Arr = Sheet1.Range(\"A1:D\" & rowsToCopy).Value\n Set rng = Sheet1.Range(\"A1:D\" & rowsToCopy)\n\n 'Build target container\n ReDim newArr(1 To rowsToCopy)\n Debug.Print \"Trials=\" & trials & \" Rows=\" & rowsToCopy\n 'Range\n t3 = 0\n For t = 1 To trials\n t1 = GetTickCount\n\n For i = LBound(newArr, 1) To UBound(newArr, 1)\n newArr(i) = rng(i, 2).Value2\n Next i\n\n t2 = GetTickCount\n t3 = t3 + (t2 - t1)\n Debug.Print \"Range: \" & t2 - t1\n Next t\n Debug.Print \"Range Avg ms: \" & t3 / trials\n\n 'Array\n t3 = 0\n For t = 1 To trials\n t1 = GetTickCount\n\n For i = LBound(newArr, 1) To UBound(newArr, 1)\n newArr(i) = Arr(i, 2)\n Next i\n\n t2 = GetTickCount\n t3 = t3 + (t2 - t1)\n Debug.Print \"Array: \" & t2 - t1\n Next t\n Debug.Print \"Array Avg ms: \" & t3 / trials\n\n 'Index\n t3 = 0\n For t = 1 To trials\n t1 = GetTickCount\n\n newArr2 = WorksheetFunction.Index(rng, 0, 2) 'newArr2 2d\n\n t2 = GetTickCount\n t3 = t3 + (t2 - t1)\n Debug.Print \"Index: \" & t2 - t1\n Next t\n Debug.Print \"Index Avg ms: \" & t3 / trials\n\n 'CopyMemBlock\n t3 = 0\n For t = 1 To trials\n t1 = GetTickCount\n\n SliceColumn 2, Arr, newArr\n\n t2 = GetTickCount\n t3 = t3 + (t2 - t1)\n Debug.Print \"CopyMem: \" & t2 - t1\n Next t\n Debug.Print \"CopyMem Avg ms: \" & t3 / trials\n\nErr:\n 'Tidy Up\n FillMemory newArr, 16, 0\n\n\nEnd Sub\n"
},
{
"answer_id": 33946145,
"author": "Vikas Gautam",
"author_id": 4850220,
"author_profile": "https://Stackoverflow.com/users/4850220",
"pm_score": 2,
"selected": false,
"text": "Function slice(ByVal arr, ByVal f, ByVal t)\n slice = Application.Index(arr, Evaluate(\"Transpose(Row(\" & f + 1 & \":\" & t + 1 & \"))\"))\nEnd Function\n"
},
{
"answer_id": 34549942,
"author": "Ben",
"author_id": 2146894,
"author_profile": "https://Stackoverflow.com/users/2146894",
"pm_score": 2,
"selected": false,
"text": "Function Subset2D(arr As Variant, Optional rowStart As Long = 1, Optional rowStop As Long = -1, Optional colIndices As Variant) As Variant\n 'Subset a 2d array (arr)\n 'If rowStop = -1, all rows are returned\n 'colIndices can be provided as a variant array like Array(1,3)\n 'if colIndices is not provided, all columns are returned\n\n Dim newarr() As Variant, newRows As Long, newCols As Long, i As Long, k As Long, refCol As Long\n\n 'Set the correct rowStop\n If rowStop = -1 Then rowStop = UBound(arr, 1)\n\n 'Set the colIndices if they were not provided\n If IsMissing(colIndices) Then\n ReDim colIndices(1 To UBound(arr, 2))\n For k = 1 To UBound(arr, 2)\n colIndices(k) = k\n Next k\n End If\n\n 'Get the dimensions of newarr\n newRows = rowStop - rowStart + 1\n newCols = UBound(colIndices) + 1\n ReDim newarr(1 To newRows, 1 To newCols)\n\n 'Loop through each empty element of newarr and set its value\n For k = 1 To UBound(newarr, 2) 'Loop through each column\n refCol = colIndices(k - 1) 'Get the corresponding reference column\n For i = 1 To UBound(newarr, 1) 'Loop through each row\n newarr(i, k) = arr(i + rowStart - 1, refCol) 'Set the value\n Next i\n Next k\n\n Subset2D = newarr\nEnd Function\n"
},
{
"answer_id": 50069592,
"author": "Paulo Buchsbaum",
"author_id": 1062727,
"author_profile": "https://Stackoverflow.com/users/1062727",
"pm_score": 1,
"selected": false,
"text": "slice '*************************************************************\n'* Fill(N1,N2)\n'* Create 1 dimension array with values from N1 to N2 step 1\n'*************************************************************\nFunction Fill(N1 As Long, N2 As Long) As Variant\n Dim Arr As Variant\n If N2 < N1 Then\n Fill = False\n Exit Function\n End If\n Fill = WorksheetFunction.Transpose(Evaluate(\"Row(\" & N1 & \":\" & N2 & \")\"))\nEnd Function\n\n'**********************************************************************\n'* Slice(AArray, [N1,N2])\n'* Slice an array between indices N1 to N2\n'***********************************************************************\nFunction Slice(VArray As Variant, Optional N1 As Long = 1, Optional N2 As Long = 0) As Variant\n Dim Indices As Variant\n If N2 = 0 Then N2 = UBound(VArray)\n If N1 = LBound(VArray) And N2 = UBound(VArray) Then\n Slice = VArray\n Else\n Indices = Fill(N1, N2)\n Slice = WorksheetFunction.Index(VArray, 1, Indices)\n End If\nEnd Function\n Var V As Variant\nV = Fill(100,109)\nPrintArr(Slice(V,3,5))\n\n'************************************************\n'* PrintArr(VArr)\n'* Print the array VARR\n'**************************************************\nFunction PrintArr(VArray As Variant)\n Dim S As String\n S = Join(VArray, \", \")\n MsgBox (S)\nEnd Function\n 102, 103, 104 \n"
},
{
"answer_id": 66672108,
"author": "iDevlop",
"author_id": 78522,
"author_profile": "https://Stackoverflow.com/users/78522",
"pm_score": 2,
"selected": false,
"text": "Sub test()\n Dim ar1\n Dim a As Object: Set a = Application\n\n ar1 = a.Transpose(a.Transpose(a.Index(Range(\"A1:C3\"), 2, 0))) 'get 2d row\n Debug.Print Join(ar1, \"|\")\nEnd Sub\n"
},
{
"answer_id": 73693895,
"author": "jzinna",
"author_id": 6889133,
"author_profile": "https://Stackoverflow.com/users/6889133",
"pm_score": 1,
"selected": false,
"text": "Dim slice(1) as Variant\n\nFor i = 0 To 1\n slice(i) = fullArray( i + 1)\nNext\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13295/"
] |
175,186
|
<p>Let's say I have this type in my application:</p>
<pre><code>public class A {
public int id;
public B b;
public boolean equals(Object another) { return this.id == ((A)another).id; }
public int hashCode() { return 31 * id; //nice prime number }
}
</code></pre>
<p>and a <code>Set<code><A</code>></code> structure. Now, I have an object of type <code>A</code> and want to do the following:</p>
<ul>
<li>If my <code>A</code> is within the set, update its field <code>b</code> to match my object.</li>
<li>Else, add it to the set.</li>
</ul>
<p>So checking if it is in there is easy enough (<code>contains</code>), and adding to the set is easy too. My question is this: how do I get a handle to update the object within? Interface <code>Set</code> doesn't have a <code>get</code> method, and the best I could think of was to remove the object in the set and add mine. another, even worse, alternative is to traverse the set with an iterator to try and locate the object.</p>
<p>I'll gladly take better suggestions... This includes the efficient use of other data structures.</p>
<p>Yuval =8-)</p>
<p><strong>EDIT</strong>: Thank you all for answering... Unfortunately I can't 'accept' the best answers here, those that suggest using a <code>Map</code>, because changing the type of the collection radically for this purpose only would be a little extreme (this collection is already mapped through Hibernate...)</p>
|
[
{
"answer_id": 175211,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 5,
"selected": false,
"text": "equals hashCode"
},
{
"answer_id": 175212,
"author": "Jason Cohen",
"author_id": 4926,
"author_profile": "https://Stackoverflow.com/users/4926",
"pm_score": 4,
"selected": false,
"text": "Map<Integer,A> Set<A> A A a = ...;\nMap<Integer,A> map = new HashMap<Integer,A>();\nmap.put( a.id, a );\n public static void update( Map<Integer,A> map, A obj ) {\n A existing = map.get( obj.id );\n if ( existing == null )\n map.put( obj.id, obj );\n else\n existing.b = obj.b;\n}\n A Map<Integer,B> Map<Integer,B> map = new HashMap<Integer,B>();\n// The insert-or-update is just this:\nmap.put( id, b );\n"
},
{
"answer_id": 175317,
"author": "extraneon",
"author_id": 24582,
"author_profile": "https://Stackoverflow.com/users/24582",
"pm_score": 0,
"selected": false,
"text": "public class A {\n public int id;\n public B b;\n public int hashCode() {return id;} // simple and efficient enough for small Sets \n public boolean equals(Object another) { \n if (object == null || ! (object instanceOf A) ) {\n return false;\n }\n return this.id == ((A)another).id; \n }\n}\npublic class Logic {\n /**\n * Replace the element in data with the same id as element, or add element\n * to data when the id of element is not yet used by any A in data. \n */\n public void update(Set<A> data, A element) {\n data.remove(element); // Safe even if the element is not in the Set\n data.add(element); \n }\n}\n"
},
{
"answer_id": 175533,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<A,A"
},
{
"answer_id": 175648,
"author": "Josh",
"author_id": 2204759,
"author_profile": "https://Stackoverflow.com/users/2204759",
"pm_score": 0,
"selected": false,
"text": "class ASet {\n private Map<Integer, A> map;\n public ASet() {\n map = new HashMap<Integer, A>();\n }\n\n public A updateOrAdd(Integer id, int delta) {\n A a = map.get(a);\n if(a == null) {\n a = new A(id);\n map.put(id,a);\n }\n a.setX(a.getX() + delta);\n }\n}\n"
},
{
"answer_id": 175686,
"author": "18Rabbit",
"author_id": 12662,
"author_profile": "https://Stackoverflow.com/users/12662",
"pm_score": 4,
"selected": false,
"text": "set.remove(a);\nset.add(a);\n if (set.contains(A))"
},
{
"answer_id": 177139,
"author": "Kevin Day",
"author_id": 10973,
"author_profile": "https://Stackoverflow.com/users/10973",
"pm_score": 3,
"selected": false,
"text": "hashCode equals equals hashCode equals hashCode"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2819/"
] |
175,205
|
<p>Consider the following code:</p>
<pre><code>$("a").attr("disabled", "disabled");
</code></pre>
<p>In IE and FF, this will make anchors unclickable, but in WebKit based browsers (Google Chrome and Safari) this does nothing. The nice thing about the disabled attribute is that it is easily removed and does not effect the href and onclick attributes.</p>
<p>Do you have any suggestions on how to get the desired result. Answers must be:</p>
<ul>
<li>Easily be revertable, since I want to disable form input controls while I have an AJAX call running.</li>
<li>Must work in IE, FF, and WebKit</li>
</ul>
|
[
{
"answer_id": 175221,
"author": "Neall",
"author_id": 619,
"author_profile": "https://Stackoverflow.com/users/619",
"pm_score": 4,
"selected": true,
"text": "$(\"a\").click(function(event){\n if (this.disabled) {\n event.preventDefault();\n } else {\n // make your AJAX call or whatever else you want\n }\n});\n a[disabled=disabled] { cursor: wait; }\n"
},
{
"answer_id": 15128693,
"author": "hernant",
"author_id": 722778,
"author_profile": "https://Stackoverflow.com/users/722778",
"pm_score": 2,
"selected": false,
"text": "$('a').each(function () {\n $(this).click(function (e) {\n if ($(this).attr('disabled')) {\n e.preventDefault();\n e.stopImmediatePropagation();\n }\n });\n var events = $._data ? $._data(this, 'events') : $(this).data('events');\n events.click.splice(0, 0, events.click.pop());\n});\n a[disabled] {\n color: gray;\n text-decoration: none;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175205",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19704/"
] |
175,228
|
<p>Is it ever appropriate to abandon the "getMyValue()" and "setMyValue()" pattern of getters and setters if alternative function names make the API more obvious?</p>
<p>For example, imagine I have this class in C++:</p>
<pre><code>
public class SomeClass {
private:
bool mIsVisible;
public:
void draw();
void erase();
}
</code></pre>
<p>I could add functions to get/set "mIsVisible" like this:</p>
<p><pre><code>
bool getVisible() { return mIsVisible; };</p>
<p>void setVisible(bool visible) {
if (!mIsVisible && visible) {
draw();
} else if (mIsVisible && !visible) {
erase();
}</p>
<pre><code>mIsVisible = visible;
</code></pre>
<p>}
</pre></code></p>
<p>However, it would be equally possible to use the following methods instead:</p>
<pre><code>
bool isVisible() { return mIsVisible; };
void show() {
if (!mIsVisible) {
mIsVisible = true;
draw();
}
}
void hide() {
if (mIsVisible) {
mIsVisible = false;
erase();
}
}
</code></pre>
<p>In brief, is it better to have a single "setVisible(bool)" method, or a pair of "show()" and "hide()" methods? Is there a convention, or is it purely a subjective thing?</p>
|
[
{
"answer_id": 175233,
"author": "Adam Bellaire",
"author_id": 21632,
"author_profile": "https://Stackoverflow.com/users/21632",
"pm_score": 3,
"selected": false,
"text": "show() hide() skinPigment tanMe() makeAlbino()"
},
{
"answer_id": 175467,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "if (shouldBeShowingAccordingToBusinessLogic()) w.show();\nelse w.hide();\n w.showIfAndOnlyIf(shouldBeShowingAccordingToBusinessLogic())\n w.setPostponedVisibility(shouldBeShowingAccordingToBusinessLogic());\n...\nw.realizeVisibility();\n"
},
{
"answer_id": 175469,
"author": "andreas buykx",
"author_id": 19863,
"author_profile": "https://Stackoverflow.com/users/19863",
"pm_score": 0,
"selected": false,
"text": "setVisible SomeClass"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2289/"
] |
175,240
|
<p>I use a 3rd party tool that outputs a file in Unicode format. However, I prefer it to be in ASCII. The tool does not have settings to change the file format.</p>
<p>What is the best way to convert the entire file format using Python?</p>
|
[
{
"answer_id": 175258,
"author": "Pete Karl II",
"author_id": 22491,
"author_profile": "https://Stackoverflow.com/users/22491",
"pm_score": 4,
"selected": false,
"text": "> >>> unicode('hello') u'hello'\n> >>> unicode('hello', 'ascii') u'hello'\n> >>> unicode('hello', 'iso-8859-1') u'hello'\n> >>>\n > >>> a = unicode('André','latin-1')\n> >>> a u'Andr\\202'\n"
},
{
"answer_id": 175260,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 2,
"selected": false,
"text": "uc = open(filename).read().decode('utf8')\nascii = uc.decode('ascii')\n UnicodeDecodeError"
},
{
"answer_id": 175270,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 6,
"selected": true,
"text": "unicode unicodedata >>> title = u\"Klüft skräms inför på fédéral électoral große\"\n Klft skrms infr p fdral lectoral groe\n unicodedata >>> import unicodedata\n>>> unicodedata.normalize('NFKD', title).encode('ascii','ignore')\n'Kluft skrams infor pa federal electoral groe'\n"
},
{
"answer_id": 175286,
"author": "giltay",
"author_id": 21106,
"author_profile": "https://Stackoverflow.com/users/21106",
"pm_score": 2,
"selected": false,
"text": "input_codec = 'UTF-16'\noutput_codec = 'ASCII'\n\nunicode_file = open('filename')\nunicode_data = unicode_file.read().decode(input_codec)\nascii_file = open('new filename', 'w')\nascii_file.write(unicode_data.write(unicode_data.encode(output_codec)))\n ascii_file.write(unicode_data.write(unicode_data.encode(output_codec, 'replace')))\n"
},
{
"answer_id": 176044,
"author": "Jerry Hill",
"author_id": 12773,
"author_profile": "https://Stackoverflow.com/users/12773",
"pm_score": 0,
"selected": false,
"text": "in_file = open(\"myfile.txt\", \"rb\")\nout_file = open(\"mynewfile.txt\", \"wb\")\n\nin_byte_string = in_file.read()\nunicode_string = bytestring.decode('UTF-16')\nout_byte_string = unicode_string.encode('ASCII')\n\nout_file.write(out_byte_string)\nout_file.close()\n"
},
{
"answer_id": 1906165,
"author": "mikemaccana",
"author_id": 123671,
"author_profile": "https://Stackoverflow.com/users/123671",
"pm_score": 0,
"selected": false,
"text": "mystring = u'bar'\ntype(mystring)\n <type 'unicode'>\n\nmyasciistring = (mystring.encode('ASCII'))\ntype(myasciistring)\n <type 'str'>\n"
},
{
"answer_id": 6312083,
"author": "Vijay",
"author_id": 684799,
"author_profile": "https://Stackoverflow.com/users/684799",
"pm_score": 2,
"selected": false,
"text": " import unicodedata\n input = open(filename).read().decode('UTF-16')\n output = unicodedata.normalize('NFKD', input).encode('ASCII', 'ignore')\n"
},
{
"answer_id": 8543825,
"author": "kev",
"author_id": 348785,
"author_profile": "https://Stackoverflow.com/users/348785",
"pm_score": 2,
"selected": false,
"text": "iconv iconv -f utf8 -t ascii <input.txt >output.txt\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
175,244
|
<p>Every so often, I'll have to switch between languages for the majority of the code I write (whether for work or for play). I find that C++ is one of those languages that requires a lot of mental cache space, so if I take a long break from it, then I forget a lot of the details. Even things like adding items to an STL container or using the <code>static</code> storage keyword in various contexts get all jumbled up ("is it <code>add</code>, <code>append</code>, <code>push</code>...oh, it's <code>push_back</code>").</p>
<p>So what essential tidbits do you like to have loaded into your brain when you're writing C++?</p>
<p>Edit: I should say, I'd like to be able to bookmark this page and use it as my cheatsheet :)</p>
|
[
{
"answer_id": 175564,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 4,
"selected": false,
"text": "std::swap() const * * const *this Base::operator=(rhs); operator=() operator=() operator=()"
},
{
"answer_id": 177108,
"author": "jonner",
"author_id": 78437,
"author_profile": "https://Stackoverflow.com/users/78437",
"pm_score": 4,
"selected": false,
"text": "int * p; // pointer\nint const * p; // pointer to const value\nint * const p; // const pointer\nint const * const p; // const pointer to const value\n *"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24923/"
] |
175,252
|
<p>I am trying to create a custom control that a "gridview" like control but specifcally for business objects that implement certain custom interfaces. </p>
<p>In doing this I have come across the following problem.</p>
<p>I have a control that I have disabled viewstate on (and I don't want to re-enable it) and it has a child control that I want viewstate enabled on. I can't seem to get the viewstate on the child control to work since its parents is disabled. Does anyone have any ideas of how to get that to work?</p>
|
[
{
"answer_id": 533306,
"author": "teedyay",
"author_id": 15825,
"author_profile": "https://Stackoverflow.com/users/15825",
"pm_score": 0,
"selected": false,
"text": "this.ViewState[\"someKey\"] = someValue;\n this.Page.ViewState[\"someKey\"] = someValue;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9581/"
] |
175,256
|
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx" rel="nofollow noreferrer">AssemblyVersion</a> and <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assemblyfileversionattribute.aspx" rel="nofollow noreferrer">AssemblyFileVersion</a> attributes are the built-in way of handling version numbers for .NET assemblies. While the framework provides the ability to have the least significant parts of a version number (build and revision, in Microsoft terms) automatically determined, I find the method for this pretty weak, and no doubt have many others.</p>
<p>So I'd like to ask, what ways have been determined to do the best job of having version numbers that better reflect the actual version of a project? Do you have a pre-build script that sets part of the version to the date and time, or repository version for your working copy of a project? Do you just use the automatic generation provided by the framework? Or something else? What's the best way to manage assembly/file versioning? </p>
|
[
{
"answer_id": 448852,
"author": "Daniel Fortunov",
"author_id": 5975,
"author_profile": "https://Stackoverflow.com/users/5975",
"pm_score": 2,
"selected": false,
"text": "AssemblyFileVersion AssemblyVersion"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5697/"
] |
175,264
|
<p>So i have this local SVN repo that i am using for my dev work on a particular project, and i also have a SVN repo setup on the customers media temple account for a more secure backup. </p>
<p>I do all of my development on my laptop so i don't always have an internet connection (hence the local SVN), so i was wondering if there is an easy way to push the changes i commit to my local repo onto the server repo?</p>
|
[
{
"answer_id": 175282,
"author": "Fernando Barrocal",
"author_id": 2274,
"author_profile": "https://Stackoverflow.com/users/2274",
"pm_score": 3,
"selected": true,
"text": "svn merge"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18811/"
] |
175,296
|
<p>I use TortoiseSVN 1.5.3 and VisualSVN 1.5.3 (Subversion 1.5.2)</p>
<p>Suppose that I create a new branch (/branches/branch1) of the trunk(/trunk) then someone (also using TortoiseSVN 1.5.3) merges their branch back into the trunk. </p>
<p>I try to merge from the trunk into the branch (to aquire all changes which might have beemn merged into the trunk by others)</p>
<p>I do not specify any particular revision(s) because I want the merge-tracking to determine which revisions I need to merge. I expect these to be revisions after the one in which I created the branch.</p>
<p>When I start the merge, the output dialog seems to merge every revision back to revision 1. this causes everything in the repository to be 'added'.</p>
<p>What a I doing wrong?.... I expected a single revision to be targeted and for this to be a very quick operation.</p>
<p>I have tried...</p>
<pre><code>SVNAdmin Upgrade <MyRepoPath>
</code></pre>
<p>This resulted in a an instantaneous success message after which I repeated my experiment with no change in results</p>
<p>Update: I have noticed that the TortoiseSVN dialog says "To merge all revisions, leave the box empty."... does this mean that TortoiseSVN is adding the 1-Head explicity and that there is no way to use Merge-Tracking? That would seem a bit strange.</p>
|
[
{
"answer_id": 178004,
"author": "Rory Becker",
"author_id": 11356,
"author_profile": "https://Stackoverflow.com/users/11356",
"pm_score": 2,
"selected": true,
"text": "http://SomeUsername@Myserver:8080/myrepo/trunk\n http://Myserver:8080/myrepo/trunk\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11356/"
] |
175,312
|
<p>I am writing a software synthesizer and need to generate bandlimited, alias free waveforms in real time at 44.1 kHz samplerate. Sawtooth waveform would do for now, since I can generate a pulse wave by mixing two sawtooths together, one inverted and phase shifted.</p>
<p>So far I've tried the following approaches:</p>
<ol>
<li><p>Precomputing one-cycle perfectly bandlimited waveform samples at different bandlimit frequencies at startup, then playing back the two closest ones mixed together. Works okay I guess, but does not feel very elegant. A lot of samples are needed or the "gaps" between them will be heard. Interpolating and mixing is also quite CPU intensive.</p></li>
<li><p>Integrating a train of DC compensated sinc pulses to get a sawtooth wave. Sounds great except that the wave drifts away from zero if you don't get the DC compensation exactly right (which I found to be really tricky). The DC problem can be reduced by adding a bit of leakage to the integrator, but then you lose the low frequencies.</p></li>
</ol>
<p>So, my question is: What is the usual way this is done? Any suggested solution must be efficient in terms of CPU, since it must be done in real time, for many voices at once.</p>
|
[
{
"answer_id": 175808,
"author": "finalman",
"author_id": 20522,
"author_profile": "https://Stackoverflow.com/users/20522",
"pm_score": 2,
"selected": false,
"text": "float getSaw(float phaseChange)\n{\n static float phase = 0.0f;\n phase = fmod(phase + phaseChange, 1.0f);\n return getBoxFilteredSaw(phase, phaseChange);\n}\n\nfloat getPulse(float phaseChange, float pulseWidth)\n{\n static float phase = 0.0f;\n phase = fmod(phase + phaseChange, 1.0f);\n return getBoxFilteredSaw(phase, phaseChange) - getBoxFilteredSaw(fmod(phase + pulseWidth, 1.0f), phaseChange);\n}\n\nfloat getBoxFilteredSaw(float phase, float kernelSize)\n{\n float a, b;\n\n // Check if kernel is longer that one cycle\n if (kernelSize >= 1.0f) {\n return 0.0f;\n }\n\n // Remap phase and kernelSize from [0.0, 1.0] to [-1.0, 1.0]\n kernelSize *= 2.0f;\n phase = phase * 2.0f - 1.0f;\n\n if (phase + kernelSize > 1.0f)\n {\n // Kernel wraps around edge of [-1.0, 1.0]\n a = phase;\n b = phase + kernelSize - 2.0f;\n }\n else\n {\n // Kernel fits nicely in [-1.0, 1.0]\n a = phase;\n b = phase + kernelSize;\n }\n\n // Integrate and divide with kernelSize\n return (b * b - a * a) / (2.0f * kernelSize);\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20522/"
] |
175,323
|
<p>As I am coding my unit tests, I tend to find that I insert the following lines:</p>
<pre><code>Console.WriteLine("Starting InteropApplication, with runInBackground set to true...");
try
{
InteropApplication application = new InteropApplication(true);
application.Start();
Console.WriteLine("Application started correctly");
}
catch(Exception e)
{
Assert.Fail(string.Format("InteropApplication failed to start: {0}", e.ToString()));
}
//test code continues ...
</code></pre>
<p>All of my tests are pretty much the same thing. They are displaying information as to why they failed, or they are displaying information about what they are doing. I haven't had any <em>formal</em> methods of how unit tests should be coded. Should they be displaying information as to what they are doing? Or should the tests be silent and not display any information at all as to what they are doing, and only display failure messages?</p>
<p>NOTE: The language is C#, but I don't care about a language specific answer.</p>
|
[
{
"answer_id": 175456,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "public void TestApplicationStart()\n{\n InteropApplication application = new InteropApplication(true);\n application.Start();\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8505/"
] |
175,381
|
<p>I'm trying to grab a div's ID in the code behind (C#) and set some css on it. Can I grab it from the DOM or do I have to use some kind of control?</p>
<pre><code><div id="formSpinner">
<img src="images/spinner.gif" />
<p>Saving...</p>
</div>
</code></pre>
|
[
{
"answer_id": 175407,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": false,
"text": "<div runat=\"server\" id=\"formSpinner\">\n ...content...\n</div>\n formSpinner.Attributes[\"class\"] = \"class-name\";\n"
},
{
"answer_id": 175408,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 2,
"selected": false,
"text": "<div id=\"formSpinner\" runat=\"server\">\n <img src=\"images/spinner.gif\">\n <p>Saving...</p>\n</div\n"
},
{
"answer_id": 175475,
"author": "Rob",
"author_id": 7872,
"author_profile": "https://Stackoverflow.com/users/7872",
"pm_score": 7,
"selected": true,
"text": "runat=\"server\" <div id=\"formSpinner\" runat=\"server\">\n <img src=\"images/spinner.gif\">\n <p>Saving...</p>\n</div>\n formSpinner.Attributes[\"class\"] = \"classOfYourChoice\";\n asp:Panel div <asp:Panel id=\"formSpinner\" runat=\"server\">\n <img src=\"images/spinner.gif\">\n <p>Saving...</p>\n</asp:Panel>\n formSpinner.CssClass = \"classOfYourChoice\";\n"
},
{
"answer_id": 4998251,
"author": "mokumaxCraig",
"author_id": 572807,
"author_profile": "https://Stackoverflow.com/users/572807",
"pm_score": 2,
"selected": false,
"text": "<body runat=\"server\" id=\"body1\">\n $(\"#body1\").addClass('modalBackground');\n"
},
{
"answer_id": 5131231,
"author": "Peri",
"author_id": 636118,
"author_profile": "https://Stackoverflow.com/users/636118",
"pm_score": 2,
"selected": false,
"text": "<div id=\"formSpinner\" class=\"<%= _css %>\">\n</div>\n protected string _css = \"modalBackground\";\n"
},
{
"answer_id": 14345960,
"author": "RandomUs1r",
"author_id": 1981471,
"author_profile": "https://Stackoverflow.com/users/1981471",
"pm_score": 1,
"selected": false,
"text": "style=\"<%= _myCSS %>\" Protected _myCSS As String = \"display: none\""
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25538/"
] |
175,385
|
<p>When setting up a rollover effect in HTML, are there any benefits (or pitfalls) to doing it in CSS vs. JavaScript? Are there any performance or code maintainability issues I should be aware of with either approach?</p>
|
[
{
"answer_id": 175422,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 6,
"selected": true,
"text": ":hover a{\n background-image: url(non-hovered-state.png);\n}\na:hover{\n background-image: url(hovered-state.png);\n}\n :hover <a> <a> background-position a{\n background-image: url(rollover-sprites.png);\n background-position: 0 0; /* Added for clarity */\n height: 20px;\n}\na:hover{\n background-position: 0 -20px; /* move the image up 20px to show the hovered state below */\n}\n background-position"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2470/"
] |
175,415
|
<p>What is the best way to get the names of all of the tables in a specific database on SQL Server?</p>
|
[
{
"answer_id": 175417,
"author": "Ray",
"author_id": 4872,
"author_profile": "https://Stackoverflow.com/users/4872",
"pm_score": 3,
"selected": false,
"text": "exec sp_msforeachtable 'print ''?'''\n"
},
{
"answer_id": 175423,
"author": "spoulson",
"author_id": 3347,
"author_profile": "https://Stackoverflow.com/users/3347",
"pm_score": 3,
"selected": false,
"text": "select * from sysobjects where xtype='U'"
},
{
"answer_id": 175427,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 3,
"selected": false,
"text": "SELECT name \nFROM sysobjects \nWHERE xtype='U' \nORDER BY name;\n"
},
{
"answer_id": 175429,
"author": "Erikk Ross",
"author_id": 18772,
"author_profile": "https://Stackoverflow.com/users/18772",
"pm_score": 3,
"selected": false,
"text": "SELECT sobjects.name\nFROM sysobjects sobjects\nWHERE sobjects.xtype = 'U' \n"
},
{
"answer_id": 175433,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 7,
"selected": false,
"text": "SELECT * FROM INFORMATION_SCHEMA.TABLES \n SELECT * FROM Sys.Tables\n"
},
{
"answer_id": 175446,
"author": "ScottStonehouse",
"author_id": 2342,
"author_profile": "https://Stackoverflow.com/users/2342",
"pm_score": 12,
"selected": true,
"text": "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'\n SELECT TABLE_NAME \nFROM [<DATABASE_NAME>].INFORMATION_SCHEMA.TABLES \nWHERE TABLE_TYPE = 'BASE TABLE'\n SELECT TABLE_NAME \nFROM INFORMATION_SCHEMA.TABLES \nWHERE TABLE_TYPE = 'BASE TABLE' \n AND TABLE_CATALOG='dbName' --(for MySql, use: TABLE_SCHEMA='dbName' )\n SELECT * FROM sysobjects WHERE xtype='U' \n"
},
{
"answer_id": 175450,
"author": "Micah",
"author_id": 17744,
"author_profile": "https://Stackoverflow.com/users/17744",
"pm_score": 8,
"selected": false,
"text": "SELECT sobjects.name\nFROM sysobjects sobjects\nWHERE sobjects.xtype = 'U'\n"
},
{
"answer_id": 18203391,
"author": "Rasoul Zabihi",
"author_id": 851784,
"author_profile": "https://Stackoverflow.com/users/851784",
"pm_score": 4,
"selected": false,
"text": "SELECT * FROM information_schema.tables\nwhere TABLE_TYPE = 'BASE TABLE'\n"
},
{
"answer_id": 19157943,
"author": "Vikash Singh",
"author_id": 2767928,
"author_profile": "https://Stackoverflow.com/users/2767928",
"pm_score": 5,
"selected": false,
"text": "USE YourDBName\nGO \nSELECT *\nFROM sys.Tables\nGO\n USE YourDBName\nGO\nSELECT * FROM INFORMATION_SCHEMA.TABLES \nGO\n"
},
{
"answer_id": 33692871,
"author": "Demietra95",
"author_id": 4926279,
"author_profile": "https://Stackoverflow.com/users/4926279",
"pm_score": 2,
"selected": false,
"text": "--for oracle\nselect tablespace_name, table_name from all_tables;\n"
},
{
"answer_id": 44962622,
"author": "NoWar",
"author_id": 196919,
"author_profile": "https://Stackoverflow.com/users/196919",
"pm_score": 1,
"selected": false,
"text": "SELECT TABLE_NAME \nFROM INFORMATION_SCHEMA.TABLES \nWHERE TABLE_TYPE='BASE TABLE' \nORDER BY TABLE_NAME\n"
},
{
"answer_id": 45745748,
"author": "Frank",
"author_id": 2372560,
"author_profile": "https://Stackoverflow.com/users/2372560",
"pm_score": 1,
"selected": false,
"text": "select * from dbo.sysobjects o \njoin sys.all_objects syso on o.id = syso.object_id \nwhere OBJECTPROPERTY(o.id, 'IsUserTable') = 1 \nand o.category & 2 = 0 \n"
},
{
"answer_id": 46447731,
"author": "Leon Bouquiet",
"author_id": 843345,
"author_profile": "https://Stackoverflow.com/users/843345",
"pm_score": 3,
"selected": false,
"text": "INFORMATION_SCHEMA.TABLES dtproperties MSpeer_... sys.objects select *\nfrom sys.objects\nwhere type = 'U' -- User tables\nand is_ms_shipped = 0 -- Exclude system tables\n"
},
{
"answer_id": 46721932,
"author": "Scott Software",
"author_id": 3174453,
"author_profile": "https://Stackoverflow.com/users/3174453",
"pm_score": 2,
"selected": false,
"text": "SELECT [TABLE_CATALOG] + '.' + [TABLE_SCHEMA] + '.' + [TABLE_NAME]\nFROM MyDatabase.INFORMATION_SCHEMA.Tables\nWHERE [TABLE_TYPE] = 'BASE TABLE' and [TABLE_NAME] <> 'sysdiagrams'\nORDER BY [TABLE_SCHEMA], [TABLE_NAME]\n"
},
{
"answer_id": 47460840,
"author": "Vikash",
"author_id": 8351544,
"author_profile": "https://Stackoverflow.com/users/8351544",
"pm_score": 2,
"selected": false,
"text": "SELECT SYSSCHEMA.NAME, SYSTABLE.NAME\nFROM SYS.tables SYSTABLE\nINNER JOIN SYS.SCHEMAS SYSSCHEMA\nON SYSTABLE.SCHEMA_ID = SYSSCHEMA.SCHEMA_ID\n"
},
{
"answer_id": 54070318,
"author": "Masoud Darvishian",
"author_id": 1402749,
"author_profile": "https://Stackoverflow.com/users/1402749",
"pm_score": 1,
"selected": false,
"text": "SELECT * FROM INFORMATION_SCHEMA.COLUMNS"
},
{
"answer_id": 54721471,
"author": "DarkRob",
"author_id": 10837441,
"author_profile": "https://Stackoverflow.com/users/10837441",
"pm_score": 3,
"selected": false,
"text": " GO\n select * from sys.objects where type_desc='USER_TABLE' order by name\n GO\n -- For all tables\nselect * from INFORMATION_SCHEMA.TABLES \nGO \n\n --- For user defined tables\nselect * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE'\nGO\n\n --- For Views\nselect * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='VIEW'\nGO\n"
},
{
"answer_id": 68838583,
"author": "JoelF",
"author_id": 2236804,
"author_profile": "https://Stackoverflow.com/users/2236804",
"pm_score": 0,
"selected": false,
"text": "SELECT s.NAME SchemaName, t.NAME TableName\nFROM [dbname].SYS.tables t\nINNER JOIN [dbname].SYS.SCHEMAS s\nON t.SCHEMA_ID = s.SCHEMA_ID\nWHERE t.is_ms_shipped=0 and type_desc = 'USER_TABLE'\nORDER BY s.NAME, t.NAME\n"
},
{
"answer_id": 70776670,
"author": "Hassan Munir",
"author_id": 3079433,
"author_profile": "https://Stackoverflow.com/users/3079433",
"pm_score": 2,
"selected": false,
"text": "Any of the T-SQL code below will work in SQL Server 2019:\n\n-- here, you need to prefix the database name in INFORMATION_SCHEMA.TABLES\nSELECT TABLE_NAME FROM [MSSQL-TEST].INFORMATION_SCHEMA.TABLES;\n\n-- The next 2 ways will require you to point\n-- to the specific database you want to list the tables\n\nUSE [MSSQL-TEST];\n-- (1) Using sys.tables\nSELECT * FROM sys.tables;\n\n-- (2) Using sysobjects\nSELECT * FROM sysobjects\nWHERE type='U';\n\nHere’s a working example using [Skyvia] using sys.tables.\n\n[Skyvia] should be the link to https://skyvia.com/connectors/sql-server\n\n\n [1]: https://i.stack.imgur.com/o3qo9.png\n Your SQL GUI tool should also have a way to list down all the tables in a database like the one above.\n\nSo, whatever suits your need and taste, there’s a code or GUI tool for that.\n"
},
{
"answer_id": 74280587,
"author": "Muneeb Ejaz",
"author_id": 5122498,
"author_profile": "https://Stackoverflow.com/users/5122498",
"pm_score": 0,
"selected": false,
"text": "select * from SYS.TABLES;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
175,437
|
<p>We have a number of projects that use the same and/or similar package names. Many or these projects will build jar files that are used by other projects. We have found a number of foo.util foo.db and foo.exceptions where the same class names are being used leading to name space conflicts. </p>
<p>Does anyone know of a tool that will search a set of java code bases and automatically find name space conflicts and ambiguous imports?</p>
|
[
{
"answer_id": 175552,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": true,
"text": "foo.this foo.that org.apache.project.component.lower.level.names com.projectX.foo.this com.projectZ.foo.that"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13753/"
] |
175,451
|
<p>How do you prepare your SQL deltas? do you manually save each schema-changing SQL to a delta folder, or do you have some kind of an automated diffing process?</p>
<p>I am interested in conventions for versioning database schema along with the source code. Perhaps a pre-commit hook that diffs the schema?</p>
<p>Also, what options for diffing deltas exist aside from <a href="http://dbdeploy.com/" rel="noreferrer">DbDeploy</a>?</p>
<p><strong>EDIT:</strong> seeing the answers I would like to clarify that I am familiar with the standard scheme for running a database migration using deltas. My question is about creating the deltas themselves, preferably automatically.</p>
<p>Also, the versioning is for PHP and MySQL if it makes a difference. (No Ruby solutions please).</p>
|
[
{
"answer_id": 175675,
"author": "Swaroop C H",
"author_id": 4869,
"author_profile": "https://Stackoverflow.com/users/4869",
"pm_score": 1,
"selected": false,
"text": "cake schema generate"
},
{
"answer_id": 39343500,
"author": "Nolwennig",
"author_id": 4457531,
"author_profile": "https://Stackoverflow.com/users/4457531",
"pm_score": 1,
"selected": false,
"text": "mysqldump --no-data --skip-comments --skip-extended-insert -h __DB_HOSTNAME__ -u __DB_USERNAME__ -p __DB1_NAME__ | sed 's/ AUTO_INCREMENT=[0-9]*//g' > FILENAME_1.sql\nmysqldump --no-data --skip-comments --skip-extended-insert -h __DB_HOSTNAME__ -u __DB_USERNAME__ -p __DB2_NAME__ | sed 's/ AUTO_INCREMENT=[0-9]*//g' > FILENAME_2.sql\ndiff FILENAME_1.sql FILENAME_2.sql > DIFF_FILENAME.txt\ncat DIFF_FILENAME.txt | less\n mysqldiff information_schema initial version : 1.0.0\n ^ ^ ^\n | | |\nstructure change: - | |\ndatas added: -------- |\ndatas updated: --------\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175451",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10585/"
] |
175,454
|
<p>I am working on a web application and I have run into the following situation.</p>
<pre><code>Dim a as Object
Dim i as Integer = 0
Try
For i=1 to 5
a = new Object()
'Do stuff '
a = Nothing
Next
Catch
Finally
a = Nothing
End Try
</code></pre>
<p>Do i need to do the a=Nothing in the loop or will the garbage collector clean a up?</p>
|
[
{
"answer_id": 175465,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "a = Nothing try/finally"
},
{
"answer_id": 175480,
"author": "John Rudy",
"author_id": 14048,
"author_profile": "https://Stackoverflow.com/users/14048",
"pm_score": 5,
"selected": true,
"text": "Nothing null Nothing Try Finally Try Dim a as Object\nDim i as Integer = 0\n\nFor i=1 to 5\n a = new Object()\n 'Do stuff\nNext\n"
},
{
"answer_id": 175640,
"author": "Anders",
"author_id": 25515,
"author_profile": "https://Stackoverflow.com/users/25515",
"pm_score": 0,
"selected": false,
"text": "System.GC.Collect()\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1001650/"
] |
175,488
|
<p>I have a website form that requires a US phone number input for follow up purposes, and this is very necessary in this case. I want try to eliminate users entering junk data <em>330-000-0000</em>. I have seen some options of third parties that validate phone numbers for you, however idk if that is the best option for this situation. However if you have every used one of these third parties and can make a recommendation that would also be greatly appreciated here.</p>
<p>However I am considering checking the number against a set of rules to just try to narrow down the junk phone numbers received.</p>
<ul>
<li>not a 555 number</li>
<li>does not contain 7 identical digits</li>
<li>valid area code (this is readily available)</li>
<li>not a 123-1234 or 123-4567</li>
<li>I guess I could also count out 867-5309 (heh<a href="http://en.wikipedia.org/wiki/8675309" rel="nofollow noreferrer">*</a>)</li>
</ul>
<p>Would this result in any situations that you can think of that would not allow a user to enter their phone number? Could you think of any other rules that a phone number should not contain? Any other thoughts?</p>
|
[
{
"answer_id": 175518,
"author": "GloryFish",
"author_id": 3238,
"author_profile": "https://Stackoverflow.com/users/3238",
"pm_score": 2,
"selected": false,
"text": "function phone_number_is_valid($phone) {\n return (eregi('^(?:\\([2-9]\\d{2}\\)\\ ?|[2-9]\\d{2}(?:\\-?|\\ ?))[2-9]\\d{2}[- ]?\\d{4}$', $phone));\n}\n"
},
{
"answer_id": 1516998,
"author": "J.Hendrix",
"author_id": 180385,
"author_profile": "https://Stackoverflow.com/users/180385",
"pm_score": 0,
"selected": false,
"text": " public static bool isPhone(string phoneNum)\n {\n Regex rxPhone1, rxPhone2;\n\n rxPhone1 = new Regex(@\"^\\d{10,}$\");\n rxPhone2 = new Regex(@\"(\\d)\\1\\1\\1\\1\\1\\1\\1\\1\\1\");\n\n if(phoneNum.Trim() == string.Empty)\n return false;\n\n if(phoneNum.Length != 10)\n return false;\n\n //Check to make sure the phone number has at least 10 digits\n if (!rxPhone1.IsMatch(phoneNum))\n return false;\n\n //Check for repeating characters (ex. 9999999999)\n if (rxPhone2.IsMatch(phoneNum))\n return false;\n\n //Make sure first digit is not 1 or zero\n if(phoneNum.Substring(0,1) == \"1\" || phoneNum.Substring(0,1) == \"0\")\n return false;\n\n return true;\n\n }\n"
},
{
"answer_id": 1641854,
"author": "Shimmy Weitzhandler",
"author_id": 75500,
"author_profile": "https://Stackoverflow.com/users/75500",
"pm_score": 0,
"selected": false,
"text": "Private Sub OnNumberChanged()\n Dim sep = \"-\"\n Dim num As String = Number.ToCharArray.Where(Function(c) Char.IsDigit(c)) _\n .ToArray\n Dim ext As String = Nothing\n If num.Length > 10 Then ext = num.Substring(10)\n ext = If(IsNullOrEmpty(ext), \"\", \" x\" & ext)\n _Number = Left(num, 3) & sep & Mid(num, 4, 3) & sep & Mid(num, 7, 4) & ext\nEnd Sub\n Public Shared Function ValidatePhoneNumber(ByVal number As String)\n Return number IsNot Nothing AndAlso number.ToCharArray. _\n Where(Function(c) Char.IsNumber(c)).Count >= 10\nEnd Function\n"
},
{
"answer_id": 4168845,
"author": "Josh",
"author_id": 59143,
"author_profile": "https://Stackoverflow.com/users/59143",
"pm_score": 0,
"selected": false,
"text": "((\\+[1-9]{1,4}[ \\-]*)|(\\([0-9]{2,3}\\)[ \\-]*)|([0-9]{2,4})[ \\-]*)*?[0-9]{3,4}?[ \\-]*[0-9]{3,4}?$\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19226/"
] |
175,505
|
<p>I have an application where whenever a file is uploaded to a directory, I have to call SSIS to parse the XML file.</p>
<p>Can I call a SSIS directly from a .NET Windows service?</p>
|
[
{
"answer_id": 12881116,
"author": "Hassan Boutougha",
"author_id": 1542767,
"author_profile": "https://Stackoverflow.com/users/1542767",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing Microsoft.SqlServer.Dts.Runtime.Wrapper;\n\nnamespace ConsoleApplicationSSIS\n{\n class Program\n {\n static void Main(string[] args)\n {\n Console.WriteLine(\"Loading SSIS Service...\");\n //Application object allows load your SSIS package\n Application app = new Application();\n //In order to retrieve the status (success or failure) after running SSIS Package\n DTSExecResult result ;\n //Specify the location of SSIS package - dtsx file\n string SSISPackagePath = @\"C:\\Microsofts\\BI\\SSIS\\ConsoleApplicationSSIS\\IntegrationServiceScriptTask\\Package.dtsx\";\n //Load your package\n Package pckg = (Package)app.LoadPackage(SSISPackagePath,true,null);\n //Execute the package and retrieve result\n result = pckg.Execute();\n //Print the status success or failure of your package\n Console.WriteLine(\"{0}\", result.ToString());\n Console.ReadLine();\n }\n }\n} \n"
},
{
"answer_id": 43463937,
"author": "Yasskier",
"author_id": 1341244,
"author_profile": "https://Stackoverflow.com/users/1341244",
"pm_score": 0,
"selected": false,
"text": "create_execution set_execution_parameter"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,532
|
<p>I am using java language,I have a method that is supposed to return an object if it is found.</p>
<p>If it is not found, should I:</p>
<ol>
<li>return null</li>
<li>throw an exception</li>
<li>other</li>
</ol>
<p>Which is the best practise or idiom?</p>
|
[
{
"answer_id": 175574,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 2,
"selected": false,
"text": "Object *findObject(Key &key);\n void findObject(Key &key, Object &found);\n bool findObject(Key &key, Object &found);\n if (!findObject(myKey, myObj)) { ...\n"
},
{
"answer_id": 175647,
"author": "codeape",
"author_id": 3571,
"author_profile": "https://Stackoverflow.com/users/3571",
"pm_score": 0,
"selected": false,
"text": "\nDataType GetObject(DBConnection conn, string id, bool throwOnNotFound) {\n DataType retval = ... // find object in database\n if (retval != null || ! throwOnNotFound) {\n return retval;\n } else {\n throw new NoRowsFoundException(\"DataType object with id {id} not found in database\");\n }\n}\n\nDataType GetObject(DBConnection conn, string id) {\n return GetObject(conn, id, true);\n} \n"
},
{
"answer_id": 175677,
"author": "Kevin Gale",
"author_id": 7176,
"author_profile": "https://Stackoverflow.com/users/7176",
"pm_score": 6,
"selected": false,
"text": "object o = FindObject();\n if (TryFindObject(out object o)\n // Do something with o\nelse\n // o was not found\n"
},
{
"answer_id": 175943,
"author": "Lev",
"author_id": 7224,
"author_profile": "https://Stackoverflow.com/users/7224",
"pm_score": 2,
"selected": false,
"text": "..., bool verify = true)\n"
},
{
"answer_id": 176693,
"author": "akuhn",
"author_id": 24468,
"author_profile": "https://Stackoverflow.com/users/24468",
"pm_score": 3,
"selected": false,
"text": "is_present(key)\nfind(key) throws Exception\n"
},
{
"answer_id": 411400,
"author": "Lena Schimmel",
"author_id": 39946,
"author_profile": "https://Stackoverflow.com/users/39946",
"pm_score": 5,
"selected": false,
"text": "Object findObjectOrNull(String key);\nObject findObjectOrThrow(String key) throws SomeException;\nObject findObjectOrCreate(String key, SomeClass dataNeededToCreateNewObject);\nObject findObjectOrDefault(String key, Object defaultReturnValue);\n"
},
{
"answer_id": 4511243,
"author": "DorD",
"author_id": 208955,
"author_profile": "https://Stackoverflow.com/users/208955",
"pm_score": 2,
"selected": false,
"text": "bool TryFindObject(RequestParam request, out ResponseParam response)\n ...\nif(TryFindObject(request, out response)\n{\n handleSuccess(response)\n}\nelse\n{\n handleFailure()\n}\n...\n"
},
{
"answer_id": 5087531,
"author": "kizzx2",
"author_id": 111021,
"author_profile": "https://Stackoverflow.com/users/111021",
"pm_score": 2,
"selected": false,
"text": "try catch"
},
{
"answer_id": 26507432,
"author": "svlzx",
"author_id": 1692465,
"author_profile": "https://Stackoverflow.com/users/1692465",
"pm_score": 1,
"selected": false,
"text": "public class Main {\npublic static void main(String[] args) {\n Example example = new Example();\n\n try {\n Example2 obj = example.doExample();\n\n if(obj == null){\n System.out.println(\"Hey object is null!\");\n }\n } catch (Exception e) {\n System.out.println(\"Congratulations, you caught the exception!\");\n System.out.println(\"Here is stack trace:\");\n e.printStackTrace();\n }\n}\n}\n /**\n * Example.java\n * @author Seval\n * @date 10/22/2014\n */\npublic class Example {\n /**\n * Returns Example2 object\n * If there is no Example2 object, throws exception\n * \n * @return obj Example2\n * @throws Exception\n */\n public Example2 doExample() throws Exception {\n try {\n // Get the object\n Example2 obj = new Example2();\n\n return obj;\n\n } catch (Exception e) {\n // Log the exception and rethrow\n // Log.logException(e);\n throw e;\n }\n\n }\n}\n /**\n * Example2.java\n * @author Seval\n *\n */\npublic class Example2 {\n /**\n * Constructor of Example2\n * @throws Exception\n */\n public Example2() throws Exception{\n throw new Exception(\"Please set the \\\"obj\\\"\");\n }\n\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9516/"
] |
175,544
|
<p>I'm trying to write a tennis reservation system and I got stucked with this problem.
Let's say you have players with their prefs regarding court number, day and hour.
Also every player is ranked so if there is day/hour slot and there are several players
with preferences for this slot the one with top priority should be chosen.
I'm thinking about using some optimization algorithms to solve this problem but I'am not sure what would be the best cost function and/or algorithm to use.
Any advice?
One more thing I would prefer to use Python but some language-agnostic advice would be welcome also.
Thanks!</p>
<p>edit:</p>
<p>some clarifications-</p>
<p>the one with better priority wins and loser is moved to nearest slot,
rather flexible time slots question
yes, maximizing the number of people getting their most highly preffered times </p>
|
[
{
"answer_id": 175585,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 2,
"selected": false,
"text": "sort players by priority, highest to lowest\nstart with empty schedule\nfor player in players:\n for timeslot in player.preferences():\n if timeslot is free:\n schedule.fillslot(timeslot, player)\n break\n else:\n #if we get here, it means this player couldn't be accomodated at all.\n #you'll have to go through the slots that were filled and move another (higher-priority) player's time slot\n"
},
{
"answer_id": 175831,
"author": "ARKBAN",
"author_id": 11889,
"author_profile": "https://Stackoverflow.com/users/11889",
"pm_score": 1,
"selected": false,
"text": "FinalScore = ( PlayerRanking * N1 ) + ( PlayerPreference * N2 )\n"
},
{
"answer_id": 178185,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 2,
"selected": false,
"text": "Player 1 - Request 1\nPlayer 2 - Request 1\nPlayer 3 - Request 1\nPlayer 4 - Request 1\nPlayer 1 - Request 2\nPlayer 2 - Request 2\n:\n Rank 1 - 50%\nRank 2 - 25%\nRank 3 - 12,5%\nRank 4 - 6,25%\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25587/"
] |
175,547
|
<p>How you fix the following Hibernate error:</p>
<p>What does "Use of the same entity name twice".</p>
|
[
{
"answer_id": 175599,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 0,
"selected": false,
"text": "<xml>nicely formatted</xml>\n"
},
{
"answer_id": 23336677,
"author": "Misha Zadorozhnyy",
"author_id": 1915382,
"author_profile": "https://Stackoverflow.com/users/1915382",
"pm_score": 4,
"selected": false,
"text": "package A;\n\n@Entity\nclass Cell{\n ... \n}\n\n\npackage B;\n\n@Entity\nclass Cell{\n ... \n}\n @Entity(name=\"a.Cell\")\nclass Cell{\n ... \n}\n\n\npackage B;\n\n@Entity(name=\"b.Cell\")\nclass Cell{\n ... \n}\n ...createQuery(\"from a.Cell\")...\n"
},
{
"answer_id": 45366073,
"author": "amisiuryk",
"author_id": 2378369,
"author_profile": "https://Stackoverflow.com/users/2378369",
"pm_score": 2,
"selected": false,
"text": "<property name=\"hibernate.auto-import\" value=\"false\"/> entityManager.createQuery(\"Select a.Name, b.name from AEntity a,\nBEntity b where a.ID = b.parentID\")"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175547",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,554
|
<p>I need to convert an arbitrary amount of milliseconds into Days, Hours, Minutes Second.</p>
<p>For example: 10 Days, 5 hours, 13 minutes, 1 second.</p>
|
[
{
"answer_id": 175575,
"author": "friol",
"author_id": 23034,
"author_profile": "https://Stackoverflow.com/users/23034",
"pm_score": 6,
"selected": false,
"text": "seconds=(A/1000)%60\nminutes=(A/(1000*60))%60\nhours=(A/(1000*60*60))%24\n %"
},
{
"answer_id": 175576,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 9,
"selected": true,
"text": "x = ms / 1000\nseconds = x % 60\nx /= 60\nminutes = x % 60\nx /= 60\nhours = x % 24\nx /= 24\ndays = x\n / /"
},
{
"answer_id": 175588,
"author": "albertein",
"author_id": 23020,
"author_profile": "https://Stackoverflow.com/users/23020",
"pm_score": 3,
"selected": false,
"text": "int milliseconds = someNumber;\n\nint seconds = milliseconds / 1000;\n\nint minutes = seconds / 60;\n\nseconds %= 60;\n\nint hours = minutes / 60;\n\nminutes %= 60;\n\nint days = hours / 24;\n\nhours %= 24;\n"
},
{
"answer_id": 3943656,
"author": "Krolique",
"author_id": 189909,
"author_profile": "https://Stackoverflow.com/users/189909",
"pm_score": 2,
"selected": false,
"text": "Long serverUptimeSeconds = \n (System.currentTimeMillis() - SINCE_TIME_IN_MILLISECONDS) / 1000;\n\n\nString serverUptimeText = \nString.format(\"%d days %d hours %d minutes %d seconds\",\nserverUptimeSeconds / 86400,\n( serverUptimeSeconds % 86400) / 3600 ,\n((serverUptimeSeconds % 86400) % 3600 ) / 60,\n((serverUptimeSeconds % 86400) % 3600 ) % 60\n);\n"
},
{
"answer_id": 8795493,
"author": "iTurki",
"author_id": 543711,
"author_profile": "https://Stackoverflow.com/users/543711",
"pm_score": 2,
"selected": false,
"text": "integer milliseconds value human-readable String public String convertMS(int ms) {\n int seconds = (int) ((ms / 1000) % 60);\n int minutes = (int) (((ms / 1000) / 60) % 60);\n int hours = (int) ((((ms / 1000) / 60) / 60) % 24);\n\n String sec, min, hrs;\n if(seconds<10) sec=\"0\"+seconds;\n else sec= \"\"+seconds;\n if(minutes<10) min=\"0\"+minutes;\n else min= \"\"+minutes;\n if(hours<10) hrs=\"0\"+hours;\n else hrs= \"\"+hours;\n\n if(hours == 0) return min+\":\"+sec;\n else return hrs+\":\"+min+\":\"+sec;\n\n}\n"
},
{
"answer_id": 12420737,
"author": "Nick Grealy",
"author_id": 782034,
"author_profile": "https://Stackoverflow.com/users/782034",
"pm_score": 5,
"selected": false,
"text": "> 1 month var date = new Date(536643021);\nvar str = '';\nstr += date.getUTCDate()-1 + \" days, \";\nstr += date.getUTCHours() + \" hours, \";\nstr += date.getUTCMinutes() + \" minutes, \";\nstr += date.getUTCSeconds() + \" seconds, \";\nstr += date.getUTCMilliseconds() + \" millis\";\nconsole.log(str);\n \"6 days, 5 hours, 4 minutes, 3 seconds, 21 millis\"\n var getDuration = function(millis){\n var dur = {};\n var units = [\n {label:\"millis\", mod:1000},\n {label:\"seconds\", mod:60},\n {label:\"minutes\", mod:60},\n {label:\"hours\", mod:24},\n {label:\"days\", mod:31}\n ];\n // calculate the individual unit values...\n units.forEach(function(u){\n millis = (millis - (dur[u.label] = (millis % u.mod))) / u.mod;\n });\n // convert object to a string representation...\n var nonZero = function(u){ return dur[u.label]; };\n dur.toString = function(){\n return units\n .reverse()\n .filter(nonZero)\n .map(function(u){\n return dur[u.label] + \" \" + (dur[u.label]==1?u.label.slice(0,-1):u.label);\n })\n .join(', ');\n };\n return dur;\n};\n console.log(getDuration(536643021).toString());\n \"6 days, 5 hours, 4 minutes, 3 seconds, 21 millis\"\n"
},
{
"answer_id": 12668818,
"author": "AK Joshi",
"author_id": 1670594,
"author_profile": "https://Stackoverflow.com/users/1670594",
"pm_score": 0,
"selected": false,
"text": " public String getDuration(String _currentTimemilliSecond)\n {\n long _currentTimeMiles = 1; \n int x = 0;\n int seconds = 0;\n int minutes = 0;\n int hours = 0;\n int days = 0;\n int month = 0;\n int year = 0;\n\n try \n {\n _currentTimeMiles = Long.parseLong(_currentTimemilliSecond);\n /** x in seconds **/ \n x = (int) (_currentTimeMiles / 1000) ; \n seconds = x ;\n\n if(seconds >59)\n {\n minutes = seconds/60 ;\n\n if(minutes > 59)\n {\n hours = minutes/60;\n\n if(hours > 23)\n {\n days = hours/24 ;\n\n if(days > 30)\n {\n month = days/30;\n\n if(month > 11)\n {\n year = month/12;\n\n Log.d(\"Year\", year);\n Log.d(\"Month\", month%12);\n Log.d(\"Days\", days % 30);\n Log.d(\"hours \", hours % 24);\n Log.d(\"Minutes \", minutes % 60);\n Log.d(\"Seconds \", seconds % 60); \n\n return \"Year \"+year + \" Month \"+month%12 +\" Days \" +days%30 +\" hours \"+hours%24 +\" Minutes \"+minutes %60+\" Seconds \"+seconds%60;\n }\n else\n {\n Log.d(\"Month\", month);\n Log.d(\"Days\", days % 30);\n Log.d(\"hours \", hours % 24);\n Log.d(\"Minutes \", minutes % 60);\n Log.d(\"Seconds \", seconds % 60); \n\n return \"Month \"+month +\" Days \" +days%30 +\" hours \"+hours%24 +\" Minutes \"+minutes %60+\" Seconds \"+seconds%60;\n }\n\n }\n else\n {\n Log.d(\"Days\", days );\n Log.d(\"hours \", hours % 24);\n Log.d(\"Minutes \", minutes % 60);\n Log.d(\"Seconds \", seconds % 60); \n\n return \"Days \" +days +\" hours \"+hours%24 +\" Minutes \"+minutes %60+\" Seconds \"+seconds%60;\n }\n\n }\n else\n {\n Log.d(\"hours \", hours);\n Log.d(\"Minutes \", minutes % 60);\n Log.d(\"Seconds \", seconds % 60);\n\n return \"hours \"+hours+\" Minutes \"+minutes %60+\" Seconds \"+seconds%60;\n }\n }\n else\n {\n Log.d(\"Minutes \", minutes);\n Log.d(\"Seconds \", seconds % 60);\n\n return \"Minutes \"+minutes +\" Seconds \"+seconds%60;\n }\n }\n else\n {\n Log.d(\"Seconds \", x);\n return \" Seconds \"+seconds;\n }\n }\n catch (Exception e) \n {\n Log.e(getClass().getName().toString(), e.toString());\n }\n return \"\";\n }\n\n private Class Log\n {\n public static void d(String tag , int value)\n {\n System.out.println(\"##### [ Debug ] ## \"+tag +\" :: \"+value);\n }\n }\n"
},
{
"answer_id": 13151858,
"author": "Rajiv",
"author_id": 302303,
"author_profile": "https://Stackoverflow.com/users/302303",
"pm_score": 2,
"selected": false,
"text": "function convertTime(time) { \n var millis= time % 1000;\n time = parseInt(time/1000);\n var seconds = time % 60;\n time = parseInt(time/60);\n var minutes = time % 60;\n time = parseInt(time/60);\n var hours = time % 24;\n var out = \"\";\n if(hours && hours > 0) out += hours + \" \" + ((hours == 1)?\"hr\":\"hrs\") + \" \";\n if(minutes && minutes > 0) out += minutes + \" \" + ((minutes == 1)?\"min\":\"mins\") + \" \";\n if(seconds && seconds > 0) out += seconds + \" \" + ((seconds == 1)?\"sec\":\"secs\") + \" \";\n if(millis&& millis> 0) out += millis+ \" \" + ((millis== 1)?\"msec\":\"msecs\") + \" \";\n return out.trim();\n}\n"
},
{
"answer_id": 13376991,
"author": "Rafal Pastuszak",
"author_id": 969813,
"author_profile": "https://Stackoverflow.com/users/969813",
"pm_score": 1,
"selected": false,
"text": "var days, hours, minutes, seconds, x;\nx = ms / 1000;\nseconds = Math.floor(x % 60);\nx /= 60;\nminutes = Math.floor(x % 60);\nx /= 60;\nhours = Math.floor(x % 24);\nx /= 24;\ndays = Math.floor(x);\n getFormattedTime : (ms)->\n x = ms / 1000\n seconds = Math.floor x % 60\n x /= 60\n minutes = Math.floor x % 60\n x /= 60\n hours = Math.floor x % 24\n x /= 24\n days = Math.floor x\n formattedTime = \"#{seconds}s\"\n if minutes then formattedTime = \"#{minutes}m \" + formattedTime\n if hours then formattedTime = \"#{hours}h \" + formattedTime\n formattedTime \n"
},
{
"answer_id": 16715577,
"author": "ssamuel68",
"author_id": 1178789,
"author_profile": "https://Stackoverflow.com/users/1178789",
"pm_score": 1,
"selected": false,
"text": "/**\n * Converts milliseconds to human readeable language separated by \":\"\n * Example: 190980000 --> 2:05:3 --> 2days 5hours 3min\n */\nfunction dhm(t){\n var cd = 24 * 60 * 60 * 1000,\n ch = 60 * 60 * 1000,\n d = Math.floor(t / cd),\n h = '0' + Math.floor( (t - d * cd) / ch),\n m = '0' + Math.round( (t - d * cd - h * ch) / 60000);\n return [d, h.substr(-2), m.substr(-2)].join(':');\n}\n\nvar delay = 190980000; \nvar fullTime = dhm(delay);\nconsole.log(fullTime);\n"
},
{
"answer_id": 17352661,
"author": "Asit",
"author_id": 2529686,
"author_profile": "https://Stackoverflow.com/users/2529686",
"pm_score": 2,
"selected": false,
"text": "Long expireTime = 69l;\nLong tempParam = 0l;\n\nLong seconds = math.mod(expireTime, 60);\ntempParam = expireTime - seconds;\nexpireTime = tempParam/60;\nLong minutes = math.mod(expireTime, 60);\ntempParam = expireTime - minutes;\nexpireTime = expireTime/60;\nLong hours = math.mod(expireTime, 24);\ntempParam = expireTime - hours;\nexpireTime = expireTime/24;\nLong days = math.mod(expireTime, 30);\n\nsystem.debug(days + '.' + hours + ':' + minutes + ':' + seconds);\n"
},
{
"answer_id": 24576327,
"author": "dafunker",
"author_id": 1765329,
"author_profile": "https://Stackoverflow.com/users/1765329",
"pm_score": 1,
"selected": false,
"text": "def remainingStr = \"\"\n\n/* Days */\nint days = MILLISECONDS.toDays(remainingTime) as int\nremainingStr += (days == 1) ? '1 Day : ' : \"${days} Days : \"\nremainingTime -= DAYS.toMillis(days)\n\n/* Hours */\nint hours = MILLISECONDS.toHours(remainingTime) as int\nremainingStr += (hours == 1) ? '1 Hour : ' : \"${hours} Hours : \"\nremainingTime -= HOURS.toMillis(hours)\n\n/* Minutes */\nint minutes = MILLISECONDS.toMinutes(remainingTime) as int\nremainingStr += (minutes == 1) ? '1 Minute : ' : \"${minutes} Minutes : \"\nremainingTime -= MINUTES.toMillis(minutes)\n\n/* Seconds */\nint seconds = MILLISECONDS.toSeconds(remainingTime) as int\nremainingStr += (seconds == 1) ? '1 Second' : \"${seconds} Seconds\"\n"
},
{
"answer_id": 28004110,
"author": "yorg",
"author_id": 3225970,
"author_profile": "https://Stackoverflow.com/users/3225970",
"pm_score": 1,
"selected": false,
"text": "/**\nconvert duration to a ms/sec/min/hour/day/week array\n@param {int} msTime : time in milliseconds \n@param {bool} fillEmpty(optional) : fill array values even when they are 0.\n@param {string[]} suffixes(optional) : add suffixes to returned values.\n values are filled with missings '0'\n@return {int[]/string[]} : time values from higher to lower(ms) range.\n*/\nvar msToTimeList=function(msTime,fillEmpty,suffixes){\n suffixes=(suffixes instanceof Array)?suffixes:[]; //suffixes is optional\n var timeSteps=[1000,60,60,24,7]; // time ranges : ms/sec/min/hour/day/week\n timeSteps.push(1000000); //add very big time at the end to stop cutting\n var result=[];\n for(var i=0;(msTime>0||i<1||fillEmpty)&&i<timeSteps.length;i++){\n var timerange = msTime%timeSteps[i];\n if(typeof(suffixes[i])==\"string\"){\n timerange+=suffixes[i]; // add suffix (converting )\n // and fill zeros :\n while( i<timeSteps.length-1 &&\n timerange.length<((timeSteps[i]-1)+suffixes[i]).length )\n timerange=\"0\"+timerange;\n }\n result.unshift(timerange); // stack time range from higher to lower\n msTime = Math.floor(msTime/timeSteps[i]);\n }\n return result;\n};\n var elsapsed = Math.floor(Math.random()*3000000000);\n\nconsole.log( \"elsapsed (labels) = \"+\n msToTimeList(elsapsed,false,[\"ms\",\"sec\",\"min\",\"h\",\"days\",\"weeks\"]).join(\"/\") );\n\nconsole.log( \"half hour : \"+msToTimeList(elsapsed,true)[3]<30?\"first\":\"second\" );\n\nconsole.log( \"elsapsed (classic) = \"+\n msToTimeList(elsapsed,false,[\"\",\"\",\"\",\"\",\"\",\"\"]).join(\" : \") );\n"
},
{
"answer_id": 29181707,
"author": "Vishal Makasana",
"author_id": 2626901,
"author_profile": "https://Stackoverflow.com/users/2626901",
"pm_score": 1,
"selected": false,
"text": "PrettyTime p = new PrettyTime();\n System.out.println(p.format(new Date())); PrettyTime p = new PrettyTime());\n Date d = new Date(System.currentTimeMillis());\n d.setHours(d.getHours() - 1);\n String ago = p.format(d);"
},
{
"answer_id": 38934961,
"author": "Camilo Silva",
"author_id": 766855,
"author_profile": "https://Stackoverflow.com/users/766855",
"pm_score": 2,
"selected": false,
"text": "public static String formatMs(long millis) {\n long hours = TimeUnit.MILLISECONDS.toHours(millis);\n long mins = TimeUnit.MILLISECONDS.toMinutes(millis);\n long secs = TimeUnit.MILLISECONDS.toSeconds(millis);\n return String.format(\"%dh %d min, %d sec\",\n hours,\n mins - TimeUnit.HOURS.toMinutes(hours),\n secs - TimeUnit.MINUTES.toSeconds(mins)\n );\n}\n 12h 1 min, 34 sec\n"
},
{
"answer_id": 64721281,
"author": "bougui",
"author_id": 1679629,
"author_profile": "https://Stackoverflow.com/users/1679629",
"pm_score": 0,
"selected": false,
"text": "awk $ ms=10000001; awk -v ms=$ms 'BEGIN {x=ms/1000; \n s=x%60; x/=60;\n m=x%60; x/=60;\n h=x%60;\n printf(\"%02d:%02d:%02d.%03d\\n\", h, m, s, ms%1000)}'\n02:46:40.001\n"
},
{
"answer_id": 64800061,
"author": "keocra",
"author_id": 2019601,
"author_profile": "https://Stackoverflow.com/users/2019601",
"pm_score": 1,
"selected": false,
"text": "from datetime import timedelta\n\nms = 536643021\ntd = timedelta(milliseconds=ms)\n\nprint(str(td))\n# --> 6 days, 5:04:03.021000\n"
},
{
"answer_id": 68988002,
"author": "Jonathan",
"author_id": 2407212,
"author_profile": "https://Stackoverflow.com/users/2407212",
"pm_score": 0,
"selected": false,
"text": "const toTimeString = (value, singularName) =>\n `${value} ${singularName}${value !== 1 ? 's' : ''}`;\n\nconst readableTime = (ms) => {\n const days = Math.floor(ms / (24 * 60 * 60 * 1000));\n const daysMs = ms % (24 * 60 * 60 * 1000);\n const hours = Math.floor(daysMs / (60 * 60 * 1000));\n const hoursMs = ms % (60 * 60 * 1000);\n const minutes = Math.floor(hoursMs / (60 * 1000));\n const minutesMs = ms % (60 * 1000);\n const seconds = Math.round(minutesMs / 1000);\n\n const data = [\n [days, 'day'],\n [hours, 'hour'],\n [minutes, 'minute'],\n [seconds, 'second'],\n ];\n\n return data\n .filter(([value]) => value > 0)\n .map(([value, name]) => toTimeString(value, name))\n .join(', ');\n};\n\n// Tests\nconst hundredDaysTwentyHoursFiftyMinutesThirtySeconds = 8715030000;\nconst oneDayTwoHoursEightMinutesTwelveSeconds = 94092000;\nconst twoHoursFiftyMinutes = 10200000;\nconst oneMinute = 60000;\nconst fortySeconds = 40000;\nconst oneSecond = 1000;\nconst oneDayTwelveSeconds = 86412000;\n\nconst test = (result, expected) => {\n console.log(expected, '- ' + (result === expected));\n};\n\ntest(readableTime(\n hundredDaysTwentyHoursFiftyMinutesThirtySeconds\n), '100 days, 20 hours, 50 minutes, 30 seconds');\n\ntest(readableTime(\n oneDayTwoHoursEightMinutesTwelveSeconds\n), '1 day, 2 hours, 8 minutes, 12 seconds');\n\ntest(readableTime(\n twoHoursFiftyMinutes\n), '2 hours, 50 minutes');\n\ntest(readableTime(\n oneMinute\n), '1 minute');\n\ntest(readableTime(\n fortySeconds\n), '40 seconds');\n\ntest(readableTime(\n oneSecond\n), '1 second');\n\ntest(readableTime(\n oneDayTwelveSeconds\n), '1 day, 12 seconds');"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
175,579
|
<p>What are they and how do they work?</p>
<p>Context happens to be SQL Server</p>
|
[
{
"answer_id": 175630,
"author": "John Nilsson",
"author_id": 24243,
"author_profile": "https://Stackoverflow.com/users/24243",
"pm_score": 4,
"selected": false,
"text": "echo \"test\" | wc\n mkdnod apipe p\nwc apipe\n echo \"test\" > apipe\n"
},
{
"answer_id": 175654,
"author": "John Mulder",
"author_id": 2242,
"author_profile": "https://Stackoverflow.com/users/2242",
"pm_score": 5,
"selected": false,
"text": "mkfifo myPipe \n #include <sys/types.h>\n#include <sys/stat.h>\nint mkfifo(const char *pathname, mode_t mode);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3208/"
] |
175,621
|
<p>I want completely automated integration testing for a Maven project. The integration tests require that an external (platform-dependent) program is started before running. Ideally, the external program would be killed after the unit tests are finished, but is not necessary. </p>
<p>Is there a Maven plugin to accomplish this? Other ideas?</p>
|
[
{
"answer_id": 175664,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 3,
"selected": true,
"text": "<plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-antrun-plugin</artifactId>\n <version>1.2</version>\n <executions>\n <execution>\n <phase> <!-- a lifecycle phase --> </phase>\n <configuration>\n\n <tasks>\n <apply os=\"unix\" executable=\"cmd\">\n <arg value=\"/c\"/>\n <arg value=\"ant.bat\"/>\n <arg value=\"-p\"/>\n </apply>\n <apply os=\"windows\" executable=\"cmd.exe\">\n <arg value=\"/c\"/>\n <arg value=\"ant.bat\"/>\n <arg value=\"-p\"/>\n </apply>\n </tasks>\n\n </configuration>\n <goals>\n <goal>run</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n"
},
{
"answer_id": 176345,
"author": "heckj",
"author_id": 19477,
"author_profile": "https://Stackoverflow.com/users/19477",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\"?><project>\n <parent>\n <artifactId>maven-example</artifactId>\n <groupId>com.jheck</groupId>\n <version>1.5.0.4-SNAPSHOT</version>\n </parent>\n <modelVersion>4.0.0</modelVersion>\n <groupId>com.jheck.example</groupId>\n <artifactId>functional-test</artifactId>\n <name>Example Functional Test</name>\n <packaging>pom</packaging>\n\n <dependencies>\n <dependency>\n <groupId>com.jheck.example</groupId>\n <artifactId>example-war</artifactId>\n <type>war</type>\n <scope>provided</scope>\n <version>LATEST</version>\n </dependency>\n <dependency>\n <groupId>httpunit</groupId>\n <artifactId>httpunit</artifactId>\n <version>1.6.1</version>\n <scope>test</scope>\n </dependency>\n </dependencies>\n\n <build>\n <plugins>\n\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <executions>\n <execution>\n <goals>\n <goal>testCompile</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-surefire-plugin</artifactId>\n <executions>\n <execution>\n <phase>integration-test</phase>\n <goals>\n <goal>test</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n\n <plugin>\n <groupId>org.codehaus.cargo</groupId>\n <artifactId>cargo-maven2-plugin</artifactId>\n <version>0.3</version>\n <configuration>\n <wait>false</wait> <!-- don't pause on launching tomcat... -->\n <container>\n <containerId>tomcat5x</containerId>\n <log>${project.build.directory}/cargo.log</log>\n <zipUrlInstaller>\n <!--\n <url>http://www.apache.org/dist/tomcat/tomcat-5/v5.0.30/bin/jakarta-tomcat-5.0.30.zip</url>\n -->\n <!-- better be using Java 1.5... -->\n <url>http://www.apache.org/dist/tomcat/tomcat-5/v5.5.26/bin/apache-tomcat-5.5.26.zip</url>\n\n <installDir>${installDir}</installDir>\n </zipUrlInstaller>\n </container>\n <configuration>\n <!-- where the running instance will be deployed for testing -->\n <home>${project.build.directory}/tomcat5x/container</home>\n </configuration>\n </configuration>\n\n <executions>\n <execution>\n <id>start-container</id>\n <phase>pre-integration-test</phase>\n <goals>\n <goal>start</goal>\n <goal>deploy</goal>\n </goals>\n <configuration>\n <deployer>\n <deployables>\n <deployable>\n <groupId>com.jheck.example</groupId>\n <artifactId>example-war</artifactId>\n <type>war</type>\n <!-- <properties>\n <plan>${basedir}/src/deployment/geronima.plan.xml</plan>\n </properties> -->\n <pingURL>http://localhost:8080/example-war</pingURL>\n </deployable>\n </deployables>\n </deployer>\n </configuration>\n </execution>\n <execution>\n <id>stop-container</id>\n <phase>post-integration-test</phase>\n <goals>\n <goal>stop</goal>\n </goals>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n\n</project>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12880/"
] |
175,649
|
<p>I'm working on a project where I have 2 web services that need the same entity. The 2 web services are on the same server so on the back-end, they share the same classes. </p>
<p>On the front-end side, my code consumes <em>both</em> web services and sees the entities from both services as separate (in different namespaces) so I can't use the entity across both services.</p>
<p>Does anyone know of a way to allow this to work in .NET 2.0?</p>
<p>I've done this with my entity: </p>
<pre><code>[XmlType(TypeName = "Class1", Namespace = "myNamespace")]
public class Class1
{
public int field;
}
</code></pre>
<p>Hoping that my IDE would somehow "know" that the class is the same on both web services so that it wouldn't create separate entities for both classes, but no luck.</p>
<p>Is this possible to do with .NET 2.0 web services?</p>
|
[
{
"answer_id": 175855,
"author": "Panos",
"author_id": 8049,
"author_profile": "https://Stackoverflow.com/users/8049",
"pm_score": 3,
"selected": true,
"text": "wsdl.exe wsdl.exe /sharetypes http://localhost/MyService1.asmx?wsdl http://localhost/MyService2.asmx?wsdl\n /sharetypes"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175649",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
175,655
|
<p>We recently had a problem where, after a series of commits had occurred, a backend process failed to run. Now, we were good little boys and girls and ran <code>rake test</code> after every check-in but, due to some oddities in Rails' library loading, it only occurred when we ran it directly from Mongrel in production mode.</p>
<p>I tracked the bug down and it was due to a new Rails gem overwriting a method in the String class in a way that broke one narrow use in the runtime Rails code.</p>
<p>Anyway, long story short, is there a way, at runtime, to ask Ruby where a method has been defined? Something like <code>whereami( :foo )</code> that returns <code>/path/to/some/file.rb line #45</code>? In this case, telling me that it was defined in class String would be unhelpful, because it was overloaded by some library. </p>
<p>I cannot guarantee the source lives in my project, so grepping for <code>'def foo'</code> won't necessarily give me what I need, not to mention if I have <em>many</em> <code>def foo</code>'s, sometimes I don't know until runtime which one I may be using.</p>
|
[
{
"answer_id": 175947,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 3,
"selected": false,
"text": "nil ArgumentError NoMethodError"
},
{
"answer_id": 176006,
"author": "AShelly",
"author_id": 10396,
"author_profile": "https://Stackoverflow.com/users/10396",
"pm_score": 2,
"selected": false,
"text": " class String\n def String.method_added(name)\n if (name==:foo)\n puts \"defining #{name} in:\\n\\t\"\n puts caller.join(\"\\n\\t\")\n end\n end\n end\n ruby -r foo_finder.rb railsapp\n"
},
{
"answer_id": 177285,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "caller()"
},
{
"answer_id": 660129,
"author": "wesgarrison",
"author_id": 62140,
"author_profile": "https://Stackoverflow.com/users/62140",
"pm_score": 10,
"selected": true,
"text": "# How to find out where a method comes from.\n# Learned this from Dave Thomas while teaching Advanced Ruby Studio\n# Makes the case for separating method definitions into\n# modules, especially when enhancing built-in classes.\nmodule Perpetrator\n def crime\n end\nend\n\nclass Fixnum\n include Perpetrator\nend\n\np 2.method(:crime) # The \"2\" here is an instance of Fixnum.\n#<Method: Fixnum(Perpetrator)#crime>\n source_location require 'csv'\n\np CSV.new('string').method(:flock)\n# => #<Method: CSV#flock>\n\nCSV.new('string').method(:flock).source_location\n# => [\"/path/to/ruby/1.9.2-p290/lib/ruby/1.9.1/forwardable.rb\", 180]\n __file__ __line__"
},
{
"answer_id": 2836679,
"author": "tig",
"author_id": 96823,
"author_profile": "https://Stackoverflow.com/users/96823",
"pm_score": 2,
"selected": false,
"text": "set_trace_func proc{ |event, file, line, id, binding, classname|\n printf \"%8s %s:%-2d %10s %8s\\n\", event, file, line, id, classname\n}\n# call your method\nset_trace_func nil\n"
},
{
"answer_id": 3564633,
"author": "James Adam",
"author_id": 125773,
"author_profile": "https://Stackoverflow.com/users/125773",
"pm_score": 6,
"selected": false,
"text": "__file__ __line__ Method require 'rubygems'\nrequire 'activesupport'\n\nm = 2.days.method(:ago)\n# => #<Method: Fixnum(ActiveSupport::CoreExtensions::Numeric::Time)#ago>\n\nm.__file__\n# => \"/Users/james/.rvm/gems/ree-1.8.7-2010.01/gems/activesupport-2.3.8/lib/active_support/core_ext/numeric/time.rb\"\nm.__line__\n# => 64\n source_location require 'active_support/all'\nm = 2.days.method(:ago)\n# => #<Method: Fixnum(Numeric)#ago> # comes from the Numeric module\n\nm.source_location # show file and line\n# => [\"/var/lib/gems/1.9.1/gems/activesupport-3.0.6/.../numeric/time.rb\", 63]\n"
},
{
"answer_id": 9356057,
"author": "Alex D",
"author_id": 960828,
"author_profile": "https://Stackoverflow.com/users/960828",
"pm_score": 5,
"selected": false,
"text": "Method#owner class A; def hello; puts \"hello\"; end end\nclass B < A; end\nb = B.new\nb.method(:hello).owner\n=> A\n"
},
{
"answer_id": 13015691,
"author": "Laas",
"author_id": 465345,
"author_profile": "https://Stackoverflow.com/users/465345",
"pm_score": 4,
"selected": false,
"text": "m = Foo::Bar.method(:create)\n source_location m.source_location\n ActiveRecord::Base#validates ActiveRecord::Base.method(:validates).source_location\n# => [\"/Users/laas/.rvm/gems/ruby-1.9.2-p0@arveaurik/gems/activemodel-3.2.2/lib/active_model/validations/validates.rb\", 81]\n source_location where_is(ActiveRecord::Base, :validates)\n\n# => [\"/Users/laas/.rvm/gems/ruby-1.9.2-p0@arveaurik/gems/activemodel-3.2.2/lib/active_model/validations/validates.rb\", 81]\n"
},
{
"answer_id": 38368482,
"author": "Samda",
"author_id": 2547201,
"author_profile": "https://Stackoverflow.com/users/2547201",
"pm_score": 3,
"selected": false,
"text": "#source_location ModelName.method(:has_one).source_location\n [project_path/vendor/ruby/version_number/gems/activerecord-number/lib/active_record/associations.rb\", line_number_of_where_method_is]\n ModelName.new.method(:valid?).source_location\n [project_path/vendor/ruby/version_number/gems/activerecord-number/lib/active_record/validations.rb\", line_number_of_where_method_is]\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2590/"
] |
175,684
|
<p>I have currently 200+ GB database that is using the DB2 built in backup to do a daily backup (and hopefully not restore - lol) But since that backup now takes more than 2.5 hours to complete I am looking into a Third party Backup and Restore utility. The version is 8.2 FP 14 But I will be moving soon to 9.1 and I also have some 9.5 databases to backup and restore. What are the best tools that you have used for this purpose?</p>
<p>Thanks!</p>
|
[
{
"answer_id": 199131,
"author": "Antonio Cangiano",
"author_id": 6551,
"author_profile": "https://Stackoverflow.com/users/6551",
"pm_score": 2,
"selected": false,
"text": "db2 backup db mydb /mnt/disk1 /mnt/disk2 /mnt/disk3 ... WITH num_buffers BUFFERS BUFFER buffer-size PARALLELISM n UTIL_IMPACT_PRIORITY UTIL_IMPACT_LIM"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6788/"
] |
175,689
|
<p>I know you can use C++ keyword 'explicit' for constructors of classes to prevent an automatic conversion of type. Can you use this same command to prevent the conversion of parameters for a class method?</p>
<p>I have two class members, one which takes a bool as a param, the other an unsigned int. When I called the function with an int, the compiler converted the param to a bool and called the wrong method. I know eventually I'll replace the bool, but for now don't want to break the other routines as this new routine is developed.</p>
|
[
{
"answer_id": 175759,
"author": "Lev",
"author_id": 7224,
"author_profile": "https://Stackoverflow.com/users/7224",
"pm_score": 4,
"selected": false,
"text": "explicit"
},
{
"answer_id": 175926,
"author": "Patrick Johnmeyer",
"author_id": 363,
"author_profile": "https://Stackoverflow.com/users/363",
"pm_score": 7,
"selected": true,
"text": "delete #include <iostream>\n\nstruct Thing {\n void Foo(int value) {\n std::cout << \"Foo: value\" << std::endl;\n }\n\n template <typename T>\n void Foo(T value) = delete;\n};\n Thing::Foo size_t error: use of deleted function\n ‘void Thing::Foo(T) [with T = long unsigned int]’\n class ClassThatOnlyTakesBoolsAndUIntsAsArguments\n{\npublic:\n // Assume definitions for these exist elsewhere\n void Method(bool arg1);\n void Method(unsigned int arg1);\n\n // Below just an example showing how to do the same thing with more arguments\n void MethodWithMoreParms(bool arg1, SomeType& arg2);\n void MethodWithMoreParms(unsigned int arg1, SomeType& arg2);\n\nprivate:\n // You can leave these undefined\n template<typename T>\n void Method(T arg1);\n\n // Below just an example showing how to do the same thing with more arguments\n template<typename T>\n void MethodWithMoreParms(T arg1, SomeType& arg2);\n};\n bool unsigned int Method bool unsigned int"
},
{
"answer_id": 176181,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "foo<>() bool unsigned int int main() int foo<int>() foo( 1) int \"U\" int \"U\" unsigned int unsigned int #include <stdio.h>\n\ntemplate <typename T>\nvoid foo( T);\n\ntemplate <>\nvoid foo<bool>( bool x)\n{\n printf( \"foo( bool)\\n\");\n}\n\n\ntemplate <>\nvoid foo<unsigned int>( unsigned int x)\n{\n printf( \"foo( unsigned int)\\n\");\n}\n\n\ntemplate <>\nvoid foo<int>( int x)\n{\n printf( \"foo( int)\\n\");\n}\n\n\n\nint main () \n{\n foo( true);\n foo( false);\n foo( static_cast<unsigned int>( 0));\n foo( 0U);\n foo( 1U);\n foo( 2U);\n foo( 0);\n foo( 1);\n foo( 2);\n}\n"
},
{
"answer_id": 176248,
"author": "Richard Corden",
"author_id": 11698,
"author_profile": "https://Stackoverflow.com/users/11698",
"pm_score": 3,
"selected": false,
"text": "template <typename V, class D> \nclass StrongType\n{\npublic:\n inline explicit StrongType(V const &v)\n : m_v(v)\n {}\n\n inline operator V () const\n {\n return m_v;\n }\n\nprivate:\n V m_v; // use V as \"inner\" type\n};\n\nclass Tag1;\ntypedef StrongType<int, Tag1> Tag1Type;\n\n\nvoid b1 (Tag1Type);\n\nvoid b2 (int i)\n{\n b1 (Tag1Type (i));\n b1 (i); // Error\n}\n class WidthTag;\ntypedef StrongType<int, WidthTag> Width; \nclass HeightTag;\ntypedef StrongType<int, HeightTag> Height; \n\nvoid foo (Width width, Height height);\n"
},
{
"answer_id": 58020805,
"author": "Apollys supports Monica",
"author_id": 7022459,
"author_profile": "https://Stackoverflow.com/users/7022459",
"pm_score": 1,
"selected": false,
"text": "delete #include <iostream>\n\nstruct Thing {\n void Foo(int value) {\n std::cout << \"Foo: value\" << std::endl;\n }\n\n template <typename T>\n void Foo(T value) = delete;\n};\n\nint main() {\n Thing t;\n int int_value = 1;\n size_t size_t_value = 2;\n\n t.Foo(int_value);\n\n // t.Foo(size_t_value); // fails with below error\n // error: use of deleted function\n // ‘void Thing::Foo(T) [with T = long unsigned int]’\n\n return 0;\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16496/"
] |
175,690
|
<p>I know I could just ask, but that would involve bureaucratic entanglements.</p>
|
[
{
"answer_id": 175701,
"author": "jj33",
"author_id": 430,
"author_profile": "https://Stackoverflow.com/users/430",
"pm_score": 0,
"selected": false,
"text": "C:\\Documents and Settings\\jj33>nslookup companyname.ad\nServer: palpatine.companyname.ad\nAddress: 172.19.1.3\n\nName: companyname.ad\nAddresses: 172.16.3.2, 172.16.6.2, 172.19.1.3, 172.16.7.9\n 172.19.1.14, 172.19.1.11\nC:\\Documents and Settings\\jj33>\n"
},
{
"answer_id": 175709,
"author": "VolkA",
"author_id": 25472,
"author_profile": "https://Stackoverflow.com/users/25472",
"pm_score": 2,
"selected": false,
"text": "_ldap._tcp.*\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
] |
175,695
|
<p>How can I represent the following in XSD.</p>
<pre><code><price-update>
<![CDATA[
arbitrary data goes here
]]>
</price-update>
</code></pre>
|
[
{
"answer_id": 175706,
"author": "Oliver Hallam",
"author_id": 19995,
"author_profile": "https://Stackoverflow.com/users/19995",
"pm_score": 5,
"selected": false,
"text": "<doc>value</doc>\n <doc><![CDATA[value]]></doc>\n"
},
{
"answer_id": 175866,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 6,
"selected": true,
"text": "<element name=\"price-update\" type=\"string\"></element> \n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21297/"
] |
175,696
|
<p>I'm looking for the class name of the popup/message windows on the iPhone (it's a blueish window that comes up when you have a missed call, or a message comes in for example.)</p>
|
[
{
"answer_id": 175700,
"author": "lajos",
"author_id": 3740,
"author_profile": "https://Stackoverflow.com/users/3740",
"pm_score": 4,
"selected": true,
"text": "UIAlertView"
},
{
"answer_id": 178889,
"author": "davidmytton",
"author_id": 2183,
"author_profile": "https://Stackoverflow.com/users/2183",
"pm_score": 1,
"selected": false,
"text": "UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@\"Message\" message:nil delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles: nil] autorelease];\n\n[alert show];\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3740/"
] |
175,717
|
<p>This is something that I have never fully grasped in .NET as to the correct application of the .dispose() method.</p>
<p>Say I have something like</p>
<pre><code>Public Class someClass()
sub someMethod
' do some stuff tying up resources
end sub
End Class
public class mainApp
dim _class as new SomeClass
_class.someMethod()
End Class
</code></pre>
<p>In all cases is it good practice to implement a dispose method, and if so what should go in there?</p>
<p>If it is not the case that every class should have dispose method (which my gut feeling says the shouldn't) what classes should? I have always thought anything which may tie up a resource (i.e. connection, datareader etc) should have a .dispose() which would unallocate these resources. </p>
<p>Also how would you enforce a calling into calling the .dispose() method?</p>
|
[
{
"answer_id": 175722,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": "Dispose() Using"
},
{
"answer_id": 175731,
"author": "user7116",
"author_id": 7116,
"author_profile": "https://Stackoverflow.com/users/7116",
"pm_score": 4,
"selected": true,
"text": "Public Class someClass()\n sub someMethod\n Using someResource As New ResourceType( arguments )\n ' no worries about IDisposable for someResource, as it is automatic\n End Using\n end sub\nEnd Class\n"
},
{
"answer_id": 175802,
"author": "Nick",
"author_id": 22407,
"author_profile": "https://Stackoverflow.com/users/22407",
"pm_score": 1,
"selected": false,
"text": "public class Foo : IDisposable\n{\n public Foo()\n {\n // Allocate some resource here\n }\n\n ~Foo()\n {\n Dispose( false );\n }\n\n public void Dispose()\n {\n Dispose( true );\n }\n\n private void Dispose( bool disposing )\n {\n // De-allocate resource here\n if ( disposing )\n GC.SuppressFinalize( this );\n }\n}\n using ( Foo f = new Foo() )\n{\n // Do something with Foo\n}\n Foo f;\ntry\n{\n f = new Foo();\n // Do something with Foo\n}\nfinally\n{\n f.Dispose();\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11802/"
] |
175,723
|
<p>I have a form where controls are dynamically added to a Panel. However, when they do so, they are many times added below the fold (bottom of the container). It's nice that the .NET Framework provides this ScrollControlIntoView method, however, for added usability, it would also be nice if there was an easy way to animate so that it is easy for the user to understand that the Panel was automatically scrolled.</p>
<p>Has anyone ever encountered this or have any ideas as to how to tackle it?</p>
|
[
{
"answer_id": 175722,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": "Dispose() Using"
},
{
"answer_id": 175731,
"author": "user7116",
"author_id": 7116,
"author_profile": "https://Stackoverflow.com/users/7116",
"pm_score": 4,
"selected": true,
"text": "Public Class someClass()\n sub someMethod\n Using someResource As New ResourceType( arguments )\n ' no worries about IDisposable for someResource, as it is automatic\n End Using\n end sub\nEnd Class\n"
},
{
"answer_id": 175802,
"author": "Nick",
"author_id": 22407,
"author_profile": "https://Stackoverflow.com/users/22407",
"pm_score": 1,
"selected": false,
"text": "public class Foo : IDisposable\n{\n public Foo()\n {\n // Allocate some resource here\n }\n\n ~Foo()\n {\n Dispose( false );\n }\n\n public void Dispose()\n {\n Dispose( true );\n }\n\n private void Dispose( bool disposing )\n {\n // De-allocate resource here\n if ( disposing )\n GC.SuppressFinalize( this );\n }\n}\n using ( Foo f = new Foo() )\n{\n // Do something with Foo\n}\n Foo f;\ntry\n{\n f = new Foo();\n // Do something with Foo\n}\nfinally\n{\n f.Dispose();\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21807/"
] |
175,726
|
<p>c# windows forms: How do you create new settings at run time so that they are permanently saved as Settings.Default.-- values?</p>
|
[
{
"answer_id": 1236190,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "RegistryKey ProgSettings = Registry.CurrentUser.OpenSubKey(\"Software\", true);\nProgSettings.CreateSubKey(\"Your Program settings\"); \nProgSettings.Close();\n RegistryKey ProgSettings = Registry.CurrentUser.OpenSubKey(\"Software\\\\Your Program settings\", true);\nProgSettings.SetValue(\"Setting Name\", value); // store settings \nstring settings = ProgSettings.GetValue(\"Setting Name\", false); // retreave settings \nProgSettings.DeleteValue(\"Setting Name\", false);\n"
},
{
"answer_id": 2143936,
"author": "Tom Wilson",
"author_id": 259706,
"author_profile": "https://Stackoverflow.com/users/259706",
"pm_score": 2,
"selected": false,
"text": "Box1Text=A\nBox1List=abc;def;foo;bar;\nBox2Text=hello\nBox2List=server1;server2;\n foreach (string item in Properties.Settings.Default.ControlData) {\n string[] parts=item.split('=');\n"
},
{
"answer_id": 7608985,
"author": "John",
"author_id": 972892,
"author_profile": "https://Stackoverflow.com/users/972892",
"pm_score": 4,
"selected": false,
"text": "Settings.Default.Properties.Add(...) Settings.Default.Properties // create new setting from a base setting:\nvar property = new SettingsProperty(Settings.Default.Properties[\"<baseSetting>\"]);\nproperty.Name = \"<dynamicSettingName>\";\nSettings.Default.Properties.Add(property);\n// will have the stored value:\nvar dynamicSetting = Settings.Default[\"<dynamicSettingName>\"];\n"
},
{
"answer_id": 10584286,
"author": "Drew Ogle",
"author_id": 1243932,
"author_profile": "https://Stackoverflow.com/users/1243932",
"pm_score": 4,
"selected": false,
"text": "ApplicationSettingsBase settings = passed_in;\nSettingsProvider sp = settings.Providers[\"LocalFileSettingsProvider\"];\nSettingsProperty p = new SettingsProperty(\"your_prop_name\");\nyour_class conf = null;\np.PropertyType = typeof( your_class );\np.Attributes.Add(typeof(UserScopedSettingAttribute),new UserScopedSettingAttribute());\np.Provider = sp;\np.SerializeAs = SettingsSerializeAs.Xml;\nSettingsPropertyValue v = new SettingsPropertyValue( p );\nsettings.Properties.Add( p );\n\nsettings.Reload();\nconf = (your_class)settings[\"your_prop_name\"];\nif( conf == null )\n{\n settings[\"your_prop_name\"] = conf = new your_class();\n settings.Save();\n}\n"
},
{
"answer_id": 62154988,
"author": "Girl Spider",
"author_id": 5481566,
"author_profile": "https://Stackoverflow.com/users/5481566",
"pm_score": 1,
"selected": false,
"text": " private void FormPersistence_Load(object sender, EventArgs e)\n {\n StartPosition = FormStartPosition.Manual;\n // Set window location\n var exists = Settings.Default.Properties.OfType<SettingsProperty>().Any(p => p.Name == Name + \"Location\");\n if (exists)\n {\n this.Location = (Point)Settings.Default[Name + \"Location\"];\n }\n else\n {\n var property = new SettingsProperty(Settings.Default.Properties[\"baseLocation\"]);\n property.Name = Name + \"Location\";\n Settings.Default.Properties.Add(property);\n Settings.Default.Reload();\n this.Location = (Point)Settings.Default[Name + \"Location\"];\n }\n }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175726",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,733
|
<p>I have two tables in my database, called <em>ratings</em> and <em>movies</em>.</p>
<p><strong>Ratings:</strong></p>
<blockquote>
<p><code>| id | movie_id | rating |</code></p>
</blockquote>
<p><strong>Movies:</strong></p>
<blockquote>
<p><code>| id | title |</code></p>
</blockquote>
<p>A typical movie record might be like this:</p>
<blockquote>
<p><code>| 4 | Cloverfield (2008) |</code></p>
</blockquote>
<p>and there may be several rating records for Cloverfield, like this:</p>
<blockquote>
<p><code>| 21 | 4 | 3 |</code> (rating number 21, on movie number 4, giving it a rating of 3)</p>
<p><code>| 22 | 4 | 2 |</code> (rating number 22, on movie number 4, giving it a rating of 2)</p>
<p><code>| 23 | 4 | 5 |</code> (rating number 23k on movie number 4, giving it a rating of 5)</p>
</blockquote>
<p><strong>The question:</strong></p>
<p>How do I create a JOIN query for only selecting the rows in the movie table that have more than <code>x</code> number of ratings in the ratings table? For example, in the above example if Cloverfield only had one rating in the ratings table and <code>x</code> was 2, it would not be selected.</p>
<p>Thanks for any help or advice!</p>
|
[
{
"answer_id": 175743,
"author": "ceejayoz",
"author_id": 1902010,
"author_profile": "https://Stackoverflow.com/users/1902010",
"pm_score": 4,
"selected": true,
"text": "SELECT movies.id, movies.title, COUNT(ratings.id) AS num_ratings \n FROM movies \n LEFT JOIN ratings ON ratings.movie_id=movies.id \n GROUP BY movies.id \n HAVING num_ratings > 5;\n"
},
{
"answer_id": 175801,
"author": "Jeff Mc",
"author_id": 25521,
"author_profile": "https://Stackoverflow.com/users/25521",
"pm_score": 2,
"selected": false,
"text": "SELECT * FROM movies \nINNER JOIN\n(SELECT movie_id, COUNT(*) as num_ratings from ratings GROUP BY movie_id) as movie_counts\nON movies.id = movie_counts.movie_id\nWHERE num_ratings > 3;\n"
},
{
"answer_id": 175824,
"author": "Matt Rogish",
"author_id": 2590,
"author_profile": "https://Stackoverflow.com/users/2590",
"pm_score": 2,
"selected": false,
"text": "SELECT whatever\n FROM movies m\n WHERE EXISTS( SELECT COUNT(*) \n FROM reviews\n WHERE movie_id = m.id\n HAVING COUNT(*) > xxxxxxxx )\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/326176/"
] |
175,739
|
<p>I'm hoping there's something in the same conceptual space as the old VB6 <code>IsNumeric()</code> function?</p>
|
[
{
"answer_id": 175775,
"author": "roenving",
"author_id": 23142,
"author_profile": "https://Stackoverflow.com/users/23142",
"pm_score": 6,
"selected": false,
"text": "var num = \"987238\";\n\nif(num.match(/^-?\\d+$/)){\n //valid integer (positive or negative)\n}else if(num.match(/^\\d+\\.\\d+$/)){\n //valid float\n}else{\n //not valid number\n}\n"
},
{
"answer_id": 175787,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 13,
"selected": true,
"text": ". function isNumeric(str) {\n if (typeof str != \"string\") return false // we only process strings! \n return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...\n !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail\n}\n isNaN(num) // returns true if the variable does NOT contain a valid number\n isNaN(123) // false\nisNaN('123') // false\nisNaN('1e10000') // false (This translates to Infinity, which is a number)\nisNaN('foo') // true\nisNaN('10px') // true\nisNaN('') // false\nisNaN(' ') // false\nisNaN(false) // false\n IsNumeric function isNumeric(num){\n return !isNaN(num)\n}\n NaN +num // returns the numeric value of the string, or NaN \n // if the string isn't purely numeric characters\n +'12' // 12\n+'12.' // 12\n+'12..' // NaN\n+'.12' // 0.12\n+'..12' // NaN\n+'foo' // NaN\n+'12px' // NaN\n parseInt(num) // extracts a numeric value from the \n // start of the string, or NaN.\n parseInt('12') // 12\nparseInt('aaa') // NaN\nparseInt('12px') // 12\nparseInt('foo2') // NaN These last three may\nparseInt('12a5') // 12 be different from what\nparseInt('0x10') // 16 you expected to see.\n +num parseInt parseInt() +'12.345' // 12.345\nparseInt(12.345) // 12\nparseInt('12.345') // 12\n +num isNaN() +'' // 0\n+' ' // 0\nisNaN('') // false\nisNaN(' ') // false\n parseInt() parseInt('') // NaN\nparseInt(' ') // NaN\n"
},
{
"answer_id": 9776169,
"author": "Rafael",
"author_id": 1279325,
"author_profile": "https://Stackoverflow.com/users/1279325",
"pm_score": 2,
"selected": false,
"text": "function checkNumber(value) {\n return value % 1 == 0;\n}\n"
},
{
"answer_id": 10844900,
"author": "Siubear",
"author_id": 711801,
"author_profile": "https://Stackoverflow.com/users/711801",
"pm_score": 2,
"selected": false,
"text": "var num = /^\\d+$/.test(num)\n"
},
{
"answer_id": 19135863,
"author": "mark",
"author_id": 80002,
"author_profile": "https://Stackoverflow.com/users/80002",
"pm_score": 4,
"selected": false,
"text": "!isNaN('1e+30') true 1e+30 > var s = Array(16 + 1).join('9')\nundefined\n> s.length\n16\n> s\n'9999999999999999'\n> !isNaN(s)\ntrue\n> Number(s)\n10000000000000000\n> String(Number(s)) === s\nfalse\n>\n > var s = Array(16 + 1).join('1')\nundefined\n> String(Number(s)) === s\ntrue\n> var s = Array(15 + 1).join('9')\nundefined\n> String(Number(s)) === s\ntrue\n>\n String(Number(s)) === s > typeof Infinity\n'number'\n> !isNaN('Infinity')\ntrue\n> isFinite('Infinity')\nfalse\n>\n Number String function isNonScientificNumberString(o) {\n if (!o || typeof o !== 'string') {\n // Should not be given anything but strings.\n return false;\n }\n return o.length <= 15 && o.indexOf('e+') < 0 && o.indexOf('E+') < 0 && !isNaN(o) && isFinite(o);\n }\n"
},
{
"answer_id": 23389525,
"author": "Predhin",
"author_id": 1122656,
"author_profile": "https://Stackoverflow.com/users/1122656",
"pm_score": 2,
"selected": false,
"text": " function(check){ \n check = check + \"\";\n var isNumber = check.trim().length>0? !isNaN(check):false;\n return isNumber;\n }\n"
},
{
"answer_id": 24457420,
"author": "Gavin",
"author_id": 2211053,
"author_profile": "https://Stackoverflow.com/users/2211053",
"pm_score": 7,
"selected": false,
"text": "isNaN function isNumeric(value) {\n return /^-?\\d+$/.test(value);\n}\n\nconsole.log(isNumeric('abcd')); // false\nconsole.log(isNumeric('123a')); // false\nconsole.log(isNumeric('1')); // true\nconsole.log(isNumeric('1234567890')); // true\nconsole.log(isNumeric('-23')); // true\nconsole.log(isNumeric(1234)); // true\nconsole.log(isNumeric(1234n)); // true\nconsole.log(isNumeric('123.4')); // false\nconsole.log(isNumeric('')); // false\nconsole.log(isNumeric(undefined)); // false\nconsole.log(isNumeric(null)); // false\n function isNumeric(value) {\n return /^\\d+$/.test(value);\n}\n\nconsole.log(isNumeric('123')); // true\nconsole.log(isNumeric('-23')); // false\n"
},
{
"answer_id": 24635695,
"author": "rwheadon",
"author_id": 396988,
"author_profile": "https://Stackoverflow.com/users/396988",
"pm_score": 0,
"selected": false,
"text": "function isStringNumeric(str_input){ \n //concat a temporary 1 during the modulus to keep a beginning hex switch combination from messing us up \n //very simple and as long as special characters (non a-z A-Z 0-9) are trapped it is fine \n return '1'.concat(str_input) % 1 === 0;}\n"
},
{
"answer_id": 25193433,
"author": "GoTo",
"author_id": 832370,
"author_profile": "https://Stackoverflow.com/users/832370",
"pm_score": 0,
"selected": false,
"text": "// returns true for positive ints; \n// no scientific notation, hexadecimals or floating point dots\n\nvar isPositiveInt = function(str) { \n var result = true, chr;\n for (var i = 0, n = str.length; i < n; i++) {\n chr = str.charAt(i);\n if ((chr < \"0\" || chr > \"9\") && chr != \",\") { //not digit or thousands separator\n result = false;\n break;\n };\n if (i == 0 && (chr == \"0\" || chr == \",\")) { //should not start with 0 or ,\n result = false;\n break;\n };\n };\n return result;\n };\n"
},
{
"answer_id": 26343042,
"author": "Murray Lang",
"author_id": 4138008,
"author_profile": "https://Stackoverflow.com/users/4138008",
"pm_score": -1,
"selected": false,
"text": "function isString(value)\n{\n return value.length !== undefined;\n}\nfunction isNumber(value)\n{\n return value.NaN !== undefined;\n}\n"
},
{
"answer_id": 29028824,
"author": "GibboK",
"author_id": 379008,
"author_profile": "https://Stackoverflow.com/users/379008",
"pm_score": 4,
"selected": false,
"text": "'\\t\\t' '\\n\\t' Number('34.00') // 34\n Number('-34') // -34\n Number('123e5') // 12300000\n Number('123e-5') // 0.00123\n Number('999999999999') // 999999999999\n Number('9999999999999999') // 10000000000000000 (integer accuracy up to 15 digit)\n Number('0xFF') // 255\n Number('Infinity') // Infinity \n\n Number('34px') // NaN\n Number('xyz') // NaN\n Number('true') // NaN\n Number('false') // NaN\n\n // cavets\n Number(' ') // 0\n Number('\\t\\t') // 0\n Number('\\n\\t') // 0\n"
},
{
"answer_id": 32539708,
"author": "Endless",
"author_id": 1008999,
"author_profile": "https://Stackoverflow.com/users/1008999",
"pm_score": 0,
"selected": false,
"text": "function isInt(a){\n return a === \"\"+~~a\n}\n\n\nconsole.log(isInt('abcd')); // false\nconsole.log(isInt('123a')); // false\nconsole.log(isInt('1')); // true\nconsole.log(isInt('0')); // true\nconsole.log(isInt('-0')); // false\nconsole.log(isInt('01')); // false\nconsole.log(isInt('10')); // true\nconsole.log(isInt('-1234567890')); // true\nconsole.log(isInt(1234)); // false\nconsole.log(isInt('123.4')); // false\nconsole.log(isInt('')); // false\n\n// other types then string returns false\nconsole.log(isInt(5)); // false\nconsole.log(isInt(undefined)); // false\nconsole.log(isInt(null)); // false\nconsole.log(isInt('0x1')); // false\nconsole.log(isInt(Infinity)); // false\n"
},
{
"answer_id": 35759874,
"author": "Michael",
"author_id": 543873,
"author_profile": "https://Stackoverflow.com/users/543873",
"pm_score": 6,
"selected": false,
"text": "parseInt() parseFloat() Number() !isNaN() !isNaN() true Number() false NaN parseFloat() parseFloat(\"2016-12-31\") // returns 2016\nparseFloat(\"1-1\") // return 1\nparseFloat(\"1.2.3\") // returns 1.2\n Number() Number(\"\") // returns 0\nNumber(\" \") // returns 0\nNumber(\" \\u00A0 \\t\\n\\r\") // returns 0\n Number() isNaN() parseFloat() function isNumber(str) {\n if (typeof str != \"string\") return false // we only process strings!\n // could also coerce to string: str = \"\"+str\n return !isNaN(str) && !isNaN(parseFloat(str))\n}\n"
},
{
"answer_id": 41458529,
"author": "The Dembinski",
"author_id": 5689384,
"author_profile": "https://Stackoverflow.com/users/5689384",
"pm_score": 2,
"selected": false,
"text": "function isNumeric(val) {\n var _val = +val;\n return (val !== val + 1) //infinity check\n && (_val === +val) //Cute coercion check\n && (typeof val !== 'object') //Array/object check\n}\n isNumeric(\"1\"))\nisNumeric(1e10))\nisNumeric(1E10))\nisNumeric(+\"6e4\"))\nisNumeric(\"1.2222\"))\nisNumeric(\"-1.2222\"))\nisNumeric(\"-1.222200000000000000\"))\nisNumeric(\"1.222200000000000000\"))\nisNumeric(1))\nisNumeric(0))\nisNumeric(-0))\nisNumeric(1010010293029))\nisNumeric(1.100393830000))\nisNumeric(Math.LN2))\nisNumeric(Math.PI))\nisNumeric(5e10))\n isNumeric(NaN))\nisNumeric(Infinity))\nisNumeric(-Infinity))\nisNumeric())\nisNumeric(undefined))\nisNumeric('[1,2,3]'))\nisNumeric({a:1,b:2}))\nisNumeric(null))\nisNumeric([1]))\nisNumeric(new Date()))\n isNumeric(new Number(1)) => false\n"
},
{
"answer_id": 41546441,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "if(str === String(Number(str))) {\n // it's a \"perfectly formatted\" number\n}\n .1 40.000 080 00.1 String Number Number"
},
{
"answer_id": 42356340,
"author": "JohnP2",
"author_id": 1691651,
"author_profile": "https://Stackoverflow.com/users/1691651",
"pm_score": 4,
"selected": false,
"text": "function isNumeric(num){\n num = \"\" + num; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n}\n return !isNaN(num);\n return (+num === +num);\n"
},
{
"answer_id": 43979827,
"author": "Ultroman the Tacoman",
"author_id": 1289974,
"author_profile": "https://Stackoverflow.com/users/1289974",
"pm_score": 3,
"selected": false,
"text": "function isNumeric(a) {\n var b = a && a.toString();\n return !$.isArray(a) && b - parseFloat(b) + 1 >= 0;\n};\n function isNumeric(num){\n num = \"\" + num; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n}\n function isNumeric(a) {\n var str = a + \"\";\n var b = a && a.toString();\n return !$.isArray(a) && b - parseFloat(b) + 1 >= 0 &&\n !/^\\s+|\\s+$/g.test(str) &&\n !isNaN(str) && !isNaN(parseFloat(str));\n};\n function isNumeric(a) {\n if ($.isArray(a)) return false;\n var b = a && a.toString();\n a = a + \"\";\n return b - parseFloat(b) + 1 >= 0 &&\n !/^\\s+|\\s+$/g.test(a) &&\n !isNaN(a) && !isNaN(parseFloat(a));\n};\n"
},
{
"answer_id": 47333150,
"author": "What Would Be Cool",
"author_id": 753279,
"author_profile": "https://Stackoverflow.com/users/753279",
"pm_score": 0,
"selected": false,
"text": "// @flow\n\nfunction acceptsNumber(value: number) {\n // ...\n}\n\nacceptsNumber(42); // Works!\nacceptsNumber(3.14); // Works!\nacceptsNumber(NaN); // Works!\nacceptsNumber(Infinity); // Works!\nacceptsNumber(\"foo\"); // Error!\n"
},
{
"answer_id": 47515519,
"author": "lifebalance",
"author_id": 307454,
"author_profile": "https://Stackoverflow.com/users/307454",
"pm_score": 1,
"selected": false,
"text": "sNum // returns True if sNum is a numeric value \n!!sNum && !isNaN(+sNum.replace(/\\s|\\$/g, '')); \n"
},
{
"answer_id": 51056946,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 3,
"selected": false,
"text": "Number.isNaN(Number(value))\n isNotNumber(value: string | number): value is string {\n return Number.isNaN(Number(this.smartImageWidth));\n}\nisNumber(value: string | number): value is number {\n return Number.isNaN(Number(this.smartImageWidth)) === false;\n}\n width number | string var width: number|string;\nwidth = \"100vw\";\n\nif (isNotNumber(width)) \n{\n // the compiler knows that width here must be a string\n if (width.endsWith('vw')) \n {\n // we have a 'width' such as 100vw\n } \n}\nelse \n{\n // the compiler is smart and knows width here must be number\n var doubleWidth = width * 2; \n}\n width if string width.endsWith(...) string | number isNotNumber isNumber isString isNotString isString"
},
{
"answer_id": 52710457,
"author": "Travis Parks",
"author_id": 984335,
"author_profile": "https://Stackoverflow.com/users/984335",
"pm_score": 2,
"selected": false,
"text": "+x ~~x string number trim // Check for a valid float\nif (x == null\n || (\"\" + x).trim() === \"\"\n || isNaN(+x)) {\n return false; // not a float\n}\n\n// Check for a valid integer\nif (x == null\n || (\"\" + x).trim() === \"\"\n || ~~x !== +x) {\n return false; // not an integer\n}\n"
},
{
"answer_id": 52986361,
"author": "Hamzeen Hameem",
"author_id": 4947422,
"author_profile": "https://Stackoverflow.com/users/4947422",
"pm_score": 6,
"selected": false,
"text": "function isNumeric(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n}\n console.log(isNumeric(12345678912345678912)); // true\nconsole.log(isNumeric('2 ')); // true\nconsole.log(isNumeric('-32.2 ')); // true\nconsole.log(isNumeric(-32.2)); // true\nconsole.log(isNumeric(undefined)); // false\n\n// the accepted answer fails at these tests:\nconsole.log(isNumeric('')); // false\nconsole.log(isNumeric(null)); // false\nconsole.log(isNumeric([])); // false\n"
},
{
"answer_id": 53875569,
"author": "cdeutsch",
"author_id": 346259,
"author_profile": "https://Stackoverflow.com/users/346259",
"pm_score": 2,
"selected": false,
"text": "npm install is-number console.log(+[]); //=> 0\nconsole.log(+''); //=> 0\nconsole.log(+' '); //=> 0\nconsole.log(typeof NaN); //=> 'number'\n"
},
{
"answer_id": 54442167,
"author": "gvlax",
"author_id": 988394,
"author_profile": "https://Stackoverflow.com/users/988394",
"pm_score": 2,
"selected": false,
"text": "function isNumberCandidate(s) {\n const str = (''+ s).trim();\n if (str.length === 0) return false;\n return !isNaN(+str);\n}\n\nconsole.log(isNumberCandidate('1')); // true\nconsole.log(isNumberCandidate('a')); // false\nconsole.log(isNumberCandidate('000')); // true\nconsole.log(isNumberCandidate('1a')); // false \nconsole.log(isNumberCandidate('1e')); // false\nconsole.log(isNumberCandidate('1e-1')); // true\nconsole.log(isNumberCandidate('123.3')); // true\nconsole.log(isNumberCandidate('')); // false\nconsole.log(isNumberCandidate(' ')); // false\nconsole.log(isNumberCandidate(1)); // true\nconsole.log(isNumberCandidate(0)); // true\nconsole.log(isNumberCandidate(NaN)); // false\nconsole.log(isNumberCandidate(undefined)); // false\nconsole.log(isNumberCandidate(null)); // false\nconsole.log(isNumberCandidate(-1)); // true\nconsole.log(isNumberCandidate('-1')); // true\nconsole.log(isNumberCandidate('-1.2')); // true\nconsole.log(isNumberCandidate(0.0000001)); // true\nconsole.log(isNumberCandidate('0.0000001')); // true\nconsole.log(isNumberCandidate(Infinity)); // true\nconsole.log(isNumberCandidate(-Infinity)); // true\n\nconsole.log(isNumberCandidate('Infinity')); // true\n\nif (isNumberCandidate(s)) {\n // use +s as a number\n +s ...\n}\n"
},
{
"answer_id": 54460006,
"author": "Alireza",
"author_id": 5423108,
"author_profile": "https://Stackoverflow.com/users/5423108",
"pm_score": -1,
"selected": false,
"text": "isNaN() false isNaN(\"Alireza\"); //return true\nisNaN(\"123\"); //return false\n"
},
{
"answer_id": 54997869,
"author": "haxpanel",
"author_id": 789076,
"author_profile": "https://Stackoverflow.com/users/789076",
"pm_score": -1,
"selected": false,
"text": "const isNumber = s => !isNaN(+s)\n"
},
{
"answer_id": 55204768,
"author": "Abtin Gramian",
"author_id": 7003429,
"author_profile": "https://Stackoverflow.com/users/7003429",
"pm_score": 3,
"selected": false,
"text": "null // Base cases that are handled properly\nNumber.isNaN(Number('1')); // => false\nNumber.isNaN(Number('-1')); // => false\nNumber.isNaN(Number('1.1')); // => false\nNumber.isNaN(Number('-1.1')); // => false\nNumber.isNaN(Number('asdf')); // => true\nNumber.isNaN(Number(undefined)); // => true\n\n// Special notation cases that are handled properly\nNumber.isNaN(Number('1e1')); // => false\nNumber.isNaN(Number('1e-1')); // => false\nNumber.isNaN(Number('-1e1')); // => false\nNumber.isNaN(Number('-1e-1')); // => false\nNumber.isNaN(Number('0b1')); // => false\nNumber.isNaN(Number('0o1')); // => false\nNumber.isNaN(Number('0xa')); // => false\n\n// Edge cases that will FAIL if not guarded against\nNumber.isNaN(Number('')); // => false\nNumber.isNaN(Number(' ')); // => false\nNumber.isNaN(Number(null)); // => false\n\n// Edge cases that are debatable\nNumber.isNaN(Number('-0b1')); // => true\nNumber.isNaN(Number('-0o1')); // => true\nNumber.isNaN(Number('-0xa')); // => true\nNumber.isNaN(Number('Infinity')); // => false \nNumber.isNaN(Number('INFINITY')); // => true \nNumber.isNaN(Number('-Infinity')); // => false \nNumber.isNaN(Number('-INFINITY')); // => true \n null parseInt // Base cases that are handled properly\nNumber.isNaN(parseInt('1')); // => false\nNumber.isNaN(parseInt('-1')); // => false\nNumber.isNaN(parseInt('1.1')); // => false\nNumber.isNaN(parseInt('-1.1')); // => false\nNumber.isNaN(parseInt('asdf')); // => true\nNumber.isNaN(parseInt(undefined)); // => true\nNumber.isNaN(parseInt('')); // => true\nNumber.isNaN(parseInt(' ')); // => true\nNumber.isNaN(parseInt(null)); // => true\n\n// Special notation cases that are handled properly\nNumber.isNaN(parseInt('1e1')); // => false\nNumber.isNaN(parseInt('1e-1')); // => false\nNumber.isNaN(parseInt('-1e1')); // => false\nNumber.isNaN(parseInt('-1e-1')); // => false\nNumber.isNaN(parseInt('0b1')); // => false\nNumber.isNaN(parseInt('0o1')); // => false\nNumber.isNaN(parseInt('0xa')); // => false\n\n// Edge cases that are debatable\nNumber.isNaN(parseInt('-0b1')); // => false\nNumber.isNaN(parseInt('-0o1')); // => false\nNumber.isNaN(parseInt('-0xa')); // => false\nNumber.isNaN(parseInt('Infinity')); // => true \nNumber.isNaN(parseInt('INFINITY')); // => true \nNumber.isNaN(parseInt('-Infinity')); // => true \nNumber.isNaN(parseInt('-INFINITY')); // => true \n parseFloat // Base cases that are handled properly\nNumber.isNaN(parseFloat('1')); // => false\nNumber.isNaN(parseFloat('-1')); // => false\nNumber.isNaN(parseFloat('1.1')); // => false\nNumber.isNaN(parseFloat('-1.1')); // => false\nNumber.isNaN(parseFloat('asdf')); // => true\nNumber.isNaN(parseFloat(undefined)); // => true\nNumber.isNaN(parseFloat('')); // => true\nNumber.isNaN(parseFloat(' ')); // => true\nNumber.isNaN(parseFloat(null)); // => true\n\n// Special notation cases that are handled properly\nNumber.isNaN(parseFloat('1e1')); // => false\nNumber.isNaN(parseFloat('1e-1')); // => false\nNumber.isNaN(parseFloat('-1e1')); // => false\nNumber.isNaN(parseFloat('-1e-1')); // => false\nNumber.isNaN(parseFloat('0b1')); // => false\nNumber.isNaN(parseFloat('0o1')); // => false\nNumber.isNaN(parseFloat('0xa')); // => false\n\n// Edge cases that are debatable\nNumber.isNaN(parseFloat('-0b1')); // => false\nNumber.isNaN(parseFloat('-0o1')); // => false\nNumber.isNaN(parseFloat('-0xa')); // => false\nNumber.isNaN(parseFloat('Infinity')); // => false \nNumber.isNaN(parseFloat('INFINITY')); // => true \nNumber.isNaN(parseFloat('-Infinity')); // => false \nNumber.isNaN(parseFloat('-INFINITY')); // => true\n Infinity Number Math Number null"
},
{
"answer_id": 56276861,
"author": "Greg Wozniak",
"author_id": 2170368,
"author_profile": "https://Stackoverflow.com/users/2170368",
"pm_score": 3,
"selected": false,
"text": "declare function isNaN(number: number): boolean; /^\\d+$/.test(key)"
},
{
"answer_id": 57478170,
"author": "c7x43t",
"author_id": 9905358,
"author_profile": "https://Stackoverflow.com/users/9905358",
"pm_score": 0,
"selected": false,
"text": "var isNumber = (function () {\n var isIntegerTest = /^\\d+$/;\n var isDigitArray = [!0, !0, !0, !0, !0, !0, !0, !0, !0, !0];\n function hasLeading0s (s) {\n return !(typeof s !== 'string' ||\n s.length < 2 ||\n s[0] !== '0' ||\n !isDigitArray[s[1]] ||\n isIntegerTest.test(s));\n }\n var isWhiteSpaceTest = /\\s/;\n return function isNumber (s) {\n var t = typeof s;\n var n;\n if (t === 'number') {\n return (s <= 0) || (s > 0);\n } else if (t === 'string') {\n n = +s;\n return !((!(n <= 0) && !(n > 0)) || n === '0' || hasLeading0s(s) || !(n !== 0 || !(s === '' || isWhiteSpaceTest.test(s))));\n } else if (t === 'object') {\n return !(!(s instanceof Number) || ((n = +s), !(n <= 0) && !(n > 0)));\n }\n return false;\n };\n})();\n"
},
{
"answer_id": 58550111,
"author": "Jeremy",
"author_id": 4888826,
"author_profile": "https://Stackoverflow.com/users/4888826",
"pm_score": 5,
"selected": false,
"text": "var isNumeric = function(num){\n return (typeof(num) === 'number' || typeof(num) === \"string\" && num.trim() !== '') && !isNaN(num); \n}\n const isNumeric = (num) => (typeof(num) === 'number' || typeof(num) === \"string\" && num.trim() !== '') && !isNaN(num);\n const isNumeric = (num: any) => (typeof(num) === 'number' || typeof(num) === \"string\" && num.trim() !== '') && !isNaN(num as number);\n // Positive Cases\nconsole.log(0, isNumeric(0) === true);\nconsole.log(1, isNumeric(1) === true);\nconsole.log(1234567890, isNumeric(1234567890) === true);\nconsole.log('1234567890', isNumeric('1234567890') === true);\nconsole.log('0', isNumeric('0') === true);\nconsole.log('1', isNumeric('1') === true);\nconsole.log('1.1', isNumeric('1.1') === true);\nconsole.log('-1', isNumeric('-1') === true);\nconsole.log('-1.2354', isNumeric('-1.2354') === true);\nconsole.log('-1234567890', isNumeric('-1234567890') === true);\nconsole.log(-1, isNumeric(-1) === true);\nconsole.log(-32.1, isNumeric(-32.1) === true);\nconsole.log('0x1', isNumeric('0x1') === true); // Valid number in hex\n// Negative Cases\nconsole.log(true, isNumeric(true) === false);\nconsole.log(false, isNumeric(false) === false);\nconsole.log('1..1', isNumeric('1..1') === false);\nconsole.log('1,1', isNumeric('1,1') === false);\nconsole.log('-32.1.12', isNumeric('-32.1.12') === false);\nconsole.log('[blank]', isNumeric('') === false);\nconsole.log('[spaces]', isNumeric(' ') === false);\nconsole.log('null', isNumeric(null) === false);\nconsole.log('undefined', isNumeric(undefined) === false);\nconsole.log([], isNumeric([]) === false);\nconsole.log('NaN', isNumeric(NaN) === false);\n isNumeric"
},
{
"answer_id": 58849715,
"author": "J.P. Duvet",
"author_id": 7807090,
"author_profile": "https://Stackoverflow.com/users/7807090",
"pm_score": 3,
"selected": false,
"text": "/**\n * Returns true if 'candidate' is a finite number or a string referring (not just 'including') a finite number\n * To keep in mind:\n * Number(true) = 1\n * Number('') = 0\n * Number(\" 10 \") = 10\n * !isNaN(true) = true\n * parseFloat('10 a') = 10\n *\n * @param {?} candidate\n * @return {boolean}\n */\nfunction isReferringFiniteNumber(candidate) {\n if (typeof (candidate) === 'number') return Number.isFinite(candidate);\n if (typeof (candidate) === 'string') {\n return (candidate.trim() !== '') && Number.isFinite(Number(candidate));\n }\n return false;\n}\n if (isReferringFiniteNumber(theirValue)) {\n myCheckedValue = Number(theirValue);\n} else {\n console.warn('The provided value doesn\\'t refer to a finite number');\n}\n"
},
{
"answer_id": 60990380,
"author": "Zoman",
"author_id": 118195,
"author_profile": "https://Stackoverflow.com/users/118195",
"pm_score": 2,
"selected": false,
"text": "const isNumRegEx = /^-?(\\d*\\.)?\\d+$/;\n\nfunction isNumeric(n, allowScientificNotation = false) {\n return allowScientificNotation ? \n !Number.isNaN(parseFloat(n)) && Number.isFinite(n) :\n isNumRegEx.test(n);\n}\n"
},
{
"answer_id": 61108035,
"author": "dsmith63",
"author_id": 3645358,
"author_profile": "https://Stackoverflow.com/users/3645358",
"pm_score": 2,
"selected": false,
"text": "function isNumber(x, noStr) {\n /*\n\n - Returns true if x is either a finite number type or a string containing only a number\n - If empty string supplied, fall back to explicit false\n - Pass true for noStr to return false when typeof x is \"string\", off by default\n\n isNumber(); // false\n isNumber([]); // false\n isNumber([1]); // false\n isNumber([1,2]); // false\n isNumber(''); // false\n isNumber(null); // false\n isNumber({}); // false\n isNumber(true); // false\n isNumber('true'); // false\n isNumber('false'); // false\n isNumber('123asdf'); // false\n isNumber('123.asdf'); // false\n isNumber(undefined); // false\n isNumber(Number.POSITIVE_INFINITY); // false\n isNumber(Number.NEGATIVE_INFINITY); // false\n isNumber('Infinity'); // false\n isNumber('-Infinity'); // false\n isNumber(Number.NaN); // false\n isNumber(new Date('December 17, 1995 03:24:00')); // false\n isNumber(0); // true\n isNumber('0'); // true\n isNumber(123); // true\n isNumber(123.456); // true\n isNumber(-123.456); // true\n isNumber(-.123456); // true\n isNumber('123'); // true\n isNumber('123.456'); // true\n isNumber('.123'); // true\n isNumber(.123); // true\n isNumber(Number.MAX_SAFE_INTEGER); // true\n isNumber(Number.MAX_VALUE); // true\n isNumber(Number.MIN_VALUE); // true\n isNumber(new Number(123)); // true\n */\n\n return (\n (typeof x === 'number' || x instanceof Number || (!noStr && x && typeof x === 'string' && !isNaN(x))) &&\n isFinite(x)\n ) || false;\n};\n"
},
{
"answer_id": 63355463,
"author": "ling",
"author_id": 405042,
"author_profile": "https://Stackoverflow.com/users/405042",
"pm_score": 1,
"selected": false,
"text": "<script>\n\n function isNumber(value, acceptScientificNotation) {\n\n if(true !== acceptScientificNotation){\n return /^-{0,1}\\d+(\\.\\d+)?$/.test(value);\n }\n\n if (true === Array.isArray(value)) {\n return false;\n }\n return !isNaN(parseInt(value, 10));\n }\n\n\n console.log(isNumber(\"\")); // false\n console.log(isNumber(false)); // false\n console.log(isNumber(true)); // false\n console.log(isNumber(\"0\")); // true\n console.log(isNumber(\"0.1\")); // true\n console.log(isNumber(\"12\")); // true\n console.log(isNumber(\"-12\")); // true\n console.log(isNumber(-45)); // true\n console.log(isNumber({jo: \"pi\"})); // false\n console.log(isNumber([])); // false\n console.log(isNumber([78, 79])); // false\n console.log(isNumber(NaN)); // false\n console.log(isNumber(Infinity)); // false\n console.log(isNumber(undefined)); // false\n console.log(isNumber(\"0,1\")); // false\n\n\n\n console.log(isNumber(\"1e-1\")); // false\n console.log(isNumber(\"1e-1\", true)); // true\n</script>\n"
},
{
"answer_id": 64437101,
"author": "lebobbi",
"author_id": 1128552,
"author_profile": "https://Stackoverflow.com/users/1128552",
"pm_score": 2,
"selected": false,
"text": "function isNumeric(number) {\n return !isNaN(parseFloat(number)) && !isNaN(+number);\n}\n 0, 1 , -1, 1.1 , -1.1 , 1E1 , -1E1 , 1e1 , -1e1, 0.1e10, -0.1.e10 , 0xAF1 , 0o172, Math.PI, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY '0', '1', '-1', '1.1', '-1.1', '1E1', '-1E1', '1e1', '-1e1', '0.1e10', '-0.1.e10', '0xAF1', '0o172' '', ' ', [], {}, null, undefined, NaN"
},
{
"answer_id": 67266686,
"author": "vitoboski",
"author_id": 15621907,
"author_profile": "https://Stackoverflow.com/users/15621907",
"pm_score": 2,
"selected": false,
"text": "isFinite(20)\n//True\n parseInt('2.5rem')\n//2\nparseFloat('2.5rem')\n//2.5 \n isInteger(23 / 0)\n//False\n isNaN(20)\n//False\n"
},
{
"answer_id": 68417450,
"author": "ekerner",
"author_id": 233060,
"author_profile": "https://Stackoverflow.com/users/233060",
"pm_score": 0,
"selected": false,
"text": "const isNumeric = stringOrNumber =>\n stringOrNumber == 0 || !!+stringOrNumber;\n const toNumber = stringOrNumber =>\n stringOrNumber == 0 || +stringOrNumber ? +stringOrNumber : NaN;\n"
},
{
"answer_id": 68821383,
"author": "Hasan Nahiyan Nobel",
"author_id": 6606776,
"author_profile": "https://Stackoverflow.com/users/6606776",
"pm_score": 4,
"selected": false,
"text": "!isNaN(input) +input === +input !isNaN(parseFloat(input)) isFinite(input) input !isNaN(input) +input===+input !isNaN( parseFloat( input)) isFinite( input) parseFloat() isNaN() parseFloat() parseFloat(null) NaN isNaN() parseFloat() isFinite() isNaN() isFinite() /**\n * My necessity was met by the following code.\n */\n\nif (input === null) {\n // Null input\n} else if (input.trim() === '') {\n // Empty or whitespace-only string\n} else if (isFinite(input)) {\n // Input is a number\n} else {\n // Not a number\n}\n /**\n * Note: JavaScript does not print numeric separator inside a number.\n * In that single case, the markdown output was manually corrected.\n * Also, the comments were manually added later, of course.\n */\n\nlet inputs = [\n 123, '123', 12.3, '12.3', ' 12.3 ',\n 1_000_000, '1_000_000',\n '0b11111111', '0o377', '0xFF',\n '', ' ',\n 'abc', '12.34Ab!@#$',\n '10e100', '10e1000',\n null, undefined, Infinity];\n\nlet markdownOutput = `| \\`input\\` | \\`!isNaN(input)\\` or <br>\\`+input === +input\\` | \\`!isNaN(parseFloat(input))\\` | \\`isFinite(input)\\` | Comment |\n| :---: | :---: | :---: | :---: | :--- |\\n`;\n\nfor (let input of inputs) {\n let outputs = [];\n outputs.push(!isNaN(input));\n outputs.push(!isNaN(parseFloat(input)));\n outputs.push(isFinite(input));\n\n if (typeof input === 'string') {\n // Output with quotations\n console.log(`'${input}'`);\n markdownOutput += `| '${input}'`;\n } else {\n // Output without quotes\n console.log(input);\n markdownOutput += `| ${input}`;\n }\n\n for (let output of outputs) {\n console.log('\\t' + output);\n if (output === true) {\n markdownOutput += ` | <div style=\"color:limegreen\">true</div>`;\n // markdownOutput += ` | ✔️`; // for stackoverflow\n } else {\n markdownOutput += ` | <div style=\"color:orangered\">false</div>`;\n // markdownOutput += ` | ❌`; // for stackoverflow\n }\n }\n\n markdownOutput += ` ||\\n`;\n}\n\n// Replace two or more whitespaces with $nbsp;\nmarkdownOutput = markdownOutput.replaceAll(` `, ` `);\n\n// Print markdown to console\nconsole.log(markdownOutput);\n"
},
{
"answer_id": 69402873,
"author": "Stefan Bracke",
"author_id": 2316698,
"author_profile": "https://Stackoverflow.com/users/2316698",
"pm_score": -1,
"selected": false,
"text": "if (mystring > 0) ...\n"
},
{
"answer_id": 70052447,
"author": "Emrah Tuncel",
"author_id": 2138283,
"author_profile": "https://Stackoverflow.com/users/2138283",
"pm_score": 2,
"selected": false,
"text": "function isNumeric(num){\n let value1 = num.toString();\n let value2 = parseFloat(num).toString();\n return (value1 === value2);\n}\n console.log(\n isNumeric(123), //true\n isNumeric(-123), //true\n isNumeric('123'), //true\n isNumeric('-123'), //true\n isNumeric(12.2), //true\n isNumeric(-12.2), //true\n isNumeric('12.2'), //true\n isNumeric('-12.2'), //true\n isNumeric('a123'), //false\n isNumeric('123a'), //false\n isNumeric(' 123'), //false\n isNumeric('123 '), //false\n isNumeric('a12.2'), //false\n isNumeric('12.2a'), //false\n isNumeric(' 12.2'), //false\n isNumeric('12.2 '), //false\n)\n"
},
{
"answer_id": 70408790,
"author": "chickens",
"author_id": 1602301,
"author_profile": "https://Stackoverflow.com/users/1602301",
"pm_score": 4,
"selected": false,
"text": "const isInteger = num => /^-?[0-9]+$/.test(num+'');\n const isNumeric = num => /^-?[0-9]+(?:\\.[0-9]+)?$/.test(num+'');\n"
},
{
"answer_id": 70628230,
"author": "Karwan E. Othman",
"author_id": 6523910,
"author_profile": "https://Stackoverflow.com/users/6523910",
"pm_score": 0,
"selected": false,
"text": " isNumeric(value: string): boolean {\n let valueToNumber = Number(value);\n var result = typeof valueToNumber == 'number' ;\n if(valueToNumber.toString() == 'NaN')\n {\n result = false;\n }\n return result;\n }\n"
},
{
"answer_id": 72620343,
"author": "Christian Vincenzo Traina",
"author_id": 1850851,
"author_profile": "https://Stackoverflow.com/users/1850851",
"pm_score": -1,
"selected": false,
"text": "const isNumeric = str => parseFloat(str) === parseFloat(str)\n const isNumeric = str => parseFloat(str) === parseFloat(str)\n \nconsole.log(isNumeric('10'))\nconsole.log(isNumeric('-10.2'))\nconsole.log(isNumeric('15abc'))\nconsole.log(isNumeric('0.0001'))\nconsole.log(isNumeric('abc'))\nconsole.log(isNumeric('abc123'))"
},
{
"answer_id": 72719062,
"author": "yusung lee",
"author_id": 7275648,
"author_profile": "https://Stackoverflow.com/users/7275648",
"pm_score": -1,
"selected": false,
"text": "const a = '1'\n\nconst isNumber = (a) => Number(a) === +a\n\n"
},
{
"answer_id": 72770816,
"author": "Musaib Mushtaq",
"author_id": 17860991,
"author_profile": "https://Stackoverflow.com/users/17860991",
"pm_score": 4,
"selected": false,
"text": "let a = isFinite('abc') // false;\nlet b = isFinite('123')//true;\nlet c = isFinite('12a') // false;\nconsole.log(a,b,c)"
},
{
"answer_id": 72831311,
"author": "Lajos Arpad",
"author_id": 436560,
"author_profile": "https://Stackoverflow.com/users/436560",
"pm_score": 1,
"selected": false,
"text": "(isNaN(foo) || ((foo !== 0) && (!foo)))\n foo isNaN(foo) !isNaN(parseFloat(foo))\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19074/"
] |
175,742
|
<p>I want to allocate a 2 D Array in Java Script. </p>
<p>I want do some thing similar to this in JavaScript</p>
<pre><code>typedef struct
{
int itemA,
int itemB,
string testC
} myStruc;
myStruct MyArray [100];
</code></pre>
<p>How to do this ? </p>
|
[
{
"answer_id": 175764,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 0,
"selected": false,
"text": "var myArray = new Array(\"someString1\", \"someString2\", \"someString3\", ...);\n \"someString1\" var myArray = new Array(5);\nmyArray[0] = ...;\nmyArray[1] = ...;\n"
},
{
"answer_id": 175769,
"author": "theraccoonbear",
"author_id": 7210,
"author_profile": "https://Stackoverflow.com/users/7210",
"pm_score": 1,
"selected": false,
"text": "function Person(first, last) {\n this.first = first;\n this.last = last;\n}\n\nvar person = new Person(\"John\", \"Dough\");\n"
},
{
"answer_id": 175781,
"author": "Ken",
"author_id": 20621,
"author_profile": "https://Stackoverflow.com/users/20621",
"pm_score": 1,
"selected": false,
"text": "function Sample(value1, value2) {\n this.value1 = value1;\n this.value2 = value2;\n}\n\nvar test = new Array();\n\ntest[0] = new Sample(\"a\",\"aa\");\ntest[1] = new Sample(\"b\",\"bb\");\n"
},
{
"answer_id": 175792,
"author": "jsight",
"author_id": 1432,
"author_profile": "https://Stackoverflow.com/users/1432",
"pm_score": 3,
"selected": false,
"text": "var arr = []\narr[0] = { \"itemA\": \"A\", \"itemB\": \"B\", \"itemC\": \"C\" }\narr[1] = { \"itemA\": \"A\", \"itemB\": \"B\", \"itemC\": \"C\" }\n arr[100] = { \"itemA\": \"A\", \"itemB\": \"B\", \"itemC\": \"C\" }\n"
},
{
"answer_id": 175985,
"author": "Thevs",
"author_id": 8559,
"author_profile": "https://Stackoverflow.com/users/8559",
"pm_score": 1,
"selected": false,
"text": "arr = [];\n\nfor (i=0; i<100; i++) {\n arr[i] = {itemA: <value>, itemB: <value>, textC: <string>, ... };\n}\n"
},
{
"answer_id": 6485303,
"author": "jBrushFX",
"author_id": 816321,
"author_profile": "https://Stackoverflow.com/users/816321",
"pm_score": 2,
"selected": false,
"text": " JS way\n\n function myStruct( a , b , c )\n @param {int} a\n @param {int} b\n @param {string} c\n @return {object}\n // arguments\n var a = arguments[0] , b = arguments[1] , c = arguments[2];\n\n // check INT type for argument a\n if( typeof a == \"number\" && (a + \"\").indexOf('.') == -1 ){ this['itemA'] = a; }\n // check INT type for argument b\n if( typeof b == \"number\" && (b + \"\").indexOf('.') == -1 ){ this['itemB'] = b; }\n // check INT type for argument b\n if( typeof c == \"string\" /*check for string length?!*/){ this['testC'] = c; }\n}\n\n// myStruct prototype\nmyStruct.prototype = {\n // constructor\n 'constructor' : myStruct,\n // default value for itemA\n 'itemA' : 0,\n // default value for itemB\n 'itemB' : 0,\n // default value for testC\n 'testC' : ''\n};\n\n/*\n static function defaultLength([, length])\n Set/Get the defaultLength value.\n @param {unsigned int|void} length\n @return {void|unsigned int}\n*/\n\nmyStruct.defaultLength = function(){\n // return the default value\n if( arguments.length == 0 ){\n return myStruct._default;\n }else{\n // set the default value\n var l = arguments[0];\n myStruct._default = ( typeof l == \"number\" && (l + \"\").indexOf('.') == -1 ) ? Math.abs( l ) : 0;\n }\n};\n\n// @var {unsigned int} myStruct._default = 0\nmyStruct._default = 0;\n\n/*\n static function makeArray( length )\n @param {unsigned int} length the length of the array\n @return {array}\n*/\nmyStruct.makeArray = function( length ){\n // Check if length is unsigned int\n length = ( typeof length == \"number\" && (length + \"\").indexOf('.') == -1 ) ? Math.abs( length ) : myStruct.defaultLength();\n\n // local array\n var array = [] , i = 0;\n\n // populate the array\n for( ; i < length; i++){\n array[ i ] = new myStruct();\n }\n\n // return\n return array;\n};\n\n// MAKE IT!\nmyStruct.defaultLength(10); // set the default length == 10\nvar arr = myStruct.makeArray(); // [myStruct, myStruct, myStruct, myStruct, myStruct, myStruct, myStruct, myStruct, myStruct, myStruct]\narr.length; // 10\nObject.prototype.toString.call( arr ); // [object Array]\n\n/* ANOTHER EXAMPLE */\nvar arr2 = []; // make an empty array\narr2[0] = new myStruct(1,1,'test1'); // make a first myStruct object\narr2[1] = new myStruct(2,2,'test2'); // make a second myStruct object\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,763
|
<p>What are some resources that will help get me up and running quickly with the Excel interop in C#?</p>
|
[
{
"answer_id": 176130,
"author": "BKimmel",
"author_id": 13776,
"author_profile": "https://Stackoverflow.com/users/13776",
"pm_score": 3,
"selected": false,
"text": "object missing = System.Reflection.Missing.Value;\nstring somestring = \"string\";\nobject refstring = (object)s;\nwrd.Selection.Hyperlinks.Add(wrd.Selection.Range, **ref refstring, ref missing, ref missing, ref missing, ref missing**);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25571/"
] |
175,785
|
<p>I have a form with a textarea. Users enter a block of text which is stored in a database.</p>
<p>Occasionally a user will paste text from Word containing smart quotes or emdashes. Those characters appear in the database as: –, ’, “ ,â€</p>
<p>What function should I call on the input string to <em>convert smart quotes to regular quotes and emdashes to regular dashes</em>? </p>
<p>I am working in PHP.</p>
<p>Update: Thanks for all of the great responses so far. The page on Joel's site about encodings is very informative: <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow noreferrer">http://www.joelonsoftware.com/articles/Unicode.html</a></p>
<p>Some notes on my environment:</p>
<p>The MySQL database is using UTF-8 encoding. Likewise, the HTML pages that display the content are using UTF-8 (Update:) by explicitly setting the meta content-type.</p>
<p>On those pages the smart quotes and emdashes appear as a diamond with question mark.</p>
<p>Solution:</p>
<p>Thanks again for the responses. The solution was twofold:</p>
<ol>
<li>Make sure the database and HTML
files were explicitly set to use
UTF-8 encoding.</li>
<li>Use <code>htmlspecialchars()</code> instead of
<code>htmlentities()</code>.</li>
</ol>
|
[
{
"answer_id": 175819,
"author": "Patrick McElhaney",
"author_id": 437,
"author_profile": "https://Stackoverflow.com/users/437",
"pm_score": 1,
"selected": false,
"text": "accept-charset=\"utf-8\""
},
{
"answer_id": 175820,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 1,
"selected": false,
"text": "$str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');\n"
},
{
"answer_id": 175848,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 2,
"selected": false,
"text": "iconv // Convert input data to UTF8, ignore any odd (MS Word..) chars\n// that don't translate\n$input = iconv(\"ISO-8859-1\",\"UTF-8//IGNORE\",$input);\n //IGNORE"
},
{
"answer_id": 179197,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 3,
"selected": false,
"text": "Content-Type \"text/html;charset=utf-8\" <meta> <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n <meta>"
},
{
"answer_id": 4009395,
"author": "hawshy",
"author_id": 408953,
"author_profile": "https://Stackoverflow.com/users/408953",
"pm_score": 1,
"selected": false,
"text": "mysql_set_charset('utf8',$link); \n"
},
{
"answer_id": 26396404,
"author": "Jonathan Lidbeck",
"author_id": 133836,
"author_profile": "https://Stackoverflow.com/users/133836",
"pm_score": 1,
"selected": false,
"text": "$trans_tbl = false;\n\nfunction htmlEncode($text) {\n\n global $trans_tbl;\n\n // create translation table once\n if(!$trans_tbl) {\n // start with the default set of conversions and add more.\n\n $trans_tbl = get_html_translation_table(HTML_ENTITIES); \n\n $trans_tbl[chr(130)] = '‚'; // Single Low-9 Quotation Mark\n $trans_tbl[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook\n $trans_tbl[chr(132)] = '„'; // Double Low-9 Quotation Mark\n $trans_tbl[chr(133)] = '…'; // Horizontal Ellipsis\n $trans_tbl[chr(134)] = '†'; // Dagger\n $trans_tbl[chr(135)] = '‡'; // Double Dagger\n $trans_tbl[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent\n $trans_tbl[chr(137)] = '‰'; // Per Mille Sign\n $trans_tbl[chr(138)] = 'Š'; // Latin Capital Letter S With Caron\n $trans_tbl[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark\n $trans_tbl[chr(140)] = 'Œ'; // Latin Capital Ligature OE\n\n // smart single/ double quotes (from MS)\n $trans_tbl[chr(145)] = '‘'; \n $trans_tbl[chr(146)] = '’'; \n $trans_tbl[chr(147)] = '“'; \n $trans_tbl[chr(148)] = '”'; \n\n $trans_tbl[chr(149)] = '•'; // Bullet\n $trans_tbl[chr(150)] = '–'; // En Dash\n $trans_tbl[chr(151)] = '—'; // Em Dash\n $trans_tbl[chr(152)] = '˜'; // Small Tilde\n $trans_tbl[chr(153)] = '™'; // Trade Mark Sign\n $trans_tbl[chr(154)] = 'š'; // Latin Small Letter S With Caron\n $trans_tbl[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark\n $trans_tbl[chr(156)] = 'œ'; // Latin Small Ligature OE\n $trans_tbl[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis\n\n ksort($trans_tbl);\n }\n\n // escape HTML \n return strtr($text, $trans_tbl); \n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3238/"
] |
175,835
|
<p>I'm trying add a tab to my web page that looks like this: <img src="https://i.stack.imgur.com/DT3e7.png" alt="alt text"></p>
<p>Using <a href="http://mattberseth.com/blog/2007/09/using_css_image_sprites_with_t.html" rel="nofollow noreferrer">this example</a> as a basis, I've gotten it partially working. My case differs because I want the text section to be a fixed with, but the tail section to dynamically resize to take up the rest of the tab's container.</p>
<p>It looks good in IE 6, but doesn't really take up the full width of the container.
In Firefox 3 it doesn't render well at all:<img src="https://i.stack.imgur.com/Zeypv.png" alt="alt text"> (the red is a blank area between the spans).</p>
<p>How do I get this to render properly in both IE6 and Firefox to take up the full width specified for #Tab? #Tab4 is the area I'd like to size to take up as much room as possible.</p>
<pre><code> <style type="text/css">
#Tab
{
width: 300px;
}
#Tab1
{
background: #000 url(BlueTabSprite.png) no-repeat 0 -136px;
display: inline-block;
height: 23px;
padding-left: 4px;
}
#Tab2
{
background: #000 url(BlueTabSprite.png) repeat-x 0 -242px;
display: inline-block;
overflow: hidden;
padding-top: 4px;
height: 19px;
width: 100px;
}
#Tab3
{
background: #000 url(BlueTabSprite.png) no-repeat right -30px;
display: inline-block;
height: 23px;
padding-right: 6px;
}
#Tab4
{
background: #000 url(BlueTabSprite.png) repeat-x 0 -83px;
display: inline-block;
height: 23px;
width:60%
}
#Tab5
{
background: #000 url(BlueTabSprite.png) no-repeat right -189px;
display: inline-block;
height: 23px;
padding-right:6px;
}
</style>
<div id="Tab">
<span id="Tab1">
<span id="Tab3">
<span id="Tab2">Test Tab</span>
</span>
</span>
<span id="Tab5">
<span id="Tab4"></span>
</span>
</div>
</code></pre>
|
[
{
"answer_id": 175900,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": true,
"text": "<div style=\"background: url('BlueTabSprite.png') no-repeat; width: 290px; min-width: 120px; max-width: 290px; height: 23px;\">\n<div style=\"float: right; background: url('BlueTabSprite.png') top right no-repeat; width: 10px; height: 23px;\"></div>\nTest\n</div>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12601/"
] |
175,836
|
<p>When using the .NET WebBrowser control how do you open a link in a new window using the the same session (ie.. do not start a new ASP.NET session on the server), or how do you capture the new window event to open the URL in the same WebBrowser control?</p>
|
[
{
"answer_id": 175851,
"author": "Greg Bray",
"author_id": 17373,
"author_profile": "https://Stackoverflow.com/users/17373",
"pm_score": 5,
"selected": true,
"text": "//-------------------------------VB.NET Version:-------------------------------\n\nDim WithEvents Web_V1 As SHDocVwCtl.WebBrowser_V1\n\nPrivate Sub Form_Load()\n Set Web_V1 = WebBrowser1.Object\nEnd Sub\n\nPrivate Sub Web_V1_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)\n Processed = True\n WebBrowser1.Navigate URL\nEnd Sub\n\n\n//-------------------------------C# Version-------------------------------\n\nprivate SHDocVw.WebBrowser_V1 Web_V1; //Interface to expose ActiveX methods\n\nprivate void Form1_Load(object sender, EventArgs e)\n{\n //Setup Web_V1 interface and register event handler\n Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance;\n Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow);\n}\n\nprivate void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed)\n{\n Processed = true; //Stop event from being processed\n\n //Code to open in same window\n this.webBrowser1.Navigate(URL);\n\n //Code to open in new window instead of same window\n //Form1 Popup = new Form1();\n //Popup.webBrowser1.Navigate(URL);\n //Popup.Show();\n}\n"
},
{
"answer_id": 16401565,
"author": "Jerod Venema",
"author_id": 25330,
"author_profile": "https://Stackoverflow.com/users/25330",
"pm_score": 2,
"selected": false,
"text": "InlinePopups(webBrowser1);\n // interface to expose ActiveX methods\nprivate SHDocVw.WebBrowser_V1 Web_V1;\nprivate void InlinePopups(WebBrowser browser)\n{\n // hooks to force new windows to open in the current instance\n Web_V1 = (SHDocVw.WebBrowser_V1)browser.ActiveXInstance;\n Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler((string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) =>\n {\n Processed = true; // stop event from being processed\n\n // open in the existing window\n browser.Navigate(URL);\n });\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17373/"
] |
175,845
|
<p>I have a repeater control where in the footer I have a DropDownList. In my code-behind I have:</p>
<pre><code>protected void ddMyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
// Item binding code
}
else if (e.Item.ItemType == ListItemType.Footer)
{
DropDownList ddl = e.Item.FindDropDownList("ddMyDropDownList");
// Fill the list control
ddl.SelectedIndexChanged += new
EventHandler(ddMyDropDownList_SelectedIndexChanged);
ddl.AutoPostBack = true;
}
}
</code></pre>
<p>The page appear to PostBack however my EventHandler does not get called. Any ideas?</p>
|
[
{
"answer_id": 176003,
"author": "KyleLanser",
"author_id": 12923,
"author_profile": "https://Stackoverflow.com/users/12923",
"pm_score": 5,
"selected": true,
"text": "<FooterTemplate>\n <asp:DropDownList ID=\"ddlOptions\"\n runat=\"server\" \n AutoPostBack=\"true\" \n onselectedindexchanged=\"ddlOptions_SelectedIndexChanged\">\n <asp:ListItem>Option1</asp:ListItem>\n <asp:ListItem>Option2</asp:ListItem>\n </asp:DropDownList>\n</FooterTemplate>\n protected void ddlOptions_SelectedIndexChanged(object sender, EventArgs e)\n {\n //Event Code here.\n }\n"
},
{
"answer_id": 2317302,
"author": "KevinUK",
"author_id": 1469,
"author_profile": "https://Stackoverflow.com/users/1469",
"pm_score": 3,
"selected": false,
"text": "EnableViewState=\"false\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3111/"
] |
175,847
|
<p>I am writing a fairly basic script using jQuery. However, the script behaves differently depending on whether I am running it on my local Web server (localhost) or on a production server.</p>
<p>On development, the following code returns the HTML I'm expecting: </p>
<pre><code>$('#objID').siblings('.mAddress').html();
</code></pre>
<p>On production, the same statement returns <code>undefined</code>.</p>
<p>The document structures are the same on both machines. The only difference I can find is when I use Firebug to step through the script. On the development machine, putting a watch on $('#objID').siblings('.mAddress') results in <code>[ span#object ]</code> while on production the same watch results in <code>[ [ span#object ] ]</code><br>
(Notice the double sets of square brackets).</p>
<p>Any ideas?</p>
<p>Added:</p>
<p>I've verified that the two libraries are identical.</p>
<p>I've done some more experimenting using Firebug. Another part of the script grabs a set of elements using the statement:</p>
<pre><code>$('.ParentColumn2').each(function(i) { ... })
</code></pre>
<p>Within the body of that function, if I set a watch on <code>this</code>, on development the value of <code>this</code> is what I expect: <code>div.ParentColumn2</code> , but on production the value of <code>this</code> returns what looks like an array: <code>[ div.ParentColumn2, div.ParentColumn2, div.ParentColumn2, .....]</code></p>
<p>The HTML is basically a table (I've stripped out irrelevant HTML, and the rows repeat):</p>
<pre><code><table>
<tr>
<td>
<div class="ItemTemplate">
<div class="ParentColumn2">
<div><span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lbl_Address" class="lbl_Address mAddress">111 W Wacker Dr, </span><span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lbl_City" class="lbl_Address mCity">Chicago</span>&nbsp;<span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lbl_PostalCode" class="lbl_Address mPostalCode">60601</span>&nbsp;<a href="javascript:MapMe(this);" id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_hypMap" class="hypMap">Map</a>&nbsp;&nbsp;<span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lbl_Area" class="mArea">Loop</span><span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lt" class="mLt">41.8868010285473</span><span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl02_lg" class="mLg">-87.6312860701286</span>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="ItemTemplate">
<div class="ParentColumn2">
<div><span id="dnn_ctr45874_ViewProjectGrid_GridView1_ctl03_lbl_Address" class="lbl_Address mAddress">...</span> ...
</div>
</div>
</div>
</td>
</tr>
</table>
</code></pre>
<p>The HTML is as identical between the two machines as can be possible given that it's all generated by .Net (don't get me started).</p>
|
[
{
"answer_id": 176768,
"author": "Bruce Aldridge",
"author_id": 21460,
"author_profile": "https://Stackoverflow.com/users/21460",
"pm_score": 1,
"selected": false,
"text": "<div><p></p><p></p></div>\n $('#objID').find('.mAddress').html();\n $('#objID').children('.mAddress').html();\n $('#objID .mAddress').html();\n"
},
{
"answer_id": 185489,
"author": "Svante Svenson",
"author_id": 19707,
"author_profile": "https://Stackoverflow.com/users/19707",
"pm_score": 0,
"selected": false,
"text": "$('#objID .mAddress').html();\n $($('#objID .mAddress').get(0)).html();\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13449/"
] |
175,858
|
<p>Has anyone found a way to save a FlowDocument as BAML or other compressed format? I can import XML with images to create a new FlowDocument:</p>
<pre><code><TextRange class instance>.Load(fs, DataFormats.Rtf)
</code></pre>
<p>However, I haven't found a good way to save it in a 'native' compressed format. Uncompressed XAML is easy to generate using:</p>
<pre><code><TextRange class instance>.Save(fs, DataFormats.Xaml);
</code></pre>
<p>But is there any programmatic method to save it to a compressed format?</p>
<p>If there isn't an existing method, does anyone know where to find a programmatic XAML compiler? Or even just the BAML specifications? I could programmatically generate an entire XAML window with the FlowDocument embedded, but I'd still want to convert the XAML to BAML for faster load times. I'm using relatively large rtf documents and conversion time using DataFormats.Rtf is significant.</p>
|
[
{
"answer_id": 320737,
"author": "Fred",
"author_id": 177,
"author_profile": "https://Stackoverflow.com/users/177",
"pm_score": 0,
"selected": false,
"text": "<TextRange class instance>.Save(fs, DataFormats.Xaml);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175858",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/177/"
] |
175,880
|
<p>It appears that our implementation of using Quartz - JDBCJobStore along with Spring, Hibernate and Websphere is throwing unmanaged threads. </p>
<p>I have done some reading and found a tech article from IBM stating that the usage of Quartz with Spring will cause that. They make the suggestion of using CommnonJ to address this issue.</p>
<p>I have done some further research and the only examples I have seen so far all deal with the plan old JobStore that is not in a database.</p>
<p>So, I was wondering if anyone has an example of the solution for this issue.</p>
<p>Thanks</p>
|
[
{
"answer_id": 17742363,
"author": "PaoloC",
"author_id": 2365724,
"author_profile": "https://Stackoverflow.com/users/2365724",
"pm_score": 3,
"selected": false,
"text": "ctx.lookup(myJndiUrl) <dependency>\n <groupId>org.quartz-scheduler</groupId>\n <artifactId>quartz-commonj</artifactId>\n <version>1.8.6</version>\n</dependency>\n org.quartz.threadExecutor.class=org.quartz.custom.WorkManagerThreadExecutor\norg.quartz.threadExecutor.workManagerName=wm/default\n newInstance() java:global execute(JobExecutionContext)"
},
{
"answer_id": 43793069,
"author": "pufface",
"author_id": 6451286,
"author_profile": "https://Stackoverflow.com/users/6451286",
"pm_score": 2,
"selected": false,
"text": "org.quartz.threadPool.class WorkManagerThreadExecutor org.quartz.threadExecutor.class"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8981/"
] |
175,882
|
<p>Now there's something I always wondered: how is sleep() implemented ?</p>
<p>If it is all about using an API from the OS, then how is the API made ?</p>
<p>Does it all boil down to using special machine-code on the CPU ? Does that CPU need a special co-processor or other gizmo without which you can't have sleep() ?</p>
<p>The best known incarnation of sleep() is in C (to be more accurate, in the libraries that come with C compilers, such as GNU's libc), although almost every language today has its equivalent, but the implementation of sleep in some languages (think Bash) is not what we're looking at in this question...</p>
<p>EDIT: After reading some of the answers, I see that the process is placed in a wait queue. From there, I can guess two alternatives, either</p>
<ol>
<li>a timer is set so that the kernel wakes the process at the due time, or</li>
<li>whenever the kernel is allowed a time slice, it polls the clock to check whether it's time to wake a process.</li>
</ol>
<p>The answers only mention alternative 1. Therefore, I ask: how does this timer behave ? If it's a simple interrupt to make the kernel wake the process, how can the kernel ask the timer to "wake me up in 140 milliseconds so I can put the process in running state" ?</p>
|
[
{
"answer_id": 33639161,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 2,
"selected": false,
"text": "nanosleep git ls-files | grep sleep\n sysdeps/unix/sysv/linux/sleep.c\n sysdeps/unix/sysv/linux/\n /* We are going to use the `nanosleep' syscall of the kernel. But the\n kernel does not implement the stupid SysV SIGCHLD vs. SIG_IGN\n behaviour for this syscall. Therefore we have to emulate it here. */\nunsigned int\n__sleep (unsigned int seconds)\n weak_alias (__sleep, sleep)\n __sleep sleep nanosleep result = __nanosleep (&ts, &ts);\n git grep nanosleep | grep -v abilist\n __nanosleep sysdeps/unix/sysv/linux/syscalls.list \n nanosleep - nanosleep Ci:pp __nanosleep nanosleep\n sysdeps/unix/make-syscalls.sh\n grep -r __nanosleep\n /sysd-syscalls make-syscalls.sh #### CALL=nanosleep NUMBER=35 ARGS=i:pp SOURCE=-\nifeq (,$(filter nanosleep,$(unix-syscalls)))\nunix-syscalls += nanosleep\n$(foreach p,$(sysd-rules-targets),$(foreach o,$(object-suffixes),$(objpfx)$(patsubst %,$p,nanosleep)$o)): \\\n $(..)sysdeps/unix/make-syscalls.sh\n $(make-target-directory)\n (echo '#define SYSCALL_NAME nanosleep'; \\\n echo '#define SYSCALL_NARGS 2'; \\\n echo '#define SYSCALL_SYMBOL __nanosleep'; \\\n echo '#define SYSCALL_CANCELLABLE 1'; \\\n echo '#include <syscall-template.S>'; \\\n echo 'weak_alias (__nanosleep, nanosleep)'; \\\n echo 'libc_hidden_weak (nanosleep)'; \\\n ) | $(compile-syscall) $(foreach p,$(patsubst %nanosleep,%,$(basename $(@F))),$($(p)CPPFLAGS))\nendif\n git grep sysd-syscalls sysdeps/unix/Makefile:23:-include $(common-objpfx)sysd-syscalls \n compile-syscall # This is the end of the pipeline for compiling the syscall stubs.\n# The stdin is assembler with cpp using sysdep.h macros.\ncompile-syscall = $(COMPILE.S) -o $@ -x assembler-with-cpp - \\\n $(compile-mkdep-flags)\n -x assembler-with-cpp gcc #define #define SYSCALL_NAME nanosleep\n #include <syscall-template.S>\n posix/nanosleep.o sys_nanosleep\n kernel/time/hrtimer.c SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,\n hrtimer hrtimer_nanosleep do_nanosleep set_current_state(TASK_INTERRUPTIBLE); freezable_schedule(); schedule() hrtimer_start_expires hrtimer_start_range_ns arch/x86"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15649/"
] |
175,891
|
<p>Lets assume we have this xml: </p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<tns:RegistryResponse status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure"
xmlns:tns="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0"
xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0">
<tns:RegistryErrorList highestSeverity="">
<tns:RegistryError codeContext="XDSInvalidRequest - DcoumentId is not unique."
errorCode="XDSInvalidRequest"
severity="urn:oasis:names:tc:ebxml-regrep:ErrorSeverityType:Error"/>
</tns:RegistryErrorList>
</tns:RegistryResponse>
</code></pre>
<p>To retrieve RegistryErrorList element, we can do </p>
<pre><code>XDocument doc = XDocument.Load(<path to xml file>);
XNamespace ns = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0";
XElement errorList = doc.Root.Elements( ns + "RegistryErrorList").SingleOrDefault();
</code></pre>
<p>but not like this</p>
<pre><code>XElement errorList = doc.Root.Elements("RegistryErrorList").SingleOrDefault();
</code></pre>
<p>Is there a way to do the query without the namespace of the element. Basicly is there something conceptially
similiar to using local-name() in XPath (i.e. //*[local-name()='RegistryErrorList'])</p>
|
[
{
"answer_id": 175920,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 4,
"selected": true,
"text": "var q = from x in doc.Root.Elements()\n where x.Name.LocalName==\"RegistryErrorList\"\n select x;\n\nvar errorList = q.SingleOrDefault();\n"
},
{
"answer_id": 178373,
"author": "aogan",
"author_id": 4795,
"author_profile": "https://Stackoverflow.com/users/4795",
"pm_score": 2,
"selected": false,
"text": "XElement errorList = doc.Root.Elements().Where(o => o.Name.LocalName == \"RegistryErrorList\").SingleOrDefault();\n"
},
{
"answer_id": 33830922,
"author": "Paul Shepard",
"author_id": 4487589,
"author_profile": "https://Stackoverflow.com/users/4487589",
"pm_score": 1,
"selected": false,
"text": " public static IEnumerable<XElement> GetElements(this XContainer doc, string elementName)\n {\n return doc.Descendants().Where(p => p.Name.LocalName == elementName);\n }\n var errorList = doc.GetElements(\"RegistryErrorList\").SingleOrDefault();\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4795/"
] |
175,892
|
<p>I'm trying to resize an embedded object. The issue is that when the mouse hovers over the object, it takes "control" of the mouse, swallowing up movement events. The result being that you can expand the div containing the object, but when you try to shrink it, if the mouse enters the area of the object the resize halts. </p>
<p>Currently, I hide the object while moving. I'm wondering if there's a way to just prevent the object from capturing the mouse. Perhaps overlaying another element on top of it that prevents mouse events from reaching the embedded object?</p>
<hr>
<p>using ghosting on the resize doesn't work for embedded objects, btw.</p>
<hr>
<p>Adding a bounty, as I can't ever seem to get this working. To collect, simply do the following:</p>
<p>Provide a webpage with a PDF embedded in it, centered on the page. The pdf can't take up the entire page; make its width/height 50% the width of the browser window or something.</p>
<p>Use jQuery 1.2.6 to add resize to every side and corner of the pdf. </p>
<p>The pdf MUST NOT CAPTURE THE MOUSE and stop dragging WHEN SHRINKING THE PDF. That means when I click on the edge of the pdf and drag, when the mouse enters the display box of the pdf, the resize operation continues.</p>
<p>This must work in IE 7. Conditional CSS (if gte ie7 or whatever) hacks are fine.</p>
<hr>
<p>Hmmm... I'm thinking it might be an issue with iframe...</p>
<pre><code> <div style="text-align:center; padding-top:50px;">
<div id="doc" style="width:384px;height:512px;">
<iframe id="docFrame" style="width: 100%; height: 100%;"
src='http://www.ready.gov/america/_downloads/sampleplan.pdf'>
</iframe></div></div>
<div id="data"></div>
<script type="text/javascript">
$(document).ready(function() {
var obj = $('#docFrame');
$('#doc').resizable({handles:'all', resize: function(e, ui) {
$('#data').html(ui.size.width + 'x' + ui.size.height);
obj.attr({width: ui.size.width, height: ui.size.height});
}});
});
</script>
</code></pre>
<p>This doesn't work. When your mouse strays into the iframe the resize operation stops.</p>
<hr>
<p>There are some good answers; if the bounty runs out before I can get around to vetting them all I'll reinstate the bounty (same 150 points).</p>
|
[
{
"answer_id": 486265,
"author": "Paolo Bergantino",
"author_id": 16417,
"author_profile": "https://Stackoverflow.com/users/16417",
"pm_score": 3,
"selected": true,
"text": "this working sample wmode transparent <object> <object>"
},
{
"answer_id": 497044,
"author": "Jab",
"author_id": 29676,
"author_profile": "https://Stackoverflow.com/users/29676",
"pm_score": 0,
"selected": false,
"text": "$(document).ready(function() {\n var obj = $('#docFrame');\n $('#doc').resizable(\n { \n handles: 'all', \n resize: function(e, ui) {\n $('#data').html(ui.size.width + 'x' + ui.size.height);\n obj.attr({ width: ui.size.width, height: ui.size.height });\n },\n start: function(e, ui) { $('#docFrame').hide(); },\n stop: function(e, ui) { $('#docFrame').show(); }\n });\n});\n"
},
{
"answer_id": 497968,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 0,
"selected": false,
"text": "<div style=\"text-align: center; padding-top: 50px;\">\n <div id=\"doc\" style=\"width: 384px; height: 512px; position: relative;\">\n <div id=\"overlay\" style=\"position: absolute; top: -5px; left: -5px;\n padding: 5px; width: 100%; height: 100%; background: red;\n opacity: 0.5; z-index: 1; display: none;\"></div>\n <iframe id=\"docFrame\" style=\"width: 100%; height: 100%; position: relative; z-index: 0;\"\n src='http://www.ready.gov/america/_downloads/sampleplan.pdf'></iframe>\n </div>\n</div>\n<div id=\"data\"></div>\n<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n<script src=\"http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.js\" type=\"text/javascript\" charset=\"utf-8\"></script>\n<script type=\"text/javascript\">\n $(document).ready(function() {\n var obj = $('#docFrame'), overlay = $('#overlay');\n $('#doc').resizable({\n handles: 'all',\n start: function() {\n overlay.show();\n },\n resize: function(e, ui) {\n $('#data').html(ui.size.width + 'x' + ui.size.height);\n obj.attr({\n width: ui.size.width,\n height: ui.size.height\n });\n },\n stop: function(e, ui) {\n overlay.hide();\n }\n });\n });\n</script>\n"
},
{
"answer_id": 23929782,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var dframe = $(\"#docFrame\");\n\n$(document).ready(function () {\n var b = dframe;\n $(\"#doc\").e({\n b: \"all\",\n resize: function (c, a) {\n $(\"#data\").html(a.size.width + \"x\" + a.size.height);\n object.attr({\n width: a.size.width,\n height: a.size.height\n });\n },\n start: function () {\n dframe.hide();\n },\n stop: function () {\n dframe.show();\n }\n });\n});\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
175,951
|
<p>Among other text and visual aids on a form submission, post-validation, I'm coloring my input boxes red to signify the interactive area needing attention.</p>
<p>On Chrome (and for Google Toolbar users) the auto-fill feature re-colors my input forms yellow. Here's the complex issue: I want auto-complete allowed on my forms, as it speeds users logging in. I am going to check into the ability to turn the autocomplete attribute to off if/when there's an error triggered, but it is a complex bit of coding to programmatically turn off the auto-complete for the single affected input on a page. This, to put it simply, would be a major headache.</p>
<p>So to try to avoid that issue, is there any simpler method of stopping Chrome from re-coloring the input boxes?</p>
<p>[edit] I tried the !important suggestion below and it had no effect. I have not yet checked Google Toolbar to see if the !important attribute would work for that.</p>
<p>As far as I can tell, there isn't any means other than using the autocomplete attribute (which does appear to work).</p>
|
[
{
"answer_id": 175980,
"author": "Ben Hoffstein",
"author_id": 4482,
"author_profile": "https://Stackoverflow.com/users/4482",
"pm_score": 7,
"selected": true,
"text": "<input type=\"text\" name=\"name\" autocomplete=\"off\">\n <form autocomplete=\"off\" ...>\n"
},
{
"answer_id": 582741,
"author": "John Leidegren",
"author_id": 58961,
"author_profile": "https://Stackoverflow.com/users/58961",
"pm_score": 7,
"selected": false,
"text": "input[type=\"text\"], input[type=\"password\"], textarea, select { \n outline: none;\n}\n :focus { background-color: #fff; }\n"
},
{
"answer_id": 4261239,
"author": "Benjamin",
"author_id": 518077,
"author_profile": "https://Stackoverflow.com/users/518077",
"pm_score": 4,
"selected": false,
"text": "if (navigator.userAgent.toLowerCase().indexOf(\"chrome\") >= 0) {\n$(window).load(function(){\n $('input:-webkit-autofill').each(function(){\n var text = $(this).val();\n var name = $(this).attr('name');\n $(this).after(this.outerHTML).remove();\n $('input[name=' + name + ']').val(text);\n });\n});}\n"
},
{
"answer_id": 4646436,
"author": "Kita",
"author_id": 569779,
"author_profile": "https://Stackoverflow.com/users/569779",
"pm_score": 3,
"selected": false,
"text": "*:focus { outline:none; } .nohighlight:focus { outline:none; } .changeborder:focus { outline:Blue Solid 4px; }"
},
{
"answer_id": 6243894,
"author": "Tim",
"author_id": 181971,
"author_profile": "https://Stackoverflow.com/users/181971",
"pm_score": 1,
"selected": false,
"text": "if (BrowserDetect.browser == \"Chrome\") {\n jQuery('form').attr('autocomplete','off');\n};\n"
},
{
"answer_id": 6329149,
"author": "NewFangSol",
"author_id": 795741,
"author_profile": "https://Stackoverflow.com/users/795741",
"pm_score": 0,
"selected": false,
"text": "input:focus { outline:none; }\n textarea:focus { outline:none; }\n input:focus { outline:#HEXCOD SOLID 2px ; }\n"
},
{
"answer_id": 9152101,
"author": "hohner",
"author_id": 427992,
"author_profile": "https://Stackoverflow.com/users/427992",
"pm_score": 2,
"selected": false,
"text": "if ($.browser.webkit) {\n $(\"input\").attr('autocomplete','off');\n}\n"
},
{
"answer_id": 15957374,
"author": "321X",
"author_id": 243493,
"author_profile": "https://Stackoverflow.com/users/243493",
"pm_score": 1,
"selected": false,
"text": "<script type=\"text/javascript\">\n $(function() {\n if (navigator.userAgent.toLowerCase().indexOf(\"chrome\") >= 0) {\n var intervalId = 0;\n $(window).load(function() {\n intervalId = setInterval(function () { // << somehow this does the trick!\n if ($('input:-webkit-autofill').length > 0) {\n clearInterval(intervalId);\n $('input:-webkit-autofill').each(function () {\n var text = $(this).val();\n var name = $(this).attr('name');\n $(this).after(this.outerHTML).remove();\n $('input[name=' + name + ']').val(text);\n });\n }\n }, 1);\n });\n }\n });\n</script>\n"
},
{
"answer_id": 20671898,
"author": "Vin",
"author_id": 1982454,
"author_profile": "https://Stackoverflow.com/users/1982454",
"pm_score": 1,
"selected": false,
"text": "if (navigator.userAgent.toLowerCase().indexOf(\"chrome\") >= 0) {\n $(document).ready(function() {\n $('input:-webkit-autofill').each(function(){\n var text = $(this).val();\n var name = $(this).attr('name');\n $(this).after(this.outerHTML).remove();\n $('input[name=' + name + ']').val(text);\n });\n });\n};\n"
},
{
"answer_id": 25881221,
"author": "JStormThaKid",
"author_id": 1935762,
"author_profile": "https://Stackoverflow.com/users/1935762",
"pm_score": 6,
"selected": false,
"text": "// Just change \"red\" to any color\ninput:-webkit-autofill {\n -webkit-box-shadow: 0 0 0px 1000px red inset;\n}\n"
},
{
"answer_id": 36440039,
"author": "hsobhy",
"author_id": 1030977,
"author_profile": "https://Stackoverflow.com/users/1030977",
"pm_score": 1,
"selected": false,
"text": "<input readonly=\"readonly\" onfocus=\"this.removeAttribute('readonly');\" />\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2486915/"
] |
175,955
|
<p>I am currently trying to import a semi-colon delimited text file into a database in c# using OleDb where I don't know the type (SQL Server, Access, Oracle, MySQL, postgreSQL, etc.) Currently I'm reading in the file as a database using the Jet text reader then creating a prepared insert statement, populating the fields, then commiting at the end. While that works, it's slow and for millions of rows, it takes way too long.</p>
<p>So my question: Does anybody have any other thoughts on how to best import a text file to a generic database, or comments on my approaches that will lead to a faster import?</p>
<p>I cannot use 3rd party libraries or software to do this as it is part of a larger project</p>
|
[
{
"answer_id": 184234,
"author": "Fry",
"author_id": 23553,
"author_profile": "https://Stackoverflow.com/users/23553",
"pm_score": 1,
"selected": false,
"text": "Dataset.Tables[x].ImportRow(DataRow)\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23553/"
] |
175,962
|
<p>How can I have a dynamic variable setting the amount of rows to return in SQL Server? Below is not valid syntax in SQL Server 2005+:</p>
<pre><code>DECLARE @count int
SET @count = 20
SELECT TOP @count * FROM SomeTable
</code></pre>
|
[
{
"answer_id": 175965,
"author": "Brian Kim",
"author_id": 5704,
"author_profile": "https://Stackoverflow.com/users/5704",
"pm_score": 10,
"selected": true,
"text": "SELECT TOP (@count) * FROM SomeTable\n"
},
{
"answer_id": 175978,
"author": "x0n",
"author_id": 6920,
"author_profile": "https://Stackoverflow.com/users/6920",
"pm_score": 5,
"selected": false,
"text": "set rowcount @top\n\nselect * from sometable\n\nset rowcount 0 \n"
},
{
"answer_id": 176262,
"author": "Codewerks",
"author_id": 17729,
"author_profile": "https://Stackoverflow.com/users/17729",
"pm_score": 4,
"selected": false,
"text": "SET ROWCOUNT @top\n\nSELECT * from sometable\n\nSET ROWCOUNT 0\n"
},
{
"answer_id": 177626,
"author": "Jan",
"author_id": 25727,
"author_profile": "https://Stackoverflow.com/users/25727",
"pm_score": 2,
"selected": false,
"text": "declare @sql nvarchar(200), @count int\nset @count = 10\nset @sql = N'select top ' + cast(@count as nvarchar(4)) + ' * from table'\nexec (@sql)\n"
},
{
"answer_id": 34663655,
"author": "ShawnThompson",
"author_id": 5759395,
"author_profile": "https://Stackoverflow.com/users/5759395",
"pm_score": 3,
"selected": false,
"text": "DECLARE @top INT = 10;\n\nSELECT TOP (@Top) *\nFROM <table_name>;\n"
},
{
"answer_id": 42775624,
"author": "David Castro",
"author_id": 3199531,
"author_profile": "https://Stackoverflow.com/users/3199531",
"pm_score": 3,
"selected": false,
"text": "declare @rows int = 10\n\nselect top (@rows) *\nfrom Employees\norder by 1 desc -- optional to get the last records using the first column of the table\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5769/"
] |
175,982
|
<p>I have a copy of emacs that I use on a couple of different (windows) computers from a thumb drive, and I am wondering if it is possible to create something that is sort of the equivalent of a bash alias or symlink within emacs? Something that I could use within find-file is the main thing that i'm looking for, so for example: <code>C-f <some link></code> would take me somewhere. Currently I have to add a new defun every time i get to a new computer, which is just kind of a pain and I would <em>swear</em> i've seen this somewhere, but months of googling have turned up nothing.</p>
<p>What i've got right now is something like:</p>
<pre><code>(defun go-awesome ()
"Find my way to my work home"
(interactive)
(find-file "c:/cygwin/home/awesome"))
</code></pre>
<p>But that feels increadibly overdone and hacky for just visiting a fairly hacky for just visiting a file that i visit semi-regularly. And it requires a lot of effort to set up a new file.</p>
<p>The biggest problem with it though, in my opinion is that it doesn't fit in my workflow. When i want to visit a file i always do <code>C-x C-f</code>, and if i realize that "hey i'm at work" i then have to <code>C-g M-x go-awesome</code>. Perhaps it would be more clear if i said that i wanted to be able to do something that is the equivalent of an <code>ln -s /some/awesome/dir</code> but internal to emacs, instead of built into the OS, so that <code>C-x C-f ~/awesome/some/sub/dir</code> would work on windows or anywhere else.</p>
|
[
{
"answer_id": 176194,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 5,
"selected": true,
"text": "(set-register ?c '(file . \"c:/data/common.txt\"))\n(set-register ?f '(file . \"c:/data/frequent.txt\"))\n jump-to-register C-x r j C-x r j c c:/data/common.txt"
},
{
"answer_id": 177314,
"author": "quodlibetor",
"author_id": 25616,
"author_profile": "https://Stackoverflow.com/users/25616",
"pm_score": -1,
"selected": false,
"text": "(defun nuke ()\n \"alias delete-trailing-whitespace\"\n (interactive)\n (delete-trailing-whitespace))\n"
},
{
"answer_id": 177345,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 2,
"selected": false,
"text": "defalias (defalias 'nuke 'delete-trailing-whitespace)\n partial-completion-mode M-x d-t-w [RET]\n delete-trailing-whitespace"
},
{
"answer_id": 200489,
"author": "stephanea",
"author_id": 8776,
"author_profile": "https://Stackoverflow.com/users/8776",
"pm_score": 0,
"selected": false,
"text": " C-x( # start defining the macro\n C-x C-f ~/.bashrc \n C-x ) # end definition\n M-x name-last-kbd-macro\nvisitbashrc #give it a name\n M-x insert-kbd-macro\n"
},
{
"answer_id": 365543,
"author": "polyglot",
"author_id": 45383,
"author_profile": "https://Stackoverflow.com/users/45383",
"pm_score": 0,
"selected": false,
"text": "(global-set-key [f3] 'ffap)\n\n;comcplete shortcut in minibuffer\n(define-key minibuffer-local-completion-map (kbd \"<f3>\")\n 'complete-minibuffer-path) \n\n(defun complete-minibuffer-path ()\n \"Extension to the complete word facility of the minibuffer by\nreplacing matching strings to a specific path\"\n (interactive)\n (setq found t)\n (cond\n ; just add new entries if needed; shortcut up to 4 letters will work\n ((looking-back \"j\" 5 nil) (setq directory \"D:/Desktop/\"))\n ((looking-back \"k\" 5 nil) (setq directory \"D:/Documents/\"))\n ((looking-back \"l\" 5 nil) (setq directory home-dir))\n ((looking-back \"i\" 5 nil) (setq directory \"D:/Programs/\"))\n (t (setq found nil)))\n (cond (found (beginning-of-line)\n (kill-line)\n (insert directory))\n (t (minibuffer-complete)))) \n"
},
{
"answer_id": 1934276,
"author": "quodlibetor",
"author_id": 25616,
"author_profile": "https://Stackoverflow.com/users/25616",
"pm_score": 0,
"selected": false,
"text": "$"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25616/"
] |
175,993
|
<p>After making some changes in my models (eg. new field in a model and a new model) what is the best way of reflecting these changes to my populated database? </p>
<hr>
<p>PS: I wanted to see many solutions in one place rated. Apparently more solutions are already listed <a href="https://stackoverflow.com/questions/35991/altering-database-tables-in-django">here</a>.</p>
|
[
{
"answer_id": 209722,
"author": "shacker",
"author_id": 8438,
"author_profile": "https://Stackoverflow.com/users/8438",
"pm_score": 5,
"selected": false,
"text": "python manage.py dumpdata > dump.json python manage.py loaddata dump.json"
},
{
"answer_id": 19586888,
"author": "Vijesh Venugopal",
"author_id": 2178962,
"author_profile": "https://Stackoverflow.com/users/2178962",
"pm_score": 0,
"selected": false,
"text": "Perform these steps in order may help you For more details, python manage.py schemamigration apps.appname --initial python manage.py migrate apps.appname --fake python manage.py schemamigration apps.appname --auto python manage.py migrate apps.appname"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12785/"
] |
175,994
|
<p>I have written an HTML Application (hta file) and am wondering if there is a way to embed an icon file into the hta file itself.</p>
<p>I have seen html emails that include embedded graphic files, is there any way to do this with html applications and icons?</p>
<p>HTA files have an HTA:APPLICATION tag that allows you to specify an icon, but I want to have only a single file for download. I don't want to have an external icon file. Is this possible?</p>
<p>More info on hta files here: <a href="http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx" rel="noreferrer">HTA files</a>.</p>
|
[
{
"answer_id": 176065,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 3,
"selected": false,
"text": "<img src=\"data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7\"width=\"16\" height=\"14\" alt=\"embedded folder icon\">\n"
},
{
"answer_id": 185470,
"author": "Joel Anair",
"author_id": 7441,
"author_profile": "https://Stackoverflow.com/users/7441",
"pm_score": 1,
"selected": false,
"text": "MSXML.DomDocument"
},
{
"answer_id": 1052110,
"author": "Bob77",
"author_id": 126278,
"author_profile": "https://Stackoverflow.com/users/126278",
"pm_score": 1,
"selected": false,
"text": "iframe"
},
{
"answer_id": 1138939,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<hta:application icon=\"magnify.exe\" />\n"
},
{
"answer_id": 1871411,
"author": "Alex Jasmin",
"author_id": 162407,
"author_profile": "https://Stackoverflow.com/users/162407",
"pm_score": 6,
"selected": true,
"text": "<HTML>\n<HEAD>\n <SCRIPT>\n path = document.URL;\n document.write(\n '<HTA:APPLICATION ID=\"oHTA\" APPLICATIONNAME=\"myApp\" ICON=\"'+path+'\">');\n </SCRIPT>\n</HEAD>\n<BODY SCROLL=\"no\">\n Hello, World!\n</BODY>\n</HTML>\n copy /b icon.ico+source.hta iconapp.hta\n"
},
{
"answer_id": 21924835,
"author": "Stephen Quan",
"author_id": 881441,
"author_profile": "https://Stackoverflow.com/users/881441",
"pm_score": 2,
"selected": false,
"text": ".hta favicon.ico <HTML>\n<HEAD>\n <HTA:APPLICATION\n ID=\"oHTA\"\n APPLICATIONNAME=\"myApp\"\n ICON=\"https://stackoverflow.com/favicon.ico\">\n</HEAD>\n<BODY SCROLL=\"no\">\n Hello, World!\n</BODY>\n</HTML>\n"
},
{
"answer_id": 41581844,
"author": "Kerry Johnson",
"author_id": 7402315,
"author_profile": "https://Stackoverflow.com/users/7402315",
"pm_score": 0,
"selected": false,
"text": "<!DOCTYPE html>\n<html>\n<head>\n <HTA:APPLICATION\n ID=\"oHta\"\n APPLICATIONNAME=\"Icon test...\"\n ICON=\"favicon.ico\"\n />\n<LINK id=shortcutlink REL=\"SHORTCUT ICON\" HREF=\"favicon.ico\">\n<META http-equiv=\"x-ua-compatible\" content=\"text/html; charset=utf-8\">\n<TITLE>Icon test</TITLE>\n</head>\n\n<script language=vbscript>\n\nFunction fBase64Encode(sourceStr)\n\n Dim rarr()\n\n carr = Array( \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", _\n \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\" ,\"P\", _\n \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", _\n \"Y\", \"Z\", \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", _\n \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", _\n \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", _\n \"w\", \"x\", \"y\", \"z\", \"0\", \"1\", \"2\", \"3\", _\n \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"+\", \"/\") \n\n n = Len(sourceStr)-1\n\n ReDim rarr(n\\3)\n\n For i=0 To n Step 3\n a = Asc(Mid(sourceStr,i+1,1))\n If i < n Then\n b = Asc(Mid(sourceStr,i+2,1))\n Else\n b = 0\n End If\n If i < n-1 Then\n c = Asc(Mid(sourceStr,i+3,1))\n Else\n c = 0\n End If\n rarr(i\\3) = carr(a\\4) & carr((a And 3) * 16 + b\\16) & carr((b And 15) * 4 + c\\64) & carr(c And 63)\n Next\n\n i = UBound(rarr)\n If n Mod 3 = 0 Then\n rarr(i) = Left(rarr(i),2) & \"==\"\n ElseIf n Mod 3 = 1 Then\n rarr(i) = Left(rarr(i),3) & \"=\"\n End If\n\n fBase64Encode = Join(rarr,\"\")\n\nEnd Function\n'-------------------------------------------------------------------------------\n\nfunction fBase64Decode(str)\n\n fBase64Decode = \"\"\n\n table = fGenerateBase64Table\n\n bits = 0\n\n for x = 1 to len(str) step 1\n c = table(1+asc(mid(str,x,1)))\n if (c <> -1) then\n if (bits = 0) then\n outword = c*4\n bits = 6\n elseif (bits = 2) then\n outword = c+outword\n strBase64 = strBase64 & chr(clng(\"&H\" & hex(outword mod 256)))\n bits = 0\n elseif (bits = 4) then\n outword = outword + int(c/4)\n strBase64 = strBase64 & chr(clng(\"&H\" & hex(outword mod 256)))\n outword = c*64\n bits = 2\n else\n outword = outword + int(c/16)\n strBase64 = strBase64 & chr(clng(\"&H\" & hex(outword mod 256)))\n outword = c*16\n bits = 4\n end if\n end if\n next\n\n fBase64Decode = strBase64\n\nend function\n'---------------------------------------------------\n\nfunction fGenerateBase64Table()\n\n r64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"\n\n 'set up decode table\n dim table(256)\n for x = 1 to 256 step 1\n table(x) = -1\n next\n for x = 1 to 64 step 1\n table(1+asc(mid(r64,x,1))) = x - 1\n next\n\n fGenerateBase64Table = table\n\nend function\n'---------------------------------------------------\n\nfunction fSelectFile()\n\n fSelectFile = \"\"\n strMSHTA = \"mshta.exe \"\"about:<input type=file id=FILE>\" & _\n \"<\"&\"script>FILE.click();new ActiveXObject('Scripting.FileSystemObject')\" & _\n \".GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);<\"&\"/script>\"\"\"\n\n Set wshShell = CreateObject( \"WScript.Shell\" )\n Set objExec = wshShell.Exec( strMSHTA )\n fSelectFile = objExec.StdOut.ReadLine( )\n Set objExec = Nothing\n Set wshShell = Nothing\n\nend function\n\n'-------------------------------------------------------------------------\n\nsub getBase64()\n\n 'this can be BMP, PNG, ICO\n REM sImgFile = \"favicon.ico\"\n sImgFile = fSelectFile()\n\n if sImgFile = \"\" then exit sub\n\n Set fso = CreateObject(\"Scripting.FileSystemObject\")\n Set f = fso.GetFile(sImgFile)\n filesize = f.size\n set f = fso.opentextfile(sImgFile,1,0) 'open as ascii\n strBinFile = f.read(filesize)\n f.close\n set fso = nothing\n\n strPNGFile = fBase64Encode(strBinFile)\n s = s & \"Base64 encoding of \"&sImgFile&\"<br><br>\" & strPNGFile & \"<br><br>\"\n s = s & \"<img src=\"\"data:image/bmp;base64,\" & strPNGFile & \"\"\"><br><br>\" & vbcrlf\n\n imgbase64.innerhtml = s\n\nend sub\n'-------------------------------------------------------------------------\n\nsub setup()\n\n 'https://stackoverflow.com/favicon.ico in base64 \n base64Icon=\"AAABAAIAEBAAAAEAIABoBAAAJgAAACAgAAABACAAqBAAAI4EAAAoAAAAEAAAACAAAAABACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv8AAAAAAAAAAAAAAAAAAAAAAAAAAKmjnv8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACpo57/AAAAAAAAAAAAAAAAAAAAAAAAAACpo57/AAAAAAlw8v8JcPL/CXDy/wlw8v8JcPL/CXDy/wlw8v8AAAAAqaOe/wAAAAAAAAAAAAAAAAAAAAAAAAAAqaOe/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlw8hMJcPI2AAAAAKmjnv8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACXDyLwlw8l0JcPKJCXDytglw8uIJcPLvCXDyvQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlw8sIJcPKlCXDydwlw8kkJcPIdCXDyEwlw8nEJcPIvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJcPI9CXDypQlw8u8JcPKgCXDyLwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACXDyDwlw8nEJcPLWCXDy0wlw8msJcPIPCXDyPQlw8uIJcPInAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlw8iMJcPKgCXDyOgAAAAAAAAAACXDydwlw8ugJcPJGCXDyUQlw8oIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJcPITCXDytglw8sIJcPIdCXDyGAlw8ugJcPI2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJcPI6CXDy4glw8okJcPIDAAAAAAlw8rYJcPJ+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACXDyZAlw8kkAAAAAAAAAAAlw8msJcPLICXDyAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlw8icJcPLoCXDyIwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJcPLCCXDyZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACXDyHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//AADABwAA3/cAANAXAADflwAA8B8AAPAPAAD+DwAA8AcAAPGDAAD+AwAA/CcAAPzHAAD/jwAA/58AAP+/AAAoAAAAIAAAAEAAAAABACAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAKmjngCpo54AqaOeAP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wCpo54AqaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po54A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AKmjngCpo57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjnv+po57/qaOe/6mjngD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AqaOeAKmjnv+po57/JID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0AKmjnv+po57/JID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wCpo54AqaOe/6mjnv8kgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAqaOe/6mjnv8kgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AKmjngCpo57/qaOe/ySA9AAkgPQAJID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0ACSA9ACpo57/qaOe/ySA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8AqaOeAKmjnv+po57/JID0ACSA9AAkgPT/JID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0/ySA9P8kgPQAJID0AKmjnv+po57/JID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wCpo54AqaOe/6mjnv8kgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAqaOe/6mjnv8kgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AKmjngCpo57/qaOe/ySA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9B4kgPRRJID0gSSA9LQkgPTjJID0EiSA9ACpo57/qaOe/ySA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8AqaOeAKmjngCpo54AJID0ACSA9AAkgPQAJID0AiSA9CYkgPRXJID0iSSA9LokgPTtJID0/ySA9P8kgPT/JID0/ySA9P8kgPRKJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9LgkgPTxJID0/ySA9P8kgPT/JID0/ySA9P8kgPT/JID0+SSA9M0kgPSaJID0aiSA9CQkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0vSSA9P8kgPT/JID09CSA9MUkgPSUJID0YiSA9DEkgPQFJID0ACSA9DQkgPSjJID05iSA9A0kgPQAJID0ACSA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPRKJID0WySA9CkkgPQDJID0ACSA9AAkgPQAJID0BSSA9FgkgPTHJID0/ySA9P8kgPT/JID0eCSA9AAkgPQAJID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0FSSA9HwkgPTkJID0/ySA9P8kgPT/JID02SSA9GwkgPQ9JID0LCSA9AAkgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0MiSA9J8kgPT4JID0/ySA9P8kgPT+JID0tySA9EkkgPQCJID0YiSA9PckgPTjJID0HCSA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPQAJID0KiSA9MIkgPT/JID0/ySA9P8kgPTyJID0lCSA9CYkgPQAJID0CCSA9J8kgPT/JID0/ySA9OkkgPRGJID0IySA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9AAkgPQPJID07iSA9P8kgPTcJID0cCSA9A8kgPQAJID0ACSA9CQkgPTPJID0/ySA9P8kgPTDJID0HCSA9K4kgPTzJID0ZiSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0ACSA9AAkgPRaJID0TCSA9AIkgPQAJID0ACSA9AAkgPRQJID07ySA9P8kgPT+JID0jiSA9AUkgPR+JID0/ySA9P8kgPSOJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQEJID0iCSA9P4kgPT/JID08SSA9FQkgPQAJID0TSSA9P4kgPT/JID0uySA9AMkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0GCSA9MAkgPT/JID0/ySA9NMkgPQmJID0ACSA9CgkgPTwJID0/ySA9N4kgPQUJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9B8kgPTnJID0/ySA9P8kgPSiJID0CiSA9AAkgPQPJID02CSA9P8kgPT1JID0LiSA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9JYkgPT4JID0ZySA9AAkgPQAJID0AiSA9LQkgPT/JID0/iSA9FYkgPQAJID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0AySA9CokgPQAJID0ACSA9AAkgPSCJID0/ySA9P8kgPSIJID0ACSA9AAkgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0UySA9P4kgPT/JID0tySA9AMkgPQAJID0ACSA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9A8kgPTvJID0/ySA9NskgPQQJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9DQkgPTIJID0LCSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQA////AP///wD///8A////AP///wD///8A////AP///wD///8A////ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8AJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0ACSA9AAkgPQAJID0AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP////////////////wAAD/8AAA//P//P/z//z/8wAM//MADP/z//z/8/4E//+AB///AAf//wBD//8OA///+AH//+AA//+AQH//gYA//8cAP//8CD//+BB///Ag///4wf//+cP///+D////B////4///////////////////////\" \n\n Set fso = CreateObject(\"Scripting.FileSystemObject\")\n if not fso.fileexists(\"favicon.ico\") then\n strBin = fBase64Decode(base64Icon)\n set outfile = fso.createtextfile(\"favicon.ico\")\n outfile.write strBin\n outfile.close\n\n document.title = \"Need to refresh to see the new icon\"\n\n end if \n set fso = nothing\n\nend sub \n\n</script>\n\n<style type=\"text/css\">\n\n body {font-family:\"CONSOLAS\";font-size:\"10pt\";}\n input {font-family:\"CONSOLAS\";font-size:\"8pt\";}\n\n</style>\n\n<body onLoad=setup()>\n\n<input type=button value=\"Encode an image file...\" \ndata-tooltip title=\"Choose a PNG, BMP, ICO file to encode in base64\" \nonclick=getBase64>\n\n<br><br>\n\n<div id=imgbase64 style=\"word-wrap: break-word;\"></div>\n\n</body>\n</html>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/175994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20848/"
] |
176,011
|
<p>If you are creating a 1d array, you can implement it as a list, or else use the 'array' module in the standard library. I have always used lists for 1d arrays.</p>
<p>What is the reason or circumstance where I would want to use the array module instead?</p>
<p>Is it for performance and memory optimization, or am I missing something obvious?</p>
|
[
{
"answer_id": 176589,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 10,
"selected": true,
"text": "float uint64_t array.array sizeof(one object) * length ioctl fctnl array.array array('B', bytes) bytearray array.array"
},
{
"answer_id": 62399645,
"author": "Hephaestus",
"author_id": 985088,
"author_profile": "https://Stackoverflow.com/users/985088",
"pm_score": 3,
"selected": false,
"text": "# Python list with append()\nnp.mean(timeit.repeat(setup=\"a = []\", stmt=\"a.append(1.0)\", number=1000, repeat=5000)) * 1000\n# 0.054 +/- 0.025 msec\n\n# Python array with append()\nnp.mean(timeit.repeat(setup=\"import array; a = array.array('f')\", stmt=\"a.append(1.0)\", number=1000, repeat=5000)) * 1000\n# 0.104 +/- 0.025 msec\n\n# Numpy array with append()\nnp.mean(timeit.repeat(setup=\"import numpy as np; a = np.array([])\", stmt=\"np.append(a, [1.0])\", number=1000, repeat=5000)) * 1000\n# 5.183 +/- 0.950 msec\n\n# Python list using +=\nnp.mean(timeit.repeat(setup=\"a = []\", stmt=\"a += [1.0]\", number=1000, repeat=5000)) * 1000\n# 0.062 +/- 0.021 msec\n\n# Python array using += \nnp.mean(timeit.repeat(setup=\"import array; a = array.array('f')\", stmt=\"a += array.array('f', [1.0]) \", number=1000, repeat=5000)) * 1000\n# 0.289 +/- 0.043 msec\n\n# Python list using extend()\nnp.mean(timeit.repeat(setup=\"a = []\", stmt=\"a.extend([1.0])\", number=1000, repeat=5000)) * 1000\n# 0.083 +/- 0.020 msec\n\n# Python array using extend()\nnp.mean(timeit.repeat(setup=\"import array; a = array.array('f')\", stmt=\"a.extend([1.0]) \", number=1000, repeat=5000)) * 1000\n# 0.169 +/- 0.034\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16148/"
] |
176,051
|
<p>I want to save and store simple mail objects via serializing, but I get always an error and I can't find where it is.</p>
<pre><code>package sotring;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import com.sun.org.apache.bcel.internal.generic.INEG;
public class storeing {
public static void storeMail(Message[] mail){
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("mail.ser"));
out.writeObject(mail);
out.flush();
out.close();
} catch (IOException e) {
}
}
public static Message[] getStoredMails(){
try
{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("mail.ser"));
Message[] array = (Message[]) in.readObject() ;
for (int i=0; i< array.length;i++)
System.out.println("EMail von:"+ array[i].getSender() + " an " + array[i].getReceiver()+ " Emailbetreff: "+ array[i].getBetreff() + " Inhalt: " + array[i].getContent());
System.out.println("Size: "+array.length); //return array;
in.close();
return array;
}
catch(IOException ex)
{
ex.printStackTrace();
return null;
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
return null;
}
}
public static void main(String[] args) {
User user1 = new User("User1", "geheim");
User user2 = new User("User2", "geheim");
Message email1 = new Message(user1.getName(), user2.getName(), "Test", "Fooobaaaar");
Message email2 = new Message(user1.getName(), user2.getName(), "Test2", "Woohoo");
Message email3 = new Message(user1.getName(), user2.getName(), "Test3", "Okay =) ");
Message [] mails = {email1, email2, email3};
storeMail(mails);
Message[] restored = getStoredMails();;
}
}
</code></pre>
<p>Here are the user and message class</p>
<pre><code>public class Message implements Serializable{
static final long serialVersionUID = -1L;
private String receiver; //Empfänger
private String sender; //Absender
private String Betreff;
private String content;
private String timestamp;
private String getDateTime() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}
Message (String receiver, String sender, String Betreff, String content) {
this.Betreff= Betreff;
this.receiver = receiver;
this.sender = sender;
this.content = content;
this.timestamp = getDateTime();
}
Message() { // Just for loaded msg
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getBetreff() {
return Betreff;
}
public void setBetreff(String betreff) {
Betreff = betreff;
}
public String getContent() {
return content;
}
public String getTime() {
return timestamp;
}
public void setContent(String content) {
this.content = content;
}
}
public class User implements Serializable{
static final long serialVersionUID = -1L;
private String username; //unique Username
private String ipadress; //changes everytime
private String password; //Password
private int unreadMsg; //Unread Messages
private static int usercount;
private boolean online;
public String getName(){
return username;
}
public boolean Status() {
return online;
}
public void setOnline() {
this.online = true;
}
public void setOffline() {
this.online = false;
}
User(String username,String password){
if (true){
this.username = username;
this.password = password;
usercount++;
} else System.out.print("Username not availiable");
}
public void changePassword(String newpassword){
password = newpassword;
}
public void setIP(String newip){
ipadress = newip;
}
public String getIP(){
if (ipadress.length() >= 7){
return ipadress;
} else return "ip address not set.";
}
public int getUnreadMsg() {
return unreadMsg;
}
}
</code></pre>
<p>Here is the exception:</p>
<p><code>exception in thread "main" java.lang.Error: Unresolved compilation problem:
This method must return a result of type Message[]
at sotring.storeing.getStoredMails(storeing.java:22)
at sotring.storeing.main(storeing.java:57)</code></p>
<p>THANK YOU FOR YOUR HELP!!!!!!!!!!!</p>
|
[
{
"answer_id": 176068,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 3,
"selected": false,
"text": "public static Message[] getStoredMails(){\n\n try\n {\n\n ObjectInputStream in = new ObjectInputStream(new FileInputStream(\"mail.ser\"));\n Message[] array = (Message[]) in.readObject() ;\n System.out.println(\"Size: \"+array.length); //return array;\n in.close();\n return array; \n }\n catch(IOException ex)\n {\n ex.printStackTrace();\n }\n catch(ClassNotFoundException ex)\n {\n ex.printStackTrace();\n } \n return null; //fix \n}\n"
},
{
"answer_id": 176157,
"author": "Declan Shanaghy",
"author_id": 21297,
"author_profile": "https://Stackoverflow.com/users/21297",
"pm_score": 1,
"selected": false,
"text": "public static Message[] getStoredMails(){\n\n try\n {\n\n ObjectInputStream in = new ObjectInputStream(new FileInputStream(\"mail.ser\"));\n Message[] array = (Message[]) in.readObject() ;\n System.out.println(\"Size: \"+array.length); //return array;\n in.close();\n return array; \n }\n catch(IOException ex)\n {\n ex.printStackTrace();\n }\n catch(ClassNotFoundException ex)\n {\n ex.printStackTrace();\n } \n\n return null; \n }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25128/"
] |
176,058
|
<p>I was wondering is there is a fool-proof way to run a program on windows such that I'm <b>guaranteed</b> that <b>no interactive dialogs of any kind</b> are displayed.</p>
<p>I've tried the registry ErrorMode hack, calling _CrtSetReportMode(), etc., but they all have holes in them or require you to modify the program.</p>
<p>I need a way to run an <b>arbitrary</b> program and practically force Windows to execute them such that there is no possibility for them to open a window. It is perfectly ok for the program to crash if it attempts to open a window.</p>
<p>Would running the program as a service solve the problem?</p>
|
[
{
"answer_id": 176068,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 3,
"selected": false,
"text": "public static Message[] getStoredMails(){\n\n try\n {\n\n ObjectInputStream in = new ObjectInputStream(new FileInputStream(\"mail.ser\"));\n Message[] array = (Message[]) in.readObject() ;\n System.out.println(\"Size: \"+array.length); //return array;\n in.close();\n return array; \n }\n catch(IOException ex)\n {\n ex.printStackTrace();\n }\n catch(ClassNotFoundException ex)\n {\n ex.printStackTrace();\n } \n return null; //fix \n}\n"
},
{
"answer_id": 176157,
"author": "Declan Shanaghy",
"author_id": 21297,
"author_profile": "https://Stackoverflow.com/users/21297",
"pm_score": 1,
"selected": false,
"text": "public static Message[] getStoredMails(){\n\n try\n {\n\n ObjectInputStream in = new ObjectInputStream(new FileInputStream(\"mail.ser\"));\n Message[] array = (Message[]) in.readObject() ;\n System.out.println(\"Size: \"+array.length); //return array;\n in.close();\n return array; \n }\n catch(IOException ex)\n {\n ex.printStackTrace();\n }\n catch(ClassNotFoundException ex)\n {\n ex.printStackTrace();\n } \n\n return null; \n }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13051/"
] |
176,061
|
<p>I'm building an application that is used by several different customers. Each customer has a fair amount of custom business logic, which I have cleverly refactored out into an assembly that gets loaded at runtime. The name of that assembly, along with a number of other customer-specific settings, are stored in the application's configuration file.</p>
<p>Right now, here's what I have to do in order to debug the application for customer foo:</p>
<ol>
<li>Go to the filesystem in my project directory and delete <code>app.config</code></li>
<li>Copy <code>app.config.foo</code> to <code>app.config.foo - Copy</code>.</li>
<li>Rename <code>app.config.foo - Copy</code> as <code>app.config</code>.</li>
<li>Tell Windows that yes, I want to change the file's extension.</li>
<li>Switch back to Visual Studio.</li>
<li>Open the <code>Settings.settings</code> item in my project.</li>
<li>Click "Yes" 13 or 14 times as VS asks me if I want to use the new settings that have been changed in <code>app.config</code>.</li>
<li>Close <code>Settings.settings</code>.</li>
</ol>
<p>Okay! Now I'm ready to debug!</p>
<p>It seems to me that the rigamarole of opening <code>Settings.settings</code> is, or ought to be, unnecessary: I don't need the default values in <code>Settings.cs</code> to be regenerated, because I don't use them. But it's the only way I know of to make VS aware of the fact that the <code>app.config</code> file has changed, so that the build will copy it to the output directory.</p>
<p>There's got to be an easier way of doing this. What is it?</p>
|
[
{
"answer_id": 1371662,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 3,
"selected": true,
"text": "app.config.XXX app.config Settings.cs app.config.XXX bin\\debug\\myprogram.exe.config bin\\release\\myprogram.exe.config"
},
{
"answer_id": 5676433,
"author": "Rafael",
"author_id": 709762,
"author_profile": "https://Stackoverflow.com/users/709762",
"pm_score": 2,
"selected": false,
"text": "configuration files"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19403/"
] |
176,062
|
<p>I have the following unmanaged C++ code:</p>
<pre><code>MessageBox( NULL, strMessage, "Cool Product", MB_RETRYCANCEL | MB_ICONEXCLAMATION);
</code></pre>
<p>I want to disable the RETRY button for 10 seconds (for example), then enable it.</p>
<p>How can I do this?</p>
|
[
{
"answer_id": 176149,
"author": "efotinis",
"author_id": 12320,
"author_profile": "https://Stackoverflow.com/users/12320",
"pm_score": 1,
"selected": false,
"text": "_ _"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16794/"
] |
176,084
|
<p>When writing the string "¿" out using</p>
<pre><code>System.out.println(new String("¿".getBytes("UTF-8")));
</code></pre>
<p>¿ is written instead of just ¿.</p>
<p>WHY? And how do we fix it?</p>
|
[
{
"answer_id": 176154,
"author": "p3t0r",
"author_id": 16685,
"author_profile": "https://Stackoverflow.com/users/16685",
"pm_score": 4,
"selected": true,
"text": "new String(\"¿\".getBytes(\"UTF-8\"), \"UTF-8\");\n getBytes()"
},
{
"answer_id": 176162,
"author": "John Meagher",
"author_id": 3535,
"author_profile": "https://Stackoverflow.com/users/3535",
"pm_score": 1,
"selected": false,
"text": "System.out.println(new String(\"¿\".getBytes(\"UTF-8\"), \"UTF-8\"));\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176084",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9518/"
] |
176,088
|
<p>Is it possible to open an HTML page using navigateToURL and specifying a named frame in your HTML document? For instance, if you have an iframe on the page called "Steven", can you call</p>
<pre><code>navigateToURL("someURL","Steven");
</code></pre>
<p>instead of something like</p>
<pre><code>navigateToURL("someURL","_self");
</code></pre>
<p>I have tried this and it opens the URL in a new window.</p>
|
[
{
"answer_id": 176108,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 0,
"selected": false,
"text": "navigateToURL(\"javascript:loadFrame(someURL)\");\n function loadFrame(url) {\n documents.frames[1].src=url\n}\n"
},
{
"answer_id": 177138,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 2,
"selected": true,
"text": "navigateToURL()"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25280/"
] |
176,093
|
<p>Is there a way to use a Graphics object's 'setClip()' method to clip using a Line-ish shape? Right now I'm trying to use a Polygon shape but I'm having problems simulating the "width" of the line. I basically draw the line, and when I reach the end, I redraw it but this time subtract the line width from y-coordinate:</p>
<pre><code>Polygon poly = new Polygon();
for(int i = 0; i < points.length; i++)
poly.addPoint(points.[i].x, points.[i].y);
// Retrace line to add 'width'
for(int i = points.length - 1; i >=0; i--)
poly.addPoint(points[i].x, points[i].y - lineHeight);
</code></pre>
<p>It almost works but the width of the line varies based upon its slope. </p>
<p>I can't use the BrushStroke and drawLine() methods because the line can change color once it passes some arbitrary reference line. Is there some implementation of Shape that I overlooked, or an easy one I can create, that will let me do this more easily?</p>
|
[
{
"answer_id": 176399,
"author": "Tim Frey",
"author_id": 1471,
"author_profile": "https://Stackoverflow.com/users/1471",
"pm_score": 1,
"selected": false,
"text": "BufferedImage mask = g2d.getDeviceConfiguration().createCompatibleImage(width, height, BufferedImage.TRANSLUCENT);\nGraphics2D maskGraphics = (Graphics2D) mask.getGraphics();\nmaskGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\n\nmaskGraphics.setStroke(new BasicStroke(lineWidth));\nmaskGraphics.setPaint(Color.BLACK);\n\n// Draw line onto mask surface first.\nPoint prev = line.get(0);\nfor(int i = 1; i < line.size(); i++)\n{\n Point current = line.get(i);\n maskGraphics.drawLine(prev.x, prev.y, current.x, current.y);\n prev = current;\n}\n\n// AlphaComposite.SrcIn: \"If pixels in the source and the destination overlap, only the source pixels\n// in the overlapping area are rendered.\"\nmaskGraphics.setComposite(AlphaComposite.SrcIn);\n\nmaskGraphics.setPaint(top);\nmaskGraphics.fillRect(0, 0, width, referenceY);\n\nmaskGraphics.setPaint(bottom);\nmaskGraphics.fillRect(0, referenceY, width, height);\n\ng2d.drawImage(mask, null, 0, 0);\nmaskGraphics.dispose();\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1471/"
] |
176,106
|
<p>I need to be able to validate a string against a list of the possible United States Postal Service state abbreviations, and Google is not offering me any direction. </p>
<p>I know of the obvious solution: and that is to code a horridly huge if (or switch) statement to check and compare against all 50 states, but I am asking StackOverflow, since there has to be an easier way of doing this. Is there any RegEx or an enumerator object out there that I could use to quickly do this the most efficient way possible?</p>
<p>[C# and .net 3.5 by the way]</p>
<p><a href="https://www.usps.com/send/official-abbreviations.htm" rel="noreferrer">List of USPS State Abbreviations</a></p>
|
[
{
"answer_id": 176127,
"author": "Ben Hoffstein",
"author_id": 4482,
"author_profile": "https://Stackoverflow.com/users/4482",
"pm_score": 3,
"selected": false,
"text": "^(?-i:A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$\n"
},
{
"answer_id": 176291,
"author": "Craig Trader",
"author_id": 12895,
"author_profile": "https://Stackoverflow.com/users/12895",
"pm_score": 6,
"selected": true,
"text": "private static String states = \"|AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|\";\n\npublic static bool isStateAbbreviation (String state)\n{\n return state.Length == 2 && states.IndexOf( state ) > 0;\n}\n"
},
{
"answer_id": 69489334,
"author": "kbrannen",
"author_id": 908522,
"author_profile": "https://Stackoverflow.com/users/908522",
"pm_score": 0,
"selected": false,
"text": "/* assumes 2 letter code is in upper case, returns 1 if valid or 0 if not */\nint validate_state( const char *state )\n{\n if (state[0] == ' ' || state[1] == ' ' || state[2] != '\\0') return 0;\n return strstr(\"WVALAKSCARIDE CTNVTX NHINMNCOKY MSD MIA MOR WIL GAZ FL ME MD MA MT NE NJ NY ND OH PA UT WA WY\", state) ? 1 : 0;\n}\n /* assumes 2 letter code is in upper case */\nbool ValidateState(string state)\n{\n const string ValidStatesMerged = \"WVALAKSCARIDE CTNVTX NHINMNCOKY MSD MIA MOR WIL GAZ FL ME MD MA MT NE NJ NY ND OH PA UT WA WY\";\n\n if (state == null)\n throw new ArgumentNullException(nameof(state));\n if (state.Length != 2 || state[0] == ' ' || state[1] == ' ')\n return false;\n return ValidStatesMerged.IndexOf(state) >= 0;\n}\n state \"WV\" \"VA\" \"WVA\""
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/506/"
] |
176,113
|
<p>The project I'm on is using a 3rd party component to build dynamic PDFs in a VB.Net web system called ABCpdf.Net. (not a terrible tool, but not a great one either.)</p>
<p>Every now and then, for reasons I can't fathom, the document object throws a SEHException. Digging futher, it turns out this is caused by a custom exception in the document object of the type WebSupergoo.ABCpdf6.Internal.PDFException. The contents contains only the not -terribly-helpful title "Unable to get image data. Out Of Memory" Usually this happens when trying to add an image to the PDF. Since these images are PNGs of less than 100k, I'm guessing their size isn't the issue.</p>
<p>Also, the really strange thing is that once this issue starts happening, the only way to get it to stop seems to be to reboot the web server, which is clearly a little sub-par.</p>
<p>Has anyone ever had this problem (or even used this tool?)</p>
|
[
{
"answer_id": 176143,
"author": "Craig Wilson",
"author_id": 25333,
"author_profile": "https://Stackoverflow.com/users/25333",
"pm_score": 1,
"selected": false,
"text": "\nDim doc As New Doc()\n'etc...\n \n Dim doc as Doc\n Using doc As New Doc()\n 'etc...\n End Using\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19074/"
] |
176,118
|
<p>Apparently there's a lot of variety in opinions out there, ranging from, "<strong>Never! Always encapsulate (even if it's with a mere macro!)</strong>" to "<strong>It's no big deal – use them when it's more convenient than not.</strong>"</p>
<p>So.</p>
<p>Specific, concrete reasons (preferably with an example)</p>
<ul>
<li>Why global variables are dangerous</li>
<li>When global variables <em>should</em> be used in place of alternatives</li>
<li>What alternatives exist for those that are tempted to use global variables inappropriately</li>
</ul>
<p>While this is subjective, I will pick one answer (that to me best represents the love/hate relationship every developer should have with globals) and the community will vote theirs to just below.</p>
<p>I believe it's important for newbies to have this sort of reference, but please don't clutter it up if another answer exists that's substantially similar to yours – add a comment or edit someone else's answer.</p>
|
[
{
"answer_id": 176428,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 4,
"selected": false,
"text": ".h .h"
},
{
"answer_id": 5052330,
"author": "yingted",
"author_id": 556493,
"author_profile": "https://Stackoverflow.com/users/556493",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#define MAX_INPUT 46\nint runs=0;\nint fib1(int n){\n ++runs;\n return n>2?fib1(n-1)+fib1(n-2):1;\n};\nint fib2(int n,int *cache,int *len){\n ++runs;\n if(n<=2){\n if(*len==2)\n return 1;\n *len=2;\n return cache[0]=cache[1]=1;\n }else if(*len>=n)\n return cache[n-1];\n else{\n if(*len!=n-1)\n fib2(n-1,cache,len);\n *len=n;\n return cache[n-1]=cache[n-2]+cache[n-3];\n };\n};\nint main(){\n int n;\n int cache[MAX_INPUT];\n int len=0;\n scanf(\"%i\",&n);\n if(!n||n>MAX_INPUT)\n return 0;\n printf(\"fib1(%i)==%i\",n,fib1(n));\n printf(\", %i run(s)\\n\",runs);\n runs=0;\n printf(\"fib2(%i)==%i\",n,fib2(n,&cache,&len));\n printf(\", %i run(s)\\n\",runs);\n main();\n};\n"
},
{
"answer_id": 59490268,
"author": "Onat Korucu",
"author_id": 10037278,
"author_profile": "https://Stackoverflow.com/users/10037278",
"pm_score": 1,
"selected": false,
"text": "public static SettingForIncubator settings;\n\npublic static void main(String[] args) {\n while(true){\n SettingsForIncubator settings = getSettings(args);\n\n int counter=0;\n\n while(medicalDeviceIsGivingData && counter < 1000){\n readData(); //using settings\n\n //a lot of of other functions that use settings.\n\n counter++;\n }\n } \n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] |
176,137
|
<p>Does anyone know of a way, in Java, to convert an earth surface position from lat, lon to UTM (say in WGS84)? I'm currently looking at Geotools but unfortunately the solution is not obvious.</p>
|
[
{
"answer_id": 176925,
"author": "Steve Kuo",
"author_id": 24396,
"author_profile": "https://Stackoverflow.com/users/24396",
"pm_score": 5,
"selected": true,
"text": "double utmZoneCenterLongitude = ... // Center lon of zone, example: zone 10 = -123\nint zoneNumber = ... // zone number, example: 10\ndouble latitude, longitude = ... // lat, lon in degrees\n\nMathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(null);\nReferencingFactoryContainer factories = new ReferencingFactoryContainer(null);\n\nGeographicCRS geoCRS = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84;\nCartesianCS cartCS = org.geotools.referencing.cs.DefaultCartesianCS.GENERIC_2D;\n\nParameterValueGroup parameters = mtFactory.getDefaultParameters(\"Transverse_Mercator\");\nparameters.parameter(\"central_meridian\").setValue(utmZoneCenterLongitude);\nparameters.parameter(\"latitude_of_origin\").setValue(0.0);\nparameters.parameter(\"scale_factor\").setValue(0.9996);\nparameters.parameter(\"false_easting\").setValue(500000.0);\nparameters.parameter(\"false_northing\").setValue(0.0);\n\nMap properties = Collections.singletonMap(\"name\", \"WGS 84 / UTM Zone \" + zoneNumber);\nProjectedCRS projCRS = factories.createProjectedCRS(properties, geoCRS, null, parameters, cartCS);\n\nMathTransform transform = CRS.findMathTransform(geoCRS, projCRS);\n\ndouble[] dest = new double[2];\ntransform.transform(new double[] {longitude, latitude}, 0, dest, 0, 1);\n\nint easting = (int)Math.round(dest[0]);\nint northing = (int)Math.round(dest[1]);\n"
},
{
"answer_id": 28224544,
"author": "user2548538",
"author_id": 2548538,
"author_profile": "https://Stackoverflow.com/users/2548538",
"pm_score": 6,
"selected": false,
"text": "private class Deg2UTM\n{\n double Easting;\n double Northing;\n int Zone;\n char Letter;\n private Deg2UTM(double Lat,double Lon)\n {\n Zone= (int) Math.floor(Lon/6+31);\n if (Lat<-72) \n Letter='C';\n else if (Lat<-64) \n Letter='D';\n else if (Lat<-56)\n Letter='E';\n else if (Lat<-48)\n Letter='F';\n else if (Lat<-40)\n Letter='G';\n else if (Lat<-32)\n Letter='H';\n else if (Lat<-24)\n Letter='J';\n else if (Lat<-16)\n Letter='K';\n else if (Lat<-8) \n Letter='L';\n else if (Lat<0)\n Letter='M';\n else if (Lat<8) \n Letter='N';\n else if (Lat<16) \n Letter='P';\n else if (Lat<24) \n Letter='Q';\n else if (Lat<32) \n Letter='R';\n else if (Lat<40) \n Letter='S';\n else if (Lat<48) \n Letter='T';\n else if (Lat<56) \n Letter='U';\n else if (Lat<64) \n Letter='V';\n else if (Lat<72) \n Letter='W';\n else\n Letter='X';\n Easting=0.5*Math.log((1+Math.cos(Lat*Math.PI/180)*Math.sin(Lon*Math.PI/180-(6*Zone-183)*Math.PI/180))/(1-Math.cos(Lat*Math.PI/180)*Math.sin(Lon*Math.PI/180-(6*Zone-183)*Math.PI/180)))*0.9996*6399593.62/Math.pow((1+Math.pow(0.0820944379, 2)*Math.pow(Math.cos(Lat*Math.PI/180), 2)), 0.5)*(1+ Math.pow(0.0820944379,2)/2*Math.pow((0.5*Math.log((1+Math.cos(Lat*Math.PI/180)*Math.sin(Lon*Math.PI/180-(6*Zone-183)*Math.PI/180))/(1-Math.cos(Lat*Math.PI/180)*Math.sin(Lon*Math.PI/180-(6*Zone-183)*Math.PI/180)))),2)*Math.pow(Math.cos(Lat*Math.PI/180),2)/3)+500000;\n Easting=Math.round(Easting*100)*0.01;\n Northing = (Math.atan(Math.tan(Lat*Math.PI/180)/Math.cos((Lon*Math.PI/180-(6*Zone -183)*Math.PI/180)))-Lat*Math.PI/180)*0.9996*6399593.625/Math.sqrt(1+0.006739496742*Math.pow(Math.cos(Lat*Math.PI/180),2))*(1+0.006739496742/2*Math.pow(0.5*Math.log((1+Math.cos(Lat*Math.PI/180)*Math.sin((Lon*Math.PI/180-(6*Zone -183)*Math.PI/180)))/(1-Math.cos(Lat*Math.PI/180)*Math.sin((Lon*Math.PI/180-(6*Zone -183)*Math.PI/180)))),2)*Math.pow(Math.cos(Lat*Math.PI/180),2))+0.9996*6399593.625*(Lat*Math.PI/180-0.005054622556*(Lat*Math.PI/180+Math.sin(2*Lat*Math.PI/180)/2)+4.258201531e-05*(3*(Lat*Math.PI/180+Math.sin(2*Lat*Math.PI/180)/2)+Math.sin(2*Lat*Math.PI/180)*Math.pow(Math.cos(Lat*Math.PI/180),2))/4-1.674057895e-07*(5*(3*(Lat*Math.PI/180+Math.sin(2*Lat*Math.PI/180)/2)+Math.sin(2*Lat*Math.PI/180)*Math.pow(Math.cos(Lat*Math.PI/180),2))/4+Math.sin(2*Lat*Math.PI/180)*Math.pow(Math.cos(Lat*Math.PI/180),2)*Math.pow(Math.cos(Lat*Math.PI/180),2))/3);\n if (Letter<'M')\n Northing = Northing + 10000000;\n Northing=Math.round(Northing*100)*0.01;\n }\n}\n\nprivate class UTM2Deg\n{\n double latitude;\n double longitude;\n private UTM2Deg(String UTM)\n {\n String[] parts=UTM.split(\" \");\n int Zone=Integer.parseInt(parts[0]);\n char Letter=parts[1].toUpperCase(Locale.ENGLISH).charAt(0);\n double Easting=Double.parseDouble(parts[2]);\n double Northing=Double.parseDouble(parts[3]); \n double Hem;\n if (Letter>'M')\n Hem='N';\n else\n Hem='S'; \n double north;\n if (Hem == 'S')\n north = Northing - 10000000;\n else\n north = Northing;\n latitude = (north/6366197.724/0.9996+(1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)-0.006739496742*Math.sin(north/6366197.724/0.9996)*Math.cos(north/6366197.724/0.9996)*(Math.atan(Math.cos(Math.atan(( Math.exp((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*( 1 - 0.006739496742*Math.pow((Easting - 500000) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996 )/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996)))*Math.tan((north-0.9996*6399593.625*(north/6366197.724/0.9996 - 0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996 )*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996))-north/6366197.724/0.9996)*3/2)*(Math.atan(Math.cos(Math.atan((Math.exp((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996)))*Math.tan((north-0.9996*6399593.625*(north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3))/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996))-north/6366197.724/0.9996))*180/Math.PI;\n latitude=Math.round(latitude*10000000);\n latitude=latitude/10000000;\n longitude =Math.atan((Math.exp((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3))-Math.exp(-(Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2)/3)))/2/Math.cos((north-0.9996*6399593.625*( north/6366197.724/0.9996-0.006739496742*3/4*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.pow(0.006739496742*3/4,2)*5/3*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2* north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4-Math.pow(0.006739496742*3/4,3)*35/27*(5*(3*(north/6366197.724/0.9996+Math.sin(2*north/6366197.724/0.9996)/2)+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/4+Math.sin(2*north/6366197.724/0.9996)*Math.pow(Math.cos(north/6366197.724/0.9996),2)*Math.pow(Math.cos(north/6366197.724/0.9996),2))/3)) / (0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2))))*(1-0.006739496742*Math.pow((Easting-500000)/(0.9996*6399593.625/Math.sqrt((1+0.006739496742*Math.pow(Math.cos(north/6366197.724/0.9996),2)))),2)/2*Math.pow(Math.cos(north/6366197.724/0.9996),2))+north/6366197.724/0.9996))*180/Math.PI+Zone*6-183;\n longitude=Math.round(longitude*10000000);\n longitude=longitude/10000000; \n } \n}\n"
},
{
"answer_id": 33806387,
"author": "russellhoff",
"author_id": 828551,
"author_profile": "https://Stackoverflow.com/users/828551",
"pm_score": 1,
"selected": false,
"text": "public void setPunto(Point punto) {\n this.punto = punto;\n LatLon latlon = UTMCoord.locationFromUTMCoord(30, AVKey.NORTH, punto.getX(), punto.getY());\n this.latitud = latlon.getLatitude().degrees;\n this.longitud = latlon.getLongitude().degrees;\n}\n"
},
{
"answer_id": 38399170,
"author": "Dominic",
"author_id": 3049015,
"author_profile": "https://Stackoverflow.com/users/3049015",
"pm_score": 3,
"selected": false,
"text": "Coordinate coordinate = new Coordinate(x, y);\nMathTransform transform = CRS.findMathTransform(CRS.decode(\"EPSG:4326\"), CRS.decode(\"EPSG:3857\"), false);\nJTS.transform(coordinate, coordinate, transform); \n <repositories>\n <repository>\n <id>osgeo</id>\n <name>Open Source Geospatial Foundation Repository</name>\n <url>http://download.osgeo.org/webdav/geotools/</url>\n </repository>\n</repositories>\n\n<dependencies>\n <dependency>\n <groupId>org.geotools</groupId>\n <artifactId>gt-api</artifactId>\n <version>${geotools.version}</version>\n </dependency>\n <dependency>\n <groupId>org.geotools</groupId>\n <artifactId>gt-epsg-hsql</artifactId>\n <version>${geotools.version}</version>\n </dependency>\n</dependencies>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
176,150
|
<p>I'm working with a combobox in a Swing-based application, and I'm having a hard time figuring out what to do to differentiate between an ItemEvent that is generated from a user event vs one caused by the application. </p>
<p>For instance, Lets say I have a combobox, '<code>combo</code>' and I'm listening for itemStateChanged events with my ItemListener, '<code>listener</code>'. When either a user changes the selection to item 2 or I execute the line (pseudocode):</p>
<p><code>combo.setSelection(2)</code></p>
<p>.. it seems like I'm not able to tell these events apart. </p>
<p>That said, I'm no Swing expert by any means, so I thought I would ask. </p>
<p>Thanks!</p>
|
[
{
"answer_id": 177636,
"author": "Rastislav Komara",
"author_id": 22068,
"author_profile": "https://Stackoverflow.com/users/22068",
"pm_score": 3,
"selected": true,
"text": "class ApplicationDataModel {\n\n private Flag current = Flag.RW;\n\n public void setData(ApplicationData data) {\n current = Flag.RO;\n setDataImpl(data);\n notifyObservers();\n current = Flag.RW;\n }\n\n public void reaction(Event e) {\n if (flag = Flag.RO) return;\n ...\n }\n\n}\n ApplicationData"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13812/"
] |
176,158
|
<p>Is it possible to create an STL-like container, or even just an STL-style iterator, for an existing array of POD-type elements?</p>
<p>For example, suppose I have an array of ints. It would be convenient to be able to call some of the STL functions, such as find_if, count_if, or sort directly on this array.</p>
<p>Non-solution: copying the entire array, or even just references to the elements. The goal is to be very memory- and time-saving while hopefully allowing use of other STL algorithms.</p>
|
[
{
"answer_id": 176167,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 2,
"selected": false,
"text": "int a[100];\nfor (int i = 0; i < 100; ++i)\n a[i] = 0;\n boost::array<int,100> a;\nfor (boost::array<int,100>::iterator i = a.begin(); i != a.end(); ++i)\n *i = 0;\n std::array"
},
{
"answer_id": 176173,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 6,
"selected": true,
"text": "int ary[100];\n// init ...\n\nstd::sort(ary, ary+100); // sorts the array\nstd::find(ary, ary+100, pred); find some element\n"
},
{
"answer_id": 176177,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 3,
"selected": false,
"text": "#include <algorithm>\n#include <iostream>\n#include <iterator>\n\nint main()\n{\n int data[] = {4,3,7,5,8};\n std::sort(data,data+5);\n\n std::copy(data,data+5,std::ostream_iterator<int>(std::cout,\"\\t\"));\n}\n"
},
{
"answer_id": 176207,
"author": "Matt Price",
"author_id": 852,
"author_profile": "https://Stackoverflow.com/users/852",
"pm_score": 2,
"selected": false,
"text": "struct Bob\n{ int val; };\n\nbool operator<(const Bob& lhs, const Bob& rhs)\n{ return lhs.val < rhs.val; }\n\n// let's do a reverse sort\nbool pred(const Bob& lhs, const Bob& rhs)\n{ return lhs.val > rhs.val; }\n\nbool isBobNumberTwo(const Bob& bob) { return bob.val == 2; }\n\nint main()\n{\n Bob bobs[4]; // ok, so we have 4 bobs!\n const size_t size = sizeof(bobs)/sizeof(Bob);\n bobs[0].val = 1; bobs[1].val = 4; bobs[2].val = 2; bobs[3].val = 3;\n\n // sort using std::less<Bob> wich uses operator <\n std::sort(bobs, bobs + size);\n std::cout << bobs[0].val << std::endl;\n std::cout << bobs[1].val << std::endl;\n std::cout << bobs[2].val << std::endl;\n std::cout << bobs[3].val << std::endl;\n\n // sort using pred\n std::sort(bobs, bobs + size, pred);\n std::cout << bobs[0].val << std::endl;\n std::cout << bobs[1].val << std::endl;\n std::cout << bobs[2].val << std::endl;\n std::cout << bobs[3].val << std::endl;\n\n //Let's find Bob number 2\n Bob* bob = std::find_if(bobs, bobs + size, isBobNumberTwo);\n if (bob->val == 2)\n std::cout << \"Ok, found the right one!\\n\";\n else \n std::cout << \"Whoops!\\n\";\n\n return 0;\n}\n"
},
{
"answer_id": 176270,
"author": "Richard Corden",
"author_id": 11698,
"author_profile": "https://Stackoverflow.com/users/11698",
"pm_score": 3,
"selected": false,
"text": "template <typename T, int I>\ninline T * array_begin (T (&t)[I])\n{\n return t;\n}\n\ntemplate <typename T, int I>\ninline T * array_end (T (&t)[I])\n{\n return t + I;\n}\n\nvoid foo ()\n{\n int array[100];\n std::find (array_begin (array)\n , array_end (array)\n , 10);\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3561/"
] |
176,159
|
<p>In most modern IDEs, you can have Debug and Release build configurations, and you can quickly switch between them.</p>
<p>In Delphi 7, this does not seem to be possible. I have to go to Project Settings and toggle optimization and all the debug information stuff manually.</p>
<p>It would be great if there was a plugin or some such that handled this for me.</p>
<p>Does anyone know of one? Any other suggestions?</p>
<p><strong>Edit:</strong> I can't upgrade to Delphi 2007 or 2009 as we have a large Delphi 7 codebase which would have to be converted. I agree that would be the best solution in theory though :P</p>
|
[
{
"answer_id": 176187,
"author": "PatrickvL",
"author_id": 12170,
"author_profile": "https://Stackoverflow.com/users/12170",
"pm_score": 3,
"selected": false,
"text": "{$IFDEF DEBBUG}\n\n{$OPTIMIZATION OFF}\n{$RANGECHECKING ON}\n// etc\n\n{$ELSE}\n\n{$OPTIMIZATION ON}\n{$RANGECHECKING OFF}\n\n{$ENDIF}\n"
},
{
"answer_id": 176200,
"author": "Giacomo Degli Esposti",
"author_id": 20796,
"author_profile": "https://Stackoverflow.com/users/20796",
"pm_score": 1,
"selected": false,
"text": "rem release.bat\ncopy release.cfg myprog.cfg\ndcc32 -B myprog.dpr\n\nrem debug.bat\ncopy debug.cfg myprog.cfg\ndcc32 -B myprog.dpr\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/369/"
] |
176,171
|
<p>I have run in to a bit of a problem and I have done a bit of digging, but struggling to come up with a conclusive answer/fix.</p>
<p>Basically, I have some javascript (created by a 3rd party) that does some whizzbang stuff to page elements to make them look pretty. The code works great on single pages (i.e. no master), however, when I try and apply the effects to a content page within a master, it does not work.</p>
<p>In short I have a master page which contains the main script reference. All pages will use the script, but the parameters passed to it will differ for the content pages.</p>
<p><strong>Master Page Script Reference</strong></p>
<pre><code><script src="scripts.js" language="javascript" type="text/javascript" />
</code></pre>
<p><strong>Single Page</strong></p>
<pre><code><script>
MakePretty("elementID");
</script>
</code></pre>
<p>As you can see, I need the reference in each page (hence it being in the master) but the actual elements I want to "MakePretty" will change dependant on content.</p>
<p><strong>Content Pages</strong></p>
<p>Now, due to the content page not having a <code><head></code> element, I have been using the following code to add it to the master pages <code><head></code> element:</p>
<pre><code>HtmlGenericControl ctl = new HtmlGenericControl("script");
ctl.Attributes.Add("language", "javascript");
ctl.InnerHtml = @"MakePretty(""elementID"")";
Master.Page.Header.Controls.Add(ctl);
</code></pre>
<p>Now, this <strong>fails to work</strong>. However, if I replace with something simple like <code>alert("HI!")</code>, all works fine. So the code is being added OK, it just doesn't seem to always execute depending on what it is doing..</p>
<p>Now, having done some digging, I have learned that th content page's <code>Load</code> event is raised before the master pages, which may be having an effect, however, I thought the javascript on the page was all loaded/run at once?</p>
<p>Forgive me if this is a stupid question, but I am still relatively new to using javascript, especially in the master pages scenario.</p>
<p><strong>How can I get content pages to call javascript code which is referenced in the Master page?</strong></p>
<p>Thanks for any/all help on this guys, you will really be helping me out with this work problem.</p>
<h2>NOTES:</h2>
<ul>
<li><code>RegisterStartupScript</code> and the like does not seem to work at any level..</li>
<li>The control ID's are being set fine, even in the MasterPage environment and are rendering as expected.</li>
</ul>
<hr />
<p>Apologies if any of this is unclear, I am real tired so if need be please comment if a re-word/clarification is required.</p>
|
[
{
"answer_id": 176208,
"author": "roenving",
"author_id": 23142,
"author_profile": "https://Stackoverflow.com/users/23142",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/javascript\">\n window.onload = function(){\n MakePretty(\"elementID\");\n }\n</script>\n <script type=\"text/javascript\" src=\"myScript.js\"></script>\n"
},
{
"answer_id": 176389,
"author": "Aaron Powell",
"author_id": 11388,
"author_profile": "https://Stackoverflow.com/users/11388",
"pm_score": 1,
"selected": false,
"text": "$(document).ready(function(){\n $(\"input[type='text'], input[type='radio'], input[type='checkbox'], select, textarea\").each(function(){\n MakePretty(this);\n });\n});\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/832/"
] |
176,196
|
<p>Why is the following displayed different in Linux vs Windows?</p>
<pre><code>System.out.println(new String("¿".getBytes("UTF-8"), "UTF-8"));
</code></pre>
<p>in Windows:</p>
<p>¿</p>
<p>in Linux:</p>
<p>¿</p>
|
[
{
"answer_id": 176289,
"author": "McDowell",
"author_id": 304,
"author_profile": "https://Stackoverflow.com/users/304",
"pm_score": 2,
"selected": false,
"text": "public static void main(String[] args) throws Exception {\n String s = \"¿\";\n printHex(Charset.defaultCharset(), s);\n\n Charset utf8 = Charset.forName(\"UTF-8\");\n printHex(utf8, s);\n}\n\npublic static void printHex(Charset encoding, String s)\n throws UnsupportedEncodingException {\n System.out.print(encoding + \"\\t\" + s + \"\\t\");\n\n byte[] barr = s.getBytes(encoding);\n for (int i = 0; i < barr.length; i++) {\n int n = barr[i] & 0xFF;\n String hex = Integer.toHexString(n);\n if (hex.length() == 1) {\n System.out.print('0');\n }\n System.out.print(hex);\n }\n System.out.println();\n}\n"
},
{
"answer_id": 176724,
"author": "Alan Moore",
"author_id": 20938,
"author_profile": "https://Stackoverflow.com/users/20938",
"pm_score": 5,
"selected": true,
"text": "javac new String(\"¿\".getBytes(\"UTF-8\"), \"UTF-8\")\n FileOutputStream fos = new FileOutputStream(\"out.txt\");\nOutputStreamWriter osw = new OutputStreamWriter(fos, \"UTF-8\");\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9518/"
] |
176,213
|
<p>I want to write a web application using <a href="http://code.google.com/appengine/" rel="noreferrer">Google App Engine</a> (so the reference language would be <strong>Python</strong>). My application needs a simple search engine, so the users would be able to find data specifying keywords.</p>
<p>For example, if I have one table with those rows:</p>
<blockquote>
<p>1 Office space<br> 2 2001: A space
odyssey<br> 3 Brazil</p>
</blockquote>
<p>and the user queries for "space", rows 1 and 2 would be returned. If the user queries for "office space", the result should be rows 1 and 2 too (row 1 first).</p>
<p>What are the technical guidelines/algorithms to do this in a simple way?<br>
Can you give me good pointers to the theory behind this?<br></p>
<p>Thanks.</p>
<p><em>Edit</em>: I'm not looking for anything complex here (say, indexing tons of data).</p>
|
[
{
"answer_id": 41473754,
"author": "PythonMaster",
"author_id": 7376398,
"author_profile": "https://Stackoverflow.com/users/7376398",
"pm_score": -1,
"selected": false,
"text": "query = input(\"Query: \").strip().lower()#Or raw_input, for python 2\nend = []\nfor item in table:\n if query in item.strip().lower():\n end.append(item)\n\nprint end #Narrowed results\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23034/"
] |
176,255
|
<p>What is everyone's favorite way to sanitize user data?</p>
<p>I've been using Javascript, but have recently required something more secure (people can turn it off, after all), so I was looking at Flex, but thought I'd ask the community what they thought.</p>
|
[
{
"answer_id": 176337,
"author": "Bill",
"author_id": 24190,
"author_profile": "https://Stackoverflow.com/users/24190",
"pm_score": 1,
"selected": false,
"text": "preg_match('/^[\\w][\\w\\,\\-\\.]*\\@[\\w]+[\\w\\-\\.]*$/', $_GET['email'], $matches);\nif (count($matches) > 0) {\n $_GET['email'] = $matches[0];\n} else {\n die('invalid email address');\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14877/"
] |
176,264
|
<p>What is the difference between a <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator" rel="noreferrer"><strong>URL</strong></a>, a <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier" rel="noreferrer"><strong>URI</strong></a>, and a <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Name" rel="noreferrer"><strong>URN</strong></a>?</p>
|
[
{
"answer_id": 1984274,
"author": "Greg",
"author_id": 12971,
"author_profile": "https://Stackoverflow.com/users/12971",
"pm_score": 8,
"selected": false,
"text": "urn:isbn:0-486-27557-4 file://hostname/sharename/RomeoAndJuliet.pdf"
},
{
"answer_id": 1984412,
"author": "D.C.",
"author_id": 202431,
"author_profile": "https://Stackoverflow.com/users/202431",
"pm_score": 5,
"selected": false,
"text": "<rootElement xmlns:myPrefix=\"com.mycompany.mynode\">\n <myPrefix:aNode>some text</myPrefix:aNode>\n</rootElement>\n"
},
{
"answer_id": 1984443,
"author": "Swapnil",
"author_id": 241333,
"author_profile": "https://Stackoverflow.com/users/241333",
"pm_score": 4,
"selected": false,
"text": "ftp://example.com"
},
{
"answer_id": 1984749,
"author": "Gumbo",
"author_id": 53114,
"author_profile": "https://Stackoverflow.com/users/53114",
"pm_score": 4,
"selected": false,
"text": "REDIRECT_URL /foo REQUEST_URI /foo REDIRECT_SCRIPT_URL /foo REDIRECT_SCRIPT_URI http://example.com/foo SCRIPT_URL /foo SCRIPT_URI http://example.com/foo"
},
{
"answer_id": 2840452,
"author": "dierre",
"author_id": 259562,
"author_profile": "https://Stackoverflow.com/users/259562",
"pm_score": 3,
"selected": false,
"text": "url::current() http://example.com/kohana/index.php/welcome/home.html?query=string url:current()"
},
{
"answer_id": 12329174,
"author": "Sujit",
"author_id": 792713,
"author_profile": "https://Stackoverflow.com/users/792713",
"pm_score": 4,
"selected": false,
"text": "http://example.com ftp://example.com"
},
{
"answer_id": 25545360,
"author": "Prashanth Sams",
"author_id": 1482709,
"author_profile": "https://Stackoverflow.com/users/1482709",
"pm_score": 4,
"selected": false,
"text": "scheme://authority/path?query\n"
},
{
"answer_id": 28865728,
"author": "Stephen Ostermiller",
"author_id": 1145388,
"author_profile": "https://Stackoverflow.com/users/1145388",
"pm_score": 10,
"selected": false,
"text": "http://example.com/mypage.html ftp://example.com/download.zip mailto:user@example.com file:///home/user/file.txt tel:1-888-555-5555 http://example.com/resource?foo=bar#fragment /other/link.html http example.com /foo/mypage.html urn: urn:isbn:0451450523 urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66 urn:publishing:book view-source:http://example.com/ data:,Hello%20World href <a href=\"urn:isbn:0451450523\"> urn: http://www.w3.org/TR/html4/strict.dtd"
},
{
"answer_id": 28971343,
"author": "Bruno Bronosky",
"author_id": 117471,
"author_profile": "https://Stackoverflow.com/users/117471",
"pm_score": 3,
"selected": false,
"text": "s3://www-example-com/index.html http://www.example.com/index.html s3:// authority scheme://authority/path?query#fragment"
},
{
"answer_id": 34435000,
"author": "Premraj",
"author_id": 1697099,
"author_profile": "https://Stackoverflow.com/users/1697099",
"pm_score": 6,
"selected": false,
"text": "urn:[namespace identifier]:[namespace specific string] arn:partition:service:region:account-id:resource [scheme]://[Domain][Port]/[path]?[queryString]#[fragmentId]"
},
{
"answer_id": 35851710,
"author": "Rick O'Shea",
"author_id": 303623,
"author_profile": "https://Stackoverflow.com/users/303623",
"pm_score": -1,
"selected": false,
"text": "URI: foo\nURL: http://some.domain.com/foo\nURL: http://some.domain.com:8080/foo\nURL: ftp://some.domain.com/foo\n"
},
{
"answer_id": 61041945,
"author": "Mischa",
"author_id": 3900251,
"author_profile": "https://Stackoverflow.com/users/3900251",
"pm_score": 3,
"selected": false,
"text": "IRI is a superset of URI (IRI ⊃ URI)\nURI is a superset of URL (URI ⊃ URL)\nURI is a superset of URN (URI ⊃ URN)\nURL and URN are disjoint (URL ∩ URN = ∅)\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2041950/"
] |
176,273
|
<p>I'm currently working on a server-side product which is a bit complex to deploy on a new server, which makes it an ideal candidate for testing out in a VM. We are already using Hudson as our CI system, and I would really like to be able to deploy a virtual machine image with the latest and greatest software as a build artifact.</p>
<p>So, how does one go about doing this exactly? What VM software is recommended for this purpose? How much scripting needs to be done to accomplish this? Are there any issues in particular when using Windows 2003 Server as the OS here?</p>
|
[
{
"answer_id": 180522,
"author": "seisyll",
"author_id": 21815,
"author_profile": "https://Stackoverflow.com/users/21815",
"pm_score": 1,
"selected": false,
"text": "VBoxManage startvm \"Windows 2003 Server\" -type vrdp\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14302/"
] |
176,284
|
<p>Im looking for a method (or function) to strip out the domain.ext part of any URL thats fed into the function. The domain extension can be anything (.com, .co.uk, .nl, .whatever), and the URL thats fed into it can be anything from <a href="http://www.domain.com" rel="noreferrer">http://www.domain.com</a> to www.domain.com/path/script.php?=whatever</p>
<p>Whats the best way to go about doing this?</p>
|
[
{
"answer_id": 176300,
"author": "davidmytton",
"author_id": 2183,
"author_profile": "https://Stackoverflow.com/users/2183",
"pm_score": 4,
"selected": false,
"text": "$url = 'http://www.example.com';\n$domain = parse_url($url, PHP_URL_HOST);\n$domain = str_replace('www.','',$domain);\n"
},
{
"answer_id": 176341,
"author": "Robert Elwell",
"author_id": 23102,
"author_profile": "https://Stackoverflow.com/users/23102",
"pm_score": 8,
"selected": true,
"text": "php > $foo = \"http://www.example.com/foo/bar?hat=bowler&accessory=cane\";\nphp > $blah = parse_url($foo);\nphp > print_r($blah);\nArray\n(\n [scheme] => http\n [host] => www.example.com\n [path] => /foo/bar\n [query] => hat=bowler&accessory=cane\n)\n"
},
{
"answer_id": 190721,
"author": "firstresponder",
"author_id": 26088,
"author_profile": "https://Stackoverflow.com/users/26088",
"pm_score": 4,
"selected": false,
"text": "$pattern = '/\\w+\\..{2,3}(?:\\..{2,3})?(?:$|(?=\\/))/i';\n$url = 'http://www.example.com/foo/bar?hat=bowler&accessory=cane';\nif (preg_match($pattern, $url, $matches) === 1) {\n echo $matches[0];\n}\n example.com\n"
},
{
"answer_id": 3561064,
"author": "livingtech",
"author_id": 18961,
"author_profile": "https://Stackoverflow.com/users/18961",
"pm_score": 0,
"selected": false,
"text": "'/\\w+\\..{2,3}(?:\\..{2,3})?(?=[\\/\\W])/i' parse_url() split()"
},
{
"answer_id": 4354145,
"author": "z3ro",
"author_id": 530504,
"author_profile": "https://Stackoverflow.com/users/530504",
"pm_score": 1,
"selected": false,
"text": "$requestedServerName = $_SERVER['SERVER_NAME']; // = dev.mysite.com\n\n$thisSite = explode('.', $requestedServerName); // site name now an array\n\narray_shift($thisSite); //chop off the first array entry eg 'dev'\n\n$thisSite = join('.', $thisSite); //join it back together with dots ;)\n\necho $thisSite; //outputs 'mysite.com'\n"
},
{
"answer_id": 8388380,
"author": "Mark Shust at M.academy",
"author_id": 832719,
"author_profile": "https://Stackoverflow.com/users/832719",
"pm_score": 2,
"selected": false,
"text": "/**\n * Get root domain from full domain\n * @param string $domain\n */\npublic function getRootDomain($domain)\n{\n $domain = explode('.', $domain);\n\n $tld = array_pop($domain);\n $name = array_pop($domain);\n\n $domain = \"$name.$tld\";\n\n return $domain;\n}\n\n/**\n * Get domain name from url\n * @param string $url\n */\npublic function getDomainFromUrl($url)\n{\n $domain = parse_url($url, PHP_URL_HOST);\n $domain = $this->getRootDomain($domain);\n\n return $domain;\n}\n"
},
{
"answer_id": 38047898,
"author": "Oleksandr Fediashov",
"author_id": 6488546,
"author_profile": "https://Stackoverflow.com/users/6488546",
"pm_score": 0,
"selected": false,
"text": "$extract = new LayerShifter\\TLDExtract\\Extract();\n\n$result = $extract->parse('www.domain.com/path/script.php?=whatever');\n$result->getSubdomain(); // will return (string) 'www'\n$result->getHostname(); // will return (string) 'domain'\n$result->getSuffix(); // will return (string) 'com'\n"
},
{
"answer_id": 60327194,
"author": "Mohamad Hamouday",
"author_id": 4110122,
"author_profile": "https://Stackoverflow.com/users/4110122",
"pm_score": 0,
"selected": false,
"text": "function Delete_Domain_From_Url($Url = false)\n{\n if($Url)\n {\n $Url_Parts = parse_url($Url);\n $Url = isset($Url_Parts['path']) ? $Url_Parts['path'] : '';\n $Url .= isset($Url_Parts['query']) ? \"?\".$Url_Parts['query'] : '';\n }\n\n return $Url;\n}\n $Url = \"https://stackoverflow.com/questions/176284/how-do-you-strip-out-the-domain-name-from-a-url-in-php\";\necho Delete_Domain_From_Url($Url);\n\n# Output: \n#/questions/176284/how-do-you-strip-out-the-domain-name-from-a-url-in-php\n"
},
{
"answer_id": 63489368,
"author": "AndreyP",
"author_id": 1414555,
"author_profile": "https://Stackoverflow.com/users/1414555",
"pm_score": 3,
"selected": false,
"text": "$urlWithoutDomain = preg_replace('#^.+://[^/]+#', '', $url);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
176,295
|
<p>I've tried these, and they did not work (Access opens, but it does not wait:</p>
<pre><code>start "C:\program files\Microsoft Office\Office\MSACCESS.EXE" filename.mdb
start /WAIT "C:\program files\Microsoft Office\Office\MSACCESS.EXE" filename.mdb
start /W "C:\program files\Microsoft Office\Office\MSACCESS.EXE" filename.mdb
start filename.mdb
start msaccess.exe filename.mdb
</code></pre>
|
[
{
"answer_id": 176297,
"author": "pc1oad1etter",
"author_id": 525,
"author_profile": "https://Stackoverflow.com/users/525",
"pm_score": 3,
"selected": true,
"text": "start /WAIT msaccess.exe filename.mdb\n"
},
{
"answer_id": 6817094,
"author": "James whatley",
"author_id": 861678,
"author_profile": "https://Stackoverflow.com/users/861678",
"pm_score": 1,
"selected": false,
"text": "PATH=\"C:\\Program Files\\Microsoft Office\\OFFICE11\\; C:\\Windows\\Command\"\nSTART /WAIT MSACCESS.exe \"path to mdb file\" /X \"name of macro\"\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/525/"
] |
176,318
|
<p>Is there a way to get the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365527%28v=vs.85%29.aspx" rel="nofollow noreferrer">SearchPath</a> API to not search in c:\windows when using the default search path (passing NULL as the first param)? I can't modify the caller to send in a specific path.</p>
<p>I have a system with an application ini file in c:\windows (which I don't want it to use, but for legacy reasons has to remain there). I put my copy of the same ini file in c:\users\public, and put c:\users\public at the front of my system path environment variable, but a call to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365527%28v=vs.85%29.aspx" rel="nofollow noreferrer">SearchPath</a> still finds the c:\windows version. If I delete that version, it then finds the c:\users\public version, so I know the path was set correctly.</p>
|
[
{
"answer_id": 178685,
"author": "akalenuk",
"author_id": 25459,
"author_profile": "https://Stackoverflow.com/users/25459",
"pm_score": 1,
"selected": false,
"text": "SetCurrentDirectory(\"c:\\users\\public\") SearchPath(...)"
},
{
"answer_id": 995174,
"author": "Jason Owen",
"author_id": 25637,
"author_profile": "https://Stackoverflow.com/users/25637",
"pm_score": 2,
"selected": false,
"text": "DWORD err = GetEnvironmentVariable(\"PATH\", NULL, 0);\nchar* path = new char[err+1]; path[err] = 0;\nGetEnvironmentVariable(\"PATH\", path, err);\n\nerr = SearchPath(path, \"application\", \".ini\", 0, NULL, NULL);\nchar* searchResult = new char[err+1]; searchResult[err] = 0;\nerr = SearchPath(path, \"application\", \".ini\", err, searchResult, NULL);\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176318",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7893/"
] |
176,331
|
<p>I've developed a windows application that uses shared memory---that is---memory mapped files for interprocess communication. I have a windows service that does some processing and periodically writes data to the memory mapped file. I have a separate windows application that reads from the memory mapped file and displays the information. The application works as expected on Windows XP, XP Pro and Server 2003, but NOT on Vista.</p>
<p>I can see that the data being written to the memory mapped file is happening correctly by the windows service because I can open the file with a text editor and see the stored messages, but the "consumer" application can't read from the file. One interesting thing to note here, is that if I close the consumer application and restart it, it consumes the messages that were previously written to the memory mapped file. </p>
<p>Also, another strange thing is that I get the same behavior when I connect to the windows host using Remote Desktop and invoke/use the consumer application through remote desktop. However, if I invoke the Remote Desktop and connect to the target host's console session with the following command: <code>mstsc -v:servername /F -console</code>, everything works perfectly. </p>
<p>So that's why I think the problem is related to permissions. Can anyone comment on this?</p>
<p>EDIT:</p>
<p>The ACL that I'm using to create the memory mapped file and the Mutex objects that sychronize access is as follows:</p>
<pre class="lang-cpp prettyprint-override"><code>TCHAR * szSD = TEXT("D:")
TEXT("(A;;RPWPCCDCLCSWRCWDWOGAFA;;;S-1-1-0)")
TEXT("(A;;GA;;;BG)")
TEXT("(A;;GA;;;AN)")
TEXT("(A;;GA;;;AU)")
TEXT("(A;;GA;;;LS)")
TEXT("(A;;GA;;;RD)")
TEXT("(A;;GA;;;WD)")
TEXT("(A;;GA;;;BA)");
</code></pre>
<p>I think this may be part of the issue.</p>
|
[
{
"answer_id": 176426,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 1,
"selected": false,
"text": "FILE_MAP_ALL_ACCESS"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25636/"
] |
176,338
|
<p>I have an ASP.NET 2.0 [no ajax...yet] web site that will be deployed in compiled form on multiple customer sites. Typically the site will be intranet only. Some customers trust all of their people and don't care about limiting access to the site and/or page functions, others trust no one and want only certain people and/or groups to be able to view certain pages, click certain buttons, et al.</p>
<p>i could do some home-grown solution, possibly drive the access permissions from a database table, but before i go down that road i thought i'd ask in SO: what is a good solution for this situation? preferably one that can be controlled completedly in the web.config file and/or database, since rebuilding the web site is not possible (for the client, and i don't want to have to do it for them over and over). Active Directory integration would be a bonus, but not a requirement (unless that's just easier).</p>
<p>as a starting point, i'm thinking that each page/function point in the site be given an identity and associated with a permission group...</p>
<p>EDIT: web.config authorization section to allow/deny access by role and user is good, but that is only half of the problem - the other half is controlling access to the individual methods (buttons, whatever) on each page. For example, some users can view whatchamacallits while others are allowed to edit, create, delete, or disable/enable them. All of these buttons/links/actions are on the view page...</p>
<p>[ideally i would make the disabled buttons invisible, but that is not important here]</p>
<p>EDIT: some good suggestions so far, but no complete solution yet - still leaning towards a database-driven solution...</p>
<ul>
<li>security permission demand attributes will throw exceptions when buttons are clicked, which is not a friendly thing to do; i'd much rather hide buttons that the user is not allowed to use</li>
<li>the LoginView control is also interesting, but would require replicating most of the page content several times (once for each role) and may not handle the case where a user is in more than one role - i cannot assume that the roles are hierarchical since they will be defined by the customer</li>
</ul>
<p>EDIT: platform is Win2K/XP, Sql Server 2005, ASP.NET 2.0, not using AJAX</p>
|
[
{
"answer_id": 176384,
"author": "Jeremy",
"author_id": 9266,
"author_profile": "https://Stackoverflow.com/users/9266",
"pm_score": 2,
"selected": true,
"text": "<authorization>\n <!-- \n <deny users=\"?\" />\n <allow users=\"[comma separated list of users]\"\n roles=\"[comma separated list of roles]\"/>\n <deny users=\"[comma separated list of users]\"\n roles=\"[comma separated list of roles]\"/>\n -->\n</authorization>\n"
},
{
"answer_id": 177346,
"author": "ddc0660",
"author_id": 16027,
"author_profile": "https://Stackoverflow.com/users/16027",
"pm_score": 1,
"selected": false,
"text": "[PrincipalPermissionAttribute(SecurityAction.Demand, Name = \"MyUser\", Role = \"User\")]\npublic static void PrivateInfo()\n{ \n //Print secret data.\n Console.WriteLine(\"\\n\\nYou have access to the private data!\");\n}\n"
},
{
"answer_id": 177358,
"author": "martin",
"author_id": 8421,
"author_profile": "https://Stackoverflow.com/users/8421",
"pm_score": 1,
"selected": false,
"text": "<asp:LoginView id=\"LoginView1\" runat=\"server\">\n <RoleGroups>\n <asp:RoleGroup Roles=\"Admin\">\n <ContentTemplate>\n <asp:LoginName id=\"LoginName2\" runat=\"Server\"></asp:LoginName>, you\n are logged in as an administrator.\n </ContentTemplate>\n </asp:RoleGroup>\n <asp:RoleGroup Roles=\"User\">\n <ContentTemplate>\n <asp:Button id=\"Button1\" runat=\"Server\" OnClick=\"AllUserClick\">\n </ContentTemplate>\n </asp:RoleGroup>\n </RoleGroups>\n </asp:LoginView>\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176338",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9345/"
] |
176,343
|
<p>Perl 6 seems to have an explosion of equality operators. What is <code>=:=</code>? What's the difference between <code>leg</code> and <code>cmp</code>? Or <code>eqv</code> and <code>===</code>?</p>
<p>Does anyone have a good summary?</p>
|
[
{
"answer_id": 176381,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 7,
"selected": true,
"text": "my $x;\nmy @a = 1, 2, 3;\n# $x =:= @a[0] is false\n$x := @a[0];\n# now $x == 1, and $x =:= @a[0] is true\n$x = 4;\n# now @a is 4, 2, 3 \n [1, 2, 3] === [1, 2, 3] [1, 2, 3] eqv [1, 2, 3] leg cmp cmp <=> leg 13 leg 4 # -1, because 1 is smaller than 4, and leg converts to string\n13 cmp 4 # +1, because both are numbers, so use numeric comparison.\n ~~ $x $y $y $y"
},
{
"answer_id": 177306,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 4,
"selected": false,
"text": "eqv cmp cmp cmp Order cmp leg cmp ~$a cmp ~$b ~ leg cmp"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7598/"
] |
176,347
|
<p>I read some of the answers on here re: testing views and controllers, and mocking, but I still can't figure out how to test an ASP.NET MVC controller that reads and sets Session values (or any other context based variables.)
How do I provide a (Session) context for my test methods? Is mocking the answer? Anybody have examples?
Basically, I'd like to fake a session before I call the controller method and have the controller use that session. Any ideas?</p>
|
[
{
"answer_id": 176390,
"author": "chadmyers",
"author_id": 10862,
"author_profile": "https://Stackoverflow.com/users/10862",
"pm_score": 4,
"selected": false,
"text": "public interface ISecurityContext\n{\n bool IsAuthenticated { get; }\n IIdentity CurrentIdentity { get; }\n IPrincipal CurrentUser { get; set; }\n}\n public class SecurityContext : ISecurityContext\n{\n private readonly HttpContext _context;\n\n public SecurityContext()\n {\n _context = HttpContext.Current;\n }\n\n public bool IsAuthenticated\n {\n get { return _context.Request.IsAuthenticated; }\n }\n\n public IIdentity CurrentIdentity\n {\n get { return _context.User.Identity; }\n }\n\n public IPrincipal CurrentUser\n {\n get { return _context.User; }\n set { _context.User = value; }\n }\n}\n"
},
{
"answer_id": 176554,
"author": "Korbin",
"author_id": 17902,
"author_profile": "https://Stackoverflow.com/users/17902",
"pm_score": 3,
"selected": false,
"text": "[TestMethod]\n public void HowTo_CheckSession_With_TennisApp() {\n var request = new Mock<HttpRequestBase>();\n request.Expect(r => r.HttpMethod).Returns(\"GET\"); \n\n var httpContext = new Mock<HttpContextBase>();\n var session = new Mock<HttpSessionStateBase>();\n\n httpContext.Expect(c => c.Request).Returns(request.Object);\n httpContext.Expect(c => c.Session).Returns(session.Object);\n\n session.Expect(c => c.Add(\"test\", \"something here\")); \n\n var playerController = new NewPlayerSignupController();\n memberController.ControllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), playerController); \n\n session.VerifyAll(); // function is trying to add the desired item to the session in the constructor\n //TODO: Add Assertions \n }\n"
},
{
"answer_id": 238370,
"author": "David P",
"author_id": 13145,
"author_profile": "https://Stackoverflow.com/users/13145",
"pm_score": 6,
"selected": true,
"text": "[TestMethod]\npublic void TestSessionState()\n{\n // Create controller\n var controller = new HomeController();\n\n\n // Create fake Controller Context\n var sessionItems = new SessionStateItemCollection();\n sessionItems[\"item1\"] = \"wow!\";\n controller.ControllerContext = new FakeControllerContext(controller, sessionItems);\n var result = controller.TestSession() as ViewResult;\n\n\n // Assert\n Assert.AreEqual(\"wow!\", result.ViewData[\"item1\"]);\n\n // Assert\n Assert.AreEqual(\"cool!\", controller.HttpContext.Session[\"item2\"]);\n}\n"
},
{
"answer_id": 558006,
"author": "Dane O'Connor",
"author_id": 1946,
"author_profile": "https://Stackoverflow.com/users/1946",
"pm_score": 3,
"selected": false,
"text": "var controller = new HomeController();\nvar context = MockRepository.GenerateStub<ControllerContext>();\ncontext.Expect(x => x.HttpContext.Session[\"MyKey\"]).Return(\"MyValue\");\ncontroller.ControllerContext = context;\n"
},
{
"answer_id": 9860514,
"author": "Mathias Lykkegaard Lorenzen",
"author_id": 553609,
"author_profile": "https://Stackoverflow.com/users/553609",
"pm_score": 2,
"selected": false,
"text": "public class TestableController : Controller\n{\n\n public new HttpSessionStateBase Session\n {\n get\n {\n if (session == null)\n {\n session = base.Session ?? new CustomSession();\n }\n return session;\n }\n }\n private HttpSessionStateBase session;\n\n public class CustomSession : HttpSessionStateBase\n {\n\n private readonly Dictionary<string, object> dictionary; \n\n public CustomSession()\n {\n dictionary = new Dictionary<string, object>();\n }\n\n public override object this[string name]\n {\n get\n {\n if (dictionary.ContainsKey(name))\n {\n return dictionary[name];\n } else\n {\n return null;\n }\n }\n set\n {\n if (!dictionary.ContainsKey(name))\n {\n dictionary.Add(name, value);\n }\n else\n {\n dictionary[name] = value;\n }\n }\n }\n\n //TODO: implement other methods here as needed to forefil the needs of the Session object. the above implementation was fine for my needs.\n\n }\n\n}\n public class MyController : TestableController { }\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17729/"
] |
176,373
|
<p>We are trying to make a project template, but the documentation on this is spotty or non-existent.</p>
<p>Doing some reverse-engineering on some template files, we have come up with the following. However, it doen't actually work!</p>
<p>First of all, we have figured out that project templates should be installed inside:</p>
<p>~/Library/Application Support/Developer/Shared/Xcode/Project Templates</p>
<p>We have made project and installed it here, and this part works - we see this show up in the "User Templates" section of the Xcode "New Project" chooser.</p>
<p>The project folder contains the following files. As you can see, I want the file names to be subsituted (that part works) but as you will see, I also want the contents of the files to be substituted; this doesn't happen.</p>
<ul>
<li>___PROJECTNAME___.xcodeproj </li>
<li>___PROJECTNAMEASIDENTIFIER____Prefix.pch </li>
<li>___PROJECTNAMEASIDENTIFIER___.icns </li>
<li>___PROJECTNAMEASIDENTIFIER___Delegate.h </li>
<li>___PROJECTNAMEASIDENTIFIER___Delegate.m </li>
<li>___PROJECTNAMEASIDENTIFIER___Template.html </li>
<li>Debug.xcconfig </li>
<li>en.lproj </li>
<li>Info.plist </li>
<li>Release.xcconfig </li>
</ul>
<p>I have put in two special files into the ___PROJECTNAME___.xcodeproj package:</p>
<ul>
<li>TemplateInfo.plist </li>
<li>TemplateIcon.icns - the icon to show up in the New Project window</li>
</ul>
<p>If I create a new project (called "Foo & Bar" as a stress test) using this template, these are the files it creates:</p>
<ul>
<li>Debug.xcconfig</li>
<li>en.lproj</li>
<li>Foo & Bar.xcodeproj</li>
<li>Foo___Bar_Prefix.pch</li>
<li>Foo___Bar.icns</li>
<li>Foo___BarDelegate.h</li>
<li>Foo___BarDelegate.m</li>
<li>Foo___BarTemplate.html</li>
<li>Info.plist</li>
<li>Release.xcconfig</li>
</ul>
<p>So far so good! </p>
<p>But looking in the file contents, I get things like this. Here is the contents of Foo___BarDelegate.m:</p>
<pre><code>//
// «PROJECTNAMEASIDENTIFIER»Delegate.m
// «PROJECTNAME»
//
// Created by «FULLUSERNAME» on «DATE».
// Copyright «ORGANIZATIONNAME» «YEAR» . All rights reserved.
//
#import "«PROJECTNAMEASIDENTIFIER»Delegate.h"
@implementation «PROJECTNAMEASIDENTIFIER»Delegate
@end
</code></pre>
<p>The apparent issue is that somehow I'm doing the TemplateInfo.plist wrong. But then again, notice how not only are my special items not being substitued, but the standard items don't even get replaced! So maybe it's a deeper issue.</p>
<p>But with a problematic TemplateInfo.plist being my best hypothesis, I present a couple of variations I have tried. Neither work.</p>
<p>Either:</p>
<pre><code>{
FilesToMacroExpand = (
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch",
"en.lproj/InfoPlist.strings",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_\_Prefix.pch",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_.icns",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.h",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Delegate.m",
"\_\_\_PROJECTNAMEASIDENTIFIER\_\_\_Template.html",
"Info.plist"
);
Description = "This project builds a cocoa-based \"element\" plugin for Sandvox.";
}
</code></pre>
<p>or:</p>
<pre><code>{
FilesToMacroExpand = (
"«PROJECTNAMEASIDENTIFIER»\_Prefix.pch",
"en.lproj/InfoPlist.strings",
"«PROJECTNAMEASIDENTIFIER»\_Prefix.pch",
"«PROJECTNAMEASIDENTIFIER».icns",
"«PROJECTNAMEASIDENTIFIER»Delegate.h",
"«PROJECTNAMEASIDENTIFIER»Delegate.m",
"«PROJECTNAMEASIDENTIFIER»Template.html",
"Info.plist"
);
Description = "This project builds a cocoa-based \"element\" plugin for Sandvox.";
}
</code></pre>
<p><strong>Update</strong>: I've also tried adding the "FilesToRename" key, even though the ___ seems to be automatically causing renaming to happen. This is the plist contents with that in, in XML format (since some people were worried about that UTF-8 nature of things -- yes, it's a valid plist):</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>This project builds a cocoa-based "element" plugin for Sandvox.</string>
<key>FilesToMacroExpand</key>
<array>
<string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string>
<string>en.lproj/InfoPlist.strings</string>
<string>«PROJECTNAMEASIDENTIFIER».icns</string>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string>
<string>«PROJECTNAMEASIDENTIFIER»Template.html</string>
<string>Info.plist</string>
</array>
<key>FilesToRename</key>
<dict>
<key>___PROJECTNAMEASIDENTIFIER___.icns</key>
<string>«PROJECTNAMEASIDENTIFIER».icns</string>
<key>___PROJECTNAMEASIDENTIFIER___Delegate.h</key>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.h</string>
<key>___PROJECTNAMEASIDENTIFIER___Delegate.m</key>
<string>«PROJECTNAMEASIDENTIFIER»Delegate.m</string>
<key>___PROJECTNAMEASIDENTIFIER___Template.html</key>
<string>«PROJECTNAMEASIDENTIFIER»Template.html</string>
<key>___PROJECTNAMEASIDENTIFIER____Prefix.pch</key>
<string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string>
<key>___PROJECTNAME___.xcodeproj</key>
<string>«PROJECTNAME».xcodeproj</string>
</dict>
</dict>
</plist>
</code></pre>
|
[
{
"answer_id": 176420,
"author": "bbum",
"author_id": 25646,
"author_profile": "https://Stackoverflow.com/users/25646",
"pm_score": 2,
"selected": false,
"text": " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>Description</key>\n <string>This project builds a Cocoa-based application written in Python that uses the NSDocument architecture.</string>\n <key>FilesToMacroExpand</key>\n <array>\n <string>«PROJECTNAME»_Prefix.pch</string>\n <string>Info.plist</string>\n <string>English.lproj/InfoPlist.strings</string>\n <string>English.lproj/MainMenu.xib</string>\n <string>English.lproj/«PROJECTNAMEASIDENTIFIER»Document.xib</string>\n <string>main.py</string>\n <string>«PROJECTNAMEASIDENTIFIER»Document.py</string>\n <string>main.m</string>\n </array>\n <key>FilesToRename</key>\n <dict>\n <key>CocoaAppDocument.py</key>\n <string>«PROJECTNAMEASIDENTIFIER»Document.py</string>\n <key>CocoaDocApp_Prefix.pch</key>\n <string>«PROJECTNAMEASIDENTIFIER»_Prefix.pch</string>\n <key>English.lproj/CocoaAppDocument.xib</key>\n <string>English.lproj/«PROJECTNAMEASIDENTIFIER»Document.xib</string>\n </dict>\n</dict>\n</plist>\n"
},
{
"answer_id": 181758,
"author": "mmalc",
"author_id": 23233,
"author_profile": "https://Stackoverflow.com/users/23233",
"pm_score": 2,
"selected": false,
"text": "//\n// ___PROJECTNAMEASIDENTIFIER___AppDelegate.m\n// ___PROJECTNAME___\n//\n// Created by ___FULLUSERNAME___ on ___DATE___.\n// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.\n//\n\n#import \"___PROJECTNAMEASIDENTIFIER___AppDelegate.h\"\n\n@implementation ___PROJECTNAMEASIDENTIFIER___AppDelegate\n"
},
{
"answer_id": 1469219,
"author": "Puneet Madaan",
"author_id": 178168,
"author_profile": "https://Stackoverflow.com/users/178168",
"pm_score": 0,
"selected": false,
"text": "xcode"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25560/"
] |
176,376
|
<p>Suppose I have a set of values, stored in a std::set:</p>
<p>{1, 2, 6, 8}</p>
<p>and I have a search key, say, 3. I want to put 3 into a function and get the first value greater than or equal to 3, in this case I would want to get 6.</p>
<p>The find() function provided in map/set/multimap/and set will, of course, return the end iterator for this case. Is there a similar function to find that would return 6 in this case?</p>
|
[
{
"answer_id": 176393,
"author": "gbjbaanb",
"author_id": 13744,
"author_profile": "https://Stackoverflow.com/users/13744",
"pm_score": 2,
"selected": false,
"text": "map<int, int> mymap = { 1,2,6,8 };\nmap<int,int>::iterator i = mymap.upper_bound(3); // returns an iterator to the '6' element.\n"
},
{
"answer_id": 176395,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "upper_bound(X) X lower_bound(X) X [lower_bound(X), upper_bound(X))"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8123/"
] |
176,379
|
<p>SQL Server 2005/2008 Express edition has the limitation of 4 GB per database. As far as I known the database engine considers data only, thus excluding log files, unused space, and index size.</p>
<p>Getting the length of the MDF file should not give the correct database size in terms of SQL Server limitation. My question is how to get the database size?</p>
|
[
{
"answer_id": 176437,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 4,
"selected": false,
"text": "CREATE TABLE #t (name SYSNAME, rows CHAR(11), reserved VARCHAR(18), \ndata VARCHAR(18), index_size VARCHAR(18), unused VARCHAR(18))\n\nEXEC sp_msforeachtable 'INSERT INTO #t EXEC sp_spaceused ''?'''\n-- SELECT * FROM #t ORDER BY name\n-- SELECT name, CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3)) FROM #t ORDER BY name\nSELECT SUM(CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3))) FROM #t\nDROP TABLE #t\n"
},
{
"answer_id": 7579480,
"author": "MAXE",
"author_id": 833644,
"author_profile": "https://Stackoverflow.com/users/833644",
"pm_score": 3,
"selected": false,
"text": "USE [myDatabase]\nGO\n\nSELECT\n [size] * 8\n , [filename]\nFROM sysfiles\n"
},
{
"answer_id": 9885894,
"author": "Heinrich",
"author_id": 1294984,
"author_profile": "https://Stackoverflow.com/users/1294984",
"pm_score": 2,
"selected": false,
"text": "set ANSI_NULLS ON\nset QUOTED_IDENTIFIER ON\ngo\n\nDECLARE @iCount int, @iMax int, @DatabaseName varchar(200), @SQL varchar (8000)\n\nSelect NAME, DBID, crdate, filename, version \nINTO #TEMP\nfrom MAster..SYSDatabASES \n\nSELECT @iCount = Count(DBID) FROM #TEMP\n\nSelect @SQL='Create Table ##iFile1 ( DBName varchar( 200) NULL, Fileid INT, FileGroup int, TotalExtents INT , USedExtents INT , \nName varchar(100), vFile varchar (300), AllocatedSpace int NUll, UsedSpace int Null, PercentageFree int Null ) '+ char(10)\nexec (@SQL)\n\n\nCreate Table ##iTotals ( ServerName varchar(100), DBName varchar( 200) NULL, FileType varchar(10),Fileid INT, FileGroup int, TotalExtents INT , USedExtents INT , \nName varchar(100), vFile varchar (300), AllocatedSpace int NUll, UsedSpace int Null, PercentageFree int Null ) \n\n\nWHILE @iCount>0\nBEGIN \n SELECT @iMax =Max(dbid) FROM #TEMP\n Select @DatabaseName = Name FROM #TEMP where dbid =@iMax\n\n SELECT @SQL = 'INSERT INTO ##iFile1(Fileid , FileGroup , TotalExtents , USedExtents , Name , vFile)\n EXEC (''USE [' + @DatabaseName + '] DBCC showfilestats'') ' + char(10)\n\n Print (@SQL)\n EXEC (@SQL)\n\n\n SELECT @SQL = 'UPDATE ##iFile1 SET DBName ='''+ @DatabaseName +''' WHERE DBName IS NULL'\n EXEC (@SQL)\n\n\n DELETE FROM #TEMP WHERE dbid =@iMax\n Select @iCount =@iCount -1\nEND\nUPDATE ##iFile1\nSET AllocatedSpace = (TotalExtents * 64.0 / 1024.0 ), UsedSpace =(USedExtents * 64.0 / 1024.0 )\n\nUPDATE ##iFile1\nSET PercentageFree = 100-Convert(float,UsedSpace)/Convert(float,AllocatedSpace )* 100\nWHERE USEDSPACE>0\n\nCREATE TABLE #logspace (\n DBName varchar( 100),\n LogSize float,\n PrcntUsed float,\n status int\n )\nINSERT INTO #logspace\nEXEC ('DBCC sqlperf( logspace)')\n\n\n\nINSERT INTO ##iTotals(ServerName, DBName, FileType,Name, vFile,PercentageFree,AllocatedSpace)\nselect @@ServerName ,DBNAME, 'Data' as FileType,Name, vFile, PercentageFree , AllocatedSpace\nfrom ##iFile1\nUNION\nselect @@ServerName ,DBNAME, 'Log' as FileType ,DBName,'' as vFile ,PrcntUsed , LogSize\nfrom #logspace\n\nSelect * from ##iTotals\n\nselect ServerName ,DBNAME, FileType, Sum( AllocatedSpace) as AllocatedSpaceMB\nfrom ##iTotals\nGroup By ServerName ,DBNAME, FileType\nOrder By ServerName ,DBNAME, FileType\n\n\nselect ServerName ,DBNAME, Sum( AllocatedSpace) as AllocatedSpaceMB\nfrom ##iTotals\nGroup By ServerName ,DBNAME\nOrder By ServerName ,DBNAME\n\n\n\ndrop table ##iFile1\ndrop table #logspace\ndrop table #TEMP\ndrop table ##iTotals\n"
},
{
"answer_id": 18018978,
"author": "foxfire",
"author_id": 2166762,
"author_profile": "https://Stackoverflow.com/users/2166762",
"pm_score": 3,
"selected": false,
"text": "SELECT \n DB_NAME( dbid ) AS DatabaseName, \n CAST( ( SUM( size ) * 8 ) / ( 1024.0 * 1024.0 ) AS decimal( 10, 2 ) ) AS DbSizeGb \nFROM \n sys.sysaltfiles \nGROUP BY \n DB_NAME( dbid )\n"
},
{
"answer_id": 59800578,
"author": "Arulmouzhi",
"author_id": 7905444,
"author_profile": "https://Stackoverflow.com/users/7905444",
"pm_score": 0,
"selected": false,
"text": "SELECT\n DB_NAME() AS [database_name],\n CONCAT(CAST(SUM(\n CAST( (size * 8.0/1024) AS DECIMAL(15,2) )\n ) AS VARCHAR(20)),' MB') AS [database_size]\nFROM sys.database_files;\n EXEC sp_spaceused ;\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23372/"
] |
176,403
|
<p>In C++/CLI , you can use native types in a managed class by it is not allowed to hold a member of a native class in a managed class : you need to use pointers in that case.</p>
<p>Here is an example :</p>
<pre><code>class NativeClass
{
....
};
public ref class ManagedClass
{
private:
NativeClass mNativeClass; // Not allowed !
NativeClass * mNativeClass; // OK
auto_ptr<NativeClass> mNativeClass; //Not allowed !
boost::shared_ptr<NativeClass> mNativeClass; //Not allowed !
};
</code></pre>
<p>Does anyone know of an equivalent of shared_ptr in the C++/CLI world?</p>
<p>Edit:
Thanks for your suggestion, "1800-Information". Following your suggestion, I checked about STL.Net but it is only available with Visual Studio 2008, and it provides containers + algorithms, but no smart pointers.</p>
|
[
{
"answer_id": 12643978,
"author": "chillitom",
"author_id": 56679,
"author_profile": "https://Stackoverflow.com/users/56679",
"pm_score": 2,
"selected": false,
"text": "#pragma once\n\n#include <memory>\n\ntemplate <class T>\npublic ref class m_shared_ptr sealed\n{\n std::shared_ptr<T>* pPtr;\n\npublic:\n m_shared_ptr() \n : pPtr(nullptr) \n {}\n\n m_shared_ptr(T* t) {\n pPtr = new std::shared_ptr<T>(t);\n }\n\n m_shared_ptr(std::shared_ptr<T> t) {\n pPtr = new std::shared_ptr<T>(t);\n }\n\n m_shared_ptr(const m_shared_ptr<T>% t) {\n pPtr = new std::shared_ptr<T>(*t.pPtr);\n }\n\n !m_shared_ptr() {\n delete pPtr;\n }\n\n ~m_shared_ptr() {\n delete pPtr;\n }\n\n operator std::shared_ptr<T>() {\n return *pPtr;\n }\n\n m_shared_ptr<T>% operator=(T* ptr) {\n pPtr = new std::shared_ptr<T>(ptr);\n return *this;\n }\n\n T* operator->() {\n return (*pPtr).get();\n }\n};\n"
},
{
"answer_id": 71784151,
"author": "Lars",
"author_id": 42809,
"author_profile": "https://Stackoverflow.com/users/42809",
"pm_score": 0,
"selected": false,
"text": "auto_ptr #include <msclr/auto_gcroot.h>\n\n...\n{\n msclr::auto_gcroot<ManagedType^> item(gcnew ManagedType());\n ...\n}\n"
}
] |
2008/10/06
|
[
"https://Stackoverflow.com/questions/176403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19816/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.