instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>What are some strategies to achieve code separation in AJAX applications?</p> <p>I am building a PHP application that I would like to have a nice AJAX front end on. I have long since learned to use some kind of templating in my PHP code to make sure I maintain good separation between my logic and display code, but...
<ul> <li>write your templates in the HTML page, probably within a hidden element.</li> <li>fetch data via AJAX calls, i find easier to use JSON, so you don't have to 'reformat' XML, it's only data.</li> <li>apply the template to the data to generate HTML and insert into the displayed page.</li> </ul> <p>check some jQu...
<p>If I correctly understand the question, you're having a lot of HTML/javascript in same code block, and you want to separate them.</p> <p>I would use several tricks to have a clean separation:</p> <ul> <li>One JS file containing scripts/functions per actions group. </li> <li>One JS file containing all common functi...
33,742
<p>is there any support in Mac OS X for signing data using smartcards? I have looked through the system headers and found only vauge references to smart card support (in SecKeychain.h), which didn't really take me anywhere.</p> <p>If there's no built-in support, which are my options (ie. what free/non-free libraries e...
<p>The <a href="http://lists.apple.com/mailman/listinfo/apple-cdsa" rel="nofollow noreferrer" title="Apple-CDSA mailing list">Apple-CDSA mailing list</a> is probably the best place to ask this; CDSA stands for Common Data Security Architecture, which includes all of the security/keychain/signing infrastructure on Mac O...
<p>I'm answering my own question here, for reference. The <a href="http://www.opensc-project.org/" rel="nofollow noreferrer">OpenSC</a> libraries provides everything you need to deal with smartcards, and it is cross-platform (Windows, Linux and Mac), and its license is good for commercial projects.</p>
44,668
<p>...I want to Show the 'delete' button when user is an admin, and show the 'add item' button when user is a contributor:</p> <pre><code>&lt;!-- More code above --&gt; &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /&gt; &lt;asp:TemplateField ShowHeader="F...
<p>Try setting it in code behind, instead of in mark up, in Page_Load. Assuming the id is promptTable (it wasn't given in your example), just add:</p> <pre><code>promptTable.Visible = User.IsInRole(@"DOMAIN\CMDB_CONTRIBUTE"); </code></pre> <p>Presumably this needs to be done regardless of whether it is a postback o...
<p>Try:</p> <pre><code>Visible='&lt;%= User.IsInRole(@"DOMAIN\CMDB_CONTRIBUTE") %&gt;' </code></pre> <p>The asp:table doesn't appear to be databound.</p>
30,397
<p>I wrote a simple javascript image rotator which picks a random image on each page load. The issue is that if i use a default image, that default image will show up for a second before the javascript loads and replaces it. Obviously if someone has javascript disabled i want them to see an image. How can i have a def...
<p>It sounds like you want to change the page HTML before window.onload fires (because at that point the default image has been displayed already).</p> <p>You need to attach your javascript function to a "DOMContentLoaded" or commonly called domready event. Dean Edwards provided us a fantastic cross-browser implementa...
<p>If you hide the default image as the first thing you do when the page loads, there probably won't be a chance for the users to see the image. You can then install an onload handler on the image and change its source to your random image. When the image loads, you can unhide the image.</p> <pre><code>window.onload =...
27,189
<p>Let's say that I have a widget that displays summary information about how many posts or comments that I have on a site.</p> <p>What's the cleanest way to persist this information across controllers? </p> <p>Including the instance variables in the application controller seems like a bad idea. Having a before filte...
<p>Presumably, you have a single partial that displays this info. You can put the methods that fetch the data you need in ApplicationHelper or as class methods on whatever model(s) you're getting the data from. Then call that method in the partial when you need to display it.</p>
<p>I wound up doing something similar to this:</p> <p>In controllers/application.rb</p> <pre><code>def load_sidebar @posts = Post.find(:all) end </code></pre> <p>To include the sidebar in various actions I did this:</p> <pre><code>before_filter :load_sidebar, :only =&gt; [ :index ] #load from application.rb file ...
15,121
<p>A voice recorder doesn't need uncompressed Linear PCM audio. Compressed <code>AMR</code> would do fine. The iPhone framework built for recording audio is simple enough, but the only examples I've found for setting up the audio format (which come from Apple) use LinearPCM. I've tried various other combinations of ...
<p>AMR codec is NOT supported for encoding/recording on the iPhone, albeit it is supported for playback: this is the reason the kAudioFormatAMR constant exists.</p> <p><a href="http://developer.apple.com/library/ios/#qa/qa1615/_index.html" rel="nofollow noreferrer">Official api</a> says that supported encoding formats...
<p>You can record audio to a uncompressed Linear PCM buffer (circular or ring), and, in another thread, convert data in this buffer, using your own AMR (or other) compression engine, before saving the compressed audio data to a file.</p>
34,886
<p>How can I elegantly print the date in RFC822 format in Perl?</p>
<pre><code>use POSIX qw(strftime); print strftime("%a, %d %b %Y %H:%M:%S %z", localtime(time())) . "\n"; </code></pre>
<p>Just using <code>POSIX::strftime()</code> has issues that have already been pointed out in other answers and comments on them:</p> <ul> <li>It will not work with MS-DOS aka Windows which produces strings like &quot;W. Europe Standard Time&quot; instead of &quot;+0200&quot; as required by <a href="https://www.rfc-edi...
20,741
<p>I wanted to deserialize an XML message containing an element that can be marked <code>nil="true"</code> into a class with a property of type <code>int?</code>. The only way I could get it to work was to write my own <code>NullableInt</code> type which implements <code>IXmlSerializable</code>. Is there a better way t...
<p>I think you need to prefix the nil="true" with a namespace in order for XmlSerializer to deserialise to null. </p> <p><a href="http://msdn.microsoft.com/en-us/library/ybce7f69(VS.80).aspx" rel="noreferrer">MSDN on xsi:nil</a></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;entities xmlns:xsi="http:...
<p>The exceptionally lazy way to do it. It's fragile for a number of reasons but my XML is simple enough to warrant such a quick and dirty fix.</p> <pre><code>xmlStr = Regex.Replace(xmlStr, "nil=\"true\"", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\""); </code></pre>
39,478
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
<p>Why not let MySQL do the hard work?</p> <pre><code>select unix_timestamp(fieldname) from tablename; </code></pre>
<p>I use something like the following to get seconds since the epoch (UTC) from a MySQL date (local time):</p> <pre><code>calendar.timegm( time.gmtime( time.mktime( time.strptime(t, "%Y-%m-%d %H:%M:%S")))) </code></pre> <p>More info in this question: <a href="https://stackove...
14,125
<p>Does anyone know how the developers of Marlin decided to name it that?</p>
<p>As far as I know Erik van der Zalm started Marlin. He is from the Netherlands and Zalm translates to "salmon". One of the design goals of Marlin was to make it faster than the other firmware available at that time. And a marlin is a very fast swimming fish.</p> <p>Some firmwares developed after Marlin also joined t...
<p>Yes, it probably is totally off-topic, but fun too, so I'll try to get an answer in, before the question gets closed.</p> <p>The best place to ask would be the <a href="https://reprap.org/forum/list.php?415" rel="nofollow noreferrer">Firmware - Marlin forum</a>, on RepRap.org.</p> <p>The question is there now, <a ...
1,311
<p>I've been working for years with VS's debugger, but every now and then I come across a feature I have never noticed before, and think &quot;Damn! How could I have missed that? It's <strong>so</strong> useful!&quot;</p> <p>[Disclaimer: These tips work in VS 2005 on a C# project, no guarantees for older incarnations o...
<p>I always make sure to set the "Name" property on new threads that I create. That way, when I'm debugging I can more easily identify different threads.</p>
<p>In unmanaged code you can set "data breakpoints". They user the debug registers of the CPU to issue an INT3 and the debugger stops on that instruction with no overhead during run time (in older version the debugger stepped through the program checking the memory..... slow!)</p> <p>This is useful if you have some co...
24,596
<p>I allow users to enter a regular expression to match IP addresses, for doing an IP filtration in a related system. I would like to validate if the entered regular expressions are valid as a lot of userse will mess op, with good intentions though.</p> <p>I can of course do a Regex.IsMatch() inside a try/catch and se...
<p>As long as you catch very specific exceptions, just do the try/catch.</p> <p>Exceptions are not evil if used correctly.</p>
<p>By using following method you can check wether your reguler expression is valid or not. here testPattern is the pattern you have to check.</p> <pre><code>public static bool VerifyRegEx(string testPattern) { bool isValid = true; if ((testPattern != null) &amp;&amp; (testPattern.Trim().Length &gt; 0)) { ...
26,905
<p>I have recently run across these terms few times but I am quite confused how they work and when they are usualy implemented?</p>
<p>Well, think of it this way.</p> <p>If you use an array, a simple index-based data structure, and fill it up with random stuff, finding a particular entry gets to be a more and more expensive operation as you fill it with data, since you basically have to start searching from one end toward the other, until you find...
<p>Hashtables/hashmaps associate a value (called 'key' for disambiguation purposes) with another value. You can think them as kind of a dictionary (word: definition) or a database record (key: data).</p>
16,734
<p>I have a heap of unit tests that need to check XML outputs.</p> <p>I have started out comparing strings but this isn't going to scale as formatting and superficial differences get in the way.</p> <p>What is the easiest way in .NET to evaluate whether the generated XML is semantically the same as what the test exp...
<p>Microsoft offers its XML Diff tools/classes <a href="http://msdn.microsoft.com/en-gb/library/aa302294.aspx" rel="noreferrer">here</a>. I haven't personally used it, but it sounds like it'll get you started:</p> <blockquote> <p>"By using the XMLDiff class, the programmer is able to determine if the two files a...
<p>This is one of those problems that sounds like it's going to be easy to start with, but the more you dig the more depth you find in the problem space.</p> <p>There are a number of pre-existing tools out there that will do xml diffs - both in a GUI fashion (along the same lines as textual diff tools), and command li...
34,767
<p>What makes all the words of a programming language actually do anything? I mean, what's actually happening to make the computer know what all of those words mean? If I verbally tell my my computer to do something, it doesn't do it, because it doesn't understand. So how exactly can these human words written into a la...
<p>It all starts with the CPU or processor. Each processor type has a defined set of instructions it's able to perform. These instructions operate over ones and zeroes, which in turn represent whatever you wish them to: numbers, letters, even the instructions themselves. </p> <p>At the lowest level, a zero is determin...
<p>Basically, you start out with something simple such as:</p> <pre><code>print("Hello World"); </code></pre> <p>Then you simply sprinkle syntactic sugar and magic tokens over it until it does what you want!</p>
34,521
<p>I have a simple setter method for a property and <code>null</code> is not appropriate for this particular property. I have always been torn in this situation: should I throw an <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/IllegalArgumentException.html" rel="noreferrer"><code>IllegalArgumentException</...
<p>It seems like an <code>IllegalArgumentException</code> is called for if you don't want <code>null</code> to be an allowed value, and the <code>NullPointerException</code> would be thrown if you were trying to <em>use</em> a variable that turns out to be <code>null</code>.</p>
<p>If you choose to throw a NPE and you are using the argument in your method, it might be redundant and expensive to explicitly check for a null. I think the VM already does that for you.</p>
2,593
<p>Anytime I have to handle dates/times in java it makes me sad </p> <p>I'm trying to parse a string and turn it into a date object to insert in a preparepared statement. I've been trying to get this working but am having no luck. I also get the helpful error message when I go to compile the class.</p> <p>"Exception ...
<p><a href="http://java.sun.com/javase/6/docs/api/java/sql/PreparedStatement.html#setDate(int,%20java.sql.Date)" rel="noreferrer">PreparedStatement.setDate</a> takes a <a href="http://java.sun.com/javase/6/docs/api/java/sql/Date.html" rel="noreferrer">java.sql.Date</a>, not a <a href="http://java.sun.com/javase/6/docs/...
<p>String to MySQL Date/Time</p> <pre><code>import java.sql.Date; import java.sql.Time; statement.setDate(4, Date.valueOf("2009-08-26")); statement.setTime(5, Time.valueOf("12:04:08")); </code></pre>
48,462
<p>I’m trying to run this SQL using get external.</p> <p>It works, but when I try to rename the sub-queries or anything for that matter it remove it.</p> <p>I tried <code>as</code>, <code>as</code> and the name in <code>''</code>, <code>as</code> then the name in <code>""</code>, and the same with space. What is the...
<p>You could get rid of your <code>dbo.d_agent_define</code> subquery and just add in a join to the agent define table.</p> <p>Would this code work?</p> <pre><code>select list_name, app_name, map.fname + ' ' + map.lname as agent_login, input, convert(varchar,dateadd(ss,TAC_BEG_tstamp,'01/01/1970')) as tac_seconds ...
<p>To remove the sub query in the SELECT statement I suggest the following:</p> <pre><code>SELECT list_name, app_name, map.fname + ' ' + map.lname as agent_login, input, convert(varchar,dateadd(ss, TAC_BEG_tstamp, '01/01/1970)) FROM dbo.maps_report_list inner join (dbo.report_tac_agent as tac inner join dbo.d_agent_...
11,483
<p>For some reason, when I try to install <code>SQL Server 2008 Express</code>, I get an error saying that I need to have <code>.Net Framework 3.5</code> installed first, but the thing is: I already have! So could anybody tell me if I can bypass this verification by updating a registry key or something? I have np with ...
<p>I ran into this once before. Make sure that it is installed. Reinstall if necessary. I believe what I did was install SP1. SQL Server 2008 has a tendency of trying to install the Compact Framework 3.5 and based on the build or refresh of SQL, Compact Framework 3.5 SP1. HTH!</p>
<p>Installing Windows Installer 4.5 worked for me. Once installed, the message goes away.</p>
14,980
<p>I am looking for the way to mount NTFS hard disk on FreeBSD 6.2 in read/write mode.</p> <p>searching google, I found that NTFS-3G can be a help.</p> <p>Using NTFS-3G, there is no problem when I try to mount/unmount NTFS manually:</p> <p>mount: ntfs-3g /dev/ad1s1 /home/admin/data -o uid=1002,</p> <p>or</p> <p>um...
<p>If you want true random data, then unfortunately you have to wait for it. This includes the seed for a <code>SecureRandom</code> PRNG. Uncommon Maths can't gather true random data any faster than <code>SecureRandom</code>, although it can connect to the internet to download seed data from a particular website. My gu...
<p>Something else to look at is the property securerandom.source in file lib/security/java.security <P>There may be a performance benefit to using /dev/urandom rather than /dev/random. Remember that if the quality of the random numbers is important, don't make a compromise which breaks security.</p>
16,595
<p>I need a function which executes an INSERT statement on a database and returns the Auto_Increment primary key. I have the following C# code but, while the INSERT statement works fine (I can see the record in the database, the PK is generated correctly and rows == 1), the id value is always 0. Any ideas on what might...
<p>1) combine the INSERT and SELECT statement (concatenate using ";") into 1 db command</p> <p>2) use SCOPE_IDENTITY() instead of @@IDENTITY</p> <p>INSERT INTO blabla... ; SELECT OID FROM table WHERE OID = SCOPE_IDENTITY()</p> <p>-- update:</p> <p>as it turned out that the question was related to MS ACCESS, I found...
<p>As you're using Access, take a look at <a href="http://databases.aspfaq.com/general/how-do-i-get-the-identity/autonumber-value-for-the-row-i-inserted.html" rel="nofollow noreferrer">this article</a> from aspfaq, scroll down to about half way down the page. The code's in classic ASP, but hopefully the principles shou...
22,574
<p>The question says it all. </p> <p>Example: I'm planning to shard a database table. The table contains customer orders which are flagged as "active", "done" and "deleted". I also have three shards, one for each flag.</p> <p>As far as I understand a row has to be moved to the right shard, when the flag is changed. <...
<p>Sharding usually refer to separating them in different databases on different servers. Oracle can do what you want using a feature called partitioned tables.</p> <p>If you're using triggers (after/before_update/insert), it would be an immediate move, other methods would result in having different types of data in t...
<p>Sharding usually refer to separating them in different databases on different servers. Oracle can do what you want using a feature called partitioned tables.</p> <p>If you're using triggers (after/before_update/insert), it would be an immediate move, other methods would result in having different types of data in t...
37,549
<p>I'm trying to get a stored procedure to work for a co-worker who is out sick (and thus can't be asked for guidance).</p> <p>I have a SQL Server 2005 database that has this exact procedure, and I'm trying to make the scripts to convert a test database to match this dev database. My script has several lines like:</p...
<p>I believe that what you are looking for is decimal(10,3). Float has a specific defined size and precision. Decimal allows you to specify the precision, and it appears that you are looking to use a decimal, not a float.</p>
<p>Hmmm, why cast at all, varchar to numeric has an implicit conversion as long as the data is correct (I presume you are checking in your cleanup process to make sure the data is numeric before trying to insert it to production, even the cast would fail if someone put character data in the field).</p>
39,973
<p>I want to create a box shape and I am having trouble. I want the box to have a background color, and then different color inside the box.<br> The box will then have a list of items using ul and li, and each list item will have a background of white, and the list item's background color is too stretch the entire dist...
<p>You can do this pretty cleanly with this css:</p> <pre><code>.box { width: 100px; border: solid #884400; border-width: 8px 3px 8px 3px; background-color: #ccaa77; } .box ul { margin: 0px; padding: 0px; padding-top: 50px; /* presuming the non-list header space...
<p>Maybe those two will help:</p> <ul> <li><a href="http://css.maxdesign.com.au/listutorial/" rel="nofollow noreferrer">Listutorial</a></li> <li><a href="http://www.cssplay.co.uk/menus/" rel="nofollow noreferrer">CssPlay Menus</a></li> </ul>
13,402
<p>when i create an aspx page, the header includes something like this:-</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Create.aspx.cs" Inherits="My.Mvc.Views.Blah" %&gt; </code></pre> <p>With ASP.NET MVC apps, do we:</p>...
<p>Sorry - the default is true in ASP.NET, so you should explicitly set AutoEventWireup to false in the @ Page directive, or remove it and set it to false in pages section of web.config for MVC. </p>
<p>You can get rid of this attribute, or set it to false (which is the default). </p> <p>AutoEventWireup means ASP.NET will use reflection at runtime to look for methods on your web form class in the form of Page_EventName (like Page_Load, Page_Init, etc), and automatically wire the methods to the corresponding page l...
34,787
<p>I have a list of cities, states/provinces, and countries and I need to find their respective timezones easily. Specifically, I need to know which Windows TimeZone they map to. So far this has been a difficult process, because there's no easy way to pass a city to something and get a timezone back (a timezone being ...
<p>Interesting question! These other three SO posts (<a href="https://stackoverflow.com/questions/41504/timezone-lookup-from-latitude-longitude">41504</a>, <a href="https://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city">55901</a> and <a href="https://stackoverflow.com/questions/237023/is-th...
<p>I can help with the 2nd part of your current workflow. I've written a Java library which maps lat/long's to timezones, where the database is encoded in the source code. </p> <p>The source code is basically an enormous tree of if statements: if (lat >= -33.0) if (lng &lt; -151.5) ... else ... and so on. It's jus...
32,818
<p>I recently discovered this kit after reading this Instructables, <a href="https://www.instructables.com/id/Adding-More-Extruders-to-Any-3d-Printer/" rel="nofollow noreferrer">Adding More Extruders to Any 3d Printer</a>: </p> <blockquote> <p><a href="https://i.stack.imgur.com/Lq4uQ.png" rel="nofollow noreferrer" t...
<p>The <a href="http://www.robotrebels.org/index.php?topic=769.0" rel="nofollow noreferrer">MKS Gen L v1.0</a> Board you are using does support microcontroller controlled fans without doing some surface level modification to the board via the <code>D9/FAN</code>. The port you marked FAN is not a controllable port, it r...
<p>You can use the <code>M42</code> g-code to manually set any supported digital pin, which can then be used to either enable one of the on-board MOSFETs (D7, D8, D9, D10) or an external MOSFET. For example, <code>M42 P9 S255</code> would enable the parts cooling fan at 100&nbsp;%.</p> <p>You should never run any fan ...
1,397
<p>I use jQuery to make an AJAX POST request to my server, which can return HTTP response with status 302. Then JavaScript just sends GET request to this URL, while I'd like to redirect user to URL in this response. Is this possible?</p>
<p>The accepted answer does not work for the reasons given. I posted a comment with a link to a question that described a hack to get round the problem of the 302 being transparently handled by the browser:</p> <p><a href="https://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-...
<pre><code>function doAjaxCall() { $.ajaxSetup({complete: onRequestCompleted}); $.get(yourUrl,yourData,yourCallback); } function onRequestCompleted(xhr,textStatus) { if (xhr.status == 302) { location.href = xhr.getResponseHeader("Location"); } } </code></pre>
48,785
<p>I use the recent Ganymede release of Eclipse, specifically the distro for Java EE and web developers. I have installed a few additional plugins (e.g. Subclipse, Spring, FindBugs) and removed all the Mylyn plugins. </p> <p>I don't do anything particularly heavy-duty within Eclipse such as starting an app server or c...
<p>I don't know about Eclipse specifically, I use IntelliJ which also suffers from memory growth (whether you're actively using it or not!). Anyway, in IntelliJ, I couldn't eliminate the problem, but I did slow down the memory growth by playing with the runtime VM options. You could try resetting these in Eclipse and s...
<p>Eclipse generally keeps a lot of meta-data in memory to allow for all kinds of IDE gymnastics.</p> <p>I have found that the default configuration of Eclipse works well for most purposes and that includes a limit (either given explicitly or implictly by the JVM) to how much memory can be consumed, and Eclipse will s...
11,996
<p>I am using <a href="http://msdn.microsoft.com/en-us/library/aa387410(VS.85).aspx" rel="nofollow noreferrer">Windows Media Format SDK</a> to capture the desktop in real time and save it in a WMV file (actually this is an oversimplification of my project, but this is the relevant part). For encoding, I am using the <a...
<p>The source to CamStudio, a GPL'd screencasting app that's been around for years (commercially and then open-srcd later) might be useful?</p> <p><a href="http://sourceforge.net/project/showfiles.php?group_id=131922" rel="nofollow noreferrer">http://sourceforge.net/project/showfiles.php?group_id=131922</a></p> <p>I'...
<p>It's been ages since I've done any Win32 coding, but AFAIK, WMF as a format is basically a list of GDI commands and their parameters which would explain why it is much more efficient to encode...</p> <p>You'd probably need to hook into the top level GDI context (just as Remote Desktop does, I guess) and capture the...
8,900
<p>What is <code>std::pair</code> for, why would I use it, and what benefits does <code>boost::compressed_pair</code> bring?</p>
<p><a href="http://en.cppreference.com/w/cpp/utility/pair" rel="nofollow noreferrer"><code>std::pair</code></a> is a data type for grouping two values together as a single object. <a href="http://en.cppreference.com/w/cpp/container/map" rel="nofollow noreferrer"><code>std::map</code></a> uses it for key, value pairs.<...
<p>Sometimes there are two pieces of information that you just always pass around together, whether as a parameter, or a return value, or whatever. Sure, you could write your own object, but if it's just two small primitives or similar, sometimes a pair seems just fine.</p>
12,342
<p>The [x] button in the top bar of a window that normally closes the window in standard Windows, appears to do a minimise instead on Windows Compact.</p> <p>How do it make it close instead? I need to also be able to raise an event when this happens as I want to preform some logic on window close.</p>
<p>Set the Form.MinimizeBox property to false. This will change the [X] to [ok], and close your form instead of minimizing it when clicked.</p> <p>Edit: The event you want is either Closing or Closed.</p>
<p>I'm not sure how this relates to the .NET forum support but you need to use the Native API <a href="http://msdn.microsoft.com/en-us/library/aa458082.aspx" rel="nofollow noreferrer">SHDoneButton</a>.</p> <p>By default it's set to "<code>SHDB_HIDE</code>" which then shows the "Windows Mobile" "X" button (or any appli...
40,666
<p>There is this example code, but then it starts talking about millisecond / nanosecond problems.</p> <p>The same question is on MSDN, <em><a href="https://learn.microsoft.com/archive/blogs/brada/seconds-since-the-unix-epoch-in-c" rel="noreferrer">Seconds since the Unix epoch in C#</a></em>.</p> <p>This is what I've...
<p>Here's what you need:</p> <pre><code>public static DateTime UnixTimeStampToDateTime( double unixTimeStamp ) { // Unix timestamp is seconds past epoch DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dateTime = dateTime.AddSeconds( unixTimeStamp ).ToLocalTime(); return dateT...
<p>For .NET 4.6 and later:</p> <pre><code>public static class UnixDateTime { public static DateTimeOffset FromUnixTimeSeconds(long seconds) { if (seconds &lt; -62135596800L || seconds &gt; 253402300799L) throw new ArgumentOutOfRangeException("seconds", seconds, ""); return new Date...
31,060
<p>I have a Windows Service written in Delphi which runs a number of programs. </p> <p>On Stopping the service, I want to also close these programs. When the service was originally written, this worked fine, but I think I've updated the tProcess component and now - The subordinate programs are not being closed. </p> ...
<p>I'd use <strong>TJvCreateProcess</strong> component of <a href="http://jvcl.sourceforge.net/" rel="nofollow noreferrer">JVCL</a> which wraps about any process related functionality of win32 in a graceful way. This answer comes from Dont-touch-winapi-unless-really-required department :-)</p>
<p>The only generic way to stop a process is to use <a href="http://msdn.microsoft.com/en-us/library/ms686714.aspx" rel="nofollow noreferrer">TerminateProcess</a>. But that's as far from graceful as you can get. To gracefully close a process, you need to tell the process that you'd like it to stop, and then hope it obe...
33,655
<p>There are a dozen Rails plugins whose goal is to replace fixtures in testing. Here are a few I can think of:</p> <ul> <li>fixture replacement</li> <li>factory girl</li> <li>factories and workers</li> <li>rails scenarios</li> <li>fixture-scenarios</li> <li>object daddy</li> </ul> <p>There are probably others. Which...
<p>I personally use <a href="http://faker.rubyforge.org/" rel="nofollow noreferrer">Faker</a> with a custom Factory class. This allows me to create my factories, and populate the generated instances with non-static data.</p> <pre><code># spec/factory.rb module Factory def self.create_offer(options={}) Offer.crea...
<p>Factory Girl is great. We use it in work loads.</p> <pre><code>Factory.define :usa, :class =&gt; Team do |f| f.country_name 'USA' f.rank 15.6 end Factory.define :player do |f| f.first_name 'Stevie' f.last_name 'Wonder' f.team Factory.build(:usa) end </code></pre> <p>Then in your specs you...
26,007
<p>How would you find the fractional part of a floating point number in PHP?</p> <p>For example, if I have the value <code>1.25</code>, I want to return <code>0.25</code>.</p>
<pre><code>$x = $x - floor($x) </code></pre>
<p>To stop the confusion on this page actually this is the best answer, which is fast and works for both positive and negative values of $x:</p> <pre><code>$frac=($x&lt;0) ? $x-ceil($x) : $x-floor($x); </code></pre> <p>I ran speed tests of 10 million computations on PHP 7.2.15 and even though both solutions give the ...
7,360
<p>What is a smart pointer and when should I use one?</p>
<p><strong>UPDATE</strong></p> <p>This answer is rather old, and so describes what was 'good' at the time, which was smart pointers provided by the Boost library. Since C++11, the standard library has provided sufficient smart pointers types, and so you should favour the use of <a href="http://en.cppreference.com/w/cp...
<p>Smart Pointers are those where you don't have to worry about Memory De-Allocation, Resource Sharing and Transfer. </p> <p>You can very well use these pointer in the similar way as any allocation works in Java. In java Garbage Collector does the trick, while in Smart Pointers, the trick is done by Destructors.</p>
13,205
<p>I've have observed that when the printer is finishing a layer, the flow of plastic through the nozzle starts fading out as it comes closer to the point of layer change.</p> <p>As an example, let's say that I'm printing the first layer of a cube. The nozzle first prints the perimeters ok. Then it begins to print the...
<p>If you think it is a slicing problem, look at the G-code. You might want to arrange for the infill to be orthogonal to the axes, but it ought to be easy enough to calculate the ratio between printhead motion and the extruder. G-code is just text, and fairly easy to make sense of. The <a href="http://reprap.org/wiki/...
<p>The Prusa Slic3r edition has <a href="http://manual.slic3r.org/expert-mode/fighting-ooze" rel="nofollow noreferrer">specific help references</a> in the manual that may be of value to you. One of the entries that catches my eye is the line marked "Retract on layer change" which appears to be just as you are describin...
795
<p>I refactor my and other people's code <strong>all the time</strong>. When I work in a branch and not in Trunk, this sometimes results in some extremely painful merges, especially if I don't merge back to Trunk regularly (the code at the branch slowly shifts away from the Trunc, and when people modify Trunk I have to...
<p>Refactoring on a large scale needs to be done at the right time in the development timeline. If you do huge amounts of refactoring near release you'll end up hurting yourself because you'll introduce painful merges at a time when changes should be minimized. The more disruptive your refactoring will be the earlier i...
<p>This is where a good distributed VCS excels. But I am guessing you are committed to SVN already.</p> <p>Personally, I just do the refactor and then merge as soon as possible to avoid the conflict hell. It is not the most productive method, but the least error prone.</p> <p>I once had a branch that sat dormant fo...
14,356
<p>Given the following:</p> <pre><code>List&lt;List&lt;Option&gt;&gt; optionLists; </code></pre> <p>what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value.</p> <p>So we should end up wi...
<p>Ok, this will find the list of Option objects that have a Value appearing in <em>every</em> list.</p> <pre><code>var x = from list in optionLists from option in list where optionLists.All(l =&gt; l.Any(o =&gt; o.Value == option.Value)) orderby option.Value select option; </code></pre...
<p>Sort, then do something akin to a merge-sort.</p> <p>Basically you would do this:</p> <ol> <li>Retrieve the first item from each list</li> <li>Compare the items, if equal, output</li> <li>If any of the items are before the others, sort-wise, retrieve a new item from the corresponding list to replace it, otherwise,...
6,242
<p>We have a couple of ASP.Net dataview column templates that are dynamically added to the dataview depending on columns selected by users.</p> <p>These templated cells need to handle custom databindings:</p> <pre><code>public class CustomColumnTemplate: ITemplate { public void InstantiateIn( Control contain...
<p>I have worked extensively with templated control and I have not found a better solution.</p> <p>Why are you referencing the contentLable in the event handler?</p> <p>The sender is the label you can cast it to the label and have the reference to the label. Like below.</p> <pre><code> //add a custom data bi...
<p>One solution is to make your template <em>itself</em> implement <code>IDisposable</code>, and then dispose the controls in your template's <code>Dispose</code> method. Of course this means you need some sort of collection to keep track of the controls you've created. Here is one way to go about it:</p> <pre><code>p...
4,979
<p>I have created a setup project using Visual Studio 2008. After the application is finished installing, I would like to have it start up immediately. Any thoughts on how this can be done?</p>
<p>I have used a custom action in <a href="http://www.codeproject.com/KB/install/Installation.aspx" rel="noreferrer">VS 2005</a>. Not sure if this is enhanced in VS 2008.</p>
<p>Here's how to make your application launch after install (using VS2010):</p> <p>Assuming you already have 2 projects like: <code>MyApp.Application</code> and <code>MyApp.Installer</code>.</p> <ol> <li>Right-click the project for <code>MyApp.Application</code> and choose <code>Add</code> > <code>New Item...</code> ...
30,736
<p>We've got a situation where someone messed up a Commit to our SVN server. A lot of files were deleted, etc. </p> <p><strong>Question:</strong> What is the technique for making the previous (to the bad Commit) revision the HEAD revision? I've seen discussion here on SO for doing this for 1 file, but we'd like to mak...
<p>The cleanest way would be to <a href="http://svnbook.red-bean.com/en/1.5/svn-book.html#svn.branchmerge.basicmerging.undo" rel="noreferrer">undo changes</a></p> <blockquote> <p>You can use svn merge to “undo” the change in your working copy, and then commit the local modification to the repository. All you need to...
<p>You can svn cp specific revisions, so if there are no intervening operations that you wan to save, you could svn rm the offending directory and then svn cp the old version. See the <a href="http://svnbook.red-bean.com/en/1.5/svn-book.html#svn.advanced.pegrevs" rel="nofollow noreferrer">Peg and Operative Revision se...
44,124
<p>I had been happily coding along on a decent sized solution (just over 13k LOC, 5 projects) which utilizes Linq to Sql for it's data access. All of sudden I performed a normal build and I received a sweet, sweet ambiguous message:</p> <p><strong>Error 1 Build failed due to validation errors in C:\xxx\xxx.dbml. Open ...
<p>TBH, I have had a couple of instances like this where files "seemed to go crazy".. However, upon investigation it has appeared that the files have changed in some way, shape or form.. (e.g. sometimes changes can be made to the file by inadvertantly changing a property somewhere that <em>seems</em> unrelated).</p> <...
<p>I had the same issue in VS 2010 (build failed due to validation errors in dbml file). I resolved this by viewing the designer view of the dbml file and dragging a table slightly to a different location so that it refreshed the dbml layout etc files. This seemed to do the trick, but was a bit of a weird issue.</p>
4,848
<p>I have a WCF application that has two Services that I am trying to host in a single Windows Service using net.tcp. I can run either of the services just fine, but as soon as I try to put them both in the Windows Service only the first one loads up. I have determined that the second services ctor is being called but ...
<p>Base your service on this <a href="http://msdn.microsoft.com/en-us/library/ms733069.aspx" rel="nofollow noreferrer">MSDN article</a> and create two service hosts. But instead of actually calling each service host directly, you can break it out to as many classes as you want which defines each service you want to ru...
<p>you probably just need 2 service hosts.</p> <p>_host1 and _host2.</p>
7,803
<p>Which log4j Version is bundled with latest OpenCms 7?</p>
<p>OpenCms 7.5.3 includes log4j <strong>1.2.15</strong></p>
<p>OpenCms <a href="http://www.opencms.org/en/modules/downloads/dl_7.0.5_dist.html" rel="nofollow noreferrer">7.0.5</a> includes log4j <strong>1.2.14</strong></p>
26,133
<p>I am looking for a Repository pattern implementation example/resource that follows domain driven design principles for my ASP.net MVC application. Does anyone have a good example or learning resource that can be shared?</p>
<p>It's not an uncontroversial implementation, but Rob Conery's web storefront project has implemented repository via Linq to Sql in C#.</p> <p><a href="http://blog.wekeroad.com/" rel="nofollow noreferrer">http://blog.wekeroad.com/</a></p> <p>Source is available.</p> <p>He's not quite doing strict DDD, but his TDD i...
<p>Domain Driven Design by Eric Evans is a great place to learn all about the Repository pattern and more. <a href="http://dddcommunity.org/books/" rel="nofollow noreferrer">http://dddcommunity.org/books/</a></p>
15,247
<p>This isn't as malicious as it sounds, I want to get the current size of their windows, not look at what is in them. The purpose is to figure out that if every other window is fullscreen then I should start up like that too. Or if all the other processes are only 800x600 despite there being a huge resolution then t...
<p>Using hints from <a href="http://www.devx.com/opensource/Article/37773/1954" rel="noreferrer">WindowMover article</a> and <a href="http://our.obor.us/?q=node/42" rel="noreferrer">Nattee Niparnan's blog post</a> I managed to create this:</p> <pre><code>import win32con import win32gui def isRealWindow(hWnd): '''...
<p>I updated the GREAT @DZinX code adding the title/text of the windows:</p> <pre><code>import win32con import win32gui def isRealWindow(hWnd): #'''Return True iff given window is a real Windows application window.''' if not win32gui.IsWindowVisible(hWnd): return False if win32gui.GetParent(hWnd) ...
18,304
<p>I'm racking my brain trying to come up with an elegant solution to a DLL load problem. I have an application that statically links to other lib files which load DLLs. I'm not loading the DLLs directly. I'd like to have some DLLs in another folder other than the folder that the executable is in. Something like %worki...
<p>[Edit - after re-reading the question I see that the problem you're having is that the DLLs are getting loaded before <code>main</code> starts]</p> <p>I'm guessing that those libraries are written in C++ and are loading the DLLs from the constructor of some objects in global scope. This is problematic. Allow me t...
<p>[Edit - after re-reading the question I see that the problem you're having is that the DLLs are getting loaded before <code>main</code> starts]</p> <p>I'm guessing that those libraries are written in C++ and are loading the DLLs from the constructor of some objects in global scope. This is problematic. Allow me t...
42,378
<p>I have some simple shell scripting tasks that I want to do </p> <p>For example: Selecting a file in the working directory from a list of the files matching some regular expression.</p> <p>I know that I can do this sort of thing using standard bash and grep but I would be nice to be able to hack quick scripts tha...
<p>By default, you already have access to <a href="http://www.ruby-doc.org/core/classes/Dir.html" rel="noreferrer">Dir</a> and <a href="http://www.ruby-doc.org/core/classes/File.html" rel="noreferrer">File</a>, which are pretty useful by themselves.</p> <pre><code>Dir['*.rb'] #basic globs Dir['**/*.rb'] #** == any dep...
<p>Place this at the beginning of your script.rb</p> <pre><code>#!/usr/bin/env ruby </code></pre> <p>Then mark it as executable:</p> <pre><code>chmod +x script.rb </code></pre>
20,091
<p>I'd like to be able to detect Vista IE7 Protected Mode within a page using javascript, preferably. My thinking is to perform an action that would violate protected mode, thus exposing it. The goal is to give appropriate site help messaging to IE7 Vista users. </p>
<p>What are you trying to accomplish that is substantially different for protected users? I've seen some window popup issues, but otherwise, clean JavaScript tends to be less affected. If you're finding that a block of code won't execute, why not do a check after attempted execution to see if the document is the state ...
<p>Adobe Flash may behave differently (or not as expected) in Vista IE7 Protected Mode. The intention is to provide this feedback to the user. </p>
43,450
<p>Javascript client side application.</p> <p>Trying to eliminate memory leaks leads to ugly (to say the least) code.</p> <p>I am trying to clean up in window.unload instead on messing up all the code trying to avoid them.</p> <p>We use mostly <code>element.onevent=function(){..};</code> pattern, that results in clo...
<p>The best solution is for you to roll out your own method that manages event handling. Therefore, when attaching an event handler, your method can keep track of all the added events. On unload, it can unregister all the handlers.</p> <p>I know you said you don't use libraries, but you can use their code as inspirati...
<p>I'm not sure what you mean with cleanup as JavaScript has an automatic memory management. But anyway, as I understand, after the window is unloaded, all the memory associated with JS is released as well. After all - there is no more JS executing from a page after it has unloaded, right?</p>
44,151
<p>Given a typical class:</p> <pre> struct Whatever { void Doit(); }; Whatever w; </pre> <p>what is the best way to get the member function to be called by a C void* based callback such as pthread_create() or a signal handler ?</p> <pre> pthread_t pid; pthread_create(&pid, 0, ... &w.Doit() ... ); </pre>
<p>Most C callbacks allow to specify an argument e.g.</p> <pre><code>int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg); </code></pre> <p>So you could have </p> <pre><code>void myclass_doit(void* x) { MyClass* c = reinterpret_cast&lt;MyCla...
<p>See this <a href="http://www.newty.de/fpt/callback.html#member" rel="nofollow noreferrer">link</a></p> <p>Basically, it's not directly possible, because: "Pointers to non-static members are different to ordinary C function pointers since they need the this-pointer of a class object to be passed. Thus ordinary funct...
16,964
<p>In C# code can you catch a native exception thrown from deep in some unmanaged library? If so do you need to do anything differently to catch it or does a standard try...catch get it?</p>
<p>You can use <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.aspx" rel="noreferrer">Win32Exception</a> and use its NativeErrorCode property to handle it appropriately. </p> <pre><code>// http://support.microsoft.com/kb/186550 const int ERROR_FILE_NOT_FOUND = 2; const int ERROR_A...
<p>If you use a </p> <pre><code>try { } catch(Exception ex) { } </code></pre> <p>it will catch ALL exceptions, depending on how you call the external libraries you might get a com related exception that encapsulates the error but it will catch the error.</p>
18,148
<p>I am compiling a legacy C code here and there is a lot of variables and struct members named "interface", but VC2008 express is complaining about these, do you know how to disable this?</p> <p>I already changed settings to compile the code only as a C code, but no effect on this.</p>
<p>Do a </p> <pre><code>#define interface QQInterface </code></pre> <p>before your code (eg. in the header file), this way everywhere where the keyword interface is used, the compilers sees "QQInterface", which is not a keyword. If all code includes this define, you will not get compiler or linker errors.</p>
<p>I faced a similar problem while compiling C++ code which included a dbus header file. since dbus has several functions where it uses "interface" as an I/P parameter name, which happens to be C++ keyword, I got following error: <code>error: expected ',' or '...' before 'struct'</code>.</p> <p>When I tried this: </p>...
38,386
<p>Our team is developing a rather big ASP.NET web project which initially started in ASP.NET 1.0 and was ported several times to all new versions of .NET.</p> <p>We made extensively use of <strong>User Controls (ascx)</strong>. But in retrospect I doubt that it was a good decision. A very small percentage of these co...
<p>We have some projects which use ASCX controls extensively, and others that don't. In my experience you have to decide on a case by case basis.</p> <p>My two favourite reasons for using ASCX controls are:</p> <ol> <li>You're implementing a piece of UI functionality which will appear on many different pages (or mul...
<p>I would use usercontrols still, and mainly because you can disassociate content from design this way much more easily which will ultimately help a lot when you are changing the design of the application. </p> <p>It also makes it a bit easier to move the controls around on the page than if you had to cut/paste code...
35,926
<p>I understand that this could be a big security issue if people manage to hack it and able to view the server logs. Is there any application that can actually grab logs and display via web interface with the necessary security imposed? I am talking about java enterprise application</p>
<p>Take a look at Splunk. <a href="http://www.splunk.com/" rel="nofollow noreferrer">http://www.splunk.com/</a> This tool is likely overkill for what you are looking for, but should do the job.</p>
<p>I haven't tried any of the products available, but often thought about it trying. I even implemented some log analysis tools myself.</p> <p>Maybe have a look at this <a href="http://regumindtrail.wordpress.com/2007/02/06/the-spot-the-log-entry-contest/" rel="nofollow noreferrer">"commercial"</a></p>
18,979
<p>I'm developing an application based on Eclipse's Rich Client Platform that relies heavily on the use of tables for showing and editing data. I'm currently using the SWT implementations of Table and TableViewer. </p> <p>My users are forever complaining that it "doesn't work like in excel". Most notably, I can't sele...
<p>Check out the <a href="http://www.eclipse.org/nebula/widgets/grid/grid.php" rel="noreferrer">Nebula Grid</a> component. It's still being developed, so is not 100% mature, but seems to meet your needs.</p>
<p>KTable is similar to JTable.</p> <p>Nebula Grid fits in well with the Widget + Viewer paradigm. I was able to migrate from normal SWT table to this in a matter of minutes.</p>
14,111
<p>I am a novice programmer who is trying to teach myself to code, specifically in C#. I've taken on a project from a friend of mine and I am not sure what I need to know to get the project done. I suppose the issue is I don't know what I need to know to even get the project started.</p> <p>I do have many of the basic...
<p><a href="http://msdn.microsoft.com/en-us/library/a72418yk(VS.80).aspx" rel="nofollow noreferrer"><strong>Getting started with Visual C#</strong></a>.</p>
<p>I started with the <a href="http://www.csharp-station.com/Tutorial.aspx" rel="nofollow noreferrer">C# Station</a> tutorials. "Getting started with Visual C#" gives me the creeps...</p>
6,446
<p>Using jQuery, how do you bind a click event to a table cell (below, <code>class="expand"</code>) that will change the <code>image src</code> (which is in the clicked cell - original will be plus.gif, alternating with minus.gif) and <code>hide/show</code> the row immediately below it based on whether that row has a c...
<p>You don't need the show and hide tags:</p> <pre><code>$(document).ready(function(){ $('.expand').click(function() { if( $(this).hasClass('hidden') ) $('img', this).attr("src", "plus.jpg"); else $('img', this).attr("src", "minus.jpg"); $(this).toggleClass('hid...
<p>This is how the images are set up in the html</p> <pre><code>&lt;tr&gt; &lt;td colspan="2" align="center" &lt;input type="image" src="save.gif" id="saveButton" name="saveButton" style="visibility: collapse; display: none" onclick="ToggleFunction(false)"/&gt; &lt;input type="image" src="saveDisabled.jpg"...
15,015
<p>I have a Chiron from Anycubic and I have had some leveling issues in the last few weeks, however, I believe that I have sorted that. The layers attached to the base plate or the raft now come out very weird and I am uncertain why. I heard that this is caused by the extruder being too cold but I have turned up the te...
<p>Not sure what the other answers are talking about. From the picture, your nozzle is just way too far from the bed and the extruded material is just barely making contact. Adjust it so that, when moved to position Z=0.2, there is exactly 0.2 mm between the nozzle tip and the bed. Then fine-tune with single-layer test...
<p>What software do you use? Your nozzle diameter seems to be selected incorrectly or you have a slightly enlarged nozzle. Buy an unused nozzle and make your bed adjustments again.</p> <p>Select correct a nozzle diameter (such as 0.4 mm, 0.6 mm) and slice your print again. For PLA, I suggest using 200-215 °C for better...
2,050
<p>I made an html file called test.html then I navigated to it as "<a href="http://site.com/test.html?test1=a" rel="nofollow noreferrer">http://site.com/test.html?test1=a</a>" but the textbox stayed blank. Why is this? </p> <p>Super simple code</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; ...
<p>The file should be a PHP file, so test.php.</p> <p>Then maybe something like this:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="text" name="test1" value="&lt;?php echo htmlspecialchars($_GET['test1'], ENT_QUOTES); ?&gt;"&gt; &lt;/body&g...
<p>It might be possible to read the URL via javascript and populate the textbox that way if you must use static html.</p>
47,129
<p>Is there a <a href="http://en.wikipedia.org/wiki/Box_plot" rel="nofollow noreferrer">Box Plot</a> graph, or box and whisker graph available for Reporting Services 2005? From the looks of the documentation there doesn't seem to be one out of the box; so I am wondering if there is a third party that has the graph, or ...
<p>There definitely isn't a Box Plot built into SSRS 2005, though it's possible that 2008 has one. SSRS 2005 does have a robust extension model. If you can implement a chart in System.Drawing/GDI+, you can make it into a <a href="http://msdn.microsoft.com/en-us/magazine/cc188686.aspx" rel="nofollow noreferrer">custom...
<p><a href="http://sourceforge.net/project/showfiles.php?group_id=114675" rel="nofollow noreferrer">ZedGraph</a> is a good open source alternative.</p>
4,750
<p>Regarding cross-site request forgery (CSRF) attacks, if cookies are most used authentication method, why do web browsers allow sending cookies of some domain (and to that domain) from a page generated from another domain?</p> <p>Isn't CSRF easily preventable in browser by disallowing such behavior? </p> <p>As far ...
<p>Why wouldn't the browser send cookies?</p> <p>Site A (<a href="http://www.sitea.com" rel="noreferrer">http://www.sitea.com</a>) sets a cookie for the user.</p> <p>User navigates to site B (<a href="http://www.siteb.com" rel="noreferrer">http://www.siteb.com</a>). Site B features integration with site A - click he...
<p>Some people have said they don't think there's a lot the browser can do.</p> <p>See this:</p> <p><a href="http://people.mozilla.org/~bsterne/content-security-policy/origin-header-proposal.html" rel="nofollow noreferrer">http://people.mozilla.org/~bsterne/content-security-policy/origin-header-proposal.html</a></p> ...
27,678
<p>I have an ASP page which will fetch records from a SQL server DB table. The table "order_master" has a field called order_date. I want to frame a select query to fetch order date > a date entered by user(ex : 07/01/2008)</p> <p>I tried with convert and cast, but both are not working. The sample data in order_date c...
<p>I'd check to make sure that the SQL datatype is a DateTime or SmallDateTime first, then I'd check to make sure that you're passing in a Date/DateTime value from the page.</p> <p>If those are both correct, then you'd probably be better off following Joel's advice and explicitly convert both values to dates before tr...
<p>You could create a stored procedure like this</p> <pre><code>CREATE PROCEDURE GetOrders @OrderDate DATETIME AS SELECT * FROM order_master WHERE Order_Date &gt; @OrderDate GO </code></pre> <p>Then you can just convert the users input to a date before calling the stored procedure via your ASP code.</p> <p>...
25,235
<p>I have a large collection of raw data (around 300million rows) with about 10% replicated data. I need to get the data into a database. For the sake of performance I'm trying to use SQL copy. The problem being when I commit the data, primary key exceptions prevent any of the data from being processed. Can I change th...
<p>I think your best bet would be to drop the constraint, load the data, then clean it up and reapply the constraint.</p>
<p>That's what I was considering doing, but was worried about performance of getting rid of 30million randomly placed rows in a 300million entry database. The duplicate data also has a spatial relationship which is why I wanted to try to fix the problem while loading the data rather than after I have it all loaded.</p>...
26,646
<p>Way back in the days when "delicious" was just "del.icio.us", I had assumed that everyone had finally caught on that <a href="http://www.shirky.com/writings/ontology_overrated.html" rel="nofollow noreferrer">Ontology is overrated</a>. </p> <p>So why am I still having to roll my own tagging system using sqlite and a...
<p>The BeOS operating system already did this in 1991, before it became fashionable on the web – in fact, the web didn't even exist then. There's several successors, reimplementations and filesystems inspired by the BeFS out there. Some operating systems that include them are <a href="http://ZETA-OS.Com/" rel="nofollow...
<p><strong>Emacs Org Mode:</strong> <a href="http://www.youtube.com/watch?v=oJTwQvgfgMM&amp;feature=related" rel="nofollow noreferrer">youtube google tech talk</a></p>
43,974
<p>I'm using StringBuffer in Java to concat strings together, like so:</p> <pre><code>StringBuffer str = new StringBuffer(); str.append("string value"); </code></pre> <p>I would like to know if there's a method (although I didn't find anything from a quick glance at the documentation) or some other way to add "paddi...
<p>I think this is handled easier either with a helper method (untested code):</p> <pre><code>public String myMethod() { StringBuilder sb = new StringBuilder(); addToBuffer(sb, "Hello").addToBuffer("there,"); addToBuffer(sb, "it").addToBuffer(sb, "works"); } private StringBuilder addToBuffer(StringBuilder...
<p>Another possibility is that StringBuilder objects return themselves when you call append, meaning you can do:</p> <pre><code>str.append("string value").append(" "); </code></pre> <p>Not quite as slick, but it is probably an easier solution than the + " " method.</p> <p>Another possibility is to build a wrapper cl...
18,356
<p>I am getting the following error whenever I click on a postbacking control</p> <pre><code>HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cann...
<p>There is an article about this here: <a href="http://blogs.msdn.com/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx</a> .</p> <p>The basic problem is that Your page hasn't compl...
<p>I have encountered the same problem with a custom build ASP.NET control which was dynamically reloaded and rebuild on every POST / GET request. Thus the page sending the POST request was not the same as the one recieving the response. If you use any custom or databound controls look closly how they behave on a POST ...
13,956
<p>Here is a nice underhand lob pitch to you guys.</p> <p>So basically I've got my content table with unique primary key IDs and I've got my tag table with unique primary key IDs. </p> <p>I've got a table that has an identity column as a primary key but the two other columes are the contentID and tagID. What do I ne...
<p>You put a Unique constraint on contentID, tagID.</p> <p>For SQL Server</p> <pre><code>ALTER TABLE ContentTag ADD CONSTRAINT IX_ContentID_TagID_Unique UNIQUE NONCLUSTERED ( contentID, tagID ) GO </code></pre>
<p>Consider this problem:</p> <p>Table A has 2 child tables ( B &amp; C )</p> <p>The PK of B and C is an identity, and they both have a FK back to Table A.</p> <p>I have a table D, which is a join table on B and C </p> <p>Table D has PK of an identity and FK's back to B and C.</p> <p>A ..... two rows ... A1 and A2...
36,282
<p>Assuming following definition:</p> <pre><code>/// &lt;summary&gt; /// Replaces each occurrence of sPattern in sInput with sReplace. This is done /// with the CLR: /// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). /// The result of the replacement is the return value. /// &lt;/summary&gt;...
<p>Oh, whatever, I found the answer myself: </p> <pre><code>/// &lt;summary&gt; /// Replaces each occurrence of sPattern in sInput with sReplace. This is done /// with the CLR: /// new RegEx(sPattern, RegexOptions.Multiline).Replace(sInput, sReplace). /// The result of the replacement is the return value. /// &lt;/...
<p>See also <a href="https://stackoverflow.com/questions/4213788/how-to-create-clr-stored-procedure-with-nvarcharmax-parameter">How to create CLR stored procedure with Nvarchar(max) parameter</a> where you'll discover how/why you really should use the SqlChars data type. See <a href="https://learn.microsoft.com/en-us/...
46,464
<p>I'm writing a script that pulls XML data from wowarmory.com, using PHP 5 and cURL:</p> <pre><code>$url = "http://www.wowarmory.com"; $userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_...
<p>Can you access it from your local host via a web browser or even via the <code>curl</code> or <code>wget</code> command line utilities?</p> <p>What does <code>tcptraceroute</code> tell you?</p> <p>If neither a web browser nor the command line utility work, but <code>tcptraceroute</code> works (and does not show a ...
<p>api's probably give responses back to some URL (say nextUrl or currentUrl). if your URL is localhost or a local system IP address, how and where an api response back to..? Coz the api will response back to the nextUrl() or currentUrl(). So please use a permanent IP or domain name to work.</p>
37,595
<p>I have a C project that is built using a makefile, Eclipse constantly warns about "Invalid project path: Duplicate path entries", but I cannot figure out what the hell it wants me to do. I would like to disable this warning and continue with my life.</p> <p>My application compiles and runs fine, with not a single ...
<p>This worked for me with Eclipse 3.7.2 and CDT 8.0.2:</p> <ol> <li>Open the project properties | C/C++ Build | Discovery Options.</li> <li>Click the button by Clear discovered entries now:.</li> <li>Rebuild.</li> </ol> <p>It is seems to be a new feature in CDT 8. I have had this "Invalid project path: Duplicate pa...
<p>It seems like a bug in CDT.</p> <p>If you really want to get rid of it, you should try getting rid of the spaces in the project path; this was suggested in a search result for the error. If that doesn't work, you can try to open the .cproject file -it's where all the CDT settings lie- and check for an actual path w...
39,558
<p>I am using partial classes to split some functionality between 2 files, but I am getting an error. What am I doing wrong?</p> <p>A1.cs:</p> <pre><code>private partial class A { private string SomeProperty { get { return "SomeGeneratedString"; } } } </code></pre> <p>A2.cs:</p> <pre><code>private parti...
<p>Are the two partial classes in the same namespace? That could be an explanation.</p>
<p>Just for reference (VS 2020)... Error CS0103 =&gt; All same but different folder.</p> <p>But classes should have same namespace AND ALSO BE in same folder !!!</p> <p>Although they could be defined in the same namespace, both files should be in the same folder. I know that the folder structure should reflect the name...
22,368
<p>I have an interface method</p> <pre><code> public void Execute(ICommand command); </code></pre> <p>which needs to pass known subtypes of <code>ICommand</code> to an apropriate <code>Handle(SpecificCommand command)</code> method implementation and do some generic handling of unknown types. I am looking for a unive...
<p>The cast is emitted at compile-time, so you need to know the type at compile-time. The overloading is also determined at compile-time - so by the time you actually know the concrete type to use, it's too late.</p> <p>I don't see that you'd actually be duplicating any <em>logic</em> by using delegates. Alternatively...
<p>I've tried working out a way which would work using Double Dispatch (<a href="http://en.wikipedia.org/wiki/Double_dispatch" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Double_dispatch</a>), but it seems that you have a situation where the number of classes implementing ICommand and those implementing Exec...
43,209
<p>Table: </p> <pre><code>UserId, Value, Date. </code></pre> <p>I want to get the UserId, Value for the max(Date) for each UserId. That is, the Value for each UserId that has the latest date. Is there a way to do this simply in SQL? (Preferably Oracle)</p> <p><strong>Update:</strong> Apologies for any ambiguity: I n...
<p>This will retrieve all rows for which the my_date column value is equal to the maximum value of my_date for that userid. This may retrieve multiple rows for the userid where the maximum date is on multiple rows.</p> <pre><code>select userid, my_date, ... from ( select userid, my_date, .....
<p>If (UserID, Date) is unique, i.e. no date appears twice for the same user then:</p> <pre><code>select TheTable.UserID, TheTable.Value from TheTable inner join (select UserID, max([Date]) MaxDate from TheTable group by UserID) UserMaxDate on TheTable.UserID = ...
14,765
<p>I'm working with SChannel at the moment for an async (IOCP) based server and I've got most things working fine but I'm having a problem with renegotiation. Specifically, when peer A sends peer B a request to renegotiate and peer B responds with an TLS1 <code>NO RENEGOTIATION</code> alert how does peer A continue? I ...
<p>There was a HOTFIX issued for this a while back for Intel AMT based hardware. Essentially, the root certificate was stored as an SHA-1 hash instead of caching the entire certificate. SSPI passes all certificates EXCEPT the root, expecting the root to have this certificate for trust-chain verification. When the full ...
<p>May be this will help you: <a href="http://www.codeproject.com/KB/IP/sslsocket.aspx" rel="nofollow noreferrer">Code Project: SSLSocket</a>.</p>
27,530
<p>When building some of my PHP apps, a lot of the functionality could be coded using PEAR/PECL modules, however, the fact that some people using it may not have the access to install things, It poses a puzzler for me.</p> <p>Should I forsake some users to use PEAR/PECL for functionality, where these will allow me to ...
<p>It partly depends on how much time you have, and the purpose of the project. If you're just trying to make something that works, go with PEAR/PECL. If you're trying to learn to be a better programmer, and you have the time, then I'd recommend taking the effort to write your own versions. Once you understand the i...
<p>What I do most times is I'll never use PEAR installed globally on a server. Versions can change and affect your application.. Instead I have a config file (in my case XML) that lists all the packages required and their versions. The installer connects to my personal FTP repository and downloads and installs all th...
14,779
<p>The plastic glide rail on which my refrigerator vegetable drawer (bin) traveled recently broke.</p> <p>The rail was part of a large plastic shelf, which is no longer available for purchase.</p> <p>I'm thinking about 3D printing a new glide rail and attaching it (somehow) to the existing shelf.</p> <p>Can 3D printing...
<blockquote> <p>Can 3D printing be used for this task to make the repair any easier or more successful to complete than simply cutting a piece of plastic and (again, somehow) affixing it to the shelf?</p> </blockquote> <p><strong>Yes.</strong> 3D printed parts can be plenty strong enough to handle the kind of load you'...
<p>If you have powder plastic then I believe it will be easier for you to 3D print the shelf, resulting in smooth finish and high load capacity.</p> <p>Powder plastics offer the benefits of increased utilization rate and easy production process. Also, the excessive amount of powder can be eliminated at the finish produ...
1,782
<p>You walk into a store, select several products, then go to the counter to pay your bill. The total is some amount (<code>A</code>). You reach into your wallet, purse, or pocket and put down some cash (<code>P</code>), where <code>P</code> >= <code>A</code>, and the cashier gives you change.</p> <p>Given the set of ...
<p>There are also other factors, you are not likely to pay with 6 x 0.25, you would use 1 x 1.00 and 2 x 0.25 instead. Generally 0.25 would be no more then 3, 0.10 would be no more then 2, and 0.05 would be no more then 1.</p> <p>Also in the real world, many people never bother with values less then 1.00, they alawys ...
<p>OH !@#$%^&amp;*()_, now I am really pi..ed.</p> <p>I just wrote pseudocode and complexity estimation for 10 minutes, and when I post there is just the button "I am a human being" without any opportunity to enter something and my complete post is gone (and of course, this time I did not make a copy of the edit windo...
38,828
<p>I have a relatively simple site that I'm working up for an intranet environment. The pages have a hook to display a simple bit of text (possibly with a bit of HTML for markup purposes) for help when the user clicks a link on the page. I'm debating whether to put the help snippets in their own XML file or create a se...
<p>Sounds like a perfect candidate for resx (resource) files in the App_GlobalResources folder. Those are easily editable and posted to a site without any restarts.</p>
<p>What about using an embedded resource? There are several tutorials around how to use embedded resources and package it up in a dll to distribute along with your website.</p>
39,453
<p>I am trying to use the range property of the jQuery slider so that the slider control displays two handles from which the user can select a price range for real estate. The code I have is:</p> <pre><code>$("#price").slider({ range: true, minValue: 0, maxValue: 2000000, change: function(e, ui) { var range = ...
<p>To access the slider handle values in a double handled slider you need to access them from the <a href="http://docs.jquery.com/UI/Slider/slider#slider.28.C2.A0.22value.22.2C.C2.A0index_.29" rel="noreferrer">slider( "value", index )</a> function. Try the following code:</p> <pre><code>$(document).ready(function(){ ...
<p>Single Slider - <a href="https://codepen.io/ssuryar/pen/PoZEBgm" rel="nofollow noreferrer">DEMO</a></p> <p><a href="https://codepen.io/ssuryar/pen/PoZEBgm" rel="nofollow noreferrer">https://codepen.io/ssuryar/pen/PoZEBgm</a></p> <p>HTML</p> <pre><code>&lt;div id=&quot;slider-range&quot;&gt;&lt;/div&gt; </code></pre>...
45,306
<p>The <code>.XFDL</code> file extension identifies <code>XFDL</code> Formatted Document files. These belong to the XML-based document and template formatting standard. This format is exactly like the XML file format however, contains a level of encryption for use in secure communications.</p> <p>I know how to view XF...
<p>If the encoding is <strong>base64</strong> then this is the solution I've stumbled upon on the web:</p> <p>"Decoding XDFL files saved with 'encoding=base64'. Files saved with: </p> <pre><code>application/vnd.xfdl;content-encoding="base64-gzip" </code></pre> <p>are simple base64-encoded gzip files. They can be eas...
<p>You don't have to get out of Ruby to do this, can use the Base64 module in Ruby to encode the document like this:</p> <pre><code>irb(main):005:0&gt; require 'base64' =&gt; true irb(main):007:0&gt; Base64.encode64("Hello World") =&gt; "SGVsbG8gV29ybGQ=\n" irb(main):008:0&gt; Base64.decode64("SGVsbG8gV29ybGQ=\n") =...
2,395
<p>Here's my scenario - I have an SSIS job that depends on another prior SSIS job to run. I need to be able to check the first job's status before I kick off the second one. It's not feasible to add the 2nd job into the workflow of the first one, as it is already way too complex. I want to be able to check the first jo...
<p>You may want to create a third package the runs packageA and then packageB. The third package would only contain two execute package tasks.</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms137609.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms137609.aspx</a></p> <p>@Craig A sta...
<p>Why not use a table? Just have the first job update the table with it's status. The second job can use the table to check the status. That should do the trick if I am reading the question correctly. The table would (should) only have one row so it won't kill performance and shouldn't cause any deadlocking (of co...
6,095
<p>Is there a way to catch a click on a cell in VBA with Excel? I am not referring to the <code>Worksheet_SelectionChange</code> event, as that will not trigger multiple times if the cell is clicked multiple times. <code>BeforeDoubleClick</code> does not solve my problem either, as I do not want to require the user to ...
<p>Clearly, there is no perfect answer. However, if you want to allow the user to </p> <ol> <li>select certain cells </li> <li>allow them to change those cells, and</li> <li>trap each click,even repeated clicks on the same cell,</li> </ol> <p>then the easiest way seems to be to move the focus off the selected cell, ...
<p>I don't think so. But you can create a shape object ( or wordart or something similiar ) hook Click event and place the object to position of the specified cell.</p>
21,545
<p>Looking up LINQ and Or in google is proving somewhat difficult so here I am.</p> <p>I want to so the following:</p> <pre><code>(from creditCard in AvailableCreditCards where creditCard.BillToName.ToLowerInvariant().Contains(txtFilter.Text.ToLowerInvariant()) **or creditCard.CardNumber.().Contains(txtFilter.Text)*...
<p>C# keywords supporting LINQ are still C#. Consider <code>where</code> as a conditional like <code>if</code>; you perform logical operations in the same way. In this case, a logical-OR, you use <code>||</code></p> <pre><code>(from creditCard in AvailableCreditCards where creditCard.BillToName.ToLowerInvariant().Co...
<p>You should use the boolean operator that works in your language. Pipe | works in C#</p> <p>Here's <a href="http://msdn.microsoft.com/en-us/library/kxszd0kx(VS.80).aspx" rel="nofollow noreferrer">msdn</a> on the single | Here's <a href="http://msdn.microsoft.com/en-us/library/6373h346(VS.80).aspx" rel="nofollow no...
31,313
<p>What is the most appropriate media type (formally MIME type) to use when sending data structured with YAML over HTTP and why?</p> <p>There is no registered <a href="http://www.iana.org/assignments/media-types/application/" rel="noreferrer">application type</a> or <a href="http://www.iana.org/assignments/media-types/...
<p>Ruby on Rails uses <code>application/x-yaml</code> with an alternative of <code>text/yaml</code> (<a href="https://github.com/rails/rails/blob/d41d586/actionpack/lib/action_dispatch/http/mime_types.rb#L39" rel="noreferrer">source</a>).</p> <p>I think it's just a matter of convention, there is no <em>technical</em> ...
<p>As per <a href="https://www.freeformatter.com/mime-types-list.html" rel="nofollow noreferrer">MIME Types list</a> it's <code>text/yaml</code>, even though it's not in official <a href="https://www.iana.org/assignments/media-types/media-types.xhtml#text" rel="nofollow noreferrer">IANA MIME list </a></p>
43,027
<p>I've seen a number of postgresql modules for python like pygresql, pypgsql, psyco. Most of them are Python DB API 2.0 compliant, some are not being actively developed anymore. Which module do you recommend? Why?</p>
<p>psycopg2 seems to be the most popular. I've never had any trouble with it. There's actually a pure Python interface for PostgreSQL too, called <a href="http://barryp.org/software/bpgsql/" rel="noreferrer">bpgsql</a>. I wouldn't recommend it over psycopg2, but it's recently become capable enough to support Django ...
<p>Psycopg1 is known for better performance in heavilyy threaded environments (like web applications) than Psycopg2, although not maintained. Both are well written and rock solid, I'd choose one of these two depending on use case.</p>
17,421
<pre><code>$c = $record['corrects']; $i = $record['incorrects']; if($c == 0 &amp;&amp; $i == 0) { $image = imagecreatetruecolor(200,80); $white = imagecolorallocate($image,255,255,255); $red = imagecolorallocate($image,255,0,0); imagefilledrectangle($image,0,0,199,79,$white); $text = 'Quiz cance...
<p>Comment out the imagepng() and header() calls and view the output in your browser to see if any errors are being generated</p>
<p>I tried it, and it works. It produced a piece of red text, saying "Quiz canceled!".</p> <p>Maybe you should check whether $c and $i are both indeed 0?</p> <p>I assume you have &lt; ? php and ? > tags at the beginning and end of the file?</p> <p>Edit: also, is the ttf font file in the right location?</p> <p>It mi...
49,566
<p>I have something like the following in an ASP.NET MVC application:</p> <pre><code>IEnumerable&lt;string&gt; list = GetTheValues(); var selectList = new SelectList(list, "SelectedValue"); </code></pre> <p>And even thought the selected value is defined, it is not being selected on the view. I have this feeling I'm ...
<p>Try this instead:</p> <pre><code>IDictionary&lt;string,string&gt; list = GetTheValues(); var selectList = new SelectList(list, "Key", "Value", "SelectedValue"); </code></pre> <p>SelectList (at least in Preview 5) is not clever enough to see that elements of IEnumerable are value type and so it should use the item ...
<p>Take a look at this: <a href="http://replay.web.archive.org/20090628135923/http://blog.benhartonline.com/post/2008/11/24/ASPNET-MVC-SelectList-selectedValue-Gotcha.aspx" rel="nofollow noreferrer">ASP.NET MVC SelectList selectedValue Gotcha</a></p> <p>This is as good explanation of what is going on as any.</p>
27,455
<p>I'm using the following JavaScript code:</p> <pre><code>&lt;script language="JavaScript1.2" type="text/javascript"&gt; function CreateBookmarkLink(title, url) { if (window.sidebar) { window.sidebar.addPanel(title, url,""); } else if( window.external ) { window.external.AddFavorite( url, tit...
<p>I think that's the only solution for Firefox... I have a better function for that action, it works even for Opera and shows a message for other "unsupported" browsers.</p> <pre><code>&lt;script type="text/javascript"&gt; function addBookmark(url,name){ if(window.sidebar &amp;&amp; window.sidebar.addPanel) { ...
<p>You have a special case for </p> <pre><code>if (window.sidebar) </code></pre> <p>and then a branch for 'else' - wouldn't firefox land in the first branch and hence only add the panel?</p>
13,333
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
<p>You may have "Class" and "Instance" confused. It's not clear from your example, so I'll presume that you're using a lot of class definitions and don't have appropriate object instances of those classes.</p> <p>Classes don't really have usable attribute values. A class is just a common set of definitions for a col...
<p>If I understood you correctly, then the answer is: You can't.</p> <p>intelligence should be an attribute of WizardPageSimple, if you'd want both classes to inherit it.</p> <p>Depending on your situation, you might try to extract intelligence and related attributes into another baseclass. Then you could inherit fro...
13,841
<p>I am migrating a site from SharePoint 2 to 3 (in fact, from SharePoint Portal Server 2003 to Microsoft Office SharePoint Server 2007). There are a handful of 3rd party web parts and since this is a migration, not an in-place upgrade, I need to install these web parts on the new farm.</p> <p>How do I do this, given...
<p>You can still install .CAB files with WSSv3 using the same STSADM command as you used in WSSv2</p> <pre><code>STSADM -o addwppack -filename &lt;filename.CAB&gt; </code></pre> <p>However, maybe you should get in touch with the providers of these 3rd party web parts? Perhaps they will have versions for WSSv3 package...
<p>You should be able to pull them apart and either repackage them as solutions or manually deploy them. Obviously, if they are real complicated webparts that have other dependencies, this might become more difficult.</p>
22,721
<p>My business is setting up online billing using PayPal and Google checkout. I'm looking for the best way to charge a recurring monthly service fee for my website. My site is subscription based and I charge X amount of dollars per month. I want to bill the customer's credit card each month for that monthly fee. Th...
<p>Google Checkout doesn't currently support recurring billing, but it is on their <a href="http://checkout.google.com/support/sell/bin/request.py?contact_type=suggest" rel="noreferrer">Feature Suggestions</a> page.</p> <p>PayPal supports <a href="https://www.paypal.com/IntegrationCenter/ic_recurringpayments.html" rel...
<p>Goole Checkout now supports "Recurring charges and subscriptions" in beta mode</p> <p>There's more info at <a href="http://support.google.com/checkout/sell/bin/answer.py?hl=en&amp;answer=63440" rel="nofollow">Google's site</a></p>
36,621
<p>What exactly do <code>*args</code> and <code>**kwargs</code> mean?</p> <p>According to the Python documentation, from what it seems, it passes in a tuple of arguments.</p> <pre><code>def foo(hello, *args): print(hello) for each in args: print(each) if __name__ == '__main__': foo(&quot;LOVE&quot...
<p>Putting <code>*args</code> and/or <code>**kwargs</code> as the last items in your function definition’s argument list allows that function to accept an arbitrary number of arguments and/or keyword arguments.</p> <p>For example, if you wanted to write a function that returned the sum of all its arguments, no matter ...
<p>Just to clarify how to unpack the arguments, and take care of missing arguments etc.</p> <pre><code>def func(**keyword_args): #--&gt;keyword_args is a dictionary print 'func:' print keyword_args if keyword_args.has_key('b'): print keyword_args['b'] if keyword_args.has_key('c'): print keyword_args['c'] de...
36,513
<p>I'm missing the boat on something here, kids. This keeps rearing its head and I don't know what's going on with it, so I hope my homeys here can help.</p> <p>When working in Silverlight, when I create bindings in my c# code, they never hold up when the application is running. The declarative bindings from my xaml...
<p>I've just tried the exact code you just posted and it worked fine, with some changes. I believe the problem is the element you are using for the SetBinding call is not the textblock you want to bind. It should be:</p> <pre><code>TextBlock tb = new TextBlock(); Binding b = new Binding("FontSize"); b.Source = this; t...
<p>I've just tried the exact code you just posted and it worked fine, with some changes. I believe the problem is the element you are using for the SetBinding call is not the textblock you want to bind. It should be:</p> <pre><code>TextBlock tb = new TextBlock(); Binding b = new Binding("FontSize"); b.Source = this; t...
9,748
<p>I can't find any information about this on either www.episerver.com or world.episerver.com, anyone knows?</p>
<p>thread safe is a nebulous concept. In this particular case, if you are sharing data between different requests, it is not. Otherwise by the nature of web requests it is.</p>
<p>Yes, per definition it is thread safe because it runs under a web service that uses threads to execute (so it has to be thread safe otherwise it is a bug, and there has been o few of those bugs – but no one reported for CMS R2 what I can see in the bug list). </p>
22,532
<p>I'm passing small (2-10 KB)XML documents as input to a WCF service. now I've two option to read data values from incoming XML</p> <ol> <li>Deserialize to a strongly typed object and use object properties to access values</li> <li>use XPath to access values</li> </ol> <p>which approach is faster? some statistics to...
<p>I would deserialize it.</p> <p>If you use xpath, you will deserialize (or "load") it to XmlDocument or something anyway. So both solutions use time deserializing. After this is done, xpath will be slower because of the time spent parsing that string, resolving names, executing functions and so on. Also, if you go w...
<p>There's a third option of sticking with XML, but query with whatever XML API you're using - e.g. LINQ to XML makes queries relatively straightforward in code.</p> <p>Have you already parsed the text into an XML document?</p> <p>Are you convinced that this is actually a significant performance bottleneck in your co...
35,047
<blockquote> <p>CREATE DATABASE permission denied in database 'master'. An attempt to attach an auto-named database for file C:\Documents and Settings\..\App_Data\HelloWorld.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.</p> </blockquote>...
<p>Generally the user that you are using to run the SQL Server service will not have access to your personal user folders, that is why you're getting the error. You either need to change the credentials used for the service, or move the database to another folder, which did the trick in your case.</p>
<p>Yes, a previous attachment wasn't unattached properly, or it was attached manually. Go in to Management Studio connect to the database, and disconnect the long database name that looks like a file path. Then try again it should work.</p>
3,564
<p>I have a batch file that uses this idiom (many times) to read a registry value into an environment variable:</p> <pre><code>FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName') DO SET MyVariable=%%B </code></pre> <p>(There's a tab character after <code>delims=</code>)</p> <p>...
<p>I would check:</p> <ol> <li>The customer's role on the machine - are they an admin?</li> <li>Where is reg.exe on the box - is there more than one copy of copy of reg.exe in the path? </li> <li>Is there any locale difference on the customer's machine from the machines where this normally works? </li> </ol> <p>Basi...
<p>The <code>/F</code> switch needs command extensions to be turned on. Usually they are turned on by default, but I'd check that. On XP systems you can turn them on doing something like</p> <pre><code>cmd /e:on </code></pre> <p>or checking the registry under </p> <pre><code>HKCU\Software\Microsoft\Command Processor...
22,174