instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I have a column of data that contains a percentage range as a string that I'd like to convert to a number so I can do easy comparisons.</p> <p>Possible values in the string:</p> <pre><code>'&lt;5%' '5-10%' '10-15%' ... '95-100%' </code></pre> <p>I'd like to convert this in my select where clause to just the first...
<p>Try this,</p> <pre><code>SELECT substring(replace(interest , '&lt;',''), patindex('%[0-9]%',replace(interest , '&lt;','')), patindex('%[^0-9]%',replace(interest, '&lt;',''))-1) FROM table1 </code></pre> <p>Tested at my end and it works, it's only my first try so you might be able to optimise it.</p>
<p>You can convert char data to other types of char (convert char(10) to varchar(10)), but you won't be able to convert character data to integer data from within SQL.</p>
3,898
<p>I want to hook up an Arduino to my Creality printer running Marlin firmware, such that I can have a few physical buttons mounted on the machine that will execute commands such as preheat, home, disable steppers, and so on, so that I don't have to navigate through the clunky LCD screen.</p> <p>Ideally it would work i...
<p>One option would be to have your printer controlled by an Octoprint server. You would then use the <a href="https://github.com/chunkysteveo/OctoPrintAPI" rel="nofollow noreferrer">Octoprint Api plugin</a> to use your arduino to send commands to octoprint - and from there, your printer. Octoprint has a fairly fully...
<p>There's already Arduino inside the printer (to be precise: the printer board with spare pins). Im sure its possible to hook up a switch then change firmware to send G-codes; 1 pin per series of commands?</p>
1,137
<p>I run a site where users have their own profile pages. They are also able to post products for sale (that they have made) and write/import blog posts. I am going to be implementing a sitemap and I need to make a final decision with the URL strategy.</p> <p>Here's what I currently have for products (where 1234 is th...
<p>I think the first example (example.com/product/1234.product-category.product-name) is the best format but I would consider changing then "." to "-". I am just thinking that if somehow a product name ends in something that triggers an different handler on your server like ".php" or ".jsp" you might have some undesir...
<p>I prefer this: example.com/users_name/product-category/product-name/1234</p> <p>However, one should be aware that the url gets too long some times. It is difficult to represent or promote in a blog or a forum. Why not simply use example.com/1234 and use the Title to put the other details like category and product ...
41,269
<p>I'm currently writing a TYPO3 extension which is configured with a list of <code>tt_content</code> UID's. These point to content elements of type "text" and i want to render them by my extension.</p> <p>Because of TYPO3s special way of transforming the text you enter in the rich text editing when it enters the data...
<p>I had the same problem a couple of months ago. Now I must say that I am no typo3 developer, so I don't know if this is the right solution.</p> <p>But I used something like this:</p> <p><code>$output .= $this-&gt;pi_RTEcssText( $contentFromDb );</code></p> <p>in my extension and it works.</p>
<h2>PHP</h2> <p>That works for me; it renders any content element with the given ID:</p> <pre><code>function getCE($id) { $conf['tables'] = 'tt_content'; $conf['source'] = $id; $conf['dontCheckPid'] = 1; return $GLOBALS['TSFE']-&gt;cObj-&gt;cObjGetSingle('RECORDS', $conf); } </code></pre> <p>See <a h...
9,669
<p>Let's say I have the following function:</p> <pre><code>sumAll :: [(Int,Int)] -&gt; Int sumAll xs = foldr (+) 0 (map f xs) where f (x,y) = x+y </code></pre> <p>The result of <code>sumAll [(1,1),(2,2),(3,3)]</code> will be <code>12</code>.</p> <p>What I don't understand is where the <code>(x,y)</code> values are...
<p>In Haskell, functions are first class datatypes.</p> <p>This means you can pass functions around like other types of data such as integers and strings.</p> <p>In your code above you declare 'f' to be a function, which takes in one argumenta (a tuple of two values (x,y)) and returns the result of (x + y).</p> <p>f...
<p>Not an answer, but I thought I should point out that your function f:</p> <pre><code>f (x, y) = x + y </code></pre> <p>can be expressed as</p> <pre><code>f = uncurry (+) </code></pre>
49,348
<p>Is there a way to tell subversion "update/merge unless it would cause a conflict"?</p> <p>I know you can use <code>--dry-run</code> / <code>status -u</code> to check before running the update, but I often have others running updates and getting broken webpages because they don't notice the "C index.php" line.</p>...
<p>You can use the --accept parameter to indicate what should happen when a conflict occurs:</p> <pre><code>--accept ARG : specify automatic conflict resolution action ('postpone', 'base', 'mine-full', 'theirs-full', 'edit', 'launch') </code></pre> <p>Se...
<p>you could also use a pre-commit script to look for conflict markers in files and prevent commit when they are present.</p>
5,353
<p>What's the best way to do the semantic equivalent of the traditional sleep() system call from within an Informix SPL routine? In other words, simply "pause" for N seconds (or milliseconds or whatever, but seconds are fine). I'm looking for a solution that does <em>not</em> involve linking some new (perhaps written...
<p>There must be some good reason you're not wanting the obvious answer: <code>SYSTEM "sleep 5"</code>. If all you're wanting is for the SPL to pause while you check various values etc, here are a couple of thoughts (all of which are utter hacks, of course):</p> <ol> <li>Make the TRACE FILE a named pipe (assuming Unix...
<p>I assume that you want this "pause" for debugging purposes, otherwise think about it, you'll always have some better tasks to do for your server than sleep ...</p> <p>A suggestion: Maybe you could get CURRENT, add it a few seconds ( let mytimestamp ) then in a while loop select CURRENT while CURRENT &lt;= mytimesta...
2,752
<p>What might be changing the DOM of a web page after the browser receives the response?</p> <p>I'm seeing this behavior in the value of a hidden input element that holds a single-use form token.</p> <p>When I 'view source' in a browser, I see the correct value, as written out by the server. When I submit the form, v...
<p>I wasn't correct in my interpretation of what was happening. I guess that's a good thing, because what I thought I was seeing shouldn't ever happen! Anyway, here's the situation as I now understand it:</p> <p>The form token here is single use, so it's only valid for a single page load. Somewhere else on the page wa...
<p>What do you mean by <em>"when I submit the form, view the current state of the DOM"</em>?</p> <p>If you submit the form, does it send a request to the server? Are you talking about the state of the DOM on the resulting page sent back by the server?</p> <p>It's not really possible that, with no client-side scriptin...
44,561
<p>Currently, if I want to output a SQL script for a table in my database, in Management Studio, I can right click and output a create script. </p> <p>Is there an equivalent to output an SQL script for a database's maintenance plan?#</p> <p>Edit</p> <p>The company I work for has 4 servers, 3 servers and no sign of...
<p>You can't export them as scripts, but if your intention is to migrate them between server instances then you can import and export them as follows:</p> <p>Connect to Integration Services and expand Stored Packages>MSDB>Maintenance Plans. You can then right click on the plan and select import or export</p>
<p>I don't think you can do that with Maintenance Plans, because those are DTS packages, well now they are called SSIS (SQL Server Integration Services). </p> <p>There was a stored procedure from which you could add maintenance plans, but I think that it may be deprecated. (sp_add_maintenance_plan). I don't have a SQL...
5,267
<p>What does it mean when you get or create a date in UTC format in JavaScript?</p>
<p>A date represents a specific point in time. This point in time will be called differently in different places. As I write this, it's 00:27 on Tuesday in Germany, 23:27 on Monday in the UK and 18:27 on Monday in New York.</p> <p>To take an example method: getDay returns the day of the week in the local timezone. ...
<p>getUTC is for converting times to Coordinated Universal Time (UTC, the acronym is ordered differently than what it stands for) which is the standard time based on the time in Greenwich, London.</p> <p>The universal time is calculated using a time offset (in minutes when in JavaScript.) This offset is based on the t...
3,610
<p>What is a good use case for uncaught_exception?</p>
<p>Herb Sutter seems to give good advice <a href="http://www.gotw.ca/gotw/047.htm" rel="noreferrer">here</a>. He doesn't know of a good use for it and says that some cases where it appears to be useful don't really work.</p>
<p><a href="http://www.gotw.ca/gotw/047.htm" rel="nofollow noreferrer">Probably none</a></p>
34,692
<p>In C# you can use verbatim strings like this:</p> <pre><code>@"\\server\share\file.txt" </code></pre> <p>Is there something similar in JavaScript?</p>
<p>No, there isn't support for that in JavaScript. And that workaround seems very problematic as you now lose the ability to have forward slashes.</p> <p>I've run into this issue myself when I needed to build an alert message or something from an ASP.NET back end, and stick it in a JavaScript alert on the front end. T...
<p>I'll re-iterate what's been said before - verbatim strings aren't possible in javascript. It's actually easy to escape valid escape characters like <code>\n \\ \t</code> etc but the problem comes from escaping non-valid characters due to the way they are handled in the different functions they become incompatible. ...
35,937
<p>I have a SQL Report that insists on printing an extra blank page at the end, even though all the report items should fit on one page. I tried shortening the elements on the page that is spilling over, but no matter how much I compress them, or how much blank space is left on the first page, SRS still thinks it need...
<p>Try removing any 'empty space' from the body. Shrink the editing surface to be just large enough for all your ReportItems, both height-wise and width-wise. ReportingServices thinks the space you have in your body is intentional, so it's preserved.</p> <p>If that doesn't help and you're noticing this issue on 2005...
<p>use <code>ConsumeContainerWhitespace</code> to <code>TRUE</code> in the Report Properties its <code>FALSE</code> by default</p>
44,779
<p>Does anyone know how to print a barcode to the Intermec PB20 bluetooth printer from a Windows Compact Framework application? We are currently using the Intermec LinePrinter API but have been unable to find a way to print a barcode. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
<p>Thank you all for your thoughts. Printing directly to the serial port is likely the most flexible method. In this case we didn't want to replicate all of the work that was already built into the Intermec dll for handling the port, printer errors, etc. We were able to get this working by sending the printer the appro...
<p>Last time I had to print Barcode (despite the printer or framework) I resorted to use a True Type font with the Barcode I needed. (In my case was EAN-13 something), an european barcode.</p> <p>There are fonts where you simply write numbers (and/or letters when supported) and you get a perfect barcode any scanner ca...
4,590
<p>I have this code:</p> <pre><code>@PersistenceContext(name="persistence/monkey", unitName="deltaflow-pu") ... @Stateless public class GahBean implements GahRemote { </code></pre> <p>But when I use this:</p> <pre><code>try{ InitialContext ic = new InitialContext(); System.out.println("Pissing me off * " + ic.look...
<p>This could be my ignorance about JPA showing, but you appear to have "persistence" in some places and "persistent" in others. I'd start by making sure the names match.</p>
<p>If I inject it by the way it works fine, but everywhere I read about that they say it isn't threadsafe to do it that way.</p>
17,119
<p>Has anyone else experienced this error? Sometimes it pops up at the beginning of loading the application with Argument Error 2082. The only way I can solve it is by rebooting my machine. Restarting the browser doesn't even solve it. I have read about some solutions on the web, but I am interested in knowing what oth...
<p>It's a known bug in Flash, there's a pretty long discussion about it here:</p> <p><a href="http://tech.groups.yahoo.com/group/flexcoders/message/63829" rel="nofollow noreferrer">http://tech.groups.yahoo.com/group/flexcoders/message/63829</a></p> <p>The long and short of it is you should wrap your localConnection.c...
<p>Are you talking about the <a href="http://livedocs.adobe.com/flex/3/langref/runtimeErrors.html" rel="nofollow noreferrer">Actionscript 3.0 Runtime Error 2082</a>?</p>
13,009
<p>I can't figure out why the following wont work, any ideas?? public interface IFieldSimpleItem { }</p> <pre><code>public interface IFieldNormalItem : IFieldSimpleItem { } public class Person { public virtual T Create&lt;T&gt;() where T : IFieldSimpleItem { return default(T); } } ...
<p>I'm pretty sure you're out of luck as far as using the compiler and generics to save you some runtime checks. You can't override something that doesn't already exist, and you can't have different return types to the same methods. </p> <p>I can't say I completely understand your motivation, but it has technical meri...
<p>What about this:</p> <pre><code>public interface IFieldNormalItem : IFieldSimpleItem { } public class Person&lt;T&gt; where T : IFieldSimpleItem { public virtual T Create() { return default(T); } } </code></pre> <p>Now you can have <code>Person&lt;IFieldSimpleItem&gt;</code> (corresponds to <c...
35,997
<p>I have two classes that are associated with a one-to-one mapping:</p> <pre><code>&lt;class name="Employee" table="Employees"&gt; ... &lt;one-to-one name="Address" class="AddressInfo"&gt; ... &lt;/class&gt; </code></pre> <p>I would like to use a criteria expression to get only Employees where the the associat...
<p>Have you tried creating an alias for the Address property and checking if the ID/primary key of the Address is not null?</p> <p>Something like: </p> <pre><code>IList employeesWithAddresses = sess.CreateCriteria(typeof(Employee)) .CreateCriteria("Address", "address").Add( Expression.IsNotNull("Id") ) .List(...
<p>To implicitly trigger a Alias/Join for one-to-one, shouldn't you use dot-notation? And then checking any field in your Address-class:</p> <pre><code>IList employeesWithAddresses = sess.CreateCriteria(typeof(Employee)) .Add( Expression.IsNotNull("Address.Id") ) .List(); </code></pre> <p>This is probably the...
38,915
<p>How to Connect to PickBasic database using Ole db driver .. I need it badly help me out</p>
<p>I recently joined this company and i see they are using UniObjects.Net dll for interacting with this Data base Check it out its from IBM not sure about the performance though</p>
<p>Create an ODBC DSN Datasource, then use it just like any other ODBC connection</p>
41,424
<p>I need a good stemming algorithm for a project I'm working on. It was suggested that I look at the Porter Stemmer. When I checked out the page on the Porter stemmer I found that it is deprecated now in favor of the "Snowball" stemmer.</p> <p>I need a good stemmer, but I can't really spend significant time implement...
<p>The <a href="http://snowball.tartarus.org/algorithms/english/stemmer.html" rel="noreferrer">Porter2</a> stemmer is the one I've decided to go with. It seemed the porter stemmer was the standard, but when I found the page by the author he recommended the "Snowball (Porter2)" stemmer. There is a C port link on this pa...
<p>It really depends on how you're planning to apply it. The Natural Language Toolkit (<a href="http://nltk.sourceforge.net" rel="nofollow noreferrer">http://nltk.sourceforge.net</a>) has a number of stemmers implemented in it that should be able to handle most applications. I prefer the Morphy stemmer.</p> <p>Of co...
28,010
<p>still new to the world of linq, and i need some help flatening a list of parents that have children, into a single list of ParentChild's.</p> <p>Just like this:</p> <pre><code>class Program { static void Main() { List&lt;Parent&gt; parents = new List&lt;Parent&gt;(); parents.Add(new Parent...
<pre><code>from parent in parents from child in parent.Children select new ParentChild() { ParentName = parent.Name, ChildName = child.Name }; </code></pre>
<p>This should do it for you:</p> <pre><code>var k = from p in parents from c in p.Children select new {Name = p.Name, Child = c.Name }; </code></pre> <p>EDIT: Opps forgot to return a new ParentChild object. but Kent beat me to it ;)</p>
35,041
<p>I have a custom error page set up for my application:</p> <pre><code>&lt;customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx" /&gt; </code></pre> <p>In Global.asax, Application_Error(), the following code works to get the exception details:</p> <pre><code> Exception ex = Server.GetLastError(); i...
<p>Looking more closely at my web.config set up, one of the comments in <a href="http://msdn.microsoft.com/en-us/library/vstudio/h0hfz6fc(v=vs.100).aspx" rel="noreferrer">this post is very helpful</a></p> <blockquote> <p>in asp.net 3.5 sp1 there is a new parameter redirectMode</p> </blockquote> <p>So we can amend <...
<p>I think you have a couple of options here.</p> <p>you could store the last Exception in the Session and retrieve it from your custom error page; or you could just redirect to your custom error page within the Application_error event. If you choose the latter, you want to make sure you use the Server.Transfer method...
44,595
<p>I am fairly beginner level at shell scripts and following are the details..</p> <p>Am looking for the best way to fire sql queries and and carry out some logic based on that data. I've used the following snippet..</p> <p>shellvariable=<code>sqlplus $user/$passwd &lt;&lt;END select count(1) from table1; end EOF</co...
<p>you're on the right track. sqlplus is the best way to interact with the database when you are shell scripting, but two things to note:</p> <ol> <li>use the "-S" parameter to stop sqlplus from printing all its application info </li> <li>to read data directly into a variable, you will need some sqlplus environment se...
<p><a href="http://scripterworld.blogspot.com/2009/08/connecting-to-oracle-database-from-unix.html" rel="nofollow noreferrer">Accessing database through shell scripting</a></p>
42,486
<p>Today my colleagues and me have a discussion about the usage of the <code>final</code> keyword in Java to improve the garbage collection.</p> <p>For example, if you write a method like:</p> <pre><code>public Double doCalc(final Double value) { final Double maxWeight = 1000.0; final Double totalWeight = maxWe...
<p>Here's a slightly different example, one with final reference-type fields rather than final value-type local variables:</p> <pre><code>public class MyClass { public final MyOtherObject obj; } </code></pre> <p>Every time you create an instance of MyClass, you'll be creating an outgoing reference to a MyOtherOb...
<p>The only thing that I can think of is that the compiler might optimize away the final variables and inline them as constants into the code, thus you end up with no memory allocated.</p>
39,474
<p>All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and doing so efficiently, involves a tedious process partly characterized by learning unfamiliar paradigms, and finding out that some of our most familiar programming patterns don't wor...
<p>I am consistently disappointed by most programmers' tendency to mix their UI-logic in the data access layer:</p> <pre><code>SELECT FirstName + ' ' + LastName as "Full Name", case UserRole when 2 then "Admin" when 1 then "Moderator" else "User" end as "User's Role", case Signe...
<p>Not using the With clause or a proper join and relying on sub-queries.</p> <p><strong>Anti-Pattern:</strong></p> <pre><code>select ... from data where RECORD.STATE IN ( SELECT STATEID FROM STATE WHERE NAME IN ('Published to test', 'Approve...
45,104
<p>I'm working on a game where I need to let the player look at a plane (e.g., a wall) through a lens (e.g., a magnifying glass). The game is to run on the iPhone, so my choices are Core Animation or OpenGL ES.</p> <p>My first idea (that I have not yet tried) is to do this using Core Animation.</p> <ol> <li>Create t...
<p>That is how I'd do it, it sounds like a good plan.</p> <p>Whether you choose OGL or CA the basic principle is the same so I would stick with what you're more comfortable with.</p> <ol> <li>Identify the region you wish to magnify</li> <li>Render this region to a separate surface</li> <li>Render any border/overlay o...
<p>I have implemented a magnifying glass on the iPhone using a UIView. CA was way too slow.</p> <p>You can draw a CGImage into a UIView using it's drawRect method. Here's the steps in my drawRect:</p> <ol> <li>get the current context</li> <li>create a path for clipping the view (circle)</li> <li>scale the current tra...
19,912
<p>I'm having performance oddities with Java2D. I know of the sun.java2d.opengl VM parameter to enable 3D acceleration for 2D, but even using that has some weird issues. </p> <p>Here are results of tests I ran:</p> <p>Drawing a 25x18 map with 32x32 pixel tiles on a JComponent<br> Image 1 = .bmp format, Image 2 = A .p...
<p>I think I found a solution by researching and putting bits and pieces together from too many Google searches. </p> <p>Here it is, comments and all:</p> <pre><code>private BufferedImage toCompatibleImage(BufferedImage image) { // obtain the current system graphical settings GraphicsConfiguration gfxConfig =...
<p>From what I remember when I was thinking about doing graphics programming in Java, the built in libraries are slow. I was advised on GameDev.Net that anyone doing anything serious would have to use something like <a href="http://jogl.dev.java.net/" rel="nofollow noreferrer">jogl</a></p>
23,927
<p>I have one autocomplete search, in which by typing few characters it will show all the names, which matches the entered character. I am populating this data in the jsp using DIV tag, by using mouse I'm able to select the names. But I want to select the names in the DIV tag to be selected using the keyboard up and do...
<p>Use the <code>onkeydown</code> and <code>onkeyup</code> events to check for key press events in your results div:</p> <pre><code>var UP = 38; var DOWN = 40; var ENTER = 13; var getKey = function(e) { if(window.event) { return e.keyCode; } // IE else if(e.which) { return e.which; } // Netscape/Firefox/Opera...
<p>I assume that you have an input which handles the input. </p> <p>map onkeyup-eventhandler for that input in which you read out event.keyCode, and do stuff when it's the appropriate keycodes for up/down-arrow (38, 40), to keep a reference to which node (item in your div) you move the focus to.</p> <p>Then call the ...
35,461
<p>With PHP, I can make numerous PHP websites locally and then upload each of them to its own sub-directory of my PHP hosting service. </p> <p>However, with ASP.NET, it seems that I can only upload my ASP.NET to the root of my hosting service. If I upload to a sub-directory, I get an error in </p> <pre><code>section ...
<p>A better solution, IMO, is to change the signature of your method to use a bounded wildcard:</p> <pre><code>public List&lt;? extends IField&gt; getFields() </code></pre> <p>This will let the caller treat anything coming "out" of the list as an IField, but it won't let the caller add anything into the list (without...
<p>Sunlight is right, you can just cast it.</p> <p>Another fix is to double-check that you really need a <code>List&lt;Field&gt;</code>, or whether you can change your internal <code>fields</code> variable to <code>List&lt;IField&gt;</code>.</p> <p>As long as you only ever use methods on the contents of the list that...
40,513
<p>I just started using the WPF WebBrowser that is included in Net 3.5 SP1. I built my setup project (which I have been using prior to moving to 3.5 SP1) and installed it on a test machine but the WebBrowser was not available.</p> <p>What must I do to be sure that the setup.exe/msi combination checks for and installs...
<p>Open the properties of the Setup Project, then click on the Prerequesites button. Then check the prerequisites to install.</p> <p><img src="https://i.stack.imgur.com/arDF8.png" alt="License"></p> <p>Then you can define how the user gets the pre-reqs.</p> <p>Here is a link to framework version information and an ...
<p>On my way to answering my own question. Double-clicking on the Microsoft .net Framework in the Detected dependencies one can choose the version. </p> <p>Now the question is which is appropriate, <strong>3.5.30729</strong> or <strong>3.5 SP1 Client</strong>?</p> <p><strong>EDIT:</strong> 3.5.30729 works. Any ide...
11,375
<p>I was asked this question in a job interview. The interviewer and I disagreed on what the correct answer was. I'm wondering if anyone has any data on this.</p> <p>Update: I should have mentioned that the use of shuffle() was strictly forbidden... sorry.</p>
<p>You could use the <a href="http://en.wikipedia.org/wiki/Knuth_shuffle" rel="nofollow noreferrer">Fisher-Yates shuffle</a>.</p>
<p>The "correct" way is pretty vague. The best (fastest / easiest / most elegant) to sort an array would be to just use the built-in shuffle() function.</p>
9,161
<p>I have a YouTube's player in the webpage. I need to change the video played by this player dynamicaly.</p> <p>This is (relatively) easy using YouTube's chromeless player. It has method <a href="http://code.google.com/apis/youtube/chromeless_player_reference.html#loadVideoById" rel="noreferrer"><code>loadVideoById()...
<p>You can not do that, cause the calls in the "regular youtube player" have the VideoID in the URL instead as a parameter:</p> <ul> <li>Regular Video: <a href="http://www.youtube.com/v/VIDEO_ID&amp;enablejsapi=1&amp;playerapiid=ytplayer" rel="noreferrer">http://www.youtube.com/v/VIDEO_ID&amp;enablejsapi=1&amp;playera...
<p>I found it easier to use loadVideoByUrl() as an alternative to loadVideoByIdl() instead of using createSWF, you don't have to mess with the swfobject this way, it's a built-in function...just use the video ID to create a youtube swf url such as: url="http://www.youtube.com/e/" + VIDEO_ID + "?enablejsapi=1&amp;versi...
48,523
<p>I'm a bit surprised that this isn't on more forums as it is a total show stopper. I have a ASP.NET app that calls a web service I wrote. It is hosted on a shared hosting site. Recently the company moved my server to allow for both 1.1 and 2.0 applications. The trust level has changed from 'full' to 'medium' and my ...
<p>It sounds to me like your web host is not very flexible. I would ask them about adding the needed permissions they allow. I had the same problem with Server Intellect and after speaking with them and telling them the permission I needed, they helped out and worked it out.</p> <p>Honestly though, there are a lot o...
<p>Hostgator seem to be the best among the lot.I am using hostgator.</p>
31,447
<p>I need to use the popcnt instruction in a project that is compiled using Visual Stdio 2005<br> The intrinsic <code>__popcnt()</code> only works with VS2008 and the compiler doesn't seem to recognize the instruction even when I write in a <code>__asm {}</code> block.</p> <p>Is there any way to do this?</p>
<p>Okay, this is a wild guess thing but ... assuming you've set up VS2005 like <a href="http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/3e24f203-c516-41e2-a7bf-325452157336/" rel="nofollow noreferrer">this</a> to do assembly language, then you could get a hold of the <a href="http://www.developers.net/fi...
<p>Okay, this is a wild guess thing but ... assuming you've set up VS2005 like <a href="http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/3e24f203-c516-41e2-a7bf-325452157336/" rel="nofollow noreferrer">this</a> to do assembly language, then you could get a hold of the <a href="http://www.developers.net/fi...
47,155
<p>I'm fine working on Linux using gcc as my C compiler but would like a Windows solution. Any ideas? I've looked at <a href="http://en.wikipedia.org/wiki/Dev-C%2B%2B" rel="noreferrer">Dev-C++ from Bloodshed</a> but looking for more options.</p>
<p>You can use GCC on Windows by downloading <a href="http://www.mingw.org/" rel="noreferrer">MingW</a> (<em>discontinued</em>) or its successor <a href="https://mingw-w64.org/" rel="noreferrer">Mingw-w64</a>.</p>
<p>Must Windows C++ compilers will work. </p> <p>Also, check out <a href="http://www.mingw.org/" rel="nofollow noreferrer">MinGW</a>.</p>
14,177
<p>I am looking for a reference database that can be used to test for possible name typos in a contact database. This is for a batch process, so performance isn't a real issue. Ideally I'd like a comprehensive database, but even something like "top 5000" would go a long way. </p> <p>Thanks!</p>
<p>I don't know about a database, but populating one yourself from a resource such as this <a href="http://web.archive.org/web/20081218100813/http://www.census.gov/genealogy/names/dist.all.last" rel="nofollow noreferrer">http://web.archive.org/web/20081218100813/http://www.census.gov/genealogy/names/dist.all.last</a> s...
<p>If there is no additional language information involved, this can be pretty useless. I would not spend effort on this as it probably works only on a small population procentage. </p> <p>PS: Don't forget the chinese, russian and indian names (millions)</p>
47,268
<p>I would love to start a small engraving business without having to purchase expensive hardware. </p> <p>Using scrap parts at home, or parts from broken CD players, are there any ways to make a laser engraver at home? My cousin managed to make one of his own from scraps.</p>
<p>I have a printer and a diode laser head which will etch aluminum for under $4k, but you're going to have to manage potentially noxious fumes based on what material you're lasering. It's safe if used safely: the focal distance is 15-20mm from the lens, but all present should wear PPE.</p> <p>Note: I work for Hyrel3D...
<p>If you do not have knowledge about the electronics then consider buying a cheap etching machine instead.</p> <h1>Build</h1> <p>Take a look on <a href="https://hackaday.com/" rel="nofollow noreferrer">https://hackaday.com/</a> and search for laser engravers.</p> <p>I have found following articles in few seconds:</...
1,004
<p>What are the best algorithms for recognizing structured data on an HTML page?</p> <p>For example Google will recognize the address of home/company in an email, and offers a map to this address.</p>
<p>A named-entity extraction framework such as <a href="http://gate.ac.uk/" rel="noreferrer">GATE</a> has at least tackled the <a href="http://gate.ac.uk/ie/index.html" rel="noreferrer">information extraction problem</a> for locations, assisted by a gazetteer of known places to help resolve common issues. Unless the p...
<p>Again, regular expressions should do the trick.</p> <p>Because of the wide variety of addresses, you can only guess if a string is an address or not by an expression like "(number), (name) Street|Boulevard|Main", etc</p> <p>You can consider looking into some firefox extensions which aim to map addresses found in t...
45,402
<p>My question is on the ASP.NET GridView control. I am using a CommandField in the Columns tag as seen below.</p> <pre><code>&lt;asp:CommandField ShowEditButton="True" HeaderStyle-Width="40px" UpdateText="Save" ButtonType="Link" HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-Width="40px"/&gt; </code></pre> ...
<p>If you use a template field it will give you complete control over the look of your page, but it requires that you use the CommandName and possible CommandArgument properties, and also using the GridView's OnRowCommand.</p> <p>The aspx page:</p> <pre><code>&lt;asp:GridView id="gvGrid" runat="server" OnRowCommand="...
<p>Don't use a command field, use a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx" rel="nofollow noreferrer">TemplateField</a> and put your command button in that with a line break (br) before it like you want.</p>
22,831
<p>How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel?</p> <p>Edit: A language-agnostic algorithm to determine this is the main goal here.</p>
<p>I once wrote this function to perform that exact task:</p> <pre><code>public static string Column(int column) { column--; if (column &gt;= 0 &amp;&amp; column &lt; 26) return ((char)('A' + column)).ToString(); else if (column &gt; 25) return Column(column / 26) + Column(column % 26 + 1);...
<p>I currently use this, but I have a feeling that it can be optimized.</p> <pre><code>private String GetNthExcelColName(int n) { String firstLetter = ""; //if number is under 26, it has a single letter name // otherwise, it is 'A' for 27-52, 'B' for 53-78, etc if(n &gt; 26) { //the Conve...
4,275
<p>I'm trying to get a set of reports running in an (VB) ASP.NET project and as part of that I'd like to display some charts visualising the data. I'm able to get charts generated, and have used Flotr, Plotr, Google Charts, and some CSS techniques at various times as I've experimented with this.</p> <p>Ideally, what I...
<p>a clickable image map would probably do the trick...</p> <p>...or you could just buy Dundas</p>
<p>a clickable image map would probably do the trick...</p> <p>...or you could just buy Dundas</p>
30,466
<p>I bought a few new nozzles expecting them to come with that little tube that comes out of the nozzle. They didn't come with them after all, so I tried to reuse the tube I originally had in the printer. Turns out my old tube is 4mm OD and 2mm ID, but the new nozzles have 2mm holes for the tube to go in. I use 1.75mm ...
<p>To answer your question directly, the PTFE tube (or a separate thin walled PTFE tube for the bottom part of the heatbreak) <em>generally</em> always is outside the nozzle, so yes (unless you have an all-metal hotend, then there is no PTFE tube up to the nozzle). But as read from your question, your setup has the tub...
<p>Yes, you can use a direct drive hotend with a bowden tube, but it won't just plug together. You just need a way to secure the end of the bowden tube to be centered above and as close the the hotend mouth as possible. In a pinch, you can spin a 4mm nut onto the tube and secure it down against the hotend mount with zi...
1,104
<p>I am currently trying to create a win32 service using pywin32. My main point of reference has been this tutorial:</p> <p><a href="http://code.activestate.com/recipes/551780/" rel="noreferrer">http://code.activestate.com/recipes/551780/</a></p> <p>What i don't understand is the initialization process, since the Dae...
<p>I've never used these APIs, but digging through the code, it looks like the class passed in is used to register the name of the class in the registry, so you can't do any initialization of your own. But there's a method called GetServiceCustomOption that may help:</p> <p><a href="http://mail.python.org/pipermail/p...
<p>I just create a simple "how to" where the program is in one module and the service is in another place, it uses py2exe to create the win32 service, which I believe is the best you can do for your users that don't want to mess with the python interpreter or other dependencies.</p> <p>You can check my tutorial here: ...
32,959
<p>I have an ASP.Net GridView control that I need to remain a fixed size whether there are 0 records or <em>n</em> records in the grid. The header and the footer should remain in the same position regardless of the amount of data in the grid. Obviously, I need to implement paging for larger datasets but how would I a...
<p>You may have to drop the headers and footers from the GridView altogether and add them to the page as separate table elements. You will need to make sure each table cell in the header and footer tables have fixed widths that correspond to the widths of the cells in your GridView. </p> <p>The GridView itself would p...
<p>Put grid inside div set div style as follows</p> <pre><code>&lt;div style="width:100px; height:100px; overflow:scroll;"&gt; &lt;asp:GridView ID="GridView1" runat="server"&gt; &lt;/asp:GridView&gt; &lt;/div&gt; </code></pre>
13,459
<p>does anybody know some free tool for synchronization MySQL database (data and structure) like in <a href="http://mysql.navicat.com/" rel="nofollow noreferrer">Navicat</a> for Windows ?</p> <hr> <p>I'm using Structure and Data synchronization. Sometimes Data transfer. I was just wondering if there is not any softwa...
<p><a href="http://wb.mysql.com/" rel="noreferrer">MySQL Workbench Beta</a> does this perfectly and for free for now.</p>
<p>What functionality of Navicat do you need? There is a number of ways without that software to synchronize mysql. You can use the MySQL replication functionality or simply copy and paste the data files (if your using MyISAM tables it's just a straight copy) innoDB tables are a little more tricky.</p>
47,559
<p>I've got the following PLA filament that is not feeding correctly into our Ultimaker 2+</p> <p>It starts to feed and then all of the sudden, the wire 'eats' (read <em>breaks, but not entirely</em>) the plastic filament as you can see on the picture below:</p> <p><a href="https://i.stack.imgur.com/OnQy7.jpg" rel="n...
<p>The photograph and your description indicate that the drive gear is eating the filament because the filament has stopped moving. The least likely problem would be that something is jammed at the spool or between the spool and the entry to the drive mechanism.</p> <p>The more likely problem is that your nozzle is cl...
<p>I had a clogged filament. I heated up to 240 C, and pushed a wire up through the nozzle. It took some effort, and much patience is expected. I left the wire inside, as it helped soften the PLA. Then I pushed the filament by hand from top. After some efforts, the needle moved, indicating the movement of the PLA clog...
609
<p>How would one go about deleting all of the directories in a directory tree that have a certain name if the only access to the server available is via FTP?</p> <p>To clarify, I would like to iterate over a directory tree and delete every directory whose name matches a certain string via FTP. A way to implement this...
<p>Here is a starting point- a function that will scan through an FTP directory and print the name of any directory in the tree which matches the pattern. I have tested it briefly.</p> <pre><code>function scan_ftp_dir($conn, $dir, $pattern) { $files = ftp_nlist($conn, $dir); if (!$files) { return; ...
<p>Well, this is the script I ended up using. It's a rather specific instance where one would have to use this, but if you are in the same predicament I was in, simply put in your ftp server address, username, password, the name of the folders you want deleted, and the path of the folder to start in and this will iter...
34,800
<p>I am trying to implement a request to an unreliable server. The request is a nice to have, but not 100% required for my perl script to successfully complete. The problem is that the server will occasionally deadlock (we're trying to figure out why) and the request will never succeed. Since the server thinks it is...
<p>You might try <a href="http://search.cpan.org/%7Ebradfitz/LWPx-ParanoidAgent-1.02/lib/LWPx/ParanoidAgent.pm" rel="noreferrer">LWPx::ParanoidAgent</a>, a subclass of LWP::UserAgent which is more cautious about how it interacts with remote webservers.</p> <p>Among other things, it allows you to specify a global timeou...
<p>From what I understand, the timeout property doesn't take into account DNS timeouts. It's possible that you could make a DNS lookup separately, then make the request to the server if that works, with the correct timeout value set for the useragent.</p> <p>Is this a DNS problem with the server, or something else?</p...
9,898
<p>Considering that the debug data file is available (PDB) and by using either <strong>System.Reflection</strong> or another similar framework such as <strong>Mono.Cecil</strong>, how to retrieve programmatically the source file name and the line number where a type or a member of a type is declared.</p> <p>For exampl...
<p>Up to date method:</p> <pre><code>private static void Log(string text, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0) { Console.WriteLine("{0}_{1}({2}): {3}", Path.GetFileName(file...
<p>you might find some help with these links:</p> <p><a href="http://www.busycode.com/news/index.php/article/news-about-adobe-flex/2008-09-09/1570.html" rel="nofollow noreferrer">Getting file and line numbers without deploying the PDB files</a> also found this following <a href="http://bytes.com/forum/thread348765.ht...
15,331
<p>I'm using <code>$.post()</code> to call a servlet using Ajax and then using the resulting HTML fragment to replace a <code>div</code> element in the user's current page. However, if the session times out, the server sends a redirect directive to send the user to the login page. In this case, jQuery is replacing the ...
<p>I read this question and implemented the approach that has been stated regarding setting the response <em>HTTP status code</em> to 278 in order to avoid the browser transparently handling the redirects. Even though this worked, I was a little dissatisfied as it is a bit of a hack.</p> <p>After more digging around, ...
<p>Additionally you will probably want to redirect user to the given in headers URL. So finally it will looks like this:</p> <pre><code>$.ajax({ //.... other definition complete:function(xmlHttp){ if(xmlHttp.status.toString()[0]=='3'){ top.location.href = xmlHttp.getResponseHeader('Location'); ...
24,269
<p>I have managed to create an <a href="http://docs.sencha.com/ext-js/3-4/#!/api/Ext.tree.TreeNode" rel="nofollow noreferrer">Ext.tree.TreePanel</a> that loads child nodes dynamically, but I'm having a difficult time clearing the tree and loading it with new data. Can someone help me with the code to do this?</p>
<p>From the wonderful blog of Saki an ExtJS guru.</p> <pre><code>while (node.firstChild) { node.removeChild(node.firstChild); } </code></pre> <p><a href="http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/" rel="nofollow noreferrer">http://blog.extjs.eu/know-how/how-to-remove-all-children-of-...
<blockquote> <pre><code>if (tree) { var delNode; while (delNode = tree.root.childNodes[0]) tree.root.removeChild(delNode); } </code></pre> </blockquote> <p>I don't know Ext, but I'm guessing that they have DOM abstraction that might make that easier. An equivalent in Prototype would be something like:</p> <pre><code>...
23,525
<p>I have a website form that requires a US phone number input for follow up purposes, and this is very necessary in this case. I want try to eliminate users entering junk data <em>330-000-0000</em>. I have seen some options of third parties that validate phone numbers for you, however idk if that is the best option fo...
<p>It seems to me that you're putting more effort into this than it warrants. Consider:</p> <p>If your purpose is to guard against mis-entered phone numbers, then you can probably catch well over 90% of them with just a very simple check.</p> <p>If your purpose is to try to force users to provide a valid number whet...
<p>Those parameters look pretty good to me, I might also avoid numbers starting with 911 just to be safe.</p>
21,152
<p>I recall reading, on multiple occasions and in multiple locations, that when firing the typical event:</p> <pre><code>protected virtual OnSomethingHappened() { this.SomethingHappened(this, EventArgs.Empty); } </code></pre> <p>e should be EventArgs.Empty if there are no interesting event args, not null.</p> <p...
<p>I believe the reasoning behind the NOT NULL is that when passed as a parameter, it is not expected for the method to need to potentially handle a null reference exception.</p> <p>If you pass null, and the method tries to do something with e it will get a null reference exception, with EventArgs.Empty it will not.</...
<p>I used long time "new EventArgs()" instead of "EventArgs.Empty"... I think the important is to pass something that will not cause an Null exception.</p>
22,883
<p>I am trying to extract a certain part of a column that is between delimiters.</p> <p>e.g. find foo in the following</p> <p>test 'esf :foo: bar</p> <p>So in the above I'd want to return foo, but all the regexp functions only return true|false, is there a way to do this in MySQL</p>
<p>Here ya go, bud:</p> <pre><code>SELECT SUBSTR(column, LOCATE(':',column)+1, (CHAR_LENGTH(column) - LOCATE(':',REVERSE(column)) - LOCATE(':',column))) FROM table </code></pre> <p>Yea, no clue why you're doing this, but this will do the trick.</p> <p>By performing a LOCATE, we can find the first ':'...
<p>you can use the substring / locate function in 1 command </p> <p>here is a mice tutorial:</p> <p><a href="http://infofreund.de/mysql-select-substring-2-different-delimiters/" rel="nofollow">http://infofreund.de/mysql-select-substring-2-different-delimiters/</a></p> <p>The command as describes their should look fo...
18,038
<p>How would you implement a system with the following objectives:</p> <ul> <li>Manage authentication, authorization for <strong>hundreds of thousands</strong> of <em>existing users</em> currently tightly integrated with a 3rd party vendor's application (We want to bust these users out into something we manage and mak...
<p>There is a difference between authentication and authorization/profiling so don't force both necessarily into a single tool. Your second solution of using LDAP for authentication and a DB for authorization seems more robust as the LDAP data is controlled by the user and the DB would be controlled by an admin. The ...
<p>You can always implement your own <a href="http://openid.net/what/" rel="nofollow noreferrer">OpenID</a> server. There is already a <a href="http://openidenabled.com/python-openid/" rel="nofollow noreferrer">Python library for OpenID</a> so it should be fairly easy. </p> <p>Of course you don't need to accept logins...
10,367
<p>I'm trying to include JQuery in my DotNetNuke skin by adding these two lines of code at the top of my DNN skin:</p> <pre><code>&lt;% Page.ClientScript.RegisterClientScriptInclude("jquery", "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js") Page.ClientScript.RegisterStar...
<p>Sigh. The solution is to make sure you put it in the Page_Load() method, and not the page rendering code itself. I suppose I was too late in the page lifecycle to do what I'd wanted to do.</p> <pre><code>&lt;script runat="server"&gt; Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.Even...
<p>What version of DNN are you using? DNN doesn't support including jQuery unless you're using DNN version 5. <a href="http://blog.theaccidentalgeek.com/post/2008/10/02/DotNetNuke-50-Now-with-jQuery.aspx" rel="nofollow noreferrer">See here for more information</a></p>
49,807
<p>We get an abort when a C++ exception is thrown when running code compiled with -pthread.</p> <p>Platform: AIX 5.3 technical level 8 Compiler: gcc 3.4.6 Linker: AIX linker 1.65.2.4</p> <p>Test Code:</p> <pre><code>// exception.cpp #include &lt;iostream&gt; class MyException { public: MyException(){} ...
<p>Tried your program on AIX:</p> <blockquote> <p>oslevel -r</p> <p>5200-08</p> </blockquote> <p>with g++ --version</p> <blockquote> <p>g++ (GCC) 3.3.2</p> <p>g++ -o ex -pthread ex.cpp</p> </blockquote> <p>will result in symbols not found at runtime (pthread_mutex_t)</p> <p>However if you build it like:</p> <blockquote...
<p>g++ 4.3.2 seems to work Ok for this problem. Also xlC v10 works.</p>
39,278
<p>I know this is somewhat of a server question, but I wanted to ask anyways in case someone has done this before.</p> <p>I have a web service that is on our internal 172.x.x.x subnet and a web server that is on our internal 10.x.x.x subnet. The webserver needs to hit the 172 web service, but is unable to route there...
<p>As you mentioned, the best option is to cram the web server into the DMZ. That being impossible, see if the wiremonkeys can open up the appropriate port in the firewall <em>just between the server and the web service (and just for http/https traffic)</em>. If both are impossible, I guess a proxy is possible (if the ...
<p>It is really quick and dirty, but you could use the <a href="https://tcpmon.dev.java.net/" rel="nofollow noreferrer">tcpmon</a> tool on a windows machine that has access to both networks.</p>
18,632
<p>In VisualBasic.Net When I activate a picture box and then draw something on it, it draws and then immediately goes blank. Works fine when I re-draw it, but almost always messes up the first time I draw on it. This has happenned with several different programs, and the help file is no help.</p>
<p>Try setting the <code>DoubleBuffered</code> property</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx</a></p> <p>If that's not it, please provi...
<p>Thank you Andrew, but no help. I'm using .Net Framework 1.1, which does not offer the DoubleBuffered property... it was new in 2.0.</p> <p>Not sure what additional info to provide.. the code is 300 lines long. When a button is clicked, the code expands my form, makes two picture boxes visible (one on top of the o...
44,883
<p>I need help finding resources that would help me or at least point me in the right direction in building a Flash media server/PHP application. I basically want to improve my current application by instead of progressive download using flash media server so that the videos will not only stream well but they can't be ...
<p>Really, PHP and FMS shouldn't be talking at all. It can be done within FMS, but a much easier approach is to let your Flash Player (which you'll have to have anyway) do the talking to FMS. Flash to FMS communication is well documented and very easy. Just have the PHP call forth a Flash video player with whatever inf...
<blockquote> <p>Using flash media server so that the videos will not only stream well but they can't be downloaded by the end user</p> </blockquote> <p>This won't really work. It make make it "harder" for some people in the same way that not putting a big, huge "<strong>download here</strong>" button makes it ...
40,619
<p>What is the best way to sort the results of a sql query into a random order within a stored procedure?</p>
<p>This is a duplicate of <a href="https://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql">SO# 19412</a>. Here's the answer I gave there:</p> <pre><code>select top 1 * from mytable order by newid() </code></pre> <p>In SQL Server 2005 and up, you can use TABLESAMPLE to get a random sample that's ...
<p>You can't just ORDER BY RAND(), as you know, because it will only generate one value. So use a key for a seed value.</p> <pre> SELECT RAND(object_id), object_id, name FROM sys.objects ORDER BY 1 </pre>
7,632
<p>I'm using Pyglet(and OpenGL) in Python on an application, I'm trying to use glReadPixels to get the RGBA values for a set of pixels. It's my understanding that OpenGL returns the data as packed integers, since that's how they are stored on the hardware. However for obvious reasons I'd like to get it into a normal ...
<p>You must first create an array of the correct type, then pass it to glReadPixels:</p> <pre><code>a = (GLuint * 1)(0) glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_INT, a) </code></pre> <p>To test this, insert the following in the Pyglet "opengl.py" example:</p> <pre><code>@window.event def on_mouse_press(x, y, but...
<p>If you read the snippet you link to you can understand that the simplest and way to get the "normal" values is just accessing the array in the right order.<br> That snippet looks like it's supposed to do the job. If it doesn't, debug it and see what's the problem.</p>
47,987
<p>Is there a way to spawn a new window via javascript in IE7 that hides the statusbar?</p> <p>I've added the intranet app as a trusted site. Not sure what else I can use to try. This is my JS</p> <pre><code>window.open("http:/localhost/start.html", "MyApp", "left=0, top=0, width=" + screen.width + "," + ...
<p><strong>No.</strong> Microsoft decided that <strong>"in the name of security"</strong> (<a href="http://blogs.msdn.com/ie/archive/2006/08/25/719355.aspx" rel="nofollow noreferrer">IE Blog Link</a>) they would force the status bar to show on popup windows in IE7. (they also force a new minimum width of ~250px instea...
<p>Your code worked for me, <a href="http://img511.imageshack.us/my.php?image=workshq7.png" rel="nofollow noreferrer">and here's a screenshot.</p> <p>Example of how IE7 renders popup without status bar. http://img511.imageshack.us/img511/7757/workshq7.th.png</a></p> <p>Note that experment was done on local filesystem...
26,713
<p>I'm trying to re-install a DLL in the GAC, everything seems to work fine but the web application accessing it still seems to be using the old one.</p> <p>The old DLL is the same version as the new one with only a minor edit, it will be used by 50 different sites so changing the version then changing the reference i...
<p>AFAIK, you need to restart IIS for it to get a fresh reference to the updated DLL. Your best bet is to perform the reset at a low traffic time. If you are running multiple servers with load balancing, you can prevent new connections from hitting one server until all connections have been closed. Afterwards, updat...
<p>Since you don't make a reference to application pools, I'm going to assume you are on the old version of IIS. In that case, what you'll need to do is to "touch" all the DLLs in each site that references the DLL. </p> <p>The problem is that the code is already loaded and you need to find a non-intrusive way to r...
4,625
<p>im just wondering about data contracts to be sent over the wire in WCF communication. i know for the sake of interoperability it is not advisable (maybe not even allowed?) to send native .NET types as part of a data contract.</p> <p>I wish to have a service which accepts, as an input to a <code>ServiceOperation</co...
<p>You will need to add the [XmlSerializerFormat] attribute.</p> <p>So (without using Datacontract although you can use that too):</p> <p>[ServiceContract(Namespace = "urn:SerializationTest")]</p> <p>[XmlSerializerFormat]</p> <p>public interface IBlah</p> <p>{</p> <p>[OperationContract]</p> <p>XmlDocument Return...
<p>Pass a string would be better for interop, but if you want to pass CLR data types you can look into marking up your classes with the KnownType attribute.</p>
39,722
<p>The point of const-correctness is to be able to provide a view of an instance that can't be altered or deleted by the user. The compiler supports this by pointing out when you break constness from within a const function, or try to use a non-const function of a const object. So without copying the const approach, is...
<p>I've come across this issue a lot of times too and ended up using interfaces.</p> <p>I think it's important to drop the idea that C# is any form, or even an evolution of C++. They're two different languages that share almost the same syntax.</p> <p>I usually express 'const correctness' in C# by defining a read-onl...
<ul> <li>The <strong>const</strong> keyword can be used for compile time constants such as primitive types and strings</li> <li>The <strong>readonly</strong> keyword can be used for run-time constants such as reference types</li> </ul> <p>The problem with <strong>readonly</strong> is that it only allows the reference ...
13,932
<h2>Scenario</h2> <p>I have two wrappers around Microsoft Office, one for 2003 and one for 2007. Since having two versions of Microsoft Office running side by side is "not officially possible" nor recommended by Microsoft, we have two boxes, one with Office 2003 and the other with Office 2007. We compile the wrappers ...
<p>When the .NET assembly resolver is unable to find a referenced assembly at runtime (in this case, it cannot find the particular wrapper DLL version the application was linked against), its default behavior is to fail and essentially crash the application. However, this behavior can be overridden by hooking the AppDo...
<p>Nice sleuthwork! I just threw together an implementation based on the concept presented above, and it works wonderfully:</p> <pre><code>static Assembly domain_AssemblyResolve(object sender, ResolveEventArgs args) { string partialName = args.Name.Substring(0, args.Name.IndexOf(',')); return Assembly.Load(...
35,062
<p>I have to develop an application using C#.net that has to be run once a day. It only runs for at most one minute, so developing a Windows service is overkill and a scheduled task is the appropriate way.</p> <p>However, I have a few questions about how the application can communicate its results:</p> <ul> <li>How d...
<p>In answer to your questions -</p> <ol> <li><p>If a task fails because it threw an unchecked exception you'll see that in the Sheduled Task viewer, there will be a 'Last Result' with a value something like <code>0xe0434f4d</code>. Alternatively if you return an exit code that will be also be shown in the Last Result...
<p>AFAIK the scheduler just kicks off a process. You can use the event log or another logging system to record the information you need to refer to later.</p>
20,897
<p>Please take a look at the html listed below and let me know why IE6 freezes when trying to load the remote script (located at '<a href="http://code.katzenbach.com/Default.aspx" rel="nofollow noreferrer">http://code.katzenbach.com/Default.aspx</a>'). The script returns JSONP and executes the 'callbackFunction' liste...
<p>I took a look with Fiddler and IE6 and was unable to see anything out of the ordinary (besides the fact that it freezes the browser).</p> <p>The request to <code>http://code.katzenbach.com/Default.aspx?callback=callbackFunction&amp;test=true&amp;c=500</code> does get made and returns 2909 bytes.</p> <p>I'd suggest...
<p>The return is of the external script is:</p> <pre><code>callbackFunction(["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","5...
22,391
<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; CurrentCustome...
<p>a trivial example, yes, but with all the basic elements - they just belong in 3 different classes (see below). The main reason for this is the "separation of concerns" principle, i.e. the GUI is only concerned with GUI things, the Biz Logic layer is only concerned with the business rules, and the data-access layer i...
<p>What is the purpose of the button?</p> <p>My first steps would be:</p> <ul> <li>extract the part accessing the database. (warning: air code ahead)</li> </ul> <pre><code>function getCustomer(CurrentCustomerID as Long) strSQL = "select * from tblCustomers where ID = " &amp; CurrentCustomerID set rec1 = GlobalDataB...
28,189
<p>I would like to have a Java component which has a resize icon on the bottom right of the component so that when I drag that icon, the component will automatically resize with it.</p> <p>By resize icon, I mean the following:</p> <p><img src="https://lh5.ggpht.com/_7dfPdX2BP6o/SQ_sPvvHpTI/AAAAAAAAAKU/vRWKb_pLVvc/s14...
<p>You will find in this article how to add an icon looking like the resize icon you are referring to.</p> <p><img src="https://i.stack.imgur.com/uyYo4.gif" alt="PixelPushing"> <a href="http://today.java.net/pub/a/today/2005/06/07/pixelpushing.html" rel="nofollow noreferrer">PixelPushing</a></p> <p><img src="https://...
<p>the JStatusBar ?</p>
32,640
<p>Is there a real way to get Netbeans to load and work faster?</p> <p>It is too slow and gets worse when you have been coding for some time. It eats all my RAM.</p> <hr> <p>I am on a Windows machine, specifically Windows Server 2008 Datacenter Edition x64, 4Gb of RAM, 3Ghz Core 2 Duo processor, etc. I am using the ...
<p>Don't invest time in optimizing your NB installation as long as you can scale vertically: get a SSD (and faster hardware in general).</p> <p>Also:</p> <ul> <li>Add an exception for all relevant folders (e.g. project dir, temp dir) to your anti virus software (or better, get rid of it). </li> <li>Don't use network ...
<p>Verify if your project folder has a folder that contains files of your framework, or libraries (Ex.: The Laravel has a folder vendor) - files that you not use directly. Click on your "project" > properties. In left side, select "ignore folders" (I don't no how is in english, but is before 'Frameworks'). In right sid...
28,443
<p>What are your usage of delegates in C#?</p>
<p>Now that we have lambda expressions and anonymous methods in C#, I use delegates much more. In C# 1, where you always had to have a separate method to implement the logic, using a delegate often didn't make sense. These days I use delegates for:</p> <ul> <li>Event handlers (for GUI and more)</li> <li>Starting threa...
<ol> <li><p>For event handler</p></li> <li><p>To pass method in a method parameters</p></li> </ol>
23,208
<p>What exactly is the difference between the <code>window.onload</code> event and the <code>onload</code> event of the <code>body</code> tag? when do I use which and how should it be done correctly?</p>
<p><code>window.onload = myOnloadFunc</code> and <code>&lt;body onload="myOnloadFunc();"&gt;</code> are different ways of using <strong>the same event</strong>. Using <code>window.onload</code> is less obtrusive though - it takes your JavaScript out of the HTML.</p> <p>All of the common JavaScript libraries, Prototype...
<p>They both work the same. However, note that if both are defined, only one of them will be invoked. I generally avoid using either of them directly. Instead, you can attach an event handler to the load event. This way you can incorporate more easily other JS packages which might also need to attach a callback to the ...
23,209
<p>What should every WPF developer know?</p> <p><strong>Entry Level</strong></p> <ul> <li>Strong .NET 2.0 Background &amp; willing to learn!</li> <li>Explain dependency properties?</li> <li>What's a style?</li> <li>What's a template?</li> <li>Binding</li> <li>Differences between base classes: Visual, UIElement, Frame...
<p>I'd put binding and converters at entry level, since that is how you spend a lot of time in WPF.</p>
<p>I think lifecycle of WPF application - from creation to runtime should be included in the Beginner level of questions. Without knowing it, its hard to believe one is a real WPF dev.</p>
8,316
<p>I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to be on the same line as the declaration. If you have any suggestions to improve my regex or simply have a better one then please submit an answer...
<pre><code>(public|protected|private|static|\s) +[\w\&lt;\&gt;\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;]) </code></pre> <p>I think that the above regexp can match almost all possible combinations of Java method declarations, even those including generics and arrays are return arguments, which the regexp provided by the ori...
<p>I built a vim regex to do this for <a href="https://github.com/pydave/ctrlp-funky/blob/master/autoload/ctrlp/funky/java.vim" rel="nofollow">ctrlp/funky</a> based on Georgios Gousios's answer.</p> <pre><code> let regex = '\v^\s+' " preamble let regex .= '%(&lt;\w+&gt;\s+){0,3}' " visibility...
9,418
<p>What techinques do you use? How do you find out which jobs take the longest to run? Is there a way to find out the offending applications?</p>
<p>Step 1: Install the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=1d3a4a0d-7e0c-4730-8204-e419218c1efc&amp;displaylang=en" rel="nofollow noreferrer">SQL Server Performance Dashboard</a>.</p> <p>Step2: Profit.</p> <p>Seriously, you do want to start with a look at that dashboard. More about insta...
<p>I use a few different techniques.</p> <p>If you're trying to optimize a specific query, use Query Analyzer. Use the tools in there like displaying the execution plan, etc.</p> <p>For your situation where you're not sure WHICH query is running slowly, one of the most powerful tools you can use is SQL Profiler.</p>...
27,965
<p>When I started programming I was using Ruby and the colorful little notepad that came with it. Since I started learning Java I've been using Eclipse, which is apparently an IDE. Now I've read a bit about this Mono on Reddit, but I don't think I understand exactly what it is. The website says it is a development fram...
<p>a framework is a set of classes and supporting code to be used to build applications. this can be as simple as the C standard library or as complex as the Smalltalk environment, or may even include the infrastructure for complex application like Dynamic or ERP systems - but essentially a framework is just a class li...
<p>Now I've always liked this analogy:</p> <ul> <li>Class libraries: mom&amp;pop shops that you get in and get out after you get what you need. </li> <li>Frameworks: those big supermarkets like Wallmart that sucks you into their existence and make you dependant on theirselves.</li> </ul> <p>IDE's are another issue an...
34,966
<p>In SQL Server what is the simplest/cleanest way to make a datetime representing the first of the month based on another datetime? eg I have a variable or column with 3-Mar-2005 14:23 and I want to get 1-Mar-2005 00:00 (as a datetime, not as varchar)</p>
<pre><code>Select DateAdd(Month, DateDiff(Month, 0, GetDate()), 0) </code></pre> <p>To run this on a column, replace GetDate() with your column name.</p> <p>The trick to this code is with DateDiff. DateDiff returns an integer. The second parameter (the 0) represents the 0 date in SQL Server, which is Jan 1, 1900. ...
<p>Just use</p> <pre><code>DATEADD(DAY, 1-DAY(@date), @date) </code></pre>
14,781
<p>It seems that the choice to use string parsing vs. regular expressions comes up on a regular basis for me anytime a situation arises that I need part of a string, information about said string, etc.</p> <p>The reason that this comes up is that we're evaluating a soap header's action, <strong>after</strong> it has b...
<p>My main guideline is to use regular expressions for throwaway code, and for user-input validation. Or when I'm trying to find a specific pattern within a big glob of text. For most other purposes, I'll write a grammar and implement a simple parser.</p> <p>One important guideline (that's really hard to sidestep, tho...
<p>I would always use a regex unless it's something <em>very</em> simple such as splitting a comma-separated string. If I think there's a chance the strings might one day get more complicated, I'll probably start with a regex.</p> <p>I don't subscribe to the view that regexes are hard or complicated. It's one tool tha...
46,660
<p>What Abstract Datatypes should be added to OpenJDK7 ?</p>
<p>If you look at these two links you will see what some people feel is missing:</p> <ul> <li><a href="http://commons.apache.org/collections/" rel="nofollow noreferrer">http://commons.apache.org/collections/</a></li> <li><a href="http://code.google.com/p/google-collections/" rel="nofollow noreferrer">http://code.googl...
<p>I think they should stop adding new libraries to the JDK. You can easily get what you need from third-party, open-source libraries. Hopefully, with version 7 the JVM and its standard libraries will become more modular.</p>
19,446
<p>Given a string S, what is the best algorithm to find a substring which repeats maximum number of times.</p> <p>For example, in "assdssfssd", it is "ss" which repeats maximum number of times.</p>
<p>I can see building a tree to solve that particular problem.</p> <p>There is a notional root node. The first character is the first child. The second character is a child of the first character a -> s in your case. It also begins a new leaf of the root node. If, in adding a node, you visit an existing node, you ...
<pre><code>// C# code, finds one of the most occurred non-empty substrings in O(n), proof by the reader! int[] x = new int[65536]; foreach (char c in myString) x[(int)c]++; int max = 0; for (int i = 0; i &lt; x.Length; ++i) if (x[max] &lt; x[i]) max = i; return ((char)max).ToString(); </code></pre> <p...
49,499
<p>I'm looking to have a simple custom dialog box, like a message box, that has a label and a TextBox. If there's a simple way to do this, sorry! I'm really not well versed in the dialog stuff. </p> <p>Thanks for any help, guys!</p>
<p>Here is how to make a small custom dialog box in Windows Mobile that looks like this:</p> <p><a href="http://www.freeimagehosting.net/uploads/b8fb5421d6.jpg">alt text http://www.freeimagehosting.net/uploads/b8fb5421d6.jpg</a></p> <p>Add a form to your project, and set its FormBorderStyle property to None. This al...
<p>I'm assuming you basically want a custom dialog box that returns a string entered by the user. One way is to add a reference to Microsoft.VisualBasic to your project, which gives you access to the InputBox method, which is basically a message box with a text box on it. But that's no fun and I'm not sure it would w...
38,878
<p>I need to know what internet connection is available when my application is running. I checked out the Reachability example from Apple, but this differs only between wifi and carrier network. What I need to know is what carrier network is selected, UMTS or EDGE or GPRS.</p>
<p>Currently, this information is not available. If you want this feature, file a new bug and mention that this is a duplicate of bug 6014806.</p>
<p>Rather than hardcoding different versions of your site for 3G, EDGE, GPRS, wifi broadband, why not build a framework which detects connection speed and bootstraps your site up to the appropriate level of bandwidth? That way you would get appropriate results on slow 3G / wifi, and it would naturally scale to the next...
21,532
<p>I'm looking at some GXT code for GWT and I ran across this use of Generics that I can't find another example of in the Java tutorials. The class name is <a href="http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/data/BaseModelData.html" rel="noreferrer"><code>com.extjs.gxt.ui.client.data.BaseModelData</code></...
<p>The method returns a type of whatever you expect it to be (<code>&lt;X&gt;</code> is defined in the method and is absolutely unbounded).</p> <p>This is very, very dangerous as no provision is made that the return type actually matches the returned value.</p> <p>The only advantage this has is that you don't have to...
<p>Yes, this is dangerous. Normally, you'd protect this code like so:</p> <pre><code>&lt;X&gt; getProperty(String name, Class&lt;X&gt; clazz) { X foo = (X) whatever(name); assert clazz.isAssignableFrom(foo); return foo; } String getString(String name) { return getProperty(name, String.class); } int getInt...
44,001
<p>For a school project, I need to create a way to create personnalized queries based on end-user choices.<br /> Since the user can choose basically any fields from any combination of tables, I need to find a way to map the tables in order to make a join and not have extraneous data (This may lead to incoherent report...
<p>An analysis of the various options available, and the pros and cons of each is available in Jeanne Boyarsky's <em><a href="http://www.javaranch.com/journal/200510/Journal200510.jsp#a2" rel="nofollow noreferrer">Batching Select Statements in JDBC</a></em> entry on JavaRanch Journal.</p> <p>The suggested options are:<...
<p>My workaround (JavaScript)</p> <pre><code> var s1 = " SELECT " + "FROM table t " + " where t.field in "; var s3 = '('; for(var i =0;i&lt;searchTerms.length;i++) { if(i+1 == searchTerms.length) { s3 = s3+'?)'; } else { s3 = s3+'?, ' ; } } var query = s1...
21,512
<p>Is it possible to have multiple listeners to messages carried by MSMQ?</p> <p>WCF appears to frame everything in terms of services, making communication a point-to-point affair. I want to use a message queue to buffer incoming traffic for another process that records the logs in a database. </p> <p>There can be be...
<p>I don't believe MSMQ is appropriately designed to handle this situation by itself. There are only 2 things you can do to a message - Peek() or Get(). AFAIK, there isn't a good way to track whether a message had been processed by all handlers. </p> <p>What might work is to have your process that transcribes the mess...
<p>I think you need a <a href="http://www.enterpriseintegrationpatterns.com/PublishSubscribeChannel.html" rel="nofollow">Publish-Subscribe Channel</a>:</p> <blockquote> <p><strong>How can the sender broadcast an event to all interested receivers?</strong> <em>Send the event on a Publish-Subscribe Channel, which de...
30,885
<p>Apparently we use the Scrum development methodology. Here's generally how it goes: </p> <p>Developers thrash around trying to accomplish their tasks. Generally the tasks take most of the sprint to complete. QA pesters Dev to release something they can test, Dev finally throws some buggy code out to QA a day or two ...
<p>My opinion is that you have an estimation problem. It seems that the time to test each feature is missing, and only the building part is being considered when planning the sprint. </p> <p>I'm not saying it is an easy problem to solve, because it is more common than anything. But things that could help are:</p> <ul...
<p>Here I would say that, One size does not fit all. Every team deals QA differently. It so much depends on the project you are working on, either it's a small one or big one. Does it need extensive regression, User acceptance and exploratory testing or you have quite few scenarios to test. Let me restate that in Agile...
18,773
<p>I am trying to send an email from a site I am building, but it ends up in the yahoo spam folder. It is the email that sends credentials. What can I do to legitimize it?</p> <pre><code>$header = "From: site &lt;sales@site.com&gt;\r\n"; $header .= "To: $name &lt;$email&gt;\r\n"; $header .= "Subject: $subject\r\n"; $h...
<ul> <li>Don't use HTML in your email.</li> <li>Send it via a legitimate mail server with a static IP and reverse-DNS (PTR) that points to the machine's real host name (and matches a forward lookup).</li> <li>Include a Message-ID (or ensure that the local mailer adds one for you).</li> <li>Run your email through <a hre...
<p>Check rfc 822 and rfc 2045 for email format. I find python's Email class really easy to work with. I assume php's PEAR does the same (according to earlier mails). Also the header and the body are separated by a "\r\n\r\n", not sure if your code automatically inserts that, but you can try appending that to the header...
19,463
<p>In my previous research for mods for my Ender 3v2, I came across the topic of part cooling mods. The two most common are the Petsfang and Hero Me sets.</p> <ol> <li><p>What are the pros and cons of third-party/DIY part cooling mods?</p> </li> <li><p>What benefit does having a third-party/DIY part cooling mod provide...
<p>Cooling duct design is not well understood by either the 3D printer OEMs (exceptions may apply) nor by the aftermarket cooling options or most of the homebrew designs.</p> <p>The problem is the lack of the understanding in aerodynamic design. Note that the fans that we use to produce the cooling flows are pushing f...
<p>Part cooling is essential to print at any decent <em>vertical speed</em> (layers per second), which is critical if you do rapid prototyping of small parts or vase mode prints. This is because you can't (repeatedly) print on top of material that hasn't yet cooled enough to be rigid; if you do, after a few layers, you...
2,132
<p>We have a couple of applications running on Java 5 and would like now to bring in an application based on Java 6. Can both java versions live together under Windows? </p> <p>Is there any control panel to set the appropriate Java version for different applications, or any other way to set up, what version of Java wi...
<p>Of course you can use multiple versions of Java under Windows. And different applications can use different Java versions. How is your application started? Usually you will have a batch file where there is something like </p> <pre><code>java ... </code></pre> <p>This will search the Java executable using the PATH...
<p>Using Java Web Start, you can install multiple JRE, then call what you need. On win, you can make a .bat file:</p> <p>1- online version: &lt;<em>your_JRE_version</em>\bin\javaws.exe> -localfile -J-Djnlp.application.href=&lt;<em>the url of .jnlp file</em>.jnlp> -localfile -J "&lt;<em>path_temp_jnlp_file_</em>.jnlp>"...
34,162
<p>In C# language when you refer to an array element you can write:</p> <p>myclass.my_array['element_name'] = new Point(1,1);</p> <p>I think about refering to a element with name element_name by using dot in place of backets:</p> <p>myclass.my_array.element_name = new Point(1,1);</p> <p>Do you know any language whe...
<p>You could almost certainly do this in any dynamic language, by handling property/variable access as an indexer if the specified property/variable didn't actually exist. I suspect that many dynamic languages already provide this functionality in some areas.</p> <p>It's possible that in C# 4 you'll be able to make yo...
<p>Maybe you are looking for a class or struct if you you want to use the element name as a field/property.</p>
42,832
<p>I'm using a FullTextSqlQuery in SharePoint 2007 (MOSS) and need to order the results by two columns:</p> <pre><code>SELECT WorkId FROM SCOPE() ORDER BY Author ASC, Rank DESC </code></pre> <p>However it seems that only the first column from ORDER BY is taken into account when returning results. In this case the res...
<p>Microsoft <em>finally</em> posted a knowledge base article about this issue.</p> <p>"When using RANK in the ORDER BY clause of a SharePoint Search query, no other properties should be used"</p> <p><a href="http://support.microsoft.com/kb/970830" rel="nofollow noreferrer">http://support.microsoft.com/kb/970830</a><...
<p>I have no experience in SharePoint, but if it is the case where only one ORDER BY clause is being honored I would change it to an expression rather than a column. Assuming "Rank" is a numeric column with a maximum value of 10 the following may work:</p> <pre><code>SELECT WorkId FROM SCOPE() ORDER BY AUTHOR + (10 - ...
11,723
<p>I know this is a subjective question, but why does Hibernate seem to be designed for short lived sessions? Generally in my apps I create DAOs to abstract my data layer, but since I can't predict how the entity objects are going to be used some of its collections are lazy loaded, or I should say fail to load once th...
<p>Becuase once you move out of your transaction boundary you can't hit the database again without starting a new transaction. Having long running transactions 'just in case' is a bad thing (tm). </p> <p>I guess you want to lazy load object from your view - take a look <a href="http://www.hibernate.org/43.html" rel="n...
<p>Connections are a scarce resource that need to be recycled as soon as you are done using them. If you are also using connection pooling, getting another one when you need it should be quick. This is the architecture that you have to use to make websites scale -- even though you are a desktop app, their use-cases p...
15,145
<p>I have a master / detail table and want to update some summary values in the master table against the detail table. I know I can update them like this:</p> <pre><code>update MasterTbl set TotalX = (select sum(X) from DetailTbl where DetailTbl.MasterID = MasterTbl.ID) update MasterTbl set TotalY = (select sum(Y) fr...
<p>Try this:</p> <pre><code> Update MasterTbl Set TotalX = Sum(D.X), TotalY = Sum(D.Y), TotalZ = Sum(D.Z) From MasterTbl M Join DetailTbl D On D.MasterID = M.MasterID </code></pre> <p>Depending on which database you are using, if that doesn't work, then try this (this is non-standard SQL but ...
<p>If your DB supports it, concatenating all 3 updates into one sql string will save on server-round-trips if querying over the LAN. So if nothing else works, this might give you a slight improvement. The typical 'multi-statement delimiter is the semi-colon, eg:</p> <pre><code>'update x....;update y...;update...z' </c...
36,782
<p>I want to call a web service, but I won't know the url till runtime.</p> <p>Whats the best way to get the web reference in, without actually committing to a url.</p> <p>What about having 1 client hit the same web service on say 10 different domains?</p>
<p>Create the web reference, and convert the web service to a dynamic web service. A dynamic web service allows you to modify the Url.</p> <p>You need to create the web reference now to ensure your application understands the interfaces available. By switching to a dynamic web service you can then modify the .Url prop...
<p>you could call your web service by a simple http Request: Example:</p> <p><a href="http://serverName/appName/WSname.asmx/yourMethod" rel="nofollow noreferrer">http://serverName/appName/WSname.asmx/yourMethod</a>? param1=val1&amp;param2=val2;</p> <p>if you call via Http, http response will be serialized result.</p...
15,274
<p>I've been looking for the answer for how to use BSWAP for lower 32-bit sub-register of 64-bit register. For example, <code>0x0123456789abcdef</code> is inside RAX register, and I want to change it to <code>0x01234567efcdab89</code> with a single instruction (because of performance).</p> <p>So I tried following inli...
<p>Ah, yes, I understand the problem now:</p> <p>the x86-64 processors <em><a href="http://www.x86-64.org/documentation/assembly.html" rel="noreferrer">implicitly zero-extend</a></em> the 32-bit registers to 64-bit when doing 32-bit operations (on %eax, %ebx, etc). This is to maintain compatibility with legacy code t...
<p>Check the assembly output generated by gcc! Use the <code>gcc -s</code> flag to compile the code and generate asm output.</p> <p>IIRC, x86-64 uses 32-bit integers by default when not explicitly directed to do otherwise, so this may be (part of) the problem.</p>
21,315
<p>There is another recent Project Euler question but I think this is a bit more specific (I'm only really interested in PHP based solutions) so I'm asking anyway.</p> <p><a href="http://projecteuler.net/index.php?section=problems&amp;id=5" rel="nofollow noreferrer">Question #5</a> tasks you with: "What is the smalles...
<p>Collect prime factors for all numbers between 1 and 20. Counting the maximal exponents of each prime factor, we have <code>16 = 2**4</code>, <code>9 = 3**2</code>, as well as 5, 7, 11, 13, 17, 19 (each appearing only once). Multiply the lot, and you have your answer.</p>
<p>I know you said PHP, but here's my rough draft in Python.</p> <pre><code>#!/usr/bin/env python from operator import mul def factor(n): factors = {} i = 2 while i &lt; n and n != 1: while n % i == 0: try: factors[i] += 1 except KeyError: f...
23,520
<p>What is a good regular expression that can validate a text string to make sure it is a valid Windows filename? (AKA not have <code>\/:*?"&lt;&gt;|</code> characters).</p> <p>I'd like to use it like the following:</p> <pre><code>// Return true if string is invalid. if (Regex.IsMatch(szFileName, "&lt;your regex stri...
<p>As answered already, GetInvalidFileNameChars should do it for you, and you don't even need the overhead of regular expressions:</p> <pre><code>if (proposedFilename.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) != -1) { MessageBox.Show("The filename is invalid"); return; } </code></pre>
<p>Why not using the System.IO.FileInfo class, together with the DirectoryInfo class you have a set of usefull methods. </p>
12,522
<p>I am developing a wrapper for a third party function library that is interfacing with some special hardware. So basically, I want to encapsulate the dll functions (<code>bool Connect()</code>, <code>void Disconnect()</code> etc) in a MyHardwareObject with connect- and disconnect methods.</p> <p>The Connect function...
<p>It's really difficult to choose wisely between exceptions and return codes. It depends on a lot of things, and how errors are handled in the rest of your codebase would be the most important one - stay consistent.</p> <p>Lately, I'm leaning more towards the "don't throw an exception if it's not worth it". Our excep...
<p>I believe the principle behind the exception mechanism is the "<strong>fail fast</strong>" theory.</p> <p>Do you want your client's application to "fail fast" is the connection is unsuccessful ?<br> If yes, just throw back the exception or encapsulate the exception in an applicative exception of your own.</p> <p>I...
43,733