qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
227,305
<p>I am building up a view with various text and image elements.</p> <p>I want to display some text in the view with a blurry copy of the text behind it, but not just a text shadow.</p> <p>How do I apply Gaussian blurred text onto a UIImage or layer?</p>
[ { "answer_id": 1256500, "author": "mahboudz", "author_id": 86020, "author_profile": "https://Stackoverflow.com/users/86020", "pm_score": 3, "selected": false, "text": "static void blur(V2fT2f *quad, float t) // t = 1\n{\n GLint tex;\n V2fT2f tmpquad[4];\n float offw = t / Input.wide;\n float offh = t / Input.high;\n int i;\n\n glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex);\n\n // Three pass small blur, using rotated pattern to sample 17 texels:\n //\n // .\\/.. \n // ./\\\\/ \n // \\/X/\\ rotated samples filter across texel corners\n // /\\\\/. \n // ../\\. \n\n // Pass one: center nearest sample\n glVertexPointer (2, GL_FLOAT, sizeof(V2fT2f), &quad[0].x);\n glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &quad[0].s);\n glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);\n glColor4f(1.0/5, 1.0/5, 1.0/5, 1.0);\n validateTexEnv();\n glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);\n\n // Pass two: accumulate two rotated linear samples\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\n glEnable(GL_BLEND);\n glBlendFunc(GL_SRC_ALPHA, GL_ONE);\n for (i = 0; i < 4; i++)\n {\n tmpquad[i].x = quad[i].s + 1.5 * offw;\n tmpquad[i].y = quad[i].t + 0.5 * offh;\n tmpquad[i].s = quad[i].s - 1.5 * offw;\n tmpquad[i].t = quad[i].t - 0.5 * offh;\n }\n glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &tmpquad[0].x);\n glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);\n glActiveTexture(GL_TEXTURE1);\n glEnable(GL_TEXTURE_2D);\n glClientActiveTexture(GL_TEXTURE1);\n glTexCoordPointer(2, GL_FLOAT, sizeof(V2fT2f), &tmpquad[0].s);\n glEnableClientState(GL_TEXTURE_COORD_ARRAY);\n glBindTexture(GL_TEXTURE_2D, tex);\n glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);\n glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);\n glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);\n glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);\n glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PRIMARY_COLOR);\n glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);\n glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);\n glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);\n\n glColor4f(0.5, 0.5, 0.5, 2.0/5);\n validateTexEnv();\n glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);\n\n // Pass three: accumulate two rotated linear samples\n for (i = 0; i < 4; i++)\n {\n tmpquad[i].x = quad[i].s - 0.5 * offw;\n tmpquad[i].y = quad[i].t + 1.5 * offh;\n tmpquad[i].s = quad[i].s + 0.5 * offw;\n tmpquad[i].t = quad[i].t - 1.5 * offh;\n }\n glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);\n\n // Restore state\n glDisableClientState(GL_TEXTURE_COORD_ARRAY);\n glClientActiveTexture(GL_TEXTURE0);\n glBindTexture(GL_TEXTURE_2D, Half.texID);\n glDisable(GL_TEXTURE_2D);\n glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);\n glActiveTexture(GL_TEXTURE0);\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\n glDisable(GL_BLEND);\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30342/" ]
227,312
<p>Currently we are using prototype and jQuery as our js frameworks. Right now, jQuery is set to $j() to prevent conflicts from prototype.</p> <p>In the past, we've used a lot of prototype's Element.down(), Element.next(), and Element.previous() to traverse the DOM. However, I need a simple way to retrieve the last child element. I know i can loop through an array by using Element.childElements() but I would like something inline that reads cleanly and can be pipelined.</p> <p>Just thought I would ask before I go reinventing the wheel. Here's a snippet of code that has lastChild in it that needs to be replaced:</p> <pre><code>_find : function(rows, address) { var obj = null; for (var i=0; i &lt; rows.length &amp;&amp; obj == null; i++) { if (rows[i].down().className == 'b') obj = this._find(rows[i].lastChild.down().down().childElements(), address); else if (rows[i].lastChild.getAttribute('tabAddress') == address) return rows[i].lastChild; } return obj; } </code></pre>
[ { "answer_id": 227323, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 1, "selected": false, "text": "var lastChild = $(\"#parent :last-child\");\n" }, { "answer_id": 227342, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 1, "selected": false, "text": "var lastChild = $$(\".b:last-child\")[0];\n" }, { "answer_id": 228558, "author": "Leo", "author_id": 20689, "author_profile": "https://Stackoverflow.com/users/20689", "pm_score": 5, "selected": true, "text": "//if you only have the id of the parent\nvar lastChild = $$(\"#parent :last-child\")[0]; \n//or\n//if you have the actual DOM element\nvar lastChild = $(element).select(\":last-child\")[0]; \n" }, { "answer_id": 15666324, "author": "Chris McFadyen", "author_id": 2216908, "author_profile": "https://Stackoverflow.com/users/2216908", "pm_score": 0, "selected": false, "text": "Element.childElements().last();\n" }, { "answer_id": 37665142, "author": "mwieczorek", "author_id": 280919, "author_profile": "https://Stackoverflow.com/users/280919", "pm_score": 0, "selected": false, "text": "Element.addMethods({ ... });" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5203/" ]
227,318
<p>I need to write a browser interface for an application running embedded on a single board computer (<a href="http://www.gumstix.com/store/catalog/product_info.php?products_id=178" rel="nofollow noreferrer">Gumstix Verdex</a> for anyone who's interested), so I won't be able to use any web frameworks due to space and processor constraints (and availability for the environment I'm running in). I'm limited to the core Python and cgi modules to create pages that will communicate with a C++ application.</p> <p>Can anyone recommend a good resource (web or book form, but books are preferred) for learning CGI programming in Python?</p> <p>What I need the application to do is fairly simple. I have a C++ program running on the same device and I need to create a browser based user interface so the configuration settings of that application can be changed. The UI needs to communicate with the C++ application, where the final data validation will be done. Preliminary validation can be done on the UI using Javascript, then again on the server using Python, but the final validation has to be done in the application itself, since it's getting its initial config from a file anyway. The configuration data takes all forms (booleans, ints, floats, and strings).</p>
[ { "answer_id": 227857, "author": "Florian Bösch", "author_id": 19435, "author_profile": "https://Stackoverflow.com/users/19435", "pm_score": 1, "selected": false, "text": "from wsgiref.simple_server import make_server\n\ndef application(environ, start_response):\n start_response('200 OK', [\n ('Content-Type', 'text/plain'),\n ])\n return ['Hello World!']\n\nhttpd = make_server('', 8000, application)\nhttpd.serve_forever()\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227318", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1288/" ]
227,340
<p>For our software we use hardware dongles to protect the software. No protection is perfect but this commercial solution is affordable and keeps honest people honest (as mentioned in another thread). The advantage is the 128 bit key that is stored 'unreadable' on the hardware dongle. </p> <p>We want to remove this hardware dongle and start using software protection. Basically we can use a commercial product, but on the other hand that won't be unbreakable either. I don't know much about encryption and that's why I am posting this. How do I store a key on a Windows computer that will not be possible to read by using Reflector or something else? However I should be able to access the key for testing the license code.</p> <p>I would just like a simple solution that can't be hacked by simply using Reflector.</p> <p>Or am I asking a very stupid question?</p> <hr> <p>Thank you all for your very fast and useful replies. I don't want to use licensing over the internet, since the application is running not always on computers that are connected. I will then get probably more problems then solving them. We will now most probably go for a commercial solution. It seems that protection is not that trivial. </p> <p>Thanks a lot!!</p>
[ { "answer_id": 227453, "author": "Hallgrim", "author_id": 15454, "author_profile": "https://Stackoverflow.com/users/15454", "pm_score": 0, "selected": false, "text": "bool CheckKey(string keyFromUser) \n return SHA1(key) == \"ABC2983CF293892CD298392FG\";\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30507/" ]
227,351
<p>I want to expose the functionality of an SAP program (transaction) as a BAPI. I need to call a report and supply range filters such that the GUI is bypassed.</p> <p>Does anyone have a working example of the SUBMIT ... WITH ... ABAP construct, or other suggestions on how to accomplish what I need to do?</p>
[ { "answer_id": 231587, "author": "Esti", "author_id": 25687, "author_profile": "https://Stackoverflow.com/users/25687", "pm_score": 2, "selected": false, "text": "SUBMIT SAPF140 \n TO SAP-SPOOL \"optional\"\n SPOOL PARAMETERS print_parameters \"optional\"\n WITHOUT SPOOL DYNPRO \"optional (hides the spool pop-up)\"\n VIA JOB jobname NUMBER l_number \"optional\"\n AND RETURN \"optional - returns to the calling prog\"\n WITH EVENT = REVENT\n WITH BUKRS IN RBUKRS\n WITH BELNR IN lRBELNR\n WITH GJAHR IN RGJAHR\n WITH USNAM = SY-UNAME\n WITH DATUM = SAVE_DATUM\n WITH UZEIT = SAVE_UZEIT\n WITH DELDAYS = RDELDAYS\n WITH KAUTO = 'X'\n WITH RPDEST = SAVE_PDEST\n WITH TITLE = TITLE.\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227351", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26652/" ]
227,357
<p>I have a master page, with a help link in the top menu. This link should contain the a dynamic bookmark from the current page, so that the user scrolls to the help for the page he is currently seeing.</p> <pre><code>&lt;a href="help.aspx#[NameOfCurentPage]"&gt;Help&lt;/a&gt; </code></pre> <p>How would you implement this?</p>
[ { "answer_id": 227387, "author": "JPrescottSanders", "author_id": 19444, "author_profile": "https://Stackoverflow.com/users/19444", "pm_score": 1, "selected": false, "text": "Path.GetFileName(Request.PhysicalPath).ToUpper()\n" }, { "answer_id": 227406, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 3, "selected": true, "text": "Public Sub SetNavigationPage(ByVal LinkName As String)\n DirectCast(Me.FindControl(MenuName), HyperLink).NavigateUrl = \"help.aspx#\" & LinkName\nEnd Sub\n" }, { "answer_id": 227567, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 1, "selected": false, "text": "<a href=\"help.aspx#<%= Path.GetFileName(this.Page.Request.FilePath) %>\">Help</a>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8547/" ]
227,376
<p>I need to round a value up to the nearest multiple of 2.5.</p> <p>For example:<br> 6 --> 7.5<br> 7.6 --> 10<br> etc. </p> <p>This seems like the best way to do this?</p> <pre><code> Function RoundToIncrement(ByVal originalNumber As Decimal, ByVal increment As Decimal) As Decimal Dim num = Math.Round(originalNumber / increment, MidpointRounding.AwayFromZero) * increment If originalNumber Mod increment &lt;&gt; 0 And num &lt; originalNumber Then num += increment End If Return num End Function </code></pre>
[ { "answer_id": 227384, "author": "harpo", "author_id": 4525, "author_profile": "https://Stackoverflow.com/users/4525", "pm_score": 6, "selected": true, "text": "Function RoundToIncrement(ByVal orignialNumber As Decimal, ByVal increment As Decimal) As Decimal\n Return Math.Ceiling( orignialNumber / increment ) * increment\nEnd Function\n" }, { "answer_id": 14125433, "author": "WAL", "author_id": 1943387, "author_profile": "https://Stackoverflow.com/users/1943387", "pm_score": 2, "selected": false, "text": " /*\n This will round up (Math.Ceiling) or down (Math.Floor) based on the midpoint of the increment. \n The other examples use Math.Ceiling and therefore always round up.\n Assume the increment is 2.5 in this example and the number is 6.13\n */\n var halfOfIncrement = Increment / 2; // 2.5 / 2 = 1.25\n var floorResult = Math.Floor(originalNumber / Increment); //Math.Floor(6.13 / 2.5) = Math.Floor(2.452) = 2\n var roundingThreshold = (floorResult * Increment) + halfOfIncrement; //(2 * 2.5) = 5 + 1.25 = 6.25\n\n if (originalNumber >= roundingThreshold) //6.13 >= 6.25 == false therefore take Math.Floor(6.13/2.5) = Math.Floor(2.452) = 2 * 2.5 = 5\n result = Math.Ceiling(originalNumber / Increment) * Increment;\n else\n result = Math.Floor(originalNumber / Increment) * Increment;\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34548/" ]
227,380
<p>Consider the following code:</p> <pre><code>abstract class SomeClassX&lt;T&gt; { // blah } class SomeClassY: SomeClassX&lt;int&gt; { // blah } class SomeClassZ: SomeClassX&lt;long&gt; { // blah } </code></pre> <p>I want a collection of SomeClassX&lt;T&gt;'s, however, this isn't possible since SomeClassX&lt;int&gt; != SomeClassX&lt;long&gt; and List&lt;SomeClassX&lt;&gt;&gt; isn't allowed.</p> <p>So my solution is to have SomeClassX&lt;T&gt; implement an interface and define my collection as, where ISomeClassX is the interface:</p> <pre><code>class CollectionOfSomeClassX: List&lt;ISomeClassX&gt; { // blah } </code></pre> <p>Is this the best way to do this, or is there better way?</p>
[ { "answer_id": 227384, "author": "harpo", "author_id": 4525, "author_profile": "https://Stackoverflow.com/users/4525", "pm_score": 6, "selected": true, "text": "Function RoundToIncrement(ByVal orignialNumber As Decimal, ByVal increment As Decimal) As Decimal\n Return Math.Ceiling( orignialNumber / increment ) * increment\nEnd Function\n" }, { "answer_id": 14125433, "author": "WAL", "author_id": 1943387, "author_profile": "https://Stackoverflow.com/users/1943387", "pm_score": 2, "selected": false, "text": " /*\n This will round up (Math.Ceiling) or down (Math.Floor) based on the midpoint of the increment. \n The other examples use Math.Ceiling and therefore always round up.\n Assume the increment is 2.5 in this example and the number is 6.13\n */\n var halfOfIncrement = Increment / 2; // 2.5 / 2 = 1.25\n var floorResult = Math.Floor(originalNumber / Increment); //Math.Floor(6.13 / 2.5) = Math.Floor(2.452) = 2\n var roundingThreshold = (floorResult * Increment) + halfOfIncrement; //(2 * 2.5) = 5 + 1.25 = 6.25\n\n if (originalNumber >= roundingThreshold) //6.13 >= 6.25 == false therefore take Math.Floor(6.13/2.5) = Math.Floor(2.452) = 2 * 2.5 = 5\n result = Math.Ceiling(originalNumber / Increment) * Increment;\n else\n result = Math.Floor(originalNumber / Increment) * Increment;\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30521/" ]
227,383
<p>How do I programmatically return the maximum of two integers without using any comparison operators and without using <code>if</code>, <code>else</code>, etc?</p>
[ { "answer_id": 227393, "author": "bobwienholt", "author_id": 24257, "author_profile": "https://Stackoverflow.com/users/24257", "pm_score": 2, "selected": false, "text": "int max(int a, int b)\n{\n int x = (a - b) >> 31;\n int y = ~x;\n return (y & a) | (x & b); \n}\n" }, { "answer_id": 227416, "author": "MSN", "author_id": 6210, "author_profile": "https://Stackoverflow.com/users/6210", "pm_score": 3, "selected": false, "text": "r = x - ((x - y) & -(x < y)); // max(x, y)\n" }, { "answer_id": 227418, "author": "plinth", "author_id": 20481, "author_profile": "https://Stackoverflow.com/users/20481", "pm_score": 6, "selected": true, "text": "a -= b;\na &= (~a) >> 31;\na += b;\n" }, { "answer_id": 227432, "author": "Blank", "author_id": 19521, "author_profile": "https://Stackoverflow.com/users/19521", "pm_score": 3, "selected": false, "text": "int data[2] = {a,b};\nint c = a - b;\nreturn data[(int)((c & 0x80000000) >> 31)];\n" }, { "answer_id": 227433, "author": "mspmsp", "author_id": 21724, "author_profile": "https://Stackoverflow.com/users/21724", "pm_score": 2, "selected": false, "text": "int getMax(int a, int b)\n{\n for(int i=0; (i<a) || (i<b); i++) { }\n return i;\n}\n" }, { "answer_id": 227435, "author": "ADEpt", "author_id": 10105, "author_profile": "https://Stackoverflow.com/users/10105", "pm_score": 2, "selected": false, "text": "let greater x y = signum (1+signum (x-y))\n\nlet max a b = (greater a b)*a + (greater b a)*b\n" }, { "answer_id": 227477, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 1, "selected": false, "text": "\n// GCC inline assembly\nint max(int a, int b)\n{\n __asm__(\"movl %0, %%eax\\n\\t\" // %eax = a\n \"cmpl %%eax, %1\\n\\t\" // compare a to b\n \"cmovg %1, %%eax\" // %eax = b if b>a\n :: \"r\"(a), \"r\"(b));\n}\n" }, { "answer_id": 867612, "author": "Dimitris", "author_id": 108668, "author_profile": "https://Stackoverflow.com/users/108668", "pm_score": 3, "selected": false, "text": "max(a+b) = ( (a+b) + |(a-b)| ) / 2\nmin(a-b) = ( (a+b) - |(a-b)| ) / 2\n" }, { "answer_id": 1693476, "author": "Bartosz Wójcik", "author_id": 205036, "author_profile": "https://Stackoverflow.com/users/205036", "pm_score": 2, "selected": false, "text": "#define H0(x) (((signed)(x)) >> (sizeof((signed)(x))*8-1))\n#define H1(a,b) H0((a)-(b))\n\n#define MIN1(a,b) ((a)+(H1(b,a) & ((b)-(a))))\n#define MIN2(a,b) ((a)-(H1(b,a) & ((a)-(b))))\n#define MIN3(a,b) ((b)-(H1(a,b) & ((b)-(a))))\n#define MIN4(a,b) ((b)+(H1(a,b) & ((a)-(b))))\n//#define MIN5(a,b) ((a)<(b)?(a):(b))\n//#define MIN6(a,b) ((a)>(b)?(b):(a))\n//#define MIN7(a,b) ((b)>(a)?(a):(b))\n//#define MIN8(a,b) ((b)<(a)?(b):(a))\n\n#define MAX1(a,b) ((a)+(H1(a,b) & ((b)-(a))))\n#define MAX2(a,b) ((a)-(H1(a,b) & ((a)-(b))))\n#define MAX3(a,b) ((b)-(H1(b,a) & ((b)-(a))))\n#define MAX4(a,b) ((b)+(H1(b,a) & ((a)-(b))))\n//#define MAX5(a,b) ((a)<(b)?(b):(a))\n//#define MAX6(a,b) ((a)>(b)?(a):(b))\n//#define MAX7(a,b) ((b)>(a)?(b):(a))\n//#define MAX8(a,b) ((b)<(a)?(a):(b))\n\n#define ABS1(a) (((a)^H0(a))-H0(a))\n//#define ABS2(a) ((a)>0?(a):-(a))\n//#define ABS3(a) ((a)>=0?(a):-(a))\n//#define ABS4(a) ((a)<0?-(a):(a))\n//#define ABS5(a) ((a)<=0?-(a):(a))\n" }, { "answer_id": 19205123, "author": "mkny", "author_id": 2055965, "author_profile": "https://Stackoverflow.com/users/2055965", "pm_score": -1, "selected": false, "text": "int max(int a, int b)\n{\n return ((a - b) >> 31) ? b : a;\n}\n" }, { "answer_id": 66017995, "author": "giokoguashvili", "author_id": 5200896, "author_profile": "https://Stackoverflow.com/users/5200896", "pm_score": 0, "selected": false, "text": "+, -, *, %, /" }, { "answer_id": 66018533, "author": "chqrlie", "author_id": 4593267, "author_profile": "https://Stackoverflow.com/users/4593267", "pm_score": 1, "selected": false, "text": "int min(int a, int b) {\n return (a <= b) * a + (b < a) * b;\n}\nint max(int a, int b) {\n return (a <= b) * b + (b < a) * a;\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
227,401
<p>I would like to be able to know, in run-time in my code, how much memory a certain object is taking (a Dataset in this case, but i'm looking for a "general" solution).</p> <p>Is this possible through reflection?</p> <p>This is for .Net 2.0.</p> <p>Thanks!</p>
[ { "answer_id": 227499, "author": "justin.m.chase", "author_id": 12958, "author_profile": "https://Stackoverflow.com/users/12958", "pm_score": 0, "selected": false, "text": "int size = Marshal.SizeOf(typeof(int));\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3314/" ]
227,417
<p>I've run across the following line in a VB6 application.</p> <pre><code>mobjParentWrkBk.ExcelWorkBook.Application.Selection.Insert Shift:=xlToRight </code></pre> <p>Unfortunately Google and other search engines have not been very useful as they seem to omit the := part. </p> <p>What would be a C# equivalent?</p>
[ { "answer_id": 227431, "author": "John Rudy", "author_id": 14048, "author_profile": "https://Stackoverflow.com/users/14048", "pm_score": 5, "selected": true, "text": "Insert" }, { "answer_id": 227448, "author": "shahkalpesh", "author_id": 23574, "author_profile": "https://Stackoverflow.com/users/23574", "pm_score": 2, "selected": false, "text": "\nvoid Shift()\n{\ndefaultDirection = directionEnum.Left;\nShift(defaultDirection);\n}\n\nvoid Shift(directionEnum direction)\n{\n}\n" }, { "answer_id": 229167, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 3, "selected": false, "text": "Optional" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14177/" ]
227,428
<p>I am planning a PHP application that needs to store date/times in an MSSQL database. (For the curious, it is a calendar application.) What is the preferred format to store this information?</p> <p>MSSQL has its own datetime data type, which works well in the database itself and is very readable. However, there aren't any MSSQL functions to translate datetime values to PHP's preferred format--UNIX timestamp. This makes it a bit more painful to use with PHP. UNIX timestamp is attractive because that's what PHP likes, but it's certainly not as readable and there aren't a bunch of nice built-in MSSQL functions for working with the data.</p> <p>Would you store this information as datetime data type, as UNIX timestamps (as int, bigint, or varchar datatype), as both formats side by side, or as something else entirely?</p>
[ { "answer_id": 227451, "author": "Kris", "author_id": 18565, "author_profile": "https://Stackoverflow.com/users/18565", "pm_score": 3, "selected": false, "text": "date('Y-m-d H:i:s', $myTimeStampInSeconds);" }, { "answer_id": 227508, "author": "Adam Ness", "author_id": 21973, "author_profile": "https://Stackoverflow.com/users/21973", "pm_score": 5, "selected": true, "text": "SELECT * FROM Foo\nWHERE DateDiff(d,field1,now()) < 1\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18986/" ]
227,430
<p>Here is my function (<strong>updated</strong>):</p> <pre><code>Public Shared Function shortenUrl(ByVal URL As String) As String Return shortenUrl(URL, 32) End Function Public Shared Function shortenUrl(ByVal URL As String, ByVal maxLength As Integer) As String If URL.Length &gt; maxLength Then String.Format("{0}...{1}", URL.Substring(0, (maxLength / 2)), URL.Substring(URL.Length - ((maxLength / 2) - 3))) Else Return URL End If End Function </code></pre> <p>I fixed the problem where it didn't return <code>maxLength</code> chars because it didn't take into account the ellipses.</p> <hr> <p>It seems to me that it is too complicated; any suggestions, comments, concerns are more than welcome.</p>
[ { "answer_id": 227445, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 2, "selected": true, "text": "Public Shared Function shortenUrl(ByVal URL As String) As String\n Return shortenUrl(URL, 29)\nEnd Function\nPublic Shared Function shortenUrl(ByVal URL As String, ByVal maxLength As Integer) As String\n If URL.Length > maxLength Then\n Return String.Format(\"{0}...{1}\", URL.Substring(0, maxLength / 2),URL.Substring(URL.Length - (maxLength / 2)))\n Else\n Return URL\n End If\nEnd Function\n" }, { "answer_id": 227452, "author": "tom.dietrich", "author_id": 15769, "author_profile": "https://Stackoverflow.com/users/15769", "pm_score": 0, "selected": false, "text": "Public Shared Function shortenUrl(ByVal URL As String, Optional ByVal maxLength As Integer = 29) As String\n If URL.Length > maxLength Then \n Return String.Format(\"{0}...{1}\", URL.Substring(0, maxLength / 2), URL.Substring(URL.Length - (maxLength / 2)))\n Else\n Return URL\n End If\nEnd Function\n" }, { "answer_id": 227671, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 1, "selected": false, "text": "Public Function shortenUrl2(ByVal URL As String, ByVal maxLength As Integer) As String\n Const middle as String = \"...\"\n If maxLength < 0 Then\n Throw New ArgumentOutOfRangeException(\"maxLength\", \"must be greater than or equal to 0\")\n ElseIf String.IsNullOrEmpty(URL) OrElse URL.Length <= maxLength Then\n Return URL\n ElseIf maxLength < middle.Length Then\n Return URL.Substring(0, maxLength)\n End If\n\n Dim left as String = URL.Substring(0, CType(Math.Floor(maxLength / 2), Integer))\n Dim right as String = URL.Substring(URL.Length - (maxLength - left.Length - middle.Length))\n\n Return left & middle & right\nEnd Function\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25515/" ]
227,434
<p>I have an XML schema that includes multiple addresses:</p> <pre><code>&lt;xs:element name="personal_address" maxOccurs="1"&gt; &lt;!-- address fields go here --&gt; &lt;/xs:element&gt; &lt;xs:element name="business_address" maxOccurs="1"&gt; &lt;!-- address fields go here --&gt; &lt;/xs:element&gt; </code></pre> <p>Within each address element, I include a "US State" enumeration:</p> <pre><code>&lt;xs:simpleType name="state"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:enumeration value="AL" /&gt; &lt;xs:enumeration value="AK" /&gt; &lt;xs:enumeration value="AS" /&gt; .... &lt;xs:enumeration value="WY" /&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; </code></pre> <p>How do I go about writing the "US State" enumeration once and re-using it in each of my address elements? I apologize in advance if this is a n00b question -- I've never written an XSD before.</p> <p>My initial stab at it is the following:</p> <pre><code>&lt;xs:element name="business_address" maxOccurs="1"&gt; &lt;!-- address fields go here --&gt; &lt;xs:element name="business_address_state" type="state" maxOccurs="1"&gt;&lt;/xs:element&gt; &lt;/xs:element&gt; </code></pre>
[ { "answer_id": 227522, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 4, "selected": true, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n targetNamespace=\"http://www.example.org/foo\"\n xmlns:tns=\"http://www.example.org/foo\"\n elementFormDefault=\"qualified\">\n <xs:element name=\"business_address\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"business_address_state\"\n type=\"tns:state\" maxOccurs=\"1\" />\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n <xs:simpleType name=\"state\">\n <xs:restriction base=\"xs:string\">\n <xs:enumeration value=\"AL\" />\n <xs:enumeration value=\"AK\" />\n <xs:enumeration value=\"AS\" />\n <xs:enumeration value=\"WY\" />\n </xs:restriction>\n </xs:simpleType>\n</xs:schema>\n" }, { "answer_id": 232595, "author": "6eorge Jetson", "author_id": 23422, "author_profile": "https://Stackoverflow.com/users/23422", "pm_score": 2, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xs:schema targetNamespace=\"TargetNamespace\" xmlns:TN=\"TargetNamespace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\nelementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\">\n <xs:element name=\"BookInformation\" type=\"BookInformationType\"/>\n <xs:complexType name=\"BookInformationType\">\n <xs:sequence>\n <xs:element ref=\"Title\"/>\n <xs:element ref=\"ISBN\"/>\n <xs:element ref=\"Publisher\"/>\n <xs:element ref=\"PeopleInvolved\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n <xs:complexType name=\"PeopleInvolvedType\">\n <xs:sequence>\n <xs:element name=\"Author\"/>\n </xs:sequence>\n </xs:complexType>\n <xs:element name=\"Title\"/>\n <xs:element name=\"ISBN\"/>\n <xs:element name=\"Publisher\"/>\n <xs:element name=\"PeopleInvolved\" type=\"PeopleInvolvedType\"/>\n</xs:schema>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227434", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10040/" ]
227,438
<p>I'm attempting to determine the row length in bytes of a table by executing the following stored procedure:</p> <pre><code>CREATE TABLE #tmp ( [ID] int, Column_name varchar(640), Type varchar(640), Computed varchar(640), Length int, Prec int, Scale int, Nullable varchar(640), TrimTrailingBlanks varchar(640), FixedLenNullInSource varchar(640), Collation varchar(256) ) INSERT INTO #tmp exec sp_help MyTable SELECT SUM(Length) FROM #tmp DROP TABLE #tmp </code></pre> <p>The problem is that I don't know the table definition (data types, etc..) of the table returned by 'sp_help.'</p> <p>I get the following error:</p> <pre><code>Insert Error: Column name or number of supplied values does not match table definition. </code></pre> <p>Looking at the sp_help stored procedure does not give me any clues.</p> <p>What is the proper CREATE TABLE statement to insert the results of a sp_help?</p>
[ { "answer_id": 227516, "author": "Vendoran", "author_id": 24666, "author_profile": "https://Stackoverflow.com/users/24666", "pm_score": 3, "selected": false, "text": "CREATE TABLE tblShowContig\n(\n ObjectName CHAR (255),\n ObjectId INT,\n IndexName CHAR (255),\n IndexId INT,\n Lvl INT,\n CountPages INT,\n CountRows INT,\n MinRecSize INT,\n MaxRecSize INT,\n AvgRecSize INT,\n ForRecCount INT,\n Extents INT,\n ExtentSwitches INT,\n AvgFreeBytes INT,\n AvgPageDensity INT,\n ScanDensity DECIMAL,\n BestCount INT,\n ActualCount INT,\n LogicalFrag DECIMAL,\n ExtentFrag DECIMAL\n)\nGO\n\nINSERT tblShowContig\nEXEC ('DBCC SHOWCONTIG WITH TABLERESULTS')\nGO\n\nSELECT * from tblShowContig WHERE ObjectName = 'MyTable'\nGO\n" }, { "answer_id": 227592, "author": "Cervo", "author_id": 16219, "author_profile": "https://Stackoverflow.com/users/16219", "pm_score": 2, "selected": false, "text": "select SUM(sc.length) \nfrom syscolumns sc \ninner join systypes st on sc.xtype = st.xtype \nwhere id = object_id('table')\n" }, { "answer_id": 227664, "author": "Booji Boy", "author_id": 1433, "author_profile": "https://Stackoverflow.com/users/1433", "pm_score": 0, "selected": false, "text": "Select * into #mytables\nfrom INFORMATION_SCHEMA.columns\n\nselect * from #mytables\n\ndrop table #mytables\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21826/" ]
227,440
<p>I have a Rails application that in the erb code, I use a select box. What I would like to do is reload the page passing the sort parameter. My controller already handles it, but I don't know how to reload the page with the selected value from my select box. Here is my code:</p> <pre><code>&lt;% @options = {:latest =&gt; 'lastest' , :alphabetical =&gt; 'alphabetical', :pricelow =&gt; 'price-low', :pricehigh =&gt;'pricehigh'} %&gt; &lt;%= select_tag 'sort[]', options_for_select(@options), :include_blank =&gt; true,:onchange =&gt; "location.reload('location?sort='+this.value)"%&gt; </code></pre>
[ { "answer_id": 227829, "author": "workmad3", "author_id": 16035, "author_profile": "https://Stackoverflow.com/users/16035", "pm_score": 3, "selected": true, "text": "<% @options = {:latest => 'lastest' , :alphabetical => 'alphabetical', :pricelow => 'price-low', :pricehigh =>'pricehigh'} %>\n<%= select_tag 'sort[]', options_for_select(@options), :include_blank => true,:onchange => remote_function(:url => {:controller => 'your_controller', :action => 'list_sort_method'}, :with => \"'sort='+this.value\", :update => \"div_containing_list\") %>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18642/" ]
227,447
<p>When I use this code to output some XML I parsed (and modified) with <code>XmlParser</code></p> <pre><code>XmlParser parser = new XmlParser() def root = parser.parseText(feedUrl.toURL().text) def writer = new StringWriter() new XmlNodePrinter(new PrintWriter(writer)).print(root) println writer.toString() </code></pre> <p>the namespace declarations on the root node are not printed, even though they are there in the <code>toString()</code> of <em>root</em>... any ideas?</p>
[ { "answer_id": 228593, "author": "Ted Naleid", "author_id": 8912, "author_profile": "https://Stackoverflow.com/users/8912", "pm_score": 2, "selected": true, "text": "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:creativeCommons=\"http://backend.userland.com/creativeCommonsRssModule\" xmlns:thr=\"http://purl.org/syndication/thread/1.0\">\n <!-- snip -->\n <creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>\n <!-- snip -->\n</feed>\n" }, { "answer_id": 5012799, "author": "Damo", "author_id": 2955, "author_profile": "https://Stackoverflow.com/users/2955", "pm_score": 2, "selected": false, "text": "def root = new XmlSlurper().parseText(\"http://stackoverflow.com/feeds/question/227447\".toURL().text))\ndef outputBuilder = new StreamingMarkupBuilder()\nString result = XmlUtil.serialize(outputBuilder.bind {\n mkp.declareNamespace('':'http://www.w3.org/2005/Atom')\n mkp.declareNamespace('creativeCommons':'http://backend.userland.com/creativeCommonsRssModule')\n mkp.declareNamespace('re':'http://purl.org/atompub/rank/1.0')\n mkp.yield root }\n)\nprintln result\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2031/" ]
227,449
<p>I'm fairly new to JavaScript. </p> <p>Given a local machine's folder path (Windows), I was wondering how you can extract the names of all the possible folders in the current path, without the knowledge of how many folders there are or what they are called.</p> <p>Thank you very much in advance.</p>
[ { "answer_id": 227582, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 3, "selected": false, "text": "var fso = new ActiveXObject(\"Scripting.FileSystemObject\");\nvar shell = new ActiveXObject(\"WScript.Shell\");\nvar path = \"%ProgramFiles%\";\n\nvar programFiles = fso.GetFolder(shell.ExpandEnvironmentStrings(path));\nvar subFolders = new Enumerator(programFiles.SubFolders);\n\nwhile (!subFolders.atEnd())\n{\n var subFolder = subFolders.item();\n WScript.Echo(subFolder.Name);\n subFolders.moveNext();\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
227,457
<p>I'm writing a query to summarize some data. I have a flag in the table that is basically boolean, so I need some sums and counts based on one value of it, and then the same thing for the other value, like so:</p> <pre><code>select location ,count(*) ,sum(duration) from my.table where type = 'X' and location = @location and date(some_tstamp) = @date group by location </code></pre> <p>And then the same for another value of the type column. If I join this table twice, how do I still group so I can only get aggregation for each table, i.e. count(a.<code>*</code>) instead of count(*)...</p> <p>Would it be better to write two separate queries?</p> <p><strong>EDIT</strong></p> <p>Thanks everybody, but that's not what I meant. I need to get a summary where type = 'X' and a summary where type = 'Y' separately...let me post a better example. What I meant was a query like this:</p> <pre><code>select a.location ,count(a.*) ,sum(a.duration) ,count(b.*) ,sum(b.duration) from my.table a, my.table b where a.type = 'X' and a.location = @location and date(a.some_tstamp) = @date and b.location = @location and date(b.some_tstamp) = @date and b.type = 'Y' group by a.location </code></pre> <p>What do I need to group by? Also, DB2 doesn't like count(a.<code>*</code>), it's a syntax error.</p>
[ { "answer_id": 227475, "author": "George Eadon", "author_id": 30530, "author_profile": "https://Stackoverflow.com/users/30530", "pm_score": 3, "selected": false, "text": "select\n type\n ,location\n ,count(*)\n ,sum(duration)\nfrom my.table\nwhere type IN ('X', 'Y')\n and location = @location\n and date(some_tstamp) = @date\ngroup by type, location\n" }, { "answer_id": 227502, "author": "shahkalpesh", "author_id": 23574, "author_profile": "https://Stackoverflow.com/users/23574", "pm_score": 4, "selected": true, "text": "\nselect\n location\n ,Sum(case when type = 'X' then 1 else 0 end) as xCount\n ,Sum(case when type = 'Y' then 1 else 0 end) as YCount\n ,Sum(case when type = 'X' then duration else 0 end) as xCountDuration\n ,Sum(case when type = 'Y' then duration else 0 end) as YCountDuration\nfrom my.table\nwhere \nlocation = @location\n and date(some_tstamp) = @date\ngroup by location\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13791/" ]
227,459
<p>How do I get the <a href="http://en.wikipedia.org/wiki/ASCII" rel="noreferrer">ASCII</a> value of a character as an <code>int</code> in Python?</p>
[ { "answer_id": 227466, "author": "Jacob Krall", "author_id": 3140, "author_profile": "https://Stackoverflow.com/users/3140", "pm_score": 6, "selected": false, "text": "ord()\n" }, { "answer_id": 227472, "author": "Matt J", "author_id": 18528, "author_profile": "https://Stackoverflow.com/users/18528", "pm_score": 12, "selected": true, "text": "ord()" }, { "answer_id": 227889, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 8, "selected": false, "text": "ord()" }, { "answer_id": 36225223, "author": "ShadowRanger", "author_id": 364696, "author_profile": "https://Stackoverflow.com/users/364696", "pm_score": 6, "selected": false, "text": "for ch in mystr:\n code = ord(ch)\n" }, { "answer_id": 58654933, "author": "Indi", "author_id": 11893427, "author_profile": "https://Stackoverflow.com/users/11893427", "pm_score": 3, "selected": false, "text": "ord()" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17693/" ]
227,461
<p>I want to do some basic filtering on a file. Read it, do processing, write it back. </p> <p>I'm not looking for "golfing", but want the simplest and most elegant method to achieve this. I came up with:</p> <pre><code>from __future__ import with_statement filename = "..." # or sys.argv... with open(filename) as f: new_txt = # ...some translation of f.read() open(filename, 'w').write(new_txt) </code></pre> <p>The <code>with</code> statement makes things shorter since I don't have to explicitly open and close the file.</p> <p>Any other ideas ?</p>
[ { "answer_id": 227721, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "with open(filename, \"r+\") as f:\n new_txt = process(f.read())\n f.truncate(0)\n f.write(new_txt)\n" }, { "answer_id": 228858, "author": "Glyph", "author_id": 13564, "author_profile": "https://Stackoverflow.com/users/13564", "pm_score": 1, "selected": false, "text": "from twisted.python.filepath import FilePath\np = FilePath(filename)\np.setContent(process(p.getContent()))\n" }, { "answer_id": 230416, "author": "Hortitude", "author_id": 16584, "author_profile": "https://Stackoverflow.com/users/16584", "pm_score": 6, "selected": true, "text": "import fileinput\nfor line in fileinput.input (filenameToProcess, inplace=1):\n process (line)\n" }, { "answer_id": 344925, "author": "muhuk", "author_id": 42188, "author_profile": "https://Stackoverflow.com/users/42188", "pm_score": 0, "selected": false, "text": "# Some setup first\nfile('test.txt', 'w').write('\\n'.join('%05d' % i for i in range(100)))\n\n\n# This is the filter function\ndef f(i):\n return i % 3\n\n\n# This is the main part \nfile('test2.txt', 'w').write('\\n'.join(str(f(int(l))) for l in file('test.txt', 'r').readlines()))\n\n\n# And a wrapper for sanity\ndef filter_file(infile, outfile, filter_function)\n outfile.write('\\n'.join(filter_function(l) for l in infile.readlines()))\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
227,470
<p>I have a search form on each of my pages. If I use form helper, it defaults to <code>$_POST</code>. I'd like the search term to show up in the URI:</p> <pre><code>http://example.com/search/KEYWORD </code></pre> <p>I've been on Google for about an hour, but to no avail. I've only found articles on how <code>$_GET</code> is basically disabled, because of the native URI convention. I can't be the first person to want this kind of functionality, am I? Thanks in advance!</p>
[ { "answer_id": 227494, "author": "Justin Voss", "author_id": 5616, "author_profile": "https://Stackoverflow.com/users/5616", "pm_score": -1, "selected": false, "text": "$_GET" }, { "answer_id": 227496, "author": "64BitBob", "author_id": 16339, "author_profile": "https://Stackoverflow.com/users/16339", "pm_score": 2, "selected": false, "text": "<form id=\"myform\" onsubmit=\"return changeurl();\" method=\"POST\">\n<input id=\"keyword\">\n</form>\n\n<script>\nfunction changeurl()\n{\n var form = document.getElementById(\"myform\");\n var keyword = document.getElementById(\"keyword\");\n\n form.action = \"http://mysite.com/search/\"+escape(keyword.value);\n\n return true;\n}\n</script>\n" }, { "answer_id": 242432, "author": "muitocomplicado", "author_id": 23561, "author_profile": "https://Stackoverflow.com/users/23561", "pm_score": 0, "selected": false, "text": "// url = http://example.com/search/?q=text\n$this->input->get('q');\n" }, { "answer_id": 319525, "author": "Teej", "author_id": 37532, "author_profile": "https://Stackoverflow.com/users/37532", "pm_score": 4, "selected": true, "text": "<?php echo form_open('ad/pre_search');?>\n <input type=\"text\" name=\"keyword\" />\n</form>\n" }, { "answer_id": 3438630, "author": "Jimmy", "author_id": 414891, "author_profile": "https://Stackoverflow.com/users/414891", "pm_score": 0, "selected": false, "text": "$uri = $_SERVER['REQUEST_URI'];\n\n$pieces = explode(\"/\", $uri);\n\n$uri_3 = $pieces[3];\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24708/" ]
227,473
<p>I need a well tested Regular Expression (.net style preferred), or some other simple bit of code that will parse a USA/CA phone number into component parts, so:</p> <ul> <li>3035551234122</li> <li>1-303-555-1234x122</li> <li>(303)555-1234-122</li> <li>1 (303) 555 -1234-122</li> </ul> <p>etc...</p> <p>all parse into:</p> <ul> <li>AreaCode: 303</li> <li>Exchange: 555</li> <li>Suffix: 1234</li> <li>Extension: 122</li> </ul>
[ { "answer_id": 227509, "author": "Philip Rieck", "author_id": 12643, "author_profile": "https://Stackoverflow.com/users/12643", "pm_score": 2, "selected": false, "text": "^(?:(?:[\\+]?(?<CountryCode>[\\d]{1,3}(?:[ ]+|[\\-.])))?[(]?(?<AreaCode>[\\d]{3})[\\-/)]?(?:[ ]+)?)?(?<Number>[a-zA-Z2-9][a-zA-Z0-9 \\-.]{6,})(?:(?:[ ]+|[xX]|(i:ext[\\.]?)){1,2}(?<Ext>[\\d]{1,5}))?$\n" }, { "answer_id": 227524, "author": "Peter Stone", "author_id": 1806, "author_profile": "https://Stackoverflow.com/users/1806", "pm_score": 1, "selected": false, "text": "/^1?(\\d{3})(\\d{3})(\\d{4})(\\d*)$/" }, { "answer_id": 227546, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 1, "selected": false, "text": "Regex regexObj = new Regex(@\"\\(?(?<AreaCode>[0-9]{3})\\)?[-. ]?(?<Exchange>[0-9]{3})[-. ]*?(?<Suffix>[0-9]{4})[-. x]?(?<Extension>[0-9]{3})\");\nMatch matchResult = regexObj.Match(\"1 (303) 555 -1234-122\");\n\n// Now you have the results in groups \nmatchResult.Groups[\"AreaCode\"];\nmatchResult.Groups[\"Exchange\"];\nmatchResult.Groups[\"Suffix\"];\nmatchResult.Groups[\"Extension\"];\n" }, { "answer_id": 16864443, "author": "gorth", "author_id": 1470847, "author_profile": "https://Stackoverflow.com/users/1470847", "pm_score": 0, "selected": false, "text": "string_o s2, s1 = \"888/872.7676\";\nz_fix_phone_number (s1, s2);\ncout << s2.print(); // prints \"+1 (888) 872-7676\"\nphone_number_o pho = s2;\npho.store_save();\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30529/" ]
227,485
<p>I have a little demonstration below of a peculiar problem.</p> <pre><code>using System; using System.Windows.Forms; namespace WindowsApplication1 { public class TestForm : Form { private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TextBox textBox1; public TestForm() { //Controls this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.textBox1 = new System.Windows.Forms.TextBox(); // tabControl1 this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(12, 12); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(260, 240); this.tabControl1.TabIndex = 0; this.tabControl1.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabControl1_Selected); // tabPage1 this.tabPage1.Controls.Add(this.textBox1); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Size = new System.Drawing.Size(252, 214); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "tabPage1"; // tabPage2 this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Size = new System.Drawing.Size(192, 74); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "tabPage2"; // textBox1 this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox1.Location = new System.Drawing.Point(6, 38); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(240, 20); this.textBox1.TabIndex = 0; // TestForm this.ClientSize = new System.Drawing.Size(284, 264); this.Controls.Add(this.tabControl1); this.Name = "Form1"; this.Text = "Form1"; } //Tab Selected private void tabControl1_Selected(object sender, EventArgs e) { this.Text = "TextBox Width: " + this.textBox1.Width.ToString(); } } //Main static class Program { static void Main() { Application.Run(new TestForm()); } } } </code></pre> <p>If you run the above C# code you will have a small form containing a tabcontrol. Within the tabcontrol is a texbox on the first tab. If you follow these steps you will see the problem:</p> <ol> <li>Select tabPage2 (textBox1's width is reported in the form title)</li> <li>Resize the form</li> <li>Select tabPage1 (The wrong textBox1 width is reported)</li> </ol> <p>Any ideas what is going on here? The textbox is obviously bigger than what is being reported. If you click again on tabPage2 the correct size is then updated. Obviously there is an event updating the width of textBox1. Can i trigger this when tabPage1 is selected?</p>
[ { "answer_id": 227528, "author": "OwenP", "author_id": 2547, "author_profile": "https://Stackoverflow.com/users/2547", "pm_score": 1, "selected": false, "text": "Selected" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13227/" ]
227,486
<p>Does anyone know how to programmaticly find out where the java classloader actually loads the class from? </p> <p>I often work on large projects where the classpath gets very long and manual searching is not really an option. I recently had a <a href="https://stackoverflow.com/questions/226280/eclipse-class-version-bug" title="problem">problem</a> where the classloader was loading an incorrect version of a class because it was on the classpath in two different places.</p> <p>So how can I get the classloader to tell me where on disk the actual class file is coming from?</p> <p><strong><em>Edit:</em></strong> What about if the classloader actually fails to load the class due to a version mismatch (or something else), is there anyway we could find out what file its trying to read before it reads it?</p>
[ { "answer_id": 227492, "author": "Daniel Spiewak", "author_id": 9815, "author_profile": "https://Stackoverflow.com/users/9815", "pm_score": -1, "selected": false, "text": "MyClass" }, { "answer_id": 227569, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 9, "selected": true, "text": "package foo;\n\npublic class Test\n{\n public static void main(String[] args)\n {\n ClassLoader loader = Test.class.getClassLoader();\n System.out.println(loader.getResource(\"foo/Test.class\"));\n }\n}\n" }, { "answer_id": 227640, "author": "Dave DiFranco", "author_id": 30547, "author_profile": "https://Stackoverflow.com/users/30547", "pm_score": 7, "selected": false, "text": "getClass().getProtectionDomain().getCodeSource().getLocation();\n" }, { "answer_id": 227677, "author": "Jevgeni Kabanov", "author_id": 20022, "author_profile": "https://Stackoverflow.com/users/20022", "pm_score": 5, "selected": false, "text": "public static String getClassResource(Class<?> klass) {\n return klass.getClassLoader().getResource(\n klass.getName().replace('.', '/') + \".class\").toString();\n}\n" }, { "answer_id": 228823, "author": "jiriki", "author_id": 19907, "author_profile": "https://Stackoverflow.com/users/19907", "pm_score": 7, "selected": false, "text": "-verbose:class" }, { "answer_id": 19494116, "author": "OldCurmudgeon", "author_id": 823393, "author_profile": "https://Stackoverflow.com/users/823393", "pm_score": 4, "selected": false, "text": "ClassLoader" }, { "answer_id": 29802725, "author": "ecerer", "author_id": 4820142, "author_profile": "https://Stackoverflow.com/users/4820142", "pm_score": 3, "selected": false, "text": "Main" }, { "answer_id": 42238344, "author": "Adam", "author_id": 321772, "author_profile": "https://Stackoverflow.com/users/321772", "pm_score": 0, "selected": false, "text": "Class clazz = Class.forName(nameOfClassYouWant);\n\nURL resourceUrl = clazz.getResource(\"/\" + clazz.getCanonicalName().replace(\".\", \"/\") + \".class\");\nInputStream classStream = resourceUrl.openStream(); // load the bytecode, if you wish\n" }, { "answer_id": 46856293, "author": "Hongyang", "author_id": 6090659, "author_profile": "https://Stackoverflow.com/users/6090659", "pm_score": 2, "selected": false, "text": " String className = MyClass.class.getName().replace(\".\", \"/\")+\".class\";\n URL classUrl = MyClass.class.getClassLoader().getResource(className);\n String fullPath = classUrl==null ? null : classUrl.getPath();\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25920/" ]
227,500
<p>I'm working on a JSP where I need to call methods on object that come from a Bean. The previous version of the page does not use JSTL and it works properly. My new version has a set up like this:</p> <pre><code>&lt;jsp:useBean id="pageBean" scope="request" type="com.epicentric.page.website.PageBean" /&gt; &lt;c:set var="pageDividers" value="&lt;%= pageBean.getPageDividers() %&gt;" /&gt; &lt;c:set var="numColumns" value="${pageDividers.size()}" /&gt; </code></pre> <p>The variable <code>pageDividers</code> is a <code>List</code> object.</p> <p>I'm encountering this issue: when I ask for <code>pageDivider</code>'s size, an exception is thrown. I know this is a simple JTSL error -- what am I doing wrong?</p> <p>The error message is:</p> <blockquote> <p>The function size must be used with a prefix when a default namespace is not specified</p> </blockquote> <p>How do I correctly access or call the methods of my <code>pageDividers</code> object?</p>
[ { "answer_id": 227511, "author": "Vincent Ramdhanie", "author_id": 27439, "author_profile": "https://Stackoverflow.com/users/27439", "pm_score": 2, "selected": false, "text": "${pageDividers.size}\n" }, { "answer_id": 227551, "author": "abahgat", "author_id": 27565, "author_profile": "https://Stackoverflow.com/users/27565", "pm_score": 6, "selected": true, "text": "${pageDividers.size}" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18265/" ]
227,507
<p>How can I read an Open Office 3.0 spreadsheet (.ods) from Groovy? I'd like to select specific columns from a named worksheet. Ideally, it would be useful to add a 'where' clause, or other criteria clause.</p>
[ { "answer_id": 12933631, "author": "Aaron Digulla", "author_id": 34088, "author_profile": "https://Stackoverflow.com/users/34088", "pm_score": 0, "selected": false, "text": "content.xml" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
227,519
<p>I am writing a tool to help students learn regular expressions. I will probably be writing it in Java.</p> <p>The idea is this: the student types in a regular expression and the tool shows which parts of a text will get matched by the regex. Simple enough.</p> <p>But I want to support several different regex "flavors" such as:</p> <ul> <li>Basic regular expressions (think: grep)</li> <li>Extended regular expressions (think: egrep)</li> <li>A subset of Perl regular expressions, including the character classes \w, \s, etc.</li> <li>Sed-style regular expressions</li> </ul> <p>Java has the java.util.Regex class, but it supports only Perl-style regular expressions, which is a superset of the basic and extended REs. What I think I need is a way to take any given regular expression and escape the meta-characters that aren't part of a given flavor. Then I could give it to the Regex object and it would behave as if it was written for the selected RE interpreter.</p> <p>For example, given the following regex:</p> <pre><code>^\w+[0-9]{5}-(\d{4})?$ </code></pre> <p>As a basic regular expression, it would be interpreted as:</p> <pre><code>^\\w\+[0-9]\{5\}-\(\\d\{4\}\)\?$ </code></pre> <p>As an extended regular expression, it would be:</p> <pre><code>^\\w+[0-9]{5}-(\\d{4})?$ </code></pre> <p>And as a Perl-style regex, it would be the same as the original expression.</p> <p>Is there a "regular expression for regular expressions" than I could run through a regex search-and-replace to quote the non-meta characters? What else could I do? Are there alternative Java classes I could use?</p>
[ { "answer_id": 227626, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 1, "selected": false, "text": "[^?+*{}()[\\]\\\\] # literal characters\n\\\\[A-Za-z] # Character classes\n\\\\\\d+ # Back references\n\\\\\\W # Escaped characters\n\\[\\^?(?:\\\\.|[^\\\\])+?\\] # Character classs\n\\((?:\\?[:=!>]|\\?<[=!])? # Beginning of a group\n\\) # End of a group\n(?:[?+*]|\\{\\d+(?:,\\d*)?\\})\\?? # Repetition\n\\| # Alternation\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227519", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17312/" ]
227,545
<p>When I build a unit test project before the tests are executed the test output is copied to a TestResults folder and then the tests are executed. The issue I'm having is that not all the files in the Debug/bin directory are copied to the TestResults project.</p> <p>How can I get a file that is copied to the Debug/bin directory to also be copied to the TestResults folder?</p>
[ { "answer_id": 227713, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 8, "selected": true, "text": ".testrunconfig" }, { "answer_id": 3447009, "author": "Sanjay10", "author_id": 61102, "author_profile": "https://Stackoverflow.com/users/61102", "pm_score": 6, "selected": false, "text": "[TestMethod]\n[DeploymentItem(\"mytestdata.xml\")]\npublic void UploadTest()\n{\n\n\n\n}\n" }, { "answer_id": 6776561, "author": "tomfanning", "author_id": 17971, "author_profile": "https://Stackoverflow.com/users/17971", "pm_score": 3, "selected": false, "text": "Test -> Edit Test Settings -> Local -> Deployment" }, { "answer_id": 25674485, "author": "Richard Morris", "author_id": 4009522, "author_profile": "https://Stackoverflow.com/users/4009522", "pm_score": 2, "selected": false, "text": "xcopy /Y /S /i \"$(ProjectDir)<Project_Folder_Name>\\*\" \"$(TargetDir)<Deployment_Folder_Name>\"\n" }, { "answer_id": 33344679, "author": "JamesDill", "author_id": 2537017, "author_profile": "https://Stackoverflow.com/users/2537017", "pm_score": 2, "selected": false, "text": "[DeploymentItem(\"bin\\\\release\\\\iRock.dll\")]\n[DeploymentItem(\"bin\\\\debug\\\\iRock.dll\")]\n" }, { "answer_id": 45165101, "author": "Nina", "author_id": 3884240, "author_profile": "https://Stackoverflow.com/users/3884240", "pm_score": 1, "selected": false, "text": "[TestMethod]\n[DeploymentItem(\"ProjectName/Folder/SubFolder/file.xml\", \"Folder/Subfolder\")]\npublic void YourTestMethod()\n{\n // in the method you are testing you should have this:\n var filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) + \"/Folder/Subfolder/file.xml\";\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227545", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3957/" ]
227,552
<p>I am trying to debug a JavaScript script that gets read in a Firefox extension and executed. I only can see errors via the Firebug console (my code is invisible to Firebug), and it's reporting a "unterminated string literal." </p> <p>I checked the line and the lines around it and everything seems fine-parentheses, braces, and quotes are balanced, etc. What are other possible causes that I should be looking for?</p>
[ { "answer_id": 1373122, "author": "VoY", "author_id": 6254, "author_profile": "https://Stackoverflow.com/users/6254", "pm_score": 7, "selected": true, "text": "var foo = \"</script>\";\n" }, { "answer_id": 4334841, "author": "Ipsoratio", "author_id": 527943, "author_profile": "https://Stackoverflow.com/users/527943", "pm_score": 2, "selected": false, "text": "$message = 'line 1.\\\\n';\n$message .= 'line 2.';\n" }, { "answer_id": 5918844, "author": "PJ Brunet", "author_id": 722796, "author_profile": "https://Stackoverflow.com/users/722796", "pm_score": 5, "selected": false, "text": "$str = str_replace(array(\"\\r\", \"\\n\"), '', $str);\n" }, { "answer_id": 7420855, "author": "Queue", "author_id": 945238, "author_profile": "https://Stackoverflow.com/users/945238", "pm_score": 4, "selected": false, "text": "\"<\\/script>\"" }, { "answer_id": 8684425, "author": "Brian", "author_id": 1123591, "author_profile": "https://Stackoverflow.com/users/1123591", "pm_score": 4, "selected": false, "text": "<\\/script>\n" }, { "answer_id": 9688136, "author": "Predte4a", "author_id": 1267014, "author_profile": "https://Stackoverflow.com/users/1267014", "pm_score": 2, "selected": false, "text": "\\u2028\n" }, { "answer_id": 13947608, "author": "Vishal Venugopal", "author_id": 1840974, "author_profile": "https://Stackoverflow.com/users/1840974", "pm_score": -1, "selected": false, "text": "str = str_replace(array(\"\\r\\n\",\"\\n\\r\",\"\\r\", \"\\n\"), '<br />', stripslashes($str));\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1227001/" ]
227,566
<p>Does anyone have a good articles or tutorial on correctly using dispose and IDisposable. I am trying to explain this to some junior dev and wanted to get some extra material, examples, etc.</p>
[ { "answer_id": 228326, "author": "NotDan", "author_id": 3291, "author_profile": "https://Stackoverflow.com/users/3291", "pm_score": 0, "selected": false, "text": "using (MyDisposable obj = new MyDisposable())\n{\n obj.some_stuff();\n\n} //obj is disposed here\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
227,575
<p>Here is a snippet of the code :</p> <pre><code>HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(request.RawUrl); WebRequest.DefaultWebProxy = null;//Ensure that we will not loop by going again in the proxy HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); string charSet = response.CharacterSet; Encoding encoding; if (String.IsNullOrEmpty(charSet)) encoding = Encoding.Default; else encoding = Encoding.GetEncoding(charSet); StreamReader resStream = new StreamReader(response.GetResponseStream(), encoding); return resStream.ReadToEnd(); </code></pre> <p>The problem is if I test with : <a href="http://www.google.fr" rel="noreferrer">http://www.google.fr</a></p> <p>All &quot;é&quot; are not displaying well. I have try to change ASCII to UTF8 and it still display wrong. I have tested the html file in a browser and the browser display the html text well so I am pretty sure the problem is in the method I use to download the html file.</p> <p>What should I change?</p> <p><em>removed dead ImageShack link</em></p> <h3>Update 1: Code and test file changed</h3>
[ { "answer_id": 227598, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": true, "text": "HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myURL);\nusing (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())\n{\n using (Stream resStream = response.GetResponseStream())\n {\n StreamReader reader = new StreamReader(resStream, Encoding.???);\n return reader.ReadToEnd();\n }\n}\n" }, { "answer_id": 4229277, "author": "Alex Dubinsky", "author_id": 513966, "author_profile": "https://Stackoverflow.com/users/513966", "pm_score": 5, "selected": false, "text": " string strWebPage = \"\";\n // create request\n System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(sURL);\n // get response\n System.Net.HttpWebResponse objResponse;\n objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();\n // get correct charset and encoding from the server's header\n string Charset = objResponse.CharacterSet;\n Encoding encoding = Encoding.GetEncoding(Charset);\n // read response\n using (StreamReader sr = \n new StreamReader(objResponse.GetResponseStream(), encoding))\n {\n strWebPage = sr.ReadToEnd();\n // Close and clean up the StreamReader\n sr.Close();\n }\n\n // Check real charset meta-tag in HTML\n int CharsetStart = strWebPage.IndexOf(\"charset=\");\n if (CharsetStart > 0)\n {\n CharsetStart += 8;\n int CharsetEnd = strWebPage.IndexOfAny(new[] { ' ', '\\\"', ';' }, CharsetStart);\n string RealCharset = \n strWebPage.Substring(CharsetStart, CharsetEnd - CharsetStart);\n\n // real charset meta-tag in HTML differs from supplied server header???\n if(RealCharset!=Charset)\n {\n // get correct encoding\n Encoding CorrectEncoding = Encoding.GetEncoding(RealCharset);\n\n // read the web page again, but with correct encoding this time\n // create request\n System.Net.WebRequest objRequest2 = System.Net.HttpWebRequest.Create(sURL);\n // get response\n System.Net.HttpWebResponse objResponse2;\n objResponse2 = (System.Net.HttpWebResponse)objRequest2.GetResponse();\n // read response\n using (StreamReader sr = \n new StreamReader(objResponse2.GetResponseStream(), CorrectEncoding))\n {\n strWebPage = sr.ReadToEnd();\n // Close and clean up the StreamReader\n sr.Close();\n }\n }\n }\n" }, { "answer_id": 9841920, "author": "Eddo", "author_id": 1288569, "author_profile": "https://Stackoverflow.com/users/1288569", "pm_score": 4, "selected": false, "text": "public static string DownloadString(string address)\n{\n string strWebPage = \"\";\n // create request\n System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(address);\n // get response\n System.Net.HttpWebResponse objResponse;\n objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();\n // get correct charset and encoding from the server's header\n string Charset = objResponse.CharacterSet;\n Encoding encoding = Encoding.GetEncoding(Charset);\n\n // read response into memory stream\n MemoryStream memoryStream;\n using (Stream responseStream = objResponse.GetResponseStream())\n {\n memoryStream = new MemoryStream();\n\n byte[] buffer = new byte[1024];\n int byteCount;\n do\n {\n byteCount = responseStream.Read(buffer, 0, buffer.Length);\n memoryStream.Write(buffer, 0, byteCount);\n } while (byteCount > 0);\n }\n\n // set stream position to beginning\n memoryStream.Seek(0, SeekOrigin.Begin);\n\n StreamReader sr = new StreamReader(memoryStream, encoding);\n strWebPage = sr.ReadToEnd();\n\n // Check real charset meta-tag in HTML\n int CharsetStart = strWebPage.IndexOf(\"charset=\");\n if (CharsetStart > 0)\n {\n CharsetStart += 8;\n int CharsetEnd = strWebPage.IndexOfAny(new[] { ' ', '\\\"', ';' }, CharsetStart);\n string RealCharset =\n strWebPage.Substring(CharsetStart, CharsetEnd - CharsetStart);\n\n // real charset meta-tag in HTML differs from supplied server header???\n if (RealCharset != Charset)\n {\n // get correct encoding\n Encoding CorrectEncoding = Encoding.GetEncoding(RealCharset);\n\n // reset stream position to beginning\n memoryStream.Seek(0, SeekOrigin.Begin);\n\n // reread response stream with the correct encoding\n StreamReader sr2 = new StreamReader(memoryStream, CorrectEncoding);\n\n strWebPage = sr2.ReadToEnd();\n // Close and clean up the StreamReader\n sr2.Close();\n }\n }\n\n // dispose the first stream reader object\n sr.Close();\n\n return strWebPage;\n}\n" }, { "answer_id": 34367416, "author": "Etienne Coumont", "author_id": 183084, "author_profile": "https://Stackoverflow.com/users/183084", "pm_score": 0, "selected": false, "text": "myHttpWebRequest.UserAgent = \"Mozilla/5.0\";\n" }, { "answer_id": 38650509, "author": "KinBread", "author_id": 4866150, "author_profile": "https://Stackoverflow.com/users/4866150", "pm_score": 1, "selected": false, "text": "String FinalResult = \"\";\nHttpWebRequest Request = (HttpWebRequest)System.Net.WebRequest.Create( URL );\nHttpWebResponse Response = (HttpWebResponse)Request.GetResponse();\nStream ResponseStream = Response.GetResponseStream();\nStreamReader Reader = new StreamReader( ResponseStream );\n\nbool NeedEncodingCheck = true;\n\nwhile( true )\n{\n string NewLine = Reader.ReadLine(); // it may not working for zipped HTML.\n if( NewLine == null )\n {\n break;\n }\n\n FinalResult += NewLine;\n FinalResult += Environment.NewLine;\n\n if( NeedEncodingCheck )\n {\n int Start = NewLine.IndexOf( \"charset=\" );\n if( Start > 0 )\n {\n Start += \"charset=\\\"\".Length; \n int End = NewLine.IndexOfAny( new[] { ' ', '\\\"', ';' }, Start );\n\n Reader = new StreamReader( ResponseStream, Encoding.GetEncoding(\n NewLine.Substring( Start, End - Start ) ) ); // Replace Reader with new encoding.\n\n NeedEncodingCheck = false;\n }\n }\n}\n\nReader.Close();\nResponse.Close();\n" }, { "answer_id": 39458423, "author": "stephenr85", "author_id": 3363709, "author_profile": "https://Stackoverflow.com/users/3363709", "pm_score": 2, "selected": false, "text": " var client = new System.Net.WebClient();\n var data = client.DownloadData(url);\n var encoding = System.Text.Encoding.Default;\n var contentType = new System.Net.Mime.ContentType(client.ResponseHeaders[HttpResponseHeader.ContentType]);\n if (!String.IsNullOrEmpty(contentType.CharSet))\n {\n encoding = System.Text.Encoding.GetEncoding(contentType.CharSet);\n }\n string result = encoding.GetString(data);\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
227,590
<p>For an iPhone app that submits images to a server I need somehow to tie all the images from a particular phone together. With every submit I'd like to send some unique phone id. Looked at <pre> [[UIDevice mainDevice] uniqueIdentifier]<br> and [[NSUserDefaults standardDefaults] stringForKey:@"SBFormattedPhoneNumber"] </pre></p> <p>but getting errors in the simulator.</p> <p>Is there an Apple sanctioned way of doing this?</p>
[ { "answer_id": 227654, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 6, "selected": true, "text": "[[UIDevice currentDevice] uniqueIdentifier]" }, { "answer_id": 228230, "author": "Jason Harris", "author_id": 1345109, "author_profile": "https://Stackoverflow.com/users/1345109", "pm_score": 4, "selected": false, "text": "NSString *uuid = nil;\nCFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);\nif (theUUID) {\n uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));\n [uuid autorelease];\n CFRelease(theUUID);\n}\n" }, { "answer_id": 260759, "author": "wisequark", "author_id": 33159, "author_profile": "https://Stackoverflow.com/users/33159", "pm_score": 4, "selected": false, "text": "[[UIDevice currentDevice] uniqueIdentifier]" }, { "answer_id": 1049473, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "NSString *phoneNumber = (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:@\"SBFormattedPhoneNumber\"]; // Will return null in simulator!\nNSLog(@\"Formatted phone number [%@]\", phoneNumber);\n" }, { "answer_id": 1178227, "author": "Holtwick", "author_id": 140927, "author_profile": "https://Stackoverflow.com/users/140927", "pm_score": 0, "selected": false, "text": "- (NSString *)stringUniqueID {\n NSString * result;\n CFUUIDRef uuid;\n CFStringRef uuidStr;\n uuid = CFUUIDCreate(NULL);\n assert(uuid != NULL);\n uuidStr = CFUUIDCreateString(NULL, uuid);\n assert(uuidStr != NULL);\n result = [NSString stringWithFormat:@\"%@\", uuidStr];\n assert(result != nil);\n NSLog(@\"UNIQUE ID %@\", result);\n CFRelease(uuidStr);\n CFRelease(uuid);\n return result;\n} \n" }, { "answer_id": 8677052, "author": "Moomio", "author_id": 1122488, "author_profile": "https://Stackoverflow.com/users/1122488", "pm_score": 3, "selected": false, "text": " [SSKeychain setPassword:@\"Your UUID\" forService:@\"com.yourapp.yourcompany\" account:@\"user\"];\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30541/" ]
227,596
<p>This has been bugging me, I can't get my head around it. I will use the foodstuffs analogy to try and simplify my probelm.</p> <p>1000 members of the public where asked to pick a variety from each of 13 categories of footstuff. These selections were then stored in a mysql database against their name.</p> <pre><code>e.g. billy mary etc. etc. milk....semi. .skimmed... bread...white...brown.... cheese..edam.....edam.... fruit...apple...orange... veg....potato...sprout... meat....beef.....beef.... sweet..bonbons..liquorice.. fish...trout....salmon... crisp....s&amp;v....plain.... biscuit..hovis..rich tea.. wine.....red.....red..... beer....stella..carlsburg.. carb....coke.....pepsi.... </code></pre> <p>One of those 1000 was then asked to select anywhere from zero to 13 of their selections via checkboxes.</p> <p>By searching the database how many others selected the same varieties?</p> <p>Display in a table showing all their names and what they selected for all 13 varieties.</p> <p>Does that make sense? I hope so 'cause it's driving me mad.</p>
[ { "answer_id": 227794, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": false, "text": "PersonId What_Milk What_Bread What_Cheese\n 1 Semi Wheat Swiss\n 2 Skimmed Rolls French\n 3 Soy Brown Smelly\n 4 Low Fat Wheat Swiss\n" }, { "answer_id": 227876, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "SELECT \n PersonId, \n milk, \n bread, \n cheese\nFROM FoodPreference\nWHERE PersonId != :chosen_person_id \n AND $milk= CASE WHEN :isset($_POST[\"milk\"]))> '' THEN :isset($_POST[\"milk\"])) ELSE milk END \n AND $bread= CASE WHEN :isset($_POST[\"bread\"]))> '' THEN :isset($_POST[\"bread\"])) ELSE bread END \n AND $cheese= CASE WHEN :isset($_POST[\"cheese\"]))> '' THEN :isset($_POST[\"cheese\"])) ELSE cheese END\n" }, { "answer_id": 228037, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 0, "selected": false, "text": "CREATE TABLE FoodPreference (\n PersonID INT NOT NULL REFERENCES People,\n FoodCat VARCHAR(10) NOT NULL REFERENCES FoodCategories,\n FoodChoice VARCHAR(10) NOT NULL,\n PRIMARY KEY (PersonID, FoodCat)\n);\nINSERT INTO FoodPreference VALUES\n (123, 'bread', 'white'),\n (123, 'milk', 'skim'),\n (123, 'cheese', 'edam'), ...\n (321, 'bread', 'brown'),\n (321, 'milk', 'whole'),\n (321, 'cheese', 'edam'), ...\n" }, { "answer_id": 228249, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "$sql = mysql_query(\" \n SELECT \n *\n FROM \".$prefix.\"_users\n WHERE username !='$username' \n AND req_country = IFNULL(NULLIF($bcountry, ''), req_country) \n AND req_region = IFNULL(NULLIF($bregion, ''), req_region) \n AND req_type = IFNULL(NULLIF($btype, ''), req_type)\n AND req_beds = IFNULL(NULLIF($bbeds, ''), req_beds)\n AND req_value = IFNULL(NULLIF($bvalue, ''), req_value)\n AND country = IFNULL(NULLIF($scountry, ''), country) \n AND region = IFNULL(NULLIF($sregion, ''), region) \n AND type = IFNULL(NULLIF($stype, ''), type)\n AND beds = IFNULL(NULLIF($sbeds, ''), beds)\n AND value = IFNULL(NULLIF($svalue, ''), value)\n AND pool = IFNULL(NULLIF($spool, ''), 'Yes')\n AND garage = IFNULL(NULLIF($sgarage, ''), >0) \n AND disabled = IFNULL(NULLIF($sdisabled, ''), 'Yes')\");\n$num = mysql_num_rows($sql);\necho \"Total matches ($num): <br><br>\";\n while($row = mysql_fetch_array($sql)){...etc\n" }, { "answer_id": 231941, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "case \"display_results\":\n\nif ($bcountry = !isset($_POST[\"bcountry\"])){\n $bcountry = \"No\";\n }else {\n $bcountry = \"Yes\";\n }\nif ($bregion = !isset($_POST[\"bregion\"])){\n $bregion = \"No\";\n }else {\n $bregion = \"Yes\";\n }\nif ($btype = !isset($_POST[\"btype\"])){\n $btype = \"No\";\n }else {\n $btype = \"Yes\";\n }\nif ($bbeds = !isset($_POST[\"bbeds\"])){\n $bbeds = \"No\";\n }else {\n $bbeds = \"Yes\";\n }\nif ($bvalue = !isset($_POST[\"bvalue\"])){\n $bvalue = \"No\";\n }else {\n $bvalue = \"Yes\";\n }\nif ($scountry = !isset($_POST[\"scountry\"])){\n $scountry = \"No\";\n }else {\n $scountry = \"Yes\";\n }\nif ($sregion = !isset($_POST[\"sregion\"])){\n $sregion = \"No\";\n }else {\n $sregion = \"Yes\";\n }\nif ($stype = !isset($_POST[\"stype\"])){\n $stype = \"No\";\n }else {\n $stype = \"Yes\";\n }\nif ($sbeds = !isset($_POST[\"sbeds\"])){\n $sbeds = \"No\";\n }else {\n $sbeds = \"Yes\";\n }\nif ($svalue = !isset($_POST[\"svalue\"])){\n $svalue = \"No\";\n }else {\n $svalue = \"Yes\";\n }\nif ($spool = !isset($_POST[\"spool\"])){\n $spool = \"No\";\n }else {\n $spool = \"Yes\";\n }\nif ($sgarage = !isset($_POST[\"sgarage\"])){\n $sgarage = \"No\";\n }else {\n $sgarage = \"Yes\";\n }\nif ($sdisabled = !isset($_POST[\"sdisabled\"])){\n $sdisabled = \"No\";\n }else {\n $sdisabled = \"Yes\";\n }\n\n $result = mysql_query(\"SELECT * FROM \".$prefix.\"_users WHERE username!='$username' \nAND (('$bcountry'='Yes' AND req_country= '$country') OR ('$bcountry'='No')) \nAND (('$bregion'='Yes' AND req_region= '$region') OR ('$bregion'='No'))\nAND (('$btype'='Yes' AND req_type= '$type') OR ('$btype'='No'))\nAND (('$bbeds'='Yes' AND req_beds= '$beds') OR ('$bbeds'='No'))\nAND (('$bvalue'='Yes' AND req_value= '$value') OR ('$bvalue'='No'))\nAND (('$scountry'='Yes' AND country= '$req_country') OR ('$scountry'='No'))\nAND (('$sregion'='Yes' AND region= '$req_region') OR ('$sregion'='No'))\nAND (('$stype'='Yes' AND type= '$req_type') OR ('$stype'='No'))\nAND (('$sbeds'='Yes' AND beds= '$req_beds') OR ('$sbeds'='No'))\nAND (('$svalue'='Yes' AND value= '$req_value') OR ('$svalue'='No'))\nAND (('$spool'='Yes' AND pool= 'Yes') OR ('$spool'='No'))\nAND (('$sgarage'='Yes' AND garage>=1 ) OR ('$sgarage'='No'))\nAND (('$sdisabled'='Yes' AND disabled= 'Yes') OR ('$sdisabled'='No'))\n\")or die(\"MySQL ERROR: \".mysql_error());\n$number = mysql_num_rows($result);\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
227,604
<p>Is there a good way to read RAW image files (especially Canon CR2 and Adobe DNG files) as GDI+ bitmaps that is reasonably fast?</p> <p>I found an example running under WPF that would read an image using any installed image codec and then display it in an image control. And I modified this example to create a GDI+ bitmap by writing the WPF image to a MemoryStream and creating the Bitmap from that. But this process is slow! Horribly slow! Opening a simple image takes around 10 seconds on my computer. This solution also requires references to the WPF assemblies and that doesn't feel right, especially not since I would like to run the code in an ASP.NET project. </p> <p>There are programs that will do batch conversions of the images, but I would prefer converting the images dynamically when requested. </p> <p>So, any suggestions? </p>
[ { "answer_id": 229045, "author": "Rune Grimstad", "author_id": 30366, "author_profile": "https://Stackoverflow.com/users/30366", "pm_score": 2, "selected": false, "text": "Process.Start" }, { "answer_id": 4256784, "author": "glenneroo", "author_id": 209866, "author_profile": "https://Stackoverflow.com/users/209866", "pm_score": 2, "selected": false, "text": "using dcraw;" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30366/" ]
227,608
<p>Is there a simple way to parse a date that may be in MM/DD/yyyy, or M/D/yyyy, or some combination? i.e. the zero is optional before a single digit day or month.</p> <p>To do it manually, one could use:</p> <pre><code>String[] dateFields = dateString.split("/"); int month = Integer.parseInt(dateFields[0]); int day = Integer.parseInt(dateFields[1]); int year = Integer.parseInt(dateFields[2]); </code></pre> <p>And validate with:</p> <pre><code>dateString.matches("\\d\\d?/\\d\\d?/\\d\\d\\d\\d") </code></pre> <p>Is there a call to SimpleDateFormat or JodaTime that would handle this?</p>
[ { "answer_id": 227625, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 4, "selected": false, "text": "DateFormat df = new SimpleDateFormat(\"MM/dd/yyyy\");\ndf.setLenient(true);\nSystem.out.println(df.parse(\"05/05/1999\"));\nSystem.out.println(df.parse(\"5/5/1999\"));\n" }, { "answer_id": 228356, "author": "Ray Myers", "author_id": 2046, "author_profile": "https://Stackoverflow.com/users/2046", "pm_score": 2, "selected": true, "text": "new SimpleDateFormat(\"MM/dd/yyyy\").parse(dateString);\n" }, { "answer_id": 33405835, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 2, "selected": false, "text": "MM" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2046/" ]
227,612
<p>I am inserting a column in a DataGridView programmatically (i.e., not bound to any data tables/databases) as follows:</p> <pre><code>int lastIndex = m_DGV.Columns.Count - 1; // Count = 4 in this case DataGridViewTextBoxColumn col = (DataGridViewTextBoxColumn)m_DGV.Columns[lastIndex]; m_DGV.Columns.RemoveAt(lastIndex); m_DGV.Columns.Insert(insertIndex, col); // insertIndex = 2 </code></pre> <p>I have found that my columns are visually out of order sometimes using this method. A workaround is to manually set the DisplayIndex property of the column afterwards. Adding this code "fixes it", but I don't understand why it behaves this way.</p> <pre><code>Console.Write(m_DGV.Columns[0].DisplayIndex); // Has value of 0 Console.Write(m_DGV.Columns[1].DisplayIndex); // Has value of 1 Console.Write(m_DGV.Columns[2].DisplayIndex); // Has value of 3 Console.Write(m_DGV.Columns[3].DisplayIndex); // Has value of 2 col.DisplayIndex = insertIndex; Console.Write(m_DGV.Columns[0].DisplayIndex); // Has value of 0 Console.Write(m_DGV.Columns[1].DisplayIndex); // Has value of 1 Console.Write(m_DGV.Columns[2].DisplayIndex); // Has value of 2 Console.Write(m_DGV.Columns[3].DisplayIndex); // Has value of 3 </code></pre> <p>As an aside, my grid can grow its column count dynamically. I wanted to grow it in chunks, so each insert didn't require a column allocation (and associated initialization). Each "new" column would then be added by grabbing an unused column from the end, inserting it into the desired position, and making it visible.</p>
[ { "answer_id": 241167, "author": "e-holder", "author_id": 22252, "author_profile": "https://Stackoverflow.com/users/22252", "pm_score": 0, "selected": false, "text": "Insert" }, { "answer_id": 355463, "author": "lc.", "author_id": 44853, "author_profile": "https://Stackoverflow.com/users/44853", "pm_score": 2, "selected": false, "text": "GetFirstColumn" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22252/" ]
227,613
<p>How do I copy a directory including sub directories excluding files or directories that match a certain regex on a Windows system?</p>
[ { "answer_id": 227636, "author": "Niniki", "author_id": 4155, "author_profile": "https://Stackoverflow.com/users/4155", "pm_score": 1, "selected": false, "text": "ls -R1 | grep -v <regex to exclude> | awk '{printf(\"cp %s /destination/path\",$1)}' | /bin/sh\n" }, { "answer_id": 227675, "author": "moritz", "author_id": 14132, "author_profile": "https://Stackoverflow.com/users/14132", "pm_score": 3, "selected": false, "text": "rsync (1)" }, { "answer_id": 227696, "author": "dwarring", "author_id": 2105284, "author_profile": "https://Stackoverflow.com/users/2105284", "pm_score": 3, "selected": false, "text": " use File::Xcopy;\n\n my $fx = new File::Xcopy; \n $fx->from_dir(\"/from/dir\");\n $fx->to_dir(\"/to/dir\");\n $fx->fn_pat('(\\.pl|\\.txt)$'); # files with pl & txt extensions\n $fx->param('s',1); # search recursively to sub dirs\n $fx->param('verbose',1); # search recursively to sub dirs\n $fx->param('log_file','/my/log/file.log');\n my ($sr, $rr) = $fx->get_stat; \n $fx->xcopy; # or\n $fx->execute('copy'); \n\n # the same with short name\n $fx->xcp(\"from_dir\", \"to_dir\", \"file_name_pattern\");\n" }, { "answer_id": 227699, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 1, "selected": false, "text": "cpio -p" }, { "answer_id": 227936, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 5, "selected": true, "text": "use File::Copy;\nsub copy_recursively {\n my ($from_dir, $to_dir, $regex) = @_;\n opendir my($dh), $from_dir or die \"Could not open dir '$from_dir': $!\";\n for my $entry (readdir $dh) {\n next if $entry =~ /$regex/;\n my $source = \"$from_dir/$entry\";\n my $destination = \"$to_dir/$entry\";\n if (-d $source) {\n mkdir $destination or die \"mkdir '$destination' failed: $!\" if not -e $destination;\n copy_recursively($source, $destination, $regex);\n } else {\n copy($source, $destination) or die \"copy failed: $!\";\n }\n }\n closedir $dh;\n return;\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2133/" ]
227,624
<p>I am trying to create controller actions which will return either JSON or partial html depending upon a parameter. What is the best way to get the result returned to an MVC page asynchronously?</p>
[ { "answer_id": 227638, "author": "Haacked", "author_id": 598, "author_profile": "https://Stackoverflow.com/users/598", "pm_score": 10, "selected": true, "text": "public ActionResult SomeActionMethod() {\n return Json(new {foo=\"bar\", baz=\"Blech\"});\n}\n" }, { "answer_id": 227706, "author": "SaaS Developer", "author_id": 7215, "author_profile": "https://Stackoverflow.com/users/7215", "pm_score": 6, "selected": false, "text": "public ActionResult SomeActionMethod(int id) \n{ \n return Json(new {foo=\"bar\", baz=\"Blech\"});\n}\n" }, { "answer_id": 228182, "author": "Brad Wilson", "author_id": 1554, "author_profile": "https://Stackoverflow.com/users/1554", "pm_score": 4, "selected": false, "text": "return PartialView(\"viewname\");\n" }, { "answer_id": 1492970, "author": "James Green", "author_id": 31736, "author_profile": "https://Stackoverflow.com/users/31736", "pm_score": 7, "selected": false, "text": "if (Request.AcceptTypes.Contains(\"text/html\")) {\n return View();\n}\nelse if (Request.AcceptTypes.Contains(\"application/json\"))\n{\n return Json( new { id=1, value=\"new\" } );\n}\nelse if (Request.AcceptTypes.Contains(\"application/xml\") || \n Request.AcceptTypes.Contains(\"text/xml\"))\n{\n //\n}\n" }, { "answer_id": 16393288, "author": "Vlad", "author_id": 2349318, "author_profile": "https://Stackoverflow.com/users/2349318", "pm_score": 3, "selected": false, "text": " [HttpGet]\n public ActionResult SomeActionMethod()\n {\n return IncJson(new SomeVm(){Id = 1,Name =\"Inc\"});\n }\n" }, { "answer_id": 17734878, "author": "Shane Kenyon", "author_id": 1158844, "author_profile": "https://Stackoverflow.com/users/1158844", "pm_score": 6, "selected": false, "text": "JsonRequestBehavior.AllowGet" }, { "answer_id": 45560042, "author": "Anil Vaddepally", "author_id": 6593652, "author_profile": "https://Stackoverflow.com/users/6593652", "pm_score": 3, "selected": false, "text": "public ActionResult DynamicReturnType(string parameter)\n {\n if (parameter == \"JSON\")\n return Json(\"<JSON>\", JsonRequestBehavior.AllowGet);\n else if (parameter == \"PartialView\")\n return PartialView(\"<ViewName>\");\n else\n return null;\n\n\n }\n" }, { "answer_id": 46094924, "author": "sakthi", "author_id": 5311353, "author_profile": "https://Stackoverflow.com/users/5311353", "pm_score": 2, "selected": false, "text": " public ActionResult GetExcelColumn()\n { \n List<string> lstAppendColumn = new List<string>();\n lstAppendColumn.Add(\"First\");\n lstAppendColumn.Add(\"Second\");\n lstAppendColumn.Add(\"Third\");\n return Json(new { lstAppendColumn = lstAppendColumn, Status = \"Success\" }, JsonRequestBehavior.AllowGet);\n }\n }\n" }, { "answer_id": 49531015, "author": "Mannan Bahelim", "author_id": 5326667, "author_profile": "https://Stackoverflow.com/users/5326667", "pm_score": 1, "selected": false, "text": "public class AuctionsController : Controller\n{\n public ActionResult Auction(long id)\n {\n var db = new DataContext();\n var auction = db.Auctions.Find(id);\n\n // Respond to AJAX requests\n if (Request.IsAjaxRequest())\n return PartialView(\"Auction\", auction);\n\n // Respond to JSON requests\n if (Request.IsJsonRequest())\n return Json(auction);\n\n // Default to a \"normal\" view with layout\n return View(\"Auction\", auction);\n }\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30544/" ]
227,627
<p>I have this 'simplified' fortran code</p> <pre><code>real B(100, 200) real A(100,200) ... initialize B array code. do I = 1, 100 do J = 1, 200 A(J,I) = B(J,I) end do end do </code></pre> <p>One of the programming gurus warned me, that fortran accesses data efficiently in column order, while c accesses data efficiently in row order. He suggested that I take a good hard look at the code, and be prepared to switch loops around to maintain the speed of the old program.</p> <p>Being the lazy programmer that I am, and recognizing the days of effort involved, and the mistakes I am likely to make, I started wondering if there might a #define technique that would let me convert this code safely, and easily.</p> <p>Do you have any suggestions?</p>
[ { "answer_id": 227680, "author": "itsmatt", "author_id": 7862, "author_profile": "https://Stackoverflow.com/users/7862", "pm_score": 2, "selected": false, "text": "real B(100, 200) \nreal A(100,200)\n\n... initialize B array code.\n\ndo I = 1, 100\n do J = 1, 200\n A(I,J) = B(I,J)\n end do\nend do\n" }, { "answer_id": 229932, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 3, "selected": true, "text": "#define array_length(a) (sizeof(a)/sizeof((a)[0]))\nfloat a[100][200];\na[x][y] == ((float *)a)[array_length(a[0])*x + y];\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7734/" ]
227,634
<p>I am copying a repository by using svnsync and am receiving this error on the same revision every time.</p> <blockquote> <p>Transmitting file data ...svnsync: REPORT of '<a href="https://svn1.avlux.net/xxxxxx.net" rel="nofollow noreferrer">https://svn1.avlux.net/xxxxxx.net</a>': Could not read response body: Secure connection truncated <a href="https://svn1.avlux.net" rel="nofollow noreferrer">https://svn1.avlux.net</a>)</p> </blockquote> <p>It is a large revision and I don't have admin access to the server. Is there a way around this, even if it involves checking out and copying the revision manually?</p>
[ { "answer_id": 228427, "author": "Mike Deck", "author_id": 1247, "author_profile": "https://Stackoverflow.com/users/1247", "pm_score": 3, "selected": true, "text": "svn diff -r134:135 http://your/repo/url > patch.diff\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5233/" ]
227,650
<p>Say I have an MSSQL table with two columns: an int ID column that's the identity column and some other datetime or whatever column. Say the table has 10 records with IDs 1-10. Now I delete the record with ID = 5.</p> <p>Are there any scenarios where another record will "fill-in" that missing ID? I.e. when would a record be inserted and given an ID of 5?</p>
[ { "answer_id": 229079, "author": "onedaywhen", "author_id": 15354, "author_profile": "https://Stackoverflow.com/users/15354", "pm_score": 0, "selected": false, "text": "CREATE TABLE Test \n(\n ID INTEGER IDENTITY(1, 1) NOT NULL, \n data_col INTEGER NOT NULL\n);\n\nINSERT INTO Test (data_col) \n VALUES (1), (2), (3), (4);\n\nDELETE\n FROM Test \n WHERE ID BETWEEN 2 AND 3;\n\nDBCC CHECKIDENT ('Test', RESEED, 1)\n\nINSERT INTO Test (data_col) \n VALUES (5), (6), (7), (8);\n\nSELECT T1.ID, T1.data_col \n FROM Test AS T1\n ORDER \n BY data_col;\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
227,667
<p>What type of exception is caught by the beanshell catch(ex): Exception or Throwable?.</p> <p>Example:</p> <pre><code>try { .... } catch (ex) { } </code></pre>
[ { "answer_id": 232275, "author": "Bob Cross", "author_id": 5812, "author_profile": "https://Stackoverflow.com/users/5812", "pm_score": 3, "selected": false, "text": "try {\n new Throwable(\"Something Exceptional\");\n} catch (ex) {\n System.err.println(ex.getMessage());\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
227,674
<p>I've got a few very short audio clips (less than a second long) to be played on various events (button hover, click, etc). However, there is usually a significant lag between the action and the actual playing of the sound. I have tried both embedding the sound in the .swf, and loading it externally at the start, but both lead to the same results. Likewise, I've tried with compressed and uncompressed audio.</p> <p>What it <em>seems</em> like is that the audio buffers are just a lot longer than I need them to be, like perhaps Flash is optimized more towards playing longer sounds without any stutter at the expense of a little more latency in starting sounds. Could this be it? Is there any way to change them? Since what I'm working on will never need to play sounds more than a second or so long and will always be loaded completely at the start, it wouldn't hurt it at all to have really short buffers.</p> <p>One other possible thing that might be the cause: if I use .wav files when using loadSound()... I can't get it to actually play the sounds. There's no errors, and everything returns as it should, but no actual sound is played, which is why I have them as .mp3 currently. Perhaps when using .mp3 audio (or any compressed audio), there just will be lag in decoding it? The reason I still have doubts about this, though, is that when embedding them in the .swf as .wav files (by importing them into the library), they still have the same latency on playback.</p> <p>Just for a sanity check, I'll include the code I've got, minus irrelevant parts and error checking. First, loading them at runtime:</p> <pre><code>var soundArray:Array = new Array(); loadSound( "click", "sounds/buttondroop4.mp3" ); loadSound( "hover", "sounds/Dink-Public_D-146.mp3" ); function loadSound( name:String, url:String ):void { var req:URLRequest = new URLRequest( url ); soundArray[ name ] = new Sound( req ); soundArray[ name ].addEventListener( Event.COMPLETE, soundLoaded ); } function soundLoaded( event:Event ):void { for( var name:String in soundArray ) { if( event.target == soundArray[name] ) { trace( "Loaded sound [" + name + "]" ); return; } } } function playSound( name:String ):void { for( var nameSrc:String in soundArray ) { if( name == nameSrc ) { var channel:SoundChannel = soundArray[ name ].play(); return; } } } // Sometime later, well after soundLoaded() callback is triggered... playSound( "click" ); playSound( "hover" ); </code></pre> <p>And an alternate way, embedding them in the library as classes and going from there:</p> <pre><code>var sClick:soundClick = new soundClick(); var sHover:soundHover = new soundHover(); sClick.play(); sHover.play(); </code></pre> <p>The sound files are tiny, less than 10kb generally. The lag is apparent enough that one of the first complaints someone had when looking at it was that the sound effects on button hovers seemed delayed, so it wasn't just me being picky. I feel like I must just be doing something wrong; there's too many flash things out there that have snappy sound effects without anywhere near this kind of lag.</p> <p>edit: In response to the first response about sound files themselves, I've already checked, and the sound starts immediately at the start of the file (even clipping out everything but the very first millisecond of sound, I can still hear the start of the 'tick' noise it makes).</p>
[ { "answer_id": 238176, "author": "James Fassett", "author_id": 27081, "author_profile": "https://Stackoverflow.com/users/27081", "pm_score": 4, "selected": true, "text": "function playSound( name:String ):void\n{\n for( var nameSrc:String in soundArray )\n {\n if( name == nameSrc )\n {\n var channel:SoundChannel = soundArray[ name ].play();\n return;\n }\n }\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227674", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9330/" ]
227,701
<p>I can't for the life of me find a form that doesn't email the results that you submit.</p> <p>I'm looking to find a form that I can have users enter simple data that i can then spit back out at them in different arrangements. If they submit First and Last, I'll spit out, amongst other things, FirstLast@domain.com. I'm willing to scrounge the code manually to do this, but I cant find a simple form that would allow me to do this. </p> <p><strong>Edit:</strong> PHP or similar simple languages. I've never touched .NET before.</p>
[ { "answer_id": 227891, "author": "Kornel", "author_id": 27009, "author_profile": "https://Stackoverflow.com/users/27009", "pm_score": 0, "selected": false, "text": "<form onsubmit=\"magic(this);return false\">\n <p><label>First <input name=first/></label>\n <p><label>Last <input name=last/></label>\n <input type=\"submit\">\n\n <div id=\"output\"></div>\n</form> \n\n<script type=\"text/javascript\">\n var output = document.getElementById('output');\n function toHTML(text)\n {\n return text.replace(/</g,'&lt;');\n }\n\n function magic(form)\n {\n output.innerHTML = toHTML(form.first.value + form.last.value) + '@domain.com';\n }\n</script>\n" }, { "answer_id": 227899, "author": "alex77", "author_id": 1555, "author_profile": "https://Stackoverflow.com/users/1555", "pm_score": 2, "selected": false, "text": "<form action=\"process.php\" method=\"post\">\n First: <input type=\"text\" name=\"first\" />\n Last: <input type=\"text\" name=\"last\" />\n <input type=\"submit\" />\n</form>\n" }, { "answer_id": 227920, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 1, "selected": false, "text": "<?php\n\n$sfirst = htmlentities($_POST['first']);\n$slast = htmlentities($_POST['last']);\n\necho $first . \".\" . $last . \"@domain.com\";\n?>\n" }, { "answer_id": 261216, "author": "Tim", "author_id": 33914, "author_profile": "https://Stackoverflow.com/users/33914", "pm_score": 0, "selected": false, "text": "<?php\n// loop through every form field\nwhile( list( $field, $value ) = each( $_POST )) {\n // display values\n if( is_array( $value )) {\n // if checkbox (or other multiple value fields)\n while( list( $arrayField, $arrayValue ) = each( $value ) {\n echo \"<p>\" . $arrayValue . \"</p>\\n\";\n }\n } else {\n echo \"<p>\" . $value . \"</p>\\n\";\n }\n}\n?>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
227,708
<p>I would like to apply some logic to a page containing a CheckBoxList control when the user checks or unchecks individual checkbox items. Say, for instance to dynamically show or hide a related control.</p> <p>I came up with a way using ASP.Net 2.0 callback mechanism (AJAX) with a combination of client-side Javascript and server-side logic in the code-behind. However, this solution is not very bullet-proof (i.e. most likely suffers from timing issues). It is not portable, because the code needs to know the sequential ids of individual items, etc.</p> <p>The code I came up with is separated in two functions, one handling the <code>onclick</code> event, and the other processing the returned callback string :</p> <pre><code>&lt;script type="text/javascript"&gt; function OnCheckBoxClicked() { // gathers the semi-colon separated list of labels, // associated with the currently checked items var texts = ''; // iterate over each individual checkbox item // items in a checkboxlist are sequential, so // stop iteration at the first missing sequence number for (var index = 0; index &lt; 99; index++) { var checkbox = document.getElementById('ctl00_cphAdmin_cblCategories_' + index); if (checkbox == null) break; if (checkbox.checked) { // find label associated with the current checkbox item var labels = document.getElementsByTagName('label'); for (var index_ = 0; index_ &lt; labels.length; index_ ++) { if (labels[index_].htmlFor == checkbox.id) { texts = texts + labels[index_].innerHTML + ';'; break; } } } } // perform callback request // result will be processed by the UpdateCheckBoxes function WebForm_DoCallback('__Page', '_checkbox' + texts, UpdateCheckBoxes, 'checkbox', null, true /* synchronous */); } &lt;/script&gt; </code></pre> <p>In this example, my checkboxes match categories of a blog post.</p> <p>I need to process the resulting callback string as containing a list of semicolon-separated names of checkboxes to check/uncheck, in order to make sure that related parent/child categories are synchronized correctly. This string results from logic executed on the server.</p> <p>In other cases, the resulting callback string might be something else.</p> <pre><code>&lt;script type="text/javascript"&gt; function UpdateCheckBoxes(returnmessage, context) { if (returnmessage == null || returnmessage == '') return ; // iterate over each individual checkbox item // items in a checkboxlist are sequential, so // stop iteration at the first missing sequence number for (var index = 0; index &lt; 99; index++) { var checkbox = document.getElementById('ctl00_cphAdmin_cblCategories_' + index); if (checkbox == null) break; // find label associated with the current checkbox item var label = ''; var labels = document.getElementsByTagName('label'); for (var index_ = 0; index_ &lt; labels.length; index_ ++) { if (labels[index_].htmlFor == checkbox.id) { label = ';' + labels[index_].innerHTML + ';'; break; } } // perform custom processing based on the contents // of the returned callback string // for instance, here we check whether the returnmessage // contains the string ';' + label + ';' if (returnmessage.indexOf(label, 1) &gt; 0) { // do something } } } &lt;/script&gt; </code></pre> <p>Isn't there a more elegant solution to this problem?</p>
[ { "answer_id": 228448, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": true, "text": " <label for=\"something\">CheckBox 1</label>\n <input type='checkbox' id='ctl00_....' value='1' onclick=\"OnCheckBoxClicked(this,'CheckBox_1');\" />\n" }, { "answer_id": 228469, "author": "Oscar Cabrero", "author_id": 14440, "author_profile": "https://Stackoverflow.com/users/14440", "pm_score": 0, "selected": false, "text": "<input type='checkbox' id='ctl00_....' value='1' onclick=\"OnCheckBoxClicked('ctrl_toUpdateID');\" />\n\n\n\n<script type=\"text/javascript\">\n\nfunction OnCheckBoxClicked(ctrlID)\n{\n var ctrl = document.getElementById(ctrlID);\n if(ctrl.getAttribute('disabled')\n ctrl.removeAttribute('disabled')\nelse\n ctrl.setAttribute('disabled','disabled')\n\n\n}\n</script>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18865/" ]
227,711
<p>I found <a href="http://www.jenitennison.com/xslt/grouping/muenchian.html" rel="noreferrer">this page</a> describing the Muenchian method, but I think I'm applying it wrong.</p> <p>Consider that this would return a set of ages:</p> <pre><code>/doc/class/person/descriptive[(@name='age')]/value </code></pre> <blockquote> <p>1..2..2..2..3..3..4..7</p> </blockquote> <p>But I would like a nodeset only one node for each age.</p> <blockquote> <p>1..2..3..4..7</p> </blockquote> <p>Each of these seem to return all of the values, instead of unique values:</p> <pre><code>/doc/class/person/descriptive[(@name='age')][not(value=preceding-sibling::value)]/value /doc/class/person/descriptive[(@name='age')]/value[not(value=preceding-sibling::value)] </code></pre> <p>What am I missing?</p>
[ { "answer_id": 227765, "author": "JacobE", "author_id": 30056, "author_profile": "https://Stackoverflow.com/users/30056", "pm_score": 1, "selected": false, "text": "/doc/class/person/descriptive[(@name='age')][not(value=preceding-sibling::descriptive[@name='age']/value)]/value\n" }, { "answer_id": 227805, "author": "BQ.", "author_id": 4632, "author_profile": "https://Stackoverflow.com/users/4632", "pm_score": 6, "selected": true, "text": "<root>\n <item type='test'>A</item>\n <item type='test'>B</item>\n <item type='test'>C</item>\n <item type='test'>A</item>\n <item type='other'>A</item>\n <item type='test'>B</item>\n <item type='other'>D</item>\n <item type=''>A</item>\n</root>\n" }, { "answer_id": 230028, "author": "ChuckB", "author_id": 28605, "author_profile": "https://Stackoverflow.com/users/28605", "pm_score": 4, "selected": false, "text": "<?xml version=\"1.0\"?>\n<xsl:stylesheet version=\"1.0\"\n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n\n <xsl:output indent=\"yes\" method=\"text\"/>\n <xsl:key name=\"item-by-value\" match=\"item\" use=\".\"/>\n\n <xsl:template match=\"/\">\n <xsl:apply-templates select=\"/root/item\"/>\n </xsl:template>\n\n <xsl:template match=\"item\">\n <xsl:if test=\"generate-id() = generate-id(key('item-by-value', normalize-space(.)))\">\n <xsl:value-of select=\".\"/>\n <xsl:text>\n</xsl:text>\n </xsl:if>\n </xsl:template>\n\n <xsl:template match=\"text()\">\n <xsl:apply-templates/>\n </xsl:template>\n</xsl:stylesheet>\n" }, { "answer_id": 1112524, "author": "matpie", "author_id": 51021, "author_profile": "https://Stackoverflow.com/users/51021", "pm_score": 2, "selected": false, "text": "<!-- Set the name to whatever you want -->\n<xsl:key name=\"PeopleAges\" match=\"/doc/class/person/descriptive[@name = 'age']/value\" use=\".\" />\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/525/" ]
227,717
<p>I need to be able to launch a process and read the output into a variable. Then based on the return of the command I can choose to show the full output or just a selected subset.</p> <p>So to be clear, I want to launch a text based process (psexec actually) and read the output from that command (stdout, stderr, etc) into a variable rather than have it directly outputted to the console.</p>
[ { "answer_id": 227748, "author": "Pseudo Masochist", "author_id": 8529, "author_profile": "https://Stackoverflow.com/users/8529", "pm_score": 4, "selected": true, "text": "System.Diagnostics.Process" }, { "answer_id": 227784, "author": "alastairs", "author_id": 5296, "author_profile": "https://Stackoverflow.com/users/5296", "pm_score": 1, "selected": false, "text": "$output = ps\n" }, { "answer_id": 227894, "author": "Scott Saad", "author_id": 4916, "author_profile": "https://Stackoverflow.com/users/4916", "pm_score": 1, "selected": false, "text": "> $proc = Start-Process pslist -NoShellExecute\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24279/" ]
227,729
<p>I am a self taught vb6 programmer who uses DAO. Below is an example of a typical piece of code that I could churn out:</p> <pre><code>Sub cmdMultiplier_Click() 'Button on form, user interface ' dim Rec1 as recordset dim strSQL as string strSQL = "select * from tblCustomers where ID = " &amp; CurrentCustomerID 'inline SQL ' set rec1 = GlobalDataBase.openrecordset(strSQL) ' Data access ' if rec1.bof &lt;&gt; true or rec1.eof &lt;&gt; true then if rec1.fields("Category").value = 1 then PriceMultiplier = 0.9 ' Business Logic ' else priceMultiplier = 1 end if end if End Sub </code></pre> <p>Please pretend that the above is the entire source code of a CRUD application. I know this design is bad, everything is mixed up together. Ideally it should have three distinct layers, user interface, business logic and data access. I sort-of get why this is desirable but I don't know how it's done and I suspect that's why I don't fully get why such a separation is good. I think I'd be a lot further down the road if someone could refactor the above ridiculously trivial example into 3 tiers. </p>
[ { "answer_id": 227764, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "function getCustomer(CurrentCustomerID as Long)\n\nstrSQL = \"select * from tblCustomers where ID = \" & CurrentCustomerID\nset rec1 = GlobalDataBase.openrecordset(strSQL)\nresult = 1\n\nif rec1.recordcount >0 then\n getCustomer = rec1\nelse\n getCustomer = false\nendif\nend function\n" }, { "answer_id": 228085, "author": "Brian Schmitt", "author_id": 30492, "author_profile": "https://Stackoverflow.com/users/30492", "pm_score": 1, "selected": false, "text": "btnClick\n Dim Cust as New Customer(ID)\n multplr = Cust.DiscountMultiplier\nEnd Click\n\nClass Customer\n Sub New(ID)\n Data = DAL.GetCustomerData(ID)\n Me.Name = Data(\"Name\")\n Me.Address = Data(\"Address\")\n Me.DiscountMultiplier = Data(\"DiscountMultiplier\")\n End Sub\n Property ID\n Property Name\n Property Address\n Property DiscountMultiplier\n Return _discountMultiplier\n End\nEnd Class\n\n\nClass DAL\n Function GetCustomerData(ID)\n SQL = \"Paramaterized SQL\"\n Return Data\n End Function\nEnd Class\n" }, { "answer_id": 228359, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 3, "selected": true, "text": "'in Form class - button handler\nSub cmdMultiplier_Click()\n PriceMultiplier = ComputePriceMultiplier(CurrentCustomerId)\nEnd Sub\n\n'in Biz Logic class\nFunction ComputePriceMultiplier(custId as Integer) as Double\n Dim cust as Customer = GetCustomer(custId)\n if cust.Category = 1 then 'please ignore magic number, real code uses enums\n return 0.9\n end if\n return 1\nEnd Function\n\n'in Data Access Layer class\nFunction GetCustomer(custId as Integer) as Customer\n Dim cust as Customer = New Customer 'all fields/properties to default values\n Dim strSQL as String = \"select * from tblCustomers where ID = \" & custId\n set rec1 = GlobalDataBase.openrecordset(strSQL) ' Data access '\n if rec1.bof <> true or rec1.eof <> true then\n cust.SetPropertiesFromRecord(rec1)\n end if\n return cust\nEnd Function\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6164/" ]
227,731
<p>I need to do some large integer math. Are there any classes or structs out there that represent a 128-bit integer and implement all of the usual operators?</p> <p>BTW, I realize that <code>decimal</code> can be used to represent a 96-bit int.</p>
[ { "answer_id": 227795, "author": "Larsenal", "author_id": 337, "author_profile": "https://Stackoverflow.com/users/337", "pm_score": 7, "selected": true, "text": "var i = System.Numerics.BigInteger.Parse(\"10000000000000000000000000000000\");\n" }, { "answer_id": 228874, "author": "sbeskur", "author_id": 10446, "author_profile": "https://Stackoverflow.com/users/10446", "pm_score": 2, "selected": false, "text": "using java.math;\n\npublic static void Main(){\n BigInteger biggy = new BigInteger(....)\n\n}\n" }, { "answer_id": 5384298, "author": "Charles Burns", "author_id": 161816, "author_profile": "https://Stackoverflow.com/users/161816", "pm_score": 3, "selected": false, "text": "BigInteger" }, { "answer_id": 28258429, "author": "Rick Sladkey", "author_id": 553613, "author_profile": "https://Stackoverflow.com/users/553613", "pm_score": 6, "selected": false, "text": "BigInteger" }, { "answer_id": 73005626, "author": "phuclv", "author_id": 995714, "author_profile": "https://Stackoverflow.com/users/995714", "pm_score": 4, "selected": false, "text": "System.Int128" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4066/" ]
227,738
<p>I have a case where a 3rd party ad is bleeding through my modal window implementation. I'd like to up the z-index of the modal overlay as high as possible so the ad won't show on top of it. Is there a limit to z-index values? I'm sure if there is it varies by browser. Anyone know?</p>
[ { "answer_id": 227782, "author": "Kornel", "author_id": 27009, "author_profile": "https://Stackoverflow.com/users/27009", "pm_score": 5, "selected": true, "text": "z-index" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11577/" ]
227,743
<p>Someone told me that it's faster to concatenate strings with StringBuilder. I have changed my code but I do not see any Properties or Methods to get the final build string. </p> <p>How can I get the string?</p>
[ { "answer_id": 227744, "author": "BlackWasp", "author_id": 21862, "author_profile": "https://Stackoverflow.com/users/21862", "pm_score": 4, "selected": false, "text": "using System;\nusing System.Text;\n\npublic sealed class App \n{\n static void Main() \n {\n // Create a StringBuilder that expects to hold 50 characters.\n // Initialize the StringBuilder with \"ABC\".\n StringBuilder sb = new StringBuilder(\"ABC\", 50);\n\n // Append three characters (D, E, and F) to the end of the StringBuilder.\n sb.Append(new char[] { 'D', 'E', 'F' });\n\n // Append a format string to the end of the StringBuilder.\n sb.AppendFormat(\"GHI{0}{1}\", 'J', 'k');\n\n // Display the number of characters in the StringBuilder and its string.\n Console.WriteLine(\"{0} chars: {1}\", sb.Length, sb.ToString());\n\n // Insert a string at the beginning of the StringBuilder.\n sb.Insert(0, \"Alphabet: \");\n\n // Replace all lowercase k's with uppercase K's.\n sb.Replace('k', 'K');\n\n // Display the number of characters in the StringBuilder and its string.\n Console.WriteLine(\"{0} chars: {1}\", sb.Length, sb.ToString());\n }\n}\n\n// This code produces the following output.\n//\n// 11 chars: ABCDEFGHIJk\n// 21 chars: Alphabet: ABCDEFGHIJK\n" }, { "answer_id": 227745, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 8, "selected": true, "text": ".ToString()" }, { "answer_id": 227817, "author": "Bill K", "author_id": 12943, "author_profile": "https://Stackoverflow.com/users/12943", "pm_score": 2, "selected": false, "text": "String a = \"abc\" + \"def\" + \"ghi\";\n" }, { "answer_id": 227831, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 4, "selected": false, "text": "StringBuilder" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14441/" ]
227,762
<p>I am working on an embedded systems project and have run into an issue of the compiler being programatically embedded in the Paradigm C++ IDE. I would like to be able to automate building.</p> <p>The processor is the AMD186ES. I am not working with the OS - just baremetal stuff. I need to generate real-mode 16-bit 8086 machine code from C++. </p> <p>My googling indicates that G++ can build such code. </p> <p>My questions are: </p> <p>Can g++ be configured to build this machine code?</p> <p>Are there other C++ compilers that can do it as well?</p>
[ { "answer_id": 12829806, "author": "Hawken", "author_id": 800270, "author_profile": "https://Stackoverflow.com/users/800270", "pm_score": 4, "selected": true, "text": "as" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26227/" ]
227,775
<p>Let's say I have a class in my web app called class "Foo". It has an initialise() method that is called when the bean is created using Spring. The initialise() method then tries to load an external service and assign it to a field. If the service could not be contacted, the field will be set to null. </p> <pre><code>private Service service; public void initialise() { // load external service // set field to the loaded service if contacted // set to field to null if service could not be contacted } </code></pre> <p>When someone calls the method get() on the class "Foo" the service will be invoked if it was started in the initialise() method. If the field for the service is null, I want to try and load the external service.</p> <pre><code>public String get() { if (service == null) { // try and load the service again } // perform operation on the service is service is not null } </code></pre> <p>Is it possible that I may have sync issues if I would do something like this?</p>
[ { "answer_id": 227812, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 0, "selected": false, "text": "public class FooServlet extends HttpServlet {\n\n private MyBean myBean;\n\n public void init() {\n myBean = (MyBean) WebApplicationContextUtils.\n getRequiredWebApplicationContext(getServletContext()).getBean(\"myBean\");\n }\n\n public void doGet(HttpRequest request, HttpResponse response) {\n String string = myBean.get();\n ....\n }\n\n}\n\nclass MyBean {\n public String get() {\n if (service == null) {\n // try and load the service again\n }\n // perform operation on the service is service is not null\n }\n}\n" }, { "answer_id": 227964, "author": "Dov Wasserman", "author_id": 26010, "author_profile": "https://Stackoverflow.com/users/26010", "pm_score": 2, "selected": true, "text": "private Service service;\n\npublic synchronized void initialise() {\n if (service == null) {\n // load external service\n // set field to the loaded service if contacted\n }\n}\n\npublic String get() {\n if (service == null) { \n initialise(); // try and load the service again\n }\n // perform operation on the service is service is not null\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30563/" ]
227,790
<p>So I'm teaching myself Python, and I'm having an issue with lists. I want to pass my function a list and pop items off it while retaining the original list. How do I make python "instance" the passed list rather that passing a pointer to the original one?</p> <p>Example:</p> <pre><code>def burninate(b): c = [] for i in range(3): c.append(b.pop()) return c a = range(6) d = burninate(a) print a, d </code></pre> <p>Output: [0, 1, 2] [5, 4, 3]<br> Desired output: [0, 1, 2, 3, 4, 5] [5, 4, 3]</p> <p>Thanks!</p>
[ { "answer_id": 227802, "author": "mhawke", "author_id": 21945, "author_profile": "https://Stackoverflow.com/users/21945", "pm_score": 3, "selected": false, "text": "burninate()" }, { "answer_id": 227810, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "d = burninate(list(a))\n" }, { "answer_id": 227850, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 2, "selected": false, "text": "def burninate(b):\n c = []\n for i in range(1, 4):\n c.append(b[-i])\n return c\n" }, { "answer_id": 227854, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 3, "selected": false, "text": "import copy" }, { "answer_id": 227855, "author": "John Fouhy", "author_id": 15154, "author_profile": "https://Stackoverflow.com/users/15154", "pm_score": 5, "selected": true, "text": "def burninate(b):\n c = []\n b = list(b)\n for i in range(3):\n c.append(b.pop())\n return c\n" }, { "answer_id": 227875, "author": "Federico A. Ramponi", "author_id": 18770, "author_profile": "https://Stackoverflow.com/users/18770", "pm_score": 0, "selected": false, "text": "burninate = lambda x: x[:-4:-1]" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5625/" ]
227,797
<p>In my cross-platform architecture, I would like to act on a context menu click (right button click) during a mouse click event. In Cocoa, can you detect that the user either Ctrl-Clicked or double-tapped on touchpad (right-click equivalent) DURING the mouseDown event? I am aware of NSView's menuForEvent but do not wish to handle it here.</p>
[ { "answer_id": 227816, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 5, "selected": true, "text": "-[NSResponder rightMouseDown:]" }, { "answer_id": 237156, "author": "Wil Shipley", "author_id": 30602, "author_profile": "https://Stackoverflow.com/users/30602", "pm_score": 4, "selected": false, "text": "- (void)mouseDown:(NSEvent *)event;\n{\n if (event.modifierFlags & NSControlKeyMask)\n return [self rightMouseDown:event];\n\n...\n}\n" }, { "answer_id": 36769932, "author": "Klaas", "author_id": 292145, "author_profile": "https://Stackoverflow.com/users/292145", "pm_score": 1, "selected": false, "text": "override func mouseDown(theEvent: NSEvent) {\n if theEvent.modifierFlags.contains(.ControlKeyMask) {\n return rightMouseDown(theEvent)\n }\n\n super.mouseDown(theEvent)\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8761/" ]
227,807
<p>I have a Rails app that sets a cookie and does a redirect to another server once the user is logged in. However, the cookie that the Rails app sets isn't seen by the server for some reason. I've tried setting http_only to false but I still can't even see the cookie unless the domain is the same as my Rails app. Here's the code I'm using to set the cookie:</p> <pre><code>cookies[:dev_appserver_login] = { :value =&gt; "#{email}:#{nick}:#{admin}:#{hsh}", :domain =&gt; "webserver-to-redirect-to", :expires =&gt; 30.days.from_now } redirect_to session[:dest_url] </code></pre> <p>If I manually create a cookie with the <a href="https://addons.mozilla.org/en-US/firefox/addon/60" rel="nofollow noreferrer">Web Developer extension</a> in Firefox it works fine, but not when Rails does it. Any ideas?</p>
[ { "answer_id": 24663350, "author": "Elocution Safari", "author_id": 43670, "author_profile": "https://Stackoverflow.com/users/43670", "pm_score": 0, "selected": false, "text": "127.0.0.1 app1.localdev.com, app2.localdev.com" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/422/" ]
227,820
<p>I was just writing some quick code and noticed this complier error </p> <blockquote> <p>Using the iteration variable in a lambda expression may have unexpected results.<br> Instead, create a local variable within the loop and assign it the value of the iteration variable.</p> </blockquote> <p>I know what it means and I can easily fix it, not a big deal.<br> But I was wondering why it is a bad idea to use a iteration variable in a lambda?<br> What problems can I cause later on?</p>
[ { "answer_id": 227833, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 7, "selected": true, "text": "List<Action> actions = new List<Action>();\n\nfor (int i = 0; i < 10; i++)\n{\n actions.Add(() => Console.WriteLine(i));\n}\n\nforeach (Action action in actions)\n{\n action();\n}\n" }, { "answer_id": 55317222, "author": "jrh", "author_id": 4975230, "author_profile": "https://Stackoverflow.com/users/4975230", "pm_score": 2, "selected": false, "text": "Delegate" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6335/" ]
227,856
<p>It seems that the decision to make your objects fully cognizant of their roles within the system, and still avoid having too many dependencies within the domain model on the database, and service layers?</p> <p>For example: Say that I've got an entity with a revision history, and several "lookup tables" that the data references, your entity object should have methods to get the details from some of the lookup tables, whether by providing access to the lookup table rows, or by delegating methods down to them, but in order to do so it depends on the database layer to read the data from those rows. Also, when the entity is saved, It needs to know not only how to save itself, but also to save entries into the revision history. Is it necessary to pass references to dozens of different data layer objects and service objects to the model object? This seems like it makes the logic far more complex to understand than just passing back and forth thin models to service layer objects, but I've heard many "wise men" recommending this sort of structure.</p>
[ { "answer_id": 228001, "author": "moffdub", "author_id": 10759, "author_profile": "https://Stackoverflow.com/users/10759", "pm_score": 5, "selected": true, "text": "entity.saveIn(repository);\n" }, { "answer_id": 1890255, "author": "Steve", "author_id": 229889, "author_profile": "https://Stackoverflow.com/users/229889", "pm_score": 1, "selected": false, "text": "Service(IRepository) injected\n\nSave(){\n\nDomainEntity.DoSomething();\nRepository.Save(DomainEntity);\n\n}\n\n'Do Something' is the business logic of the domain entity.\n\n**This would be anemic**:\nService(IRepository) injected\n\nSave(){\n\nif(DomainEntity.IsSomething)\n DomainEntity.SetItProperty();\nRepository.Save(DomainEntity);\n\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21973/" ]
227,886
<p>How do I determine the dependencies of a .NET application? Does <a href="http://www.dependencywalker.com/" rel="noreferrer">Dependency Walker</a> work with managed apps? I've downloaded the latest and tried profiling the app, but it just exits without much of an explanation. If it doesn't work with .NET, then is there some other tool that would help me debug a run-time DLL loading issue?</p>
[ { "answer_id": 308256, "author": "Patrick from NDepend team", "author_id": 27194, "author_profile": "https://Stackoverflow.com/users/27194", "pm_score": 4, "selected": false, "text": "from m in Methods \nlet depth = m.DepthOfIsUsing(\"NHibernate.NHibernateUtil.Entity(Type)\") \nwhere depth >= 0 && m.IsUsing(\"System.IDisposable\")\norderby depth\nselect new { m, depth }\n" }, { "answer_id": 28923399, "author": "Alexander O'Mara", "author_id": 3155639, "author_profile": "https://Stackoverflow.com/users/3155639", "pm_score": 3, "selected": false, "text": "monodis" }, { "answer_id": 33869995, "author": "Colonel Panic", "author_id": 284795, "author_profile": "https://Stackoverflow.com/users/284795", "pm_score": 5, "selected": false, "text": "Assembly.GetReferencedAssemblies()" }, { "answer_id": 36404201, "author": "Alexander van Trijffel", "author_id": 689718, "author_profile": "https://Stackoverflow.com/users/689718", "pm_score": 6, "selected": false, "text": ".dll" }, { "answer_id": 40306858, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "--staticlink:\"Namespace.Assembly\"" }, { "answer_id": 69633773, "author": "Jonathan E. Landrum", "author_id": 2386514, "author_profile": "https://Stackoverflow.com/users/2386514", "pm_score": 0, "selected": false, "text": "dotnet" }, { "answer_id": 70329571, "author": "Kevin North", "author_id": 831520, "author_profile": "https://Stackoverflow.com/users/831520", "pm_score": 0, "selected": false, "text": "ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=484f84ea1d6cf4da\nmscorlib, Culture=neutral, PublicKeyToken=b77a5c561934e089\nmscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\nSystem.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\nSystem.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3114/" ]
227,897
<p>I just finished a test as part of a job interview, and one question stumped me, even using Google for reference. I'd like to see what the StackOverflow crew can do with it:</p> <blockquote> <p>The <code>memset_16aligned</code> function requires a 16-byte aligned pointer passed to it, or it will crash.</p> <p>a) How would you allocate 1024 bytes of memory, and align it to a 16 byte boundary?<br /> b) Free the memory after the <code>memset_16aligned</code> has executed.</p> </blockquote> <pre><code>{ void *mem; void *ptr; // answer a) here memset_16aligned(ptr, 0, 1024); // answer b) here } </code></pre>
[ { "answer_id": 227900, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 10, "selected": true, "text": "{\n void *mem = malloc(1024+16);\n void *ptr = ((char *)mem+16) & ~ 0x0F;\n memset_16aligned(ptr, 0, 1024);\n free(mem);\n}\n" }, { "answer_id": 227922, "author": "florin", "author_id": 18308, "author_profile": "https://Stackoverflow.com/users/18308", "pm_score": 5, "selected": false, "text": "posix_memalign()" }, { "answer_id": 228015, "author": "Steve Jessop", "author_id": 13005, "author_profile": "https://Stackoverflow.com/users/13005", "pm_score": 6, "selected": false, "text": "/* allocate a buffer with room to add 0-15 bytes to ensure 16-alignment */\nvoid *mem = malloc(1024+15);\nASSERT(mem); // some kind of error-handling code\n/* round up to multiple of 16: add 15 and then round down by masking */\nvoid *ptr = ((char*)mem+15) & ~ (size_t)0x0F;\n" }, { "answer_id": 228079, "author": "An̲̳̳drew", "author_id": 17035, "author_profile": "https://Stackoverflow.com/users/17035", "pm_score": 4, "selected": false, "text": "uintptr_t" }, { "answer_id": 1602046, "author": "Adisak", "author_id": 14904, "author_profile": "https://Stackoverflow.com/users/14904", "pm_score": 4, "selected": false, "text": "MEMORY_ALLOCATOR_NATIVE_ALIGNMENT" }, { "answer_id": 6696782, "author": "Lutorm", "author_id": 307175, "author_profile": "https://Stackoverflow.com/users/307175", "pm_score": 3, "selected": false, "text": "uintptr_t" }, { "answer_id": 12260015, "author": "Ramana", "author_id": 1645623, "author_profile": "https://Stackoverflow.com/users/1645623", "pm_score": -1, "selected": false, "text": "long add; \nmem = (void*)malloc(1024 +15);\nadd = (long)mem;\nadd = add - (add % 16);//align to 16 byte boundary\nptr = (whatever*)(add);\n" }, { "answer_id": 15622073, "author": "resultsway", "author_id": 551514, "author_profile": "https://Stackoverflow.com/users/551514", "pm_score": 0, "selected": false, "text": "main(){\nvoid *mem1 = malloc(1024+16);\nvoid *mem = ((char*)mem1)+1; // force misalign ( my computer always aligns)\nprintf ( \" ptr = %p \\n \", mem );\nvoid *ptr = ((long)mem+16) & ~ 0x0F;\nprintf ( \" aligned ptr = %p \\n \", ptr );\n\nprintf (\" ptr after adding diff mod %p (same as above ) \", (long)mem1 + (16 -((long)mem1%16)) );\n\n\nfree(mem1);\n}\n" }, { "answer_id": 20194221, "author": "Chris", "author_id": 2891833, "author_profile": "https://Stackoverflow.com/users/2891833", "pm_score": 1, "selected": false, "text": "char* p = malloc (size + 15);\np += (- (unsigned int) p) % 16;\n" }, { "answer_id": 20195009, "author": "Deepthought", "author_id": 996882, "author_profile": "https://Stackoverflow.com/users/996882", "pm_score": 0, "selected": false, "text": " void *mem; \n void *ptr;\ntry:\n mem = malloc(1024); \n if (mem % 16 != 0) { \n free(mem); \n goto try;\n } \n ptr = mem; \n memset_16aligned(ptr, 0, 1024);\n" }, { "answer_id": 22407273, "author": "user3415603", "author_id": 3415603, "author_profile": "https://Stackoverflow.com/users/3415603", "pm_score": 0, "selected": false, "text": "aligned_alloc (16, size)" }, { "answer_id": 24052152, "author": "Ian Ollmann", "author_id": 3166255, "author_profile": "https://Stackoverflow.com/users/3166255", "pm_score": 3, "selected": false, "text": " void my_func( void )\n {\n uint8_t array[1024] __attribute__ ((aligned(16)));\n ...\n }\n" }, { "answer_id": 37149280, "author": "J-a-n-u-s", "author_id": 5437832, "author_profile": "https://Stackoverflow.com/users/5437832", "pm_score": 2, "selected": false, "text": "__attribute__((packed))" }, { "answer_id": 58736672, "author": "stackguy", "author_id": 3624305, "author_profile": "https://Stackoverflow.com/users/3624305", "pm_score": -1, "selected": false, "text": "size =1024;\nalignment = 16;\naligned_size = size +(alignment -(size % alignment));\nmem = malloc(aligned_size);\nmemset_16aligned(mem, 0, 1024);\nfree(mem);\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/63/" ]
227,907
<p>I am trying to debug an ActiveResource call that is not working.</p> <p>What's the best way to view the HTTP response to the request ActiveResource is making?</p>
[ { "answer_id": 236378, "author": "Ian Terrell", "author_id": 9269, "author_profile": "https://Stackoverflow.com/users/9269", "pm_score": 3, "selected": true, "text": "puts response.inspect" }, { "answer_id": 237776, "author": "derfred", "author_id": 10286, "author_profile": "https://Stackoverflow.com/users/10286", "pm_score": 1, "selected": false, "text": "Completed in 0.26889 (3 reqs/sec) | Rendering: 0.00036 (0%) | DB: 0.02424 (9%) | 200 OK [http://localhost/notifications/summary.xml?person_id=25738]\n" }, { "answer_id": 7175431, "author": "Kai Wren", "author_id": 274533, "author_profile": "https://Stackoverflow.com/users/274533", "pm_score": 4, "selected": false, "text": "Net::HTTP.enable_debug!" }, { "answer_id": 8040859, "author": "reto", "author_id": 102200, "author_profile": "https://Stackoverflow.com/users/102200", "pm_score": 2, "selected": false, "text": "config/initializers/" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227907", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17965/" ]
227,909
<p>I could use some advice on tracking down the cause of memory leaks in C#. I understand what is a memory leak and I get why they occur in C# but I'm wondering what tools/strategies have you used in the past to resolve them?</p> <p>I am using .NET Memory Profiler and I've found that one of my huge main objects is staying in memory after I close the window it manages but I'm not sure what to do to severe all links to it.</p> <p>If I'm not being clear enough just post an answer with a question and I'll edit my question in response. Thanks!</p>
[ { "answer_id": 227966, "author": "Daniel Earwicker", "author_id": 27423, "author_profile": "https://Stackoverflow.com/users/27423", "pm_score": 5, "selected": false, "text": ".load C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\sos.dll\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9401/" ]
227,924
<p>I can't see the 'Collection of Repositories" page after adding authentication and access rules to svn. 'guest' can navigate to mydomain.com/svn/public and admin can see both svn/public and svn/private, but none of the users can see /svn. </p> <p>Is it possible to have 'guest' access mydomain.com/svn and only see a /public link?</p> <p>Here's what I have setup...</p> <p><strong>subversion.conf:</strong></p> <pre><code>&lt;location /svn&gt; DAV svn SVNParentPath /home/subversion SVNListParentPath on AuthzSVNAccessFile /etc/svn-access-file AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/svn-auth-file Require valid-user &lt;/Location&gt; </code></pre> <p><strong>svn-access-file:</strong></p> <pre><code>[public:/] guest = r @admin = rw [private:/] @admin = rw [groups] admin = karl.r </code></pre> <p>Thanks.</p>
[ { "answer_id": 229104, "author": "remmelt", "author_id": 30709, "author_profile": "https://Stackoverflow.com/users/30709", "pm_score": 2, "selected": true, "text": "<Location /websvn>\n AuthType Basic\n AuthName \"Company WebSVN\"\n AuthUserFile /home/svn/dav_svn.passwd\n Require group developers\n AuthGroupFile /home/svn/dav_svn_groups\n</Location>\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22934/" ]
227,928
<p>I'm building an open source project that uses python and c++ in Windows. I came to the following error message:</p> <pre><code> ImportError: No module named win32con </code></pre> <p>The same happened in a "prebuilt" code that it's working ( except in my computer :P ) </p> <p>I think this is kind of "popular" module in python because I've saw several messages in other forums but none that could help me.</p> <p>I have Python2.6, should I have that module already installed? Is that something of VC++?</p> <p>Thank you for the help.</p> <p>I got this url <a href="http://sourceforge.net/projects/pywin32/" rel="noreferrer">http://sourceforge.net/projects/pywin32/</a> but I'm not sure what to do with the executable :S</p>
[ { "answer_id": 39329641, "author": "anatoly techtonik", "author_id": 239247, "author_profile": "https://Stackoverflow.com/users/239247", "pm_score": 6, "selected": false, "text": "pip install pypiwin32\n" }, { "answer_id": 61448846, "author": "Thomas Ducrot", "author_id": 8047453, "author_profile": "https://Stackoverflow.com/users/8047453", "pm_score": 3, "selected": false, "text": "import win32.lib.win32con as win32con\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20654/" ]
227,935
<p>In response to a rightMouse event I want to call a function that displays a context menu, runs it, and responds to the selected menu item. In Windows I can use TrackPopupMenu with the TPM_RETURNCMD flag.</p> <p>What is the easiest way to implement this in Cocoa? It seems NSMenu:popUpContextMenu wants to post an event to the specified NSView. Must I create a dummy view and wait for the event before returning? If so, how do I "wait" or flush events given I am not returning to my main ?</p>
[ { "answer_id": 227975, "author": "Ben Gottlieb", "author_id": 6694, "author_profile": "https://Stackoverflow.com/users/6694", "pm_score": 2, "selected": false, "text": "[NSView nextEventMatchingMask:]" }, { "answer_id": 228492, "author": "Peter Hosey", "author_id": 30461, "author_profile": "https://Stackoverflow.com/users/30461", "pm_score": 0, "selected": false, "text": "[[NSRunLoop currentRunLoop] runMode:NSEventTrackingRunLoopMode untilDate:[NSDate distantFuture]]" }, { "answer_id": 230808, "author": "AlanKley", "author_id": 8761, "author_profile": "https://Stackoverflow.com/users/8761", "pm_score": 2, "selected": true, "text": "// Dummy View class used to receive Menu Events\n\n@interface DVFBaseView : NSView\n{\n NSMenuItem* nsMenuItem;\n}\n- (void) OnMenuSelection:(id)sender;\n- (NSMenuItem*)MenuItem;\n@end\n\n@implementation DVFBaseView\n- (NSMenuItem*)MenuItem\n{\n return nsMenuItem;\n}\n\n- (void)OnMenuSelection:(id)sender\n{\n nsMenuItem = sender;\n}\n\n@end\n\n// Calling Code (in response to rightMouseDown event in my main NSView\n\nvoid HandleRButtonDown (NSPoint pt)\n{\n NSRect graphicsRect; // contains an origin, width, height\n graphicsRect = NSMakeRect(200, 200, 50, 100);\n\n //-----------------------------\n // Create Menu and Dummy View\n //-----------------------------\n\n nsMenu = [[[NSMenu alloc] initWithTitle:@\"Contextual Menu\"] autorelease];\n nsView = [[[DVFBaseView alloc] initWithFrame:graphicsRect] autorelease];\n\n NSMenuItem* item = [nsMenu addItemWithTitle:@\"Menu Item# 1\" action:@selector(OnMenuSelection:) keyEquivalent:@\"\"];\n\n [item setTag:ID_FIRST];\n\n item = [nsMenu addItemWithTitle:@\"Menu Item #2\" action:@selector(OnMenuSelection:) keyEquivalent:@\"\"];\n\n [item setTag:ID_SECOND];\n //---------------------------------------------------------------------------------------------\n// Providing a valid windowNumber is key in getting the Menu to display in the proper location\n//---------------------------------------------------------------------------------------------\n\n int windowNumber = [(NSWindow*)myWindow windowNumber];\n NSRect frame = [(NSWindow*)myWindow frame];\n NSPoint wp = {pt.x, frame.size.height - pt.y}; // Origin in lower left\n\n NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined\n location:wp\n modifierFlags:NSApplicationDefined \n timestamp: (NSTimeInterval) 0\n windowNumber: windowNumber\n context: [NSGraphicsContext currentContext]\n subtype:0\n data1: 0\n data2: 0]; \n\n [NSMenu popUpContextMenu:nsMenu withEvent:event forView:nsView]; \n NSMenuItem* MenuItem = [nsView MenuItem];\n\n switch ([MenuItem tag])\n {\n case ID_FIRST: HandleFirstCommand(); break;\n case ID_SECOND: HandleSecondCommand(); break;\n }\n }\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8761/" ]
227,939
<p>We're using HAProxy as a load balancer at the moment, and it regularly makes requests to the downstream boxes to make sure they're alive using an OPTIONS request:</p> <blockquote> <p>OPTIONS /index.html HTTP/1.0</p> </blockquote> <p>I'm working with getting nginx set up as a reverse proxy with caching (using ncache). For some reason, nginx is returning a 405 when an OPTIONS request comes in:</p> <blockquote> <p>192.168.1.10 - - [22/Oct/2008:16:36:21 -0700] "OPTIONS /index.html HTTP/1.0" 405 325 "-" "-" 192.168.1.10</p> </blockquote> <p>When hitting the downstream webserver directly, I get a proper 200 response. My question is: how to you make nginx pass that response along to HAProxy, or, how can I set the response in the nginx.conf?</p>
[ { "answer_id": 4662858, "author": "Mark Rose", "author_id": 438631, "author_profile": "https://Stackoverflow.com/users/438631", "pm_score": 2, "selected": false, "text": "httpchk GET http://example.com/check.php\n" }, { "answer_id": 9197143, "author": "rogeriopvl", "author_id": 28388, "author_profile": "https://Stackoverflow.com/users/28388", "pm_score": 6, "selected": false, "text": "error_page 405 =200 @405;\nlocation @405 {\n root /;\n proxy_pass http://yourproxy:8080;\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227939", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30575/" ]
227,950
<p>I need to compare 2 strings as equal such as these:</p> <blockquote> <p>Lubeck == Lübeck</p> </blockquote> <p>In JavaScript.</p> <p>Why? Well, I have an auto-completion field that's going out to a Java service using Lucene, where place names are stored naturally (as Lübeck), but also indexed as normalized text, </p> <pre><code>import sun.text.Normalizer; oDoc.setNameLC = Normalizer.normalize(oLocName, Normalizer.DECOMP, 0) .toLowerCase().replaceAll("[^\\p{ASCII}]",""); </code></pre> <p>This way some-one who doesn't know to type "Mèxico" can type "mexico" and get a match which returns "Mèxico" (among a lot of other possible hits, like "Café Mèxico, Dubai, UAE").</p> <p>Now the thing is I don't have the ability to change the service to do any highlighting on the server side, therefore I am highlighting on the client JavaScript side with something like:</p> <pre><code>return result.replace( input.replace(/[aeiou]/g,"."), "&lt;b&gt;$1&lt;/b&gt;"); </code></pre> <p>It's a little more fancy because I am escaping special regex characters in the input. This is fine for simple one word matches at the beginning of a hit, but it really breaks down if you suddenly wish to support multi-word matches like "london cafe":</p> <pre><code>input = input.strip().toLowerCase(); //fyi prototype's strip is like trim re = new RegEx(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;"); </code></pre> <p>This doesn't work for say "london ca" (was typing london cafe), because it would mark "Jack London Cabin, Dawson City, Canada" as: <code>"Ja&lt;b&gt;ck&lt;/b&gt; &lt;b&gt;London&lt;/b&gt; &lt;b&gt;ca&lt;/b&gt;bin, Dawson &lt;b&gt;Ci&lt;/b&gt;ty, &lt;b&gt;Ca&lt;b/&gt;nada"</code> [note the "ck" and "Ci" particularly]</p> <p>Therefore I'm sort of looking for something that's not as crazy as:</p> <pre><code>input = input.strip().toLowerCase(); input = input.replace(/a/g,"[ÀàÁáÂâÃãÄäÅ寿ĀāĂ㥹]"); input = input.replace(/e/g,"[ÈèÉéÊêËëĒēĔĕĖėĘęĚě]"); // ditto for i, o, u, y, c, n, maybe also d, g, h, j, k, l, r, s, t, w, z re = new RegEx(input.replace(/\s+/g,"|"),"gi"); return result.replace(re, "&lt;b&gt;$1&lt;/b&gt;"); </code></pre> <p>Is there a compiled table I can refer to mapping a range of characters which are accented versions of an other character to that character, by which I don't mean the plain unicode chart. And if so, could I avoid using weird, possibly slow, RegEx statements?</p> <p><em>About the bounty:</em><br> Before I started a bounty there were two answers, the one pointing me to doing it in Ruby, and <a href="https://stackoverflow.com/questions/227950/programatic-accent-reduction-in-javascript-aka-text-normalization-or-unaccenting/228006#228006">the one</a> that <a href="https://stackoverflow.com/users/22364/mizardx">MizzardX</a> wrote which was a completion of the basic form I'd put in my question. Now don't get me wrong, I really appreciate working it out as completely as he did, but I just wished that there might be another way. It seems so far that everyone who's dropped by to look at the question and answer has decided that MizzardX covers it just fine, or that they have no different approach. I would be interested in a different approach, and if it simply isn't available before the bounty closes, MizzardX will win the bounty (though in a cruel twist, his edits mad it a community wiki answer, so I'm not sure if he'll get the bounty!)</p>
[ { "answer_id": 228006, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 7, "selected": true, "text": "/**\n * Creates a RegExp that matches the words in the search string.\n * Case and accent insensitive.\n */\nfunction make_pattern(search_string) {\n // escape meta characters\n search_string = search_string.replace(/([|()[{.+*?^$\\\\])/g,\"\\\\$1\");\n\n // split into words\n var words = search_string.split(/\\s+/);\n\n // sort by length\n var length_comp = function (a,b) {\n return b.length - a.length;\n };\n words.sort(length_comp);\n\n // replace characters by their compositors\n var accent_replacer = function(chr) {\n return accented[chr.toUpperCase()] || chr;\n }\n for (var i = 0; i < words.length; i++) {\n words[i] = words[i].replace(/\\S/g,accent_replacer);\n }\n\n // join as alternatives\n var regexp = words.join(\"|\");\n return new RegExp(regexp,'g');\n}\n\nvar accented = {\n 'A': '[Aa\\xaa\\xc0-\\xc5\\xe0-\\xe5\\u0100-\\u0105\\u01cd\\u01ce\\u0200-\\u0203\\u0226\\u0227\\u1d2c\\u1d43\\u1e00\\u1e01\\u1e9a\\u1ea0-\\u1ea3\\u2090\\u2100\\u2101\\u213b\\u249c\\u24b6\\u24d0\\u3371-\\u3374\\u3380-\\u3384\\u3388\\u3389\\u33a9-\\u33af\\u33c2\\u33ca\\u33df\\u33ff\\uff21\\uff41]',\n 'B': '[Bb\\u1d2e\\u1d47\\u1e02-\\u1e07\\u212c\\u249d\\u24b7\\u24d1\\u3374\\u3385-\\u3387\\u33c3\\u33c8\\u33d4\\u33dd\\uff22\\uff42]',\n 'C': '[Cc\\xc7\\xe7\\u0106-\\u010d\\u1d9c\\u2100\\u2102\\u2103\\u2105\\u2106\\u212d\\u216d\\u217d\\u249e\\u24b8\\u24d2\\u3376\\u3388\\u3389\\u339d\\u33a0\\u33a4\\u33c4-\\u33c7\\uff23\\uff43]',\n 'D': '[Dd\\u010e\\u010f\\u01c4-\\u01c6\\u01f1-\\u01f3\\u1d30\\u1d48\\u1e0a-\\u1e13\\u2145\\u2146\\u216e\\u217e\\u249f\\u24b9\\u24d3\\u32cf\\u3372\\u3377-\\u3379\\u3397\\u33ad-\\u33af\\u33c5\\u33c8\\uff24\\uff44]',\n 'E': '[Ee\\xc8-\\xcb\\xe8-\\xeb\\u0112-\\u011b\\u0204-\\u0207\\u0228\\u0229\\u1d31\\u1d49\\u1e18-\\u1e1b\\u1eb8-\\u1ebd\\u2091\\u2121\\u212f\\u2130\\u2147\\u24a0\\u24ba\\u24d4\\u3250\\u32cd\\u32ce\\uff25\\uff45]',\n 'F': '[Ff\\u1da0\\u1e1e\\u1e1f\\u2109\\u2131\\u213b\\u24a1\\u24bb\\u24d5\\u338a-\\u338c\\u3399\\ufb00-\\ufb04\\uff26\\uff46]',\n 'G': '[Gg\\u011c-\\u0123\\u01e6\\u01e7\\u01f4\\u01f5\\u1d33\\u1d4d\\u1e20\\u1e21\\u210a\\u24a2\\u24bc\\u24d6\\u32cc\\u32cd\\u3387\\u338d-\\u338f\\u3393\\u33ac\\u33c6\\u33c9\\u33d2\\u33ff\\uff27\\uff47]',\n 'H': '[Hh\\u0124\\u0125\\u021e\\u021f\\u02b0\\u1d34\\u1e22-\\u1e2b\\u1e96\\u210b-\\u210e\\u24a3\\u24bd\\u24d7\\u32cc\\u3371\\u3390-\\u3394\\u33ca\\u33cb\\u33d7\\uff28\\uff48]',\n 'I': '[Ii\\xcc-\\xcf\\xec-\\xef\\u0128-\\u0130\\u0132\\u0133\\u01cf\\u01d0\\u0208-\\u020b\\u1d35\\u1d62\\u1e2c\\u1e2d\\u1ec8-\\u1ecb\\u2071\\u2110\\u2111\\u2139\\u2148\\u2160-\\u2163\\u2165-\\u2168\\u216a\\u216b\\u2170-\\u2173\\u2175-\\u2178\\u217a\\u217b\\u24a4\\u24be\\u24d8\\u337a\\u33cc\\u33d5\\ufb01\\ufb03\\uff29\\uff49]',\n 'J': '[Jj\\u0132-\\u0135\\u01c7-\\u01cc\\u01f0\\u02b2\\u1d36\\u2149\\u24a5\\u24bf\\u24d9\\u2c7c\\uff2a\\uff4a]',\n 'K': '[Kk\\u0136\\u0137\\u01e8\\u01e9\\u1d37\\u1d4f\\u1e30-\\u1e35\\u212a\\u24a6\\u24c0\\u24da\\u3384\\u3385\\u3389\\u338f\\u3391\\u3398\\u339e\\u33a2\\u33a6\\u33aa\\u33b8\\u33be\\u33c0\\u33c6\\u33cd-\\u33cf\\uff2b\\uff4b]',\n 'L': '[Ll\\u0139-\\u0140\\u01c7-\\u01c9\\u02e1\\u1d38\\u1e36\\u1e37\\u1e3a-\\u1e3d\\u2112\\u2113\\u2121\\u216c\\u217c\\u24a7\\u24c1\\u24db\\u32cf\\u3388\\u3389\\u33d0-\\u33d3\\u33d5\\u33d6\\u33ff\\ufb02\\ufb04\\uff2c\\uff4c]',\n 'M': '[Mm\\u1d39\\u1d50\\u1e3e-\\u1e43\\u2120\\u2122\\u2133\\u216f\\u217f\\u24a8\\u24c2\\u24dc\\u3377-\\u3379\\u3383\\u3386\\u338e\\u3392\\u3396\\u3399-\\u33a8\\u33ab\\u33b3\\u33b7\\u33b9\\u33bd\\u33bf\\u33c1\\u33c2\\u33ce\\u33d0\\u33d4-\\u33d6\\u33d8\\u33d9\\u33de\\u33df\\uff2d\\uff4d]',\n 'N': '[Nn\\xd1\\xf1\\u0143-\\u0149\\u01ca-\\u01cc\\u01f8\\u01f9\\u1d3a\\u1e44-\\u1e4b\\u207f\\u2115\\u2116\\u24a9\\u24c3\\u24dd\\u3381\\u338b\\u339a\\u33b1\\u33b5\\u33bb\\u33cc\\u33d1\\uff2e\\uff4e]',\n 'O': '[Oo\\xba\\xd2-\\xd6\\xf2-\\xf6\\u014c-\\u0151\\u01a0\\u01a1\\u01d1\\u01d2\\u01ea\\u01eb\\u020c-\\u020f\\u022e\\u022f\\u1d3c\\u1d52\\u1ecc-\\u1ecf\\u2092\\u2105\\u2116\\u2134\\u24aa\\u24c4\\u24de\\u3375\\u33c7\\u33d2\\u33d6\\uff2f\\uff4f]',\n 'P': '[Pp\\u1d3e\\u1d56\\u1e54-\\u1e57\\u2119\\u24ab\\u24c5\\u24df\\u3250\\u3371\\u3376\\u3380\\u338a\\u33a9-\\u33ac\\u33b0\\u33b4\\u33ba\\u33cb\\u33d7-\\u33da\\uff30\\uff50]',\n 'Q': '[Qq\\u211a\\u24ac\\u24c6\\u24e0\\u33c3\\uff31\\uff51]',\n 'R': '[Rr\\u0154-\\u0159\\u0210-\\u0213\\u02b3\\u1d3f\\u1d63\\u1e58-\\u1e5b\\u1e5e\\u1e5f\\u20a8\\u211b-\\u211d\\u24ad\\u24c7\\u24e1\\u32cd\\u3374\\u33ad-\\u33af\\u33da\\u33db\\uff32\\uff52]',\n 'S': '[Ss\\u015a-\\u0161\\u017f\\u0218\\u0219\\u02e2\\u1e60-\\u1e63\\u20a8\\u2101\\u2120\\u24ae\\u24c8\\u24e2\\u33a7\\u33a8\\u33ae-\\u33b3\\u33db\\u33dc\\ufb06\\uff33\\uff53]',\n 'T': '[Tt\\u0162-\\u0165\\u021a\\u021b\\u1d40\\u1d57\\u1e6a-\\u1e71\\u1e97\\u2121\\u2122\\u24af\\u24c9\\u24e3\\u3250\\u32cf\\u3394\\u33cf\\ufb05\\ufb06\\uff34\\uff54]',\n 'U': '[Uu\\xd9-\\xdc\\xf9-\\xfc\\u0168-\\u0173\\u01af\\u01b0\\u01d3\\u01d4\\u0214-\\u0217\\u1d41\\u1d58\\u1d64\\u1e72-\\u1e77\\u1ee4-\\u1ee7\\u2106\\u24b0\\u24ca\\u24e4\\u3373\\u337a\\uff35\\uff55]',\n 'V': '[Vv\\u1d5b\\u1d65\\u1e7c-\\u1e7f\\u2163-\\u2167\\u2173-\\u2177\\u24b1\\u24cb\\u24e5\\u2c7d\\u32ce\\u3375\\u33b4-\\u33b9\\u33dc\\u33de\\uff36\\uff56]',\n 'W': '[Ww\\u0174\\u0175\\u02b7\\u1d42\\u1e80-\\u1e89\\u1e98\\u24b2\\u24cc\\u24e6\\u33ba-\\u33bf\\u33dd\\uff37\\uff57]',\n 'X': '[Xx\\u02e3\\u1e8a-\\u1e8d\\u2093\\u213b\\u2168-\\u216b\\u2178-\\u217b\\u24b3\\u24cd\\u24e7\\u33d3\\uff38\\uff58]',\n 'Y': '[Yy\\xdd\\xfd\\xff\\u0176-\\u0178\\u0232\\u0233\\u02b8\\u1e8e\\u1e8f\\u1e99\\u1ef2-\\u1ef9\\u24b4\\u24ce\\u24e8\\u33c9\\uff39\\uff59]',\n 'Z': '[Zz\\u0179-\\u017e\\u01f1-\\u01f3\\u1dbb\\u1e90-\\u1e95\\u2124\\u2128\\u24b5\\u24cf\\u24e9\\u3390-\\u3394\\uff3a\\uff5a]'\n};\n" }, { "answer_id": 5913376, "author": "khel", "author_id": 171964, "author_profile": "https://Stackoverflow.com/users/171964", "pm_score": 5, "selected": false, "text": "var defaultDiacriticsRemovalMap = [\n {'base':'A', 'letters':/[\\u0041\\u24B6\\uFF21\\u00C0\\u00C1\\u00C2\\u1EA6\\u1EA4\\u1EAA\\u1EA8\\u00C3\\u0100\\u0102\\u1EB0\\u1EAE\\u1EB4\\u1EB2\\u0226\\u01E0\\u00C4\\u01DE\\u1EA2\\u00C5\\u01FA\\u01CD\\u0200\\u0202\\u1EA0\\u1EAC\\u1EB6\\u1E00\\u0104\\u023A\\u2C6F]/g},\n {'base':'AA','letters':/[\\uA732]/g},\n {'base':'AE','letters':/[\\u00C6\\u01FC\\u01E2]/g},\n {'base':'AO','letters':/[\\uA734]/g},\n {'base':'AU','letters':/[\\uA736]/g},\n {'base':'AV','letters':/[\\uA738\\uA73A]/g},\n {'base':'AY','letters':/[\\uA73C]/g},\n {'base':'B', 'letters':/[\\u0042\\u24B7\\uFF22\\u1E02\\u1E04\\u1E06\\u0243\\u0182\\u0181]/g},\n {'base':'C', 'letters':/[\\u0043\\u24B8\\uFF23\\u0106\\u0108\\u010A\\u010C\\u00C7\\u1E08\\u0187\\u023B\\uA73E]/g},\n {'base':'D', 'letters':/[\\u0044\\u24B9\\uFF24\\u1E0A\\u010E\\u1E0C\\u1E10\\u1E12\\u1E0E\\u0110\\u018B\\u018A\\u0189\\uA779]/g},\n {'base':'DZ','letters':/[\\u01F1\\u01C4]/g},\n {'base':'Dz','letters':/[\\u01F2\\u01C5]/g},\n {'base':'E', 'letters':/[\\u0045\\u24BA\\uFF25\\u00C8\\u00C9\\u00CA\\u1EC0\\u1EBE\\u1EC4\\u1EC2\\u1EBC\\u0112\\u1E14\\u1E16\\u0114\\u0116\\u00CB\\u1EBA\\u011A\\u0204\\u0206\\u1EB8\\u1EC6\\u0228\\u1E1C\\u0118\\u1E18\\u1E1A\\u0190\\u018E]/g},\n {'base':'F', 'letters':/[\\u0046\\u24BB\\uFF26\\u1E1E\\u0191\\uA77B]/g},\n {'base':'G', 'letters':/[\\u0047\\u24BC\\uFF27\\u01F4\\u011C\\u1E20\\u011E\\u0120\\u01E6\\u0122\\u01E4\\u0193\\uA7A0\\uA77D\\uA77E]/g},\n {'base':'H', 'letters':/[\\u0048\\u24BD\\uFF28\\u0124\\u1E22\\u1E26\\u021E\\u1E24\\u1E28\\u1E2A\\u0126\\u2C67\\u2C75\\uA78D]/g},\n {'base':'I', 'letters':/[\\u0049\\u24BE\\uFF29\\u00CC\\u00CD\\u00CE\\u0128\\u012A\\u012C\\u0130\\u00CF\\u1E2E\\u1EC8\\u01CF\\u0208\\u020A\\u1ECA\\u012E\\u1E2C\\u0197]/g},\n {'base':'J', 'letters':/[\\u004A\\u24BF\\uFF2A\\u0134\\u0248]/g},\n {'base':'K', 'letters':/[\\u004B\\u24C0\\uFF2B\\u1E30\\u01E8\\u1E32\\u0136\\u1E34\\u0198\\u2C69\\uA740\\uA742\\uA744\\uA7A2]/g},\n {'base':'L', 'letters':/[\\u004C\\u24C1\\uFF2C\\u013F\\u0139\\u013D\\u1E36\\u1E38\\u013B\\u1E3C\\u1E3A\\u0141\\u023D\\u2C62\\u2C60\\uA748\\uA746\\uA780]/g},\n {'base':'LJ','letters':/[\\u01C7]/g},\n {'base':'Lj','letters':/[\\u01C8]/g},\n {'base':'M', 'letters':/[\\u004D\\u24C2\\uFF2D\\u1E3E\\u1E40\\u1E42\\u2C6E\\u019C]/g},\n {'base':'N', 'letters':/[\\u004E\\u24C3\\uFF2E\\u01F8\\u0143\\u00D1\\u1E44\\u0147\\u1E46\\u0145\\u1E4A\\u1E48\\u0220\\u019D\\uA790\\uA7A4]/g},\n {'base':'NJ','letters':/[\\u01CA]/g},\n {'base':'Nj','letters':/[\\u01CB]/g},\n {'base':'O', 'letters':/[\\u004F\\u24C4\\uFF2F\\u00D2\\u00D3\\u00D4\\u1ED2\\u1ED0\\u1ED6\\u1ED4\\u00D5\\u1E4C\\u022C\\u1E4E\\u014C\\u1E50\\u1E52\\u014E\\u022E\\u0230\\u00D6\\u022A\\u1ECE\\u0150\\u01D1\\u020C\\u020E\\u01A0\\u1EDC\\u1EDA\\u1EE0\\u1EDE\\u1EE2\\u1ECC\\u1ED8\\u01EA\\u01EC\\u00D8\\u01FE\\u0186\\u019F\\uA74A\\uA74C]/g},\n {'base':'OI','letters':/[\\u01A2]/g},\n {'base':'OO','letters':/[\\uA74E]/g},\n {'base':'OU','letters':/[\\u0222]/g},\n {'base':'P', 'letters':/[\\u0050\\u24C5\\uFF30\\u1E54\\u1E56\\u01A4\\u2C63\\uA750\\uA752\\uA754]/g},\n {'base':'Q', 'letters':/[\\u0051\\u24C6\\uFF31\\uA756\\uA758\\u024A]/g},\n {'base':'R', 'letters':/[\\u0052\\u24C7\\uFF32\\u0154\\u1E58\\u0158\\u0210\\u0212\\u1E5A\\u1E5C\\u0156\\u1E5E\\u024C\\u2C64\\uA75A\\uA7A6\\uA782]/g},\n {'base':'S', 'letters':/[\\u0053\\u24C8\\uFF33\\u1E9E\\u015A\\u1E64\\u015C\\u1E60\\u0160\\u1E66\\u1E62\\u1E68\\u0218\\u015E\\u2C7E\\uA7A8\\uA784]/g},\n {'base':'T', 'letters':/[\\u0054\\u24C9\\uFF34\\u1E6A\\u0164\\u1E6C\\u021A\\u0162\\u1E70\\u1E6E\\u0166\\u01AC\\u01AE\\u023E\\uA786]/g},\n {'base':'TZ','letters':/[\\uA728]/g},\n {'base':'U', 'letters':/[\\u0055\\u24CA\\uFF35\\u00D9\\u00DA\\u00DB\\u0168\\u1E78\\u016A\\u1E7A\\u016C\\u00DC\\u01DB\\u01D7\\u01D5\\u01D9\\u1EE6\\u016E\\u0170\\u01D3\\u0214\\u0216\\u01AF\\u1EEA\\u1EE8\\u1EEE\\u1EEC\\u1EF0\\u1EE4\\u1E72\\u0172\\u1E76\\u1E74\\u0244]/g},\n {'base':'V', 'letters':/[\\u0056\\u24CB\\uFF36\\u1E7C\\u1E7E\\u01B2\\uA75E\\u0245]/g},\n {'base':'VY','letters':/[\\uA760]/g},\n {'base':'W', 'letters':/[\\u0057\\u24CC\\uFF37\\u1E80\\u1E82\\u0174\\u1E86\\u1E84\\u1E88\\u2C72]/g},\n {'base':'X', 'letters':/[\\u0058\\u24CD\\uFF38\\u1E8A\\u1E8C]/g},\n {'base':'Y', 'letters':/[\\u0059\\u24CE\\uFF39\\u1EF2\\u00DD\\u0176\\u1EF8\\u0232\\u1E8E\\u0178\\u1EF6\\u1EF4\\u01B3\\u024E\\u1EFE]/g},\n {'base':'Z', 'letters':/[\\u005A\\u24CF\\uFF3A\\u0179\\u1E90\\u017B\\u017D\\u1E92\\u1E94\\u01B5\\u0224\\u2C7F\\u2C6B\\uA762]/g},\n {'base':'a', 'letters':/[\\u0061\\u24D0\\uFF41\\u1E9A\\u00E0\\u00E1\\u00E2\\u1EA7\\u1EA5\\u1EAB\\u1EA9\\u00E3\\u0101\\u0103\\u1EB1\\u1EAF\\u1EB5\\u1EB3\\u0227\\u01E1\\u00E4\\u01DF\\u1EA3\\u00E5\\u01FB\\u01CE\\u0201\\u0203\\u1EA1\\u1EAD\\u1EB7\\u1E01\\u0105\\u2C65\\u0250]/g},\n {'base':'aa','letters':/[\\uA733]/g},\n {'base':'ae','letters':/[\\u00E6\\u01FD\\u01E3]/g},\n {'base':'ao','letters':/[\\uA735]/g},\n {'base':'au','letters':/[\\uA737]/g},\n {'base':'av','letters':/[\\uA739\\uA73B]/g},\n {'base':'ay','letters':/[\\uA73D]/g},\n {'base':'b', 'letters':/[\\u0062\\u24D1\\uFF42\\u1E03\\u1E05\\u1E07\\u0180\\u0183\\u0253]/g},\n {'base':'c', 'letters':/[\\u0063\\u24D2\\uFF43\\u0107\\u0109\\u010B\\u010D\\u00E7\\u1E09\\u0188\\u023C\\uA73F\\u2184]/g},\n {'base':'d', 'letters':/[\\u0064\\u24D3\\uFF44\\u1E0B\\u010F\\u1E0D\\u1E11\\u1E13\\u1E0F\\u0111\\u018C\\u0256\\u0257\\uA77A]/g},\n {'base':'dz','letters':/[\\u01F3\\u01C6]/g},\n {'base':'e', 'letters':/[\\u0065\\u24D4\\uFF45\\u00E8\\u00E9\\u00EA\\u1EC1\\u1EBF\\u1EC5\\u1EC3\\u1EBD\\u0113\\u1E15\\u1E17\\u0115\\u0117\\u00EB\\u1EBB\\u011B\\u0205\\u0207\\u1EB9\\u1EC7\\u0229\\u1E1D\\u0119\\u1E19\\u1E1B\\u0247\\u025B\\u01DD]/g},\n {'base':'f', 'letters':/[\\u0066\\u24D5\\uFF46\\u1E1F\\u0192\\uA77C]/g},\n {'base':'g', 'letters':/[\\u0067\\u24D6\\uFF47\\u01F5\\u011D\\u1E21\\u011F\\u0121\\u01E7\\u0123\\u01E5\\u0260\\uA7A1\\u1D79\\uA77F]/g},\n {'base':'h', 'letters':/[\\u0068\\u24D7\\uFF48\\u0125\\u1E23\\u1E27\\u021F\\u1E25\\u1E29\\u1E2B\\u1E96\\u0127\\u2C68\\u2C76\\u0265]/g},\n {'base':'hv','letters':/[\\u0195]/g},\n {'base':'i', 'letters':/[\\u0069\\u24D8\\uFF49\\u00EC\\u00ED\\u00EE\\u0129\\u012B\\u012D\\u00EF\\u1E2F\\u1EC9\\u01D0\\u0209\\u020B\\u1ECB\\u012F\\u1E2D\\u0268\\u0131]/g},\n {'base':'j', 'letters':/[\\u006A\\u24D9\\uFF4A\\u0135\\u01F0\\u0249]/g},\n {'base':'k', 'letters':/[\\u006B\\u24DA\\uFF4B\\u1E31\\u01E9\\u1E33\\u0137\\u1E35\\u0199\\u2C6A\\uA741\\uA743\\uA745\\uA7A3]/g},\n {'base':'l', 'letters':/[\\u006C\\u24DB\\uFF4C\\u0140\\u013A\\u013E\\u1E37\\u1E39\\u013C\\u1E3D\\u1E3B\\u017F\\u0142\\u019A\\u026B\\u2C61\\uA749\\uA781\\uA747]/g},\n {'base':'lj','letters':/[\\u01C9]/g},\n {'base':'m', 'letters':/[\\u006D\\u24DC\\uFF4D\\u1E3F\\u1E41\\u1E43\\u0271\\u026F]/g},\n {'base':'n', 'letters':/[\\u006E\\u24DD\\uFF4E\\u01F9\\u0144\\u00F1\\u1E45\\u0148\\u1E47\\u0146\\u1E4B\\u1E49\\u019E\\u0272\\u0149\\uA791\\uA7A5]/g},\n {'base':'nj','letters':/[\\u01CC]/g},\n {'base':'o', 'letters':/[\\u006F\\u24DE\\uFF4F\\u00F2\\u00F3\\u00F4\\u1ED3\\u1ED1\\u1ED7\\u1ED5\\u00F5\\u1E4D\\u022D\\u1E4F\\u014D\\u1E51\\u1E53\\u014F\\u022F\\u0231\\u00F6\\u022B\\u1ECF\\u0151\\u01D2\\u020D\\u020F\\u01A1\\u1EDD\\u1EDB\\u1EE1\\u1EDF\\u1EE3\\u1ECD\\u1ED9\\u01EB\\u01ED\\u00F8\\u01FF\\u0254\\uA74B\\uA74D\\u0275]/g},\n {'base':'oi','letters':/[\\u01A3]/g},\n {'base':'ou','letters':/[\\u0223]/g},\n {'base':'oo','letters':/[\\uA74F]/g},\n {'base':'p','letters':/[\\u0070\\u24DF\\uFF50\\u1E55\\u1E57\\u01A5\\u1D7D\\uA751\\uA753\\uA755]/g},\n {'base':'q','letters':/[\\u0071\\u24E0\\uFF51\\u024B\\uA757\\uA759]/g},\n {'base':'r','letters':/[\\u0072\\u24E1\\uFF52\\u0155\\u1E59\\u0159\\u0211\\u0213\\u1E5B\\u1E5D\\u0157\\u1E5F\\u024D\\u027D\\uA75B\\uA7A7\\uA783]/g},\n {'base':'s','letters':/[\\u0073\\u24E2\\uFF53\\u00DF\\u015B\\u1E65\\u015D\\u1E61\\u0161\\u1E67\\u1E63\\u1E69\\u0219\\u015F\\u023F\\uA7A9\\uA785\\u1E9B]/g},\n {'base':'t','letters':/[\\u0074\\u24E3\\uFF54\\u1E6B\\u1E97\\u0165\\u1E6D\\u021B\\u0163\\u1E71\\u1E6F\\u0167\\u01AD\\u0288\\u2C66\\uA787]/g},\n {'base':'tz','letters':/[\\uA729]/g},\n {'base':'u','letters':/[\\u0075\\u24E4\\uFF55\\u00F9\\u00FA\\u00FB\\u0169\\u1E79\\u016B\\u1E7B\\u016D\\u00FC\\u01DC\\u01D8\\u01D6\\u01DA\\u1EE7\\u016F\\u0171\\u01D4\\u0215\\u0217\\u01B0\\u1EEB\\u1EE9\\u1EEF\\u1EED\\u1EF1\\u1EE5\\u1E73\\u0173\\u1E77\\u1E75\\u0289]/g},\n {'base':'v','letters':/[\\u0076\\u24E5\\uFF56\\u1E7D\\u1E7F\\u028B\\uA75F\\u028C]/g},\n {'base':'vy','letters':/[\\uA761]/g},\n {'base':'w','letters':/[\\u0077\\u24E6\\uFF57\\u1E81\\u1E83\\u0175\\u1E87\\u1E85\\u1E98\\u1E89\\u2C73]/g},\n {'base':'x','letters':/[\\u0078\\u24E7\\uFF58\\u1E8B\\u1E8D]/g},\n {'base':'y','letters':/[\\u0079\\u24E8\\uFF59\\u1EF3\\u00FD\\u0177\\u1EF9\\u0233\\u1E8F\\u00FF\\u1EF7\\u1E99\\u1EF5\\u01B4\\u024F\\u1EFF]/g},\n {'base':'z','letters':/[\\u007A\\u24E9\\uFF5A\\u017A\\u1E91\\u017C\\u017E\\u1E93\\u1E95\\u01B6\\u0225\\u0240\\u2C6C\\uA763]/g}\n];\nvar changes;\nfunction removeDiacritics (str) {\n if(!changes) {\n changes = defaultDiacriticsRemovalMap;\n }\n for(var i=0; i<changes.length; i++) {\n str = str.replace(changes[i].letters, changes[i].base);\n }\n return str;\n}\n" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459/" ]
227,973
<p>I've got an application that needs quite a bit of data (1000s of records) to do appropriate testing. The only way I've found to get a decent set of testable, sensible data is to use a <strong>subset of my production DB</strong>. I've converted this to YAML fixtures in the normal `test/fixtures' location.</p> <p>This works, but now I have a bunch of seemingly brittle tests and assertions that depend on their being a particular number of records that meet condition X...</p> <p>example</p> <pre><code>def test_children_association p = Parent.find(1) assert_equal 18, p.children.count, "Parent.children isn't providing the right records" end </code></pre> <p>This doesn't seem like a good idea to me, but <strong>I'm not sure if there is a better / accepted way</strong> to test an application that needs a large hierarchy of data.</p>
[ { "answer_id": 229188, "author": "derfred", "author_id": 10286, "author_profile": "https://Stackoverflow.com/users/10286", "pm_score": 0, "selected": false, "text": "def test_foo\n project = Project.create valid_project.merge(....)\n *do assertions here*\nend\n" }, { "answer_id": 236700, "author": "Daniel Beardsley", "author_id": 13216, "author_profile": "https://Stackoverflow.com/users/13216", "pm_score": 0, "selected": false, "text": "has_many" } ]
2008/10/22
[ "https://Stackoverflow.com/questions/227973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13216/" ]
227,977
<p>Is there a CSS style that IE7 and Firefox will obey that changes the behaviour of a TEXTAREA so that it behaves more like.... um..... more like the thing I'm typing into right now!</p>
[ { "answer_id": 227998, "author": "lewinski", "author_id": 30491, "author_profile": "https://Stackoverflow.com/users/30491", "pm_score": 0, "selected": false, "text": "<textarea wrap=\"soft\"></textarea>\n" }, { "answer_id": 228071, "author": "lock", "author_id": 24744, "author_profile": "https://Stackoverflow.com/users/24744", "pm_score": 0, "selected": false, "text": "cols" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/227977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9328/" ]
227,984
<p>I have a JSP page that will display the exact content of another web page on a different server. My understanding was that c:import from the JSTL should be able to include content from files that are not part of the current web application.</p> <p>I added c:import url="page on my server in a different application" and it works fine, but when I try to include a page from another server it fails.</p> <p>Any suggestions as to what might be wrong?</p> <p><strong>EDIT:</strong> The exact error is: "The server encountered an internal error () that prevented it from fulfilling this request.". However, requesting a page from the same server, different app works...I get the content of the page.</p>
[ { "answer_id": 228240, "author": "Vladimir Dyuzhev", "author_id": 1163802, "author_profile": "https://Stackoverflow.com/users/1163802", "pm_score": 1, "selected": false, "text": "<%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jstl/core\" %>\n...\n<c:import \n url=\"http://www.truenorthguitars.com/Clients/Richman/index.htm\" />\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/227984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27439/" ]
227,993
<p>I want to create a DTS Package to pull data from an Oracle table into a SQL2K table. How can I insert rows that are not already in the SQL2K table and update rows that already exist in the SQL2K table?</p> <p>I guess I could truncate and repopulate the entire table or create a temporary table and then do updates/inserts from the temp table into the destination table.</p> <p>Is there any easier way using DTS?</p> <p>Thanks,</p> <p>Rokal</p>
[ { "answer_id": 232976, "author": "Timothy Khouri", "author_id": 11917, "author_profile": "https://Stackoverflow.com/users/11917", "pm_score": 0, "selected": false, "text": "DELETE FROM dbo.WhateverTable \nWHERE WhateverTableID IN (SELECT WhateverTableID FROM MySource)\n" }, { "answer_id": 2085473, "author": "P2theK", "author_id": 253126, "author_profile": "https://Stackoverflow.com/users/253126", "pm_score": 0, "selected": false, "text": "DELETE FROM dbo.WhateverTable WHERE WhateverTableID IN (SELECT WhateverTableID FROM MySource)\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/227993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24358/" ]
227,994
<p>We have the following simple Stored Procedure that runs as an overnight SQL server agent job. Usually it runs in 20 minutes, but recently the MatchEvent and MatchResult tables have grown to over 9 million rows each. This has resulted in the store procedure taking over 2 hours to run, with all 8GB of memory on our SQL box being used up. This renders the database unavailable to the regular queries that are trying to access it.</p> <p>I assume the problem is that temp table is too large and is causing the memory and database unavailablity issues.</p> <p>How can I rewrite the stored procedure to make it more efficient and less memory intensive?</p> <p>Note: I have edited the SQL to indicate that there is come condition affecting the initial SELECT statement. I had previously left this out for simplicity. Also, when the query runs CPU usage is at 1-2%, but memoery, as previously stated, is maxed out</p> <p><pre><code> CREATE TABLE #tempMatchResult ( matchId VARCHAR(50) )</p> <p>INSERT INTO #tempMatchResult SELECT MatchId FROM MatchResult WHERE SOME_CONDITION</p> <p>DELETE FROM MatchEvent WHERE<br> MatchId IN (SELECT MatchId FROM #tempMatchResult)</p> <p>DELETE FROM MatchResult WHERE MatchId In (SELECT MatchId FROM #tempMatchResult)</p> <p>DROP TABLE #tempMatchResult </pre></code></p>
[ { "answer_id": 228003, "author": "shahkalpesh", "author_id": 23574, "author_profile": "https://Stackoverflow.com/users/23574", "pm_score": 0, "selected": false, "text": "\nDELETE FROM MatchEvent WHERE\nMatchId IN (SELECT MatchId FROM MatchResult)\n\n\nDELETE FROM MatchResult\n-- OR Truncate can help here, if all the records are to be deleted anyways.\n" }, { "answer_id": 228052, "author": "Anders Eurenius", "author_id": 1421, "author_profile": "https://Stackoverflow.com/users/1421", "pm_score": 0, "selected": false, "text": "LIMIT 100" }, { "answer_id": 228204, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 3, "selected": true, "text": "CREATE TABLE #tempMatchResult (\n matchId VARCHAR(50) NOT NULL PRIMARY KEY /* NOT NULL if at all possible */\n);\n\nINSERT INTO #tempMatchResult\nSELECT DISTINCT MatchId FROM MatchResult;\n" }, { "answer_id": 228822, "author": "Sam Saffron", "author_id": 17174, "author_profile": "https://Stackoverflow.com/users/17174", "pm_score": 0, "selected": false, "text": "CREATE TABLE #tempMatchResult (\n matchId VARCHAR(50) NOT NULL PRIMARY KEY /* NOT NULL if at all possible */\n);\n\nINSERT INTO #tempMatchResult\nSELECT DISTINCT MatchId FROM MatchResult;\n\nset transaction isolation level serializable\nbegin transaction \n\ncreate table MatchEventT(columns... here)\n\ninsert into MatchEventT\nselect * from MatchEvent m\nleft join #tempMatchResult t on t.MatchId = m.MatchId \nwhere t.MatchId is null \n\n-- create all the indexes for MatchEvent\n\ndrop table MatchEvent\nexec sp_rename 'MatchEventT', 'MatchEvent'\n\n-- similar code for MatchResult\n\ncommit transaction \n\n\nDROP TABLE #tempMatchResult\n" }, { "answer_id": 229048, "author": "AJ.", "author_id": 7211, "author_profile": "https://Stackoverflow.com/users/7211", "pm_score": 0, "selected": false, "text": "DELETE MatchEvent\nFROM MatchEvent e , \n MatchResult r\nWHERE e.MatchId = r.MatchId \n" }, { "answer_id": 13495590, "author": "Philip Wade", "author_id": 1017395, "author_profile": "https://Stackoverflow.com/users/1017395", "pm_score": 0, "selected": false, "text": "DELETE FROM MatchResult WHERE\nMatchId In (SELECT MatchId FROM #tempMatchResult)\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/227994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17765/" ]
228,005
<p>I was wondering if there was an alternative to <code>itoa()</code> for converting an integer to a string because when I run it in visual Studio I get warnings, and when I try to build my program under Linux, I get a compilation error.</p>
[ { "answer_id": 228010, "author": "Leon Timmermans", "author_id": 4727, "author_profile": "https://Stackoverflow.com/users/4727", "pm_score": 6, "selected": false, "text": "#include <boost/lexical_cast.hpp>\nint main(int argc, char** argv) {\n std::string foo = boost::lexical_cast<std::string>(argc);\n}\n" }, { "answer_id": 228012, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 5, "selected": false, "text": "char str[12];\nint num = 3;\nsprintf(str, \"%d\", num); // str now contains \"3\"\n" }, { "answer_id": 228039, "author": "spoulson", "author_id": 3347, "author_profile": "https://Stackoverflow.com/users/3347", "pm_score": 9, "selected": true, "text": "std::to_string" }, { "answer_id": 228041, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 4, "selected": false, "text": "std::stringstream str;\nstr << myint;\nstd::string result;\nstr >> result;\n" }, { "answer_id": 228749, "author": "Len Holgate", "author_id": 7925, "author_profile": "https://Stackoverflow.com/users/7925", "pm_score": 1, "selected": false, "text": "stringstream" }, { "answer_id": 230663, "author": "Johann Gerell", "author_id": 6345, "author_profile": "https://Stackoverflow.com/users/6345", "pm_score": 0, "selected": false, "text": "iostream" }, { "answer_id": 900075, "author": "dcw", "author_id": 73491, "author_profile": "https://Stackoverflow.com/users/73491", "pm_score": 3, "selected": false, "text": "int i = 10;\nstd::string result;\n" }, { "answer_id": 2768637, "author": "Mark Renslow", "author_id": 332781, "author_profile": "https://Stackoverflow.com/users/332781", "pm_score": 3, "selected": false, "text": "//Mark Renslow, Globe University, Minnesota School of Business, Utah Career College\n//C++ instructor and Network Dean of Information Technology\n\n#include <cstdlib>\n#include <iostream>\n#include <string>\n#include <sstream> // string stream\n#include <direct.h>\n\nusing namespace std;\n\nstring intToString(int x)\n{\n/**************************************/\n/* This function is similar to itoa() */\n/* \"integer to alpha\", a non-standard */\n/* C language function. It takes an */\n/* integer as input and as output, */\n/* returns a C++ string. */\n/* itoa() returned a C-string (null- */\n/* terminated) */\n/* This function is not needed because*/\n/* the following template function */\n/* does it all */\n/**************************************/ \n string r;\n stringstream s;\n\n s << x;\n r = s.str();\n\n return r;\n\n}\n\ntemplate <class T>\nstring toString( T argument)\n{\n/**************************************/\n/* This template shows the power of */\n/* C++ templates. This function will */\n/* convert anything to a string! */\n/* Precondition: */\n/* operator<< is defined for type T */\n/**************************************/\n string r;\n stringstream s;\n\n s << argument;\n r = s.str();\n\n return r;\n\n}\n\nint main( )\n{\n string s;\n\n cout << \"What directory would you like me to make?\";\n\n cin >> s;\n\n try\n {\n mkdir(s.c_str());\n }\n catch (exception& e) \n {\n cerr << e.what( ) << endl;\n }\n\n chdir(s.c_str());\n\n //Using a loop and string concatenation to make several sub-directories\n for(int i = 0; i < 10; i++)\n {\n s = \"Dir_\";\n s = s + toString(i);\n mkdir(s.c_str());\n }\n system(\"PAUSE\");\n return EXIT_SUCCESS;\n}\n" }, { "answer_id": 6494263, "author": "Kendra", "author_id": 817552, "author_profile": "https://Stackoverflow.com/users/817552", "pm_score": 2, "selected": false, "text": "int number = 123;\n\nstringstream = s;\n\ns << number;\n\ncout << ss.str() << endl;\n" }, { "answer_id": 7223104, "author": "jm1234567890", "author_id": 283271, "author_profile": "https://Stackoverflow.com/users/283271", "pm_score": 3, "selected": false, "text": "template <typename T> string toStr(T tmp)\n{\n ostringstream out;\n out << tmp;\n return out.str();\n}\n\n\ntemplate <typename T> T strTo(string tmp)\n{\n T output;\n istringstream in(tmp);\n in >> output;\n return output;\n}\n" }, { "answer_id": 10642026, "author": "Vasaka", "author_id": 672985, "author_profile": "https://Stackoverflow.com/users/672985", "pm_score": 4, "selected": false, "text": "std::to_string" }, { "answer_id": 13203143, "author": "Tag318", "author_id": 1795447, "author_profile": "https://Stackoverflow.com/users/1795447", "pm_score": 4, "selected": false, "text": "iota" }, { "answer_id": 23371483, "author": "vitaut", "author_id": 471164, "author_profile": "https://Stackoverflow.com/users/471164", "pm_score": 2, "selected": false, "text": "format_int" }, { "answer_id": 24505125, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "start = clock();\nfor (int i = LONG_MIN; i < LONG_MAX; i++) {\n if (i != atoi(_i32toa(buff, (int32_t)i))) {\n printf(\"\\nError for %i\", i);\n }\n if (!i) printf(\"\\nAt zero\");\n}\nprintf(\"\\nElapsed time was %f milliseconds\", (double)clock() - (double)(start));\n" }, { "answer_id": 24619502, "author": "Erik Aronesty", "author_id": 627042, "author_profile": "https://Stackoverflow.com/users/627042", "pm_score": 2, "selected": false, "text": "char* itoa(int value, char* result, int base);\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29326/" ]
228,025
<p>How do you insert/update a column through Linq To SQL and Linq To SQL use the default values? In particular I'm concerned with a timestamp field.</p> <p>I've tried setting that column to readonly and autogenerated, so it stopped trying to put in DateTime.MinValue, but it doesn't seem to be updating on updates.</p>
[ { "answer_id": 228080, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 3, "selected": true, "text": "public partial class YourDatabaseDataContext\n{\n partial void InsertYourTable(YourTable instance)\n {\n instance.LastUpdateTime = DateTime.Now;\n\n this.ExecuteDynamicInsert(instance);\n }\n\n partial void UpdateYourTable(YourTable instance)\n {\n instance.LastUpdateTime = DateTime.Now;\n\n this.ExecuteDynamicUpdate(instance);\n }\n" }, { "answer_id": 228093, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": false, "text": "AutoGenerated=true\nAutoSync=Always\nNullable, Primary Key, and ReadOnly = false\nSQLDataType = rowversion not null\nTimestamp = true\nUpdateCheck = never\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228025", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4050/" ]
228,036
<p>I have the following problem using template instantiation [*]. </p> <p>file <strong>foo.h</strong></p> <pre><code>class Foo { public: template &lt;typename F&gt; void func(F f) private: int member_; }; </code></pre> <p>file <strong>foo.cc</strong></p> <pre><code>template &lt;typename F&gt; Foo::func(F f) { f(member_); } </code></pre> <p>file <strong>caller.cc</strong></p> <pre><code>Foo::func(boost::bind(&amp;Bar::bar_func, bar_instance, _1)); </code></pre> <p>While this compiles fine, the linker complains about an undefined symbol:</p> <p><code>void Foo::func&lt;boost::_bi::bind_t...&gt;</code></p> <p>How can I instantiate the <em>function</em> <code>Foo::func</code>? Since it takes a function as argument, I am little bit confused. I tried to add an instantiation function in <strong>foo.cc</strong>, as I am used to with regular <em>non-function</em> types:</p> <pre><code>instantiate() { template&lt;&gt; void Foo::func&lt;boost::function&lt;void(int)&gt; &gt;(boost::function&lt;void(int)&gt;); } </code></pre> <p>Obviously, this does not work. I would appreciate if someone can point me in the right direction.</p> <p>Thanks!</p> <p>[*] Yes, I read the parashift FAQ lite.</p>
[ { "answer_id": 228370, "author": "Head Geek", "author_id": 12193, "author_profile": "https://Stackoverflow.com/users/12193", "pm_score": 1, "selected": false, "text": "#include" }, { "answer_id": 228372, "author": "SCFrench", "author_id": 4928, "author_profile": "https://Stackoverflow.com/users/4928", "pm_score": 0, "selected": false, "text": "boost::_bi::bind_t..." }, { "answer_id": 228581, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 2, "selected": false, "text": "#include <iostream>\nclass Foo\n{\npublic:\n Foo(): member_(15){}\n\n\n // Note No definition of this in a header file.\n // It is defined in plop.cpp and a single instantiation forced\n // Without actually using it.\n template <typename F>\n void func(F f);\n\nprivate:\n int member_;\n};\n\n\nstruct Bar\n{\n void bar_func(int val) { std::cout << val << \"\\n\"; }\n};\n\nstruct Tar\n{\n void tar_func(int val) { std::cout << \"This should not print because of specialisation of func\\n\";}\n};\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1170277/" ]
228,038
<p>I've just had to write a string reverse function in C# 2.0 (i.e. LINQ not available) and came up with this:</p> <pre><code>public string Reverse(string text) { char[] cArray = text.ToCharArray(); string reverse = String.Empty; for (int i = cArray.Length - 1; i &gt; -1; i--) { reverse += cArray[i]; } return reverse; } </code></pre> <p>Personally I'm not crazy about the function and am convinced that there's a better way to do it. Is there?</p>
[ { "answer_id": 228055, "author": "Mike Thompson", "author_id": 2754, "author_profile": "https://Stackoverflow.com/users/2754", "pm_score": 4, "selected": false, "text": "string s = \"olleh\";\ns.Reverse();\n" }, { "answer_id": 228056, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 4, "selected": false, "text": "ToCharArray" }, { "answer_id": 228060, "author": "PeteT", "author_id": 16989, "author_profile": "https://Stackoverflow.com/users/16989", "pm_score": 11, "selected": true, "text": "public static string Reverse( string s )\n{\n char[] charArray = s.ToCharArray();\n Array.Reverse(charArray);\n return new string(charArray);\n}\n" }, { "answer_id": 228062, "author": "Sam Saffron", "author_id": 17174, "author_profile": "https://Stackoverflow.com/users/17174", "pm_score": 7, "selected": false, "text": "public string Reverse(string text)\n{\n if (text == null) return null;\n\n // this was posted by petebob as well \n char[] array = text.ToCharArray();\n Array.Reverse(array);\n return new String(array);\n}\n" }, { "answer_id": 228063, "author": "Ash", "author_id": 5023, "author_profile": "https://Stackoverflow.com/users/5023", "pm_score": 2, "selected": false, "text": "string inputString=\"The quick brown fox jumps over the lazy dog.\";\nchar[] charArray = inputString.ToCharArray(); \nArray.Reverse(charArray); \n\nstring reversed = new string(charArray);\n" }, { "answer_id": 228084, "author": "Mike Two", "author_id": 23659, "author_profile": "https://Stackoverflow.com/users/23659", "pm_score": 4, "selected": false, "text": "\npublic string Reverse(string str)\n{\n char[] array = str.ToCharArray();\n Array.Reverse(array);\n return new string(array);\n}\n" }, { "answer_id": 228094, "author": "JPrescottSanders", "author_id": 19444, "author_profile": "https://Stackoverflow.com/users/19444", "pm_score": 2, "selected": false, "text": "private static string Reverse(string str)\n{\n if (str.IsNullOrEmpty(str) || str.Length == 1)\n return str;\n else\n return str[str.Length - 1] + Reverse(str.Substring(0, str.Length - 1));\n}\n" }, { "answer_id": 228166, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 3, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n public static string ReverseUsingArrayClass(string text)\n {\n char[] chars = text.ToCharArray();\n Array.Reverse(chars);\n return new string(chars);\n }\n\n public static string ReverseUsingCharacterBuffer(string text)\n {\n char[] charArray = new char[text.Length];\n int inputStrLength = text.Length - 1;\n for (int idx = 0; idx <= inputStrLength; idx++) \n {\n charArray[idx] = text[inputStrLength - idx]; \n }\n return new string(charArray);\n }\n\n public static string ReverseUsingStringBuilder(string text)\n {\n if (string.IsNullOrEmpty(text))\n {\n return text;\n }\n\n StringBuilder builder = new StringBuilder(text.Length);\n for (int i = text.Length - 1; i >= 0; i--)\n {\n builder.Append(text[i]);\n }\n\n return builder.ToString();\n }\n\n private static string ReverseUsingStack(string input)\n {\n Stack<char> resultStack = new Stack<char>();\n foreach (char c in input)\n {\n resultStack.Push(c);\n }\n\n StringBuilder sb = new StringBuilder();\n while (resultStack.Count > 0)\n {\n sb.Append(resultStack.Pop());\n }\n return sb.ToString();\n }\n\n public static string ReverseUsingXOR(string text)\n {\n char[] charArray = text.ToCharArray();\n int length = text.Length - 1;\n for (int i = 0; i < length; i++, length--)\n {\n charArray[i] ^= charArray[length];\n charArray[length] ^= charArray[i];\n charArray[i] ^= charArray[length];\n }\n\n return new string(charArray);\n }\n\n\n static void Main(string[] args)\n {\n string testString = string.Join(\";\", new string[] {\n new string('a', 100), \n new string('b', 101), \n new string('c', 102), \n new string('d', 103), \n });\n int cycleCount = 100000;\n\n Stopwatch stopwatch = new Stopwatch();\n stopwatch.Start();\n for (int i = 0; i < cycleCount; i++) \n {\n ReverseUsingCharacterBuffer(testString);\n }\n stopwatch.Stop();\n Console.WriteLine(\"ReverseUsingCharacterBuffer: \" + stopwatch.ElapsedMilliseconds + \"ms\");\n\n stopwatch.Reset();\n stopwatch.Start();\n for (int i = 0; i < cycleCount; i++) \n {\n ReverseUsingArrayClass(testString);\n }\n stopwatch.Stop();\n Console.WriteLine(\"ReverseUsingArrayClass: \" + stopwatch.ElapsedMilliseconds + \"ms\");\n\n stopwatch.Reset();\n stopwatch.Start();\n for (int i = 0; i < cycleCount; i++) \n {\n ReverseUsingStringBuilder(testString);\n }\n stopwatch.Stop();\n Console.WriteLine(\"ReverseUsingStringBuilder: \" + stopwatch.ElapsedMilliseconds + \"ms\");\n\n stopwatch.Reset();\n stopwatch.Start();\n for (int i = 0; i < cycleCount; i++) \n {\n ReverseUsingStack(testString);\n }\n stopwatch.Stop();\n Console.WriteLine(\"ReverseUsingStack: \" + stopwatch.ElapsedMilliseconds + \"ms\");\n\n stopwatch.Reset();\n stopwatch.Start();\n for (int i = 0; i < cycleCount; i++) \n {\n ReverseUsingXOR(testString);\n }\n stopwatch.Stop();\n Console.WriteLine(\"ReverseUsingXOR: \" + stopwatch.ElapsedMilliseconds + \"ms\"); \n }\n }\n}\n" }, { "answer_id": 228376, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 4, "selected": false, "text": "Array.Reverse" }, { "answer_id": 228460, "author": "Bradley Grainger", "author_id": 23633, "author_profile": "https://Stackoverflow.com/users/23633", "pm_score": 6, "selected": false, "text": "public static string Reverse(this string input)\n{\n if (input == null)\n throw new ArgumentNullException(\"input\");\n\n // allocate a buffer to hold the output\n char[] output = new char[input.Length];\n for (int outputIndex = 0, inputIndex = input.Length - 1; outputIndex < input.Length; outputIndex++, inputIndex--)\n {\n // check for surrogate pair\n if (input[inputIndex] >= 0xDC00 && input[inputIndex] <= 0xDFFF &&\n inputIndex > 0 && input[inputIndex - 1] >= 0xD800 && input[inputIndex - 1] <= 0xDBFF)\n {\n // preserve the order of the surrogate pair code units\n output[outputIndex + 1] = input[inputIndex];\n output[outputIndex] = input[inputIndex - 1];\n outputIndex++;\n inputIndex--;\n }\n else\n {\n output[outputIndex] = input[inputIndex];\n }\n }\n\n return new string(output);\n}\n" }, { "answer_id": 2439839, "author": "Saeed", "author_id": 293114, "author_profile": "https://Stackoverflow.com/users/293114", "pm_score": -1, "selected": false, "text": "public string rev(string str)\n{\n if (str.Length <= 0)\n return string.Empty;\n else\n return str[str.Length-1]+ rev(str.Substring(0,str.Length-1));\n}\n" }, { "answer_id": 3047997, "author": "Dan Tao", "author_id": 105570, "author_profile": "https://Stackoverflow.com/users/105570", "pm_score": 4, "selected": false, "text": "unsafe" }, { "answer_id": 4891003, "author": "Zamir", "author_id": 602149, "author_profile": "https://Stackoverflow.com/users/602149", "pm_score": 2, "selected": false, "text": " private string Reverse(string stringToReverse)\n {\n char[] rev = stringToReverse.Reverse().ToArray();\n return new string(rev); \n }\n" }, { "answer_id": 8419391, "author": "richardtallent", "author_id": 16306, "author_profile": "https://Stackoverflow.com/users/16306", "pm_score": 5, "selected": false, "text": "public string Reverse(string text)\n{\n return Microsoft.VisualBasic.Strings.StrReverse(text);\n}\n" }, { "answer_id": 9307098, "author": "mike01010", "author_id": 480118, "author_profile": "https://Stackoverflow.com/users/480118", "pm_score": 2, "selected": false, "text": " public static string ReverseString(string stringToReverse)\n {\n char[] charArray = stringToReverse.ToCharArray();\n int len = charArray.Length-1;\n int mid = len / 2;\n\n for (int i = 0; i < mid; i++)\n {\n char tmp = charArray[i];\n charArray[i] = charArray[len - i];\n charArray[len - i] = tmp;\n }\n return new string(charArray);\n }\n" }, { "answer_id": 10345725, "author": "Shrini", "author_id": 1360399, "author_profile": "https://Stackoverflow.com/users/1360399", "pm_score": 1, "selected": false, "text": "public static string Reverse2(string x)\n {\n char[] charArray = new char[x.Length];\n int len = x.Length - 1;\n for (int i = 0; i <= len; i++)\n charArray[i] = x[len - i];\n return new string(charArray);\n }\n" }, { "answer_id": 12328464, "author": "Marcel Valdez Orozco", "author_id": 697862, "author_profile": "https://Stackoverflow.com/users/697862", "pm_score": 3, "selected": false, "text": "public string Reverse(string input)\n{\n char[] output = new char[input.Length];\n\n int forwards = 0;\n int backwards = input.Length - 1;\n\n do\n {\n output[forwards] = input[backwards];\n output[backwards] = input[forwards];\n }while(++forwards <= --backwards);\n\n return new String(output);\n}\n\npublic string DotNetReverse(string input)\n{\n char[] toReverse = input.ToCharArray();\n Array.Reverse(toReverse);\n return new String(toReverse);\n}\n\npublic string NaiveReverse(string input)\n{\n char[] outputArray = new char[input.Length];\n for (int i = 0; i < input.Length; i++)\n {\n outputArray[i] = input[input.Length - 1 - i];\n }\n\n return new String(outputArray);\n} \n\npublic string RecursiveReverse(string input)\n{\n return RecursiveReverseHelper(input, 0, input.Length - 1);\n}\n\npublic string RecursiveReverseHelper(string input, int startIndex , int endIndex)\n{\n if (startIndex == endIndex)\n {\n return \"\" + input[startIndex];\n }\n\n if (endIndex - startIndex == 1)\n {\n return \"\" + input[endIndex] + input[startIndex];\n }\n\n return input[endIndex] + RecursiveReverseHelper(input, startIndex + 1, endIndex - 1) + input[startIndex];\n}\n\n\nvoid Main()\n{\n int[] sizes = new int[] { 10, 100, 1000, 10000 };\n for(int sizeIndex = 0; sizeIndex < sizes.Length; sizeIndex++)\n {\n string holaMundo = \"\";\n for(int i = 0; i < sizes[sizeIndex]; i+= 5)\n { \n holaMundo += \"ABCDE\";\n }\n\n string.Format(\"\\n**** For size: {0} ****\\n\", sizes[sizeIndex]).Dump();\n\n string odnuMaloh = DotNetReverse(holaMundo);\n\n var stopWatch = Stopwatch.StartNew();\n string result = NaiveReverse(holaMundo);\n (\"Naive Ticks: \" + stopWatch.ElapsedTicks).Dump();\n\n stopWatch.Restart();\n result = Reverse(holaMundo);\n (\"Efficient linear Ticks: \" + stopWatch.ElapsedTicks).Dump();\n\n stopWatch.Restart();\n result = RecursiveReverse(holaMundo);\n (\"Recursive Ticks: \" + stopWatch.ElapsedTicks).Dump();\n\n stopWatch.Restart();\n result = DotNetReverse(holaMundo);\n (\"DotNet Reverse Ticks: \" + stopWatch.ElapsedTicks).Dump();\n }\n}\n" }, { "answer_id": 15006915, "author": "vikas", "author_id": 845912, "author_profile": "https://Stackoverflow.com/users/845912", "pm_score": 1, "selected": false, "text": "private static string Reverse(string str)\n {\n string revStr = string.Empty;\n for (int i = str.Length - 1; i >= 0; i--)\n {\n revStr += str[i].ToString();\n }\n return revStr;\n }\n" }, { "answer_id": 15111719, "author": "R. Martinho Fernandes", "author_id": 46642, "author_profile": "https://Stackoverflow.com/users/46642", "pm_score": 8, "selected": false, "text": "\"Les Mise\\u0301rables\"" }, { "answer_id": 15754309, "author": "B H", "author_id": 1539001, "author_profile": "https://Stackoverflow.com/users/1539001", "pm_score": 3, "selected": false, "text": "string s = \"Blah\";\ns = new string(s.ToCharArray().Reverse().ToArray()); \n" }, { "answer_id": 15848573, "author": "SGRao", "author_id": 1571208, "author_profile": "https://Stackoverflow.com/users/1571208", "pm_score": 6, "selected": false, "text": "using System.Linq;" }, { "answer_id": 15908939, "author": "Vlad Bezden", "author_id": 30038, "author_profile": "https://Stackoverflow.com/users/30038", "pm_score": 3, "selected": false, "text": "public static string Reverse(string input)\n{\n return string.Concat(Enumerable.Reverse(input));\n}\n" }, { "answer_id": 20564284, "author": "AMIN", "author_id": 3098994, "author_profile": "https://Stackoverflow.com/users/3098994", "pm_score": -1, "selected": false, "text": "string A = null;\n//a now is reversed and you can use it\nA = SimulateStrReverse.StrReverse(\"your string\");\n\npublic static class SimulateStrReverse\n{\n public static string StrReverse(string expression)\n {\n if (string.IsNullOrEmpty(expression))\n return string.Empty;\n\n string reversedString = string.Empty;\n for (int charIndex = expression.Length - 1; charIndex >= 0; charIndex--)\n {\n reversedString += expression[charIndex];\n }\n return reversedString;\n }\n}\n" }, { "answer_id": 21414083, "author": "Rezo Megrelidze", "author_id": 2204040, "author_profile": "https://Stackoverflow.com/users/2204040", "pm_score": 2, "selected": false, "text": " public static string Reverse(string text)\n {\n var stack = new Stack<char>(text);\n var array = new char[stack.Count];\n\n int i = 0;\n while (stack.Count != 0)\n {\n array[i++] = stack.Pop();\n }\n\n return new string(array);\n }\n" }, { "answer_id": 21430958, "author": "Rezo Megrelidze", "author_id": 2204040, "author_profile": "https://Stackoverflow.com/users/2204040", "pm_score": 2, "selected": false, "text": " public static string ASCIIReverse(string s)\n {\n byte[] reversed = new byte[s.Length];\n\n int k = 0;\n for (int i = s.Length - 1; i >= 0; i--)\n {\n reversed[k++] = (byte)s[i];\n }\n\n return Encoding.ASCII.GetString(reversed);\n }\n" }, { "answer_id": 22361614, "author": "Raphael Saldanha", "author_id": 3412087, "author_profile": "https://Stackoverflow.com/users/3412087", "pm_score": 0, "selected": false, "text": " string original = \"Stack Overflow\";\n string reversed = new string(original.Reverse().ToArray());\n" }, { "answer_id": 22415201, "author": "TSqealBroDuh", "author_id": 2873025, "author_profile": "https://Stackoverflow.com/users/2873025", "pm_score": -1, "selected": false, "text": "SELECT REVERSE('somestring');" }, { "answer_id": 24499284, "author": "natenho", "author_id": 1987788, "author_profile": "https://Stackoverflow.com/users/1987788", "pm_score": 2, "selected": false, "text": "Microsoft.VisualBasic.Financial.Pmt()" }, { "answer_id": 26271208, "author": "Reasurria", "author_id": 2790482, "author_profile": "https://Stackoverflow.com/users/2790482", "pm_score": 2, "selected": false, "text": " char[] chars = new char[str.Length];\n for (int i = str.Length - 1, j = 0; i >= 0; --i, ++j)\n {\n chars[j] = str[i];\n }\n str = new String(chars);\n" }, { "answer_id": 26439257, "author": "Mehdi Khademloo", "author_id": 4038978, "author_profile": "https://Stackoverflow.com/users/4038978", "pm_score": 4, "selected": false, "text": "static class ExtentionMethodCollection\n{\n public static string Inverse(this string @base)\n {\n return new string(@base.Reverse().ToArray());\n }\n}\n" }, { "answer_id": 27171827, "author": "Mark Henry", "author_id": 4295340, "author_profile": "https://Stackoverflow.com/users/4295340", "pm_score": -1, "selected": false, "text": "String input = \"Mark Henry\";\n//Just to convert into char array. One can simply take input in char array.\nChar[] array = input.toCharArray(input);\nint a = input.length;\n\nfor(int i=0; i<(array.length/2 -1) ; i++)\n{\n array[i] = array[i] + array[a];\n array[a] = array[i] - array[a];\n array[i] = array[i] - array[a--];\n}\n" }, { "answer_id": 30936734, "author": "Jason Ausborn", "author_id": 4473175, "author_profile": "https://Stackoverflow.com/users/4473175", "pm_score": 2, "selected": false, "text": "static String Reverse2(string str)\n{\n int strLen = str.Length, elem = strLen - 1;\n char[] charA = new char[strLen];\n\n for (int i = 0; i < strLen; i++)\n {\n charA[elem] = str[i];\n elem--;\n }\n\n return new String(charA);\n}\n" }, { "answer_id": 33413626, "author": "ddagsan", "author_id": 1580548, "author_profile": "https://Stackoverflow.com/users/1580548", "pm_score": 2, "selected": false, "text": "public static string reverse(string s) \n{\n string r = \"\";\n for (int i = s.Length; i > 0; i--) r += s[i - 1];\n return r;\n}\n" }, { "answer_id": 37541215, "author": "Munavvar", "author_id": 3261852, "author_profile": "https://Stackoverflow.com/users/3261852", "pm_score": 1, "selected": false, "text": " private static string ReverseString1(string text)\n {\n char[] rtext = text.ToCharArray();\n Array.Reverse(rtext);\n return new string(rtext);\n }\n" }, { "answer_id": 39400093, "author": "simon", "author_id": 5225334, "author_profile": "https://Stackoverflow.com/users/5225334", "pm_score": -1, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace BackwardsTest\n{\n class PrintBackwards\n {\n public static void print(string param)\n {\n if (param == null || param.Length == 0)\n {\n Console.WriteLine(\"string is null\");\n return;\n }\n List<char> list = new List<char>();\n string returned = null;\n foreach(char d in param)\n {\n list.Add(d);\n }\n for(int i = list.Count(); i > 0; i--)\n {\n returned = returned + list[list.Count - 1];\n list.RemoveAt(list.Count - 1);\n }\n Console.WriteLine(returned);\n }\n }\n class Program\n {\n static void Main(string[] args)\n {\n string test = \"I want to print backwards\";\n PrintBackwards.print(test);\n System.Threading.Thread.Sleep(5000);\n }\n }\n}\n" }, { "answer_id": 39622549, "author": "Raktim Biswas", "author_id": 6290553, "author_profile": "https://Stackoverflow.com/users/6290553", "pm_score": 1, "selected": false, "text": "string x = \"your string\"; \nstring x1 = \"\";\nfor(int i = x.Length-1 ; i >= 0; i--)\n x1 += x[i];\nConsole.WriteLine(\"The reverse of the string is:\\n {0}\", x1);\n" }, { "answer_id": 46515622, "author": "Slai", "author_id": 1383168, "author_profile": "https://Stackoverflow.com/users/1383168", "pm_score": 4, "selected": false, "text": "string s = \"z̽a̎l͘g̈o̓\", pattern = @\"(?s).(?<=(?:.(?=.*$(?<=((\\P{M}\\p{C}?\\p{M}*)\\1?))))*)\";\n\nstring s1 = string.Concat(s.Reverse()); // \"☐☐̓ög͘l̎a̽z\" \n\nstring s2 = Microsoft.VisualBasic.Strings.StrReverse(s); // \"o̓g̈l͘a̎̽z\" \n\nstring s3 = string.Concat(StringInfo.ParseCombiningCharacters(s).Reverse()\n .Select(i => StringInfo.GetNextTextElement(s, i))); // \"o̓g̈l͘a̎z̽\" \n\nstring s4 = Regex.Replace(s, pattern, \"$2\").Remove(s.Length); // \"o̓g̈l͘a̎z̽\" \n" }, { "answer_id": 47080314, "author": "Jim", "author_id": 2040068, "author_profile": "https://Stackoverflow.com/users/2040068", "pm_score": 1, "selected": false, "text": "public static class StringExtensions\n{\n public static string Reverse(this string s)\n {\n var info = new StringInfo(s);\n var charArray = new char[s.Length];\n var teIndices = StringInfo.ParseCombiningCharacters(s).Reverse();\n\n int j = 0;\n foreach(var i in teIndices)\n {\n if (char.IsHighSurrogate(s[i]))\n {\n charArray[j] = s[i];\n j++;\n charArray[j] = s[i+1];\n }\n else\n {\n charArray[j] = s[i];\n }\n j++;\n }\n\n return new string(charArray);\n\n }\n}\n" }, { "answer_id": 48792874, "author": "joegreentea", "author_id": 2337475, "author_profile": "https://Stackoverflow.com/users/2337475", "pm_score": 1, "selected": false, "text": "static string ReverseString(string text)\n{\n string sub = \"\";\n int indexCount = text.Length - 1;\n for (int i = indexCount; i > -1; i--)\n {\n sub = sub + text.Substring(i, 1);\n }\n return sub;\n}\n" }, { "answer_id": 50337746, "author": "Milad Jafari", "author_id": 4220076, "author_profile": "https://Stackoverflow.com/users/4220076", "pm_score": -1, "selected": false, "text": "public Static void main(){\n string text = \"Test Text\";\n Console.Writeline(RevestString(text))\n}\n\npublic Static string RevestString(string text){\n char[] textToChar = text.ToCharArray();\n string result= string.Empty;\n int length = textToChar .Length;\n for (int i = length; i > 0; --i)\n result += textToChar[i - 1];\n return result;\n}\n" }, { "answer_id": 50412992, "author": "Pankaj Rawat", "author_id": 4140278, "author_profile": "https://Stackoverflow.com/users/4140278", "pm_score": -1, "selected": false, "text": "static void Reverse()\n {\n string str = \"PankajRawat\";\n var arr = str.ToCharArray();\n for (int i = str.Length-1; i >= 0; i--)\n {\n Console.Write(arr[i]);\n }\n }\n" }, { "answer_id": 53648374, "author": "Shadi Serhan", "author_id": 2979382, "author_profile": "https://Stackoverflow.com/users/2979382", "pm_score": 3, "selected": false, "text": "string reversed = new string(text.Reverse().ToArray());\n" }, { "answer_id": 56772632, "author": "Deep", "author_id": 2785027, "author_profile": "https://Stackoverflow.com/users/2785027", "pm_score": 0, "selected": false, "text": "static void Main(string[] args)\n{\n string str = \"\";\n string reverse = \"\";\n Console.WriteLine(\"Enter the value to reverse\");\n str = Console.ReadLine();\n int length = 0;\n length = str.Length - 1;\n while(length >= 0)\n {\n reverse = reverse + str[length];\n length--;\n }\n Console.Write(\"Reverse string is {0}\", reverse);\n Console.ReadKey();\n}\n" }, { "answer_id": 56937817, "author": "Flogex", "author_id": 8336143, "author_profile": "https://Stackoverflow.com/users/8336143", "pm_score": 4, "selected": false, "text": "string.Create" }, { "answer_id": 56982067, "author": "Punit Pandya", "author_id": 10747653, "author_profile": "https://Stackoverflow.com/users/10747653", "pm_score": 0, "selected": false, "text": " using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\n\nnamespace ConsoleApplication1\n{\n class Program\n { \n public static string ReverseString(string str)\n {\n int totalLength = str.Length;\n int iCount = 0;\n string strRev = string.Empty;\n iCount = totalLength;\n while (iCount != 0)\n {\n iCount--;\n strRev += str[iCount]; \n }\n return strRev;\n }\n static void Main(string[] args)\n {\n string str = \"Punit Pandya\";\n string strResult = ReverseString(str);\n Console.WriteLine(strResult);\n Console.ReadLine();\n }\n }\n\n }\n" }, { "answer_id": 57177035, "author": "Karthik", "author_id": 10726714, "author_profile": "https://Stackoverflow.com/users/10726714", "pm_score": 1, "selected": false, "text": "string s = \"Karthik U\";\ns = s.Aggregate(new StringBuilder(), (o, p) => o.Insert(0, p)).ToString();\n" }, { "answer_id": 57577337, "author": "SET", "author_id": 8547919, "author_profile": "https://Stackoverflow.com/users/8547919", "pm_score": 2, "selected": false, "text": "string.Create" }, { "answer_id": 60997534, "author": "Gigabyte", "author_id": 3729730, "author_profile": "https://Stackoverflow.com/users/3729730", "pm_score": 1, "selected": false, "text": " public static string ReverseString(this string content) {\n\n var textElementEnumerator = StringInfo.GetTextElementEnumerator(content);\n\n var SbBuilder = new StringBuilder(content.Length);\n\n while (textElementEnumerator.MoveNext()) {\n SbBuilder.Insert(0, textElementEnumerator.GetTextElement());\n }\n\n return SbBuilder.ToString();\n }\n" }, { "answer_id": 64250151, "author": "Ramakrishna Talla", "author_id": 849030, "author_profile": "https://Stackoverflow.com/users/849030", "pm_score": 2, "selected": false, "text": " public static string MyReverse(string s)\n {\n char[] charArray = s.ToCharArray();\n int bgn = -1;\n int end = s.Length;\n while(++bgn < --end)\n {\n charArray[bgn] ^= charArray[end];\n charArray[end] ^= charArray[bgn];\n charArray[bgn] ^= charArray[end];\n }\n return new string(charArray);\n }\n" }, { "answer_id": 71577236, "author": "Perdente", "author_id": 14071426, "author_profile": "https://Stackoverflow.com/users/14071426", "pm_score": 0, "selected": false, "text": "string s = Console.ReadLine();\nConsole.WriteLine(s + \"\\n\");\nchar[] charArray = s.ToCharArray();\nint i = 0, j = s.Length - 1;\nwhile (i < j) {\n char temp = charArray[i];\n charArray[i] = charArray[j];\n charArray[j] = temp;\n i++; j--;\n}\nstring ans = new string(charArray);\nConsole.WriteLine(ans + \"\\n\");\n// Input: hello\n// Output: olleh\n" }, { "answer_id": 73419041, "author": "l33t", "author_id": 419761, "author_profile": "https://Stackoverflow.com/users/419761", "pm_score": 1, "selected": false, "text": "LINQ" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
228,081
<p>I'm looking for ideas for a heap-manager to handle a very specific situation: Lots and lots of very small allocations, ranging from 12 to 64 bytes each. Anything bigger, I will pass on to the regular heap-manager, so only tiny blocks need be catered for. Only 4-byte alignment is needed.</p> <p>My main concerns are</p> <ol> <li>Overhead. The regular libc heap will typically round up an allocation to a multiple of 16 bytes, then add another 16 byte header - this means over 50% overhead on a 20-byte allocation, which sucks.</li> <li>Performance</li> </ol> <p>One helpful aspect is that Lua (which is the user of this heap) will tell you the size of the block it's freeing when it calls free() - this may enable certain optimisations.</p> <p>I'll post my current approach, which works ok, but I'd like to improve on it if at all possible. Any ideas?</p>
[ { "answer_id": 228132, "author": "hazzen", "author_id": 5066, "author_profile": "https://Stackoverflow.com/users/5066", "pm_score": 0, "selected": false, "text": "typedef struct _allocator {\n void* buffer;\n int start;\n int max;\n} allocator;\n\nvoid init_allocator(size_t size, allocator* alloc) {\n alloc->buffer = malloc(size);\n alloc->start = 0;\n alloc->max = size;\n}\n\nvoid* allocator_malloc(allocator* alloc, size_t amount) {\n if (alloc->max - alloc->start < 0) return NULL;\n void* mem = alloc->buffer + alloc->start;\n alloc->start += bytes;\n return mem;\n}\n\nvoid allocator_free(allocator* alloc) {\n alloc->start = 0;\n}\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228081", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29539/" ]
228,102
<pre><code>&lt;div&gt; &lt;span&gt;left&lt;/span&gt; &lt;span&gt;right&lt;/span&gt; &lt;!-- new line break, so no more content on that line --&gt; &lt;table&gt; ... &lt;/table&gt; &lt;/div&gt; </code></pre> <p>How can I position those spans (they can be changed to any element) so that depending on how big the table is (not defined anywhere, and shouldn't be) the spans are positioned just on top of the left side of the table and the right side of the table.</p> <p>Example:</p> <pre> a b table0 table1 table2 </pre> <p>(where a is the left span, and b is the right span)</p> <p>P.S. You can change anything bar inner table html.</p>
[ { "answer_id": 228126, "author": "Rob Allen", "author_id": 149, "author_profile": "https://Stackoverflow.com/users/149", "pm_score": 3, "selected": false, "text": "<style type=\"text/css\">\n #wrapper, #top, #tableArea\n {\n width: 100%;\n padding: 10px;\n margin: 0px auto;\n }\n\n #top\n {\n padding: 0px;\n }\n\n #leftBox, #rightBox\n {\n margin: 0px;\n float: left;\n display: inline;\n clear: none;\n }\n\n #rightBox\n {\n float: right;\n }\n </style>\n<div id=\"wrapper\">\n <div id=\"top\">\n <div id=\"leftBox\">A</div>\n <div id=\"rightBox\">b<</div>\n </div>\n <div id=\"tableArea\">\n <table> ... </table>\n </div>\n</div>\n" }, { "answer_id": 228133, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<div>\n<div style=\"float:left\">a</div><div style=\"float:right\">b</div>\n<br style=\"clear: both\">\naaaaaaaaaaaaaaaaaaaaaaaaaaa<br />\naaaaaaaaaaaaaaaaaaaaaaaaaaa<br />\naaaaaaaaaaaaaaaaaaaaaaaaaaa<br />\n</div>\n" }, { "answer_id": 228406, "author": "Darryl Hein", "author_id": 5441, "author_profile": "https://Stackoverflow.com/users/5441", "pm_score": 0, "selected": false, "text": "<style type=\"text/css\">\n#wrapper {\n width: 1%;\n min-width:50em;\n padding: 10px;\n}\n#mainTable {\n width:100%;\n}\n\n#leftBox {\n float: left;\n}\n\n#rightBox {\n float: right;\n}\n</style>\n<div id=\"wrapper\">\n <div id=\"leftBox\">A</div>\n <div id=\"rightBox\">b</div>\n <br style=\"clear: both\" />\n some text some text some text some text some text <br />\n some text some text some text some text some text <br />\n some text some text some text some text some text\n <table id=\"mainTable\" border=\"1\"><tr><td>test</td><td>test 2</td></tr></table>\n</div>\n" }, { "answer_id": 8680378, "author": "Trix", "author_id": 1123037, "author_profile": "https://Stackoverflow.com/users/1123037", "pm_score": 2, "selected": false, "text": " <style>\n .tablediv {\n float:left; /* this is a must otherwise the div will take a full width of our page and this way it wraps only our content (so only the table) */\n position:relative; /* we are setting this to start the trickie part */ \n padding-top:2.7em; /* we have to set the room for our spans, 2.7em is enough for two rows otherwise try to use something else; for one row e.g. 1.7em */\n }\n .leftspan {\n position:absolute; /* seting this to our spans will start our behaviour */\n top:0; /* we are setting the position where it will be placed inside the .tablediv */\n left:0;\n }\n .rightspan {\n position:absolute; \n top:0; \n right:0; \n }\n </style>\n<div class=\"tablediv\">\n <span class=\"leftspan\">Left text</span>\n <span class=\"rightspan\">Right text <br /> with row</span>\n <table border=\"1\">\n <tr><td colspan=\"3\">Header</td></tr>\n <tr><td rowspan=\"2\">Left content</td><td>Content</td><td rowspan=\"2\">Right content</td></tr>\n <tr><td>Bottom content</td></tr>\n </table>\n</div>\n <!-- If you don't want to float this on the right side of the table than you must use the clear style -->\n <p style=\"clear:both\">\n something that continues under our tablediv\n </p>\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
228,125
<p>I am after a regular expression that validates a percentage from 0 100 and allows two decimal places. </p> <p>Does anyone know how to do this or know of good web site that has example of common regular expressions used for client side validation in javascript?</p> <p>@Tom - Thanks for the questions. Ideally there would be no leading 0's or other trailing characters.</p> <p>Thanks to all those who have replied so far. I have found the comments really interesting.</p>
[ { "answer_id": 228152, "author": "Julien Grenier", "author_id": 23051, "author_profile": "https://Stackoverflow.com/users/23051", "pm_score": 0, "selected": false, "text": "(100|[0-9]{1,2})(\\.[0-9]{1,2})?" }, { "answer_id": 228158, "author": "Czimi", "author_id": 3906, "author_profile": "https://Stackoverflow.com/users/3906", "pm_score": 1, "selected": false, "text": "str.match(/^(100(\\.0{1,2})?|([0-9]?[0-9](\\.[0-9]{1,2})))$/)\n" }, { "answer_id": 228180, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 6, "selected": true, "text": "var x = parseFloat(str);\nif (isNaN(x) || x < 0 || x > 100) {\n // value is out of range\n}\n" }, { "answer_id": 228709, "author": "Alexander Prokofyev", "author_id": 11256, "author_profile": "https://Stackoverflow.com/users/11256", "pm_score": 4, "selected": false, "text": "(^100(\\.0{1,2})?$)|(^([1-9]([0-9])?|0)(\\.[0-9]{1,2})?$)\n" }, { "answer_id": 228774, "author": "Tom", "author_id": 26155, "author_profile": "https://Stackoverflow.com/users/26155", "pm_score": 1, "selected": false, "text": "^100(\\.(0){0,2})?$|^([1-9]?[0-9])(\\.(\\d{0,2}))?\\%$\n" }, { "answer_id": 228885, "author": "kentaromiura", "author_id": 27340, "author_profile": "https://Stackoverflow.com/users/27340", "pm_score": 0, "selected": false, "text": "100|(([1-9][0-9])|[0-9])(\\.(([0-9][1-9])|[1-9]))?\n" }, { "answer_id": 49747017, "author": "L. Schilling", "author_id": 9491307, "author_profile": "https://Stackoverflow.com/users/9491307", "pm_score": 1, "selected": false, "text": "[0-9]{1,2}((,|\\.)[0-9]{1,10})?%?\n" }, { "answer_id": 52160949, "author": "Gangadhara S M", "author_id": 9636426, "author_profile": "https://Stackoverflow.com/users/9636426", "pm_score": 0, "selected": false, "text": "(100(\\.(0){1,2})?|([1-9]{1}|[0-9]{2})(\\.[0-9]{1,2})?)\n" }, { "answer_id": 66141634, "author": "Henry Brigham", "author_id": 7133371, "author_profile": "https://Stackoverflow.com/users/7133371", "pm_score": 0, "selected": false, "text": "/(^$)|(^100(\\.0{1,2})?$)|(^([1-9]([0-9])?|0)\\.(\\.[0-9]{1,2})?$)|(^([1-9]([0-9])?|0)(\\.[0-9]{1,2})?$)/" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5360/" ]
228,134
<p>I like Steve Yegge's <a href="http://steve-yegge.blogspot.com/2008/10/universal-design-pattern.html" rel="noreferrer">Prototype Pattern example</a> and decided to whip up a quick proof of concept example.</p> <p>However, I didn't really think things through. While it is great for dynamically specifying the behaviour of objects and is an easy solution to Steve's <a href="http://steve.yegge.googlepages.com/when-polymorphism-fails" rel="noreferrer">opinionated elf</a> example, I'm still trying to work out the best way to handle instance variables.</p> <p>For instance, let's say I have an AwesomeDragon object. I then want to make an AwesomeDragonImmuneToFire object so I make a new child of the AwesomeDragon (AwesomeDragonImmuneToFire inherits properties from AwesomeDragon) and 'put' "ImmuneToFire" as a property with a value of 'true'. So far so good. Now let's say I want to send my AwesomeDragon object on a tour of nearby peasant villages. This will involve updating the 'position' property of AwesomeDragon. However, the moment I do this AwesomeDragonImmuneToFire will take off as well.</p> <p>Is the best solution to override instance values upon object creation e.g. immediately 'put' the 'position' value on AwesomeDragonImmuneToFire to the current 'get' value of 'position'?</p>
[ { "answer_id": 228232, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 4, "selected": true, "text": "prototype" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
228,145
<p>I am progamatically creating a SharePoint site using </p> <pre><code>SPWeb spWeb = spSite.AllWebs.Add(...); </code></pre> <p>What code do I need run to set the spWeb to turn off the "Show pages in navigation" option?</p> <p><strong>Answer:</strong></p> <pre><code>publishingWeb.IncludePagesInNavigation = false; </code></pre>
[ { "answer_id": 228211, "author": "Brian Schmitt", "author_id": 30492, "author_profile": "https://Stackoverflow.com/users/30492", "pm_score": 4, "selected": true, "text": "publishingWeb.InheritGlobalNavigation = false;\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13813/" ]
228,164
<p>The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design.</p> <p>Give me scenarios, other than the good old logger where it makes sense to use the singleton.</p>
[ { "answer_id": 383919, "author": "Schwern", "author_id": 14660, "author_profile": "https://Stackoverflow.com/users/14660", "pm_score": 3, "selected": false, "text": "new()" }, { "answer_id": 4081829, "author": "Ozgur Zeren", "author_id": 495232, "author_profile": "https://Stackoverflow.com/users/495232", "pm_score": 3, "selected": false, "text": "$gb->config['hostname']" }, { "answer_id": 63301141, "author": "raiks", "author_id": 412965, "author_profile": "https://Stackoverflow.com/users/412965", "pm_score": 3, "selected": false, "text": "public class Singleton {\n private static Singleton instance;\n\n private Singleton() {}\n\n public static Singleton instance() {\n if (instance == null) {\n instance = new Singleton();\n }\n return instance;\n }\n}\n" }, { "answer_id": 74066812, "author": "adityaatri", "author_id": 13192685, "author_profile": "https://Stackoverflow.com/users/13192685", "pm_score": -1, "selected": false, "text": "Singleton" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21537/" ]
228,165
<p>I stumbled across my rather ancient photo objects disks, and sadly found out the company (hemera) doesn't provide support for it anymore. this has left me with a whole pile of .hpi files. Luckily, I found <a href="http://www.halley.cc/ed/linux/interop/hemera.html" rel="nofollow noreferrer">this information</a> on extracting the jpg and png components of the file.</p> <p>Unfortunately, I haven't been able to get it to work. Can anyone figure out what's wrong with this code? I'd be happy with a PHP or Python solution if Perl isn't your thing. :)</p> <pre><code>open(I, "$name") || die; binmode(I); $_ = &lt;I&gt;; close(I); my ($j, $p) = m|^.{32}(.*)(\211PNG.*)$|s; open(J, "&gt;$name.jpg") &amp;&amp; do { binmode(J); print J $j; close J; }; open(P, "&gt;$name.png") &amp;&amp; do { binmode(P); print P $p; close P; }; </code></pre> <p>The hexdump of the current test file I snagged off a CD is here, if it helps at all:</p> <pre><code>0000000 89 48 50 49 0d 0a 1a 0a 64 00 00 00 20 00 00 00 0000010 45 89 00 00 65 89 00 00 0a 21 00 00 00 d0 d0 00 </code></pre>
[ { "answer_id": 228192, "author": "ypnos", "author_id": 21974, "author_profile": "https://Stackoverflow.com/users/21974", "pm_score": 3, "selected": true, "text": "#include <stdio.h>\n#include <stdlib.h>\n\n#define MAX_SIZE 1048576\n\nchar stuff[MAX_SIZE];\n\nint main (int argc, char **argv)\n{\n unsigned int j_off, j_len, p_off, p_len;\n FILE *fp, *jp, *pp;\n fp = fopen (argv[1], \"r\");\n if (!fp) goto error;\n if (fseek (fp, 12, SEEK_SET)) goto error;\n if (!fread (&j_off, 4, 1, fp)) goto error;\n if (!fread (&j_len, 4, 1, fp)) goto error;\n if (!fread (&p_off, 4, 1, fp)) goto error;\n if (!fread (&p_len, 4, 1, fp)) goto error;\n fprintf (stderr, \"INFO %s \\t%d %d %d %d\\n\",\n argv[1], j_off, j_len, p_off, p_len);\n if (j_len > MAX_SIZE || p_len > MAX_SIZE) {\n fprintf (stderr, \"%s: Chunk size too big!\\n\", argv[1]);\n return EXIT_FAILURE;\n }\n\n jp = fopen (argv[2], \"w\");\n if (!jp) goto error;\n if (fseek (fp, j_off, SEEK_SET)) goto error;\n if (!fread (stuff, j_len, 1, fp)) goto error;\n if (!fwrite (stuff, j_len, 1, jp)) goto error;\n fclose (jp);\n\n pp = fopen (argv[3], \"w\");\n if (!pp) goto error;\n if (fseek (fp, p_off, SEEK_SET)) goto error;\n if (!fread (stuff, p_len, 1, fp)) goto error;\n if (!fwrite (stuff, p_len, 1, pp)) goto error;\n fclose (pp);\n fclose (fp);\n return EXIT_SUCCESS;\n\nerror:\n perror (argv[1]);\n return EXIT_FAILURE;\n}\n" }, { "answer_id": 228259, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 3, "selected": false, "text": "#!/usr/bin/perl\nuse strict;\n\nmy $HEADER = \"\\211PNG\";\nmy $FOOTER = \"IEND\\xAEB`\\x82\";\n\nforeach my $file ( @ARGV )\n {\n print \"Extracting $file\\n\";\n (my $image_base = $file) =~ s/(.*)\\..*/$1/;\n\n my $data = do { local $/; open my( $fh ), $file; <$fh> };\n\n my $count = 0;\n\n while( $data =~ m/($HEADER.*?$FOOTER)/sg )\n {\n my $image = $1;\n $count++;\n my $image_name = \"$image_base.$count.png\";\n open my $fh, \"> $image_name\" or warn \"$image_name: $!\", next;\n print \"Writing $image_name: \", length($image), \" bytes\\n\";\n print $fh $image;\n close $fh;\n }\n\n }\n\n\n__END__\n" }, { "answer_id": 4773813, "author": "Aziz K.", "author_id": 586323, "author_profile": "https://Stackoverflow.com/users/586323", "pm_score": 2, "selected": false, "text": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\nimport re, sys\n\ndef main():\n if len(sys.argv) < 2:\n print \"\"\"Usage:\n {0} BINARY_FILE PNG_PATH_TEMPLATE\nExample:\n {0} bin/program 'imgs/image.{{0:03d}}.png'\"\"\".format(__file__)\n return\n binfile, pngpath_tpl = sys.argv[1:3]\n\n rx = re.compile(\"\\x89PNG.+?IEND\\xAEB`\\x82\", re.S)\n bintext = open(binfile, \"rb\").read()\n PNGs = rx.findall(bintext)\n\n for i, PNG in enumerate(PNGs):\n f = open(pngpath_tpl.format(i), \"wb\") # Simple string format.\n f.write(PNG)\n f.close()\n\nif __name__ == \"__main__\":\n main()\n" }, { "answer_id": 10355166, "author": "sinelaw", "author_id": 562906, "author_profile": "https://Stackoverflow.com/users/562906", "pm_score": 0, "selected": false, "text": ".jpeg" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4853/" ]
228,175
<p>When using SubSonic, do you return the data as a dataset or do you put that in a strongly typed custom collection or a generic object?</p> <p>I ran through the subsonic project and for the four stored procs I have in my DB, it gave me a Sps.cs with 4 methods which return a StoredProcedure object.</p> <p>If you used a MVC, do you usually use the StoredProcedure object or wrap that around your business logic and return a dataset, list, collection or something else?</p> <p>Are datasets still the norm or is that replaced by something else?</p>
[ { "answer_id": 228190, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 3, "selected": false, "text": "ProductCollection coll = new ProductCollection();\ncoll.LoadAndCloseReader(SPs.GetProducts(1).GetReader());\n" }, { "answer_id": 716884, "author": "Rick Rat", "author_id": 43754, "author_profile": "https://Stackoverflow.com/users/43754", "pm_score": 0, "selected": false, "text": "Dim Charts As Generic.List(Of MusicDB.Billboard) = _\n New SubSonic.Select(MusicDB.DB.Repository.Provider, New String() _\n {\"Prefix\", \"Artist\", \"Track\", \"ArtistNarrowToken\", \"TrackNarrowToken\", \"ArtistId\", \"TrackId\", \"TrackYear\"}). _\n From(MetadataTagger.MusicDB.Tables.Billboard). _\n Where(MusicDB.Billboard.Columns.ArtistNarrowToken).IsLessThan(10). _\n Or(MusicDB.Billboard.Columns.TrackId).IsNull(). _\n OrderAsc(New String() {\"TrackYear\"}).ExecuteTypedList(Of MetadataTagger.MusicDB.Billboard)()\n" }, { "answer_id": 717601, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "ExecuteTypedList<>" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
228,200
<p><code>%AX = (%AH + %AL)</code></p> <p>So why not <code>%EAX = (%SOME_REGISTER + %AX)</code> for some register <code>%SOME_REGISTER</code>? </p>
[ { "answer_id": 228367, "author": "Mike Thompson", "author_id": 2754, "author_profile": "https://Stackoverflow.com/users/2754", "pm_score": 8, "selected": true, "text": "8080/Z80 8086\nA AX\nBC BX\nDE CX\nHL DX\nIX SI \nIY DI\n" }, { "answer_id": 32472219, "author": "Sean Werkema", "author_id": 412416, "author_profile": "https://Stackoverflow.com/users/412416", "pm_score": 5, "selected": false, "text": "POP AX" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10432/" ]
228,205
<p>How do you handle update refresh rate from your worker function to your UI ?</p> <p>Sending everything to the UI or maybe using a timer (from which side ? worker or UI ?)</p>
[ { "answer_id": 228367, "author": "Mike Thompson", "author_id": 2754, "author_profile": "https://Stackoverflow.com/users/2754", "pm_score": 8, "selected": true, "text": "8080/Z80 8086\nA AX\nBC BX\nDE CX\nHL DX\nIX SI \nIY DI\n" }, { "answer_id": 32472219, "author": "Sean Werkema", "author_id": 412416, "author_profile": "https://Stackoverflow.com/users/412416", "pm_score": 5, "selected": false, "text": "POP AX" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2566/" ]
228,218
<p>I am very new to Java. My assignment is to create my own method and then create a class to test it in. My question, do I create the method separate of the class, or within the class? If it is separate of the class, how do I get the class to access my method?</p> <p>(Are they saved as two separate files?)</p> <p>This is what I have so far, but I am getting an error that I have to initialize KILOWATT in class DWindmill. I thought I did already in the method??? Any suggestions?</p> <pre><code>//This is the method Windmill import java.util.*; import static java.lang.Math.*; class DWindmill { public static void Windmill(){ //create the method for the Windmill class int miles = 50; //int miles = 200; //int miles = 250; int KILOWATT = (miles / 50);} static Scanner console = new Scanner(System.in); { System.out.println("Enter miles per hour:"); miles = console.nextInt(); Windmill(); System.out.println(+ KILOWATT + "kilowatts"); } } </code></pre>
[ { "answer_id": 228226, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 2, "selected": false, "text": "public class MyClass {\n\n public static void Hello() {\n //This is your method!\n }\n\n public static void main (String[] args) {\n Hello(); //This is how you call your method.\n }\n}\n" }, { "answer_id": 228236, "author": "anjanb", "author_id": 11142, "author_profile": "https://Stackoverflow.com/users/11142", "pm_score": 1, "selected": false, "text": "public class MyClass {\n public int myMethod() {\n ,,,,,\n }\n}\n\npublic class myTest {\n public void testMyMethod() {\n MyClass testClass = new MyClass();\n int output = testClass.myMethod();\n . \n. \n }\n}\n" }, { "answer_id": 228429, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 2, "selected": false, "text": "class Windmill\n{\n public static void main(String args[])\n {\n Scanner console = new Scanner(System.in);\n System.out.println(\"Enter miles per hour:\");\n int miles = console.nextInt();\n int KILOWATT = (miles / 50);\n System.out.println(KILOWATT + \" kilowatts\");\n }\n}\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30606/" ]
228,220
<p>Let's say we have 2 php variables:</p> <ul> <li><strong>$name</strong> = 'caption';</li> <li><strong>$url</strong> = '<a href="http://domain.com/photo.jpg" rel="nofollow noreferrer">http://domain.com/photo.jpg</a>';</li> </ul> <p>The input string of <code>'{@url,&lt;img src="," alt="{@name}" /&gt;}'</code> should return:</p> <p><code>'&lt;img src="http://domain.com/photo.jpg" alt="caption" /&gt;'</code></p> <p>The <code>{tag}</code> takes up to 3 parameters: <code>{@variable[,text_before][,text_after]}</code>.</p> <p>What regex would be needed to make this happen? The tricky part is that a <code>{@..}</code> tag is nested within another.</p>
[ { "answer_id": 228307, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<p>Link: <a href=\"{@url}\">{@name}</a> - {@date}</p>" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
228,221
<p>I know that I can insert multiple rows using a single statement, if I use the syntax in <a href="https://stackoverflow.com/questions/39576/best-way-to-do-multi-row-insert-in-oracle#39602">this answer</a>. </p> <p>However, one of the values I am inserting is taken from a sequence, i.e. </p> <pre><code>insert into TABLE_NAME (COL1,COL2) select MY_SEQ.nextval,'some value' from dual union all select MY_SEQ.nextval,'another value' from dual ; </code></pre> <p>If I try to run it, I get an ORA-02287 error. Is there any way around this, or should I just use a lot of INSERT statements?</p> <p>EDIT:<br> If I have to specify column names for all other columns other than the sequence, I lose the original brevity, so it's just not worth it. In that case I'll just use multiple INSERT statements.</p>
[ { "answer_id": 228294, "author": "WW.", "author_id": 14663, "author_profile": "https://Stackoverflow.com/users/14663", "pm_score": 6, "selected": true, "text": "insert into TABLE_NAME (COL1,COL2)\nselect my_seq.nextval, a\nfrom\n(SELECT 'SOME VALUE' as a FROM DUAL\n UNION ALL\n SELECT 'ANOTHER VALUE' FROM DUAL)\n" }, { "answer_id": 228310, "author": "EvilTeach", "author_id": 7734, "author_profile": "https://Stackoverflow.com/users/7734", "pm_score": 2, "selected": false, "text": "insert into TABLE_NAME\n(COL1,COL2)\nWITH\ndata AS\n(\n select 'some value' x from dual\n union all\n select 'another value' x from dual\n)\nSELECT my_seq.NEXTVAL, x \nFROM data\n;\n" }, { "answer_id": 237634, "author": "Dilshod Tadjibaev", "author_id": 29122, "author_profile": "https://Stackoverflow.com/users/29122", "pm_score": 5, "selected": false, "text": "insert into table_name\n (col1, col2)\n select my_seq.nextval, inner_view.*\n from (select 'some value' someval\n from dual\n union all\n select 'another value' someval\n from dual) inner_view;\n" }, { "answer_id": 11580817, "author": "Mordred", "author_id": 1540960, "author_profile": "https://Stackoverflow.com/users/1540960", "pm_score": 0, "selected": false, "text": "Insert into BARCODECHANGEHISTORY (IDENTIFIER,MESSAGETYPE,FORMERBARCODE,NEWBARCODE,REPLACEMENTDATETIME,OPERATORID,REASON)\nselect SEQ_BARCODECHANGEHISTORY.nextval, MESSAGETYPE, FORMERBARCODE, NEWBARCODE, REPLACEMENTDATETIME, OPERATORID, REASON\nfrom (\n SELECT\n 'BAR' MESSAGETYPE,\n '1234567890' FORMERBARCODE,\n '1234567899' NEWBARCODE,\n to_timestamp('20/07/12','DD/MM/RR HH24:MI:SSXFF') REPLACEMENTDATETIME,\n 'PIMATD' OPERATORID,\n 'CORRECTION' REASON\n FROM dual\n);\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3751/" ]
228,225
<p>Is it possible to prevent the browser from following redirects when sending XMLHttpRequest-s (i.e. to get the redirect status code back and handle it myself)?</p>
[ { "answer_id": 28411170, "author": "Roland Pihlakas", "author_id": 193017, "author_profile": "https://Stackoverflow.com/users/193017", "pm_score": 4, "selected": false, "text": "responseURL" }, { "answer_id": 33578947, "author": "user", "author_id": 3075942, "author_profile": "https://Stackoverflow.com/users/3075942", "pm_score": 5, "selected": false, "text": "follow" }, { "answer_id": 64232437, "author": "Shahzoob", "author_id": 6435076, "author_profile": "https://Stackoverflow.com/users/6435076", "pm_score": 0, "selected": false, "text": "let xhttp = new XMLHttpRequest();\nxhttp.onreadystatechange = function () {\n if (this.readyState == 4 && this.status == 200) {\n reqObj.success(JSON.parse(this.responseText))\n } else if (this.status != 200) {\n reqObj.error(this.statusText)\n }\n};\nxhttp.open(reqObj.type, reqObj.url, reqObj.async);\nxhttp.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\nxhttp.send();\n" }, { "answer_id": 69456804, "author": "dooderson", "author_id": 1311069, "author_profile": "https://Stackoverflow.com/users/1311069", "pm_score": 1, "selected": false, "text": "abort()" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30609/" ]
228,256
<p>Is there a good, up-to-date listing anywhere that maps User-Agent HTTP Header strings --> operating systems?</p>
[ { "answer_id": 228298, "author": "Dan Herbert", "author_id": 392, "author_profile": "https://Stackoverflow.com/users/392", "pm_score": 4, "selected": false, "text": "browser.php" }, { "answer_id": 261012, "author": "Osama Al-Maadeed", "author_id": 25544, "author_profile": "https://Stackoverflow.com/users/25544", "pm_score": 2, "selected": false, "text": "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) \nGecko/2008101315 Ubuntu/8.10 (intrepid) Firefox/3.0.3 \n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5682/" ]
228,265
<p>I'm hoping this question isn't too obscure <em>cross fingers</em></p> <p>I'm looking for a decent reference for <a href="http://netsuite.com" rel="noreferrer">netsuite</a> scripting and api (both of which are based on ASP)</p> <p>does anybody know where to find this stuff? The netsuite help pages are mediocre at best, and the forums aren't very active. (I suppose these two things are already bad signs, but it's worth a try right?)</p>
[ { "answer_id": 11965724, "author": "Web Developer", "author_id": 1600039, "author_profile": "https://Stackoverflow.com/users/1600039", "pm_score": 2, "selected": false, "text": "nlapiGetFieldValue();\nrecord.getFieldValue();\nrec.getValue();\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2908/" ]
228,268
<p><a href="http://blogs.msdn.com/drnick/archive/2007/03/23/preventing-anonymous-access.aspx" rel="noreferrer">http://blogs.msdn.com/drnick/archive/2007/03/23/preventing-anonymous-access.aspx</a> </p> <p>Can someone clarify whether it is possible to use wsHttpBinding in WCF and disable anonymous access in IIS without transport (ssl) or message security being required?</p>
[ { "answer_id": 265895, "author": "Tobias Hertkorn", "author_id": 33827, "author_profile": "https://Stackoverflow.com/users/33827", "pm_score": 2, "selected": false, "text": "public class TestService : ITestService\n{\n [PrincipalPermission(SecurityAction.Demand, Name = \"testdomain\\\\administrator\")]\n public string DoWork()\n { \n return \"Hello World \" + Thread.CurrentPrincipal.Identity.Name;\n }\n}\n\n <system.serviceModel>\n <behaviors>\n <serviceBehaviors>\n <behavior name=\"WcfSecurity.Www.TestServiceBehavior\">\n <serviceMetadata httpGetEnabled=\"true\" />\n <serviceDebug includeExceptionDetailInFaults=\"false\" />\n <serviceAuthorization principalPermissionMode=\"UseWindowsGroups\" />\n </behavior>\n </serviceBehaviors>\n </behaviors>\n <services>\n <service behaviorConfiguration=\"WcfSecurity.Www.TestServiceBehavior\" name=\"WcfSecurity.Www.TestService\">\n <endpoint address=\"\" binding=\"wsHttpBinding\" contract=\"WcfSecurity.Www.ITestService\" />\n <endpoint address=\"mex\" binding=\"mexHttpBinding\" contract=\"IMetadataExchange\" />\n </service>\n </services> \n </system.serviceModel>\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228268", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25255/" ]
228,288
<p>Is it possible to subscribe to a Windows event that fires when Windows is going into or coming out of Sleep or Hibernate state?</p> <p>I need my application to be made aware when the computer is going to sleep to do some cleanup and avoid timing issues when it comes out of sleep.</p>
[ { "answer_id": 228405, "author": "Jeff Yates", "author_id": 23234, "author_profile": "https://Stackoverflow.com/users/23234", "pm_score": 5, "selected": true, "text": "Microsoft.Win32.SystemEvents.PowerModeChanged" }, { "answer_id": 31033210, "author": "Richard Chambers", "author_id": 1466970, "author_profile": "https://Stackoverflow.com/users/1466970", "pm_score": 2, "selected": false, "text": "ON_MESSAGE()" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5982/" ]
228,300
<p>I need to recover form an error case where a file gets left in a locked state. How can I in c# tell this file to reset it's locks? I need to add to this the file is opened by a 3rd party dll and I don't actually have access to the file handle.</p>
[ { "answer_id": 228351, "author": "LizB", "author_id": 13616, "author_profile": "https://Stackoverflow.com/users/13616", "pm_score": 1, "selected": false, "text": " try {\n thirdPartyObj = new ThirdPartObj();\n // Some possible error causing object actions\n catch(Exception ex) {\n thirdPartyObj = null; // The object should close its resources\n }\n" }, { "answer_id": 228381, "author": "Jason Lautzenheiser", "author_id": 30016, "author_profile": "https://Stackoverflow.com/users/30016", "pm_score": 2, "selected": true, "text": "System.Diagnostics.Process.Start(\"psfile c:\\myfile.txt -c\");" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22835/" ]
228,319
<p>I am using a navigation controller, and I have the style set to :</p> <pre><code>navController.navigationBar.barStyle = UIBarStyleBlackTranslucent; </code></pre> <p>But when I run my program, the navigation controller looks like it is on top of a white background, not my background. When I push a controller, left or right, all my view, the current one, shifts to the top exactly the size of the navigation bar. And it is there where I can see my background through the navigation controller bar. Any ideas? When my barStyle is set to opaque, everything looks fine. I was thinking on setting my view frame a negative 'y' value, but I think there should a more elegant way.</p>
[ { "answer_id": 2876401, "author": "Shizam", "author_id": 155513, "author_profile": "https://Stackoverflow.com/users/155513", "pm_score": 2, "selected": false, "text": " self.navigationController.navigationBar.tintColor = [UIColor blackColor];\n self.navigationController.navigationBar.translucent = YES;\n" }, { "answer_id": 3979693, "author": "Harpreet", "author_id": 475548, "author_profile": "https://Stackoverflow.com/users/475548", "pm_score": 1, "selected": false, "text": "_topToolBar.barStyle = UIBarStyleBlackTranslucent;\n_topToolBar.alpha = 0.3;\n" }, { "answer_id": 4132534, "author": "xiaogong", "author_id": 501727, "author_profile": "https://Stackoverflow.com/users/501727", "pm_score": 1, "selected": false, "text": "ImageViewExtendController *detailImageController = [[ImageViewExtendController alloc] init]; \n[detailImageController loadImage:url];\n[self.navigationController pushViewController:detailImageController animated:YES];\n" }, { "answer_id": 4213088, "author": "Hanno", "author_id": 511877, "author_profile": "https://Stackoverflow.com/users/511877", "pm_score": 0, "selected": false, "text": "self.tabBarController.tabBar.superview.backgroundColor = [UIColor blackColor];\n" }, { "answer_id": 12173058, "author": "Pill Gong", "author_id": 1299641, "author_profile": "https://Stackoverflow.com/users/1299641", "pm_score": 2, "selected": false, "text": "self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.169 green:0.373 blue:0.192 alpha:0.9];\nself.navigationController.navigationBar.translucent = YES;\n" }, { "answer_id": 13818316, "author": "Resh32", "author_id": 1611950, "author_profile": "https://Stackoverflow.com/users/1611950", "pm_score": 3, "selected": false, "text": "self.navigationController.navigationBar.translucent = YES;\nUIImage * backgroundImage = [UIImage imageNamed:@\"spacer.gif\"];\n[self.navigationController.navigationBar setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:UIBarMetricsDefault];\n" }, { "answer_id": 23548800, "author": "Alejandro Teixeira Muñoz", "author_id": 3617531, "author_profile": "https://Stackoverflow.com/users/3617531", "pm_score": 0, "selected": false, "text": "Extend Edges;\n Under Top Bars;\n Under Bottom Bars;\n Under Opaque Bars;\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29642/" ]
228,321
<p>On an embedded target I use far pointers to access some parts of the memory map. </p> <p>near pointer (without explicitely specifying __near):</p> <pre>unsigned int *VariableOnePtr;</pre> <p>Pointer to near pointer: <pre>unsigned int **VariableOnePtrPtr;</pre></p> <p>far pointer: <pre>unsigned int *__far VariableTwoPtr;</pre> </p> <p>What is the correct way to declare a pointer to a far pointer? Does this pointer have to be a far pointer itself?</p>
[ { "answer_id": 228331, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": true, "text": "unsigned int * __far *VariableThreePtrPtr;\n" }, { "answer_id": 228482, "author": "dmityugov", "author_id": 3232, "author_profile": "https://Stackoverflow.com/users/3232", "pm_score": 2, "selected": false, "text": "typedef unsigned int *__far VariableTwoPtr_t;\nVariableTwoPtr_t* VariableTwoPtrPtr;\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2386/" ]
228,353
<p>A lambda expression which takes a function (of one argument) and a number, and applies the function to twice the number.</p>
[ { "answer_id": 228361, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "(lambda (f x) (f (* 2 x)))\n" }, { "answer_id": 228456, "author": "grettke", "author_id": 121526, "author_profile": "https://Stackoverflow.com/users/121526", "pm_score": 3, "selected": false, "text": "; A lambda expression\n;(lambda () )\n\n; which takes a function (of one argument) and a number\n;(lambda (fun num) )\n\n; and applies the function\n;(lambda (fun num) (fun num))\n\n; to twice the number\n;(lambda (fun num) (fun (* 2 num)))\n\n((lambda (fun num) (fun (* 2 num))) + 12)\n" }, { "answer_id": 228487, "author": "grettke", "author_id": 121526, "author_profile": "https://Stackoverflow.com/users/121526", "pm_score": 2, "selected": false, "text": ";; apply-double : function -> number -> any\n;; to apply a given function to double a given number\n(define (apply-double fun num) ...)\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30622/" ]
228,375
<p>How to get the path of the current csproject?</p> <p>Let's say I have a csproject name <code>MyProj.csproj</code>, inside there is a class that wants to know what is the file path of this csproj, any idea on how to do this? thanks.</p>
[ { "answer_id": 33606582, "author": "weiky", "author_id": 3346178, "author_profile": "https://Stackoverflow.com/users/3346178", "pm_score": 1, "selected": false, "text": "string solutionPath = @\"C:\\Users\\...\\PathToSolution\\MySolution.sln\";\nvar msWorkspace = MSBuildWorkspace.Create();\n\nvar solution = msWorkspace.OpenSolutionAsync(solutionPath).Result;\nforeach (var project in solution.Projects)\n{\n foreach (var document in project.Documents)\n {\n //get all C# Files here\n }\n}\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/228375", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]