instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>This very simple code gives me tons of errors:</p>
<pre><code>#include <iostream>
#include <string>
int main() {
std::string test = " ";
std::cout << test;
}
</code></pre>
<p>I tried to compile it on linux by typing <strong>gcc -o simpletest simpletest.cpp</strong> on the console. I can't see why it isn't working. What is happening?</p>
|
<p>Try using 'g++' instead of 'gcc'.</p>
|
<p>You declared your <code>main()</code> as returning an <code>int</code> yet you have no return statement. Add <code>return 0;</code> and see if that helps. If that doesn't solve your problem, try editing your post to include some representative lines from those errors your getting and maybe we can help you better.</p>
| 33,483
|
<p>I have unevenly distributed data (wrt <code>date</code>) for a few years (2003-2008). I want to query data for a given set of start and end date, grouping the data by any of the supported intervals (day, week, month, quarter, year) in <a href="https://www.postgresql.org/docs/8.3/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC" rel="nofollow noreferrer">PostgreSQL 8.3</a>.</p>
<p>The problem is that some of the queries give results continuous over the required period, as this one:</p>
<pre><code>select to_char(date_trunc('month',date), 'YYYY-MM-DD'), count(distinct post_id)
from some_table
where category_id = 1
and entity_id = 77
and entity2_id = 115
and date <= '2008-12-06'
and date >= '2007-12-01'
group by date_trunc('month',date)
order by date_trunc('month',date);
to_char | count
------------+-------
2007-12-01 | 64
2008-01-01 | 31
2008-02-01 | 14
2008-03-01 | 21
2008-04-01 | 28
2008-05-01 | 44
2008-06-01 | 100
2008-07-01 | 72
2008-08-01 | 91
2008-09-01 | 92
2008-10-01 | 79
2008-11-01 | 65
(12 rows)
</code></pre>
<p>But some of them miss some intervals because there is no data present, as this one:</p>
<pre><code>select to_char(date_trunc('month',date), 'YYYY-MM-DD'), count(distinct post_id)
from some_table
where category_id=1
and entity_id = 75
and entity2_id = 115
and date <= '2008-12-06'
and date >= '2007-12-01'
group by date_trunc('month',date)
order by date_trunc('month',date);
to_char | count
------------+-------
2007-12-01 | 2
2008-01-01 | 2
2008-03-01 | 1
2008-04-01 | 2
2008-06-01 | 1
2008-08-01 | 3
2008-10-01 | 2
(7 rows)
</code></pre>
<p>where the required resultset is:</p>
<pre><code> to_char | count
------------+-------
2007-12-01 | 2
2008-01-01 | 2
2008-02-01 | 0
2008-03-01 | 1
2008-04-01 | 2
2008-05-01 | 0
2008-06-01 | 1
2008-07-01 | 0
2008-08-01 | 3
2008-09-01 | 0
2008-10-01 | 2
2008-11-01 | 0
(12 rows)
</code></pre>
<p>A count of 0 for missing entries.</p>
<p>I have seen earlier discussions on Stack Overflow but they don't solve my problem it seems, since my grouping period is one of (day, week, month, quarter, year) and decided on runtime by the application. So an approach like left join with a calendar table or sequence table will not help I guess.</p>
<p>My current solution to this is to fill in these gaps in Python (in a Turbogears App) using the calendar module.</p>
<p>Is there a better way to do this?</p>
|
<p>You can create the list of all first days of the last year (say) with</p>
<pre><code>select distinct date_trunc('month', (current_date - offs)) as date
from generate_series(0,365,28) as offs;
date
------------------------
2007-12-01 00:00:00+01
2008-01-01 00:00:00+01
2008-02-01 00:00:00+01
2008-03-01 00:00:00+01
2008-04-01 00:00:00+02
2008-05-01 00:00:00+02
2008-06-01 00:00:00+02
2008-07-01 00:00:00+02
2008-08-01 00:00:00+02
2008-09-01 00:00:00+02
2008-10-01 00:00:00+02
2008-11-01 00:00:00+01
2008-12-01 00:00:00+01
</code></pre>
<p>Then you can join with that series.</p>
|
<p>You could create a temporary table at runtime and left join on that. That seems to make the most sense.</p>
| 45,042
|
<p>I'm loading data into a DataSet from an XML file using the ReadXml method. This results in two tables with the same name. One of the tables has a namespace and the other doesn't. I'm trying to reference the table with the namespace. Can anyone tell me how to do this?</p>
<pre><code> Dim reader As XmlTextReader = New XmlTextReader(strURL)
Dim city as string = ""
Dim ds As DataSet = New DataSet()
ds.Namespace = "HomeAddress"
ds.ReadXml(reader)
city = ds.Tables("Address").Rows(0).Item(2).ToString()
</code></pre>
|
<p>Browsers (and Dashcode) provide an XMLHttpRequest object which can be used to make HTTP requests from JavaScript:</p>
<pre><code>function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
</code></pre>
<p>However, synchronous requests are discouraged and will generate a warning along the lines of:</p>
<blockquote>
<p>Note: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), <strong>synchronous requests on the main thread have been deprecated</strong> due to the negative effects to the user experience.</p>
</blockquote>
<p>You should make an asynchronous request and handle the response inside an event handler.</p>
<pre><code>function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
</code></pre>
|
<p>You can do it with pure JS too:</p>
<pre><code>// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
// Make the actual CORS request.
function makeCorsRequest() {
// This is a sample server that supports CORS.
var url = 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var text = xhr.responseText;
alert('Response from CORS request to ' + url + ': ' + text);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send();
}
</code></pre>
<p>See: for more details: <a href="https://www.html5rocks.com/en/tutorials/cors/" rel="nofollow noreferrer">html5rocks tutorial</a></p>
| 30,744
|
<p>Which is better in general in terms of the ordering? Do you put the fault condition at the top or bottom?</p>
<pre><code>if (noProblems == true) {
// do stuff
} else {
// deal with problem
}
</code></pre>
<p>OR</p>
<pre><code>if (noProblems == false) {
// deal with problem
} else {
// do stuff
}
</code></pre>
|
<p>i like to eliminate error cases first - and return from the function early so that the 'happy path' remains un-nested, e.g.</p>
<pre><code>if (some error condition)
{
//handle it
return;
}
//implicit else for happy path
...
</code></pre>
<p>if it is easy to identify the conditions leading to the happy path, then by all means put that clause first (thanks Marcin!)</p>
|
<p>It depends on what is clearer to you. I mean, what makes more sense, that noProblems has a true value or that it has a false value.</p>
<p>For example for isDeviceEnabled() I would always check for a true result as "Enabled" has implicitly a positive value. For an implicit negative value we could check for example for "isMemoryAvailable()", maybe because you need to check only if there is no more room for new objects/arrays or other data.</p>
| 40,733
|
<p>I have a 30000x14000 sparse matrix in MATLAB (version 7), which I need to use in another program. Calling save won't write this as ASCII (not supported). Calling <code>full()</code> on this monster results in an <code>Out of Memory</code> error.<br>
How do I export it?</p>
|
<p>You can use find to get index & value vectors:</p>
<pre><code>[i,j,val] = find(data)
data_dump = [i,j,val]
</code></pre>
<p>You can recreate data from data_dump with spconvert, which is meant to "Import from sparse matrix external format" (so I guess it's a good export format):</p>
<pre><code>data = spconvert( data_dump )
</code></pre>
<p>You can save to ascii with:</p>
<pre><code>save -ascii data.txt data_dump
</code></pre>
<p>But this dumps indices as double, you can write it out more nicely with fopen/fprintf/fclose:</p>
<pre><code>fid = fopen('data.txt','w')
fprintf( fid,'%d %d %f\n', transpose(data_dump) )
fclose(fid)
</code></pre>
<p>Hope this helps.</p>
|
<p>If this is pretty much a one time deal, then I would just iterate through the matrix and write the matrix to an ASCII file by brute force, or else use @<a href="https://stackoverflow.com/questions/217852/saving-matlab-sparse-matrix-to-text-file#217885">Veynom's</a> suggestion and call full() on a subset of rows. It may take a while, but it will probably be done faster than it might take to learn how to read in a .mat file outside of the MATLAB environment.</p>
<p>If this is something you need to do on a recurring basis, then I would take @<a href="https://stackoverflow.com/questions/217852/saving-matlab-sparse-matrix-to-text-file#217891">Vebjorn</a>'s advice and use a library to read the .mat file.</p>
| 26,780
|
<p>So, you are all ready to do a big SVN Commit and it bombs because you have inconsistent line endings in some of your files. Fun part is, you're looking at 1,000s of files spanning dozens of folders of different depths.</p>
<p>What do you do?</p>
|
<p>I don't think the <a href="http://svnbook.red-bean.com/nightly/en/svn.ref.reposhooks.pre-commit.html" rel="noreferrer">pre-commit</a> hook can actually change the data that is being committed - it can disallow a commit, but I don't think it can do the conversion for you.</p>
<p>It sounds like you want the <a href="http://svnbook.red-bean.com/nightly/en/svn.ref.properties.html" rel="noreferrer">property</a> 'svn:eol-style' set to 'native' - this will automatically convert newlines to whatever is used on your platform (use 'CRLF', 'CR' or 'LF' to get those regardless of what the OS wants).</p>
<p>You can use <a href="http://subversion.apache.org/faq.html#auto-props" rel="noreferrer">auto-properties</a> so that all future files you create will have this property set (auto props are handled client-side, so you'd have to set this up for each user).</p>
|
<p>you can use notepad++ to batch convert line endings.
Make regex search:</p>
<p><code>([^\r])\n</code></p>
<p>and replace it with</p>
<p><code>$1\r\n</code></p>
<p>you then should choose a bunch of test files like:</p>
<p><code>*.xml;*.txt;*.csv;...</code>asf.</p>
<p>this avoids that you accidently modify binary files</p>
<p><em>NOTE</em>: the regex patterns skip empty lines, so you have to run a second replace job with <code>\n\n</code> and replace it with <code>\n\r\n</code></p>
| 3,646
|
<p>I have a nested function to show/hide paragraphs news-ticker-style.</p>
<p>The problem is that when the loop starts over (line 4), the opacity effects stop working correctly so the paragraphs appear abruptly. </p>
<p>Any jquery masters know about this? Am I making this too hard?</p>
<pre><code>$('#special-ticker p').hide();
var a=0;
function outer() {
function inner() {
if(a===$('#special-ticker p').length) { a = 0; }
$('#special-ticker p').
eq(a).
fadeIn(800, function(){
$(this).animate({opacity:100},10000,null,function(){
$(this).hide(800,function(){
a++;
outer();
});
});
});
}
return inner();
}
$(function(){
outer();
});
</code></pre>
|
<p>the problem is line 9:</p>
<pre><code>$(this).animate({opacity:100},10000,null,function(){
//...
</code></pre>
<p>opacity should be "1" (opacity is a value between 0 and 1)</p>
<pre><code>$(this).animate({ opacity : 1 }, 10000, null, function() {
</code></pre>
|
<p>Try this: </p>
<pre><code>
newsticker = function (selector) {
$(selector).hide();
var i = $(selector).length - 1;
var toggle = function() {
$(selector).eq(i).fadeOut("slow", function() {
i = ++i % $(selector).length;
$(selector).eq(i).fadeIn("slow", function() {
setTimeout(toggle, 1000)
});
});
};
toggle();
};
</code></pre>
<p>and initialize it with this:</p>
<pre><code>
new newsticker("#special-ticker p");
</code></pre>
| 37,243
|
<p>I have a table with 3 columns. I want to write a formula that, given a structured reference, returns the index of the column. This will help me write VLookup formulas using the structured reference.</p>
<p>So, for example, for the table <code>MyTable</code> with columns <code>A</code>, <code>B</code>, <code>C</code> I'd like to be able to write:</p>
<pre><code>=GetIndex(MyTable[C])
</code></pre>
<p>and have it return 3.</p>
<p>Right now I just make sure the table range starts on the sheet's first column and I write</p>
<pre><code>=Column(MyTable[C])
</code></pre>
<p>but I want something a more robust.</p>
|
<p>A suitable formula based on your example would be</p>
<pre><code>=COLUMN(MyTable[C])-COLUMN(MyTable)+1
</code></pre>
<p>The first part of the forumla <code>COLUMN(MyTable[C])</code> will return the column number of the referenced column.</p>
<p>The second part of the formula <em>COLUMN(MyTable)</em> will always return the column number of the first column of the table.</p>
|
<p>You could use: <code>=COLUMN(MyTable[<code>*</code>]) - COLUMN(MyTable[A]) + 1</code>, where <code>*</code> is the column whose index you want.</p>
| 47,540
|
<p>When writing a custom itemRenderer, how do you reference the height and width of the grid cell that it will be rendered in? In such a way that it will resize correctly when the grid is resized.</p>
<p>I am writing a dataGrid itemRenderer that draws a bar graph in the final column of a table.</p>
<p>I have tried referencing 'this', 'this.parent', and a few other things with no success.
My interim hack solution is to add this data to the datacollection, but this wont work when the grid changes size, so I will have to edit it every time.</p>
|
<p>All flex components including cell renderers are aware of their own widths and heights, so you should be able to just access this.width and this.height</p>
<p>If you're looking for events that tell you when a cell has resized you can listen to the
<code>ResizeEvent.RESIZE</code> event or override
<code>protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void</code> on the component.</p>
|
<p>Your itemRenderer for the final column inherits the layout's size. Use absolute layout for the MXML itemRenderer and it will scale to fit.</p>
| 36,557
|
<p>Someone told me about a C++ style difference in their team. I have my own viewpoint on the subject, but I would be interested by <em>pros</em> and <em>cons</em> coming from everyone.</p>
<p>So, in case you have a class property you want to expose via two getters, one read/write, and the other, readonly (i.e. there is no set method). There are at least two ways of doing it:</p>
<pre><code>class T ;
class MethodA
{
public :
const T & get() const ;
T & get() ;
// etc.
} ;
class MethodB
{
public :
const T & getAsConst() const ;
T & get() ;
// etc.
} ;
</code></pre>
<p>What would be the pros and the cons of each method?</p>
<p>I am interested more by C++ technical/semantic reasons, but style reasons are welcome, too.</p>
<p>Note that <code>MethodB</code> has one major technical drawback (hint: in generic code).</p>
|
<p>Well, for one thing, getAsConst <em>must</em> be called when the 'this' pointer is const -- not when you want to receive a const object. So, alongside any other issues, it's subtly misnamed. (You can still call it when 'this' is non-const, but that's neither here nor there.)</p>
<p>Ignoring that, getAsConst earns you nothing, and puts an undue burden on the developer using the interface. Instead of just calling "get" and knowing he's getting what he needs, now he has to ascertain whether or not he's currently using a const variable, and if the new object he's grabbing needs to be const. And later, if both objects become non-const due to some refactoring, he's got to switch out his call.</p>
|
<p>While it appears your question only addresses one method, I'd be happy to give my input on style. Personally, for style reasons, I prefer the former. Most IDEs will pop up the type signature of functions for you.</p>
| 12,254
|
<p>For a right triangle specified by an equation aX + bY <= c on integers </p>
<p>I want to plot each pixel(*) in the triangle once and only once, in a pseudo-random order, and without storing a list of previously hit points.</p>
<p>I know how to do this with a line segment between 0 and x</p>
<blockquote>
<p>pick a random point'o' along the line,<br>
pick 'p' that is relatively prime to x<br>
repeat for up to x times: O<sub>next</sub> = (O<sub>cur</sub> + P) MOD x</p>
</blockquote>
<p>To do this for a triangle, I would<br>
1. Need to count the number of pixels in the triangle sans lists<br>
2. Map an integer 0..points into a x,y pair that is a valid pixel inside the triangle</p>
<p>I hope any solution could be generalized to pyramids and higher dimensional shapes. </p>
<p>(*) I use the CG term pixel for the pair of integer points X,Y such that the equation is satisfied. </p>
|
<p>Since you want to guarantee visiting each pixel once and only once, it's probably better to think in terms of pixels rather than the real triangles.
You can slice the triangles horizontally and get bunch of horizontal <a href="http://en.wikipedia.org/wiki/Scan_line" rel="nofollow noreferrer">scan lines</a>. Connect the scan lines together and you have converted your "triangle" into a long line. Apply your point visiting algorithm to your long chain of scan lines.</p>
<p>By the way, this mapping only needs to happen on paper, all you need is a function that can return (x, y) given (t) along the virtual scan line. </p>
<p>Edit:
To convert two points to a line segment, you can look for <a href="http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm" rel="nofollow noreferrer">Bresenham's scan conversion</a>. Once you get the 3 line segments converted into series of points, you can put all points into a bucket and group all points by y. Within the same y-value, sort points by x. The smallest x within a y-value is the begin point of the scan line and the largest x within the y-value is the end point of the scan line. This is called "scan converting triangle". You can find more info if you Google.</p>
|
<p>One method is to put all of the pixels into an array and then shuffle the array (this is O(n)), then visit the pixels in the order in the shuffled array. This could require quite a lot of memory though.</p>
| 19,472
|
<p>i know its a new thing , more powerful and a lot more options added to it,
but is linq2sql is part of the new EF ? </p>
<p>if not , what is the main different between the two frameworks?</p>
|
<p>I've written a couple of opinion pieces about LINQ-to-Entities, and its relation to LINQ-to-SQL:</p>
<p><a href="http://www.hackification.com/2008/12/03/linq-to-entities-the-blackberry-storm-of-orms/" rel="nofollow noreferrer">http://www.hackification.com/2008/12/03/linq-to-entities-the-blackberry-storm-of-orms/</a>
<a href="http://www.hackification.com/2008/12/04/linq-to-entities-follow-up/" rel="nofollow noreferrer">http://www.hackification.com/2008/12/04/linq-to-entities-follow-up/</a></p>
<p>Summary: LINQ-to-SQL isn't the same as LINQ-to-Entities. L2S has a small feature-set, but what it does, it does very well. L2E aims to cover a much wider feature-set, but the current version seems to have some glaring omissions (eg lazy-loading). v2 of L2E should be much better; the current version (IMHO) feels more like a beta.</p>
|
<p>From what I have read and been told (repeatedly =) ), linq 2 sql is being retired in favor of Linq to EF. </p>
<p>See here <a href="https://stackoverflow.com/questions/253263/has-microsoft-really-killed-linq-to-sql">https://stackoverflow.com/questions/253263/has-microsoft-really-killed-linq-to-sql</a> and here <a href="https://stackoverflow.com/questions/252683/is-linq-to-sql-doa">Is LINQ to SQL Dead or Alive?</a></p>
<p>EF will allow you to use a more generic backing store, and that is better for users of non MSSQL backing stores.</p>
| 46,014
|
<p>I'm making my way through the early <a href="http://www.asp.net/learn/data-access/?lang=cs" rel="noreferrer">Data Access Tutorials</a> on Microsoft's ASP.NET website and it occurred to me that this all seems awfully similar to what I have read about separating your logic and presentation code using the <a href="http://en.wikipedia.org/wiki/Model-view-controller" rel="noreferrer">MVC pattern</a>. As a newbie I have yet to implement the MVC pattern but I'm curious as to how these two design structures differ and if I should be focusing my attention on one or the other, particularly in the context of web design.</p>
|
<p>The link you've posted for the Data Access Tutorial is implementation of MVC pattern. MVC pattern is a concept, implementation can differ; you have this in ASP.NET whereas in Java there's one framework called <a href="http://en.wikipedia.org/wiki/Apache_Struts" rel="noreferrer">Struts</a>, which is an implementation MVC.</p>
<p>DAL & BLL patterns differ from the MVC pattern in terms of concepts; but NOT this specific implementation. MVC is actually achieved through usage of DAL, BLL & View Patterns.</p>
|
<p>The link you've posted for the Data Access Tutorial is implementation of MVC pattern. MVC pattern is a concept, implementation can differ; you have this in ASP.NET whereas in Java there's one framework called <a href="http://en.wikipedia.org/wiki/Apache_Struts" rel="noreferrer">Struts</a>, which is an implementation MVC.</p>
<p>DAL & BLL patterns differ from the MVC pattern in terms of concepts; but NOT this specific implementation. MVC is actually achieved through usage of DAL, BLL & View Patterns.</p>
| 33,611
|
<p>I've got a byte() array returned as result of directx sound capture, but for other parts of my program I want to treat the results as single(). Is trundling down the array item by item the fastest way of doing it or is there a clever way to do it ? </p>
<p>The code that gets it is</p>
<pre><code>CType(Me._applicationBuffer.Read(Me._nextCaptureOffset, GetType(Byte), LockFlag.None, LockSize), Byte())
</code></pre>
<p>which creates the byte array, can Ctype handle single ? (note, I can't figure out a way to do it!)</p>
|
<pre><code>public float[] ByteArrayToFloatArray(byte[] byteArray)
{
float[] floatArray = new float[byteArray.Length / 4];
for (int i = 0; i < floatArray.Length; i++)
{
floatArray[i] = BitConverter.ToSingle(byteArray, i * 4);
}
return floatArray;
}
</code></pre>
<p>The fastest way to do this (in terms of performance as opposed to how long it takes to write) would probably be to use the <a href="http://www.codeproject.com/KB/vb/netcopymemorysample.aspx" rel="nofollow noreferrer">CopyMemory</a> API call.</p>
|
<p>Try</p>
<pre><code>float f = BitConverter.ToSingle(bytearray, 0);
</code></pre>
<p>In VB (I think):</p>
<pre><code>Dim single s;
s = BitConverter.ToSingle(bytearray, 0);
</code></pre>
| 20,138
|
<p>How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?</p>
|
<p>Running a jar is as simple as</p>
<pre><code>java -jar filename.jar
</code></pre>
|
<p>In the project properties dialog in NetBeans you need to set the Main Class - otherwise the generated .jar will not be executable. Then, as already indicated, either double clicking on the .jar or the command java -jar will start the program.</p>
| 21,307
|
<p>I am currently using the following javascript to create an expanding menu:</p>
<p><a href="http://demo.raibledesigns.com/struts-menu/scripts/menuExpandable.js.src" rel="nofollow noreferrer">http://demo.raibledesigns.com/struts-menu/scripts/menuExpandable.js.src</a></p>
<p>Currently, only the hyperlink text is clickable. What is the best way to have the icon next to the text respond to the click?</p>
|
<p>The icons should be be:</p>
<ul>
<li>inline elements within the anchor tag</li>
<li>background images for the anchor tag</li>
</ul>
<p>You can do all of that in CSS and/or markup, keeping the javascript nice and simple.</p>
<p>The third alternative would be to bind the icon element to the hyperlink's event handler method, but the end result is less optimal and it requires the most work.</p>
|
<p>HTML</p>
<pre><code><a id="icon" href="blah">blah</a>
</code></pre>
<p>CSS</p>
<pre><code>#icon {
background: transparent url(img.gif) no-repeat right center;
padding-right: 10px;
}
</code></pre>
| 32,645
|
<p>A few months ago I was introduced to the new <a href="http://msdn.microsoft.com/library/system.datetimeoffset.aspx" rel="noreferrer"><code>DateTimeOffset</code></a> type and was glad <a href="http://msdn.microsoft.com/library/system.datetime.aspx" rel="noreferrer"><code>DateTime</code></a>'s flaws with regard to time zones were finally taken care of.</p>
<p>However, I was left wondering if there were any overhead or problems that could occur from using this new type.</p>
<p>I work on a multi-locale web application. Does anyone know of anything that could sway me from just using it for all my date/time work? Is there a window for abuse here?</p>
<p>Reference: <a href="http://blogs.msdn.com/bclteam/archive/2007/06/14/datetimeoffset-a-new-datetime-structure-in-net-3-5-justin-van-patten.aspx" rel="noreferrer">DateTimeOffset: A New DateTime Structure in .NET 3.5 by Justin Van Patten</a></p>
|
<p>Sometimes you really just want to represent a "local" (timezone unaware) date and time rather than an <em>instant</em> in time. To be honest it's more often useful to represent just a time - e.g. "wake me up at 8am, regardless of timezone" - but date and time could be useful too.</p>
<p>I agree that for the vast majority of cases, <code>DateTimeOffset</code> is a better fit. It does strike me as odd that there isn't a <code>DateTimeTimeZone</code> struct which has both the instant and its timezone though... an offset doesn't actually give you all the information you need. (For instance, given a <code>DateTimeOffset</code>, you don't know what the time will be 24 hours later, because you don't know when DST might kick in.)</p>
<p>If you want that kind of structure, I have a <a href="https://stackoverflow.com/questions/246498/creating-a-datetime-in-a-specific-time-zone-in-c-fx-35#246529">very crude implementation in another answer</a>. I'm sure it could be improved very easily :)</p>
|
<p>Whilst I wouldn't PREFER to use DateTime over DateTimeOffset, please note that sometimes you NEED to, as MS .Net does not support DateTimeOffset as a DataColumn.DataType property <a href="https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.datatype?view=netframework-4.7.2" rel="nofollow noreferrer">DataColumn.DataType Property</a> even though SQL datetimeoffset has been around since SQL2008. </p>
<p>I myself had a problem with reading (<code>ReadXml</code>) a DateTimeOffset value of an XML exported DataSet with <code>XmlReadMode.InferTypedSchema</code>; it read it as a DateTime and crashed when I tried to merge it into a DateTimeOffset column</p>
| 33,150
|
<p>What algorithms could i use to determine common characters in a set of strings?</p>
<p>To make the example simple, I only care about 2+ characters in a row and if it shows up in 2 or more of the sample. For instance:</p>
<ol>
<li>0000abcde0000 </li>
<li>0000abcd00000 </li>
<li>000abc0000000</li>
<li>00abc000de000</li>
</ol>
<p>I'd like to know:</p>
<p>00 was used in 1,2,3,4<br>
000 was used in 1,2,3,4<br>
0000 was used in 1,2,3<br>
00000 was used in 2,3<br>
ab was used in 1,2,3,4<br>
abc was used in 1,2,3,4<br>
abcd was used in 1,2<br>
bc was used in 1,2,3,4<br>
bcd was used in 1,2<br>
cd was used in 1,2<br>
de was used in 1,4 </p>
|
<p>I'm assuming that this is not homework. (If it is, you're one your own re plagiarism! ;-)</p>
<p>Below is a quick-and-dirty solution. The time complexity is <code>O(m**2 * n)</code> where <code>m</code> is the average string length and <code>n</code> is the size of the array of strings.</p>
<p>An instance of <code>Occurrence</code> keeps the set of indices which contain a given string. The <code>commonOccurrences</code> routine scans a string array, calling <code>captureOccurrences</code> for each non-null string. The <code>captureOccurrences</code> routine puts the current index into an <code>Occurrence</code> for each possible substring of the string it is given. Finally, <code>commonOccurrences</code> forms the result set by picking only those <code>Occurrences</code> that have at least two indices.</p>
<p>Note that your example data has many more common substrings than you identified in the question. For example, <code>"00ab"</code> occurs in each of the input strings. An additional filter to select interesting strings based on content (e.g. all digits, all alphabetic, etc.) is -- as they say -- left as an exercise for the reader. ;-)</p>
<p>QUICK AND DIRTY JAVA SOURCE:</p>
<pre><code>package com.stackoverflow.answers;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class CommonSubstringFinder {
public static final int MINIMUM_SUBSTRING_LENGTH = 2;
public static class Occurrence implements Comparable<Occurrence> {
private final String value;
private final Set<Integer> indices;
public Occurrence(String value) {
this.value = value == null ? "" : value;
indices = new TreeSet<Integer>();
}
public String getValue() {
return value;
}
public Set<Integer> getIndices() {
return Collections.unmodifiableSet(indices);
}
public void occur(int index) {
indices.add(index);
}
public String toString() {
StringBuilder result = new StringBuilder();
result.append('"').append(value).append('"');
String separator = ": ";
for (Integer i : indices) {
result.append(separator).append(i);
separator = ",";
}
return result.toString();
}
public int compareTo(Occurrence that) {
return this.value.compareTo(that.value);
}
}
public static Set<Occurrence> commonOccurrences(String[] strings) {
Map<String,Occurrence> work = new HashMap<String,Occurrence>();
if (strings != null) {
int index = 0;
for (String string : strings) {
if (string != null) {
captureOccurrences(index, work, string);
}
++index;
}
}
Set<Occurrence> result = new TreeSet<Occurrence>();
for (Occurrence occurrence : work.values()) {
if (occurrence.indices.size() > 1) {
result.add(occurrence);
}
}
return result;
}
private static void captureOccurrences(int index, Map<String,Occurrence> work, String string) {
final int maxLength = string.length();
for (int i = 0; i < maxLength; ++i) {
for (int j = i + MINIMUM_SUBSTRING_LENGTH; j < maxLength; ++j) {
String partial = string.substring(i, j);
Occurrence current = work.get(partial);
if (current == null) {
current = new Occurrence(partial);
work.put(partial, current);
}
current.occur(index);
}
}
}
private static final String[] TEST_DATA = {
"0000abcde0000",
"0000abcd00000",
"000abc0000000",
"00abc000de000",
};
public static void main(String[] args) {
Set<Occurrence> found = commonOccurrences(TEST_DATA);
for (Occurrence occurrence : found) {
System.out.println(occurrence);
}
}
}
</code></pre>
<p>SAMPLE OUTPUT: (note that there was actually only one Occurrence per line; I can't seem to prevent the blockquote markup from merging lines)</p>
<blockquote>
<p>"00": 0,1,2,3
"000": 0,1,2,3<br>
"0000": 0,1,2
"0000a": 0,1<br>
"0000ab": 0,1
"0000abc": 0,1<br>
"0000abcd": 0,1
"000a": 0,1,2<br>
"000ab": 0,1,2
"000abc": 0,1,2<br>
"000abcd": 0,1
"00a": 0,1,2,3<br>
"00ab": 0,1,2,3
"00abc": 0,1,2,3<br>
"00abc0": 2,3
"00abc00": 2,3<br>
"00abc000": 2,3
"00abcd": 0,1<br>
"0a": 0,1,2,3
"0ab": 0,1,2,3<br>
"0abc": 0,1,2,3
"0abc0": 2,3<br>
"0abc00": 2,3
"0abc000": 2,3<br>
"0abcd": 0,1
"ab": 0,1,2,3
"abc": 0,1,2,3
"abc0": 2,3
"abc00": 2,3<br>
"abc000": 2,3
"abcd": 0,1
"bc": 0,1,2,3
"bc0": 2,3
"bc00": 2,3<br>
"bc000": 2,3
"bcd": 0,1
"c0": 2,3
"c00": 2,3
"c000": 2,3
"cd": 0,1<br>
"de": 0,3
"de0": 0,3
"de00": 0,3<br>
"e0": 0,3
"e00": 0,3</p>
</blockquote>
|
<p>you can use an analysis of distance matrix. Any diagonal movement (no cost change) is an exact match.</p>
| 34,006
|
<p>Is there a <code>wchar_t</code> version of <code>exec[lv][pe]</code> (i.e. an <code>exec</code> that uses <code>wchar_t</code> as path and <code>wchar_t</code> as arguments)?
In <code>Windows</code>, I can just do <code>CreateProcessW(process, cmdline)</code>, but in <code>*nix</code>, I'm stuck (i.e. no pure <code>POSIX</code> equivalent).
I'm trying to add <code>UTF-16</code> support to my program (an autorun).</p>
|
<p>There is not. In UNIX, it's customary to use UTF-8 when interacting with the environment.</p>
|
<p>There is not. In UNIX, it's customary to use UTF-8 when interacting with the environment.</p>
| 17,526
|
<p>Anyone know the formula used to control the movement of a simple tank-like vehicle?</p>
<p>To 'steer' it, you need to alter the force applied the left and right "wheels". Eg. 1 unit of force on both wheels makes it go forward. -1 units of force on both wheels makes it go backwards. Apply more force to one wheel than the other and it turns.</p>
<p>How would you calculate the amount of force needed on both wheels to turn the tank a certain number of degrees either way?</p>
<p>Or am I thinking about this in the wrong way?</p>
<p>edit:
As William Keller mentioned I missed out the speed of the tank. Assume 1 unit of force on both wheels moves the tank forward at 1 unit per second.</p>
<p>For anyone who's interested, I just found this thread on gamedev.net:
<a href="http://66.102.9.104/search?q=cache:wSn5t58ACJwJ:www.gamedev.net/community/forums/topic.asp%3Ftopic_id%3D407491+tank+track+radius+velocity&hl=en&ct=clnk&cd=1&gl=za&client=firefox-a" rel="nofollow noreferrer">http://66.102.9.104/search?q=cache:wSn5t58ACJwJ:www.gamedev.net/community/forums/topic.asp%3Ftopic_id%3D407491+tank+track+radius+velocity&hl=en&ct=clnk&cd=1&gl=za&client=firefox-a</a></p>
<p>Another thread:
<a href="http://www.physicsforums.com/showthread.php?t=220317" rel="nofollow noreferrer">http://www.physicsforums.com/showthread.php?t=220317</a></p>
<p>It turns out the key to finding the formula was just knowing the correct terminology ("skid steer") :P</p>
|
<p>For a skid steered vehicle that is required to turn in radius 'r' at a given speed 'Si' of the Inner Wheel/Track, the Outer track must be driven at speed 'So' :</p>
<pre><code>So = Si * ((r+d)/r)
</code></pre>
<p><strong>Details:</strong></p>
<p>In Skid Steering, a turn is performed by the outer wheels/track traveling further distance than the inner wheels/track.</p>
<p>Furthermore, the extra distance traveled is completed in the same time as the inner track, meaning that the outer wheels/track must run faster.</p>
<p>Circle circumference circumscribed by "Inner" track:</p>
<pre><code>c1 = 2*PI*r
'r' is radius of circle origin to track/wheel
</code></pre>
<p>Circle circumference circumscribed by "Outer" track:</p>
<pre><code>c2 = 2*PI*(r+d)
'r' is radius of circle origin to inner track/wheel
'd' is the distance between the Inner and Outer wheels/track.
</code></pre>
<p>Furthermore, c2 = X * c1, which says that c2 is proportionally bigger than c1</p>
<pre><code>X = c2 / c1
X = 2*PI*(r+d) / 2*PI*r
X = (r+d)/r
</code></pre>
<p>Therefore for a skid steered vehicle that is required to turn in radius 'r' at a given speed 's' of the Inner Wheel/Track, the Outer track must be driven at :</p>
<pre><code>So = Si * ((r+d)/r)
</code></pre>
<p>Where:</p>
<pre><code>'So' = Speed of outer track
'Si' = Speed of inner track
'r' = turn radius from inner track
'd' = distance between vehicle tracks.
********* <---------------- Outer Track
**** | ****
** |<--------**----------- 'd' Distance between tracks
* *******<-------*---------- Inner Track
* *** ^ *** *
* * |<-----*------*-------- 'r' Radius of Turn
* * | * *
* * O * *
* * * *
* * * *
* *** *** *
* ******* *
** **
**** ****
*********
</code></pre>
|
<p>It has been a while since I did any physics but I would have thought that the apposing forces of the two tracks moving in opposite directions results in a torque about the center of mass of the tank.</p>
<p>It is this torque that results in the angular momentum of the tank which is just another way of saying the tank starts to rotation.</p>
| 15,205
|
<p>Having programmed for a while now I have noticed that I am becoming more and more reliant on the internet and IntelliSense to do my job. But I was wondering how much that has affected my knowledge over the past year or so. But does this matter?</p>
<p>For example I am more likely now to remember that when I need to program against objects I have no knowledge about, I will go to the System.Reflection namespace and a quick look down the list will provide me with enough detail to get going again. But if you was to ask me which classes etc are required I would struggle to name them all.</p>
<p>This problem of remembering seems to manifest itself more when going for interviews when people seem to focus more on the minute detail of obscure areas of the .NET framework and not on the wide and varied knowledge and experience of the applicant. Anyway I digress.</p>
<p>Does anyone else think that maybe its time to turn off the IntelliSense and try and find better ways to learn, than quick fixes and work-arounds of the internet?</p>
|
<p>Have you read <a href="http://charlespetzold.com/etc/DoesVisualStudioRotTheMind.html" rel="nofollow noreferrer">Charles Petzold's essay</a> on the subject? There's some thought-provoking stuff there.</p>
<p>I'm not sure that it matters too much that you don't know things off by heart. Yes, it's a problem for interviews - but that shows that the interviewing process doesn't match reality.</p>
<p>I certainly wouldn't recommend turning off Intellisense. Coding is hard enough without trying to learn by heart things which the computer can easily tell us.</p>
|
<p>I agree with every answer here.</p>
<p>It's not that I would turn off IS or remove myself from the internet. I suppose I was thinking more along the lines of: most if not all of these questions asked on this forum could be answered by doing searches on the internet. Is knowledge and understanding gauged by how quickly and effectively one can search Google? Is it effecting the way we learn.</p>
<p>Yes I could answer every question on here if I had the time to search for the answers, maybe I would learn something but I would not classify myself as a Guru. Further, I would feel I have cheated.</p>
<p>And in the same way IS and the Internet help people with a solid understanding to quickly get the job done. It also limits or slows down the learning (and understanding) of people new to programming to gain that understanding. So I assume people who have programmed for a long time but learning new skills or techniques my also have the same problem as those who are just starting to learn. When I first started programming - not just randomly smacking keys on my C64 - I followed tutorials online and read oodles of stuff to get the job done. But it wasn't until I actually stepped away from "getting the job done" and started learning about processor architecture, APIs, memory management, well you get the picture, that I actually started to understand.</p>
<p>Maybe I just have a misplaced perception that understanding and a thorough knowledge make a good programmer good.</p>
| 45,867
|
<p>I'm just starting to try out phpunit on some existing code. The naming convention we use is that the MyClass class should be in MyClass.class.php. PHPUnit seems to require that the file should be called MyClass.php. </p>
<p>Is there any way around this?</p>
<p>I noticed it while trying to generate a skeleton test class:</p>
<pre><code>phpunit --skeleton-test MyClass.class
PHPUnit 3.3.4 by Sebastian Bergmann.
Could not find class "MyClass.class" in "/home/jd/skeleton/classes/MyClass.class.php".
Fatal error: Call to a member function getOutClassName() on a non-object in /usr/share/php/PHPUnit/TextUI/Command.php on line 470
</code></pre>
|
<p>Its not a requirement, its just assumptive. You can write your own test-cases. </p>
<p>Skeleton just makes a mock-up one "the easy way" that makes dummy functions for all your classes dummy functions. </p>
<p>Also, </p>
<pre><code>phpunit --skeleton-test MyClass MyClass.class.php
</code></pre>
<p>Might do what you want. </p>
<pre><code> Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches] <directory>
--skeleton-class Generate Unit class for UnitTest in UnitTest.php.
--skeleton-test Generate UnitTest class for Unit in Unit.php.
</code></pre>
<p>so by that reasoning, if you don't tell it what file the class is in it will try guess, if you do tell it what file the class is in, it wont guess.</p>
|
<p>I ran up against a similar problem when the class a skeleton is being generated for is namespaced. I'm using phpunit 3.5.6 from the command-line. The phpUnit documentation example didn't work for me and I couldn't find the answer online so I figured I share it here. Suppose you have class Foo inside directory /my/dir and it's declared in a single file Foo.php so the full path to the class file is /my/dir/Foo.php</p>
<p>Also suppose that Foo is declared as follows:</p>
<pre><code><?php
namespace my\space;
class Foo
{
...
}
</code></pre>
<p>In order to generate a test skeleton I made sure I was in the directory where Foo.php resides and then I ran the following command:</p>
<pre><code>user[/my/dir]$ phpunit --skeleton-test my\\dir\\Foo Foo.php
</code></pre>
<p>That got my skeleton to generate. The key was escaping the backslash as the documentation of phpUnit mentions namespaces but only shows one backslash. Hope this helps someone.</p>
| 36,907
|
<p>I'm sure some of you noticed that if you have Acrobat Reader ( or any other pdf viewer ) , and open a pdf in Firefox , you will see it embedded inside your tab . Is there any way to embed an application in a JFrame ?</p>
|
<p>This is a rather tricky. In general, native application such and Adobe Reader does not provide component which can be embedded into swing application. But in Windows there is COM/OLE approach which allows embedding of application together. This <a href="http://www.javalobby.org/java/forums/t70811.html" rel="noreferrer">article</a> can help you. It points on two project JCOM and JACOB which allows such embedding.</p>
|
<p>Yes, but that application will need to provide JComponent version which is embeddable.</p>
| 39,834
|
<p>I learned some time ago about Decision Trees and Decision tables. I feel that Decision Tables can help with conditional If-Then-Else statements. In particular, I feel that Decision Tables have no side-effects, for example, if you didn't notice that you need one more "else if" statement.</p>
<p>But I am not sure how I can implement it. Arrays? Database Tables?
Does anyone even use Decision Tables in their code, nowadays?</p>
|
<p>I would highly recommend chapter 18 of <a href="http://cc2e.com/" rel="nofollow noreferrer">Code Complete</a>.</p>
<p>You could also check this post <a href="https://stackoverflow.com/questions/105311/what-are-table-driven-methods">What Are Table Driven Methods</a></p>
|
<p>A table-driven method uses data structures instead of if-then statements to drive program logic. For example, if you are processing two types of records (tv versus cable) you might do this:</p>
<p>hash[tv] = processTvRecords</p>
<p>hash[cable] = processCableRecords</p>
<p>In some languages, like Ruby or Perl, this technique is straightforward. In Java, you'd need to use Reflection to find method handles.</p>
<p>If you want to learn about decision tables, investiagethe Fitnesse testing framework at <a href="http://fitnesse.org/" rel="nofollow noreferrer">http://fitnesse.org/</a>.</p>
| 14,243
|
<p>I work for an R&D company in the energy business. We've developed some successful products, but now seem to be spending all our time fixing issues relating to those products. We don't seem to have any time to work on developing new products.
Does anyone have any good ideas on how to both handle problems arising with the existing products but still have the time and resources to develop new products as well?</p>
<p>TY,
Fred</p>
|
<p>If you have a successful product, and are staffed to handle either development OR maintenance then the solution seems to point at hiring. <br><br>Perhaps bring in some new blood/fresh grads to "grow" them into the more mission critical side of the R&D company? Thus the new blood would gain experience on existing products (with guidance from the more senior staff) and grow into great devs for the R&D side!</p>
|
<p>"time-management"</p>
<p>try <a href="http://www.amazon.com/s/ref=nb_ss_gw_0_19?url=search-alias%3Dstripbooks&field-keywords=getting+things+done+david+allen&sprefix=getting+things+done" rel="nofollow noreferrer"><em>Getting Things Done</em></a> by David Allen</p>
| 29,780
|
<p>Is there a programmatic way to build <em>htpasswd</em> files, without depending on OS specific functions (i.e. <code>exec()</code>, <code>passthru()</code>)?</p>
|
<p>.httpasswd files are just text files with a specific format depending on the hash function specified. If you are using MD5 they look like this:</p>
<pre><code>foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241
</code></pre>
<p>That's the login, a colon, ,$apr1$, the salt and 1000 times md5 encoded as base64. If you select SHA1 they look like this:</p>
<pre><code>foo:{SHA}BW6v589SIg3i3zaEW47RcMZ+I+M=
</code></pre>
<p>That's the login, a colon, the string {SHA} and the SHA1 hash encoded with base64.</p>
<p>If your language has an implementation of either MD5 or SHA1 and base64 you can just create the file like this:</p>
<pre><code><?php
$login = 'foo';
$pass = 'pass';
$hash = base64_encode(sha1($pass, true));
$contents = $login . ':{SHA}' . $hash;
file_put_contents('.htpasswd', $contents);
?>
</code></pre>
<p>Here's more information on the format:</p>
<p><a href="http://httpd.apache.org/docs/2.2/misc/password_encryptions.html" rel="noreferrer">http://httpd.apache.org/docs/2.2/misc/password_encryptions.html</a></p>
|
<p><a href="http://trac.edgewall.org" rel="nofollow noreferrer">Trac</a> ships with a Python replacement for htpasswd, which I'm sure you could port to your language of choice: <a href="http://trac.edgewall.org/browser/trunk/contrib/htpasswd.py" rel="nofollow noreferrer">htpasswd.py</a>.</p>
| 6,111
|
<p>Is it possible to set the position of the tabs to be at the bottom of the tabcontainer using the AjaxToolkit? You do have some control over the CSS but I'm not au-fait enough with CSS to see whether it's feasible?</p>
<p>Thanks</p>
|
<p>Well really it's down to the browser; not the protocol (HTTP 1.0 does allow for compression quite happily)</p>
<p>You should be examining the <a href="http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Accept-Encoding" rel="noreferrer">Accept-Encoding</a> header, which will either be gzip, deflate. If the header isn't there then don't compress.</p>
|
<p>Check out <a href="http://www.computec.ch/projekte/browserrecon/scan/accept-encoding.fdb" rel="nofollow noreferrer">this rather extensive list</a>. (short answer appears to be : Yes they do).</p>
| 29,637
|
<p>I'm trying to identify differences between a base case and supplied case. Looking for a library to tell me similarity in percentage or something like that.</p>
<p>For Example:</p>
<p>I've 10 different HTML pages.
* All of them are 404 responses with only one 2 lines of random code (such as time or quote of the day).</p>
<p>Now when I supply a new 404 page I want a result back such as "%80" similar,however if I supply another page totally different or same website but quite different content I should get something lile "%20 similar".</p>
<p>Basically what I want to do is, when I've got a new response I want to identify if the new response is similar to these 10 pages which I supplied before.</p>
<p>I'm trying to solve this in .NET, A library or an algorithm recommendation would be great.</p>
|
<p>Rather than using a diff tool you could use a copy/paste detector (cpd). Then you can configure a threshold of how alike you want files to be.</p>
<p>As an aside, I have used these in the past to track down cheaters in school.</p>
<p>Sam</p>
|
<p>A quick and dirty way would be to compute the Levenshtein distance of the markup.</p>
<p><a href="http://en.wikipedia.org/wiki/Levenstein_distance" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Levenstein_distance</a></p>
| 13,327
|
<p>I have a generic function which gets a interface as a type, now in one condition I have to create a new class depending on the interface. I have been thinking about it and a way to solve it would be to use an IoC but I was hoping there would be an other way because an IoC seems a bit like an overkill. </p>
<p>below is an attempt using the visitor pattern:</p>
<pre><code>public class RepositoryManager<T> : IRepositoryManager<T> where T : class, new()
{
public T GetOrCreate(string id)
{
T item = (T)CreateNew(new T(), id);
return item;
}
}
</code></pre>
<p>If instead of an interface I was getting an object then I could use the visitor pattern to figure out what class to instantiate but I can't seem to figure this out depending on the interface provided.</p>
<p>An other idea I had was if I can make the where declaration like an or?</p>
<pre><code>public class RepositoryManager<T> : IRepositoryManager<T> where T : class, Iabc or Ixyz, new()
</code></pre>
<p>I hope the question is clear :)</p>
<p>-Mark</p>
<hr>
<p>Thanks for the reply's.</p>
<p>The problem is that the method can have many different interfaces assigned to it for example:</p>
<p>RepositoryManager class:</p>
<pre><code>private static IMedicament CreateNew(IMedicament emptyType, string id)
{
return new Medicament { Id = id };
}
private static IRefund CreateNew(IRefund emptyType, string id)
{
return new Refund { Id = id };
}
RepositoryManager<Iabc> abcRepository = new RepositoryManager<Iabc>();
RepositoryManager<Ixyz> xyzRepository = new RepositoryManager<Ixyz>();
Iabc abc = abcRepository.GetOrCreate("12345");
Ixyz xyz = xyzRepository.GetOrCreate("12345");
</code></pre>
<p>so using <code>T item = (T)CreateNew(new T(), id);</code> won't work because I have to tell it that T can either be of type Iabc or Ixyz but when I do that I get the following error:</p>
<p>The call is ambiguous between the following methods or properties: <code>RepositoryManager<T>.CreateNew(IMedicament, string)</code> and <code>RepositoryManager<T>.CreateNew(IRefund, string)</code></p>
<p>It would be nice if I get this working besides just copying the code several times.</p>
|
<p>And why doesn't this work?</p>
<pre><code>public class RepositoryManager<T> : IRepositoryManager<T> where T : Ixyz, new()
{
public T GetOrCreate(string id)
{
T item = (T)CreateNew(new T(), id);
return item;
}
}
</code></pre>
<p>An alternative, if you can't use new() is to pass in a delegate to create the object (or a compatible type):</p>
<pre><code>public class RepositoryManager<T> : IRepositoryManager<T> where T : Ixyz
{
private Func<T> _tConstructor;
public RepositoryManager(Func<T> tConstructor)
{
this._tConstructor = tConstructor;
}
public T GetOrCreate(string id, )
{
T item = (T)CreateNew(this._tConstructor(), id);
return item;
}
}
</code></pre>
|
<p>I came across this problem myself just the other day. The probem is that you don't know how many parameters the constructor takes. On the assumption that it takes none, the following code will work.</p>
<pre><code>public void Method<T>()
{
Type type = typeof(T);
T newObject = (T)type.GetConstructor(new System.Type[] { }).Invoke(new object[] { });
}
</code></pre>
<p>The example uses reflection. If you need parameters then you can put objects into the arrays created in the code.</p>
| 39,055
|
<p>Our team would like to move from the Visual SourceSafe (VSS) to the Team Foundation Server (TFS). I know that the TFS is much more than just a version control system, but for the first time I would like to use it this way.</p>
<p>Currently our projects are organized within the single solution that consists of the shared part (common library) and many customer projects.</p>
<p>Is there some kind of migration guide that would describe such a challenge? Or TFS enforces its own usage scenarios (versioning of projects, releases, etc.)?</p>
|
<p>TFS certainly has much more potential than just as a source repository, but it's quite understandable why you would want to migrate source control first.</p>
<p>The migration utility of choice is generally <a href="http://msdn.microsoft.com/en-us/library/ms253090(VS.80).aspx" rel="nofollow noreferrer">VSSConverter.exe</a> which allows you to map VSS paths to Team Project source control paths and is pretty well documented in this walkthrough <a href="http://msdn.microsoft.com/en-us/library/ms181247(VS.80).aspx" rel="nofollow noreferrer">here</a>.</p>
<p>There's another tool (<A href="http://www.codeplex.com/MigrationSyncToolkit" rel="nofollow noreferrer">TFS Migration and Synchronization Toolkit</a>) available over on CodePlex, but when I compared the two, I determined that VSSConverter has been more widely used and I think is generally accepted as being the tool of choice for VSS migrations.</p>
<p>It seems there are a few more answers <a href="https://stackoverflow.com/questions/29838/visual-source-safe-tfs-migration">on this thread here</a> also. </p>
<p>Now, the question I think you are <b>really</b> asking is more about guidance on creating Team Projects and structuring? </p>
<p>This is a little harder to answer without knowing more about your specific circumstance. Patterns and Practices published a <a href="http://www.codeplex.com/TFSGuide" rel="nofollow noreferrer">book on CodePlex called the TFS Guide</a> which might help - it describes amongst many things, a suggested Team Project source control structure. It might help in giving you some guidance around how to migrate and/or remap your solution structure.</p>
<p>Regards to versioning and branching, check out this <a href="http://www.codeplex.com/BranchingGuidance" rel="nofollow noreferrer">site here on branching guidance</a> - it's not a bad overview of some common branching/release management techniques using TFS.</p>
<p>If you get through all that reading, you'll really be on top of most of the essential TFS groundwork!</p>
|
<p>When we switched from Sourcesafe to TFS2005 the biggest hurdle were Sourcesafe's shared files, the "Get latest on checkout" approach and the branch/merge "support" in Sourcesafe. Everybody feared branching and merging in Sourcesafe and it took some time convincing all colleagues that it is not that bad with TFS. </p>
<p>We decided to not migrate files from Sourcesafe. We used TFS2005 for a new project and kept the old stuff in Sourcesafe. We didn't want to keep the project and folder structure which had grown over the years and was rather unorganized. </p>
<p>The old stuff is history now and we do all development work with TFS2008. </p>
| 19,334
|
<p>I have an application A with a domain-model which is mapped to a database using Hibernate. I have another application B that uses exactly the same domain-model-classes as A and adds some additional classes. </p>
<p>My goal is to read data from database A in application B and transfer that data into the database of B (to make a copy of it). In addition, some the domain-classes of B have associations (OneToOne) to domain-classes of A (but in the database of B, of course).</p>
<p>What's the best strategy to accomplish this? I thought of two session factories and using <code>Session.replicate()</code> (how does that work?). Or should I better introduce an additional mapping layer between these two domain-models for loose coupling?</p>
|
<p>I've done this before to transfer data between two different database types (in my case DB2 and MS SQL Server). What I did was to create two separate session factories, and give both of them the same list of mapping files. Then I simply read records from one, and saved them to the other.</p>
<p>Of course, this assumed that both data sources were identical.</p>
|
<p>What is the purpose of the copying? Is that part of your application flow or logic? or just straight data copying?</p>
<p>If it is just for the sake of copying data over, there is no need to use hibernate. There are plenty of tools for it.</p>
| 19,617
|
<p>In a bash script I execute a command on a remote machine through ssh. If user breaks the script by pressing Ctrl+C it only stops the script - not even ssh client. Moreover even if I kill ssh client the remote command is still running...</p>
<p>How can make bash to kill local ssh client and remote command invocation on Crtl+c?</p>
<p>A simple script:</p>
<pre><code>#/bin/bash
ssh -n -x root@db-host 'mysqldump db' -r file.sql
</code></pre>
|
<p>Eventual I found a solution like that:</p>
<pre><code>#/bin/bash
ssh -t -x root@db-host 'mysqldump db' -r file.sql
</code></pre>
<p>So - I use '-t' instead of '-n'.
Removing '-n', or using different user than root does not help.</p>
|
<p>What if you don't want to require using "ssh -t" (for those as forgetful as I am)?</p>
<p>I stumbled upon looking at the parent PID, because CTRL/C from the initiating session results in the ssh-launched process on the remote process exiting, although its child process continues. By way of example, here's my script that is on the remote server.</p>
<pre><code>#!/bin/bash
Answer=(Alive Dead)
Index=0
while [ ${Index} -eq 0 ]; do
if ! kill -0 ${PPID} 2> /dev/null ; then Index=1; fi
echo "Parent PID ${PPID} is ${Answer[$Index]} at $(date +%Y%m%d%H%M%S%Z)" > ~/NowTime.txt
sleep 1
done
</code></pre>
<p>I then invoke it with "ssh remote_server ./test_script.sh"
"watch cat ~/NowTime.txt" on the remote server shows the timestamp in the file increasing and declaring that the parent process is alive; once I hit CTRL/C in the launching process, the script on the remote server notes that its parent process has died, and the script exits.</p>
| 42,972
|
<p>We all know that deadlines and/or critical bugfixes and make us forget a bit about source formatting guidelines. Or sometimes you need to work with 3rd party source code which seems to have been coded by someone who doesn't know the meaning of whitespace and readability. What is your favorite tool to tabulate your code (or 3rd party code) to your specification?</p>
|
<p>Resharper's built in tool is pretty awesome.</p>
|
<p>For Delphi I like <a href="http://www.aew.wur.nl/UK/Delforexp/" rel="nofollow noreferrer">Delforexp</a>. Simple and quite fast.</p>
| 23,467
|
<p>My website has been giving me intermittent errors when trying to perform <em>any</em> Ajax activities. The message I get is</p>
<pre><code>Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
<!DOCTYPE html P'.
</code></pre>
<p>So its obviously some sort of server timeout or the server's just returning back mangled garbage. This generally, unfortunately not always, happe</p>
|
<p>There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:</p>
<p><strong><a href="http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx" rel="noreferrer">Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it</a></strong></p>
<p>Read the comments too. There is a comment of somebody with the same problem: "<strong>I solved it changing server idle time of my app pool on IIS</strong>. It was only 5, so I incremented it and now works."</p>
<p><em>"The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server.</em></p>
<p><em>Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often).</em></p>
<p><em>Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts."</em></p>
<p><strong>Most common reasons for that error:</strong></p>
<ol>
<li>Calls to Response.Write():</li>
<li>Response filters</li>
<li>HttpModules</li>
<li>Server trace is enabled</li>
<li>Calls to Server.Transfer()</li>
</ol>
|
<p>I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)</p>
<p>But later the error returned again, now in a random fashion. After some search I got the answer: the viewstate was becoming too large and was been truncated. I disable some viewstates on grids and menus and the problem haven't shown again.</p>
| 36,972
|
<p>What is the best way to get hosting of an ASP.NET MVC application to work on IIS 5 (6 or 7). When I tried to publish my ASP.NET MVC application, all I seemed to get is 404 errors. I've done a bit of googleing and have found a couple of solutions, but neither seem super elegant, and I worry if they will be unusable once I come to use a shared hosting environment for the application.</p>
<p><a href="http://blogs.microsoft.co.il/blogs/dorony/archive/2007/12/15/using-asp-net-mvc-on-iis-5.aspx" rel="nofollow noreferrer">Solution 1</a></p>
<blockquote>
<ol>
<li>Right-click your application virtual directory on inetmgr.exe.</li>
<li>Properties->Virtual Directory Tab-> Configuration.</li>
<li>Add a new mapping extension. The extension should be .*, which will be
mapped to the Executable
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,
or the appropriate location on your
computer (you can simply copy this
from the mapping for .aspx files). On
the mapping uncheck "check that file
exists".</li>
<li>3 X OK and you're good to go.</li>
<li>If you want, you can apply this setting to all your web sites. In
step1, click on the "Default Web Site"
node instead of your own virtual
directory, and in step 2 go to the
"Home Directory" tab. The rest is the
same.</li>
</ol>
</blockquote>
<p>It seems a tad hacky to route everything through ASP.NET.</p>
<p><a href="http://blog.pagedesigners.co.nz/?p=29" rel="nofollow noreferrer">Solutions 2</a></p>
<p>Edit the MVC routing to contain .mvc in the URL and then follow the steps in solution 1 based around this extension. <em>Edit: The original image link was lost, but here it is from Google's Cache:</em></p>
<p><img src="https://i.stack.imgur.com/TDp4F.png" alt="alt text"></p>
|
<p>Answer is <a href="http://forums.asp.net/p/1239943/2294813.aspx" rel="nofollow noreferrer">here</a></p>
<blockquote>
<p>If *.mvc extension is not registered
to the hosting , it will give 404
exception. The working way of hosting
MVC apps in that case is to modify
global.asax routing caluse in the
following way.</p>
<p>routes.Add(new
Route("{controller}.mvc.aspx/{action}",
new MvcRouteHandler()) {
Defaults = new RouteValueDictionary (new{ controller
= "YourController"} ) });</p>
<p>In this way all your controller
request will end up in *.mvc.aspx,
which is recognized by your hosting.
And as the MVC dlls are copied into
your local bin , no special setttings
need to be done for it.</p>
</blockquote>
|
<p>Have you tried adding .aspx to the end of the controller name?</p>
<p>It worked for Stack Overflow question <em><a href="https://stackoverflow.com/questions/32757/where-can-i-get-asp-mvc-hosting">Where can I get ASP.NET MVC hosting?</a></em>.</p>
| 8,206
|
<p>I have some shared server web hosting in the States (I'm from the UK), which allows me to publish PHP and .NET applications. I cannot install my own software onto the remote server, but I'd like to set up a web forwarding proxy for accessing sites that serve different content depending on what country you're from.</p>
<p>My C# and ASP.NET skills are OK, but my PHP is very limited. Are there any solutions that anyone would recommend for this sort of problem? The proxies I've investigated all seem to require installation on the server machine itself, whereas I'm just looking for something that's accessible from a URL.</p>
<p>Obviously, as the requests are coming from the UK, the headers will have to be manipulated by the proxy before forwarding them on. I was going to code my own HTTP handler in C#, but I don't want to reinvent the wheel if there's something out there already ;)</p>
|
<p>Check out this plugin for AuthLogic:</p>
<p><a href="http://github.com/phurni/authlogic_api" rel="noreferrer">http://github.com/phurni/authlogic_api</a></p>
<p>I think that does what you are looking for.</p>
|
<p>The <a href="http://code.google.com/p/oauth/" rel="nofollow noreferrer">OAuth plugin</a> could be useful for the keys. It may look like <a href="http://oauth.net/" rel="nofollow noreferrer">OAuth</a> is only for user authentication, but if you autogenerate the access tokens and give them to developers, instead of having an interactive user process with request tokens and account authorization, then you basically have a quite secure API key system. And the plugin will just drop in nicely.</p>
<p>Other than that, some nice use of rails' routes (with conditions to call a different action on get, post, put, etc, and a prefix of /api/v1/) and format (format.xml, format.js, etc) provides a pretty nice way to build RESTful APIs, withought really needing a plugin.</p>
| 45,594
|
<p>I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems.</p>
<p>So, sometime in the very far past I went to try and find if there existed any "pattern" or text-book way of transforming a common recursion approach to iteration and found nothing. Or at least nothing that I can remember it would help.</p>
<ul>
<li>Are there general rules?</li>
<li>Is there a "pattern"?</li>
</ul>
|
<p>Usually, I replace a recursive algorithm by an iterative algorithm by pushing the parameters that would normally be passed to the recursive function onto a stack. In fact, you are replacing the program stack by one of your own.</p>
<pre class="lang-js prettyprint-override"><code>var stack = [];
stack.push(firstObject);
// while not empty
while (stack.length) {
// Pop off end of stack.
obj = stack.pop();
// Do stuff.
// Push other objects on the stack as needed.
...
}
</code></pre>
<p>Note: if you have more than one recursive call inside and you want to preserve the order of the calls, you have to add them in the reverse order to the stack:</p>
<pre><code>foo(first);
foo(second);
</code></pre>
<p>has to be replaced by</p>
<pre><code>stack.push(second);
stack.push(first);
</code></pre>
<p>Edit: The article <a href="http://cs.saddleback.edu/rwatkins/CS2B/Lab%20Exercises/Stacks%20and%20Recursion%20Lab.pdf" rel="noreferrer">Stacks and Recursion Elimination</a> (or <a href="https://web.archive.org/web/20120227170843/http://cs.saddleback.edu/rwatkins/CS2B/Lab%20Exercises/Stacks%20and%20Recursion%20Lab.pdf" rel="noreferrer">Article Backup link</a>) goes into more details on this subject.</p>
|
<p>A rough description of how a system takes any recursive function and executes it using a stack:</p>
<p>This intended to show the idea without details. Consider this function that would print out nodes of a graph:</p>
<pre><code>function show(node)
0. if isleaf(node):
1. print node.name
2. else:
3. show(node.left)
4. show(node)
5. show(node.right)
</code></pre>
<p>For example graph:
A->B
A->C
show(A) would print B, A, C</p>
<p>Function calls mean save the local state and the continuation point so you can come back, and then jump the the function you want to call.</p>
<p>For example, suppose show(A) begins to run. The function call on line 3. show(B) means
- Add item to the stack meaning "you'll need to continue at line 2 with local variable state node=A"
- Goto line 0 with node=B.</p>
<p>To execute code, the system runs through the instructions. When a function call is encountered, the system pushes information it needs to come back to where it was, runs the function code, and when the function completes, pops the information about where it needs to go to continue.</p>
| 19,305
|
<p>Are there any downsides to passing structs by value in C, rather than passing a pointer?</p>
<p>If the struct is large, there is obviously the performance aspect of copying lots of data, but for a smaller struct, it should basically be the same as passing several values to a function.</p>
<p>It is maybe even more interesting when used as return values. C only has single return values from functions, but you often need several. So a simple solution is to put them in a struct and return that.</p>
<p>Are there any reasons for or against this?</p>
<p>Since it might not be obvious to everyone what I'm talking about here, I'll give a simple example.</p>
<p>If you're programming in C, you'll sooner or later start writing functions that look like this:</p>
<pre><code>void examine_data(const char *ptr, size_t len)
{
...
}
char *p = ...;
size_t l = ...;
examine_data(p, l);
</code></pre>
<p>This isn't a problem. The only issue is that you have to agree with your coworker in which the order the parameters should be so you use the same convention in all functions.</p>
<p>But what happens when you want to return the same kind of information? You typically get something like this:</p>
<pre><code>char *get_data(size_t *len);
{
...
*len = ...datalen...;
return ...data...;
}
size_t len;
char *p = get_data(&len);
</code></pre>
<p>This works fine, but is much more problematic. A return value is a return value, except that in this implementation it isn't. There is no way to tell from the above that the function <code>get_data</code> isn't allowed to look at what <code>len</code> points to. And there is nothing that makes the compiler check that a value is actually returned through that pointer. So next month, when someone else modifies the code without understanding it properly (because he didn't read the documentation?) it gets broken without anyone noticing, or it starts crashing randomly.</p>
<p>So, the solution I propose is the simple struct</p>
<pre><code>struct blob { char *ptr; size_t len; }
</code></pre>
<p>The examples can be rewritten like this:</p>
<pre><code>void examine_data(const struct blob data)
{
... use data.tr and data.len ...
}
struct blob = { .ptr = ..., .len = ... };
examine_data(blob);
struct blob get_data(void);
{
...
return (struct blob){ .ptr = ...data..., .len = ...len... };
}
struct blob data = get_data();
</code></pre>
<p>For some reason, I think that most people would instinctively make <code>examine_data</code> take a pointer to a struct blob, but I don't see why. It still gets a pointer and an integer, it's just much clearer that they go together. And in the <code>get_data</code> case it is impossible to mess up in the way I described before, since there is no input value for the length, and there must be a returned length.</p>
|
<p>For small structs (eg point, rect) passing by value is perfectly acceptable. But, apart from speed, there is one other reason why you should be careful passing/returning large structs by value: Stack space.</p>
<p>A lot of C programming is for embedded systems, where memory is at a premium, and stack sizes may be measured in KB or even Bytes... If you're passing or returning structs by value, copies of those structs will get placed on the stack, potentially causing the situation that <a href="https://www.stackoverflow.com">this site</a> is named after...</p>
<p>If I see an application that seems to have excessive stack usage, structs passed by value is one of the things I look for first.</p>
|
<p>I just want to point one advantage of passing your structs by value is that an optimizing compiler may better optimize your code.</p>
| 19,562
|
<p>Say I have a user control like the one below, how would I bind something to the <code>ActualWidth</code> of the "G1" grid from outside of the control?</p>
<pre><code><UserControl x:Class="Blah">
<WrapPanel>
<Grid x:Name="G1">
...
</Grid>
<Grid>
...
</Grid>
</WrapPanel>
</UserControl>
</code></pre>
|
<p>If you mean with outside the control, not as Content of the control, you can use <code>ElementName</code> in the Binding like so:</p>
<pre><code>{Binding ElementName=G1, Path=ActualWidth}
</code></pre>
<p>If you mean outside the control in another Xaml file, then you can try to use the Path property if your control is in the scope of the other control:</p>
<pre><code>{Binding ElementName=ParentControl, Path=G1.ActualWidth}
</code></pre>
<p>However I would advise against this design, because you may change the name of G1 one day, and you would never know of any bindings that might break.</p>
|
<p>If you want to bind to an external control where you use this user control, declare a <code>DependencyProperty</code> at your UserControl code behind and then Bind G1 to that property.
And bind the external control's property to the UserControl's <code>DependencyProperty</code>.
It is like a 2 level of indirection.</p>
| 39,602
|
<p>I have a very basic app that I believe should change the width of an image, but it does nothing... can anyone tell me why, when I click on the image, nothing happens to the image? </p>
<p><em>(note, the image itself doesnt really matter, Im just trying to figure out how to shrink and grow and image in JavaFX)</em></p>
<pre><code>import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.input.MouseEvent;
var w:Number = 250;
Frame {
title: "Image View Sample"
width: 500
height: 500
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true
stage: Stage {
content: [
ImageView {
x: 200;
y: 200;
image: Image {
url: "{__DIR__}/c1.png"
width: bind w;
}
onMouseClicked: function( e: MouseEvent ):Void {
w = 100;
}
}
]
}
}
</code></pre>
<p>Thanks heaps!</p>
|
<p>You can use eval to make your code snippet work:</p>
<pre><code>eval("document.net1003Form." + myField + ".value=val.replace(re, '');");
</code></pre>
<p>As mentioned below, the square brackets work (and don't suck like eval), stupid me for forgetting about those:</p>
<pre><code>document.net1003Form[myField].value=val.replace(re, '');
</code></pre>
<p>Alternatively, try something like this:</p>
<pre><code>function replaceCommaInCurrency(field){
var re = /,/g;
field.value = field.value.replace(re, '');
}
</code></pre>
<p>Which gets called like so:</p>
<pre><code>onBlur="replaceCommaInCurrency(this); return false";
</code></pre>
<p>You should consider using a javascript toolkit for things like this. You could set a class like "currency" on each input, then use this snippet of jQuery based Javascript to handle everything:</p>
<pre><code>$(function(){
$("input.currency").bind('blur', function(){
this.value = $(this).val().replace(',', '');
})
});
</code></pre>
<p>This code would fire on document ready, attach an event handler to each input with currency as its class, and then do the replacements. Note that you don't need a regex for replacement as well.</p>
|
<pre><code> function removeCommaInCurrency(myField)
{
var re = /,/g;
myField.value=myField.value.replace(re, '');
}
</code></pre>
<p>-- and then call it like this:</p>
<pre><code><input type="text" name="..." onchange="removeCommaInCurrency(this);">
</code></pre>
| 35,343
|
<p>The product-group I work for is currently using gcc 3.4.6 (we know it is ancient) for a large low-level c-code base, and want to upgrade to a later version. We have seen performance benefits testing different versions of gcc 4.x on all hardware platforms we tested it on. We are however <em>very</em> scared of c-compiler bugs (for a good reason historically), and wonder if anyone has insight to which version we should upgrade to.</p>
<p>Are people using 4.3.2 for large code-bases and feel that it works fine?</p>
|
<p>The best quality control for gcc is the linux kernel. GCC is the compiler of choice for basically all major open source C/C++ programs. A released GCC, especially one like 4.3.X, which is in major linux distros, should be pretty good.</p>
<p>GCC 4.3 also has better support for optimizations on newer cpus.</p>
|
<p>If you are interested in OpenMP then you will need to move to gcc 4.2 or greater. We are using 4.2.2 on a code base of around 5M lines and are not having any problems with it.</p>
| 5,238
|
<p>If an interface inherits IEquatable the implementing class can define the behavior of the Equals method. Is it possible to define the behavior of == operations?</p>
<pre><code>public interface IFoo : IEquatable
{}
public class Foo : IFoo
{
// IEquatable.Equals
public bool Equals(IFoo other)
{
// Compare by value here...
}
}
</code></pre>
<p>To check that two IFoo references are equal by comparing their values: </p>
<pre><code>IFoo X = new Foo();
IFoo Y = new Foo();
if (X.Equals(Y))
{
// Do something
}
</code></pre>
<p>Is it possible to make <code>if (X == Y)</code> use the Equals method on Foo?</p>
|
<p>No - you can't specify operators in interfaces (mostly because operators are static). The compiler determines which overload of == to call based purely on their static type (i.e. polymorphism isn't involved) and interfaces can't specify the code to say "return the result of calling X.Equals(Y)".</p>
|
<p>No, because interface can't contain operator functions. A solution would be to make IFoo an abstract class instead of an interface :</p>
<pre><code>abstract class IFoo : IEquatable<IFoo>
{
public static bool operator ==(IFoo i1, IFoo i2) { return i1.Equals(i2); }
public static bool operator !=(IFoo i1, IFoo i2) { return !i1.Equals(i2); }
public abstract bool Equals(IFoo other);
}
class Foo : IFoo
{
public override bool Equals(IFoo other)
{
// Compare
}
}
</code></pre>
<p>Of course, this makes you lose the flexibility provided by interfaces.</p>
| 32,749
|
<p>I am working on a C++ project and I noticed that we have a number of warnings about unused parameters.</p>
<p>What effect could it have if these warnings are ignored?</p>
|
<p>The function with an unused parameter may have a real bug in the following cases:</p>
<ol>
<li><p>There is an <strong>output</strong> parameter, which is not being assigned or written into, resulting in undefined value for the caller.</p></li>
<li><p>One of parameters is a callback function pointer, which you must invoke and forget to do so. May happen if there is a lot of <code>#ifdef</code>s in the function.</p></li>
<li><p>You declare a local variable with the same name that shadows a parameter and subsequently use the wrong value down in the function.</p></li>
</ol>
<p>Not using an <strong>input</strong> parameters <strong>may</strong> be harmless, but you can reduce the noise to see useful warnings by marking unused input parameters explicitly in the beginning of the function by casting it to <code>void</code> (works for both C and C++):</p>
<pre><code>(void)param1;
</code></pre>
<p>Or,</p>
<pre><code>#define UNUSED(expr) do { (void)(expr); } while (0)
...
void foo(int param1, int param2)
{
UNUSED(param2);
bar(param1);
}
</code></pre>
<p>Or omit parameter name (C++ only):</p>
<pre><code>void foo(int param1, int /*param2*/)
{
bar(param1);
}
</code></pre>
|
<p>If a method doesn't use a parameter then the first question that arises is that why is that parameter a part of the method's signature in the first place. These warnings do make sense since it is bad design that these are referring to and further, there is a little overhead as well that whenever this method is called, this parameter is pushed on the stack so, the best is to refactor the method and remove such parameters which do not have any use.</p>
<p>Having said that, leaving these parameters doesnt harm a lot except for a little overhead that I mentioned.</p>
| 39,703
|
<p>I was reading up on Ruby, and learned about its mixins pattern, but couldn't think of many useful mixin functionality (because I'm not used to thinking that way most likely). So I was wondering what would be good examples of useful Mixin functionality?</p>
<p>Thanks</p>
<p>Edit: A bit of background. I'm Coming from C++, and other Object languages, but my doubt here is that Ruby says it's not inheriting mixins, but I keep seeing mixins as Multiple inheritance, so I fear I'm trying to categorize them too soon into my comfort zone, and not really grok what a mixin is.</p>
|
<p>They are usually used to add some form of standard functionality to a class, without having to redefine it all. You can probably think of them a bit like interfaces in Java, but instead of just defining a list of methods that need to be implemented, many of them will actually <em>be</em> implemented by including the module.</p>
<p>There are a few examples in the standard library:</p>
<p>Singleton - A module that can be mixed into any class to make it a singleton. The initialize method is made private, and an instance method added, which ensures that there is only ever one instance of that class in your application.</p>
<p>Comparable - If you include this module in a class, defining the <=> method, which compares the current instance with another object and says which is greater, is enough to provide <, <=, ==, >=, >, and between? methods.</p>
<p>Enumerable - By mixing in this module, and defining an <strong>each</strong> method, you get support for all the other related methods such as collect, inject, select, and reject. If it's also got the <=> method, then it will also support sort, min, and max.</p>
<p>DataMapper is also an interesting example of what can be done with a simple include statement, taking a standard class, and adding the ability to persist it to a data store.</p>
|
<p>It is largely used as one might use multiple inheritance in C++ or implementing interfaces in Java/C#. I'm not sure where your experience lies, but if you have done those things before, mixins are how you would do them in Ruby. It's a systemized way of injecting functionality into classes.</p>
| 46,355
|
<p>For example, let's take the format of a forum, where we have multiple users and multiple threads. Say this forum wants to track which users have read which threads and, say, use that information to mark which threads are unread when viewing the thread list.</p>
<p>The only solution I can imagine is something that drops a record into the database each time a user visits a thread. I suppose there could be a 'mark all as read' button, which could employ a time stamp to help lessen the sprawl in the database... regardless this isn't a solution that impresses me.</p>
<p>I have a feeling that I'm missing something here... maybe Thanksgiving morning isn't the time to think over one's programming problems.</p>
<p>Is there a better solution out there for this? Any ideas?</p>
|
<ol>
<li>Drop a record in the database for each user-thread combination</li>
<li>Or store this information in a file - one file per user. It may need to be locked/unlocked in case multiple logins by the same user are allowed.</li>
</ol>
|
<p>I think I saw somewhere, maybe phpbb forum? anyway</p>
<p>there was a table in it with userid, threadid, last-read-datetime (let name it userAsRead)</p>
<p>then it would compare the last post made in that threadid vs last-read-datetime</p>
<p>for the mark as all read, it was a field in the usertable using the same logic as above</p>
<p>don't forget to clear the userAsRead if "mark as all read" is used, would save DB space</p>
| 41,917
|
<p>The Eclipse IDE has a neat little feature that I really miss in Visual Studio.</p>
<p>If I place the cursor on a variable or method name, the IDE will automatically highlight all references to it in the current document within the relevant scope.</p>
<p>I can't seem to find an option to turn on similar behaviour in VS2008 or Resharper 4. I know VS has a Find Usages function, but I'd like to do it automatically on the fly.</p>
<p>Does anyone know of a free addin which will add this functionality?</p>
|
<p>If you're using ReSharper, you can highlight the usages in the file with Shift-Alt-F11. Place your cursor on the variable you want to find usages of, and press the Shift-Alt-F11 combination.</p>
|
<p>Visual Studio 2010 has sorta implemented this, but the feature is somewhat lacking. There is a non-configurable delay between placing the cursor and highlighting.</p>
<p>The RockScroll Addin is not available for Visual Studio 2010 and above.</p>
<p>As a replacement, the free <a href="http://visualstudiogallery.msdn.microsoft.com/4b92b6ad-f563-4705-8f7b-7f85ba3cc6bb" rel="nofollow">"Highlight all occurrences of selected word"</a> plugin will highlight all occurences of the selected string after a doubleclick. There is no delay as with the native vs2010 highlighter.</p>
<p>It is string-based, which means it works inside comments and string literals.</p>
| 45,961
|
<p>In C# how do you make the columns in a DataGrid AutoFit Column Width like you can in Excel? Currently my five columns are fixed width but the column headers can change so I would like the columns to autofit to the width of the column.</p>
<p>Thanks</p>
|
<p>There's a property on the DataGridView called AutoSizeColumnsMode which is an enum. The available values are:</p>
<p>AllCells</p>
<p>AllCellsExceptHeader</p>
<p>ColumnHeader</p>
<p>DisplayedCells</p>
<p>DisplayedCellsExceptHeader</p>
<p>Fill</p>
<p>None</p>
|
<p><strong>VB this is my function for add a DataGrid on your form with all fit Columns</strong></p>
<pre><code>Shared Function AddDataGrid(ByVal DG As DataGrid, ByVal This As Object, ByVal DS As System.Data.DataTable) As DataGrid
Try
DG.DataSource = DS
This.Controls.Add(DG)
Dim TblS As New DataGridTableStyle() With {.MappingName = DS.TableName}
DG.TableStyles.Clear()
DG.TableStyles.Add(TblS)
For ColIndex = 0 To DS.Columns.Count - 1
Dim maxlength As Integer = 0
Dim g As Graphics = DG.CreateGraphics()
' Take width of one blank space and add to the new width of the Column.
Dim offset As Integer = Convert.ToInt32(Math.Ceiling(g.MeasureString(" ", DG.Font).Width))
Dim i As Integer = 0
Dim intaux As Integer
Dim straux As String
Dim tot As Integer = DS.Rows.Count
For i = 0 To (tot - 1)
straux = DS.Rows(i)(ColIndex).ToString()
' Get the width of Current Field String according to the Font.
intaux = Convert.ToInt32(Math.Ceiling(g.MeasureString(straux, DG.Font).Width))
If (intaux > maxlength) Then
maxlength = intaux
End If
Next
' Assign New Width to DataGrid column.
DG.TableStyles(DS.TableName).GridColumnStyles(ColIndex).Width = maxlength + offset
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
Finally
DG.Show()
End Try
Return DG
End Function
</code></pre>
<p><strong>a example for using this function...</strong></p>
<pre><code>Private Sub AddDataGrid(ByVal Ds As DataSet)
AddDataGrid(New DataGrid With {.Dock = DockStyle.Fill}, Me, Ds.Tables(0))
End Sub
</code></pre>
| 33,517
|
<p>I'm implementing a cache in a class library that i'm using in an asp.net application. </p>
<p>I created my cache object as a singleton pattern with a static method to update the cache which is really just loading a member variable/property with a collection of data i need cached (got some locking logic ofcourse). I figured it was a nice way to go since i can just access my data by calling </p>
<pre><code>MyCacheObject.Instance.MyDataCollection
</code></pre>
<p>I'm creating a new cache object to store a pretty big amount of data partitioned by some key. What i'm saying is i'm creating a new cache but this one will not load all of the data at once, but rather store a collection for each key accessed.</p>
<pre><code>MyOtherCacheObject.Instance.MyOtherDataCollection(indexkey)
</code></pre>
<p>This time the question about garbage collection was brought up. Since i'm storing a huge amount of data, wouldn't it be a waste if it got gc'ed all of a sudden? Since it's just a singleton pattern there is nothing ensuring data will stay in cache.</p>
<p>So my question is - what is best practice for implemeting a cache to handle this situation? I really don't like a huge complex solution to this, and i know there is caching in System.Web but that seems a bit 'off' since this is just a class library, or what do you think?</p>
|
<p>In my opinion, the best solution would have the following characteristics:</p>
<ul>
<li><p>Uses the available caching services provided by the platform trying to avoid writing your own.</p>
</li>
<li><p>Does not couple your class library to System.Web, in order to have the layers coherent.</p>
</li>
<li><p>But if the class library is running inside an ASP.NET application the solution should not require to bring another caching implementation on (for example, the Enterprise Library Caching Application Block), which requires additional configuration and setup.</p>
</li>
</ul>
<p>So, I would use an IoC strategy in order to allow the class library to use different caching implementations, based on the environment it is running on.</p>
<p>Suppose you define your abstract caching contract as:</p>
<pre><code>public interface ICacheService
{
AddItem(...);
}
</code></pre>
<p>You could provide an implementation based on System.Web:</p>
<pre><code>public AspNetBasedCacheService : ICacheService
{
AddItem(...)
{
// Implementation that uses the HttpContext.Cache object
}
}
</code></pre>
<p>And then have that implementation 'published' as singleton. Note that the difference with your original approach is that the singleton is just a reference to the ASP.NET cache service based implementation, instead of the full 'cache object'.</p>
<pre><code>public class CacheServiceProvider
{
public static ICacheService Instance {get; set;}
}
</code></pre>
<p>You would have to initialize the caching implementation either by performing lazy initialization, or at application startup (in <code>Global.asax.cs</code>)</p>
<p>And every domain component would be able to use the published caching service without knowing that it is implemented based on System.Web.</p>
<pre><code>// inside your class library:
ICacheService cache = CacheServiceProvider.Instance;
cache.AddItem(...);
</code></pre>
<p>I agree that it is probably not the simplest solution, but I'm aiming for taking advantage of the ASP.NET cache implementation without sacrificing code decoupling and flexibility.</p>
<p>I hope I understood your question right.</p>
|
<p>The data wouldn't get garbage collected as long as the cache still holds a reference to it.</p>
<p>Also, don't ever use Singletons.</p>
| 18,928
|
<p>I have snippets of Html stored in a table. <em>Not entire pages, no tags or the like, just basic formatting.</em></p>
<p>I would like to be able to display that Html as text only, <em>no formatting</em>, on a given page (actually just the first 30 - 50 characters but that's the easy bit).</p>
<p>How do I place the "text" within that Html into a string as straight text?</p>
<p>So this piece of code.</p>
<pre><code><b>Hello World.</b><br/><p><i>Is there anyone out there?</i><p>
</code></pre>
<p>Becomes:</p>
<p>Hello World. Is there anyone out there?</p>
|
<p>The MIT licensed <a href="https://github.com/linezero/HtmlAgilityPack" rel="noreferrer">HtmlAgilityPack</a> has <a href="https://github.com/ceee/ReadSharp/blob/master/ReadSharp/HtmlUtilities.cs" rel="noreferrer">in one of its samples</a> a method that converts from HTML to plain text.</p>
<pre><code>var plainText = HtmlUtilities.ConvertToPlainText(string html);
</code></pre>
<p>Feed it an HTML string like</p>
<pre><code><b>hello, <i>world!</i></b>
</code></pre>
<p>And you'll get a plain text result like:</p>
<pre><code>hello world!
</code></pre>
|
<p>public static string StripTags2(string html)
{
return html.Replace("<", "<").Replace(">", ">");
}</p>
<p>By this you escape all "<" and ">" in a string. Is this what you want?</p>
| 36,467
|
<p>What would be the easiest way to move the mouse around (and possibly click) using Python on OS X? </p>
<p>This is just for rapid prototyping, it doesn't have to be elegant.</p>
|
<p>Try the code at <a href="http://web.archive.org/web/20111229234504/http://www.geekorgy.com:80/index.php/2010/06/python-mouse-click-and-move-mouse-in-apple-mac-osx-snow-leopard-10-6-x/" rel="noreferrer">this page</a>. It defines a couple of functions, <code>mousemove</code> and <code>mouseclick</code>, which hook into Apple's integration between Python and the platform's Quartz libraries.</p>
<p>This code works on 10.6, and I'm using it on 10.7. The nice thing about this code is that it generates mouse events, which some solutions don't. I use it to control BBC iPlayer by sending mouse events to known button positions in their Flash player (very brittle I know). The mouse move events, in particular, are required as otherwise the Flash player never hides the mouse cursor. Functions like <code>CGWarpMouseCursorPosition</code> will not do this.</p>
<pre><code>from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(
None,
type,
(posx,posy),
kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
# uncomment this line if you want to force the mouse
# to MOVE to the click location first (I found it was not necessary).
#mouseEvent(kCGEventMouseMoved, posx,posy);
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
</code></pre>
<p>Here is the code example from above page:</p>
<pre><code>##############################################################
# Python OSX MouseClick
# (c) 2010 Alex Assouline, GeekOrgy.com
##############################################################
import sys
try:
xclick=intsys.argv1
yclick=intsys.argv2
try:
delay=intsys.argv3
except:
delay=0
except:
print "USAGE mouseclick [int x] [int y] [optional delay in seconds]"
exit
print "mouse click at ", xclick, ",", yclick," in ", delay, "seconds"
# you only want to import the following after passing the parameters check above, because importing takes time, about 1.5s
# (why so long!, these libs must be huge : anyone have a fix for this ?? please let me know.)
import time
from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
def mouseEventtype, posx, posy:
theEvent = CGEventCreateMouseEventNone, type, posx,posy, kCGMouseButtonLeft
CGEventPostkCGHIDEventTap, theEvent
def mousemoveposx,posy:
mouseEventkCGEventMouseMoved, posx,posy;
def mouseclickposx,posy:
#mouseEvent(kCGEventMouseMoved, posx,posy); #uncomment this line if you want to force the mouse to MOVE to the click location first (i found it was not necesary).
mouseEventkCGEventLeftMouseDown, posx,posy;
mouseEventkCGEventLeftMouseUp, posx,posy;
time.sleepdelay;
mouseclickxclick, yclick;
print "done."
</code></pre>
|
<p>The easiest way? Compile <a href="http://web.archive.org/web/20100328083020/http://www.macosxhints.com/article.php?story=2008051406323031" rel="nofollow noreferrer">this</a> Cocoa app and pass it your mouse movements.</p>
<p>Here is the code:</p>
<pre><code>// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation
//
// Usage:
// ./click -x pixels -y pixels
// At the given coordinates it will click and release.
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, char **argv) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
// grabs command line arguments -x and -y
//
int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
// The data structure CGPoint represents a point in a two-dimensional
// coordinate system. Here, X and Y distance from upper left, in pixels.
//
CGPoint pt;
pt.x = x;
pt.y = y;
// https://stackoverflow.com/questions/1483567/cgpostmouseevent-replacement-on-snow-leopard
CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, pt, kCGMouseButtonLeft);
CGEventSetType(theEvent, kCGEventLeftMouseDown);
CGEventPost(kCGHIDEventTap, theEvent);
CFRelease(theEvent);
[pool release];
return 0;
}
</code></pre>
<blockquote>
<p>App called click that invokes CGPostMouseEvent from the CGRemoteOperation.h header file. It takes coordinates as command line arguments, moves the mouse to that position, then clicks and releases the mouse button.</p>
<p>Save the above code as click.m, open Terminal, and switch to the folder where you saved the source. Then compile the program by typing <code>gcc -o click click.m -framework ApplicationServices -framework Foundation</code>. Don't be intimidated by needing to compile this as there are more comments than code. It is a very short program that does one simple task. </p>
</blockquote>
<hr>
<p>Another way? Import <a href="http://developer.apple.com/cocoa/pyobjc.html" rel="nofollow noreferrer">pyobjc</a> to access some of the OSX framework and access the mouse that way. (see the code from the first example for ideas).</p>
| 35,567
|
<p>The arguments about the simplicity of solutions using XML-RPC or REST are easy to understand and hard to argue with.</p>
<p>I have often also heard arguments that the increased overhead of SOAP may significantly impact used bandwidth and possibly even latency. I would like to see the results of a test that quantifies the impact. Any one know a good source for such information?</p>
|
<p>The main impact in speed of SOAP vs. REST has not to do with wire speed, but with cachability. REST suggests using the web's semantics instead of trying to tunnel over it via XML, so RESTful web services are generally designed to correctly use cache headers, so they work well with the web's standard infrastructure like caching proxies and even local browser caches. Also, using the web's semantics means that things like ETags and automatic zip compression are well understood ways to increase efficiency.</p>
<p>..and now you say you want benchmarks. Well, with Google's help, I found <a href="http://www.learnosity.com/techblog/index.cfm/2008/3/13/CFMX--SOAP-vs-REST-benchmarks" rel="noreferrer">one guy</a> whose testing shows REST to be 4-6x faster than SOAP and another <a href="http://www.informs-sim.org/wsc09papers/133.pdf" rel="noreferrer">paper</a> that also favors REST.</p>
|
<p>I guess the main question here is how compares RPC with SOAP. </p>
<p>they both serve the same approach of communication abstraction by having stub objects you operate with and primitive/complex data types you get back without really knowing how this all is handled underneath.</p>
<p>I would always prefer (JSON-)RPC because </p>
<ul>
<li>it's lightweight</li>
<li>there are many great implementations for all programming languages out there</li>
<li>it's simple to learn/use/create</li>
<li>it's fast (especially with JSON)</li>
</ul>
<p>although there are reasons you should use SOAP, i.e. if you need naming parameters instead of relying on their correct order</p>
<p>some more details you get from this stackoverflow <a href="https://stackoverflow.com/questions/80112/whats-the-difference-between-xml-rpc-and-soap">question</a></p>
| 13,209
|
<p>I'm working on a database for a small web app at my school using <code>SQL Server 2005</code>.<br>
I see a couple of schools of thought on the issue of <code>varchar</code> vs <code>nvarchar</code>:</p>
<ol>
<li>Use <code>varchar</code> unless you deal with a lot of internationalized data, then use <code>nvarchar</code>.</li>
<li>Just use <code>nvarchar</code> for everything.</li>
</ol>
<p>I'm beginning to see the merits of view 2. I know that nvarchar does take up twice as much space, but that isn't necessarily a huge deal since this is only going to store data for a few hundred students. To me it seems like it would be easiest not to worry about it and just allow everything to use nvarchar. Or is there something I'm missing?</p>
|
<p>Always use nvarchar. </p>
<p>You may never need the double-byte characters for most applications. However, if you need to support double-byte languages and you only have single-byte support in your database schema it's really expensive to go back and modify throughout your application. </p>
<p>The cost of migrating one application from varchar to nvarchar will be much more than the little bit of extra disk space you'll use in most applications.</p>
|
<p>If you are using <code>NVARCHAR</code> just because a system stored procedure requires it, the most frequent occurrence being inexplicably <code>sp_executesql</code>, and your dynamic SQL is very long, you would be better off from performance perspective doing all string manipulations (concatenation, replacement etc.) in <code>VARCHAR</code> then converting the end result to <code>NVARCHAR</code> and feeding it into the proc parameter. So no, do not always use <code>NVARCHAR</code>!</p>
| 5,583
|
<p>For years I have been using the DEBUG compiler constant in VB.NET to write messages to the console. I've also been using System.Diagnostics.Debug.Write in similar fashion. It was always my understanding that when RELEASE was used as the build option, that all of these statements were left out by the compiler, freeing your production code of the overhead of debug statements. Recently when working with Silverlight 2 Beta 2, I noticed that Visual Studio actually attached to a RELEASE build that I was running off of a public website and displayed DEBUG statements which I assumed weren't even compiled! Now, my first inclination is to assume that that there is something wrong with my environment, but I also want to ask anyone with deep knowledge on System.Diagnostics.Debug and the DEBUG build option in general what I may be misunderstanding here.</p>
|
<p>The preferred method is to actually use the conditional attribute to wrap your debug calls, not use the compiler directives. #ifs can get tricky and can lead to weird build problems.</p>
<p>An example of using a conditional attribute is as follows (in C#, but works in VB.NET too):</p>
<pre><code>[ Conditional("Debug") ]
private void WriteDebug(string debugString)
{
// do stuff
}
</code></pre>
<p>When you compile without the DEBUG flag set, any call to WriteDebug will be removed as was assumed was happening with Debug.Write().</p>
|
<p>In my experience choosing between Debug and Release in VB.NET makes no difference. You may add custom actions to both configuration, but by default I think they are the same.</p>
<p>Using Release will certainly not remove the System.Diagnostics.Debug.Write statements.</p>
| 4,854
|
<p>As a novice, I've spent time learning a smattering of C and a fair bit of PHP. I've looked at writing desktop applications for Windows, but there seems to be a fair barrier to entry due to complexity of APIs. Is it worth learning this, or will native applications become less common in the future?</p>
<p>The way I see it, the only desktop application I ever use is a web browser and a text editor as well as the obviously the OS itself. Everything I need is online now.</p>
<p>Is learning to write non-web applications a useful skill going forwards? If so, what should I learn?</p>
|
<p>I don't think it is ever a good idea to choose one side and stick with it religiously. I think a good engineer will expose themselves to as much as they can so he can make an informed decision about which is the best tool to complete a task.</p>
<p>In other words, don't choose a platform, OS, programming language, etc. and then ignore the others. It is best to be well-rounded in your skill set.</p>
|
<p>I agree, you should learn what you want to. Once you have an understanding of Web, then learn some desktop programming to broaden your horizons a bit. You'll never know when you'll need it.</p>
<p>But, also, if you're looking at learning windows desktop development, then you should definitely look at C# and/or VB.NET. The .NET Framework is by far the easiest way to develop desktop app for Windows; much easy than C++ from what I understand (I actually didn't spend much time on C++ myself).</p>
| 13,362
|
<p>Situation: you've got a .swf embedded in an html page, and when you click on something in the .swf, it needs to popup a chromeless window. Normally this would be fairly easy - but consider Safari, which completely disables all 'window.open' functionality while its popup-blocker is enabled (it makes an exception if the function is triggered onclick, but it doesn't count clicks in flash). How can you create something which gracefully degrades (provides an alternate and roughly equivalent experience) for browsers that won't execute window.open?</p>
<p>(note: this is AS3, and Safari 3 for PC or Mac we're talking about - but more broadly, any browser that doesn't support or refuses to allow the javascript window.open function.)</p>
|
<p>If your SWF is loaded using <code>wmode='opaque'</code> or <code>wmode='transparent'</code>, then you could have the SWF output JavaScript code that would create an empty <code><div></code> that's positioned over the SWF area. That <code><div></code> could then handle the <code>onclick</code> event and create the popup window rather than the Flash code.</p>
|
<p>the div overlay was more complicated than the project deserved - check out <a href="http://code.google.com/p/popupfromflash/" rel="nofollow noreferrer">code.google.com/p/popupfromflash</a> for the code I came up with.</p>
<p>It attempts to use ExternalInterface to setup a window.open function, and if that fails (particularly in Safari) it calls back into flash and prompts it to do a navigateToURL to pop up the window normally (instead of chromlessly)</p>
| 40,323
|
<p>I have a question about asp.net compiling. I know the different ways you can compile but my question is with the default method. </p>
<p>Microsoft says that pages and code are compiled on their first use and then cached. My question is, when does that cache clear... </p>
<p>when the app pool recycles? Or, does it cache it until it's changed even through server reboots. Basically, if it compiles once and then caches it until it's changed I'm ok with it... if it recompiles with every reboot or app pool recycle I'm going to go the route of pre-compiling.</p>
|
<p>The cache is cleared upon app pool shutdown, at each app pool startup it is re-compiled and cached.</p>
|
<p>So the files are created in a temp folder but do not get cleared on shutdown. They will only be recompiled if something changes. So if you restart IIS or reboot the machine, they will not recompile. Just reload them from the temp folder.</p>
<p>Changes to any of the files of the project, or any files the project is dependant on will cause a recompile.</p>
| 21,125
|
<p>What steps do I need to take to change an IP address for Oracle 10g? I cannot connect to the database after going from a dhcp address to a static IP and a reboot.</p>
|
<p>More info please. Do you mean that you have changed the ip address of the host that the database is on and now you have to connect to it from a different macine, or are you having trouble starting the database after the ip change?</p>
<p>... and what error message do you receive?</p>
|
<p>Did you change the hostname in DNS? Can you ping the hostname from another machine?</p>
| 10,955
|
<p>Example: </p>
<pre><code>$ svn copy foo.txt bar.txt
A bar.txt
</code></pre>
<ul>
<li>When would you use this technique, and why? </li>
<li>Will this command (taken from svn's "red book") creates a copy of <code><foo.txt></code> while preserving the history of it to be shared with <code><bar.txt></code>? </li>
<li>If I'm changing <code><bar.txt></code>, what will happen to <code><foo.txt></code>? </li>
</ul>
<p>What are the equivalents to this in other modern systems (Clearcase, Accurev, Perforce)? </p>
<p>Let me emphasize the point I'm searching for:<br>
Is this kind of branching out on a file level?<br>
What happens if you use it in the same branch, i.e. create a copy of a file and than start changing that new file. all in the same branch?<br>
I understand that it is also used for tagging but what is interesting me is what to expect when performing <code><svn copy></code> on the file level.</p>
|
<p>Aside from branching/tagging, you can also use it when you split a file in two. In this case both new files will have history and you'll be able to look at the code before the split.</p>
<p>BTW: that's one of few features that SVN has, but Git doesn't (Git will try to guess origin of code after the fact, especially if you add <code>-C</code> to commands).</p>
|
<p>Branch is not a first-class citizen in Subversion, since it is "implemented" as a directory.</p>
<p>Hence, the <code>svn copy</code> allow to kind of branch of file within the same branch (directory). You can later merge back the copied file into the first. But <strong>this is ill-suited for just one file</strong>, as mentionned in <a href="http://svn.haxx.se/users/archive-2007-04/1062.shtml" rel="nofollow noreferrer">this thread</a></p>
<p>The equivalent in ClearCase would be a select rule like</p>
<pre><code>element * .../myBranchForCopy/LATEST
element /myPath/myFile /main/myBranch/LATEST -mkbranch myBranchForCopy
</code></pre>
<p>However, in this view made for branching a file, you will only see one <code>foo.txt</code> at a time (either in the <code>myBranch</code>, or if it is checked-out, in the <code>myBranchForCopy</code>). There is no real "copy", it is the same element. Any merge would be between:</p>
<ul>
<li><code>foo.txt@@/main/myBranch/myBranchForCopy/LATEST</code><br>
and</li>
<li><code>foo.txt@@/main/myBranch/LATEST</code></li>
</ul>
| 43,554
|
<p>I'm using Eclipse PHP Development Tools. What would be the easiest way to access a file or maybe create a remote project trough FTP and maybe SSH and SFTP?.</p>
|
<p>Eclipse natively supports FTP and SSH. Aptana is not necessary.</p>
<p>Native FTP and SSH support in Eclipse is in the "Remote System Explorer End-User Runtime" Plugin.</p>
<p>Install it through Eclipse itself. These instructions may vary slightly with your version of Eclipse:</p>
<ol>
<li>Go to 'Help' -> 'Install New Software' (in older Eclipses, this is called something a bit different)</li>
<li>In the 'Work with:' drop-down, select your version's plugin release site. Example: for Kepler, this is <br/> <em>Kepler - <a href="http://download.eclipse.org/releases/kepler" rel="noreferrer">http://download.eclipse.org/releases/kepler</a></em> </li>
<li>In the filter field, type 'remote'.</li>
<li>Check the box next to 'Remote System Explorer End-User Runtime'</li>
<li>Click 'Next', and accept the terms. It should now download and install.</li>
<li>After install, Eclipse may want to restart.</li>
</ol>
<p>Using it, in Eclipse:</p>
<ol>
<li>Window -> Open Perspective -> (perhaps select 'Other') -> Remote System Explorer</li>
<li>File -> New -> Other -> Remote System Explorer (folder) -> Connection (or type Connection into the filter field)</li>
<li>Choose FTP from the 'Select Remote System Type' panel.</li>
<li>Fill in your FTP host info in the next panel (username and password come later).</li>
<li>In the Remote Systems panel, right-click the hostname and click 'connect'.</li>
<li>Enter username + password and you're good!</li>
<li>Well, not exactly 'good'. The RSE system is fairly unusual, but you're connected.</li>
<li>And you're one smart cookie! You'll figure out the rest.</li>
</ol>
<p><strong>Edit:</strong> To change the default port, follow the instructions on this page: <a href="http://ikool.wordpress.com/2008/07/25/tips-to-access-ftpssh-on-different-ports-using-eclipse-rse/" rel="noreferrer">http://ikool.wordpress.com/2008/07/25/tips-to-access-ftpssh-on-different-ports-using-eclipse-rse/</a></p>
|
<p>As none of the other solutions mentioned satisfied me, I wrote a script that uses WinSCP to sync local directories in a project to a FTP(S)/SFTP/SCP Server when eclipse's autobuild feature is triggered. Obviously, this is a Windows-only solution.</p>
<p>Maybe someone finds this useful:
<a href="http://rays-blog.de/2012/05/05/94/use-winscp-to-upload-files-using-eclipses-autobuild-feature/" rel="nofollow">http://rays-blog.de/2012/05/05/94/use-winscp-to-upload-files-using-eclipses-autobuild-feature/</a></p>
| 12,131
|
<p>This is probably a simple answer but I can't find it. I have a table with a column of integers and I want to ensure that when a row is inserted that the value in this column is greater than zero. I could do this on the code side but thought it would be best to enforce it on the table.</p>
<p>Thanks!</p>
<p>I was in error with my last comment all is good now.</p>
|
<p>You can use a check constraint on the column. IIRC the syntax for this looks like:</p>
<pre><code>create table foo (
[...]
,Foobar int not null check (Foobar > 0)
[...]
)
</code></pre>
<p>As the poster below says (thanks Constantin), you should create the check constraint outside the table definition and give it a meaningful name so it is obvious which column it applies to.</p>
<pre><code>alter table foo
add constraint Foobar_NonNegative
check (Foobar > 0)
</code></pre>
<p>You can get out the text of check constraints from the system data dictionary in <code>sys.check_constraints</code>:</p>
<pre><code>select name
,description
from sys.check_constraints
where name = 'Foobar_NonNegative'
</code></pre>
|
<p>Add a <code>CHECK</code> constraint when creating your table</p>
<pre><code>CREATE TABLE Test(
[ID] [int] NOT NULL,
[MyCol] [int] NOT NULL CHECK (MyCol > 1)
)
</code></pre>
| 25,120
|
<p>Here's one from the "No question's too dumb" department:</p>
<p>Well, as the subject says: Is there an impact? If so, how much? Will all the string literals I have in my code and in my DFM resources now take up twice as much space inside the compiled binaries? What about runtime memory usage of compiled applications? Will all the string variables now take up twice as much RAM? Should I even bother?</p>
<p>I remember something like this being asked during one of the early pre-release webcasts but I can't remember the answer. And as the trial is only 14 days I'm not going to just try it myself before the third-party libraries I need have been updated (supposedly in about a month).</p>
|
<p>D2009 uses UTF-16 for the default string type, although you can make variables UTF-8 if you need to.</p>
<p>Jan Goyvaerts <a href="http://www.micro-isv.asia/2008/09/speed-benefits-of-using-the-native-win32-string-type/" rel="nofollow noreferrer">discusses the size/speed tradeoff</a> in a good blog post.</p>
<p>String literals in DFMs have been UTF-8 since at least D7. Hence, there will be no increase in size due to strings in DFMs with D2009.</p>
|
<p>I haven't used Delphi in years, but it probably depends on what Unicode encoding they use. UTF8 will be exactly the same for the regular ASCII character set (it only uses more than one byte when you get into the exotic characters). UTF16 might be a bit bloated.</p>
| 10,821
|
<p>What is the best way to use ListView and a set of GroupBoxes as an Options window?</p>
<p>For example, Listview will have items such as General, Sounds, Shortcuts and there will be three groupboxes defining those same things.</p>
<p>What would be the best programmatical way to navigate through them everytime an item in the listview is selected?</p>
<p>Hide all groupboxes, then show groupbox based by index of selected listview? Or does anyone have a better idea to handle something like this?</p>
|
<p>I may have misunderestimated your question, but perhaps a TreeView would be more appropriate for your problem? This would allow you to have top-level category nodes (like General, Sounds etc.) and then lists of items under each node.</p>
|
<p>I don't know if there's a better way, but in the past that what you described is the general approach I have taken.</p>
| 34,614
|
<p>If I create an ADO .Net Data Service, can I access it from Silverlight across domains as long as I don't use the ADO .Net Silverlight Client helpers and I have a proper crossdomain.xml file in place? (I would essentially just get the raw xml and parse it myself)</p>
<p>Asked another way, is it the ADO .Net Data Services Silverlight Client components that don't allow crossdomain calls, or is it the ADO .Net Data Service itself?</p>
<p>I assume it's the client components but would like some confirmation.</p>
|
<p>I wrote about using a Server-side proxy to make the Silverlight Client library with DataServices hosted on a different domain .
<a href="http://blogs.msdn.com/phaniraj/archive/2008/10/21/accessing-cross-domain-ado-net-data-services-from-the-silverlight-client-library.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/phaniraj/archive/2008/10/21/accessing-cross-domain-ado-net-data-services-from-the-silverlight-client-library.aspx</a></p>
|
<p>After further investigation, I found it is as I suspected, the ADO .Net Data Services <strong>Silverlight Client</strong> limits the communication to calls that are from the same domain. (Not ADO .Net Data Services itself)</p>
<p>This apparently is going to be fixed in a future version of Silverlight. </p>
| 46,055
|
<p>Let's say I am modelling a process that involves a conversation or exchnage between two actors. For this example, I'll use something easily understandable:-</p>
<ol>
<li>Supplier creates a price list,</li>
<li>Buyer chooses some items to buy and sends a Purchase Order,</li>
<li>Supplier receives the purchase order and sends the goods.</li>
<li>Supplier sends an invoice</li>
<li>Buyer receives the invoice and makes a payment</li>
</ol>
<p>Of course each of those steps in itself could be quick complicated. How would you split this up into use cases in your requirements document?</p>
<p>If this process was treated as a single use-case it could fill a book.</p>
<p>Alternatively, making a use case out of each of the above steps would hide some of the essential interaction and flow that should be captured. Would it make sense to have a use case that starts at "Received a purchase order" and finishes at "Send an Invoice" and then another that starts at "Receive an Invoice" and ends at "Makes a Payment"?</p>
<p>Any advice?</p>
|
<p>Solved the problem. I'm not sure I understand why it happened but here is the offending code;</p>
<pre><code>if (User.Identity.IsAuthenticated) {
if (User.Identity is BookingIdentity) {
BookingIdentity id = (BookingIdentity) User.Identity;
Response.Write("<p/>UserName: " + id.Name);
}
}
</code></pre>
<p>Removing the Response.Write makes everything work again.
The Response.Write (which I added to check the user was logged in at same time as the forms authentication) seems to be doing something to the page render? Any ideas?</p>
<p>Turns out that Response.Write was the problem, it essentially aborts the rendering of the rest of the page from that point. (or words to that effect)</p>
|
<p>Yes you should check the output html, and your browser.</p>
<p>If there is no style tag in your html output you could use and try:</p>
<pre><code><body bgcolor="#C3DAF9">
</code></pre>
| 19,461
|
<p>Recently I converted a Swing application to Webstart. The process was pretty straightforward, but I found that after I close all windows, my application's JVM did not terminate. The thread dump showed that there are a couple of non-daemon threads, notably Swing's EDT, AWT and a couple of websart related threads. </p>
<p>The actual strategy used is that each window increments a counter when it is created and decrements one when it is closed. The default close operation is DISPOSE_ON_CLOSE. Wen the counter reaches zero, I stop all threadpools and release all JNI resources.</p>
<p>When I launched the application from a bat file (same JARs), it terminated fine when all windows were closed, so I figured that the problem has something to do with Webstart.</p>
<p>Now the questions:</p>
<ol>
<li>Can anybody tell me what exactly is happening? Why does Webstart leave zombie JVMs? </li>
<li>Is there a way to release the Webstart resources explicitly without halting the JVM? </li>
<li>I've always had the opinion that calling System.exit() encourages the sloppy practice of not releasing your resources and relying on the OS to clean up after you (which can lead to nasty surprises if you reuse the code later)... am I missing something?</li>
</ol>
<p>See also the <a href="https://stackoverflow.com/questions/216315/what-is-the-best-way-to-detect-whether-an-application-is-launched-by-webstart">followup question</a> for detecting whether the app has been launched by Webstart.</p>
|
<p>Because of bugs in WebStart, yes. WebStart starts up a "secure thread" for it's own purposes that interacts with the EDT. This SecureThread prevents the automatic termination of the Java process one would expect when all windows and AWT resources are disposed.</p>
<p>For more information see <a href="http://www.pushing-pixels.org/?p=232" rel="nofollow noreferrer">http://www.pushing-pixels.org/?p=232</a></p>
|
<p>Webstart starts the Console window (you may be able to disable that). The console window is used to see stdout/err of the webstart process as well as rudimentary log/debug but has the side effect of created a top-level AWT/Swing window. Since the AWT/EDT only ends when the LAST window is disposed, the console window is holding up your application. You should probably call System.exit() to be 100% sure your application exits (unless you can gurantee a certain client configuration, webstart console turned off)</p>
| 26,055
|
<p>I have a Console application hosting a WCF service. I would like to be able to fire an event from a method in the WCF service and handle the event in the hosting process of the WCF service. Is this possible? How would I do this? Could I derive a custom class from ServiceHost?</p>
|
<p>You don't need to inherit from <code>ServiceHost</code>. There are other approaches to your problem.</p>
<p>You can pass an instance of the service class, instead of a type to <code>ServiceHost</code>. Thus, you can create the instance before you start the <code>ServiceHost</code>, and add your own event handlers to any events it exposes.</p>
<p>Here's some sample code:</p>
<pre><code>MyService svc = new MyService();
svc.SomeEvent += new MyEventDelegate(this.OnSomeEvent);
ServiceHost host = new ServiceHost(svc);
host.Open();
</code></pre>
<p>There are some caveats when using this approach, as described in <a href="http://msdn.microsoft.com/en-us/library/ms585487.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms585487.aspx</a></p>
<p>Or you could have a well-known singleton class, that your service instances know about and explicitly call its methods when events happen.</p>
|
<pre><code>using ...
using ...
namespace MyWCFNamespace
{
class Program {
static void Main(string[] args){
//instantiate the event receiver
Consumer c = new Consumer();
// instantiate the event source
WCFService svc = new WCFService();
svc.WCFEvent += new SomeEventHandler(c.ProcessTheRaisedEvent);
using(ServiceHost host = new ServiceHost(svc))
{
host.Open();
Console.Readline();
}
}
}
public class Consumer()
{
public void ProcessTheRaisedEvent(object sender, MyEventArgs e)
{
Console.WriteLine(e.From.toString() + "\t" + e.To.ToString());
}
}
}
namespace MyWCFNamespace
{
public delegate void SomeEventHandler(object sender,MyEventArgs e)
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class WCFService : IWCFService
{
public event SomeEventHandler WCFEvent;
public void someMethod(Message message)
{
MyEventArgs e = new MyEventArgs(message);
OnWCFEvent(e);
}
public void OnWCFEvent(MyEventArgs e)
{
SomeEventHandler handler = WCFEvent;
if(handler!=null)
{
handler(this,e);
}
}
// to do
// Implement WCFInterface methods here
}
public class MyEventArgs:EventArgs
{
private Message _message;
public MyEventArgs(Message message)
{
this._message=message;
}
}
public class Message
{
string _from;
string _to;
public string From {get{return _from;} set {_from=value;}}
public string To {get{return _to;} set {_to=value;}}
public Message(){}
public Message(string from,string to)
this._from=from;
this._to=to;
}
}
</code></pre>
<p>You can define your WCF service with <code>InstanceContextMode = InstanceContextMode.Single</code>.</p>
<pre><code>TestService svc = new TestService();
svc.SomeEvent += new MyEventHandler(receivingObject.OnSomeEvent);
ServiceHost host = new ServiceHost(svc);
host.Open();
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] // so that a single service instance is created
public class TestService : ITestService
{
public event MyEventHandler SomeEvent;
...
...
}
</code></pre>
| 16,907
|
<p>I have a website where clients pay for a service but have to out the money upfront via escrow, I'm very proficient with PHP (this is what the website is coded in) how would I go about implementing an escrow system that would work automatically?</p>
|
<p>You need to break down your design into components and think about the process.</p>
<p>Escrow works like this:</p>
<ul>
<li>Entity A deposits money into Escrow Account for Entity B.</li>
<li>Entity A and Entity B come to an agreement</li>
<li>The Escrow account is deposited to Entity B.</li>
</ul>
<p>Implementation wise, I'd track escrow deposits like any transaction, I'd also track escrow payments the same way.</p>
<p>You need to come up with a way to store "Work Orders" in a database. These would have two columns "AcceptedByA", and "AcceptedByB", as well as the amount of money.</p>
<p>The process would be:</p>
<ul>
<li>Entity A opens a workorder and pays $X into the Escrow Account</li>
<li>Entity B does whatever the workorder requires (Setting AcceptedByB to true)</li>
<li>Entity A sets "AcceptedByA" to true.</li>
<li>A transaction runs to pay EntityB from the Escrow Account.</li>
</ul>
<p>This is extremely high level, but its a rather simple idea.</p>
|
<p>There are many ways to tackle something like this. You can create a one off solution for your own platform or use marketplace payment solutions like Paypal's <a href="https://www.braintreepayments.com/" rel="nofollow noreferrer">Braintree</a>, or another platform such as <a href="https://stripe.com/" rel="nofollow noreferrer">Stripe</a>. Check those out, they give you the ability to market split payments and run an escrow. </p>
| 16,422
|
<p>I have several large csv files with thousands of columns that I need to import and then remove entire columns based contents of the column. Is there an easy way to handle this in Ruby?</p>
<p>I could transpose the data and then just delete rows but I was wondering if there was a more syntactically sugary way of doing it. </p>
|
<p>You need to iterate on rows and remove columns with <code>Array#slice!</code>.</p>
<p>Something like:</p>
<pre><code>my_array.each do |row|
row.slice!(3) if <insert condition>
end
</code></pre>
<p>should do it.</p>
|
<p>As you need to assign all the columns in the csv to the columns in the database you just need to ignore the columns you don't need in the csv. <a href="http://satishonrails.wordpress.com/2007/07/18/how-to-import-csv-file-in-rails/" rel="nofollow noreferrer">This</a> blog posting has a good example.</p>
| 48,999
|
<p>I have a project built and packaged with a specific version of jsp-apiand servlet-api jar files. Now I want these jars to be loaded when deploying the web project on any application server for example tomcat, WAS, Weblogic etc.</p>
<p>The behaviour I have seen on tomcat is that it gives messages that the packaged version of these apis are not loaded along with an offending class.</p>
<p>Is there any way I could override these server settings or behaviour?</p>
<p>My concern is that letting the default behaviour of a server may allow different behaviour on different servers or even on different versions of same app server.</p>
|
<ol>
<li>If you have control over the server where you want to install this webapp you can replace the core jars with yours. </li>
<li>Additionally you can prepend the jars in the startup of the app server. </li>
</ol>
<p><strong>Update:</strong></p>
<p>As for the second part, you'll need to modify the startup file of the application server it self. </p>
<p>I don't have an installation at hand but lets suppose in the dir $YOUR_APPSERV/bin there are a bunch of scripts ( either .cmd or .sh files ) </p>
<p>Some of them start the app server , some other help to configure it. </p>
<p>You need to modify one of those in such a way the command line look like this:</p>
<p>(assume a windows installation)</p>
<pre><code>java -Xbootclasspath/p:c:\cutomjars\myJar.jar;customjars\myOtherJar.jar ..................... // the rest of the normal command line.
</code></pre>
<p>-bootclasspath/p prepends the jars to the app classpath</p>
<p>-bootclasspath/a appends the jars to the app claspath</p>
<p>This option let you override any class in the JVM with those specified in the jars, so you can even substitute java.lang.String if you want to.</p>
<p>That's one approach. Unfortunately -Xbootclasspath is an option for Sun JVM ( that is JRockit does not have it, nor the IBM's VM what ever his name is ) </p>
<p>There was another option where you declare a folder where all the extensions are. Plus, there is an ext directory in the jre.</p>
<p>Take a deep dive into your application server bin directory and find out what each script is used for, I'm pretty sure you'll make it through.</p>
<p>Here's a more formal explanation of this topic: <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/tooldocs/findingclasses.html</a></p>
<p>I hope it helps. </p>
<p>BTW, I use to do this years ago, to substitue the CORBA package with a veeeery old version. So this works for sure.</p>
|
<p>JRockit can use -Xbootclasspath. See the <a href="http://edocs.bea.com/jrockit/jrdocs/refman/optionX.html" rel="nofollow noreferrer">command line reference</a></p>
| 42,101
|
<p>I have seen a lot of discussions going on and people asking about DataGrid for WPF and complaining about Microsoft for not having one with their WPF framework till date. We know that WPF is a great UI technology and have the Concept of ItemsControl,DataTemplate, etc,etc to make great UX. Even WPF has got a more closely matching control- ListView, which can be easily templated to give better UX than a traditional Datagrid like display. And I would say a readymade DataGrid control will kill or hide a lot of creativity and it surely will decrease the innovations in User Experience field.</p>
<p>So what is your opinion about the need of DataGrid in WPF as a Framework component? If you feel it is necessary then is it just because the world is so used to the DatGrid way of data display for many years?</p>
<p>Some other threads having the discussion about DatGrid are <a href="https://stackoverflow.com/questions/112518/what-wpf-datagrid-controls-are-worth-the-money-andor-effort#112623">here</a> and <a href="https://stackoverflow.com/questions/127647/what-is-the-best-free-datagrid-for-wpf#127740">here</a></p>
<p>Link to <a href="http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=14963" rel="nofollow noreferrer">WPF ToolKit</a> - Latest WPF DatGrid</p>
|
<p>DataGrids are excellent for displaying large amounts of tabular data bound to a backing store. </p>
<p>But what happened in the WinForms world was that people often used them for everything that required a multi-element scrolling list. Souped-up third-party DataGrids soon became available that allowed columns and fields to contain buttons and ComboBoxes and icons, etc.</p>
<p>The DataGrid became a workhorse because there was a need for something it could be coaxed into behaving like. Similar happened to DataTables before generic collections came along--and when you're using lots of DataTables, presenting it in the UI with a DataGrid is the path of least resistance.</p>
<p>I think that when WPF came out, a lot of programmers like me were still thinking in this fashion, and sought out WPF ports of the DataGrid concept. </p>
|
<p>After working with WPF for about 2 years now. I would say that a DataGrid is really just a glorified ListBox (since [almost] everything in WPF is styleless). </p>
<p>One could style a ListBox to take an Entity of some sort and show a "record" control for each entry. Depending on how flexible these are made, they could automatically adjust based on the entity passed.</p>
| 15,624
|
<p>I've worked on a number of different embedded systems. They have all used <code>typedef</code>s (or <code>#defines</code>) for types such as <code>UINT32</code>.</p>
<p>This is a good technique as it drives home the size of the type to the programmer and makes you more conscious of chances for overflow etc.</p>
<p>But on some systems you know that the compiler and processor won't change for the life of the project.</p>
<p>So what should influence your decision to create and enforce project-specific types?</p>
<p>EDIT
I think I managed to lose the gist of my question, and maybe it's really two.</p>
<p>With embedded programming you may need types of specific size for interfaces and also to cope with restricted resources such as RAM. This can't be avoided, but you can choose to use the basic types from the compiler.</p>
<p>For everything else the types have less importance.<br>
You need to be careful not to cause overflow and may need to watch out for register and stack usage. Which may lead you to <code>UINT16</code>, <code>UCHAR</code>.
Using types such as <code>UCHAR</code> can add compiler 'fluff' however. Because registers are typically larger, some compilers may add code to force the result into the type.<br>
<PRE>i++;</PRE>
can become
<PRE>ADD REG,1
AND REG, 0xFF</PRE>
which is unecessary.</p>
<p>So I think my question should have been :-</p>
<p>given the constraints of embedded software what is the best policy to set for a project which will have many people working on it - not all of whom will be of the same level of experience.</p>
|
<p>I use type abstraction very rarely. Here are my arguments, sorted in increasing order of subjectivity:</p>
<ol>
<li><p>Local variables are different from struct members and arrays in the sense that you want them to fit in a register. On a 32b/64b target, a local <code>int16_t</code> can make code slower compared to a local int since the compiler will have to add operations to /force/ overflow according to the semantics of <code>int16_t</code>. While C99 defines an <code>intfast_t</code> typedef, AFAIK a plain int will fit in a register just as well, and it sure is a shorter name.</p></li>
<li><p>Organizations which like these typedefs almost invariably end up with several of them (<code>INT32, int32_t, INT32_T</code>, ad infinitum). Organizations using built-in types are thus better off, in a way, having just one set of names. I wish people used the typedefs from stdint.h or windows.h or anything existing; and when a target doesn't have that .h file, how hard is it to add one?</p></li>
<li><p>The typedefs can theoretically aid portability, but I, for one, never gained a thing from them. Is there a useful system you can port from a 32b target to a 16b one? Is there a 16b system that isn't trivial to port to a 32b target? Moreover, if most vars are ints, you'll actually gain something from the 32 bits on the new target, but if they are <code>int16_t</code>, you won't. And the places which are hard to port tend to require manual inspection anyway; before you try a port, you don't know where they are. Now, if someone thinks it's so easy to port things if you have typedefs all over the place - when time comes to port, which happens to few systems, write a script converting all names in the code base. This should work according to the "no manual inspection required" logic, and it postpones the effort to the point in time where it actually gives benefit.</p></li>
<li><p>Now if portability may be a theoretical benefit of the typedefs, <i>readability</i> sure goes down the drain. Just look at stdint.h: <code>{int,uint}{max,fast,least}{8,16,32,64}_t</code>. Lots of types. A program has lots of variables; is it really that easy to understand which need to be <code>int_fast16_t</code> and which need to be <code>uint_least32_t</code>? How many times are we silently converting between them, making them entirely pointless? (I particularly like BOOL/Bool/eBool/boolean/bool/int conversions. Every program written by an orderly organization mandating typedefs is littered with that).</p></li>
<li><p>Of course in C++ we could make the type system more strict, by wrapping numbers in template class instantiations with overloaded operators and stuff. This means that you'll now get error messages of the form "class Number<int,Least,32> has no operator+ overload for argument of type class Number<unsigned long long,Fast,64>, candidates are..." I don't call this "readability", either. Your chances of implementing these wrapper classes correctly are microscopic, and most of the time you'll wait for the innumerable template instantiations to compile.</p></li>
</ol>
|
<p>Maybe I'm weird, but I use ub, ui, ul, sb, si, and sl for my integer types. Perhaps the "i" for 16 bits seems a bit dated, but I like the look of ui/si better than uw/sw.</p>
| 2,872
|
<p>I am currently in the process of creating my own blog and I have got to marking up the comments, but what is the best way to mark it up?</p>
<p>The information I need to present is:</p>
<ol>
<li>Persons Name</li>
<li>Gravatar Icon</li>
<li>Comment Date</li>
<li>The Comment</li>
</ol>
<p><em>PS: I'm only interested in semantic HTML markup.</em></p>
|
<p>I think that your version with the cite, blockquote, etc. would definitely work, but if semantics is your main concern then I personally wouldn't use cite and blockquote as they have specific things that they are supposed to represent.</p>
<p>The blockquote tag is meant to represent a quotation taken from another source and the cite tag is meant to represent a source of information (like a magazine, newspaper, etc.).</p>
<p>I think an argument can certainly made that you can use semantic HTML with class names, provided they are meaningful. This article on Plain Old Semantic HTML makes a reference to using class names - <a href="http://www.fooclass.com/plain_old_semantic_html" rel="nofollow noreferrer">http://www.fooclass.com/plain_old_semantic_html</a></p>
|
<p>I don't know that there's markup that would necessarily represent the comment structure well without using <em>divs</em> or classes as well, but you could use definition lists. You can use multiple <em>dt</em> and <em>dd</em> tags in the context of a definition list - see <em><a href="http://www.w3.org/TR/html401/struct/lists.html#edef-DL" rel="nofollow noreferrer">10.3 Definition lists: the DL, DT, and DD elements</a></em>.</p>
<pre><code><dl>
<dt>By [Name] at 2008-01-01<dt>
<dd><img src='...' alt=''/></dd>
<dd><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed mauris. Morbi quis tellus sit amet eros ullamcorper ultrices. Proin a tortor. Praesent et odio. Duis mi odio, consequat ut, euismod sed, commodo vitae, nulla. Suspendisse potenti. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam pede.</p>
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas rhoncus accumsan velit. Donec varius magna a est. </p>
</dd>
</dl>
</code></pre>
<p>The concern I'd have with an approach like this is that it could be difficult to uniquely identify the elements with CSS for styling purposes. You could use JavaScript (jQuery would be great here) to find and apply styles. Without full CSS selector support across browsers (<a href="https://en.wikipedia.org/wiki/Internet_Explorer" rel="nofollow noreferrer">Internet Explorer</a>), it would be tougher to style.</p>
| 2,720
|
<p>I'm trying to write a web application using SpringMVC. Normally I'd just map some made-up file extension to Spring's front controller and live happily, but this time I'm going for REST-like URLs, with no file-name extensions.</p>
<p>Mapping everything under my context path to the front controller (let's call it "<strong>app</strong>") means I should take care of static files also, something I'd rather not do (why reinvent yet another weel?), so some combination with tomcat's default servlet (let's call it "<strong>tomcat</strong>") appears to be the way to go.</p>
<p>I got the thing to work doing something like </p>
<pre class="lang-xml prettyprint-override"><code><servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tomcat</servlet-name>
<url-pattern>*.ext</url-pattern>
</servlet-mapping>
</code></pre>
<p>and repeating the latter for each one of the file extensions of my static content. I'm just wondering why the following setups, which to me are equivalent to the one above, don't work.</p>
<pre class="lang-xml prettyprint-override"><code><!-- failed attempt #1 -->
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tomcat</servlet-name>
<url-pattern>*.ext</url-pattern>
</servlet-mapping>
<!-- failed attempt #2 -->
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tomcat</servlet-name>
<url-pattern>/some-static-content-folder/*</url-pattern>
</servlet-mapping>
</code></pre>
<p>Can anyone shed some light?</p>
|
<p>I think I may know what is going on.</p>
<p>In your working web.xml you have set your servlet to be the default servlet (/ by itself is the default servlet called if there are no other matches), it will answer any request that doesn't match another mapping.</p>
<p>In Failed 1 your /* mapping does appear to be a valid path mapping. With the /* mapping in web.xml it answers all requests except other path mappings. According to the specification extension mappings are implicit mappings that are overwritten by explicit mappings. That's why the extension mapping failed. Everything was explicitly mapped to app.</p>
<p>In Failed 2, App is responsible for everything, except content that matches the static content mapping. To show what is happening in the quick test I set up. Here is an example. <code>/some-static-content-folder/</code> contains <code>test.png</code></p>
<p>Trying to access test.png I tried:</p>
<pre><code>/some-static-content-folder/test.png
</code></pre>
<p>and the file was not found. However trying</p>
<pre><code>/some-static-content-folder/some-static-content-folder/test.png
</code></pre>
<p>it comes up. So it seems that the Tomcat default servlet (6.0.16 at least) drops the servlet mapping and will try to find the file by using the remaining path. According to this post <a href="https://stackoverflow.com/questions/132052">Servlet for serving static content</a> Jetty gives the behavior you and I were expecting.</p>
<p>Is there some reason you can't do something like map a root directory for your rest calls. Something like app mapped to /rest_root/* than you are responsible for anything that goes on in the rest_root folder, but anywhere else should be handled by Tomcat, unless you make another explicit mapping. I suggest setting your rest servlet to a path mapping, because it declares the intent better. Using / or /* don't seem appropriate, since you have to map out the exceptions. Using SO as an example, my rest mappings would be something like</p>
<blockquote>
<p>/users/* for the user servlet</p>
<p>/posts/* for the posts servlet</p>
</blockquote>
<p>Mapping order</p>
<ol>
<li>Explicit (Path mappings)</li>
<li>Implicit (Extension mappings)</li>
<li>Default (/)</li>
</ol>
<p>Please correct anything that I got wrong.</p>
|
<p>I've never tried to map a servlet like this, but I <em>would</em> argue that /* does technically both start with / and end with /*, even though the same character is used for both matches.</p>
| 28,986
|
<p>We have a CGI based web report framework written in C/C++. The <em>CGI</em> client connects with proprietary code which in turn connects to database.</p>
<p>We are looking for a better Java based replacement for <em>CGI</em> due to performance, maintenance and probably security factors. </p>
<ul>
<li>Can <em>JasperReports</em> connect with the proprietary code? Or will <em>servlet</em> be enough to replace CGI client? </li>
<li>Can be <em>JasperReports</em> run on Tomcat?</li>
</ul>
<p>Any help is appreciated.</p>
|
<p>Jasper works great in Tomcat. JasperReports is not limited to using SQL as a data source - it would be pretty easy to write your own data provider that interacts with your proprietary code.</p>
<p>If the proprietary code is native, you'll have to figure out how to handle that part of it, though...</p>
|
<p>You (or anyone else with a similar question) can check out this <a href="http://gilbertadjin.wordpress.com/2009/07/01/inserting-images-from-database-into-jasper-reports/" rel="nofollow noreferrer" title="partial example">partial custom data source example</a> to get started. I've found Jasper Reports to be quite easy to set up a basic system and integrate with. The documentation is not quite complete, but the code is somewhat more understandable than BIRT. Data from Java beans, Hibernate, and POJOs is all usable...</p>
| 30,377
|
<p>The last week on the ACM ICPC Mexico competition, I missed a "return 0" on a C++ program. For this reason we got punished with 20 minutes.</p>
<p>I had read that the standard does not oblige us to write it at the end of a main function. It is implicit, isn't it? How can I prove it? </p>
<p>We were using a Fedora system with a G++ compiler. </p>
|
<p>You refer to the C++ Standard, chapter 3.6.1 paragraph 5:</p>
<blockquote>
<p>A return statement in main has the
effect of leaving the main function
(destroying any objects with automatic
storage duration) and calling
exit with the return value as the
argument. If control reaches the end
of main without encountering a return
statement, the effect is that of
executing <code>return 0;</code></p>
</blockquote>
<p>If you haven't got the Standard at hand, you can show then the paragraph in a Working Draft. Here is one for c++98, which already had this defined.</p>
<p>You can learn more <a href="http://www.kuzbass.ru:8086/docs/isocpp/basic.html#basic.start.main" rel="noreferrer">here</a>.</p>
|
<p>You could show them the line in <a href="http://www.research.att.com/~bs/3rd.html" rel="nofollow noreferrer">Bjarne Stroustrup's book</a> defining the standard where it states it: since it is the canonical standard for the language, it is not open for debate. Unfortunately I don't have a copy to look it up myself.</p>
| 34,912
|
<p>I have used C# in Visual Studio with .NET, and I have played around a little with Mono on openSUSE Linux, but I don't really understand how it works.</p>
<p>If I write an app in Windows on .NET, how does this relate to Mono? I can't just execute an a Windows .exe file on Linux without Wine, so it doesn't help me execute apps developed in Windows.</p>
<p>Is the purpose purely to have a .NET library equivalent on Linux (and others) to make cross platform development easier? For example, if I was a business and wanted to reach Linux customers, but really wanted to use .NET, then Mono should be my choice? Or is there something more that I'm missing?</p>
|
<p>This is an old question (with an already selected answer) but I do not believe the question has really been answered well.</p>
<p>First, a little background...</p>
<p><strong>How does .NET work?</strong></p>
<p>A traditional Windows .EXE file is a binary file that represents a series of machine language instructions that your computer understands and that makes calls into the Win32 API which are parts of Windows that deliver services that applications can take advantage of. The machine language used is very specific to your kind of computer and the Win32 calls make the executable very dependent on Windows. A .NET executable is not like that.</p>
<p>It is important to realize that a .NET executable (.EXE file) is not actually a native Windows application. Windows itself does not understand how to run the code in a .NET executable. Your computer does not understand it either.</p>
<p>Much like Java, a .NET application is made up of instructions in a language called CIL (Common Intermediate Language) that you can think of as the machine language for an idealized computer that does not really exist. In .NET, the software implementation of this idealized machine is called the Common Language Runtime (CLR). The equivalent in the Java world is called the Java Virtual Machine (JVM). In Java, the equivalent to CIL is called Java bytecode. CIL is sometimes called MSIL (Microsoft Intermediate Language). </p>
<p>CIL is designed to run on the CLR (an idealized machine) but is otherwise platform independent, which means that the CIL does not care what kind of computer you have or what operating system you are running.</p>
<p>Just as you need a native version of the Java JVM on each platform on which you want to run Java, you need a native version of the CLR to run .NET CIL executables. The CLR is a native Windows application just like the traditional Win32 EXE files described above. The CLR itself is specific to the Windows implementation and computer architecture on which it was designed to run.</p>
<p>It does not matter what .NET language you start with (C#, VisualBasic, F#, IronPython, IronRuby, Boo, etc.), they all get compiled down to CIL bytecode. You can easily "disassemble" a CIL program into a form of object-oriented assembly language that is easily readable by humans. You can write a program in CIL directly yourself but few people do.</p>
<p>On Windows, the CLR compiles this CIL code Just-in-Time (JIT) right when you run the executable--just before the code is actually run. This means that the CIL bytecode is converted (compiled) to actual machine code that runs natively on your computer. This part of the CLR is called the JIT compiler or often just the JIT.</p>
<p>To date, Microsoft has released four versions of the CLR: 1.0, 1.1, 2.0, and 4.0. You need to have the right version of the CLR installed on your machine if you want to run .NET executables targeting that runtime. The CLR 2.0 supports .NET 2.0, 3.0, and 3.5 applications. For other versions of .NET, the .NET version maps cleanly to the CLR version.</p>
<p>In addition to the JIT/CLR, .NET provides a host of libraries (assemblies) that make up the rest of the .NET framework and that provide a host of capabilities and services that .NET applications can call upon. The great majority of these assemblies are pure CIL code which runs on the CLR. On Windows, a some make calls into the Win32 API as well. When you install .NET, you are installing the CLR, the class libraries (framework), and a bunch of development tools. Each version of the CLR generally requires a complete set of these "framework" assemblies. Some versions of .NET (eg. 3.0 and 3.5) added additional framework assemblies without updating the CLR or the existing assemblies associated with that CLR.</p>
<p>The Portable Executable (PE) file format that a Windows .EXE file is delivered in contains a header that describes the executable and identifies the file as a .NET file or a native Win32 file. When Windows tries to run a .NET file, it sees this header and automatically invokes the CLR on your behalf. This is why .NET EXE files appear to run natively on Windows.</p>
<p><strong>Ok, so how does Mono work?</strong></p>
<p>Mono implements the CLR on Linux, Mac, and other platforms. The Mono runtime (the CLR) is a native application written mostly in the C language and compiled down to machine language code for the computer system on which is designed to run. Like on Windows, the Mono runtime is specific to the Operating System and kind of machine you are using.</p>
<p>Just like on Windows, the Mono runtime (the CLR) compiles the CIL bytecode in your .NET executable Just-in-time to native code that your computer can understand and execute. In this way, a .NET file is just as "native" to Linux as it is to Windows.</p>
<p>To port Mono to a new architecture you need to port the JIT/CLR. This is just like porting any native application to a new platform.</p>
<p>How well .NET code runs on Linux or Mac is really just a question of how well the CLR is implemented on these systems. In theory, the Mono CLR could execute .NET code on these systems much better than the MS version of .NET does on Windows. In practice, the MS implementation is generally superior (though not in all cases).</p>
<p>In addition to the CLR, Mono provides most of the rest of the libraries (assemblies) that make up the .NET framework. Just as with the Microsoft version of .NET (in fact more so) the Mono assemblies are provided as CIL bytecode. This makes it possible to take a *.dll or *.exe file from Mono and run it unmodified on Windows, Mac, or Linux as CIL is the "native" language of the CLR implementations on these systems.</p>
<p>Just like on Windows, Mono supports multiple versions of the CLR and the associated assemblies:</p>
<p>Very early versions of Mono (before 1.2?) only supported CLR 1.0 or 1.1.
Mono did not support big chunks of the 2.0 framework until it's own 2.0 version.</p>
<p>Mono versions up to version 2.4 supported both CLR 1.1 and CLR 2.0 applications.</p>
<p>Starting with Mono 2.6, CLR 4.0 was added but CLR 2.0 was still the default.</p>
<p>Starting with Mono 2.8 the CLR 4.0 became the default and the CLR 1.1 is no longer supported.</p>
<p>Mono 2.10 continues to use the CLR 4.0 as default and also to support the CLR 2.0.</p>
<p>Just like the real .NET (but in far fewer cases) there are some Mono assemblies that call into native libraries. In order to make the System.Drawing assembly work on Mono, the Mono team wrote a Linux program to simulate the GDI+ portion of the Win32 API on Linux. This library is called 'libgdiplus'. If you compile Mono from source, you will notice that you need to build this 'libgdiplus' file before you can build 'mono'. You do not need 'libgdiplus' on Windows because the GDI+ portion of the Win32 API is already part of Windows. A full port of Mono to new platforms requires this 'libgdiplus' library to be ported as well.</p>
<p>In areas where the design of the .NET library is overly influenced by the design of Windows, and a poor fit for systems like Mac or Linux, the Mono team has written extensions to the .NET framework. The Mono extensions are also just CIL bytecode and generally work just fine on .NET.</p>
<p>Unlike on Windows, Linux generally does not detect .NET executables and launch the CLR by default. The user must usually run the CLR directly by typing 'mono appname.exe' or something similar. Here 'mono' is the application that implements the CLR and 'appname.exe' is the EXE file that contains the .NET code to be executed.</p>
<p>To make things easier for users, Mono applications are often wrapped in a shell script that launches the CLR. This hides the fact that the CLR is being used just as in Windows. It is also possible to tell Linux to launch the CLR when a file using the PE file format is encountered. This is usually not done as the PE file format is also used for native Win32 Windows executables which of course the CLR (Mono) does not support.</p>
<p>There is no technical reason why a PE launcher could not be used by Linux which then launches either a system that understands native Windows code (like Wine) or the CLR (Mono) as appropriate. This has simply not been done to my knowledge.</p>
<p><strong>Back and forth</strong></p>
<p>Any .NET code that sticks to "fully managed" code, which means it does not call into non-.NET code, should work fine on Mono on all platforms. I routinely use compiled .NET assemblies from Windows (for which I do not have the code) on Linux and Mac.</p>
<p>I can also take any code that I compile on Mono and run that on .NET on Windows. I can provide a client some code I compiled with Mono and not worry if he is on 32-bit or 64-bit Windows for example. The client does need to have the right version of .NET (the right CLR) installed fo course. CLR 2.0 has been around for a very long time and you can bet almost all Windows users have it installed. The Mono compilers and other code are also just CIL executables and so they run fine on Windows if you like.</p>
<p>Mono compatibility is good enough that large chunks of actual Microsoft code, like ASP.NET MVC, can be taken (where legal to do so) from the actual MS version of .NET and run on Mac or Linux. In general, the Mono team has done a great job of implementing both the CLR and the rest of the framework (class libraries/assemblies).</p>
<p><strong>ASP.NET</strong></p>
<p>On Windows, the Internet Information Server (IIS) knows how to call into the CLR to execute .NET as part of a web application. On Linux/Mac there is an Apache module (mod_mono) that provides similar capabilities to the Apache webserver. This application is written in C and must also be ported to new architectures.</p>
<p><strong>Porting Mono</strong></p>
<p>This discussion has identified parts of Mono that are built as "native" executables and must exist on a system on which you want to run .NET applications.</p>
<ul>
<li>The CLR (including JIT compiler) - generally known as Mono</li>
<li>libgdiplus (for systems which do not natively support the GDI+ API [only Windows does])</li>
<li>mod_mono (to allow Apache to invoke the CLR for .NET web applications)</li>
</ul>
<p>These three components, with the addition of the class libraries, provide a .NET environment that looks "native" to the .NET executable files you need to run.</p>
<p>That is how Mono works.</p>
|
<p>To further Michael's response, I believe you will have to recompile on Mono for the app to run on the Mono runtime. Exceptions may exist. I've only played around with Mono just a bit, and I've always re-compiled the source. I've never tried to run a .NET app directly on Mono.</p>
<p>Also, Mono 1.9 is supposed to be fully .NET 2.0 compliant. Mono Olive and Moonlight are supposed to add .NET 3.0 (less WPF) and Silverlight functionality.</p>
| 26,660
|
<p>The question is not how to tell in a oneliner. If you're writing the code in a one-liner, <em>you know</em> you are. But how does a module, included by <code>-MMy::Module::Name</code> know that it all started from a oneliner. </p>
<p>This is mine. It's non-portable though and relies on UNIX standard commands (although, it can be made portable more or less.)</p>
<pre><code>my $process_info = `ps $$ | tail -1`;
my $is_oneliner
= $process_info =~ m/perl.*?\s+-[^\P{IsLower}e]*e[^\P{IsLower}e]*\s+/m
;
</code></pre>
<p>And if you have a snazzier regex, feel free to improve upon mine. </p>
<hr>
<p>A couple of people have asked why I would want to do this. brian correctly guessed that I wanted to change export behavior based on whether it's a script, which we can assume has had some amount of design, or whether it's a oneliner where the user is trying to do as much as possible in a single command line. </p>
<p>This sounds bad, because there's this credo that exporters should respect other packages--sometimes known as "<code>@EXPORT</code> is <em>EVIL</em>!" But it seems to me that it's a foolish consistency when applied to oneliners. After all perl itself goes out of it's way to violate the structure of its language and give you easy loops if you ask for them on the command line, I simply want to extend that idea for my operational/business domain. I even want to apply source filters (<em>gasp!</em>) if it helps. </p>
<p>But this question also suggests that I might want to be a good citizen of Perl as well, because I only to break the community guidelines in certain cases. It is quite awesome to be able to create major business-level actions just by changing the command line in a batch scheduler rather than writing a whole new module. The test cycle is much compressed. </p>
|
<p><code>$0</code> is set to <code>"-e"</code> if you're running from <code>-e</code>.</p>
|
<p>In your <code>import()</code>, the line number returned by <code>caller()</code> will be <code>0</code> if your module was loaded via <code>-M</code>. This is true <em>whenever</em> -M is used (with -e or not) but I think it is the only case where the line number is <code>0</code>.</p>
| 20,197
|
<p>I took a wsp file, and did my <strong>stsadm -o addsolution</strong> like usual. Then I went into <em>central administration->solution management</em> and it showed up just fine. Then I deployed the web part, no problems so far.</p>
<p>The problem is when I go to add it to the webpart gallery (<em>Web Part Gallery: New Web Parts</em>) usually the web part is in the list, I check the box next to it and click <strong>populate gallery</strong> but it is not showing up in the list? Could I be missing something in my manifest.xml to cause this? I just wrote and deployed another web part this <em>exact</em> same way and it went fine. Also, I wrote a dummy webpart that does nothing but print "working" and tried it with that getting the same results. </p>
<p>Any ideas?</p>
|
<p>wow... turns out that all I was missing was a 'public' declaration on my class!?!</p>
<p>I feel like an idiot. But also, I did have to manually delete it to get it recognized. Thanks everyone!</p>
|
<p>Target .NET Framework was the issue for me. I targeted .NET 3.5 and that didn't work for me. So I targeted .NET 3.0 instead, and that worked out well.</p>
| 25,556
|
<p>I see a lot of talk on here about functional languages and stuff. Why would you use one over a "traditional" language? What do they do better? What are they worse at? What's the ideal functional programming application?</p>
|
<p>Functional languages use a different paradigm than imperative and object-oriented languages. They use side-effect-free functions as a basic building block in the language. This enables lots of things and makes a lot of things more difficult (or in most cases different from what people are used to).</p>
<p>One of the biggest advantages with functional programming is that the order of execution of side-effect-free functions is not important. For example, in Erlang this is used to enable concurrency in a very transparent way.
And because functions in functional languages behave very similar to mathematical functions it's easy to translate those into functional languages. In some cases, this can make code more readable.</p>
<p>Traditionally, one of the big disadvantages of functional programming was also the lack of side effects. It's very difficult to write useful software without IO, but IO is hard to implement without side effects in functions. So most people never got more out of functional programming than calculating a single output from a single input. In modern mixed-paradigm languages like F# or Scala this is easier.</p>
<p>Lots of modern languages have elements from functional programming languages. C# 3.0 has a lot functional programming features and you can do functional programming in Python too. I think the reasons for the popularity of functional programming is mostly because of two reasons: Concurrency is getting to be a real problem in normal programming because we're getting more and more multiprocessor computers; and the languages are getting more accessible.</p>
|
<p>I don't think that functional languages will solve anything, and that this is just a hype that management is trying to sell, remember the only truth:</p>
<p>There is no silver bullet.</p>
<p>All the rest, is bullshit, also they've said that OO would solve our problems, that Web Services would solve our problems, that Xml would solve our problems, but in the end the above truth applied, and everything went down. Also, twenty years from now on, who says that we will be using binary computers at all? Why not quantic computers? No one can predict the future, at least not on this planet. (That is the second truth)</p>
| 5,710
|
<p>I had been printing with ABS and took the advice to alter the fan so I can see the filament when I am loading it into the cold end. It was tricky but doable. I am now trying with PLA and getting it to line up with the whole is a nightmare. Can the driving cog and guide wheel be moved? A couple of mm would stop the driving cog pushing the filament off line.</p>
|
<p>I was having the same issue as you and know what you are talking about and there is a file that you should print that will help you (I have printed this).</p>
<p>While the file says for the Anet A6, I think the extrude are the same on the Anet A8. It goes under the gear and bearing and guides the filament to the hole. Should work well for you.</p>
<p>Other things that you can do is straighten out the filament. That is what I do, it helps that much more. You can also cut the end at a angle to sharpen the end with a pencil sharpener, also helps find the hole. </p>
<p>So try the file, I think it will help you would. </p>
<p>File --> <a href="https://www.thingiverse.com/thing:2242903" rel="noreferrer">https://www.thingiverse.com/thing:2242903</a> </p>
|
<p>A lot of people complain on the filament insertion of the Anet A8. Personally, I have no problems at all. I cut the filament under a sharp angle and pre-bend the filament (not completely straight) and push it in the hole, it works every time without having to disassemble the extruder fan. Note that if you have the throat screwed in too much that it sticks out of the aluminum throat holder of the extruder (so not the part where the brass nozzle screws in) it is way more difficult to insert. I kept the top of the throat more or less flush with the block.</p>
<p>Other techniques to insert filament include:</p>
<ul>
<li>cutting the old filament (straight cut) and let the extruder feed while you press the new filament on top of the old filament stump, if done correctly the friction will feed the new filament right after the old,</li>
<li>print <a href="https://www.thingiverse.com/thing:2366523" rel="nofollow noreferrer">filament guides</a> for inside the extruder gear cavity,</li>
<li>removable or magnetic fan brackets.</li>
</ul>
| 810
|
<p>I'm trying to find out where a BerkeleyDB PPM is for ActivePerl 5.10. Anyone have a clue where to find this, or how to build it?</p>
<p>I had found a lead <a href="http://trouchelle.com/perl/ppmrepview.pl?l=berkeleydb&v=10" rel="nofollow noreferrer">here</a>. They claim BerkeleyDB 0.33 had built ok for Perl 5.10. They provide a link to the PPM, but not to the supporting zip file. So I got around it, manually getting <a href="http://trouchelle.com/ppm10/MSWin32-x86-multi-thread-5.10/BerkeleyDB.ppm" rel="nofollow noreferrer">the ppm</a> and <a href="http://trouchelle.com/ppm10/BerkeleyDB-0.33.zip" rel="nofollow noreferrer">the zip</a> and running ppm install on the ppm file. That didn't work because the dll provided in the zip can't be loaded.</p>
<p>It seems like the only thing to do is to get the BerkeleyDB code from Oracle, compile it for Win32 with visual studio (the provided MSI uses Cygwin tools), modify the tarball from CPAN and build the ppm myself.</p>
|
<p>The short answer: Use Sqlite.
The long answer, compile it and debug it yourself, contribute it to the community.</p>
|
<p>Doesn't DBD::DBM support BerkelyDB?</p>
| 49,098
|
<p>For a while now, I have been thinking about designing things such as small bedside tables, game/dvd/bluray racks for 3d printing. I've always thought that making them modular would be a good way to go about doing this as well.</p>
<p>Modular design would help to create an end result that is vastly larger than the print volume of my 3d printer. I might even be able to recycle models for use in other projects. However, I'm not sure of what I need to think about if I decide to go ahead with these ideas I have floating around in my head.</p>
<p>I'm assuming that certain joints (dovetail, etc), tolerances for different types of plastic due to shrinkage, and print settings (% infill, in particular) would be important to have thought about and evaluated to some extent, but I'm not sure about what else I might be missing.</p>
<p>So my question is to anyone who has designed anything to be modularly printed. Have you really had to think carefully about the engineering side of the print? Or am I simply overthinking this? Should I just design what I want and give it reasonable infill, walls and whatnot, and just go for a trial and error approach? I'm sure there is a method to this madness, but is a concrete understanding of this type of engineering absolutely paramount when it comes to this sort of stuff?</p>
<hr>
<p>EDIT: Although I've marked darth pixel's answer as accepted, I'm still going to follow JKEngineer's advise and check out that book as well since I feel as though proper engineering techniques alongside a good mentality towards how I would tackle the problem (as outlined in darth pixel's answer) would prove to yield better results in the long run.</p>
|
<p>All printers are designed with an idea of <a href="https://en.wikipedia.org/wiki/WYSIWYG" rel="nofollow">WYSIWYG</a> for sure. Depending on:</p>
<ul>
<li>printer - type/quality/settings/configuration/assembly precission</li>
<li>filament - type/quality/shrinkage</li>
<li>user skills - manual/using app proficiency</li>
<li>model complexity</li>
<li>environment conditions and so on</li>
</ul>
<p>you can get different results.</p>
<p>I venture to say users know their printers (after some time and by trials and errors) so they know how to manage dimensions to compensate all above so you will get this knowledge too.</p>
<p>Mathematical formula can describe shrinkage of the material, all other elements are very hard to describe (mathematically) in a general way.</p>
<p>Of course someone can simplify it and say: more money you spend better effects you'll get. It's sometimes true ;)</p>
<p>So all your modular things will be better and better if you will increase (what is to be increased) in above points especially "user skills".</p>
<p>Is engineering paramount? It depends of whay you gonna create. If your modular things have to lock itself, have to have threads, screws and such stuff then this is engineering. Is it the most important part of the design? Not necessarily.</p>
<p>I would say 3D printing moved engineering to next level. I'm talking about <a href="http://www.thingiverse.com/thing:258201" rel="nofollow">this</a> or <a href="http://www.thingiverse.com/thing:249341" rel="nofollow">this</a>. Is it still art or engineering? :)</p>
<p>This is my receipt:</p>
<p><em>think > imagine > design > rethink > redesign > give it a try > get back to thinking</em></p>
<p>good luck</p>
|
<p>A book you would benefit from reading is "Functional Design for 3D Printing...Designing 3D Printed things for everyday use - 2nd Edition" by Clifford Smyth. </p>
<p>It deals with FDM printing only. It deals with considerations of orientation of the parts being printed to address required strength in the 3 directions (x, y, z), tolerances, and designing parts in such a way that they can be assembled, have the strength needed, have flexibility, etc. In some instances he shows how to split a single functional part into multiple parts so that, when assembled, it actually performs as required. </p>
<p>It's available from Amazon at <a href="http://rads.stackoverflow.com/amzn/click/1511572027" rel="nofollow">Book on Amazon</a>. I received it as a present and have no commercial interest in it. </p>
<p>Here's a review: <a href="http://3dprintingforbeginners.com/book-review-functional-design-for-3d-printing/" rel="nofollow">Book Review on 3D Printing for Beginners</a></p>
| 369
|
<p>I have a large UIScrollView into which I'm placing 3-4 rather large (320x1500 pixels or so) UIImageView image tiles. I'm adding these UIImageViews to the scroll view inside of my NIB files. I have one outlet on my controller, and that is to the UIScrollView. I'm using a property (nonatomic, retain) for this, and sythesizing it.</p>
<p>My question is this: When I observe this in Memory Monitor, I can see that the memory used goes up quite a bit when the view with all these images is loaded (as expected). But when I leave the view, it and its controller are dealloc'd, but do not seem to give up anywhere near the memory they had taken up. When I cut one of these views (there are several in my app) down to just 1-3 images that were 320x460 and left everything else the same, it recaptures the memory just fine.</p>
<p>Is there some issue with using images this large? Am I doing something wrong in this code (pasted below)?</p>
<p>This is a snippet from the viewController that is causing problems.</p>
<pre><code>- (CGFloat)findHeight
{
UIImageView *imageView = nil;
NSArray *subviews = [self.scrollView subviews];
CGFloat maxYLoc = 0;
for (imageView in subviews)
{
if ([imageView isKindOfClass:[UIImageView class]])
{
CGRect frame = imageView.frame;
if ((frame.origin.y + frame.size.height) > maxYLoc) {
maxYLoc = frame.origin.y;
maxYLoc += frame.size.height;
}
}
}
return maxYLoc;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.scrollView setContentSize:CGSizeMake(320, [self findHeight])];
[self.scrollView setCanCancelContentTouches:NO];
self.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
self.scrollView.clipsToBounds = YES;
self.scrollView.scrollEnabled = YES;
self.scrollView.pagingEnabled = NO;
}
- (void)dealloc {
NSLog(@"DAY Controller Dealloc'd");
self.scrollView = nil;
[super dealloc];
}
</code></pre>
<p>UPDATE: I've noticed another weird phenomenon. If I don't use the scroll on the view, it seems to be hanging on to the memory. But if I scroll around a bunch and ensure that all of the UIImageViews became visible at one point, it will free up and regain most of the memory it lost.</p>
<p>UPDATE2: The reason I'm asking this is my app is actually crashing due to low memory. I wouldn't mind if it were just caching and using up extra memory, but it doesn't seem to ever release it - even in didReceiveMmoryWarning conditions</p>
|
<p>I've solved the mystery - and I'm pretty sure this is a bug on Apple's side.</p>
<p>As Kendall suggested (thanks!), the problem lies in how InterfaceBuilder loads images from the NIB file. When you initFromNib, all UIImageViews will init with a UIImage using the imageNamed: method of UIImage. This call uses caching for the image. Normally, this is what you want. However, with very large images and additionally ones that scroll far off of the visible area, it does not seem to be obeying memory warnings and dumping this cache. This is what I believe to be a bug on Apple's side (please comment if you agree/disagree - I'd like to submit this if others agree). As I said above, the memory used by these images does seem to be released if a user scrolls around enough to make it all visible.</p>
<p>The workaround that I've found (also Kendall's suggestion) is to leave the image name blank in the NIB file. So you lay out your UIImageView elements as normal, but don't select an image. Then in your viewDidLoad code, you go in and load an image using imageWithContentsOfFile: instead. This method does NOT cache the image, and therefore does not cause any memory issues with retaining large images.</p>
<p>Of course, imageNamed: is a lot easier to use, because it defaults to anything in the bundle, rather than having to find the path. However, you can get the path to the bundle with the following:</p>
<pre><code>NSString *fullpath = [[[NSBundle mainBundle] bundlePath];
</code></pre>
<p>Putting that all together, here's what that looks like in code:</p>
<pre><code>NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:[NSString stringWithFormat:@"/%@-%d.png", self.nibName, imageView.tag]];
UIImage *loadImage = [UIImage imageWithContentsOfFile:fullpath];
imageView.image = loadImage;
</code></pre>
<p>So adding that to my code above, the full function looks like this: </p>
<pre><code>- (CGFloat)findHeight
{
UIImageView *imageView = nil;
NSArray *subviews = [self.scrollView subviews];
CGFloat maxYLoc = 0;
for (imageView in subviews)
{
if ([imageView isKindOfClass:[UIImageView class]])
{
CGRect frame = imageView.frame;
if ((frame.origin.y + frame.size.height) > maxYLoc) {
maxYLoc = frame.origin.y;
maxYLoc += frame.size.height;
}
NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:[NSString stringWithFormat:@"/%@-%d.png", self.nibName, imageView.tag]];
NSLog(fullpath);
UIImage *loadImage = [UIImage imageWithContentsOfFile:fullpath];
imageView.image = loadImage;
}
}
return maxYLoc;
}
</code></pre>
|
<pre><code>- (void)dealloc {
NSLog(@"DAY Controller Dealloc'd");
[self.scrollView release];
[super dealloc];
}
</code></pre>
<p>give that a shot, your @property() definition is requesting it to be retained, but you weren't explicitly releasing the object</p>
| 36,846
|
<p>Does anyone know how to generate SQL scripts from a query?</p>
<p>For example, </p>
<ol>
<li>Script some tables.</li>
<li>Do custom action 1.</li>
<li>Script the views. </li>
<li>Do custom action 2.</li>
<li>Etc.</li>
</ol>
|
<p>It sounds like you want to write a cursor to execute custom SQL. This is common and easy to do. What you need to do is specify a few things to help us more completely answer your question:</p>
<ol>
<li>What type of SQL server are you using? (MSSQL, Oracle, MySQL)</li>
<li>What language are you writing in? (Java, C++, PL/SQL, TSQL)</li>
</ol>
<p>You can either write code (Java / C++) to generate SQL from a query, or possibly use a cursor to iterate over recordsets (PL/SQL / TSQL). You can use the results to give you information that can then be executed as SQL via an exec (of some kind depending on the language).</p>
|
<p>With Microsoft Sql Server, the best way to script database objects is to use <a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx" rel="nofollow noreferrer">SMO</a>. Sql Management Objects is a c# api, but you could always execute t-sql scripts from c# using a SqlClient.</p>
| 33,568
|
<p>I want to do a select in MySql that combines several columns... something like this pseudocode:</p>
<pre><code>SELECT payment1_paid AND payment2_paid AS paid_in_full
FROM denormalized_payments
WHERE payment1_type = 'check';
</code></pre>
<p><strong>Edit</strong>: payment1_paid and payment2_paid are booleans.</p>
<p>I can't use any other language for this particular problem than MySql.</p>
<p>Thanks for any help!</p>
<p><strong>Edit</strong>: Sorry to everybody who gave me suggestions for summing and concatenating, but I've voted those early answers up because they're useful anyway. And <strong>thanks</strong> to everybody for your incredibly quick answers!</p>
|
<p>Ok, for logical and you can do </p>
<pre><code>Select (payment1_paid && payment2_paid) as paid_in_full
from denormalized_payments
where payment1_type = 'check';
</code></pre>
<p>As seen <a href="http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html#operator_and" rel="noreferrer">here</a>.</p>
|
<p>If are Strings (or you want to treat like Strings the columns that you want to combine) you can use <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat" rel="nofollow noreferrer">CONCAT</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws" rel="nofollow noreferrer">CONCAT_WS</a>. Good luck!</p>
| 30,905
|
<p>So, I use Linux, and I've been trying to find the time to get into game programming. I started out with Panda3d and had some pretty decent results and got a feel for many of the concepts in game programming. Not too long after that, I decided to step it up a notch and go to something more powerful and C or C++ based.</p>
<p>I'm probably just really dumb, but I could never really figure out how to use Crystalspace correctly. If somebody has any useful resources on how to use it, I would appreciate that. But in the meantime, I was messing around with Irrlicht and I like it, but I would like to know what more knowledgable people have to say about the subject. And maybe theres another awesome option out there I don't know about.</p>
|
<p>Ogre3D</p>
<p><a href="http://www.ogre3d.org/" rel="noreferrer">http://www.ogre3d.org/</a></p>
<p>Is typically named together with crystalspace and irrlicht.</p>
<p>Ogre and Irrlicht both are said to have a cleaner design than crystalspace so I wouldn't worry to much about problems with the latter.</p>
|
<p>If you're looking for productive game development, then my best bet would be to use Unity 3D. I started off by using Irrlicht but quickly backed out because of non intuitive tools and a lot of stress on programming. Ogre seemed to be even more complex.
<br/>Unity on the other hand is rapidly gaining grounds with each release. The recent Unity 4 is packed with a ton of features.<br/> With very little game dev knowledge, I've managed to write my own flight sim engine in Unity Android. Even learned to write shaders easily.<br/>
Though advanced Unity licenses are paid, but they are well worth it. But you can always use Unity free edition to make commercial PC games. In all, game development is all about getting the hang of a game engine. Master any, and you will rule.</p>
| 18,044
|
<p>I'm generating ICalendar (.ics) files.</p>
<p>Using the UID and SEQUENCE fields I can update existing events in Google Calendar and in Windows Calendar <strong><em>BUT NOT</em></strong> in MS Outlook 2007 - it just creates a second event</p>
<p>How do I get them to work for Outlook ?</p>
<p>Thanks</p>
<p>Tom</p>
|
<p>I've continued to do some testing and have now managed to get Outlook to update and cancel events based on the .cs file.</p>
<p>Outlook in fact seems to respond to the rules defined in <a href="https://www.rfc-editor.org/rfc/rfc2446#page-19" rel="nofollow noreferrer">RFC 2446</a></p>
<p>In summary you have to specify</p>
<p><code>METHOD:REQUEST</code> and <code>ORGANIZER:xxxxxxxx</code></p>
<p>in addition to <code>UID</code>: and <code>SEQUENCE:</code></p>
<p>For a cancellation you have to specify <code>METHOD:CANCEL</code></p>
<p>Request/Update Example</p>
<pre><code>BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//SYFADIS//PORTAIL FORMATION//FR
METHOD:REQUEST
BEGIN:VEVENT
UID:TS_229377_MS_262145@syfadis.com
SEQUENCE:5
DTSTAMP:20081106T154911Z
ORGANIZER:catalog@syfadis.com
DTSTART:20081113T164907
DTEND:20081115T170000
SUMMARY:TestTraining
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
</code></pre>
<p>Cancel Example;</p>
<pre><code>BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//SYFADIS//PORTAIL FORMATION//FR
METHOD:CANCEL
BEGIN:VEVENT
UID:TS_229377_MS_262145@syfadis.com
SEQUENCE:7
DTSTAMP:20081106T154916Z
ORGANIZER:catalog@syfadis.com
DTSTART:20081113T164907
SUMMARY:TestTraining
STATUS:CANCELLED
END:VEVENT
END:VCALENDAR
</code></pre>
|
<p>I'm using Entourage, so this may not match up exactly with the behavior you're seeing, but I hope it helps.</p>
<p>Using the iCalendar from your reply, Entourage wouldn't even import the data. Using a known-good file, I got it to import, then successfully update. Comparing the two files, the only structural differences are as follows:</p>
<ul>
<li>My known-good doesn't have a <code>VERSION</code> element</li>
<li>My known-good doesn't have a <code>PRODID</code> element</li>
<li>My known-good doesn't have a <code>STATUS</code> element</li>
<li>My known-good doesn't have a <code>SEQUENCE</code> element</li>
</ul>
<p>Since Microsoft's support for open standards tends to lag, I'd suggest trying without the <code>VERSION</code> info.</p>
| 6,733
|
<p>I see the "More Action" drop-down box in gmail inbox page.
It has levels and some disabled item in the list.</p>
<p>How to do that in HTML+CSS?</p>
<p>Thank you</p>
|
<p>You can group and disable elements in an HTML <code><select></code> element without resorting to the use of JavaScript. Something like the following should work:</p>
<pre><code><select name="foo">
<optgroup label="Odds">
<option value="1">1</option>
<option value="3">3</option>
<option value="5">5</option>
</optgroup>
<optgroup label="Evens">
<option value="2">2</option>
<option value="4">4</option>
<option value="6" disabled="disabled">6</option>
</optgroup>
</select>
</code></pre>
<p>A brief inspection in Firebug shows that Google are faking their drop-down box with a whole bunch of HTML and some clever CSS. Personally, I think taking the "correct" approach and styling it to look prettier is a lot more readable than reinventing the wheel here.</p>
|
<p>You want an unordered list based popup/drop-down menu.</p>
| 42,465
|
<p><strong>NOTE: <em>XMLIgnore</em> is NOT the answer!</strong></p>
<p>OK, so following on from my question on <a href="https://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types">XML Serialization and Inherited Types</a>, I began integrating that code into my application I am working on, stupidly thinking all will go well..</p>
<p>I ran into problems with a couple of classes I have that implement <em>IEnumerable</em> and <em>ICollection<T></em></p>
<p>The problem with these is that when the XMLSerializer comes to serialize these, it views them as an external property, and instead of using the property we would like it to (i.e. the one with our <em>AbstractXmlSerializer</em> ) it comes here and falls over (due to the type mismatch), pretty much putting us back to square one. You cannot decorate these methods with the <strong>XmlIgnore</strong> attribute either, so we cannot stop it that way.</p>
<p>My current solution is to remove the interface implementation (in this current application, its no real big deal, just made the code prettier).</p>
<p><strong>Do I need to swallow my pride on this one and accept it cant be done?</strong> I know I have kinda pushed and got more out of the XmlSerializer than what was expected of it :)</p>
<hr />
<h3>Edit</h3>
<p>I should also add, I am currently working in framework 2.</p>
<hr />
<h3>Update</h3>
<p>I have accepted <a href="https://stackoverflow.com/questions/31799/preventing-xml-serialization-of-ienumerable-and-icollectiont-inherited-types#31810">lomaxx's answer</a>. In my scenario I cannot actually do this, but I do know it will work. Since their have been no other suggestions, I ended up removing the interface implementation from the code.</p>
|
<p>you can get around this problem by getting hold of the System.RunTime.Serialization dll (it's a .net 3.x assembly) and referencing it from your .net 2.0 application. This works because the .net 3.0 binaries are compiled to run on the .net 2.0 CLR.</p>
<p>By doing this, you get access to the DataContractSerliazer which I've used to get around a similar problem where I wanted to pass in a ICollection as a parameter to a webservice and the xmlserializer didn't know how to deal with it properly.</p>
<p>If you're cool with using the .net 3.x dll in your 2.x application you should be able to use the DataContractSerializer to solve this problem</p>
|
<p>If you use these attributes:</p>
<pre><code> [XmlArray("ProviderPatientLists")]
[XmlArrayItem("File")]
public ProviderPatientList Files
{
get { return _ProviderPatientLists; }
set
{
_ProviderPatientLists = value;
}
}
</code></pre>
<p>Where ProviderPatientList inherit's <code>List<PatientList></code></p>
<p>You can then have more control over the xml outputed
will create </p>
<p>
</p>
| 5,168
|
<p>How can I correctly serve WSDL of a WCF webservice located in a private LAN from behind a reverse proxy listening on public IP?</p>
<p>I have an Apache webserver configured in reverse proxy mode which listens for requests on a public IP address and serves them from the internal IIS host. WCF webservice generates WSDL using the FQDN address of the LAN host which, of course, cannot be read by an internet web service client.</p>
<p>Is there any setting that can be configured in wcf application's web.config or in IIS in order to customize the WSDL generated containing host address and put public address instead?</p>
|
<p>Add the following attribute to your service class:</p>
<pre class="lang-xml prettyprint-override"><code><ServiceBehavior(AddressFilterMode:=AddressFilterMode.Any)>
</code></pre>
<p>This allows the service to be addressed by the client as <code>https://...</code> but the service can still be hosted on <code>http://.....</code></p>
<p>See my answer on <a href="https://stackoverflow.com/a/6878145/1366033">How to specify AddressFilterMode.Any declaratively</a> for how to create an extension to allow <code>AddressFilterMode.Any </code>to be specified through configuration without requiring code attributes.</p>
<p>In the <code>web.config</code> of the service host, the endpoint element <em>must have an absolute URL</em> in the address attribute that is the public URL that will be used by the client. In the same endpoint element, set the <code>listenUri</code> attribute to the absolute URL on which the service host is listening.</p>
<p>The way I determine what the default absolute URI the host is listening on is to add a service reference in a client application which points the the physical server where the service is hosted. The web.config of the client will have an address for the service. I then copy that into the listenUri attribute in the hosts web.config.</p>
<p>In your service behavior configuration, add the element <code>serviceMetaData</code> with attribute <code>httpGetEnabled=true</code></p>
<p>So you'll have something like this:</p>
<pre class="lang-xml prettyprint-override"><code><serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<!-- ... -->
<services>
<service name="NamespaceQualifiedServiceClass" behavior="myBehavior" >
<endpoint listenUri="http://www.servicehost.com"
address="https://www.sslloadbalancer.com"
binding="someBinding"
contract="IMyServiceInterface" ... />
</service>
</services>
</code></pre>
<p>I am not sure if this works with message security or transport security. For this particular application, the credentials were passed as part of the DataContract so we had <code>basicHttpBinding</code> > <code>security</code> > <code>mode=none</code>. Since the transport is secure (to the ssl load balancer) there were no security issues.</p>
<p>It is also possible in to leave the listenUri attribute blank, however it must be present.</p>
<p>Unfortunately, there is a bug in WCF where the the base address of imported schemas in the WSDL have the listenUri base address rather than the public base address (the one configured using the address attribute of the endpoint). To work around that issue, you need to create an IWsdlExportExtension implementation which brings the imported schemas into the WSDL document directly and removes the imports.</p>
<p>An example of this is provided in this article on <a href="https://web.archive.org/web/20150315045205/http://winterdom.com/2006/10/inlinexsdinwsdlwithwcf" rel="nofollow noreferrer">Inline XSD in WSDL with WCF</a>. Additionally you can have the example class inherit from <code>BehaviorExtensionElement</code> and complete the two new methods with:</p>
<pre class="lang-vb prettyprint-override"><code>Public Overrides ReadOnly Property BehaviorType() As System.Type
Get
Return GetType(InlineXsdInWsdlBehavior)
End Get
End Property
Protected Overrides Function CreateBehavior() As Object
Return New InlineXsdInWsdlBehavior()
End Function
</code></pre>
<p>This will allow you to add an extension behavior in the .config file and add the behavior using configuration rather than having to create a service factory.</p>
<p>Under the <code>system.servicemodel</code> configuration element add:</p>
<pre class="lang-xml prettyprint-override"><code><behaviors>
<endpointBehaviors>
<behavior name="SSLLoadBalancerBehavior">
<flattenXsdImports/>
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<!--The full assembly name must be specified in the type attribute as of WCF 3.5sp1-->
<add name="flattenXsdImports" type="Org.ServiceModel.Description.FlattenXsdImportsEndpointBehavior, Org.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</code></pre>
<p>And then reference the new endpoint behavior in your endpoint configuration using the behaviorConfiguration attribute</p>
<pre class="lang-xml prettyprint-override"><code><endpoint address="" binding="basicHttpBinding" contract="WCFWsdlFlatten.IService1" behaviorConfiguration="SSLLoadBalancerBehavior">
</code></pre>
|
<p><strong>See</strong>: <a href="https://learn.microsoft.com/en-us/archive/msdn-magazine/2007/june/service-station-wcf-addressing-in-depth" rel="nofollow noreferrer">Service Station WCF Addressing In Depth</a> by Aaron Skonnard</p>
<p><del><a href="https://web.archive.org/web/20110514060231/http://msdn.microsoft.com/en-us/magazine/cc163412.aspx" rel="nofollow noreferrer">archive link</a></del></p>
| 34,649
|
<p>Can i override fetchall method in a model? I need to check sth everytime fetchAll is called. The model extends Zend_db_table_abstract</p>
|
<p>To override this method you would need to subclass the Zend_Db_Table_Abstract. Like so:</p>
<pre><code><?php
abstract class My_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
...
public function fetchAll($where, $order)
{
...
}
...
}
</code></pre>
<p>Then make sure your models extend My_Db_Table_Abstract instead. This way, you will always inherit your overridden fetchAll method.</p>
|
<p>Yes. Just define a new fetchAll() method in your model with the same construction as the Zend_db_table_abstract method (ie same input / output) then at the end of your method call the parent method:</p>
<p>parent::fetchAll($params)</p>
<p>Andrew</p>
| 22,582
|
<p>I like generics a lot and use them whereever I can. Every now and then I need to use one of my classes in another project which has to run on an old JVM (before 5.0), needs to run on JavaME (where generics are not allowed neither) or in Microsoft J# (which has VERY poor Support for generics).</p>
<p>At the moment, I remove all generics manually, which means inserting many casts as well.</p>
<p>Since generics are said to be compile-time-only, and every piece of generic code could possibly converted to non-generic code automatically, I wonder if there is any tool which can do this for me.</p>
<p>If there is no such tool, how else could I solve the problem? Should I completely stop using generics?</p>
<p>There already are answers related to <em>bytecode compability</em>. What if I need <em>source code compability</em> for some reason?</p>
|
<p>You need to use something like <a href="http://retroweaver.sourceforge.net/" rel="nofollow noreferrer">Retroweaver</a> in order to achieve this sort of thing. The other answers on this question are slightly misleading. Generics are sort-of bytecode compatible with previous versions, but not entirely (see <code>java.lang.reflect.Type</code> if you don't believe me). Also, there is an issue of the bytecode version attribute, which will prevent a class compiled against 1.5 from running on a previous version. Retroweaver works around both problems while also enabling other Java 5 features like annotations and enums.</p>
|
<p>Its bytecode compatible, it should work out of the box with an old interpreter.</p>
| 40,151
|
<p>First of all, I know how to build a Java application. But I have always been puzzled about where to put my classes. There are proponents for organizing the packages in a strictly domain oriented fashion, others separate by tier.</p>
<p>I myself have always had problems with </p>
<ul>
<li>naming, </li>
<li>placing</li>
</ul>
<p>So,</p>
<ol>
<li>Where do you put your domain specific constants (and what is the best name for such a class)?</li>
<li>Where do you put classes for stuff which is both infrastructural and domain specific (for instance I have a FileStorageStrategy class, which stores the files either in the database, or alternatively in database)?</li>
<li>Where to put Exceptions?</li>
<li>Are there any standards to which I can refer?</li>
</ol>
|
<p>I've really come to like Maven's <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html" rel="noreferrer" title="S">Standard Directory Layout</a>.</p>
<p>One of the key ideas for me is to have two source roots - one for production code and one for test code like so:</p>
<pre><code>MyProject/src/main/java/com/acme/Widget.java
MyProject/src/test/java/com/acme/WidgetTest.java
</code></pre>
<p>(here, both src/main/java and src/test/java are source roots).</p>
<p>Advantages:</p>
<ul>
<li>Your tests have package (or "default") level access to your classes under test.</li>
<li>You can easily package only your production sources into a JAR by dropping src/test/java as a source root.</li>
</ul>
<p>One rule of thumb about class placement and packages:</p>
<p>Generally speaking, well structured projects will be free of <a href="http://en.wikipedia.org/wiki/Circular_dependency" rel="noreferrer">circular dependencies</a>. Learn when they are bad (and when they are <a href="http://beust.com/weblog/archives/000208.html" rel="noreferrer">not</a>), and consider a tool like <a href="http://www.google.ca/search?q=JDepend&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a" rel="noreferrer">JDepend</a> or <a href="http://www.hello2morrow.com/products/sonargraph" rel="noreferrer">SonarJ</a> that will help you eliminate them.</p>
|
<p>One thing I've done in the past - if I'm extending a class I'll try and follow their conventions. For example, when working with the Spring Framework, I'll have my MVC Controller classes in a package called com.mydomain.myapp.web.servlet.mvc
If I'm not extending something I just go with what is simplest. com.mydomain.domain for Domain Objects (although if you have a ton of domain objects this package could get a bit unwieldy).
For domain specific constants, I actually put them as public constants in the most related class. For example, if I have a "Member" class and have a maximum member name length constant, I put it in the Member class. Some shops make a separate Constants class but I don't see the value in lumping unrelated numbers and strings into a single class. I've seen some other shops try to solve this problem by creating SEPARATE Constants classes, but that just seems like a waste of time and the result is too confusing. Using this setup, a large project with multiple developers will be duplicating constants all over the place.</p>
| 2,915
|
<p>Slashdot's RSS feed is <a href="http://rss.slashdot.org/Slashdot/slashdot" rel="nofollow noreferrer">http://rss.slashdot.org/Slashdot/slashdot</a>. If I download the XML file directly, I only get a few of the posts from today. However, if I subscribe to the feed in Google Reader, and keep scrolling down in their "infinite scroll" interface, it seems like I can get an arbitrary number of Slashdot posts from the past - maybe I can get every Slashdot post ever?</p>
<ol>
<li>How does Google Reader retrieve an unlimited number of posts from an RSS feed?</li>
<li>How can I do the same?</li>
</ol>
|
<p>Google follows one instance of the feed for all its users, so they've been tracking and storing Slashdot articles, for example, long before any new subscriber starts reading.</p>
<p>To do the same, you would have to poll the RSS feeds you want at regular intervals and store any unique articles you find locally.</p>
|
<p>I built a RSS archival service that does what you're talking about (<a href="https://app.pub.center" rel="nofollow noreferrer">https://app.pub.center</a>). All of the RSS is free to use via REST. If you want push notifications you have to switch to a paid plan.</p>
<p>PubCenter daily polls it's catalog of RSS feeds, and caches the articles. Then, you can get these articles back in a chronological order. For example:</p>
<p>Page 1 of The Atlantic <code>https://pub.center/feed/02702624d8a4c825dde21af94e9169773454e0c3/articles?limit=10&page=1</code></p>
<p>Page 2 of The Atlantic <code>https://pub.center/feed/02702624d8a4c825dde21af94e9169773454e0c3/articles?limit=10&page=2</code></p>
| 27,209
|
<p>I have a <code>TreeView</code> windows forms control with an <code>ImageList</code>, and I want some of the nodes to display images, but the others to not have images.</p>
<p>I <em>don't</em> want a blank space where the image should be. I <em>don't</em> want an image that looks like the lines that the TreeView would draw if it didn't have an ImageList. How do I get it to draw images for some items and not others, without resorting to clumsy hacks like that?</p>
|
<p>I tried this once and I don't think it is possible.</p>
<p>If you try to set both <code>ImageKey</code> and <code>ImageIndex</code> to "not set" values the control just defaults <code>ImageIndex</code> to 0. The following code:</p>
<pre><code>treeView.ImageKey = "Value";
Debug.WriteLine(treeView.ImageIndex);
treeView.ImageKey = null;
Debug.WriteLine(treeView.ImageIndex);
treeView.ImageIndex = -1;
Debug.WriteLine(treeView.ImageIndex);
</code></pre>
<p>Produces output:</p>
<pre><code>-1
0
0
</code></pre>
<p>This kind of tells you that the control developers wanted to make sure that there was always a default image. That just leaves you with the hack options I'm afraid.</p>
|
<p>Hei bro, i found a way.
Set the first image as an empty image, like this...</p>
<pre><code>TreeView treeView = new TreeView();
treeView.ImageList.Images.Add(new Bitmap(1,1));
</code></pre>
<p>So, the index 0 is an empty image.
I hope this helps</p>
| 32,731
|
<p>How do most people handle updating ASP.NET applications running in a webfarm? I am having the problem that because the app is in use and the request affitnity is not sticky, when we push the update users run into errors as the process requests the request might be handled by the wrong version of the application. How do you do this? Take the entire application offline and let the push complete or do you update live and let the chips fall where they may? Ideally we'd like to minimize down time if at all possible.</p>
<p>any thoughts/suggestions/pointers would be appreciated</p>
|
<p>Generally there is a server/client protocol defined between the 2 parties. In the company I work for the connection is maintained at all times.</p>
<p>Here is info on real time data feeds to go with your stock example</p>
<p><a href="http://www.nyxdata.com/" rel="nofollow noreferrer">NYSE</a>,<a href="http://www.nasdaqtrader.com/trader.aspx?id=dpspecs" rel="nofollow noreferrer">NASDAQ</a></p>
<p>It is common for data providers to also have FTP sites with (delayed) batched data. One that comes to mind is the <a href="http://www.weather.gov/emwin/user-intro.htm" rel="nofollow noreferrer">NWS EMWIN</a></p>
|
<p>I've done this making an attempt to retrieve the stock quote from the source, and falling back to a timestamped on-disk cache of the quote when the main source fails or times out.</p>
| 20,662
|
<p>I downloaded the Aptana_Studio_Setup_Linux.zip package, unpacked it and run ./AptanaStudio. It starts fine, but reports one problem:</p>
<p><em>The embedded browser widget for this editor cannot be created. It is either not available for your operating system or the system needs to be configured in order to support embedded browser.</em></p>
<p>After that, it opens the "Welcome page" in external browser (Mozilla), but when I click on a link to install PHP support it does not open the destination target. No wonder, because the link is in format: com.aptana....etc. I.e. written in reverse. I assume such links only work with internal browser.</p>
<p>If I look into details, I get these error messages:</p>
<pre><code>No more handles [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]
org.eclipse.swt.SWTError: No more handles [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]
at org.eclipse.swt.SWT.error(SWT.java:3400)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:138)
at org.eclipse.ui.internal.browser.BrowserViewer.<init>(BrowserViewer.java:224)
at org.eclipse.ui.internal.browser.WebBrowserEditor.createPartControl(WebBrowserEditor.java:78)
at com.aptana.ide.intro.browser.CoreBrowserEditor.createPartControl(CoreBrowserEditor.java:138)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:596)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:372)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:566)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:290)
</code></pre>
<p>etc. I hope this is enough.</p>
<p>I tried to set the env. variable:</p>
<pre><code>export MOZILLA_FIVE_HOME=/usr/lib/mozilla/
</code></pre>
<p>However, it only changes the error message to:</p>
<pre><code>No more handles [NS_InitEmbedding /usr/lib/mozilla/ error -2147221164]
org.eclipse.swt.SWTError: No more handles [NS_InitEmbedding /usr/lib/mozilla/ error -2147221164]
at org.eclipse.swt.SWT.error(SWT.java:3400)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:225)
at org.eclipse.ui.internal.browser.BrowserViewer.<init>(BrowserViewer.java:224)
at org.eclipse.ui.internal.browser.WebBrowserEditor.createPartControl(WebBrowserEditor.java:78)
at com.aptana.ide.intro.browser.CoreBrowserEditor.createPartControl(CoreBrowserEditor.java:138)
at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:596)
at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:372)
</code></pre>
<p>For start I really want to have PHP working, but I'd also like to fix the whole internal browser issue in the end.</p>
|
<p>I happened to come across this: <a href="https://groups.google.com/forum/#!msg/xmind/5SjPTy0MmEo/PbPi0OGzqPwJ">https://groups.google.com/forum/#!msg/xmind/5SjPTy0MmEo/PbPi0OGzqPwJ</a></p>
<p>Which advised running: </p>
<pre><code>sudo apt-get install libwebkitgtk-1.0-0
</code></pre>
<p>should solve the problem. It worked for me so I figured I'd share here.</p>
<p>FWIW, I ended up here while trying to get the Play! Framework working on Ubuntu 13.04. using the Scala-IDE. So far, everything seems to be working...</p>
|
<p>If this is the problem I think you're having, just installing Firefox 2 (alongside FF3) should fix the issue. It happens because Aptana can only use FF2 at the moment. Hopefully they'll fix this soon.</p>
<p>If you're on Ubuntu, it's really just a case of:</p>
<pre><code>sudo apt-get install firefox-2
</code></pre>
<p>Naturally, the process will vary on different distributions.</p>
| 26,342
|
<p>Ive recently been asked to recommend a .NET framework version to use in a (GUI based) project for an XP machine.</p>
<p>Can anyone explain the differences between all the .NET versions?</p>
<p>OR,</p>
<p>Does anyone have a good reference to a site that details (briefly) the differences?</p>
|
<p>Jon Skeet's book <em>C# In Depth</em> has one section describing versions of .NET in details. </p>
|
<p>The short answer is that it depends.</p>
<p>.NET 2.0 is the oldest version you should be considering. </p>
<p>.NET 3.0 is an easy upgrade path from 2.0, not the same amount of breaking changes as from 1.1 to 2.0. However it is more of an extension, horizontally of functionality, and you would not see a huge shift in graphical options. </p>
<p>.NET 3.5 should be looked at if you are interested in much more sophisticated gui such as sliverlight. It has a lot more new technologies and options to offer including WPF, a new IDE in Expression and much more. <a href="http://www.asp.net" rel="nofollow noreferrer">http://www.asp.net</a> would not be a bad start.</p>
| 29,430
|
<p>My server already runs IIS on TCP ports 80 and 443. I want to make a centralized "push/pull" Git repository available to all my team members over the Internet.</p>
<p>So I should use HTTP or HTTPS.</p>
<p>But I cannot use Apache because of IIS already hooking up listening sockets on ports 80 and 443! Is there any way to publish a Git repository over <em>IIS</em>? Does Git use WebDAV?</p>
<p><strong>Update.</strong> It seems that Git HTTP installation is read-only. That's sad. I intended to keep the stable branch on a build server and redeploy using a hook on push. Does anyone see a workaround besides using SVN for that branch?</p>
|
<p><strong>Bonobo Git Server</strong></p>
<p><a href="https://bonobogitserver.com/" rel="noreferrer">https://bonobogitserver.com/</a></p>
<hr>
<p><strong>GitAspx</strong> - By Jeremy Skinner</p>
<p><a href="https://github.com/JeremySkinner/git-dot-aspx/" rel="noreferrer">https://github.com/JeremySkinner/git-dot-aspx/</a></p>
<p><a href="https://github.com/JeremySkinner/git-dot-aspx/downloads" rel="noreferrer">https://github.com/JeremySkinner/git-dot-aspx/downloads</a></p>
<p><em>Install Instructions</em></p>
<p><a href="https://www.jeremyskinner.co.uk/2010/10/19/gitaspx-0-3-available/" rel="noreferrer">https://www.jeremyskinner.co.uk/2010/10/19/gitaspx-0-3-available/</a></p>
<hr>
<p><strong>Git Web</strong></p>
<p><a href="https://gitweb.codeplex.com/" rel="noreferrer">https://gitweb.codeplex.com/</a></p>
<hr>
<p><strong>WebGitNET</strong></p>
<p><a href="https://github.com/otac0n/WebGitNet" rel="noreferrer">https://github.com/otac0n/WebGitNet</a></p>
<hr>
<p><strong><em>Alternatively ...</em></strong> (non-IIS, but highly recommend, free and open-source)</p>
<p><strong>Gitea</strong> (fork of Gogs): <a href="https://gitea.io" rel="noreferrer">https://gitea.io</a></p>
<p><strong>Gogs</strong>: <a href="https://gogs.io" rel="noreferrer">https://gogs.io</a></p>
<p><strong>SCM Manager</strong> allows you to easily set up revision control endpoints for <strong>Git</strong>, <strong>Hg</strong>, and <strong>SVN</strong> under the same hosting process. HTTP/HTTPS is supported along with built-in user authentication.</p>
<p><a href="https://www.scm-manager.org" rel="noreferrer">https://www.scm-manager.org</a><br>
<a href="https://bitbucket.org/sdorra/scm-manager/" rel="noreferrer">https://bitbucket.org/sdorra/scm-manager/</a></p>
|
<p>Try this instruction that uses SCM-Manager and IIS: <a href="http://www.helicontech.com/articles/hosting-git-svn-and-hg-mercurial-repositories-on-windows-with-iis/" rel="nofollow">Hosting Git, SVN and Hg (Mercurial) repositories on Windows with IIS</a></p>
| 7,477
|
<p>Does anyone know of any good image resizing libraries that will handling resizing large images(~7573 x ~9485). Something that is fast and doesn't chew to much memory would be great. At the moment I am using IrfanView and just shell invoking it with arguments but I would like to find something that integrates into .net a bit more.</p>
<p>Thanks.</p>
|
<p><a href="http://www.imagemagick.org" rel="noreferrer">ImageMagick</a> all the way. It's a codebase with nearly every image-related operation you could possibly want to do, implemented fairly efficiently in C. This includes various types of resizing, both interpolated (bilinear, trilinear, adaptive, etc.), and not (just decimating (sampling) or replicating pixels. There are a ton of APIs (language bindings) that you can use in your applications, including <a href="http://midimick.com/magicknet/" rel="noreferrer">MagickNet</a>.</p>
<p>Also, not sure if it's at all relevant to what you're trying to do, but I thought this was a pretty darn cool SIGGRAPH paper, so here goes: ImageMagick also supports what they call "liquid rescaling", or seam carving, a technique shown in this cool demo <a href="http://www.youtube.com/watch?v=qadw0BRKeMk" rel="noreferrer">here</a>, and whose implementation and use in ImageMagick is discussed <a href="http://www.imagemagick.org/Usage/resize/#liquid-rescale" rel="noreferrer">here</a>.</p>
|
<p>I've used ImageMagick in the past - note that you would have to invoke it from command line, too. The good news is that it's a breeze to integrate into your project, and it's a very powerful utility.</p>
| 13,822
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.