instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>I'm using Cura as my slicing/printing software and I just started using the BuildTak printing surface.</p>
<p>The BuildTak is damaged by pushing a hot nozzle into it and my printer's (Robo3D R1+) autoleveling feature works by pushing the nozzle into the build surface.</p>
<p>Is there a way to configure Cura so that it runs the Z probe first, then heat up the nozzle?</p>
<p>My first sheet of BuildTak already has 10 small holes in it (at the homing position and at the 9 leveling touch points)</p>
|
<p>In Cura (and Slic3r), you can 100% customize what the printer does before printing your actual model through custom <strong>start/end g-code</strong>.</p>
<p>If you navigate to the <code>Start/End-GCode tab in Cura</code>, then select <code>start.gcode</code>, you can see what operations are run before each print begins. Lines prefixed with <code>;</code> are comments, and does not affect the printing in any way. </p>
<p>Basically, we want to manually tell the printer to do the auto leveling <em>before</em> heating up the nozzle by editing the g-code in <code>start.gcode</code>.</p>
<h3>G-Code generated with the default start.gcode:</h3>
<p>If you try to slice some model with the default code found in <code>start.gcode</code>, you will get something like the following (depending on your printer):</p>
<pre><code>; CURA AUTOMATICALLY INSERTS THESE TEMPERATURE CODES
M190 S70.000000 ; Set bed temperature to 70 degrees
M109 S210.000000 ; Set nozzle temperature to 210 degrees
; THESE ARE THE CODES FROM START.GCODE (for a ROBO 3D R1)
G28 ;move printer to endstops (the home position)
G92 E0 ;zero the extruded filament length
M565 Z-1 ;set z-probe offset
G1 Z5 F5000 ;move the printer 5mm above the bed
G29 ;run auto-leveling
; THE ACTUAL MODEL BEGINS HERE
;Layer count: 168
;LAYER:0
.
.
</code></pre>
<h3>Analyzing the g-code output</h3>
<p>At the top of this code snippet, we can see that Cura automatically inserts g-code for heating up the bed and nozzle to their respective temperatures with the <a href="http://reprap.org/wiki/G-code#M190:_Wait_for_bed_temperature_to_reach_target_temp" rel="noreferrer">M190</a> and <a href="http://reprap.org/wiki/G-code#M109:_Set_Extruder_Temperature_and_Wait" rel="noreferrer">M109</a> g-codes. This means the printer always will heat up the nozzle before reading the <code>start.gcode</code>s that we set. However, if we manually override <a href="http://reprap.org/wiki/G-code#M109:_Set_Extruder_Temperature_and_Wait" rel="noreferrer">M109</a> code in <code>start.gcode</code>, the <a href="http://reprap.org/wiki/G-code#M109:_Set_Extruder_Temperature_and_Wait" rel="noreferrer">M109</a> at the top will automagically disappear from the generated g-code output! (Thanks, @TomvanderZanden!)</p>
<p>We could therefore use the auto-leveling command <a href="http://reprap.org/wiki/G-code#G29:_Detailed_Z-Probe" rel="noreferrer">G29</a> before manually setting the nozzle temperature with <a href="http://reprap.org/wiki/G-code#M109:_Set_Extruder_Temperature_and_Wait" rel="noreferrer">M109</a>; specifically, we want to add <code>M109 S{print_temperature}</code>, which reads the <code>Basic -> Print Temperature</code>-setting in Cura, and replace <code>{print_temperature}</code> with it automatically.</p>
<h3>Manipulating start.gcode:</h3>
<p>In order to postpone heating the hotend till after probing, <code>start.gcode</code> could be something like: </p>
<pre><code>G28 ;move printer to endstops (the home position)
G92 E0 ;zero the extruded filament length
M565 Z-1 ;set z-probe offset <----- ( YOU HAVE TO ADJUST THIS, READ BELOW)
G1 Z5 F5000 ;move the printer 5mm above the bed
G29 ;run auto-leveling
M109 S{print_temperature} ;set nozzle temperature, and wait for it heat up
</code></pre>
<p>And that's about it! You can then use these codes in your <code>start.gcode</code>. However, you probably will have to recalibrate your z-prove offset. </p>
<h3>Adjust z-probe offset:</h3>
<p>Normally, auto-leveling is done with the nozzle heated for a reason: when the nozzle is warm, it expands slightly, moving closer to the bed. You might therefore have to adjust your Z-probe offset with the <a href="http://reprap.org/wiki/G-code#M565:_Set_Z_probe_offset" rel="noreferrer">M565</a> command (as demonstrated in the snippet) to account for the increase in nozzle length when warm.</p>
<h3>Remember:</h3>
<p>Remember that when editing g-code in this manner, you will take full control of how the printer operates. You could therefore very well do something unintended, so keep the power switch close! </p>
|
<p>As pointed out in <a href="https://3dprinting.stackexchange.com/questions/454/how-to-configure-cura-to-run-the-z-probe-before-heating/469#comment6403_469">Markus's comment</a> to <a href="https://3dprinting.stackexchange.com/a/469/4762">Tormod's answer</a>, <code>{print_temperature}</code> needs to be replaced by <code>{material_print_temperature}</code>, so the code now becomes:</p>
<pre><code>G28 ;move printer to endstops (the home position)
G92 E0 ;zero the extruded filament length
M565 Z-1 ;set z-probe offset <----- ( YOU HAVE TO ADJUST THIS, READ BELOW)
G1 Z5 F5000 ;move the printer 5mm above the bed
G29 ;run auto-leveling
M109 S{material_print_temperature} ;set nozzle temperature, and wait for it heat up
</code></pre>
| 179
|
<p>I am writing an <a href="http://www.eclipse.com" rel="nofollow noreferrer">Eclipse</a> plug-in that loads resources from a central database. I would like to use <a href="http://www.hibernate.org" rel="nofollow noreferrer">Hibernate</a> to access that database. </p>
<p>So how would I add this as a dependency to my plug-in project? I've tried Google but only get hits on about plug-ins for editing Hibernate configuration files.</p>
|
<p>I would create a hibernate plugin, that exposes all the hibernate jar files and exports the classes contained. My configuration and data would then be in another plugin that depends on hibernate.</p>
<p>Then, because hibernate uses reflection like no tomorrow, the Hibernate plug-in needs to be able to load classes from the plug ins that depend on it. To do that you need to use the Eclipse-BuddyPolicy directive. <a href="http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements" rel="nofollow noreferrer">Check this documentation on classloading on eclipse that mentions BuddyPolicy</a></p>
<p>I've set up a Kodo JDO plug-in using this technique and it works quite well. A sample from my Manifest.mf is attached</p>
<pre><code>Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Solarmetric Kodo
Bundle-SymbolicName: com.solarmetric.kodo
Bundle-Activator: com.solarmetric.kodo.KodoPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-AutoStart: true
Eclipse-BuddyPolicy: global
Export-Package: com.solarmetric.ant,
com.solarmetric.apache.commons.collections,
com.solarmetric.apache.commons.collections.buffer,
com.solarmetric.apache.commons.collections.collection,
com.solarmetric.apache.commons.collections.functors,
com.solarmetric.apache.commons.collections.iterators,
com.solarmetric.apache.commons.collections.keyvalue,
</code></pre>
|
<p>You could stick to the standard hibernate tutorials like the documentation provided at hibernate.org or Gaven Kings book, for using hibernate in combination within an eclipse rcp project.</p>
<p>The simplest way would be to include your Hibernate related code and your config in the plugin you currently develop. </p>
<p>Therefore your plugin has to depend on the jar files, each hibernate projects depends on. You could also provide these libs by a separated plugin and simply export them.</p>
<p>But you have to keep in mind that hibernate makes heavy use of reflection and your persistable classes have to be accessible for your persistence manager. </p>
<p>There is also a very good tutorial for integrating hibernate as a separate plugin on <a href="http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html" rel="nofollow noreferrer">http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html</a> but unfortunately it is only in german.</p>
| 46,858
|
<p>Velocity DisplayTool has a useful method:</p>
<pre><code>$display.list($list)
</code></pre>
<p>That will format a collection or array into the form "A, B and C". </p>
<p>The problem is lets say I have an ArrayList of objects, how do I output a specific object field instead of the whole object?
For example the regular loop would look like this:</p>
<pre><code>#foreach($obj in $list)
${obj.title}
#end
</code></pre>
<p>For now I just made obj.toString() to return obj.title, but what if I will need another field?</p>
<p>Thanks.</p>
<p><strong>UPDATE</strong> Ended up implementing this method myself and committing it to DisplayTools. So it is a part of Tools 2.0 now.</p>
|
<p>You might consider extending the DisplayTool to support this. Take a look at the SortTool, it allows you to sort on properties. Copying code from there should give you a good start toward adding this to DisplayTool. And if you do this and feel like sharing, let us know over on the dev@velocity.apache.org list. Heck, if i'm bored some day, i might do this myself.</p>
|
<p>So you want to end up with a formatted string like "title1, title2 and title3", where each element is the title property of a list of, say, Book objects? Two approaches come to mind:</p>
<p>1) Construct the list of titles yourself manually then hand that off to $display.list(). E.g.,:</p>
<pre><code>#set($titles = [])
#foreach($obj in $list)
$titles.add($obj.title)
#end
$display.list($titles)
</code></pre>
<p>2) Create a Velocity macro to retrieve a given property from a list, call that macro on your book list with the title property, then hand that to $display.list(). E.g.: </p>
<pre><code>#macro(retrieveProperty $list $property $newList)
#foreach($obj in $list)
$newList.add(${obj.${property}})
#end
#end
#set($titles = [])
retrieveProperty($list 'title' $titles)
$display.list($titles)
</code></pre>
<p>Hope this helps.</p>
| 43,415
|
<p>Love to hear your opinions and justification?</p>
<p>I've heard deep directories are bad, but how does it compare to underscore characters?</p>
|
<p>In my experience, ER (or UML) diagrams aren't the most useful artifact - with a large number of tables, diagrams (especially reverse engineered ones) are often a big convoluted mess that nobody learns anything from.</p>
<p>For my money, some good human-readable documentation (perhaps supplemented with diagrams of smaller portions of the system) will give you the most mileage. This will include, for each table:</p>
<ul>
<li>Descriptions of what the table means and how it's functionally used (in the UI, etc.)</li>
<li>Descriptions of what each attribute means, if it isn't obvious</li>
<li>Explanations of the relationships (foreign keys) from this table to others, and vice-versa</li>
<li>Explanations of additional constraints and / or triggers</li>
<li>Additional explanation of major views & procs that touch the table, if they're not well documented already</li>
</ul>
<p>With all of the above, don't document for the sake of documenting - documentation that restates the obvious just gets in people's way. Instead, focus on the stuff that confused you at first, and spend a few minutes writing really clear, concise explanations. That'll help you think it through, and it'll <em>massively</em> help other developers who run into these tables for the first time.</p>
<p>As others have mentioned, there are a wide variety of tools to help you manage this, like <a href="http://www.sparxsystems.com.au/" rel="noreferrer">Enterprise Architect</a>, <a href="http://www.red-gate.com/products/SQL_Doc/index.htm" rel="noreferrer">Red Gate SQL Doc</a>, and the built-in tools from various vendors. But while tool support is helpful (and even critical, in bigger databases), doing the hard work of <em>understanding</em> and <em>explaining</em> the conceptual model of the database is the real win. From that perspective, you can even do it in a text file (though doing it in Wiki form would allow several people to collaborate on adding to that documentation incrementally - so, every time someone figures out something, they can add it to the growing body of documentation instantly).</p>
|
<p>Well, a picture tells a thousand words so I would recommend creating ER diagrams where you can view the relationship between tables at a glance, something that is hard to do with a text-only description.</p>
<p>You don't have to do the whole database in one diagram, break it up into sections. We use Visual Paradigm at work but EA is a good alternative as is ERWIN, and no doubt there are lots of others that are just as good.</p>
<p>If you have the patience, then using html to document the tables and columns makes your documentation easier to access.</p>
| 48,226
|
<p>If I want to move to C++ and SDL in the future, is Python and pygame a good way to learn SDL?</p>
|
<p>Python+PyGame is a really great idea for learning SDL.</p>
<p>I wrote a <a href="http://taw.github.io/jrpg" rel="nofollow noreferrer">somewhat popular game that way</a>. Python/PyGame seems much more advanced than SDL bindings to any other language, and one huge advantage compared to C++ is that don't have to compile code, and with some simple hacking can even modify a running program, and see the feedback live. It makes a huge huge difference - like using a GUI vector graphics program vs writing SVG in a text editor. Unfortunately you don't get this out of the box, because you need to adapt your program a bit to see it.</p>
<p>As for other advantages of PyGame, jrpg ran with very small changes on Linux, Windows, and OSX. I had to do some tweaks to fullscreen mode switching, and double buffering as there were some differences between OSes, but no recompilation was ever necessary. If you have any problems you can get good stack trace and debug your problems live, that's not really possible with C++ once you get a memory corruption or a segfault.</p>
<p>I don't really know how easy or how hard would it be to mix C++ and Python for your SDL games. I think it cannot be too hard, as PyGame is a pretty straightforward but very nicely made wrapper for SDL, and Python/C++ mixing is supposed to be easy enough.</p>
|
<p>I wouldn't consider Python (or any managed or interpreted language, for that matter) a good way to learn any complex task, because it insulates the programmer from the workings of the system too much. As a friend of mine put it, "Python loves you and wants you to be happy." And that's all well and good if you already know the fundamentals, but if you want to <em>learn</em>, the last thing you want is a language that does all the work for you.</p>
<p>You'll learn the what very quickly, but not the why, and then when something goes badly wrong, (and it will eventually, in any non-trivial project,) you'll be left with no idea what's happening or why.</p>
| 29,501
|
<p>I notice that there's frequently an aspnet_client folder under the standard IIS web folder structure. What is this used for? Is it needed?</p>
|
<p>In the .NET 1.1 days and before, this folder provided ASP.NET with its JavaScript support for the validation controls and other functionality. If you don't have a .NET 1.1 site or older running it should be safe to delete it. I would rename it first to ensure it doesn't cause any problems.</p>
|
<p>If you are using Installshield to configure ASP.net website, be aware that this feature was present in Installshield 2010 and is missing in Installshield 2012.
<a href="https://i.stack.imgur.com/AfhJk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AfhJk.png" alt="Installshield 2010 Vs 2012"></a></p>
| 25,827
|
<p>In Team Foundation Server, I know that you can use the <strong>Annotate</strong> feature to see who last edited each line in a particular file (equivalent to "Blame" in CVS). What I'd like to do is akin to running Annotate on every file in a project, and get a summary report of all the developers who have edited a file in the project, and how many lines of code they currently "own" in that project.</p>
<p>Aside from systematically running Annotate of each file, I can't see a way to do this. Any ideas that would make this process faster?</p>
<p>PS - I'm doing to this to see how much of a consultant's code still remains in a particular (rather large) project, not to keep tabs on my developers, in case you're worried about my motivation :)</p>
|
<p>It's easy enough to use the "tf.exe history" command recursively across a directory of files in TFS. This will tell you who changed what files.</p>
<p>However what you're after is a little bit more than this - you want to know if the latest versions of any files have lines written by a particular user.</p>
<p>The Team Foundation Power Tools ship with a command-line version of annotate called "tfpt.exe annotate". This has a /noprompt option to direct the output to the console, but it only outputs the changeset id - not the user name.</p>
<p>You could also use the TFS VersionControl object model to write a tool that does exactly what you need.</p>
|
<p>I'm writing an answer to an 8 year old question :). Its not really a full answer, but a suggestion to look into excel reports for TFS.</p>
<p>TFS2013 / 2015 on prem has something has an excel report that can be used to visualize Code Churn. </p>
<p>In VS open team explorer then select "Documents" then explode "Excel Reports". I believe Code Churn report has something like discussed. The report is made by some default project template so I think tfs2013 on prem just creates it.</p>
<p>Code Churn Excel Report VS2015
<a href="https://msdn.microsoft.com/en-us/library/dd695782.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/dd695782.aspx</a></p>
| 10,019
|
<p>I'm having problems deciding on what is the best way is to handle and store time measurements.</p>
<p>I have an app that has a textbox that allows the users to input time in either hh:mm:ss or mm:ss format. </p>
<p>So I was planning on parsing this string, tokenizing it on the colons and creating TimeSpan (or using TimeSpan.Parse() and just adding a "00:" to the mm:ss case) for my business logic. Ok?</p>
<p>How do I store this as in a database though? What would the field type be? DateTime seems wrong. I don't want a time of 00:54:12 to be stored as 1901-01-01 00:54:12 that seems a bit poor?</p>
|
<p>TimeSpan has an Int64 <a href="https://learn.microsoft.com/en-us/dotnet/api/system.timespan.ticks" rel="nofollow noreferrer">Ticks</a> property that you can store instead, and a <a href="https://learn.microsoft.com/en-us/dotnet/api/system.timespan.-ctor#System_TimeSpan__ctor_System_Int64_" rel="nofollow noreferrer">constructor</a> that takes a Ticks value.</p>
|
<p>Most databases have some sort of time interval type. The answer depends on which database you're talking about. For Oracle, it's just a floating point NUMBER that represents the number of days (including fractional days). You can add/subtract that to/from any DATE type and you get the right answer.</p>
| 11,088
|
<p>I would like to know many minutes between 2 dates?</p>
<p>Example : Now - tommorow at the exact time would return me 1440.</p>
|
<pre><code>DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(1);
int diff = dt2.Subtract(dt1).TotalMinutes;
</code></pre>
|
<pre><code>DateTime currentTime = DateTime.Now;
DateTime tommorowTime = currentTime.AddDays(1);
TimeSpan diffTime = tommorowTime - currentTime ;
Console.WriteLine(diffTime.TotalMinutes);
</code></pre>
| 25,853
|
<p>I have a legacy application that is written in C# and it displays a very complex treeview with 10 to 20 thousand elements.</p>
<p>In the past I encountered a similar problem (but in C++) that i solved with the OWNERDATA capability offered by the Win32 API.</p>
<p>Is there a similar mechanism in C#?</p>
<p>EDIT: The plan is to optimize the creation time as well as browsing time. The method available through Win32 API is excellent in both of these cases as it reduce initialization time to nothing and the number of requests for elements are limited to only the ones visible at any one time.
Joshl: We are actually doing exactly what you suggest already, but we still need more efficiency.</p>
|
<p>One technique for improving performance is to load TreeNodes as the user expands the treeview. Normally a user will not require 20,000 nodes to be open on their screen at once. Only load the level that the user needs to see, along with whatever child information you need to properly display affordances to the user (expand icon if children exist, counts, icons, etc). As the user expands nodes, load children just in time.</p>
<p>Helpful hint from Keith: With the winforms TreeView you need to have at least one child node or it won't show the expand [+], but then you handle the TreeNodeExpanded event to remove that dummy node and populate the children.</p>
|
<p>This works for me (CSharp):</p>
<pre><code> Visible = false;
...
Visible = true;
</code></pre>
<p>In my case(2000 nodes), it takes only 1~2 seconds to load the tree, which is much more quicker than any other ways.
It might work well in C++.</p>
| 14,729
|
<p>In FlashPrint there is an <strong>Extrusion Ratio</strong> setting. It's set to 97 % for the stock PLA profile and 107 % for the stock PETG profile.</p>
<p>I would've thought these would be 100 % by default (and the same for all materials). Why is it that these defaults make sense and they differ? Why would you need to push more PETG for the same print than PLA if they're the same diameter filament?</p>
<p><a href="https://i.stack.imgur.com/fiXhW.png" rel="nofollow noreferrer" title="FlashPrint Extrusion Ratio setting"><img src="https://i.stack.imgur.com/fiXhW.png" alt="FlashPrint Extrusion Ratio setting" title="FlashPrint Extrusion Ratio setting" /></a></p>
|
<p>If your extruder uses spring tension to hold the filament against the hob, the effective diameter of the filament at the point the hob contacts, which determines the amount moved, is a function of the compressibility of the material. Thus, it makes sense to use a higher flow ratio for more compressible filaments. However, this is very much a matter of what type of extruder your machine has, and doesn't apply if you have a tension arm holding the idler bearing at fixed distance from the hob.</p>
|
<p>I may be entirely out of my league here, But I think it's related to Viscosity, or how thin or thick the fluid plastic is while hot and Temperature Expansion, how much larger in volume the fluid plastic will be hot compared to cold.</p>
| 2,006
|
<p>I'm trying to convert Matt Berseth's '<a href="http://mattberseth.com/blog/2007/10/yui_style_yesno_confirm_dialog.html" rel="nofollow noreferrer">YUI Style Yes/No Confirm Dialog</a>' so I can use it with the jQuery blockUI plugin.</p>
<p>I have to admit I'm no CSS guru but I thought this would pretty easy even for me....except 10hrs later I'm at a loss as to why I can't get the blasted thing to work. </p>
<p>The problem is that I can't seem to get the 'confirmDialogue' DIV to centre on the page without some artifacts showing above it. Alternatively if I reset blockUI's CSS settings by doing....:</p>
<pre><code>$.blockUI.defaults.css = {};
</code></pre>
<p>.....I find that the DIV aligns left.</p>
<p>I've tried all sorts of stuff but CSS isn't my strong point being a server side app kinda guy :(</p>
<p>So if anyone out there who's a jQuery/blockUI/CSS wizard reading this...please can you have a go and let me know what I'm getting wrong?</p>
<p>Basically I followed the design template on Matt's blog and the HTML looks like the stuff below (the CSS is unchanged from Matt's sample). You can grab the png 'sprite' file from the complete sample project download at <a href="http://mattberseth2.com/downloads/yui_simpledialog.zip" rel="nofollow noreferrer">http://mattberseth2.com/downloads/yui_simpledialog.zip</a> - it's a .net project but I'm just trying to get this to work in a simple html file, so no .NET knowledge required.</p>
<p>Anyway any advice and guidance would be really really really useful. I'll even incentivise things buy promising to buy you lashings of beer if we ever meet :)</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
<script type="text/javascript" src="script/jquery-1.2.6.js"></script>
<script type="text/javascript" src="script/jquery.blockUI.js"></script>
<style>
.modalpopup
{
font-family: arial,helvetica,clean,sans-serif;
font-size: small;
padding: 2px 3px;
display: block;
position: absolute;
}
.container
{
width: 300px;
border: solid 1px #808080;
border-width: 1px 0px;
}
.header
{
background: url(img/sprite.png) repeat-x 0px -200px;
color: #000;
border-color: #808080 #808080 #ccc;
border-style: solid;
border-width: 0px 1px 1px;
padding: 3px 10px;
}
.header .msg
{
font-weight: bold;
}
.body
{
background-color: #f2f2f2;
border-color: #808080;
border-style: solid;
border-width: 0px 1px;
padding-top: 10px;
padding-left: 10px;
padding-bottom: 30px;
}
.body .msg
{
background: url(img/sprite.png) no-repeat 0px -1150px;
float: left;
padding-left: 22px;
}
.footer
{
background-color: #f2f2f2;
border-color: #808080;
border-style: none solid;
border-width: 0px 1px;
text-align:right;
padding-bottom: 8px;
padding-right: 8px;
}
.close
{
right: 7px;
background: url(img/sprite.png) no-repeat 0px -300px;
width: 25px;
cursor: pointer;
position: absolute;
top: 7px;
height: 15px;
}
.modalBackground
{
background-color:Gray;
filter:alpha(opacity=50);
opacity:0.5;
}
</style>
</head>
<body>
<input id="triggerDialogue" name="triggerDialogue" type="button" value="Go" />
<div id="confirmDialogue"
class="modalpopup" style="display:none; text-align: center">
<div class="container">
<div class="header">
<span class="msg">Are you sure?</span>
<a onclick="return false;" class="close"
href="javascript: return false;"></a>
</div>
<div class="body">
<span class="msg">Do you want to continue?</span>
</div>
<div class="footer">
<input type="button" id="Button1" value="Yes" style="width:40px" />
<input type="button" id="Button2" value="No" style="width:40px" />
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#triggerDialogue').click(function() {
$.blockUI({ message: $('#confirmDialogue') });
});
});
</script>
</body>
</html>
</code></pre>
<p>@Owen - many thanks for that. I had to make a wee change in the .modalPopup CSS class in Matt's stylesheet to:</p>
<pre><code>position: fixed;
</code></pre>
<p>....and it works. Much appreciated. I really gotta sit down with my <a href="http://oreilly.com/catalog/9780596527334/" rel="nofollow noreferrer">O'Reilly CSS book</a> which I never get a chance to read some night....:)</p>
|
<p>hmm i'm not that familiar with blockUI, but the basics of centering a div are pretty universal. i'm assuming you want your <code>#confirmDialogue</code> div centered within the whole screen?</p>
<p>if so, you want to do a few things:</p>
<pre><code>#confirmDialogue {
position: fixed; // absolutely position this element on the page
height: 200px; // define your height/width so we can calculate with it after
width: 300px;
}
</code></pre>
<p>now your jQuery:</p>
<pre><code>$('#triggerDialogue').click(function() {
// to position #confirmDialogue, we need the window height/width
var msg = $('#confirmDialogue');
var height = $(window).height();
var width = $(document).width();
msg.css({
'left' : width/2 - (msg.width() / 2), // half width - half element width
'top' : height/2 - (msg.height() / 2), // similar
'z-index' : 15, // make sure element is on top
});
// etc...
});
</code></pre>
<p>basically, you want to fix the position of your <code>#confirmDialogue</code> (so that you can position it relative to the size of your window/document. <code>left</code> and <code>top</code> declarations are calculated based on the elements current height/width, and the window's height and document width.</p>
|
<p>You might find some useful info here. <a href="https://stackoverflow.com/questions/210717/what-is-the-best-way-to-center-a-div-on-the-screen-using-jquery">Using jQuery to center a DIV on the screen</a></p>
| 37,593
|
<p>I am looking for a good Environment (GUI based Editor) for blackberry webapps.
e.g., is there a Eclipse plugin out there ?</p>
|
<p>In my opinion, and experience, using a GUI based editor for any kind of web development is a Very Bad Idea. Get to know HTML and CSS, write your own JavaScript. There isn't a <a href="http://en.wikipedia.org/wiki/WYSIWYG" rel="nofollow noreferrer">WYSIWYG</a> editor out there that can generate markup as good as I can by hand.</p>
<p>Of course, the part were tools come in is testing. And getting to know the paricular inconsistencies of your platform. In that instance, check out:</p>
<ul>
<li><a href="http://na.blackberry.com/eng/developers/browserdev/" rel="nofollow noreferrer">BlackBerry Browser Development</a></li>
</ul>
<p>You'll also want to test, test and test. For that, grab yourself the full range of <a href="http://na.blackberry.com/eng/developers/resources/simulators.jsp" rel="nofollow noreferrer">BlackBerry emulators</a>.</p>
|
<p>The Blackberry Applications are developed in Java and RIM provides the needed tools and simulators here: <a href="http://na.blackberry.com/eng/developers/resources/devtools.jsp" rel="nofollow noreferrer" title="RIM Development Tools">http://na.blackberry.com/eng/developers/resources/devtools.jsp</a></p>
| 40,519
|
<p>We have a Prusa i3 MK2 and we've changed for a print with another colour material but when I pressed "load filament", it didn't make anything. </p>
<p>Often after five times doing that the printer works. I don't have any pictures but the filament is in the hole and the printer holds it. However, it doesn't push it into the extruder and the remains of the old filament do not come out, so I wonder why the motors just stop and don't work. </p>
<p>Sometimes there are no problems - sometimes more and sometimes less. I hope someone has the reason for this problem.</p>
|
<p>My 0.02c:</p>
<ol>
<li>Cut the tip of the new filament at an angle so that it is pointed enough. This will ensure that it easily enters the hole leading into the hot end beneath the extruder drive gear. A lot of times the curl in the filament (from being wound on a spool) will cause misalignment and lead to it not entering this hole properly.</li>
<li>Check filament debris lodged in the extruder gear teeth. Sometimes this will prevent good grip on the filament.</li>
<li>Finally you can try increasing the nozzle temperature. Often times any residue inside the nozzle will be cleared by elevating temperature and pushing in new filament.</li>
</ol>
|
<p>First make sure that the hotend is hot enough.
Second you need to check your extruder if it is clean.
Third try to push the filament by hand and look if it comes out. If yes than the problem should be in the motor.
The motor connection wire could be loose.</p>
| 847
|
<p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p>
<p>I get the following error:</p>
<pre><code>TypeError: __init__() got an unexpected keyword argument 'core'
</code></pre>
<p>[Edit] However, by just removing the core argument I get a "This field is required." error in the admin interface on attempted submission. How does one accomplish what core=False is meant to do using newforms admin?</p>
|
<p>To get rid of "This field is required," you need to make it not required, by using blank=True (and possibly null=True as well, if it's not a CharField).</p>
|
<p>This is simple. I started getting this problems a few revisions ago. Basically, just remove the "core=True" parameter in the ImageField in the models, and then follow the instructions <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects" rel="nofollow noreferrer">here</a> to convert to what the newforms admin uses.</p>
| 5,440
|
<p>when installing SQLServer2005 developer edition (not express) I created a named instance:</p>
<pre><code>MYSERVERNAME/MYINSTANCENAME
</code></pre>
<p>Is it possible to </p>
<p>1) change the name of my named instance to default:</p>
<pre><code>MYSERVERNAME
</code></pre>
<p>OR</p>
<p>2) create a new default instance (MYSERVERNAME as above).</p>
<p>any help would be appreciated!</p>
|
<p>Hm, when I use the "Change" button in Add/Remove Programs, SQL Server 2005 setup offers me the instance selection screen, and even allows me to list the existing instances. (I'm running XP SP2, by the way.)</p>
<p>I selected the "To install a new component, click here" link in the setup program, then selected SQL Server Database Services on the "Components to Install" screen to arrive at the instance selection screen that allows me to install a new default instance.</p>
|
<p>If you have installed a named instance. You cannot change the name to default. You can however:
* make the named instance listen to the default port.
* OR create aliases (with name like MSSQLServer or the IP address, as a trick) to make your clients work.
* If this workaround doesn't help then your best bet is to uninstall SQL Complete and re-install again but chances are that the new installation might take the named instance's name again even if you selected 'default instance'. You can verify this in the SQL services to see if it is still taking the old name.
In this case, the best way (which worked for me) is to install a new instance with the explicit name of MSSQLServer which is known to be the default instance name.</p>
<p>Keep in mind also that SQL takes the computer name and uses it as an alias. </p>
| 33,213
|
<p>This may be a silly question to a graphics guru (which I am not), but what's the difference between affine transformations and keyframing? I'm reading about the former in the iPhone cookbook, and she states that 'Affine transforms enable you to change an object's geometry by mapping that object from one view coordinate system into another'. This reminds me of when I played with Adobe After Effects, and you'd set the start, 'in between', and finishing positions, and would get a nice visual animation. They called it keyframing. So what's the difference this and affine transormations. Is it a 2D vs 3D thing? Thanks all.</p>
|
<p>an affine transform is a linear mapping from one coordinate system to another. if i have an affine transform X, I can take a square "s" and X(s) could return some type of parallelogram. There is no concept of time, just a space-to-different-space mapping.</p>
<p>A Keyframe is a fixed state in space/time. so, you can say, take your square s and perform a transform X at 3 seconds, perform another transform Y at 6 seconds, and interpolate between those. Note that keyframes don't require affine transforms -- you could store keys as non-linear transformations, or even non-matrix transformations (such as character animation in a video game)</p>
|
<p>An affine transformation is a linear transformation followed by a translation. Examples would be:</p>
<ul>
<li>Rotate 45 degrees to the left then shift up 10 pixels</li>
<li>Zoom in by a factor of 2, then move 10 pixels to the right.</li>
<li>Rotate 95 degrees.</li>
</ul>
<p>They are much simpler than keyframing and the like.</p>
| 46,653
|
<p>Due to legacy issues I have two folders under App_Code directory. One for VB.Net and another for C#. Problem is, I have a service in the C# folder that needs to leverage a class in the VB.Net folder but they dont seem to know about each other. Any ideas are welcome :)</p>
<p>Thanks in advance!</p>
<p>Trev</p>
|
<p>I had this same problem and ended up having to move the code to a class library and not use App_Code, so my answer is:</p>
<p>Unless someone has a solution for you, move your code that needs to be seen by both into a separate class library project.</p>
|
<p>Here's one approach: <a href="http://www.aspnetlibrary.com/articledetails.aspx?article=Use-C-Sharp-and-VB.NET-in-the-same-project" rel="nofollow noreferrer">http://www.aspnetlibrary.com/articledetails.aspx?article=Use-C-Sharp-and-VB.NET-in-the-same-project</a>. </p>
<p>See also: <a href="https://stackoverflow.com/questions/196677/can-you-mix-net-languages-within-a-single-project">Can you mix .net languages within a single project?</a>.</p>
<p>If you're already set up as described in the article and the problem is calling one App_Code sub-directory from another, you have to refactor a bit. You mention it's a service calling the other sub-directory. Consider moving the service's code-behind to the same directory as its .asmx. That way, it can use code from anywhere in App_Code. If your service is in the wrong language for the project, you'll have to re-write it.</p>
| 26,525
|
<p>I have found some libraries or web services in PHP that does the job. The problem is that the conversion is done when the page is fully loaded, I would like to <strong>convert the page to PDF</strong> <strong>after some content dynamically added via AJAX</strong> in onload event. </p>
<p>Thank you very much,
Omar</p>
|
<p>You could post back <code>document.getElementsByTagName('html')[0].innerHTML</code> to the server (possibly using AJAX) and generate a PDF from that.</p>
|
<p>This is a client-side requirement due to the Ajax situation. If they're using a Mac they can simply save as PDF but otherwise you have little control over what they can do.</p>
<p>What you can do however for a server-side implementation is keep a record of the page and all their AJAX requests since loading that page, and construct the HTML and PDF on the server from that record if it is requested. Of course this is not a simple task and quite overkill. You'd probably be better off having a different mechanism to create a server-side PDF report of a page other than turning HTML into PDF.</p>
| 23,169
|
<p>I have a project with a formidable data access layer using LinqtoSQL for just about anything touching our databases. I needed to build a helper class that bridges some common crud operations from CLSA objects to LinqToSql ones. Everything has been operating swimmingly until I needed to do a truncate on a table and all I had were “delete” methods.</p>
<p>Uh-oh. A quick search reveals that some people are using YourContext.ExecuteCommand(), which is nice and all, but I am trying to go “t-sql-less” as much as possible these days.</p>
<p>Is there a LINQ way to perform a <a href="http://msdn.microsoft.com/en-us/library/aa260621(SQL.80).aspx" rel="nofollow noreferrer">truncate on a table</a>? Or am I just <a href="http://en.wikipedia.org/wiki/Clueless_(film)" rel="nofollow noreferrer">clueless</a>?</p>
|
<p>This is not possible without doing a custom T-SQL query. Doing a .Delete() and SubmitChanges afterwords would, as you probably already know, result in a DELETE statement.</p>
<p>Of course you could create a stored procedure that truncates the table, and then call the procedure from LINQ, but that isn't really what you're looking for I believe.</p>
|
<p>You can do something like this:</p>
<pre><code>yourDataContext.ExecuteCommand("TRUNCATE TABLE YourTable");
</code></pre>
| 22,917
|
<p>There is this style of exception system where a component throws component-specific exception. For example, all data access classes throw <code>DataAccessException</code>.</p>
<p>In this style, I often find myself having to catch and rethrow the component specific exception, because called methods are delcared as <code>throws Exception</code>:</p>
<pre><code>try {
int foo = foo();
if (foo != expectedValue) {
throw new ComponentException("bad result from foo(): " + foo);
}
bar();
}
catch (ComponentException e) {
throw e;
}
catch (Exception e) {
throw new ComponentException(e);
}
</code></pre>
<p>Do you find yourself doing the same? Do you find it ugly?</p>
<p>This question is not about validity of this style, but something within the constraints of this style.</p>
|
<p>That is ugly as hell. There isn't much more to comment on that ugly style, I think. If you already have all the code to handle different issues using the cause, that'd work. It's just that using </p>
<pre><code>try {
componentCall();
} catch (ComponentException e) {
Throwable t = e.getCause();
//Handle each possible cause
}
</code></pre>
<p>is less maintainable and more confusing than the other way, and the main point is that I see no advantage to using it.</p>
<p>Given that you are restricted to using it, I'd at least try to avoid throwing the ComponentException both with and without a cause, that makes it more confusing than it needs to be, in your example I'd add a InvalidFooException and add it as a cause for the generic ComponentException.</p>
<pre><code>try {
int foo = foo();
if (foo != expectedValue) {
throw new InvalidFooException("bad result from foo(): " + foo);
}
bar();
}
catch (Exception e) {
throw new ComponentException(e);
}
</code></pre>
<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html#getCause()" rel="nofollow noreferrer">getCause()</a> is intended for <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/chained.html" rel="nofollow noreferrer">chains of exceptions</a> that are only causally instead of semantically related. </p>
<p>If you need them to differentiate between different exceptions (for instance, a SQLExecutionException should be corrected by a different action than an AccessDeniedException) then your method is not applicable (because forcing the use of getCause() in each catch to see what needs to be done is awful and offers no benefit than just catching the right exception out front).</p>
<p>If all the calling classes have to do is report an error and cancel, then the wrapping might be okay, but I wouldn't do it, as it adds little benefit and if you later need to differentiate will make you rewrite lots of stuff.</p>
<p>What is useful is to create a <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/creating.html" rel="nofollow noreferrer">hierarchy of exceptions</a> for exception of the same type, in the lines of:</p>
<p>If DataAccessException would be the root, then you could for example have DataSourceUnavailableException, InvalidDataSourceException, InvalidDataException and then you can decide to catch either parent only (if the action is the same) or to catch each exception separately.</p>
<p>Why do you need this to behave this way, by the way?</p>
|
<p>It would maybe less ugly to do so (if the function foo() is the one declared to throw Exception) :</p>
<pre><code>int foo;
try {
foo = foo();
}
catch (Exception e) {
throw new ComponentException(e);
}
if (foo != expectedValue) {
throw new ComponentException("bad result from foo(): " + foo);
}
bar();
</code></pre>
| 25,439
|
<p>Details are as follows:</p>
<p>Environment:</p>
<p>SSRS 2008 Server, SQL Server 2008 for database, Report Developed in SQL Server Business Intelligence Devlopment Studio - Reporting Project</p>
<p>Error Messages: </p>
<p>"An error occurred during client rendering."
"An error has occurred during report processing."
"Query execution failed for dataset 'DataSource1'."
"For more information about this error navigate to the report server on the local server machine, or enable remote errors "</p>
<p>I have done that (navigation & all that) and the result was that a parameter of a scalar variable needs to be declared. The funny thing is that those variables are properly declared in the datasource and in the report sources everywhere. Also this report/datasource worked no problem on SSRS 2005. In the Development Environment the report runs perfectly. On the server the report only fails when executing and after the parameters have been accepted. We use no stored procedures.</p>
<p>Any help / ideas will be greatly appreciated.</p>
<p>Thanks in advance.</p>
|
<p>Did you try to call Form.Refresh() after updating the title?</p>
<p>Edit:</p>
<p>If you are doing the title updates in a loop you might have to do something along the line of:</p>
<pre><code> this.Invalidate();
this.Update();
Application.DoEvents();
</code></pre>
|
<p>I just did a simple test. The changes are quite instantaneous. From the look of it, it's definitely less than 500ms. If you need to update the title at a higher rate, I won't really recommend it. Generally I've seen the fastest update rate of twice per second.</p>
<p>EDIT:
I tested using keypress event. When I hold down the key for a fast repeat, it won't update until I've release my key. Thus, same scenario as your setup. </p>
<p>Btw, why do you need to update every 10ms? Just keep in mind that <code>Thread.Sleep(timeout)</code> with timeout of less than 50ms is not accurate. Also, 10ms timeout will equal to 100Hz, unless you're using high end display, you'll have miss a few frame. Most general LCD have a refresh rate of 60Hz. And our eye can't differentiate anything faster than 25Hz. Thus 40ms delay is more than enough, if you want to animate. Generally I would recommend 15Hz (67ms) for simple animation. If just want to scroll some text, 2Hz is more than enough. Anything faster will make the user dizzy.</p>
| 49,846
|
<p>Is there an easy way to delete an element from an array using PHP, such that <code>foreach ($array)</code> no longer includes that element?</p>
<p>I thought that setting it to <code>null</code> would do it, but apparently it does not work.</p>
|
<p>There are different ways to delete an array element, where some are more useful for some specific tasks than others.</p>
<h2>Deleting a single array element</h2>
<p>If you want to delete just one array element you can use <a href="https://secure.php.net/manual/en/function.unset.php" rel="noreferrer"><code>unset()</code></a> or alternatively <a href="https://secure.php.net/manual/en/function.array-splice.php" rel="noreferrer"><code>\array_splice()</code></a>.</p>
<p>If you know the value and don’t know the key to delete the element you can use <a href="http://php.net/manual/en/function.array-search.php" rel="noreferrer"><code>\array_search()</code></a> to get the key. This only works if the element does not occur more than once, since <code>\array_search</code> returns the first hit only.</p>
<h3><a href="http://php.net/manual/en/function.unset.php" rel="noreferrer"><code>unset()</code></a></h3>
<p>Note that when you use <code>unset()</code> the array keys won’t change. If you want to reindex the keys you can use <a href="http://php.net/manual/en/function.array-values.php" rel="noreferrer"><code>\array_values()</code></a> after <code>unset()</code>, which will convert all keys to numerically enumerated keys starting from 0.</p>
<p>Code:</p>
<pre><code>$array = [0 => "a", 1 => "b", 2 => "c"];
unset($array[1]);
// ↑ Key which you want to delete
</code></pre>
<p>Output:</p>
<pre><code>[
[0] => a
[2] => c
]
</code></pre>
<h3><a href="http://php.net/manual/en/function.array-splice.php" rel="noreferrer"><code>\array_splice()</code></a> method</h3>
<p>If you use <code>\array_splice()</code> the keys will automatically be reindexed, but the associative keys won’t change — as opposed to <code>\array_values()</code>, which will convert all keys to numerical keys.</p>
<p><code>\array_splice()</code> needs the <em>offset</em>, not the <em>key</em>, as the second parameter.</p>
<p>Code:</p>
<pre><code>$array = [0 => "a", 1 => "b", 2 => "c"];
\array_splice($array, 1, 1);
// ↑ Offset which you want to delete
</code></pre>
<p>Output:</p>
<pre><code>[
[0] => a
[1] => c
]
</code></pre>
<p><code>array_splice()</code>, same as <code>unset()</code>, take the array by reference. You don’t assign the return values of those functions back to the array.</p>
<h2>Deleting multiple array elements</h2>
<p>If you want to delete multiple array elements and don’t want to call <code>unset()</code> or <code>\array_splice()</code> multiple times you can use the functions <code>\array_diff()</code> or <code>\array_diff_key()</code> depending on whether you know the values or the keys of the elements which you want to delete.</p>
<h3><a href="http://php.net/manual/en/function.array-diff.php" rel="noreferrer"><code>\array_diff()</code></a> method</h3>
<p>If you know the values of the array elements which you want to delete, then you can use <code>\array_diff()</code>. As before with <code>unset()</code> it won’t change the keys of the array.</p>
<p>Code:</p>
<pre><code>$array = [0 => "a", 1 => "b", 2 => "c", 3 => "c"];
$array = \array_diff($array, ["a", "c"]);
// └────────┘
// Array values which you want to delete
</code></pre>
<p>Output:</p>
<pre><code>[
[1] => b
]
</code></pre>
<h3><a href="http://php.net/manual/en/function.array-diff-key.php" rel="noreferrer"><code>\array_diff_key()</code></a> method</h3>
<p>If you know the keys of the elements which you want to delete, then you want to use <code>\array_diff_key()</code>. You have to make sure you pass the keys as keys in the second parameter and not as values. Keys won’t reindex.</p>
<p>Code:</p>
<pre><code>$array = [0 => "a", 1 => "b", 2 => "c"];
$array = \array_diff_key($array, [0 => "xy", "2" => "xy"]);
// ↑ ↑
// Array keys which you want to delete
</code></pre>
<p>Output:</p>
<pre><code>[
[1] => b
]
</code></pre>
<p>If you want to use <code>unset()</code> or <code>\array_splice()</code> to delete multiple elements with the same value you can use <a href="http://php.net/manual/en/function.array-keys.php" rel="noreferrer"><code>\array_keys()</code></a> to get all the keys for a specific value and then delete all elements.</p>
<h3><a href="https://www.php.net/manual/en/function.array-filter.php" rel="noreferrer"><code>\array_filter()</code></a> method</h3>
<p>If you want to delete all elements with a specific value in the array you can use <code>\array_filter()</code>.</p>
<p>Code:</p>
<pre><code>$array = [0 => "a", 1 => "b", 2 => "c"];
$array = \array_filter($array, static function ($element) {
return $element !== "b";
// ↑
// Array value which you want to delete
});
</code></pre>
<p>Output:</p>
<pre><code>[
[0] => a
[1] => c
]
</code></pre>
|
<p>Yes, there is an easy way to delete an element from an array using PHP. The unset() function can be used to delete an element from an array, and the array_values() function can be used to reindex the array to ensure that the element is no longer included in the array when using the foreach loop.</p>
<p>For example, to delete the element with the key "foo" from an array called $array:</p>
<pre><code>$array = array("foo" => "bar", "baz" => "qux");
// Delete the element with the key "foo"
unset($array["foo"]);
// Reindex the array
$array = array_values($array);
// Use the foreach loop
foreach ($array as $key => $value) {
// Do something with each element
}
</code></pre>
<p>This will ensure that the element with the key "foo" is no longer included in the array when using the foreach loop.</p>
| 48,277
|
<p>Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with id, version and other common properties? Are there any drawbacks?</p>
<p>Example:</p>
<pre><code>@MappedSuperclass()
public class BaseEntity {
private Long id;
private Long version;
...
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
@Version
public Long getVersion() {return version;}
...
// Common properties
@Temporal(TemporalType.TIMESTAMP)
public Date creationDate() {return creationDate;}
...
}
@Entity
public class Customer extends BaseEntity {
private String customerName;
...
}
</code></pre>
|
<p>This works fine for us. As well as the ID and creation date, we also have a modified date. We also have an intermediate <em>TaggedBaseEntity</em> that implements a <em>Taggable</em> interface, because some of our web application's entities have tags, like questions on Stack Overflow.</p>
|
<p>You can find some samples here</p>
<p><a href="http://blogsprajeesh.blogspot.com/2010/01/nhibernate-defining-mappings-part-4.html" rel="nofollow noreferrer">http://blogsprajeesh.blogspot.com/2010/01/nhibernate-defining-mappings-part-4.html</a></p>
| 18,956
|
<p>I have an app that display's the current time when a page opens. I would like that time to update every 30 seconds. I've read about prototype's Ajax.PeriodicalUpdater and it seems to be an answer. This is how I achieve the static time display on page load with php: </p>
<pre><code> <tr>
<td>
<input class="standard" type="text" name="start_time"
value="<?php echo prev_end();?>">
<!--prev_end is last end time from database-->
</td>
<td>
<input class="standard" type="text" name="end_time"
value="<?php echo $now;?>">
<!--$now = date("G:i");-->
</td>
</code></pre>
<p>This is what I've attempted with prototype:</p>
<pre><code><script type="javascript">
new Ajax.PeriodicalUpdater("updater", "unow.php", {frequency : 30});
</script>
...
<tr>
<td>
<input class="standard" type="text" name="start_time"
value="<?php echo prev_end();?>">
</td>
<td>
<input id="updater" class="standard" type="text" name="end_time"
value="">
</td>
</code></pre>
<p>Where "unow.php" does this</p>
<pre><code><?php
$unow=date("G:i");
echo $unow;
?>
</code></pre>
<p>It seems that I don't need a callback to put the value from unow.php into the input "updater" since PeriodicalUpdater calls for an element id. What am I missing?</p>
|
<p>Unless you want your time output to always match the timezone of the server, you could do this very quickly with a bit of Javascript on the client side and skip contacting the server entirely.</p>
<pre><code><html>
<body onload="init();">
<div id=time></div>
</body>
</html>
<script type=text/javascript>
function init()
{
updateTime();
window.setInterval(updateTime,30000);
}
function updateTime()
{
var time = document.getElementById('time');
time.innerText = new Date().toLocaleString();
}
</script>
</code></pre>
|
<p>This can be accomplished without hitting up the server. Prototype's PeriodicalExecuter class encapsulates JavaScript's setInterval function, which allows you to run a JavaScript function every X seconds.</p>
<p><strong>time.html</strong></p>
<pre><code><html>
<head>
<title>Time</title>
<script type="text/javascript" src="time.js">
</head>
<body>
<span id="timeDisplay"></span>
</body>
</html>
</code></pre>
<p><strong>time.js</strong> </p>
<pre><code>document.observe("dom:loaded", function() {
new PeriodicalExecuter(updateTimeDisplay, 30);
});
updateTimeDisplay = function(pe) { // accepts the PeriodicalExecuter instance
var now = new Date();
$('timeDisplay').innerHTML = now.toString();
};
</code></pre>
| 43,907
|
<p>Can an XML attribute be the empty string?</p>
<p>In other words, is</p>
<pre><code><element att="" />
</code></pre>
<p>valid XML?</p>
|
<p>Yes, this is well-formed XML.</p>
<p>An easy way to test this (on Windows) is to save the sample in a <code>test.xml</code> file and open it with Internet Explorer. IE will display an error message if the document is not well-formed.</p>
|
<p>Yes - element content can be empty, and as you used in your question there's even the special Empty-Element tag notation:</p>
<pre><code><elementname />
</code></pre>
<p>Except when interop with SGML is necessary, the above is equivalent to </p>
<pre><code><elementname></elementname>
</code></pre>
<p>Attribute values can also be empty, but attributes must always be followed by an '=' and a quoted string, even if the string contains no characters.</p>
<hr>
<p>The definitive place for this
information is the XML spec:
<a href="http://www.xml.com/axml/testaxml.htm" rel="nofollow noreferrer">http://www.xml.com/axml/testaxml.htm</a></p>
<p>Here's what the Annotated XML Reference has to say about empty elements:</p>
<blockquote>
<p>So, is this: <code><img
src='madonna.gif'></img></code> really
exactly the same as <code><img
src='madonna.gif'/></code>? As far as XML is
concerned, they are. This decision was
the occasion of much religious debate,
with some feeling that there is an
essential element between "point" and
"container" type elements. And as the
"for interoperability" note below
makes clear, if you are using pre-1998
SGML software to process XML, there is
a big difference.</p>
</blockquote>
<p><strong>note:</strong> the discussion on empty elements was due to the original wording of the posted question.</p>
| 22,251
|
<p>Im developing a "desktop" for WM6+ and i was wondering if i can override the draw that WM does when it starts the OS (like the start menu, softkey bar, and background) basically have my program draw the today screen instead of windows. My program will of course integrate everything that the original "screen" integrated.</p>
<p>C++</p>
|
<p>Do you want to implement a today screen "theme" or have the device operate in kiosk mode? The first one is easy - you would need great experience to do the second one.</p>
<p>There are commercial solutions available that will enable you to operate your device in "Kiosk" mode. These aren't cheap though. If you plan to do it yourself, then good knowledge of Windows CE OS is needed - I suggest that you download Platform Builder (I am not sure how they call it now) and have a look at the source code. This is the best way to learn about the internals of the system.</p>
<p>One, not so perfect but easy to implement solution, is to create a full screen application and have it launched at start up. You need also to intercept the hardware keys.</p>
|
<p>You have a few options. You can <a href="http://www.microsoft.com/windowsmobile/en-us/totalaccess/columns/tips-personalize.mspx" rel="nofollow noreferrer">personalize the home screen</a>, which doesn't require code, use a theme generator like the <a href="http://www.ruttensoft.com/Products/HomescreenDesigner/HomescreenDesigner2007/tabid/106/Default.aspx" rel="nofollow noreferrer">one from Ruttensoft</a> (there are others too, so do some searching). The final option is to write your own theme using either the <a href="http://msdn.microsoft.com/en-us/library/aa457653.aspx" rel="nofollow noreferrer">Home Screen API</a> or the <a href="http://msdn.microsoft.com/en-us/library/aa458908.aspx" rel="nofollow noreferrer">Today Screen API</a>, depending on your target device form factor.</p>
| 34,108
|
<p>Can I put my "bin" folder with all of its .dll files at a higher level then the IIS Local Path/web root for the site? I need to keep my dll files in a directory outside of my project is this possible, I tried to use a virtual directory but .net seems to ignore it. </p>
<p>Can I use a virtual directory for my bin folder?</p>
<p><strong>DUPLICATE:</strong> More info provided here: <a href="https://stackoverflow.com/questions/375887/adding-net-code-to-a-classic-asp-website-cant-reference-namespaces-in-dll-file">adding .net code to a classic asp website, can't reference namespaces in .dll file</a></p>
|
<p>No, you cannot. Maybe the GAC will work.</p>
|
<p>You can. You will need to modify the config file for your application to probe the location:</p>
<pre><code><runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="MyCoolNewPath/bin" />
</assemblyBinding>
</runtime>
</code></pre>
| 49,205
|
<p>How can I hide the div without using <code>display:none</code> or JavaScript?</p>
<p>In my country, a lot of Blackberrys come with the CSS support disabled (the mobile companies here are not so good to developers). I have text that says</p>
<pre><code><div class="BBwarn">
please activate your css support and a link
</div>
</code></pre>
<p>I want to hide that once the user activates CSS support, but i can't use <code>display:none;</code> because it is only supported in BB firmware 4.6. It is a public site and I can't make all my visitors upgrade.</p>
<p>Does anybody knows a solution to this? I hope the question is easier to understand now.</p>
<p>Update:
Thank you all for the answers but I can't use </p>
<ul>
<li>position:absolute</li>
<li>overflow</li>
</ul>
<p>because they are available from Blackberry firmware 4.6 and up</p>
|
<p>This is a common way:<br/></p>
<p><code>margin-left: -9999;</code></p>
|
<p>What exactly is wrong with (the earlier mentioned)</p>
<p>width: 0
height:0
visibility: hidden</p>
| 47,432
|
<p>I'm currently in the process of choosing a project for a grad-level compiler course to be done over the next 8 weeks. I'd like to do something related to optimization since I haven't worked much in that area before, but anything in the field is fair game. </p>
<p>What was the most interesting compiler-related project you've done? What did you learn the most from?</p>
<hr>
<p><strong>Edit:</strong> Thank you all for your great suggestions. I apologize for not updating this for so long.</p>
<p>The project I ended up doing was a simple autovectorization optimization on LLVM. LLVM has vector types, but there didn't seem to be any way to take advantage of them without support for the front-end. This optimization converted normal scalar code into vector code.</p>
<p>Since auto-vectorization is a fairly difficult optimization to implement, we limited our scope as much as we could. First, in order to expose instruction level parallelism in the code, we looked for one-block loops that matched our criteria, then unrolled them a specific number of times so they would be conveniently vectorizable. We then implemented the packing algorithm laid out in <a href="http://groups.csail.mit.edu/cag/slp/SLarsen-SM.pdf" rel="noreferrer">Exploiting Superword Level Parallelism with Multimedia Instruction Sets</a> by Larsen and Amarasinghe.</p>
<p>Even a simplified version of this optimization is pretty complicated. There are a lot of constraints; for instance, you don't want to vectorize a variable that lives out of the loop, since the rest of the program expects it to be scalar. We put in a lot of hours in the last few weeks. The project was a lot of fun though, and we learned a lot. </p>
|
<p>If you're interested in optimization, Vectorization of loops using SSE and MMX instruction sets could be interesting.</p>
|
<p>The B::CC perl compiler would benefit from adding and analyzing types. I just don't have enough time for that yet.</p>
<p>Had enough time lately. <a href="http://blogs.perl.org/users/rurban/2011/02/use-types.html" rel="nofollow">http://blogs.perl.org/users/rurban/2011/02/use-types.html</a></p>
| 22,232
|
<p>How can I return the result of a different action or move the user to a different action if there is an error in my <code>ModelState</code> without losing my <code>ModelState</code> information?</p>
<p>The scenario is; <code>Delete</code> action accepts a POST from a DELETE form rendered by my <code>Index</code> Action/View. If there is an error in the <code>Delete</code> I want to move the user back to the <code>Index</code> Action/View and show the errors that are stored by the <code>Delete</code> action in the <code>ViewData.ModelState</code>. How can this be done in ASP.NET MVC?</p>
<pre><code>[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Delete)]
public ActionResult Delete([ModelBinder(typeof(RdfUriBinder))] RdfUri graphUri)
{
if (!ModelState.IsValid)
return Index(); //this needs to be replaced with something that works :)
return RedirectToAction("Index");
}
</code></pre>
|
<p>Store your view data in <code>TempData</code> and retrieve it from there in your <code>Index</code> action, if it exists.</p>
<pre><code> ...
if (!ModelState.IsValid)
TempData["ViewData"] = ViewData;
RedirectToAction( "Index" );
}
public ActionResult Index()
{
if (TempData["ViewData"] != null)
{
ViewData = (ViewDataDictionary)TempData["ViewData"];
}
...
}
</code></pre>
<p>[EDIT] I checked the on-line source for MVC and it appears that the <code>ViewData</code> in the Controller is settable, so it is probably easiest just to transfer all of the <code>ViewData</code>, including the <code>ModelState</code>, to the Index action.</p>
|
<p>Maybe try</p>
<pre><code>return View("Index");
</code></pre>
<p>instead of</p>
<pre><code>return Index();
</code></pre>
| 35,351
|
<p>I use pstack to analyze core dump files in Solaris</p>
<p>How else can I analyze the core dump from solaris?</p>
<p>What commands can be used to do this?</p>
<p>What other information will be available from the dump? </p>
|
<p>You can use Solaris modular debugger,mdb, or dbx. mdb comes with SUNWmdb (or SUNWmdb x for the 64 bits version) package. </p>
<p>A core file is the image of your running process at the time it crashed. </p>
<p>Depending on whether your application was compiled with debug flags or not,you will be able to view an image of the stack, hence to know which function caused the core, to get the value of the parameters that were passed to that function, the value of the variables, the allocated memory zones ... </p>
<p>On recent solaris versions, you can configure what the core file will contain with the coreadm command ; for instance, you can have the mapped memory segments the process were attached to. </p>
<p>Refer to <a href="http://docs.oracle.com/cd/E19082-01/817-2543/" rel="noreferrer">MDB documentation</a> and <a href="http://docs.oracle.com/cd/E19422-01/819-3683/" rel="noreferrer">dbx documentation</a>. The <a href="http://users.ece.utexas.edu/~adnan/gdb-refcard.pdf" rel="noreferrer">GDB quick reference</a> card is also helpful once you know the basics of GDB.</p>
|
<p>GDB can be used.</p>
<p>It can give the call that was attempted prior to the dump. </p>
<p><a href="http://sourceware.org/gdb/" rel="nofollow noreferrer">http://sourceware.org/gdb/</a></p>
<p><a href="http://en.wikipedia.org/wiki/GDB" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/GDB</a></p>
<p>Having the source is great and if you can reproduce the errors even better as you can use this to debug it.</p>
<p>Worked great for me in the past.</p>
| 13,951
|
<p>We are rolling out a site for a client using IIS tomorrow. </p>
<p>I am to take the site down to the general public (Sorry, we are updating message) and allow the client to test over the weekend after we perform the upgrade.</p>
<p>If it is successful, I open it to everbody - if not, I rollback.</p>
<p>What is the easiest way to put a "We're not open" sign for the general public, but leave the rest open to testers?</p>
|
<p>Redirect via IIS. Create a new website in IIS and put your "Sorry updating" message in the Default.aspx. Then switch ports between the real site (will go from 80, to something else (6666)) and the 'maintenance' site (set on 80).</p>
<p>Then tell your testers to go to yoursite.com:6666.</p>
<p>Then switch the real site back to 80 after taking down the 'maintenance' site.</p>
|
<p>We tend to have a log in page and an include file across all pages in the site (usually the DB Connection as it's included in all files) that checks for a valid logged in session. If you've not logged in you get a message saying the site's down for maintainance</p>
| 33,846
|
<p>I have been asked to standardize the screen saver and desktop background used by everyone in my company and, aside from going around to each PC individually, I'm looking for a programmatic way to accomplish this. I am not a systems admin, so have never crossed this bridge before. It is also worth noting that most PCs are running Windows XP, however some are Windows Server 2003 and a few are Vista.</p>
|
<p>Why not just use <a href="http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/prork/prdb_cdk_ugxd.mspx?mfr=true" rel="noreferrer">Group Policies</a>?</p>
|
<p><a href="http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx" rel="noreferrer">Changing screensaver in C#</a></p>
<p><a href="http://www.dotnetspider.com/resources/19517-change-wallpaper-using-vb-net.aspx" rel="noreferrer">Changing desktop in VB.net</a></p>
| 17,600
|
<p><code>String.length</code> will only tell me how many characters are in the String. (In fact, before Ruby 1.9, it will only tell me how many bytes, which is even less useful.)</p>
<p>I'd really like to be able to find out how many 'en' wide a String is. For example:</p>
<pre><code>'foo'.width
# => 3
'moo'.width
# => 3.5 # m's, w's, etc. are wide
'foi'.width
# => 2.5 # i's, j's, etc. are narrow
'foo bar'.width
# => 6.25 # spaces are very narrow
</code></pre>
<p>Even better would be if I could get the first <code>n</code> en of a String:</p>
<pre><code>'foo'[0, 2.en]
# => "fo"
'filial'[0, 3.en]
# => "fili"
'foo bar baz'[0, 4.5en]
# => "foo b"
</code></pre>
<p>And better still would be if I could strategize the whole thing. Some people think a space should be 0.25en, some think it should be 0.33, etc.</p>
|
<p>You should use the RMagick gem to render a "Draw" object using the font you want (you can load .ttf files and such)</p>
<p>The code would look something like this:</p>
<pre><code> the_text = "TheTextYouWantTheWidthOf"
label = Draw.new
label.font = "Vera" #you can also specify a file name... check the rmagick docs to be sure
label.text_antialias(true)
label.font_style=Magick::NormalStyle
label.font_weight=Magick::BoldWeight
label.gravity=Magick::CenterGravity
label.text(0,0,the_text)
metrics = label.get_type_metrics(the_text)
width = metrics.width
height = metrics.height
</code></pre>
<p>You can see it in action in my button maker here: <a href="http://risingcode.com/button/everybodywangchungtonite" rel="noreferrer">http://risingcode.com/button/everybodywangchungtonite</a></p>
|
<p>Once I had to display a string array (containing the coming world days, current namedays, etc) in two lines, putting the linebreak after the appropriate string I had to determine the cumulative widths of the strings, printed in Arial. I opened my word editor, typed the alphabet, and I classified the characters into two classes, based on their width in the given font:</p>
<pre><code>w="023456789AÁBCDEFGHJKLMNOÓÖŐPQRSTUÚÜŰWZYaábcdeghksoóöőpqwuúüűzymn".chars.yield_self{|z| z.zip(Array.new(z.size){1.5})}.to_h.merge("1rfiíjltIÍ ".chars.yield_self{|z| z.zip(Array.new(z.size){1})}.to_h)
w.default=1
nntd=["01-21:A vallások világnapja", "01-19:Kanut", "Kenéz", "Margaréta", "Márió", "Máriusz", "Megyer", "Sára", "Szultána", "Vázsony"]
nntd.sort_by!{|z| z.chars.map{|q| w[q]}.sum}.reverse
</code></pre>
<p>Then I was able to determine the position of the linebreak:</p>
<pre><code>ind=nntd.collect.with_index.find_index{|z,i| nntd[0..i].join.chars.map{|q| w[q]}.sum >=nntd.join.chars.map{|q| w[q]}.sum/2}
t=[nntd[0..ind],nntd[ind+1..-1]].map{|z| z.join(",")}.join("\n")
</code></pre>
<p>After all I got a nice, balanced output, divided into two lines:</p>
<p>01-21:A vallások világnapja,01-19:Margaréta,Szultána
Vázsony,Máriusz,Megyer,Kenéz,Kanut,Márió,Sára</p>
<p><a href="https://i.stack.imgur.com/JKeSS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JKeSS.png" alt="enter image description here" /></a></p>
<p>This way I can check with an eyeblink the incoming world days, and current namedays.</p>
| 49,635
|
<p>There are <strong>two different</strong> ways to create an empty object in JavaScript:</p>
<pre><code>var objectA = {}
var objectB = new Object()
</code></pre>
<p>Is there any difference in how the script engine handles them? Is there any reason to use one over the other?</p>
<p>Similarly it is also possible to create an empty array using different syntax:</p>
<pre><code>var arrayA = []
var arrayB = new Array()
</code></pre>
|
<h2>Objects</h2>
<p>There is no benefit to using <code>new Object();</code> - whereas <code>{};</code> can make your code more compact, and more readable.</p>
<p>For defining empty objects they're technically the same. The <code>{}</code> syntax is shorter, neater (less Java-ish), and allows you to instantly populate the object inline - like so:</p>
<pre><code>var myObject = {
title: 'Frog',
url: '/img/picture.jpg',
width: 300,
height: 200
};
</code></pre>
<h2>Arrays</h2>
<p>For arrays, there's similarly almost no benefit to ever using <code>new Array();</code> over <code>[];</code> - with one minor exception:</p>
<pre><code>var emptyArray = new Array(100);
</code></pre>
<p>creates a 100 item long array with all slots containing <code>undefined</code> - which may be nice/useful in certain situations (such as <code>(new Array(9)).join('Na-Na ') + 'Batman!'</code>).</p>
<h2>My recommendation</h2>
<ol>
<li>Never use <code>new Object();</code> - it's clunkier than <code>{};</code> and looks silly.</li>
<li>Always use <code>[];</code> - except when you need to quickly create an "empty" array with a predefined length.</li>
</ol>
|
<p>This is essentially the same thing. Use whatever you find more convenient.</p>
| 31,307
|
<p>I want to be able to selectively copy a list of files and preserve their directory structure. The problem is that there are quite a few files that their path exceeds 256 character. How is this problem usually handled?</p>
<p>Edit:
I should make it clear that I only want to selectively copy files, not folders. I don't think robocopy can be efficiently used to copy an individual file and it's folder structure effectively.</p>
|
<p>I wrote a VBscript that checks path length and calls <code>subst</code>, as soon as a certain threshold is reached. These calls are stacked on each other so that in the middle of a recursion, this layout exists:</p>
<pre><code>C:\a\very\long\path
subst K: "C:\a\very\long\path"
K:\another\very\long\path
subst L: "K:\another\very\long\path"
L:\yet\another\very\long\path
subst M: "L:\yet\another\very\long\path"
xcopy M:\*.* "D:\target"
</code></pre>
<p>This way with each level of subst, a shorter path is generated. It also means, that you must copy your folders sequentially, to be able check for long paths before you issue the copy command.</p>
<p>Once all files in a folder are copied, the recursion does jump back one level (<code>subst /d</code>), freeing up one drive letter.</p>
<p>Using 4-5 drive letters, that subst each other when the path gets to deep I had been able to copy paths that had lengths waaaaay over the MAX_PATH limit.</p>
<hr>
<p>EDIT</p>
<p>This describes the general procedure of doing it with subst. How you do it depends on your needs, I always used that little subst trick in a minimal, "solves this single problem" way. </p>
<p>For example, copying to an equally deep target path means you need another stack of subst'ed drive letters. </p>
<p>Unpacking all .zip files within a single, deeply nested directory structure may require only on stack, but you need to shorten the threshold a bit to account for folders in the .zip, etc.</p>
|
<p>As Sören suggested, try Robocopy:</p>
<pre><code>robocopy empty_dir base_nested_dir /purge
</code></pre>
| 29,273
|
<p>I have a members table in MySQL</p>
<pre><code>CREATE TABLE `members` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(65) collate utf8_unicode_ci NOT NULL,
`order` tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
</code></pre>
<p>And I would like to let users order the members how they like.
I'm storing the order in <code>order</code> column.</p>
<p>I'm wondering how to insert new user to be added to the bottom of the list.
This is what I have today:</p>
<pre><code>$db->query('insert into members VALUES (0, "new member", 0)');
$lastId = $db->lastInsertId();
$maxOrder = $db->fetchAll('select MAX(`order`) max_order FROM members');
$db->query('update members
SET
`order` = ?
WHERE
id = ?',
array(
$maxOrder[0]['max_order'] + 1,
$lastId
));
</code></pre>
<p>But that's not really precise while when there are several users adding new members at the same time, it might happen the <code>MAX(order)</code> will return the same values.</p>
<p>How do you handle such cases?</p>
|
<p>You can do the SELECT as part of the INSERT, such as:</p>
<pre>INSERT INTO members SELECT 0, "new member", max(`order`)+1 FROM members;</pre>
<p>Keep in mind that you are going to want to have an index on the <code>order</code> column to make the SELECT part optimized. </p>
<p>In addition, you might want to reconsider the tinyint for order, unless you only expect to only have 255 orders ever.</p>
<p>Also order is a reserved word and you will always need to write it as `order`, so you might consider renaming that column as well.</p>
|
<p>I am not sure I understand. If each user wants a different order how will you store individual user preferences in one single field in the "members" table?</p>
<p>Usually you just let users to order based on the natural order of the fields. What is the purpose of the order field?</p>
| 13,033
|
<p>As a "look under the covers" tutorial for myself I am building a PHP script to gather emails from a POP3 mailbox. While attempting to make use of binary attachments I am stuck trying to figure out what to do with the attachment information.</p>
<p>Given a string that would be gathered from an email:</p>
<blockquote>
<p>------=_Part_16735_17392833.1229653992102
Content-Type: image/jpeg; name=trans2.jpg
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fow87t5j0
Content-Disposition: attachment; filename=trans2.jpg</p>
<p>/9j/4AAQSkZJRgABAgEASABIAAD/4QxrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUA
AAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAUAAAAcgEyAAIAAAAUAAAAhodp</p>
<p>(...)</p>
<p>EAgEAgEAgEAgEAg8IBQRL/Lbe/tJrScHqZ2lkmE4XUP2XcSDZZ2VvZ28dtbsDIYmhkbRxAIJCAQC
AQCAQf/ScyAQCAQCAQCAQCAQCAQCAQCAQCAQCAQf/9k=
------=_Part_16735_17392833.1229653992102--</p>
</blockquote>
<p>Is there a way to save off the data to disk so that it would be in a usable format?</p>
|
<p>Pass the data to <a href="http://php.net/base64_decode" rel="noreferrer">base64_decode()</a> to get the binary data, write it out to a file with <a href="http://php.net/file_put_contents" rel="noreferrer">file_put_contents()</a></p>
|
<p>For big base64 strings from a DB you need use load()</p>
<pre><code>$imgdata = $FromDB['BASE64']->load();
$imgdata = base64_decode($imgdata);
file_put_contents($fileName, $imgdata);
</code></pre>
| 49,921
|
<p>I have a Java Applet that uses AWT. In some (rare) circumstances, the platform does not refresh the screen properly. I can move or minimize/maximize the window and see that my applet refreshed properly. I am looking for code that will give me the fullest possible applet screen repaint, simulating the behaviour of a minimize/maximize. </p>
<p>I've tried calling various combinations of paint()/repaint()/invalidate()/update() on the parent containers and recursing on various children. However, no combination (that I've found) cleans up the framework bugs that I am encountering. I am looking for techniques to fully refresh the applet, even if they may cause some slight flickering, as I will be invoking this code only on the problematic platform. </p>
<p>In my tests, moving to Swing did not help resolve my problem. </p>
<p>By the way, this is a simplification of my previous (more complicated) post: <a href="https://stackoverflow.com/questions/184491/java-applet-awt-refresh-problem-mac-os-x-104">Java Applet, AWT Refresh problem Mac OS X 10.4</a> </p>
<p>Edit: Investigation in threading did not solve this problem. Marking best answer as the good one. </p>
|
<p>This happens all the time if you are not programming carefully in AWT/Swing.</p>
<p>First of all, you should do ALL work on the event thread. This means you can't do any of it in your main statement (or anything it calls directly). I know every Java GUI app ever invented violates this rule, but that's the rule.</p>
<p>For the most part, they used to say you could use a non-awt thread until the window was "Realized" (pack/setVisible), but Sun figured out that didn't always work.</p>
<p>Second, when you get an event on the AWT thread, be sure to return it quickly. Never sleep or execute a long operation.</p>
<p>Third, (and this is an extension of "First", if you get a callback that is NOT already on the AWT worker thread, be sure to put it on the AWT thread before doing anything with the GUI.</p>
<p>Generally, any event generated by an AWT component will be on the correct thread. Events generated by timers, manually created threads, or the one handed to main() are not.</p>
|
<p>I was able to fix 99% of my AWT Applet redraw issues by switching to Swing. Swing seems to be more reliable on refreshing. </p>
<p>Earlier I had a lot of manual repaints() in my applet code, but with Swing these were removed and applet is now faster especially under Terminal Server / LTSP.</p>
<p>I placed critical stuff inside this:</p>
<pre><code>public class VeryFastPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public void update(Graphics g) {
paint(g);
}
}
</code></pre>
| 24,278
|
<p>ok so basically I am asking the question of their name
I want this to be one input rather than Forename and Surname.</p>
<p>Now is there any way of splitting this name? and taking just the last word from the "Sentence" e.g.</p>
<pre><code>name = "Thomas Winter"
print name.split()
</code></pre>
<p>and what would be output is just "Winter"</p>
|
<p>You'll find that your key problem with this approach isn't a technical one, but a human one - different people write their names in different ways.</p>
<p>In fact, the terminology of "forename" and "surname" is itself flawed.</p>
<p>While many blended families use a hyphenated family name, such as Smith-Jones, there are some who just use both names separately, "Smith Jones" where both names are the family name.</p>
<p>Many european family names have multiple parts, such as "de Vere" and "van den Neiulaar". Sometimes these extras have important family history - for example, a prefix awarded by a king hundreds of years ago.</p>
<p>Side issue: I've capitalised these correctly for the people I'm referencing - "de" and "van den" don't get captial letters for some families, but do for others. </p>
<p>Conversely, many Asian cultures put the family name first, because the family is considered more important than the individual.</p>
<p>Last point - some people place great store in being "Junior" or "Senior" or "III" - and your code shouldn't treat those as the family name.</p>
<p>Also noting that there are a fair number of people who use a name that isn't the one bestowed by their parents, I've used the following scheme with some success:</p>
<p>Full Name (as normally written for addressing mail);
Family Name;
Known As (the name commonly used in conversation).</p>
<p>e.g:</p>
<p>Full Name: William Gates III; Family Name: Gates; Known As: Bill</p>
<p>Full Name: Soong Li; Family Name: Soong; Known As: Lisa</p>
|
<p>You would probably want to use rsplit for this:</p>
<pre><code>rsplit([sep [,maxsplit]])
</code></pre>
<p>Return a list of the words in the string, using <code>sep</code> as the delimiter string. If <code>maxsplit</code> is given, at most <code>maxsplit</code> splits are done, the rightmost ones. If <code>sep</code> is not specified or <code>None</code>, any whitespace string is a separator. Except for splitting from the right, <code>rsplit()</code> behaves like <code>split()</code> which is described in detail below. New in version 2.4. </p>
| 32,443
|
<p>I can't think of many reasons (or any at all) in which multiple independent user interfaces should be instantiated in a desktop application. Is it good practice to implement the UI as a singleton? Are there are advantages or disadvantages to this approach?</p>
|
<p>uh...i open multiple copies of Internet Explorer, Word, and Excel all the time!</p>
<p>EDIT: I also have several emails open at once in Eudora</p>
<p>I see no good reason to restrict a user-interface to a singleton...</p>
|
<p>What advantage does a singleton give you? Are you aware of the potential problems of this pattern (e.g. multithreading issues with all obvious implementations)?</p>
<p>In practice, if there's no compelling reason to use it, you might want to avoid using the Singleton. For the UI, there isn't actually a compelling reason even if it doesn't get instantiated multiple times.</p>
| 31,361
|
<p>I have a windows application running at the backend. I have functions in this applications mapped to hot keys. Like if I put a message box into this function and give hot key as <kbd>Alt</kbd>+<kbd>Ctrl</kbd>+<kbd>D</kbd>. then on pressing <kbd>Alt</kbd>, <kbd>Ctrl</kbd> and <kbd>D</kbd> together the message box comes up. My application is working fine till this point. </p>
<p>Now I want to write a code inside this function so that when I am using another application like notepad, I select a particular line of text and press the hot key <kbd>Alt</kbd> + <kbd>Ctrl</kbd> + <kbd>D</kbd> it is supposed to copy the selected text append it with "_copied" and paste it back to notepad. </p>
<p>Anyone who has tried a similar application please help me with your valuable inputs.</p>
|
<p>Your question has two answers</p>
<h2>How can my app set a global hotkey</h2>
<p>You have to call an API funcion called RegisterHotKey</p>
<pre><code>BOOL RegisterHotKey(
HWND hWnd, // window to receive hot-key notification
int id, // identifier of hot key
UINT fsModifiers, // key-modifier flags
UINT vk // virtual-key code
);
</code></pre>
<p>More info here: <a href="http://www.codeproject.com/KB/system/nishhotkeys01.aspx" rel="noreferrer">http://www.codeproject.com/KB/system/nishhotkeys01.aspx</a></p>
<h2>How to get the selected text from the foreground window</h2>
<p>Easiest way is to send crl-C to the window and then capture the clipboard content.</p>
<pre><code>[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
.....
private void SendCtrlC(IntPtr hWnd)
{
uint KEYEVENTF_KEYUP = 2;
byte VK_CONTROL = 0x11;
SetForegroundWindow(hWnd);
keybd_event(VK_CONTROL,0,0,0);
keybd_event (0x43, 0, 0, 0 ); //Send the C key (43 is "C")
keybd_event (0x43, 0, KEYEVENTF_KEYUP, 0);
keybd_event (VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up
}
</code></pre>
<p>Disclaimer: Code by Marcus Peters from here: <a href="http://bytes.com/forum/post1029553-5.html" rel="noreferrer">http://bytes.com/forum/post1029553-5.html</a><br>
Posted here for your convenience.</p>
|
<p>I think you can use <a href="http://msdn.microsoft.com/en-us/library/ms646310.aspx" rel="nofollow noreferrer" title="SendInput">SendInput</a> function to send the text to the target window or just the command to paste it if you have put it in clipboard before.</p>
| 29,202
|
<p>Can anyone point me to the preferences page that has the setting of the <strong>DEBUG</strong> current line background color? I have changed almost all the colours to dark ones and still get annoyed by this almost white current line indicator while debugging (note that the current line indication in editing mode is OK).</p>
|
<p>Ok, now I found it myself (through major reverse engineering). It is in General\Editors\Text Editors\Annotations page. It's called "Debug Current Instruction Pointer"</p>
|
<p>Because Eclipse change stuff more than they change clothes</p>
<p>As of Eclipse for Java EE 2019-09 , took me 30 min just to find this stupid preferences</p>
<p><a href="https://i.stack.imgur.com/5zC9x.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5zC9x.png" alt="enter image description here"></a></p>
<p>Than go to </p>
<p><a href="https://i.stack.imgur.com/dWvMk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dWvMk.png" alt="enter image description here"></a></p>
| 25,994
|
<p>I can create the following and reference it using</p>
<pre><code>area[0].states[0]
area[0].cities[0]
var area = [
{
"State" : "Texas",
"Cities" : ['Austin','Dallas','San Antonio']
},
{
"State" :"Arkansas",
"Cities" : ['Little Rock','Texarkana','Hot Springs']
}
] ;
</code></pre>
<p>How could I restructure "area" so that if I know the name of the state, I can use it in a reference to get the array of cities?</p>
<p>Thanks</p>
<p><strong>EDIT</strong> Attempting to implement with the answers I received (thanks @Eli Courtwright, @17 of 26, and @JasonBunting) I realize my question was incomplete. I need to loop through "area" the first time referencing "state" by index, then when I have the selection of the "state", I need to loop back through a structure using the value of "state" to get the associated "cities". I do want to start with the above structure (although I am free to build it how I want) and I don't mind a conversion similar to @eli's answer (although I was not able to get that conversion to work). Should have been more complete in first question. Trying to implement 2 select boxes where the selection from the first populates the second...I will load this array structure in a js file when the page loads.</p>
|
<p>If you want to just create it that way to begin with, just say</p>
<pre><code>area = {
"Texas": ['Austin','Dallas','San Antonio']
}
</code></pre>
<p>and so on. If you're asking how to take an existing object and convert it into this, just say</p>
<pre><code>states = {}
for(var j=0; j<area.length; j++)
states[ area[0].State ] = area[0].Cities
</code></pre>
<p>After running the above code, you could say</p>
<pre><code>states["Texas"]
</code></pre>
<p>which would return</p>
<pre><code>['Austin','Dallas','San Antonio']
</code></pre>
|
<p>This would give you the array of cities based on knowing the state's name:</p>
<pre><code>var area = {
"Texas" : ["Austin","Dallas","San Antonio"],
"Arkansas" : ["Little Rock","Texarkana","Hot Springs"]
};
// area["Texas"] would return ["Austin","Dallas","San Antonio"]
</code></pre>
| 8,179
|
<p>Is there any way to see an overview of what kind of queries are spent the most time on every day on MySQL?</p>
|
<p>Yes, mysql can create a slow query log. You'll need to start <code>mysqld</code> with the <code>--log-slow-queries</code> flag:</p>
<pre><code>mysqld --log-slow-queries=/path/to/your.log
</code></pre>
<p>Then you can parse the log using <code>mysqldumpslow</code>:</p>
<pre><code>mysqldumpslow /path/to/your.log
</code></pre>
<p>More info is here (<a href="http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html</a>).</p>
|
<p>You can always set up query logging as described here:<br>
<a href="http://dev.mysql.com/doc/refman/5.0/en/query-log.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/query-log.html</a></p>
| 17,687
|
<p>I'm refactoring some code I inherited from a long-gone developer, and I find this:</p>
<pre><code>ImportExportForm l_Form = new ImportExportForm();
l_Form.InitializeLifetimeService();
l_Form.ShowDialog();
</code></pre>
<p>I've never seen or used the LifetimeService before, but from the little I've read, I don't understand why I would want to use it here, but before saying WTF, I wondered if I might be missing some subtle detail?</p>
|
<p>As far as I know this is a method normally use for Remote .Net Objects, and to establish the lifetime of an instance. Look here:</p>
<p><a href="http://msdn.microsoft.com/es-es/magazine/cc300474(en-us).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/es-es/magazine/cc300474(en-us).aspx</a></p>
<p>I don't think that it's important for normal Windows Form.</p>
|
<p>True, it is used for .Net remoting, like WCF. Except if your object ImportExportForm is loading something remotely, i don't see any reason to use this. See there: <a href="http://msdn.microsoft.com/en-us/library/23bk23zc(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/23bk23zc(v=vs.100).aspx</a> </p>
| 42,107
|
<p>I'm trying to create a pimped-out version of the slider that has a user control in the "thumb"-part (meaning: the moving thingy on the slider) that reacts to the slider's movements. Basically my current demo / development version is just a UserControl with 5 visual states that just make it change a smiley face to an angry face in 5 phases. I'd like to put that user control into the thumb.</p>
<p>My only problem is as follows: I can get the UserControl into the thumb no problem, by editing the Slider-control's template in Expression Blend. However, once the UserControl is in the ControlTemplate, it's no longer visible to the new user control class and thus is not changeable with VisualStateManager.</p>
<p>So basically, my question is two-fold:</p>
<ol>
<li><p>Is there any better way to replace the thumb of the Slider-control than editing it's template?</p></li>
<li><p>If not, how can I access stuff I've added to the template?</p></li>
</ol>
<p>Thanks for any answers! </p>
|
<p>I'm answering myself. After visiting every single page on the internet, I finally figured out a solution by myself!</p>
<p>I added a Loaded-event handler to my control in the ControlTemplate and in that event handler I took the reference to that control for the actual class! After that I was able to refer to that control with that reference and for example visualstate changes worked like a charm!</p>
<p>I've now got a hopped-up slider that has a smiley in the handle part and the face on the smiley changes in relation to the position of the slider! Pretty cool!</p>
|
<p>I worked it from a different angle:
You can override the OnApplyTemplate() and get your reference with the GetTemplateChild methode. It somehow feels cleaner</p>
| 40,523
|
<p>I'm trying to find a good way to detect a loss of connection. </p>
<p>My adapter is implemented as a Fix::Application based on one of the examples. It uses a socket initiator to connect to the fix gateway. </p>
<p>When I unplug the internet it takes about 30 seconds for the Fix::Application's onLogout method to be fired. It seems like some underlying class would be aware that there is a problem with the socket much earlier. Is there a quick way took hook into this?</p>
|
<p>The best way to solve this would probably be to decrease your Heartbeat Interval so you know sooner. I don't know of any messages that fire for a loss of TCP connection, but I don't think QuickFix is listening for OS events either. Although, it would likely flow through the fromAdmin event if there were such a message. </p>
<p>Did you post your question to the QuickFix DL?</p>
|
<p>It's possible that the fix engine you're using doesn't call back when TCP is disconnected, or it calls back on something other than onLogout.
Since you're using fix, I would guess it forces a logout due to missed heartbeats.</p>
<p>Quick way would be to look into the code and check where socket close is being handled, and what path executes when this happens.</p>
| 40,764
|
<p>I made a simple logo using Inkscape, after saving as an svg file, but when I export that file into Fusion 360 something strange happened.</p>
<p>Multiple times I convert some images (png, svg) to svg file. The process I use is this:</p>
<ol>
<li>Scan logo image (scanner or smartphone)</li>
<li>Open image with Inkscape</li>
<li>Using the stroke, generate the shape</li>
<li>All process for generate and save</li>
</ol>
<p>This process explained above always works for me, when I copy the shape using the <em>stroke</em> in Inkscape.</p>
<p>However, when I was do the process using the <em>shape generator</em> - for example, rectangles, circles, squares, etc. - and export the file into the Fusion 360, it doesn't work.</p>
<h3>1 - Inkscape logo</h3>
<p><a href="https://i.stack.imgur.com/eA3Wz.png" rel="nofollow noreferrer" title="Inkscape"><img src="https://i.stack.imgur.com/eA3Wz.png" alt="inkscape" title="Inkscape" /></a></p>
<h3>2 - Logo import to Fusion 360</h3>
<p><a href="https://i.stack.imgur.com/9vskK.png" rel="nofollow noreferrer" title="Import into Fusion 360"><img src="https://i.stack.imgur.com/9vskK.png" alt="Import into Fusion 360" title="Import into Fusion 360" /></a></p>
<p>In the example above, the first word does not appear.</p>
|
<h1>read first</h1>
<p>When you use painters tape, you need to level your printer <strong>with</strong> the tape applied. You need to relevel if you change the tape type.</p>
<h1>Basics</h1>
<p>It's not <em>any</em> blue tape that printers love. There are basically two factors that make a tape useful:</p>
<ul>
<li>It has to stick during printing.</li>
<li>Its surface has to allow the filament to stick to it.</li>
</ul>
<p>Let's look at some <a href="https://www.youtube.com/watch?time_continue=2&v=GIEaOdKVCO8" rel="nofollow noreferrer">different tapes</a> and their suitability - from my own experience.</p>
<h2>ScotchBlue</h2>
<p>The <em>original</em> blue tape is actually <a href="https://www.scotchblue.com/3M/en_US/scotchblue/" rel="nofollow noreferrer">ScotchBlue</a> for delicate surfaces by 3M. It has a good surface to stick to and at the same time an adhesive that does not degrade to unsuitability by heating. The delicate surface one is just as good as the all surfaces type. But don't use the outdoor type, it is sealed too much.</p>
<h2>FrogTape</h2>
<p><a href="https://www.frogtape.com/" rel="nofollow noreferrer">FrogTape</a> has an adhesive that has no problems with heating, the surface is sometimes a little smoother. Its green variant is about as useful as ScotchBlue, while the yellow variant is easier to remove - which can be an issue when the printhead is not calibrated correctly.</p>
<h2>Generic painters tape</h2>
<p><em>Generic</em> painters tape is a can of worms - there are so many different ones it is hard to describe. I have had very good off-yellow rolls from the dollar store of the 'fine surface' type - as in the tape had a fine surface - and their adhesive was good and didn't degrade too much under heat. The followup roll was a little thinner of material and released under heat so it can be a hit and miss - it's ok for starting out though.</p>
<p>I also tried a roll of UHU painters tape of the <em>easy remove</em> type and it was <em>horrible</em>, as it didn't want to stick after the nozzle went over it once even on an unheated bed.</p>
<h2>Generic blue colored tape</h2>
<p>I even tried two blue colored tapes from different dollar/hobby stores. One was ok-ish and had a similar result as the good dollar store tape in look, but left a blue shadow on the base of the print after two or three prints. The other was showing similar behavior to other mild-adhesive/easy peel tapes.</p>
<h2>Conclusion</h2>
<p>It's not <em>color</em> that matters, it is the <em>formulation</em>. If you must use blue tape, spend the extra bucks for quality. Some bloggers <a href="https://3dprinting-blog.com/61-trying-out-different-kinds-of-tapes-for-3d-printing-on/" rel="nofollow noreferrer">compared other tapes</a>, tested <a href="http://www.3dprinterprices.net/kapton-tape-vs-blue-painters-tape/" rel="nofollow noreferrer">ScotchBlue vs Kapton</a>, <a href="https://all3dp.com/2/3d-printer-tape-the-best-tape-for-better-adhesion/" rel="nofollow noreferrer">discussed the benefits of either</a>, <a href="http://www.desiquintans.com/bluetape" rel="nofollow noreferrer">discussed the ScotchBlue tape in depth</a>.</p>
<p>While in general, I prefer to print on the surface of my (blue) BuildTak (clone), I occasionally whip out painters tape on an unheated surface for very delicate prints: I remove the print together with the tape from the surface, which allows better handling. Sacrificing a layer of tape only costs some cents after all while breaking a print is hours and filament for much more money wasted.</p>
|
<p>The second image isn't exactly painter's tape. Both images are types of masking tape, but the common manila/cream-colored masking tape vs the blue or green painter's tape <em>typically</em> has three features that make it less desirable for bed adhesion:</p>
<ol>
<li>Stronger glue holding the tape to the bed, that will make it harder to change later.</li>
<li>Narrower strips, so it's harder and takes longer to place the tape on the bed.</li>
<li>Thicker, softer material. This is <em>good</em> for filament adhesion, but bad for separating from the filament after the print and accurately leveling the bed.</li>
</ol>
<p>Again: those are only typical arrangements. You can get blue painters tape at the same narrow width as manila masking tape, and you can get wider or thin manila tape. It's more a matter of what you'll commonly find for sale, and in all probability the manila/cream-colored tape will work just fine.</p>
| 1,319
|
<p>Instead of hardcoding the default @author template I would like Eclipse to use user's real name taken from account information (in Linux - but Windows solution is also welcome). Entering it somewhere into Eclipse configuration would be acceptable, too, alas I can't find the right place.</p>
|
<p>It seems that your best bet is to redefine the java <code>user.name</code> variable either at your command line, or using the <code>eclipse.ini</code> file in your eclipse install root directory.</p>
<p>This seems to work fine for me:</p>
<pre><code>-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Duser.name=Davide Inglima
-Xms40m
-Xmx512m
</code></pre>
<hr />
<h3>Update:</h3>
<p><a href="http://morlhon.net/blog/2005/09/07/eclipse-username/" rel="noreferrer">http://morlhon.net/blog/2005/09/07/eclipse-username/</a> is a dead link...</p>
<p>Here's a new one: <a href="https://web.archive.org/web/20111225025454/http://morlhon.net:80/blog/2005/09/07/eclipse-username/" rel="noreferrer">https://web.archive.org/web/20111225025454/http://morlhon.net:80/blog/2005/09/07/eclipse-username/</a></p>
|
<p>just other option. goto <strong><em>PREFERENCES >> JAVA >> EDITOR >> TEMPLATES</em></strong>, Select @author and change the variable ${user}.</p>
| 30,548
|
<p>I have a table which is referenced by foreign keys on many other tables. In my program if I want to delete one of these rows I need to first search for dependencies and present them to the user - "This object depends on x from table y, z from table q, etc". I also expect the number of tables which have foreign keys to this table to grow considerably over time. </p>
<p>Is the information_schema database a good way to do a search for all dependencies? I tried to query it to retrieve a list of all tables which have foreign keys to my table, then iterate over the result and select all entries from each table where the foreign key value matches the value the user is trying to delete. The query I have is as follows:</p>
<pre><code>SELECT * FROM `KEY_COLUMN_USAGE` kcu
LEFT JOIN TABLE_CONSTRAINTS tc
ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
WHERE tc.CONSTRAINT_TYPE='FOREIGN KEY'
AND (kcu.REFERENCED_TABLE_SCHEMA='db')
AND (kcu.REFERENCED_TABLE_NAME = 'testtable')
</code></pre>
<p>which works perfectly for determining the tables which I need to search, however it is <em>very</em> slow. The query takes around 1 to 2 seconds at best to execute on my development machine, which will reduce a lot when I run it on my production server, but will still be quite slow.</p>
<p>I need to know if it's a bad idea to use information_schema in this way. If not, how I can extract better performance from the query. Is the query I'm using solid or is there a better way to do it? If so, how best should I tackle this problem from a maintainability perspective.</p>
|
<p>Dvorak is right, INFORMATION_SCHEMA is intended for that.</p>
<p>Concerning your performance concerns, there are several ways you can improve the performance</p>
<ul>
<li><p>Easy way, but not much improvement will come from it:
Store the info in a static variable. At least the query will occur only once per page</p></li>
<li><p>Use persistent caching : The alternative PHP cache can help you (see <a href="http://fr3.php.net/manual/en/book.apc.php" rel="nofollow noreferrer">http://fr3.php.net/manual/en/book.apc.php</a>).
The info you'll get from the information schema is a good candidate to store in a persistent cache.</p></li>
<li><p>Use a ORM library, such as doctrine (<a href="http://www.doctrine-project.org/" rel="nofollow noreferrer">http://www.doctrine-project.org/</a>)
A look at the file lib/Doctrine/Import/Mysql.php will show that it does exactly what you need, and much more.</p></li>
</ul>
|
<p>Slows my applications to a crawl, but I need the foreign key constraint data to get everything hooked together properly.</p>
<p>The delays are huge when querying information schema, and make a page that used to load instantly, load in 3-4 seconds.</p>
<p>Well, at least foreign key constraints are available in MySQL 5, that makes for more robust application development, but obviously at a cost.</p>
<p>People have been complaining about this issue since 2006 based on my Google searches, and the problem remains -- must not be an easy fix ;--(</p>
| 13,628
|
<p>I have a form I am submitting using jQuery's ajaxSubmit function from the Forms plugin. I'm trying to add a form name/value pair to the form data just before submission occurs. My plan is to modify the form data in the beforeSubmit event handler.</p>
<p>Given a function that looks like:</p>
<pre><code>function handleActionFormBeforeSubmit(formData, form, options) {
// Add a name/value pair here somehow to formData
}
</code></pre>
<p>How do I add a simple pair to formData? It is an array in the form of:</p>
<pre><code>[ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
</code></pre>
<p>Thanks,
Brian</p>
|
<p>After an hour of experimentation, I figured out a solution. To append a value to the form data, the following code will work.</p>
<pre><code>function handleActionFormBeforeSubmit(formData, form, options) {
// Add a name/value pair indicating this is an asynchronous call.
// This works with the ASP.NET MVC framework's Request.IsMvcAjaxRequest() method.
formData[formData.length] = { "name": "__MVCASYNCPOST", "value": "true" };
}
</code></pre>
<p>You can also modify the data if you know the index of the value you want to change such as:</p>
<pre><code>formData[0].value = 'new value';
</code></pre>
<p>I hope this helps someone else.</p>
|
<p>For some reason changing the data in the beforeSubmit callback didn't work for me when I encountered this problem. </p>
<p>However assigning an object to "data" in the form options caused this object to be appended to the serialised data. This is not documented explicitly on the jquery form website but is part of the underlying $.ajax method.</p>
| 30,714
|
<p>(Warning - asp newbie) I have an aspx file with the tag</p>
<pre><code> <%@ Page Language=VB ... %>
</code></pre>
<p>right at the beginning of the file.</p>
<p>When calling this from my IIS server (<a href="http://localhost/myservice/default.aspx" rel="noreferrer">http://localhost/myservice/default.aspx</a>), this gives me the error </p>
<blockquote>
<p>This page contains the following
errors: </p>
<p>error on line 1 at column 2:
StartTag: invalid element name<br>
Below is a rendering of the page up to
the first error.</p>
</blockquote>
<p>What am I doing wrong?</p>
|
<p>It appears as if the browser tries to display what it thinks is an XML file, since it gives an error on the second character of the first line. So I think the file is not parsed, but simply returned as is immediately. Check if your IIS server is configured correctly and that it actually parses your ASP tags before returning the page.</p>
|
<p>For me, the problem was in the serialization that responded to client.</p>
<p>My problem was in the xml tags spaces:</p>
<pre><code> - < tag > text < / tag > ---> wrong
- <tag> text </tag> ----> good.
</code></pre>
| 35,549
|
<p>The question is how to scale an existing mesh without changing the thickness of the walls? </p>
<p>I am using Blender to create STL files for 3D printing. Let's say I create a shell for a model railroad car. Since 1/87th is the most common scale I make the walls of the shell just thick enough to make it rigid in 1/87 scale. Now, if I want to print the same shell in a larger scale, say 1/48, the wall thickness will nearly double and it will waste material printing walls that are thicker than needed. If I want to print in 1/160 the printing may fail because the wall thickness falls below the minimum the printer will support. </p>
<p>Any ideas?</p>
|
<p>Your question falls into two different categories, here at 3D Printing SE and there, at <a href="https://blender.stackexchange.com/">Blender SE</a>. </p>
<p>I would consider that your objective would best be solved using some form of parametric modeling, an aspect that is rarely embraced by Blender. Even though the limitations of Blender make life interesting for you, there may be a couple of useful features within (and without) the program.</p>
<p>On <a href="https://blender.stackexchange.com/questions/53293/is-blender-actually-useable-for-engineering">Blender SE</a>, a question of similar format exists, with a somewhat open-ended answer. A quick search using The Google, with the terms "<a href="https://www.google.com/#q=parametric+modeling+with+blender" rel="nofollow noreferrer">Parametric Modeling with Blender</a>" results in a number of different approaches. According to a quick perusal of the search results, some of the solutions involve free plug-ins or add-ons for Blender. More complexity rather than less, perhaps.</p>
<p>I'm familiar enough with the very simple basics of Blender to know I would not be able to make use of those answers. I'm also well aware that Blender's power extends beyond my own limitations with features supporting scripting, animation and so many other tools. Seeing the workflow diagrams/charts that make up some of the advanced portion of the program leads me to believe that one can accomplish your objective, but one must be a certified wizard with the program. </p>
<p>As an alternative, one could engage any one of the many parametric modeling programs available. I'm a fan of OpenSCAD, although the text/scripting interface can be daunting for some. If you've become skilled in Blender, a non-GUI format isn't necessarily the best route, although the GUI options are no less confusing, in my opinion.</p>
|
<p>The minimum scale of your model
The modeling of your 3D file doesn’t necessarily require that you work with a given unit or scale. It’s particularly true with software like Blender in which you’re able to give proportion but no unit. This job will be done after the modeling phase when you send your model to a 3D printer. That’s why you need to pay extra attention to both the scale and the size of your model at that point. Creating a 3D print in millimeters instead of centimeters might very well result in a bad 3D print.</p>
<p>A powerful example of that can be found in architectural models. This is, in fact, one of the main issues we encountered while working with La Cité de L’Architecture on La Merveille’s reproduction. With architectural models, it can, for instance, be entirely possible to 3D print a scale 1/10 of something and just impossible to do the same at 1/250.</p>
<p>After a certain level of miniaturization, the details (present in the digital 3D file) are starting to vanish in the physical world because the 3D printer itself is no able to create them (or will create very fragile one). Quite often for architectural models, human intervention is necessary to decide which details will be kept and which won’t so that the 3D file doesn’t contain information that won’t be printable.</p>
| 528
|
<p>I want to configure SMTP on my web server, so that any email sent through the SMTP server is relayed to a remote SMTP Server. The IIS SMTP server would have to use SMTP authentication, and use the host name, username and password (as if configuring a normal email client).</p>
<p>Does anybody know if this is possible?</p>
|
<p>Yes, it' completely possible, and relatively easy to configure.</p>
<p>I've got a couple of articles about SmartHosting on my web site that will probably help:</p>
<p><a href="http://www.christopherlewis.com/SmartHosting/SMTPSmartHosting.htm" rel="noreferrer">http://www.christopherlewis.com/SmartHosting/SMTPSmartHosting.htm</a>
<br>and<br>
<a href="http://www.christopherlewis.com/SmartHosting/SMTPSmartHostingPt2.htm" rel="noreferrer">http://www.christopherlewis.com/SmartHosting/SMTPSmartHostingPt2.htm</a></p>
<p>They're written towards Exchange 2003, but Exchange 2003 used IIS's SMTP engine, so the settings are the same.</p>
<p>Bascially, you right click the SMTP site, select properties, Delivery tab, Outbound security, and enter your credientials in the Basic Authentication fields. Back on the Delivery tab, you then click Advanced and enter the remote SMTP server name in the SmartHost field.</p>
<h2><strong>Editing</strong></h2>
<p>The links above are no longer available.</p>
<p>Try <a href="http://intellitect.com/configuring-windows-smtp-server-on-windows-2008-for-relay/" rel="noreferrer">http://intellitect.com/configuring-windows-smtp-server-on-windows-2008-for-relay/</a>.</p>
|
<p>HTH and answers your needs</p>
<p><a href="http://www.cmsconnect.com/praetor/webhelpg2/Chapter_2_-_Pre-installation_considerations/Configuring_the_SMTP_Server.htm" rel="nofollow noreferrer">http://www.cmsconnect.com/praetor/webhelpg2/Chapter_2_-_Pre-installation_considerations/Configuring_the_SMTP_Server.htm</a></p>
| 29,599
|
<p>I'm in the middle of writing code in .Net to draw something in my app and I need to pick a color to use. But what does the color "Chartreuse" look like? Isn't there a nice bitmap that shows what each of the system colors look like somewhere?</p>
<p>Thanks!</p>
|
<p>Try this <a href="http://www.blizzardskies.com/bz/colorchart.html" rel="nofollow noreferrer">site</a>. </p>
<p>This site is nice because it shows how the color will look as foreground and background color.</p>
|
<p>Check this out: <a href="http://www.w3schools.com/TAGS/ref_color_tryit.asp?color=BlanchedAlmond" rel="nofollow noreferrer">http://www.w3schools.com/TAGS/ref_color_tryit.asp?color=BlanchedAlmond</a></p>
<p>(Pay attention the URL and modify as necessary)</p>
| 12,863
|
<p>I have a client who is using one TFS project just for source control only and now wants to manage work items in a totally different TFS project, using a different process template, and intends to link changesets to work items across TFS projects.</p>
<p>I know that this is possible in TFS, but don't know what the limitations or issues that come with this configuration. e.g Build Summaries, Reporting, etc.</p>
<p>I would prefer branching the code into a new TFS project and managing code and work items together in one project, but need to know how the above method stacks up.</p>
|
<p>It'll work - I've occasionally had to associate checkins with work items from other projects. I haven't noticed any issues with reports or the like, that said this seems like an overly complex arrangement with little benefit.</p>
|
<p>Seems like a strange set-up to me. While it will work, TFS is designed for the check-ins and work items to be in the same team project so you won't really get the full benefit of the TFS features. Does the client know that they can modify the process template of the existing team project or do what you say and branch or even just move the source into a new team project.</p>
| 22,283
|
<p>Is there anything better than a <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow noreferrer">Trie</a> for this situation?</p>
<ul>
<li>Storing a list of ~100k English words</li>
<li>Needs to use minimal memory</li>
<li>Lookups need to be reasonable, but don't have to be lightning fast</li>
</ul>
<p>I'm working with Java, so my first attempt was to just use a Set<String>. However, I'm targeting a mobile device and already running low on memory. Since many English words share common prefixes, a trie seems like a decent bet to save some memory -- anyone know some other good options?</p>
<p>EDIT - More info - The data structure will be used for two operations</p>
<ul>
<li>Answering: Is some word XYZ in the list?</li>
<li>Generating the neighborhood of words around XYZ with one letter different</li>
</ul>
<p>Thanks for the good suggestions</p>
|
<p>What are you doing? If it's spell checking, you could use a bloom filter - see this <a href="http://codekata.pragprog.com/2007/01/kata_five_bloom.html" rel="nofollow noreferrer">code kata</a>.</p>
|
<p>You still have to maintain the tree structure itself with Trie. <a href="http://en.wikipedia.org/wiki/Huffman_coding" rel="nofollow noreferrer">Huffman encoding</a> the alphabet or N-letters (for common forms like "tion", "un", "ing") can take advantage of the occurrence frequency in your dictionary and compress the entry to bits.</p>
| 46,716
|
<p>This is somewhat of a follow-up to an answer <a href="https://stackoverflow.com/questions/26536/active-x-control-javascript">here</a>.</p>
<p>I have a custom ActiveX control that is raising an event ("ReceiveMessage" with a "msg" parameter) that needs to be handled by Javascript in the web browser. Historically we've been able to use the following IE-only syntax to accomplish this on different projects:</p>
<pre><code>function MyControl::ReceiveMessage(msg)
{
alert(msg);
}
</code></pre>
<p>However, when inside a layout in which the control is buried, the Javascript cannot find the control. Specifically, if we put this into a plain HTML page it works fine, but if we put it into an ASPX page wrapped by the <code><Form></code> tag, we get a "MyControl is undefined" error. We've tried variations on the following:</p>
<pre><code>var GetControl = document.getElementById("MyControl");
function GetControl::ReceiveMessage(msg)
{
alert(msg);
}
</code></pre>
<p>... but it results in the Javascript error "GetControl is undefined."</p>
<p>What is the proper way to handle an event being sent from an ActiveX control? Right now we're only interested in getting this working in IE. This has to be a custom ActiveX control for what we're doing.</p>
<p>Thanks.</p>
|
<p>I was able to get this working using the following script block format, but I'm still curious if this is the best way:</p>
<pre><code><script for="MyControl" event="ReceiveMessage(msg)">
alert(msg);
</script>
</code></pre>
|
<p>I think that the MyControl::ReceiveMessage example does not work because the ActiveX control is being exposed with a different name or in a different scope.</p>
<p>With the example GetControl::ReceiveMessage, I believe that the function definition is being parsed before the GetControl reference is being set, thus it does not refer to a valid object and cannot bind the function to the object.</p>
<p>I would attack this problem by using the MS script debugger and trying to determine if a default reference for the control exists with a different name or in a different scope (possibly as a child of the form). If you can determine the correct reference for the control, you should be able to bind the function properly with the Automagic :: method that the MSDN article specifies.</p>
<p>One more thought, the reference may be based on the name of the object and not the ID, so try setting both :)</p>
| 18,184
|
<p>I was inserting data into a MS Access database using JDBC-ODBC driver. The blank mdb file was 2KB. After populating this database, the size grew to 155MB. Then I was deleting the data. But I found the size of mdb remains the same as 155MB. I don't get any errors. But is it normal this way? I would expect the file size reduces. If it is designed in this way, what is the idea behind it? Thanks</p>
|
<p>MS Access doesn't reclaim the space for records until you have compacted the database.</p>
<p>This is something you should do to an access database as part of your regularly maintenance otherwise you will end up with some pretty painful problems.</p>
<p>You can compact a database either through the MS Access UI (Tools -> Database Utilities -><br>
Compact and Repair Database) of you can use the command prompt using:</p>
<pre><code>msaccess.exe "target database.accdb" /compact
</code></pre>
<p>N.B. the /Compact switch must be after the target database</p>
|
<p>The first stop, as mentioned should be attempting to compact/repair the database. However you can also get some size saving past that by creating a new database and importing all of the objects from the old. Past that, converting it to an MDE should get you a hair more. As always, don't play around with your production copy. Also if you go with an MDE, make sure you have properly split the database first. (And of course keep a copy of the source MDB should you need to make modifications in the future.)</p>
| 18,910
|
<p>I need advice for rendering an undirected graph with 178,000 nodes and 500,000 edges. I've tried Neato, Tulip, and Cytoscape. Neato doesn't even come remotely close, and Tulip and Cytoscape claim they can handle it but don't seem to be able to. (Tulip does nothing and Cytoscape claims to be working, and then just stops.)</p>
<p>I'd just like a vector format file (ps or pdf) with a remotely reasonable layout of the nodes.</p>
|
<p>Graphviz itself provides a solution for rendering large graphs.</p>
<p>Namely, Graphviz includes <code>sfdp</code>, a multiscale version of fdp (also in graphviz, similar to neato) for the layout of large undirected graphs which has been useful for drawing large graphs (70k nodes, 500k edges) in my project.</p>
<p>You can find documentation for this software on the graphviz web site itself at <a href="http://www.graphviz.org/" rel="nofollow noreferrer">http://www.graphviz.org/</a></p>
<p>For more information, here is <em>Efficient and high quality force-directed graph drawing</em>, a paper by Yifan Hu describing the underlying techniques and examples:
<a href="http://yifanhu.net/PUB/graph_draw_small.pdf" rel="nofollow noreferrer">http://yifanhu.net/PUB/graph_draw_small.pdf</a></p>
<p>And a web archive version: <a href="https://web.archive.org/web/20210812011222/http://yifanhu.net/PUB/graph_draw.pdf" rel="nofollow noreferrer">https://web.archive.org/web/20210812011222/http://yifanhu.net/PUB/graph_draw.pdf</a></p>
|
<p>First, I would like to second aliekens' suggestion to try sfdp. It is the large scale version of Neato. </p>
<p>As OJW suggests you could also just plot the nodes in R2. Your edges actually supply what he calls a "natural ordering." In particular you can plot the components of the second and third eigenvectors of the normalized graph Laplacian. This is the matrix <code>L</code> in <a href="http://en.wikipedia.org/wiki/Spectral_clustering#Algorithms" rel="nofollow">this wikipedia page about spectral clustering</a>. You should be able to write down this matrix without understanding the linear algebra behind it. Then, you have reduced your problem to approximately computing the first few eigenvectors of a large sparse matrix. This is traditionally done by iterative methods and is implemented in standard linear algebra packages. This method should scale up to very large graphs.</p>
| 29,529
|
<p>I'm creating a site where the user unfortunately has to provide a regex to be used in a MySQL WHERE clause. And of course I have to validate the user input to prevent SQL injection. The site is made in PHP, and I use the following regex to check my regex:</p>
<pre><code>/^([^\\\\\']|\\\.)*$/
</code></pre>
<p>This is double-escaped because of PHP's way of handling regexes.
The way it's supposed to work is to only match safe regexps, without unescaped single quotes. But being mostly self-taught, I'd like to know if this is a safe way of doing it.</p>
|
<p>If you use prepared statements, SQL injection will be impossible. You should always use prepared statements.</p>
<p>Roborg makes an excellent point though about expensive regexes.</p>
|
<p>If it is anly for the purposes of display this reg expression then most programs simply Html Encode the value and store in the DB and then the Decode on the way out. Again only for Display purposes though, if you need to use the reg exp that is submitted this won't work. </p>
<p>Also know there is a method where the person intent on injecting writes out there SQL, Converts it to varbinary and submits the exec command with the base 64 representation of the query which I have been hit with in the past.</p>
| 26,595
|
<p>I am new to the <code>.Net</code> Compact Framework and have been unable to find an answer via Google. Gasp! Yes, it's true, but that is part of why StackOverflow is here, right?</p>
<p>I have a form that is longer than the screen, so a vertical scroll-bar appears as expected. However, this appears to force a horizontal scroll-bar to appear as well. (If I scroll to the right, there is nothing visible except white space ... about the size of a scroll-bar.)</p>
<p>Is this a "feature" that is unavoidable? Anyone have experience in this area?
</p>
|
<p>Place your controls within a panel or equivalent and then reduce the width of the panel by the size of a vertical scrollbar. That means that when the vertical scrollbar appears then it will no longer require the horizontal scrollbar to make up for the lost width that the vertical scrollbar took.</p>
|
<p>Yes - I've got experience with that - unfortunately it was no different from your own. I've generally avoided scrolling forms and used paging wherever possible on .Net CF. If this is an option for you, I'd recommend it.</p>
<p>I'd assume the scroll bar issue is to do with the form size being fixed to the width of the available screen (regardless of design-time settings) so the introduction of a vertical scroll bar obscures part of the (not needed) full-width form.</p>
| 5,115
|
<p>Is there an easy way to programmatically determine the number of lines within a text file? </p>
|
<p><strong>Seriously belated edit: If you're using .NET 4.0 or later</strong></p>
<p>The <code>File</code> class has a new <a href="http://msdn.microsoft.com/en-us/library/dd383503.aspx" rel="noreferrer"><code>ReadLines</code></a> method which lazily enumerates lines rather than greedily reading them all into an array like <code>ReadAllLines</code>. So now you can have both efficiency and conciseness with:</p>
<pre><code>var lineCount = File.ReadLines(@"C:\file.txt").Count();
</code></pre>
<hr>
<p><strong>Original Answer</strong></p>
<p>If you're not too bothered about efficiency, you can simply write:</p>
<pre><code>var lineCount = File.ReadAllLines(@"C:\file.txt").Length;
</code></pre>
<p>For a more efficient method you could do:</p>
<pre><code>var lineCount = 0;
using (var reader = File.OpenText(@"C:\file.txt"))
{
while (reader.ReadLine() != null)
{
lineCount++;
}
}
</code></pre>
<p><strong>Edit: In response to questions about efficiency</strong></p>
<p>The reason I said the second was more efficient was regarding memory usage, not necessarily speed. The first one loads the entire contents of the file into an array which means it must allocate at least as much memory as the size of the file. The second merely loops one line at a time so it never has to allocate more than one line's worth of memory at a time. This isn't that important for small files, but for larger files it could be an issue (if you try and find the number of lines in a 4GB file on a 32-bit system, for example, where there simply isn't enough user-mode address space to allocate an array this large).</p>
<p>In terms of speed I wouldn't expect there to be a lot in it. It's possible that ReadAllLines has some internal optimisations, but on the other hand it may have to allocate a massive chunk of memory. I'd guess that ReadAllLines might be faster for small files, but significantly slower for large files; though the only way to tell would be to measure it with a Stopwatch or code profiler.</p>
|
<p>You can launch the "<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?wc" rel="nofollow noreferrer">wc</a>.exe" executable (comes with <a href="http://unxutils.sourceforge.net/" rel="nofollow noreferrer">UnixUtils</a> and does not need installation) run as an external process. It supports different line count methods (like unix vs mac vs windows).</p>
| 14,539
|
<p>So my program needs to go through a plain text file line by line essentially:</p>
<pre><code>Read line 1:
Do commands
loop
Read line2:
Do Commands
loop
</code></pre>
<p>etc until its done with the entire file does anyone know any good coding examples for this, all the tutorials seem to show open and writing/reading textfiles but nothing on how to do it line by line.</p>
|
<pre><code>For Each line As String In System.IO.File.ReadAllLines("file.txt")
' Do Something'
Next
</code></pre>
|
<p>You could do it like this:</p>
<pre><code>Using f As System.IO.FileStream = System.IO.File.OpenRead("somefile.txt")
Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
While Not s.EndOfStream
Dim line As String = s.ReadLine
'put you line processing code here
End While
End Using
End Using
</code></pre>
| 35,880
|
<p>We use a lot of of python to do much of our deployment and would be handy to connect to our TFS server to get information on iteration paths, tickets etc. I can see the webservice but unable to find any documentation. Just wondering if anyone knew of anything?</p>
|
<p>The web services are not documented by Microsoft as it is not an officially supported route to talk to TFS. The officially supported route is to use their <a href="http://msdn.microsoft.com/en-us/library/bb130146(VS.80).aspx" rel="noreferrer">.NET API</a>. </p>
<p>In the case of your sort of application, the course of action I usually recommend is to create your own web service shim that lives on the TFS server (or another server) and uses their API to talk to the server but allows you to present the data in a nice way to your application. </p>
<p>Their object model simplifies the interactions a great deal (depending on what you want to do) and so it actually means less code over-all - but better tested and testable code and also you can work around things such as the NTLM auth used by the TFS web services.</p>
<p>Hope that helps,</p>
<p>Martin.</p>
|
<p>So, this question is friggin' old, but let me take a whack at it (since it keeps coming up in my google searches).</p>
<p>There's no officiall supported API for the on premise TFS (the MSFT hosted one has <a href="http://www.visualstudio.com/en-us/integrate/api/overview" rel="nofollow">http://www.visualstudio.com/en-us/integrate/api/overview</a>).</p>
<p>That said, you can always use Fiddler (<a href="http://www.telerik.com/fiddler" rel="nofollow">http://www.telerik.com/fiddler</a>) or something like it to inspect the calls that the web client for TFS is making to the server and do your magic to turn those into the scripts in python you want.</p>
<p>You'll need to run your python scripts under a service account that has TFS privs appropriate to what it is trying to do (read, update, confugure... whatever).</p>
<p>Since it sounds like you are just trying to read from TFS, this might be a really easy way for you to get what you want since an HTTP get to
<a href="http://yourserver/tfs/yourcollection/yourproject/_workitems#id=yourworkitemid" rel="nofollow">http://yourserver/tfs/yourcollection/yourproject/_workitems#id=yourworkitemid</a>
will hand you back (halfway) sane html payloads.</p>
<p>If you want lists of iterations or teams or whatever, then your service account needs to have the appropriate admin privileges and hit things like
<a href="http://yourserver/tfs/yourcollection/yourproject/_admin/_iterations" rel="nofollow">http://yourserver/tfs/yourcollection/yourproject/_admin/_iterations</a>
and use that response.</p>
| 23,400
|
<p>According to the <a href="http://uk3.php.net/features.safe-mode" rel="nofollow noreferrer">PHP Safe Mode Docs</a> on safe_mode_gid:</p>
<blockquote>
<p>By default, Safe Mode does a UID compare check when opening files. If you want to relax this to a GID compare, then turn on safe_mode_gid. Whether to use UID (FALSE) or GID (TRUE) checking upon file access.</p>
</blockquote>
<p>To a PHP script running on a web server, what is the difference between a UID (User Identifier) check and a GID (Group identifier) check?</p>
|
<p>This will just allow you a little more flexibility in your web server setup. Using safe_mode_gid, you should be able to run individual PHP/httpd processes for each user on your system, but give each process the ability to read some shared files as long as they are all run as the same group (GID) and the shared files are owned by this group.</p>
|
<p>Safe mode UID check is used to prevent users from accessing other peoples files. GID is used to prevent a GROUP of users from accessing other GROUPS files.</p>
| 2,940
|
<p>Any recommended crypto libraries for Python. I know I've asked something similar in <a href="https://stackoverflow.com/questions/143523/">x509 certificate parsing libraries for Java</a>, but I should've split the question in two.</p>
<p>What I need is the ability to parse X.509 Certificates to extract the information contained in them.</p>
<p>Looking around, I've found two options:</p>
<ul>
<li>Python OpenSSL Wrappers (<a href="http://sourceforge.net/projects/pow" rel="nofollow noreferrer" title="Python OpenSSL Wrappers">http://sourceforge.net/projects/pow</a>)</li>
<li><a href="https://github.com/pyca/pyopenssl" rel="nofollow noreferrer">pyOpenSSL</a></li>
</ul>
<p>Of the two, pyOpenSSL seems to be the most "maintained", but I'd like some feedback on anybody who might have experience with them?</p>
|
<p>You might want to try <a href="http://www.keyczar.org/" rel="nofollow noreferrer">keyczar</a> as mentioned by me in your other post, since that library actually has implementations for both python and java. That would make it easier to use it in both contexts.</p>
<p>A word of warning: I have not actually used this library 8(, so please take this with a grain of salt.</p>
|
<p>The <code>keyczar</code> project is deprecated.
You can check out <a href="https://github.com/google/tink" rel="nofollow noreferrer"><code>tink</code></a>.</p>
| 17,333
|
<p>Does anyone know of any good tools to view the store name, store location, or values of an X.509 Certificate?</p>
|
<p>i'm supposing that you are using Windows. So here it is <a href="http://msdn.microsoft.com/en-us/library/aa529278.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa529278.aspx</a>. It's a good tool, but to do it thru API is not hard and it's a good exercise to learn the API.</p>
<p>Regards,</p>
<p>Victor</p>
|
<p>See <a href="http://msdn.microsoft.com/en-us/library/ms819944.aspx" rel="nofollow">How to: Use the X.509 Certificate Management Tools</a> on MSDN for instructions on how to use the Microsoft Management Console (MMC) Certificates snap-in to manage X.509 certificates.</p>
| 26,569
|
<p>On a Unix system, where does gcc look for header files?</p>
<p>I spent a little time this morning looking for some system header files, so I thought this would be good information to have here.</p>
|
<pre><code>`gcc -print-prog-name=cc1plus` -v
</code></pre>
<p>This command asks gcc which <strong>C++</strong> preprocessor it is using, and then asks that preprocessor where it looks for includes.</p>
<p>You will get a reliable answer for your specific setup.</p>
<p>Likewise, for the <strong>C</strong> preprocessor:</p>
<pre><code>`gcc -print-prog-name=cpp` -v
</code></pre>
|
<p>My system has gcc9 by default and I have built a gcc12 from source and I think the accepted answer is not correct, that is <code>gcc -print-prog-name=cc1plus -v</code> doesn't give the real include search path.</p>
<p>My build configuration is</p>
<pre><code>Configured with: /home/tian/playground/gcc_build_play/objdir/../gcc-12.1.0/configure --prefix=/home/tian/GCC-12.1.0 --disable-multilib
</code></pre>
<p><strong>And no matter where I <code>mv</code> the gcc12 directoy in my machine. It can always include its own c++ header files correctly.</strong></p>
<hr />
<p>If I type <code>./gcc -print-prog-name=cc1plus -v</code>, in the original installed directory, it gives:</p>
<pre><code>tian@tian-B250M-Wind:~/GCC-12.1.0/bin$ `./gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0
/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/x86_64-pc-linux-gnu
/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/backward
/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include
/usr/local/include
/home/tian/GCC-12.1.0/include
/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed
/usr/include
End of search list.
</code></pre>
<p><code>mv</code> my gcc12 to <code>~/Desktop/</code>, run again, gives:</p>
<pre><code>tian@tian-B250M-Wind:~/Desktop/GCC-12.1.0/bin$ `./gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/home/tian/GCC-12.1.0/include/c++/12.1.0"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/include/c++/12.1.0/x86_64-pc-linux-gnu"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/include/c++/12.1.0/backward"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/include"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed"
ignoring nonexistent directory "/home/tian/GCC-12.1.0/x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/include
End of search list.
</code></pre>
<p>If that's true, then I compile a program with <code>./g++</code>, it should use c++ header files in <code>/usr/include</code> or <code>/usr/local/include</code>. But it's not.</p>
<p>Experiment is omitted here. You can try using <code>mv</code> to rename any header file of gcc12 your test program use or add some garbage code to the header file. Then you will see the gcc12 <code>./g++</code> is complaining about the gcc12 c++ header file, not my system gcc9's c++ header files in <code>/usr/include</code> or <code>/usr/local/include</code>.</p>
<p>So in both places <code>./g++</code> can find its gcc12 c++ headers files correctly.</p>
<hr />
<p>So I guess <code>gcc</code> and <code>g++</code> are finding headers in relative directory, relative to <code>/path_to_gcc12/bin/gcc</code>.</p>
<p>Try<code>./g++ -g -Wall --verbose -o test test.cpp</code> gives the real include path:</p>
<pre><code>tian@tian-B250M-Wind:~/Desktop/GCC-12.1.0/bin$ ./g++ -g -Wall --verbose -o test test.cpp
Using built-in specs.
COLLECT_GCC=./g++
COLLECT_LTO_WRAPPER=/home/tian/Desktop/GCC-12.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/tian/playground/gcc_build_play/objdir/../gcc-12.1.0/configure --prefix=/home/tian/GCC-12.1.0 --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (GCC)
COLLECT_GCC_OPTIONS='-g' '-Wall' '-v' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/home/tian/Desktop/GCC-12.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/12.1.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -iprefix /home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/ -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -g -Wall -version -o /tmp/ccrg0qhG.s
GNU C++17 (GCC) version 12.1.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0"
ignoring duplicate directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/x86_64-pc-linux-gnu"
ignoring duplicate directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/backward"
ignoring duplicate directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/include"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring duplicate directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed"
ignoring nonexistent directory "/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/x86_64-pc-linux-gnu
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/backward
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/include
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed
/usr/local/include
/home/tian/Desktop/GCC-12.1.0/bin/../lib/gcc/../../include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
</code></pre>
<p>So I think my guess is correct.</p>
| 44,784
|
<p>What is the best way to get the current system time milliseconds?</p>
|
<pre><code>[[NSDate date] timeIntervalSince1970];
</code></pre>
<p>It returns the number of seconds since epoch as a double. I'm almost sure you can access the milliseconds from the fractional part.</p>
|
<p><code>[NSDate timeIntervalSinceReferenceDate]</code> is another option, if you don't want to include the Quartz framework. It returns a double, representing seconds.</p>
| 46,710
|
<p>When you're passing variables through your site using GET requests, do you validate (regular expressions, filters, etc.) them before you use them?</p>
<p>Say you have the URL <a href="http://www.example.com/i=45&p=custform" rel="nofollow noreferrer">http://www.example.com/i=45&p=custform</a>. You know that "i" will always be an integer and "p" will always contain only letters and/or numbers. Is it worth the time to make sure that no one has attempted to manipulate the values and then resubmit the page?</p>
|
<p>Yes. Without a doubt. Never trust user input.</p>
<p>To improve the user experience, input fields can (and IMHO should) be validated on the client. This can pre-empt a round trip to the server that only leads to the same form and an error message.</p>
<p>However, input must <strong>always</strong> be validated on the server side since the user can just change the input data manually in the GET url or send crafted POST data.</p>
<p>In a worst case scenario you can end up with an <a href="http://unixwiz.net/techtips/sql-injection.html" rel="noreferrer">SQL injection</a>, or even worse, a <a href="http://www.cgisecurity.com/articles/xss-faq.shtml" rel="noreferrer">XSS</a> vulnerability.</p>
<p>Most frameworks already have some builtin way to clean the input, but even without this it's usually very easy to clean the input using a combination of regular exceptions and lookup tables.</p>
<ul>
<li>Say you know it's an integer, use int.Parse or match it against the regex "^\d+$".</li>
<li>If it's a string and the choices are limited, make a dictionary and run the string through it. If you don't get a match change the string to a default.</li>
<li>If it's a user specified string, match it against a strict regex like "^\w+$"</li>
</ul>
|
<p>Yes, check them as thoroughly as you can. In PHP I always check the types (<code>IsInt(i), IsString(p)</code>).</p>
| 21,491
|
<p>I'm desperately looking for cheap ways to lower the build times on my home PC. I just read an <a href="http://www.axantum.com/Blog/post/How-to-make-a-file-read-in-Windows-not-become-a-write.aspx" rel="nofollow noreferrer">article about disabling the Last Access Time attribute</a> of a file on Windows XP, so that simple reads don't write anything back to disk.</p>
<blockquote>
<p>It's really simple too. At a DOS-prompt write:</p>
<p><code>fsutil behavior set disablelastaccess 1</code></p>
</blockquote>
<p>Has anyone ever tried it in the context of <strong>building C++ projects</strong>? Any drawbacks?</p>
<p>[Edit] More on the topic <a href="http://www.windowsdevcenter.com/pub/a/windows/2005/02/08/NTFS_Hacks.html" rel="nofollow noreferrer">here</a>.</p>
|
<p>From <a href="http://msdn.microsoft.com/en-us/library/ms724933(VS.85).aspx" rel="nofollow noreferrer">SetFileTime's documentation</a>:</p>
<p>"NTFS delays updates to the last access time for a file by up to one hour after the last access."</p>
<p>There's no real point turning this off - the original article is wrong, the data is not written out on every access.</p>
<p>EDIT:</p>
<p>As to why the author of that article claimed a 10x speed-up, I think he attributed his speed-up to the wrong thing: he also disabled 8.3 filename generation. To generate an 8.3 filename for a file, NTFS has to basically generate each possibility in turn then see if it's already in use (no reference; I'm sure <a href="http://blogs.msdn.com/oldnewthing/" rel="nofollow noreferrer">Raymond</a> has talked about it but can't find a link). If your files all share the same first six characters, you will be bitten by this problem, and the corrolary is you should put characters which differentiate files in the first six characters so they don't clash. Turning off short name generation will prevent this.</p>
|
<p>To Mike Dimmick:</p>
<p>Try to connect USB drive with many files and copy them to your internal drive. That's also the case in addition to program compilation (which is described in original post).</p>
| 10,672
|
<p>I know this is probably the dumbest question ever, however I am a total beginner when it comes to CSS; how do you hyperlink an image on a webpage using an image which is sourced from CSS? I am trying to set the title image on my website linkable to the frontpage. Thanks!</p>
<p><strong>Edit:</strong> Just to make it clear, I'm sourcing my image <em>from CSS</em>, the CSS code for the header div is as follows:-</p>
<pre><code>#header
{
width: 1000px;
margin: 0px auto;
padding: 0px 15px 0px 15px;
border: none;
background: url(images/title.png) no-repeat bottom;
width: 1000px;
height: 100px;
}
</code></pre>
<p>I want to know how to make this <em>div</em> hyperlinked on my webpage without having to make it an anchor rather than a div.</p>
|
<p>You control design and styles with CSS, not the behavior of your content. </p>
<p>You're going to have to use something like <code><a id="header" href="[your link]">Logo</a></code> and then have a CSS block such as:</p>
<pre><code>a#header {
background-image: url(...);
display: block;
width: ..;
height: ...;
}
</code></pre>
<p>You cannot nest a <code>div</code> inside <code><a></code> and still have 'valid' code. <code><a></code> is an inline element that cannot legally contain a block element. The only non-Javascript way to make a link is with the <code><a></code> element. </p>
<p>You can nest your <code><a></code> tag inside <code><div></code> and then put your image inside :)</p>
<p>If you don't want that, you're going to have to use JavaScript to make your <code><div></code> clickable:</p>
<pre><code>Document.getElementById("header").onclick = function() {
window.location='...';
}
</code></pre>
|
<p>CSS is for presentation only, not content. A link is content and should be put into the HTML of the site using a standard <code><a href=""></code> tag. You can then style this link (or add an image to the link) using CSS.</p>
| 14,329
|
<p>When viewing files in a shelveset, I would like the option of comparing the files to my current local version. Unfortunately, the only options available are "With Unmodified", "With Workspace" (I guess this one would be the answer, if it wasn't disabled) and "With Latest".</p>
<p>Any ideas?</p>
|
<p>Export Shelveset to a local folder using Team Foundation Sidekicks and use file comparison tool to compare with local version.</p>
|
<p>This is a little laborious but it does the job:</p>
<ol>
<li><p>Right click any file in Solution
Explorer and select 'Unshelve
Pending Changes...' from the context
menu.</p></li>
<li><p>Double click the relevant shelveset in the Unshelve dialog.</p></li>
<li><p>Double click the file that you want to compare. This will open the sheleveset version of the file in notepad.</p></li>
<li><p>Save the file somewhere on your local machine.</p></li>
<li><p>Close all the dialogs.</p></li>
<li><p>Right click the local workspace version of your file in Solution Explorer and select 'Compare' from the context menu.</p></li>
<li><p>Change the target path to that of the file that you saved earlier and click OK.</p></li>
</ol>
| 20,913
|
<p>I have the following query:</p>
<pre><code>SELECT c.*
FROM companies AS c
JOIN users AS u USING(companyid)
JOIN jobs AS j USING(userid)
JOIN useraccounts AS us USING(userid)
WHERE j.jobid = 123;
</code></pre>
<p>I have the following questions:</p>
<ol>
<li>Is the USING syntax synonymous with ON syntax?</li>
<li>Are these joins evaluated left to right? In other words, does this query say: x = companies JOIN users; y = x JOIN jobs; z = y JOIN useraccounts;</li>
<li>If the answer to question 2 is yes, is it safe to assume that the companies table has companyid, userid and jobid columns?</li>
<li>I don't understand how the WHERE clause can be used to pick rows on the companies table when it is referring to the alias "j"</li>
</ol>
<p>Any help would be appreciated!</p>
|
<ol>
<li><p>USING (fieldname) is a shorthand way of saying ON table1.fieldname = table2.fieldname.</p></li>
<li><p>SQL doesn't define the 'order' in which JOINS are done because it is not the nature of the language. Obviously an order has to be specified in the statement, but an INNER JOIN can be considered commutative: you can list them in any order and you will get the same results.</p>
<p>That said, when constructing a SELECT ... JOIN, particularly one that includes LEFT JOINs, I've found it makes sense to regard the third JOIN as joining the new table to the results of the first JOIN, the fourth JOIN as joining the results of the second JOIN, and so on.</p>
<p>More rarely, the specified order can influence the behaviour of the query optimizer, due to the way it influences the heuristics.</p></li>
<li><p>No. The way the query is assembled, it requires that companies and users both have a companyid, jobs has a userid and a jobid and useraccounts has a userid. However, only one of companies <em>or</em> user needs a userid for the JOIN to work.</p></li>
<li><p>The WHERE clause is filtering the whole result -- i.e. all JOINed columns -- using a column provided by the jobs table.</p></li>
</ol>
|
<p>SEE <a href="http://dev.mysql.com/doc/refman/5.0/en/join.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/join.html</a></p>
<p><em>AND start reading here:</em></p>
<hr>
<p><strong>Join Processing Changes in MySQL 5.0.12</strong></p>
<p>Beginning with MySQL 5.0.12, natural joins and joins with USING, including outer join variants, are processed according to the SQL:2003 standard. The goal was to align the syntax and semantics of MySQL with respect to NATURAL JOIN and JOIN ... USING according to SQL:2003. However, these changes in join processing can result in different output columns for some joins. Also, some queries that appeared to work correctly in older versions must be rewritten to comply with the standard.</p>
<p>These changes have five main aspects:</p>
<ul>
<li><p>The way that MySQL determines the result columns of NATURAL or USING join operations (and thus the result of the entire FROM clause).</p></li>
<li><p>Expansion of SELECT * and SELECT tbl_name.* into a list of selected columns.</p></li>
<li><p>Resolution of column names in NATURAL or USING joins.</p></li>
<li><p>Transformation of NATURAL or USING joins into JOIN ... ON.</p></li>
<li><p>Resolution of column names in the ON condition of a JOIN ... ON.</p></li>
</ul>
| 28,267
|
<p>Is there a better way than simply trying to open the file?</p>
<pre><code>int exists(const char *fname)
{
FILE *file;
if ((file = fopen(fname, "r")))
{
fclose(file);
return 1;
}
return 0;
}
</code></pre>
|
<p>Look up the <code>access()</code> function, found in <code>unistd.h</code>. You can replace your function with</p>
<pre><code>if (access(fname, F_OK) == 0) {
// file exists
} else {
// file doesn't exist
}
</code></pre>
<p>Under Windows (VC) <code>unistd.h</code> does not exist. To make it work it is necessary to define:</p>
<pre class="lang-c prettyprint-override"><code>#ifdef WIN32
#include <io.h>
#define F_OK 0
#define access _access
#endif
</code></pre>
<p>You can also use <code>R_OK</code>, <code>W_OK</code>, and <code>X_OK</code> in place of <code>F_OK</code> to check for read permission, write permission, and execute permission (respectively) rather than existence, and you can OR any of them together (i.e. check for both read <em>and</em> write permission using <code>R_OK|W_OK</code>)</p>
<p><em>Update</em>: Note that on Windows, you can't use <code>W_OK</code> to reliably test for write permission, since the access function does not take DACLs into account. <code>access( fname, W_OK )</code> may return 0 (success) because the file does not have the read-only attribute set, but you still may not have permission to write to the file.</p>
|
<p>From the Visual C++ help, I'd tend to go with</p>
<pre><code>/* ACCESS.C: This example uses _access to check the
* file named "ACCESS.C" to see if it exists and if
* writing is allowed.
*/
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
/* Check for existence */
if( (_access( "ACCESS.C", 0 )) != -1 )
{
printf( "File ACCESS.C exists\n" );
/* Check for write permission */
if( (_access( "ACCESS.C", 2 )) != -1 )
printf( "File ACCESS.C has write permission\n" );
}
}
</code></pre>
<p>Also worth noting mode values of <code>_access(const char *path,</code><strong><code>int mode</code></strong><code>)</code>:</p>
<ul>
<li><p>00: Existence only</p></li>
<li><p>02: Write permission </p></li>
<li><p>04: Read permission</p></li>
<li><p>06: Read and write permission </p></li>
</ul>
<p>As your <code>fopen</code> could fail in situations where the file existed but could not be opened as requested.</p>
<p>Edit: Just read Mecki's post. <code>stat()</code> does look like a neater way to go. Ho hum.</p>
| 28,478
|
<p>I'm trying to write a software synthesizer that recreates the sounds made by classic synthesizers like the Moog and the DX7. Does anyone know of any code resources for something like this? Thanks.</p>
|
<p>There are an awful lot of C/C++ libraries out there, most no longer updated. There's not much for C#, but I have seen a couple. I haven't really used any of them in anger, so I can't give any recommendations.</p>
<p>I would start with <a href="http://www.harmony-central.com/Computer/Programming/" rel="noreferrer">Harmony Central</a> and see if you find anything of use there.</p>
<p>Alternatively, a search for <a href="http://www.google.co.uk/search?hl=en&q=analog+synthesis+site%3Asourceforge.net&meta=" rel="noreferrer">analog synthesis</a> on sourceforge.net has plenty of results.</p>
|
<p>I've had some success with the <a href="http://www.un4seen.com/" rel="nofollow noreferrer">BASS library</a>, but it's .Net support was a little crude when last I played with it. It mostly low-level stream encoding and such, but it does have support for some DX8 effects.</p>
| 31,151
|
<p>I am about to set up a subversion server to be accessed via svn+ssh. I was wondering, where the <em>default</em> repository location is (on a unix box).</p>
<p>Do you put it in</p>
<pre><code>/opt/svn
</code></pre>
<p>or</p>
<pre><code>/home/svn
</code></pre>
<p>or</p>
<pre><code>/usr/subversion
</code></pre>
<p>or even</p>
<pre><code>/svn
</code></pre>
<p>or somewhere else?</p>
<p>I am looking for the place, most people put it. Is there a convention?</p>
<p>EDIT:</p>
<p>It is absolutely possible to "hide" the actual repository location from the user. For example (in my case) by wrapping the <code>svnserve</code> executable in a way that it is called like:</p>
<pre><code>svnserve -r /var/svn/repos
</code></pre>
|
<p>I typically place the repositories somewhere under <code>/var</code>, usually in <code>/var/lib/svn</code> - I'm trying to follow the <a href="http://www.pathname.com/fhs/" rel="nofollow noreferrer">Filesystem Hierarchy Standard</a> which has this to say about the <a href="http://www.pathname.com/fhs/pub/fhs-2.3.html#PURPOSE31" rel="nofollow noreferrer">purpose of /var</a>:</p>
<p><code>/var</code> is specified here in order to make it possible to mount <code>/usr</code> read-only. Everything that once went into <code>/usr</code> that is written to during system operation (as opposed to installation and software maintenance) must be in <code>/var</code>.</p>
|
<p>It should definitely be in /var. I keep mine in /var/lib/svn. /opt is useful for keeping applications that you might not necessarily want as part of the system, for example: Firefox or MySql. A repository is not an application so it doesn't make sense to keep it in /opt. </p>
<p>And like the comment above you can refer to the <a href="http://www.pathname.com/fhs/pub/fhs-2.3.html" rel="nofollow noreferrer">FHS</a></p>
| 18,372
|
<p>What is the easiest way to copy the all the values from a column in a table to another column in the same table?</p>
|
<p>With a single statement (if the columns have the same datatype)</p>
<pre><code>UPDATE <tablename>
SET <destination column name> = <source column name>
</code></pre>
|
<p>This script will update ALL values in the field1 with the values from the field2 in the corresponding row</p>
<pre><code>UPDATE table SET field1 = field2
</code></pre>
| 20,931
|
<p>I have some user controls that I'm loading in SharePoint and I would prefer to have all those styles contained in an external style sheet. What's the best way to link to an external stylesheet in CSS?</p>
<p>Thanks.</p>
|
<p>Can you not add a <link rel...> to the head? If not, can you this.page.header.controls.add?</p>
|
<p>Thanks,</p>
<p>I was looking at that way too complicated like. Your answer solved my problem and will actually work a lot better than the method that I was going to approach it from.</p>
| 30,912
|
<p>I use this code to create a .zip with a list of files:</p>
<pre><code>ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
for (int i=0;i<srcFiles.length;i++){
String fileName=srcFiles[i].getName();
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);
InputStream fis = new FileInputStream(srcFiles[i]);
int read;
for(byte[] buffer=new byte[1024];(read=fis.read(buffer))>0;){
zos.write(buffer,0,read);
}
fis.close();
zos.closeEntry();
}
zos.close();
</code></pre>
<p>I don't know how the zip algorithm and the ZipOutputStream works, if it writes something before I read and send to 'zos' all of the data, the result file can be different in size of bytes than if I choose another buffer size. </p>
<p>in other words I don't know if the algorithm is like:</p>
<p>READ DATA-->PROCESS DATA-->CREATE .ZIP</p>
<p>or</p>
<p>READ CHUNK OF DATA-->PROCESS CHUNK OF DATA-->WRITE CHUNK IN .ZIP-->|
^-----------------------------------------------------------------------------------------------------------------------------</p>
<p>If this is the case, what buffer size is the best?</p>
<p>Update:</p>
<p>I have tested this code, changing the buffer size from 1024 to 64, and zipping the same files: with 1024 bytes the 80 KB result file was 3 bytes smaller than with 64 bytes buffer. Which is the best buffer size to produce the smallest .zip in the fatest time?</p>
|
<p>Short answer: I would pick something like 16k.</p>
<hr>
<p>Long answer:</p>
<p>ZIP is using the DEFLATE algorithm for compression (<a href="http://en.wikipedia.org/wiki/DEFLATE" rel="noreferrer">http://en.wikipedia.org/wiki/DEFLATE</a>). Deflate is a flavor of Ziv Lempel Welch(search wikipedia for LZW). DEFLATE uses LZ77 and Huffman coding.</p>
<p>This is a dictionary compression, and as far as I know from the algorithm standpoint the buffer size used when feeding the data into the deflater should have almost no impact. The biggest impact for LZ77 are dictionary size and sliding window, which are not controlled by the buffer size in your example.</p>
<p>I think you can experiment with different buffer sizes if you want and plot a graph, but I am sure you will not see any significant changes in compression ratio (3/80000 = 0.00375%).</p>
<p>The biggest impact the buffer size has is on the speed due to the amount of overhead code that is executed when you make the calls to FileInputStream.read and zos.write. From this point of view you should take into account what you gain and what you spend.</p>
<p>When increasing from 1 byte to 1024 bytes, you lose 1023 bytes (in theory) and you gain a ~1024 reduction of the overhead time in the .read and .write methods.
However when increasing from 1k to 64k, you are spending 63k which reducing the overhead 64 times.</p>
<p>So this comes with diminishing returns, thus I would choose somewhere in the middle (let's say 16k) and stick with that.</p>
|
<p>Depends on the hardware you have (disk speed and file search time). I would say if you are not interested in squeezing the last drop of performance pick any size between 4k and 64k. Since it is a short-lived object it will be collected quickly anyway.</p>
| 24,500
|
<p>In svn, I have a branch which was created, say at revision 22334. Commits were then made on the branch.</p>
<p>How do I get a list of all files that were changed on the branch compared to what's on the trunk? I do not want to see files that were changed on the trunk between when the branch was created and "now".</p>
|
<p>This will do it I think:</p>
<pre><code>svn diff -r 22334:HEAD --summarize <url of the branch>
</code></pre>
|
<p>-u option will display including object files if they are added during compilation.</p>
<p>So, to overcome that additionally you may use like this.</p>
<pre><code>svn status -u | grep -v '\?'
</code></pre>
| 19,391
|
<p>Is there a way to get drop_receiving_element to not generate "// ..</p>
|
<p>The code for the <code>drop_receiving_element</code> is</p>
<pre><code>def drop_receiving_element(element_id, options = {})
javascript_tag(drop_receiving_element_js(element_id, options).chop!)
end
</code></pre>
<p><code>javascript_tag</code> is what adds the script tags, so it looks like you should just be able to leave those out, and enter this yourself.</p>
<pre><code>drop_receiving_element_js(element_id, options).chop!
</code></pre>
<p>Note: It might be a private method, in which case just use</p>
<pre><code>send(:drop_receiving_element_js, element_id, options).chop!
</code></pre>
|
<p>I'm not sure what you want to acheve (the script helpers job <em>is</em> to write scripts in tags). But if what you want is to place the code elsewhere, for instance at the bottom of the page since loading javascript last makes the page appear faster, you could use <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html" rel="nofollow noreferrer"><code>content_for</code></a>. </p>
<pre><code><% content_for :inline_javascript do %>
<%# Script helpers here %>
<% end %>
</code></pre>
<p>then in the bottom (or wherever you want it), you place this line:</p>
<pre><code><%# Include tags for other Js code the inline scripts rely on above here %>
<%= yield :inline_javascript %>
</code></pre>
<p>This doesn't work for asyncronous content (ajax), but on the other hand the other script includes is allready loaded when you update a page with ajax content. </p>
<p>(You can write your own helper that, depending on the request type, uses the content_for variable or writes the script tag inline. I've made one before, I can try locate it if you want me to)</p>
| 41,174
|
<p>In our project we have a large number (hundreds) of FLA files created by the artists in CS3, from which we compile SWFs to use in our Flex/AS3 application.</p>
<p>As part of a streamlined build/deploy system, it would be really handy to be able to automate publishing all these FLAs, and ideally deploying the SWFs too. I found some ways to do the batch publishing from CS3 using JSFL, but was surprised to discover CS3 doesn't apparently have any command-line functionality for this?</p>
<p>This is on a Linux system for what it's worth, I don't have experience with JSFL to know if you can run scripts from the command line somehow?</p>
<p><strong>note</strong>: I should have said "Linux is preferred"... I don't use Linux but our server/build PC is Linux... I didn't realise CS3 was not compatible so I guess we can do this part on Windows.</p>
|
<p>Execute your JSFL scripts from the command line just like this:</p>
<p>on Windows: <code>"c:\program files\macromedia\flash 8\flash.exe" myscript.jsfl</code></p>
<p>on Mac: <code>open myscript.jsfl</code></p>
<p>I believe older versions of Flash ran on Wine no problem but not as sure about CS3.</p>
<p>To iterate over a batch of local files, try something like this (in JSFL):</p>
<pre><code>var importFolder = fl.browseForFolderURL('Select a folder with existing FLA files');
var importFolderContents = FLfile.listFolder(importFolder);
for (i = 0; i <importFolderContents.length; i++) {
file = importFolderContents[i];
fl.openDocument(file); // and so on
}
</code></pre>
<p>And some other methods you'll probably want to investigate are..</p>
<p><a href="http://livedocs.adobe.com/flash/8/main/00004635.html" rel="noreferrer">fl.getDocumentDOM()</a>
<a href="http://livedocs.adobe.com/flash/9.0/main/00003933.html" rel="noreferrer">document.exportSWF()</a>
<a href="http://livedocs.adobe.com/flash/9.0/main/00003968.html" rel="noreferrer">document.publish()</a>
<a href="http://livedocs.adobe.com/flash/9.0/main/00004130.html" rel="noreferrer">fl.closeDocument()</a></p>
|
<p>Yes, absolutely. In fact, I've built an end-to-end solution which, at the click of a single button, will update class files with a version time stamp, open Flash if it's not already open, open individual files for publication, signal the automation program via inter-process-communication when each file has completed publishing so you don't run into any timing issues, and deploy specific files to the web upon completion (after automatically backing them up and timestamping the filenames), and the whole process completes in under 10 seconds.</p>
<p>See my Q&A here: <a href="https://stackoverflow.com/q/23525495/88409">Automating publishing of FLA files; calling Process.Start multiple times</a></p>
| 32,804
|
<p>Elementree has become the accepted standard for interacting with xml. What is the prevalent web service/SOAP library in use today?</p>
|
<p>I'm not sure about an accepted standard, but I've found <a href="http://soapy.sourceforge.net/" rel="nofollow noreferrer">SOAPpy</a> to be fairly straight-forward and useful library for handling SOAP-based web services.</p>
<blockquote>
<p>SOAPy is a SOAP/XML Schema Library for Python. Given either a WSDL or SDL document, SOAPy discovers the published API for a web service and exposes it to Python applications as transparently as possible.</p>
</blockquote>
<p>IBM provide a <a href="http://www.ibm.com/developerworks/library/ws-pyth5/" rel="nofollow noreferrer">good walk-through and example</a> on their site for getting started with SOAPpy.</p>
<p>SOAPpy's no longer under active development, but is instead being folded into Zolera SOAP Infrastructure (ZSI) at the <a href="http://pywebsvcs.sourceforge.net/" rel="nofollow noreferrer">Python Web Services Project</a>. This project however has alos <a href="http://sourceforge.net/projects/pywebsvcs" rel="nofollow noreferrer">not seen much activity</a> since November last year.</p>
|
<p>soaplib is very easy to use and seems to be active.</p>
<p><a href="http://web.archive.org/web/20090729125144/https://wiki.github.com/jkp/soaplib/" rel="nofollow noreferrer">http://web.archive.org/web/20090729125144/https://wiki.github.com/jkp/soaplib/</a></p>
| 19,325
|
<p>Excel 2007</p>
<p>I have a row of cells with variation of numbers and letters (which all mean something.. not random.)</p>
<p>It's basically a timesheet. If they take a sick day they put in S, if they take a partial sick day they put in PS. The problem is they also put in the hours they did work too. They put it in this format: (number)/PS. </p>
<p>Now if it were just letters I could just do =countif(range,"S") to keep track of how many s / ps cells there are. How would I keep track if they are PS where it also has a number separated by a slash then PS.... I also still need to be able to use that number to add to a total. Is it even possible or will I have to format things different to be able to keep track of all this stuff.</p>
|
<p>I remember a <a href="http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic47934.aspx" rel="nofollow noreferrer">problem</a> with mysql's ADO.NET driver, where it was not playing nice with nulled date/time fields at all.</p>
<p>Even IsDBNull was throwing exception on a field with null date/time.</p>
<p>It may be still an issue.</p>
|
<p>Fixed -
It turned out to be an issue with the connection string to connect to the mySQL DB. </p>
<p>Also I didn't know that it was possible to drop a table into the DBML using the Server Explorer. All I needed to do was connect to the database then drop the table onto the DBML.</p>
| 45,724
|
<p>In many languages, assignments are legal in conditions. I never understood the reason behind this. Why would you write:</p>
<pre><code>if (var1 = var2) {
...
}
</code></pre>
<p>instead of:</p>
<pre><code>var1 = var2;
if (var1) {
...
}
</code></pre>
<p>?</p>
|
<p>It's more useful for loops than <em>if</em> statements.</p>
<pre><code>while(var = GetNext())
{
...do something with 'var'
}
</code></pre>
<p>Which would otherwise have to be written</p>
<pre><code>var = GetNext();
while(var)
{
...do something
var = GetNext();
}
</code></pre>
|
<p>The reason is:</p>
<ol>
<li><p>Performance improvement (sometimes)</p>
</li>
<li><p>Less code (always)</p>
</li>
</ol>
<p>Take an example: There is a method <code>someMethod()</code> and in an <code>if</code> condition you want to check whether the return value of the method is <code>null</code>. If not, you are going to use the return value again.</p>
<pre><code>If(null != someMethod()){
String s = someMethod();
......
//Use s
}
</code></pre>
<p>It will hamper the performance since you are calling the same method twice. Instead use:</p>
<pre><code>String s;
If(null != (s = someMethod())) {
......
//Use s
}
</code></pre>
| 18,305
|
<p>Can someone please explain how to remove the background/borders off an embedded CrystalReportViewer control in Visual Studio 2008.</p>
<p>I'm trying to remove the light gray (below the "Crystal Report" heading) and then the darker gray underneath that. I want to be left with only the white box and the report inside this.</p>
<p>This is the output I'm currently getting:</p>
<p><strong><a href="http://img411.imageshack.us/my.php?image=screenshotml3.jpg" rel="nofollow noreferrer">http://img411.imageshack.us/my.php?image=screenshotml3.jpg</a></strong></p>
<p>The HTML snippet is:</p>
<pre><code><div>
<h2>Crystal Report</h2>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
AutoDataBind="true" DisplayToolbar="False" />
</div>
</code></pre>
<p>The C# code snippet is: </p>
<pre><code>string strReportName = "CrystalReport";
string strReportPath = Server.MapPath(strReportName + ".rpt");
ReportDocument rptDocument = new ReportDocument();
rptDocument.Load(strReportPath);
CrystalReportViewer1.HasCrystalLogo = false;
CrystalReportViewer1.HasDrilldownTabs = false;
CrystalReportViewer1.HasDrillUpButton = false;
CrystalReportViewer1.HasExportButton = false;
CrystalReportViewer1.HasGotoPageButton = false;
CrystalReportViewer1.HasPageNavigationButtons = false;
CrystalReportViewer1.HasPrintButton = false;
CrystalReportViewer1.HasRefreshButton = false;
CrystalReportViewer1.HasSearchButton = false;
CrystalReportViewer1.HasToggleGroupTreeButton = false;
CrystalReportViewer1.HasToggleParameterPanelButton = false;
CrystalReportViewer1.HasZoomFactorList = false;
CrystalReportViewer1.DisplayToolbar = false;
CrystalReportViewer1.EnableDrillDown = false;
CrystalReportViewer1.BestFitPage = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
CrystalReportViewer1.BackColor = System.Drawing.Color.Red;
CrystalReportViewer1.BorderColor = System.Drawing.Color.Green;
CrystalReportViewer1.CssClass
CrystalReportViewer1.Height = 200;
CrystalReportViewer1.Width = 500;
CrystalReportViewer1.ReportSource = rptDocument;
</code></pre>
|
<p>I would put the method inside the interface and then let polymorphism decide which method to call</p>
<pre><code>interface I
{
void Method();
}
class B : I
{
public void Method() { /* previously A.Method(B) */}
}
class C : I
{
public void Method() { /* previously A.Method(C) */ }
}
class A
{
public void Method(I obj)
{
obj.Method();
}
}
</code></pre>
<p>Now when you need to add a new class, you only need to implement I.Method. You don't need to touch A.Method.</p>
|
<p>It doesn't exist in a convenient form withing C# - <a href="https://stackoverflow.com/questions/156467/switch-pattern-matching-idea">see here</a> for an idea based on F#'s pattern matching, that does exactly what you want. You can do some things with reflection to select the overload at runtime, but that will be very slow, and has severe issues if anything satisfies both overloads. If you had a return value you could use the conditional operator;</p>
<pre><code>return (I is B) ? Method((B)I) : ((I is C) ? Method((C)I) : 0);
</code></pre>
<p>Again - not pretty.</p>
| 20,859
|
<p>How does one add a comment to an MS Access Query, to provide a description of what it does?</p>
<p>Once added, how can one retrieve such comments programmatically?</p>
|
<p><strong>NOTE:</strong> Confirmed with Access 2003, don't know about earlier versions.</p>
<p>For a query in an MDB you can right-click in the query designer (anywhere in the empty space where the tables are), select Properties from the context menu, and enter text in the <em>Description</em> property. </p>
<p>You're limited to 256 characters, but it's better than nothing.</p>
<p>You can get at the description programatically with something like this:</p>
<pre><code>Dim db As Database
Dim qry As QueryDef
Set db = Application.CurrentDb
Set qry = db.QueryDefs("myQuery")
Debug.Print qry.Properties("Description")
</code></pre>
|
<p>if you are trying to add a general note to the overall object (query or table etc..)</p>
<p>Access 2016
go to navigation pane, highlight object, right click, select object / table properties, add a note in the description window i.e. inventory "table last last updated 05/31/17"</p>
| 31,594
|
<p>It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?</p>
|
<p>Use the <kbd>></kbd> command. To indent five lines, <kbd>5</kbd><kbd>></kbd><kbd>></kbd>. To mark a block of lines and indent it, <kbd>V</kbd><kbd>j</kbd><kbd>j</kbd><kbd>></kbd> to indent three lines (Vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use <kbd>></kbd><kbd>%</kbd> or from anywhere inside block use <kbd>></kbd><kbd>i</kbd><kbd>B</kbd>.</p>
<p>If you’re copying blocks of text around and need to align the indent of a block in its new location, use <kbd>]</kbd><kbd>p</kbd> instead of just <kbd>p</kbd>. This aligns the pasted block with the surrounding text.</p>
<p>Also, the <a href="http://vimdoc.sourceforge.net/htmldoc/options.html#'shiftwidth'" rel="noreferrer"><code>shiftwidth</code></a> setting allows you to control how many spaces to indent.</p>
|
<p>Suppose <code>|</code> represents the position of the cursor in Vim. If the text to be indented is enclosed in a code block like:</p>
<pre><code>int main() {
line1
line2|
line3
}
</code></pre>
<p>you can do <code>>i{</code> which means "<em>indent (<code>></code>) inside (<code>i</code>) block (<code>{</code>)</em>" and get:</p>
<pre><code>int main() {
line1
line2|
line3
}
</code></pre>
<p>Now suppose the lines are contiguous but outside a block, like:</p>
<pre><code>do
line2|
line3
line4
done
</code></pre>
<p>To indent lines 2 thru 4 you can visually select the lines and type <code>></code>. Or even faster you can do <code>>2j</code> to get:</p>
<pre><code>do
line2|
line3
line4
done
</code></pre>
<p>Note that <code>>Nj</code> means indent from current line to <code>N</code> lines below. If the number of lines to be indented is large, it could take some seconds for the user to count the proper value of <code>N</code>. To save valuable seconds you can activate the option of <em>relative number</em> with <code>set relativenumber</code> (available since Vim version 7.3).</p>
| 29,186
|
<p>Is there a framework that can be used to enable a C# Windows Service to automatically check for a newer version and upgrade itself? I can certainly write code to accomplish this, but I am looking for a framework that has already been implemented and (most importantly) tested.</p>
<p>[edit]
Here is a link to a similar question with links to modern projects that help accomplish this: <a href="https://stackoverflow.com/questions/691663/auto-update-library-for-net">Auto-update library for .NET?</a></p>
|
<p>The only way to unload types is to destroy the appdomain. To do this would require separation of your hosting layer from your executing service code - this is pretty complex. (sort of like doing keyhole surgery)</p>
<p>May be easier to either a) run a batch task or b) in-service detect updates then launch a seperate process that stops the service, updates assemblies etc. then restarts it.</p>
<p>If you're interested in the former, the MSDN patterns and practices folk wrote an app updater block that you adapt to your service.</p>
<p><a href="https://web.archive.org/web/20080506103749/http://msdn.microsoft.com/en-us/library/ms978574.aspx" rel="nofollow noreferrer">https://web.archive.org/web/20080506103749/http://msdn.microsoft.com/en-us/library/ms978574.aspx</a></p>
|
<p>Could you clarify your question a bit? I'm a bit confused, because as far as I know,
you can always overwrite the DLLs the service uses. The copy and restart of the service can easily be made part of you build process.</p>
| 13,234
|
<p>Can I run the python interpreter without generating the compiled .pyc files?</p>
|
<p>From <a href="http://docs.python.org/dev/whatsnew/2.6.html#interpreter-changes" rel="nofollow noreferrer">"What’s New in Python 2.6 - Interpreter Changes"</a>:</p>
<blockquote>
<p>Python can now be prevented from
writing .pyc or .pyo files by
supplying the <a href="http://docs.python.org/using/cmdline.html#cmdoption-B" rel="nofollow noreferrer">-B</a> switch to the Python
interpreter, or by setting the
<a href="http://docs.python.org/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE" rel="nofollow noreferrer">PYTHONDONTWRITEBYTECODE</a> environment
variable before running the
interpreter. This setting is available
to Python programs as the
<a href="http://docs.python.org/library/sys.html#sys.dont_write_bytecode" rel="nofollow noreferrer"><code>sys.dont_write_bytecode</code></a> variable, and
Python code can change the value to
modify the interpreter’s behaviour.</p>
</blockquote>
<p>So run your program as <code>python -B prog.py</code>.</p>
<p>Update 2010-11-27: Python 3.2 addresses the issue of cluttering source folders with <code>.pyc</code> files by introducing a special <code>__pycache__</code> subfolder, see <a href="http://docs.python.org/dev/whatsnew/3.2.html#pep-3147-pyc-repository-directories" rel="nofollow noreferrer">What's New in Python 3.2 - PYC Repository Directories</a>.</p>
<h4>NOTE: The default behavior is to generate the bytecode and is done for "performance" reasons (for more information see here for <a href="https://www.python.org/dev/peps/pep-0304/" rel="nofollow noreferrer">python2</a> and see here for <a href="https://www.python.org/dev/peps/pep-3147/" rel="nofollow noreferrer">python3</a>).</h4>
<ul>
<li>The generation of bytecode .pyc files is a form of <a href="https://en.wikipedia.org/wiki/Cache_(computing)" rel="nofollow noreferrer">caching</a> (i.e. greatly improves average performance).</li>
<li>Configuring python with <code>PYTHONDONTWRITEBYTECODE=1</code> can be bad for python performance (for python2 see <a href="https://www.python.org/dev/peps/pep-0304/" rel="nofollow noreferrer">https://www.python.org/dev/peps/pep-0304/</a> and for python3 see <a href="https://www.python.org/dev/peps/pep-3147/" rel="nofollow noreferrer">https://www.python.org/dev/peps/pep-3147/</a> ).</li>
<li>If you are interested in the performance impact please see here <a href="https://github.com/python/cpython" rel="nofollow noreferrer">https://github.com/python/cpython</a> .</li>
</ul>
|
<p>As far as I know python will compile all modules you "import". However python will NOT compile a python script run using: "python script.py" (it will however compile any modules that the script imports).</p>
<p>The real questions is why you don't want python to compile the modules? You could probably automate a way of cleaning these up if they are getting in the way.</p>
| 18,666
|
<p>What is the time complexity? Why?</p>
<pre><code>(define (mult a b)
(define (internal a accum)
(if (= a 1) accum
(internal (- a 1) (+ accum b))))
(internal a b))
(define (to-the-power-of m n)
(define (internal x accum)
(if (= x 0) accum
(internal (- x 1) (mult accum m))))
(internal n 1))
</code></pre>
|
<p>the time complexity for the mult part can be found like this:</p>
<p>to calculate (mult a b), (internal a accum) is called until a = 1
so we have some kind of tail recursion (loop) that iterates over a.</p>
<p>we thus know that the time complexity of (mult a b) is <strong>O(a)</strong> (= linear time complexity)</p>
<p>(to-the-power-of m n) also has an (internal x accum) definition, that also loops (until x = 0)</p>
<p>so again we have <strong>O(x)</strong> (= linear time complexity)</p>
<p><em>But</em>: we didn't take into account the time needed for the function calls of internal...<br>
In internal, we use the (mult a b) definition which is linear in time complexity so we have the following case:
in the first iteration mult is called with: (mult 1 m) --> O(1)<br>
second iteration this becomes: (mult m m) --> O(m)<br>
third iteration: (mult m² m) --> O(m*m)
and so on
It is clear that this grows until n = 0 (or in internal this becomes x = 0)</p>
<p>thus we can say that the time complexity will depend on m and n: <strong>O(m^n)</strong></p>
<p>[edit:] you can also take a look at a related question I asked earlier: <a href="https://stackoverflow.com/questions/3255/big-o-how-do-you-calculateapproximate-it">Big O, how do you calculate/approximate it?</a> which may give you a clue how you can handle the approximation more generally</p>
|
<p>Assuming addition and multiplication are both counted as a single operation, this function performs O(m^n) operations. </p>
<p>First consider the mult function. It (mult a b) will perform exactly a-1 additions. Since, the asymptotic growth is the same, lets approximate this by a, for mathematical simplicity.</p>
<p>Now for the to-the-power-of function, this performs n calls to the mult function. These calls are to (mult 1 m), yield m, then to (mult m m), yielding m^2, then to (mult m^2 m), yielding m^3 and so on upto m^n. So the total number of operations performed here is the sum m^0 + m^1 + ... + m^n. This is (m^n - 1) / (m-1) which grows as m^n.</p>
| 31,040
|
<p>In C++, is it possible to have a base plus derived class implement a single interface?</p>
<p>For example:</p>
<pre><code>class Interface
{
public:
virtual void BaseFunction() = 0;
virtual void DerivedFunction() = 0;
};
class Base
{
public:
virtual void BaseFunction(){}
};
class Derived : public Base, public Interface
{
public:
void DerivedFunction(){}
};
void main()
{
Derived derived;
}
</code></pre>
<p>This fails because Derived can not be instantiated. As far as the compiler is concerned Interface::BaseFunction is never defined.</p>
<p>So far the only solution I've found would be to declare a pass through function in Derived</p>
<pre><code>class Derived : public Base, public Interface
{
public:
void DerivedFunction(){}
void BaseFunction(){ Base::BaseFunction(); }
};
</code></pre>
<p>Is there any better solution?</p>
<hr>
<p><strong>EDIT:</strong> If it matters, here is a real world problem I had using MFC dialogs. </p>
<p>I have a dialog class (MyDialog lets say) that derives from CDialog. Due to dependency issues, I need to create an abstract interface (MyDialogInterface). The class that uses MyDialogInterface needs to use the methods specific to MyDialog, but also needs to call CDialog::SetParent. I just solved it by creating MyDialog::SetParent and having it pass through to CDialog::SetParent, but was wondering if there was a better way.</p>
|
<p>C++ doesn't notice the function inherited from Base already implements <code>BaseFunction</code>: The function has to be implemented explicitly in a class derived from <code>Interface</code>. Change it this way:</p>
<pre><code>class Interface
{
public:
virtual void BaseFunction() = 0;
virtual void DerivedFunction() = 0;
};
class Base : public Interface
{
public:
virtual void BaseFunction(){}
};
class Derived : public Base
{
public:
virtual void DerivedFunction(){}
};
int main()
{
Derived derived;
}
</code></pre>
<p>If you want to be able to get away with only implementing one of them, split <code>Interface</code> up into two interfaces: </p>
<pre><code>class DerivedInterface
{
public:
virtual void DerivedFunction() = 0;
};
class BaseInterface
{
public:
virtual void BaseFunction() = 0;
};
class Base : public BaseInterface
{
public:
virtual void BaseFunction(){}
};
class Derived : public DerivedInterface
{
public:
virtual void DerivedFunction(){}
};
class Both : public DerivedInterface, public Base {
public:
virtual void DerivedFunction(){}
};
int main()
{
Derived derived;
Base base;
Both both;
}
</code></pre>
<p>Note: main must return int<br>
Note: it's good practise to keep <code>virtual</code> in front of member functions in the derived that were virtual in the base, even if it's not strictly required.</p>
|
<p>I found one thing lacking from litb's answer. If I have a <code>Derived</code> instance, I can get a <code>DerivedInterface</code> and <code>BaseInterface</code>. But if I only have a <code>DerivedInterface</code> I can't get a <code>BaseInterface</code> since deriving <code>DerivedInterface</code> from <code>BaseInterface</code> won't work.</p>
<p>But, this whole time I've been limiting myself to compile time checking for some reason. This <code>DerivedInterface</code> works just great:</p>
<pre><code>class DerivedInterface
{
public:
virtual void DerivedFunction() = 0;
BaseInterface* GetBaseInterface()
{return dynamic_cast<BaseInterface*>(this);}
};
void main()
{
Derived derived;
DerivedInterface* derivedInterface = &derived;
derivedInterface->GetBaseInterface()->BaseFunction();
}
</code></pre>
<p>No pass through functions necessary in Derived, and everyone is happy. Sure, it's not strictly an interface anymore, but that's fine. Why didn't I think of that sooner? :)</p>
| 37,097
|
<p><strong>Facts:</strong></p>
<ol>
<li>Breaking down (or melting) plastic creates nanoparticles.<sup>1</sup></li>
<li>3D printers melt plastic.<sup>2</sup></li>
<li>Therefore, 3D printers make nanoparticles.<sup>3</sup></li>
<li>Nanoparticles are evil.<sup><em>[citation needed]</em></sup></li>
</ol>
<p>Wait, What?</p>
<hr>
<p><sub>1. <a href="https://phys.org/news/2018-12-plastic-disintegrates-nanoparticles.html" rel="nofollow noreferrer">Plastic waste disintegrates into nanoparticles</a></sub><br>
<sub>2. <a href="https://www.explainthatstuff.com/how-3d-printers-work.html" rel="nofollow noreferrer">How do 3D printers work?</a></sub><br>
<sub>3. <a href="https://www.tandfonline.com/doi/full/10.1080/02786826.2017.1342029" rel="nofollow noreferrer">Characterization of particle emissions from consumer fused deposition modeling 3D printers</a></sub></p>
<hr>
<p><em>I know</em> that 3D printers make nanoparticles. But is that actually a safety concern? There are multiple <a href="https://www.zimple3d.com/zimpure/" rel="nofollow noreferrer">products</a> on the market today that will suck up your nanoparticles for you. However, I can't see an obvious danger in the particles themselves. Who decided that these nanoparticles are bad for your health? 3D printers put out plenty of heat too, but nobody thinks that's dangerous.</p>
<p>So my question: <strong>Does anyone know of sources/research articles of the possible harmful effects of nanoparticles created by 3D printing?</strong> I'm looking for real scientific research. Thanks.</p>
|
<p>At the time of this writing (March 2019), I don't think theres any study on the health effects of nanoparticles emmitted by 3D Printers. The general consensus seems to be right now that those particles are potentially harmful, as they build up in the lungs, and therefore precautions should be taken.</p>
<p>The reason why nobody has yet determined if and how harmful they are, might be that those adverse health effects are probably long term, and hard to isolate. Plastic is everywhere today - it's not that easy to just study harmful health effects caused by 3D printers.</p>
<p>But we can say for sure that plastic in our bodies isn't ideal and can cause damage, so we should avoid it.</p>
|
<p>Perhaps FDM 3D printing does emit nanoparticles during the process of printing, but the syllogism does not prove it or even suggest it. </p>
<p>Parenthetically, your headline is not actually addressed by the body of your question. As an answerer, I have been misled by other questions which seemed clear enough from the headline, but where the question body actually posed a completely different question. </p>
<p>Double parenthetically, your final question does align with your headline. The discussion of 3D printing and the assertion that it is dangerous is not actually relevant to the question at all. It might be better to remove the references to 3D printing and post this in another SE group focused on human health.</p>
<p>The first point, that breaking down or <em>melting</em> plastic produces nano-particles is not supported by your reference. The reference refers to the mechanical breakdown of particles in a simulated oceanic environment and does not mention melting. The reference is silent on the possibility of melting producing and emitting nanoparticles.</p>
<p>In an FDM 3D printer, the melting takes place in an enclosed capsule, the hot-end. The plastic is heated to the point where the viscosity is low enough that the pressure of the unsoftened plastic filament pushes the softened material out of the hot-end through the nozzle. Upon exiting the nozzle the temperature falls, and the plastic begins to recrystallize.</p>
<p>I have seen no evidence of outgassing during printing with dry filament, other than an odor. Usually melting joins separated objects, pellets, and larger particles in a unified liquid state. </p>
<p>Without specific testing, one can not say there is no risk of nanoparticles emitted by FDM 3D printing. Ventilation remains a useful method of reducing local exposure to nanoparticles and odors. Airborne risks are one of the many risks to be considered, but I have no evidence that they are more serious than the burn risk, the fire risk, or the risk of a stroke from high blood pressure induced by failed prints.</p>
| 1,256
|
<p>We are trying to create some tests that reference an vendors custom grid. Unfortunatly QTP only recognises it as a WinObject which is quite useless. We need to be able to navigate the grid and change cell values, double click on a cell(without using X,Y co-ordinates) etc.</p>
<p>Ideally we want to get QTP to understand that this object is a grid and treat it as one.</p>
<p>Any help would be greatly appreciated.</p>
<p>Thanks</p>
<p>Jon</p>
|
<p>What vendor?</p>
<p>I have a few suggestions:</p>
<ol>
<li>Use key strokes to navigate the grid, rather than mouse clicks. Ctrl-Home to set focus to the top-left cell, then use up, down, left, right to move around. Use Enter keystroke to simulate double clicking. Often you can use Ctrl-A, Ctrl-C to copy the contents of the grid to the system clipboard, and use the clipboard API to retrieve the data.</li>
<li><p>You may be able to programmatically get/set the grid properties using the .Object property. .Object provides access to the underlying native properties and methods of the object, as opposed to the QTP methods and properties. You could do something like the following pseudo-code to set focus to a cell and change the value. Your code would differ depending on the vendor implementation. Consult the vendor's documentation to find out what methods and properties you would be able to use.</p>
<p><code>WinObject("mygrid").Object.CurRow = 1</code></p>
<p><code>WinObject("mygrid").Object.CurCol = 1</code></p>
<p><code>WinObject("mygrid").Object.Value = "my new value"</code></p></li>
</ol>
|
<p>If the grid in question happens to be a Stingray Objective Grid, QTP has plugins specifically for that.</p>
| 24,522
|
<p>To make things easier when switching between machines (my workstation at the office and my personal laptop) I have thought about trying an external hard drive to store my working directory on. Specifically I am looking at Firewire 800 drives (most are 5400 rpm 8mb cache). What I am wondering is if anyone has experience with doing this with Visual Studio projects and what sort of performance hit they see.</p>
|
<p>It depends on the size of the project. The throughput is low and the latency is high, so you're going to get hit every which way, but due to the latency you'll be hit harder if you have a lot of little files rather than a few large ones.</p>
<p>Have you considered simply carrying around a GIT or other distributed repository and updating the machine repositories as you move around? Then you can compile locally and treat the drive and a roving server. Since only changes will be moved across, it should be faster, and your code will be 'backed up' in more places.</p>
<p>If you forget the drive, it breaks, or is lost/stolen, then you can still sit down at a PC and program with no code missing if you're at the last PC you used, or very little code missing (which will be updated later with a resync anyway).</p>
<p>And it's just a hop skip and a jump away from simply using the network to move the changes between the systems if you don't want to carry the drive around later.</p>
|
<p>I use vmware and the virtual machines are on an external usb drive. Performance is fine. You might have some issues with the drive name changing - not an issue if you use virtual machines.</p>
| 8,263
|
<p>I have a gridview like below:</p>
<pre><code> <asp:GridView DataKeyNames="TransactionID"
AllowSorting="True" AllowPaging="True"ID="grvBrokerage"
runat="server" AutoGenerateColumns="False"
CssClass="datatable" Width="100%"
<Columns>
<asp:BoundField DataField="BrkgAccountNameOutput"
HeaderText="Account Name"/>
<asp:BoundField DataField="TransactionAmount"
HeaderText="Transaction Amount"
SortExpression="TransactionAmount" />
<asp:BoundField DataField="TransType"
HeaderText="Transaction Type"
SortExpression="TransType"/>
<asp:BoundField DataField="AccountBalance"
HeaderText="Account Balance"/>
<asp:BoundField DataField="CreateDt"
HeaderText="Transaction Date" />
</Columns>
</asp:GridView>
</code></pre>
<p>I have a page with a gridview and a objectdatasource control. AllowPaging and AllowSorting is enabled. Here is the method I use that gets the data and binds the objectdatasource to the grid:</p>
<pre><code> protected void BindBrokerageDetails()
{
HomePage master = (HomePage)Page.Master;
BrokerageAccount brokerageAccount = new BrokerageAccount();
brokerageAccount.UserID = new Guid(Membership.GetUser().ProviderUserKey.ToString());
ddlBrokerageDetails.DataSource = brokerageAccount.GetAll();
ddlBrokerageDetails.DataTextField = "Account Name";
ddlBrokerageDetails.DataValueField = "Account Name";
ddlBrokerageDetails.DataBind();
if (ddlBrokerageDetails.Items.Count > 0)
{
BrokerageTransactions brokerageaccountdetails = new
BrokerageTransactions();
DataSet ds = BrokerageAccount.GetBrkID2(
new Guid(Membership
.GetUser()
.ProviderUserKey
.ToString()),
ddlBrokerageDetails
.SelectedItem
.Text
.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
brokerageaccountdetails.BrokerageId = new Guid(dr["BrkrgId"].ToString());
}
ddlBrokerageDetails.SelectedItem.Value = brokerageaccountdetails.BrokerageId.ToString();
grvBrokerage.DataSource = ObjectDataSource1;
grvBrokerage.DataBind();
}
}
</code></pre>
<p>I have a sorting event, but when I check the grvBrokerage.DataSource, it is null. I am curious as to why? Here is the code for that?</p>
<pre><code> protected void grvBrokerage_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dt = grvBrokerage.DataSource as DataTable;
if (dt != null)
{
DataView dv = new DataView(dt);
dv.Sort = e.SortExpression + " " + e.SortDirection;
grvBrokerage.DataSource = dv;
grvBrokerage.DataBind();
}
}
</code></pre>
<p>Here is the ObjectDataSource declaration:</p>
<pre><code><asp:ObjectDataSource ID="ObjectDataSource1"
runat="server"
SelectMethod="GetAllWithId"
TypeName="BrokerageTransactions">
<SelectParameters>
<asp:ControlParameter
ControlID="ddlBrokerageDetails"
Name="brokid"
PropertyName="SelectedValue"
Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
</code></pre>
<p>Thanks,
X</p>
|
<p>When you are using an ObjectDataSource (or any other *DataSource), you set the DataSourceID for your GridView, not the DataSource. The DataSourceID should be whatever the ID of your ObjectDataSource is. If you provide the declaration of your ObjectDataSource, I might be able to help more.</p>
<p>As to why your DataSource is null in your Sorting event, it's because you set the DataSource, sent the page to the client, clicked on a column header, posted back to the server, and now have a brand new GridView instance that has never had its DataSource property set. The old GridView instance (and the data table you bound to) have been thrown away.</p>
|
<pre><code>Protected Sub gvRevstatus_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvRevstatus.Sorting
Dim instance As GridView = gvRevstatus Dim cmd As String
cmd = "SELECT Status,CONVERT(VARCHAR(10),StatusDate,101) AS StatusDate,RevNo,CommentBY FROM tabStatus WHERE ID =" & CInt(lblId.Text.Trim) & _
" Order by StatusDate"
dim gvtab as datatable = BOClaim.GVBoundTab(cnstr, cmd, gvstatus) ' my own classto databind
Dim dv As New DataView(gvtab)
dv.Sort = e.SortExpression
gvRevstatus.DataSource = dv
gvRevstatus.DataBind()
End Sub
</code></pre>
| 32,986
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.