instruction
stringlengths
27
22.5k
chosen
stringlengths
27
28.2k
rejected
stringlengths
19
24.9k
__index_level_0__
int64
0
10k
<p>Is there a way of getting all required assemblies (excluding the .net framework) for a .net project into a folder ready to be packaged into an <a href="http://nsis.sourceforge.net/Main_Page" rel="nofollow noreferrer">nsis</a> as setup file?</p> <p>I've tried writing a small console app that uses reflection to get a list of dlls but have got stuck with finding a foolproof way of determining if a dll is from the .net framework or not.</p> <p>The answer could be a simple switch in Visual Studio to output all dependencies, or a standalone app that can do it, or a plugin for Nsis, or some information on reflection that I've missed.</p>
<p>In Visual Studio (2005 at least - what I'm using right now), each reference that you have associated to a project has a property called "Copy Local", this can be set to true/false. When true it will copy the dll's for you into the current configuration directory.</p>
<p><a href="http://www.dependencywalker.com" rel="nofollow noreferrer">Dependency Walker</a> is what you need. Or maybe <a href="http://www.netomatix.com/Development/DependsNet.aspx" rel="nofollow noreferrer">Depends.Net</a></p>
7,525
<p>I started a print on my Monoprice Select v2 and let it run. I'm printing with Dikale PLA at 200&nbsp;&deg;C extruder and 60&nbsp;&deg;C build plate temperatures. My initial layer speed is 30mm/s then 60mm/s after that. Although the Monoprice comes with an aluminum build plate, I put on a <a href="https://rads.stackoverflow.com/amzn/click/com/B07HPXGJVT" rel="nofollow noreferrer" rel="nofollow noreferrer">FYSETC magnetic bed plate</a> which says it's suitable for PLA printing between 50&nbsp;&deg;C&nbsp;-&nbsp;80&nbsp;&deg;C.</p> <p>When I returned home, the print had been lifted off the build plate. I used a brim and even applied magigoo gluestick to help it stick but that didn't do the trick.</p> <p>I also noticed it's charred at one corner. Any idea of what this might be a symptom of?</p> <p>Here's what was printed <a href="https://i.stack.imgur.com/2eMLy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2eMLy.jpg" alt="enter image description here"></a></p>
<p>You have more than one problem going on. As for the print lifting up, that could be for a multitude of reasons. Clearly better bed adhesion is required. It also appears the printer stopped printing at one layer. Now for the charred part, I think it could've been caused by the nozzle staying in one area for too long (possibly when the printer stopped printing.). This causes the plastic touching the nozzle to overheat and burn up. The charred section can usually be pulled off pretty easily. However, since it definitely appears you have more than one issue here you should pursue some research (perhaps other questions on the site) on the matter.</p> <p>Hope this helps!</p>
<p>1) You have a layer shift. I guess the shift is caused by an <em>overheating</em> stepper driver, because it started relatively late, but could be also a mechanical issue.</p> <p>2) Print bed adhesion is a minor problem. Just test your printer with a simpler shape (large ground area).</p> <p>3) After carbonization, your nozzle might be clogged. Make sure there is an even extrusion.</p>
1,151
<p>I have used fork() in C to start another process. How do I start a new thread?</p>
<p>Since you mentioned fork() I assume you're on a Unix-like system, in which case <a href="http://en.wikipedia.org/wiki/POSIX_Threads" rel="noreferrer">POSIX threads</a> (usually referred to as pthreads) are what you want to use.</p> <p>Specifically, pthread_create() is the function you need to create a new thread. Its arguments are:</p> <pre><code>int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void * arg); </code></pre> <p>The first argument is the returned pointer to the thread id. The second argument is the thread arguments, which can be NULL unless you want to start the thread with a specific priority. The third argument is the function executed by the thread. The fourth argument is the single argument passed to the thread function when it is executed.</p>
<p>Check out the <a href="https://computing.llnl.gov/tutorials/pthreads/" rel="nofollow noreferrer">pthread</a> (POSIX thread) library.</p>
8,091
<p>I have a table containing prices for a lot of different "things" in a MS SQL 2005 table. There are hundreds of records per thing per day and the different things gets price updates at different times.</p> <pre><code>ID uniqueidentifier not null, ThingID int NOT NULL, PriceDateTime datetime NOT NULL, Price decimal(18,4) NOT NULL </code></pre> <p>I need to get today's latest prices for a group of things. The below query works but I'm getting hundreds of rows back and I have to loop trough them and only extract the latest one per ThingID. How can I (e.g. via a GROUP BY) say that I want the latest one per ThingID? Or will I have to use subqueries?</p> <pre><code>SELECT * FROM Thing WHERE ThingID IN (1,2,3,4,5,6) AND PriceDate &gt; cast( convert(varchar(20), getdate(), 106) as DateTime) </code></pre> <p><strong>UPDATE:</strong> In an attempt to hide complexity I put the ID column in a an int. In real life it is GUID (and not the sequential kind). I have updated the table def above to use uniqueidentifier.</p>
<p>I think the only solution with your table structure is to work with a subquery:</p> <pre><code>SELECT * FROM Thing WHERE ID IN (SELECT max(ID) FROM Thing WHERE ThingID IN (1,2,3,4) GROUP BY ThingID) </code></pre> <p>(Given the highest ID also means the newest price)</p> <p>However I suggest you add a "IsCurrent" column that is 0 if it's not the latest price or 1 if it is the latest. This will add the possible risk of inconsistent data, but it will speed up the whole process a lot when the table gets bigger (if it is in an index). Then all you need to do is to...</p> <pre><code>SELECT * FROM Thing WHERE ThingID IN (1,2,3,4) AND IsCurrent = 1 </code></pre> <p><strong>UPDATE</strong></p> <p>Okay, Markus updated the question to show that ID is a uniqueid, not an int. That makes writing the query even more complex.</p> <pre><code>SELECT T.* FROM Thing T JOIN (SELECT ThingID, max(PriceDateTime) WHERE ThingID IN (1,2,3,4) GROUP BY ThingID) X ON X.ThingID = T.ThingID AND X.PriceDateTime = T.PriceDateTime WHERE ThingID IN (1,2,3,4) </code></pre> <p>I'd really suggest using either a "IsCurrent" column or go with the other suggestion found in the answers and use "current price" table and a separate "price history" table (which would ultimately be the fastest, because it keeps the price table itself small).</p> <p>(I know that the ThingID at the bottom is redundant. Just try if it is faster with or without that "WHERE". Not sure which version will be faster after the optimizer did its work.)</p>
<p>maybe i missunderstood the taks but what about a: </p> <p><code>SELECT ID, ThingID, max(PriceDateTime), Price FROM Thing GROUP BY ThingID</code></p>
7,195
<p>In Delphi, I want to be able to create an private object that's associated with a class, and access it from all instances of that class. In Java, I'd use:</p> <pre><code>public class MyObject { private static final MySharedObject mySharedObjectInstance = new MySharedObject(); } </code></pre> <p>Or, if MySharedObject needed more complicated initialization, in Java I could instantiate and initialize it in a static initializer block.</p> <p>(You might have guessed... I know my Java but I'm rather new to Delphi...)</p> <p>Anyway, I don't want to instantiate a new MySharedObject each time I create an instance of MyObject, but I do want a MySharedObject to be accessible from each instance of MyObject. (It's actually logging that has spurred me to try to figure this out - I'm using Log4D and I want to store a TLogLogger as a class variable for each class that has logging functionality.)</p> <p>What's the neatest way to do something like this in Delphi?</p>
<p>Here is how I'll do that using a class variable, a class procedure and an initialization block:</p> <pre><code>unit MyObject; interface type TMyObject = class private class var FLogger : TLogLogger; public class procedure SetLogger(value:TLogLogger); class procedure FreeLogger; end; implementation class procedure TMyObject.SetLogger(value:TLogLogger); begin // sanity checks here FLogger := Value; end; class procedure TMyObject.FreeLogger; begin if assigned(FLogger) then FLogger.Free; end; initialization TMyObject.SetLogger(TLogLogger.Create); finalization TMyObject.FreeLogger; end. </code></pre>
<p>Before version 7, Delphi didn't have static variables, you'd have to use a global variable.</p> <p>To make it as private as possible, put it in the <code>implementation</code> section of your unit.</p>
9,730
<p>Terminals and shells are very powerful but can be complicated to learn, especially to get the best out of them. Does anyone know of a more GUI based command shell that helps a user or displays answers in a more friendly way? I'm aware of IPython, but even the syntax of that is somewhat convoluted, although it's a step in the right direction.</p> <p>Further to this, results could be presented graphically, e.g. wouldn't it be nice to be able to pipe file sizes into a pie chart?</p>
<p><a href="http://hotwire-shell.org" rel="noreferrer">Hotwire</a> is an attempt to combine the power of the traditional command line interface with GUI elements. So it has a GUI side, and tries to be helpful in suggesting commands, and in showing you possible matches from your history. (While there are keyboard shortcuts to do this in bash and other shells, you have to know them ...)</p> <p>You can use all your common system commands, but a number of key ones have new versions by default which use an object pipeline, and are displayed with a nice GUI view. In particular ls (aka dir) shows lists files and shows them in columns. You can sort by clicking on the column headers, double click on files to open, or double click on directories to move to that directory. The proc command allows you to right click on a process and one of the options is to kill it.</p> <p>The object pipeline works in a similar way to Microsoft Powershell, allowing commands in the pipe to access object properties directly rather than having to do text processing to extract it.</p> <p>Hotwire is cross platform (<a href="http://code.google.com/p/hotwire-shell/wiki/HotwireUnixLinux" rel="noreferrer">Linux, BSD</a>, <a href="http://code.google.com/p/hotwire-shell/wiki/HotwireWindows" rel="noreferrer">Windows</a>, <a href="http://code.google.com/p/hotwire-shell/wiki/HotwireMacOSX" rel="noreferrer">Mac</a>), though it is at an early stage of development. To learn more, install (click on the link for your platform) and work through the simple <a href="http://code.google.com/p/hotwire-shell/wiki/GettingStarted0700" rel="noreferrer">getting started</a> page.</p> <p>If you don't like hotwire, you could also look at the list of <a href="http://code.google.com/p/hotwire-shell/wiki/RelatedProjectsAndIdeas" rel="noreferrer">related projects and ideas</a> maintained on the hotwire wiki.</p>
<p>Check out <a href="http://hotwire-shell.org/" rel="nofollow noreferrer">http://hotwire-shell.org/</a></p>
5,022
<p>I'm behind a firewall at work at the moment and I was testing something that I had deployed to my website, and the work proxy seems to be blocking it somewhat.</p> <p>Basically I am getting a message of:</p> <blockquote> <p>Operation is not valid due to the current state of the object</p> </blockquote> <p>I've got it down to my proxy interferring, but I can't see any advanced settings or anything I can set up to go through my proxy to get to my service.</p> <p>I did a quick google for it, but no joy.</p> <p>Anyone found a quick way to get around it?</p>
<p>Edit, I forgot to write this part in the answer: You may need to add the web reference url to the safe list for your proxy. I am not sure what proxy you are using or if you have control of it, but this should solve your problem. If you don't have access to change the proxy, then I put a quick work around right below.</p> <p>Here's a quick work around, just use the browser to navigate to the WSDL. Grab the xml and save it as a .wsdl file on your computer you would like to generate the client on. Then use the <a href="http://shrinkster.com/11sv" rel="noreferrer">wsdl.exe</a> to generate the client pointing it to the path you saved the wsdl file.</p>
<p>Another option is to go to your application's web config or app config and add the following under the element:</p> <pre><code>&lt;system.net&gt; &lt;defaultProxy useDefaultCredentials="false"&gt; &lt;proxy usesystemdefault="true" proxyaddress="10.0.0.1" port="80" bypassonlocal="true" /&gt; &lt;/defaultProxy&gt; &lt;/system.net&gt; </code></pre> <p>You can then add the web reference in the normal way.</p>
6,460
<p>Even though <a href="http://twistedmatrix.com/pipermail/twisted-python/2004-May/007896.html" rel="noreferrer">Python</a> and <a href="http://www.reddit.com/comments/6wmum/thread_safe_ruby_on_rails_in_22_release/" rel="noreferrer">Ruby</a> have one kernel thread per interpreter thread, they have a global interpreter lock (GIL) that is used to protect potentially shared data structures, so this inhibits multi-processor execution. Even though the portions in those languajes that are written in C or C++ can be free-threaded, that's not possible with pure interpreted code unless you use multiple processes. What's the best way to achieve this? <a href="http://blogs.codehaus.org/people/tirsen/archives/001041_ruby_on_rails_and_fastcgi_scaling_using_processes_instead_of_threads.html" rel="noreferrer">Using FastCGI</a>? Creating a <a href="http://blog.innerewut.de/files/images/stage_2.png" rel="noreferrer">cluster or a farm</a> of virtualized servers? Using their Java equivalents, JRuby and Jython?</p>
<p>I'm not totally sure which problem you want so solve, but if you deploy your python/django application via an apache prefork MPM using mod_python apache will start several worker processes for handling different requests.</p> <p>If one request needs so much resources, that you want to use multiple cores have a look at <a href="http://pyprocessing.berlios.de/" rel="nofollow noreferrer">pyprocessing</a>. But I don't think that would be wise.</p>
<p>For Python, the <a href="http://pyprocessing.berlios.de/" rel="nofollow noreferrer">PyProcessing</a> project allows you to program with processes much like you would use threads. It is included in the standard library of the recently released 2.6 version as <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow noreferrer"><code>multiprocessing</code></a>. The module has many features for establishing and controlling access to shared data structures (queues, pipes, etc.) and support for common idioms (i.e. managers and worker pools).</p>
5,783
<p>This is ASP classic, not .Net. We have to get a way to SFTP into a server to upload and download a couple of files, kicked off by a user.</p> <p>What have other people used to do SFTP in ASP classic? Not necessarily opposed to purchasing a control.</p>
<p>If you have the ability to use WScript.Shell then you can just execute pscp.exe from the <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" rel="noreferrer">Putty</a> package. Obviously this is less then ideal but it will get the job done and let you use SCP/SFTP in classic ASP.</p>
<p>December 2020 :</p> <ul> <li>ASP is dead, it has been superseded by ASP .Net 18 years ago.</li> <li>At this time, the most common way to use SFTP in .Net is to use the <a href="https://github.com/sshnet/SSH.NET/" rel="nofollow noreferrer">SSH.NET NuGet package</a>.</li> </ul> <p>Maybe this question should be closed ?</p>
2,322
<p>I am trying to get the DB2 data provider from a 32-bit .Net application to connect to DB2 running as a 32-bit application on Vista 64 (is that confusing enough yet)? Unfortunately, I am getting the following error:</p> <blockquote> <p>SQL1159 Initialization error with DB2 .NET Data Provider, reason code 7, tokens 9.5.0.DEF.2, SOFTWARE\IBM\DB2\InstalledCopies</p> </blockquote> <p>There are several <a href="http://www-128.ibm.com/developerworks/forums/thread.jspa?threadID=207638&amp;tstart=45" rel="nofollow noreferrer">IBM forum posts</a> mentioning it, but little useful guidance. Has anyone experienced this before? Or do you have better ideas for fixing it?</p>
<p>Are you required to have it run as x86? I had similar issues with web apps under Visual Studio's dev web server (which is x86), but switching over to IIS (x64) worked for me. Since I was deploying to IIS x64, I called it a day at that point.</p> <p>I tried tracing with Filemon and Regmon, but didn't get any denied or missing keys errors. If I were to look again, I'd check HKLM\Software\WOW6432Node, guessing that the installer writes to the x64 HKLM\Software node, but not the x86 one.</p>
<p>I uninstalled the previous 32bit version, reinstalled as 64bit, and now I get a completely different error. Its mentioned as requiring FP2 to fix, but since I'm using Express-C, I can't install the fixpack (IBM doesn't provide fixpacks for free DB2 products). Anyway, thanks for the help. At least I can come closer to connecting now. :)</p>
4,901
<p>I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using <code>#define</code> constants like <code>M_PI</code>, or hard-coding the number in.</p> <p>The program below tests the various ways I know of. The inline assembly version is, in theory, the fastest option, though clearly not portable. I've included it as a baseline to compare against the other versions. In my tests, with built-ins, the <code>4 * atan(1)</code> version is fastest on GCC 4.2, because it auto-folds the <code>atan(1)</code> into a constant. With <code>-fno-builtin</code> specified, the <code>atan2(0, -1)</code> version is fastest.</p> <p>Here's the main testing program (<code>pitimes.c</code>):</p> <pre class="lang-c prettyprint-override"><code>#include &lt;math.h&gt; #include &lt;stdio.h&gt; #include &lt;time.h&gt; #define ITERS 10000000 #define TESTWITH(x) { \ diff = 0.0; \ time1 = clock(); \ for (i = 0; i &lt; ITERS; ++i) \ diff += (x) - M_PI; \ time2 = clock(); \ printf("%s\t=&gt; %e, time =&gt; %f\n", #x, diff, diffclock(time2, time1)); \ } static inline double diffclock(clock_t time1, clock_t time0) { return (double) (time1 - time0) / CLOCKS_PER_SEC; } int main() { int i; clock_t time1, time2; double diff; /* Warmup. The atan2 case catches GCC's atan folding (which would * optimise the ``4 * atan(1) - M_PI'' to a no-op), if -fno-builtin * is not used. */ TESTWITH(4 * atan(1)) TESTWITH(4 * atan2(1, 1)) #if defined(__GNUC__) &amp;&amp; (defined(__i386__) || defined(__amd64__)) extern double fldpi(); TESTWITH(fldpi()) #endif /* Actual tests start here. */ TESTWITH(atan2(0, -1)) TESTWITH(acos(-1)) TESTWITH(2 * asin(1)) TESTWITH(4 * atan2(1, 1)) TESTWITH(4 * atan(1)) return 0; } </code></pre> <p>And the inline assembly stuff (<code>fldpi.c</code>) that will only work for x86 and x64 systems:</p> <pre class="lang-c prettyprint-override"><code>double fldpi() { double pi; asm("fldpi" : "=t" (pi)); return pi; } </code></pre> <p>And a build script that builds all the configurations I'm testing (<code>build.sh</code>):</p> <pre><code>#!/bin/sh gcc -O3 -Wall -c -m32 -o fldpi-32.o fldpi.c gcc -O3 -Wall -c -m64 -o fldpi-64.o fldpi.c gcc -O3 -Wall -ffast-math -m32 -o pitimes1-32 pitimes.c fldpi-32.o gcc -O3 -Wall -m32 -o pitimes2-32 pitimes.c fldpi-32.o -lm gcc -O3 -Wall -fno-builtin -m32 -o pitimes3-32 pitimes.c fldpi-32.o -lm gcc -O3 -Wall -ffast-math -m64 -o pitimes1-64 pitimes.c fldpi-64.o -lm gcc -O3 -Wall -m64 -o pitimes2-64 pitimes.c fldpi-64.o -lm gcc -O3 -Wall -fno-builtin -m64 -o pitimes3-64 pitimes.c fldpi-64.o -lm </code></pre> <p>Apart from testing between various compiler flags (I've compared 32-bit against 64-bit too because the optimizations are different), I've also tried switching the order of the tests around. But still, the <code>atan2(0, -1)</code> version still comes out on top every time.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method" rel="noreferrer">Monte Carlo method</a>, as mentioned, applies some great concepts but it is, clearly, not the fastest, not by a long shot, not by any reasonable measure. Also, it all depends on what kind of accuracy you are looking for. The fastest π I know of is the one with the digits hard coded. Looking at <a href="http://functions.wolfram.com/Constants/Pi/" rel="noreferrer" title="pi">Pi</a> and <a href="http://functions.wolfram.com/PDF/Pi.pdf" rel="noreferrer" title="pi formulas">Pi[PDF]</a>, there are a lot of formulae.</p> <p>Here is a method that converges quickly — about 14 digits per iteration. <a href="http://numbers.computation.free.fr/Constants/PiProgram/pifast.html" rel="noreferrer" title="PiFast">PiFast</a>, the current fastest application, uses this formula with the FFT. I'll just write the formula, since the code is straightforward. This formula was almost found by <a href="http://numbers.computation.free.fr/Constants/Pi/piramanujan.html" rel="noreferrer">Ramanujan and discovered by Chudnovsky</a>. It is actually how he calculated several billion digits of the number — so it isn't a method to disregard. The formula will overflow quickly and, since we are dividing factorials, it would be advantageous then to delay such calculations to remove terms.</p> <p><img src="https://i.stack.imgur.com/aQMkk.gif" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/2y2l9.gif" alt="enter image description here"></p> <p>where,</p> <p><img src="https://i.stack.imgur.com/QqVnB.gif" alt="enter image description here"></p> <p>Below is the <a href="http://mathworld.wolfram.com/Brent-SalaminFormula.html" rel="noreferrer" title="Brent Salamin Formula">Brent–Salamin algorithm</a>. Wikipedia mentions that when <strong>a</strong> and <strong>b</strong> are "close enough" then <strong>(a + b)² / 4t</strong> will be an approximation of π. I'm not sure what "close enough" means, but from my tests, one iteration got 2 digits, two got 7, and three had 15, of course this is with doubles, so it might have an error based on its representation and the <em>true</em> calculation could be more accurate.</p> <pre><code>let pi_2 iters = let rec loop_ a b t p i = if i = 0 then a,b,t,p else let a_n = (a +. b) /. 2.0 and b_n = sqrt (a*.b) and p_n = 2.0 *. p in let t_n = t -. (p *. (a -. a_n) *. (a -. a_n)) in loop_ a_n b_n t_n p_n (i - 1) in let a,b,t,p = loop_ (1.0) (1.0 /. (sqrt 2.0)) (1.0/.4.0) (1.0) iters in (a +. b) *. (a +. b) /. (4.0 *. t) </code></pre> <p>Lastly, how about some pi golf (800 digits)? 160 characters!</p> <pre><code>int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);} </code></pre>
<h2>Better Approach</h2> <p>To get the output of standard constants like <strong>pi</strong> or the standard concepts, we should first go with the builtins methods available in the language that you are using. It will return a value in the fastest and best way. I am using python to run the fastest way to get the value of pi.</p> <ul> <li><strong>pi variable of the math library</strong>. The math library stores the variable pi as a constant.</li> </ul> <p>math_pi.py</p> <pre><code>import math print math.pi </code></pre> <p>Run the script with time utility of linux <code>/usr/bin/time -v python math_pi.py</code></p> <p>Output:</p> <pre><code>Command being timed: "python math_pi.py" User time (seconds): 0.01 System time (seconds): 0.01 Percent of CPU this job got: 91% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.03 </code></pre> <ul> <li><strong>Use arc cos method of math</strong></li> </ul> <p>acos_pi.py</p> <pre><code>import math print math.acos(-1) </code></pre> <p>Run the script with time utility of linux <code>/usr/bin/time -v python acos_pi.py</code></p> <p>Output:</p> <pre><code>Command being timed: "python acos_pi.py" User time (seconds): 0.02 System time (seconds): 0.01 Percent of CPU this job got: 94% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.03 </code></pre> <ul> <li><strong>use <a href="https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula" rel="nofollow noreferrer">BBP formula</a></strong></li> </ul> <p>bbp_pi.py</p> <pre><code>from decimal import Decimal, getcontext getcontext().prec=100 print sum(1/Decimal(16)**k * (Decimal(4)/(8*k+1) - Decimal(2)/(8*k+4) - Decimal(1)/(8*k+5) - Decimal(1)/(8*k+6)) for k in range(100)) </code></pre> <p>Run the script with time utility of linux <code>/usr/bin/time -v python bbp_pi.py</code></p> <p>Output:</p> <pre><code>Command being timed: "python c.py" User time (seconds): 0.05 System time (seconds): 0.01 Percent of CPU this job got: 98% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.06 </code></pre> <p><strong>So the best way is to use builtin methods provided by the language because they are the fastest and best to get the output. In python use math.pi</strong></p>
2,238
<p><a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="noreferrer">AOP</a> is an interesting programming paradigm in my opinion. However, there haven't been discussions about it yet here on stackoverflow (at least I couldn't find them). What do you think about it in general? Do you use AOP in your projects? Or do you think it's rather a niche technology that won't be around for a long time or won't make it into the mainstream (like OOP did, at least in theory ;))? </p> <p>If you do use AOP then please let us know which tools you use as well. Thanks!</p>
<p>Yes.</p> <p>Orthogonal concerns, like security, are best done with AOP-style interception. Whether that is done automatically (through something like a dependency injection container) or manually is unimportant to the end goal.</p> <p>One example: the "before/after" attributes in <a href="http://www.codeplex.com/xunit" rel="noreferrer">xUnit.net</a> (an open source project I run) are a form of AOP-style method interception. You decorate your test methods with these attributes, and just before and after that test method runs, your code is called. It can be used for things like setting up a database and rolling back the results, changing the security context in which the test runs, etc.</p> <p>Another example: the filter attributes in <a href="http://www.asp.net/mvc" rel="noreferrer">ASP.NET MVC</a> also act like specialized AOP-style method interceptors. One, for instance, allows you to say how unhandled errors should be treated, if they happen in your action method.</p> <p>Many dependency injection containers, including Castle Windsor and Unity, support this behavior either "in the box" or through the use of extensions.</p>
<p>Yes, we do use AOP in application programming . I preferably use AspectJ for integrating aop in my Spring applications. Have a look at this article for getting a broader prospective for the same.</p> <p><a href="http://codemodeweb.blogspot.in/2018/03/spring-aop-and-aspectj-framework.html" rel="nofollow noreferrer">http://codemodeweb.blogspot.in/2018/03/spring-aop-and-aspectj-framework.html</a></p>
4,098
<p>I own a DIY Hypercube Evolution equipped with Tevo Titan extruder, Clone Chimera hotend and Capricorn's High-temp PTFE tube. I use RAMPS with Mega and A4988's.</p> <p>During prints, my extruder motor randomly clicks. I touched the filament and during the clicks I'ven't felt any problems with extrusion. I looked at the motor shaft to control if it clicks at special angles or randomly, but it clicks randomly. My prints do look very good: clear and shiny.</p> <p>Do you have any suggestions? (the sound really gives me headache)</p>
<p>Even though you may have acceptable extrusion, any clicking from that area of your printer is likely to be a missed step on the extruder motor. This may be insignificant with respect to print quality, but as you suggest, it is an irritation.</p> <p>If you are confident that your nozzle is clean of debris (which is likely), you could consider to raise the nozzle temperature a few degrees. If the nozzle is not applying enough heat to the filament, it may resist being forced through and a click representing a delay, allows that much more heat to be applied.</p> <p>You should not have to increase by much, certainly no more than five degrees. It's also possible that you can slow the feed rate a bit to accomplish a similar result.</p>
<p>Even though you may have acceptable extrusion, any clicking from that area of your printer is likely to be a missed step on the extruder motor. This may be insignificant with respect to print quality, but as you suggest, it is an irritation.</p> <p>If you are confident that your nozzle is clean of debris (which is likely), you could consider to raise the nozzle temperature a few degrees. If the nozzle is not applying enough heat to the filament, it may resist being forced through and a click representing a delay, allows that much more heat to be applied.</p> <p>You should not have to increase by much, certainly no more than five degrees. It's also possible that you can slow the feed rate a bit to accomplish a similar result.</p>
971
<p>Given a Marlin firmware and a line of G-code such as the following:</p> <blockquote> <p>G1 F100 X50 Y50 Z0 E-10</p> </blockquote> <p>What defines the speed at which the stepper motor associated with the E-value is retracting? It is my understanding that the Feed Rate defines the speed of the movement (in this case 100mm/m) but I am not clear how I could accelerate a retraction? </p> <p>The reason I am asking is that I am not seeing a swift removal of material as i retract. Could the slow feed rate be the issue? I am using a pellet printer (WASP 3MT) and generating G-code from polylines on Silkworm.</p>
<p>You instruct the printer to move from a certain X-Y position instructed by the previous move, to X=50 and Y=50. While moving at a feedrate of 100 mm/min, it will also retract 10 mm of filament (if the previous extruder distance was 0) during that move. If the movement distance is large, the retraction is slow. If you started from X,Y = 49.99,49.99 it would be very fast.</p> <p>If you want a fast retraction, first move to a position, and than retract fast, so in separate commands. Do note that we usually do it the other way around: first retract fast and then move, this way there is less oozing of the nozzle.</p> <p>To sum up, in your G-code command, the speed of retraction depends on the path of travel (the length and speed defined by the feed rate <code>F</code>). If it is fast retraction you are after, you should split the command into two separate commands.</p>
<p>It seems like you are particularly talking about your extruder, please correct me if I have misread.</p> <p>In the command <code>G1 F100 X50 Y50 Z0 E-10</code>:</p> <ul> <li><code>G1</code> - move linearly</li> <li><code>F100</code> - Use a feed rate of 100 mm/minute</li> <li><code>X50 Y50 Z0</code> - tells those axes to move to (50, 50, 0) (absolute positioning)</li> <li><code>E-10</code> - tells the extruder to retract 10mm (relative positioning)</li> </ul> <p>If you are not experiencing high enough retraction speed:</p> <ul> <li>Try increasing the retraction speed in your slicer.</li> <li>Try increasing the max acceleration for the E axis using <a href="http://marlinfw.org/docs/gcode/M201.html" rel="nofollow noreferrer">M201</a> (e.g. <code>M201 E10000</code> sets to 10,000 <strong>mm/s</strong>).</li> <li>Try increasing the max feed rate for the E axis using <a href="http://marlinfw.org/docs/gcode/M203.html" rel="nofollow noreferrer">M203</a> (e.g. <code>M203 E25</code> sets to 25 <strong>mm/s</strong>).</li> </ul> <p>Notes:</p> <ul> <li>If you're able to connect to your printer over USB, and you aren't already using an interface to control it, something like <a href="http://www.pronterface.com/#download" rel="nofollow noreferrer">Pronterface</a> might make it easier to test retraction speeds.</li> <li><strong>If</strong> <a href="https://www.personalfab.it/en/downloads-2/download-info/firmware-powerwasp/" rel="nofollow noreferrer">this</a> is the correct firmware for your printer, it looks like it is able to save changed values to the EEPROM. They may be using a modified Marlin firmware. If so, EEPROM can be saved with <code>M500</code>, loaded with <code>M501</code>, and reset with <code>M502</code>.</li> <li>If your firmware limits what you can set with <code>M201</code> and <code>M203</code>, you may want to download the firmware and try to edit its maximum accel/feedrate before flashing.</li> </ul>
1,093
<p>In LINQ to SQL, is it possible to check to see if an entity is already part of the data context before trying to attach it?</p> <p>A little context if it helps...</p> <p>I have this code in my <code>global.asax</code> as a helper method. Normally, between requests, this isn't a problem. But right after signing in, this is getting called more than once, and the second time I end up trying to attach the <code>Member</code> object in the same unit of work where it was created.</p> <pre><code>private void CheckCurrentUser() { if (!HttpContext.Current.User.Identity.IsAuthenticated) { AppHelper.CurrentMember = null; return; } IUserService userService = new UserService(); if (AppHelper.CurrentMember != null) userService.AttachExisting(AppHelper.CurrentMember); else AppHelper.CurrentMember = userService.GetMember( HttpContext.Current.User.Identity.Name, AppHelper.CurrentLocation); } </code></pre>
<p>My rules:</p> <ol> <li>Don't initialize with the default values in declaration (<code>null</code>, <code>false</code>, <code>0</code>, <code>0.0</code>…).</li> <li>Prefer initialization in declaration if you don't have a constructor parameter that changes the value of the field.</li> <li>If the value of the field changes because of a constructor parameter put the initialization in the constructors.</li> <li>Be consistent in your practice (the most important rule).</li> </ol>
<p>I normally try the constructor to do nothing but getting the dependencies and initializing the related instance members with them. This will make you life easier if you want to unit test your classes.</p> <p>If the value you are going to assign to an instance variable does not get influenced by any of the parameters you are going to pass to you constructor then assign it at declaration time.</p>
4,419
<p>I saw this in <a href="https://stackoverflow.com/a/4384/697449">an answer to another question</a>, in reference to shortcomings of the Java spec:</p> <blockquote> <p>There are more shortcomings and this is a subtle topic. Check <a href="http://kiranthakkar.blogspot.com/2007/05/method-overloading-with-new-features-of.html" rel="noreferrer">this</a> out:</p> <pre><code>public class methodOverloading{ public static void hello(Integer x){ System.out.println(&quot;Integer&quot;); } public static void hello(long x){ System.out.println(&quot;long&quot;); } public static void main(String[] args){ int i = 5; hello(i); } } </code></pre> <p>Here &quot;long&quot; would be printed (haven't checked it myself), because the compiler chooses widening over auto-boxing. Be careful when using auto-boxing or don't use it at all!</p> </blockquote> <p><em>Are we sure that this is actually an example of widening instead of autoboxing, or is it something else entirely?</em></p> <p>On my initial scanning, I would agree with the statement that the output would be &quot;long&quot; on the basis of <code>i</code> being declared as a primitive and not an object. However, if you changed</p> <pre><code>hello(long x) </code></pre> <p>to</p> <pre><code>hello(Long x) </code></pre> <p>the output would print &quot;Integer&quot;</p> <p>What's really going on here? I know nothing about the compilers/bytecode interpreters for java...</p>
<p>In the first case, you have a widening conversion happening. This can be see when runinng the "javap" utility program (included w/ the JDK), on the compiled class:</p> <pre><code>public static void main(java.lang.String[]); Code: 0: iconst_ 5 1: istore_ 1 2: iload_ 1 3: i2l 4: invokestatic #6; //Method hello:(J)V 7: return } </code></pre> <p>Clearly, you see the I2L, which is the mnemonic for the widening Integer-To-Long bytecode instruction. See reference <a href="http://java.sun.com/docs/books/jvms/second_edition/html/Instructions2.doc6.html" rel="noreferrer">here</a>.</p> <p>And in the other case, replacing the "long x" with the object "Long x" signature, you'll have this code in the main method:</p> <pre><code>public static void main(java.lang.String[]); Code: 0: iconst_ 5 1: istore_ 1 2: iload_ 1 3: invokestatic #6; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 6: invokestatic #7; //Method hello:(Ljava/lang/Integer;)V 9: return } </code></pre> <p>So you see the compiler has created the instruction Integer.valueOf(int), to box the primitive inside the wrapper.</p>
<p>Another interesting thing with this example is the method overloading. The combination of type widening and method overloading only working because the compiler has to make a decision of which method to choose. Consider the following example:</p> <pre><code>public static void hello(Collection x){ System.out.println("Collection"); } public static void hello(List x){ System.out.println("List"); } public static void main(String[] args){ Collection col = new ArrayList(); hello(col); } </code></pre> <p>It doesn't use the run-time type which is List, it uses the compile-time type which is Collection and thus prints "Collection". </p> <p>I encourage your to read <a href="http://books.google.com/books?id=ZZOiqZQIbRMC" rel="nofollow noreferrer">Effective Java</a>, which opened my eyes to some corner cases of the JLS.</p>
2,691
<p>What is the normal way people writing network code in Delphi use Windows-style overlapped asynchronous socket I/O?</p> <p>Here's my prior research into this question:</p> <p>The <a href="http://indyproject.org/" rel="noreferrer">Indy</a> components seem entirely synchronous. On the other hand, while ScktComp unit does use WSAAsyncSelect, it basically only asynchronizes a BSD-style multiplexed socket app. You get dumped in a single event callback, as if you had just returned from select() in a loop, and have to do all the state machine navigation yourself.</p> <p>The .NET situation is considerably nicer, with Socket.BeginRead / Socket.EndRead, where the continuation is passed directly to Socket.BeginRead, and that's where you pick back up. A continuation coded as a closure obviously has all the context you need, and more.</p>
<p>I have found that Indy, while a simpler concept in the beginning, is awkward to manage due to the need to kill sockets to free threads at application termination. In addition, I had the Indy library stop working after an OS patch upgrade. ScktComp works well for my application.</p>
<p>Indy uses synchronous sockets because it's a simpler way of programming. The asynchronous socket blocking was something added to the winsock stack back in the Windows 3.x days. Windows 3.x did not support threads and there you couldn't do socket I/O without threads. For some additional information about why Indy uses the blocking model, please see <a href="http://www.swissdelphicenter.ch/en/showarticle.php?id=4" rel="nofollow noreferrer">this article</a>.</p> <p>The .NET Socket.BeginRead/EndRead calls are using threads, it's just managed by the Framework instead of by you.</p> <p>@Roddy, Indy 10 has been bundled with Delphi since at Delphi 2006. I found that migrating from Indy 9 to Indy 10 to be a straight forward task.</p>
5,786
<p>I just listened to the StackOverflow team's 17th podcast, and they talked so highly of <a href="http://www.asp.net/mvc/" rel="noreferrer">ASP.NET MVC</a> that I decided to check it out.</p> <p>But first, I want to be sure it's worth it. I already created a base web application (for other developers to build on) for a project that's starting in a few days and wanted to know, based on your experience, if I should take the time to learn the basics of MVC and re-create the base web application with this model.</p> <p>Are there really big pros that'd make it worthwhile?</p> <p>EDIT: It's not an existing project, it's a project about to start, so if I'm going to do it it should be now...</p> <hr> <p>I just found this</p> <blockquote> <p>It does not, however, use the existing post-back model for interactions back to the server. Instead, you'll route all end-user interactions to a Controller class instead - which helps ensure clean separation of concerns and testability (<strong>it also means no viewstate or page lifecycle with MVC based views</strong>).</p> </blockquote> <p>How would that work? No viewstate? No events?</p>
<p>If you are quite happy with WebForms today, then maybe ASP.NET MVC isn't for you.</p> <p>I have been frustrated with WebForms for a really long time. I'm definitely not alone here. The smart-client, stateful abstraction over the web breaks down severely in complex scenarios. I happen to love HTML, Javascript, and CSS. WebForms tries to hide that from me. It also has some really complex solutions to problems that are really not that complex. Webforms is also inherently difficult to test, and while you can use MVP, it's not a great solution for a web environment...(compared to MVC).</p> <p>MVC will appeal to you if... - you want more control over your HTML - want a seamless ajax experience like every other platform has - want testability through-and-through - want meaningful URLs - HATE dealing with postback &amp; viewstate issues</p> <p>And as for the framework being Preview 5, it is quite stable, the design is mostly there, and upgrading is not difficult. I started an app on Preview 1 and have upgraded within a few hours of the newest preview being available.</p>
<p>Is the fact that ASP.net MVC is only in 'Preview 5' be a cause for concern when looking into it? </p> <p>I know that StackOverflow was created using it, but is there a chance that Microsoft could implement significant changes to the framework before it is officially out of beta/alpha/preview release?</p>
4,993
<p>I want to print this <a href="https://www.thingiverse.com/thing:2213410" rel="nofollow noreferrer">heat tower calibration test</a>.</p> <p>The instructions say to change the temperature every 25 layers. It also tells me to use G-Code command <code>M104 Sxxx</code></p> <p>First, is there a way to specify this command using Ultimaker Cura?</p> <p>If not, how do I do so in the G-code file? </p> <p>I see that the G-code file is just a plain text file with a command per line presumably. Do I just insert <code>M104 S225</code> at one point and then <code>M104 S220</code>...? If so, how do I know where the 25th layer is?</p>
<p>Every time you see a Z movement that matches the layer height (eg. 0.20&nbsp;mm) you can assume that is the end/start of one "layer". It should have a line like:</p> <pre><code>;Layer count: 17 ;LAYER:0. ; mine has this as the first layer M107 G0 F2400 X67.175 Y61.730 Z0.250. ; moves to Z0.250 mm for the first layer, with layer thickness 0.25 mm </code></pre> <p>Then later:</p> <pre><code>;LAYER:1 M106 S255 G0 F2400 X78.078 Y69.627 Z0.550 ; 2nd layer. </code></pre> <p>So search for "Z" or "Layer" and once you've seen 25 of these "small" movements (comparing to previous Z movement?), insert your line of code at the end of the layer commands. Don't confuse it with large Z-movements, that may correspond to move up/retract filaments. Depending on your goals for the print, maybe you also want to insert a wait time - say a minute or two for the new temp to stabilize? Here is the line for that:</p> <pre><code>G4 P200 ; Sit still doing nothing for 200 milliseconds. </code></pre>
<p>Every time you see a Z movement that matches the layer height (eg. 0.20&nbsp;mm) you can assume that is the end/start of one "layer". It should have a line like:</p> <pre><code>;Layer count: 17 ;LAYER:0. ; mine has this as the first layer M107 G0 F2400 X67.175 Y61.730 Z0.250. ; moves to Z0.250 mm for the first layer, with layer thickness 0.25 mm </code></pre> <p>Then later:</p> <pre><code>;LAYER:1 M106 S255 G0 F2400 X78.078 Y69.627 Z0.550 ; 2nd layer. </code></pre> <p>So search for "Z" or "Layer" and once you've seen 25 of these "small" movements (comparing to previous Z movement?), insert your line of code at the end of the layer commands. Don't confuse it with large Z-movements, that may correspond to move up/retract filaments. Depending on your goals for the print, maybe you also want to insert a wait time - say a minute or two for the new temp to stabilize? Here is the line for that:</p> <pre><code>G4 P200 ; Sit still doing nothing for 200 milliseconds. </code></pre>
1,181
<p>Was wondering if there was a way to put a wildcard in the schema.ini for example [*.txt] FMT=TabDelimited</p> <p>I've got an app that is imported tab delimited files and the only place I can seem to get the FMT="TabDelimited" is in the schema.ini (doesn't work in the connection string for some reason), but I will have no idea what the filenames are other than the txt extension.</p> <p>BTW I'm connecting using an OdbcConnection and the Microsoft Text Driver.</p>
<p>I guess I could potentially rename the file temporarily to match whatever I decide to put in the schema.ini or potentially modify the schema.ini on the fly and put the correct filename in there, but I'd love to do know if there was a better way.</p>
<p>A single schema.ini file can contain multiple [fileName.txt] entries and format descriptions, (for all the files in the Directory), so you might consider creating the .ini file dynamically from the directory file names. </p>
9,931
<p>Is their any profilers that support Silverlight? I have tried ANTS (Version 3.1) without any success? Does version 4 support it? Any other products I can try?</p> <p><strong>Updated</strong> since the release of Silverlight 4, it is now possible to do full profiling on SL applications... check out <a href="http://blogs.msdn.com/seema/archive/2010/01/28/pdc-vs2010-profiling-silverlight-4.aspx" rel="noreferrer">this</a> article on the topic</p> <blockquote> <p>At PDC, I announced that Silverlight 4 came with the new CoreCLR capability of being profile-able by the VS2010 profilers: this means that for the first time, we give you the power to profile the managed and native code (user or platform) used by a Silverlight application. woohoo. kudos to the CLR team.</p> <p>Sidenote: From silverlight 1-3, one could only use things like xperf (see XPerf: A CPU Sampler for Silverlight) which is very powerful to see the layout/text/media/gfx/etc pipelines, but only gives the native callstack.)</p> </blockquote> <p>From <a href="http://blogs.msdn.com/seema" rel="noreferrer">SilverLite</a> (<a href="http://blogs.msdn.com/seema/archive/2010/01/28/pdc-vs2010-profiling-silverlight-4.aspx" rel="noreferrer">PDC video, TechEd Iceland, VS2010, profiling, Silverlight 4</a>)</p>
<p>Install XPerf and xperfview as available here: <a href="https://web.archive.org/web/20140825011849/http://blogs.msdn.com:80/b/seema/archive/2008/10/08/xperf-a-cpu-sampler-for-silverlight.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/cc305218.aspx</a></p> <p>(1) Startup your sample</p> <p>(2) xperf -on base</p> <p>(3) wait for a bit</p> <p>(4) xperf –d myprofile.etl</p> <p>(5) when this is done, set your symbol path: <pre> set _NT_SYMBOL_PATH= srv<em>C:\symbols</em><a href="http://msdl.microsoft.com/downloads/symbols" rel="nofollow noreferrer">http://msdl.microsoft.com/downloads/symbols</a></pre></p> <p>(6) xperfview myprofile.etl</p> <p>(7) Trace -&gt; Load Symbols</p> <ul> <li>Select the area of the CPU graph that you want to see</li> <li>Right-click and select Summary Table</li> </ul> <p>(8) Accept the EULA for using symbols, expand IExplore, expand agcore.dll or whatever is your top module</p>
<p><a href="http://blogs.msdn.com/seema/archive/2008/10/08/xperf-a-cpu-sampler-for-silverlight.aspx" rel="nofollow noreferrer">Here</a> is a detailed blog entry about using XPerf... Also check out <a href="http://channel9.msdn.com/pdc2008/PC06/" rel="nofollow noreferrer">this</a> video (at PDC) about profiling silverlight!!!</p>
7,978
<p>What can be a practical solution to center vertically and horizontally content in HTML that works in Firefox, IE6 and IE7?</p> <p>Some details:</p> <ul> <li><p>I am looking for solution for the entire page.</p></li> <li><p>You need to specify only width of the element to be centered. Height of the element is not known in design time.</p></li> <li><p>When minimizing window, scrolling should appear only when all white space is gone. In other words, width of screen should be represented as: </p></li> </ul> <p>"leftSpace width=(screenWidth-widthOfCenteredElement)/2"+<br> "centeredElement width=widthOfCenteredElement"+<br> "rightSpace width=(screenWidth-widthOfCenteredElement)/2" </p> <p>And the same for the height:</p> <p>"topSpace height=(screenHeight-heightOfCenteredElement)/2"+<br> "centeredElement height=heightOfCenteredElement"+<br> "bottomSpace height=(screenWidth-heightOfCenteredElement)/2"</p> <ul> <li>By practical I mean that use of tables is OK. I intend to use this layout mostly for special pages like login. So CSS purity is not so important here, while following standards is desirable for future compatibility.</li> </ul>
<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Centering&lt;/title&gt; &lt;style type="text/css" media="screen"&gt; body, html {height: 100%; padding: 0px; margin: 0px;} #outer {width: 100%; height: 100%; overflow: visible; padding: 0px; margin: 0px;} #middle {vertical-align: middle} #centered {width: 280px; margin-left: auto; margin-right: auto; text-align:center;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="outer" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt;&lt;td id="middle"&gt; &lt;div id="centered" style="border: 1px solid green;"&gt; Centered content &lt;/div&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Solution from <a href="http://community.contractwebdevelopment.com/css-vertically-horizontally-center" rel="nofollow noreferrer">community.contractwebdevelopment.com</a> also is a good one. And if you know height of your content that needs to be centered seems to be better.</p>
<p>Is this what you are trying to accomplish? If not, please explain what is different than the image below?</p> <p><img src="https://content.screencast.com/users/jessegavin/folders/Jing/media/a7adbb3d-dfc9-4f57-9cca-c47e9d399dd0/2008-09-11_1259.png" alt="alt text"></p>
7,187
<p>CSS and Javascript files don't change very often, so I want them to be cached by the web browser. But I also want the web browser to see changes made to these files without requiring the user to clear their browser cache. Also want a solution that works well with a version control system such as Subversion.</p> <hr /> <blockquote> <p>Some solutions I have seen involve adding a version number to the end of the file in the form of a query string.</p> <p>Could use the SVN revision number to automate this for you: <a href="https://stackoverflow.com/questions/2308/aspnet-display-svn-revision-number">ASP.NET Display SVN Revision Number</a></p> </blockquote> <p>Can you specify how you include the <a href="http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html" rel="noreferrer">Revision</a> variable of another file? That is in the HTML file I can include the Revision number in the URL to the CSS or Javascript file.</p> <p>In the <a href="http://svnbook.red-bean.com" rel="noreferrer">Subversion book</a> it says about Revision: &quot;This keyword describes the last known revision in which this file changed in the repository&quot;.</p> <blockquote> <p>Firefox also allows pressing <kbd>CTRL</kbd>+<kbd>R</kbd> to reload everything on a particular page.</p> </blockquote> <p>To clarify I am looking for solutions that don't require the user to do anything on their part.</p>
<p>I found that if you append the last modified timestamp of the file onto the end of the URL the browser will request the files when it is modified. For example in PHP:</p> <pre><code>function urlmtime($url) { $parsed_url = parse_url($url); $path = $parsed_url['path']; if ($path[0] == "/") { $filename = $_SERVER['DOCUMENT_ROOT'] . "/" . $path; } else { $filename = $path; } if (!file_exists($filename)) { // If not a file then use the current time $lastModified = date('YmdHis'); } else { $lastModified = date('YmdHis', filemtime($filename)); } if (strpos($url, '?') === false) { $url .= '?ts=' . $lastModified; } else { $url .= '&amp;ts=' . $lastModified; } return $url; } function include_css($css_url, $media='all') { // According to Yahoo, using link allows for progressive // rendering in IE where as @import url($css_url) does not echo '&lt;link rel="stylesheet" type="text/css" media="' . $media . '" href="' . urlmtime($css_url) . '"&gt;'."\n"; } function include_javascript($javascript_url) { echo '&lt;script type="text/javascript" src="' . urlmtime($javascript_url) . '"&gt;&lt;/script&gt;'."\n"; } </code></pre>
<p>Some solutions I have seen involve adding a version number to the end of the file in the form of a query string.</p> <pre><code>&lt;script type="text/javascript" src="funkycode.js?v1"&gt; </code></pre> <p>You could use the SVN revision number to automate this <a href="https://stackoverflow.com/questions/2308/aspnet-display-svn-revision-number">for you</a> by including the word <strong>LastChangedRevision</strong> in your html file after where v1 appears above. You must also setup your repository to do this.</p> <p>I hope this further clarifies my answer?</p> <p>Firefox also allows pressing <kbd>CTRL</kbd> + <kbd>R</kbd> to reload everything on a particular page.</p>
2,539
<p>Because Linux (and its variants) have a completely different set of fonts than Windows and Mac OS X, is there anyone with any experience of creating cross-platform font families - ideally finding equivalents to the common fonts found on the aforementioned operating systems?</p> <p>If so, what is the best route to take?</p>
<p>Here are some good up-to-date listings of the most-installed fonts for PC, Mac, and Linux:</p> <p><a href="http://www.codestyle.org/css/font-family/sampler-SansSerif.shtml" rel="nofollow noreferrer">Sans serif font sampler and survey results</a></p> <p><a href="http://www.codestyle.org/css/font-family/sampler-Serif.shtml" rel="nofollow noreferrer">Serif font sampler and survey results</a></p> <p>Hope this helps your decision!</p>
<p>TrueType Fonts (TTF) will generally work on Windows, Mac, and Linux platforms.</p> <p><a href="http://en.wikipedia.org/wiki/TrueType" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/TrueType</a></p>
5,924
<p>I've noticed that there seems to be quite a bit of hostility towards Linq To Entities particularly from the Alt.Net folks. I understand the resistance to more "drag and drop" programming, but from my understanding, Linq To Entities doesn't require it. </p> <p>We're currently using Linq to SQL, and we are using the DBML document to define it (once you get more than a dozen or so tables, the designer is pretty useless.)</p> <p>So why wouldn't the same approach work for Linq To Entities?</p>
<p>I don't think it's a hate for the <em>idea</em> of it per se. It's just that people don't like the <em>implementation</em> of it.</p> <p><a href="http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/" rel="nofollow noreferrer">http://efvote.wufoo.com/forms/ado-net-entity-framework-vote-of-no-confidence/</a></p>
<p>I would add that LTE implementation of TPT inheritance is nothing short of criminal. See my question <a href="https://stackoverflow.com/questions/4126668/when-quering-over-a-base-type-why-does-the-ef-provider-generate-all-those-union-a">here</a>.</p> <p>And while I'm at it, I believe that the many <a href="http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias=aps&amp;field-keywords=entity+framework+in+books&amp;x=0&amp;y=0" rel="nofollow noreferrer">published EF pundits</a> are at least in part complicit. I have yet to find any published material on EF that cautions against queries of base types. If I were to try it on the model that I have, SQL Server simply gives up with the exception.</p> <blockquote> <p>Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.</p> </blockquote> <p>I would love to rewrite the query, but LTE as absolved me of that burden. Thanks (^not)</p>
7,890
<p>I've created a seperate assembly with a class that is intended to be published through wmi. Then I've created a windows forms app that references that assembly and attempts to publish the class. When I try to publish the class, I get an exception of type System.Management.Instrumentation.WmiProviderInstallationException. The message of the exception says "Exception of type 'System.Management.Instrumentation.WMIInfraException' was thrown.". I have no idea what this means. I've tried .Net2.0 and .Net3.5 (sp1 too) and get the same results.</p> <p>Below is my wmi class, followed by the code I used to publish it.</p> <pre><code>//Interface.cs in assembly WMI.Interface.dll using System; using System.Collections.Generic; using System.Text; [assembly: System.Management.Instrumentation.WmiConfiguration(@"root\Test", HostingModel = System.Management.Instrumentation.ManagementHostingModel.Decoupled)] namespace WMI { [System.ComponentModel.RunInstaller(true)] public class MyApplicationManagementInstaller : System.Management.Instrumentation.DefaultManagementInstaller { } [System.Management.Instrumentation.ManagementEntity(Singleton = true)] [System.Management.Instrumentation.ManagementQualifier("Description", Value = "Obtain processor information.")] public class Interface { [System.Management.Instrumentation.ManagementBind] public Interface() { } [System.Management.Instrumentation.ManagementProbe] [System.Management.Instrumentation.ManagementQualifier("Descriiption", Value="The number of processors.")] public int ProcessorCount { get { return Environment.ProcessorCount; } } } } </code></pre> <p><BR/></p> <pre><code>//Button click in windows forms application to publish class try { System.Management.Instrumentation.InstrumentationManager.Publish(new WMI.Interface()); } catch (System.Management.Instrumentation.InstrumentationException exInstrumentation) { MessageBox.Show(exInstrumentation.ToString()); } catch (System.Management.Instrumentation.WmiProviderInstallationException exProvider) { MessageBox.Show(exProvider.ToString()); } catch (Exception exPublish) { MessageBox.Show(exPublish.ToString()); } </code></pre>
<p>To summarize, this is the final code that works:</p> <p>Provider class, in it's own assembly:</p> <pre><code>// the namespace used for publishing the WMI classes and object instances [assembly: Instrumented("root/mytest")] using System; using System.Collections.Generic; using System.Text; using System.Management; using System.Management.Instrumentation; using System.Configuration.Install; using System.ComponentModel; namespace WMITest { [InstrumentationClass(System.Management.Instrumentation.InstrumentationType.Instance)] //[ManagementEntity()] //[ManagementQualifier("Description",Value = "Obtain processor information.")] public class MyWMIInterface { //[System.Management.Instrumentation.ManagementBind] public MyWMIInterface() { } //[ManagementProbe] //[ManagementQualifier("Descriiption", Value="The number of processors.")] public int ProcessorCount { get { return Environment.ProcessorCount; } } } /// &lt;summary&gt; /// This class provides static methods to publish messages to WMI /// &lt;/summary&gt; public static class InstrumentationProvider { /// &lt;summary&gt; /// publishes a message to the WMI repository /// &lt;/summary&gt; /// &lt;param name="MessageText"&gt;the message text&lt;/param&gt; /// &lt;param name="Type"&gt;the message type&lt;/param&gt; public static MyWMIInterface Publish() { // create a new message MyWMIInterface pInterface = new MyWMIInterface(); Instrumentation.Publish(pInterface); return pInterface; } /// &lt;summary&gt; /// revoke a previously published message from the WMI repository /// &lt;/summary&gt; /// &lt;param name="Message"&gt;the message to revoke&lt;/param&gt; public static void Revoke(MyWMIInterface pInterface) { Instrumentation.Revoke(pInterface); } } /// &lt;summary&gt; /// Installer class which will publish the InfoMessage to the WMI schema /// (the assembly attribute Instrumented defines the namespace this /// class gets published too /// &lt;/summary&gt; [RunInstaller(true)] public class WMITestManagementInstaller : DefaultManagementProjectInstaller { } } </code></pre> <p>Windows forms application main form, publishes provider class:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Management; using System.Management.Instrumentation; namespace WMI { public partial class Form1 : Form { public Form1() { InitializeComponent(); } WMITest.MyWMIInterface pIntf_m; private void btnPublish_Click(object sender, EventArgs e) { try { pIntf_m = WMITest.InstrumentationProvider.Publish(); } catch (ManagementException exManagement) { MessageBox.Show(exManagement.ToString()); } catch (Exception exPublish) { MessageBox.Show(exPublish.ToString()); } } } } </code></pre> <p>Test web application, consumer:</p> <pre><code>using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Management.Instrumentation; using System.Management; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ManagementClass pWMIClass = null; pWMIClass = new ManagementClass(@"root\interiorhealth:MyWMIInterface"); lblOutput.Text = "ClassName: " + pWMIClass.ClassPath.ClassName + "&lt;BR/&gt;" + "IsClass: " + pWMIClass.ClassPath.IsClass + "&lt;BR/&gt;" + "IsInstance: " + pWMIClass.ClassPath.IsInstance + "&lt;BR/&gt;" + "IsSingleton: " + pWMIClass.ClassPath.IsSingleton + "&lt;BR/&gt;" + "Namespace Path: " + pWMIClass.ClassPath.NamespacePath + "&lt;BR/&gt;" + "Path: " + pWMIClass.ClassPath.Path + "&lt;BR/&gt;" + "Relative Path: " + pWMIClass.ClassPath.RelativePath + "&lt;BR/&gt;" + "Server: " + pWMIClass.ClassPath.Server + "&lt;BR/&gt;"; //GridView control this.gvProperties.DataSource = pWMIClass.Properties; this.gvProperties.DataBind(); //GridView control this.gvSystemProperties.DataSource = pWMIClass.SystemProperties; this.gvSystemProperties.DataBind(); //GridView control this.gvDerivation.DataSource = pWMIClass.Derivation; this.gvDerivation.DataBind(); //GridView control this.gvMethods.DataSource = pWMIClass.Methods; this.gvMethods.DataBind(); //GridView control this.gvQualifiers.DataSource = pWMIClass.Qualifiers; this.gvQualifiers.DataBind(); } } } </code></pre>
<p>I used gacutil - installutil to to test your class (as a dll). The gacutil part worked, but installutil (actually mofcomp) complained about a syntax error:</p> <p>...</p> <p>error SYNTAX 0X80044014: Unexpected character in class name (must be an identifier)</p> <p>Compiler returned error 0x80044014</p> <p>...</p> <p>So I changed the class name to 'MyInterface' the installutil part worked, but the class didn't return any instances. Finally I changed the hosting model to Network Service and got it to work.</p>
9,110
<p>What would be the best way to write Objective-C on the Windows platform?</p> <p>Cygwin and gcc? Is there a way I can somehow integrate this into Visual Studio?</p> <p>Along those lines - are there any suggestions as to how to link in and use the Windows SDK for something like this. Its a different beast but I know I can write assembly and link in the Windows DLLs giving me accessibility to those calls but I don't know how to do this without googling and getting piecemeal directions.</p> <p>Is anyone aware of a good online or book resource to do or explain these kinds of things?</p>
<p>Expanding on the two previous answers, if you just want Objective-C but not any of the Cocoa frameworks, then gcc will work on any platform. You can use it through Cygwin or get MinGW. However, if you want the Cocoa frameworks, or at least a reasonable subset of them, then GNUStep and Cocotron are your best bets.</p> <p>Cocotron implements a lot of stuff that GNUStep does not, such as CoreGraphics and CoreData, though I can't vouch for how complete their implementation is on a specific framework. Their aim is to keep Cocotron up to date with the latest version of OS X so that any viable OS X program can run on Windows. Because GNUStep typically uses the latest version of gcc, they also add in support for Objective-C++ and a lot of the Objective-C 2.0 features.</p> <p>I haven't tested those features with GNUStep, but if you use a sufficiently new version of gcc, you might be able to use them. I was not able to use Objective-C++ with GNUStep a few years ago. However, GNUStep does compile from just about any platform. Cocotron is a very mac-centric project. Although it is probably possible to compile it on other platforms, it comes XCode project files, not makefiles, so you can only compile its frameworks out of the box on OS X. It also comes with instructions on compiling Windows apps on XCode, but not any other platform. Basically, it's probably possible to set up a Windows development environment for Cocotron, but it's not as easy as setting one up for GNUStep, and you'll be on your own, so GNUStep is definitely the way to go if you're developing on Windows as opposed to just for Windows.</p> <p>For what it's worth, Cocotron is licensed under the MIT license, and GNUStep is licensed under the LGPL.</p>
<p>If you are comfortable with Visual Studio environment, </p> <p>Small project: jGRASP with gcc Large project: Cocotron </p> <p>I heard there are emulators, but I could find only Apple II Emulator <a href="http://virtualapple.org/" rel="nofollow">http://virtualapple.org/</a>. It looks like limited to games. </p>
8,076
<p>I'd like a concise introduction to the different options.</p>
<p>From <a href="http://en.wikipedia.org/wiki/Flash_video" rel="nofollow noreferrer">Wikipedia</a></p> <blockquote> <blockquote> <p><strong>Embedded in an SWF file</strong> using the Flash authoring tool (supported in Flash Player 6 and later). The entire file must be transferred before playback can begin. Changing the video requires rebuilding the SWF file.[citation needed]</p> <p><strong>Progressive download via HTTP</strong> (supported in Flash Player 7 and later). This method uses ActionScript to include an externally hosted Flash Video file client-side for playback. Progressive download has several advantages, including buffering, use of generic HTTP servers, and the ability to reuse a single SWF player for multiple Flash Video sources. Flash Player 8 includes support for random access within video files using the partial download functionality of HTTP, sometimes this is referred to as streaming. However, unlike streaming using RTMP, HTTP "streaming" does not support real-time broadcasting. Streaming via HTTP requires a custom player and the injection of specific Flash Video metadata containing the exact starting position in bytes and timecode of each keyframe. Using this specific information, a custom Flash Video player can request any part of the Flash Video file starting at a specified keyframe. For example, Google Video and Youtube support progressive downloading and can seek to any part of the video before buffering is complete. The server-side part of this "HTTP pseudo-streaming" method is fairly simple to implement, for example in PHP, as an Apache HTTPD module, or a lighttpd module. Rich Media Project provides players and Flash components compatible with "HTTP pseudo-streaming" method.</p> <p><strong>Streamed via RTMP to the Flash Player</strong> using the Flash Media Server (formerly called Flash Communication Server), VCS, ElectroServer, Wowza Pro or the open source Red5 server. As of April 2008, there are four stream recorders available for this protocol, re-encoding screencast software excluded.</p> </blockquote> </blockquote> <p>There is a useful introduction from Adobe here: <a href="http://www.adobe.com/devnet/flash/articles/video_guide_02.html" rel="nofollow noreferrer">Flash video learning guide</a></p>
<p>Further to yoavf's answer, you can also use haxevideo as an open source rtmp video streaming server.</p>
2,934
<p>I'm currently trying out db4o (the java version) and I pretty much like what I see. But I cannot help wondering how it does perform in a real live (web-)environment. Does anyone have any experiences (good or bad) to share about running db4o? </p>
<p>We run DB40 .NET version in a large client/server project.</p> <p>Our experiences is that you can potentially get much better performance than typical relational databases.</p> <p>However, you really have to tweak your objects to get this kind of performance. For example, if you've got a list containing a lot of objects, DB4O activation of these lists is slow. There are a number of ways to get around this problem, for example, by inverting the relationship.</p> <p>Another pain is activation. When you retrieve or delete an object from DB4O, by default it will activate the whole object tree. For example, loading a Foo will load Foo.Bar.Baz.Bat, etc until there's nothing left to load. While this is nice from a programming standpoint, performance will slow down the more nesting in your objects. To improve performance, you can tell DB4O how many levels deep to activate. This is time-consuming to do if you've got a lot of objects.</p> <p>Another area of pain was text searching. DB4O's text searching is far, far slower than SQL full text indexing. (They'll tell you this outright on their site.) The good news is, it's easy to setup a text searching engine on top of DB4O. On our project, we've hooked up Lucene.NET to index the text fields we want.</p> <p>Some APIs don't seem to work, such as the GetField APIs useful in applying database upgrades. (For example, you've renamed a property and you want to upgrade your existing objects in the database, you need to use these "reflection" APIs to find objects in the database. Other APIs, such as the [Index] attribute don't work in the stable 6.4 version, and you must instead specify indexes using the Configure().Index("someField"), which is not strongly typed.</p> <p>We've witnessed performance degrade the larger your database. We have a 1GB database right now and things are still fast, but not nearly as fast as when we started with a tiny database.</p> <p>We've found another issue where Db4O.GetByID will close the database if the ID doesn't exist anymore in the database.</p> <p>We've found the Native Query syntax (the most natural, language-integrated syntax for queries) is far, far slower than the less-friendly SODA queries. So instead of typing:</p> <pre><code>// C# syntax for "Find all MyFoos with Bar == 23". // (Note the Java syntax is more verbose using the Predicate class.) IList&lt;MyFoo&gt; results = db4o.Query&lt;MyFoo&gt;(input =&gt; input.Bar == 23); </code></pre> <p>Instead of that nice query code, you have to an ugly SODA query which is string-based and not strongly-typed.</p> <p>For .NET folks, they've recently introduced a LINQ-to-DB4O provider, which provides for the best syntax yet. However, it's yet to be seen whether performance will be up-to-par with the ugly SODA queries.</p> <p>DB4O support has been decent: we've talked to them on the phone a number of times and have received helpful info. Their user forums are next to worthless, however, almost all questions go unanswered. Their JIRA bug tracker receives a lot of attention, so if you've got a nagging bug, file it on JIRA on it often will get fixed. (We've had 2 bugs that have been fixed, and another one that got patched in a half-assed way.)</p> <p>If all this hasn't scared you off, let me say that we're very happy with DB4O, despite the problems we've encountered. The performance we've got has blown away some O/RM frameworks we tried. I recommend it.</p> <p><strong>update July 2015</strong> Keep in mind, this answer was written back in 2008. While I appreciate the upvotes, the world has changed since then, and this information may not be as reliable as it was when it was written.</p>
<p>Judah, it sounds like you are not using transparent activation, which is a feature of the latest production version (7.4)? Perhaps if you specified the version you are using as there may be other issues which are now resolved in the latest version?</p>
4,145
<p>In an application that heavily relies on <code>.htaccess</code> RewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is:</p> <pre><code>/appRoot/.htaccess app/ static/ </code></pre> <p>By default every request to <code>/appRoot/*</code> is being rewritten to be picked up by <code>app/webroot/index.php</code>, where it's being analysed and corresponding controller actions are being invoked. This is done by these directives in <code>.htaccess</code>:</p> <pre><code>RewriteBase /appRoot RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </code></pre> <p>I now want to exclude a few directories like static/ from this rewriting. I tried with this <em>before</em> the Cake RewriteRules:</p> <pre><code>RewriteCond $1 ^(static|otherDir).*$ [NC] RewriteRule (.*) - [L] </code></pre> <p>It works in so far that requests are no longer rewritten, but now <strong>all</strong> requests are being skipped, even legitimate Cake requests which should not match <code>^(static|otherDir).*$</code>.</p> <p>I tried several variations of these rules but can't get it to work the way I want.</p>
<p>And the correct answer iiiiis...</p> <pre><code>RewriteRule ^(a|bunch|of|old|directories).* - [NC,L] # all other requests will be forwarded to Cake RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </code></pre> <p>I still don't get why the index.php file in the root directory was called initially even with these directives in place. It is now located in</p> <pre><code>/appRoot/app/views/pages/home.ctp </code></pre> <p>and handled through Cake as well. With this in place now, I suppose this would have worked as well (slightly altered version of Mike's suggestion, untested):</p> <pre><code>RewriteCond $1 !^(a|bunch|of|old|directories).*$ [NC] RewriteRule ^(.*)$ app/webroot/$1 [L] </code></pre>
<p>Remove the [L] from the previous rules:</p> <pre><code>RewriteBase /appRoot RewriteRule ^$ app/webroot/ &amp;nbsp; &amp;nbsp; RewriteRule (.*) app/webroot/$1 </code></pre> <p>[L] means "Stop the rewriting process here and don't apply any more rewriting rules."</p>
2,533
<p>I need to periodically download, extract and save the contents of <a href="http://data.dot.state.mn.us/dds/det_sample.xml.gz" rel="noreferrer">http://data.dot.state.mn.us/dds/det_sample.xml.gz</a> to disk. Anyone have experience downloading gzipped files with C#?</p>
<p>To compress:</p> <pre><code>using (FileStream fStream = new FileStream(@"C:\test.docx.gzip", FileMode.Create, FileAccess.Write)) { using (GZipStream zipStream = new GZipStream(fStream, CompressionMode.Compress)) { byte[] inputfile = File.ReadAllBytes(@"c:\test.docx"); zipStream.Write(inputfile, 0, inputfile.Length); } } </code></pre> <p>To Decompress:</p> <pre><code>using (FileStream fInStream = new FileStream(@"c:\test.docx.gz", FileMode.Open, FileAccess.Read)) { using (GZipStream zipStream = new GZipStream(fInStream, CompressionMode.Decompress)) { using (FileStream fOutStream = new FileStream(@"c:\test1.docx", FileMode.Create, FileAccess.Write)) { byte[] tempBytes = new byte[4096]; int i; while ((i = zipStream.Read(tempBytes, 0, tempBytes.Length)) != 0) { fOutStream.Write(tempBytes, 0, i); } } } } </code></pre> <p>Taken from a post I wrote last year that shows how to decompress a gzip file using C# and the built-in GZipStream class. <a href="http://blogs.msdn.com/miah/archive/2007/09/05/zipping-files.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/miah/archive/2007/09/05/zipping-files.aspx</a></p> <p>As for downloading it, you can use the standard <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx" rel="nofollow noreferrer">WebRequest</a> or <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx" rel="nofollow noreferrer">WebClient</a> classes in .NET. </p>
<p>You can use the <code>HttpContext</code> object to download a csv.gz file</p> <p>Convert you <code>DataTable</code> into string using <code>StringBuilder</code> (<code>inputString</code>)</p> <pre><code>byte[] buffer = Encoding.ASCII.GetBytes(inputString.ToString()); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ContentType = &quot;application/zip&quot;; HttpContext.Current.Response.AddHeader(&quot;Content-Disposition&quot;, string.Format(&quot;attachment;filename={0}.csv.gz&quot;, fileName)); HttpContext.Current.Response.Filter = new GZipStream(HttpContext.Current.Response.Filter, CompressionMode.Compress); HttpContext.Current.Response.AppendHeader(&quot;Content-Encoding&quot;, &quot;gzip&quot;); using (GZipStream zipStream = new GZipStream(HttpContext.Current.Response.OutputStream, CompressionMode.Compress)) { zipStream.Write(buffer, 0, buffer.Length); } HttpContext.Current.Response.End(); </code></pre> <p>You can extract this downloaded file using 7Zip</p>
3,754
<p>If you already have a 3D printer, would you say that you have saved money on buying the printer, buying models and then printing the models, compared to buying something alike in retail?</p> <p>Would you say that saving money is an argument to buy a 3D printer?</p>
<p>I would say that the general answer to your specific question is no. If you want to justify buying a printer because of all the things you could print instead of buying that is not going to be easy. </p> <p>If however you are a DIYer and you have some CAD skills, or are willing to learn some, then consider the 3D printer as another tool you can use. There are plenty of stories about people who fixed some very expensive thing instead of having to buy a whole new one for hundreds of $/£; so if you have a specific use in mind then it may be justifiable to you.</p> <p>I have made and fixed stuff around the house, but it's often things you simply couldn't buy, or could have fixed some other way.</p> <p>There is an ever growing library of models available out there, and many are free. I recently fixed the leg on my keyboard with a printed one which I found on thingiverse, took minutes to print and the keyboard is part of a wireless set which would cost £30 to replace, so that was great but you won't normally find exactly what you want like that at this time.</p> <p>And lastly it's not plug 'n Play yet, so you need to be a tinkerer at heart to use most printers out there right now.</p>
<h1>Yes and No.</h1> <p>There are two sides of this, <strong><em>yes</em></strong> and <strong><em>no</em></strong>. Why I say <em>yes</em> is because there are little things that the 3D Printer can come in use for, like creating charger holders or just little household objects. The <em>no</em> side of this for me would be because of the cost of the filament in general and the maximum object size you can create with your 3D Printer. I know they have bigger ones out there, but you aren't going to make anything too big. Another reason it's a <em>no</em> is because of duration of time. It may save you money, but your going to be spending a lot more time and possibly more money the bigger your objects get, which is the only reason I'm not trying to get one at the moment. I'm choosing to wait until technologies advance to get my personal one, where it doesn't take over an hour to print out a keychain tag.</p> <p>So <strong><em>yes</em></strong>, you probably could save money in the long run, depending on what you create with it based on size and how much filament you use, but I'm also going to say <strong><em>no</em></strong> because of the disadvantages the 3D Printer has. I personally would wait for technology to advance in the next 5-15 years before buying one that has a lot more power than these, as the one's currently in the market are expensive.</p> <hr> <p><strong>EDIT:</strong> As I stated in my reasoning, I currently do not own a 3D Printer, but I do use one at my school for educational purposes and I do know the hassle on time and money for creating products that are relatively small in size.</p>
228
<p>Trying to use a guid as a resource id in a rest url but cant find any resource on how to. My best right now (not working though) is: <a href="http://localhost:49157/PhotogalleryDS.svc/gallery" rel="nofollow noreferrer">http://localhost:49157/PhotogalleryDS.svc/gallery</a>('1d03beb3-6d63-498b-aad7-fab0b1480996') (I've tried duouble/single quotes. And also {guid....} with braces. Still no luck.</p> <p>i only get: Syntax error '"' at position 0. </p> <p>Question is: How would I (with regard to specification) write the url for a resource where the id is a guid?</p>
<p>I figured it out!</p> <p><a href="http://localhost:49157/PhotogalleryDS.svc/photo(guid" rel="nofollow noreferrer">http://localhost:49157/PhotogalleryDS.svc/photo(guid</a>'01231cc7-1e26-4f33-9fdf-fdf7015267dd')</p> <p>This is the way</p>
<p>My best guess based on what you've written is that you're wrapping that URL in double quotes. The position 0 in that error message probably refers to the character directly before http</p>
4,648
<p>What makes a module/service/bit of application functionality a particularly good candidate for an OSGi module? </p> <p>I'm interested in using <a href="http://en.wikipedia.org/wiki/OSGi" rel="noreferrer">OSGi</a> in my applications. We're a Java shop and we use Spring pretty extensively, so I'm leaning toward using <a href="http://www.springframework.org/osgi" rel="noreferrer">Spring Dynamic Modules for OSGi(tm) Service Platforms</a>. I'm looking for a good way to incorporate a little bit of OSGi into an application as a trial. Has anyone here used this or a similar OSGi technology? Are there any pitfalls? </p> <p>@Nicolas - Thanks, I've seen that one. It's a good tutorial, but I'm looking more for ideas on how to do my first "real" OSGi bundle, as opposed to a Hello World example.</p> <p>@david - Thanks for the link! Ideally, with a greenfield app, I'd design the whole thing to be dynamic. What I'm looking for right now, though, is to introduce it in a small piece of an existing application. Assuming I can pick any piece of the app, what are some factors to consider that would make that piece better or worse as an OSGi guinea pig?</p>
<p>Well, since you can not have one part OSGi and one part non-OSGi you'll need to make your entire app OSGi. In its simplest form you make a single OSGi bundle out of your entire application. Clearly this is not a best practice but it can be useful to get a feel for deploying a bundle in an OSGi container (Equinox, Felix, Knoplerfish, etc).</p> <p>To take it to the next level you'll want to start splitting your app into components, components should typically have a set of responsibilities that can be isolated from the rest of your application through a set of interfaces and class dependencies. Identifying these purely by hand can range from rather straightforward for a well designed highly cohesive but loosely coupled application to a nightmare for interlocked source code that you are not familiar with.</p> <p>Some help can come from tools like <a href="http://clarkware.com/software/JDepend.html" rel="noreferrer">JDepend</a> which can show you the coupling of Java packages against other packages/classes in your system. A package with low efferent coupling should be easier to extract into an OSGi bundle than one with high efferent coupling. Even more architectural insight can be had with pro tools like <a href="http://www.headwaysoftware.com/products/structure101/index.php" rel="noreferrer">Structure 101</a>.</p> <p>Purely on a technical level, working daily with an application that consists of 160 OSGi bundles and using Spring DM I can confirm that the transition from "normal" Spring to Spring DM is largely pain free. The extra namespace and the fact that you can (and should) isolate your OSGi specific Spring configuration in separate files makes it even easier to have both with and without OSGi deployment scenarios.</p> <p>OSGi is a deep and wide component model, documentation I recommend:</p> <ul> <li><a href="http://www.osgi.org/Release4/Download" rel="noreferrer">OSGi R4 Specification</a>: Get the PDFs of the Core and Compendium specification, they are canonical, authoritative and very readable. Have a shortcut to them handy at all times, you will consult them.</li> <li>Read up on OSGi best practices, there is a large set of things you <strong>can</strong> do but a somewhat smaller set of things you <strong>should</strong> do and there are some things you should <strong>never do</strong> (DynamicImport: * for example). </li> </ul> <p>Some links: </p> <ul> <li><a href="http://felix.apache.org/site/presentations.data/best-practices-apachecon-20060628.pdf" rel="noreferrer">OSGi best practices and using Apache Felix</a></li> <li><a href="http://www.osgi.org/wiki/uploads/CommunityEvent2007/OSGiBestPractices.pdf" rel="noreferrer">Peter Kriens and BJ Hargrave in a Sun presentation on OSGi best practices</a> </li> <li>one key OSGi concept are Services, learn why and how they supplant the Listener pattern with the <a href="http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf" rel="noreferrer">Whiteboard pattern</a></li> <li><strike><a href="http://groups.google.com/group/spring-osgi" rel="noreferrer">The Spring DM Google Group</a> is very responsive and friendly in my experience</strike><br> <a href="http://groups.google.com/group/spring-osgi" rel="noreferrer">The Spring DM Google Group</a> is <a href="https://groups.google.com/forum/#!topic/spring-osgi/e-3gVCgl-_M" rel="noreferrer">no longer active</a> and has moved to Eclipse.org as the Gemini Blueprint project which has a forum <a href="http://www.eclipse.org/forums/index.php?t=thread&amp;frm_id=153" rel="noreferrer">here</a>.</li> </ul>
<p>I really like the <a href="http://felix.apache.org/site/tutorials-examples-and-presentations.html" rel="nofollow noreferrer">Apache Felix tutorials</a>. However, I think in general leveraging OSGi in your application isn't one of those "let's use this framework, because it's hype" decision. It's more of a design question, but then everything that OSGi gives you in terms of design, you can have with vanilla Java as well.</p> <p>As for the runtime, you cannot just add an existing application and make it OSGi enabled. It needs to be design to be dynamic. Spring DM makes it easy to hide that from you, but it's still there and you need to be aware of it.</p>
3,686
<p>There are various documents describing threading on Solaris/Linux, but nowwhere describing the Windows implementation. I have a passing interest in this, it seems strange that something so critical is (seemingly) not documented.</p> <p>Threading is not the same on different OS' - "Write Once, Run Anywhere" isn't true for threading.</p> <p>See <a href="http://java.sun.com/docs/hotspot/threads/threads.html" rel="nofollow noreferrer">http://java.sun.com/docs/hotspot/threads/threads.html</a></p>
<p>It really depends on the specific JVM implementation. I assume you're wondering about Sun's Windows JVM, and I can tell you with certainty that the Sun JVM maps a Java thread to an OS thread.</p> <p>You could try spawning up a couple of threads from Java code, open up Task Manager and see what happened.</p>
<p>That document is a little more about Solaris threading than the Java threading model. All JVMs call the native thread API of the OS they're written for so there is always one Java thread for an OS thread. The diagram in the document shows that it's not until the threads are in the OS space that they change. Each OS can handle threads in different ways for Windows specific documentation here is a good place to start: <a href="http://msdn.microsoft.com/en-us/library/ms681917(VS.85).aspx" rel="nofollow noreferrer">MSDN About Processes and Threads</a>.</p> <p>For a long time various flavours of *nix have implemented their threads with processes rather than actual threads it seems that those specific tuning parameters where there to sort of ease the transition to a newer threading model in Solaris. Which made the older model and those JVM options obsolete.</p> <p>For a list of JVM options for the HotSpot JVM you can look at: <a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp" rel="nofollow noreferrer">HotSpot VM Options</a>. A lot of these are useful for tuning long running applications but you can also get into trouble with them if you don't understand what they're doing. Also keep in mind that each implementation of the JVM can have a different set of options you won't find some of them on IBM's VM or BEA's. </p>
9,277
<p>I have an Interface called <code>IStep</code> that can do some computation (See "<a href="http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html" rel="nofollow noreferrer">Execution in the Kingdom of Nouns</a>"). At runtime, I want to select the appropriate implementation by class name.</p> <pre> // use like this: IStep step = GetStep(sName); </pre>
<p>Your question is very confusing...</p> <p>If you want to find types that implement IStep, then do this:</p> <pre><code>foreach (Type t in Assembly.GetCallingAssembly().GetTypes()) { if (!typeof(IStep).IsAssignableFrom(t)) continue; Console.WriteLine(t.FullName + " implements " + typeof(IStep).FullName); } </code></pre> <p>If you know already the name of the required type, just do this</p> <pre><code>IStep step = (IStep)Activator.CreateInstance(Type.GetType("MyNamespace.MyType")); </code></pre>
<p>Well Assembly.CreateInstance would seem to be the way to go - the only problem with this is that it needs the fully qualified name of the type, i.e. including the namespace.</p>
4,007
<p>I´m currently writing my own firmware for a custom delta printer. Therefore I also need to read G-code from programs like Slic3r. Even with an small example like an cube I´m struggling to find out where the z-coordinate is hidden in the code. Here is a small example of the code.</p> <pre><code>; generated by Slic3r 1.2.9 on 2017-02-13 at 15:08:01 ; external perimeters extrusion width = 0.50mm ; perimeters extrusion width = 0.58mm ; infill extrusion width = 0.58mm ; solid infill extrusion width = 0.58mm ; top infill extrusion width = 0.58mm M107 M104 S205 ; set temperature G28 ; home all axes G1 Z5 F5000 ; lift nozzle M109 S205 ; wait for temperature to be reached G21 ; set units to millimeters G90 ; use absolute coordinates M82 ; use absolute distances for extrusion G92 E0 G1 Z0.500 F7800.000 G1 E-2.00000 F2400.00000 G92 E0 G1 X-31.893 Y0.000 F7800.000 G1 E2.00000 F2400.00000 G1 X-31.893 Y-25.001 E3.57871 F1800.000 G1 X-31.496 Y-27.307 E3.72646 G1 X-30.350 Y-29.347 E3.87420 G1 X-28.588 Y-30.886 E4.02194 G1 X-26.413 Y-31.748 E4.16968 G1 X-25.000 Y-31.894 E4.25936 G1 X25.000 Y-31.894 E7.41663 G1 X27.306 Y-31.497 E7.56437 G1 X29.346 Y-30.351 E7.71211 F1800.000 G1 X30.885 Y-28.589 E7.85985 G1 X31.746 Y-26.414 E8.00759 G1 X31.893 Y-25.001 E8.09727 G1 X31.893 Y25.001 E11.25470 G1 X31.496 Y27.307 E11.40244 G1 X30.350 Y29.347 E11.55019 G1 X28.588 Y30.886 E11.69793 G1 X26.413 Y31.748 E11.84567 G1 X25.000 Y31.894 E11.93535 G1 X-25.000 Y31.894 E15.09262 G1 X-27.306 Y31.497 E15.24036 G1 X-29.346 Y30.351 E15.38810 G1 X-30.885 Y28.589 E15.53584 G1 X-31.746 Y26.414 E15.68358 G1 X-31.893 Y25.001 E15.77326 G1 X-31.893 Y0.075 E17.34724 G1 E15.34724 F2400.00000 G92 E0 G1 X-22.715 Y-22.716 F7800.000 G1 E2.00000 F2400.00000 G1 X22.715 Y-22.716 E4.86865 F1800.000 G1 X22.715 Y22.716 E7.73745 G1 X-22.715 Y22.716 E10.60609 G1 X-22.715 Y-22.641 E13.47016 G1 X-23.607 Y-23.609 F7800.000 G1 X23.607 Y-23.609 E16.45155 F1800.000 G1 X23.607 Y23.608 E19.43309 G1 X-23.607 Y23.608 E22.41447 G1 X-23.607 Y-23.534 E25.39128 G1 X-24.500 Y-24.501 F7800.000 G1 X24.500 Y-24.501 E28.48541 F1800.000 G1 X24.500 Y24.501 E31.57969 G1 X-24.500 Y24.501 E34.67382 G1 X-24.500 Y-24.426 E37.76336 </code></pre> <p>Here some configuration details:<br> G-code flavor: RepRap<br> Nozzle diameter: 0,5mm </p> <p>filament<br> diameter: 3mm </p> <p>general:<br> layer height: 0,4 mm<br> perimeters: 3<br> solid layers top:3 bottom :3 </p> <p><a href="http://pastebin.com/YW05y3ze" rel="noreferrer">Here</a> is the full G-code</p>
<p>It isn't hidden at all. It's just that the Z-axis position only changes with each layer change, so the Z coordinate is only passed at layer change. On line 17 of your example G-code, it starts the first layer at Z=0.5mm:</p> <pre><code>G1 Z0.500 F7800.000 </code></pre> <p>The next time you should expect Z to appear is on the next layer.</p>
<p>It isn't hidden at all. It's just that the Z-axis position only changes with each layer change, so the Z coordinate is only passed at layer change. On line 17 of your example G-code, it starts the first layer at Z=0.5mm:</p> <pre><code>G1 Z0.500 F7800.000 </code></pre> <p>The next time you should expect Z to appear is on the next layer.</p>
518
<p>I am writing a basic word processing application and am trying to settle on a native "internal" format, the one that my code parses in order to render to the screen. I'd like this to be XML so that I can, in the future, just write XSLT to convert it to ODF or XHTML or whatever.</p> <p>When searching for existing standards to use, the only one that looks promising is ODF. But that looks like massive overkill for what I need. All I need is paragraph tags, font selection, font size &amp; decoration...that's pretty much it. It would take me a long time to implement even a minimal ODF renderer, and I'm not sure it's worth the trouble.</p> <p>Right now I'm thinking of making my own XML format, but that's not really good practice. Better to use a standard, especially since then I can probably find the XSLTs I might need in the future already written.</p> <p>Or should I just bite the bullet and implement ODF?</p> <p><strong>EDIT: Regarding the Answer</strong></p> <p>I knew about XSL-FO before, but due to the weight of the spec hadn't really consdiered it. But you're right, a subset would give me everything I need to work with and room to grow. Thanks so much the reminder.</p> <p>Plus, by including a rendering library like FOP or RenderX, I get PDF generation for free. Not bad...</p>
<p>As you are sure about needing to represent the <em>presentational</em> side of things, it may be worth looking at the <a href="http://www.w3.org/TR/xsl/" rel="noreferrer">XSL-FO</a> W3C Recommendation. This is a full-blown page description language and the (deeply unfashionable) other half of the better-known XSLT.</p> <p>Clearly the whole thing is anything but "lightwight", but if you just incorporated a very limited subset - which could even just be (to match your spec of "paragraph tags, font selection, font size &amp; decoration") <a href="http://www.w3.org/TR/xsl/#fo_block" rel="noreferrer">fo:block</a> and the <a href="http://www.w3.org/TR/xsl/#common-font-properties" rel="noreferrer">common font properties</a>, something like:</p> <pre><code>&lt;yourcontainer xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt; &lt;fo:block font-family="Arial, sans-serif" font-weight="bold" font-size="16pt"&gt;Example Heading&lt;/fo:block&gt; &lt;fo:block font-family="Times, serif" font-size="12pt"&gt;Paragraph text here etc etc...&lt;/fo:block&gt; &lt;/yourcontainer&gt; </code></pre> <p>This would perhaps have a few advantages over just rolling your own. There's an open specification to work from, and all that implies. It reuses CSS properties as XML attributes (in a similar manner to SVG), so many of the formatting details will seem somewhat familiar. You'd have an upgrade path if you later decided that, say, intelligent paging was a must-have feature - including more sections of the spec as they become relevant to your application.</p> <p>There's one other thing you might get from investigating XSL-FO - seeing how even just-doing-paragraphs-and-fonts can be horrendously complicated. Trying to do text layout and line breaking 'The Right Way' for various different languages and use cases seems very daunting to me. </p>
<p>XML is an <em>external</em> format, not <em>internal</em>.</p> <p>What's wrong with <a href="http://www.w3.org/TR/xhtml1/" rel="nofollow noreferrer">XHTML</a>? It's simple and it's ubiquitous (at least HTML is). Your implementation would be easy to debug, and your users will be eternally greatful.</p>
5,113
<p>In C, what is the difference between using <code>++i</code> and <code>i++</code>, and which should be used in the incrementation block of a <code>for</code> loop?</p>
<ul> <li><p><code>++i</code> will increment the value of <code>i</code>, and then return the incremented value.</p> <pre><code> i = 1; j = ++i; (i is 2, j is 2) </code></pre></li> <li><p><code>i++</code> will increment the value of <code>i</code>, but return the original value that <code>i</code> held before being incremented.</p> <pre><code> i = 1; j = i++; (i is 2, j is 1) </code></pre></li> </ul> <p>For a <code>for</code> loop, either works. <code>++i</code> seems more common, perhaps because that is what is used in <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" rel="noreferrer">K&amp;R</a>.</p> <p>In any case, follow the guideline "prefer <code>++i</code> over <code>i++</code>" and you won't go wrong.</p> <p>There's a couple of comments regarding the efficiency of <code>++i</code> and <code>i++</code>. In any non-student-project compiler, there will be no performance difference. You can verify this by looking at the generated code, which will be identical.</p> <p>The efficiency question is interesting... here's my attempt at an answer: <a href="https://stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i">Is there a performance difference between i++ and ++i in C?</a></p> <p>As <a href="https://stackoverflow.com/users/2150/on-freund">@OnFreund</a> notes, it's different for a C++ object, since <code>operator++()</code> is a function and the compiler can't know to optimize away the creation of a temporary object to hold the intermediate value.</p>
<p><em>a=i++</em> means <em>a</em> contains the current <em>i</em> value.</p> <p><em>a=++i</em> means <em>a</em> contains the incremented <em>i</em> value.</p>
4,449
<p>Recently I've been having trouble printing properly on my Creality Ender-3 printer. I ran a pretty long print (approx. 15 hours) that turned out really well. I then started printing an attachment for the original print and saw that it was printing layers that were extremely thin. </p> <p>I first scraped off the excess filament left on the extruder nozzle. Then, I heated up the bed and rubbed off the layer with alcohol. I tried printing it again but it still didn't print right.</p> <p>Thin layer<br> <a href="https://i.stack.imgur.com/z4wh5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z4wh5.jpg" alt="Thin layer"></a></p> <p>Weird thing<br> <a href="https://i.stack.imgur.com/jUTgb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jUTgb.jpg" alt="Weird thing"></a></p> <p>From the images above, you can tell it's noticeably hard to see the layer, which shows just how thin it is. </p> <p>I sliced the model in Ultimaker Cura. I set the layer height to 0.15&nbsp;mm. I've printed models before with this height but the layer wasn't transparent. </p> <p>What should I do to fix this issue?</p>
<p>You need to level you bed. Thin prints happen when the extruder is too low and is printing too close to the bed.</p> <p><a href="https://i.stack.imgur.com/ybFIO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ybFIO.png" alt="Example of printing levels"></a></p> <p>Download the following test codes from this address:</p> <p><a href="https://www.chepclub.com/bed-level.html" rel="nofollow noreferrer">https://www.chepclub.com/bed-level.html</a></p> <p>1) The first code is the most important you will want to run moves the extruder to five points on your board - Front Left and Right, Back Left and Right, and Center. Using a folded piece of paper - I use a business card - drag the paper under extruder of each of the four corners. You want to make sure you get a bit of drag when pulling out the paper/card. If you feel have enough of a gap that you can run put the paper/card under the extruder and that you feel a bit of tug when pulling it out. It runs the middle last - if you are having issue with the drag, adjust all four corners slowly until it is right.</p> <p>2) The second runs the extruder in a square pattern on your board. You simply want to run your finger of the print - if it sticks to the bed, you are good - if it doesn't, adjust your corners up and keep testing.</p>
<p>If your first layer is more thin than you expect it to be, the bed is too close to the nozzle. Note that you need to check the level an bed-to-nozzle distance once every few prints. Also, the first layer shouldn't be a too thin layer, the Cura default for a 0.4&nbsp;mm nozzle is about 0.28&nbsp;mm. Personally, I always use 0.2&nbsp;mm.</p> <p>The best solution is to re-slice the model with a thicker first layer. Next, re-level the bed to the proper distance of an A4/US Letter printing paper. You should feel some drag when you pull it between nozzle and bed.</p> <p>Other solutions that also work include the redefinition of the Z=0 level, but this is not advised. Please fix the hardware.</p>
1,594
<p>There doesn't seem to be a way to change the padding (or row height) for all rows in a .NET ListView. Does anybody have an elegant hack-around?</p>
<p>I know this post is fairly old, however, if you never found the best option, I've got a <a href="http://qdevblog.blogspot.co.uk/2011/11/c-listview-item-spacing.html">blog post</a> that may help, it involves utilizing LVM_SETICONSPACING. </p> <p><strong>According to my blog,</strong></p> <p>Initially, you'll need to add:</p> <pre><code>using System.Runtime.InteropServices; </code></pre> <p>Next, you'll need to import the DLL, so that you can utilize SendMessage, to modify the ListView parameters.</p> <pre><code>[DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); </code></pre> <p>Once that is complete, create the following two functions:</p> <pre><code>public int MakeLong(short lowPart, short highPart) { return (int)(((ushort)lowPart) | (uint)(highPart &lt;&lt; 16)); } public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding) { const int LVM_FIRST = 0x1000; const int LVM_SETICONSPACING = LVM_FIRST + 53; SendMessage(listview.Handle, LVM_SETICONSPACING, IntPtr.Zero, (IntPtr)MakeLong(leftPadding, topPadding)); } </code></pre> <p>Then to use the function, just pass in your ListView, and set the values. In the example, 64 pixels is the image width, and 32 pixels is my horizontal spacing/padding, 100 pixels is the image height, and 16 pixels is my vertical spacing/padding, and both parameters require a minimum of 4 pixels.</p> <pre><code>ListViewItem_SetSpacing(this.listView1, 64 + 32, 100 + 16); </code></pre>
<p>A workaround is to use an ImageList that is as tall as you want the items to be. Just fill a blank image with the background color. You can even make the image 1 wide so as to not take much space horizontally.</p>
8,226
<p><strong>Backstory:</strong> Like <a href="https://3dprinting.stackexchange.com/search?q=build+plate+sticking">quite a lot of people here</a>, I'm having problems with parts adhering to the build plate of a resin printer. I've tried everything that I can think of: cleaning &amp; re-sanding the buildplate at 80 grit, levelling the plate with and without a sheet of paper between the plate and LCD, warm resin, and silicone spray on the FEP.</p> <hr /> <p>In <a href="https://3dprinting.stackexchange.com/a/6220">the answer</a> to <a href="https://3dprinting.stackexchange.com/q/4353">this question</a>, <a href="https://3dprinting.stackexchange.com/users/11171/michael-wooten">Michael Wooten</a> says:</p> <blockquote> <p><strong>PRO TIP to improve bed adhesion</strong>: apply a thin layer of resin to the build platform before you start to print. I have not any failed prints after I started coating the plate with resin.</p> </blockquote> <p>I was wondering if there was any clarification on this layer of resin:</p> <ul> <li>Should it be cured, partially cured, or left alone?</li> <li>How thick should it be?</li> </ul> <p>Also, is there any known methodology? If I paint some resin onto the build plate and cure with a UV lamp, I worry that the layer won't be particularly flat. I thought about using the &quot;cleaning&quot; function on the printer to shine UV light through, but it would also cure area between the edge of the build plate and the tank.</p> <p>Any tips on this exact method of making prints stick to the plate would be greatly appreciated!</p> <hr /> <p><strong>Update:</strong></p> <p>I tried again, and it still didn't work.</p> <p>I left a thin film of resin on the build plate from the previous failed print, and cured it for a minute or two until it felt tacky. The resin was still warm from last print, so I ran again (after removing the failed pancakes of course) and after a few hours I could see that nothing had printed this time either. The irritating bit is that the pancakes slide off the FEP pretty easily!</p>
<p>The whole reason to pre-coat the plate with <strong>liquid</strong> resin is to ensure, that no air bubbles are left under it and prevent contact of the plate to the resin.</p> <p>A layer of cured resin throws off your 0.</p>
<p>According to Uncle Jessy (<a href="https://www.youtube.com/watch?v=8SWGpY3LlX0" rel="nofollow noreferrer">see Youtube channel</a>), you simply need to pour some liquid resin over the build plate and then leave it for a couple of minutes for the worst to drip off. No</p> <p>He also recommends that the resin should be kept at a warm room temperature and that the bottle be thoroughly shaken before pouring it onto the build plate or into the resin vat.</p> <p>He also recommends that resin should not be left to sit in the vat for more than a couple of days as it can settle and separate.</p>
2,039
<p>Jeff mentioned in one of the podcasts that one of the things he always does is put in instrumentation for database calls, so that he can tell what queries are causing slowness etc. This is something I've measured in the past using SQL Profiler, but I'm interested in what strategies other people have used to include this as part of the application.</p> <p>Is it simply a case of including a timer across each database call and logging the result, or is there a 'neater' way of doing it? Maybe there's a framework that does this for you already, or is there a flag I could enable in e.g. Linq-to-SQL that would provide similar functionality.</p> <p>I mainly use c# but would also be interested in seeing methods from different languages, and I'd be more interested in a 'code' way of doing this over a db platform method like SQL Profiler.</p>
<p>If a query is more then just a simple SELECT on a single table I always run it through EXPLAIN if I am on MySQL or PostgreSQL. If you are using SQL Server then Management Studio has a Display Estimated Execution Plan which is essentially the same. It is useful to see how the engine will access each table and what indexes it will use. Sometimes it will surprise you.</p>
<p>If you're writing queries in SQL Management Studio you can enter: <code>SET STATISTICS TIME ON</code> and SQl Server will tell you how long the individual parts of a query took to parse, compile and execute. You might be able to log this information by handling the InfoMessage event of the SqlConnection class (but I think using the SQL Profiler is much easier.)</p>
3,020
<p>Other than Notepad++, what text editor do you use to program in Windows? </p>
<p>Another vote for <strong>gvim</strong> (<a href="http://www.vim.org/about.php" rel="nofollow noreferrer">about</a>, <a href="http://www.vim.org/download.php#pc" rel="nofollow noreferrer">download</a>). I think once you learn the keystrokes to control it, you won't want to use anything else.</p> <p>Plus, there is the added benefit of being able to use it on just about any platform, including the nice Windows port.</p> <p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/GVim-screenshot.png/800px-GVim-screenshot.png" alt="alt text"></p>
<p>No <a href="http://www.eclipse.org/" rel="nofollow noreferrer">Eclipse</a> in the list !!!</p>
3,498
<p>I've got a Prusa i3 MK3. I have printed with PLA, PETG and tried HIPS. Haven't had any clogs with PLA and PETG, but with HIPS I've got a weird problem.</p> <p>My first three test prints in HIPS went fine, but then I got a very bad clog (required total disassembly of the extruder) twice. And every time, it was at the same moment during a print. The object I was printing was a hollow cylinder. The walls were about 5 mm thick, getting thinner near the top edge. At the moment the walls started getting thinner, the problems started.</p> <p>I've read that HIPS can clog if the filament moves too slow through the hotend. At the moment the clog occurred, the printer was printing a very narrow part, and the extruder had to move around a lot. Is it possible that, at that moment, the filament moves too slow and the problems starts? I have also printed two copies of the object in a single run, and then the problem didn't occur.</p> <p>I hope my explanation makes sense, but here's what it comes down to: Does HIPS clog easily when the filament moves too slow, and if it does, what can I do to solve this?</p>
<p>This has been sitting for a long time without an answer, so let me answer with an experience I've had with PETG rather than HIPS. </p> <p>PETG seems to be a relatively soft plastic. It isn't soft like TPU, but it is softer than PLA or ABS. The HIPS filament (which I have but haven't used) appears to also be softer, so it is possible that my PETG problem could relate to your HIPS problem.</p> <p>I was printing and re-printing an object with PETG that had worked fine with PLA. Three times in a row, I got a filament jam in about the same place. </p> <p>The problem was that the filament was retracting, returning, retracting, and returning many times within a very small amount of extruded plastic. My extruder was set for high pressure between the drive roller and the idler. When the filament went back and forth through the extruder, it flattened enough that it would jam from being too wide to fit through the next stage (in my case, a Bowden tube).</p> <p>When I reduced the compression of the filament in the extruder, the problem stopped. I also reduced the retraction distance, and increased the minimum travel before the slicer would do a retract. Both were intended to reduce the number of times any single bit of filament would pass through the rollers.</p>
<p>HIPS does better with a wider nozzle; try a 1mm nozzle.</p>
920
<p>I've worked on a number of different embedded systems. They have all used <code>typedef</code>s (or <code>#defines</code>) for types such as <code>UINT32</code>.</p> <p>This is a good technique as it drives home the size of the type to the programmer and makes you more conscious of chances for overflow etc.</p> <p>But on some systems you know that the compiler and processor won't change for the life of the project.</p> <p>So what should influence your decision to create and enforce project-specific types?</p> <p>EDIT I think I managed to lose the gist of my question, and maybe it's really two.</p> <p>With embedded programming you may need types of specific size for interfaces and also to cope with restricted resources such as RAM. This can't be avoided, but you can choose to use the basic types from the compiler.</p> <p>For everything else the types have less importance.<br> You need to be careful not to cause overflow and may need to watch out for register and stack usage. Which may lead you to <code>UINT16</code>, <code>UCHAR</code>. Using types such as <code>UCHAR</code> can add compiler 'fluff' however. Because registers are typically larger, some compilers may add code to force the result into the type.<br> <PRE>i++;</PRE> can become <PRE>ADD REG,1 AND REG, 0xFF</PRE> which is unecessary.</p> <p>So I think my question should have been :-</p> <p>given the constraints of embedded software what is the best policy to set for a project which will have many people working on it - not all of whom will be of the same level of experience.</p>
<p>I use type abstraction very rarely. Here are my arguments, sorted in increasing order of subjectivity:</p> <ol> <li><p>Local variables are different from struct members and arrays in the sense that you want them to fit in a register. On a 32b/64b target, a local <code>int16_t</code> can make code slower compared to a local int since the compiler will have to add operations to /force/ overflow according to the semantics of <code>int16_t</code>. While C99 defines an <code>intfast_t</code> typedef, AFAIK a plain int will fit in a register just as well, and it sure is a shorter name.</p></li> <li><p>Organizations which like these typedefs almost invariably end up with several of them (<code>INT32, int32_t, INT32_T</code>, ad infinitum). Organizations using built-in types are thus better off, in a way, having just one set of names. I wish people used the typedefs from stdint.h or windows.h or anything existing; and when a target doesn't have that .h file, how hard is it to add one?</p></li> <li><p>The typedefs can theoretically aid portability, but I, for one, never gained a thing from them. Is there a useful system you can port from a 32b target to a 16b one? Is there a 16b system that isn't trivial to port to a 32b target? Moreover, if most vars are ints, you'll actually gain something from the 32 bits on the new target, but if they are <code>int16_t</code>, you won't. And the places which are hard to port tend to require manual inspection anyway; before you try a port, you don't know where they are. Now, if someone thinks it's so easy to port things if you have typedefs all over the place - when time comes to port, which happens to few systems, write a script converting all names in the code base. This should work according to the "no manual inspection required" logic, and it postpones the effort to the point in time where it actually gives benefit.</p></li> <li><p>Now if portability may be a theoretical benefit of the typedefs, <i>readability</i> sure goes down the drain. Just look at stdint.h: <code>{int,uint}{max,fast,least}{8,16,32,64}_t</code>. Lots of types. A program has lots of variables; is it really that easy to understand which need to be <code>int_fast16_t</code> and which need to be <code>uint_least32_t</code>? How many times are we silently converting between them, making them entirely pointless? (I particularly like BOOL/Bool/eBool/boolean/bool/int conversions. Every program written by an orderly organization mandating typedefs is littered with that).</p></li> <li><p>Of course in C++ we could make the type system more strict, by wrapping numbers in template class instantiations with overloaded operators and stuff. This means that you'll now get error messages of the form "class Number&lt;int,Least,32&gt; has no operator+ overload for argument of type class Number&lt;unsigned long long,Fast,64&gt;, candidates are..." I don't call this "readability", either. Your chances of implementing these wrapper classes correctly are microscopic, and most of the time you'll wait for the innumerable template instantiations to compile.</p></li> </ol>
<p>Maybe I'm weird, but I use ub, ui, ul, sb, si, and sl for my integer types. Perhaps the "i" for 16 bits seems a bit dated, but I like the look of ui/si better than uw/sw.</p>
2,872
<p>This question is addressed to a degree in this question on <a href="https://stackoverflow.com/questions/33664/best-practices-for-managing-linq-to-sql-dbml-files">LINQ to SQL .dbml best practices</a>, but I am not sure how to add to a question.</p> <p>One of our applications uses LINQ to SQL and we have currently have one .dbml file for the entire database which is becoming difficult to manage. We are looking at refactoring it a bit into separate files that are more module/functionality specific, but one problem is that many of the high level classes would have to be duplicated in several .dbml files as the associations can't be used across .dbml files (as far as I know), with the additional partial class code as well.</p> <p>Has anyone grappled with this problem and what recommendations would you make?</p>
<p>Take advantage of the namespace settings. You can get to it in properties from clicking in the white space of the ORM.</p> <p>This allows me to have a Users table and a User class for one set of business rules and a second (but the same data store) Users table and a User class for another set of business rules.</p> <p>Or, break up the library, which should also have the affect of changing the namespacing depending on your company's naming conventions. I've never worked on an enterprise app where I needed access to every single table.</p>
<p>The approach that we've used it to keep 2 .dbml files. One of them holds the Stored Procs and all production DB access is done through this. The other is in a unit test folder and holds tables and their relationships and is used for DB data manipulation and querying for unit tests.</p>
6,362
<p>I am developing a website that will manage data for multiple entities. No data is shared between entities, but they may be owned by the same customer. A customer may want to manage all their entities from a single "dashboard". So should I have one database for everything, or keep the data seperated into individual databases? Is there a best-practice? What are the positives/negatives for having a:</p> <ul> <li>database for the entire site (entity has a "customerID", data has "entityID")</li> <li>database for each customer (data has "entityID")</li> <li>database for each entity (relation of database to customer is outside of database)</li> </ul> <p>Multiple databases seems like it would have better performance (fewer rows and joins) but may eventually become a maintenance nightmare.</p>
<p>Personally, I prefer separate databases, specifically a database for each entity. I like this approach for the following reasons:</p> <ol> <li>Smaller = faster regarding the queries.</li> <li>Queries are simpler.</li> <li>No risk of ever accidentally displaying one customer's data to another.</li> <li>One database could pose a performance bottleneck as it gets large (# of entities increase). You get a sort of build in horizontal scalability with 1 per entity.</li> <li>Easy data clean up as customers or entities are removed.</li> </ol> <p>Sure it'll take more time to upgrade the schema, but in my experience modifications are fairly uncommon once you deploy and additions are trivial.</p>
<p>One good argument for keeping them in separate databases is that its easier to scale (you can simply have multiple installations of the server, with the client databases distributed across the servers).</p> <p>Another argument is that once you are logged in, you don't need to add an extra where check (for client ID) in each of your queries.</p> <p>So, a master DB backed by multiple DBs for each client may be a better approach,</p>
4,068
<p>I don't understand where the extra bits are coming from in <a href="http://en.wikipedia.org/wiki/S-box" rel="nofollow noreferrer">this article</a> about s-boxes. Why doesn't the s-box take in the same number of bits for input as output?</p>
<p>It is the way s-boxes work. They can be m * n ==> m bit input , n bit output. For example, in the <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" rel="nofollow noreferrer">AES</a> S-box the number of bits in input is equal to the number of bits in output.</p> <p>In <a href="http://en.wikipedia.org/wiki/Data_Encryption_Standard" rel="nofollow noreferrer">DES</a>, m=6 and n=4.</p> <p>The input is expanded from 32 to 48 bits in the first stages of DES. So it is be reduced to 32 bits again by applying one round of S-box substitution. Thus no information is lost here.</p> <p>The Wikipedia article on itself can be a bit confusing. It will make people think that information is lost. You should read the article in conjuncture with implementation details of some encryption algorithm using s-boxes.</p>
<p>What extra bits? They are going from 6 to 4.</p> <p>EDIT: Whoops! I'm an idiot. This is kinda like a 2nd grade multiplication table. They strip the outer bits off of the 6-bit block to be encypted, and leave the middle 4. Just like a table for an arithmatic operation, they go down one side, and find the outer bit sequence, then across the top and find the middle ones. To answer your question, it could input and output the same number of bits, but this s-box is just set up to do it the way it does. Its arbitrary.</p>
4,378
<p>Anyone know of a good, hopefully free FTP class for use in .NET that can actually work behind an HTTP proxy or FTP gateway? The FtpWebRequest stuff in .NET is horrible at best, and I really don't want to roll my own here.</p>
<p>Our <a href="http://www.rebex.net/ftp.net/" rel="nofollow noreferrer">Rebex FTP</a> works with proxies just fine. Following code shows how to connect to the FTP using HTTP proxy (code is taken from <a href="http://www.rebex.net/ftp.net/tutorial-ftp.aspx#proxy" rel="nofollow noreferrer">FTP tutorial page</a>).</p> <pre><code>// initialize FTP client Ftp client = new Ftp(); // setup proxy details client.Proxy.ProxyType = FtpProxyType.HttpConnect; client.Proxy.Host = proxyHostname; client.Proxy.Port = proxyPort; // add proxy username and password when needed client.Proxy.UserName = proxyUsername; client.Proxy.Password = proxyPassword; // connect, login client.Connect(hostname, port); client.Login(username, password); // do some work // ... // disconnect client.Disconnect(); </code></pre> <p>You can download the trial at <a href="http://www.rebex.net/ftp.net/download.aspx" rel="nofollow noreferrer">www.rebex.net/ftp.net/download.aspx</a></p>
<p>System.Net.WebClient can handle ftp urls, and it's a bit easier to work with. You can set credentials and proxy information with it, too.</p>
9,930
<p>I am having problems getting text within a table to appear centered in IE. </p> <p>In Firefox 2, 3 and Safari everything work fine, but for some reason, the text doesn't appear centered in IE 6 or 7. </p> <p>I'm using:</p> <pre class="lang-css prettyprint-override"><code>h2 { font: 300 12px "Helvetica", serif; text-align: center; text-transform: uppercase; } </code></pre> <p>I've also tried adding <code>margin-left:auto;</code>, <code>margin-right:auto</code> and <code>position:relative;</code> </p> <p>to no avail. </p>
<p>The table cell needs the text-align: center.</p>
<p>The <code>text-align: center</code> should be sufficient, since you're centering the text inside a block element (h2) - adjusting the margins will change the position of the block, not the text.</p> <p>I wonder if it's just that IE is having a dummy-spit at that <code>font</code> declaration you've got there?</p>
9,413
<p>Thinking about getting into .net technology project management</p> <p>I've had plenty of experience with PHP projects: I'm aware of most of the existing frameworks and libraries, and I've written specs and case studies based on this knowledge.</p> <p>What should I know about .net? Which top resources would you recommend me to know so I can rapidly learn and later stay up to date on the technology?</p> <p><strong>Edit (8.24.08):</strong> The answers I got so far essentially discuss being a good PM. Thanks, but this is not what I meant. Any .net essentials would be appreciated.</p>
<p>Start with the basics before you get to the higher level stuff like web services (though that is important too). The most important things you need to learn, as a project manager, are the things you're going to be questioning your underlings about later. For example, my PM (also a PHP guy) has absolutely no knowledge of garbage collection and its implications, which makes it incredibly difficult for me to explain to him why our .NET Windows service appears to be taking 80MB of RAM.</p> <p>Remember, you are not the one who needs to know everything. You should be issuing overarching directives, and let the people with the expertise sort out the details. That said, study up on the technicals a bit so that they can communicate effectively with you.</p> <p>Edit (8/24/08):You should know something about the underlying technicals; not necessarily all .NET stuff either (garbage collection, .config files, pipes and services if you're running services adjacent to your project's main focus, stuff like that). Higher-reaching concepts would probably include WPF (maybe Silverlight as well), LINQ (or your ORM of choice), as well as the Vista bridge and related bridging code if your project includes desktop apps at all. Those three things seem to be the focus for this round of .NET. Something else that's very important to have at least a passing knowledge of is the ways that .NET code can/must interoperate with native code: P/Invoke, Runtime Callable Wrapping and COM Callable Wrapping. There are still a lot of native things that don't have a .NET equivalent.</p> <p>As for resources, I'd highly recommend MSDN Magazine. They tend to preview upcoming technologies and tools well before average developers will ever see them.</p>
<p>The biggest thing you'll probably want to learn is the differences between Windows and non-Windows programmers. They approach fundamental things differently. Knowing the difference will be key to successfully managing the project. If you listen to the stack overflow podcast, and Jeff and Joel have multiple discussions on this topic. Understanding the details of the underlying technology is mostly irrelevant and you'll never know it well enough to go toe to toe with someone who works in it day in and day out. You can probably pick it up as you go.</p>
4,037
<p>I'm kind of interested in getting some feedback about this technique I picked up from somewhere.</p> <p>I use this when a function can either succeed or fail, but you'd like to get more information about why it failed. A standard way to do this same thing would be with exception handling, but I often find it a bit over the top for this sort of thing, plus PHP4 does not offer this.</p> <p>Basically the technique involves returning true for success, and <em>something</em> which <em>equates</em> to false for failure. Here's an example to show what I mean:</p> <pre><code>define ('DUPLICATE_USERNAME', false); define ('DATABASE_ERROR', 0); define ('INSUFFICIENT_DETAILS', 0.0); define ('OK', true); function createUser($username) { // create the user and return the appropriate constant from the above } </code></pre> <p>The beauty of this is that in your calling code, if you don't care WHY the user creation failed, you can write simple and readable code:</p> <pre><code>if (createUser('fred')) { // yay, it worked! } else { // aww, it didn't work. } </code></pre> <p>If you particularly want to check why it didn't work (for logging, display to the user, or do whatever), use identity comparison with ===</p> <pre><code>$status = createUser('fred'); if ($status) { // yay, it worked! } else if ($status === DUPLICATE_USERNAME) { // tell the user about it and get them to try again. } else { // aww, it didn't work. log it and show a generic error message? whatever. } </code></pre> <p>The way I see it, the benefits of this are that it is a normal expectation that a successful execution of a function like that would return true, and failure return false.</p> <p>The downside is that you can only have <code>7 "error" return values: false, 0, 0.0, "0", null, "", and (object) null.</code> If you forget to use identity checking you could get your program flow all wrong. Someone else has told me that using constants like an <code>enum</code> where they all equate to false is <code>"ick"</code>.</p> <hr> <p>So, to restate the question: how acceptable is a practise like this? Would you recommend a different way to achieve the same thing? </p>
<p>I agree with the others who have stated that this is a little on the WTFy side. If it's clearly documented functionality, then it's less of an issue, but I think it'd be safer to take an alternate route of returning 0 for success and integers for error codes. If you don't like that idea or the idea of a global last error variable, consider redefining your function as:</p> <pre><code>function createUser($username, &amp;$error) </code></pre> <p>Then you can use:</p> <pre><code>if (createUser('fred', $error)) { echo 'success'; } else { echo $error; } </code></pre> <p>Inside createUser, just populate $error with any error you encounter and it'll be accessible outside of the function scope due to the reference.</p>
<p>In my opinion, you should use this technique only if failure is a "normal part of operation" of your method / function. For example, it's as probable that a call suceeds as that it fails. If failure is a exceptional event, then you should use exception handling so your program can terminate as early and gracefully as possible.</p> <p>As for your use of different "false" values, I'd better return an instance of a custom "Result"-class with an proper error code. Something like:</p> <pre><code>class Result { var $_result; var $_errormsg; function Result($res, $error) { $this-&gt;_result = $res; $ths-&gt;_errorMsg = $error } function getResult() { return $this-&gt;_result; } function isError() { return ! ((boolean) $this-&gt;_result); } function getErrorMessage() { return $this-&gt;_errorMsg; } </code></pre>
9,818
<p>I want to embed an .asp page on an html page. I cannot use an iframe. I tried:</p> <pre><code>&lt;object width="100%" height="1500" type="text/html" data="url.asp"&gt; alt : &lt;a href="url.asp"&gt;url&lt;/a&gt; &lt;/object&gt;" </code></pre> <p>works great in ff but not ie7. Any ideas? Is it possible to use the object tag to embed .asp pages for IE or does it only work in ff?</p>
<p>I've solved it in the past using Javascript and XMLHttp. It can get a bit hacky depending on the circumstances. In particular, you have to watch out for the inner page failing and how it affects/downgrades the outer one (hopefully you can keep it downgrading elegantly).</p> <p>Search for XMLHttp (or check <a href="http://www.jibbering.com/2002/4/httprequest.html" rel="nofollow noreferrer">this great tutorial</a>) and request the "child" page from the outer one, rendering the HTML you need. Preferably you can get just the specific data you need and process it in Javascript.</p>
<p>Well, after searching around and testing I don't think it is possible. It looks to me like IE does not allow the object tag access to a resource that is not on the same domain as the parent. It would have worked for me if the content I was trying to pull in was on same domain but it wasn't. If anyone could confirm my interpretation of this it would be appreciated.</p>
7,646
<p>Jeff actually posted about this in <a href="http://refactormycode.com/codes/333-sanitize-html" rel="noreferrer">Sanitize HTML</a>. But his example is in C# and I'm actually more interested in a Java version. Does anyone have a better version for Java? Is his example good enough to just convert directly from C# to Java?</p> <p>[Update] I have put a bounty on this question because SO wasn't as popular when I asked the question as it is today (*). As for anything related to security, the more people look into it, the better it is!</p> <p>(*) In fact, I think it was still in closed beta</p>
<p>Don't do this with regular expressions. Remember, you're not protecting just against valid HTML; you're protecting against the DOM that web browsers create. Browsers can be tricked into producing valid DOM from invalid HTML quite easily. </p> <p>For example, see this list of <a href="http://ha.ckers.org/xss.html" rel="noreferrer">obfuscated XSS attacks</a>. Are you prepared to tailor a regex to prevent this real world attack on <a href="http://www.greymagic.com/security/advisories/gm005-mc/" rel="noreferrer">Yahoo and Hotmail</a> on IE6/7/8?</p> <pre><code>&lt;HTML&gt;&lt;BODY&gt; &lt;?xml:namespace prefix="t" ns="urn:schemas-microsoft-com:time"&gt; &lt;?import namespace="t" implementation="#default#time2"&gt; &lt;t:set attributeName="innerHTML" to="XSS&amp;lt;SCRIPT DEFER&amp;gt;alert(&amp;quot;XSS&amp;quot;)&amp;lt;/SCRIPT&amp;gt;"&gt; &lt;/BODY&gt;&lt;/HTML&gt; </code></pre> <p>How about this attack that works on IE6? </p> <pre><code>&lt;TABLE BACKGROUND="javascript:alert('XSS')"&gt; </code></pre> <p>How about attacks that are not listed on this site? The problem with Jeff's approach is that it's not a whitelist, as claimed. As someone on <a href="http://refactormycode.com/codes/333-sanitize-html#refactor_13642" rel="noreferrer">that page</a> adeptly notes:</p> <blockquote> <p>The problem with it, is that the html must be clean. There are cases where you can pass in hacked html, and it won't match it, in which case it'll return the hacked html string as it won't match anything to replace. This isn't strictly whitelisting.</p> </blockquote> <p>I would suggest a purpose built tool like <a href="http://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project" rel="noreferrer">AntiSamy</a>. It works by actually parsing the HTML, and then traversing the DOM and removing anything that's not in the <em>configurable</em> whitelist. The major difference is the ability to gracefully handle malformed HTML. </p> <p>The best part is that it actually unit tests for all the XSS attacks on the above site. Besides, what could be easier than this API call:</p> <pre><code>public String toSafeHtml(String html) throws ScanException, PolicyException { Policy policy = Policy.getInstance(POLICY_FILE); AntiSamy antiSamy = new AntiSamy(); CleanResults cleanResults = antiSamy.scan(html, policy); return cleanResults.getCleanHTML().trim(); } </code></pre>
<p>The biggest problem by using jeffs code is the @ which currently isnt available. </p> <p>I would probably just take the "raw" regexp from jeffs code if i needed it and paste it into </p> <p><a href="http://www.cis.upenn.edu/~matuszek/General/RegexTester/regex-tester.html" rel="nofollow noreferrer">http://www.cis.upenn.edu/~matuszek/General/RegexTester/regex-tester.html</a> </p> <p>and see the things needing escape get escaped and then use it.</p> <hr> <p>Taking the usage of this regex in mind I would personally make sure I understood exactly what I was doing, why and what consequences would be if I didnt succeed, before copy/pasting anything, like the other answers try to help you with.</p> <p><em>(Thats propbably pretty sound advice for any copy/paste)</em></p>
4,437
<p>Out of the box SSRS reports cannot have data exposed in the page header. Is there a way to get this data to show?</p>
<p>One of the things I want in my reports is to have nice headers for my reports. I like to have a logo and the user's report parameters along with other data to show to give more information for the business needs the report needs to clarify. One of the things that Microsoft SQL Server 2005 Reporting Services cannot do natively is show data from a Dataset in the header. This post will explain how to work around this and how easy it is.</p> <p>Create the Report Server Project in the Business Intelligence Projects section and call it AdventureWorksLTReports. I use the AdventureWorksLT sample database from CodePlex.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb.png">alt text http://www.cloudsocket.com/images/image-thumb.png</a></p> <p>Next show the Page Header by right clicking in the Report area with the designer.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb1.png">alt text http://www.cloudsocket.com/images/image-thumb1.png</a></p> <p>The Page Header will appear. If you want to show the Page Footer this can be accessed from the same menu as the Page Header.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb2.png">alt text http://www.cloudsocket.com/images/image-thumb2.png</a></p> <p>I created a stored procedure that returns data for the Sales Order to be presented in the Page Header. I will show the following information about the Sales Order in the Page Header:</p> <ul> <li>Order Date</li> <li>Sales Order Number</li> <li>Company</li> <li>Sales Person</li> <li>Total Due</li> </ul> <p>I create a TextBox for each of my data fields in the Page Header along with a TextBox for the corresponding label. Do not change the Expression in the TextBoxes that you want the Sales Order data in.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb3.png">alt text http://www.cloudsocket.com/images/image-thumb3.png</a></p> <p>In the Report Body, place a TextBox for each data field needed in the Page Header. In the Visibility for each TextBox, select True for Hidden. This will be the placeholder for the data needed in the Page Header.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb4.png">alt text http://www.cloudsocket.com/images/image-thumb4.png</a></p> <p>Your report should look similar to the screenshot shown below.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb5.png">alt text http://www.cloudsocket.com/images/image-thumb5.png</a></p> <p>The last step and most important is to reference the Hidden TextBox in the TextBoxes located in the Page Header. We use the the following Expression to reference the needed TextBoxes:</p> <p>=ReportItems!.Value</p> <p>Your report should now look similar to the following:</p> <p><a href="http://www.cloudsocket.com/images/image-thumb6.png">alt text http://www.cloudsocket.com/images/image-thumb6.png</a></p> <p>Your Report preview should now have the Sales Order Header data in the Report Header.</p> <p><a href="http://www.cloudsocket.com/images/image-thumb7.png">alt text http://www.cloudsocket.com/images/image-thumb7.png</a></p>
<p>Here are two possible <strong>workarounds</strong>:</p> <ol> <li><p>You can place the databound field within the body of the report as a hidden textbox, and then in the header place another textbox with it's value pointed at the the one hidden within the body.</p></li> <li><p>Try using report parameters to store the data, and use those parameters to access the data in the header.</p></li> </ol>
8,940
<p>What could be the cause of JVM thread dumps that show threads waiting to lock on a monitor, but the monitors do not have corresponding locking threads? </p> <p>Java 1.5_14 on Windows 2003</p>
<p>Does your code by any change use any JNI? (i.e. are you running any native code launched from Java?).</p> <p>We've seen a similar behavior, but JDK 1.6.0_05. App appears to deadlock, but Jstack shows threads waiting for a lock that no other threads are holding onto. We have some JNI code, so it's possible we're corrupting something.</p> <p>We haven't found a solution for this and the issue is only reproducible on 1 machine.</p>
<p>That's just a wild guess, but could it be, that a thread locks itself by trying to acquire a lock twice? Probably it would help if you could post some code.</p>
9,066
<p>I do mostly Java and C/C++ development, but I'm starting to do more web development (PHP, Rails) and Eiffel (learning a new language is always good).</p> <p>Currently, I use Eclipse for Java, C/C++, and Ruby (not Rails). Since I know the environment, I'm thinking that it would be easier for me to find a plugin and use Eclipse for all of my development languages. But are there cases where a language-specific IDE (EiffelStudio for Eiffel, as an example) would be better than Eclipse?</p>
<p>I have used many many IDE's and in most cases to me it breaks down to personal preferences. Sometimes the language specific ones have some addins/addons/features that are nice but unless they are things you can not live without you should go with what is most comfortable for you.</p> <p>I would think that if you are comfortable with the multi-language IDE it would be better to stick with that one. This way you dont have to memorize multiple IDE layouts, keyboard shortcuts etc.</p>
<p>It entirely depends on the user and the language itself, if you are comfortable with the keyboard shortcuts then you can consider the plugin else you can go for a IDE . However most of the IDE comes with a cross-functional key maps so you use the key maps which u are more comfortable with.... </p>
7,292
<p>One of the local libraries has a new small Makerbot 3D printer. I have been submitting Sketchup files converted to STL files for printing. </p> <p>The tech guy who runs the printer for patrons is having trouble getting a project of mine to come out to be the right size. I need this item go be 2 inches wide. The tech guy sizes the item on the screen to 2 inches. I watched him do it. But, the item is printed with a base of 2 inches, and the item itself comes out smaller. </p> <p>Does anyone have suggestions about this? I can get more info if someone can give me the right questions to ask. The tech is open to taking suggestions. He wants to get the printer running smoothly for patrons.</p> <p>I submitted a file with my own base with supports made in Sketchup. But, the tech guy said he needs to set the printer to create it's own base and supports.</p> <p>Additional info:</p> <p>When I printed it by letting Makerbot create the base and supports, it came out to be 1 3/4" as shown here: <a href="https://flic.kr/p/EashnD" rel="nofollow">https://flic.kr/p/EashnD</a></p> <p>Printer: Makerbot Replicator with Smart Extruder (not Plus). (I am now at the library with the technician.)</p> <p>Here is a screenshot of what I am trying to print. It is a replacement clip for a messenger bag. So, it has to be 2 inches across. <a href="https://flic.kr/p/EtdM6s" rel="nofollow">https://flic.kr/p/EtdM6s</a></p> <p>Here is the printer: <a href="https://flic.kr/p/E5F1M6" rel="nofollow">https://flic.kr/p/E5F1M6</a></p> <p>I used a website to convert the DAE file exported from Sketchup to an STL file. It was GreenToken.com.</p> <p>If I open the object's STL file in Tinkercad, the object appears two inches wide. And, if I open the file in one of the 3D printer websites in Tinkercad, the object appears two inches wide (in cm).</p> <p>The security on the library's computers do not allow me to apply plug-ins to Sketchup. The library's Tech staff is going to eventually put the plug-in in there.</p> <p>If it is resized to 2 inches wide in the MakerBot software to be sent to the printer, why is it printing the generated base 2 inches wide and not the object? Are there some settings the tech guy in the library is missing in this set up window? </p> <p>Additional notes: The library now has the latest version of SketchUp on Macs. They are working on installing the STL plugin. (Security issues)</p> <p>My process for producing an STL file to print is now this:</p> <ol> <li><p>I create something in SU and export it as a DAE file.</p></li> <li><p>I have found that meshconverter.com produces better STL files than greentoken. </p></li> <li><p>I then upload/fix the STL file at the netFabb website. </p></li> <li><p>I then import the STL file into TinkerCad to view it. If there are problems in the file, I can see them. And, I run it through netFabb again. I can also modify the file in TinkerCad. It is no where near as sophisticated as SketchUp. But, it doesn't claim to be. </p></li> </ol> <p>I have found that there is a way to export the STL file to 3D printer hubs through TinkerCad. You can see the prices, the material available and the location of the company/person doing the printing. You can contact the printer ahead of time and they can look at your file to give you advice. </p> <p><strong>Update</strong></p> <p>I just wanted to add that the netFabb website does not export STL files after it fixes them. It now gives you a 3MF file format when you upload an STL file. I am not sure why this happens. But, this has put a big wrench in my process. I can no longer fix SketchUp STL files with netFabb. When I bring them into TinkerCad, I see errors in the object. It seems like there are issues with complex curves.</p>
<p>It appears that you have scaled the object after the raft and supports were added. As you can see in your photo of the raft, the clip is approximately 7/8ths (1.75/2) the size of the raft.</p> <p>Edit: As a side note, STL files don't actually have a concept of units. Each axis is defined in arbitrary units. That's why when you export and import it you have to set the scale appropriately. </p>
<p>My advice is to use a micrometer (i.e., sliding dial caliper) accurate to within .001" and measure the printed object. If it is 1 7/8" for example, you would open the STL file in Makerbot software and use their scaling tool to scale the object to 1.0666666...., which is what you get when you divide the desired size (2") by the actual printed size (1.875"). I have found that it is much simpler to do that than to reinvent the wheel and try to figure out what each software engineer was thinking on each program and each conversion process and try to make it work right every time. Chances are that the same conversion factor might work right for any file originating from the same source and going through the same conversion software package. Also, 3D printers in general don't like edges that aren't completely "welded", or continuous seams. With Sketchup if you keep zooming in on an edge you almost always get seams that are stitched at intervals determined by Sketchup algorithms. They are "unwelded" seams. Some 3D printers can handle them. Many don't. I have used various 3D software packages, including Sketchup, and the best one so far has been Rhinoceros 3D. It handles multiple complex curvaceous planes and can radius adjoining curved edges and can "weld" them. Aeronautical and boat building companies use it for CAD/CAM applications.<br> ... The STL file converter you mentioned is probably taking the Sketchup file and "cleaning it up" so Makerbot likes it. You would almost have to know exactly what algorithms each developer uses. to try and 'fix' it mathematically Like I said, do your own measuring and scale accordingly. BTW, it's better in my opinion to let Makerbot do the rafts and supports. Their engineers typically do a pretty good job. Where I have had issues is on things with a shallow angle (almost horizontal) hanging out into empty space. If you can re-orient the object in the makerbot software so those types of angles are minimized, the print is alot cleaner.</p>
212
<p>Where can I get some decent looking free ASP.Net or CSS themes?</p>
<p>I wouldn't bother looking for ASP.NET stuff specifically (probably won't find any anyways). Finding a good CSS theme easily can be used in ASP.NET. </p> <p>Here's some sites that I love for CSS goodness:</p> <p><a href="http://www.freecsstemplates.org/" rel="noreferrer">http://www.freecsstemplates.org/</a><br> <a href="http://www.oswd.org/" rel="noreferrer">http://www.oswd.org/</a><br> <a href="http://www.openwebdesign.org/" rel="noreferrer">http://www.openwebdesign.org/</a><br> <a href="http://www.styleshout.com/" rel="noreferrer">http://www.styleshout.com/</a><br> <a href="http://www.freelayouts.com/" rel="noreferrer">http://www.freelayouts.com/</a> </p>
<p>As always, <a href="http://www.csszengarden.com/" rel="nofollow noreferrer">http://www.csszengarden.com/</a>. Note that the images aren't public domain.</p>
4,329
<p>Besides the dynamic nature of Python (and the syntax), what are some of the major features of the Python language that Java doesn't have, and vice versa?</p>
<ol> <li><p>List comprehensions. I often find myself filtering/mapping lists, and being able to say <code>[line.replace("spam","eggs") for line in open("somefile.txt") if line.startswith("nee")]</code> is really nice.</p></li> <li><p>Functions are first class objects. They can be passed as parameters to other functions, defined inside other function, and have lexical scope. This makes it really easy to say things like <code>people.sort(key=lambda p: p.age)</code> and thus sort a bunch of people on their age without having to define a custom comparator class or something equally verbose.</p></li> <li><p>Everything is an object. Java has basic types which aren't objects, which is why many classes in the standard library define 9 different versions of functions (for boolean, byte, char, double, float, int, long, Object, short). <code>Array.sort</code> is a good example. Autoboxing helps, although it makes things awkward when something turns out to be null.</p></li> <li><p>Properties. Python lets you create classes with read-only fields, lazily-generated fields, as well as fields which are checked upon assignment to make sure they're never 0 or null or whatever you want to guard against, etc.'</p></li> <li><p>Default and keyword arguments. In Java if you want a constructor that can take up to 5 optional arguments, you must define 6 different versions of that constructor. And there's no way at all to say <code>Student(name="Eli", age=25)</code></p></li> <li><p>Functions can only return 1 thing. In Python you have tuple assignment, so you can say <code>spam, eggs = nee()</code> but in Java you'd need to either resort to mutable out parameters or have a custom class with 2 fields and then have two additional lines of code to extract those fields.</p></li> <li><p>Built-in syntax for lists and dictionaries.</p></li> <li><p>Operator Overloading.</p></li> <li><p>Generally better designed libraries. For example, to parse an XML document in Java, you say<br> <code>Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("test.xml");</code><br> and in Python you say<br> <code>doc = parse("test.xml")</code></p></li> </ol> <p>Anyway, I could go on and on with further examples, but Python is just overall a much more flexible and expressive language. It's also dynamically typed, which I really like, but which comes with some disadvantages.</p> <p>Java has much better performance than Python and has way better tool support. Sometimes those things matter a lot and Java is the better language than Python for a task; I continue to use Java for some new projects despite liking Python a lot more. But as a language I think Python is superior for most things I find myself needing to accomplish.</p>
<p>With <a href="http://www.jython.org/Project/" rel="nofollow noreferrer">Jython</a> you can have both. It's only at Python 2.2, but still very useful if you need an embedded interpreter that has access to the Java runtime.</p>
7,242
<p>I'm trying to load a page that is basically an edit form inside a dialog (ui.dialog). I can load this page fine from an external (I'm using asp.net) page.</p> <p>The problem is that inside of my "popup" form, I need to <code>$(function() {my function here});</code> syntax to do some stuff when the page loads, along with registering some <code>.fn</code> extensions for some dynamic dropdowns using ajax calls.</p> <p>I have created my <code>&lt;script type="text/javascript" src="jquery.js"&gt;</code> but I don't think these are being included, and also my <code>$(function)</code> is not being called.</p> <p>Is this possible to do or do I need to find another way of accomplishing what I need to do? </p>
<p>If you really need to load that form via AJAX you could to do all the Javascript stuff in $.ajax callback itself. So, you load the popup form like this:</p> <pre><code>$.ajax({ //... success: function(text) { // insert text into container // the code from $(function() {}); } }); </code></pre>
<p>The script isn't getting run because the document's ready event has already been fired. Remove your code from within the </p> <pre><code>$() </code></pre>
8,988
<p>Did Installing OneCare cause a "Generating user instances in SQL Server is disabled" error?</p> <p>The only change that I've made to my computer is uninstalling AVG and installing the trial for Microsoft OneCare. Did OneCare change the SQLServer installation somehow?</p> <p>This is a very "odd" question but is something I would post on EE in hopes of someone having had the same issue and giving their solution.</p>
<p>I would look more at the uninstalling of AVG as the culprit. OneCare does not care or even notice SQL Server instances as far as I can tell where as AVG does. </p> <p>I would look into your SQL Server instance and check the jobs. One or more may have been added by AVG. You should remove them. You might also want to drop the AVG database. Just to be sure.</p> <p>Note: I have never <strong>uninstalled</strong> AVG. I just have notice some of what it did to my Database when my SysAdmin installed it. Being an Accidental DBA I haven't had the time to properly evaluate it's actions.</p>
<p>I didn't see anything odd in the event viewer or any db's for avg in SQLServer. btw I installed SQL server after AVG. it's curious anyway. I'll just make a VM and do a fresh install of SQLExpress so I can finish a few projects.</p> <p>it's been over a year so it's time for the annual reformat and reinstall ;-)</p>
5,946
<p>I installed the wxWidgets source code, compiled it and am linking the libraries thus obtained with my application code. Now I need to use OpenGL in my wxWidgets application. How do I enable this?</p>
<h2>For building on Windows with project files:</h2> <p>Assume $(WXWIDGETSROOT) is the root directory of your wxWidgets installation.</p> <ol> <li>Open the file $(WXWIDGETSROOT)\include\wx\msw\setup.h</li> <li>Search for the <code>#define</code> for <code>wxUSE_GLCANVAS</code>. </li> <li>Change its value from 0 to 1.</li> <li>Recompile the library.</li> </ol> <h2>For building on Linux and other <code>./configure</code> based platforms:</h2> <p>Just use <code>./configure --with-opengl</code></p> <p>(A mashup answer from two partial answers given by others)</p>
<p>(Assume $(WX_WIDGETS_ROOT) is the root directory of your wxWidgets installation.)</p> <ol> <li>Open the file $(WX_WIDGETS_ROOT)\include\wx\msw\setup.h</li> <li>Search and find the option wxUSE_GLCANVAS. Change its value from 0 to 1.</li> <li>Recompile the library.</li> </ol>
3,497
<p>The StackOverflow transcripts are enormous, and sometimes I want to link to a little bit within it.</p> <p>How do I create an HTML anchor in a FogBugz wiki page?</p>
<p>As of this writing, this feature is now supported -- just edit the wiki page's html directly (via the &lt;> button).</p> <p>See <a href="http://fogbugz.stackexchange.com/questions/2967/create-html-anchors-in-wiki-pages" rel="nofollow">this support question</a> for details. Use html anchor tags as you would in a typical html doc. (Note that I did have issues w/ FB magically removing the name attribute of the targeted anchors and had to re-add them after an initial save, so YMMV).</p>
<p>It doesn't appear to be possible.</p>
2,753
<p>We are looking for a C++ Soap web services framework that support RPC, preferably open source. Any recommendations? </p>
<p>WSO2 Web Services Framework for C++ (WSO2 WSF/C++), a binding of WSO2 WSF/C into C++ is a C++ extension for consuming Web Services in C++.</p> <p><a href="http://wso2.org/projects/wsf/cpp" rel="noreferrer">http://wso2.org/projects/wsf/cpp</a></p> <p>Apache Axis is an open source, XML based Web service framework. It consists of a Java and a C++ implementation of the SOAP server, and various utilities and APIs for generating and deploying Web service applications.</p> <p><a href="http://ws.apache.org/axis/" rel="noreferrer">http://ws.apache.org/axis/</a></p>
<p>You could try <a href="http://www.cs.fsu.edu/~engelen/soap.html" rel="nofollow noreferrer">gSOAP</a>. Available under GPL and commercial licences.</p>
9,182
<p>How can you measure the amount of time a function will take to execute? </p> <p>This is a relatively short function and the execution time would probably be in the millisecond range.</p> <p>This particular question relates to an embedded system, programmed in C or C++.</p>
<p>The best way to do that on an embedded system is to set an external hardware pin when you enter the function and clear it when you leave the function. This is done preferably with a little assembly instruction so you don't skew your results too much. </p> <p>Edit: One of the benefits is that you can do it in your actual application and you don't need any special test code. External debug pins like that are (should be!) standard practice for every embedded system.</p>
<p>If you're looking for sub-millisecond resolution, try one of these timing methods. They'll all get you resolution in at least the tens or hundreds of microseconds:</p> <p>If it's embedded Linux, look at Linux timers:</p> <p><a href="http://linux.die.net/man/3/clock_gettime" rel="nofollow noreferrer">http://linux.die.net/man/3/clock_gettime</a></p> <p>Embedded Java, look at nanoTime(), though I'm not sure this is in the embedded edition:</p> <p><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#nanoTime()" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#nanoTime()</a></p> <p>If you want to get at the hardware counters, try PAPI:</p> <p><a href="http://icl.cs.utk.edu/papi/" rel="nofollow noreferrer">http://icl.cs.utk.edu/papi/</a></p> <p>Otherwise you can always go to assembler. You could look at the PAPI source for your architecture if you need some help with this.</p>
9,438
<p>Ten years ago when I first encountered the <a href="http://en.wikipedia.org/wiki/Capability_Maturity_Model" rel="noreferrer">CMM for software</a> I was, I suppose like many, struck by how accurately it seemed to describe the chaotic "level one" state of software development in many businesses, particularly with its reference to reliance on heroes. It also seemed to provide realistic guidance for an organisation to progress up the levels improving their processes.</p> <p>But while it seemed to provide a good model and realistic guidance for improvement, I never really witnessed an adherence to CMM having a significant positive impact on any organisation I have worked for, or with. I know of one large software consultancy that claims CMM level 5 - the highest level - when I can see first hand that their processes are as chaotic, and the quality of their software products as varied, as other, non-CMM businesses.</p> <p>So I'm wondering, has anyone seen a real, tangible benefit from adherence to process improvement according to CMM?</p> <p>And if you have seen improvement, do you think that the improvement was specifically attributable to CMM, or would an alternative approach (such as <a href="http://en.wikipedia.org/wiki/Six_Sigma" rel="noreferrer">six-sigma</a>) have been equally or more beneficial?</p> <p>Does anyone still believe?</p> <p>As an aside, for those who haven't yet seen it, check out this funny-because-its-true <a href="http://en.wikipedia.org/wiki/Capability_Immaturity_Model" rel="noreferrer">parody</a></p>
<p>At the heart of the matter lies this problem, neatly described by the CMM guidance itself...</p> <p>“<em>...Sound judgment is necessary to use the CMM correctly and with insight. Intelligence, experience and knowledge must shape an appropriate interpretation of the CMM in a specific environment. That interpretation should be based on the business needs and objectives of the organization and the projects. A rote, checklist-oriented application of the CMM has the potential to harm an organization rather than help it...</em>”</p> <p>From Page 14, section 1.6 of <em>The Capability Maturity Model, Guidelines for Improving the Software Process</em> by the Carnegie Mellon University Software Engineering Institute, ISBN 0-201-54664-7.</p>
<p>At school, I was taught: CMM is a good Idea, but lacking certification (anyone can say they are level 5 / level 4) it ends up being a marketing tool for offshore shops. So, yeah, the idea is sound, but how do you prove adherence?</p>
9,106
<p>Visual Studio 2008's XAML editor (SP1) cannot reformat the XML into a consistent style.</p> <p>Which tools can I use to get a nicely formatted XAML file? Studio integration preferred.</p>
<p>While browsing through the options, I found that I had to set "Position each attribute on a separate line" and "Position first attribute on same line as start tag" under "Tools > Options ... > Text-Editor > XAML > Formatting > Spacing" and reset the Keyboard mappings under "Tools > Options ... > Environment > Keyboard" to "Visual C# 2005".</p> <p>Now the XAML editor reformats the XAML to my taste when pressing <kbd>Ctrl</kbd>+<kbd>E</kbd>, <kbd>D</kbd>.</p>
<p>I just did a post on this. This is a very versatile way to format XAML.</p> <p><a href="http://blogs.msdn.com/b/brunoterkaly/archive/2013/01/09/how-to-format-xaml-easily-and-effectively-windows-8-wpf-silverlight.aspx" rel="nofollow">http://blogs.msdn.com/b/brunoterkaly/archive/2013/01/09/how-to-format-xaml-easily-and-effectively-windows-8-wpf-silverlight.aspx</a></p>
6,994
<p>We're having sporadic, random query timeouts on our SQL Server 2005 cluster. I own a few apps that use it, so I'm helping out in the investigation. When watching the % CPU time in regular ol' Perfmon, you can certainly see it pegging out. However, SQL activity monitor only gives cumulative CPU and IO time used by a process, not what it's using right then, or over a specific timeframe. Perhaps I could use the profiler and run a trace, but this cluster is very heavily used and I'm afraid I'd be looking for a needle in a haystack. Am I barking up the wrong tree?</p> <p>Does anyone have some good methods for tracking down expensive queries/processes in this environment?</p>
<p>This will give you the top 50 statements by average CPU time, check here for other scripts: <a href="http://www.microsoft.com/technet/scriptcenter/scripts/sql/sql2005/default.mspx?mfr=true" rel="nofollow noreferrer">http://www.microsoft.com/technet/scriptcenter/scripts/sql/sql2005/default.mspx?mfr=true</a></p> <pre><code>SELECT TOP 50 qs.total_worker_time/qs.execution_count as [Avg CPU Time], SUBSTRING(qt.text,qs.statement_start_offset/2, (case when qs.statement_end_offset = -1 then len(convert(nvarchar(max), qt.text)) * 2 else qs.statement_end_offset end -qs.statement_start_offset)/2) as query_text, qt.dbid, dbname=db_name(qt.dbid), qt.objectid FROM sys.dm_exec_query_stats qs cross apply sys.dm_exec_sql_text(qs.sql_handle) as qt ORDER BY [Avg CPU Time] DESC </code></pre>
<p>Profiler may seem like a "needle in a haystack" approach, but it may turn up something useful. Try running it for a couple of minutes while the databases are under typical load, and see if any queries stand out as taking way too much time or hogging resources in some way. While a situation like this could point to some general issue, it could also be related to some specific issue with one or two sites, which mess things up enough in certain circumstances to cause very poor performance across the board.</p>
3,552
<p>I'd like to have dashes separate words in my URLs. So instead of:</p> <pre><code>/MyController/MyAction </code></pre> <p>I'd like:</p> <pre><code>/My-Controller/My-Action </code></pre> <p>Is this possible?</p>
<p>You can use the ActionName attribute like so:</p> <pre><code>[ActionName("My-Action")] public ActionResult MyAction() { return View(); } </code></pre> <p>Note that you will then need to call your View file "My-Action.cshtml" (or appropriate extension). You will also need to reference "my-action" in any Html.ActionLink methods.</p> <p>There isn't such a simple solution for controllers.</p> <h2>Edit: Update for MVC5</h2> <p>Enable the routes globally: </p> <pre><code>public static void RegisterRoutes(RouteCollection routes) { routes.MapMvcAttributeRoutes(); // routes.MapRoute... } </code></pre> <p>Now with MVC5, Attribute Routing has been absorbed into the project. You can now use:</p> <pre><code>[Route("My-Action")] </code></pre> <p>On Action Methods. </p> <p>For controllers, you can apply a <code>RoutePrefix</code> attribute which will be applied to all action methods in that controller:</p> <pre><code>[RoutePrefix("my-controller")] </code></pre> <p>One of the benefits of using <code>RoutePrefix</code> is URL parameters will also be passed down to any action methods.</p> <pre><code>[RoutePrefix("clients/{clientId:int}")] public class ClientsController : Controller ..... </code></pre> <p>Snip..</p> <pre><code>[Route("edit-client")] public ActionResult Edit(int clientId) // will match /clients/123/edit-client </code></pre>
<p>If you have access to the IIS URL Rewrite module ( <a href="http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx" rel="nofollow">http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx</a> ), you can simply rewrite the URLs.</p> <p>Requests to /my-controller/my-action can be rewritten to /mycontroller/myaction and then there is no need to write custom handlers or anything else. Visitors get pretty urls and you get ones MVC can understand.</p> <p>Here's an example for one controller and action, but you could modify this to be a more generic solution:</p> <pre><code>&lt;rewrite&gt; &lt;rules&gt; &lt;rule name="Dashes, damnit"&gt; &lt;match url="^my-controller(.*)" /&gt; &lt;action type="Rewrite" url="MyController/Index{R:1}" /&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt; </code></pre> <p>The possible downside to this is you'll have to switch your project to use IIS Express or IIS for rewrites to work during development.</p>
5,021
<p>Until recently we were using Inno Setup for our installations, something I would like to continue doing, unless we can get an <a href="https://stackoverflow.com/questions/61691/how-to-add-uninstall-option-in-net-setup-project">uninstall option in the start menu</a> (thanks Giovanni Galbo), however we now need to GAC some external libraries, something I suspect is only doable (or at least only supported) though the .NET Setup Project.</p> <p>Is it possible to call a GAC'ing library from another setup application?</p>
<p>According to <a href="http://jrsoftware.org/files/is5-whatsnew.htm" rel="noreferrer">http://jrsoftware.org/files/is5-whatsnew.htm</a> you should be able to do it with v5.3 and above</p> <blockquote> <p>Added .NET support (these cause an internal error if used on a system with no .NET Framework present):</p> <pre><code>* Added new [Files] section flag: gacinstall. * Added new [Files] section parameter: StrongAssemblyName. * Added new constants: {regasmexe}, {regasmexe32}, {regasmexe64}. </code></pre> </blockquote>
<p>Not sure about library, but you can call <a href="http://msdn.microsoft.com/en-us/library/ex0ss12c%28VS.80%29.aspx" rel="nofollow noreferrer">gacutil.exe</a> to install/uninstall assemblies.</p>
8,696
<p>Is there a way clear or reset the outputcache for an entire website without a restart?</p> <p>I'm just starting to use outputcache on a site and when I make a mistake in setting it up I need a page I can browse to that will reset it.</p>
<p>This should do the trick:</p> <pre><code>Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim path As String path="/AbosoluteVirtualPath/OutputCached.aspx" HttpResponse.RemoveOutputCacheItem(path) End Sub </code></pre>
<p>Add the following code to controller or to page code:</p> <pre><code>HttpContext.Cache.Insert("Page", 1); Response.AddCacheItemDependency("Page"); </code></pre> <p>To clear output cachne use the following command in controller:</p> <pre><code> HttpContext.Cache.Remove("Page"); </code></pre>
5,779
<p>When I drag &amp; drop a dll to the assembly folder on vista, I get the error "Access is denied: mydll.dll". How can I bypass the error message and add my dll to gac?</p>
<p>My guess would be that you have to do it as an administrator...try either disabling UAC, or using gacutil.exe to add your assembly.</p>
<p>You may not locate gacutil.exe in your windows folder while using vista. It's not included because of vista's "Logo Program blah blah" thing. Try to use windows installer to add your assemblies into gac. This is the recommended way.</p> <p>And never forget this traditional ogrish proverb: "Bi siktir git cay koy".</p>
7,645
<p>Is it completely against the Java way to create struct like objects?</p> <pre><code>class SomeData1 { public int x; public int y; } </code></pre> <p>I can see a class with accessors and mutators being more Java like.</p> <pre><code>class SomeData2 { int getX(); void setX(int x); int getY(); void setY(int y); private int x; private int y; } </code></pre> <p>The class from the first example is notationally convenient.</p> <pre><code>// a function in a class public int f(SomeData1 d) { return (3 * d.x) / d.y; } </code></pre> <p>This is not as convenient.</p> <pre><code>// a function in a class public int f(SomeData2 d) { return (3 * d.getX()) / d.getY(); } </code></pre>
<p>Use common sense really. If you have something like:</p> <pre><code>public class ScreenCoord2D{ public int x; public int y; } </code></pre> <p>Then there's little point in wrapping them up in getters and setters. You're never going to store an x, y coordinate in whole pixels any other way. Getters and setters will only slow you down.</p> <p>On the other hand, with:</p> <pre><code>public class BankAccount{ public int balance; } </code></pre> <p>You might want to change the way a balance is calculated at some point in the future. This should really use getters and setters.</p> <p>It's always preferable to know <em>why</em> you're applying good practice, so that you know when it's ok to bend the rules.</p>
<p>You can make a simple class with public fields and no methods in Java, but it is still a class and is still handled syntactically and in terms of memory allocation just like a class. There is no way to genuinely reproduce structs in Java.</p>
5,729
<p>I've deployed some Managed Beans on WebSphere 6.1 and I've managed to invoke them through a standalone client, but when I try to use the application "jconsole" distributed with the standard JDK can can't make it works.</p> <p>Has anyone achieved to connect the jconsole with WAS 6.1?</p> <p>IBM WebSphere 6.1 it's supossed to support JSR 160 JavaTM Management Extensions (JMX) Remote API. Furthermore, it uses the MX4J implementation (<a href="http://mx4j.sourceforge.net" rel="nofollow noreferrer">http://mx4j.sourceforge.net</a>). But I can't make it works with neither "jconsole" nor "MC4J".</p> <p>I have the Classpath and the JAVA_HOME correctly setted, so the issue it's not there.</p>
<p>WebSphere's support for JMX is crap. Particularly, if you need to connect to any secured JMX beans. Here's an interesting tidbit, their own implementation of jConsole will not connect to their own JVM. I have had a PMR open with IBM for over a year to fix this issue, and have gotten nothing but the runaround. They clearly don't want to fix this issue.</p> <p>The only way I have been able to invoke remote secured JMX beans hosted on WebSphere has been to implement a client using the "WebSphere application client". This is basically a stripped down app server used for stuff like this.</p> <p>Open a PMR with IBM. Perhaps if more people report this issue, they will actually fix it. </p> <blockquote> <p><strong>Update:</strong> You can run your application as a WebSphere Application Client in RAD. Open the run menu, then choose "Run...". In the dialog that opens, towards the bottom on the left hand side, you will see "WebSphere v6.1 Application Client". I'm not sure how to start and Application Client outside of RAD.</p> </blockquote>
<p>I have successfully connected to ActiveMQ and ServiceMix using the JConsole. Does WAS 6.1 use Java Management Extension (JMX) technology? JMX is required for JConsole.</p> <p>If your path is set correctly it should work fine. On windows you go to System Properties -> Advanced Tab -> Environment Variables. Have your JAVA_HOME System variable set to the path of your JDK or JRE and your Path variable with %JAVA_HOME%/bin added somewhere in there. Then all you need to do is go to Start->Run->JConsole. Select the correct Process Name and your done.</p> <p>Where are you having problems at? I hope this helps.</p> <p>Edit: Here is the Java Doc's on <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" rel="nofollow noreferrer">JConsole</a>.</p>
4,722
<p>This is kinda oddball, but I was poking around with the GNU assembler today (I want to be able to at least read the syntax), and was trying to get this little contrived example of mine to work. Namely I just want to go from 0 to 100, printing out numbers all the while. So a few minutes later I come up with this:</p> <pre><code># count.s: print the numbers from 0 to 100. .text string: .asciz "%d\n" .globl _main _main: movl $0, %eax # The starting point/current value. movl $100, %ebx # The ending point. _loop: # Display the current value. pushl %eax pushl $string call _printf addl $8, %esp # Check against the ending value. cmpl %eax, %ebx je _end # Increment the current value. incl %eax jmp _loop _end: </code></pre> <p>All I get from this is 3 printed over and over again. Like I said, just a little contrived example, so don't worry too much about it, it's not a life or death problem.</p> <p>(The formatting's a little messed up, but nothing major).</p>
<p>You can't trust what any called procedure does to any of the registers. Either push the registers onto the stack and pop them back off after calling printf or have the increment and end point values held in memory and read/written into registers as you need them. </p> <p>I hope the following works. I'm assuming that pushl has an equivalant popl and you can push an extra couple of numbers onto the stack. </p> <pre><code># count.s: print the numbers from 0 to 100. .text string: .asciz "%d\n" .globl _main _main: movl $0, %eax # The starting point/current value. movl $100, %ebx # The ending point. _loop: # Remember your registers. pushl %eax pushl %ebx # Display the current value. pushl %eax pushl $string call _printf addl $8, %esp # reinstate registers. popl %ebx popl %eax # Check against the ending value. cmpl %eax, %ebx je _end # Increment the current value. incl %eax jmp _loop _end: </code></pre>
<p>You could rewrite it so that you use registers that aren't suppose to change, for example <code>%ebp</code>. Just make sure you push them onto the stack at the beginning, and pop them off at the end of your routine.</p> <pre><code># count.s: print the numbers from 0 to 100. .text string: .asciz "%d\n" .globl _main _main: push %ecx push %ebp movl $0, %ecx # The starting point/current value. movl $100, %ebp # The ending point. _loop: # Display the current value. pushl %ecx pushl $string call _printf addl $8, %esp # Check against the ending value. cmpl %ecx, %ebp je _end # Increment the current value. incl %ecx jmp _loop _end: pop %ebp pop %ecx </code></pre>
3,984
<p>I'm making a Circuit etching machine (CNC) and I need a good DC motor and drill bit for the spindle. </p> <p>My machine should be able to <strong>etch</strong>, <strong>drill</strong>, and <strong>cut</strong>:</p> <ul> <li><strong>Etching</strong>: take copper off the surface like chemicals or a laser would</li> <li><strong>Drilling</strong>: drill holes for THT (through-hole) components and possibly 2-sided boards</li> <li><strong>Cutting</strong>: cut out a piece of the board (cutting a big piece in half or cut a circle out of a big piece)</li> </ul> <p>I'd like to have 1 drill bit work with all 3 functions if possible. Having to switch out different bits is OK but a single bit is prefered.</p> <p>What sort of specifications should my spindle DC motor (rpm, voltage/amperage rating, ...) and drill bit (material, size, angle, ...) have? </p>
<p>There are several sources of PCB "etching" bits. They tend to be single straight flutes and high angle, very pointy bits.</p> <p>For the motor, high speed is good. Look for 30k+ RPM. The main thing to be concerned about is the amount of runout, or wobble in the tip. With a tiny tip, you can't afford much runout at all. It will broaden the gap you are cutting and put stress on the bit, probably snapping it.</p> <p>The key to low runout is very careful alignment of the chuck that holds the tip with the shaft of the motor, and a collet chuck to hold the tool.</p> <p>The power needs aren't high since the speed is high and the cuts are light. I would think that a 250 watt motor should be way more than sufficient.</p> <p>The question now asks for drilling and routing, which should work better with the high-speed spindle. 30k is better for the tiny drills than a much slower spindle. These are hurt by run out.</p> <p>Usually the drill bits are made of carbide. For cutting, carbide router or file bits are used. All drill-bits and router bits and copper cutting bits I have seen for sale have 1/8" or 3mm shank.</p>
<h3>TL;DR</h3> <p>From Davo's and cmm's answers there seems to be a wide range of drill spindle speeds used (3k-30k rpm). So, just to add to that... 11,000 rpm would appear to be adequate.</p> <hr /> <p>I have been looking into converting a Wilson II 3D printer chassis into a CNC PCB etching machine, recently. In particular, what motor I needed to replace the extruder with.</p> <p>A collegue pointed me to an interesting video, <a href="https://www.youtube.com/watch?v=9DhPwtCZ9u4" rel="nofollow noreferrer">PCB making, PCB prototyping – UV solder mask STEP by STEP</a>, produced by Wegstr (no affiliation whatsoever), and their machine uses a 11,000 rpm drill. From the <a href="https://wegstr.com/CNC-Wegstr-(English)" rel="nofollow noreferrer">specification page</a>:</p> <blockquote> <ul> <li>Spindle - Brushless AC motor</li> <li>Diameter of spindle - 3.175 mm (0.000737 inch)</li> <li>Spindle speed - 11 000 rpm Electronic overload protection for the spindle motor</li> </ul> </blockquote> <p>Apparently DC motors suffer from carbon brush wear, so a combination of DC circuitry and brushless AC motor is used for &quot;superior performance and durability&quot;.</p> <p>The voltage and current of the spindle motor is unclear/unspecified, but the PSU, that comes with it, outputs 12 V 5 A.</p> <p>However, the parts page lists the spindle motor separately, <a href="https://wegstr.com/spindle-11000-rpm" rel="nofollow noreferrer">spindle 11000rpm</a>, with the following specifications:</p> <blockquote> <ul> <li>26V DC power supply</li> <li>11000 rpm</li> <li>designed for tools with shank diameter 3.175 mm</li> <li>fastening tool with the setscrew</li> <li>in the rear spindle 4x M4 threaded hole for mounting on a substrate</li> <li>power consumption 25W</li> <li>brushless construction =&gt; no carbon brush wear =&gt; long life</li> <li>low noise</li> </ul> </blockquote> <p>So, given the voltage and power consumption the current rating would seem to be ~1 A.</p> <p><a href="https://i.stack.imgur.com/qGv0B.jpg" rel="nofollow noreferrer" title="Spindle Motor 11000 rpm"><img src="https://i.stack.imgur.com/qGv0B.jpg" alt="Spindle Motor 11000 rpm" title="Spindle Motor 11000 rpm" /></a></p>
1,428
<p>I am wondering if it would it be feasible (at an affordable price) to 3D print a boat hull (small dimensions, maybe something like 60x40x20 cm). </p> <p>I am mostly concerned about: </p> <ul> <li><strong>durability</strong> (against salty water, UV rays, extreme temperatures (under the sun or in a cold ocean)</li> <li><strong>strength</strong> (the material should be able to resist some chocs and maybe a little bit of pressure if a wave was to smash on it).</li> <li><strong>waterproofness</strong></li> </ul> <p>Those characteristics should <em>last</em> during extended periods of time in water (at least several months, maybe more, about a year or two). </p> <p><strong>Is there any easily accessible 3D printing material that would match those characteristics?</strong> </p>
<p>You will really need to specify your constraints better because the short answer is <strong>yes, what you describe <em>is</em> entirely possible</strong>, but without knowing whether you are limited to a particular budget, process, or aesthetic, it's not a particularly useful answer.</p> <p>Some machines (ex. Stratasys Connex 1000) will print models up to 1m in length, so sure, you could print an entire hull with the dimensions you specify.</p> <p><strong>Pros</strong>:</p> <ul> <li>Monohull construction</li> <li>Excellent surface finish</li> <li>Many resin options are UV and salt water resistant with decent enough durability</li> </ul> <p><strong>Cons:</strong></p> <ul> <li>Ridiculously expensive machine with decently expensive resins</li> <li>It will waste plenty of support material in printing (which means added cost too)</li> <li>Not really <em>easily</em> accessible, but some design studios will have them and will print things for you, for a cost</li> </ul> <p>Other machines (ex. Ultimaker 2 Extended) will print models up to 30cm along the vertical axis. It would require some assembly in the end, but you could segment your build and get a boat hull in the end.</p> <p><strong>Pros:</strong></p> <ul> <li>Easily accessible</li> <li>Fairly low cost (Maybe under \$1000 for the machine vs nearly \$1M and many filaments cost 1/10th that of polyjet resins or sintering powders)</li> <li>The materials themselves can be UV resistant and salt water resistant</li> </ul> <p><strong>Cons:</strong></p> <ul> <li>Joinery and seams create passageways for water ingress, so you'd need secondary sealant</li> <li>The FDM process itself isn't always watertight, so you'd need sealant anyway</li> <li>Low interlayer adhesion limits the tensile strength along one axis and the shear strength in one plane, so you'd either need composite hull panels with varying print orientations (in which case, just do a composite layup instead) or a fairly careful analysis of principle hydrodynamic stresses</li> </ul> <p>There's significantly more to the discussion as well, but without really understanding your design constraints, it's difficult to give any concrete advice.</p>
<p>Probably feasible, Affordable or simple probably not. To start from an affordability perspective, kayaks normally weigh around 20 kg, they <a href="http://www.grassrootsengineering.com/blog/2014/03/" rel="nofollow noreferrer">kayak in the video mentioned in the other answer</a> weighs in at 30kgs. Assuming you print all your parts perfectly, your using \$15 a kg filament, and you use 25 kg of abs you are looking at a minimum of \$375 in material just to print the kayak. After this the cost would only go up because now you need the parts to fasten it all together, the seat ect... In other words, it will probably be no cheaper and a whole lot more time intensive then buying one.</p>
508
<p>Recently a friend and I were talking about securing stored procedure code in a SQL server database. </p> <p>From distant memory, I'm pretty certain that "with encryption" is incredibly easily broken in all versions of SQL Server, however he said it has been greatly improved in SQL 2005. As a result I have not seriously considered it as a security option in any systems I have ever worked on.</p> <p>So in what scenarious could "with encryption" be used, and when should it be avoided at all costs?</p>
<p>It can be used to hide your code from casual observers, but as you say: it's easily circumvented.</p> <p>It really can't be any other way, since the server needs to decrypt the code to execute it. It's DRM, basically, and fails for the same reason as all the other DRM does - you can't simultaneously hide the data, and allow it to be accessed.</p>
<p>Yes, it's easily broken. I had a situation this past week where I had to decrypt several sprocs that a former developer had encrypted for a client of mine. After decrypting it, which took a moderate effort, I wouldn't rely on that for any means of protecting intellectual property, passwords, user ids. Anything really.</p>
7,404
<p>I'm looking for some software to monitor a single server for performance alerts. Preferably free and with a reasonable default configuration.</p> <p>Edit: To clarify, I would like to run this software on a Windows machine and monitor a remote Windows server for CPU/memory/etc. usage alerts (not a single application).</p> <p>Edit: I suppose its not necessary that this software be run remotely, I would also settle for something that ran on the server and emailed me if there was an alert. It seems like Windows performance logs and alerts might be used for this purpose somehow but it was not immediately obvious to me.</p> <p>Edit: Found a neat tool on the coding horror blog, not as useful for remote monitoring but very useful for things you would worry about as a server admin: <a href="http://www.winsupersite.com/showcase/winvista_ff_rmon.asp" rel="nofollow noreferrer">http://www.winsupersite.com/showcase/winvista_ff_rmon.asp</a></p>
<p>For performance monitor - start it on the server (<kbd>Win</kbd>+<kbd>R</kbd> and enter "perfmon"). Select "Performance Logs and Alerts" and expand. Select "Alerts". Select "Action" &amp; then "New Alert". Give the alert a name, click "Add" to add a counter (there are hundres of counters, for example CPU %), then give it some limits.</p> <p>Select the "Action" tab, and then decide what you want to do. You may need a third party program - for example Blat to send emails - but basiaclly any script can be run.</p>
<p>MS's solutions used to be called MOM. It looks like it's been <a href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx" rel="nofollow noreferrer">redesigned a bit</a> since I last used it.</p>
3,252
<p>The collection of fonts available to a web developer is depressingly limited. I remember reading long ago about TrueDoc, as a way of shipping fonts alongside a website - but it seems to have languished. Has anybody used this, or something similar? Is it supported by enough browsers? Am I missing a good solution?</p> <p>Note that a responsible web developer does not use fonts that are only available on Windows (and <em>especially</em> ones that are only available on Vista), nor do they use a technology that isn't supported by at least the majority of browsers.</p> <hr> <p><strong>Update:</strong> As several people have pointed out, there's nothing wrong with providing a list of fallback fonts for people who don't have the specific font you use. I do in fact always do this, and didn't mean to suggest that this was wrong.</p> <p>While my question was badly phrased, what I meant was that a designer should not make too many assumptions about what the client will have available. You should plan for how all users will see your site, not just for people using your own preferred setup.</p>
<p>Safari, and to a lesser extent, Firefox 3 have support for <code>@font-face</code> in CSS, which lets you use custom fonts. You need to have the appropriate licence to distribute the font files though. These articles explain it in more detail:</p> <ul> <li><a href="http://www.css3.info/preview/web-fonts-with-font-face/" rel="noreferrer">http://www.css3.info/preview/web-fonts-with-font-face/</a></li> <li><a href="http://www.alistapart.com/articles/cssatten" rel="noreferrer">http://www.alistapart.com/articles/cssatten</a></li> <li><a href="http://www.sitepoint.com/blogs/2008/07/30/custom-web-fonts-pick-your-poison/" rel="noreferrer">http://www.sitepoint.com/blogs/2008/07/30/custom-web-fonts-pick-your-poison/</a></li> </ul>
<blockquote> <p>Note that a responsible web developer does not use fonts that are only available on Windows (and especially ones that are only available on Vista), nor do they use a technology that isn't supported by at least the majority of browsers.</p> </blockquote> <p>Well… You can, as long as you know how it will render on non-Vista/non-Windows OS.</p> <p>Otherwise: yep, @font-face in CSS2 is the best standard alternative, even if it is not widely supported.</p>
3,696
<p>I'm writing my first Perl app -- an AOL Instant Messenger bot that talks to an Arduino microcontroller, which in turn controls a servo that will push the power button on our sysadmin's server, which freezes randomly every 28 hours or so. </p> <p>I've gotten all the hard stuff done, I'm just trying to add one last bit of code to break the main loop and log out of AIM when the user types 'quit'.</p> <p>The problem is, if I try to read from STDIN in the main program loop, it blocks the process until input is entered, essentially rendering the bot inactive. I've tried testing for EOF before reading, but no dice... EOF just always returns false.</p> <p>Here's below is some sample code I'm working with:</p> <pre><code>while(1) { $oscar-&gt;do_one_loop(); # Poll to see if any arduino data is coming in over serial port my $char = $port-&gt;lookfor(); # If we get data from arduino, then print it if ($char) { print "" . $char ; } # reading STDIN blocks until input is received... AAARG! my $a = &lt;STDIN&gt;; print $a; if($a eq "exit" || $a eq "quit" || $a eq 'c' || $a eq 'q') {last;} } print "Signing off... "; $oscar-&gt;signoff(); print "Done\n"; print "Closing serial port... "; $port-&gt;close() || warn "close failed"; print "Done\n"; </code></pre>
<p>The Perl built-in is <a href="http://perldoc.perl.org/functions/select.html" rel="noreferrer"><code>select()</code></a>, which is a pass-through to the <code>select()</code> system call, but for sane people I recommend <a href="http://search.cpan.org/dist/IO/lib/IO/Select.pm" rel="noreferrer"><code>IO::Select</code></a>.</p> <p>Code sample:</p> <pre><code>#!/usr/bin/perl use IO::Select; $s = IO::Select-&gt;new(); $s-&gt;add(\*STDIN); while (++$i) { print "Hiya $i!\n"; sleep(5); if ($s-&gt;can_read(.5)) { chomp($foo = &lt;STDIN&gt;); print "Got '$foo' from STDIN\n"; } } </code></pre>
<p>I found that <a href="http://search.cpan.org/dist/IO/lib/IO/Select.pm" rel="nofollow noreferrer">IO::Select</a> works fine as long as STDOUT gets closed, such as when the upstream process in the pipeline exits, or input is from a file. However, if output is ongoing (such as from "tail -f") then any partial data buffered by <code>&lt;STDIN&gt;</code> will not be displayed. Instead, use the unbuffered <a href="https://perldoc.perl.org/functions/sysread.html" rel="nofollow noreferrer">sysread</a>:</p> <pre><code>#!/usr/bin/perl use IO::Select; $s = IO::Select-&gt;new(\*STDIN); while (++$i) { if ($s-&gt;can_read(2)) { last unless defined($foo=get_unbuf_line()); print "Got '$foo'\n"; } } sub get_unbuf_line { my $line=""; while (sysread(STDIN, my $nextbyte, 1)) { return $line if $nextbyte eq "\n"; $line .= $nextbyte; } return(undef); } </code></pre>
3,495
<p>What I want to do is something like this: I have enums with combined flagged values.</p> <pre><code>public static class EnumExtension { public static bool IsSet&lt;T&gt;( this T input, T matchTo ) where T:enum //the constraint I want that doesn't exist in C#3 { return (input &amp; matchTo) != 0; } } </code></pre> <p>So then I could do:</p> <pre><code>MyEnum tester = MyEnum.FlagA | MyEnum.FlagB if( tester.IsSet( MyEnum.FlagA ) ) //act on flag a </code></pre> <p>Unfortunately, C#'s generic where constraints have no enum restriction, only class and struct. C# doesn't see enums as structs (even though they are value types) so I can't add extension types like this.</p> <p>Does anyone know a workaround?</p>
<p><strong>EDIT: This is now live in version 0.0.0.2 of UnconstrainedMelody.</strong></p> <p>(As requested on my <a href="http://codeblog.jonskeet.uk/2009/09/10/generic-constraints-for-enums-and-delegates/" rel="noreferrer">blog post about enum constraints</a>. I've included the basic facts below for the sake of a standalone answer.)</p> <p>The best solution is to wait for me to include it in <a href="https://github.com/jskeet/unconstrained-melody" rel="noreferrer">UnconstrainedMelody</a><sup>1</sup>. This is a library which takes C# code with "fake" constraints such as</p> <pre><code>where T : struct, IEnumConstraint </code></pre> <p>and turns it into</p> <pre><code>where T : struct, System.Enum </code></pre> <p>via a postbuild step.</p> <p>It shouldn't be too hard to write <code>IsSet</code>... although catering for both <code>Int64</code>-based and <code>UInt64</code>-based flags could be the tricky part. (I smell some helper methods coming on, basically allowing me to treat any flags enum as if it had a base type of <code>UInt64</code>.)</p> <p>What would you want the behaviour to be if you called</p> <pre><code>tester.IsSet(MyFlags.A | MyFlags.C) </code></pre> <p>? Should it check that <em>all</em> the specified flags are set? That would be my expectation.</p> <p>I'll try to do this on the way home tonight... I'm hoping to have a quick blitz on useful enum methods to get the library up to a usable standard quickly, then relax a bit.</p> <p>EDIT: I'm not sure about <code>IsSet</code> as a name, by the way. Options:</p> <ul> <li>Includes</li> <li>Contains</li> <li>HasFlag (or HasFlags)</li> <li>IsSet (it's certainly an option)</li> </ul> <p>Thoughts welcome. I'm sure it'll be a while before anything's set in stone anyway...</p> <hr> <p><sup>1</sup> or submit it as a patch, of course...</p>
<p>I just wanted to add Enum as a generic constraint.</p> <p>While this is just for a tiny helper method using <a href="https://www.github.com/Fody/ExtraConstraints" rel="nofollow noreferrer"><code>ExtraConstraints</code></a> is a bit too much overhead for me.</p> <p>I decided to just just create a <code>struct</code> constraint and add a runtime check for <code>IsEnum</code>. For converting a variable from T to Enum I cast it to object first.</p> <pre><code> public static Converter&lt;T, string&gt; CreateConverter&lt;T&gt;() where T : struct { if (!typeof(T).IsEnum) throw new ArgumentException("Given Type is not an Enum"); return new Converter&lt;T, string&gt;(x =&gt; ((Enum)(object)x).GetEnumDescription()); } </code></pre>
2,886
<p>Is there any good way to deal with the class renaming refactor from Resharper when the file is under source control and TortoiseSVN is the client. I have am trying VisualSVN right now but I haven't had the need to rename anything recently. I don't want to change our repository just to try this out.</p> <p>Also not sure if this feature alone is worth the cost of VisualSVN.</p> <p><strong>Update:</strong> I have uninstalled the trial of VisualSVN and tried AhknSVN. I seems to provided the same functionality so far. </p> <p>I know this my sound trivial but the indicators seem to be lacking some functionality, it seems like they don't trickle up. (If a file in the project is different I would think the project indicator would indicate this as well.) I tend to keep my projects rolled as much as possible, so it is hard to tell what files have changed unless the project is expanded.</p>
<p>TortoiseSVN 1.5 has a neat hidden feature on the check in window:</p> <p>Select a missing file and a new file and right-click. One of the options will be "fix move".</p> <p>I tend to refactor away, and then use this to fix any files where the name has changed.</p>
<p>Time to branch your repository. That's the nice part about version control, you can create new branches without totaling the old ones.</p>
3,467
<p>I have a ListBox that has a style defined for ListBoxItems. Inside this style, I have some labels and a button. One that button, I want to define a click event that can be handled on my page (or any page that uses that style). How do I create an event handler on my WPF page to handle the event from my ListBoxItems style?</p> <p>Here is my style (affected code only):</p> <pre><code>&lt;Style x:Key="UsersTimeOffList" TargetType="{x:Type ListBoxItem}"&gt; ... &lt;Grid&gt; &lt;Button x:Name="btnRemove" Content="Remove" Margin="0,10,40,0" Click="btnRemove_Click" /&gt; &lt;/Grid&gt; &lt;/Style&gt; </code></pre> <p>Thanks! </p>
<p>Take a look at <a href="http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.aspx" rel="noreferrer">RoutedCommand</a>s.</p> <p>Define your command in myclass somewhere as follows:</p> <pre><code> public static readonly RoutedCommand Login = new RoutedCommand(); </code></pre> <p>Now define your button with this command:</p> <pre><code> &lt;Button Command="{x:Static myclass.Login}" /&gt; </code></pre> <p>You can use CommandParameter for extra information..</p> <p>Now last but not least, start listening to your command:</p> <p>In the constructor of the class you wish to do some nice stuff, you place:</p> <pre><code> CommandBindings.Add(new CommandBinding(myclass.Login, ExecuteLogin)); </code></pre> <p>or in XAML:</p> <pre><code> &lt;UserControl.CommandBindings&gt; &lt;CommandBinding Command="{x:Static myclass.Login}" Executed="ExecuteLogin" /&gt; &lt;/UserControl.CommandBindings&gt; </code></pre> <p>And you implement the delegate the CommandBinding needs:</p> <pre><code> private void ExecuteLogin(object sender, ExecutedRoutedEventArgs e) { //Your code goes here... e has your parameter! } </code></pre> <p>You can start listening to this command everywhere in your visual tree!</p> <p>Hope this helps</p> <p>PS You can also define the CommandBinding with a CanExecute delegate which will even disable your command if the CanExecute says so :)</p> <p>PPS Here is another example: <a href="http://www.wpfwiki.com/Default.aspx?Page=WPF%20Q13.8&amp;AspxAutoDetectCookieSupport=1" rel="noreferrer">RoutedCommands in WPF</a></p>
<p>You could create a user control (.ascx) to house the listbox. Then add a public event for the page.</p> <pre><code>Public Event btnRemove() </code></pre> <p>Then on the button click event in the usercontrol</p> <pre><code>RaiseEvent btnRemove() </code></pre> <p>You can also pass objects through the event just like any other method. This will allow your user control to tell your page what to delete.</p>
4,774
<p>I've inherited a large VB6 app at my current workplace. I'm kinda learning VB6 on the job and there are a number of problems I'm having. The major issue at the moment is I can't figure out how to check if a key exists in a Collection object. Can anyone help?</p>
<p>@Mark Biek Your keyExists closely matches my standard Exists() function. To make the class more useful for COM-exposed collections and checking for numeric indexes, I'd recommend changing sKey and myCollection to not be typed. If the function is going to be used with a collection of objects, 'set' is required (on the line where val is set).</p> <p><strong>EDIT</strong>: It was bugging me that I've never noticed different requirements for an object-based and value-based Exists() function. I very rarely use collections for non-objects, but this seemed such a perfect bottleneck for a bug that would be so hard to track down when I needed to check for existence. Because error handling will fail if an error handler is already active, two functions are required to get a new error scope. Only the Exists() function need ever be called:</p> <pre><code>Public Function Exists(col, index) As Boolean On Error GoTo ExistsTryNonObject Dim o As Object Set o = col(index) Exists = True Exit Function ExistsTryNonObject: Exists = ExistsNonObject(col, index) End Function Private Function ExistsNonObject(col, index) As Boolean On Error GoTo ExistsNonObjectErrorHandler Dim v As Variant v = col(index) ExistsNonObject = True Exit Function ExistsNonObjectErrorHandler: ExistsNonObject = False End Function </code></pre> <p>And to verify the functionality:</p> <pre><code>Public Sub TestExists() Dim c As New Collection Dim b As New Class1 c.Add "a string", "a" c.Add b, "b" Debug.Print "a", Exists(c, "a") ' True ' Debug.Print "b", Exists(c, "b") ' True ' Debug.Print "c", Exists(c, "c") ' False ' Debug.Print 1, Exists(c, 1) ' True ' Debug.Print 2, Exists(c, 2) ' True ' Debug.Print 3, Exists(c, 3) ' False ' End Sub </code></pre>
<p>While looking for a function like this i designed it as following. This should work with objects and non-objects without assigning new variables.</p> <pre><code>Public Function Exists(ByRef Col As Collection, ByVal Key) As Boolean On Error GoTo KeyError If Not Col(Key) Is Nothing Then Exists = True Else Exists = False End If Exit Function KeyError: Err.Clear Exists = False End Function </code></pre>
6,188
<p>I am about to write an audio file converter for my side job at the university.<br> As part of this I would need sample rate conversion. However, my professor said that it would be pretty hard to write a sample rate converter that was <em>both</em> of good quality <em>and</em> fast.</p> <p>On my research on the subject, I found some functions in the OSX CoreAudio-framework, that could do a sample rate conversion (AudioConverter.h). After all, an OS has to have some facilities to do that for its own audio stack. </p> <p>Do you know a similar method for C/C++ and Windows, that are either part of the OS or open source?<br> I am pretty sure that this function exists within DirectX Audio (XAudio2?), but I seem to be unable to find a reference to it in the MSDN library.</p>
<p>Try Secret Rabbit Code (= SRC = Sample Rate Conversion ) It's GPL, it's fast and it's high quality. <a href="http://www.mega-nerd.com/SRC/license.html" rel="noreferrer">http://www.mega-nerd.com/SRC/license.html</a></p>
<p>If you're worried about quality, check out <a href="http://src.infinitewave.ca/" rel="nofollow noreferrer">http://src.infinitewave.ca/</a>. Very good comparisons on different resamplers.</p>
6,291
<p>I have 2 SQLite databases, one downloaded from a server (<code>server.db</code>), and one used as storage on the client (<code>client.db</code>). I need to perform various sync queries on the client database, using data from the server database.</p> <p>For example, I want to delete all rows in the <code>client.db tRole</code> table, and repopulate with all rows in the <code>server.db tRole</code> table.</p> <p>Another example, I want to delete all rows in the <code>client.db tFile</code> table where the <code>fileID</code> is not in the <code>server.db tFile</code> table.</p> <p>In SQL Server you can just prefix the table with the name of the database. Is there anyway to do this in SQLite using Adobe Air?</p>
<p>I just looked at the AIR SQL API, and there's an <code>attach</code> method on <code>SQLConnection</code> it looks exactly what you need.</p> <p>I haven't tested this, but according to the documentation it should work:</p> <pre><code>var connection : SQLConnection = new SQLConnection(); connection.open(firstDbFile); connection.attach(secondDbFile, &quot;otherDb&quot;); var statement : SQLStatement = new SQLStatement(); statement.connection = connection; statement.text = &quot;INSERT INTO main.myTable SELECT * FROM otherDb.myTable&quot;; statement.execute(); </code></pre> <p>There may be errors in that code snippet, I haven't worked much with the AIR SQL API lately. Notice that the tables of the database opened with <code>open</code> are available using <code>main.tableName</code>, any attached database can be given any name at all (<code>otherDb</code> in the example above).</p>
<p>this code can be work,it is write of me:</p> <pre><code>package lib.tools import flash.utils.ByteArray; import flash.data.SQLConnection; import flash.data.SQLStatement; import flash.data.SQLResult; import flash.data.SQLMode; import flash.events.SQLErrorEvent; import flash.events.SQLEvent; import flash.filesystem.File; import mx.core.UIComponent; import flash.data.SQLConnection; public class getConn { public var Conn:SQLConnection; public function getConn(database:Array) { Conn = new SQLConnection(); var Key:ByteArray = new ByteArray(); Key.writeUTFBytes("Some16ByteString"); Conn.addEventListener(SQLErrorEvent.ERROR, createError); var dbFile:File = File.applicationDirectory.resolvePath(database[0]); Conn.open(dbFile); if(database.length &gt; 1) { for(var i:Number = 1; i &lt; database.length; i++) { var DBname:String = database[i]; Conn.attach(DBname.split("\.")[0], File.applicationDirectory.resolvePath(DBname)); } } Conn.open(dbFile, SQLMode.CREATE, false, 1024, Key); } private function createError(event:SQLErrorEvent):void { trace("Error code:", event.error.details); trace("Details:", event.error.message); } public function Rs(sql:Array):Object { var stmt:SQLStatement = new SQLStatement(); Conn.begin(); stmt.sqlConnection = Conn; try { for(var i:String in sql) { stmt.text = sql[i]; stmt.execute(); } Conn.commit(); } catch(error:SQLErrorEvent) { createError(error); Conn.rollback(); }; var result:Object =stmt.getResult(); return result; } } </code></pre>
2,462
<p>I'm working on a side project that would be a simple web application to maintain a list of classes and their upcoming schedules.</p> <p>I would really like to use Linq to SQL for this project, but unfortunately the server environment I'm developing for only has MySql available. I've dabbled briefly with Subsonic but it just doesn't get the job done.</p> <p>The database requirements for this application aren't that great, though, so I'm curious if using an MDF file in App_Data would be a workable solution. Otherwise, it appears I'm going to have to hand-code sql queries which I want to avoid at all costs.</p>
<p>Take a look at Microsoft SQL Server Compact Edition. I believe you can work with MDF files without having to run a server. All code runs in process. I believe it has some limitations but it may work for you and I think it's free.</p>
<p>I don't understand... what do you mean by "having an MDF file in App_Data"? You need a proper SQL Server installation for that to work. You can always use the free SQL Server Express for developing the application, and then move the database to the proper SQL Server once you are done. Check <a href="http://www.microsoft.com/sql/editions/express/default.mspx" rel="nofollow noreferrer">here</a>.</p>
5,567
<p>My boss has come to me and asked how to enure a file uploaded through web page is safe. He wants people to be able to upload pdfs and tiff images (and the like) and his real concern is someone embedding a virus in a pdf that is then viewed/altered (and the virus executed). I just read something on a procedure that could be used to destroy stenographic information emebedded in images by altering least sifnificant bits. Could a similar process be used to enusre that a virus isn't implanted? Does anyone know of any programs that can scrub files? </p> <p>Update: So the team argued about this a little bit, and one developer found a post about letting the file download to the file system and having the antivirus software that protects the network check the files there. The poster essentially said that it was too difficult to use the API or the command line for a couple of products. This seems a little kludgy to me, because we are planning on storing the files in the db, but I haven't had to scan files for viruses before. Does anyone have any thoughts or expierence with this?</p> <p><a href="http://www.softwarebyrob.com/2008/05/15/virus-scanning-from-code/" rel="nofollow noreferrer">http://www.softwarebyrob.com/2008/05/15/virus-scanning-from-code/</a></p>
<p>I'd recommend running your uploaded files through antivirus software such as <a href="http://www.clamav.net/" rel="nofollow noreferrer">ClamAV</a>. I don't know about scrubbing files to remove viruses, but this will at least allow you to detect and delete infected files before you view them.</p>
<p>Yes, ClamAV should scan the file regardless of the extension.</p>
5,307
<p>We are in the early design stages of a major rewrite of our product. Right now our customers are mostly businesses. We manage accounts. User names for an account are each on their own namespace but it means that we can't move assets between servers.</p> <p>We want to move to a single namespace. But that brings the problem of unique user names.</p> <p>So what's the best idea?</p> <ul> <li>Email address (w/verification) ?</li> <li>Unique alpha-numeric string ("johnsmith9234")?</li> <li>Should we look at OpenID?</li> </ul>
<p><strong>EMAIL ADDRESS</strong></p> <p>Rational</p> <ol> <li>Users don't change emails very often</li> <li>Removes the step of asking for username and email address, which you'll need anyway</li> <li>Users don't often forget their email address (see number one)</li> <li>Email will be unique unless the user already registered for the site, in which case forward them to a forgot your password screen</li> <li>Almost everyone is using email as the primary login for access to a website, this means the rate of adoption shouldn't be affected by the fact that you're asking for an email address</li> </ol> <hr> <p><strong>Update</strong></p> <p>After registration, be sure to ask the user to create some kind of username, don't litter a public site with their email address! Also, another benefit of using an email address as a login: you won't need any other information (like password / password confirm), just send them a temp password through the mail, or forgo passwords altogether and send them a one-use URL to their email address every time they'd like to login (see: <a href="http://mugshot.org/main" rel="noreferrer">mugshot.org</a>)</p>
<p>OpenID seems to be a very good alternative to writing your own user management/authentication piece. I'm seeing more and more sites using OpenID these days, so the barrier to entry for your users should be relatively low.</p>
2,789
<p>I'm looking for a technique or tool which we can use to obfuscate or somehow secure our compiled c# code. The goal is not for user/data security but to hinder reverse engineering of some of the technology in our software. </p> <p>This is not for use on the web, but for a desktop application.</p> <p>So, do you know of any tools available to do this type of thing? (They need not be free)</p> <p>What kind of performance implications do they have if any?</p> <p>Does this have any negative side effects when using a debugger during development?</p> <p>We log stack traces of problems in the field. How would obfuscation affect this?</p>
<p>This is a pretty good list of obfuscators from <a href="https://marketplace.visualstudio.com/search?term=.net%20obfuscators&amp;target=VS&amp;category=All%20categories&amp;vsVersion=&amp;sortBy=Relevance" rel="noreferrer">Visual Studio Marketplace</a> Obfuscators</p> <ul> <li><a href="https://www.armdot.com/" rel="noreferrer">ArmDot</a></li> <li><a href="http://www.ssware.com/cryptoobfuscator/obfuscator-net.htm" rel="noreferrer">Crypto Obfuscator</a></li> <li><a href="http://www.wiseowl.com/products/products.aspx" rel="noreferrer">Demeanor</a> for .NET</li> <li><a href="http://xheo.com/products/code-protection" rel="noreferrer">DeployLX CodeVeil</a></li> <li><a href="http://www.preemptive.com/" rel="noreferrer">Dotfuscator</a> .NET Obfuscator</li> <li><a href="http://www.semdesigns.com/products/obfuscators/csharpobfuscator.html" rel="noreferrer">Semantic Designs</a>: C# Source Code Obfuscator</li> <li><a href="http://www.smartassembly.com" rel="noreferrer">Smartassembly</a></li> <li><a href="http://www.9rays.net/Products/Spices.Net/" rel="noreferrer">Spices.Net</a></li> <li><a href="http://www.xenocode.com/Products/Postbuild/" rel="noreferrer">Xenocode</a> Postbuild 2006</li> <li><a href="http://www.eziriz.com/" rel="noreferrer">.NET Reactor</a></li> </ul> <p>I have not observed any performance issues when obfuscating my code. If your just sending text basted stack traces you might have a problem translating the method names.</p>
<p>You are wasting your time going down that path. If you have code that you don't want anyone to see, you need to keep it behind closed doors. For example, only execute that code on your own server using a web service interface.</p> <p>Obfuscating your code only deters the most casual of people. As the video game industry leaned a long time ago, no code is safe from cracking.</p>
8,465
<p>If I create an application on my Mac, is there any way I can get it to run on an iPhone without going through the app store?</p> <p>It doesn't matter if the iPhone has to be jailbroken, as long as I can still run an application created using the official SDK. For reasons I won't get into, I can't have this program going through the app store.</p>
<h1>Official Developer Program</h1> <p>For a standard iPhone you'll need to pay the US$99/yr to be a member of the developer program. You can then use the adhoc system to install your application onto up to 100 devices. The developer program has the details but it involves adding UUIDs for each of the devices to your application package. UUIDs can be easiest retrieved using <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=285691333&amp;mt=8" rel="noreferrer">Ad Hoc Helper</a> available from the App Store. For further details on this method, see Craig Hockenberry's <a href="http://furbo.org/2008/08/06/beta-testing-on-iphone-20/" rel="noreferrer">Beta testing on iPhone 2.0</a> article</p> <h1>Jailbroken iPhone</h1> <p>For jailbroken iPhones, you can use the following method which I have personally tested using the <a href="http://developer.apple.com/iphone/library/samplecode/AccelerometerGraph/index.html" rel="noreferrer">AccelerometerGraph</a> sample app on iPhone OS 3.0.</p> <h2>Create Self-Signed Certificate</h2> <p>First you'll need to create a self signed certificate and patch your iPhone SDK to allow the use of this certificate:</p> <ol> <li><p>Launch Keychain Access.app. With no items selected, from the Keychain menu select Certificate Assistant, then Create a Certificate.</p> <p>Name: iPhone Developer<br> Certificate Type: Code Signing<br> Let me override defaults: Yes </p></li> <li><p>Click Continue</p> <p>Validity: 3650 days</p></li> <li><p>Click Continue</p></li> <li><p>Blank out the Email address field.</p></li> <li><p>Click Continue until complete.</p> <p>You should see "This root certificate is not trusted". This is expected.</p></li> <li><p>Set the iPhone SDK to allow the self-signed certificate to be used:</p> <blockquote> <p>sudo /usr/bin/sed -i .bak 's/XCiPhoneOSCodeSignContext/XCCodeSignContext/' /Developer/Platforms/iPhoneOS.platform/Info.plist</p> </blockquote> <p>If you have Xcode open, restart it for this change to take effect.</p></li> </ol> <h2>Manual Deployment over WiFi</h2> <p>The following steps require <code>openssh</code>, and <code>uikittools</code> to be installed first. Replace <code>jasoniphone.local</code> with the hostname of the target device. Be sure to set your own password on both the <code>mobile</code> and <code>root</code> users after installing SSH.</p> <p>To manually compile and install your application on the phone as a system app (bypassing Apple's installation system):</p> <ol> <li><p>Project, Set Active SDK, Device and Set Active Build Configuration, Release.</p></li> <li><p>Compile your project normally (using Build, not Build &amp; Go).</p></li> <li><p>In the <code>build/Release-iphoneos</code> directory you will have an app bundle. Use your preferred method to transfer this to /Applications on the device.</p> <blockquote> <p><code>scp -r AccelerometerGraph.app root@jasoniphone:/Applications/</code></p> </blockquote></li> <li><p>Let SpringBoard know the new application has been installed:</p> <blockquote> <p><code>ssh mobile@jasoniphone.local uicache</code></p> </blockquote> <p>This only has to be done when you add or remove applications. Updated applications just need to be relaunched.</p></li> </ol> <p>To make life easier for yourself during development, you can setup SSH key authentication and add these extra steps as a custom build step in your project.</p> <p>Note that if you wish to remove the application later you cannot do so via the standard SpringBoard interface and you'll need to use SSH and update the SpringBoard:</p> <pre><code>ssh root@jasoniphone.local rm -r /Applications/AccelerometerGraph.app &amp;&amp; ssh mobile@jasoniphone.local uicache </code></pre>
<p>*Changes/Notes to make this work for <strong>Xcode 3.2.1</strong> and <strong>iPhone SDK 3.1.2</strong></p> <p>Manual Deployment over WiFi</p> <p>2) Be sure to restart Xcode after modifying the Info.plist</p> <p>3) The "uicache" command is not found, using killall -HUP SpringBoard worked fine for me.</p> <p>Other then that, I can confirm this works fine.</p> <p>Mac users, using PwnageTool 3.1.4 worked great for Jailbreaking (DL via torrent).</p>
5,813
<p>I'd like to discuss the case <a href="https://3dprinting.stackexchange.com/questions/1144/how-to-enlarge-a-sketchup-model">'How to enlarge a Sketchup Model'</a> question and my answer of course.</p> <p>I do agree with Robert Cartaino when he said: '<em>The folks here will work hard to curate this collection of knowledge(...)</em>'</p> <p>It's true that SE forums are so valuable also because there are hard working moderators and editors - no doubt.</p> <p>I also agree with this (but with some objections): '<em>(...) when someone finally finds this site through search, the last thing we want to do is send them elsewhere to find that information</em>'</p> <p>Being strict, according to this part, linking is not allowed... which is not true isn't it?. I didn't link poor websites or other forums or any information from "somewhere" / "elsewhere". I did link "the sources", pages which are the real sources of the knowledg in the case of asked question. And because these sources are quite big and stable, it's high prpbablility that there were available for long time (till the question and answer will have any meaning) and they will be the most accurate and up to date as possible.</p> <p>So the question is, should I rewrite such sources just because answer based on links is not allowed or maybe it's better to be not such strict.</p> <p>Please consider and express what you think about such situations.</p> <p>ps: I admit my answer could be comment insted of answer and if there will be such will of mods I'll rewrite it as comment as I wanted to help this user (and I think he upvoted which means he gathered the knowledge he asked for).</p>
<p>Looking at other SE sites, the most common approach seems to make everything lowercase (including names and trademarks) and using hyphens whenever there would be a space or hyphen in normal usage.</p> <p>As such:</p> <ul> <li><p>MatterControl becomes mattercontrol</p></li> <li><p>Makerbot becomes makerbot</p></li> <li><p>Post-production becomes post-production</p></li> <li><p>Post-processing becomes post-processing</p></li> <li><p>Multi-material becomes multi-material</p></li> </ul>
<p>I would say we could use synonyms to stay with clear tag namespace.In this case we apply following pattern (especially for proper name (product name)):</p> <pre><code>Topic | Existing tag | Synonym? ---------------+-----------------+-------------- MatterControl | mattercontrol | matter-control </code></pre> <p>I think dash could be used to separate kinda branch for example:</p> <pre><code>app-cura, app-mattercontrol, app-meshmixer &lt;&lt; these could be also synonyms 3d-printer, 3d-models, 3d-design </code></pre> <p>of course we already have tags like</p> <pre><code>feature-request, switching-power-supply </code></pre> <p>but they are descriptive and would be unreadable written as one word, one may say these describe actions</p>
30
<p>I have just installed C# for the first time, and at first glance it appears to be very similar to VB6. I decided to start off by trying to make a 'Hello, World!' UI Edition.</p> <p>I started in the Form Designer and made a button named "Click Me!" proceeded to double-click it and typed in</p> <pre><code>MessageBox("Hello, World!"); </code></pre> <p>I received the following error:</p> <p>MessageBox is a 'type' but used as a 'variable'</p> <p>Fair enough, it seems in C# MessageBox is an Object. I tried the following</p> <pre><code>MessageBox a = new MessageBox("Hello, World!"); </code></pre> <p>I received the following error: MessageBox does not contain a constructor that takes '1' arguments</p> <p>Now I am stumped. Please help.</p>
<p>MessageBox.Show also returns a DialogResult, which if you put some buttons on there, means you can have it returned what the user clicked. Most of the time I write something like</p> <pre><code>if (MessageBox.Show("Do you want to continue?", "Question", MessageBoxButtons.YesNo) == MessageBoxResult.Yes) { //some interesting behaviour here } </code></pre> <p>which I guess is a bit unwieldy but it gets the job done.</p> <p>See <a href="https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.dialogresult" rel="noreferrer">https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.dialogresult</a> for additional enum options you can use here.</p>
<p>In the <code>System.Windows.Forms</code> class, you can find more on the <a href="http://www.msdn.com/" rel="nofollow">MSDN</a> page for this here. Among other things you can control the message box text, title, default button, and icons. Since you didn't specify, if you are trying to do this in a webpage you should look at triggering the javascript <code>alert("my message");</code> or <code>confirm("my question");</code> functions.</p>
7,158
<p>I've recently been looking into targeting the .NET Client Profile for a WPF application I am building. However, I was frustrated to notice that the Client Profile is only valid for the following OS configurations: </p> <ul> <li>Windows XP SP2+</li> <li><strike>Windows Server 2003</strike> <strong>Edit:</strong> <a href="http://blogs.windowsclient.net/trickster92/archive/2008/05/21/introducing-the-net-framework-client-profile.aspx" rel="nofollow noreferrer">Appears</a> the Client Profile will not install on Windows Server 2003.</li> </ul> <p>In addition, the client profile is <strong>not</strong> valid for x64 or ia64 editions; and will also not install if <em>any previous version of the .NET Framework has been installed</em>.</p> <p>I'm wondering if the effort in adding the extra OS configurations to the testing matrix is worth the effort. Is there any metrics available that state the percentage of users that could possibly benefit from the client profile? I believe that once the .NET Framework has been installed, extra information is passed to a web server as part of a web request signifying that the framework is available. Granted, I would imagine that Windows XP SP2 users without the .NET Framework installed would be a large amount of people. It would then be a question of whether my application targeted those individuals specifically.</p> <p>Has anyone else determined if it is worth the extra effort to target these specific users?</p> <p><strong>Edit: It seems that it is possible to get a compiler warning if you use features not included in the Client Profile. As I usually run with warnings as errors, this will hopefully be enough to minimise testing in this configuration.</strong> Of course, this configuration will still need to be tested, but it should be as simple as testing if the install/initial run works on XP with SP2+.</p>
<p>Ultimately, it will not hurt any users if you target the Client Profile. This is because the client profile is a subset of the .net framework v3.5 sp1, and if v3.5 sp1 is already installed you don't need to install anything. </p> <p>The assemblies in the client profile are the same binaries as the full framework, so unless you're loading assemblies dynamically, then you shouldn't need to do any additional testing. </p> <p>My thinking is that unless you must use assemblies which are NOT in the client profile, then you should target it. </p> <p>As for the OS requirements, WPF won't run on pre-XP sp2, so if you need to run on other OSes, then you'll have to use WinForms anyways.</p> <p>EDIT:</p> <blockquote> <p>On IE, yes. It sends the .NET Framework version as part of the UA string, e.g.:</p> </blockquote> <p>Actually so does FF3+3.5sp1:</p> <blockquote> <p>Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 (.NET CLR 3.5.30729)</p> </blockquote>
<blockquote> <p>I believe that once the .NET Framework has been installed, extra information is passed to a web server as part of a web request signifying that the framework is available.</p> </blockquote> <p>On IE, yes. It sends the .NET Framework version as part of the UA string, e.g.:</p> <pre><code>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; .NET CLR 2.0.50727). </code></pre>
3,648
<p>Is it possible to use overlapped I/O with an anonymous pipe? CreatePipe() does not have any way of specifying FILE_FLAG_OVERLAPPED, so I assume ReadFile() will block, even if I supply an OVERLAPPED-structure. </p>
<p>Here is an implementation for an anonymous pipe function with the possibility to specify FILE_FLAG_OVERLAPPED:</p> <pre><code>/******************************************************************************\ * This is a part of the Microsoft Source Code Samples. * Copyright 1995 - 1997 Microsoft Corporation. * All rights reserved. * This source code is only intended as a supplement to * Microsoft Development Tools and/or WinHelp documentation. * See these sources for detailed information regarding the * Microsoft samples programs. \******************************************************************************/ /*++ Copyright (c) 1997 Microsoft Corporation Module Name: pipeex.c Abstract: CreatePipe-like function that lets one or both handles be overlapped Author: Dave Hart Summer 1997 Revision History: --*/ #include &lt;windows.h&gt; #include &lt;stdio.h&gt; static volatile long PipeSerialNumber; BOOL APIENTRY MyCreatePipeEx( OUT LPHANDLE lpReadPipe, OUT LPHANDLE lpWritePipe, IN LPSECURITY_ATTRIBUTES lpPipeAttributes, IN DWORD nSize, DWORD dwReadMode, DWORD dwWriteMode ) /*++ Routine Description: The CreatePipeEx API is used to create an anonymous pipe I/O device. Unlike CreatePipe FILE_FLAG_OVERLAPPED may be specified for one or both handles. Two handles to the device are created. One handle is opened for reading and the other is opened for writing. These handles may be used in subsequent calls to ReadFile and WriteFile to transmit data through the pipe. Arguments: lpReadPipe - Returns a handle to the read side of the pipe. Data may be read from the pipe by specifying this handle value in a subsequent call to ReadFile. lpWritePipe - Returns a handle to the write side of the pipe. Data may be written to the pipe by specifying this handle value in a subsequent call to WriteFile. lpPipeAttributes - An optional parameter that may be used to specify the attributes of the new pipe. If the parameter is not specified, then the pipe is created without a security descriptor, and the resulting handles are not inherited on process creation. Otherwise, the optional security attributes are used on the pipe, and the inherit handles flag effects both pipe handles. nSize - Supplies the requested buffer size for the pipe. This is only a suggestion and is used by the operating system to calculate an appropriate buffering mechanism. A value of zero indicates that the system is to choose the default buffering scheme. Return Value: TRUE - The operation was successful. FALSE/NULL - The operation failed. Extended error status is available using GetLastError. --*/ { HANDLE ReadPipeHandle, WritePipeHandle; DWORD dwError; UCHAR PipeNameBuffer[ MAX_PATH ]; // // Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED // if ((dwReadMode | dwWriteMode) &amp; (~FILE_FLAG_OVERLAPPED)) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } // // Set the default timeout to 120 seconds // if (nSize == 0) { nSize = 4096; } sprintf( PipeNameBuffer, "\\\\.\\Pipe\\RemoteExeAnon.%08x.%08x", GetCurrentProcessId(), InterlockedIncrement(&amp;PipeSerialNumber) ); ReadPipeHandle = CreateNamedPipeA( PipeNameBuffer, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_WAIT, 1, // Number of pipes nSize, // Out buffer size nSize, // In buffer size 120 * 1000, // Timeout in ms lpPipeAttributes ); if (! ReadPipeHandle) { return FALSE; } WritePipeHandle = CreateFileA( PipeNameBuffer, GENERIC_WRITE, 0, // No sharing lpPipeAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | dwWriteMode, NULL // Template file ); if (INVALID_HANDLE_VALUE == WritePipeHandle) { dwError = GetLastError(); CloseHandle( ReadPipeHandle ); SetLastError(dwError); return FALSE; } *lpReadPipe = ReadPipeHandle; *lpWritePipe = WritePipeHandle; return( TRUE ); } </code></pre>
<p>No. As explained <a href="http://msdn.microsoft.com/en-us/library/aa365141%28VS.85%29.aspx" rel="noreferrer">here</a>, anonymous pipes do not support asynchronous I/O. You need to use a named pipe. There's example code to do this on MSDN <a href="http://msdn.microsoft.com/en-us/library/aa365603%28VS.85%29.aspx" rel="noreferrer">here</a> and <a href="http://msdn.microsoft.com/en-us/library/aa365592%28VS.85%29.aspx" rel="noreferrer">here</a>.</p>
8,556
<p>Before I upgraded to Firefox 3 I used to constantly use the <a href="https://addons.mozilla.org/en-US/firefox/addon/655" rel="nofollow noreferrer">View Source Chart Firefox Addon</a> which shows the source HTML in a very organized, graphical form. Unfortunately, this addon is only for Firefox 2 and the beta version for Firefox 3 now costs $10 on the author's site. </p> <p>Anyone know of a similar addon that works for Firefox 3?</p> <p>(of course, I might indeed pay $10 for this, but first want to ask around if there isn't anything better and free, as the version for Firefox 2 had its limitations and I don't really want to pay $10 for something in beta that I can't test out before paying for it.)</p>
<p>Is <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" rel="nofollow noreferrer">Firebug</a> not sufficient?</p>
<p>You could always try Firefug. It sounds like it does a similar thing, plus more :)</p>
6,947
<p>Is it possible for <code>SelectNodes()</code> called on an <code>XmlDocument</code> to return null?</p> <p>My predicament is that I am trying to reach 100% unit test code coverage; ReSharper tells me that I need to guard against a null return from the <code>SelectNodes()</code> method, but I can see no way that an XmlDocument can return null (and therefore, no way to test my guard clause and reach 100% unit test coverage!)</p>
<p>Is it necessary to reach 100% code coverage? Indeed, is it even possible under normal (i.e. controllable, testable) circumstances? </p> <p>We often find that using "syntactic sugar" constructions like the <code>using {}</code> block, there are "hidden" code paths created (most likely <code>finally {}</code> or <code>catch {}</code> blocks) that can't be exercised unless some environmental condition (like a broken socket or broken disk) gets in the way.</p>
<p>If you are calling SelectNodes on the XmlDocument itself and it really is an XmlDocument and not a derived class than SelectNodes won't return null.</p> <p>If you create a descendant class and override the CreateNavigator(XmlNode) method then SelectNodes could return null.</p> <p>Similarly, if you call SelectNodes on an EntityReference, DocumentType or XmlDeclaration node, you'll get null as well</p> <p>In short, for 100% coverage on an XmlDocument or XmlNode you didn't just create, you have to test for null.</p>
8,178