instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>I've been running the built-in <a href="http://ant.apache.org/" rel="nofollow noreferrer">Ant</a> from the command line on a Macintosh (10.5.5) and have run into some trouble with the <strong>Mail</strong> task. Running the Mail task produces the following message:</p>
<pre><code>[mail] Failed to initialise MIME mail: org.apache.tools.ant.taskdefs.email.MimeMailer
</code></pre>
<p>This is most likely due to a missing ant-javamail.jar file in the /usr/share/ant/lib directory. I see a "ant-javamail-1.7.0.pom" file in this directory but not the appropriate jar file. Anyone know why this jar file might be missing and what the best way to resolve the problem is?</p>
|
<p>Here's what I ended up doing to resolve the problem:</p>
<ol>
<li>Downloaded the latest version of Ant from <a href="http://ant.apache.org/" rel="nofollow noreferrer">http://ant.apache.org/</a></li>
<li>The "built-in" Ant is installed in /usr/share/ant; I didn't want to overwrite that version so I extracted the new, full version into /usr/<strong><em>local</em></strong>/share/apache-ant-1.7.1/</li>
<li>As <a href="https://stackoverflow.com/users/17333/npellow">npellow</a> points out, the the Mac doesn't include mail.jar or activation.jar -- these files can be downloaded and extracted from <a href="http://java.sun.com/products/javamail/downloads/index.html" rel="nofollow noreferrer">JavaMail API</a> and <a href="http://java.sun.com/products/javabeans/glasgow/jaf.html" rel="nofollow noreferrer">JavaBeans Activation Framework</a> respectively and copied to the <em>new</em> ant lib folder (same folder as all the ant-*.jar files)</li>
<li>The ant command (/usr/bin/ant) is a symbolic link to /usr/share/ant/bin/ant; I updated this link to point to the new version (<code>ln -s /usr/local/share/apache-ant-1.7.1/bin/ant /usr/bin/ant</code>)</li>
</ol>
<p>If for some reason you need to make the old version of Ant the default again, just use<br>
<code>ln -s /usr/share/ant/bin/ant /usr/bin/ant</code></p>
<p>Steps 2-4 were done at the command prompt as root. That's it -- the Mac now has the latest, <em>complete</em> version of Ant and the Mail task works just fine. </p>
|
<p>I also got this working a slightly different way:</p>
<ol>
<li>Created directory <code>~/.ant/lib</code>.</li>
<li>Downloaded <a href="http://java.sun.com/products/javamail/downloads/index.html" rel="nofollow noreferrer">JavaMail API</a> and copied the jars into that directory.</li>
<li>Downloaded <a href="http://java.sun.com/javase/technologies/desktop/javabeans/jaf/downloads/index.html" rel="nofollow noreferrer">JavaBeans Activation Framework</a> and copied the jars into that directory.</li>
<li>Downloaded <a href="http://archive.apache.org/dist/ant/binaries/" rel="nofollow noreferrer">Apache Ant 1.7.0</a> (not the latest, matches the installed version) and copied the <code>apache-ant-1.7.0/lib/ant-javamail.jar</code> file into that directory.</li>
</ol>
<p>This only solves the problem for a single user account, but that was fine for my purposes and saved me the hassle of having two separate ant installations on my machine.</p>
| 29,502
|
<p>In an application where users can belong to multiple groups, I'm currently storing their groups in a column called <code>groups</code> as a binary. Every four bytes is a 32 bit integer which is the <code>GroupID</code>. However, this means that to enumerate all the users in a group I have to programatically select all users, and manually find out if they contain that group.</p>
<p>Another method was to use a unicode string, where each character is the integer denoting a group, and this makes searching easy, but is a bit of a fudge.</p>
<p>Another method is to create a separate table, linking users to groups. One column called <code>UserID</code> and another called <code>GroupID</code>.</p>
<p>Which of these ways would be the best to do it? Or is there a better way?</p>
|
<p>You have a many-to-many relationship between users and groups. This calls for a separate table to combine users with groups:</p>
<pre><code>User: (UserId[PrimaryKey], UserName etc.)
Group: (GroupId[PrimaryKey], GroupName etc.)
UserInGroup: (UserId[ForeignKey], GroupId[ForeignKey])
</code></pre>
<p>To find all users in a given group, you just say:</p>
<pre><code>select * from User join UserInGroup on UserId Where GroupId=<the GroupId you want>
</code></pre>
<p>Rule of thumb: If you feel like you need to encode multiple values in the same field, you probably need a foreign key to a separate table. Your tricks with byte-blocks or Unicode chars are just clever tricks to encode multiple values in one field. Database design should not use clever tricks - save that for application code ;-)</p>
|
<p>I would make 3 tables. users, groups and usersgroups which is used as cross-reference table to link users and groups. In usersgroups table I would add userId and groupId columns and make them as primary key. BTW. What naming conventions there are to name those xref tables?</p>
| 11,706
|
<p>I am printing ABS on an Ender 3 printer at a temperature of 240 °C on the nozzle and 110 °C on the bed. I am getting the following result:</p>
<p><a href="https://i.stack.imgur.com/FnLuQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FnLuQ.jpg" alt="enter image description here" /></a></p>
<p>Is there any way I can fix this?</p>
|
<p>I think that your bed is too hot because the bubbling is only on the bottom layer, if it was through out the entire print, I would say that it is your nozzle temp and you should do a temp tower, but because that isn't the case try lowering your bed temp</p>
|
<p>I had a similiar issue. First 2 to 4 layers looked god, than a trouble zone with 5 to 10 layers, and after that good again.
In my case the z-layer screws were not tight. During moving up I lost some steps due to the lose screws ...</p>
| 1,940
|
<p>When developing a desktop application in .NET, is it possible to not require the .NET Framework? Is developing software in .NET a preferred way to develop desktop applications? What is the most used programming language that software companies use to develop desktop applications?</p>
<p>Is the requirement of the .NET Framework just assumed based on the Windows OS you have installed hence why they list Windows OS version requirements?</p>
|
<p>You can still develop applications for the windows desktop using C/C++, eliminating the requirement to the .NET framework, but you'll need to make sure the necessary libraries are already on the system or installed.</p>
<p>The nice thing about the .NET framework is that Windows XP SP2 and Vista has the 3.0 framework runtime installed by default.</p>
<p>In a lot of ways, this is Microsoft's "development standard" and has been that way for a while. This allows you to not worry about having a bunch of libraries tacked onto your application. If you're sticking to all of the .NET provided libraries, you wind up only have to worry about deploying your executable, which is a big headache reliever. When you have a bunch of libraries you have to deploy as well, then you start to run into hassles when you write updates, because you have to make sure those updates are pushed out in your existing installer and to all the existing installed apps out there.</p>
<p>As for "preferred", that always tends to ruffle feathers at times, but there are more and more .NET developers wanted for the web and the desktop at the job hunt sites I tend to visit. 8^D</p>
<p>EDIT: Many thanks to Orion for pointing out my confusion on the frameworks. You get 3.0 "out the gate if you're on XP SP2 or Vista. Everything else is going to require a simple download or run of Windows Update.</p>
|
<p>It is possible not to require the .NET Framework; there are some companies that sell (for thousands of dollars, mind you) solutions that will allow you to do this. These are complete hacks, however, and not supported by Microsoft.</p>
<p>How you develop desktop applications (ie, using .NET or not) depends on your requirement. There isn't a preferred way.</p>
<p>Most used language is probably C#.</p>
| 3,236
|
<p>I'd like to write a script/batch that will bunch up my daily IIS logs and zip them up by month.</p>
<p>ex080801.log which is in the format of ex<em>yymmdd</em>.log</p>
<p>ex080801.log - ex080831.log gets zipped up and the log files deleted.</p>
<p>The reason we do this is because on a heavy site a log file for one day could be 500mb to 1gb so we zip them up which compresses them by 98% and dump the real log file. We use webtrend to analyze the log files and it is capable of reading into a zip file.</p>
<p>Does anyone have any ideas on how to script this or would be willing to share some code?</p>
|
<p>You'll need a command line tool to zip up the files. I recommend <a href="http://www.7-zip.org/download.html" rel="noreferrer">7-Zip</a> which is free and easy to use. The self-contained command line version (7za.exe) is the most portable choice.</p>
<p>Here's a two-line batch file that would zip the log files and delete them afterwards:</p>
<pre><code>7za.exe a -tzip ex%1-logs.zip %2\ex%1*.log
del %2\ex%1*.log
</code></pre>
<p>The first parameter is the 4 digit year-and-month, and the second parameter is the path to the directory containing your logs. For example: <code>ziplogs.bat 0808 c:\logs</code></p>
<p>It's possible to get more elaborate (i.e. searching the filenames to determine which months to archive). You might want to check out the Windows <a href="http://technet.microsoft.com/en-us/library/bb490907.aspx" rel="noreferrer">FINDSTR</a> command for searching input text with regular expressions.</p>
|
<p>Regex will do the trick... create a perl/python/php script to do the job for you..<br>
I'm pretty sure windows batch file can't do regex.</p>
| 4,914
|
<p>How can I set the cookies in my <code>PHP apps</code> as <code>HttpOnly cookies</code>?</p>
|
<ul>
<li>For <strong>your cookies</strong>, see this answer.</li>
<li>For <strong>PHP's own session cookie</strong> (<code>PHPSESSID</code>, by default), see <a href="https://stackoverflow.com/a/8726269/1820">@richie's answer</a></li>
</ul>
<p>The <a href="http://php.net/manual/en/function.setcookie.php" rel="noreferrer"><code>setcookie()</code></a> and <a href="http://php.net/manual/en/function.setrawcookie.php" rel="noreferrer"><code>setrawcookie()</code></a> functions, introduced the boolean <code>httponly</code> parameter, back in the dark ages of PHP 5.2.0, making this nice and easy. Simply set the 7th parameter to true, as per the syntax</p>
<p><em>Function syntax simplified for brevity</em></p>
<pre><code>setcookie( $name, $value, $expire, $path, $domain, $secure, $httponly )
setrawcookie( $name, $value, $expire, $path, $domain, $secure, $httponly )
</code></pre>
<p>In PHP < 8, specify <code>NULL</code> for parameters you wish to remain as default.</p>
<p>In PHP >= 8 you can benefit from using named parameters. See <a href="https://stackoverflow.com/a/64997399/1820">this question about named params</a>.</p>
<pre><code>setcookie( $name, $value, httponly:true )
</code></pre>
<p>It is also possible using the older, lower-level <a href="http://php.net/manual/en/function.header.php" rel="noreferrer"><code>header()</code></a> function:</p>
<pre><code>header( "Set-Cookie: name=value; HttpOnly" );
</code></pre>
<p>You may also want to consider if you should be setting the <code>Secure</code> parameter.</p>
|
<p>A more elegant solution since <strong>PHP >=7.0</strong> </p>
<pre><code>session_start(['cookie_lifetime' => 43200,'cookie_secure' => true,'cookie_httponly' => true]);
</code></pre>
<p><a href="https://www.php.net/manual/en/function.session-start.php" rel="nofollow noreferrer">session_start</a></p>
<p><a href="https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode" rel="nofollow noreferrer">session_start options</a></p>
| 5,747
|
<p>What's the difference between using a define statement and an enum statement in C/C++ (and is there any difference when using them with either C or C++)?</p>
<p>For example, when should one use</p>
<pre><code>enum {BUFFER = 1234};
</code></pre>
<p>over</p>
<pre><code>#define BUFFER 1234
</code></pre>
|
<p><code>enum</code> defines a syntactical element.</p>
<p><code>#define</code> is a pre-preprocessor directive, executed <em>before</em> the compiler sees the code, and therefore is not a language element of C itself.</p>
<p>Generally enums are preferred as they are type-safe and more easily discoverable. Defines are harder to locate and can have complex behavior, for example one piece of code can redefine a <code>#define</code> made by another. This can be hard to track down.</p>
|
<p>There is little difference. The C Standard says that enumerations have integral type and that enumeration constants are of type int, so both may be freely intermixed with other integral types, without errors. (If, on the other hand, such intermixing were disallowed without explicit casts, judicious use of enumerations could catch certain programming errors.)</p>
<p>Some advantages of enumerations are that the numeric values are automatically assigned, that a debugger may be able to display the symbolic values when enumeration variables are examined, and that they obey block scope. (A compiler may also generate nonfatal warnings when enumerations are indiscriminately mixed, since doing so can still be considered bad style even though it is not strictly illegal.) A disadvantage is that the programmer has little control over those nonfatal warnings; some programmers also resent not having control over the sizes of enumeration variables. </p>
| 16,568
|
<p>Is it possible to do Web form without using server control or set runat attribute on html control? How do you call the code behind function?</p>
|
<p>You can't call codebehind functions without a runat="server" tag at a minimum. If you created a Web Service instead, you could create a pure html/javascript page that interacted with the server through AJAX. These are your only two options to use ASP.Net as far as I know.</p>
|
<p>You can use a HTTPHandler for barebones ASP.NET.</p>
<p>You won't have a markup file, you'll just have a class that runs and exposes you to HttpContext for writing out to the HTTP stream.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/f3ff8w4a(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/f3ff8w4a(VS.71).aspx</a></p>
<p>In fact, HttpHandlers are the building blocks of all .NET web frameworks.</p>
| 34,028
|
<p>Let's say I wanted to make a python script interface with a site like Twitter.</p>
<p>What would I use to do that? I'm used to using curl/wget from bash, but Python seems to be much nicer to use. What's the equivalent?</p>
<p>(This isn't Python run from a webserver, but run locally via the command line)</p>
|
<p>For something like Twitter, you'll save yourself a ton of time by not reinventing the wheel. Try a library like <a href="http://code.google.com/p/python-twitter/" rel="nofollow noreferrer">python-twitter</a>. This way, you can write your script, or even a full fledged application, that interfaces with Twitter, and you don't have to care about the implementation details.</p>
<p>If you want to roll your own interface library, you're going to have to get familiar with <a href="https://docs.python.org/library/urllib.html" rel="nofollow noreferrer">urllib</a> and depending on what format they provide results, either <a href="http://lxml.de/" rel="nofollow noreferrer">lxml</a> (or some other xml parser) or <a href="http://undefined.org/python/#simplejson" rel="nofollow noreferrer">simplejson</a>.</p>
|
<p>If you're used to dealing with cURL, consider <a href="http://pycurl.sourceforge.net/" rel="nofollow noreferrer">PycURL</a>.</p>
| 36,203
|
<p>In Visual Basic 6, when I attempt to access <em>Project > References</em>, it throws an error:</p>
<blockquote>
<p>Error accessing system registry</p>
</blockquote>
<p>I am:</p>
<ul>
<li>Logged in as the local computer administrator </li>
<li>running Windows XP Professional and </li>
<li>I can execute <code>regedt32.exe</code> and access all the registry keys just fine. </li>
</ul>
<p>VB6 was installed as the local administrator. </p>
<p>Any idea why this happens? </p>
<hr>
<p>I'm running crystal reports 8.5 and it supposed to already have fixed that issue but apparently I still have the issue with 8.5 installed. I have also made the attempt of reinstalling crystal reports with no luck on the issue. </p>
|
<p>Depending on the Windows OS you have (I have Windows 7 Enterprise), you might want to try giving administrator rights to the REGTLIB.EXE (located in C:\Windws). Right click on the REGTLIB.EXE file. Select Properties from the pop-up menu. Then select the Compatiblity tab. On the Compatiblity tab, check/select the Run this program as Administrator checkbox. Click OK to save your changes. It might take take care of the problem for you. It worked for me. Good luck.</p>
|
<p>Have you tried <a href="http://www.tek-tips.com/viewthread.cfm?qid=729496&page=6" rel="nofollow noreferrer">this?</a> Basically, it seems that it is a crystal reports issue. Hope that helps.</p>
| 12,999
|
<p>I have a datagridview assigned a datasource to it. now how to add a new row to that grid and remove a row from it?</p>
|
<p>One way to do this is as follows:</p>
<p><strong>Step #1</strong> Setup the Data Adapter, Data Grid etc:</p>
<pre><code>// the data grid
DataGridView dataGrid;
// create a new data table
DataTable table = new DataTable();
// create the data adapter
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strDSN);
// populate the table using the SQL adapter
dataAdapter.Fill(table);
// bind the table to a data source
BindingSource dbSource = new BindingSource();
dbSource.DataSource = table;
// finally bind the data source to the grid
dataGrid.DataSource = dbSource;
</code></pre>
<p><strong>Step #2</strong> Setup the Data Adapter SQL Commands:</p>
<p>These SQL commands define how to move the data between the grid and the database via the adapter.</p>
<pre><code>dataAdapter.DeleteCommand = new SqlCommand(...);
dataAdapter.InsertCommand = new SqlCommand(...);
dataAdapter.UpdateCommand = new SqlCommand(...);
</code></pre>
<p><strong>Step #3</strong> Code to Remove Select lines from the Data Grid:</p>
<pre><code>public int DeleteSelectedItems()
{
int itemsDeleted = 0;
int count = dataGrid.RowCount;
for (int i = count - 1; i >=0; --i)
{
DataGridViewRow row = dataGrid.Rows[i];
if (row.Selected == true)
{
dataGrid.Rows.Remove(row);
// count the item deleted
++itemsDeleted;
}
}
// commit the deletes made
if (itemsDeleted > 0) Commit();
}
</code></pre>
<p><strong>Step #4</strong> Handling Row Inserts and Row Changes:</p>
<p>These types of changes are relatively easy to implement as you can let the grid manage the cell changes and new row inserts. </p>
<p>The only thing you will have to decide is when do you commit these changes. </p>
<p>I would recomment putting the commit in the <strong>RowValidated</strong> event handler of the DataGridView as at that point you should have a full row of data.</p>
<p><strong>Step #5</strong> Commit Method to Save the Changes back to the Database:</p>
<p>This function will handle all the pending updates, insert and deletes and move these changes from the grid back into the database.</p>
<pre><code>public void Commit()
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Do the connection using a DSN";
// open the connection
cn.Open();
// commit any data changes
dataAdapter.DeleteCommand.Connection = cn;
dataAdapter.InsertCommand.Connection = cn;
dataAdapter.UpdateCommand.Connection = cn;
dataAdapter.Update(table);
dataAdapter.DeleteCommand.Connection = null;
dataAdapter.InsertCommand.Connection = null;
dataAdapter.UpdateCommand.Connection = null;
// clean up
cn.Close();
}
</code></pre>
|
<p>I believe you'll have to get the Table collection item and retrieve the Row collection item from that. Then you can loop through the rows or however you want to remove the row.</p>
<p>You do this after binding it, of course.</p>
| 14,497
|
<p>In bash the ampersand (&) can be used to run a command in the background and return interactive control to the user before the command has finished running. Is there an equivalent method of doing this in Powershell?</p>
<p>Example of usage in bash:</p>
<pre><code> sleep 30 &
</code></pre>
|
<p>As long as the command is an executable or a file that has an associated executable, use <strong>Start-Process</strong> (available from v2):</p>
<pre><code>Start-Process -NoNewWindow ping google.com
</code></pre>
<p>You can also add this as a function in your profile:</p>
<pre><code>function bg() {Start-Process -NoNewWindow @args}
</code></pre>
<p>and then the invocation becomes:</p>
<pre><code>bg ping google.com
</code></pre>
<p>In my opinion, Start-Job is an overkill for the simple use case of running a process in the background:</p>
<ol>
<li>Start-Job does not have access to your existing scope (because it runs in a separate session). You cannot do "Start-Job {notepad $myfile}"</li>
<li>Start-Job does not preserve the current directory (because it runs in a separate session). You cannot do "Start-Job {notepad myfile.txt}" where myfile.txt is in the current directory.</li>
<li>The output is not displayed automatically. You need to run Receive-Job with the ID of the job as parameter.</li>
</ol>
<p>NOTE: Regarding your initial example, "bg sleep 30" would not work because sleep is a Powershell commandlet. Start-Process only works when you actually fork a process.</p>
|
<p>I've used the solution described here <a href="http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!130.entry" rel="nofollow noreferrer">http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!130.entry</a> successfully in PowerShell v1.0. It definitely will be easier in PowerShell v2.0.</p>
| 22,448
|
<p>So yeah, I'm a Java guy in this crazy iPhone world. When it comes to memory management I stiill don't have a very good idea of what I'm doing. </p>
<p>I have an app that uses a navigation controller, and when it's time to go on to the next view I have code that looks like this:</p>
<pre><code>UIViewController *myController = [[MyViewController alloc] initWithNibName:@"MyView"
bundle:[NSBundle mainBundle];
[[self navigationController] pushViewController:myController animated:YES];
</code></pre>
<p>Now according to Apple's fundamental rule on memory management</p>
<blockquote>
<p>You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, <code>alloc</code>, <code>newObject</code>, or <code>mutableCopy</code>), or if you send it a <code>retain</code> message. You are responsible for relinquishing ownership of objects you own using <code>release</code> or <code>autorelease</code>. Any other time you receive an object, you must not release it.</p>
</blockquote>
<p>To me that means that I should be releasing <code>myController</code>, or giving it an <code>autorelease</code> message. But, whenever I try doing that my application winds up crashing as I push and pop views off of the stack. </p>
<p>This didn't smell right to me, but in running Instruments it claims that I don't have any memory leaks. </p>
<p>So I my question is</p>
<ol>
<li>Am I doing this right?</li>
<li>Is the Navigation Controller taking ownership of MyViewController, explaining the lack of a memory leak?</li>
<li>Should I assign myController to an instance variable in my root ViewController? In that case it would be marked retain and I would release in the root's dealloc method</li>
</ol>
|
<p>The problem is (most likely) you're releasing your viewController <em>before</em> the Navigation Controller has a chance to claim ownership. There are two ways around this:</p>
<ul>
<li><code>-release</code> your controller <em>after</em> pushing it to the Nav Controller</li>
<li><code>-autorelease</code> your controller <em>before</em> pushing it. If you do this, the active NSAutoreleasePool (which you don't need to worry about) will take care of releasing your controller at a later time.</li>
</ul>
|
<p>The problem is (most likely) you're releasing your viewController <em>before</em> the Navigation Controller has a chance to claim ownership. There are two ways around this:</p>
<ul>
<li><code>-release</code> your controller <em>after</em> pushing it to the Nav Controller</li>
<li><code>-autorelease</code> your controller <em>before</em> pushing it. If you do this, the active NSAutoreleasePool (which you don't need to worry about) will take care of releasing your controller at a later time.</li>
</ul>
| 31,264
|
<p>How do I determine the (local-) path for the "Program Files" directory on a remote computer? There does not appear to any version of SHGetFolderPath (or related function) that takes the name of a remote computer as a parameter.</p>
<p>I guess I could try to query HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir using remote-registry, but I was hoping there would be "documented" way of doing it.</p>
|
<p>Those are all slightly different, and generally have an acceptable usage.</p>
<ul>
<li><code>var.</code><a href="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx" rel="noreferrer"><code>ToString</code></a><code>()</code> is going to give you the string representation of an object, regardless of what type it is. Use this if <code>var</code> is not a string already.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/0zk841e9.aspx" rel="noreferrer"><code>CStr</code></a><code>(var)</code> is the VB string cast operator. I'm not a VB guy, so I would suggest avoiding it, but it's not really going to hurt anything. I think it is basically the same as <code>CType</code>.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/4x2877xb.aspx" rel="noreferrer"><code>CType</code></a><code>(var, String)</code> will convert the given type into a string, using any provided conversion operators.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/7k6y2h6x.aspx" rel="noreferrer"><code>DirectCast</code></a><code>(var, String)</code> is used to up-cast an object into a string. If you know that an object variable is, in fact, a string, use this. This is the same as <code>(string)var</code> in C#.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/zyy863x8.aspx" rel="noreferrer"><code>TryCast</code></a> (as mentioned by @<a href="https://stackoverflow.com/questions/40764/how-should-i-cast-in-vbnet#40771">NotMyself</a>) is like <code>DirectCast</code>, but it will return <code>Nothing</code> if the variable can't be converted into a string, rather than throwing an exception. This is the same as <code>var as string</code> in C#. The <code>TryCast</code> page on MSDN has a good comparison, too.</li>
</ul>
|
<p>At one time, I remember seeing the MSDN library state to use CStr() because it was faster. I do not know if this is true though.</p>
| 6,204
|
<p>For example: <code>man(1)</code>, <code>find(3)</code>, <code>updatedb(2)</code>? </p>
<p>What do the numbers in parentheses (Brit. "brackets") mean?</p>
|
<p>It's the section that the man page for the command is assigned to.</p>
<p>These are split as</p>
<ol>
<li>General commands</li>
<li>System calls</li>
<li>C library functions</li>
<li>Special files (usually devices, those found in /dev) and drivers</li>
<li>File formats and conventions</li>
<li>Games and screensavers</li>
<li>Miscellanea</li>
<li>System administration commands and daemons</li>
</ol>
<p>Original descriptions of each section can be seen in the <a href="https://web.archive.org/web/20170601064537/http://plan9.bell-labs.com/7thEdMan/v7vol1.pdf" rel="noreferrer">Unix Programmer's Manual</a> (page ii).</p>
<p>In order to access a man page given as "foo(5)", run:</p>
<pre class="lang-sh prettyprint-override"><code>man 5 foo
</code></pre>
|
<p><a href="http://en.wikipedia.org/wiki/Man_page#Manual_sections" rel="nofollow noreferrer">Wikipedia</a> details about Manual Sections:</p>
<ol>
<li>General commands</li>
<li>System calls</li>
<li>Library functions, covering in particular the C standard library</li>
<li>Special files (usually devices, those found in /dev) and drivers</li>
<li>File formats and conventions</li>
<li>Games and screensavers</li>
<li>Miscellanea</li>
<li>System administration commands and daemons</li>
</ol>
| 8,846
|
<p>Ok, I am importing and parsing csv files in a C# app. I started out doing a simple ReadLine() and splitting on commas but it turns out some of the text fields have commas in them. So I started to roll my own splitting function. Fortunately, it was only a few minutes before the "Hey stupid, someone's probably already done this?" light came on and, after a few minutes of searching, realized I could just do an OleDb connection to the directory and import them that way. That worked like a champ, until I ran into a few files with commas and parentheses in the file names. Then it blew up. Any suggestions on getting it to import from files like that? And no, I have no control over the input file names. Some will probably be read directly from CD, so I can't temporarily change the file name.</p>
|
<p>I have used this <a href="http://www.codeproject.com/KB/database/CsvReader.aspx" rel="nofollow noreferrer">CsvReader</a>, works very well.</p>
|
<p>You can split on commas but massage the data by searching for pairs of fields that begin with and end with double-quotes and then recombine them.</p>
<p>You can manually walk the lines looking for commas while setting a quoteFound boolean on and off as you encounter double-quotes and ignore any commas encountered when quoteFound is true.</p>
<p>You could copy the source to the application directory as the first thing, renaming all files by adding a ".csv" to the end.</p>
<p>I'm pretty sure that I did this in a pleasingly clever manner with regex but I can't figure out which of my projects it was so I don't have code to provide.</p>
<p>ETA: I also think you can use the SqlBulkCopy class if you're reading into SQL Server and then you can query it however you need to.</p>
| 33,250
|
<p>I've run into a problem where I'm getting two printouts of my /etc/motd file on Gentoo Linux. sshd is doing one of the printouts, and I can toggle that by configuring /etc/ssh/sshd_config, but I can't find out who's printing the second copy. I can't disable sshd from printing out the motd due to an audit requirement. I'm running the bash shell, for what it's worth</p>
<p>Any ideas who's printing the second copy? I don't think it's bash, as when I change /etc/passwd to use /bin/ksh for my shell, I still get the motd displayed.</p>
<p>It's not /etc/issue, as that contains the string "This is \n (\s \m \r) (\l)", which is printed only when you're sitting in front of the machine.</p>
|
<p>Looks like the answer was in the /etc/pam.d/login and /etc/pam.d/system-login files. I had to comment out the pam_motd.so lines.</p>
|
<p>It is probably being done from the shell itself. Check the global profile and bashrc to see if this might be the case.</p>
| 23,177
|
<p>I just found myself creating a class called "InstructionBuilderFactoryMapFactory". That's 4 "pattern suffixes" on one class. It immediately reminded me of this:</p>
<p><a href="http://www.jroller.com/landers/entry/the_design_pattern_facade_pattern" rel="nofollow noreferrer">http://www.jroller.com/landers/entry/the_design_pattern_facade_pattern</a></p>
<p>Is this a design smell? Should I impose a limit on this number? </p>
<p>I know some programmers have similar rules for other things (e.g. no more than N levels of pointer indirection in C.)</p>
<p>All the classes seem necessary to me. I have a (fixed) map from strings to factories - something I do all the time. The list is getting long and I want to move it out of the constructor of the class that uses the builders (that are created by the factories that are obtained from the map...) And as usual I'm avoiding Singletons.</p>
|
<p>A good tip is: Your class public API (and that includes it's name) should reveal intention, not implementation. I (as a client) don't care whether you implemented the builder pattern or the factory pattern.</p>
<p>Not only the class name looks bad, it also tells nothing about what it does. It's name is based on its implementation and internal structure.</p>
<p>I rarely use a pattern name in a class, with the exception of (sometimes) Factories.</p>
<p>Edit:</p>
<p>Found an interesting <a href="http://www.codinghorror.com/blog/archives/000553.html" rel="noreferrer">article</a> about naming on Coding Horror, please check it out!</p>
|
<p>I've been thinking the same thing. In my case, the abundance of factories is caused by "build for testability". For example, I have a constructor like this:</p>
<pre><code>ParserBuilderFactoryImpl(ParserFactory psF) {
...
}
</code></pre>
<p>Here I have a parser - the ultimate class that I need.
The parser is built by calling methods on a builder.
The builders (new one for each parser that needs to be built) are obtained from builder factory.</p>
<p>Now, what the h..l is ParserFactory? Ah, I am glad you asked! In order to test the parser builder implementation, I need to call its method and then see what sort of parser got created. The only way to do it w/o breaking the incapsulation of the particular parser class that the builder is creating is to put an interception point right before the parser is created, to see what goes into its constructor. Hence ParserFactory. It's just a way for me to observe in a unit test what gets passed to the constructor of a parser.</p>
<p>I am not quite sure how to solve this, but I have a feeling that we'd be better off passing around classes rather than factories, and Java would do better if it could have proper class methods rather than static members.</p>
| 16,582
|
<p>Which of the WCF Service Protocols work well with Java?</p>
<p>Do the TCP Service Bindings work with java remoting (either Corba, EJB, JMS, etc.)?</p>
<p>What about the WebServices exposed as Service EndPoints. Have these been tested against the common Java WebServices stack for interoperability?</p>
|
<p>You will need to use one of the HTTP bindings. The TCP binding requires WCF to be on both sides.</p>
|
<p>WCF has been tested with Sun's Java WEbservices stack and Apache's Axis for interoperability.</p>
<p>So, I'd say it's pretty good.</p>
<p>Can you elaborate on "OR DOES TCP WORK AS WELL" ?</p>
<p>thank you,</p>
| 13,263
|
<p>Our product has the requirement of exporting its native format (essentially an XML file) to Excel for viewing/editing. However, what this entails is having a dependency on Excel (or Office) itself for our product build - something that we do not want. </p>
<p>What we have done is export the data from our native format to a csv file which can be opened in Excel. If user selects an option to open the generated report as well, we (try to) launch Excel application to open it (ofcourse it requires Excel to be already present on the client system).</p>
<p>The data for most part is flat list of records.</p>
<p>Is there a better format (or even a better way) to handle this requirement? This is a common requirement for many products - how do you handle this?</p>
|
<p>Excel versions, both 2007 and several previous, have native XML formats. 2007, obviously, is XML by default, and earlier versions have the ability to save as XML. <a href="https://stackoverflow.com/questions/174446/how-to-automate-converting-excel-xls-files-to-excel-xml-fromat">This SO question</a> deals with the issue. I'd guess a little inspection would give an idea of what's required. I don't know if a XSD/DTD exists for older versions, but a little creative Googling might yield something.</p>
|
<p>If you are working in Java, Checkout the POI project from APACHE.
<a href="http://poi.apache.org/" rel="nofollow noreferrer">http://poi.apache.org/</a></p>
<p>Simple, nice, complete, powerful.</p>
| 35,219
|
<p>I have a MSSQL2005 DB with about 140 tables. I want to create either an accessible diagram or a printable API type document with the table structure. Is there a program that offers this kind of db visualization?</p>
<p>I find the diagramming built into SQL Server to be very clunky and very inaccessible for my DB size.</p>
|
<p>Take a look at <a href="http://www.red-gate.com/products/SQL_Doc/index.htm" rel="nofollow noreferrer">SQL Doc</a>.</p>
|
<p>I always used Visio for this type of thing.</p>
| 23,445
|
<p>I've created a series of radio button controls in C#. <code>(radCompany, radProperty etc.)</code><br>
I've set their group name to be the same (282_Type) so they function as a list of radio buttons. </p>
<p>How do I retrieve the name <code>(like: ct100$m$dfgadjkfasdghasdkjfg$282_Type)</code> in c# so I can use this in a Javascript method i'm creating?</p>
<p>The values output are: </p>
<pre><code>Radion Button 1
id="ct223423432243_radCompany" name="ct100$sdfsdf$sdfsdf$282_Type"
Radion Button 2
id="ct223423432243_radProperty" name="ct100$sdfsdf$sdfsdf$282_Type"
</code></pre>
|
<p>You need to reference the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx" rel="nofollow noreferrer">ClientID</a> of the control; this is the id in the final html.</p>
<p>Of course, another approach might be to use some other attribute (such as the css etc), and use <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a> to find it; jQuery takes a lot of DOM pain away from javascript. It is interesting that jQuery is now even supported by VS2008 (with intellisense etc).</p>
<p>I'm currently reading <a href="http://www.manning.com/bibeault/" rel="nofollow noreferrer">jQuery in Action</a>, and liking it much. To take an example straight from the book (on the subject of radios):</p>
<pre><code>var x = $('[name=radioGroup]:checked').val();
</code></pre>
<p>which returns the value of the single checked radio button in the group, or <code>undefined</code> if none is selected.</p>
<p>Re getting the name; it uses the internal <code>UniqueGroupName</code> property, which does a lot of mangling. An option (but not an attractive one) would be to use reflection to read <code>UniqueGroupName</code>. Alternatively, use something simple like a literal control. Gawd I hate the ASP.NET forms model... roll on MVC...</p>
<p>Fianlly - I'm currently looking at the public <a href="http://www.microsoft.com/downloads/details.aspx?familyid=922b4655-93d0-4476-bda4-94cf5f8d4814&displaylang=en&tm" rel="nofollow noreferrer">VS2010 CTP</a> image; one of the new additions for ASP.NET is static <code>ClientID</code>s, by setting ClientIdMode = Static on the control. A bit overdue, but not unwelcome.</p>
|
<p>You want the UniqueID attribute:</p>
<blockquote>
<ul>
<li><p><strong>UniqueID</strong> — The hierarchically-qualified unique identifier assigned to a control by the ASP.NET page framework.</p>
</li>
<li><p><strong>ClientID</strong> — A unique identifier assigned to a control by the ASP.NET
page framework and rendered as the HTML ID attribute on the client.The
ClientID is different from the UniqueID because the UniqueID can
contain the colon character (:), which is not valid in the HTML ID
attribute (and is not allowed in variable names in client-side
script).</p>
</li>
</ul>
</blockquote>
<p>(<a href="http://msdn.microsoft.com/en-us/library/aa720435%28v=vs.71%29.aspx" rel="nofollow noreferrer">from here</a>)</p>
| 30,070
|
<p>I have written a C# Windows Forms application to merge the files and folders from a remote folder on one machine ("source" folder is a mapped drive - "Z:\folder") with another remote folder on a different machine ("destination" folder is a UNC path to a shared folder - "\\computername\sharedfolder"). I have Full permissions to both folders. When I run the program on my local machine, it works fine, but when I try to run it from from within the source folder it fails with a security exception.</p>
<p>The failure occurs when calling the DirectoryInfo constructor for the destination folder (i.e., DirectoryInfo(@"\\computername\sharedfolder"). I assume the problem is because I am running the program from a mapped drive. Any workarounds?</p>
<hr>
<p>The specific exception is:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</p>
<hr>
<p><strong>UPDATE</strong></p>
<p>okay, I got my application into Visual Studio 2008 (it was previously coded in 2005), targeted the .NET 3.5 framework, compiled and tried again.</p>
<p>I got the exact same error.</p>
<hr>
<p><strong>UPDATE - RESOLUTION</strong></p>
<p>I tried it with .NET 3.5, and it didn't work, then I noticed that you said 3.5 SP1. The service pack is definately needed.</p>
<p>Problem solved. Thank you.</p>
|
<p><a href="http://blogs.msdn.com/vancem/archive/2008/08/13/net-framework-3-5-sp1-allows-managed-code-to-be-launched-from-a-network-share.aspx" rel="noreferrer">.NET 3.5 SP1 allows running applications off a network share</a>. Previous versions did not allow it.</p>
|
<p>You need to enable FullTrust permissions for the application. .NET applications that run on a network share are given Local Intranet security permissions and thus run in a sandbox.</p>
<p>Here is a batch file that I wrote for one of our testing apps that runs off the network. It should get you up and running with minor modifications.</p>
<pre><code>@ECHO OFF
SET CASPOL=%windir%\Microsoft.NET\Framework\v2.0.50727\CasPol.exe
CLS
%CASPOL% -pp off
%CASPOL% -m -ag 1.2 -url file://server/directory/* FullTrust
</code></pre>
<p>As stated above, .NET 3.5 removes this behaviour.</p>
| 46,976
|
<p>Does cygwin allow a statically compiled binary? This would prevent the need for cygwin1.dll being on the PATH of target machines.</p>
|
<p>Nope, it's currently not possible to statically link against cygwin1.dll; if your application does not use unix emulation (i.e. pure win32) you can pass -mno-cygwin to the compiler.</p>
<p>See also the FAQ:<br>
<a href="http://cygwin.com/faq/faq.html#faq.programming.win32-no-cygwin" rel="noreferrer">http://cygwin.com/faq/faq.html#faq.programming.win32-no-cygwin</a><br>
<a href="http://cygwin.com/faq/faq.html#faq.programming.static-linking" rel="noreferrer">http://cygwin.com/faq/faq.html#faq.programming.static-linking</a></p>
|
<p>For Cygwin with mingw32 installed, your command line would be of the form</p>
<pre><code>x86_64-w64-mingw32-gcc.exe main.c -o main.exe
</code></pre>
<p>This bypasses the need for cygwin1.dll altogether.</p>
| 44,271
|
<p>Where can I download the JSSE and JCE source code for the latest release of Java? The source build available at <a href="https://jdk6.dev.java.net/" rel="noreferrer">https://jdk6.dev.java.net/</a> does not include the javax.crypto (JCE) packages nor the com.sun.net.ssl.internal (JSSE) packages.</p>
<p>Not being able to debug these classes makes solving SSL issues incredibly difficult.</p>
|
<p>there: <a href="http://openjdk.java.net/groups/security/" rel="noreferrer">openjdk javax.net</a> in the security group </p>
<pre><code>src/share/classes/javax/net
src/share/classes/com/sun/net/ssl
src/share/classes/sun/security/ssl
src/share/classes/sun/net/www/protocol/https
</code></pre>
<p>also on this page:</p>
<pre><code>src/share/classes/javax/crypto
src/share/classes/com/sun/crypto/provider
src/share/classes/sun/security/pkcs11
src/share/classes/sun/security/mscapi
</code></pre>
<blockquote>
<p>These directories contain the core
cryptography framework and three
providers (SunJCE, SunPKCS11,
SunMSCAPI). <strong>SunJCE</strong> contains Java
implementations of many popular
algorithms, and the latter two
libraries allow calls made through the
standard Java cryptography APIs to be
routed into their respective native
libraries.</p>
</blockquote>
|
<p>Put <a href="http://www.kpdus.com/jad.html" rel="nofollow noreferrer">Jad</a> on your system path. Install <a href="http://jadclipse.sourceforge.net/" rel="nofollow noreferrer">JadClipse</a> plugin for Eclipse. Use the force, read the decompiled source. :-)</p>
| 11,256
|
<p>Suppose you want to make an async request in JavaScript, but you want to pass some state along to the callback method. Is the following an appropriate use of closures in JavaScript?</p>
<pre><code>function getSomethingAsync(someState, callback) {
var req = abc.createRequestObject(someParams);
req.invoke(makeCallback(someState, callback));
}
function makeCallback(someState, callback) {
return function getSomethingCallback(data) {
var result = processDataUsingState(data, someState);
callback(result); // alternately/optionally pass someState along to result
}
}
</code></pre>
<p>If not, is there a better or more idiomatic way?</p>
|
<p>I don't see any immediate problems with this - closures are powerful for numerous reasons, one of which is removing the need to use global variables for state maintenance.</p>
<p>That said, the only thing you need to be wary of with regards to closures is memory leaks that typically occur in IE, but those are usually, IIRC, related to DOM elements and event handlers attached thereto.</p>
<p>Proceed!</p>
|
<p>its better (nicer) to use anonymous functions:</p>
<pre><code>function getSomethingAsync (someState, callback) {
req.invoke (function (data) {
var result = processDataUsingState (data, someState);
callback (result);
});
}
</code></pre>
| 31,289
|
<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, &$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->_result = $res;
$ths->_errorMsg = $error
}
function getResult()
{
return $this->_result;
}
function isError()
{
return ! ((boolean) $this->_result);
}
function getErrorMessage()
{
return $this->_errorMsg;
}
</code></pre>
| 9,818
|
<p>This is a total newbie question, so thanks in advance. I'm trying to get my head around the difference between divs and spans, and when and how to use them.</p>
<p>Say for instance, I want to have an image left justified, and I want the text to flow around the image on the right, while maintaining justification. If the text flows past the image, I want it to wrap around the bottom of the image...same as what we call in the layout world, "wrap".</p>
<p>I'm looking for an example to reference, so in your answer can you provide an example of the mark up?</p>
<p>Huge Thanks!!!</p>
|
<p>A SPAN tag is not intended to be a container for other tags. This is especially useful when combined with classes.</p>
<p>Use divs for defining sections of a page, and spans to enclose and style text or classes of text. </p>
<p><a href="http://www.learnwebdesignonline.com/htmlcourse/span-div.htm" rel="noreferrer">http://www.learnwebdesignonline.com/htmlcourse/span-div.htm</a> shows a good example of how they are used. For your example of wrapping text, float the image and wrap it all in a DIV - like so:</p>
<pre><code><div>
test test test test <img src="" alt="" style="float:left;margin:8px 0 0 8px; display:inline" /> test test test test test test test test test test test test
</div>
</code></pre>
|
<p>Divs and spans are kind like wildcard tags that have no semantic meaning. You can use them to group or identify elements when no other tag is appropriate (like tables, lists or headings). Their differences are:</p>
<p><strong>div</strong> </p>
<ul>
<li>it's a block level element </li>
<li><p>default display property is block which means:</p>
<ul>
<li>its as wide as its container</li>
<li>always makes line breaks before and after </li>
</ul></li>
<li>can contain other block level elements like <code>p</code>, <code>h1</code>, <code>table</code>, <code>ul</code>, <code>blockquote</code>, <code>div</code> </li>
<li>can contain other inline elements like <code>img</code>, <code>strong</code>, <code>em</code>, <code>input</code>, <code>a</code>, <code>span</code></li>
</ul>
<p><strong>span</strong> </p>
<ul>
<li>is an inline element </li>
<li><p>default display property is inline which means: </p>
<ul>
<li>is as narrow as its content </li>
<li>does not makes any line break if not necessary) </li>
<li>you can use the css property <code>vertical-align</code> with it</li>
</ul></li>
<li>can<strong>not</strong> contain block level elements</li>
<li>can contain other inline elements like <code>img</code>, <code>strong</code>, <code>em</code>, <code>input</code>, <code>a</code>, <code>span</code> </li>
</ul>
<p>You can always change their default display property with css, but you cannot change the type of elements they can contain, regardless of the display property value. For instance:</p>
<pre><code><span style="display:block">
this will be displayed like a div,
but still cannnot contain block level elements
</span>
</code></pre>
<p>Because they are "generic" tags, they're usually used for <a href="http://microformats.org" rel="nofollow noreferrer">microformats</a> in conjunction with classes. For instance: <code><span class="tel">555-5555</span></code>, because there is no <code><tel></code> tag.</p>
<p>As for the image wrapping, if the image is directly related to the text, you could use:</p>
<pre><code><p><img src="image.jpg" style="float: right" alt="my image" />Long paragraph.</p>
</code></pre>
<p>And no divs or spans would be required. However, if it is not, then you could use:</p>
<pre><code><p>unrelated to the image</p>
<div>
<img src="image.jpg" style="float: right" alt="my image" />
<p>Long paragraph.</p>
</div>
</code></pre>
<p>Here <code>div</code> is necessary because <code>p</code> is a block level element. </p>
<p>Finally, for more information you can check <a href="http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.4" rel="nofollow noreferrer">the official W3C spec topic</a> about divs and spans.</p>
| 47,954
|
<p>I'm experimenting with creating an add-in for Infopath 2007. The documentation is very skimpy. What I'm trying to determine is what kind of actions an add-in can take while designing a form. Most of the discussion and samples are for when the user is filling out the form. Can I, for example, add a new field to the form in the designer? Add a new item to the schema? Move a form field on the design surface? It doesn't appear so, but I can't find anything definitive.</p>
|
<p>What are you hoping to end up with at the end? The body, the subject, the sender, an attachment? You should spend some time with <a href="http://www.faqs.org/rfcs/rfc2822.html" rel="noreferrer">RFC2822</a> to understand the format of the mail, but here's the simplest rules for well formed email:</p>
<pre><code>HEADERS\n
\n
BODY
</code></pre>
<p>That is, the first blank line (double newline) is the separator between the HEADERS and the BODY. A HEADER looks like this:</p>
<pre><code>HSTRING:HTEXT
</code></pre>
<p>HSTRING always starts at the beginning of a line and doesn't contain any white space or colons. HTEXT can contain a wide variety of text, including newlines as long as the newline char is followed by whitespace.</p>
<p>The "BODY" is really just any data that follows the first double newline. (There are different rules if you are transmitting mail via SMTP, but processing it over a pipe you don't have to worry about that).</p>
<p>So, in really simple, circa-1982 <a href="http://www.faqs.org/rfcs/rfc822.html" rel="noreferrer">RFC822</a> terms, an email looks like this:</p>
<pre><code>HEADER: HEADER TEXT
HEADER: MORE HEADER TEXT
INCLUDING A LINE CONTINUATION
HEADER: LAST HEADER
THIS IS ANY
ARBITRARY DATA
(FOR THE MOST PART)
</code></pre>
<p>Most modern email is more complex than that though. Headers can be encoded for charsets or <a href="http://www.faqs.org/rfcs/rfc2047.html" rel="noreferrer">RFC2047</a> mime words, or a ton of other stuff I'm not thinking of right now. The bodies are really hard to roll your own code for these days to if you want them to be meaningful. Almost all email that's generated by an MUA will be <a href="http://www.faqs.org/rfcs/rfc2045.html" rel="noreferrer">MIME</a> encoded. That might be uuencoded text, it might be html, it might be a uuencoded excel spreadsheet.</p>
<p>I hope this helps provide a framework for understanding some of the very elemental buckets of email. If you provide more background on what you are trying to do with the data I (or someone else) might be able to provide better direction.</p>
|
<p>yeah, ive been able to write a basic parser, based off that rfc and some other basic tutorials. but its the multipart mime nested boundaries that keep messing me up.</p>
<p>i found out that MMS (not SMS) messages sent from my phone are just standard emails, so i have a system that reads the incoming email, checks the from (to only allow from my phone), and uses the body part to run different commands on my server. its sort of like a remote control by email.</p>
<p>because the system is designed to send pictures, its got a bunch of differently encoded parts. a mms.smil.txt part, a text/plain (which is useless, just says 'this is a html message'), a application/smil part (which the part that phones would pic up on), a text/html part with a advertisement for my carrier, then my message, but all wrapped in html, then finally a textfile attachment with my plain message (which is the part i use) (if i shove an image as an attachment in the message, its put at attachment 1, base64 encoded, then my text portion is attached as attachment 2)</p>
<p>i had it working with the exact mail format from my carrier, but when i ran a message from someone elses phone through it, it failed in a whole bunch of miserable ways.</p>
<p>i have other projects i'd like to extend this phone->mail->parse->command system to, but i need to have a stable/solid/generic parser to get the different parts out of the mail to use it.</p>
<p>my end goal would be to have a function that i could feed the raw piped mail into, and get back a big array with associative sub-arrays of headers var:val pairs, and one for the body text as a whole string</p>
<p>the more and more i search on this, the more i find the same thing: giant overdeveloped mail handling packages that do everything under the sun thats related to mails, or useless (to me, in this project) tutorials.</p>
<p>i think i'm going to have to bite the bullet and just carefully write something my self.</p>
| 3,398
|
<p>I'm working on a system that includes a large number of reports, generated using <a href="http://jasperforge.org/plugins/project/project_home.php?group_id=102" rel="noreferrer">JasperReports</a>. One of the newer features is that you can define styles for reports.</p>
<p>From the available docs I believe there is some way to have an external file defining styles to use, and you can reference that in your jasper reports. This allows a single style to be used by multiple reports.</p>
<p>I can't find any concrete information on whether this is an actual feature, and if it is, how to use it. Does anyone know if it is possible to have external styles for jasper reports, and if so, how to do it?</p>
|
<p>Use <a href="http://jasperreports.sourceforge.net/sample.reference/templates/#templates" rel="nofollow noreferrer">JasperReport templates</a>. A JasperReports template is one that ends in <code>.jrtx</code>, and may look similar to this (<code>styles.jrtx</code>):</p>
<pre><code><?xml version="1.0"?>
<!DOCTYPE jasperTemplate
PUBLIC "-//JasperReports//DTD Template//EN"
"http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">
<jasperTemplate>
<style name="Report Title" isDefault="false" hAlign="Center" fontSize="24" isBold="true"/>
<style name="Heading 1" isDefault="false" fontSize="18" isBold="true"/>
<style name="Heading 2" isDefault="false" fontSize="14" isBold="true"/>
</jasperTemplate>
</code></pre>
<p>and then in your <code>.jrxml</code> file, include it as a template:</p>
<pre><code>...
<template><![CDATA["styles.jrtx"]]></template>
...
</code></pre>
<p>iReport also understands this, so your styles are imported and shown in iReport correctly (though I did notice sometimes it wouldn't pick them up an a reload or recompile was necessary).</p>
|
<p>You can also avoid specifying the actual file name in the <code><template></code> element by using a parameter passed into your report at runtime</p>
<p><code><parameter name="TEMPLATE_FILE" isForPrompting="false" class="java.lang.String"/></code></p>
<p><code><template><![CDATA[$P{TEMPLATE_FILE}]]></template></code></p>
<p>where $P{TEMPLATE_FILE} is the full path to the style resource</p>
| 23,892
|
<p>I am aware of several "clear" filaments for a ABS or PLA printer. They, however, have a cloudy or frosted glass appearance. I do not believe this is possible to eliminate but I believe it can be reduced.</p>
<p>Are there effective ways to make a print have a more transparent appearance?</p>
|
<p>It depends on a lot of factors, type of plastic, whether the parts need to be strong, can you use a vase print, etc. Here's a few thoughts.</p>
<p>PLA - The brand of PLA makes a big difference, some can be printed very clear, some can't. Most of the transparent PLAs I've used print much more clear at around 240°C.</p>
<p>ABS - I've seen some pretty impressive clear parts printed as a single layer shell in ABS and then vapor smoothed. I tend to find ABS more translucent and less transparent though.</p>
<p>PETG - Again the specific PETG you use matters, but I haven't seen nearly as much variation as with PLA. I'm not sure how much temperature matters, but if it's too hot you get bubbles which will decrease clarity.</p>
<p>Thin Wall Prints - I don't have much experience here, but the Smooth On XTC-3D or vapor smoothing seem to be effective.</p>
<p>Solid Prints
If I want transparency, I usually print it at 100% infill (should be a real 100%, too much overextrusion or underextrusion will decrease transparency). Printing slower and with less cooling sometimes helps. It's easier to get the infill solid with a direct drive extruder, I couldn't get decent results with a long bowden tube (a short bowden tube works fine).</p>
<p>Here's a page where I tested 10 transparent filaments, the printed samples are 2mm thick, 100% infill - <a href="http://thrinter.com/10-transparent-filaments">http://thrinter.com/10-transparent-filaments</a>. Those samples are all overextruded a bit, you can get better results if you dial in the extrusion precisely, but that's hard to get right, and the optimal settings may change slightly depending on the part geometry. Larger nozzles and thicker layers may help to, but I haven't experimented much with that as there are significant downsides to that approach.</p>
|
<p>Use Taulman t-glase and after a light sanding with really fine paper (optional really, but go for it if you can), spray it with polyurethane varnish or something similar. Check out the article <a href="http://3dprint.com/29292/taulman-hacks-clear-t-glase-3d-printing-material/">here</a>.</p>
| 92
|
<p>How to hide controller name in Url?</p>
<p>I use the ASP.NET MVC.</p>
<p>The original url is: <a href="http://www.sample.com/Users.mvc/UserDetail/9615" rel="nofollow noreferrer">http://www.sample.com/Users.mvc/UserDetail/9615</a></p>
<p>The "Users" is controller name, the "UserDetail" is action name, and the "9615" is UserId.</p>
<p>How can I hide the controller name and action name in the url. </p>
<p>Just like this: <a href="http://www.sample.com/9615" rel="nofollow noreferrer">http://www.sample.com/9615</a></p>
<p>I have writed the following code in the Global.ascx.cs to hide the action name:</p>
<pre><code>routes.MapRoute(
"UserDetail", // Route name
"Users.mvc/{UserId}", // URL with parameters
new { controller = "Users", action = "UserDetail", UserId = "" } // Parameter defaults
);
</code></pre>
<p>Using the above code I hid the action name and got this url: <a href="http://www.sample.com/Users.mvc/9615" rel="nofollow noreferrer">http://www.sample.com/Users.mvc/9615</a></p>
<p>But how can I hide the controller name and get this url: <a href="http://www.sample.com/9615" rel="nofollow noreferrer">http://www.sample.com/9615</a></p>
<p>Thanks.</p>
|
<p>The idea is the same. You do just the thing you did to the action. However, your problem arises from the fact that IIS is probably not mapping www.xyz.com/1234 to ASP.NET runtime. To do so in IIS7, enable integrated mode and in IIS6, add a wildcard mapping in handler map that maps everything to ASP.NET.</p>
<p>To add a wildcard map, see <a href="http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx" rel="nofollow noreferrer">http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx</a> (Search for "IIS6 Extension-less URLs" in that page)</p>
<p>After that, simply add a route:</p>
<pre><code>routes.MapRoute("UserDetails", "{UserID}/{*name}",
new { controller = "Users", action = "UserDetail" , UserID=""});
</code></pre>
<p>This should do the trick.</p>
|
<p>MVC recognizes the difference between "{UserID}" and "{id}" so if you are going to have a route with only "{UserID}" in the Url you need to place it first in the list other wise it never gets hit. And make sure the default includes "id" since it will continually loop over "UserDetails" unless the default references id as apposed to UserID. I found this format works for me:</p>
<pre><code>routes.MapRoute("UserDetails",
"{UserID}",
new { controller = "Users", action = "UserDetail", id = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = "" } // Parameter defaults
);
</code></pre>
| 49,829
|
<p>I have a problem with the following code:</p>
<pre><code>for(i = 0;(i - 1)< n;i++)
{
char* b;
sprintf(b, "%d", i);
}
</code></pre>
<p>It compiles fine but when I run it it give me the infamous "0XC0000005 Access Violation" error. I have tried setting b to NULL, "", "0", 0 and a bunch of other stuff but then I get the "0XC0000005 Access Violation" error or "Expression: string != NULL. Any help would be appreciated!</p>
|
<p><code>sprintf</code> writes data into an existing buffer, which you pass into it as the first parameter. Currently you're not specifying a value for b at all, which means (IIRC in C) the value could be anything. If you set it to NULL or 0, <code>sprintf</code> is going to try to write into memory starting at address 0.</p>
<p>You need to create a buffer of the appropriate size, so that sprintf can write into it. For example:</p>
<pre><code>for(i = 0;(i - 1)< n;i++)
{
char b[10];
sprintf(b, "%d", i);
}
</code></pre>
<p>Whether that's <em>actually</em> how you want to allocate the buffer depends on what your real code wants to do with the results, of course.</p>
|
<p>Thank you very much! Since I needed a char* I rewrote the code to:</p>
<pre><code>for(i = 0;(i - 1)< n;i++)
{
char* b;
char a[100];
b = a;
sprintf(b, "%d", i);
}
</code></pre>
<p>and it works like a charm. I can finally now get on with my life! Once again thank you very very much!</p>
| 45,288
|
<p>I am developing an online exam using JSP/Servlets which is nearing completion. I'm planning to add timer function for the entire exam that shows elapsed time in minutes. How do I implement this with a fool-proof technique to implement this, because using javascript would mean that the user can turn off the feature in the browser. Any help on this would be highly appreciated.</p>
|
<p>Record the time that the user started and finished on the server. The user will have to press a button to indicate that they've started the exam, which can trigger the server to stamp the start time; when the final answer is submitted, the server can record the total time taken.</p>
|
<p>You can make javascript a requirement in the user's browser, and use javascript+AJAX - every minute, get the updated time from the server or make sure the times are synchronised.</p>
| 42,418
|
<p>One of the guys I work with needs a custom control that would work like a multiline ddl since such a thing does not exist as far as we have been able to discover</p>
<p>does anyone have any ideas or have created such a thing before<br>
we have a couple ideas but they involve to much database usage </p>
<p>We prefer that it be FREE!!!</p>
|
<p>From <a href="http://bytes.com/forum/thread16212.html" rel="noreferrer">this thread</a>, there are different ways to do this:</p>
<pre><code>double r = 5.1234;
System.out.println(r); // r is 5.1234
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);
// setScale is immutable
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
r = bd.doubleValue();
System.out.println(r); // r is 5.12
</code></pre>
<hr>
<pre><code>f = (float) (Math.round(n*100.0f)/100.0f);
</code></pre>
<hr>
<pre><code>DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" );
double dd = 100.2397;
double dd2dec = new Double(df2.format(dd)).doubleValue();
// The value of dd2dec will be 100.24
</code></pre>
<p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html" rel="noreferrer">DecimalFormat()</a> seems to be the most dynamic way to do it, and it is also very easy to understand when reading others code.</p>
|
<p>There are two approaches in the standard library. One is to use java.text.DecimalFormat. The other more cryptic methods (String.format, PrintStream.printf, etc) based around java.util.Formatter should keep C programmers happy(ish).</p>
| 7,333
|
<p>I'm new to C# and .Net in general so this may be a naive thing to ask. But anyway, consider this C# code:</p>
<pre><code>class A {
public int Data {get; set;}
}
class B {
public A Aval {get; set;}
}
</code></pre>
<p>The B.Aval property above is returning a reference to its internal A object. As a former C++ programmer, I find this dangerous because by exposing reference to an member object class B violates the principle of data hiding. Nonetheless, this seems to be the normal practice in the C# world.</p>
<p>My question is, if it is at all, why is such a design the usual approach as opposed to returning copies of internal members, which will be much safer in so many ways (including the case of thread safety)?</p>
<p>I understand that even in C++ sometimes good design demands that you do expose class members directly (a <strong>Car</strong> class with <strong>Engine</strong> and <strong>Stereo</strong> objects inside it comes to mind), but it is not the norm as seems to be in C#.</p>
|
<p>You're absolutely right - you should only return objects from properties where either the object is immutable, or you're happy for the caller to modify it to whatever extent they can. A classic example of this is returning collections - often it's much better to return a read-only wrapper round a collection than to return the "real" collection directly.</p>
<p>On the other hand, pragmatism sometimes calls for just documenting this as "please don't change the returned object" - particularly when it's an API which is only used within a company.</p>
<p>Hopefully there'll be more support for immutability in future versions of C# and .NET, which will make this easier to cope with - but it's likely to remain a knotty problem in many cases.</p>
|
<p>This isn't encapsulation - it's an act of abstraction through object composition or aggregation depending on how the internal object lifetimes are created/managed. </p>
<p>In composition patterns it is perfectly acceptable to access composite state e.g. the instance of A in the instance of B.</p>
<blockquote>
<p><a href="http://en.wikipedia.org/wiki/Object_composition" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Object_composition</a></p>
</blockquote>
<p>As you point out the semantics of encapsulation are <em>very different</em> - to completely hide the internal implementation of A e.g. by inheriting B from A.</p>
| 35,410
|
<p>Opening an Infopath form with parameter can be done like this:</p>
<pre><code>System.Diagnostics.Process.Start(PathToInfopath + "infopath.exe", "Template.xsn /InputParameters Id=123");
</code></pre>
<p>But that requires I know the path to Infopath.exe which changes with each version of Office. Is there a way to simply launch the template and pass a parameter? Or is there a standard way to find where Infopath.exe resides?</p>
|
<p>Play around with System.Diagnostics.ProcessStartInfo which allows you to specify a file you wish to open and also allows you to specify arguments.</p>
<p>You can then use Process.Start(ProcessStartInfo) to kick off the process. The framework will determine which application to run based on the file specified in the ProcessStartInfo.</p>
<p>I don't have Infopath installed so I unfortunately can't try it out. But hopefully it helps you out a little.</p>
|
<p>Try using browser based form and querystring instead</p>
| 10,726
|
<p>I have a web app which queries a Lucene index and it works just fine in a W2K3 server in my network. Now I got my azure code so I wanted to test the service uploading the app. In order to do that I had to install Vista (I did it in a Virtual machine) cause the Azure SDK won't install on an XP box.</p>
<p>I created my Cloud Service, added the files from my app but when I run it (just F5) I get a SecurityException, when I call Lucene to query the index, saying: </p>
<blockquote>
<p>The application attempted to perform
an operation not allowed by the
security policy. To grant this
application the required permission
please contact your system
administrator or change the
application's trust level in the
configuration file.</p>
</blockquote>
<p>I've been googling around and the solutions I've found concern modifying the machine.config file which is something I won't be able to do "in the cloud".</p>
<p>Could anybody help on this?</p>
|
<p>Ok, in case somebody is facing the same issues, this is the correct answer which I got from the Azure forum:</p>
<blockquote>
<p>This is because of the trust policy
for the Windows Azure CTP. The
enviroment variablies TEMP and TMP are
avaliable and set up appropiately.
However, System.IO.Path.GetTempPath
and System.IO.GetTempFile do not work
as they require unrestricted
environment permissions. I would
suggest you contact the Lucene
developers to see if they can modify
the code so it runs properly in medium
trust environments.</p>
</blockquote>
<p>Thanks to Daniel C. Wang for the answer.</p>
|
<p>Haven't done this but isn't it possible to have a desktop version of the Live Operating Environment? This would seem a good start for troubleshooting.</p>
| 42,444
|
<p>Is there a way to call an EJB that is served through WebSphere (iiop://host:port/ejbName) from a vanilla JRE (like Sun). A lot of people have been telling me that this type of architecture relies in a homogenous environment. Thoughts?</p>
|
<p>Yes, this is possible. You have to create something called a thin client. It has limitations on JNDI lookups due to not being part of the container environment, so fully qualified names have to be used.</p>
<p>Just search for "thin client ibm ejb" on google. Unfortunately, I don't have the link to the appropriate libraries (for WAS 6) here, they are at work.</p>
|
<p>Yes, this is possible. You have to create something called a thin client. It has limitations on JNDI lookups due to not being part of the container environment, so fully qualified names have to be used.</p>
<p>Just search for "thin client ibm ejb" on google. Unfortunately, I don't have the link to the appropriate libraries (for WAS 6) here, they are at work.</p>
| 17,216
|
<p>[This is for PC/Visual C++ specifically (although any other answers would be quite illuminating :))]</p>
<p>How can you tell if a pointer comes from an object in the stack? For example:</p>
<pre><code>int g_n = 0;
void F()
{
int *pA = &s_n;
ASSERT_IS_POINTER_ON_STACK(pA);
int i = 0;
int *pB = &i;
ASSERT_IS_POINTER_ON_STACK(pB);
}
</code></pre>
<p>so only the second assert <em>(pB)</em> should trip. I'm thinking using some inline assembly to figure out if it's within the SS segment register or something like that. Does anybody know if there's any built in functions for this, or a simple way to do this?</p>
<p>Thanks!
RC</p>
|
<p>Whatever you do, it'll be extremely platform-specific and non-portable. Assuming you're ok with that, read on. If a pointer points somewhere in the stack, it will lie between the current stack pointer <code>%esp</code> and the top of the stack.</p>
<p>One way to get the top of the stack is to read it in at the beginning of <code>main()</code>. However, this has a few problems:
- The top of the stack is actually slightly higher, since the C runtime initializes the stack before entering <code>main()</code>
- In C++, global objects' constructors are called before <code>main()</code>
- If your application is multithreaded, each thread has its own separate stack. In that case, you'd need a thread-local variable describing the base of the stack</p>
<p>One way to get the current stack pointer is using inline assembly:</p>
<pre><code>uint32_t GetESP(void)
{
uint32_t ret;
asm
{
mov esp, ret
}
return ret;
}
</code></pre>
<p>Beware of inlining and optimization! The optimizer might break this code.</p>
|
<p>Yes I am aware this is extremely unportable, but this is for an internal app to mimic other hardware's facilities for doing this. Seems the Thread Execution Block might be the way to go.</p>
| 43,926
|
<p>Rails has an awesome way of looking up column names and expected datatypes from the DB, alleviating a lot of programming.</p>
<p>I'm trying to build something like this in C#.NET, because we have large tables that are ever changing. I'll be adding parameters like so:</p>
<pre><code>SqlParameter param = new SqlParameter("parametername", *SqlDbType.Int*);
param.Direction = ParameterDirection.Input;
param.Value = 0;
comm.Parameters.Add(param);
</code></pre>
<p>Notice the SqlDbType. How can I get that? If I get DataColumns from the DataSet, all I can get is System types like System.string.</p>
|
<p>why not just let ADO.NET detect it automatically:</p>
<pre><code>SqlParameter param = new SqlParameter("parametername", value);
</code></pre>
<p>'course, you don't actually need Direction, either:</p>
<pre><code>comm.Parameters.Add(new SqlParameter("parametername",value));
</code></pre>
<p>I'm kind of a fan of doing things in one line :)</p>
|
<p>For our project we query the <code>INFORMATION_SCHEMA</code> tables before we build our SQL statements. If you stick the value in <code>DATA_TYPE</code> from <code>INFORMATION_SCHEMA.COLUMNS</code> into an <code>Enum.Parse</code> that should give you the correct value.</p>
| 34,422
|
<p>I'm aware I can add maven repositories for fetching dependencies in ~/.m2/settings.xml. But is it possible to add a repository using command line, something like:</p>
<pre><code>mvn install -Dmaven.repository=http://example.com/maven2
</code></pre>
<p>The reason I want to do this is because I'm using a continuous integration tool where I have full control over the command line options it uses to call maven, but managing the settings.xml for the user that runs the integration tool is a bit of a hassle.</p>
|
<p>You can do this but you're probably better off doing it in the POM as others have said.</p>
<p>On the command line you can specify a property for the local repository, and another repository for the remote repositories. The remote repository will have all default settings though</p>
<p>The example below specifies two remote repositories and a custom local repository.</p>
<pre><code>mvn package -Dmaven.repo.remote=http://www.ibiblio.org/maven/,http://myrepo
-Dmaven.repo.local="c:\test\repo"
</code></pre>
|
<p>I am using <code>xmlstarlet</code> to achieve this. Tested for Maven 3 on CentOS 7, Maven 2 was not tested yet.</p>
<pre class="lang-bash prettyprint-override"><code>XML_FULLPATH="$HOME/.m2/settings.xml"
MIRROR_ID='example'
MIRROR_MIRROROF='*'
MIRROR_NAME='Example Mirror'
MIRROR_URL='http://example.com/maven2'
## Preview settings without comment:
xmlstarlet ed -d '//comment()' "$XML_FULLPATH"
## Add Mirror settings:
xmlstarlet ed -L \
--subnode "/_:settings/_:mirrors" --type elem --name "mirrorTMP" --value "" \
--subnode "/_:settings/_:mirrors/mirrorTMP" --type elem --name "id" --value "$MIRROR_ID" \
--subnode "/_:settings/_:mirrors/mirrorTMP" --type elem --name "mirrorOf" --value "$MIRROR_MIRROROF" \
--subnode "/_:settings/_:mirrors/mirrorTMP" --type elem --name "name" --value "$MIRROR_NAME" \
--subnode "/_:settings/_:mirrors/mirrorTMP" --type elem --name "url" --value "$MIRROR_URL" \
--rename "/_:settings/_:mirrors/mirrorTMP" --value "mirror" \
"$XML_FULLPATH"
## Remove Mirror settings by id:
xmlstarlet ed -L \
--delete "/_:settings/_:mirrors/_:mirror[_:id=\"$MIRROR_ID\"]" \
"$XML_FULLPATH"
</code></pre>
<p>The idea is from: <a href="https://stackoverflow.com/a/9172796/6102698">How to insert a new element under another with xmlstarlet?</a>.</p>
| 9,645
|
<p>Is there a simple way to remove a leading zero (as in 01 becoming 1)?</p>
|
<p>You can use the <a href="http://php.net/ltrim" rel="noreferrer"><code>ltrim</code></a> function:</p>
<pre><code>ltrim($str,"0");
</code></pre>
|
<p>Just multiply by 1</p>
<pre><code>echo "01"*1
</code></pre>
| 42,867
|
<p>If I am trying to determine the read speed of a drive, I can code a routine to write files to a filesystem and then read those files back. Unfortunately, this doesn't give an accurate read speed because Windows does disk read caching. </p>
<p>Is there a way to flush the disk read cache of a drive in C# / .Net (or perhaps with Win32 API calls) so that I can read the files directly from the drive without them being cached?</p>
|
<p>Constantin: Thanks! That link has a command-line EXE which does the testing I was looking for. </p>
<p>I also found a link off that page to a more interesting article (in Word and PDF) on this page: <a href="http://research.microsoft.com/research/pubs/view.aspx?type=Technical%20Report&id=841" rel="noreferrer">Sequential File Programming Patterns and Performance with .NET</a></p>
<p>In this article, it talks about Un-buffered File Performance (iow, no read/write caching -- just raw disk performance.) </p>
<p>Quoted directly from the article:</p>
<blockquote>
<p>There is no simple way to disable
FileStream buffering in the V2 .NET
framework. One must invoke the Windows
file system directly to obtain an
un-buffered file handle and then
‘wrap’ the result in a FileStream as
follows in C#:</p>
</blockquote>
<pre><code> [DllImport("kernel32", SetLastError=true)]
static extern unsafe SafeFileHandle CreateFile(
string FileName, // file name
uint DesiredAccess, // access mode
uint ShareMode, // share mode
IntPtr SecurityAttributes, // Security Attr
uint CreationDisposition, // how to create
uint FlagsAndAttributes, // file attributes
SafeFileHandle hTemplate // template file
);
SafeFileHandle handle = CreateFile(FileName,
FileAccess.Read,
FileShare.None,
IntPtr.Zero,
FileMode.Open,
FILE_FLAG_NO_BUFFERING,
null);
FileStream stream = new FileStream(handle,
FileAccess.Read,
true,
4096);
</code></pre>
<blockquote>
<p>Calling CreateFile() with the
FILE_FLAG_NO_BUFFERING flag tells the
file system to bypass all software
memory caching for the file. The
‘true’ value passed as the third
argument to the FileStream constructor
indicates that the stream should take
ownership of the file handle, meaning
that the file handle will
automatically be closed when the
stream is closed. After this
hocus-pocus, the un-buffered file
stream is read and written in the same
way as any other.</p>
</blockquote>
|
<p>I found <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3127219&SiteID=1" rel="nofollow noreferrer">this</a> article and it seems that this is a complicated program because you also have to flush other caches.</p>
| 14,884
|
<p>I've enjoyed using the iTunes Store but I'm curious on what it was developed on (PHP & MySQL, Something Custom?). </p>
|
<p><a href="http://developer.apple.com/tools/webobjects/" rel="nofollow noreferrer">WebObjects</a>. It comes with XCode these days, but used to cost over $50 000! Not sure about the database backend. I seem to recall reading that it was Oracle, but I don't have a source and may have just accidentally made that up.</p>
|
<p>I think whatever answer you get will be 99% speculation. I would bet that if someone really did work for Apple and did have the facts they wouldn't be allowed to share them.</p>
| 43,800
|
<p>I added the following to my web.config to redirect the user to the login page if they aren't authenticated, but going to the URL does cause a redirect?</p>
<pre><code> <location path="user/add">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
</code></pre>
<p>I have setup forms authen. like this:</p>
<pre><code><authentication mode="Forms">
<forms loginUrl="/user/login"
protection="All"
timeout="30"
name="MyCookie"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
/>
</authentication>
</code></pre>
<p>Using .net and mvc.</p>
|
<p>Do you have the "Authorize" attribute on that Action or Controller?</p>
|
<p>For one of my applications I have the following in the same node as <code><authentication></code>: </p>
<pre><code><authorization>
<deny users="?"/>
</authorization>
</code></pre>
<p>But this covers the entire application...</p>
| 42,067
|
<p>I have a git repository which tracks an svn repository. I cloned it using <code>--stdlayout</code>.</p>
<p>I created a new local branch via <code>git checkout -b foobar</code></p>
<p>Now I want this branch to end up in <code>…/branches/foobar</code> in the svn repository.</p>
<p>How do I go about that?</p>
<p>(snipped lots of investigative text. see question history if you care)</p>
|
<p>I know this question has been answered a while ago, but after reading it, I it might help adding examples of the specific git svn branch command and relate it to a typical workflow.</p>
<p>Like kch answered, use <code>git svn branch</code>. Here is a full example, (note the <code>-n</code> for dry-run to test):</p>
<pre><code>git svn branch -n -m "Branch for authentication bug" auth_bug
</code></pre>
<p>If this goes well, server replies with answer like this:</p>
<blockquote>
<p>Copying <a href="https://scm-server.com/svn/portal/trunk" rel="noreferrer">https://scm-server.com/svn/portal/trunk</a> at r8914 to <a href="https://scm-server.com/svn/portal/branches/auth_bug" rel="noreferrer">https://scm-server.com/svn/portal/branches/auth_bug</a>...</p>
</blockquote>
<p>And without the <code>-n</code> switch the server probably adds something like:</p>
<blockquote>
<p>Found possible branch point: <a href="https://scm-server.com/svn/portal/trunk" rel="noreferrer">https://scm-server.com/svn/portal/trunk</a> => <a href="https://scm-server.com/portal/branches/auth_bug" rel="noreferrer">https://scm-server.com/portal/branches/auth_bug</a>, 8914</p>
<p>Found branch parent:
(refs/remotes/auth_bug)</p>
<p>d731b1fa028d30d685fe260f5bb912cbf59e1971</p>
<p>Following parent with do_switch</p>
<p>Successfully followed parent r8915 = 6ed10c57afcec62e9077fbeed74a326eaa4863b8</p>
<p>(refs/remotes/auth_bug)</p>
</blockquote>
<p>The best part of it, now you can create a local branch based on your remote branch like so:</p>
<pre><code>git checkout -b local/auth_bug auth_bug
</code></pre>
<p>Which means "check out and create local branch named <code>auth_bug</code> and make it follow the remote branch (last parameter) <code>auth_bug</code></p>
<p>Test that your local branch works on that remote branch by using <code>dcommit</code> with <code>--dry-run</code> (<code>-n</code>):</p>
<pre><code>git svn dcommit -n
</code></pre>
<p>And SVN server should reply with the new branch name:</p>
<blockquote>
<p>Committing to <a href="https://scm-server.com/svn/portal/branches/auth_bug" rel="noreferrer">https://scm-server.com/svn/portal/branches/auth_bug</a> ...</p>
</blockquote>
|
<p>@kch I just (7 December 2008) compiled the v1.6.1-rc1 tag of git and it does contain the git svn branch command and the documentation for it. So the v1.6.1 release of git should (hopefully) contain this command.</p>
| 33,402
|
<p>Using .NET 2.0 with WinForms, I'd like to create a custom, multi-columned menu (similiar to the word 2007 look&feel, but without the ribbon).</p>
<p>My approach was creating a control, and using a left/right docked toolstrip, I have constructed a similar look&feel of a menu. However, there are a few shortcomings of this solution, such as</p>
<ul>
<li>the control can only be placed, and displayed within the form; </li>
<li>if the form is too small, some area of the control won't be displayed;</li>
<li>the control also have to be manually shown/hidden.</li>
</ul>
<p>Thus, I'm looking for a way to display this control outside of the boundaries of the application. Creating a new form would result in title-bar deactivating on display, so that's also out. Alternatively, any other approach to create a customized menu would be very welcomed.</p>
<p>Edit: I don't want to use any commercial products for this; and since it's about a simple menu customization, it's not related to Microsoft's ribbon "research" in any way.</p>
|
<ul>
<li>unless you are in the business of providing .net components, you should be looking to buy it off the shelf. Its a lot of work getting such a control right - There are already vendors providing this kind of UI. e.g. <a href="http://www.componentone.com/SuperProducts/RibbonWinForms/" rel="nofollow noreferrer">ComponentOne</a></li>
<li>if you are trying to build this component as a product, you should look at the link below. Apparently Microsoft has a 'royalty-free' license around the Office UI to protect their R&D investments. As of now you need to tell them that you are using something similar to the Office UI. <a href="http://msdn.microsoft.com/en-us/office/aa973809.aspx" rel="nofollow noreferrer">More of that here</a></li>
</ul>
|
<ul>
<li>unless you are in the business of providing .net components, you should be looking to buy it off the shelf. Its a lot of work getting such a control right - There are already vendors providing this kind of UI. e.g. <a href="http://www.componentone.com/SuperProducts/RibbonWinForms/" rel="nofollow noreferrer">ComponentOne</a></li>
<li>if you are trying to build this component as a product, you should look at the link below. Apparently Microsoft has a 'royalty-free' license around the Office UI to protect their R&D investments. As of now you need to tell them that you are using something similar to the Office UI. <a href="http://msdn.microsoft.com/en-us/office/aa973809.aspx" rel="nofollow noreferrer">More of that here</a></li>
</ul>
| 9,659
|
<p>Oracle FAQ defines temp table space as follows:</p>
<blockquote>
<p>Temporary tablespaces are used to
manage space for database sort
operations and for storing global
temporary tables. For example, if you
join two large tables, and Oracle
cannot do the sort in memory, space
will be allocated in a temporary
tablespace for doing the sort
operation.</p>
</blockquote>
<p>That's great, but I need more detail about what exactly is using the space. Due to quirks of the application design most queries do some kind of sorting, so I need to narrow it down to client executable, target table, or SQL statement.</p>
<p>Essentially, I'm looking for clues to tell me more precisely what might be wrong with this (rather large application). Any sort of clue might be useful, so long as it is more precise than "sorting".</p>
|
<p>I'm not sure exactly what information you have to hand already, but using the following query will point out which program/user/sessions etc are currently using your temp space.</p>
<pre><code>SELECT b.TABLESPACE
, b.segfile#
, b.segblk#
, ROUND ( ( ( b.blocks * p.VALUE ) / 1024 / 1024 ), 2 ) size_mb
, a.SID
, a.serial#
, a.username
, a.osuser
, a.program
, a.status
FROM v$session a
, v$sort_usage b
, v$process c
, v$parameter p
WHERE p.NAME = 'db_block_size'
AND a.saddr = b.session_addr
AND a.paddr = c.addr
ORDER BY b.TABLESPACE
, b.segfile#
, b.segblk#
, b.blocks;
</code></pre>
<p>Once you find out which session is doing the damage, then have a look at the SQL being executed, and you should be on the right path.</p>
|
<p>One rule of thumb is that almost any query that takes more than a second probably uses some TEMP space, and these are not the just ones involving ORDER BYs but also:</p>
<ol>
<li>GROUP BYs (SORT GROUPBY before 10.2 and HASH GROUPBY from 10.2 onwards)</li>
<li>HASH JOINs or MERGE JOINs</li>
<li>Global Temp Tables (obviously)</li>
<li>Index rebuilds</li>
</ol>
<p>Occasionally, used space in temp tablespaces doesn't get released by Oracle (bug/quirk) so you need to manually drop a file from the tablespace, drop it from the file system and create another one.</p>
| 21,061
|
<p>Can jQuery ajax made browser request a new location in redirect header send by server?</p>
|
<p>You should parse the code and use Javascript to set the document.location</p>
<pre><code>$.get('page.php', { GETvar : 'redirectUrl' }, function(data, textString){
if (textString == "succes") { //Succes!
document.location = data;
}
else{ // failure }
});
</code></pre>
<p>If you PHP script returns a valid url this will set the location to that url. </p>
<p><b>EDIT</b><br>
You could also use a hidden iFrame like this:<br>
html:</p>
<pre>
<iframe src="blank.html" name='hiddenframe' id='hiddenframe' onload='readyLoad()'>
</pre>
<p>And then use some Javascript like this</p>
<pre><code>var first = true;
function setRedirect (url) {
hiddenframe.location = url;
}
function readyLoad() {
if( first == true ) { first = false; return false; }
else {
alert( 'ready loading, was redireced too:' + myFrame.location.href );
//Use new location code
}
}
</code></pre>
<p>You should wrap these function into nice little event handlers using jQuerys build in functions for that (they are great).</p>
|
<p>Haven't tried jQuery, and a quick peek at the doc doesn't really tell me what a redirect response is handled as. But in Prototype JS any response code other than 2xx "Success" is a onFailure event, thus a redirect is a failure. You could probably parse the response (somehow) in the error block to see what code it is and get the address, wich you can set the document.location to... But it doesn't sound very safe, or practical. </p>
<p>It's more common to print an error of some kind. Or, if the request requires a logged in user, to assume the session has timed out and redirect to the login page.</p>
| 42,199
|
<p>How do I search the whole classpath for an annotated class?</p>
<p>I'm doing a library and I want to allow the users to annotate their classes, so when the Web application starts I need to scan the whole classpath for certain annotation.</p>
<p>I'm thinking about something like the new functionality for Java EE 5 Web Services or EJB's. You annotate your class with <code>@WebService</code> or <code>@EJB</code> and the system finds these classes while loading so they are accessible remotely.</p>
|
<p>Use <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.html" rel="noreferrer">org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider</a> </p>
<p>API</p>
<blockquote>
<p>A component provider that scans the classpath from a base package. It then applies exclude and include filters to the resulting classes to find candidates. </p>
</blockquote>
<pre><code>ClassPathScanningCandidateComponentProvider scanner =
new ClassPathScanningCandidateComponentProvider(<DO_YOU_WANT_TO_USE_DEFALT_FILTER>);
scanner.addIncludeFilter(new AnnotationTypeFilter(<TYPE_YOUR_ANNOTATION_HERE>.class));
for (BeanDefinition bd : scanner.findCandidateComponents(<TYPE_YOUR_BASE_PACKAGE_HERE>))
System.out.println(bd.getBeanClassName());
</code></pre>
|
<p>Google <a href="http://code.google.com/p/reflections/" rel="nofollow">Reflections</a> seems to be much faster than Spring. Found this feature request that adresses this difference: <a href="http://www.opensaga.org/jira/browse/OS-738" rel="nofollow">http://www.opensaga.org/jira/browse/OS-738</a></p>
<p>This is a reason to use Reflections as startup time of my application is really important during development. Reflections seems also to be very easy to use for my use case (find all implementers of an interface).</p>
| 32,368
|
<p>I'm new to 3D printing and I recently got my first 3D printer, an Ender 3 Pro by Creality.</p>
<p>I've tried to find information about the type of nozzles should I look for. I'm trying to find stainless steel nozzles but there are so many models (M7, M8, etc.) and I have no idea what nozzle type I should get.</p>
<p>I've tried searching on Google but the only info I could find is that the extruder is an MK-10.</p>
<p>I am also looking for a heating cartridge for the hot end, but I still cannot find no information about the size that I need (15 mm/20 mm/30 mm). Also looked for info about the heated bed so I know what kind of thermistor I need (I found two types and no clue which one to get).</p>
<p>Where can I find some technical information about these?</p>
|
<p>The Ender 3 takes an M6 thread (metric 6 mm diameter). Measurement of stock nozzle shown. </p>
<p>Most sellers will list compatible printers Ender 2, Ender 3, Ender 4, CR-10, CR-10S, CR-10 Mini, CR-10-S4, CR-10-S5, CR-8, CR-7. Will Also Fit Any Other MK10 Heater Blocks. </p>
<p>I recently bought some titanium alloy nozzles as the brass one got closed over after crashing into the glass bed. </p>
<p><a href="https://i.stack.imgur.com/I1UPK.jpg" rel="nofollow noreferrer" title="Measurement of nozzle in digital calipers"><img src="https://i.stack.imgur.com/I1UPK.jpg" alt="Measurement of nozzle in digital calipers" title="Measurement of nozzle in digital calipers"></a></p>
|
<p>There is no such thing as a single MK10 hotend design. The Chinese aftermarket has mingled the designations.</p>
<p>If it has a <a href="https://groups.google.com/forum/m/#!topic/wanhao-printer-3d/TEdslEknny4" rel="nofollow noreferrer">MK10 like Makerbot</a> hotend, then the nozzles you are looking for are M7 threads. It appears (see <a href="https://3dprinting.stackexchange.com/a/7367/5740">this answer</a>) that your hotend is a cloned MK10 and has different dimensions, you have the M6 version.</p>
<p>Quote from link above: (this is about the Makerbot MK10)</p>
<blockquote>
<p>MK10 was a complete change of the hotend. MK10 uses smooth OD thermal
barriers with a larger 4mm OD 2mm ID PTFE liner. MK10 also uses M7
threads, vs the M6 of all previous models. This is because a 4mm PTFE
liner is barely enough metal to make the outer tube with m6 threads.
MK10 is completely incompatible with all previous hotend parts. Every
part is different. Mk10 still uses MK9 feeder parts.</p>
</blockquote>
<p>You could measure your current heat block (the width of the Aluminium block); if you look at the MK10 drawings of a proper M7 MK10 Makerbot (or derivative) hotend (below) you see that the width of the block is about 19 mm (which would be the length of the heater cartridge).</p>
<p><a href="https://i.stack.imgur.com/9TftHm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9TftHm.jpg" alt="MK10 Aluminium heater block dimensions"></a></p>
<p>The CEO of ToyBuilder labs explains the difference between an "MK10" and an MK8 in <a href="https://www.youtube.com/watch?v=UnI0aeTw9iA" rel="nofollow noreferrer">this video</a>:</p>
<p><a href="https://i.stack.imgur.com/Ah8Od.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ah8Od.png" alt=""MK10" vs. MK8 nozzle"></a></p>
<p>As can be seen, your nozzle clearly is not an MK10.</p>
| 1,082
|
<p>What's a good algorithm for calculating frames per second in a game? I want to show it as a number in the corner of the screen. If I just look at how long it took to render the last frame the number changes too fast.</p>
<p>Bonus points if your answer updates each frame and doesn't converge differently when the frame rate is increasing vs decreasing.</p>
|
<p>You need a smoothed average, the easiest way is to take the current answer (the time to draw the last frame) and combine it with the previous answer.</p>
<pre><code>// eg.
float smoothing = 0.9; // larger=more smoothing
measurement = (measurement * smoothing) + (current * (1.0-smoothing))
</code></pre>
<p>By adjusting the 0.9 / 0.1 ratio you can change the 'time constant' - that is how quickly the number responds to changes. A larger fraction in favour of the old answer gives a slower smoother change, a large fraction in favour of the new answer gives a quicker changing value. Obviously the two factors must add to one!</p>
|
<p>store a start time and increment your framecounter once per loop? every few seconds you could just print framecount/(Now - starttime) and then reinitialize them.</p>
<p>edit: oops. double-ninja'ed</p>
| 11,283
|
<p>XmlElement.Attributes.Remove* methods are working fine for arbitrary attributes resulting in the removed attributes being removed from XmlDocument.OuterXml property. Xmlns attribute however is different. Here is an example:</p>
<pre><code>XmlDocument doc = new XmlDocument();
doc.InnerXml = @"<Element1 attr1=""value1"" xmlns=""http://mynamespace.com/"" attr2=""value2""/>";
doc.DocumentElement.Attributes.RemoveNamedItem("attr2");
Console.WriteLine("xmlns attr before removal={0}", doc.DocumentElement.Attributes["xmlns"]);
doc.DocumentElement.Attributes.RemoveNamedItem("xmlns");
Console.WriteLine("xmlns attr after removal={0}", doc.DocumentElement.Attributes["xmlns"]);
</code></pre>
<p>The resulting output is</p>
<pre><code>xmlns attr before removal=System.Xml.XmlAttribute
xmlns attr after removal=
<Element1 attr1="value1" xmlns="http://mynamespace.com/" />
</code></pre>
<p>The attribute seems to be removed from the Attributes collection, but it is not removed from XmlDocument.OuterXml.
I guess it is because of the special meaning of this attribute.</p>
<p>The question is how to remove the xmlns attribute using .NET XML API.
Obviously I can just remove the attribute from a String representation of this, but I wonder if it is possible to do the same thing using the API.</p>
<p>@Edit: I'm talking about .NET 2.0.</p>
|
<p>.NET DOM API doesn't support modifying element's namespace which is what you are essentially trying to do. So, in order to solve your problem you have to construct a new document one way or another. You can use the same .NET DOM API and create a new element without specifying its namespace. Alternatively, you can create an XSLT stylesheet that transforms your original "namespaced" document to a new one in which the elements will be not namespace-qualified.</p>
|
<p>Yes, because its an ELEMENT name, you can't explicitly remove it. Using XmlTextWriter's WriteStartElement and WirteStartAttribute, and replacing the attribute with empty spaces will likely to get the job done. </p>
<p>I'm checking it out now. will update.</p>
| 10,206
|
<p>I'm a beginner with SQL and am working on one of my first databases. I am trying to create a very cut-down shopping cart and am currently working on getting the database together before I start coding the site.</p>
<p>One of the things I am struggling with is how to structure the products portion of the database. If all my products were individual items it would be ok. My problem is thatI would also like the ability to create "packages" of sorts that would combine several products into one Package/product with its own unique ID but different price.</p>
<p>Has anyone tackled this before...Heck, I am sure someone has. My question is: Is there a best practice way to structure the database tables to allow for this sort of thing? Logic-wise I am having a hard time wrapping my head around this one.</p>
|
<p>Ayende Rahien (of RhinoMocks) has recently been doing a series on building a shopping cart, starting here: <a href="http://ayende.com/Blog/archive/2008/12/07/designing-a-shopping-cart.aspx" rel="nofollow noreferrer">http://ayende.com/Blog/archive/2008/12/07/designing-a-shopping-cart.aspx</a>. It does use a class diagram but you should be able to convert the concept into a database diagram.</p>
|
<p>I would probably create a package table with the package id and price for the package and then have an intermediate (cross reference) table between the package and products with package IDs (as a FK to the package table) and corresponding product IDs (as FK to the product table).</p>
| 47,107
|
<p>Is there any way to parse a string in the format HH:MM into a Date (or other) object using the standard libraries?</p>
<p>I know that I can parse something like "9/17/2008 10:30" into a Date object using</p>
<pre><code>var date:Date = new Date(Date.parse("9/17/2008 10:30");
</code></pre>
<p>But I want to parse just 10:30 by itself. The following code will not work.</p>
<pre><code>var date:Date = new Date(Date.parse("10:30");
</code></pre>
<p>I know I can use a custom RegEx to do this fairly easily, but it seems like this should be possible using the existing Flex API.</p>
|
<p>If you have to use the exact format you specified, then you need to parse it yourself.</p>
<p>Here is a simple example (not tested):</p>
<pre><code>var str:String = "9/17/2008 10:30"
var items:Array = str.split(" ");
var dateElements:Array = items[0].split("/");
var timeElements:Array = items[1].split(":");
var n:Date = new Date(dateElements[2],
dateElements[0],
dateElements[1].
timeElements[0],
timeElements[1]);
</code></pre>
<p>If the time is not expressed in 24 clock, then there is no way to check for AM or PM (code will assume AM).</p>
|
<p>Have you considered prepending "01/01/2000 " to the time string and then applying Date?</p>
<p>Alternately there's probably a tokenizer that will take the input and split it up at the : giving you an array of strings you can convert to integers. A tokenizer isn't hard to write, either, and can be fun if one doesn't exist in flex.</p>
<p>-Adam</p>
| 11,073
|
<p>I'm using MS Access to create a database with over 5000 contacts. These contacts are separated up into which employee the contact belongs to, and then again into categories for easy searching. What I want to do is create a button that will open up a query in table form (simple), then have check boxes so an employee can select, for example, 100 contacts to send an email to out of the 110 in the table, and then send a mass email such as a newsletter (not so simple!). I've been going nuts trying to work out how to do this as I don't really understand programming (I'm a temp thrown into this job and just doing the best I can) and all I can find on the matter is something about loops (no idea!) and that I need software to do this. </p>
<p>Any solutions for me please? I'd like to avoid buying/installing software if possible and if you do have an answer, please make it as simple as possible...</p>
<p>Thanks in advance!</p>
<p>Kate</p>
|
<p>I have just created the following <strong>working</strong> example in MS Access 97.</p>
<p>A sample table (I tested the code with valid e-mail addresses):</p>
<p>ID Name Email</p>
<p>1 Rics rics@stack.com</p>
<p>2 Kate kate@stack.com</p>
<p>3 X x@stack.com</p>
<p>A form with one button.
The following code is being performed when the button is clicked:</p>
<pre><code>Private Sub Mail_Click()
Dim r As Recordset
Dim email As String
Set r = CurrentDb.OpenRecordset("select * from Addresses")
Do While Not r.EOF
email = r(2)
DoCmd.SendObject acSendNoObject, Null, Null, email, Null, Null, "Test subject", "Message body of the test letter", False, Null
r.MoveNext
Loop
r.Close
End Sub
</code></pre>
<p>I hope you could insert it into your application.</p>
|
<p>I think you're going to need to learn some VBA coding to get this done. This <a href="http://www.functionx.com/vbaccess/" rel="nofollow noreferrer">tutorial</a> might be useful.</p>
<p>Heres a way to <a href="http://www.febooti.com/products/command-line-email/online-help/send-email-ms-access.html" rel="nofollow noreferrer">send email from access</a>.</p>
| 44,081
|
<p>I have a sequential workflow with a number of Activities. One of these activities needs to access my paid S3 account. It works fine, but to be cautious, I would like to make sure it can handle unexpected situations, such as 'Host not found' or some timeout, etc.</p>
<p>So .. i would normally put the code inside a TRY / CATCH. That's fine .. but i'm not sure of what i should do with the workflow .. because if the code fails to complete correctly, the rest of the workflow shouldn't occur (based on the logic of this workflow).</p>
<p>So, i wanted to maybe retry the connect a few times .. and if that finally fails, call an Email Activity and terminate workflow.</p>
<p>Can anyone make any suggestions, links to vid's or screenies that help show what is the best practice for this?</p>
<p>cheers!</p>
|
<p>Take a look at the <a href="http://msdn.microsoft.com/en-us/library/system.workflow.componentmodel.faulthandleractivity.aspx" rel="nofollow noreferrer"><code>FaultHandlerActivity</code></a>, which is used to handle an Exception of the type specified by the <code>FaultType</code> property. Some links about error handling in WF:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms734771.aspx" rel="nofollow noreferrer">Fault Handling in Workflows</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms734709.aspx" rel="nofollow noreferrer">Using the FaultHandlerActivity Activity</a></li>
<li><a href="http://books.google.com/books?id=s5eVXpNmQxgC&pg=PA447&source=gbs_toc_r&cad=0_0" rel="nofollow noreferrer">Exception and Error Handling</a> (partial book chapter)</li>
</ul>
<p>Another way is to use the <a href="http://msdn.microsoft.com/en-us/library/system.workflow.componentmodel.activity.handlefault.aspx" rel="nofollow noreferrer"><code>Activity.HandleFault</code></a> method, which is called when an exception is raised within the context of the execution of your activity.</p>
|
<p>You might also want to have a look at this blog article on a custom Retry activity:
<a href="http://www.pluralsight.com/community/blogs/matt/archive/2007/11/28/49315.aspx" rel="nofollow noreferrer">http://www.pluralsight.com/community/blogs/matt/archive/2007/11/28/49315.aspx</a></p>
<p>Looks like it is just what you might need!</p>
| 35,304
|
<p>Word wrap is one of the must-have features in a modern text editor.</p>
<p>How word wrap be handled? What is the best algorithm for word-wrap?</p>
<p>If text is several million lines, how can I make word-wrap very fast?</p>
<p>Why do I need the solution? Because my projects must draw text with various zoom level and simultaneously beautiful appearance.</p>
<p>The running environment is Windows Mobile devices. The maximum 600 MHz speed with very small memory size.</p>
<p>How should I handle line information? Let's assume original data has three lines.</p>
<pre><code>THIS IS LINE 1.
THIS IS LINE 2.
THIS IS LINE 3.
</code></pre>
<p>Afterwards, the break text will be shown like this:</p>
<pre><code>THIS IS
LINE 1.
THIS IS
LINE 2.
THIS IS
LINE 3.
</code></pre>
<p>Should I allocate three lines more? Or any other suggestions?
</p>
|
<p>Here is a word-wrap algorithm I've written in C#. It should be fairly easy to translate into other languages (except perhaps for <code>IndexOfAny</code>).</p>
<pre class="lang-cs prettyprint-override"><code>static char[] splitChars = new char[] { ' ', '-', '\t' };
private static string WordWrap(string str, int width)
{
string[] words = Explode(str, splitChars);
int curLineLength = 0;
StringBuilder strBuilder = new StringBuilder();
for(int i = 0; i < words.Length; i += 1)
{
string word = words[i];
// If adding the new word to the current line would be too long,
// then put it on a new line (and split it up if it's too long).
if (curLineLength + word.Length > width)
{
// Only move down to a new line if we have text on the current line.
// Avoids situation where wrapped whitespace causes emptylines in text.
if (curLineLength > 0)
{
strBuilder.Append(Environment.NewLine);
curLineLength = 0;
}
// If the current word is too long to fit on a line even on it's own then
// split the word up.
while (word.Length > width)
{
strBuilder.Append(word.Substring(0, width - 1) + "-");
word = word.Substring(width - 1);
strBuilder.Append(Environment.NewLine);
}
// Remove leading whitespace from the word so the new line starts flush to the left.
word = word.TrimStart();
}
strBuilder.Append(word);
curLineLength += word.Length;
}
return strBuilder.ToString();
}
private static string[] Explode(string str, char[] splitChars)
{
List<string> parts = new List<string>();
int startIndex = 0;
while (true)
{
int index = str.IndexOfAny(splitChars, startIndex);
if (index == -1)
{
parts.Add(str.Substring(startIndex));
return parts.ToArray();
}
string word = str.Substring(startIndex, index - startIndex);
char nextChar = str.Substring(index, 1)[0];
// Dashes and the likes should stick to the word occuring before it. Whitespace doesn't have to.
if (char.IsWhiteSpace(nextChar))
{
parts.Add(word);
parts.Add(nextChar.ToString());
}
else
{
parts.Add(word + nextChar);
}
startIndex = index + 1;
}
}
</code></pre>
<p>It's fairly primitive - it splits on spaces, tabs and dashes. It does make sure that dashes stick to the word before it (so you don't end up with stack\n-overflow) though it doesn't favour moving small hyphenated words to a newline rather than splitting them. It does split up words if they are too long for a line.</p>
<p>It's also fairly culturally specific, as I don't know much about the word-wrapping rules of other cultures.</p>
|
<p>@ICR, thanks for sharing the C# example.</p>
<p>I did not succeed using it, but I came up with another solution. If there is any interest in this, please feel free to use this:
<em><a href="https://web.archive.org/web/20160403050733/http://johan.andersson.net/2010/11/03/wordwrap-function-in-c/" rel="nofollow noreferrer">WordWrap function in C#</a></em>. The source is available <a href="https://github.com/anderssonjohan/snippets/tree/master/wordwrap" rel="nofollow noreferrer">on GitHub</a>.</p>
<p>I've included unit tests / samples.</p>
| 3,819
|
<p>I'm looking to implement httpOnly in my legacy ASP classic sites.
Anyone knows how to do it?</p>
|
<pre><code>Response.AddHeader "Set-Cookie", "mycookie=yo; HttpOnly"
</code></pre>
<p>Other options like <code>expires</code>, <code>path</code> and <code>secure</code> can be also added in this way. I don't know of any magical way to change your whole cookies collection, but I could be wrong about that.</p>
|
<p>HttpOnly does very little to improve the security of web applications. For one thing, it only works in IE (Firefox "supports" it, but still discloses cookies to Javascript in some situations). For another thing, it only prevents a "drive-by" attack against your application; it does nothing to keep a cross-site scripting attack from resetting passwords, changing email addresses, or placing orders.</p>
<p>Should you use it? Sure. It's not going to hurt you. But there are 10 things you should be sure you're doing before you start messing with HttpOnly. </p>
| 7,900
|
<p>Are there any utilities or browser plugins that let you easily switch the version of the Flash player that is being used?</p>
|
<p>For Firefox 3.x on Window XP, Ubutntu Linux, and Mac OS X (Tiger and Leopard), <a href="http://www.sephiroth.it/firefox/flash_switcher/" rel="nofollow noreferrer">Flash Switcher</a> works well.</p>
|
<p>Found the following: <a href="http://www.google.be/search?q=firefox%20switch%20flash%20version" rel="nofollow noreferrer">http://www.google.be/search?q=firefox%20switch%20flash%20version</a></p>
<p><a href="http://www.sephiroth.it/weblog/archives/2006/10/flash_switcher_for_firefox.php" rel="nofollow noreferrer">http://www.sephiroth.it/weblog/archives/2006/10/flash_switcher_for_firefox.php</a> (seems nice)</p>
<p><a href="http://www.communitymx.com/content/article.cfm?page=2&cid=6FBA7" rel="nofollow noreferrer">http://www.communitymx.com/content/article.cfm?page=2&cid=6FBA7</a> (seems nicely integrated as well)</p>
<p><a href="https://addons.mozilla.org/nl/firefox/addon/5044" rel="nofollow noreferrer">https://addons.mozilla.org/nl/firefox/addon/5044</a> (from mozilla.org, must be good :p)</p>
| 9,884
|
<p>Help !!!</p>
<p>I have just spent about 10 minutes looking for a way to do a search and replace over all the files in Delphi 2006 project. </p>
<p>Please can you tell how to do it </p>
|
<p>I would use Grep Search from <a href="http://www.gexperts.org/" rel="noreferrer">GExperts</a> for this</p>
|
<p>To search all the files in your project you can use:</p>
<p><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>F</kbd></p>
| 32,284
|
<p>I'm really sick of this problem. Google searches always seem to suggest "delete all bpls for the package", "delete all dcus". Sometimes this just-does-not-work. Hopefully I can get some other ideas here.</p>
<p>I have a package written in-house, which had been installed without issue a few months ago. Having made a few changes to the source, I figured it was time to recompile/reinstall the package. Now I get two errors, the first if I choose "install" is</p>
<p><em>Access violation at address 02422108 in module 'dcc100.dll'. Read of address 00000000.</em></p>
<p>...or if I try to build/compile the package, I get</p>
<p><em>[Pascal Fatal Error] F2084 Internal Error: LA33</em></p>
<p>This is one of those Delphi problems that seems to occur time and time again for many of us. Would be great if we could collate a response something along the lines of "any one or combination of these steps <em>might</em> fix it, but if you do <em>all</em> these steps it <em>will</em> fix it...."</p>
<p>At the moment, I've removed all references to the bpl/dcp files for this package, but still getting the same error...</p>
<p>Using BDS2006 (Delphi)</p>
<p><em>Update 01-Oct-2008: I managed to solve this - see my post below. As I can't accept my own answer, I'm not entirely sure what to do here. Obviously these types of issues occur frequently for some people, so I'll leave it open for a while to get other suggestions. Then I guess if someone collates all the info into a super-post, I can accept the answer</em></p>
|
<p>I managed to solve this, following the below procedure</p>
<ol>
<li>Create a new package</li>
<li>One by one, add the components to the package, compile & install, until it failed.</li>
<li>Investigate the unit causing the failure.</li>
</ol>
<p>As it turns out, the unit in question had a class constant array, eg</p>
<pre><code>TMyClass = class(TComponent)
private
const ErrStrs: array[TErrEnum] of string
= ('', //erOK
'Invalid user name or password', //erInvUserPass
'Trial Period has Expired'); //erTrialExp
protected
...
public
...
end;
</code></pre>
<p>So it appears that Delphi does not like class constants (or perhaps class constant arrays) in package components</p>
<p><em>Update: and yes, this has been reported to codegear</em></p>
|
<p>For me, in D2010 disabling the compiler option "Emit runtime type information" did the trick.</p>
| 18,511
|
<p>For those agile practitioners out there...</p>
<p>How do you manage changes to a database schema during a project? My assumption is that in an agile project the schema of any database involved will change and be refactored just as happens with the codebase.</p>
<p>Is this assumption correct? If so, do you have any particular tools or processes that you use to help keep things running smoothly?</p>
|
<p><a href="http://www.agiledata.org/" rel="noreferrer">AgileData.org</a> is an excellent resource -- much more than I cram into a single response -- on Agile Database development. In particular, you might be interested in <a href="http://www.agiledata.org/essays/bestPractices.html" rel="noreferrer">Agile Data Best Practices</a>. If you use SQL Server, you might also be interested in SQL Compare from <a href="http://www.red-gate.com/index3.htm" rel="noreferrer">Red Gate</a> software. Our DBAs have used it to help me migrate changes from QA to Production for existing applications.</p>
|
<p>Take a look at <a href="http://wiki.rubyonrails.org/rails/pages/understandingmigrations" rel="nofollow noreferrer">Ruby on rails migrations</a>. Doesn't matter if you don't use Rails, as the idea has been copied to other framework already.</p>
| 43,307
|
<p>My first magnetic bed mat for my Ender 3 Pro is cracking underneath. On the top side there is a bubble in the middle which prevents any viable print. The layers are probably separating.</p>
<p>I am new to printing but have read many articles on hiccups to expect, fixes etc. I do understand these magnetic mats can break down. They're pretty cheap on Amazon (something like \$12 for a 2-pack). Not a huge deal. I've printed only about 1100g worth of filament over 30 prints. Despite their cheap price I don't feel I got a proper amount of mileage out of the mat. </p>
<p>I keep my bed at 60 °C and 215 °C for the filament. I'm pretty sure 60 °C is below the maximum temperature for this kind of bed. I am struggling to find articles on this issue. </p>
<p>What can I do to prolong the life of these mats? I have removed the mat (with its print) while the bed was still hot to remove items just as much as removing cold items. Am I supposed to wait until it's cold? The cracks I only assume are from flexing the mat. I'm not trying to fold it here. I do pull on the item as I'm curving the mat to break it free. I can't explain the bubble.</p>
<p>The bed deteriorated after my first large print which took 27 hours. Prior, longest print I had was about 5 hours, most prints 1-1.5 hours. Is this a factor?</p>
<p><a href="https://i.stack.imgur.com/Z69pA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z69pA.jpg" alt="gn"></a></p>
|
<p>My personal technique for removing prints (particularly larger prints) is not to flex the mat at all. Instead, I wait until it's cool and then work the spatula under an edge and move it under the model to basically peel it from the mat.</p>
<p>Smaller prints usually pop right off if I start with this technique from one end. </p>
<p>Surface area on the bed (for a single part) is most important to how much work is involved. For example, a raft or brim will greatly increase the surface area. The spatula is long enough that usually I can reach everywhere under the model so eventually it will pop free. I might have to work around the model a bit before it reaches this point.</p>
|
<p>My personal technique for removing prints (particularly larger prints) is not to flex the mat at all. Instead, I wait until it's cool and then work the spatula under an edge and move it under the model to basically peel it from the mat.</p>
<p>Smaller prints usually pop right off if I start with this technique from one end. </p>
<p>Surface area on the bed (for a single part) is most important to how much work is involved. For example, a raft or brim will greatly increase the surface area. The spatula is long enough that usually I can reach everywhere under the model so eventually it will pop free. I might have to work around the model a bit before it reaches this point.</p>
| 1,534
|
<p>For .net 3.5 SP1, Microsoft have the new client profile which installs only a subset of .net 3.5 SP1 on to Windows XP user's machines.</p>
<p>I'm aware of how to make my assemblies client-profile ready. And I've read the articles on how to implement an installer for <a href="http://msdn.microsoft.com/en-us/library/cc656916.aspx" rel="nofollow noreferrer">ClickOnce</a> or <a href="http://msdn.microsoft.com/en-us/library/cc656819.aspx" rel="nofollow noreferrer">MSI</a>.</p>
<p>But I've been using Inno Setup for my project so far and I'd like to continue to use it (as an Express user, I can't easily make MSIs), I need to know how to use the client-profile installer in a custom environment.</p>
<p>There is <a href="http://msdn.microsoft.com/en-us/library/cc656920.aspx" rel="nofollow noreferrer">an article</a> on a Deployment.xml schema, but no indication of how to write one, package it or anything else. Can someone explain this process? Finding the articles I linked to alone was a painful search experience.</p>
|
<p>Microsoft has now shipped the Client Profile Configuration Designer (Beta).</p>
<p>This designer lets you edit the XML files with some limitations, this isn't a 'Google beta' by any means.</p>
<p><a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-client-profile-config-overview.aspx" rel="nofollow noreferrer">Information and download</a></p>
|
<p>Can you clarify: Are you trying to write an installer for your app, which depends on the Client-Profile, or are you trying to write a custom installer <em>for</em> the client-profile?</p>
<p>I haven't used it personally, but if it's anything like the dotnetfx 1 and 2 msi's, you basically have to just invoke it's executable yourself from your own .exe file, or from an Msi BEFORE the InstallExecuteSequence starts up - you can't "embed" those in your own app, MS go out of their way to tell you not to do that due to suckage of MSI.</p>
| 3,482
|
<p>I've got an application that needs quite a bit of data (1000s of records) to do appropriate testing. The only way I've found to get a decent set of testable, sensible data is to use a <strong>subset of my production DB</strong>. I've converted this to YAML fixtures in the normal `test/fixtures' location.</p>
<p>This works, but now I have a bunch of seemingly brittle tests and assertions that depend on their being a particular number of records that meet condition X...</p>
<p>example</p>
<pre><code>def test_children_association
p = Parent.find(1)
assert_equal 18, p.children.count, "Parent.children isn't providing the right records"
end
</code></pre>
<p>This doesn't seem like a good idea to me, but <strong>I'm not sure if there is a better / accepted way</strong> to test an application that needs a large hierarchy of data.</p>
|
<p>Magic numbers in tests aren't an anti-pattern. Your tests need to be so dead-simple that you don't need to <em>test</em> them. This means you'll have some magic numbers. This means that your tests will break when you change small bits of functionality. This is good.</p>
<p>Fixtures have <a href="http://www.floehopper.org/articles/2006/06/27/rails-fixtures-help-or-hindrance" rel="noreferrer">some problems</a>, but there are a few simple things you can do to make them easier to work with:</p>
<ol>
<li><p>Only have baseline data in your fixtures, the sort of data that most of your tests need but don't care about. This will involve a time investment up front, but it's better to take the pain early than write poor unit tests for the life of the project.</p></li>
<li><p>Add the data to be tested in the context of the test. This improves readability of your tests and saves you from writing "make sure nobody messed up the fixtures" sanity checks at the beginning of your unit tests.</p></li>
</ol>
|
<p>The first thing I'd say is: what are you testing in that example? If it's an ordinary AR has_many association, then I wouldn't bother writing a test for it. All you're doing is testing that AR works.</p>
<p>A better example might be if you had a very complicated query or if there was other processing involved in getting the list of children records. When you get them back, rather than testing for a count you could iterate through the returned list and verify that the children match the criteria you're using.</p>
| 28,212
|
<p>Faulty endstop caused the printer (a traditional cartesian FDM) to try to move over the maximum axis limit at top, the noise has been atrocious, I don't see damages (apparently) but I'm wondering if this could have damaged something or the motors aren't strong enough to do any serious physical damage to mechanics of movement.</p>
<p>Could you clarify this?</p>
|
<p>It's highly unlikely this crash caused any physical or electrical damage to your printer. Printers are designed to be able to withstand an occasional crash as typically, no Axis Maximum endstops are installed. The 'atrocious' noise you describe hearing is the sound of the stepper motor having lost (or, in this case, repeatedly losing) steps. If you are worried, I would check that the X/Y Gantries are still in-tram and that the printer can still home itself without any problems.<br />
If this was a Z-Max runout (ie, printer tried to move too high), I would also check that the Z carriage is still on the Z axis Leadscrews before attempting to home, because if the Z carriage is not on one or both of the leadscrews, It is possible for the machine to engage them at different heights, throwing the X gantry out of tram or worse if only one leadscrew manages to re-engage.</p>
|
<p>The noise you heard was likely caused by the extruder keeping turning, resulting in the belt stretching enough to jump a tooth or more. I guess it was like "TRRRRR".</p>
<p>If the belt tension is properly set (not too tight), no damage can be caused. In fact, the belt should be loose enough so that such a mistake won't cause damages.</p>
<p>You could also reduce the current to the stepper motors in the future, to reduce even further the risk of damage.</p>
| 2,085
|
<p>I'm finding that hitting the "Refresh" button on my browser will temporarily screw up the ViewState for controls inside an UpdatePanel.</p>
<p>Here's my situation : I made a custom WebControl that stores values in the ViewState. I put this control inside an UpdatePanel. When I hit the "refresh" button on my browser, it will temporarily wipe out the values in ViewState. However, on the next postback, the values that were in the ViewState before I hit "refresh" magically reappear. </p>
<p>This behavior screws up my webcontrol. After I hit "refresh," the control is returned to its initial state, since the ViewState is empty and IsPostBack is set to false. However, when I click on one of the postback controls within my WebControl, the WebControl will reload with the same values that were in ViewState before I hit "refresh." </p>
<p>Strangely, this only happens when I'm using AJAX. When my control is outside of an UpdatePanel, Firefox gives me it's standard message, "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier (Resend) (Cancel)." This is fine, because at least the behavior is consistent. However, I absolutely must use AJAX for this project.</p>
<p>So this is what I would like to do - I want to make the "refresh" behavior consistent. It would be best if hitting "refresh" didn't affect the ViewState at all. But if it has to wipe out the ViewState, that's fine, as long as the ViewState STAYS wiped out. None of this stuff with values disappearing and reappearing.</p>
<p>Oh yeah, and here's my example code :</p>
<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace TestControls
{
public class TestControl : WebControl
{
int _clickCount;
bool _mustUpdate;
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
_clickCount = ((int)ViewState["clickCount"]);
_mustUpdate = ((bool)ViewState["mustUpdate"]);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Controls.Clear();
ControlCreator();
}
private void ControlCreator()
{
Label tempLabel = new Label();
LiteralControl tempLiteral = new LiteralControl("<br/><br/>");
LinkButton tempLink = new LinkButton();
tempLink.ID = "testLink";
tempLink.Text = "Click me!";
tempLink.Click += new EventHandler(tempLink_Click);
tempLabel.ID = "testLabel";
tempLabel.Text = _clickCount.ToString();
Controls.Add(tempLabel);
Controls.Add(tempLiteral);
Controls.Add(tempLink);
}
void tempLink_Click(object sender, EventArgs e)
{
_clickCount++;
_mustUpdate = true;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (_mustUpdate)
{
Controls.Clear();
ControlCreator();
_mustUpdate = false;
}
}
protected override object SaveViewState()
{
ViewState["clickCount"] = _clickCount;
ViewState["mustUpdate"] = _mustUpdate;
return base.SaveViewState();
}
}
}
</code></pre>
|
<p>I just re-read your question and realised I missed something... </p>
<p><strong>You are hitting the <em>browsers</em> refresh button!</strong></p>
<p>Is this a problem? <strong>YES!</strong></p>
<p>What happens when you hit the refresh button on the browser?
It refreshes the current page. If there was a postback, it will resend the post data.</p>
<p>The AJAX callback may update the ViewState as far as the page is concerned but hitting the browser refresh button will re-post the old ViewState.</p>
<p>There is a wealth is discussion on the matter which you can Google.</p>
<p>One very simple idea is to perhaps store the information in Session state instead perhaps. That too also can have its own issue too of course. But it may achieve your immediate goal.</p>
<p>A tip for wiping the history of a postback (to prevent the re-post) is to redirect back to the same page again.</p>
|
<p>Your ViewState is not being saved. The SaveViewState override is for saving OBJECTS, not for putting stuff into the ViewState bag. The ViewState bag is already beyond the point of mnarking stuff dirty and changes you make will not be persisted. You need to create an object array to load/view the ViewState information.</p>
<p>Do what BlackMael shows.</p>
| 46,140
|
<p>I want to display an error message on my asp.net application. This message is a warning message, this is the way I did it:</p>
<pre class="lang-js prettyprint-override"><code>CmdCalcInvoke.Attributes["onclick"] = "return confirm('Are you sure you want to calculate the certification? WARNING: If the quarter has not finished, all the partners status will change')";
</code></pre>
<p>The code above works fine. The <code>CmdCalcInvoke</code> is an <code>htmlInputButton</code>. This is the message that the message box displays;</p>
<blockquote>
<p><em>Are you sure you want to calculate the certification? WARNING: If the quarter has not finished, all the partners status will change</em></p>
</blockquote>
<p>What I want to do is to display this message, but wanted to highlight the WARNING word by making it bold, or displaying the word in red, can this be done???, can't remember seeing a message box with this characteristics, but I though i would ask in case</p>
<p>Any suggestions will be welcome</p>
|
<p>you can if you dont use the default alert boxes. Try using a javascript modal window which is just normal div markup that you can control the styling of. Look at blockui for jquery (there are loads of others)</p>
|
<p>You can try something like: <a href="http://weblogs.asp.net/johnkatsiotis/archive/2008/09/14/asp-net-messagebox-server-and-client.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/johnkatsiotis/archive/2008/09/14/asp-net-messagebox-server-and-client.aspx</a></p>
| 11,687
|
<p><img src="https://i.stack.imgur.com/DibJS.jpg" alt="Visual Studio folder structure"></p>
<p>I need some advice as to how I easily can separate test runs for unit tests and integration test in Visual Studio. Often, or always, I structure the solution as presented in the above picture: separate projects for unit tests and integration tests. The unit tests is run very frequently while the integration tests naturally is run when the context is correctly aligned.</p>
<p>My goal is to somehow be able configure which tests (or test folders) to run when I use a keyboard shortcut. The tests should preferably be run by a graphical test runner (ReSharpers). So for example</p>
<ul>
<li>Alt+1 runs the tests in project BLL.Test, </li>
<li>Alt+2 runs the tests in project DAL.Tests, </li>
<li>Alt+3 runs them both (i.e. all the tests in the [Tests] folder, and</li>
<li>Alt+4 runs the tests in folder [Tests.Integration].</li>
</ul>
<p>TestDriven.net have an option of running just the test in the selected folder or project by right-clicking it and select Run Test(s). Being able to do this, but via a keyboard command and with a graphical test runner would be awesome.</p>
<p><img src="https://i.stack.imgur.com/NYnmJ.jpg" alt="TestDriven.net test run output"></p>
<p>Currently I use VS2008, ReSharper 4 and nUnit. But advice for a setup in the general is of course also appreciated.</p>
|
<p>I actually found kind of a solution for this on my own by using keyboard command bound to a macro. The macro was recorded from the menu Tools>Macros>Record TemporaryMacro. While recording I selected my [Tests] folder and ran ReSharpers UnitTest.ContextRun. This resulted in the following macro, </p>
<pre><code>Sub TemporaryMacro()
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate
DTE.ActiveWindow.Object.GetItem("TestUnitTest\Tests").Select(vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("ReSharper.UnitTest_ContextRun")
End Sub
</code></pre>
<p>which was then bound to it's own keyboard command in Tools>Options>Environment>Keyboard.</p>
<p>However, what would be even more awesome is a more general solution where I can configure exactly which projects/folders/classes to run and when. For example by the means of an xml file. This could then easily be checked in to version control and distributed to everyone who works with the project.</p>
|
<p>This is a bit of fiddly solution, but you could configure some <a href="http://blogs.msdn.com/saraford/archive/2008/04/24/did-you-know-you-can-run-external-tools-within-visual-studio-201.aspx" rel="nofollow noreferrer">external tools</a> for each of group of tests you want to run. I'm not sure if you'll be able to launch the ReSharper test runner this way, but you can run the console version of nunit. Once you have of those tools setup, you can assigned keyboard shortcuts to the commands "Tools.ExternalCommand1", "Tools.ExternalCommand2", etc.</p>
<p>This wont really scale very well, and it's awkward to change - but it will give you keyboard shortcuts for running your tests. It does feel like there should be a much simpler way of doing this.</p>
| 3,484
|
<p>I'm writing an application where the user will create an appointment, and instantly get an email confirming their appointment. I'd also like to send an email the day of their appointment, to remind them to actually show up.</p>
<p>I'm in ASP.NET (2.0) on MS SQL . The immediate email is no problem, but I'm not sure about the best way to address the reminder email. Basically, I can think of three approaches:</p>
<ol>
<li>Set up a SQL job that runs every night, kicking off SQL emails to people that have appointments that day.</li>
<li>Somehow send the email with a "do not deliver before" flag, although this seems like something I might be inventing.</li>
<li>Write <em>another</em> application that runs at a certain time every night.</li>
</ol>
<p>Am I missing something obvious? How can I accomplish this?</p>
|
<p>Choice #1 would be the best option, create a table of emails to send, and update the table as you send each email. It's also best not to delete the entry but mark it as sent, you never know when you'll have a problem oneday and want to resend out emails, I've seen this happen many times in similar setups.</p>
|
<p>Your option 2 certainly seems like something you are inventing. I know that <em>my</em> mail system won't hold messages for future delivery if you were to send me something like that.</p>
<p>I don't think you're missing anything obvious. You will need something that runs the day of the appointment to send emails. Whether that might be better as a SQL job or as a separate application would be up to your application architecture.</p>
| 41,713
|
<p>I'd like to rollback a change I made recently in TFS. In Subversion, this was pretty straightforward. However, it seems to be an incredible headache in TFS:</p>
<h3>Option 1: Get Prior Version</h3>
<ol>
<li>Manually get prior version of each file</li>
<li>Check out for edit</li>
<li>Fail - the checkout (in VS2008) forces me to get the latest version</li>
</ol>
<h3>Option 2: Get TFS Power Tools</h3>
<ol>
<li>Download Team Foundation Power Tools</li>
<li>Issue rollback command from cmd line</li>
<li>Fail - it won't work if there are any other pending changes</li>
</ol>
<h3>Option 3: Manually Undo Changes</h3>
<ol>
<li>manually undo my changes, then commit a new changeset</li>
</ol>
<h3>Question</h3>
<p>How do I rollback to a previous changeset in TFS?</p>
|
<ol>
<li>Download and install <a href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=15836" rel="noreferrer">Team Foundation Power Tools</a>. </li>
<li>Open up the Visual Studio command prompt</li>
<li>Navigate to the directory on the file system that TFS is mapped to. If you don't do this you'll get an "Unable to determine the workspace" error when you try to roll back</li>
<li>Make sure everything else is checked in or shelved</li>
<li>run tfpt rollback to bring up the interface. </li>
<li>Choose the changesets you want to rollback</li>
<li>Check in the new versions of the files you rolled back</li>
</ol>
<p>The big disadvantage of the tool is that it will want to refresh everything in your workspace before you can merge. I got around this issue by creating a new workspace just for the rollback which mapped directly to the place in the source tree where the affected files were. </p>
<p>If you need help to figure out which changesets to roll back, I find the code review tool in the free <a href="http://www.attrice.info/cm/tfs/" rel="noreferrer">Team Foundation Side Kicks</a> add-in very helpful.</p>
|
<p>The solution above is for TFS2008. TFS2010 has built-in rollback feature. see <a href="http://www.edsquared.com/2010/02/02/Rollback+Or+Undo+A+Changeset+In+TFS+2010+Version+Control.aspx" rel="nofollow">this</a> article for details.</p>
| 5,256
|
<p>I have a list of error codes I need to reference, kinda like this:</p>
<pre><code>Code / Error Message
A01 = whatever error
U01 = another error
U02 = yet another error type
</code></pre>
<p>I get the Code returned to me via a web service call and I need to display or get the readable error. So I need a function when passed a Code that returns the readable description. I was just going to do a select case but thought their might be a better way. What is the best way / most effieient way to do this?</p>
|
<p>Use a Dictionary, (in C#, but the concept and classes are the same):</p>
<pre><code>// Initialize this once, and store it in the ASP.NET Cache.
Dictionary<String,String> errorCodes = new Dictionary<String,String>();
errorCodes.Add("A01", "Whatever Error");
errorCodes.Add("U01", "Another Error");
// And to get your error code:
string ErrCode = errorCodes[ErrorCodeFromWS];
</code></pre>
|
<p>You would use a dictionary. A dictionary uses a hashmap internally for performance, so it is good in that regard. Also, because you want this to go as quickly as possible by the sounds of it, I would statically initialize it in its own class instead of, for example, in an XML file or slimier. You would probably want something like:</p>
<pre><code>public static class ErrorCodes
{
private static Dictonary<string, string> s_codes = new Dicontary<string, string>();
static ErrorCodes()
{
s_codes["code"] = "Description";
s_codes["code2"] = "Description2";
}
public static string GetDesc(string code)
{
return s_codes[code];
}
}
</code></pre>
<p>That way, if you wanted to move the back end to a file instead of being static, then you could.</p>
| 39,390
|
<p>Please consider the following:</p>
<pre><code><td style="width: 500px;">
<div style="width: 400px;">SomeContent</div>
</td>
</code></pre>
<p>For some reason, the column that contains a div will not expand to 500px as the style suggests.</p>
<p>Do you know how to get the td to honor the width that I am specifying in the style?</p>
|
<p>In theory, you can use the min-width and max-width styles. In practice, some popular browsers ignore these styles. In this case you have explicitly declared a width of 400, so it should always equal 400 unless acted upon by a child growing or a parent shrinking. You could runat-"server" and programatically determine the width attribute based on content size, or you could play with the overflow style, or put it in a Panel with a horizontal scrollbar.</p>
|
<p>is there a width on the table and other tds within the table? Also, have you got a doc type going on?</p>
<p>However, that said, here's your solution:</p>
<pre><code><td style="width: 500px">
<div style="padding: 0 50px">SomeContent</div>
</td>
</code></pre>
<p>Setting your padding appropriately.</p>
<hr>
<p>Having reread your question, I feel that this might not be the answer you're looking for. Could you elaborate a little more?</p>
| 33,895
|
<p>I am developing a HTML form designer that needs to generate static HTML and show this to the user. I keep writing ugly code like this:</p>
<pre><code>public string GetCheckboxHtml()
{
return ("&lt;input type="checkbox" name="somename" /&gt;");
}
</code></pre>
<p>Isn't there a set of strongly typed classes that describe html elements and allow me to write code like this instead:</p>
<pre><code>var checkbox = new HtmlCheckbox(attributes);
return checkbox.Html();
</code></pre>
<p>I just can't think of the correct namespace to look for this or the correct search term to use in Google.</p>
|
<p>Well, if you download the <a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=MVC&referringTitle=Home" rel="nofollow noreferrer">ASP.NET MVC</a> DLL's (which you can use in <em>any</em> type of project... including Console apps)... then you can use the many HTML helpers they have.</p>
|
<p>HtmlTextWriter contains goodies like "WriteStartTag" and "WriteEndTag", which can be used to create properly formed HTML fairly easily.</p>
<p>You essentially pass the tagname and attributes to the HtmlTextWriter, and it generates the proper HTML, and will close it properly with WriteEndTag.</p>
<p>You can also use the prewritten HTMLControls that wrap this code up into strongly typed classes.</p>
| 34,502
|
<p>Does anyone know of any good tutorials on ADO.NET Entity Framework?</p>
<p>There are a few useful links here at <a href="https://stackoverflow.com/questions/42826/where-to-start-with-entity-framework">Stack OverFlow</a>, and I've found one tutorial at <a href="http://dotnet-architecture-jdo.blogspot.com/2008/08/adonet-entity-framework-part.html" rel="nofollow noreferrer">Jason's DotNet Architecture Blog</a>, but can anyone recommend any other good tutorials?
Any tutorials available from Microsoft, either online or as part of any conference/course material?</p>
|
<p>Microsoft offers <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=355c80e9-fde0-4812-98b5-8a03f5874e96&displaylang=en" rel="noreferrer">.NET 3.5 Enhancements Training Kit</a> it contains documentation and sample code for ADO.NET EF</p>
|
<p>Sample application from <a href="http://msdn.microsoft.com/en-us/library/bb399296.aspx" rel="nofollow noreferrer">MSDN</a></p>
<p>And some inside information from <a href="http://blogs.msdn.com/adonet/" rel="nofollow noreferrer">ADO.NET Team Blog</a></p>
| 8,747
|
<p>I just wonder a bit whether or not GDI+ is still a technology worth using, especially in a .net sense.</p>
<p>Granted, GDI+ is still THE technology to handle Images in Windows, but it is also unmanaged code (obviously). Now, after discovering that GDI+ is actually not supported on ASP.net¹, I just wonder: Is it actually feasible to have Image Manipulation Libraries that run completely in Managed Code? XNA does it if i remember correctly, albeit it uses the graphics card for it.</p>
<p>Is there maybe even any .net Image Library that implements a sort of managed GDI+?</p>
<p>¹ <a href="http://msdn.microsoft.com/en-us/library/system.drawing.imaging.aspx" rel="nofollow noreferrer">Source</a>, also Microsoft just offered <a href="http://www.hanselman.com/blog/ASPNETFuturesGeneratingDynamicImagesWithHttpHandlersGetsEasier.aspx" rel="nofollow noreferrer">something</a> for ASP.net that uses GDI+.</p>
|
<p>It's still a technology worth using. There are lots of Windows Forms and unmanaged apps around that use GDI+ that either won't be upgraded, or that will be upgraded, but that don't need more advanced rendering capabilities. GDI+ is a good bolt-on solution for older applications, and for new applications written in Windows Forsm. That's the primary reason GDI+ wasn't axed in Vista in favour of a totally DirectX solution.</p>
<p>There's not specifically anything wrong with GDI/GDI+. True, it's not as advanced as Aero et al, but that doesn't always matter. Particularly in LOB applications (in companies that probably don't even have machines capable of running Vista - mine certainly doesn't), GDI+ is an extremely important technology.</p>
<p>The fact that it's not supported (for drawing, at least... you CAN still use it for image manipulation) in ASP.NET is a red herring, since other drawing technologies are not supported for web applications either (plugin-based "applications" notwithstanding).</p>
|
<blockquote>
<p>Blockquote
there are plenty of other graphics libraries out there, faster and/or higher quality / fewer system dependencies...</p>
</blockquote>
<p>Could u list some of them libraries that could be used instead of GDI+ with C++ ?</p>
| 4,279
|
<p>I'm sure this has been asked before, but I can't find it. </p>
<p>What are the benefits/limitations of using a browser-based interface for a stand-alone application vs. using a normal GUI framework?</p>
<p>I'm working on a Python program currently implement with wxPython for the GUI. The application is simply user-entry forms and dialogs. I am considering moving to PyQt because of the widgets it has (for future expansion), then I realized I could probably just use a browser to do much of the same stuff.</p>
<p>The application currently doesn't require Internet access, though it's a possibility in the future. I was thinking of using <a href="http://karrigell.sourceforge.net/" rel="noreferrer">Karrigell</a> for the web framework if I go browser-based.</p>
<hr>
<p><strong>Edit</strong> For clarification, as of right now the application would be browser-based, not web-based. All the information would be stored locally on the client computer; no server calls would need to be made and no Internet access required (it may come later though). It would simply be a browser GUI instead of a wxPython/PyQt GUI. Hope that makes sense.</p>
|
<p>The obvious advantages to browser-based:</p>
<ul>
<li>you can present the same UI regardless of platform</li>
<li>you can upgrade the application easily, and all users have the same version of the app running</li>
<li>you know the environment that your application will be running in (the server hardware/OS) which makes for easier testing and support compared to the multitude of operating system/hardware configurations that a GUI app will be installed on.</li>
</ul>
<p>And for GUI based:</p>
<ul>
<li>some applications (e.g.: image editing) arguably work better in a native GUI application</li>
<li>doesn't require network access</li>
</ul>
<p>Also see my comments on <a href="https://stackoverflow.com/questions/115501/is-ruby-any-good-for-gui-development#115638">this question</a>:</p>
<blockquote>
<p>Cross-platform GUIs are an age-old problem. Qt, GTK, wxWindows, Java AWT, Java Swing, XUL -- they all suffer from the same problem: the resulting GUI doesn't look native on every platform. Worse still, every platform has a slightly different look and <strong>feel</strong>, so even if you were somehow able to get a toolkit that looked native on every platform, you'd have to somehow code your app to feel native on each platform.</p>
<p>It comes down to a decision: do you want to minimise development effort and have a GUI that doesn't look and feel quite right on each platform, or do you want to maximise the user experience? If you choose the second option, you'll need to develop a common backend and a custom UI for each platform. <em>[edit: or use a web application.]</em></p>
</blockquote>
<p>Another thought I just had: you also need to consider the kind of data that your application manipulates and where it is stored, and how the users will feel about that. People are obviously okay having their facebook profile data stored on a webserver, but they might feel differently if you're writing a finance application like MYOB and you want to store all their personal financial details on your server. You might be able to get that to work, but it would require a lot of effort to implement the required security and to assure the userbase that their data is safe. In that situation you might decide that the overall effort is lower if you go with a native GUI app.</p>
|
<p>Browsers can be accessed anywhere with internet and you deploy it on the server. The desktop app has to be deployed to their computers and each computer somehow has its own uniqueness even with same OS and same version. This could bring you lots of hassles.
Go for web.</p>
| 31,876
|
<p>I have a bash shell script that loops through all child directories (but not files) of a certain directory. The problem is that some of the directory names contain spaces. </p>
<p>Here are the contents of my test directory:</p>
<pre><code>$ls -F test
Baltimore/ Cherry Hill/ Edison/ New York City/ Philadelphia/ cities.txt
</code></pre>
<p>And the code that loops through the directories:</p>
<pre><code>for f in `find test/* -type d`; do
echo $f
done
</code></pre>
<p>Here's the output:</p>
<pre>
test/Baltimore
test/Cherry
Hill
test/Edison
test/New
York
City
test/Philadelphia
</pre>
<p>Cherry Hill and New York City are treated as 2 or 3 separate entries.</p>
<p>I tried quoting the filenames, like so:</p>
<pre><code>for f in `find test/* -type d | sed -e 's/^/\"/' | sed -e 's/$/\"/'`; do
echo $f
done
</code></pre>
<p>but to no avail.</p>
<p>There's got to be a simple way to do this.</p>
<hr>
<p>The answers below are great. But to make this more complicated - I don't always want to use the directories listed in my test directory. Sometimes I want to pass in the directory names as command-line parameters instead.</p>
<p>I took Charles' suggestion of setting the IFS and came up with the following:</p>
<pre><code>dirlist="${@}"
(
[[ -z "$dirlist" ]] && dirlist=`find test -mindepth 1 -type d` && IFS=$'\n'
for d in $dirlist; do
echo $d
done
)
</code></pre>
<p>and this works just fine unless there are spaces in the command line arguments (even if those arguments are quoted). For example, calling the script like this: <code>test.sh "Cherry Hill" "New York City"</code> produces the following output:</p>
<pre>
Cherry
Hill
New
York
City
</pre>
|
<p>First, don't do it that way. The best approach is to use <code>find -exec</code> properly:</p>
<pre><code># this is safe
find test -type d -exec echo '{}' +
</code></pre>
<p>The other safe approach is to use NUL-terminated list, though this requires that your find support <code>-print0</code>:</p>
<pre><code># this is safe
while IFS= read -r -d '' n; do
printf '%q\n' "$n"
done < <(find test -mindepth 1 -type d -print0)
</code></pre>
<p>You can also populate an array from find, and pass that array later:</p>
<pre><code># this is safe
declare -a myarray
while IFS= read -r -d '' n; do
myarray+=( "$n" )
done < <(find test -mindepth 1 -type d -print0)
printf '%q\n' "${myarray[@]}" # printf is an example; use it however you want
</code></pre>
<p>If your find doesn't support <code>-print0</code>, your result is then unsafe -- the below will not behave as desired if files exist containing newlines in their names (which, yes, is legal):</p>
<pre><code># this is unsafe
while IFS= read -r n; do
printf '%q\n' "$n"
done < <(find test -mindepth 1 -type d)
</code></pre>
<p>If one isn't going to use one of the above, a third approach (less efficient in terms of both time and memory usage, as it reads the entire output of the subprocess before doing word-splitting) is to use an <code>IFS</code> variable which doesn't contain the space character. Turn off globbing (<code>set -f</code>) to prevent strings containing glob characters such as <code>[]</code>, <code>*</code> or <code>?</code> from being expanded:</p>
<pre><code># this is unsafe (but less unsafe than it would be without the following precautions)
(
IFS=$'\n' # split only on newlines
set -f # disable globbing
for n in $(find test -mindepth 1 -type d); do
printf '%q\n' "$n"
done
)
</code></pre>
<p>Finally, for the command-line parameter case, you should be using arrays if your shell supports them (i.e. it's ksh, bash or zsh):</p>
<pre><code># this is safe
for d in "$@"; do
printf '%s\n' "$d"
done
</code></pre>
<p>will maintain separation. Note that the quoting (and the use of <code>$@</code> rather than <code>$*</code>) is important. Arrays can be populated in other ways as well, such as glob expressions:</p>
<pre><code># this is safe
entries=( test/* )
for d in "${entries[@]}"; do
printf '%s\n' "$d"
done
</code></pre>
|
<p>Just had a simple variant problem... Convert files of typed .flv to .mp3 (yawn).</p>
<pre><code>for file in read `find . *.flv`; do ffmpeg -i ${file} -acodec copy ${file}.mp3;done
</code></pre>
<p>recursively find all the Macintosh user flash files and turn them into audio (copy, no transcode) ... it's like the while above, noting that read instead of just 'for file in <code></code>' will escape.</p>
| 38,599
|
<p>Suppose I have a database table with two fields, "foo" and "bar". Neither of them are unique, but each of them are indexed. However, rather than being indexed together, they each have a separate index.</p>
<p>Now suppose I perform a query such as <code>SELECT * FROM sometable WHERE foo='hello' AND bar='world';</code> My table a huge number of rows for which foo is 'hello' and a small number of rows for which bar is 'world'.</p>
<p>So the most efficient thing for the database server to do under the hood is use the bar index to find all fields where bar is 'world', then return only those rows for which foo is 'hello'. This is <code>O(n)</code> where n is the number of rows where bar is 'world'.</p>
<p>However, I imagine it's possible that the process would happen in reverse, where the fo index was used and the results searched. This would be <code>O(m)</code> where m is the number of rows where foo is 'hello'.</p>
<p>So is Oracle smart enough to search efficiently here? What about other databases? Or is there some way I can tell it in my query to search in the proper order? Perhaps by putting <code>bar='world'</code> first in the <code>WHERE</code> clause?</p>
|
<p>Oracle will almost certainly use the most selective index to drive the query, and you can check that with the explain plan.</p>
<p>Furthermore, Oracle can combine the use of both indexes in a couple of ways -- it can convert btree indexes to bitmaps and perform a bitmap ANd operation on them, or it can perform a hash join on the rowid's returned by the two indexes.</p>
<p>One important consideration here might be any correlation between the values being queried. If foo='hello' accounts for 80% of values in the table and bar='world' accounts for 10%, then Oracle is going to estimate that the query will return 0.8*0.1= 8% of the table rows. However this may not be correct - the query may actually return 10% of the rwos or even 0% of the rows depending on how correlated the values are. Now, depending on the distribution of those rows throughout the table it may not be efficient to use an index to find them. You may still need to access (say) 70% or the table blocks to retrieve the required rows (google for "clustering factor"), in which case Oracle is going to perform a ful table scan if it gets the estimation correct.</p>
<p>In 11g you can collect multicolumn statistics to help with this situation I believe. In 9i and 10g you can use dynamic sampling to get a very good estimation of the number of rows to be retrieved.</p>
<p>To get the execution plan do this:</p>
<pre><code>explain plan for
SELECT *
FROM sometable
WHERE foo='hello' AND bar='world'
/
select * from table(dbms_xplan.display)
/
</code></pre>
<p>Contrast that with:</p>
<pre><code>explain plan for
SELECT /*+ dynamic_sampling(4) */
*
FROM sometable
WHERE foo='hello' AND bar='world'
/
select * from table(dbms_xplan.display)
/
</code></pre>
|
<p>You can provide hints as to which index to use. I'm not familiar with Oracle, but in Mysql you can use USE|IGNORE|FORCE_INDEX (see <a href="http://dev.mysql.com/doc/refman/5.1/en/index-hints.html" rel="nofollow noreferrer">here</a> for more details). For best performance though you should use a combined index.</p>
| 17,968
|
<p>If I have a DrawingVisual in WPF with Opacity=0, is that enough for it not to be drawn? We have hundreds of DrawingVisuals on a Canvas, and are currently setting Opacity=0 on the visuals that are not to be displayed, and I wanted to make sure there is no rendering performance hit for rendering a DrawingVisual with Opacity=0.</p>
<p>UPDATE: I have discovered through testing that there IS overhead when Opacity=0, but since DrawingVisual doesn't have a Visibility property, I don't know how else you would tell it to not be displayed unless you actualy remove it from the visual tree, so any suggestions are welcome. </p>
|
<p>The best way to check would be to instead set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibility.aspx" rel="nofollow noreferrer">Visibility</a> to Visibility.Colapsed, and see if there's any drawing performance differences. </p>
<p>Visibility.Colapsed ensures that the element is not visible but also that it will not participate in the Arrange, Measure and Render passes of the UI, while an element with Opacity=0 might participate in all passes.</p>
|
<p>Why not simply remove the visual from the visual children list? When it needs to be visible you add it back.</p>
| 36,135
|
<p>My goal is to implements different image classification methods to show how they function and the advantages and disadvantages behind such methods. The ones I want to try and implement using Java include; </p>
<p>Minimum distance classifier</p>
<p>k-nearest neighbour classifier.</p>
<p>I was wondering what can be used to accomplish my task that already exists in Java so that I can alter the way the algorithms operates.</p>
|
<p>Although not entirely sure this is what you are looking for (sorry, your question is a bit unclear), if what you want is a library / system to help you with the <em>classification</em> part of the work, then you may want to look at Weka (<a href="http://www.cs.waikato.ac.nz/ml/weka/" rel="nofollow noreferrer">http://www.cs.waikato.ac.nz/ml/weka/</a>), in my opinion the best Java library for data mining experimentation. </p>
<p>If, instead, you are looking for algorithms that would allow you to analyze images in order to extract features that can, in turn, be used to perform the classification, you may want to start with targeted descriptions of such algorithms in Java, such as those found in the nice on-line book <em>Java Image Processing Cookbook</em> by Rafael Santos; here's a <a href="http://www.lac.inpe.br/JIPCookbook/7020-tutorial-supervisedclassification.jsp" rel="nofollow noreferrer">direct link to the section "A Brief Tutorial on Supervised Image Classification"</a>. </p>
|
<p>You can also use RapidMiner with IMMI (IMage MIning) extension:</p>
<p><a href="http://www.burgsys.com/mumi-image-mining-community.php" rel="nofollow">http://www.burgsys.com/mumi-image-mining-community.php</a></p>
<p>For image classification you can use for example global feature extraction and then use some classification algorithm (e.g. Artificial Neural Networks).</p>
| 42,498
|
<p>We have an existing classic ASP intranet consisting of hundreds of pages. Its directory structure looks like this...</p>
<pre><code>/root
app_1
app_2
...
img
js
style
</code></pre>
<p>Obviously app_1 and so on have better names in the actual directory structure.</p>
<p>Even though the many applications have different behaviour, they are all part of the same intranet and therefore share a common look and feel by including stylesheets via /style, images via /img and client script via /js.</p>
<p>The trouble (for me at least) comes when I want to add an intranet application in ASP.NET.</p>
<p>Ultimately, I'd like this structure:</p>
<pre><code>/root
app_1
app_2
dotnetapp_1
dotnetapp_2
...
img
js
style
</code></pre>
<p>It seems to me that ASP.NET "applications" like to think of themselves as separate from everything around them (this may just be my comprehension of how they are). You create a new "project" in Visual Studio and it's like you have a new "root" a level below the actual root I want to use. It's like this new application is a thing, standing alone, with its own images and style and whatnot. However, I want it to be a sub-part of the existing intranet.</p>
<p>Ultimately I want to be able to make my whole classic ASP intranet the "root" and have ASP.NET "sub-applications" that can still access /style and /img and, I guess for ASP.NET I'll have /masterpages.</p>
<p>I've tried this before, but I think VS choked on the couple of hundred classic ASP pages that it added to the "project" when I made my existing intranet root directory the ASP.NET project root (via File->Open->Web Site). I'd be nice to edit my existing classic ASP intranet using VS 2008 SP1 (I currently use the excellent <a href="http://notepad-plus.sourceforge.net/uk/site.htm" rel="nofollow noreferrer">Notepad++</a>) because I'd like to get more hands on with VS but I guess this isn't absolutely necessary.</p>
<p>I also tried treating each new ASP.NET application as an application in its own right, effectively making the /dotnetapp_1 directory the "root" of the application (again, via File->Open->Web Site in VS2008). However, VS then complained when I tried to reference /masterpages because it "belonged to another application." I think I kludged it by adding a virtual directory inside each ASP.NET directory that "pointed" to the root /masterpages but I'm not sure VS was able to happily provide WYSIWYG editing when I did this, as opposed to making a copy of the masterpage in every ASP.NET application I add to the intranet.</p>
<p>I'm also quite likely to visit the .NET MVC framework so please offer any answers with that framework in mind. I'm hoping "projects" aren't quite to important with MVC and that rather it's just a bunch of files that creates an application that contributes to the whole (that being the intranet).</p>
<p>So, the question is: <strong>How I can best add-on ASP.NET applications to an existing classic ASP intranet (I'm not concerned about the technicalities of session sharing between classic ASP and ASP.NET, only the structural layout of directories and projects) and be able to edit these separate applications in Visual Studio 2008 SP1 and yet have these application "related" to each other by a common, intranet look and feel*?</strong></p>
<ul>
<li>Please don't just post the answer "use MasterPages." I appreciate MasterPages are .NET's method of sharing styles (and more probably) between related pages in the <em>same</em> application. I get that. What I'm looking for is the best method of adding ASP.NET applications into the existing intranet as smoothly as I can that makes editing each application simple and where each application can share (if possible) an intranet-common style.</li>
</ul>
|
<p>One solution would be to use IIS Manager to configure the website (created for your ASP.NET app by Visual Studio) and add a virtual directory for each of the common folders so that (by the 'virtual' nature of the virtual directory) they will 'appear' to be in the same root folder as your ASP.NET app.</p>
<pre><code>/root
app_1
app_2
dotnetapp_1
<virtual>img
<virtual>js
...
img
js
style
</code></pre>
<p>You can probably script IIS or edit an XML file if you need to do this in bulk, and I'm sure there must be an even more elegant way to do something similar that doesn't require to much mouse work!</p>
|
<p>Can't you run the asp.net site as a Virtual Directory?</p>
<pre><code>www.site.com/dotnetapp/
</code></pre>
<p>Where dotnetapp is a virtual directory completely separate?</p>
| 18,992
|
<p>This isn't exactly a programming question but it is related.</p>
<p>I had read a fascinating article a while ago about a teacher who explained how he taught base 2 notation to first grade children, without even "teaching" them anything but making them discover both the problem and the solutions by asking relevant questions.</p>
<p>I can't find this article anymore, anywhere on the Web -- can anyone help?</p>
<p>Thanks.</p>
|
<p>He's using the Socratic method, so a search yields <a href="http://www.garlikov.com/Soc_Meth.html" rel="nofollow noreferrer">Teaching by Asking Instead of by Telling</a> by Rick Garlikov.</p>
<p>From the text:</p>
<blockquote>
<p>The experiment was to see whether I could teach these students binary arithmetic [...]</p>
</blockquote>
<p>But only you know if this is the article you were looking for.</p>
|
<p>One method from my study class social competence: paradox intervention.</p>
<p>Claim you can count up to 1024 just with your ten fingers. They won't believe you, but you can.
Each finger stands for one digit. If your finger is out, it stands for 1, otherwise for 0. All ten fingers out will represent 1023.</p>
<p>You can also try it with a method from "Die Sendung mit der Maus" (German teaching television).
A marble run with buttons and a lamp on each twist:
All lights off: 0
If you throw a marble, it hit's the first button and falls out of the run. If you throw the second, the button is switched again (lamp 1 off) and will let the marble roll further. The marble will hit the second switch (lamp 2 on) and falls out of the run.</p>
<p>So children can see, how to count with base 2. It may help you</p>
| 43,272
|
<p>In sql server does it make a difference if I define a varchar column to be of length 32 or 128?</p>
|
<p>A <a href="http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx" rel="noreferrer">varchar</a> is a variable character field. This means it can hold text data to a certain length. A varchar(32) can only hold 32 characters, whereas a varchar(128) can hold 128 characters. If I tried to input "12345" into a varchar(3) field; this is the data that will be stored:</p>
<p>"123"</p>
<p>The "45" will be "truncated" (lost).</p>
<p>They are very useful in instances where you know that a certain field will only be (or only <em>should</em> be) a certain length at maximum. For example: a zip code or state abbreviation. In fact, they are generally used for almost all types of text data (such as names/addresses/et cetera) - but in these instances you must be careful that the number you supply is a sane maximum for the type of data that will fill that column.</p>
<p>However, you must also be careful when using them to only allow the user to input the maximum amount of characters that the field will support. Otherwise it may lend to confusion when it truncates the user's input.</p>
|
<p>There should be no noticeable difference as the backend will only store the amount of data you insert into that column. It's not padded out to the full size of the field like it is with a char column.</p>
<p>Edit: For more info, this <a href="http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx" rel="nofollow noreferrer">link</a> should be useful.</p>
| 21,366
|
<p>I have a web reference for our report server embedded in our application. The server that the reports live on could change though, and I'd like to be able to change it "on the fly" if necessary.</p>
<p>I know I've done this before, but can't seem to remember how. Thanks for your help.</p>
<p>I've manually driven around this for the time being. It's not a big deal to set the URL in the code, but I'd like to figure out what the "proper" way of doing this in VS 2008 is. Could anyone provide any further insights? Thanks!</p>
<hr>
<p>In <strong>VS2008</strong> when I change the URL Behavior property to Dynamic I get the following code auto-generated in the Reference class.</p>
<p>Can I override this setting (MySettings) in the web.config? I guess I don't know how the settings stuff works.</p>
<pre><code>Public Sub New()
MyBase.New
Me.Url = Global.My.MySettings.Default.Namespace_Reference_ServiceName
If (Me.IsLocalFileSystemWebService(Me.Url) = true) Then
Me.UseDefaultCredentials = true
Me.useDefaultCredentialsSetExplicitly = false
Else
Me.useDefaultCredentialsSetExplicitly = true
End If
End Sub
</code></pre>
<p><em>EDIT</em></p>
<p>So this stuff has changed a bit since VS03 (which was probably the last VS version I used to do this).</p>
<p>According to: <a href="http://msdn.microsoft.com/en-us/library/a65txexh.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/a65txexh.aspx</a> it looks like I have a settings object on which I can set the property programatically, but that I would need to provide the logic to retrieve that URL from the web.config.</p>
<p>Is this the new standard way of doing this in VS2008, or am I missing something?</p>
<p><em>EDIT #2</em></p>
<p>Anyone have any ideas here? I drove around it in my application and just put the URL in my web.config myself and read it out. But I'm not happy with that because it still feels like I'm missing something.</p>
|
<p>In the properties window change the "behavior" to Dynamic.</p>
<p>See: <a href="http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx</a></p>
|
<p>If you mean a VS2005 "Web Reference", then the generated proxy classes have a URL property that is the SOAP endpoint url of that service. You can change this property and have your subsequent http communications be made to that new endpoint.</p>
<p>Edit: Ah, thanks bcaff86. I didn't know you could do that simply by changing a property.</p>
| 2,716
|
<p>Does anyone know of a graphing library for simple transformation of a point from one coordinate system to another coordinate system which is rotated by a angle and some point transformation and just for 2d?
And any graphing tool for plotting and verifying the same visually?</p>
|
<p>double[3][3]</p>
|
<p><a href="http://www.gdal.org/" rel="nofollow noreferrer">GDAL</a> includes pretty much every graphic transform you could ask for, and while it is big and hence takes some time to get used to, it is a great framework to move forward with.</p>
| 21,369
|
<p>I need to have multiple forms in the same webpage, all of them POSTing to itself and then performing different actions depending on the type of form.</p>
<p>What's the best way to achieve this?</p>
<p>To be more specific, the page shows the details of an event, with a form to subscribe (a drop-down box) and another form for each of the subscribed persons that allows them to unsubscribe (it's just a button).</p>
|
<p>A few ideas for you:</p>
<ol>
<li><p>A hidden field in each form</p>
<p><code><input type="hidden" name="formname" value="firstForm" /></code></p></li>
<li><p>Or setting the action url to include a querystring</p>
<p><code><form action="mypage.php?formtype=firstForm" ...></code></p></li>
<li><p>Named buttons so you know which was clicked.</p>
<p><code><input type="submit" name="firstForm" value="Submit" /></code>
And then check that firstForm (et al) has been returned</p></li>
</ol>
<p>Edit: the code-sampling on SO doesn't seem to work for HTML properly. (Worryingly) it's not escaping forms, so I've cut the examples way down (sorry and I hope you understand what I'm saying!)</p>
|
<p>You could just have a hidden input for each form containing a formid. Then, when the page processes, you can tell which form was submitted.</p>
<p>Or am I misunderstanding your question?</p>
| 23,805
|
<p>I need to match a string like "one. two. three. four. five. six. seven. eight. nine. ten. eleven" into groups of four sentences. I need a regular expression to break the string into a group after every fourth period. Something like: </p>
<pre><code> string regex = @"(.*.\s){4}";
System.Text.RegularExpressions.Regex exp = new System.Text.RegularExpressions.Regex(regex);
string result = exp.Replace(toTest, ".\n");
</code></pre>
<p>doesn't work because it will replace the text before the periods, not just the periods themselves. How can I count just the periods and replace them with a period and new line character?</p>
|
<p><code>.</code> in a regex means "any character"</p>
<p>so in your regex, you have used <code>.*.</code> which will match a word (this is equivalent to <code>.+</code>)</p>
<p>You were probably looking for <code>[^.]\*[.]</code> - a series of characters that are not "<code>.</code>"s followed by a "<code>.</code>".</p>
|
<p>In this case it would seem that regex is a bit of overkill. I would recommend using String.split and then breaking up the resulting array of strings. It should be far simpler and far more reliable than trying to make a regex do what you're trying to do.</p>
<p>Something like this might be a bit easier to read and debug.</p>
<pre><code>String s = "one. two. three. four. five. six. seven. eight. nine. ten. eleven"
String[] splitString = s.split(".")
List li = new ArrayList(splitString.length/2)
for(int i=0;i<splitString.length;i+=4) {
st = splitString[i]+"."
st += splitString[i+1]+"."
st += splitString[i+2]+"."
st += splitString[i+3]+"."
li.add(st)
}
</code></pre>
| 30,381
|
<p>I want to do something like the following in spring:</p>
<pre><code><beans>
...
<bean id="bean1" ... />
<bean id="bean2">
<property name="propName" value="bean1.foo" />
...
</code></pre>
<p>I would think that this would access the getFoo() method of bean1 and call the setPropName() method of bean2, but this doesn't seem to work.</p>
|
<p>What I understood:</p>
<ol>
<li>You have a bean (bean1) with a
property called "foo"</li>
<li>You have another bean (bean2) with a
property named "propName", wich also
has to have the same "foo" that in
bean1.</li>
</ol>
<p>why not doing this:</p>
<pre><code><beans>
...
<bean id="foo" class="foopackage.foo"/>
<bean id="bean1" class="foopackage.bean1">
<property name="foo" ref="foo"/>
</bean>
<bean id="bean2" class="foopackage.bean2">
<property name="propName" ref="foo"/>
</bean>
....
</beans>
</code></pre>
<p>Doing this, your bean2 is not coupled to bean1 like in your example. You can change bean1 and bean2 without affecting each other.</p>
<p>If you <strong>REALLY</strong> need to do the injection you proposed, you can use:</p>
<pre><code><util:property-path id="propName" path="bean1.foo"/>
</code></pre>
|
<p>I think you have to inject bean1, then get <code>foo</code> manually because of a timing issue. When does the framework resolve the value of the target bean?</p>
<p>You could create a pointer bean and configure that.</p>
<pre><code>class SpringRef {
private String targetProperty;
private Object targetBean;
//getters/setters
public Object getValue() {
//resolve the value of the targetProperty on targetBean.
}
}
</code></pre>
<p><a href="http://commons.apache.org/beanutils/" rel="nofollow noreferrer">Common-BeanUtils</a> should be helpful.</p>
| 17,245
|
<p>I'm likely to need to print some parts from TPU (Shore 95A or harder) in the near future. I have everything I need to do a direct drive conversion using the original extruder on a bracket above the hot end -- but for most of my printing (PLA and PETG), this setup isn't required or even optimal, because of the extra moving mass on the X carriage.</p>
<p>It looks as if, once I have the bracket installed the first time, I can move the extruder (including adding/removing a wire extension and switching between full length Bowden tube and short coupler tube) in less than an hour -- in addition to the time I'd need to clear one material from the hot end before loading the other, of course. Is it practical at all to swap the extruder back and forth like this, on the assumption that I'll want/need to print TPU parts from time to time (I'll want softer material, too, since some of what I want TPU capability for is gaskets).</p>
<p>Obviously, if I needed to print TPU alongside PLA on a regular basis, I might be ahead to have a second printer, but space considerations, more than money, work against that.</p>
<p>Am I missing something on the effort needed to swap the extruder position back and forth (suggesting I should stick with direct drive and pursue firmware and tuning solutions to correct the accompanying problems with faster printing), or should I plan to do this as needed?</p>
|
<p>With some engineering, you could consider creating a tool dock version where you can easily screw off the Bowden driven hotend and screw on the direct driven hotend. You'll only need to have an extension stepper cable to connect the direct drive stepper and pluggable hotend heater and thermistor connections.</p>
<p>E.g. for the Ender printers, there are Voron Afterburner tool heads that are Bowden driven or direct driven (Clockwork or Galileo mods) available. These could be switched very easily, you do need to figure something out to plug the heater cartridge and thermistor.</p>
<hr />
<p><em>I'm doing something similar to my Hypercube Evolution where I am creating a Bowden driven 2.85 mm and a 1.75 mm direct driven tool head.</em></p>
|
<p>It depends on the level of automation you are willing to implement.</p>
<p>The Bowden extruder, including the motor, from the Ender 3 which I think you have (but in general, any Bowden extruder) does not need to be moved at all, since it's not on the printing head. You just need to disconnect the Bowden from the hot end and clip it somewhere safe.</p>
<p>The direct drive extruder, if you have a supporting plate which makes it as a single part, can be disconnected with a couple of screws and hanged somewhere nearby.</p>
<p>Depending on the knowledge of electronics you could set up a very cheap relay array (4 relays) all controlled by a single GPIO pin of your motherboard, so that you can switch the motor with a GCODE command. The relay would have the COM going to the stepper driver, the NO connected to the direct drive motor, the NC to the Bowden motor.</p>
<p>Write GCODE macros to change the current, linear advance, steps/mm settings depending on the activation of the relay board (or, even better, depending on the filament).</p>
<p>However, if money is not an issue, I would consider an Orbiter or a Sherpa mini extruder, which is direct drive but with 120 gram weight (including motor, not including hot end) can be used all the time. You are likely not going to push the X acceleration to the very very maximum you can, so you get direct drive at no performance cost.</p>
| 1,996
|
<p>Let's say I have two existing tables, "dogs" and "cats":</p>
<pre><code> dog_name | owner
---------+------
Sparky | Bob
Rover | Bob
Snoopy | Chuck
Odie | Jon
cat_name | owner
---------+------
Garfield | Jon
Muffy | Sam
Stupid | Bob
</code></pre>
<p>How do I write a query with this output?</p>
<pre><code> owner | num_dogs | num_cats
------+----------+---------
Bob | 2 | 1
Chuck | 1 | 0
Sam | 0 | 1
Jon | 1 | 1
</code></pre>
|
<pre><code>select owner, sum(num_dogs), sum(num_cats) from
(select owner, 1 as num_dogs, 0 as num_cats from dogs
union
select owner, 0 as num_dogs, 1 as num_cats from cats)
group by owner
</code></pre>
|
<p>I started with Cade Roux's excellent answer, but changed the WITH...AS () to use a table variable, as I am ended up using the results from a similar query for further aggregate functions.</p>
<pre><code>-- Table variable declaration
DECLARE @RainingCatsDogs TABLE
(
Owner nvarchar(255),
num_cats int,
num_dogs int
)
-- Populate the table variable with data from the union of the two SELECT statements
INSERT INTO @RainingCatsDogs
-- Get the count of doggies
SELECT
owner, COUNT(dog_name) AS num_dogs, 0 AS num_cats
FROM
dogs
GROUP BY
owner
-- join the results from the two SELECT statements
UNION
-- Get the count of kittehs
SELECT
owner, 0 AS num_dogs, COUNT(cat_name) as num_cats
FROM
cats
GROUP BY
owner
-- From the table variable, you can calculate the summed results
SELECT
owner,
SUM(num_dogs),
SUM(num_cats)
FROM
@RainingCatsDogs
</code></pre>
| 41,275
|
<p>Is it possible to modify a registry value (whether string or DWORD) via a .bat/.cmd script?</p>
|
<p>@Franci Penov - modify <strong>is</strong> possible in the sense of <strong>overwrite</strong> with <code>/f</code>, eg </p>
<pre><code>reg add "HKCU\Software\etc\etc" /f /v "value" /t REG_SZ /d "Yes"
</code></pre>
|
<p>See <a href="http://www.chaminade.org/MIS/Articles/RegistryEdit.htm" rel="nofollow noreferrer">http://www.chaminade.org/MIS/Articles/RegistryEdit.htm</a></p>
| 15,811
|
<p>I am unable to build my Web Application (not Web Site) in our build environement. We use DMAKE in our build environment (this unfortunately is non negotiable, therefore using MSBUILD is not permitted ) and when invoking the asp.net precompiler through</p>
<p>C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -d -nologo -p Site -f -fixednames -errorstack -v / Debug</p>
<p>We get the following error</p>
<p>error ASPPARSE: Could not load type 'X.Y.Admin.Site.Global</p>
<p>If I compile from the ide it is successful. If i then compile with aspnet_compilier it is successful. So i only get a successful compile with aspnet_compiler when the target dll i am trying to compile is in the bin of the web application i am compiling.</p>
<p>I keep running into postings that talk about solutions using MSBUILD which unfortunately I cant try.</p>
<p>Any help would be appreciated</p>
|
<p>We had the same problem on our web application:
<strong>error ASPPARSE: Could not load type '...'</strong></p>
<p>The problem was that we had the file on disk (on the project folder) but it wasn't included in our application project (in the .csproj file). We solved the problem by including the file in the project :)</p>
|
<p>I received the same problem. </p>
<p>I fixed it by copying my webapp's DLL from the OBJ/DEBUG folder to the BIN folder.</p>
| 39,976
|
<p>In my code attached below, I'm trying to upload a file via ASP.NET. I am dynamically creating the FileUpload control so that means it's not in my ViewState which (I think) means I can't use the control for uploading files unless I use the old fashioned multipat/form-data way which I don't want to do. I need to be able to allow the user to create multiple FileUpload fields and then when they click the Upload File(s) button, it loops through all the FileUpload fields and uploads them to the server.</p>
<p>I'm sure there's a way to do this that I'm just not thinking of - TIA!</p>
<pre><code><%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim fup As New FileUpload()
fup.ID = "FileUpload1"
PlaceHolder1.Controls.Add(fup)
End Sub
Protected Sub btnUploadFile_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' HOW DO I GET THE FILE THAT WAS SELECTED IN THE DYNAMICALLY CREATE FILEUPLOAD CONTROL?
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="padding:13px">
<asp:Button ID="btnAdd" runat="server" Text="Add FileUpload Control" OnClick="btnAdd_Click" />
<br /><br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
<br /><br />
<asp:Button ID="btnUploadFile" runat="server" Text="Upload File(s)" OnClick="btnUploadFile_Click" />
</div>
</form>
</body>
</html>
</code></pre>
|
<p>You can use Request.Files</p>
<p>It contains the uploaded files as HttpPostedFile objects.</p>
<pre><code>foreach(HttpPostedFile file in Request.Files)
file.SaveAs(...);
</code></pre>
|
<p>The problem is that the FileUpload control has locked off the FileName parameter from being set programmatically. The reason for this is to protect the user from some malicious script deciding that it wants to upload system files to the server instead of what the user wants.</p>
<p>You will not be able to use the FileUpload control in the situation you describe above, you'll want to seek out an alternative.</p>
| 49,143
|
<p>I'm finally getting the hang of RSpec after spending a couple of hours over the weekend. Now I'm stuck trying to figure out how to assert that parameters are indeed passed into the controller. I'm following the <a href="http://blog.8thlight.com/articles/2008/04/20/bowled-over-by-rubycocoa" rel="nofollow noreferrer">Bowled over by Ruby/Cocoa example</a> and adapting it for the iPhone SDK. I've done a more detailed <a href="http://codeforfun.wordpress.com/2008/11/10/rspec-for-iphone-development/" rel="nofollow noreferrer">writeup of my progress on my blog</a> so I'll defer there for the entire story. In short I've followed the tutorial all the way up to where you need to pass the pin value from the text field into the Bowling object. RSpec keeps complaining that, <em>"Spec::Mocks::MockExpectationError in ‘OSX::BowlingController should send the pin value to the bowling object’
Mock ‘Bowling’ expected :roll with (10) but received it with (no args)
./test/bowling_controller_spec.rb:38:”</em> Even as I'm certain that I'm passing a value in. Here's my code. Can someone tell me where I'm going wrong?</p>
<p><strong>bowling_controller_spec.rb</strong></p>
<pre><code>require File.dirname(__FILE__) + '/test_helper'
require "BowlingController.bundle"
OSX::ns_import :BowlingController
include OSX
describe BowlingController do
before(:each) do
@controller = BowlingController.new
@bowling = mock('Bowling')
@text_field = mock('Pins')
@text_field.stub!(:intValue).and_return(10)
@controller.pins = @text_field
end
it "should roll a ball" do
@controller.roll
end
it "should roll a ball and get the value from the pins outlet" do
@text_field.should_receive(:intValue).and_return(0)
@controller.roll
end
it "should be an OSX::NSObject" do
@controller.is_a?(OSX::NSObject).should == true
end
it "should have an outlet to a bowling object" do
@controller.bowling = @bowling
end
it "should send the pin value to the bowling object" do
@controller.bowling = @bowling
@bowling.should_receive(:roll).with(10)
@controller.roll
end
end
</code></pre>
<p><strong>BowlingController.h</strong></p>
<pre><code>#import <Foundation/Foundation.h>
@class UITextField;
@class Bowling;
@interface BowlingController : NSObject {
UITextField* pins;
Bowling* bowling;
}
@property (nonatomic, retain) UITextField* pins;
@property (nonatomic, retain) Bowling* bowling;
-(void) roll;
@end
</code></pre>
<p><strong>BowlingController.m</strong></p>
<pre><code>#import "BowlingController.h"
#import "Bowling.h"
@implementation BowlingController
@synthesize pins;
@synthesize bowling;
-(void) roll{
[self.bowling roll:[self.pins intValue]];
}
@end
// This initialization function gets called when we import the Ruby module.
// It doesn't need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_BowlingController() { }
</code></pre>
<p><strong>Bowling.h</strong></p>
<pre><code>#import <Foundation/Foundation.h>
@interface Bowling : NSObject {
}
- (void) roll:(int) pins;
@end
</code></pre>
<p><strong>Bowling.m</strong></p>
<pre><code>#import "Bowling.h"
@implementation Bowling
- (void) roll:(int) pins{
}
@end
// This initialization function gets called when we import the Ruby module.
// It doesn't need to do anything because the RubyCocoa bridge will do
// all the initialization work.
// The rbiphonetest test framework automatically generates bundles for
// each objective-c class containing the following line. These
// can be used by your tests.
void Init_Bowling() { }
</code></pre>
|
<p>RubyCocoa is not supported at all on the iPhone. There is no bridge support library, and I do not believe there is any ruby interpreter on the phone.</p>
<p>You might be able to get it working in the simulator, it will not stop you from using OS X only libraries if you really try, but that still will not make it work on the iPhone.</p>
<p>If you really want to use RubyCocoa on the iPhone you will need to build ruby as a static library and port the bridge to the phone, which is doable, but would probably be very difficult.</p>
|
<p>Howdy! Though I'm not familiar with how Ruby/Cocoa wraps foreign method calls- or with Objective C for that matter- the first place that would seem likely to disconnect under test is passing in a Ruby mock to the natively implemented controller. In the bowling tutorial, the ruby controller proxy is exposes its interface to the Cocoa bridge while in this implementation the proxy wraps an exposed Cocoa interface. There might be an issue, then, when substituting a ruby mock for a native field versus a ruby mock for a ruby field.</p>
<p>The roll() test for the pins succeeds, though, so it's possible that messages are being passed correctly but arguments are mangled or dropped.</p>
<p>This probably isn't much help, but it's an interesting problem. Good luck with the project!</p>
| 35,146
|
<p>I'm doing a basic homework assignment which looks like this:</p>
<pre><code> While input <> -1
input = CDbl(InputBox("Enter numbers to add, enter -1 to stop"))
values = values + input
End While
</code></pre>
<p>It works fine until I press 'cancel' on the input box. Then the string input is "", and I get the following error:</p>
<pre><code>System.InvalidCastException {"Conversion from string ""
to type 'Double' is not valid."}
</code></pre>
<p>I think I understand the error, I'm trying to convert using CDbl a non-numeric value. My question is what would be a more proper way to write this code? Is it the code, or just a lack of error handling?</p>
|
<p>Try using Double.TryParse</p>
<pre><code>Dim value as Double = Nothing
If Double.TryParse(InputBox("Enter numbers..."), value) Then
values = values + value
End If
</code></pre>
<p>My syntax may be a bit off, but you should get the idea</p>
|
<p>You'd also get an error if they entered anything other than a double or a value too big to be stored in a double.</p>
<p>The suggestions made should be enough though, you essentially want to validate the user input before you attempt to cast it.</p>
| 38,343
|
<h2>Question</h2>
<p>I'm sure many of you have been faced by the challenge of localizing a database backend to an application. If you've not then I'd be pretty confident in saying that the odds of you having to do so in the future is quite large. I'm talking anout storing multiple translations of texts (and the same can be said for currency etc.) for your database entities.</p>
<p>For example the classic "Category" table might have a Name and a Description column which should be globalized. One way would be to do have a "Text" table for each of your entities and then do a join to retreive the values based on the provided language.</p>
<p>This leaves you with a lot of "Text" tables, one for each entity which you want to localize, with the addition of a TextType to distinguish between the various texts that it may store.</p>
<p>I'm curious if there are any, documented, best-practises / design patterns on implementing this kind of support into a SQL Server 2005/2008 datebase (I'm being specific about the RDBMS since it might contain supported keywords and such which helps with the implementation)?</p>
<h2>Thoughts on XML approach</h2>
<p>One idea I have been toying with (albeit only in my head so far) was to leverage the XML datatype introduced in SQL Server 2005. The idea was to make columns which should support localization, of the XML datatype (and bind a schema to it). The XML would contain the localized strings along with the language code / culture it was tied to.</p>
<p>Something along the lines of</p>
<pre><code>Product
ID (int, identity)
Name (XML ...)
Description (XML ...)
</code></pre>
<p>Then you would have something like this as the XML</p>
<pre><code><localization>
<text culture="sv-SE">Detta är ett namn</text>
<text culture="en-EN">This is a name</text>
</localization>
</code></pre>
<p>You could then do (This isn't production code so I'll use the *)</p>
<pre><code>SELECT *
From Product
Where Product.ID = 10
</code></pre>
<p>And you would get back the product with all localized texts which would mean you would have to do the extraction on the client-side. The biggest problem here is obviously the amount of extra data that you would have to return on each query, The benefits would be a cleaner design with no look-up tables, joins and so on. </p>
<p>Btw, what ever method I do end up using in my design I will still be using Linq To SQL (.NET Platform) to query the database (the XML approach should be a problem since it would return an XElement which could be interpreted client-side)</p>
<p>So suggestion on database localization design patterns, and possibly comments on the XML thought, would be very apprechiated.</p>
|
<p>I think you can stick with XML which allows for a cleaner design. I would go further and take advantage of the <code>xml:lang</code> attribute which <a href="http://www.opentag.com/xfaq_lang.htm" rel="nofollow noreferrer">is designed for this usage</a> :</p>
<pre><code><l10n>
<text xml:lang="sv-SE">Detta är ett namn</text>
<text xml:lang="en-EN">This is a name</text>
</l10n>
</code></pre>
<p>One step further, you could select the localized resource in your query via <a href="http://msdn.microsoft.com/en-us/library/ms345117(SQL.90).aspx" rel="nofollow noreferrer">a XPath query</a> (as suggested in the comments) to avoid any client side treatment. This would give something like this (untested) :</p>
<pre><code>SELECT Name.value('(l10n/text[lang()="en"])[1]', 'NVARCHAR(MAX)')
FROM Product
WHERE Product.ID=10;
</code></pre>
<p>Note that this solution would be an elegant but less efficient solution than the separate table one. Which may be OK for some application.</p>
|
<p>I like the XML approach, because the separate-table-solution would NOT return a result if e.g. there is no swedish translation (cultureID = 1) unless you do an outer join. But nevertheless you can NOT fall back to English. With the XML approach you simply can fall back to English.
Any news on the XML approach in a producitve environment?</p>
| 32,271
|
<p>I recently signed up to shared web hosting with godaddy using Linux and PHP 5. I want to work with multiple RSS feeds. I previously had this all functioning under Apache, however, the host supplied the PEAR installation. Now I have to do this myself and I am in unfamiliar territory.I installed PEAR PHP and managed to get rss.php in the pear directory. It now asks for XML/Parser.php and I do not want to spend another week finding where and what to do.
Can you please inform me where i can find this routine and whther there is any problem in just copying it into the PEAR directory with ftp?</p>
|
<p>You can always just create some subfolder in your project and extract any PEAR libraries directly there, it's just plain php scripts. You will have to add that folder (and subfolders) to your include path so everything will be accessible.
It is considered as a bad practice because you will have to manually update PEAR libraries and stuff, but it gives you independence from your hoster.</p>
|
<p>Your PEAR (or other libraries) classes can be anywhere. You just need to set correct include paths where script will search for required code. If you can't access php.ini, you can get include paths by using <code>get_include_path()</code> function and set them using <code>set_include_path();</code></p>
| 43,151
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.