instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>I recently heard that the 3D printing lab at my college can do fused-deposition with ABS and PLA, but I would like to use TPU, for greater flexibility.</p>
<p>Is it possible to feed a TPU filament into the same machine built for ABS/PLA? Or is there no difference? Assume the diameters of the filaments are the same.</p>
|
<blockquote>
<p>Is it possible to feed a TPU filament into the same machine built for ABS/PLA? Or is there no difference? Assume the diameters of the filaments are the same.</p>
</blockquote>
<p>The question is not what the machine is <em>built for</em> but <em>how</em> it is built. Let's break stuff down some into why some filaments work better than others and the challenges with them.</p>
<h2>Temperature range</h2>
<p>The first obstacle is the temperature range of the printer. For example, if your printer's Extruder can't get over 220 °C, you can't print ABS. You need to make sure your printer can match your intended filament's temperature range.</p>
<p>TPU usually prints around between the same temperatures for PLA and ABS, so it should work from that range.</p>
<h2>Heated Bed</h2>
<p>Most Filaments work better with a heated bed, but some are almost impossible to be printed without. For TPU, a heated bed should be used but is not absolutely mandatory.</p>
<h2>Heated Chamber</h2>
<p>Some filaments can't be printed without a heated chamber, others like ABS highly benefit from it. TPU is ambivalent on this as far as I know.</p>
<h2>Extruder Setup</h2>
<p>There's basically 3 extruder setups. Pellet extruders are super rare, so we don't concern about them. The other two are Direct Drive and Bowden. In a Direct Drive, the extruder motor is right over the hotend, and pushes the filament directly into it. In a Bowden setup, the hotend and the extruder motor are connected via a Bowden tube. Both have benefits and drawbacks:</p>
<p>A Bowden makes for a lighter carriage, leading to faster printing speeds. A Direct Drive has much less trouble with elastic filaments and can do much better with retraction.</p>
<p>TPU is one of the filaments that works much better with Direct Drive.</p>
<h2>Other considerations</h2>
<p>Some Print services do print in machines set up for one filament type and that only, because it prevents cross-contamination of the nozzles, especially when a high-temperature print material remains in it when a low-temperature print comes next. Having for example a little bit of ABS left in a printer that runs PLA next can lead to very very extreme clogging.</p>
|
<p>Most printers can print most filaments. However, some more exotic filaments are not suitable for all printers:</p>
<ul>
<li><p>To print a flexible filament such as TPU, the filament path from the extruder needs to be well-constrained. A bowden extruder is generally less good at handling flexible filaments than a direct extruder. Some direct extruders without a well-constrained filament path may also be unsuitable.</p></li>
<li><p>A printer without a heated bed won't be able to print filaments that tend to warp such as ABS.</p></li>
<li><p>A printer without a (heated) enclosure won't be able to print filaments that tend to warp <em>a lot</em> such as polycarbonate</p></li>
<li><p>A printer with a PTFE-lined hotend won't be able to print filaments that require higher temperatures. PETG is at the upper end of what can be (safely) printed with a PTFE-lined hotend, while filaments such as polycarbonate require temperatures well outside the usable range.</p></li>
<li><p>A printer with a standard brass nozzle won't be able to print (not long, anyways) abrasive filaments such as glow-in-the-dark.</p></li>
</ul>
<p>It is likely the printer at your lab will be able to handle TPU just fine. If it is a bowden printer then you might have some difficulty printing but it might still work depending on exactly how soft the filament is and how well-constrained the filament path.</p>
| 1,680
|
<p>I am making a simple game in order to learn a new language. I am in the process of collecting some music for the game and would like to use the MIDI format so that I can control the flow of the track (i.e., I would like to have an introduction that only plays once and does not play again when the song loops.)</p>
<p>I am having a tough time finding information on how to modify existing MIDI files so that they may send a control change signal to the synthesizer. Has anyone had experience with this?</p>
<hr>
<p>I think that I should have been more clear with my original question. I am using an existing game engine which takes care of playing the music. I am under the impression that this control change value must be embedded directly in the MIDI file itself as I have no control over the synthesizer. From the manual:</p>
<blockquote>
<p>MIDI files are played via the
DirectMusic Synthesizer. If a BGM MIDI
file contains the control change value
111, that value is recognized as where
the song will start repeating after it
reaches the end.</p>
</blockquote>
<p>I wish I could do it programmatically. I suppose what I am after here is some sort of editor which will allow me to modify the MIDI file that I already have. </p>
|
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=6E938A6E-B383-466B-A3EE-5A655BF5DB8C&displaylang=en" rel="nofollow noreferrer">DirectMusicProducer</a> is probably your best free option if you are playing using DirectMusic. I don't believe the MIDI record feature will include control changes, but your engine may support playing segment files which are much more flexible.</p>
<p>The only MIDI sequencer I use cost around $300 (USD) about 10 years ago (and no longer appears to exist), but I am not aware of any good quality free MIDI file sequencers. (Note that "MIDI editor" is probably different to "MIDI file editor" or "MIDI sequencer")</p>
|
<p>try looking in the <a href="http://www.midi.org/about-midi/specinfo.shtml" rel="nofollow noreferrer">Midi 1.0 spec</a></p>
<p>Here's a table of the <a href="http://www.midi.org/about-midi/table3.shtml" rel="nofollow noreferrer">control change messages</a> though it looks like you're looking for a way to do this in software. yes?</p>
<p>you could try just sending it as raw midi data (ie. the messages on that table)</p>
<p>looking over your question again... my answer is not that useful...</p>
<p>what I would do if I were you is separate the introduction into it's own file and then you have a file containing <strong>just</strong> what you want to loop.</p>
<p>you could also look at the spec for the <A href="http://www.midi.org/about-midi/smf/index.shtml" rel="nofollow noreferrer">Standard Midi File format (SMF)</a></p>
| 5,420
|
<p>I have a MS SQL DB with various tables, and one field in particular is causing me grief.</p>
<p>The Data type is set to varchar(100), however the field is limited to 60 characters.</p>
<p>If I try to put any string with more than 60 characters into the field I get an exception,
"String or binary data would be truncated". Although the string is shorter than the explicitly set data type, it still throws an exception.</p>
<p>Is there perhaps a DB setting that does this? What could cause the explicitly set data type to be overwritten?</p>
<p><b>Edit:</b><br />
<em>The triggers do not copy the value or insert it into another table and they don't use the data either.</em> - (Incorrect)</p>
<p>Strings that are smaller than 60 chars work fine.</p>
<p>All the columns that have varchar(100) give the same problem, but all the other columns accept correct values. The varchar(10) column works fine.</p>
<p>Any row in this table throws the exception if I try to update the field with a string longer than 60 chars.</p>
<p>I am trying to insert the data directly into the field using SQL Server Management Studio.</p>
<p>There is no padding involved.</p>
<p><b>Answer:</b></p>
<p>There was a second table where the column was set to 60. The update trigger called a stored Procedure that inserts the data into the "Denormalised" table.</p>
<p>Thanks for all the help.</p>
|
<p>Perhaps you need NVARCHAR(100) or rather NVARCHAR(60).</p>
<p>Single character in the NVARCHAR is double the size of VARCHAR. You would use NVARCHAR if your input data is unicode</p>
<p><strong>EDIT:</strong></p>
<p>Based on your comments it looks like using nvarchar is not necessary a solution to the problem, and it is pretty hard to guess what the issues are with the information provided so far:</p>
<p>Could you script your table, with constraints and triggers and post the code, that would definitely help in finding the source of the problem.</p>
|
<p>Perhaps you need NVARCHAR(100) or rather NVARCHAR(60).</p>
<p>Single character in the NVARCHAR is double the size of VARCHAR. You would use NVARCHAR if your input data is unicode</p>
<p><strong>EDIT:</strong></p>
<p>Based on your comments it looks like using nvarchar is not necessary a solution to the problem, and it is pretty hard to guess what the issues are with the information provided so far:</p>
<p>Could you script your table, with constraints and triggers and post the code, that would definitely help in finding the source of the problem.</p>
| 44,212
|
<p>I am currently publishing code behind .aspx in SharePoint. I can automatically publish the .dll to the bin folder of the virtual directory, but I cannot figure out how to push the .aspx pages and images to the server without manually using SharePoint Designer.</p>
<p>Where does the folder exist?</p>
<p>Or do I need to create a SharePoint feature for this?</p>
|
<p>If both servers would be on Linux you could use <a href="http://samba.anu.edu.au/rsync/" rel="noreferrer">rsync</a> for any kind of files (php, xml, html, binary, etc). Even if one of them will be Windows there are rsync ports to Windows.</p>
|
<p>I had some similar situation.
After some tries, I did some thing different</p>
<p>We have 2 servers,
a (that have the original files)
b (files should moved to it)</p>
<p>And for sure the data is NOT sensitive</p>
<p>Now in server a I made a file to do the following when called:
1. Choose the file to move
2. Zip the file
3. Print the .zip file location
4. Delete the .zip file (and the original file) if delete parameter passes</p>
<p>In the server b the file should do:
1. Call the file on the a server
2. Download the zip file
3. Unzip and copy it to the proper location
4. Call the delete function on server a</p>
<p>This way I have more control on my functions, tests and operations!</p>
| 30,353
|
<p>I've got a bunch of unit tests built using Visual Studio 2005's built-in unit testing functionality. For the last little while, it's been taking absolutely <i>forever</i> to start the tests... Everything just sits there at "Pending" for two minutes or more. Now Visual Studio's decided to take things to a new level and never even start the tests. After two to three minutes, it aborts the run and barfs an error message into the log:</p>
<p>Failed to Queue Test Run '(blahblahblah)' with id {bfba05b1-afe5-499e-b452-29167f414f0f}: Microsoft.VisualStudio.TestTools.TestManagement.ExecutionException: Failed to establish communication environment for local run.</p>
<p>Anyone have any ideas? In the medium term, we are planning to switch to NUnit, but for now I'd prefer to stick to Visual Studio because the rest of the team already has that installed and that makes it easier to convince them to actually run the tests... ;-)</p>
|
<p>Is your computer name UPPERCASE? change it to lower case and try it again.</p>
|
<p>Let me say this MS TEST is not a professional product and should be avoided whenever possible. If you want to use a good testing framework then use MBUnit with TestDriven.NET. MBUnit comes with many new attributes including RollBack and RowTest , Row. </p>
<p>Also, TestDriven.NET will allow you to debug your unit tests (How cool is that). You can also run the code coverage from TestDriven.NET which shows you how much of your code is covered under tests. </p>
<p>Give it a try I am sure you like it. </p>
<p>PS: IT is FREEE</p>
| 22,938
|
<p>I have a simple "accordion" type page containing a list of H3 headers and DIV content boxes (each H3 is followed by a DIV). On this page I start with all DIVs hidden. When a H3 is clicked the DIV directly below (after) is revealed with jQuery's <a href="http://jquery.com/api/#slideDown" rel="nofollow noreferrer">"slideDown"</a> function while all other DIVs are hidden with the <a href="http://jquery.com/api/#slideUp" rel="nofollow noreferrer">"slideUp"</a> function.</p>
<p>The "slideUp" function inserts the following inline style into the specified DIVs:</p>
<pre><code>style="display: none;"
</code></pre>
<p>I am wondering if there is any way for me to show all the DIVs expanded when a user prints the page (as I do when a user has JavaScript disabled).</p>
<p>I am thinking it is impossible because the inline style will always take precedence over any other style declaration.</p>
<p>Is there another solution?</p>
<p><strong>Solution</strong></p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186189">Sugendran's solution</a> is great and works in the browsers (FF2, IE7 and IE6) I've tested so far. I wasn't aware there was any way to override inline styles which I'm pretty sure is something I've looked up before so this is great to find out. I also see there is <a href="https://stackoverflow.com/questions/104485/is-there-a-way-to-force-a-style-to-a-div-element-which-already-has-a-style-attr#104499">this answer here</a> regarding this. I wish search wasn't so difficult to navigate here :-).</p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186276">Lee Theobald's solution</a> would be great but the "slideUp" function adds the style="display:none;" bit. </p>
<p><a href="https://stackoverflow.com/questions/186035/is-it-possible-to-print-a-div-that-is-hidden-by-jquerys-slideup-function#186036">My solution</a> works fine, but is overkill when the !important declaration works.</p>
|
<p>You can use the !important clause in CSS. This will override the inline style.</p>
<p>So if you setup a print media stylesheet - you can do something like</p>
<pre><code>div.accordian { display:block !important; }
</code></pre>
|
<p>Yes.</p>
<p>On load add a class (e.g. "hideme") to all relevant DIVs like so:</p>
<pre><code>$('div#accordion> div').addClass('hideme');
</code></pre>
<p><em>NB: This means that the accordion degrades fine when JavaScript is disabled.</em></p>
<p>In this way you can have your regular stylesheet specify the "hideme" class like this:</p>
<pre><code>.hideme { display: none; }
</code></pre>
<p>While your print stylesheet can specify the "hideme" class like this:</p>
<pre><code>div.hideme { display: block; }
</code></pre>
<p>Next, in the 'click' function you add to each H3, after sliding up the DIVs, add the "hideme" class and then remove the "style" attribute from each DIV that was slided up.</p>
<p>The overall jQuery for this looks like this:</p>
<pre><code><script type="text/javascript">
//<![CDATA[
$(function() {
$('#accordion> div').addClass('hideme');
$('#accordion> h3').click(function() {
$(this).next('div:hidden').slideDown('fast').siblings('div:visible').slideUp('fast', function(){ $('#accordion> div:hidden').addClass('hideme').removeAttr('style'); });
});
});
//]]>
</script>
</code></pre>
<p>Note the need to include the function callback in the slideUp function so that the style and class changes occur after the DIV has slided up and jQuery has added "style=display:none;"</p>
| 22,506
|
<p>I've got a particular SQL statement which takes about 30 seconds to perform, and I'm wondering if anyone can see a problem with it, or where I need additional indexing.</p>
<p>The code is on a subform in Access, which shows results dependent on the content of five fields in the master form. There are nearly 5000 records in the table that's being queried. The Access project is stored and run from a terminal server session on the actual SQL server, so I don't think it's a network issue, and there's another form which is very similar that uses the same type of querying...</p>
<p>Thanks</p>
<p>PG</p>
<pre><code>SELECT TabDrawer.DrawerName, TabDrawer.DrawerSortCode, TabDrawer.DrawerAccountNo, TabDrawer.DrawerPostCode, QryAllTransactons.TPCChequeNumber, tabdrawer.drawerref
FROM TabDrawer LEFT JOIN QryAllTransactons ON TabDrawer.DrawerRef=QryAllTransactons.tpcdrawer
WHERE (Forms!FrmSearchCompany!SearchName Is Null
Or [drawername] Like Forms!FrmSearchCompany!SearchName & "*")
And (Forms!FrmSearchCompany.SearchPostcode Is Null
Or [Drawerpostcode] Like Forms!FrmSearchCompany!Searchpostcode & "*")
And (Forms!FrmSearchCompany!SearchSortCode Is Null
Or [drawersortcode] Like Forms!FrmSearchCompany!Searchsortcode & "*")
And (Forms!FrmSearchCompany!Searchaccount Is Null
Or [draweraccountno] Like Forms!FrmSearchCompany!Searchaccount & "*")
And (Forms!FrmSearchCompany!Searchcheque Is Null
Or [tpcchequenumber] Like Forms!FrmSearchCompany!Searchcheque & "*");
");
</code></pre>
<hr>
<p><strong>EDIT</strong></p>
<p>The Hold up seems to be in the union query that forms the QryAllTransactons query.</p>
<pre><code>SELECT
"TPC" AS Type,
TabTPC.TPCRef,
TabTPC.TPCBranch,
TabTPC.TPCDate,
TabTPC.TPCChequeNumber,
TabTPC.TPCChequeValue,
TabTPC.TPCFee,
TabTPC.TPCAction,
TabTPC.TPCMember,
tabtpc.tpcdrawer,
TabTPC.TPCUser,
TabTPC.TPCDiscount,
tabcustomers.*
FROM
TabTPC
INNER JOIN TabCustomers ON TabTPC.TPCMember = TabCustomers.CustomerID
UNION ALL
SELECT
"CTP" AS Type,
TabCTP.CTPRef,
TabCTP.CTPBranch,
TabCTP.CTPDate,
TabCTP.CTPChequeNumb,
TabCTP.CTPAmount,
TabCTP.CTPFee,
TabCTP.CTPAction,
TabCTP.CTPMember,
0 as CTPXXX,
TabCTP.CTPUser,
TabCTP.CTPDiscount,
TABCUSTOMERS.*
FROM
TabCTP
INNER JOIN TabCustomers ON Tabctp.ctpMember = TabCustomers.CustomerID;
</code></pre>
<p>I've done a fair bit of work with simple union queries, but never had this before...</p>
|
<p>Two things. Since this is an Access database with a SQL Server backend, you may find a considerable speed improvement by converting this to a stored proc.</p>
<p>Second, do you really need to return all those fields, especially in the tabCustomers table? Never return more fields than you actually intend to use and you will improve performance.</p>
|
<p>How many rows are in QryAllTransactons?</p>
<p>If your result returns 0 rows then Access may be able to see that immediately and stop, but if it returns even a single row then it needs to pull in the entire resultset of QryAllTransactons so that it can do the join internally. That would be my first guess as to what is happening.</p>
<p>Your best bet it usually to do joins on SQL Server. Try creating a view that does the LEFT OUTER JOIN and query against that.</p>
<p>Your goal, even when Access is running on the SQL Server itself and minimizes network traffic, is to only send to Access what it absolutely needs. Otherwise a large table will still take up memory, etc.</p>
| 35,573
|
<p>I'm a bit perplexed by drag and drop in wxPython (but perhaps this questions pertains to drag and drop in other GUI frameworks as well). The frameworks provides a couple of callbacks (OnEnter and OnDragOver) that purportedly allow me to inform the system whether the current mouse position is a valid place to drop whatever it is that is being dragged. From these methods I can return wx.DragNone, wx.DragCopy, etc. What baffles me is that from within these methods I am not allowed to call GetData, which means I am not allowed to examine the data that the user is dragging. If I cannot see the data, how am I supposed to know whether it is OK for the user to drop here?</p>
|
<p>@Geoff- </p>
<p>The system, which has been in production for 8+ years, was architected to use PL/SQL for the CRUDs and <em>most</em> of the business logic. The PL/SQL also generates 90% of the presentation layer (HTML/JavaScript), using <a href="http://www.orafaq.com/wiki/Mod_plsql_FAQ" rel="nofollow noreferrer">mod PL/SQL</a>. The other 10% is report data done via Oracle Reports Builder.</p>
<p>So, there isn't application code like you'd see in more modern, better architected systems. I do <strong>want</strong> to do things the <em>right</em> way, I just don't have that luxury given organizational constraints.</p>
|
<p>I wonder why you don't want to bring the data from Oracle into some application code and make JSON there?</p>
| 4,624
|
<p>Wanna write a RegEx to validate a driving license. </p>
<p>if it doesn't start with (US, CA, CN) then it has to be followed with XX and after that with any number of Alpha numeric letters. </p>
<p>So for example if the driving license starts with GB then it has to be followed with XX
GBXX12345363
However if it starts with US then we don't care what comes after it.
USLA039247230</p>
|
<p>Remember not everyone is familiar with that driving license notation, I'm assuming that what follows is the precise specification (you should really try to be very precise when asking for a regex else you'll get things you don't want):</p>
<ul>
<li>Has to start with two capital letters</li>
<li>If those first two letters are either US, CA or CN, the rest has to be alphanumeric and of unspecified length</li>
<li><p>If those first two letters are none of US, CA or CN, then the next two letters have to be X, the rest after that has to be alphanumeric and of unspecified length </p>
<p>((US|CA|CN)[A-Za-z0-9]+|(?<!(US|CA|CN))[A-Z]{2}XX[A-Za-z0-9]+)</p></li>
</ul>
<p>First part:</p>
<ul>
<li>Matches one of US, CA or CN</li>
<li>One or more alphanumeric characters</li>
</ul>
<p>Second part:</p>
<ul>
<li>Negative lookbehind, doesn't start with US CA CN</li>
<li>Has two uppercase letters</li>
<li>There are two X characters</li>
<li>One or more alphanumeric characters</li>
</ul>
<p>And it matches either the first part or the second one</p>
|
<pre><code>/^(?:(?:US|CA|CN)\w+|[[:alpha:]]{2}XX\w+)$/
</code></pre>
<p>I'm not sure if there's more validation that can be done, but this is what I get from what you wrote, not your examples (which seem to imply four letters followed by numbers).</p>
| 30,250
|
<p>I have a simple web page that till now didn't need any login. It is programed with Perl CGIs.</p>
<p>I would like to know the steps to add session support in order to have the login information available.</p>
<p>I don't want very complicated methods, because the web page is very simple.</p>
<p>Also I want some recommendations for the technologies/libs that I need to support sessions with Perl.</p>
|
<p>I used CGI::Session many, many moons ago.</p>
<p><a href="http://metacpan.org/pod/CGI::Session" rel="nofollow noreferrer">http://metacpan.org/pod/CGI::Session</a></p>
|
<p>I've used <a href="http://metacpan.org/pod/Apache::Session" rel="nofollow noreferrer">Apache::Session</a> for session management:</p>
| 33,226
|
<p>I would like to be able to set "Extend my Windows desktop onto this monitor" via code. A PowerShell script would be ideal. WMI seems the way forward but I have zero knowledge in WMI.</p>
|
<p>Windows 7, 8 and 10 are supposed to come with a small program that does exactly this: displayswitch.exe. <a href="http://jeffwouters.nl/index.php/2012/06/switch-your-display-through-the-command-line/" rel="noreferrer">This page</a> lists the following parameters:</p>
<pre><code>displayswitch.exe /internal Disconnect projector (same as "Show only on 1" from the Display Properties dialog)
displayswitch.exe /clone Duplicate screen
displayswitch.exe /extend Extend screen
displayswitch.exe /external Projector only (disconnect local) (same as "Show only on 2" from the Display Properties dialog)
</code></pre>
<p>For a one-click solution to the problem posed, simply create a *.bat-file containing the single line</p>
<pre><code>call displayswitch.exe /extend
</code></pre>
<p>and save it to your desktop.</p>
<p>[I tested this on Windows 8.1, and it has been confirmed to work on Windows 10.]</p>
|
<p>I had to made some small modifications to get VonC's script to work on my machine. It is now a little more generic.</p>
<pre><code>;
; — toggle-screen2.au3
;
#include <WinAPI.au3>
; exec cpanel app `display settings`
Run(_WinAPI_ExpandEnvironmentStrings("%windir%") & "\system32\control.exe desk.cpl,@0,3?")
; wait for window to be active
WinWaitActive("Display Properties")
; select 2nd display
Send("!d")
Send("{DOWN}")
; toggle the ‘extend desktop’ checkbox
Send("!e")
; close the dialog
Send("{ENTER}")
</code></pre>
| 34,662
|
<p>I would like to update a Windows Forms application to provide the following features:</p>
<ul>
<li>spell checking</li>
<li>limited formatting of text: bold, italics, bulleted lists</li>
</ul>
<p>Ideally the formatted text could be accessed in a plain text way for reporting through tools that don't support the formatting, but could also be rendered as HTML for tools that support HTML tags when rendering text.</p>
<p>It seems to me that the WPF RichTextBox would provide this functionality. What is the best way to incorporate it? Would you suggest other alternatives?</p>
|
<p>You can add / create a drop-in spell checker for the Window Forms RichTextBox.</p>
<p>A ready to go <a href="http://www.c-sharpcorner.com/UploadFile/scottlysle/SpellCheckCC05152007084528AM/SpellCheckCC.aspx" rel="nofollow noreferrer">richtextbox</a> custom control with spell checking.
An app for <a href="http://www.codeproject.com/KB/string/netspell.aspx" rel="nofollow noreferrer">checking spelling</a> that could be easily integrated</p>
<p>Also <a href="http://www.c-sharpcorner.com/UploadFile/mahesh/WPFRichTextBox09072008194855PM/WPFRichTextBox.aspx" rel="nofollow noreferrer">here</a> is a article on adding a WPF RichTextBox to your application, as well as getting spell checking working. (Requires .NET 3.0+)</p>
|
<p>Windows Forms has a RichTextBox also. If you're in a Windows Forms application, it will be easier to incorporate that than incorporate the WPF control.</p>
| 20,588
|
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace ConsoleApplication1
{
public class Class1
{
static void Main(string[] args)
{
List<Car> mylist = new List<Car>();
Car car1;
Car car2;
Car car3;
car1 = new Car()
{
make = "Honda",
id = 1
};
car2 = new Car()
{
make = "toyota",
id = 2
};
car3 = new Car()
{
make = "Honda",
id = 3,
color = "red"
};
mylist.Add(car1);
mylist.Add(car2);
**////mylist.Where(p => p.id == 1).SingleOrDefault() = car3;**
}
}
public class Car
{
public int id { get; set; }
public string make { get; set; }
public string color { get; set; }
}
}
</code></pre>
<p>How can I update the list by replacing the honda car of Id 1 with honda car with Id 3 in the best way.</p>
|
<p>Everything leppie said - plus:</p>
<pre><code>int index = mylist.FindIndex(p => p.id == 1);
if(index<0) {
mylist.Add(car3);
} else {
mylist[index] = car3;
}
</code></pre>
<p>This just uses the existing FindIndex to locate a car with id 1, then replace or add it. No LINQ; no SQL - just a lambda and <code>List<T></code>.</p>
|
<p>Just one question, why do I have to write a Update function for something that seems so basic for a list? There should be standard methods for Lists like Add(), Delete(), Edit(), Insert(), Replace() ....Find()</p>
| 47,238
|
<p>I'm trying to put several images together into one big image, and am looking for an algorithm which determines the placing most optimally. The images can't be rotated or resized, but the position in the resulting image is not important.</p>
<p>edit: added no resize constraint</p>
|
<p>Possibly you are looking for something like this: <a href="http://www.alistapart.com/articles/magazinelayout" rel="nofollow noreferrer">Automatic Magazine Layout</a>.</p>
|
<p>You are probably looking for <a href="http://en.wikipedia.org/wiki/Scale-invariant_feature_transform" rel="nofollow noreferrer">SIFT</a></p>
<p><a href="http://www.cs.ubc.ca/~lowe/keypoints/" rel="nofollow noreferrer">http://www.cs.ubc.ca/~lowe/keypoints/</a></p>
<p><a href="http://user.cs.tu-http://www.cs.ubc.ca/~lowe/keypoints/.de/~nowozin/autopano-sift/technicaldetails.html" rel="nofollow noreferrer">http://user.cs.tu-http://www.cs.ubc.ca/~lowe/keypoints/.de/~nowozin/autopano-sift/technicaldetails.html</a></p>
| 15,272
|
<p>As we all know numbers can be written either in numerics, or called by their names. While there are a lot of examples to be found that convert 123 into one hundred twenty three, I could not find good examples of how to convert it the other way around.</p>
<p>Some of the caveats:</p>
<ol>
<li>cardinal/nominal or ordinal: "one" and "first"</li>
<li>common spelling mistakes: "forty"/"fourty"</li>
<li>hundreds/thousands: 2100 -> "twenty one hundred" and also "two thousand and one hundred"</li>
<li>separators: "eleven hundred fifty two", but also "elevenhundred fiftytwo" or "eleven-hundred fifty-two" and whatnot</li>
<li>colloquialisms: "thirty-something"</li>
<li>fractions: 'one third', 'two fifths'</li>
<li>common names: 'a dozen', 'half'</li>
</ol>
<p>And there are probably more caveats possible that are not yet listed.
Suppose the algorithm needs to be very robust, and even understand spelling mistakes.</p>
<p>What fields/papers/studies/algorithms should I read to learn how to write all this?
Where is the information?</p>
<blockquote>
<p>PS: My final parser should actually understand 3 different languages, English, Russian and Hebrew. And maybe at a later stage more languages will be added. Hebrew also has male/female numbers, like "one man" and "one woman" have a different "one" — "ehad" and "ahat". Russian also has some of its own complexities.</p>
</blockquote>
<p>Google does a great job at this. For example:</p>
<p><a href="http://www.google.com/search?q=two+thousand+and+one+hundred+plus+five+dozen+and+four+fifths+in+decimal" rel="noreferrer">http://www.google.com/search?q=two+thousand+and+one+hundred+plus+five+dozen+and+four+fifths+in+decimal</a></p>
<p>(the reverse is also possible <a href="http://www.google.com/search?q=999999999999+in+english" rel="noreferrer">http://www.google.com/search?q=999999999999+in+english</a>)</p>
|
<p>I was playing around with a PEG parser to do what you wanted (and may post that as a separate answer later) when I noticed that there's a very simple algorithm that does a remarkably good job with common forms of numbers in English, Spanish, and German, at the very least.</p>
<p>Working with English for example, you need a dictionary that maps words to values in the obvious way:</p>
<pre><code>"one" -> 1, "two" -> 2, ... "twenty" -> 20,
"dozen" -> 12, "score" -> 20, ...
"hundred" -> 100, "thousand" -> 1000, "million" -> 1000000
</code></pre>
<p>...and so forth</p>
<p>The algorithm is just:</p>
<pre><code>total = 0
prior = null
for each word w
v <- value(w) or next if no value defined
prior <- case
when prior is null: v
when prior > v: prior+v
else prior*v
else
if w in {thousand,million,billion,trillion...}
total <- total + prior
prior <- null
total = total + prior unless prior is null
</code></pre>
<p>For example, this progresses as follows:</p>
<pre><code>total prior v unconsumed string
0 _ four score and seven
4 score and seven
0 4
20 and seven
0 80
_ seven
0 80
7
0 87
87
total prior v unconsumed string
0 _ two million four hundred twelve thousand eight hundred seven
2 million four hundred twelve thousand eight hundred seven
0 2
1000000 four hundred twelve thousand eight hundred seven
2000000 _
4 hundred twelve thousand eight hundred seven
2000000 4
100 twelve thousand eight hundred seven
2000000 400
12 thousand eight hundred seven
2000000 412
1000 eight hundred seven
2000000 412000
1000 eight hundred seven
2412000 _
8 hundred seven
2412000 8
100 seven
2412000 800
7
2412000 807
2412807
</code></pre>
<p>And so on. I'm not saying it's perfect, but for a quick and dirty it does quite well.</p>
<hr>
<p>Addressing your specific list on edit:</p>
<ol>
<li>cardinal/nominal or ordinal: "one" and "first" -- <strong>just put them in the dictionary</strong></li>
<li>english/british: "fourty"/"forty" -- <strong>ditto</strong></li>
<li>hundreds/thousands:
2100 -> "twenty one hundred" and also "two thousand and one hundred" -- <strong>works as is</strong></li>
<li>separators: "eleven hundred fifty two", but also "elevenhundred fiftytwo" or "eleven-hundred fifty-two" and whatnot -- <strong>just define "next word" to be the longest prefix that matches a defined word, or up to the next non-word if none do, for a start</strong></li>
<li>colloqialisms: "thirty-something" -- <strong>works</strong></li>
<li>fragments: 'one third', 'two fifths' -- <strong>uh, not yet...</strong></li>
<li>common names: 'a dozen', 'half' -- <strong>works; you can even do things like "a half dozen"</strong></li>
</ol>
<p>Number 6 is the only one I don't have a ready answer for, and that's because of the ambiguity between ordinals and fractions (in English at least) added to the fact that my last cup of coffee was <em>many</em> hours ago.</p>
|
<p>One place to start looking is the <a href="http://www.gnu.org/software/tar/manual/html_node/Date-input-formats.html" rel="nofollow noreferrer">gnu get_date lib</a>, which can parse <a href="http://php-date.com/#strtotime" rel="nofollow noreferrer">just about any</a> English textual date into a timestamp. While not exactly what you're looking for, their solution to a similar problem could provide a lot of useful clues.</p>
| 9,556
|
<p>How do I use Perl to create graphs?</p>
<p>I'm running scheduled job that creates text reports. I'd like to move this to the next step (for the management) and also create some graphs that go along with this. Is this possible / feasible? It'd be great if I could do this using Office some how.</p>
<h2>update: solutions i'm going to investigate in this order</h2>
<ul>
<li>Spreadsheet::WriteExcel (this seems to now have changed from the last time i investigated this .... wait, this was suggested by the author of the module. cool.)</li>
<li>GD Graph - this is now available for ActivePerl(wasn't last time i looked)</li>
<li>SVG</li>
<li>Open Charts look interesting.</li>
<li>Chartdirector</li>
</ul>
|
<p>GD and GD::Graph are probably your best bets, you can use them to create images that you can then embed into whatever you need.</p>
|
<p><a href="http://search.cpan.org/dist/Spreadsheet-WriteExcel" rel="nofollow noreferrer">Spreadsheet::WriteExcel</a> will let you just get the data into Excel, then write Excel equations for the graphs.</p>
| 9,009
|
<p>What are the basic differences between a semaphore & spin-lock?</p>
<p>When would we use a semaphore over a spin-lock?</p>
|
<p>Spinlock and semaphore differ mainly in four things:</p>
<p><strong>1. What they are</strong><br>
A <em>spinlock</em> is one possible implementation of a lock, namely one that is implemented by busy waiting ("spinning"). A semaphore is a generalization of a lock (or, the other way around, a lock is a special case of a semaphore). Usually, <em>but not necessarily</em>, spinlocks are only valid within one process whereas semaphores can be used to synchronize between different processes, too.</p>
<p>A lock works for mutual exclusion, that is <strong>one</strong> thread at a time can acquire the lock and proceed with a "critical section" of code. Usually, this means code that modifies some data shared by several threads.<br>
A <em>semaphore</em> has a counter and will allow itself being acquired by <strong>one or several</strong> threads, depending on what value you post to it, and (in some implementations) depending on what its maximum allowable value is.</p>
<p>Insofar, one can consider a lock a special case of a semaphore with a maximum value of 1.</p>
<p><strong>2. What they do</strong><br>
As stated above, a spinlock is a lock, and therefore a mutual exclusion (strictly 1 to 1) mechanism. It works by repeatedly querying and/or modifying a memory location, usually in an atomic manner. This means that acquiring a spinlock is a "busy" operation that possibly burns CPU cycles for a long time (maybe forever!) while it effectively achieves "nothing".<br>
The main incentive for such an approach is the fact that a context switch has an overhead equivalent to spinning a few hundred (or maybe thousand) times, so if a lock can be acquired by burning a few cycles spinning, this may overall very well be more efficient. Also, for realtime applications it may not be acceptable to block and wait for the scheduler to come back to them at some far away time in the future.</p>
<p>A semaphore, by contrast, either does not spin at all, or only spins for a very short time (as an optimization to avoid the syscall overhead). If a semaphore cannot be acquired, it blocks, giving up CPU time to a different thread that is ready to run. This may of course mean that a few milliseconds pass before your thread is scheduled again, but if this is no problem (usually it isn't) then it can be a very efficient, CPU-conservative approach.</p>
<p><strong>3. How they behave in presence of congestion</strong><br>
It is a common misconception that spinlocks or lock-free algorithms are "generally faster", or that they are only useful for "very short tasks" (ideally, no synchronization object should be held for longer than absolutely necessary, ever).<br>
The one important difference is how the different approaches behave <em>in presence of congestion</em>.</p>
<p>A well-designed system normally has low or no congestion (this means not all threads try to acquire the lock at the exact same time). For example, one would normally <em>not</em> write code that acquires a lock, then loads half a megabyte of zip-compressed data from the network, decodes and parses the data, and finally modifies a shared reference (append data to a container, etc.) before releasing the lock. Instead, one would acquire the lock only for the purpose of accessing the <em>shared resource</em>.<br>
Since this means that there is considerably more work outside the critical section than inside it, naturally the likelihood for a thread being inside the critical section is relatively low, and thus few threads are contending for the lock at the same time. Of course every now and then two threads will try to acquire the lock at the same time (if this <em>couldn't</em> happen you wouldn't need a lock!), but this is rather the exception than the rule in a "healthy" system. </p>
<p>In such a case, a spinlock <em>greatly</em> outperforms a semaphore because if there is no lock congestion, the overhead of acquiring the spinlock is a mere dozen cycles as compared to hundreds/thousands of cycles for a context switch or 10-20 million cycles for losing the remainder of a time slice.</p>
<p>On the other hand, given high congestion, or if the lock is being held for lengthy periods (sometimes you just can't help it!), a spinlock will burn insane amounts of CPU cycles for achieving nothing.<br>
A semaphore (or mutex) is a much better choice in this case, as it allows a different thread to run <em>useful</em> tasks during that time. Or, if no other thread has something useful to do, it allows the operating system to throttle down the CPU and reduce heat / conserve energy.</p>
<p>Also, on a single-core system, a spinlock will be quite inefficient in presence of lock congestion, as a spinning thread will waste its complete time waiting for a state change that cannot possibly happen (not until the releasing thread is scheduled, which <em>isn't happening</em> while the waiting thread is running!). Therefore, given <em>any</em> amount of contention, acquiring the lock takes around 1 1/2 time slices in the best case (assuming the releasing thread is the next one being scheduled), which is not very good behaviour.</p>
<p><strong>4. How they're implemented</strong><br>
A semaphore will nowadays typically wrap <code>sys_futex</code> under Linux (optionally with a spinlock that exits after a few attempts).<br>
A spinlock is typically implemented using atomic operations, and without using anything provided by the operating system. In the past, this meant using either compiler intrinsics or non-portable assembler instructions. Meanwhile both C++11 and C11 have atomic operations as part of the language, so apart from the general difficulty of writing provably correct lock-free code, it is now possible to implement lock-free code in an entirely portable and (almost) painless way.</p>
|
<p>A "mutex" (or "mutual exclusion lock") is a signal that two or more asynchronous processes can use to reserve a shared resource for exclusive use. The first process that obtains ownership of the "mutex" also obtains ownership of the shared resource. Other processes must wait for for the first process to release it's ownership of the "mutex" before they may attempt to obtain it. </p>
<p>The most common locking primitive in the kernel is the spinlock. The spinlock is a very simple single-holder lock. If a process attempts to acquire a spinlock and it is unavailable, the process will keep trying (spinning) until it can acquire the lock. This simplicity creates a small and fast lock.</p>
| 23,803
|
<p>I have SBCL running on a Ubuntu machine. I want to write a little program that I want to give to a friend who has only Windows running. What is the quickest way to cross-compile it on my machine into a "standalone" windows program (i.e. the usual runtime+core combination)?</p>
|
<p>SBCL is able to do a cross-compilation, but due to code being evaluated during the process, you need access to the target architecture. SBCL's build processed is well explained by Christophe Rhodes in <a href="https://research.gold.ac.uk/2336/1/sbcl.pdf" rel="nofollow noreferrer">SBCL: a Sanely-Bootstrappable Common Lisp
</a>.</p>
<p>If you don't have directly access to a Windows machine, I suppose you could give a try to Wine (I would expect this to fail) or <a href="http://www.reactos.org/" rel="nofollow noreferrer">ReactOS</a> inside either an emulator or hypervisor (QEMU, HVM, Xen, you name it...).</p>
|
<p>Cores are specific to a platform/version combination. Use Luís's method, or distribute with a different Lisp, such as CLisp.</p>
<blockquote>
<p>There is absolutely no binary compatibility of core images between different runtime support programs. Even runtimes built from the same sources at different times are treated as incompatible for this purpose. <a href="http://www.sbcl.org/manual/Saving-a-Core-Image.html" rel="nofollow noreferrer">SBCL Manual</a></p>
</blockquote>
| 29,459
|
<p>I am about to write an audio file converter for my side job at the university.<br>
As part of this I would need sample rate conversion. However, my professor said that it would be pretty hard to write a sample rate converter that was <em>both</em> of good quality <em>and</em> fast.</p>
<p>On my research on the subject, I found some functions in the OSX CoreAudio-framework, that could do a sample rate conversion (AudioConverter.h). After all, an OS has to have some facilities to do that for its own audio stack. </p>
<p>Do you know a similar method for C/C++ and Windows, that are either part of the OS or open source?<br>
I am pretty sure that this function exists within DirectX Audio (XAudio2?), but I seem to be unable to find a reference to it in the MSDN library.</p>
|
<p>Try Secret Rabbit Code (= SRC = Sample Rate Conversion ) It's GPL, it's fast and it's high quality. <a href="http://www.mega-nerd.com/SRC/license.html" rel="noreferrer">http://www.mega-nerd.com/SRC/license.html</a></p>
|
<p>If you're worried about quality, check out <a href="http://src.infinitewave.ca/" rel="nofollow noreferrer">http://src.infinitewave.ca/</a>. Very good comparisons on different resamplers.</p>
| 6,291
|
<p>In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I'm seeing their ASCII values instead: </p>
<pre><code>>> a = "0123"
=> "0123"
>> a[0]
=> 48
</code></pre>
<p>I've looked online but can't find any way to get the original "0" back out of it. I'm a little new to Ruby to I know it has to be something simple but I just can't seem to find it.</p>
|
<p>Or you can convert the integer to its character value:</p>
<pre><code>a[0].chr
</code></pre>
|
<p>I think <code>each_char</code> or <code>chars</code> describes better what you want.</p>
<pre><code>irb(main):001:0> a = "0123"
=> "0123"
irb(main):002:0> Array(a.each_char)
=> ["0", "1", "2", "3"]
irb(main):003:0> puts Array(a.each_char)
0
1
2
3
=> nil
</code></pre>
| 4,917
|
<p>Why do I need two of them? When I have to use one or another?</p>
|
<p><a href="https://stackoverflow.com/a/43883/6571020">Quote by @DAC</a></p>
<blockquote>
<p>In short: SID = the unique name of
your DB, ServiceName = the alias used
when connecting</p>
</blockquote>
<p>Not strictly true. SID = unique name of the INSTANCE (eg the oracle process running on the machine). Oracle considers the "Database" to be the files.</p>
<p>Service Name = alias to an INSTANCE (or many instances). The main purpose of this is if you are running a cluster, the client can say "connect me to <code>SALES.acme.com</code>", the DBA can on the fly change the number of instances which are available to <code>SALES.acme.com</code> requests, or even move <code>SALES.acme.com</code> to a completely different database without the client needing to change any settings.</p>
|
<p>As per Oracle Glossary : </p>
<blockquote>
<p>SID is a unique name for an Oracle database instance. ---> To switch
between Oracle databases, users must specify the desired SID <---. The
SID is included in the CONNECT DATA parts of the connect descriptors
in a TNSNAMES.ORA file, and in the definition of the network listener
in the LISTENER.ORA file. Also known as System ID. Oracle Service Name
may be anything descriptive like "MyOracleServiceORCL". In Windows,
You can your Service Name running as a service under Windows Services.</p>
</blockquote>
<p>You should use SID in TNSNAMES.ORA as a better approach.</p>
| 6,549
|
<p>I would love to re-use my failed prints by re-extruding the plastic to be used in the 3D printer once again. One thing that stands in my way is finding an effective way to shred the plastic into smaller bits for the extrude to use. What is a good thing to look for to accomplish this? Maybe a really big 'paper' shredder?</p>
|
<p>there is a project called <code>precious plastic</code> and there is a <a href="https://bazar.preciousplastic.com/en/listings/572981-star-international-shipping-star-shredder-kit" rel="nofollow noreferrer">plastic shredder</a>, but it is a rather expensive solution.</p>
<p>As I am waiting for parts for my <a href="https://www.thingiverse.com/thing:380987" rel="nofollow noreferrer">Lyman extruder</a>, my plan is to hammer the parts and then process in old kitchen robot with steel working area, an <a href="https://youtu.be/9a_ZYDcQV0w?t=44s" rel="nofollow noreferrer">example here</a></p>
<p>The paper shredder will be ok as long as you can feed it with plastic.</p>
|
<p>there is a project called <code>precious plastic</code> and there is a <a href="https://bazar.preciousplastic.com/en/listings/572981-star-international-shipping-star-shredder-kit" rel="nofollow noreferrer">plastic shredder</a>, but it is a rather expensive solution.</p>
<p>As I am waiting for parts for my <a href="https://www.thingiverse.com/thing:380987" rel="nofollow noreferrer">Lyman extruder</a>, my plan is to hammer the parts and then process in old kitchen robot with steel working area, an <a href="https://youtu.be/9a_ZYDcQV0w?t=44s" rel="nofollow noreferrer">example here</a></p>
<p>The paper shredder will be ok as long as you can feed it with plastic.</p>
| 899
|
<p>The HR department at the company that I am currently working for has requested that I provide a system for storing employee social security numbers in our company database. The reason for this is to streamline payroll completion, as we use in-house software for employee timesheets but have to integrate with third-party software for our actual payroll system. This is a relatively small company (20-30 employees), and we'd only be storing current employees' SSN's (so a breach would only have limited impact), but I would still like to bank on security.</p>
<p>I would like to know if there is any convention out there for storing information as sensitive as social security numbers. I'm not very skilled in encryption, and I understand that there are several encryption techniques that I could resort to, but I was wondering if there was one way in particular that was best suited for this type of situation. Would AES be my best bet?</p>
<p>As for current software, we're running MySQL and our web interface is written in PHP and running on an IIS server. </p>
|
<p>I didn't see it mentioned anywhere, but is it necessary for this information to be online? If not, then you've secured one major avenue of attack by simply having this info stored in a database on a computer that's not connected to the internet. Or, if you can get away with having it stored on your LAN somewhere (so HR can have access to it, or whatever), as opposed to production servers, that's still a step in the right direction. </p>
<p>You mentioned that you're at a relatively small company, but it seems like an investment in some cheap hardware wouldn't be too difficult a thing to convince the decision makers of, given the benefits of storing this kind of sensitive info offline. And barring a massive hiring spree in the near future, you don't need a server class computer for storing personal info on ~30 employees by any means.</p>
<p>Wherever you store it, I'd still consider some kind of encryption. AES 256 is the standard for secure these days in most applications and is pretty widely supported. It doesn't sound like it's the sort of application to be under any kind of load, so again, there's no harm in going for a larger key size along with the cheap hardware, from the sounds of it.</p>
<p>As far as implementation goes, if you're comfortable with MySQL - stick with that, they've got the tools you need to do what you want: <a href="http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html</a></p>
<p>In the end, security is all about layers, no single solution is going to be the silver bullet, but you can go a long way by adding some pretty simple, common sense security measures.</p>
<p>Edit: after reading what Graeme said, I feel I should add that most security breaches are an inside job - make sure to protect your data at the disk level, through the database, and over the wire.</p>
|
<p>Well, you haven't given any information on what you are going to do with these numbers. If you ever need to retrieve an SSN, then basically there's almost no point in doing anything with this - store it in clear. Any form of encryption where you have the ciphertext and key in the same place is going to only slow down an attacker a little. This only matters to attackers who can't take huge amounts of data, or who can't just take your whole computer, or who are not competent to join the dots. If you are dealing with the latter case, actual access control in the first place is rather more important.</p>
<p>If, however, you get an SSN externally and want to find out whose account that is, you could use a one-way hash to do that.</p>
| 31,805
|
<p>I was wondering if anyone knows of any libraries for programatically creating flash swf files. </p>
<p>Or for creating swf from svg.</p>
|
<p>This sounds like a perfect job for <a href="http://swfmill.org/" rel="noreferrer" title="swfmill">swfmill</a> I think you'll find it will allow you to do both, convert SVG to SWF and to create SWF files from code.</p>
|
<p>It's an early days project, so there may be some fiddling, but <a href="https://github.com/izb/Swiffotron" rel="nofollow">Swiffotron</a> can load, modify, generate and combine SWF files.</p>
| 24,396
|
<p>Am I missing something or is there truly no alternative (yet, I hope) to SVCUTIL.EXE for generating WCF Web service proxies? </p>
|
<p>I would strongly suggest that you look through the auto generated configurations before just using them, the autogenerated stuff is full of garbage.
Try looking at this article by Miquel Castro: <a href="http://www.code-magazine.com/Article.aspx?quickid=0809101" rel="nofollow noreferrer">WCF the Manual Way... the Right Way</a></p>
|
<p>If you're looking for a command-line alternative or standalone GUI then no - I don't know of any.</p>
<p>However, if you're wondering about usage while developing in VS, VS2008's add service reference is an alternative that can save you some headache.</p>
| 15,064
|
<p>There is two available Eclipse plugins for Maven :</p>
<ul>
<li><a href="http://www.eclipse.org/proposals/iam/" rel="noreferrer">Eclipse IAM</a> (old name is Q4E)</li>
<li><a href="http://m2eclipse.codehaus.org/" rel="noreferrer">m2eclipse</a></li>
</ul>
<p>m2eclipse seems to be the oldest but the more robust. Is there any key differences between the two ?</p>
<p>Which one should be chosen for a project starting today and why ?</p>
<p><strong>UPDATE:</strong> m2eclipse is moving to eclipse.org and will be included in the Indigo release train (Eclipse 3.7). See <a href="http://www.sonatype.com/people/2010/12/m2e-at-eclipse-what-will-this-mean-for-you/" rel="noreferrer">m2e at Eclipse: What will this mean for you?</a> and <a href="http://www.eclipse.org/m2e/" rel="noreferrer">m2eclipse is moving to eclipse.org!</a>. The accepted answer is thus even more correct.</p>
|
<p>I choose <strong>m2eclipse</strong> since it is stable and have all that I need. Especially ability to resolve dependencies inside workspace.</p>
<p>I tried the other one some time ago and didn't like it. It was to buggy so I gave up quickly.</p>
|
<p>I am using m2eclipse ... thats the best and well documented too...</p>
| 39,251
|
<p>Is there a way to specify the font size for a class to be, say, 70% of the inherited font size?</p>
<p>I have a general "button" class that sets up my buttons with the appropriate borders, background, etc. I use it in multiple places, including one where the font size is fairly small and another where the font size is quite large.</p>
<pre><code><div style="font-size: 26px;">
Push this: <input class="button" type="submit" value="Go">
</div>
<div style="font-size: 10px;">
Push this too: <input class="button" type="submit" value="Go">
</div>
</code></pre>
<p>In both instances I'd like the button font-size to be about 70% of the font size of the span or div the button is in. </p>
<p>Can I do this with pure CSS?</p>
|
<p>EMs do work like percentages in that the base font size is always 1em and .7em would be 70% of that (in the same way 1.2em would be equivalent of 120% of base font size). For this to work properly though you need to define a base font-size on the document body. Through experimentation I've found that font-size: 77%; gives you a nice base size in all browsers (that is it makes 1em render in a "normal" and readable size). You may want to try other values between 75% and 80% depending on what font-family you want to use. Also bear in mind that relative font sizes are inherited accumulatively - for example: </p>
<pre><code><style>
small { font-size: .8em; }
span.tiny { font-size: .8em }
</style>
<small>This text is 80% of base size where as
<span class="tiny">this text is 80% of 80% (or 64%) of base size</span>
</small>
</code></pre>
<p>This works in your favour as you would only need to give your button class a font-size of .7em to achieve what you want (the buttons would then always have a font size that is 70% of its parent object). Happy coding! </p>
<p><strong>2014 edit:</strong> </p>
<p>It's worth pointing out that browser support for the Root EM unit is now so good* that if you're not already using it it is worth looking into. The Root EM (rem) is tied to the root (document) font size, and unlike the "normal" EM it is unaffected by nesting - it always relates to the root font size. While <code>em</code>'s are still very useful for most text sizing, precisely because it <em>does</em> respect nesting, the <code>rem</code> is great for things like margins and padding, which you may not want to change size with nesting (this is a common cause for misaligned left margins), but which you <em>do</em> want to change size along with the root <code>html</code> font size (typically using <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries" rel="noreferrer">media queries</a>). </p>
<p>You can read more about EMs vs. REMs <a href="http://designshack.net/articles/typography/whats-the-deal-with-em-and-rem/" rel="noreferrer">over on Design Shack</a>.</p>
<p>*) IE8 is the only common browser (~5%) which does not support it - if you need to support IE8, simply include an equivalent size in pixels <em>before</em> the <code>rem</code> declaration. </p>
|
<pre><code><input style="font-size: 70%" class="button" type="submit" value="Go">
</code></pre>
<p>?</p>
| 37,690
|
<p>My current view is no, prefer Transact SQL stored procedures because they are a lighter weight and (possibly) higher performing option, while CLR procedures allow developers to get up to all sorts of mischief.</p>
<p>However recently I have needed to debug some very poorly written TSQL stored procs. As usual I found many of the problems due to the original developer developer having no real TSQL experience, they were ASP.NET / C# focused.</p>
<p>So, using CLR procedures would firstly provide a much more familiar toolset to this type of developer, and secondly, the debugging and testing facilities are more powerful (ie Visual Studio instead of SQL Management Studio). </p>
<p>I'd be very interested in hearing your experience as it's seems it is not a simple choice. </p>
|
<p>There are places for both well-written, well-thought-out T-SQL and CLR. If some function is not called frequently and if it required extended procedures in SQL Server 2000, CLR may be an option. Also running things like calculation right next to the data may be appealing. But solving bad programmers by throwing in new technology sounds like a bad idea.</p>
|
<p>I would add a couple of reasons to use CLR that may not have been mentioned.</p>
<ul>
<li>Replace and extend basic query, non-query, and scalar sql functions.<br>
A) Error reporting and alerts can be integrated based upon defined requirements.
B) Easily define debugging levels.
C) Enable an easier way to interact with foreign SQL servers </li>
<li>Move legacy code to a managed environment.</li>
</ul>
| 8,259
|
<p>I am writing an application that is linked to Active Directory, and I need to store the userPrincipalName in a database table, but I do not know how big the field would need to be.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms680857(VS.85).aspx" rel="noreferrer">On MSDN</a>, no Length is given, and neither in <a href="http://www.faqs.org/rfcs/rfc822.html" rel="noreferrer">RFC 822</a>. Now, before I revert to the DOMAIN\Username that has a defined Length (<a href="http://msdn.microsoft.com/en-us/library/ms679635(VS.85).aspx" rel="noreferrer">sAMAccountName</a> is less than 20 chars, NETBIOS Domain Name is max. 15 chars), I wonder if anyone knows what the limit is either by standard, or by the implementation within both Windows 2003 and Windows 2008 domains.</p>
|
<p>On Win2k3 SP2 the longest userPrincipleName it allows me to create is 1013 characters long.</p>
|
<p>no it's not possible to change the length of characters in Logon Name of Active directory.</p>
| 35,079
|
<p>What is the best design decision for a 'top-level' class to attach to an event to a class that may be '5+ layers down in the callstack?</p>
<p>For example, perhaps the MainForm has spawned an object, and that object has spawned a callstack of several other object calls. The most obvious way would be to chain the event up the object hierarchy, but this seems messy and requires a lot of work.</p>
<p>One other solution ive seen is to use the observer pattern by creating a publically accessible static object which exposes the event, and acts as a proxy between the bottom-level object, and the top-level 'form'.</p>
<p>Any recommendations?</p>
<p>Here's a pseudo-code example. In this example, the MainForm instantiates 'SomeObject', and attaches to an event. 'SomeObject' attaches to an object it instantiates, in an effort to carry the event up to the MainForm listener.</p>
<pre><code>class Mainform
{
public void OnLoad()
{
SomeObject someObject = new SomeObject();
someObject.OnSomeEvent += MyHandler;
someObject.DoStuff();
}
public void MyHandler()
{
}
}
class SomeObject
{
public void DoStuff()
{
SomeOtherObject otherObject = new SomeOtherObject();
otherObject.OnSomeEvent += MyHandler;
otherObject.DoStuff();
}
public void MyHandler()
{
if( OnSomeEvent != null )
OnSomeEvent();
}
public event Action OnSomeEvent;
}
</code></pre>
|
<p>If your application isn't based on Composite UI Application Blocks, the easiest solution is to put a "listener" class between Main form and your other components which both classes can easily access. Conceptually, the classes are laid out as follows:</p>
<pre>
---------- ----------------
| MainForm | | Some Component |
--------- ----------------
| |
Hooks onto Notifies
| |
\ /
-----------------
| Proxy Notifier |
-----------------
</pre>
<p>Here's some example code:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
FakeMainForm form = new FakeMainForm();
form.CreateComponentAndListenForMessage();
Console.ReadKey(true);
}
}
class FakeMainForm
{
public FakeMainForm()
{
Listener.AddListener(MessageRecieved);
}
void MessageRecieved(string msg)
{
Console.WriteLine("FakeMainForm.MessageRecieved: {0}", msg);
}
public void CreateComponentAndListenForMessage()
{
ComponentClass component = new ComponentClass();
component.PretendToProcessData();
}
}
class Listener
{
private static event Action<string> Notify;
public static void AddListener(Action<string> handler)
{
Notify += handler;
}
public static void InvokeListener(string msg)
{
if (Notify != null) { Notify(msg); }
}
}
class ComponentClass
{
public void PretendToProcessData()
{
Listener.InvokeListener("ComponentClass.PretendToProcessData() was called");
}
}
}
</code></pre>
<p>This program outputs the following:</p>
<pre>FakeMainForm.MessageRecieved: ComponentClass.PretendToProcessData() was called</pre>
<p>This code allows you to invoke methods directly on any listener, no matter how far apart they are in the call stack.</p>
<p>Its easy to rewrite your Listener class so that its a little more generic and works on different types, but you should get the idea.</p>
|
<p>My initial intention would be to try and avoid that, so that an object's scope has obvious boundaries. In the particular case of Forms, I would attempt to have the child's parent form manage all required communications withs its ancestors. Can you be more specific about your case?</p>
| 44,928
|
<p>Is it only to allow logical grouping?</p>
|
<p>It gives you flexibility. For example, you might have a bunch of constructors, some public, some protected, some private - wouldn't you want them all grouped together?</p>
|
<p>My guess is that it is an outgrowth of the C philosophy, which assumes that you know what you are doing and gives you the maximum flexibility. It is like allowing a single = in an if statement.</p>
| 39,930
|
<p>In my understanding of Servlet, the Servlet will be instantiated by the Container, its <code>init()</code> method will be called once, and the servlet will live like a singleton until the JVM shuts down.</p>
<p>I do not expect my servlet to be serialized, since it will be constructed new when the app server recovers or is starts up normally. The servlet should hold no session-specific members, so it does not make sense for it to be written to disk and re-instantiated.
Is there a practical use for this?</p>
<p>My concerns are, that I put some non-serializable fields within there and then my app will mysteriously fail in a production environment where a different sort of session replication will take place.</p>
|
<p>Technically, I believe the servlet container is allowed to "passivate" the servlet object to disk, in a similar way that EJB session beans can be. So you're correct to ask the question if your app will fail due to non-serializable fields.</p>
<p>In practise, I've never heard of a container doing this, so it's really just legacy baggage from the bad old days of early J2EE. I wouldn't worry about it.</p>
|
<p><strong>Serializable is used as a <em>marker interface</em> for session's attributes in distributed environment.</strong></p>
<blockquote>
<p><strong>SRV.7.7.2 Distributed Environments (JSR-154)</strong></p>
<p>Within an application marked as <strong>distributable</strong>, all requests that
are part of a session must be handled by one Java Virtual Machine
(“JVM”) at a time. The container must be able to handle all objects
placed into instances of the HttpSession class using the setAttribute
or putValue methods appropriately. The following restrictions are
imposed to meet these conditions:</p>
<ul>
<li><strong>The container must accept objects that implement the Serializable interface</strong>.</li>
<li>Migration of sessions will be handled by container-specific facilities.</li>
</ul>
<p>The distributed servlet container must throw an
IllegalArgumentException for objects where the <strong>container cannot
support the mechanism necessary for migration of the session storing
them</strong>.</p>
<p>The distributed servlet container must support the mechanism necessary
for
<strong>migrating objects that implement Serializable</strong>.</p>
<p>(...)</p>
<p>The Container Provider can ensure scalability and quality of service
features like load-balancing and failover by <strong>having the ability to
move a session object, and its contents, from any active node of the
distributed system to a different node of the system.</strong> If distributed
containers <strong>persist or migrate sessions</strong> to provide quality of
service features, they are not restricted to using the native JVM
Serialization mechanism for serializing HttpSessions and their
attributes. Developers are not guaranteed that containers will call
readObject and writeObject methods on session attributes if they
implement them, <strong>but are guaranteed that the Serializable closure of
their attributes will be preserved</strong>.</p>
</blockquote>
| 21,686
|
<p>Hopefully (but not necessarily) one that is independent of language or framework?</p>
|
<p>construct a normal to the vector (x1,y1)->(x2,y2). place it at the midpoint ((x1+x2)/2,(y1+y2)/2) and go out a distance h.</p>
<p>the normal will look like (-(y2-y1),x2-x1). make this a unit vector (<a href="http://en.wikipedia.org/wiki/Unit_vector" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Unit_vector</a>).</p>
<p>add h times this unit vector to the midpoint.</p>
|
<p>Al I can remember is that an isosceles triangle will have sides of equal length, and equal angles at the base. If you have the height, then you have the final coordinate because this will be the point of intersection, right?</p>
| 45,313
|
<p>In JavaScript is it wrong to use a try-catch block and ignore the error rather than test many attributes in the block for null?</p>
<pre><code>try{
if(myInfo.person.name == newInfo.person.name
&& myInfo.person.address.street == newInfo.person.address.street
&& myInfo.person.address.zip == newInfo.person.address.zip) {
this.setAddress(newInfo);
}
} catch(e) {} // ignore missing args
</code></pre>
|
<p>Yes. For one, an exception could be thrown for any number of reasons besides missing arguments. The catch-all would hide those cases which probably isn't desired.</p>
|
<p>For the example given I would say it was bad practice. There are instances however where it may be more <strong>efficient</strong> to simply trap for an <strong>expected</strong> error. Validating the format of a string before <a href="https://stackoverflow.com/questions/104850/c-test-if-string-is-a-guid-without-throwing-exceptions#104932">casting it as a GUID</a> would be a good example.</p>
| 17,091
|
<p>I'm trying to come up with a way to determine how "hot" certain threads are in a forum. What criteria would you use and why? How would these come together to give a hotness score?</p>
<p>The criteria I'm thinking of include:</p>
<ul>
<li>how many replies</li>
<li>how long since the last reply</li>
<li>average time between replies</li>
</ul>
<p>The problems this algorithm must solve:</p>
<ul>
<li>A thread which has 500 replies is clearly hot, unless the last reply was over a year ago.</li>
<li>A thread with 500 replies that was replied to a second ago is clearly hot, unless it's taken 4 years to reach 500 replies.</li>
<li>A thread with 15 replies in the last 4 minutes is really hot!</li>
</ul>
<p>Any ideas, thoughts or complete solutions out there?</p>
|
<p>Jeff Atwood has <a href="https://meta.stackexchange.com/questions/11602/what-formula-should-be-used-to-determine-hot-questions">a nice question</a> about this with a ton of information on other "hot" algorithms. I suggest using one of those and adapting it to your liking.</p>
|
<p>I was thinking you could probably model it with diminishing waves here, using amplitude (or root mean square) to measure hotness. As time goes, the wave diminishes, and so a late reply will only cause a little stir.</p>
<p>In practice, I think this requires a lot of calculation. You could make good use of caching to speed up the calculation.</p>
<p>Just my two cents.</p>
| 49,952
|
<p>When a pointer goes out of scope, its memory is freed, so why are <code>destructor</code>s created in c++?</p>
|
<p>If you're asking why C++ classes have destructors, some classes have requirements other than just freeing memory. You may have an object that's allocated a socket connection that needs to be shut down cleanly, for example.</p>
<p>Also, 'unscoping' a pointer does <em>not</em> free the memory that it points to since other pointers may be referencing it.</p>
<p>If you have a pointer on the stack, exiting the function will free the memory used by the pointer but <em>not</em> that memory pointed to by the pointer. There's a subtle but very important distinction.</p>
|
<p>When ever there is a pointer(exist as class member),there should be a destructor for that class that should delete the object pointed by the pointer member.
If you have smart_pointer in place of pointer in class then there is no need of destructor.</p>
<p>below qn will help u understand better.
<a href="https://stackoverflow.com/questions/147572/will-the-below-code-cause-memory-leak-in-c">Will the below code cause memory leak in c++</a></p>
| 47,667
|
<p>What is the best way to pass data between a C server to a Java applet? Currently it's done by using a buffer and copying bytes to it using memcpy, but if the object ever changes I have to hunt down every instance of where it's being sent to the applet and have it changed.</p>
<p>Is there a better way to pass object to java? How would you do it?</p>
<p>Edit for clarification: It is going from the C server to the Java applet only, there is no java servlet. The only thing the Applet passes to the C server is a hex number signaling an action to be taken</p>
|
<p>You might want to take a look at <a href="http://code.google.com/p/protobuf/" rel="nofollow noreferrer">Protocol Buffers</a></p>
<p>They let you define structured data, then generate the code to read and write messages in any of the supported languages. The only catch is I think they only support C++ for now, though I know there was interest in straight C implementation.</p>
|
<p>I would have opened a socket connection between the two applications. You could serialize the object to an array of bytes and have the Java servlet deserialize it into a Java object with the same value. This way if the class definition changes, you only have to change the code in two places.</p>
| 35,734
|
<p>As we know that, with compute function of datatable we can get sum of columns.
But I want to get sum of a row of datatable.
I will explain with a example:</p>
<p>I have a datatable like image below: With compute function we can get the sum of each column (product). Such as for product1, 2 + 12 + 50 + 13= 77.</p>
<p>I want to get sum of company1 : 2 + 6 + 4 + 3 + 5 = 20</p>
<p><a href="http://img123.imageshack.us/img123/1517/61519307xx5.jpg" rel="nofollow noreferrer">http://img123.imageshack.us/img123/1517/61519307xx5.jpg</a></p>
<p>How can I do it with asp.net 1.1?</p>
|
<p><strong>LINQ to the rescue:</strong></p>
<pre><code>DataTable dt = WhateverCreatesDataTable();
DataRow dr = dt.Rows[0];
int sum = dt.Columns.Cast<DataColumn>().Sum(dc=>(int)dr[dc]);
</code></pre>
<p>For those still dragging their knuckles in the stone ages (aka pre-.Net 3.5 and LINQ):</p>
<pre><code>DataTable dt = WhateverCreatesDataTable();
DataRow dr = dt.Rows[0];
int sum = 0;
foreach(DataColumn dc in dt.Columns)
sum += (int)dr[dc];
</code></pre>
|
<p>We can use Datatable's Compute() function for the following purpose:</p>
<ul>
<li>To find sum.</li>
<li>To find max value.</li>
<li>To find min value.</li>
<li>To calculate average.</li>
</ul>
<p>Below links have detailed explaination of Datatable's compute() function:</p>
<p><a href="http://codevariation.blogspot.com/2017/02/using-datatable-compute-function-in-cnet.html" rel="nofollow noreferrer">http://codevariation.blogspot.com/2017/02/using-datatable-compute-function-in-cnet.html</a></p>
<p>Hope this will help you.</p>
<p>Thanks.</p>
| 44,767
|
<p>The reason for me asking this question is:-</p>
<p>I get a real buzz out of discovering features in Visual Studio 2008 that end up saving me oodles of time every day. Recently found a blog by Sara Ford who grinds out a tip each day on her blog. </p>
<p>Am wondering what is the biggest time saving tip you can give in terms of using the IDE in visual studio 2008?</p>
<p>Up to now the best feature I have discovered is Ctrl + and Ctrl - for navigating back and forth.</p>
|
<p>A lot of features have been mentioned <a href="https://stackoverflow.com/questions/100420/hidden-features-of-visual-studio-2005-2008">here</a>... Especially <a href="http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx" rel="nofollow noreferrer">this</a> blog has loads of useful tips.</p>
|
<p>Just the <strong>refactoring</strong> on context-menu alone...</p>
<p>edit: ++conditional breaks if that wasn't obvious</p>
| 43,221
|
<p>Is it possible to configure two separate web apps (WAR) in a J2EE application (EAR) to access a shared session context?</p>
<p>Further info:</p>
<p>I ended up creating a shared class from the EAR which stored the required information in static members. This did the trick, even if it seemed like a dirty hack.</p>
|
<p>Not directly. Most containers put each WAR in a separate classloader with the EAR classloader as their parent. Each app's sessions are separate. You can put something provided by the parent EAR in each session. If you need them to share something, make it a EAR function.</p>
|
<p>There is no "standard" solution to this. However, many application servers have their own extensions for this. WebSpere has a "Shared session context" option for example.</p>
<p>See here: <a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/tprs_sharing_data.html" rel="nofollow noreferrer">http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/tprs_sharing_data.html</a></p>
| 32,613
|
<p>I am a support engineer and our company's product allows XSLT transforms to customize outputs.</p>
<p>I made a xsl transform for this purpose. It works well for source files of typical size (several 100k), but occasionally a really huge (10M) source file will come by. In such case, the output is not generated even if I let it grind several days.</p>
<p>The SW engineering team tested it and discovered that for the transform and large source file in question is indeed very slow (>days), if our product is compiled to use the transform engine in .Net 1.1, but if they compile it with .Net 2.0, it is plenty fast (about 1-2 minutes).</p>
<p>The long term solution obviously is, wait for the next release.</p>
<p>For the short term I am wondering the following:
1) Is XSLT flexible enough that there are more efficient and less efficient ways to acheive the same result? For example, is it possible that the way I structured the xsl, the transform engine has to iterate from the beginning of the source file many many times, taking longer and longer as the next result piece gets farther and farther from the beginning? (Schlemiel the Painter), or
2) Is it more dependent on how the transform engine interprets the xsl?</p>
<p>If 2 is the case, I don't want to waste a lot of time trying to improve the xsl (I am not a big xsl genius, it was hard enough for me to achieve what little I did...).</p>
<p>Thanks!</p>
|
<p>I'm not familiar with the .NET implementations, but there are a few things you can do in general to speed up processing of large documents:</p>
<ul>
<li>Avoid using "//" in Xpath expressions unless absolutely necessary.</li>
<li>If you only need the first or only element that matches an Xpath expression, use the "[1]" qualifier, e.g. "//iframe[1]". Many processors implement optimizations for this.</li>
<li>Whenever possible, when dealing with huge XML input, see if you can design a solution around a stream-based parser (like SAX) instead of a DOM-based parser.</li>
</ul>
|
<p>Upon looking up your problem, I found a KB at Microsoft about that. You can see it <a href="http://support.microsoft.com/kb/324478" rel="nofollow noreferrer">here</a>.</p>
<p>They say that the XSLT transform in .NET 1 has some issues with the performance and that they can offer a quick fix. </p>
<p>If you want to try to troubleshoot the problem, there is a XSLT profiler available <a href="http://code.msdn.microsoft.com/xsltprofiler" rel="nofollow noreferrer">here</a>.</p>
<p>Otherwise, you can see what links is given on the Microsoft website for optimizing speed issues with XSLT (<a href="http://www.google.ca/search?q=XSLT+performance+site%3Amicrosoft.com" rel="nofollow noreferrer">link</a>).</p>
| 28,108
|
<p>I started out with a generic interface called ILogin. The interfaces requires that you implement two properties: UserID and Password. I have many login-type classes that implement this interface. As my project grew and grew, I found that many classes repeated the UserID and Password code. Now I decide that I need a base Login class. </p>
<p>Is it proper to create an abstract base Login class that implements the ILogin interface and have all of my concrete classes just inherit from the abstract class and override when necessary? Originally I was thinking there would be no problem with this. Then I started think that ILogin was probably unneeded because it'll likely only ever be implemented by my abstract class.</p>
<p>Is there a benefit to keeping both the abstract class and the interface around?</p>
<p>Thanks!</p>
|
<p>Definitely. Let's think of a concrete example.</p>
<p>Say we have an abstract class <code>Animal</code>.
Say, we make some subclasses <code>Cat</code>, <code>Dog</code>, <code>Mosquito</code>, and <code>Eagle</code>. We can implement its <code>Eat()</code>, <code>Breathe()</code>, <code>Sleep()</code> methods of the abstract class <code>Animal</code>.</p>
<p>So far, so good. Now, let's say we want to have the <code>Fly()</code> method for the <code>Mosquito</code> and <code>Eagle</code> classes. Since these two organisms aren't really well-related (one is a bird, another is an insect) it wouldn't be easy to come up with a common ancestor for the two that we can have as an abstract class. This would best be implemented by an interface <code>IFly</code>.</p>
<p>The <code>IFly</code> interface can have a <code>Fly()</code> method to be implemented. Both <code>Mosquito</code> and <code>Eagle</code> classes can both be subclasses of the abstract class <code>Animal</code> and implement the interface <code>IFly</code> and be able to <code>Eat()</code>, <code>Breathe()</code>, <code>Sleep()</code> and <code>Fly()</code> without having some type of odd ancenstral relationship between the two classes.</p>
|
<p>I would always advise that you use interfaces. Abstract classes have the advantage that you can add in default functionality, but requiring that a user use their single inheritance is pretty aggressive.</p>
<p>Microsoft class libraries favour abstract classes over interfaces in a number of cases because it enables them to modify the underlying class. Adding a method to an abstract class rarely breaks someone who inherits from it. Adding a method to an interface always breaks its implementors. However, this provides one of the best reasons for using interfaces: the awful possibility that Microsoft may have already used up your one inheritance.</p>
<p>I would suggest, however, that in your particular case you may wish to revisit the design pattern you are using. It seems unusual to have a lot of "logon-type" classes.</p>
| 33,486
|
<p>I have a JQueryDialog with a text field, an OK button and a cancel button.</p>
<p>I want to be able to hit the enter key after filling in the text fields and have it do the same action as when I click the OK button.</p>
|
<p>In your dialog, call <code>getRootPane().setDefaultButton(okButton)</code>.</p>
|
<p>The code is almost correct. I would change the if comparison and use the correct method as noted below.</p>
<pre><code>if (KeyEvent.VK_ENTER == event.getKeyCode()) {
yourButton.doClick();
}
</code></pre>
| 44,881
|
<p>Is it possible using StAX (specifically woodstox) to format the output xml with newlines and tabs, i.e. in the form:</p>
<pre>
<element1>
<element2>
someData
</element2>
</element1>
</pre>
<p>instead of:</p>
<pre><element1><element2>someData</element2></element1></pre>
<p>If this is not possible in woodstox, is there any other lightweight libs that can do this?</p>
|
<p>There is com.sun.xml.txw2.output.IndentingXMLStreamWriter</p>
<pre><code>XMLOutputFactory xmlof = XMLOutputFactory.newInstance();
XMLStreamWriter writer = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(out));
</code></pre>
|
<p>With Spring Batch this requires a subclass since this <a href="https://jira.springsource.org/browse/BATCH-1867" rel="nofollow">JIRA BATCH-1867</a></p>
<pre><code>public class IndentingStaxEventItemWriter<T> extends StaxEventItemWriter<T> {
@Setter
@Getter
private boolean indenting = true;
@Override
protected XMLEventWriter createXmlEventWriter( XMLOutputFactory outputFactory, Writer writer) throws XMLStreamException {
if ( isIndenting() ) {
return new IndentingXMLEventWriter( super.createXmlEventWriter( outputFactory, writer ) );
}
else {
return super.createXmlEventWriter( outputFactory, writer );
}
}
}
</code></pre>
<p>But this requires an additionnal dependency because Spring Batch does not include the code to indent the StAX output:</p>
<pre><code><dependency>
<groupId>net.java.dev.stax-utils</groupId>
<artifactId>stax-utils</artifactId>
<version>20070216</version>
</dependency>
</code></pre>
| 37,006
|
<p>I've had this problem before and found that basically I've got a connection that I'm not closing quickly enough (leaving connections open and waiting for garbage collection isn't really a best practice).</p>
<p>Now I'm getting it again but I can't seem to find where I'm leaving my connections open. By the time is see the error the database has cleared out the old connections so I can't see all the locked up connections last command (very helpful last time I had this issue).</p>
<p>Any idea how I could instrument my code or database to track what's going on so I can find my offending piece of code?</p>
|
<p>The error you are providing doesnt really point to a connection that is left open; it is more likely that there is a query that is taking longer than the application expects.
you can increase the time it waits for a response, and you could use Sql to find which queries are the most taxing.</p>
|
<p>Hopefully you have one data access layer class, instead of a whole bunch of classes, each one creating its own connection, right? What language are you using? If your using C#, the biggest cause of this problem is DataReaders and returning these objects to the upper layers. Most likely some client class is not closing the DataReader it received from your DAL class, leaving the connection open/locked for who knows how long. Track down the DataReaders you're returning and make sure your client classes are closing/disposing of them properly.</p>
<p>I'd also start thinking about redesigning your data access layer by implementing Disposable pattern and possibly returning POCOs instead of Data (...Tables, ...Sets, ...Readers) objects.</p>
| 44,829
|
<p>The <code>datepicker</code> function only works on the first input box that is created.</p>
<p>I'm trying to duplicate a datepicker by cloning the <code>div</code> that is containing it.</p>
<pre><code><a href="#" id="dupMe">click</a>
<div id="template">
input-text <input type="text" value="text1" id="txt" />
date time picker <input type="text" id="example" value="(add date)" />
</div>
</code></pre>
<p>To initialize the datepicker, according to the <a href="http://docs.jquery.com/UI/Datepicker" rel="nofollow noreferrer">jQuery UI documentation</a> I only have to do <code>$('#example').datepicker();</code> and it does work, but only on the first datepicker that is created.</p>
<p>The code to duplicate the <code>div</code> is the following:</p>
<pre><code>$("a#dupMe").click(function(event){
event.preventDefault();
i++;
var a = $("#template")
.clone(true)
.insertBefore("#template")
.hide()
.fadeIn(1000);
a.find("input#txt").attr('value', i);
a.find("input#example").datepicker();
});
</code></pre>
<p>The strangest thing is that on the <code>document.ready</code> I have:</p>
<pre><code>$('#template #example').datepicker();
$("#template #txt").click(function() { alert($(this).val()); });
</code></pre>
<p>and if I click on the <code>#txt</code> it always works.</p>
|
<p>I use a CSS class instead:</p>
<pre><code><input type="text" id="BeginDate" class="calendar" />
<input type="text" id="EndDate" class="calendar" />
</code></pre>
<p>Then, in your <code>document.ready</code> function:</p>
<pre><code>$('.calendar').datepicker();
</code></pre>
<p>Using it that way for multiple calendar fields works for me.</p>
|
<p>The html I am cloning has multiple datepicker inputs.</p>
<p>Using Ryan Stemkoski's answer and Alex King's comment, I came up with this solution:</p>
<pre><code>var clonedObject = this.el.find('.jLo:last-child')
clonedObject.find('input.ui-datepicker').each(function(index, element) {
$(element).removeClass('hasDatepicker');
$(element).datepicker();
});
clonedObject.appendTo('.jLo');
</code></pre>
<p>Thanks yall.</p>
| 5,515
|
<p>Sometimes IE6 will render the text of a <code><ul></code> list the same color as the background color. If you select it, they show back up, or if you scroll the page up and back down.</p>
<p>It is obviously a rendering bug, but I was wondering if anyone knows of a workaround to make it reliable?</p>
|
<p>try giving it hasLayout with</p>
<pre class="lang-css prettyprint-override"><code>zoom: 1
</code></pre>
|
<p>Have you tried explicitly setting a line-height? For some reason this seems to be the solution to a great many IE6 rendering bugs!</p>
<p>e.g.</p>
<pre class="lang-css prettyprint-override"><code>.mylist {
line-height: 1.6em;
}
</code></pre>
| 6,378
|
<p>When I process a cube in Visual Studio 2005 I get following message:</p>
<blockquote>
<p>Process succeeded. Trace information
is still being transferred. If you do
not want to wait for all of the
information to arrive press Stop.</p>
</blockquote>
<p>and no trace info is displayed. Cube is processed OK by it is a little bit annoying. Any ideas? I access cubes via web server.</p>
|
<p>I get the same message when I process a cube, but if I wait for a few seconds the trace information arrives. Are you dealing with a very large quantity of data or a very complex cube? Maybe this is a silly question, but have you tried waiting a few minutes?</p>
|
<p>how are you processing the cube? through XMLA or through the GUI? If you do it in XMLA then you should see the results as they come in the output window</p>
| 3,361
|
<p>I'm trying to write a custom WPF ValidationRule to enforce that a certain property is unique within the context of a given collection. For example: I am editing a collection of custom objects bound to a ListView and I need to ensure that the Name property of each object in the collection is unique. Does anyone know how to do this?</p>
|
<p>First, I'd create a simple DependencyObject class to hold your collection: </p>
<pre><code>class YourCollectionType : DependencyObject {
[PROPERTY DEPENDENCY OF ObservableCollection<YourType> NAMED: BoundList]
}
</code></pre>
<p>Then, on your ValidationRule-derived class, create a property:</p>
<pre><code>YourCollectionType ListToCheck { get; set; }
</code></pre>
<p>Then, in the XAML, do this:</p>
<pre><code><Binding.ValidationRules>
<YourValidationRule>
<YourValidationRule.ListToCheck>
<YourCollectionType BoundList="{Binding Path=TheCollectionYouWantToCheck}" />
</YourValidationRule.ListToCheck>
</YourValidationRule>
</Binding.ValidationRules>
</code></pre>
<p>Then in your validation, look at ListToCheck's BoundList property's collection for the item that you're validating against. If it's in there, obviously return a false validation result. If it's not, return true.</p>
|
<p>I would only create a custom dependency object if there were other properties I wanted to bind to the rule. Since in this case all we're doing is attaching a single collection of values to check against, I made my <code><UniqueValueValidationRule.OtherValues></code> property a <code><CollectionContainer></code>.</p>
<p>From there, to get past the problem of the <code>DataContext</code> not being inherited, <code><TextBox.Resources></code> needed to have a <code><CollectionViewSource></code> to hold the actual binding and give it a <code>{StaticResource}</code> key, which <code>OtherValues</code> could then use as binding source.</p>
<p>The validation rule itself then need only loop through <code>OtherValues.Collection</code> and perform equality checks.</p>
<p>Observe:</p>
<pre><code> <TextBox>
<TextBox.Resources>
<CollectionViewSource x:Key="otherNames" Source="{Binding OtherNames}"/>
</TextBox.Resources>
<TextBox.Text>
<Binding Path="Name">
<Binding.ValidationRules>
<t:UniqueValueValidationRule>
<t:UniqueValueValidationRule.OtherValues>
<CollectionContainer Collection="{Binding Source={StaticResource otherNames}}"/>
</t:UniqueValueValidationRule.OtherValues>
</t:UniqueValueValidationRule>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</code></pre>
| 5,517
|
<p>So right now my project has a few custom dialogs that do things like prompt the user for his birthday, or whatever. Right now they're just doing things like setting a <code>this.Birthday</code> property once they get an answer (which is of type <code>DateTime?</code>, with the null indicating a "Cancel"). Then the caller inspects the <code>Birthday</code> property of the dialog it created to figure out what the user answered.</p>
<p>My question is, <em>is there a more standard pattern for doing stuff like this?</em> I know we can set <code>this.DialogResult</code> for basic OK/Cancel stuff, but is there a more general way in Windows Forms for a form to indicate "here's the data I collected"?</p>
|
<p>I would say exposing properties on your custom dialog is the idiomatic way to go because that is how standard dialogs (like the Select/OpenFileDialog) do it. Someone could argue it is more explicit and intention revealing to have a ShowBirthdayDialog() method that returns the result you're looking for, but following the framework's pattern is probably the wise way to go.</p>
|
<p>I've always done it exactly the way you're describing. I'm curious to see if there's a more accepted approach.</p>
| 5,760
|
<p>I am at a school with several Makerbot Replicator+ – a total of 9 of them.</p>
<p>So, they seem to print fine and I can hook up to two of them to one laptop (they are some Lenovo models from a few years back) using Makerbot Print. Well and good.</p>
<p>But I wanted to hook them up to my MacBook Pro (2020, OS X Catalina) with the USB cables, and the MacBook doesn't seem to "read" the printers, it's like they aren't even there. Makerbot Print (latest version) doesn't seem to "see" that they are hooked up. I checked the system prefs to see if the Makerbots showed up as connected USB devices and they don't seem to be there either.</p>
<p>Now, I am connecting via the USB cables and then through an adapter that connects the USB-A to USB-C. If I should just use a USB-B to USB-C cable (I ordered one to test it) then fine, I'll do that. I just wanted to check that there wasn't some other problem or if anyone else had this issue.</p>
<p>Next up: USB hubs. Makerbot says they don't recommend it, but sometimes I have to print out lots of stuff at once for student projects and I can't tie up multiple laptops for hours-long prints. I have done the technique of leaving stuff all night but that's hit or miss – if something goes wrong I am not there to stop the print (at least once something got unstuck from the build plate and I ended up with an extruder with the end encased in hard plastic like a stalactite. Unless I basically blowtorch it off... )</p>
<p>So, the question(s) is/are:</p>
<p>Any recommendations for USB hubs? (I would do wireless but that I am less sure of, and it seems easier, faster, and more reliable to link up through USB. The wireless connection always drops).</p>
<p>Any recommendations for the MacBook issue? Is it just a matter of finding the right cable? (it's certainly possible my $10 USB-A to USB-C adapter plugs aren't well designed, and I should just go for direct cabling)</p>
<p>Any recommendations for a good USB hub to link a Mac (or anything else) to Makerbots?</p>
<p>Thanks for your time and help. I do hope I am not duplicating a post but I don't see anything in my searches that addresses the specific issues I have; though it's possible I didn't use the right search terms.</p>
|
<p><em><strong>It would seem that the printer control board doesn't use a CH340 (see bottom of this answer) and therefore this answer should be ignored.</strong></em></p>
<hr />
<h3>CH340 and OS X incompatibility</h3>
<p>The reason your Mac might not see the printers <em>could</em> be down to the USB interface <em><strong>on the printer controller board</strong></em>.</p>
<p>If it is implemented by a CH340 (which is probably is, in order to reduce manufacturing costs) then, historically, MacBooks have a problem with the drivers for this device and its derivatives. That is to say, the OS has a problem - more specifically the device drivers used by the OS X kernel - as opposed to the hardware. There are a number of posts dealing with this problem, it is common on Arduino clones too, see <a href="https://arduino.stackexchange.com/search?q=mac+ch340">here</a>.</p>
<p>The third party drivers for the CH340(G) written for OS X are often poorly written and/or have shoddy documentation - although this opinion may be hotly debated, and I have no wish to expand upon.</p>
<p>If the USB interface, on the printer controller board, is implemented with an FTDI or a ATmega 16U2 then it will work fine. Unfortunately the solution is probably not to use the Mac and stick with the Lenovos (i.e. PC clone).</p>
<p>See the extensive answers to <a href="https://3dprinting.stackexchange.com/q/6221/4762">Can't connect Cura to my Anet A8 on OSX 10.11.6</a></p>
<hr />
<p>As an aside, I gave up trying to buy/use cheap Arduino clones with a CH340(G), on a Mac long along, as it just wasn't worth the effort in trying to get the Mac to see it. I now ensure that either:</p>
<ul>
<li>I purchase a slightly more expensive Arduino which uses a 16U2 (the more pricey FTDI chip is more rarely used on boards these days, but can still be found). Obviously, you don't have that sort of luxury when selecting a 3D printer.</li>
<li>I will use a PC instead, if the board has a CH340(G), or similar.</li>
</ul>
<h3>One possible solution</h3>
<p>However, having said all of that, this issue <strong>may</strong> have been resolved in newer versions of OS X (post Mountain Lion, or thereabouts). This <em>might</em> provide a solution, <a href="https://arduino.stackexchange.com/q/57126/6936">Connect to ch340 on MacOS Mojave</a></p>
<blockquote>
<p>remove all old drivers:</p>
<pre><code>sudo rm -rf /Library/Extensions/usbserial.kext
sudo rm -rf /System/Library/Extensions/usb.kext
</code></pre>
<p>Now reboot the computer.</p>
<p>And then (very important, because it took me 10 cables to find the
right one) use a <strong>fully connected</strong> cable ;-)</p>
<p>Now I have these ports:</p>
<pre><code>/dev/cu.wchusbserial1410
/dev/cu.usbserial-1410
</code></pre>
</blockquote>
<p><strong>Important note</strong>: Clearly, deleting kernel drivers (also known as <em>kernel extensions</em>, <code>.kext</code>) shouldn't be taken lightly. If you feel uncomfortable doing it, or don't know how to revert the process, by using a saved backup of the drivers, then <em><strong>please don't attempt this</strong></em>.</p>
<p>For completeness:</p>
<ul>
<li><p>To back up the <code>kext</code> (<em><strong>before</strong></em> deleting it as shown above):</p>
<pre><code>sudo cp /Library/Extensions/usbserial.kext /Library/Extensions/usbserial.kext.bak
sudo cp /System/Library/Extensions/usb.kext /System/Library/Extensions/usb.kext.bak
</code></pre>
</li>
<li><p>To restore the <code>kext</code> (<em><strong>after</strong></em> having deleted the kernel extension and then finding that it made no difference whatsoever):</p>
<pre><code>sudo mv /Library/Extensions/usbserial.kext.bak /Library/Extensions/usbserial.kext
sudo mv /System/Library/Extensions/usb.kext.bak /System/Library/Extensions/usb.kext
</code></pre>
</li>
</ul>
<hr />
<p>Alternatively, instead of <em>deleting</em> the kernel drivers, you could just <em>rename</em> them to hide them, by adding <code>.bak</code> to the filename, like so</p>
<pre><code>sudo mv /Library/Extensions/usbserial.kext /Library/Extensions/usbserial.kext.bak
sudo mv /System/Library/Extensions/usb.kext /System/Library/Extensions/usb.kext.bak
</code></pre>
<p>Then reboot. Check the printer connects or not. If not, then just <em>restore</em> them using the same commands shown above - so you just end up removing the additional <code>.bak</code> from the filename.</p>
<hr />
<p>With respect to the quoted answer, I'm not entirely sure what is meant by a <strong>fully connected</strong> cable... There <em>is</em> a well-known issue that some USB <em><strong>charging</strong></em> cables - that look like normal USB cables - have only the power lines connected, and omit the data lines (again for cheapness), and it can be difficult to tell the two apart (usually by thickness, the thicker cables have more lines connected). Obviously, if the data lines are missing then the cable will not transfer data.</p>
<p><em>However</em>, this usually applies only to cables with mini, or micro USB connectors, and usually doesn't apply to standard peripheral cables such as a USB-A to USB-B cable:</p>
<p><a href="https://i.stack.imgur.com/11mVl.png" rel="nofollow noreferrer" title="USB connectors"><img src="https://i.stack.imgur.com/11mVl.png" alt="USB connectors" title="USB connectors" /></a></p>
<p>So, this issue should only arise for micro/mini USB connectors... it will depend upon your connector type.</p>
<hr />
<p>We can't recommend particular makes or models of USB hubs as that is a shopping question, which is <a href="https://3dprinting.stackexchange.com/help/on-topic">off-topic</a>.</p>
<hr />
<h3>Analysis on the printer board</h3>
<p>Makerbot appear to use the Mightyboard for the Replicator. INterestingly from the following two photos it would appear that a CH340(G) is <em><strong>not</strong></em> used, and the IC is in fact a 16U2.</p>
<p>Here is a photo of the board (image from <a href="https://www.fargo3dprinting.com/products/makerbot-replicator-2-2x-rev-h-mightyboard-oem/" rel="nofollow noreferrer">MakerBot Replicator 2/2X Rev H Mightyboard – Official, OEM Board w/ 4 BotSteps</a>):</p>
<p><a href="https://i.stack.imgur.com/AcMoE.jpg" rel="nofollow noreferrer" title="Photo of Mightboard"><img src="https://i.stack.imgur.com/AcMoE.jpg" alt="Photo of Mightboard" title="Photo of Mightboard" /></a></p>
<p>The IC closest to the USB-B port would appear to be a 16U2:</p>
<ul>
<li>Its form is square like a 16U2 and not elongated like a CH340G</li>
<li>It would appear to have an Atmel logo printed upon it.</li>
</ul>
<p>This image (from <a href="https://www.teknistore.com/en/3d-printer-module-board/19403-mightyboard-motherboard-3d-printer-dashboard.html?mobile_theme_ok" rel="nofollow noreferrer">MightyBoard Motherboard 3D Printer Dashboard</a>), also suggests the a 16U2 is used:</p>
<p><a href="https://i.stack.imgur.com/DoO9c.jpg" rel="nofollow noreferrer" title="Annotated photo of MightBoard"><img src="https://i.stack.imgur.com/DoO9c.jpg" alt="Annotated photo of MightBoard" title="Annotated photo of MightBoard" /></a></p>
<p>All of which means that, if your printer(s) have this board, then your Mac <em>should</em> indeed connect to the printer.</p>
|
<blockquote>
<p>what do you mean by SD card approach? The Makerbots take flash drives, but my attempts to print off of one were unsuccessful (it seems to be rather hard to make the right kind of file, it won't work with STLs and I gave up figuring out how to make them .makerbot files)</p>
</blockquote>
<p>This sounds like you need a better basic understanding of the printing process.</p>
<p>An STL file describes a shape you want to print, but it does not have all the information needed to actually print the object. In order to actually print the file, you need to know things like what material you will use (which will determine temperatures), what the capabilities of the machine are (how fast you can go), how much vertical detail is important to retain (layer thickness vs print time trade-off), and how strong the piece needs to be (trade-off between infill + wall thickness vs print time + material costs). You also need to specify things like how to orient the shape for best print results and what to do when there are steep overhangs or bridges.</p>
<p>To get this information, you must <strong>slice</strong> the STL (or OBJ or 3DS) file.</p>
<p>There are a number of different software packages available to do slicing, many of them freely available: Cura and slic3r come to mind. Makerbot also has their own slicer. I know you can download and install Cura on a Mac.</p>
<p>The output of the slicer is usually a <strong>.gcode</strong> file, and I would expect your Makerbots to be able to handle gcode files that were produced with the appropriate options. In fact, I strongly suspect the ".makerbot" file mentioned in your comment is actually a gcode file in disguise.</p>
<p>Why does this matter?</p>
<p>Print jobs can take hours and even days, and they tend to completely take over the computer while printing. No one wants to leave their laptop sitting next to a printer overnight, not able to do anything else. Newer printers will also have features like automatic resume from power loss, filament out detection, are more, that a are less likely to function properly when printing from a computer.</p>
<p>There's just too much that can go wrong while printing via computer, such that <em>you're pretty much always better off going with the SD card or USB option.</em><sup>*</sup></p>
<p>In other words, printing directly from your main computer is <strong>waaaaay</strong> down the list. It's not the first, second, or even third of fourth option as the best way to do this.</p>
<hr />
<p><sub>* A <em>dedicated</em> print station can work well, when setup properly, and people often use OctoPrint installed on a Raspberri Pi in this way. However, this also implies a high-end laptop is complete overkill for the task.</sub></p>
| 2,049
|
<p>Is there a commercially available fume and nano particle extractor for a 3D printer, like the Ultimaker3 extended? I'm looking for a safe solution, to use at home, for around $800. </p>
|
<p>Following on from Harvey Lim's <a href="https://3dprinting.stackexchange.com/questions/3771/commercially-available-3d-printer-fume-and-ufp-extractor#answer-3977">answer</a>, to give a concrete example of a DIY filter, which uses active carbon, see <a href="https://web.archive.org/web/20200514160332/http://www.3dprintfilemarket.com/140629194058.html" rel="nofollow noreferrer">ABS 3d Printer Nanoparticle and Chemical Exhaust Air Filter</a>:</p>
<blockquote>
<p>###Description
Enclose your 3d printer and use this exhaust air filter along with a recirculating air filter to eliminate nanoparticles and chemical fumes. 95 to 99.5% of partilces up to 0.1 micron in size are filtered before air is exhausted into your 3d printing room. This is 3 times better than HEPA filtration. Chemical fumes such as phenols, hydrogen bromide, hydrogen cyanide, and styrene are also filtered out. The amount of chemicals filtered out depends on the amount of carbon filtration media you put into the unit and the strength of the fan you install on the unit. If you are using this for business purposes, you'll have to experiment a bit to have it pass inspection. If you are using it for personal purposes, know that the human nose is extremely sensitive. People who have the gene for hydrogen cyanide detection can smell it down to a concentration of 2 to 10 ppm. Suffice it to say, that if you can smell no evil, you are probably not experiencing evil. This has totally cleared my 3d printing room of nasty fumes. I invite you to try it out for yourself as the cost is very low since I've designed it to use surgical masks and aquarium activated carbon filtration media, which is very affordable. You should change the filtration media and surgical mask every month or 50 hours of printing, whichever comes first. I offer no warranty of any kind as this is an experimental device.</p>
</blockquote>
<p>This filter is mentioned in <a href="https://3dprinting.stackexchange.com/questions/513/what-are-the-best-air-filtration-options-for-enclosures#answer-539">tbm0115's answer</a> to <a href="https://3dprinting.stackexchange.com/questions/513/what-are-the-best-air-filtration-options-for-enclosures">What are the best air filtration options for enclosures?</a></p>
|
<p>To try to answer your question, I found these enclosures on <a href="https://www.3dprintclean.com/store-1/" rel="nofollow noreferrer">3DPrintClean</a>, by browsing the Ultimaker forum. I'm not sure it fits your needs since you did not give any details about which Ultimaker you have, nor the amount of money you are willing to spend.</p>
| 552
|
<p>i have a class with a static public property called "Info".
via reflection i want to get this properties value, so i call:</p>
<pre><code>PropertyInfo pi myType.GetProperty("Info");
string info = (string) pi.GetValue(null, null);
</code></pre>
<p>this works fine as long as the property is of type string. but actually my property is of type IPluginInfo and a PluginInfo type (implementing IPluginInfo) is instatiated and returned in the Info properties get accessor, like this:</p>
<pre><code>public static IPluginInfo PluginInfo
{
get
{
IPluginInfo Info = new PluginInfo();
Info.Name = "PluginName";
Info.Version = "PluginVersion";
return Info;
}
}
</code></pre>
<p>like this when i call:</p>
<pre><code>IPluginInfo info = pi.GetValue(null, null) as IPluginInfo;
</code></pre>
<p>info is always null, whiel PropertyInfo pi is still valid. am i missing something obvious here?</p>
|
<p>Could you create a short but complete program that demonstrates the problem?</p>
<p>Given that you're talking about plugins, my <em>guess</em> is that you've got the problem of having IPluginInfo defined in two different assemblies. See if <a href="http://pobox.com/~skeet/csharp/plugin.html" rel="nofollow noreferrer">this article</a> helps at all.</p>
<p>The easiest way to verify it is to call <code>pi.GetValue</code> and store the result in an <code>object</code> variable first, then do the cast or "as" in another line. That way you can break the debugger and look at the return value before it's lost.</p>
|
<p>Um, first of all I'd implement that property a little differently:</p>
<pre><code>private static PluginInfo _PluginInfo = null;
public static IPluginInfo PluginInfo
{
get
{
if (_PluginInfo == null)
{
_PluginInfo = new PluginInfo();
_PluginInfo.Name = "PluginName";
_PluginInfo.Version = "PluginVersion";
}
return _PluginInfo;
}
}
</code></pre>
<p>Note that this needs a little more work because it isn't threadsafe, but hopefully you get the idea: build it one time rather than repeatedly.</p>
<p>I'll stop here now, since it looks like two others already finished the rest of my answer while putting together the first part.</p>
| 25,264
|
<p>The heater cartridge on my CR10 V2 broke so I ordered a new one(12V). After replacing it the new one heats of very quickly past the target temperature and the slowly decreases to the target. Once it hits the target temp it goes up and down by 10 °C or so during prints. During the prints there is under extrusion. I read that if the filament gets hot too high up the hotted it could cause clogs. I replaced the nozzle as well and cleaned out everything.</p>
<p>Some things that I think may have an effect:</p>
<ol>
<li>Could the new heater cartridge not be compatible?</li>
<li>does a poor solder job with heater cartridge wires have an effect</li>
<li>It's possible I messed up the thermistor when replacing heater cartridge, could that explain whats happening?</li>
<li>Is there anything else in the hot end assembly such as fans that would cause this?</li>
</ol>
|
<p>This sounds as if you have bought an incorrect heater element, e.g. one for 12 V instead of 24 V. The CR-10 uses 24 V. The 12 V cartridge has a lower resistance, so when powered by 24 V, the current is much higher and therefore also the heating power (<span class="math-container">$ {(\frac{24}{12})}^2 = 4 $</span> times higher). For details on the calculation, the <a href="/a/13313">this answer</a> on question: <a href="/q/13310">"PID autotune fails 'Temp too high' with 12 V heater cartridge but works with 24 V?"</a>. This makes the hotend heat up very fast resulting in a large overshoot. You need to replace the cartridge for one for 24 V.</p>
<hr>
<p><em>Note that I recently experienced exactly the same problem by mixing up the cartridges see <a href="/a/13314">this answer</a>.</em></p>
|
<p>funny I have the opposite worry, I have a CR10s5 and relaxed the whole hot end with the CR10v2 one and now I get a thermal error at 170 degrees and it shuts off, should I just replace the cartridge, or do I need to replace the fans tooo</p>
| 1,636
|
<p>I have this java code:</p>
<pre><code><script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.2.6");
$("a#more").click(function() {
$("#info_box").show("blind", { direction: "vertical" }, 800);
});
</script>
</code></pre>
<p>And this link:</p>
<pre><code><a href="#" id="more">More Info...</a>
</code></pre>
<p>info_box is just a div with the properties:</p>
<pre><code>width: 30%;
position: absolute;
left: 35%;
top: 250px;
background-color: #FFFFFF;
border: 2px solid #000000;
visibility: hidden;
</code></pre>
<p>How can this not be working, been trying to figure it out for 20 minutes.</p>
|
<p>You may use the <code>ready()</code> function and <code>display: none</code> in the initial CSS</p>
<p>Working HTML:</p>
<pre><code><html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(
function()
{
$("a#more").click(function() {
$("#info_box").show("blind");
});
});
</script>
<style>
#info_box {
width: 30%;
position: absolute;
left: 35%;
top: 250px;
background-color: #FFFFFF;
border: 2px solid #000000;
display: none;}
</style>
</head>
<body>
<a href="#" id="more">More Info...</a>
<div id="info_box">Secret info goes here</div>
</body>
</html>
</code></pre>
<p>There are problems with the show function also. You are using a not documented <code>params</code>.
Use the "animate" function instead to do a custom animation.</p>
<p>I also recommend you to use Firebug to troubleshot javascript problems in the future.</p>
|
<p>I had the exact same problem. You need to load the jQuery ui plugin as well as normal Jquery to use the format you have there.</p>
| 37,736
|
<p>Not sure if the title is quite right for the question but I can't think of any other way to put it..</p>
<p>Suppose you wanted to create multiple different web apps, but you wanted a user who was logged into one app to be able to go straight to your other app without re-logging in (assuming they have perms to look at the other app as well). If I'm not mistaken, if you're logged into gmail you can go straight to your iGoogle, googleReader, etc without re-logging in (if you set it up right).</p>
<p>How would you approach this? What would you use? Assume the apps already exist and you don't want to change the initial login page for the users.</p>
|
<p>What you're looking for is called <a href="http://en.wikipedia.org/wiki/Single_sign-on" rel="nofollow noreferrer">Single Sign On</a>. If you follow the link you'll find several implementations.</p>
<p>Open ID as others have mentioned is not such a scheme as it requires a seperate login for each site. Open ID is merely a shared authentication system.</p>
|
<p>As mentioned you can use something like OpenId or similar to make the process simple. Otherwise if you roll your own you could use a cookie to store the login, then basically ALL applications must have an entry point that mimics the base url.</p>
<p>Google for example uses mail.google.com to as a pipline into Gmail which allows it to read a cookie stored with the google.com domain.</p>
| 21,737
|
<p>I have a flex client that makes service calls to a tomcat server running BlazeDS. I would like to gracefully handle server session timeouts in this environment.</p>
<p>I do have security constraints on the service, so the client authenticates against a remote object by initializing a ChannelSet based on the destination, and then logging in using that ChannelSet.</p>
<p>After the user is authenticated, if they go get a (long) cup of coffee, their session will inevitably time out.</p>
<p>I would like the client to detect the timeout, and return the user back to the login page, with the appropriate informational messages.</p>
<p>But I am having difficulty finding the best way to detect this timeout from the client. Is it possible, or must I have the server throw an error when the timeout occurs?</p>
<p>Thanks!</p>
|
<p>We wrote a custom component for the client capturing Keystrokes and mouse events and then handle timeouts on the client.</p>
|
<p>Look at the docs and see if an event is fired when the connection is disconnected. I would imagine that there is. If not, use try/catch around your connections and catch any connection related issues. If you do, redirect your app and notify the user. You will probably need to play with it to find the exact error codes being thrown for the connection issues but it should be fairly easy in debugging.</p>
| 35,644
|
<p>I switched from Perl to Python about a year ago and haven't looked back. There is only <i>one</i> idiom that I've ever found I can do more easily in Perl than in Python:</p>
<pre><code>if ($var =~ /foo(.+)/) {
# do something with $1
} elsif ($var =~ /bar(.+)/) {
# do something with $1
} elsif ($var =~ /baz(.+)/) {
# do something with $1
}
</code></pre>
<p>The corresponding Python code is not so elegant since the if statements keep getting nested:</p>
<pre><code>m = re.search(r'foo(.+)', var)
if m:
# do something with m.group(1)
else:
m = re.search(r'bar(.+)', var)
if m:
# do something with m.group(1)
else:
m = re.search(r'baz(.+)', var)
if m:
# do something with m.group(2)
</code></pre>
<p>Does anyone have an elegant way to reproduce this pattern in Python? I've seen anonymous function dispatch tables used, but those seem kind of unwieldy to me for a small number of regular expressions...</p>
|
<p>Using named groups and a dispatch table:</p>
<pre><code>r = re.compile(r'(?P<cmd>foo|bar|baz)(?P<data>.+)')
def do_foo(data):
...
def do_bar(data):
...
def do_baz(data):
...
dispatch = {
'foo': do_foo,
'bar': do_bar,
'baz': do_baz,
}
m = r.match(var)
if m:
dispatch[m.group('cmd')](m.group('data'))
</code></pre>
<p>With a little bit of introspection you can auto-generate the regexp and the dispatch table.</p>
|
<p>My solution would be:</p>
<pre><code>import re
class Found(Exception): pass
try:
for m in re.finditer('bar(.+)', var):
# Do something
raise Found
for m in re.finditer('foo(.+)', var):
# Do something else
raise Found
except Found: pass
</code></pre>
| 14,872
|
<p>Is it possible to call a class's static property to set the navigateurl property?</p>
<blockquote>
<pre><code><asp:HyperLink ID="hlRegister" NavigateUrl="<%= SomeClass.Property %>" runat="server" />
</code></pre>
</blockquote>
<p><b>without using codebehind ofcourse!</b></p>
|
<p>You don't need code behind. You can just try it, like i just did. I created a simple page with exactly the code you have, and then created a class called SomeClass with a property named Property. It worked fine for me the way that you have it set up above. </p>
<p>Edit: Ok, it didn't compile with an error.. but It's giving me not the result I'm looking for.</p>
<p><a href="http://localhost:3061/Sample/%3C%=%20SomeClass.Property.ToString()%20%%3E" rel="nofollow noreferrer">http://localhost:3061/Sample/%3C%=%20SomeClass.Property.ToString()%20%%3E</a></p>
<p>using:</p>
<pre><code>public static class SomeClass
{
public static string Property
{
get { return "http://www.google.com"; }
}
}
</code></pre>
<p>and</p>
<pre><code><asp:HyperLink ID="hlRegister" NavigateUrl='<%= SomeClass.Property.ToString() %>' Text="Goooooogle" runat="server" />
</code></pre>
|
<p>sure, in the code behind:</p>
<pre><code>hl.NavigateUrl = Class.Static().ToString();
</code></pre>
| 25,207
|
<p>It is discouraged to simply catch <code>System.Exception</code>. Instead, only the "known" exceptions should be caught.</p>
<p>Now, this sometimes leads to unnecessary repetitive code, for example:</p>
<pre><code>try
{
WebId = new Guid(queryString["web"]);
}
catch (FormatException)
{
WebId = Guid.Empty;
}
catch (OverflowException)
{
WebId = Guid.Empty;
}
</code></pre>
<p>I wonder: Is there a way to catch both exceptions and only call the <code>WebId = Guid.Empty</code> call once?</p>
<p>The given example is rather simple, as it's only a <a href="http://en.wikipedia.org/wiki/Globally_unique_identifier" rel="noreferrer"><code>GUID</code></a>. But imagine code where you modify an object multiple times, and if one of the manipulations fails expectedly, you want to "reset" the <code>object</code>. However, if there is an unexpected exception, I still want to throw that higher.</p>
|
<p>Catch <code>System.Exception</code> and switch on the types</p>
<pre><code>catch (Exception ex)
{
if (ex is FormatException || ex is OverflowException)
{
WebId = Guid.Empty;
return;
}
throw;
}
</code></pre>
|
<p>In c# 6.0,Exception Filters is improvements for exception handling</p>
<pre><code>try
{
DoSomeHttpRequest();
}
catch (System.Web.HttpException e)
{
switch (e.GetHttpCode())
{
case 400:
WriteLine("Bad Request");
case 500:
WriteLine("Internal Server Error");
default:
WriteLine("Generic Error");
}
}
</code></pre>
| 16,469
|
<p>Is there a particular scenario where a <code>WriteOnly</code> property makes more sense then a method? The method approach feels much more natural to me. </p>
<p>What is the right approach?</p>
<p><strong>Using Properties</strong>:</p>
<pre class="lang-vb prettyprint-override"><code>Public WriteOnly Property MyProperty As String
Set(ByVal value as String)
m_myField = value
End Set
End Property
</code></pre>
<pre class="lang-cs prettyprint-override"><code>public string MyProperty
{
set{ m_myField = value;}
}
</code></pre>
<p><strong>Using Methods</strong>:</p>
<pre class="lang-vb prettyprint-override"><code>Public Sub SetMyProperty(ByVal value as String)
m_myField = value
End Sub
</code></pre>
<pre class="lang-cs prettyprint-override"><code>public void SetMyProperty(string value)
{
m_myField = value;
}
</code></pre>
<p><strong>EDIT</strong>
Just to clarify I am referring to "WriteOnly" properties.</p>
|
<p>I think a property indicates something that can be read-only or read/write. The behaviour of a write-only property is not obvious so I avoid creating them.</p>
<p>As an example, setting a list of values in a drop-down on a view and accessing the selected item:</p>
<pre><code>public interface IWidgetSelector
{
void SetAvailableWidgets(string[] widgets);
string SelectedWidget { get; set; }
}
</code></pre>
<p>Makes more sense than:</p>
<pre><code>public interface IWidgetSelector
{
string[] AvailableWidgets { set; }
string SelectedWidget { get; set; }
}
</code></pre>
|
<p>However I've seen the .Net Framework itself use ReadOnly Properties, the first one that comes to mind is: </p>
<pre><code>System.Net.Mail.MailMessage.To
</code></pre>
<p>For which you have to call a method to write to: </p>
<pre><code>System.Net.Mail.MailMessage.To.Add(Recipient As String)
</code></pre>
| 41,798
|
<p>Are there any html helpers for page navigation. eg. if i have 1000 records to display, i want to display the Previous 1 2 3 4 ... etc Next link stuff under the filtered collection.</p>
<p>Anyone know of anything out there?</p>
|
<p>Checkout <a href="http://blogs.taiga.nl/martijn/Default.aspx" rel="nofollow noreferrer">Paging with ASP.NET MVC</a>,<a href="http://www.squaredroot.com/post/2008/07/08/PagedList-Strikes-Back.aspx" rel="nofollow noreferrer">PageList Strikes Back</a> and <a href="http://weblogs.asp.net/stephenwalther/archive/2008/09/18/asp-net-mvc-tip-44-create-a-pager-html-helper.aspx" rel="nofollow noreferrer">Create a Page HTML Helper</a></p>
|
<p>I have a paging grid in my <a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=18764" rel="nofollow noreferrer">Dynamic Data for MVC sample application</a>, but the grid is hand rendered. The data is using PagedList, which came from Rob Conery (who in turn I think got it from ScottGu).</p>
<p>I've been thinking about what a paged-grid helper might look like for MVC...</p>
| 29,985
|
<p>Visually both of the following snippets produce the same UI. So why are there 2 controls..<br>
<strong>Snippet1</strong> </p>
<pre><code><TextBlock>Name:</TextBlock>
<TextBox Name="nameTextBox" />
</code></pre>
<p><strong>Snippet2</strong></p>
<pre><code><Label>Name:</Label>
<TextBox Name="nameTextBox" />
</code></pre>
<p>(<em>Well I am gonna answer this myself... thought this is a useful tidbit I learnt today from <a href="https://rads.stackoverflow.com/amzn/click/com/0596510373" rel="noreferrer" rel="nofollow noreferrer">Programming WPF</a></em>) </p>
|
<p>The WPF Textblock inherits from <strong>FrameworkElement</strong> instead of deriving from <strong>System.Windows.Control</strong> like the Label Control. This means that the Textblock is much more lightweight. The downside of using a textblock is no support for Access/Accerelator Keys and there is no link to other controls as target.</p>
<p><strong><em>When you want to display text by itself use the TextBlock</em></strong>. The benefit is a light, performant way to display text.</p>
<p><strong><em>When you want to associate text with another control like a TextBox use the Label control</em></strong>. The benefits are access keys and references to target control.</p>
|
<p>Label can be used as an alternative to TextBlock for situations where minimal text support is required such as the label for a control. Using Label can be advantageous because it requires even less resources (lighter weight) then a TextBlock. </p>
| 8,355
|
<p>It seems like the classical way to handle transactions with JDBC is to set auto-commit to false. This creates a new transaction, and each call to commit marks the beginning the next transactions.
On multithreading app, I understand that it is common practice to open a new connection for each thread.</p>
<p>I am writing a RMI based multi-client server application, so that basically my server is seamlessly spawning one thread for each new connection.
To handle transactions correctly should I go and create a new connection for each of those thread ?
Isn't the cost of such an architecture prohibitive?</p>
|
<p>Yes, in general you need to create a new connection for each thread. You don't have control over how the operating system timeslices execution of threads (notwithstanding defining your own critical sections), so you could inadvertently have multiple threads trying to send data down that one pipe.</p>
<p>Note the same applies to any network communications. If you had two threads trying to share one socket with an HTTP connection, for instance. </p>
<ul>
<li>Thread 1 makes a request</li>
<li>Thread 2 makes a request</li>
<li>Thread 1 reads bytes from the socket, unwittingly reading the response from thread 2's request</li>
</ul>
<p>If you wrapped all your transactions in critical sections, and therefore lock out any other threads for an entire begin/commit cycle, then you might be able to share a database connection between threads. But I wouldn't do that even then, unless you really have innate knowledge of the JDBC protocol.</p>
<p>If most of your threads have infrequent need for database connections (or no need at all), you might be able to designate one thread to do your database work, and have other threads queue their requests to that one thread. That would reduce the overhead of so many connections. But you'll have to figure out how to manage connections per thread in your environment (or ask another specific question about that on StackOverflow).</p>
<p><strong>update:</strong> To answer your question in the comment, most database brands don't support multiple concurrent transactions on a single connection (InterBase/Firebird is the only exception I know of). </p>
<p>It'd be nice to have a separate transaction object, and to be able to start and commit multiple transactions per connection. But vendors simply don't support it. </p>
<p>Likewise, standard vendor-independent APIs like JDBC and ODBC make the same assumption, that transaction state is merely a property of the connection object.</p>
|
<p>It's uncommon practice to open a new connection for each thread.
Usually you use a connection pool like <a href="http://sourceforge.net/projects/c3p0" rel="nofollow noreferrer">c3po</a> library.</p>
<p>If you are in an application server, or using Hibernate for example, look at the documentation and you will find how to configure the connection pool.</p>
| 36,797
|
<p>I need to suppress autoplay for the mass storage devices.
This needs to be achieved programatically through a service/deamon running in the background.</p>
<p>I know it can be done by an application which opens a window and handles the "queryCancelAutoPlay" message sent by windows.</p>
<p>Can this be done without GUI.I have the guid/pid/vid for the device whose autoplay needs to be disabled.</p>
|
<p>Sure. You can create a message-only window. That gives you a HWND without those annoying WM_PAINT messages etc. The other way is to use COM, <a href="http://msdn.microsoft.com/en-us/library/bb761373.aspx" rel="nofollow noreferrer">IQueryCancelAutoplay</a></p>
|
<p>There is a registry entry that controls AutoRun:</p>
<pre><code>HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
</code></pre>
<p>This can be set to disable AutoRun on specific device types, from <a href="http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/93502.mspx?mfr=true" rel="nofollow noreferrer">technet</a>:</p>
<pre><code>NoDriveTypeAutoRun
Value Meaning
0x1 Disables Autoplay on drives of unknown type.
0x4 Disables Autoplay on removable drives.
0x8 Disables Autoplay on fixed drives.
0x10 Disables Autoplay on network drives.
0x20 Disables Autoplay on CD-ROM drives.
0x40 Disables Autoplay on RAM drives.
0x80 Disables Autoplay on drives of unknown type.
0xFF Disables Autoplay on all types of drives.
</code></pre>
| 35,514
|
<p>I open gmail, click on an inbox item, and look at source of the page. It doesn't look like there isn't any proper html to relate to what is shown on the actual page.</p>
<p>How is the source getting processed into the actual page? Is there some javascript processing this information?</p>
|
<p>GMail uses a large amount of java script to make its pages work. This javascript is manipulating the HTML DOM.</p>
<p>If you look at the page source you aren't seeing the current contents of the DOM. You need to use a tool that will show you the HTML DOM. I use Opera Dragonfly, but there are plenty of others for other browsers. Dragonfly will show the the scripts for the page, as well as the event handlers for each element of the DOM.</p>
<p>Edited 3 Nov 08:</p>
<p>In response to the request for access to the scripts, when I view the page the scripts all come up as inline. As others have said, they're obfuscated, so less than easy to read. Here is just a sample:</p>
<pre><code>try{function aa(a,b){return a.appendChild=b}function ba(a,b){return a.textContent=b}function da(a,b){return a.stop=b}function ea(a,b){return a.toString=b}function fa(a,b){return a.length=b}function ga(a,b){return a.title=b}function ha(a,b){return a.position=b}function ia(a,b){return a.create=b}function ja(a,b){return a.className=b}function ka(a,b){return a.width=b}function la(a,b){return a.expand=b}function ma(a,b){return a.abort=b}function na(a,b){return a.data=b}function oa(a,b){return a.next=b}
function pa(a,b){return a.load=b}function d(a,b){return a.innerHTML=b}function qa(a,b){return a.onerror=b}function sa(a,b){return a.getDate=b}function ta(a,b){return a.value=b}function ua(a,b){return a.disabled=b}function va(a,b){return a.dispatchEvent=b}function wa(a,b){return a.currentTarget=b}function xa(a,b){return a.left=b}function ya(a,b){return a.hideFocus=b}function za(a,b){return a.removeChild=b}function Aa(a,b){return a.target=b}function Ba(a,b){return a.screenX=b}
function Ca(a,b){return a.screenY=b}function Da(a,b){return a.send=b}function Ea(a,b){return a.remove=b}function Fa(a,b){return a.start=b}function Ga(a,b){return a.cssText=b}function Ha(a,b){return a.keyCode=b}function Ia(a,b){return a.enabled=b}function Ja(a,b){return a.href=b}function Ka(a,b){return a.handleEvent=b}function La(a,b){return a.removeNode=b}function Ma(a,b){return a.detach=b}function Na(a,b){return a.type=b}function Oa(a,b){return a.contains=b}function Pa(a,b){return a.tabIndex=b}
function Qa(a,b){return a.cellSpacing=b}function Ra(a,b){return a.clear=b}function Sa(a,b){return a.setPosition=b}function Ta(a,b){return a.cellPadding=b}function Ua(a,b){return a.display=b}function Va(a,b){return a.execute=b}function Wa(a,b){return a.height=b}function Xa(a,b){return a.nodeValue=b}function Ya(a,b){return a.clientX=b}function Za(a,b){return a.clientY=b}function ab(a,b){return a.right=b}function bb(a,b){return a.visibility=b}
function aaa(a){var b=cb[i](db);(new Image).src=baa+eb(b)+"&jsmsg="+eb(a)+caa+fb+daa+(new Date)[gb]()}function _B_record(){cb[k]((new Date)[gb]())}function _B_prog(a){top.pr=a;if(hb===undefined){var b=top[ib][jb](eaa);hb=b?b[m]:null}if(hb){ka(hb,n[kb](a*0.99)+lb);if(a==100)hb=null}}function _B_err(a){aaa(a);throw a;}function mb(a,b){var c=a[nb](ob),e=b||pb;for(var f;f=c[rb]();)if(e[f])e=e[f];else return null;return e}function sb(){}function tb(a){a.lg=function $(){return a.bmc||(a.bmc=new a)}}
function ub(a){var b=typeof a;if(b==vb)if(a){if(typeof a[o]==wb&&typeof a[xb]!="undefined"&&!faa(a,gaa))return yb;if(typeof a[q]!="undefined")return zb}else return Ab;else if(b==zb&&typeof a[q]=="undefined")return vb;return b}function haa(a,b){if(b in a)for(var c in a)if(c==b&&Bb[r][Cb][q](a,b))return true;return false}function Db(a){return typeof a!="undefined"}function Eb(a){return ub(a)==yb}function Fb(a){var b=ub(a);return b==yb||b==vb&&typeof a[o]==wb}function Gb(a){return typeof a==Hb}
function Ib(a){return typeof a==wb}function Jb(a){return ub(a)==zb}function Kb(a){var b=ub(a);return b==vb||b==yb||b==zb}function Lb(a){if(a[Cb]&&a[Cb](iaa)){var b=a.closure_hashCode_;if(b)return b}a.closure_hashCode_||(a.closure_hashCode_=++jaa);return a.closure_hashCode_}
function s(a,b){var c=a.SSb;if(arguments[o]>2){var e=Array[r][Mb][q](arguments,2);c&&e[Nb][Ob](e,c);c=e}b=a.WSb||b;a=a.TSb||a;var f,g=b||pb;f=c?function(){var h=Array[r][Mb][q](arguments);h[Nb][Ob](h,c);return a[Ob](g,h)}:function(){return a[Ob](g,arguments)};f.SSb=c;f.WSb=b;f.TSb=a;return f}function Pb(a){var b=Array[r][Mb][q](arguments,1);b[Nb](a,null);return s[Ob](null,b)}function Qb(a,b){for(var c in b)a[c]=b[c]}
function t(a,b){function c(){}c.prototype=b[r];a.F=b[r];a.prototype=new c;a[r].constructor=a}function Rb(a,b,c){if(a[Sb])return a[Sb](b,c);if(Array[Sb])return Array[Sb](a,b,c);var e=c==null?0:c<0?n.max(0,a[o]+c):c;for(var f=e;f<a[o];f++)if(f in a&&a[f]===b)return f;return-1}function Tb(a,b,c){if(a[Ub])a[Ub](b,c);else if(Array[Ub])Array[Ub](a,b,c);else{var e=a[o],f=Gb(a)?a[nb](v):a;for(var g=0;g<e;g++)g in f&&b[q](c,f[g],g,a)}}
function Vb(a,b,c){if(a.map)return a.map(b,c);if(Array.map)return Array.map(a,b,c);var e=a[o],f=[],g=0,h=Gb(a)?a[nb](v):a;for(var j=0;j<e;j++)if(j in h)f[g++]=b[q](c,h[j],j,a);return f}function Wb(a,b,c){if(a[Xb])return a[Xb](b,c);if(Array[Xb])return Array[Xb](a,b,c);var e=a[o],f=Gb(a)?a[nb](v):a;for(var g=0;g<e;g++)if(g in f&&b[q](c,f[g],g,a))return true;return false}
</code></pre>
|
<p>In IE you get a blank page if you right-click and "View Source". If you use the Page menu > View Source, you see the actual page source. As Steve mentioned, in Firefox you see the actual source both from right-click "View Page Source" and from View menu > Page Source.</p>
<p>I suspect they're taking advantage of some IE-specific obfuscation to hide their secret sauce from 85% of the users.</p>
| 31,436
|
<p>What I can think of is pre-populating certain form input elements based on the user's geographical information.</p>
<p>What are other ways can you think of to speed up user input on long application forms?</p>
<p>Or at least keep them focus on completing the application form?</p>
|
<p>If you have a long form, try to prune it down. Don't ask them to fill in fields that you don't really need.</p>
<p>If the form spans several pages, give the user some feedback as to how many more pages there are. We users hate clicking on the continue button wondering if this will be the last page.</p>
<p>Never lose a field that they filled in, no matter what they do. This could have security implications if passwords are involved.</p>
<p>Use dropdowns to provide the user with options unless there are a lot of options that the user would have to scroll through or if the terms in the dropdown aren't widely accepted (e.g. dropdown filled with Systems Engineer, Solution Developer, IT Application... I just want Programmer.).</p>
<p>Provide help for fields that might be hard to fill in (or provide examples).</p>
|
<p>use Ajax to populate and update the controls asynchronously.It will speedup the filling of long application forms.</p>
| 28,774
|
<p>I am trying to increase the flow rate on my Ender 3 from 100 to 108 % but every time I start a new print it reverts back to the old 100 % flow rate. I have clicked through the settings and pressed the "store settings" button but it still reverts back at the start of every print. I don't want to do this in my slicer settings as I run 18 Ender 3's so I want to be able to use the same G-code for each.</p>
|
<p>Changing the <strong>flow rate</strong> during a print can <strong>not</strong> be saved. There simply is no way. It is usually meant to be a fix with filament inconsistencies or to look for the right extrusion factor for a new filament batch.</p>
<h2>Slicer</h2>
<p>The only way to consistently increase the flow rate would be to alter the <code>flow rate</code> in your slicer to what you have found to work best for each machine, probably using separate profiles. This will up the rate for every subsequently sliced print. Note though that this 108 % increased extrusion is converted extrusion factors that are simply numerical and 1.08 times the normal in the g-code. These numerical values will be taken as 100 % by the printer - and since it requires extra work to slice the gode for different profiles it is not the optimal solution.</p>
<p>As you elaborated though, this is not a doable thing, so let's look further.</p>
<h2>Source hunt & Workaround</h2>
<p>Since only one printer is showing underextrusion while the others do not, it is time to check the hard- and firmware:</p>
<ul>
<li>underextrusion can be caused by a defective extruder assembly or a damaged or blocked nozzle.</li>
<li>if a machine has consistent underextrusion, its steps/mm in the firmware might be off. This could be altered and stored in the EEPROM. Since this could be a machine unique setting, here would be your point of attack to increase the extrusion of just one machine while using the identical G-code to all other machines.</li>
</ul>
<p>Note that the standard firmware of the Ender-3 in 2019 did not contain Thermal Runaway Protection (<a href="/q/8466/">What is Thermal Runaway Protection?</a>) and should be upgraded because of this anyway. You have to flash a bootloader too, so in the process of doing the upgradeability and safety-upgrade to all the machines, you could store the altered steps/mm to each machine individually so they get consistent output.</p>
|
<p>You should be able to add a global override to the flow percentage on Marlin firmware printers.</p>
<p>Add this line somewhere in your start code:</p>
<p><code>M221 S97 ; Flow Percentage hard set.</code></p>
<p>In Cura, edit the printer's machine settings. The <code>S</code> is the percentage. In my case, 97 % works for PLA+.</p>
<p>Here is a link you might find useful.
<a href="https://marlinfw.org/docs/gcode/M221.html" rel="nofollow noreferrer">Marlin Docs</a></p>
| 1,506
|
<p>I'd like to do something like the following in C#:</p>
<pre><code> class Container {
//...
public void ForEach(Action method) {
foreach (MyClass myObj in sequence) myObj.method();
}
}
//...
containerObj.ForEach(MyClass.Method);
</code></pre>
<p>In C++ I would use something like std::mem_fun. How would I do it in C#?</p>
|
<p>This ought to work, in C# 3.0:</p>
<pre><code>class Container
{
//...
public void ForEach(Action<MyObj> method)
{
foreach (MyClass myObj in sequence) method(myObj);
}
}
//... containerObj.ForEach( myobj => myObj.Method() );
</code></pre>
|
<p>Assuming that:</p>
<pre><code> public void ForEach(Action method) {
foreach (MyClass myObj in sequence) method(myObj);
</code></pre>
<p>is no good for you, then I think you're stuck with reflection.</p>
| 45,970
|
<p>I'd like to to associate a file extension to the current executable in C#.
This way when the user clicks on the file afterwards in explorer, it'll run my executable with the given file as the first argument.
Ideally it'd also set the icon for the given file extensions to the icon for my executable.
Thanks all.</p>
|
<p>There doesn't appear to be a .Net API for directly managing file associations but you can use the Registry classes for reading and writing the keys you need to.</p>
<p>You'll need to create a key under HKEY_CLASSES_ROOT with the name set to your file extension (eg: ".txt"). Set the default value of this key to a unique name for your file type, such as "Acme.TextFile". Then create another key under HKEY_CLASSES_ROOT with the name set to "Acme.TextFile". Add a subkey called "DefaultIcon" and set the default value of the key to the file containing the icon you wish to use for this file type. Add another sibling called "shell". Under the "shell" key, add a key for each action you wish to have available via the Explorer context menu, setting the default value for each key to the path to your executable followed by a space and "%1" to represent the path to the file selected.</p>
<p>For instance, here's a sample registry file to create an association between .txt files and EmEditor:</p>
<pre>
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.txt]
@="emeditor.txt"
[HKEY_CLASSES_ROOT\emeditor.txt]
@="Text Document"
[HKEY_CLASSES_ROOT\emeditor.txt\DefaultIcon]
@="%SystemRoot%\\SysWow64\\imageres.dll,-102"
[HKEY_CLASSES_ROOT\emeditor.txt\shell]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\open]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\open\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" \"%1\""
[HKEY_CLASSES_ROOT\emeditor.txt\shell\print]
[HKEY_CLASSES_ROOT\emeditor.txt\shell\print\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" /p \"%1\""
</pre>
|
<p>There are two cmd tools that have been around since Windows 7 which make it very easy to create simple file associations. They are <a href="https://technet.microsoft.com/en-us/library/cc770920(v=ws.11).aspx" rel="nofollow noreferrer">assoc</a> and <a href="https://technet.microsoft.com/en-us/library/cc771394(v=ws.11).aspx" rel="nofollow noreferrer">ftype</a>. Here's a basic explanation of each command.</p>
<ul>
<li><a href="https://technet.microsoft.com/en-us/library/cc770920(v=ws.11).aspx" rel="nofollow noreferrer">Assoc</a> - associates a file extension (like '.txt') with a "file type."</li>
<li><a href="https://technet.microsoft.com/en-us/library/cc771394(v=ws.11).aspx" rel="nofollow noreferrer">FType</a> - defines an executable to run when the user opens a given "file type."</li>
</ul>
<p>Note that these are cmd tools and not executable files (exe). This means that they can only be run in a cmd window, or by using ShellExecute with "cmd /c assoc." You can learn more about them at the links or by typing "assoc /?" and "ftype /?" at a cmd prompt. </p>
<p>So to associate an application with a .bob extension, you could open a cmd window (WindowKey+R, type cmd, press enter) and run the following:</p>
<pre><code>assoc .bob=BobFile
ftype BobFile=c:\temp\BobView.exe "%1"
</code></pre>
<p>This is much simpler than messing with the registry and it is more likely to work in future windows version. </p>
<p>Wrapping it up, here is a C# function to create a file association:</p>
<pre><code>public static int setFileAssociation(string[] extensions, string fileType, string openCommandString) {
int v = execute("cmd", "/c ftype " + fileType + "=" + openCommandString);
foreach (string ext in extensions) {
v = execute("cmd", "/c assoc " + ext + "=" + fileType);
if (v != 0) return v;
}
return v;
}
public static int execute(string exeFilename, string arguments) {
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
startInfo.FileName = exeFilename;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = arguments;
try {
using (Process exeProcess = Process.Start(startInfo)) {
exeProcess.WaitForExit();
return exeProcess.ExitCode;
}
} catch {
return 1;
}
}
</code></pre>
| 9,515
|
<p>I have a site I'm working on that has an event page. The owner wants to be able to edit the event page weekly. Would it be easier to teach the site owner how to edit this one page and upload it or use a CMS just for this one page??</p>
<p>Apart from a contact form that posts to an email addy, the rest of the site is static. Therefore I'd need to add in a db to store the username and password for CMS login.</p>
<p>If CMS then which one would be most suitable for this case?</p>
|
<p>It depends on the complexity of the page. If it's a fixed structure where the client won't want to add links of photos you may want to give them the ability to edit a simple data file (not the page itself). Then read in the data file. I like to use a simple JSON format for this type of thing.</p>
<p>At least with a data file you can revert to an older version or handle the error gracefully, rather than having the client break the whole page.</p>
<p>If you want to go the CMS route, <a href="http://drupal.org/" rel="nofollow noreferrer">Drupal</a> has a very well-established comunity with plenty of add-ons.</p>
<p>If you're more into roll-your-own programming, you can also look at the <a href="http://code.google.com/apis/calendar/" rel="nofollow noreferrer">Google Calendar API</a>,</p>
|
<p>Personally, I would not want to deal with software installation & database setup to edit a single page.</p>
<p>You might consider an FTP-based CMS. This would give you access to a nice web-based WYSIWYG editor and any changes you make would be transferred via FTP to your web host.</p>
<p>Here are a couple of services that do this:</p>
<p>CushyCMS - <a href="http://www.cushycms.com/" rel="nofollow noreferrer">http://www.cushycms.com/</a></p>
<p>nextEdit - <a href="http://www.nextedit.net/" rel="nofollow noreferrer">http://www.nextedit.net/</a></p>
<p>In this scenario no software installation or databases would be required.</p>
<p><strong>Update:</strong> One more service is TypeRoom - <a href="http://www.typeroom.com/" rel="nofollow noreferrer">http://www.typeroom.com/</a> I had forgotten about this one. I tested it a few months back and was impressed.</p>
| 27,028
|
<p>I have code that sends HTML emails to users. To accommodate users who dont have/ want HTML email, the email contains 2 alternate views, View(0) is HTML, View(1) is Plain text. </p>
<p>The HTML view has a header and footer graphics, but the style is done inline and not via css file. The text view is only the text; no tags, images, etc. The message has 3 pdf files attached. </p>
<p>When most users receive the message, it looks fine to them. No broken image links, no garbled text, etc. </p>
<p>When others get the message, one of 2 scenarios happen. </p>
<ul>
<li>The entire HTML alternate view is packaged as an attachment (with the 3 pdfs as an attachment to it), and the parent message contains picture alphabet / random characters like this...</li>
</ul>
<blockquote>
<p>"㰡䑏䍔奐䔠桴浬⁐啂䱉䌠∭⼯圳䌯⽄呄⁈呍䰠㐮〱⁔牡湳楴楯湡氯⽅丢㰾桴浬㰾桥慤‾ഀ
㰀⽨敡搾㱢潤礠执捯汯爽∣晦晦晦∠瑥硴㴢⌰〰〰〢㰾扲㰾⽢潤社㰯桴浬ാ
� "</p>
</blockquote>
<ul>
<li>The Email is received with the attachments, but the text of the email is similar to the previous garble. </li>
</ul>
<p>The email is sent using the System.Net.Mail classes. It reads an XML template to construct email messages, so its a bit long to post here but is pretty straight forward. </p>
<p>The users that have problems with the emails have come from comcast.net and other corporate addresses. </p>
<p>I do realize that from the receivers perspective that this is email is from an unknown sender, has graphics, has attachments, and therefore will likely be recognized as spam in some cases, but its what the biz wants, so they get it. </p>
<p>My gut tells me that this is some kind of encoding problem, I am using Unicode for all formats, is this a bad assumption? EDIT: checking <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow noreferrer">this</a> to sure up my understanding. </p>
<p>Does anybody have any idea what might be causing this, or a suggestion on what to do to remedy it?</p>
<p>EDIT @some: The html email has </p>
<pre><code><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</code></pre>
<p>at the top, but the AlternateView.CreateAlternateViewFromString() method is getting System.Text.Encoding.Unicode (utf-16) applied. I can see where this can be conflicting and will update it, but this will likely take some time to see if its fixed. </p>
<p>The users only get the email once when they complete a sign up process, but we have sent this same email to another comcast email account and had no problems viewing it. </p>
<p>Is encoding specific or forced by the OS or the email client (browser, outlook / express)?</p>
<p>(Please post as an answer so you can get votes if its helpful!)</p>
|
<p>Ideally, as recommended by W3C, you should be encoding using UTF8.</p>
<p>This may do the trick.</p>
|
<p>I had this kind of problem after my PC did a Windows update automatically. I guess some set up changed. So I went to the Mail format and looked for the Editor Option --> Proofing --> Autocorrect Option and unchecked the "Straight quotes" with "Smart quoted" which is under -AutoFormat As You Type- Tab. Then I compared the set up between my PC and my friend's (who hadn't applied the latest Window update yet -around 12 Oct 2016-). I checked and un-checked things to match him. Now it's properly working and no longer has that kind of issue. (So far another friend begin to have same kind of problem. I did not ask him yet whether he got the automatic window update or not.) Good Luck.</p>
| 48,104
|
<p>I'm currently creating a website for a client that will basically involve selling various files. This is obviously a really common thing to do, which is making me feel kind of foolish for not thinking of a method for doing it.</p>
<p>Once the purchase has been made the customer should be taken to a page containing the download link, as well as receiving emails that contain a download link and an email with information about an account that will be created for them (they will also be able to download from their account's control panel). What I'm trying to figure out is how I can hide/obscure the file's location on my server so that one person who buys it can't simply copy and paste the direct link to the file elsewhere. Even if I make the request to download a file a link of the format <a href="http://example.com/blah/download/454643" rel="nofollow noreferrer">http://example.com/blah/download/454643</a>, a URL which does not correspond to the actual location of the file, I think it might still be possible to locate the file on the server? I don't really understand too much about how permissions work on my server, which is why I ask. Thanks in advance :)</p>
|
<p>You basically don't give the users the direct URL to the file. Server based permissions have nothing to do here.</p>
<p>Say you have the required file(s) saved in /data/files/file.pdf (good practice to store files out of your web root).
You can provide the users a link to download which looks something like /download.php?auth=32</p>
<p>When a user clicks the link, download.php will check if the session/cookie is authenticated and if the download id is valid (in case you have time based download expiry)
Then download.php will read the required file from its location and send it to the browser with appropriate headers to force download.</p>
|
<p>A lot of download urls I've seen that are based on purchase tend to use some guid and other dynamic information as part of the url to not make it as simple as guessing one id. You could end up with guid/datetimepurchased/id or something like that as part of the path. </p>
<p>An additional option would be to ensure the user is logged in before allowing the download to proceed which would given an additional layer of security.</p>
| 25,860
|
<p>I just want a simple tool that will help me quickly write scripts/packages that I can schedule to run. My transform requirements are pretty simple (changing column names, merging/splitting tables, and date conversions). I'll sacrifice flexibility for speed of development on this one.</p>
<p>Any come to mind?</p>
|
<p>SQL Server 2005? SSIS (but I wouldn't call it simple, but then again out of the list of things you gave, only the naming is really simple)</p>
<p>You can actually script package creation using C# (.NET/whatever, presumably even PowerShell).</p>
<p>Resources <a href="http://blogs.conchango.com/jamiethomson/archive/2007/03/28/SSIS_3A00_-Building-Packages-Programatically.aspx" rel="nofollow noreferrer">here</a> and <a href="http://msdn.microsoft.com/en-us/library/ms345167.aspx" rel="nofollow noreferrer">here</a></p>
<p>EDIT: (hope you don't mind me butting in here Cade) Check that your ODBC driver plays nicely with SSIS. Some drivers (DB2/400 and some versions of Sybase for example) don't work all that well. </p>
|
<p>Some SQL development tools, like <a href="http://www.advancedquerytool.com" rel="nofollow noreferrer">Advanced Query Tool</a> (AQT), let you do lightweight ETL and schedule with command files...
We have Informatica, but I used AQT to write from Oracle to files, for a short term request..</p>
| 20,797
|
<p>When using PNG files (made with Paint.NET) as background images on my web site, IE7 is changing the colors and actually displaying a darker version of my images, as seen <a href="http://twitpic.com/bud1" rel="noreferrer" title="IE7 dithering">here</a>. In this image, the dark background and background image should be both #001122, and the medium background and background image #004466. But IE7 changes the images to #000C1A and #003A5B respectively. No problem with FF3.</p>
|
<p>IE has a known bug with PNG gamma info, though I thought they had fixed it in version 7 :-?</p>
<p>I remove the gamma info from PNG files using "PNG Crush". I've created a right-click shortcut in Windows explorer. Further info: <a href="http://www.weirdlooking.com/blog/64" rel="nofollow noreferrer">using pngcrush in windows</a></p>
|
<p>Additional resource on this issue: <a href="http://www.modernblue.com/web-design-blog/tweak-that-gamma/" rel="nofollow noreferrer">http://www.modernblue.com/web-design-blog/tweak-that-gamma/</a></p>
| 10,160
|
<p>I need to store large amounts of data on-disk in approximately 1k blocks. I will be accessing these objects in a way that is hard to predict, but where patterns probably exist.</p>
<p>Is there an algorithm or heuristic I can use that will rearrange the objects on disk based on my access patterns to try to maximize sequential access, and thus minimize disk seek time?</p>
|
<p>Depending on what you mean by "hard to predict", I can think of a few options:</p>
<p>If you always seek based on the same block field/property, store the records on disk sorted by that field. This lets you use <a href="http://en.wikipedia.org/wiki/Binary_search" rel="nofollow noreferrer">binary search</a> for O(log n) efficiency.</p>
<p>If you seek on different block fields, consider storing an external index for each field. A <a href="http://en.wikipedia.org/wiki/B-tree" rel="nofollow noreferrer">b-tree</a> gives you O(log n) efficiency. When you seek, grab the appropriate index, search it for your block's data file address and jump to it.</p>
<p>Better yet, if your blocks are homogeneous, consider breaking them down into database records. A database gives you optimized storage, indexing, and the ability to perform advanced queries for free.</p>
|
<p>That's an interesting challenge. Unfortunately, I don't know how to solve this out of the box, either. Corbin's approach sounds reasonable to me.</p>
<p>Here's a little optimization suggestion, at least: Place the most-accessed items at the <em>center</em> of your disk (or unfragmented file), not at the start of end. That way, seeking to lesser-used data will be closer by average. Err, that's pretty obvious, though.</p>
<p>Please let us know if you figure out a solution yourself.</p>
| 44,733
|
<p>In a web application like wiki or forums or blogging software, it is often useful to store your data in a relational database. Since many hosting companies offer a single database with their hosting plans (with additional databases costing extra) it is very useful for your users when your database objects (tables, views, constraints, and stored procedures) have a common prefix. It is typical for applications aware of database scarcity to have a hard-coded table prefix. I want more, however. Specifically, I'd like to have a table prefix that users can designate—say in the web.config file (with an appropriate default, of course).</p>
<p>Since I hate coding <a href="https://en.wikipedia.org/wiki/Create%2C_read%2C_update_and_delete" rel="nofollow noreferrer">CRUD</a> operations by hand, I prefer to work through a competent OR/M and have used (and enjoyed) LINQ to SQL, Subsonic, and ADO.Net. I'm having some thrash in a new project, however, when it comes to putting a table prefix in a user's web.config file. Are there any .Net-based OR/M products that can handle this scenario elegantly?</p>
<p>The best I have been able to come up with so far is using LINQ to SQL with an external mapping file that I'd have to update somehow based on an as-yet hypothetical web.config setting.</p>
<p>Anyone have a better solution? I tried to make it happen in Entity Framework, but that turned into a mess quickly. (Due to my unfamiliarity with EF? Possibly.) How about SubSonic? Does it have an option to apply a table prefix besides at code generation time?</p>
|
<p>I've now researched what it takes to do this in both Entity Framework and LINQ to SQL and <a href="http://theruntime.com/blogs/jacob/archive/2008/08/27/changing-table-names-in-an-orm.aspx" rel="nofollow noreferrer">documented the steps required in each</a>. It's much longer than answers here tend to be so I'll be content with a link to the answer rather than duplicate it here. It's relatively involved for each, but the LINQ to SQL is the more flexible solution and also the easiest to implment.</p>
|
<p><a href="https://www.mindscape.co.nz/products/LightSpeed/default.aspx" rel="nofollow noreferrer">LightSpeed</a> allows you to specify an <em>INamingStrategy</em> that lets you resolve table names dynamically at runtime.</p>
| 3,283
|
<p>I'm using IdeaMaker for slicing my print objects. IdeaMaker start strings have a >T0< standing alone on one line and then >T1< on the next line. What does this accomplish?</p>
|
<p>T stands for <a href="https://en.wikipedia.org/wiki/G-code#Letter_addresses" rel="nofollow noreferrer">"Tool"</a> and has its origin in the origins of <a href="https://en.wikipedia.org/wiki/G-code#Letter_addresses" rel="nofollow noreferrer"><code>.gcode</code></a> being for other automated machine controls. Depending on the machine, everything could be a tool for <code>.gcode</code>, like an actuator or pump or a spindle motor or a drill.</p>
<p>In 3D printers, the T-controlled tool is usually the <strong>extruder motor</strong>. Convention has it that the indexing always starts at 0, so T0 and T1 are your first and second Extruder respectively. It is the way to choose which tool is used. </p>
<p>As a side note: E is not originally intended for extruders but for the feed rate of lathes.</p>
|
<p>I'm not sure what it's doing in your case, but the "T" code is there to select the extruder number. T0 would be the first and T1 would be the second extruder in a multi-extruder setup. I found the information at the end of <a href="http://www.makeit-3d.com/wp-content/uploads/RepRapGcodeCheatSheet.pdf" rel="nofollow noreferrer">this cheat sheet</a>. </p>
| 1,246
|
<p>Is it possible to open an HTML page using navigateToURL and specifying a named frame in your HTML document? For instance, if you have an iframe on the page called "Steven", can you call</p>
<pre><code>navigateToURL("someURL","Steven");
</code></pre>
<p>instead of something like</p>
<pre><code>navigateToURL("someURL","_self");
</code></pre>
<p>I have tried this and it opens the URL in a new window.</p>
|
<p>Did you test this on local files saved to your hard drive? If so, then there are some security restrictions that you may be running in to. See the security note <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL()" rel="nofollow noreferrer">here</a>.</p>
<p>But if you're testing this with files on a web server, and there are no cross-domain issues, then <code>navigateToURL()</code> should work exactly the way you're using it - if your iframe's name is "Steven" then the content should be opening in that iframe.</p>
|
<p>I'm not sure, but you can use JavaScript:</p>
<pre><code>navigateToURL("javascript:loadFrame(someURL)");
</code></pre>
<p>Then in your HTML page:</p>
<pre><code>function loadFrame(url) {
documents.frames[1].src=url
}
</code></pre>
| 21,213
|
<p>Has anyone used <a href="http://web.archive.org/web/20090803092709/http://www.aptana.com:80/Jaxer" rel="nofollow noreferrer">Jaxer</a> in a production environment, I am curious as to how it holds up compared to something like php, ruby, etc. and if anyone knows of any pitfalls to using it that are well known.</p>
|
<p>@Stu: Not necessarily, maybe there's a bunch of people using it and having no issues. I love the concept having to only write validations once, using one language for everything both client and server side sounds like a interesting approach.</p>
|
<p>I'll add this <a href="http://www.ibm.com/developerworks/web/library/wa-aj-jaxer/index.html?ca=dgr-jw64wa-aj-jaxer&S_TACT=105AGY46&S_CMP=GRsitejw64" rel="nofollow noreferrer">Url</a> to my post I found it today, it has some information regarding the subject but no real "performance" information.</p>
| 3,149
|
<p>Is output buffering enabled by default in Python's interpreter for <code>sys.stdout</code>?</p>
<p>If the answer is positive, what are all the ways to disable it?</p>
<p>Suggestions so far:</p>
<ol>
<li>Use the <code>-u</code> command line switch</li>
<li>Wrap <code>sys.stdout</code> in an object that flushes after every write</li>
<li>Set <code>PYTHONUNBUFFERED</code> env var</li>
<li><code>sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)</code></li>
</ol>
<p>Is there any other way to set some global flag in <code>sys</code>/<code>sys.stdout</code> programmatically during execution?</p>
|
<p>From <a href="http://mail.python.org/pipermail/tutor/2003-November/026645.html" rel="nofollow noreferrer">Magnus Lycka answer on a mailing list</a>:</p>
<blockquote>
<p>You can skip buffering for a whole
python process using <code>python -u</code>
or by
setting the environment variable
PYTHONUNBUFFERED.</p>
<p>You could also replace sys.stdout with
some other stream like wrapper which
does a flush after every call.</p>
<pre><code>class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
import sys
sys.stdout = Unbuffered(sys.stdout)
print 'Hello'
</code></pre>
</blockquote>
|
<p>One way to get unbuffered output would be to use <code>sys.stderr</code> instead of <code>sys.stdout</code> or to simply call <code>sys.stdout.flush()</code> to explicitly force a write to occur.</p>
<p>You could easily redirect everything printed by doing:</p>
<pre><code>import sys; sys.stdout = sys.stderr
print "Hello World!"
</code></pre>
<p>Or to redirect just for a particular <code>print</code> statement:</p>
<pre><code>print >>sys.stderr, "Hello World!"
</code></pre>
<p>To reset stdout you can just do:</p>
<pre><code>sys.stdout = sys.__stdout__
</code></pre>
| 13,314
|
<p>I feel like this is a stupid question because it seems like common sense . . . but no google search I can put together seems to be able to give me the answer! </p>
<p>I know how to get data OUT of a sqlite3 database using the .dump command. But now that I have this ASCII file titled export.sqlite3.sql . . . I can't seem to get it back INTO the database I want. </p>
<p>My goal was to transfer the data I had in one rails app to another so I didn't have to take all sorts of time creating dummy data again . . . so I dumped the data from my first app, got rid of all the CREATE TABLE statements, and made sure my schema on my second app matches . . . now I just have to get it IN there. </p>
<p>Would anyone mind helping me out? And when you find a way, will you tell me what you plugged into the google, 'cause I am beating my head open with a spoon right now over what I thought would be an easy find. </p>
|
<pre><code>cat dumpfile.sql | sqlite3 my_database.sqlite
</code></pre>
<p><a href="http://www.sqlite.org/sqlite.html" rel="noreferrer">This is modified from the sqlite3 getting started guide.</a></p>
|
<p>Use this for unix flavors.</p>
<p>press Ctrl+alt+T and write</p>
<pre><code>sqlite3 /home/ubuntu/output.sqlite < /home/ubuntu/input.sql
</code></pre>
<p>It restore your database from input file.</p>
| 40,167
|
<p>Is there a limit with the number of SSL connections?</p>
<p>We are trying to connect through SSL with 2000 sessions. We have tried it a couple of times but it always dies at 1062nd. Is there a limit?</p>
|
<p>Your operating system will have a limit on the number of open files if you are on linux
ulimit -a will show your various limits.</p>
<p>I imagine yours is set to 1024 and some of the sessions just happened to have closed allow the figure of 1062 (this last bit is a guess)</p>
|
<p>Yes, everything has a limit. As far as I'm aware, there is no inherit limit with "SSL".. it is after all just a protocol.</p>
<p>But, there is a limited amount of memory, ports, CPU on the machine you are connected to, from and every single one in between.</p>
<p>The actually server you are connected to may have an arbitrary limit set too. </p>
<p>This question doesn't have enough information to answer beyond "YES".</p>
| 6,767
|
<p>I’m trying to debug a memory leak problem. I’m using <a href="http://www.gnu.org/software/libc/manual/html_node/Tracing-malloc.html#Tracing-malloc" rel="noreferrer">mtrace()</a> to get a malloc/free/realloc trace. I’ve ran my prog and have now a huge log file. So far so good. But I have problems interpreting the file. Look at these lines:</p>
<pre><code>@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x1502570 0x68
@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x1502620 0x30
@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x2aaab43a1700 0xa80
@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x1501460 0xa64
</code></pre>
<p>The strange about this is that one call (same return address) is responsible for 4 allocations.</p>
<p>Even stranger:</p>
<pre><code>@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x2aaab43a1700 0xa2c
…
@ /usr/java/ibm-java2-x86_64-50/jre/bin/libj9prt23.so:[0x2b270a384a34] + 0x2aaab43a1700 0xa80
</code></pre>
<p>Between those two lines the block 0x2aaab43a1700 is never being freed.</p>
<p>Does anyone know how to explain this? How could one call result in 4 allocations? And how could malloc return an address which was already allocated previously?</p>
<p>edit 2008/09/30:
The script to analyze the mtrace() output provided by GLIBC (mtrace.pl) isn't of any help here. It will just say: Alloc 0x2aaab43a1700 duplicate. But how could this happen?</p>
|
<p>The function that is allocating the memory is being called more than once. The caller address points to the code that did the allocation, and that code is simply being run more than once.</p>
<p>Here is an example in C:</p>
<pre><code>void *allocate (void)
{
return (malloc(1000));
}
int main()
{
mtrace();
allocate();
allocate();
}
</code></pre>
<p>The output from mtrace is:</p>
<pre>
Memory not freed:
-----------------
Address Size Caller
0x0000000000601460 0x3e8 at 0x4004f6
0x0000000000601850 0x3e8 at 0x4004f6
</pre>
<p>Note how the caller address is identical? This is why the mtrace analysing script is saying they are identical, because the same bug is being seen more that once, resulting in several memory leaks.</p>
<p>Compiling with debugs flags (-g) is helpful if you can:</p>
<pre>
Memory not freed:
-----------------
Address Size Caller
0x0000000000601460 0x3e8 at /home/andrjohn/development/playground/test.c:6
0x0000000000601850 0x3e8 at /home/andrjohn/development/playground/test.c:6
</pre>
|
<p>One possible explanation is that the same function is allocating different buffer sizes? One such example is strdup.</p>
<p>For the second question, it is possible that the runtime is allocating some "static" scratch area which is not intended to be freed until the process is terminated. And at that point, the OS will clean-up after the process anyway.</p>
<p>Think about it this way: in Java, there are no destructors, and no guarantees that finalization will be ever called for any object.</p>
| 18,598
|
<p>Has anybody any useful links that can be used to consume a web service using flex?
The easier the solution the better</p>
<p>Thanks</p>
|
<p>Try <a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/soap/mxml/WebService.html" rel="nofollow noreferrer">http://livedocs.adobe.com/flex/3/langref/mx/rpc/soap/mxml/WebService.html</a> for SOAP services. You just have to specify the WSDL location and the event handlers and call the service.</p>
<p>Flex Builder 3 also contains code generation capabilities for creating proxies for web services.
<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=data_4.html" rel="nofollow noreferrer">http://livedocs.adobe.com/flex/3/html/help.html?content=data_4.html</a></p>
|
<p>Flex Builder 3 comes with code generation tools that let you build the actionscript objects that correspond to the server side transfer object exposed by the eb service wsdl. It can make your life easier when working with web services. Here is a <a href="http://www.flexlive.net/?p=79" rel="nofollow noreferrer">good overview by Zee Yang</a>.</p>
<p>Brian Riley and Clint Modien have written an open source tool called <a href="http://code.google.com/p/vofactory/" rel="nofollow noreferrer">VOFactory</a> which lets you cast wsdl objects to actionscript objects on the fly.</p>
| 13,618
|
<p>I'm using the command line compiler for builds. One problem I see is that the paths mentioned there seem to need to be the short versions of the filenames such that they don't contain any spaces. I don't know so much about this even though I have used it for some time.</p>
<p>I recently upgraded to d2009 and the problem started then.</p>
<p>Is there a way around shortening the path? </p>
<p>I should say I'm not eager to change to use the MS Build tool at this time. I just want to build an old copy of my app & get back to other work.</p>
<p>Here's the path used in the <code>dcc32.cfg</code> file for the <code>-I</code>, <code>-U</code>, <code>-O</code>, and <code>-R</code> parameters:</p>
<pre><code>$(BDS)\LIB;$(BDS)\Imports;$(BDS)\Lib\Indy10;C:\PROGRA~1\Borland\BDS\4.0\RAVERE~1\Lib;c:\prj\lib\lib2002;C:\DOCUME~1\ALLUSE~1\DOCUME~1\RADSTU~1\5.0\Bpl;c:\DOCUME~1\mike\MYDOCU~1\BORLAN~1\bpl;C:\Prj\Lib\LOCKBO~1\source;C:\Prj\Lib\MyComp;C:\Prj\Lib\ABBREV~1\source;C:\Prj\Lib\ZLib;C:\Prj\Lib\MinMod;C:\Prj\Lib\HELPMA~1;C:\Prj\Lib\DXGETT~1;c:\windows\system32;c:\prj\lib\xpburn;C:\Prj\Lib\WININE~1;C:\Prj\Lib\regexpr\Source;C:\Prj\Lib\VCARDR~1;C:\PROGRA~1\Raize\RC4\Lib\BDS2006;C:\Prj\Lib\jcl\lib\d10;C:\Prj\Lib\jcl\source;C:\Prj\Lib\jvcl\lib\D10;C:\Prj\Lib\jvcl\common;C:\Prj\Lib\jvcl\RESOUR~1;C:\Prj\Lib\ProE6\Delphi;C:\Prj\Lib\FastMM4;C:\Prj\Lib\OPENOF~1;C:\Prj\Lib\DEVELO~1\Library\Delphi11;C:\Prj\Lib\DEVELO~1\EX38D9~1\Sources;C:\Prj\Lib\DEVELO~1\EXBD88~1\Sources;C:\Prj\Lib\DEVELO~1\XPTHEM~1\Sources;C:\Prj\Lib\DEVELO~1\EX2EBC~1\Sources;C:\Prj\Lib\DEVELO~1\EXC5FB~1\Sources;C:\Prj\Lib\DEVELO~1\EX7C7C~1\Sources;C:\Prj\Lib\DEVELO~1\EXPRES~3\Sources;C:\Prj\Lib\DEVELO~1\EXPRES~4\Sources;C:\Prj\Lib\DEVELO~1\EXC73B~1\Sources;C:\Prj\Lib\DEVELO~1\EX7165~1\Sources;C:\Prj\Lib\DEVELO~1\EXPRES~2\Sources;C:\Prj\Lib\DEVELO~1\EXPRES~1\Sources;C:\Prj\Lib\DEVELO~1\EX749C~1\Sources;C:\Prj\Lib\DEVELO~1\EX0A1A~1\Sources;C:\Prj\Lib\Mad\madBasic\BDS4;C:\Prj\Lib\Mad\MADDIS~1\BDS4;C:\Prj\Lib\Mad\MADEXC~1\BDS4;C:\Prj\Lib\Mad\MADKER~1\BDS4;C:\Prj\Lib\Mad\MADSEC~1\BDS4;C:\Prj\Lib\Mad\madShell\BDS4;C:\Prj\Lib\Mad\madShell\DeXter;C:\Prj\Lib\Mad\madExcept\..\Plugins;
</code></pre>
<p>I've copied it from the IDE's path like I have done in the path and used a program to shorten the path names.</p>
<p>Although there are no spaces in that path, it still can't find indy's <code>IdCoder.dcu</code> at <code>C:\Program Files\CodeGear\RAD Studio\5.0\lib\Indy10</code></p>
<p>According to the d2007 environment variables, <code>$(BDS)</code> would apparently expand to <code>c:\program files\codegear\rad studio\5.0</code></p>
<p>The IDE is considering this library path to be valid.</p>
<p>Why is this happening? I bet it's a simple mistake I haven't thought of!</p>
<p>Thank you for your help!</p>
|
<p>You could try to put the paths in quotes, that's the standard way of handling path-/filenames with spaces in Windows, though I never tried that in Delphi DCUs.</p>
<p>So, instead of </p>
<pre><code>$(BDS)\Lib\Indy10
</code></pre>
<p>try</p>
<pre><code>"$(BDS)\Lib\Indy10"
</code></pre>
<p>You could also try</p>
<pre><code>"C:\Program Files\CodeGear\RAD Studio\5.0\lib\Indy10"
</code></pre>
<p>to check if the environment variable is correct.</p>
|
<p>Is the $(BDS) environment variable set when you're compiling the program from the command-line? If not, that might be the problem.</p>
<p>Putting quotes around paths containing spaces will likely solve the problem with spaces. This has worked for me:</p>
<p>-U"C:\Path to libraries\First library;C:\Path to libraries\Second library;C:\Path to libraries\Third library"</p>
| 37,151
|
<p>My coworker and I have encountered a nasty situation where we have to use an active X control to manipulate a web camera on a page. </p>
<p>Is it possible to assign a javascript event handler to a button in the active x control so that it would fire an action on the page when clicked, or do we have to create a button on the html page itself that manipulates the Active X Control and then can fire any necessary actions on the page?</p>
|
<p><em>Please</em> just use an existing ActiveX control. Like Flash or Silverlight. Flash has built-in webcam support and is controllable via JavaScript. Silverlight doesn't have built-in camera support, but it's JavaScript integration is fantastic.</p>
<p>If you must write your own then fret not, it is trivial to get it to interact with JavaScript. You just have to expose the <a href="http://msdn.microsoft.com/en-us/library/ms221608.aspx" rel="noreferrer"><code>IDispatch</code></a> interface.</p>
<p>For events, you need to learn about <a href="http://msdn.microsoft.com/en-us/library/98b11x9k(VS.80).aspx" rel="noreferrer">Connection Points</a>.</p>
|
<p>Yes! You can throw events in C++/ActiveX land which makes the JavaScript code run an event handler function. I was even able to make an entire invisible ActiveX control (same color as page background) with no buttons or visual feedback that did all of its GUI work through JavaScript and CSS.</p>
<p>edit: Frank's advice is right on. <a href="https://msdn.microsoft.com/en-us/library/ms974564.aspx" rel="nofollow noreferrer">Here's the link on scripting events.</a></p>
<p>My strategy was to call a C++ function called MyUpdate (which implements IConnectionPoint) when I wanted to force updates in the browser.</p>
<p>(Also, I made sure to pump Windows messages in the Fire_MyUpdate method because sometimes JavaScript code would call back into C++ land by calling methods on the ActiveX control; this avoids freezing up the browser and ensures that the JavaScript GUI stays responsive, e.g. for a Cancel button.)</p>
<p>On the browser side, the JavaScript code has the global variable referencing the object, followed by "::", followed by the method name:</p>
<pre><code>function Uploader::MyUpdate()
{
// ... code to fetch the current state of various
// properties from the Uploader object and do something with it
// for example check Uploader.IsActive and show or hide an HTML div
}
</code></pre>
| 4,608
|
<p>JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function. How do you do the reverse, and add a function to an "object"?</p>
<p>This works:</p>
<pre><code>var foo = function() { return 1; };
foo.baz = "qqqq";
</code></pre>
<p>At this point, <code>foo()</code> calls the function, and <code>foo.baz</code> has the value "qqqq".</p>
<p>However, if you do the property assignment part first, how do you subsequently assign a function to the variable?</p>
<pre><code>var bar = { baz: "qqqq" };
</code></pre>
<p>What can I do now to arrange for <code>bar.baz</code> to have the value "qqqq" <em>and</em> <code>bar()</code> to call the function?</p>
|
<p>It's easy to be confused here, but you can't (easily or clearly or as far as I know) do what you want. Hopefully this will help clear things up.</p>
<p>First, every object in Javascript inherits from the Object object.</p>
<pre><code>//these do the same thing
var foo = new Object();
var bar = {};
</code></pre>
<p>Second, functions <strong>ARE</strong> objects in Javascript. Specifically, they're a Function object. The Function object inherits from the Object object. Checkout the <a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function" rel="noreferrer">Function constructor</a></p>
<pre><code>var foo = new Function();
var bar = function(){};
function baz(){};
</code></pre>
<p>Once you declare a variable to be an "Object" you can't (easily or clearly or as far as I know) convert it to a Function object. You'd need to declare a new Object of type Function (with the function constructor, assigning a variable an anonymous function etc.), and copy over any properties of methods from your old object.</p>
<p>Finally, anticipating a possible question, even once something is declared as a function, you can't (as far as I know) change the functionBody/source. </p>
|
<blockquote>
<p>JavaScript allows functions to be
treated as objects--you can add a
property to a function. How do you do
the reverse, and add a function to an
object?</p>
</blockquote>
<p>You appear to be a bit confused. Functions, in JavaScript, <em>are</em> objects. And <strong>variables <em>are</em> variable</strong>. You wouldn't expect this to work:</p>
<pre><code>var three = 3;
three = 4;
assert(three === 3);
</code></pre>
<p>...so why would you expect that assigning a function to your variable would somehow preserve its previous value? Perhaps some annotations will clarify things for you:</p>
<pre><code>// assigns an anonymous function to the variable "foo"
var foo = function() { return 1; };
// assigns a string to the property "baz" on the object
// referenced by "foo" (which, in this case, happens to be a function)
foo.baz = "qqqq";
</code></pre>
| 15,130
|
<p>I would like to have both Eclipse and Netbeans (with JUnit) installed on one system, so I can be somewhat familiar with both.</p>
<p>Besides GUI development (see "<a href="https://stackoverflow.com/questions/174308/using-both-eclipse-and-netbeans">Using both Eclipse and Netbeans</a>"), are there any other issues with using both IDEs on the same system, or even the same project?</p>
|
<p>We regularly use both Netbeans and Eclipse. We switch back and forth, between Vista, WinXP, and multiple versions of Fedora of the 32- and 64-bit variety, with no problems. Keeping the project files in version control makes keeping them in sync much easier. We even keep the launch files in the project directory as well. I posted a answer to <a href="https://stackoverflow.com/questions/81567/how-do-you-handle-different-java-ides-and-svn">another multiple IDEs question</a> that describes what our project directory looks like.</p>
<p>Basically, I agree with Bill the Lizard about there being no issues, but disagree about the seamless nature and keeping the project files separate. The only thing we have to do is make sure that we update the build classpath in each project if a new library is added because Netbeans and Eclipse use different files to describe the classpath.</p>
<p>Using the IDE version control system integrations helps to encourage keeping the projects up to date for everyone else.</p>
|
<p>Maven is a very good way to keep both IDEs in sync (as suggested). In my experience though, you have to create an Ant build for any given project for the sake of developers not using IDEs. Since NetBeans's build system is based on Ant, it's pretty trivial to just base the entire NetBeans project off of that base build system. A little bit of tweaking in the <code>project.xml</code> ensures that the editor classpath is kept in sync with the Ant build classpath.</p>
| 22,839
|
<p>I have a <code>char* p</code>, which points to a <code>\0</code>-terminated string. How do I create a C++ <code>string</code> from it in an exception-safe way?</p>
<p>Here is an unsafe version:</p>
<pre><code>string foo()
{
char *p = get_string();
string str( p );
free( p );
return str;
}
</code></pre>
<p>An obvious solution would be to try-catch - any easier ways? </p>
|
<p>You can use <code>shared_ptr</code> from <a href="http://en.cppreference.com/w/cpp/memory/shared_ptr" rel="noreferrer">C++11</a> or <a href="http://www.boost.org/libs/smart_ptr/" rel="noreferrer">Boost</a>:</p>
<pre><code>string
foo()
{
shared_ptr<char> p(get_string(), &free);
string str(p.get());
return str;
}
</code></pre>
<p>This uses a very specific feature of <code>shared_ptr</code> not available in <code>auto_ptr</code> or anything else, namely the ability to specify a custom deleter; in this case, I'm using <code>free</code> as the deleter.</p>
|
<p>We commonly use <a href="http://www.ddj.com/cpp/184403758" rel="nofollow noreferrer">ScopeGuard</a> for these cases:</p>
<pre><code>string foo()
{
char *p = get_string();
ScopeGuard sg = MakeGuard(&free, p);
string str( p );
return str;
}
</code></pre>
| 30,588
|
<p>We have a hosted application that manages pages of content. Each page can have a number of customized fields, and some standard fields (timestamp, user name, user email, etc).</p>
<p>With potentially hundreds of different sites using the system -- what is an efficient way to handle filtering/searching? Picture a grid view that you want to narrow down. You can filter on specific fields (userid, date) or you can enter a full-text search.</p>
<p>For example, "all pages started by userid 10" would be a pretty quick query against a MySQL database. But things like "all pages started by a user whose userid is 10 and matches [some search query]" would suck against the database, so it's suited for a search engine like Lucene.</p>
<p>Basically I'm wondering how other large sites do this sort of thing. Do they utilize a search engine 100% for all types of filtering? Do they mix database queries with a search engine?</p>
<p>If we use <em>only</em> a search engine, there's a problem with the delay time it takes for a new/updated object to appear in the search index. That is, I've read that it's not smart to update the index <em>immediately</em>, and to do it in batches instead. Even if this means every 5 minutes, users will get confused when their recently added page isn't immediately listed when they view a simple page listing (say a search query of "category:5").</p>
<p>We are using MySQL and have been looking closely at Lucene for searching. Is there some other technology I don't know about?</p>
<p>My thought is to offer a simple filtering page which uses MySQL to filter on basic fields. Then offer a separate fulltext search page that would present results similar to Google. Is this the only way? </p>
|
<p>Solr or grassyknoll both provide slightly more abstract interfaces to Lucene. </p>
<p>That said: Yes. If you are a primarily content driven site, providing fulltext searching over your data, there is something in play beyond LIKE. While MySql's FULLTEXT indexies aren't perfect, it might be an acceptable placeholder in the interim. </p>
<p>Assuming you do create a Lucene index, linking Lucene Documents to your relational objects is pretty straightforward, simply add a stored property to the document at index time (this property can be a url, ID, GUID etc.) Then, searching becomes a 2 phase system:
1) Issue query to Lucene indexies (Display simple results like title)
2) Get more detailed information about the object from your relational stores by its key</p>
<p>Since instantiation of Documents is relatively expensive in Lucene, you only want to store fields searched in the Lucene index, as opposed to complete clones of your relational objects. </p>
|
<p>Don't write-off MySQL so readily!</p>
<p>Implement it using the database e.g. a select with a 'like' in the where-clause or whatever.</p>
<p>Profile it, add indexes if necessary. Roll out a beta, so you get real numbers from user's actual data patterns - not all columns might be equally asked after, etc.</p>
<p>If the performance does suck, then thats when you consider other options. You can consider tuning your SQL, your database, the machine the database is running on, and finally using another technology stack...</p>
| 38,879
|
<p>I hear people writing these programs all the time and I know what they do, but how do they actually do it? I'm looking for general concepts.</p>
|
<p>Technically, screenscraping is any program that grabs the display data of another program and ingests it for it's own use.</p>
<p>Quite often, screenscaping refers to a web client that parses the HTML pages of targeted website to extract formatted data. This is done when a website does not offer an RSS feed or a REST API for accessing the data in a programmatic way.</p>
<p>One example of a library used for this purpose is <a href="https://github.com/hpricot/hpricot" rel="noreferrer">Hpricot</a> for Ruby, which is one of the better-architected HTML parsers used for screen scraping.</p>
|
<blockquote>
<p>Screen scraping is what you do when nobody's provided you with a reasonable machine-readable interface. It's hard to write, and brittle.</p>
</blockquote>
<p>Not quite true. I don't think I'm exaggerating when I say that most developers do not have enough experience to write decents APIs. I've worked with screen scraping companies and often the APIs are so problematic (ranging from cryptic errors to bad results) and often don't give the full functionality that the website provides that it can be better to screen scrape (web scrape if you will). The extranet/website portals are used my more customers/brokers than API clients and thus are better supported. In big companies changes to extranet portals etc.. are infrequent, usually because it was originally outsourced and now its just maintained. I refer more to screen scraping where the output is tailored, e.g. a flight on particular route and time, an insurance quote, a shipping quote etc.. </p>
<p>In terms of doing it, it can be as simple as web client to pull the page contents into a string and using a series of regular expressions to extract the information you want.</p>
<pre><code>string pageContents = new WebClient("www.stackoverflow.com").DownloadString();
int numberOfPosts = // regex match
</code></pre>
<p>Obviously in a large scale environment you'd be writing more robust code than the above.</p>
<blockquote>
<p>A screen scraper downloads the html
page, and pulls out the data
interested either by searching for
known tokens or parsing it as XML or
some such.</p>
</blockquote>
<p>That is cleaner approach than regex... in theory.., however in practice its not quite as easy, given that most documents will need normalized to XHTML before you can XPath through it, in the end we found the fine tuned regular expressions were more practical. </p>
| 18,883
|
<p>I am currently coding a simple Data Access Layer, and I was wondering which type I should expose to the other layers.</p>
<p>I am going to internally implement the Data as a List<>, but I remember reading something about not exposing the List type to the consumers if not needed.</p>
<pre><code>public List<User> GetAllUsers() // non C# users: that means List of User :)
</code></pre>
<p>Do you know why (google didn't help)? What do you usually expose for that kind of stuff? IList? IEnumerable?</p>
|
<p>Usually it's best to expose the least powerful interface that the user can still meaningfully work with. If the user just needs some enumerable data, return <code>IEnumerable<User></code>. If that's not enough because the user needs to be able to modify the list (attention! shouldn't often be the case), return an <code>IList<User></code>.</p>
<h2>/EDIT:</h2>
<p>Joel asks a valid question in his comment: Why indeed expose the least powerful interface instead of granting the user maximum power? (paraphrased)</p>
<p>The idea behind this is that the method returning the data might not expect the user to modify its content: Another method of the class might still expect the list to be non-empty after a reference to it was returned. Imagine the user removes all data from the list. The other method now has to make an additional check that ele might have been unnecessary.</p>
<p>More importantly, this exposes parts of the internal implementation through the return type. If I need to change the implementation in the future so that it no longer uses an <code>IList</code> container, I have a problem: I either need to change the method contract, introducing a build-breaking change. Or I need to copy the data into a list container.</p>
<p>As an example, imagine that an efficient implementation uses a Dictionary and just returns the <code>Values</code> collection which doesn't implement <code>IList</code>.</p>
|
<p>Definitely an ISomething. Using an interface will reduce coupling and make it easier to change details of your data layer's implementation down the road. Which interface depends on the circumstances. IList is good, but sometimes you may need ICollection functionality or want to specify values that are ReadOnly.</p>
| 24,650
|
<p>I try to migrate a Windows SVN Server to Linux.<br>
I have configured Apache to validate against AD for Useraccess so only AD Users can logon.<br>
Now i have to set permissions for repositories with authz files.<br>
When i set permission with AD username it works, but AD groups it doesn't.</p>
<p>The authz file looks like the following:</p>
<pre><code>[test:/]
user1=rw #That works
[test2:/]
@usergroup=rw #No access for the groupmembers
</code></pre>
<p>When I create groups inside the authz file and asign AD users, that internal group works fine, but i can't administer groups in 2 locations, there just to much changes made every day.</p>
<p>Has anyone an idea, how to use AD groups inside authz files?</p>
|
<p>You can't automatically use AD groups inside the authz files.</p>
<p>A possibile solution could be writing a script that query the AD for the groups and their member users and writes the correct authz file, defining also the groups themselves.</p>
<p>The final output shuold be something like:</p>
<pre><code>[groups]
usergroup = user1, user2, user3
[test:/]
user1 = rw
[test2:/]
usergroup = rw
</code></pre>
|
<p>You can't automatically use AD groups inside the authz files.</p>
<p>A possibile solution could be writing a script that query the AD for the groups and their member users and writes the correct authz file, defining also the groups themselves.</p>
<p>The final output shuold be something like:</p>
<pre><code>[groups]
usergroup = user1, user2, user3
[test:/]
user1 = rw
[test2:/]
usergroup = rw
</code></pre>
| 41,860
|
<p>In situation, when I need a webservice client, which will be used by some action controllers, how should it be implemented? As it will have some constant values (addres, parameters names) and session key, refreshed every 30 minutes, I guess model stored in database isn't the best solution. What is the best practice?</p>
|
<p>Built the web service consumer as a library and place it in your /lib directory.</p>
<p>I would also recommend <a href="http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited" rel="nofollow noreferrer">HTTParty</a> for very simple consumption of web services. You could easily build a library to handle the task, a simple class with a few methods and toss it in your /lib directory and be on your way.</p>
<p>Good luck!</p>
|
<p>Rails 1.x used to have "actionwebservices" builtin but it has been removed from Rails 2.x. The last time I did this was to build an SSO server implemented as classes using XML-RPC. The code is not public unfortunately (done internally for my employer) but was under 1k LOC incl. comments... Plain Ruby.</p>
<p>Now, I'd probably use a lightweight framework like <a href="http://sinatra.rubyforge.org/" rel="nofollow noreferrer">Sinatra</a> or an equivalent.</p>
| 43,911
|
<p>I am looking to use/connect to a different database for one of my controllers and one model. I posted this hear since on the forums of CI I am getting no response.</p>
<p>I added this in database.php:</p>
<pre><code>$db['tdb']['hostname'] = "localhost";//localhost
$db['tdb']['username'] = "username";//root
$db['tdb']['password'] = "password";//empty
$db['tdb']['database'] = "databasename";
$db['tdb']['dbdriver'] = "mysql";
$db['tdb']['dbprefix'] = "";
$db['tdb']['pconnect'] = FALSE;
$db['tdb']['db_debug'] = FALSE;
$db['tdb']['cache_on'] = FALSE;
$db['tdb']['cachedir'] = "";
$db['tdb']['char_set'] = "utf8";
$db['tdb']['dbcollat'] = "utf8_general_ci";
</code></pre>
<p>This as my model:</p>
<pre><code><?php
class Tadmin_model extends Model{
function Tadmin_model(){
parent::Model();
$tdb = $this->load->database('tdb', TRUE);
}
function FInsert($usernames){
$query = $tdb->query("SELECT * FROM following");
return $query->row();
}
}
?>
</code></pre>
<p>And this is the start of my controller:</p>
<pre><code><?php
class Tadmin extends Controller{
function Tradmin(){
parent::Controller();
$this->load->model('tadmin_model');
</code></pre>
<p>And I get this error:</p>
<blockquote>
<p>A PHP Error was encountered</p>
<p>Severity: Notice</p>
<p>Message: Undefined variable: tdb</p>
<p>Filename: models/tadmin_model.php</p>
<p>Line Number: ...</p>
<p>Fatal error: Call to a member function
query() on a non-object in
/blablabla/tadmin_model.php on line
...</p>
</blockquote>
<p>What am I doing wrong here?</p>
|
<p>Your issue here isn't with the use of CodeIgniter's database functions, but with variable scoping in classes. When you load your model you're connecting to the database and assigning the result to a local variable in the model's constructor. When any function finishes, the local variables are discarded. Later you try to call the query() method on the $tdb variable which has already been thrown away and get an error.</p>
<p>You need to store the results of $this->load->database() in a location which is available to both the constructor and the method. You could move the $this->load->database() call into the controller method and connect to the other database every time you call the Tradmin method on your model. </p>
<p>The other way if you wanted to make $tdb available to all methods in the model is to use a member variable on the class, which would look like this....</p>
<pre><code><?php
class Tadmin_model extends Model{
var $tdb;
function Tadmin_model(){
parent::Model();
$this->tdb = $this->load->database('tdb', TRUE);
}
function FInsert($usernames){
$query = $this->tdb->query("SELECT * FROM following");
return $query->row();
}
}
?>
</code></pre>
<p>Hope that helps.</p>
<p>Jim.</p>
|
<p>Have you tried loading $tdb inside the FInsert function? Looks like $tdb may be a local variable and not accessible by FInsert...</p>
| 40,277
|
<p>I am creating a secure web based API that uses HTTPS; however, if I allow the users to configure it (include sending password) using a query string will this also be secure or should I force it to be done via a POST?</p>
|
<p>Yes, it is. <strong>But using GET for sensitive data is a bad idea</strong> for several reasons:</p>
<ul>
<li>Mostly HTTP referrer leakage (an external image in the target page might leak the password[1])</li>
<li>Password will be stored in server logs (which is obviously bad)</li>
<li>History caches in browsers </li>
</ul>
<p>Therefore, even though Querystring is secured it's not recommended to transfer sensitive data over querystring.</p>
<p><em>[1] Although I need to note that RFC states that browser should not send referrers from HTTPS to HTTP. But that doesn't mean a bad 3rd party browser toolbar or an external image/flash from an HTTPS site won't leak it.</em></p>
|
<p>You can send password as MD5 hash param with some salt added. Compare it on the server side for auth.</p>
| 41,828
|
<p>I'm trying to update a variable in APC, and will be many processes trying to do that.</p>
<p>APC doesn't provide locking functionality, so I'm considering using other mechanisms... what I've found so far is mysql's GET_LOCK(), and php's flock(). Anything else worth considering?</p>
<p>Update: I've found sem_acquire, but it seems to be a blocking lock.</p>
|
<pre><code>/*
CLASS ExclusiveLock
Description
==================================================================
This is a pseudo implementation of mutex since php does not have
any thread synchronization objects
This class uses flock() as a base to provide locking functionality.
Lock will be released in following cases
1 - user calls unlock
2 - when this lock object gets deleted
3 - when request or script ends
==================================================================
Usage:
//get the lock
$lock = new ExclusiveLock( "mylock" );
//lock
if( $lock->lock( ) == FALSE )
error("Locking failed");
//--
//Do your work here
//--
//unlock
$lock->unlock();
===================================================================
*/
class ExclusiveLock
{
protected $key = null; //user given value
protected $file = null; //resource to lock
protected $own = FALSE; //have we locked resource
function __construct( $key )
{
$this->key = $key;
//create a new resource or get exisitng with same key
$this->file = fopen("$key.lockfile", 'w+');
}
function __destruct()
{
if( $this->own == TRUE )
$this->unlock( );
}
function lock( )
{
if( !flock($this->file, LOCK_EX | LOCK_NB))
{ //failed
$key = $this->key;
error_log("ExclusiveLock::acquire_lock FAILED to acquire lock [$key]");
return FALSE;
}
ftruncate($this->file, 0); // truncate file
//write something to just help debugging
fwrite( $this->file, "Locked\n");
fflush( $this->file );
$this->own = TRUE;
return TRUE; // success
}
function unlock( )
{
$key = $this->key;
if( $this->own == TRUE )
{
if( !flock($this->file, LOCK_UN) )
{ //failed
error_log("ExclusiveLock::lock FAILED to release lock [$key]");
return FALSE;
}
ftruncate($this->file, 0); // truncate file
//write something to just help debugging
fwrite( $this->file, "Unlocked\n");
fflush( $this->file );
$this->own = FALSE;
}
else
{
error_log("ExclusiveLock::unlock called on [$key] but its not acquired by caller");
}
return TRUE; // success
}
};
</code></pre>
|
<p>What I've found, actually, is that I don't need any locking at all... given what I'm trying to create is a map of all the class => path associations for autoload, it doesn't matter if one process overwrites what the other one has found (it's highly unlikely, if coded properly), because the data will get there eventually anyway. So, the solution turned out to be "no locks".</p>
| 42,203
|
<p>I got this error today when trying to open a Visual Studio 2008 <strong>project</strong> in Visual Studio 2005:</p>
<blockquote>
<p>The imported project "C:\Microsoft.CSharp.targets" was not found.</p>
</blockquote>
|
<p>Open your csproj file in notepad (or notepad++)
Find the line: </p>
<pre><code><Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</code></pre>
<p>and change it to</p>
<pre><code><Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</code></pre>
|
<p>I deleted the obj folder and then the project loaded as expected.</p>
| 2,755
|
<p>I have a problem with a Delphi 2009 project : It can't initialize Indy 10 !
This code worked fine before in Delphi 2007 (although we might have been using an older revision of Indy, but I suspect that has not much to do with it);</p>
<p>The initial call to IdWinsock2.InitializeWinSock(), raises this exception (with error code 998) :</p>
<pre><code>Project EAServer.exe raised exception class EIdWinsockStubError with message
'Error on loading Winsock2 library (WS2\_32.DLL): Invalid access to memory location'.
</code></pre>
<p>But ws2_32.dll is in C:\Windows\System32 allright, with these version details :</p>
<pre><code>File Version : 5.1.2600.5512 (xpsp.080413-0852)
Description : Windows Socket 2.0 32-Bit DLL
Copyright : © Microsoft Corporation. All rights reserved.
</code></pre>
<p>(this shows I'm on WinXP btw).</p>
<p>The silly thing is, that when I look at the process itself (using "Process Explorer"), I can see the process already has this DLL open. The reason "WS2_32.DLL" is already loaded, seems to be because we use the RTL unit Winsock.pas in this project too.
This unit is statically linked to "wsock32.dll", which has a dependancy on WS2_32.DLL, so there.</p>
<p>Does anyone know why this code worked fine before (in Delphi 2007), and now (in Delphi 2009) it suddenly breaks?</p>
<p>And is this inability to re-open the ws2_32 dll common knowledge, or is there really something wrong here? (I did check : I only have 1 version of these DLL's present on my system).</p>
<p>Better yet : Can anyone help me fixing this?</p>
|
<p>I finally found an answer to this : The affected applications contained a bit of code-hooking that randomly damaged parts of System.dcu! (FYI : We're using a Delphi 2009 beta version of madshi's madCodeHook library). As soon as we switched to another code-hooking library, these symptoms disapeared... I guess that's what happens when you use beta-software. Anyway, sorry for bothering you with this. Problem solved!</p>
|
<p>This may be overly simplistic, but have you tried changing the order in which the relevant units are listed in your uses clause? Sometimes this helps in these situations.</p>
| 24,976
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.