input
stringlengths 51
42.3k
| output
stringlengths 18
55k
|
|---|---|
How can I view more than one version of IE on my computer? <p>Where I work we only have IE 7. I want to view IE 6 on my computer also. </p>
<p>How can I view both on the same computer? </p>
<p>I want more than just a screen shot. I want to view both versions of IE as I write code.</p>
|
<p>Microsoft makes available virtual machine images that can be used with the also free Virtual PC program for each version of IE to be used by testers. You can find these here:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en" rel="nofollow">http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en</a></p>
|
Append newline to flat-file schema in BizTalk 2006 R2 <p>I have a flat-file schema that has a header and detail records. It looks something like this:</p>
<pre><code>HDR**2401*XX0062484*22750***20081006000000*000*******
LIN**001*788-0538-001*4891-788538010*20000*EA**0000***
</code></pre>
<p>I need to append two blank lines at the end of the message. Right now, if I have multiple records I get the following output:</p>
<pre><code>HDR**2401*XX0062484*22750***20081006000000*000*******
LIN**001*788-0538-001*4891-788538010*20000*EA**0000***
HDR**2401*XX0062484*22750***20081006000000*000*******
LIN**001*788-0538-001*4891-788538010*20000*EA**0000***
</code></pre>
<p>What I want to see happen is something like this:</p>
<pre><code>HDR**2401*XX0062484*22750***20081006000000*000*******
LIN**001*788-0538-001*4891-788538010*20000*EA**0000***
HDR**2401*XX0062484*22750***20081006000000*000*******
LIN**001*788-0538-001*4891-788538010*20000*EA**0000***
</code></pre>
<p>I could build a custom pipeline component to do this, but I'm wondering if there is a simpler way of getting what I need?</p>
|
<p>You should be able to accomplish what you want by using the Delimiter properties of the flat file schema.</p>
<p>Based on your example file I created a schema with the following record structure:</p>
<pre>
<Schema>
<Root>
<HDRGroup>
<HDR>
<LIN>
</pre>
<p>If you click on the root node of your schema you should see a list of properties for this root node. One properties section has the header 'Flat File'. In this flat file section the first three properties you can set are Child Delimiter, Child Delimiter Type and Child Order.</p>
<p>This is where you configure the schema to create the blank lines (in this case CR LF but you can set different things as you need) For your example I set the following:</p>
<pre>
Child Delimiter: 0x0D 0x0A 0x0D 0x0A
Child Delimiter Type: Hexadecimal
Child Order: Infix
</pre>
<p>0x0D 0x0A is a carriage return line feed, so the above simply creates two blank lines, infixed between each child of the root node.</p>
<p>The <HDRGroup> then functions to make sure that each header and its lines is kept together. For its delimiter settings I set:</p>
<pre>
Child Delimiter: 0x0D 0x0A
Child Delimiter Type: Hexadecimal
Child Order: Postfix
</pre>
<p>The <HDR> and <LIN> records then contain the actual schema definition for your message lines, delimited with an asterisk.</p>
<p>This schema works for something that looks to me like what you have asked for - this sort of flatfile schema and how it parses a file is highly dependant of the little details, however, such as what type of line breaks there are and if there are line breaks at the end of the file. </p>
<p>The princples of using the delimiters will stand, you will likely find you need to tinker with the settings.</p>
|
WinForms: How to customize a tooltip when it is about to be shown? <p>i want to have a tooltip for each item in a treeview, and each item in a listview, and different for each subitem (i.e. column) in the listview.</p>
<p>i can determine the text i want to show (using hit testing with the current mouse position, etc):</p>
<pre><code>private void toolTip1_Popup(object sender, PopupEventArgs e)
{
if (e.AssociatedControl == listView1)
{
toolTip1.SetToolTip(listView1, "foo");
}
}
</code></pre>
<p>but any attempt to set the tooltip text causes a <a href="http://stackoverflow.com" rel="nofollow">stackoverflow</a>.</p>
<p>How can i customize the tooltip (icon, title, text) just before it appears?</p>
|
<p>You need to guard your code in the <code>Popup</code> event handler so that if you are calling <code>SetToolTip</code> from within it, you don't call <code>SetToolTip</code> again.</p>
<p>Something like:</p>
<pre><code>private bool updatingTooltip;
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
if (!this.updatingTooltip && (e.AssociatedControl == listView1))
{
this.updatingTooltip = true;
toolTip1.SetToolTip(listView1, "foo");
this.updatingTooltip = false;
}
}
</code></pre>
|
mdi app with multiple GUI threads <p>C# MDI application with separate GUI threads for each child in MDI is that possible ?</p>
<p>For example if one of the child forms is blocked by some synchronous request it freezes the entire container ( MDI Parent ) and the other windows open also become in accessible.</p>
<p>In general , is it possible to have more than one GUI thread in .net windows form app domain ?</p>
<p>In visual studio default winform application has <strong>STA</strong> ( single threaded apartment ) setup.
In theory I understand what <strong>MTA</strong> means here but what is the practical use of it.</p>
<p>In my use case the individual mdi child are developed by various teams who may not defer blocking calls in an async manner , so I am just wondering if its possible to have multiple UI threads , although its not advisable - I completely agree.</p>
<p><strong>edit #1:</strong> </p>
<blockquote>
<p>I can think of google chrome browser as an
example where individual tab is a
separate process probably with a
dedicated GUI thread ? Is something
like this possible in a dot.net app.</p>
</blockquote>
|
<p>Rather than trying to force multiple threads into the GUI layer, make the GUI layer defer all its work to a background thread. That way if some background thread becomes unresponsive the whole GUI including the MDI child that is reflecting the unresponsive background thread is responsive.</p>
|
How does GB18030 differ from Unicode? <p>How does the Chinese GB18030 code set differ from Unicode?</p>
<p>What special techniques are required for handling GB18030?</p>
<p>Are there any (open source) libraries for handling GB18030?</p>
|
<p>As per the <a href="http://en.wikipedia.org/wiki/GB_18030">Wikipedia article on GB18030</a>, "GB18030 can be be considered a Unicode Transformation Format (i.e. an encoding of all Unicode code points) that maintains compatibility with a legacy character set." That is, all Unicode characters can be encoded in GB18030, but they will be encoded with different byte sequences than would be generated with UTF-8 or UTF-16. Handling the GB18030 encoding doesn't require any more special techniques than are required for any other non-Unicode encoding.</p>
<p>The <a href="http://www.icu-project.org/">ICU project</a> is an open source library (for C or Java) that has full support for many different encodings, including GB18030. Information on converting between different encodings with ICU can be found <a href="http://icu-project.org/userguide/conversion.html">here</a>.</p>
|
What are the major drawbacks to using OpenOffice DB vs. Microsoft Access? <p>I know that Open Office Database uses a java database backend. Does anyone have any insight on how this compares to the Jet Database Engine? </p>
<p>Also is the query designer/reporting nearly as robust as MS Access?</p>
|
<p>It's odd for me to say this, because I'm not a fan of Access at all. However, I think Access is actually the nicer product here, for a number of reasons:</p>
<ul>
<li>It's been around a lot longer (maturity)</li>
<li>The core db engine is included with windows. </li>
<li>There's an easily distributable runtime if your users don't already have Access and you need to distribute an application. </li>
<li>Over the years it's had enough people try to use it for things it's not designed to do (web sites, workgroups) that they've put enough work into performance and concurrency so the two more recent incarnations (2003, 2007) are actually very robust if you're doing something it is designed to do (desktop crud app, talking to linked sql server tables, very small workgroup). (<em>I guess this is really the same as the first point</em>)</li>
</ul>
<p>On the other hand, there's nothing <em>wrong</em> with the OpenOffice DB, and it's free.</p>
|
Checking for duplicates in a complex object using Linq or Lamda expression <p>I've just started learning linq and lamda expressions, and they seem to be a good fit for finding duplicates in a complex object collection, but I'm getting a little confused and hope someone can help put me back on the path to happy coding.</p>
<p>My object is structured like list.list.uniqueCustomerIdentifier</p>
<p>I need to ensure there are no duplicate uniqueCustomerIdentifier with in the entire complex object. If there are duplicates, I need to identify which are duplicated and return a list of the duplicates.</p>
|
<ul>
<li>Unpack the hierarchy</li>
<li>Project each element to its uniqueID property</li>
<li>Group these ID's up</li>
<li>Filter the groups by groups that have more than 1 element</li>
<li>Project each group to the group's key (back to uniqueID)</li>
<li>Enumerate the query and store the result in a list.</li>
</ul>
<p><hr /></p>
<pre><code>var result =
myList
.SelectMany(x => x.InnerList)
.Select(y => y.uniqueCustomerIdentifier)
.GroupBy(id => id)
.Where(g => g.Skip(1).Any())
.Select(g => g.Key)
.ToList()
</code></pre>
|
HTML encode user input when storing or when displaying <p>Simple question that keeps bugging me.</p>
<p>Should I HTML encode user input right away and store the encoded contents in the database, or should I store the raw values and HTML encode when displaying?</p>
<p>Storing encoded data greatly reduces the risk of a developer forgetting to encode the data when it's being displayed. However, storing the encoded data will make datamining somewhat more cumbersome and it will take up a bit more space, even though that's usually a non-issue.</p>
|
<p>i'd strongly suggest encoding information on the way out. storing raw data in the database is useful if you wish to change the way it's viewed at a certain point. the flow should be something similar to:</p>
<pre><code>sanitize user input -> protect against sql injection -> db -> encode for display
</code></pre>
<p>think about a situation where you might want to display the information as an RSS feed instead. having to redo any HTML specific encoding before you re-display seems a bit silly. any development should always follow the "don't trust input" meme, whether that input is from a user or from the database.</p>
|
Saving/Organizing/Searching Outlook E-mail outside of Outlook <p>My company requires me to use Outlook for my E-mail. Outlook does virtually nothing the way I want to do it and it frustrates me greatly. (I'm not trying to start a flame war here, it must do exactly what thousands of CEO's want it to do, but I'm not a CEO.)</p>
<p>I would like to be able to automatically extract the thousands of E-mails and attachments currently in my Outlook account and save them in my own alternative storage format where I can easily search them and organize them the way I want. (I'm not requesting suggestions for the new format.)</p>
<p>Maybe some nice open source program already can do this... that would be great. Please let me know.</p>
<p>Otherwise, <b>how can I obtain the message content and the attachments without going through the huge collection manually?</b> Even if I could only get the message content and the names of the attachments, that would be sufficient. Is there documentation of the Outlook mail storage format? Is there a way to query Outlook for the data?</p>
<p>Maybe there is an alternative approach I haven't considered?</p>
<p>My preferred language to do this is C#, but I can use others if needed.</p>
|
<p><a href="http://www.dimastr.com/redemption/">Outlook Redemption</a> is the best thing currently to use that I have found. It will allow you to get into the messages and extract the attachments and the message bodies. i am using it now to do just that.</p>
<p>Here is some code I use in a class. I included the constructor and the processing function I use to save off the attachments. I cut out the code that is specific to my needs but you can get an idea of what to use here.</p>
<pre><code> private RDOSession _MailSession = new RDOSession();
private RDOFolder _IncommingInbox;
private RDOFolder _ArchiveFolder;
private string _SaveAttachmentPath;
public MailBox(string Logon_Profile, string IncommingMailPath,
string ArchiveMailPath, string SaveAttPath)
{
_MailSession.Logon(Logon_Profile, null, null, true, null, null);
_IncommingInbox = _MailSession.GetFolderFromPath(IncommingMailPath);
_ArchiveFolder = _MailSession.GetFolderFromPath(ArchiveMailPath);
_SaveAttachmentPath = SaveAttPath;
}
public void ProcessMail()
{
foreach (RDOMail msg in _IncommingInbox.Items)
{
foreach (RDOAttachment attachment in msg.Attachments)
{
attachment.SaveAsFile(_SaveAttachmentPath + attachment.FileName);
}
}
if (msg.Body != null)
{
ProcessBody(msg.Body);
}
}
}
</code></pre>
<p><strong>edit:</strong>
This is how I call it and what is passed</p>
<pre><code>MailBox pwaMail = new MailBox("Self Email User", @"\\Mailbox - Someone\Inbox",
@"\\EMail - Incomming\Backup", @"\\SomePath");
</code></pre>
|
How to detect the current sharepoint pages from the client machine? <p>On the client machine I need to be able to somehow detect which sites the current user are looking at right now.
I know the base URL of the sharepoint app, say sharepoint.thecompany.net but how the hack do I get the last requested url from the server?
I have hit a dead stop when trying to iterate the current processes and the casting the iexplorer process to something I can work with, I just don't know which kind of object to cast the process to :-(</p>
<p>I hope to implement this logic in a C# assembly what should run on the client box.</p>
<p>Any other approach that might work?</p>
<p>Thanks in advance</p>
|
<p><a href="http://watin.sourceforge.net/" rel="nofollow">WatiN</a> will allow you to attach to IE instances and get the current url from them. It will also allow you to do the same with Firefox instances.</p>
<p>It might be more efficient however to try to get requested urls at the network level using a wireshark type concept where you are just listening to http traffic on the computer and keeping track of the urls but a solution like that is a bit over my head.</p>
<p>EDIT: I came across this while looking for a solution: <a href="http://www.codeproject.com/KB/IP/networkmonitor.aspx" rel="nofollow">http://www.codeproject.com/KB/IP/networkmonitor.aspx</a>
From what I can see I would think you could adapt the monitoring code to monitor and look for http request packets and parse the headers for the url information you need.</p>
|
Java generics - returning subtype of declared type from method <p>My class is implementing a super-class method which which returns <code>List<JComponent></code>. The list being returned is read-only:</p>
<pre><code>public abstract class SuperClass {
public abstract List<JComponent> getComponents();
}
</code></pre>
<p>In my class, I want to return a field which is declared as List - i.e. a sub-list:</p>
<pre><code>public class SubClass extends SuperClass {
private List<JButton> buttons;
public List<JComponent> getComponents() {
return buttons;
}
}
</code></pre>
<p>This generates a compiler error, as <code>List<JButton></code> is not a subtype of <code>List<JComponent></code>.</p>
<p>I can understand why it doesn't compile, as it shouldn't be allowed to add a JTextField to a List of JButtons.</p>
<p>However, as the list is read-only, then "conceptually" this should be allowed. But, of course, the compiler doesn't know that it is read-only.</p>
<p>Is there any way to achieve what I want to achieve, without changing the method declaration in the super-class, and the field declaration in the sub-class?</p>
<p>Thanks,
Calum</p>
|
<p>Declare <code>getComponents()</code> as:</p>
<pre><code>public List<? extends JComponent> getComponents()
</code></pre>
|
C# - Optimising binary serialization for multi-dimensional generic arrays <p>I have a class that I need to binary serialize. The class contains one field as below:</p>
<pre><code>private T[,] m_data;
</code></pre>
<p>These multi-dimensional arrays can be fairly large (hundreds of thousands of elements) and of any primitive type. When I tried standard .net serialization on an object the file written to disk was large and I think .net is storing a lot of repeated data about element types and possibly not as efficiently as could be done.</p>
<p>I have looked around for custom serializers but have not seen any that deal with multi-dimensional generic arrays. I have also experimented with built-in .net compression on a byte array of the memory stream following serializing with some success, but not as quick / compressed as I had hoped.</p>
<p>My question is, should I try and write a custom serializer to optimally serialize this array for the appropriate type (this seems a little daunting), or should I use standard .net serialization and add compression?</p>
<p>Any advice on the best approach would be most appreciated, or links to resources showing how to tackle serialization of a multi-dimensional generic array - as mentioned <a href="http://www.codeproject.com/KB/dotnet/FastSerializer.aspx">existing examples</a> I have found do not support such structures.</p>
|
<p>Here's what I came up with. The code below makes an int[1000][10000] and writes it out using the BinaryFormatter to 2 files - one zipped and one not. </p>
<p>The zipped file is 1.19 MB (1,255,339 bytes)
Unzipped is 38.2 MB (40,150,034 bytes)</p>
<pre><code> int width = 1000;
int height = 10000;
List<int[]> list = new List<int[]>();
for (int i = 0; i < height; i++)
{
list.Add(Enumerable.Range(0, width).ToArray());
}
int[][] bazillionInts = list.ToArray();
using (FileStream fsZ = new FileStream("c:\\temp_zipped.txt", FileMode.Create))
using (FileStream fs = new FileStream("c:\\temp_notZipped.txt", FileMode.Create))
using (GZipStream gz = new GZipStream(fsZ, CompressionMode.Compress))
{
BinaryFormatter f = new BinaryFormatter();
f.Serialize(gz, bazillionInts);
f.Serialize(fs, bazillionInts);
}
</code></pre>
<p>I can't think of a better/easy way to do this. The zipped version is pretty damn tight.</p>
<p>I'd go with the BinaryFormatter + GZipStream. Making something custom would not be fun at all.</p>
<p><hr /></p>
<p>[edit by MG]
I hope you won't be offended by an edit, but the uniform repeated Range(0,width) is skewing things vastly; change to:</p>
<pre><code> int width = 1000;
int height = 10000;
Random rand = new Random(123456);
int[,] bazillionInts = new int[width, height];
for(int i = 0 ; i < width;i++)
for (int j = 0; j < height; j++)
{
bazillionInts[i, j] = rand.Next(50000);
}
</code></pre>
<p>And try it; you'll see <code>temp_notZipped.txt</code> at 40MB, <code>temp_zipped.txt</code> at 62MB. Not so appealing...</p>
|
How do .NET sites hide .aspx extension of their files? <p>I'm pretty sure stackoverflow.com is created with ASP.NET, but no matter where I click I see no .aspx extension in the address bar.
How it is done and is there a particular reason for this?</p>
|
<p>In the case of stackoverflow, they use ASP.NET MVC rather than ASP.NET web forms. With web forms, the url is pointing to a file on your disk, while MVC is pointing to a controller action. If you're using webforms, you'd want to use URL rewriting. Scott Guthrie has a <a href="http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx">good article</a> on doing URL rewriting.</p>
|
How can I relax PHP's open_basedir restriction? <p><a href="http://www.php.net/features.safe-mode">open_basedir</a> limits the files that can be opened by PHP within a directory-tree.</p>
<p>I am storing several class libraries and configuration files outside of my web root directory. This way the web server does not make them publicly accessible. However when I try to include them from my application I get an open_basedir restriction error like this:</p>
<blockquote>
<p>Warning: realpath()
[function.realpath]: open_basedir
restriction in effect.
File(/var/www/vhosts/domain.tld/zend/application)
is not within the allowed path(s):
(/var/www/vhosts/domain.tld/httpdocs:/tmp)
in
/var/www/vhosts/domain.tld/httpdocs/index.php
on line 5</p>
</blockquote>
<p>My web root is here:</p>
<pre><code>/var/www/vhosts/domain.tld/httpdocs
</code></pre>
<p>My libraries and configuration directory are here:</p>
<pre><code>/var/www/vhosts/domain.tld/zend
</code></pre>
<p>What would be the best workaround to relax the open_basedir restriction so that the the directory tree under the domain folder becomes available to my application? I have a number of domains that I want to do this with, and I'm also obviously wary of creating security vulnerabilities.</p>
<p>Note: I am using CentOS, Apache, Plesk, and I have root ssh access to the server. And though this doesn't apply to Zend Framework directly, I am using it in this instance. So here is the inclusion from Zend's bootstrap:</p>
<pre><code>define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend/application/'));
set_include_path(APPLICATION_PATH . '/../zend/library' . PATH_SEPARATOR . get_include_path());
</code></pre>
|
<p>You can also do this easily on a per-directory basis using the Apache (assuming this is your web server) configuration file (e.g. httpd.conf)</p>
<pre><code><Directory /var/www/vhosts/domain.tld/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/domain.tld/httpdocs:/var/www/vhosts/domain.tld/zend"
</Directory>
</code></pre>
<p>you can also completely remove the restriction with</p>
<pre><code><Directory /var/www/vhosts/domain.tld/httpdocs>
php_admin_value open_basedir none
</Directory>
</code></pre>
|
How much JavaScript do you let Rails generate? <p>Ruby on Rails has a lot of ways to generate JavaScript. Particularly when it comes to Ajax. Unfortunately, there are a few problems that I often see with the JavaScript that it generates. </p>
<ul>
<li><p>Rails typically uses inline event handling.</p>
<pre><code><a onclick="somejavascript(); return false;" />
</code></pre>
<p>This is generally frowned upon, as it's mixing behavior in with the XHTML. </p></li>
<li><p>The generated JavaScript also relies heavily on Prototype. Personally, I prefer jQuery. </p></li>
<li><p>In my experience, the attitude with a lot of Rails developers has been to write as much of the code in Ruby as possible. The final step being to generate some very procedural and repetitive JavaScript. Often, this code ends up being very inflexible and difficult to debug.</p></li>
</ul>
<p>So, my question is: how much JavaScript do you write manually for your projects and how much of it is generated server side with Rails/Ruby? Or is there a happy medium where you get the benefits of both? With a subquestion: if you write a lot of the JavaScript manually, what techniques do you use to fit it into the MVC model?</p>
|
<p>If you prefer jQuery you can use the <a href="http://ennerchi.com/projects/jrails" rel="nofollow">jQuery on Rails Project</a>. A drop in to replace Prototype with jQuery.</p>
<p>Some of what Rails does with Javascript generation is good and some is bad. In the bad instances, write it yourself and keep it unobtrusive. At any given time you're uncomfortable with the Javascript Rails generates, you can go ahead and write it yourself. </p>
<p>And be sure to check out this great intro to <a href="http://www.railsenvy.com/2008/1/3/unobtrusive-javascript" rel="nofollow">unobtrusive Javascript</a> that was done with Rails in mind.</p>
|
Inline Disabling of Firefox Spellcheck? <p>I researched this a while ago and can't remember how to do it. I want to be able to prevent Firefox from running it's spell-checking functionality on certain input fields from within the page. I know it's possible but can't remember how to set it up.</p>
|
<p>Talk about having a big "duh" moment! I found the answer after some trial & error:</p>
<pre><code><textarea spellcheck="false"></textarea>
</code></pre>
|
How do I perform query filtering in django templates <p>I need to perform a filtered query from within a django template, to get a set of objects equivalent to python code within a view:</p>
<pre><code>queryset = Modelclass.objects.filter(somekey=foo)
</code></pre>
<p>In my template I would like to do</p>
<pre><code>{% for object in data.somekey_set.FILTER %}
</code></pre>
<p>but I just can't seem to find out how to write FILTER.</p>
|
<p>You can't do this, which is by design. The Django framework authors intended a strict separation of presentation code from data logic. Filtering models is data logic, and outputting HTML is presentation logic.</p>
<p>So you have several options. The easiest is to do the filtering, then pass the result to <code>render_to_response</code>. Or you could write a method in your model so that you can say <code>{% for object in data.filtered_set %}</code>. Finally, you could write your own template tag, although in this specific case I would advise against that.</p>
|
How do I calculate the previous business day in ksh shell script? <p>What is the most elegant way to calculate the previous business day in shell ksh script ?</p>
<p>What I got until now is :</p>
<pre><code>#!/bin/ksh
set -x
DAY_DIFF=1
case `date '+%a'` in
"Sun")
DAY_DIFF=2
;;
"Mon")
DAY_DIFF=3
;;
esac
PREV_DT=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-${DAY_DIFF}*24*60*60);printf "%4d%02d%02d",$year+1900,$mon+1,$mday;'`
echo $PREV_DT
</code></pre>
<p>How do I make the ${DAY_DIFF} variable to be transmitted as value and not as string ?</p>
|
<p>Here is a solution that doesn't use Perl. It works both with <code>ksh</code> and <code>sh</code>.</p>
<pre><code>#!/bin/ksh
diff=-1
[ `date +%u` == 1 ] && diff=-3
seconds=$((`date +%s` + $diff * 24 * 3600))
format=+%Y-%m-%d
if date --help 2>/dev/null | grep -q -- -d ; then
# GNU date (e.g., Linux)
date -d "1970-01-01 00:00 UTC + $seconds seconds" $format
else
# For BSD date (e.g., Mac OS X)
date -r $seconds $format
fi
</code></pre>
|
local variables in constructors are not followed. Is this a bug in gdb ? <p>I am currently running gdb version 6.7.1 on Ubuntu Linux, and working in a C++ project.</p>
<p>Surprisingly I was trying to debug a constructor and I have found that local variables declared within the scope of the constructor are not followed or noticed by gdb. Is this a bug ?</p>
<p>Thanks for any information ..</p>
|
<p>It is a <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27574">bug</a> in GCC, not in GDB.</p>
<p>It was recently <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27574#c21">fixed</a>.</p>
|
QuickBooks Item Query help needed <p>I'm sure this is going to be a long shot, but I need help with a query involving QuickBooks Items.</p>
<p>I need to query for all QuickBooks Items that are linked to an Income account. Is there an easy way to do this, or do I need to make 2 queries (one for items ans one for accounts) and then check the account reference?</p>
<p>albeit not much, I have this:</p>
<pre>
<code>
IItemQuery query = MsgSetRequest.AppendItemQueryRq();
</code>
</pre>
<p>any ideas would be appreciated. Thanks.</p>
|
<p>You need to use at least two queries. You'll need to fetch a list of accounts, and then compare the items AccountRef FullName to the income accounts in the list. </p>
|
SQL: How do I SELECT only the rows with a unique value on certain column? <p>Thanks a million everyone for everyone's response. Unfortunately, none of the solutions appear to be working on my end, and my guess is that the example I've provided is messed up.</p>
<p>So let me try again.</p>
<p>My table looks like this:</p>
<pre><code> contract project activity
row1 1000 8000 10
row2 1000 8000 20
row3 1000 8001 10
row4 2000 9000 49
row5 2000 9001 49
row6 3000 9000 79
row7 3000 9000 78
</code></pre>
<p>Basically, the query I'm looking for would return "2000,49" for "contract, activity" because only contract #2000 has one, and ONLY one, unique activity value.</p>
<p>Again, thanks a million in advance,
boroatel</p>
|
<p><strong>Updated to use your newly provided data:</strong></p>
<p>The solutions using the original data may be found at the end of this answer.</p>
<p>Using your new data:</p>
<pre><code>DECLARE @T TABLE( [contract] INT, project INT, activity INT )
INSERT INTO @T VALUES( 1000, 8000, 10 )
INSERT INTO @T VALUES( 1000, 8000, 20 )
INSERT INTO @T VALUES( 1000, 8001, 10 )
INSERT INTO @T VALUES( 2000, 9000, 49 )
INSERT INTO @T VALUES( 2000, 9001, 49 )
INSERT INTO @T VALUES( 3000, 9000, 79 )
INSERT INTO @T VALUES( 3000, 9000, 78 )
SELECT DISTINCT [contract], activity FROM @T AS A WHERE
(SELECT COUNT( DISTINCT activity )
FROM @T AS B WHERE B.[contract] = A.[contract]) = 1
</code></pre>
<p>returns:
2000, 49</p>
<p><strong>Solutions using original data</strong></p>
<p><strong>WARNING:</strong>
The following solutions use the data previously given in the question and may not make sense for the current question. I have left them attached for completeness only.</p>
<pre><code>SELECT Col1, Count( col1 ) AS count FROM table
GROUP BY col1
HAVING count > 1
</code></pre>
<p>This should get you a list of all the values in col1 that are not distinct. You can place this in a table var or temp table and join against it.</p>
<p>Here is an example using a sub-query:</p>
<pre><code>DECLARE @t TABLE( col1 VARCHAR(1), col2 VARCHAR(1), col3 VARCHAR(1) )
INSERT INTO @t VALUES( 'A', 'B', 'C' );
INSERT INTO @t VALUES( 'D', 'E', 'F' );
INSERT INTO @t VALUES( 'A', 'J', 'K' );
INSERT INTO @t VALUES( 'G', 'H', 'H' );
SELECT * FROM @t
SELECT col1, col2 FROM @t WHERE col1 NOT IN
(SELECT col1 FROM @t AS t GROUP BY col1 HAVING COUNT( col1 ) > 1)
</code></pre>
<p>This returns:</p>
<pre><code>D E
G H
</code></pre>
<p>And another method that users a temp table and join:</p>
<pre><code>DECLARE @t TABLE( col1 VARCHAR(1), col2 VARCHAR(1), col3 VARCHAR(1) )
INSERT INTO @t VALUES( 'A', 'B', 'C' );
INSERT INTO @t VALUES( 'D', 'E', 'F' );
INSERT INTO @t VALUES( 'A', 'J', 'K' );
INSERT INTO @t VALUES( 'G', 'H', 'H' );
SELECT * FROM @t
DROP TABLE #temp_table
SELECT col1 INTO #temp_table
FROM @t AS t GROUP BY col1 HAVING COUNT( col1 ) = 1
SELECT t.col1, t.col2 FROM @t AS t
INNER JOIN #temp_table AS tt ON t.col1 = tt.col1
</code></pre>
<p>Also returns:</p>
<pre><code>D E
G H
</code></pre>
|
What is the difference between iPod touch and iPod touch 2nd generation? <p>When submitting an app to the app store what is the real difference between iPod Touch and iPod Touch 2nd generation? </p>
|
<p>The following:</p>
<ul>
<li>Slightly thinner</li>
<li>Built-in support for Nike+</li>
<li>Volume bar</li>
<li>External speaker</li>
<li>Faster processor (533MHz vs 400MHz)</li>
<li>Supports new headphones with the microphone and volume control (allowing you to use VOIP apps)</li>
</ul>
|
log4net with ASP.NET 3.5 problems <p>I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the first time I've tried to use log4net, I feel like I'm missing a piece of the puzzle.</p>
<p>My project references the log4net assembly, and as far as I can tell, it is being deployed successfully on my server.</p>
<p>My web.config contains the following:</p>
<pre><code> <configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler
, log4net"
requirePermission="false"/>
</configSections>
<log4net>
<appender name="InfoAppender" type="log4net.Appender.FileAppender">
<file value="..\..\logs\\InfoLog.html" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern
value="%d [%t] %-5p %c [%x] - %m%n" />
</layout>
</appender>
<logger name="_Default">
<level value="INFO" />
<appender-ref ref="InfoAppender" />
</logger>
</log4net>
</code></pre>
<p>I'm using the following code to test the logger:</p>
<pre><code>using log4net;
using log4net.Config;
public partial class _Default : System.Web.UI.Page
{
private static readonly ILog log = LogManager.GetLogger("_Default");
protected void Page_Load(object sender, EventArgs e)
{
log.Info("Hello logging world!");
}
}
</code></pre>
<p>In my Global.asax, I'm doing the following:</p>
<pre><code>void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
}
</code></pre>
<p>At this point, I can't think of what else I might be doing wrong. The directory I'm trying to store the log in is writable, and even if I try different directories I get the same result: no file, no logs.</p>
<p>Any suggestions? :-)</p>
<p><hr /></p>
<p>Edit: I've tried several different formats for the path & name of the log file, some of which include "..\..\InfoLog.html", "InfoLog.html", "logs\InfoLog.html", etc, just in case someone is wondering if that's the problem.</p>
<p><hr /></p>
<p>Edit: I've added the root logger node back into the log4net section, I ommitted that on accident when copying from the samples. The root logger node looks like this:</p>
<pre><code><root>
<level value="INFO" />
<appender-ref ref="InfoAppender" />
</root>
</code></pre>
<p>Even with it, however, I'm still having no luck.</p>
|
<p>The root logger is mandatory I think. I suspect configuration is failing because the root doesn't exist.</p>
<p>Another potential problem is that Configure isn't being pointed to the Web.config.</p>
<p>Try Configure(Server.MapPath("~/web.config")) instead.</p>
|
xcopy ASP.NET deployment of a Subversion-managed project <p>I'm currently using Subversion to manage my ASP.NET website. I'm finding that whenever I go to upload my website to my server, I'm copying a large number of hidden .svn folders and whatever contents may lie within them.</p>
<p>Does anyone have any suggestions for avoiding this? I don't particularly want those hidden .svn folders on the production server, but short of manually deleting each .svn folder before I upload my website, I'm at a loss for how to have a .svn-folder-free production environment.</p>
<p><hr /></p>
<p>Edit: Thank you everyone, those are great suggestions, I really appreciate it!</p>
|
<ol>
<li>You should use export command of the subversion.</li>
<li>You may tweak registry and add a "Delete SVN Folders" to the context menu for folders. Here is an example script from <a href="http://weblogs.asp.net/jgalloway/archive/2007/02/24/shell-command-remove-svn-folders.aspx" rel="nofollow">http://weblogs.asp.net/jgalloway/archive/2007/02/24/shell-command-remove-svn-folders.aspx</a> Save it to a .reg file and execute.</li>
</ol>
<p>Right click on your project folder and delete all .svn folders recursively.</p>
<pre><code>Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
@="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
@="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
</code></pre>
|
Is it possible to see the CODE for sp_executesql? Is it TSQL? <p>Is it possible to see the CODE for sp_executesql?
I would like to see the actual code.
I could not find it in sql server management studio. </p>
|
<p>sp_executesql is an extended stored procedure. It's binary in a DLL.</p>
|
Checkout from TFS with MSBuild <p>What's the easiest way to checkout a file from our TFS with MSBUILD. </p>
<p>From what I can see it's to shell out to TF.EXE and manually call the checkout command. Is there really no built in command?!</p>
|
<p>There really is no built in command. Even worse, the tf checkout command only accepts a single filespec. </p>
<p>The recently released <a href="http://www.codeplex.com/MSBuildExtensionPack">MSBuildExtensionPack</a> has some msbuild commands for TFS, but no perf gain there. Under the hood, they shell out to tf.exe</p>
|
How does "Edit and continue" work in Visual Studio? <p>I have always found this to be a very useful feature in Visual Studio. For those who don't know about it, it allows you to edit code while you are debugging a running process, re-compile the code <em>while the binary is still running</em> and continue using the application seamlessly with the new code, without the need to restart it.</p>
<p>How is this feature implemented? If the code I am modifying is in a DLL loaded by the application, does the application simply unload the DLL and reload it again? This would seem to me like it would be prone to instability issues, so I assume it would be smarter than this. Any ideas?</p>
|
<p>My understanding is that when the app is compiled with support for Edit and Continue enabled, the compiler leaves extra room around the functions in the binary image to allow for adding additional code. Then the debugger can compile a new version of the function, replace the existing version (using the padding space as necessary), fix up the stack, set the instruction pointer, and keep going. That way you don't have to fix up any jump pointers, as long as you have enough padding.</p>
<p>Note that Edit and Continue doesn't usually work on code in libs/dlls, only with the main executable code.</p>
|
How to remove the background from a fingerprint image? <p>I have a fingerprint image taken from a sliding scanner. However the output does not have clean background. It looks like this:</p>
<p><img src="http://img208.imageshack.us/img208/2622/dirtyie0.png" alt="dirty" /></p>
<p>I want to remove the background so that further processing will be more accurate. Something like this:</p>
<p><img src="http://img515.imageshack.us/img515/7530/cleanhh6.png" alt="cleaned" /></p>
<p>How to do that? What image processing technique (if any) can be used? Thank you.</p>
|
<p>You can check the frequency spectrum for the area around the pixels. The less high frequency components you have, the more likely it is that the pixel is part of the background.</p>
<p>The most sophisticated way to do that would be to run a FFT of a block of pixels and check the spectrum directly. Since finger prints have a distinct frequency spectra it should be easy to separate background from fingerprint that way. </p>
<p>Using Wavelets could also be worth a try. That lets you split the image into sub-bands of the frequency of interest directly. Finding a good wavelet requires lot of practice though.</p>
<p>If you want a non-overkill solution it <em>may</em> be fine if you run a high-pass filter of the image and use it for a simple mask-finding pass. Here's a rough outline how that works:</p>
<ol>
<li><p>normalize the image: darkest pixel becomes -1, lightest pixel becomes 1. You can also use -128 / 127 if you prefer to work with bytes.</p></li>
<li><p>run a gaussian blur over the image. Experiment with the radius.</p></li>
<li><p>subtract the normalized image from the blured image. Handle overflows by saturating to -1 and 1. The image will now roughly look like it was edge-detected, but with shades of gray instead of a binary mask.</p></li>
<li><p>Run a mask-pass over the image from step 3. The higher the absolute value of each pixel, the higher the chance that it is part of the fingerprint. You can generate a mask by choosing a good threshold value.</p></li>
<li><p>use the mask to prepare your source-image.</p></li>
</ol>
<p>For completes sake you can also do it with image morphology:</p>
<ol>
<li><p>Run a edge-detector on your image. Using the Canny detector is a good choice but a simple 3x3 edge-detector kernel would work as well.</p></li>
<li><p>Run multiple dilation passes on the edges. This will at each pass grow a border around all white pixels and make the edges thicker. Do this until all the area of the finger-print is covered with white pixels. In your example I think 4 or 5 passes are enough. </p></li>
<li><p>You can now directly use the dilated image as a mask.</p></li>
</ol>
<p>Link: Dilation <a href="http://homepages.inf.ed.ac.uk/rbf/HIPR2/dilate.htm">http://homepages.inf.ed.ac.uk/rbf/HIPR2/dilate.htm</a></p>
|
Incoming poplib refactoring using windows python 2.3 <p>Hi Guys could you please help me refactor this so that it is sensibly pythonic.</p>
<pre><code>import sys
import poplib
import string
import StringIO, rfc822
import datetime
import logging
def _dump_pop_emails(self):
self.logger.info("open pop account %s with username: %s" % (self.account[0], self.account[1]))
self.popinstance = poplib.POP3(self.account[0])
self.logger.info(self.popinstance.getwelcome())
self.popinstance.user(self.account[1])
self.popinstance.pass_(self.account[2])
try:
(numMsgs, totalSize) = self.popinstance.stat()
for thisNum in range(1, numMsgs+1):
(server_msg, body, octets) = self.popinstance.retr(thisNum)
text = string.join(body, '\n')
mesg = StringIO.StringIO(text)
msg = rfc822.Message(mesg)
name, email = msg.getaddr("From")
emailpath = str(self._emailpath + self._inboxfolder + "\\" + email + "_" + msg.getheader("Subject") + ".eml")
emailpath = self._replace_whitespace(emailpath)
file = open(emailpath,"wb")
file.write(text)
file.close()
self.popinstance.dele(thisNum)
finally:
self.logger.info(self.popinstance.quit())
def _replace_whitespace(self,name):
name = str(name)
return name.replace(" ", "_")
</code></pre>
<p>Also in the _replace_whitespace method I would like to have some kind of cleaning routine which takes out all illegal characters which could cause processing.</p>
<p>Basically I want to write the email to the inbox directory in a standard way.</p>
<p>Am i doing something wrong here?</p>
|
<p>I don't see anything significant wrong with that code -- is it behaving incorrectly, or are you just looking for general style guidelines?</p>
<p>A few notes:</p>
<ol>
<li>Instead of <code>logger.info ("foo %s %s" % (bar, baz))</code>, use <code>"foo %s %s", bar, baz</code>. This avoids the overhead of string formatting if the message won't be printed.</li>
<li>Put a <code>try...finally</code> around opening <code>emailpath</code>.</li>
<li>Use <code>'\n'.join (body)</code>, instead of <code>string.join (body, '\n')</code>.</li>
<li>Instead of <code>msg.getaddr("From")</code>, just <code>msg.From</code>.</li>
</ol>
|
Tips for writing fluent interfaces in C# 3 <p>I'm after some good tips for fluent interfaces in C#. I'm just learning about it myself but keen to hear what others think outside of the articles I am reading. In particular I'm after:</p>
<ol>
<li>when is fluent too much?</li>
<li>are there any fluent patterns?</li>
<li>what is in C# that makes fluent interfaces more fluent (e.g. extension methods)</li>
<li>is a complex fluent interface still a fluent one?</li>
<li>refactoring to arrive at a fluent interface or refactoring an existing fluent interface</li>
<li>any good examples out there that you have worked with or could recommend?</li>
</ol>
<p>If you could post one tip or thought, or whatever per post. I want to see how they get voted on, too.</p>
<p>Thank you in advance.</p>
|
<p>The single biggest challenge I have experienced as a consumer of fluent interfaces is that most of them aren't really fluent intefaces -- instead they are really instances of what I tend to refer to as 'legible interfaces'.</p>
<p>A fluent interface implies that its primary goal is to make it easy to SPEAK it whereas a legible interface implies that its primary goal is to be easy to READ it. Most fluent interfaces only tend to be ridiculously difficult to code with but conversely incredibly easy to READ later by others.</p>
<pre><code>Assert().That().This(actual).Is().Equal().To(expected).
Except().If(x => x.GreaterThan(10));
</code></pre>
<p>...is alot easier to read later than it is to actually compose in code!</p>
|
How can I pass arguments to anonymous functions in JavaScript? <p>I'm trying to figure out how to pass arguments to an anonymous function in JavaScript.</p>
<p>Check out this sample code and I think you will see what I mean:</p>
<pre><code><input type="button" value="Click me" id="myButton" />
<script type="text/javascript">
var myButton = document.getElementById("myButton");
var myMessage = "it's working";
myButton.onclick = function(myMessage) { alert(myMessage); };
</script>
</code></pre>
<p>When clicking the button the message: <code>it's working</code> should appear. However the <code>myMessage</code> variable inside the anonymous function is null.</p>
<p>jQuery uses a lot of anonymous functions, what is the best way to pass that argument?</p>
|
<p>Your specific case can simply be corrected to be working:</p>
<pre><code><script type="text/javascript">
var myButton = document.getElementById("myButton");
var myMessage = "it's working";
myButton.onclick = function() { alert(myMessage); };
</script>
</code></pre>
<p>This example will work because the anonymous function created and assigned as a handler to element will have access to variables defined in the context where it was created.</p>
<p>For the record, a handler (that you assign through setting onxxx property) expects single argument to take that is event object being passed by the DOM, and you cannot force passing other argument in there</p>
|
How do I set a SQL Server script's timeout from within the script? <p>I have a large script file (nearly 300MB, and feasibly bigger in the future) that I am trying to run. It has been suggested in the comments of Gulzar's answer to my <a href="http://stackoverflow.com/questions/222442/sql-server-running-large-script-files">question about it</a> that I should change the script timeout to 0 (no timeout).</p>
<p>What is the best way to set this timeout from within the script? At the moment I have all of this at the top of the script file in the hopes that one of them does something:</p>
<pre><code>sp_configure 'remote login timeout', 600
go
sp_configure 'remote query timeout', 0
go
sp_configure 'query wait', 0
go
reconfigure with override
go
</code></pre>
<p>However, I'm still getting the same result and I can't tell if I'm succeeding in setting the timeout because the response from sqlcmd.exe is the world's least helpful error message:</p>
<blockquote>
<p>Sqlcmd: Error: Scripting error.</p>
</blockquote>
<p>Thanks.</p>
|
<p>Your solution - Add GO every 100 or 150 lines</p>
<p><a href="http://www.red-gate.com/MessageBoard/viewtopic.php?t=8109">http://www.red-gate.com/MessageBoard/viewtopic.php?t=8109</a></p>
|
Should the timezone be a constant or a variable? <p>I have a few places in the code where I need to use the TimeZone. I can get the timezone name using <a href="http://search.cpan.org/dist/DateTime" rel="nofollow">DateTime::TimeZone</a>. Is it reasonable to put the timezone name in a constant? Or should it be in a variable?</p>
|
<p>If the value can change, use a variable, of it is guaranteed to stay the same, use a constant. </p>
<p>For a timezone, the chance it will change is not big, but it is also not 0. The user can change the timezone and it would be nice if the program behaves accordingly.</p>
|
How to stop IE asking which debugger to choose when **trying** to debug? <p>When debugging in Internet Explorer; I first get an alert box with extremely limited if not useless information (sorry IE) and choice to debug it; After selecting yes; I get another option <em>every time</em> to chose between 'New instance of Microsoft script debugger' and 'New instance of Visual studio'. I'm fed up of having to click the yes button again after having clicking it once already on the alert box.</p>
<p>Update: I found that you can disable the microsoft script debugger from within its own options; just disabling the JIT debugger from Tools -> Options, and JIT. This stops it appearing on the menu but now I get the dialog box asking me which one to choose and it only displays the one Visual Studio - WHY? If there's only one option and you've already asked me if I want to debug, why ask again?!?! Bleh.</p>
<p>can you tell I'm getting sick of clicking, "yes" twice? Lol.</p>
|
<p>Apparently the problem happens if you do not uninstall the old (crappy) Microsoft Script Debugger before you install the newer Microsoft Script Editor.</p>
<p>You would think that all you need to do is to uninstall the old debugger - however, according to a blog posting (which I can't recall at the moment), if you uninstall the Microsoft Script Debugger at this point, it will mess up the MSE and you will have to reinstall the MSE again. I am on a tight schedule now so I don't have the time to fix the problem properly - just living with it as best as I can.</p>
|
Code Coverage on Visual Studio Team System 2008 Developer Edition (on an NUnit application) <p>Is this possible? I am looking forward to a tutorial which explains the steps to achieve this.</p>
|
<p><a href="http://testdriven.net/" rel="nofollow">TestDriven.NET</a> has the ability to test (NUnit/MSTest/etc) with Team Coverage (which you already have since you have Team System : Dev).</p>
<p>Walkthrough: <a href="http://weblogs.asp.net/nunitaddin/archive/2006/11/08/Driving-MSTest-and-Team-Coverage-using-TestDriven.NET.aspx" rel="nofollow">here</a> (you also get the coverage results window for looking at the coverage per method) - but this says it all:</p>
<p><img src="http://www.mutantdesign.co.uk/weblog/images/DrivingMSTestandTeamCoverageusingTes.NET_F424/MSTestAndTeamCoverage_thumb1.gif" alt="Using TestDriven.NET with Team Coverage" title="Using TestDriven.NET with Team Coverage" /></p>
<p>You can use NUnit tests, but use the MS IDE integration for colorization, percentagaes, etc (no need for NCover). I use this all the time ;-p</p>
<p>The advantages are:</p>
<ul>
<li>no need to set up a "Test Run Configuration" (sorry, MSFT, but an own-goal there)</li>
<li>fully integrated with VS (Code Coverage Results and Coloring)</li>
<li>easy to use (just right-click -> Test With -> Team Coverage)</li>
<li>easy to debug too (right-click -> Test With -> Debugger)</li>
<li>easy to use the separate NUnit/NCover apps if you want (right-click etc)</li>
</ul>
|
ejabberd - LDAP authentication <p>I'm trying to configure an ejabberd installation, using LDAP authentication, but I just can't login, even with the admin user.
This is part of my ejabberd.cfg file:</p>
<pre><code>%...
{auth_method, ldap}.
{ldap_servers, ["server2000.tek2000.local"]}.
{ldap_port,389}.
{ldap_uidattr, "uid"}.
{ldap_base, "dc=server2000,dc=tek2000,dc=com"}.
{ldap_rootdn, "tempadm@tek2000.local"}.
{ldap_password, "secret"}.
%...
</code></pre>
<p>What am I missing?</p>
<p>I must say that, with OpenFire, I can connect using this credentials/configuration.</p>
<p>I'm using Spark as my client application.</p>
<p>Thanks</p>
|
<p>I'd expect that your ldap_rootdn should actually look something like</p>
<pre><code>cn=tempadm,dc=server2000,dc=tek2000,dc=com
</code></pre>
<p>rather than the format you've used there.</p>
|
Receive parameter from request body in WCF/ADO.NET Data Service <p>I'm tryint to post to a ADO.NET Data Service but the parameters seems to get lost along the way.</p>
<p>I got something like:</p>
<pre><code>[WebInvoke(Method="POST")]
public int MyMethod(int foo, string bar) {...}
</code></pre>
<p>and I make an ajax-call using prototype.js as:</p>
<pre><code>var args = {foo: 4, bar: "'test'"};
new Ajax.Requst(baseurl + 'MyMethod',
method: 'POST',
parameters: args,
onSuccess: jadda,
onFailure: jidda
}
</code></pre>
<p>If I replace "method: 'POST'" with "method: 'GET'" and "WebInvoke(Method="POST")" with "WebGet" everything works but now (using post) all I get is:</p>
<blockquote>
<p>Bad Request - Error in query syntax.</p>
</blockquote>
<p>from the service.</p>
<p>The only fix (that I don't want to use) is to send all parameters in the URL even when I perform a post. Any ideas are welcome. </p>
|
<p>WCF and ASMX webservices tend to be a bit choosey about the request body, when you specify args the request is usually encoded as a form post i.e. foo=4&bar=test instead you need to specify the javascript literal:-</p>
<pre><code> new Ajax.Request(baseurl + 'MyMethod', {
method: 'POST',
postBody: '{"foo":4, "bar":"test"}',
encoding: "UTF-8",
contentType: "application/json;",
onSuccess: function(result) {
alert(result.responseJSON.d);
},
onFailure: function() {
alert("Error");
}
});
</code></pre>
|
Are there any pitfalls / things you need to know when changing from MyISAM to InnoDB <p>One of my projects use the MyISAM engine in MySQL, but I'm considering changing it to InnoDB as I need transaction support here and there.</p>
<ul>
<li>What should I look at or consider before doing this? </li>
<li>Can I just change the engine, or should the data be prepared for it?</li>
</ul>
|
<p>Yes absolutely, there are many things, you should test your application extremely thoroughly:</p>
<ul>
<li>Transactions can deadlock and need to be repeated. This is the case (in some circumstances) even with an autocommitted transaction which only inserts one row.</li>
<li>Disc usage will almost certainly increase</li>
<li>I/O load during writes will almost certainly increase</li>
<li>Behaviour of indexing will change because InnoDB uses clustered indexes - this may be a beneficial effect in some cases</li>
<li>Your backup strategy will be impacted. Consider this carefully.</li>
</ul>
<p>The migration process itself will need to be carefully planned, as it will take a long time if you have a lot of data (during which time the data will be either readonly, or completely unavailable - do check!)</p>
|
Removing Duplicate Images <p>We have a collection of photo images sizing a few hundred gigs. A large number of the photos are visually duplicates, but with differing filesizes, resolution, compression etc. </p>
<p>Is it possible to use any specific image processing methods to search out and remove these duplicate images?</p>
|
<p>I recently wanted to accomplish this task for a PHP image gallery. I wanted to be able to generate a "fuzzy" fingerprint for an uploaded image, and check a database for any images that had the same fingerprint, indicating they were similar, and then compare them more closely to determine how similar.</p>
<p>I accomplished it by resizing the uploaded image to 150 pixels wide, reducing it to greyscale, rounding the value of each colour off to the nearest multiple of 16 (giving 17 possible shades of grey between 0 and 255), normalise them and store them in an array, thereby creating a "fuzzy" colour histogram, then creating an md5sum of the histogram which I could then search for in my database. This was extremely effective in narrowing down images which were very visually similar to the uploaded file.</p>
<p>Then to compare the uploaded file against each "similar" image in the database, I took both images, resized them to 16x16, and analysed them pixel by pixel and took the RGB value of each pixel away from the value of the corresponding pixel in the other image, adding all the values together and dividing by the number of pixels giving me an average colour deviation. Anything less than specific value was determined to be a duplicate.</p>
<p>The whole thing is written in PHP using the GD module, and a comparison against thousands of images takes only a few hundred milliseconds per uploaded file.</p>
<p>My code, and methodology is here: <a href="http://www.catpa.ws/php-duplicate-image-finder/">http://www.catpa.ws/php-duplicate-image-finder/</a></p>
|
How to generate empty definitions given a header file <p>I have a 3rd-party library which for various reasons I don't wish to link against yet. I don't want to butcher my code though to remove all reference to its API, so I'd like to generate a dummy implementation of it.</p>
<p>Is there any tool I can use which spits out empty definitions of classes given their header files? It's fine to return nulls, false and 0 by default. I don't want to do anything on-the-fly or anything clever - the mock object libraries I've looked at appear quite heavy-weight? Ideally I want something to use like</p>
<pre><code>$ generate-definition my_header.h > dummy_implemtation.cpp
</code></pre>
<p>I'm using Linux, GCC4.1</p>
|
<p>This is a harder problem than you might like, as parsing C++ can quickly become a difficult task. Your best bet would be to pick an existing parser with a nice interface.</p>
<p>A quick search found <a href="http://compilers.iecc.com/comparch/article/06-09-169" rel="nofollow">this thread</a> which has many recommendations for parsers to do something similar.</p>
<p>At the very worst you might be able to use SWIG --> Python, and then use reflection on that to print a dummy implementation.</p>
<p>Sorry this is only a half-answer, but I don't think there is an existing tool to do this (other than a mocking framework, which is probably the same amount of work as using a parser).</p>
|
How to load a .NET assembly for reflection operations and subsequently unload it? <p>I'm writing a tool to report information about .NET applications deployed across environments and regions within my client's systems.</p>
<p>I'd like to read the values of assembly attributes in these assemblies.</p>
<p>This can be achieved using <code>Assembly.ReflectionOnlyLoad</code>, however even this approach keeps the assembly loaded. The issue here is that I cannot load two assemblies that have the same name from different paths, so naturally I can't compare the same application deployed in different systems.</p>
<p>At this point I'm assuming the solution will involve using temporary <code>AppDomain</code>s.</p>
<p>Can someone detail how to load an assembly into another <code>AppDomain</code>, read the attributes from it and then unload the <code>AppDomain</code>?</p>
<p>This needs to work for assemblies on the file system as well as those at URL addresses.</p>
|
<p>From the <a href="http://msdn.microsoft.com/en-us/library/0et80c7k.aspx">MSDN documentation of System.Reflection.Assembly.ReflectionOnlyLoad (String)</a> :</p>
<blockquote>
<p>The reflection-only context is no
different from other contexts.
Assemblies that are loaded into the
context can be unloaded only by
unloading the application domain.</p>
</blockquote>
<p>So, I am afraid the only way to unload an assembly is unloading the application domain.
To create a new AppDomain and load assemblies into it:</p>
<pre><code>public void TempLoadAssembly()
{
AppDomain tempDomain = AppDomain.CreateDomain("TemporaryAppDomain");
tempDomain.DoCallBack(LoaderCallback);
AppDomain.Unload(tempDomain);
}
private void LoaderCallback()
{
Assembly.ReflectionOnlyLoad("YourAssembly");
// Do your stuff here
}
</code></pre>
|
On XP, best way to synchronize files and folders <p>I'm using SyncToy 1.4 and it would be fine for what I need except that: </p>
<ul>
<li>It can't handle the assigned drive letter changing between systems (e.g. syncing a USB drive), </li>
<li>it leaves its own (hidden) files in the folders being synched (is this a limitation of the OS/FS?), </li>
<li>it recreates empty folders for ones that have been deleted, </li>
<li>it syncs new sub folders in folders that have been unselected from syncing </li>
<li>and sometimes finds all the files have changed when they are still the same as they were.</li>
<li>it can't handle very long file path/name</li>
</ul>
<p>SyncToy 2.1 is too slow to be usable. Especially when run again on a folder without any changes it will start from scratch scanning all the files and sub-folders for differences. </p>
<p>It has to be a solution without using Internet based storage, as this isn't always available and otherwise can be far too slow. I'd prefer something that doesn't add its own files to the folders to be synched, and something with which it's quick and easy to change file and folder synching selections. When run the less interactive the better, ideally safely synching multiple folder pairs with a couple of mouse clicks (as SyncToy does).</p>
<p>Do I have to use rsync and batch files? Something with a GUI for granny to use without difficulty, would be better.</p>
|
<p><a href="http://allwaysync.com/">http://allwaysync.com/</a> - and it's free</p>
|
Is there a tool that supports discrete mathematics? <p><a href="http://en.wikipedia.org/wiki/Discrete_mathematics" rel="nofollow">Discrete mathematics (also finite mathematics)</a> deals with topics such as logic, set theory, information theory, partially ordered sets, proofs, relations, and a number of other topics.</p>
<p>For other branches of mathematics, there are tools that support programming. For statistics, there is <a href="http://en.wikipedia.org/wiki/R_(programming_language)" rel="nofollow">R</a> and <a href="http://en.wikipedia.org/wiki/S_programming_language" rel="nofollow">S</a> that have many useful statistics functions built in. For numerical analysis, <a href="http://en.wikipedia.org/wiki/GNU_Octave" rel="nofollow">Octave</a> can be used as a language or integrated into C++. </p>
<p>I don't know of any languages or packages that deal specifically with discrete mathematics (although just about every language can be used to implement algorithms used in discrete mathematics, there should be libraries or environments out there designed specifically for these applications).</p>
|
<p>The current version of <a href="http://www.wolfram.com/products/mathematica/index.html">Mathematica</a> is 7. License costs:</p>
<ol>
<li><a href="http://wolfram.com/products/mathematicahomeedition/qa.html">Home Edition</a>: $295.</li>
<li>Standard: $2,495 Win/Mac/Linux PC ($3,120 for Solaris)</li>
<li>Government: $1,996 ($2,496 for Solaris)</li>
<li>Educational: $1,095 ($1,370 for Solaris)</li>
<li>Student: $139.95 (no Solaris)</li>
</ol>
<p>Above, the Home Edition link says:</p>
<p>Mathematica Home Edition is a fully functional version of Mathematica Professional with the same features.</p>
<p>The current version of <a href="http://www.maplesoft.com/">Maple</a> is 12. License costs:</p>
<ol>
<li>Student: $99</li>
<li>Commercial: $1,895</li>
<li>Academic: $995</li>
<li>Government: $1,795</li>
</ol>
<p>And yes, check out Sage, mentioned above by Thomas Owens.</p>
|
ASP.NET Performance : web application without precompilation <p>Currently we're using Web Application project, so we have a gain with compilation. But as far as I know, the aspx pages a still compiled at the first page hit. So does precompilation give a perceptible performance gain ? (first hit exluded).</p>
<p>What type of web site (hits/sec, number of users) will benefit of it ?</p>
|
<p>Pre-compilation saves the first hit the work of doing the JIT compilation, for a site with a large number of pages who knows how long it will be before every page is visited and gets compilled.</p>
<p>After the first hit there's no difference between the page having compiled JIT or pre-compilled.</p>
<p>We use pre-compilation to ensure that the website will actually compile and don't get caught out by a missing reference or some issue with the production environment. This is also important so that no user has a different experience of our site because they have to wait for the JIT complilation.</p>
|
Embed image in code, without using resource section or external images <p>I'm looking for a way to embed an image in a library (Windows-only). I don't want to go the 'traditional' way of putting it in the resources (because of special circumstances that make it not so convenient to mess around with the resource handle.</p>
<p>Ideally, there would be something like xpm files: a 'text' representation of an image that is put in a c array and that some code converts into a bitmap in memory, which can then somehow be loaded into an HIMAGE or an HICON. The images I want to embed are 32-bit bitmaps (bmp). Any ideas? I'm using MFC so an MFC library would be fine, but of course I can use a library that doesn't use MFC too. Thanks.</p>
|
<p>Google for a bin2c utility (something like <a href="http://stud3.tuwien.ac.at/~e0025274/bin2c/bin2c.c">http://stud3.tuwien.ac.at/~e0025274/bin2c/bin2c.c</a>). It takes a file's binary representation and spits out a C source file that includes an array of bytes initialized to that data.</p>
<p>Just link the file in and you have your image sitting in a chunk of memory.</p>
<p>Using this kind of tool is really common on embedded systems where such things as 'resources' and even files might not exist.</p>
|
How to close a .Net Form from its PreFilterMessage()? <p>I'm filtering the messages that come to a form with PreFilterMessage like this:</p>
<p><code>print("code sample");</code></p>
<pre><code> public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_KEYDOWN && (int)m.WParam == VK_ESCAPE)
{
this.Close();
return true;
}
return false;
}
</code></pre>
<p><code>print("code sample");</code></p>
<p>but the matter is that form closes only for the first time. After reopening a form it won't close anymore by pressing ESC.</p>
<p>How can I accomplish this?</p>
<p>Thanks</p>
|
<p>I don't know if this fits with what you are doing. I usually set Form.CancelButton to the close or cancel button on my form, and it will automatically call the button OnClick when the user hits Esc on the keyboard.</p>
|
Is there a PHP function to remove any/all key/value pairs that have a certain value from an array? <p>I think questions like this are the reason why I don't like working with PHP. The manual is good, if you can find what you are looking for. After reading through the <a href="http://us3.php.net/array" rel="nofollow">Array Functions</a>, I didn't see one that provides the functionality I need.</p>
<p>I have an array (in my case, numerically indexed) that I want to scan for a particular value and, if it's there, remove it. And then, when all instances of that value have been removed, I want to rearrange the array using <a href="http://us3.php.net/manual/en/function.array-values.php" rel="nofollow">array_values</a>.</p>
|
<p><a href="http://de.php.net/array_diff" rel="nofollow"><code>array_diff</code></a> is what you want.</p>
<pre><code>$array1 = array("a" => "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
</code></pre>
<p>Result: <code>"blue"</code>.</p>
|
Is it good to include title="" within your links? <p>I am developing a website and for the main navigation, I was thinking it would be a good idea to include the title attribute.</p>
<pre><code><a href="/results/" title="Results">Results</a>
</code></pre>
<p>Is this a good thing to do? Also, is it good for SEO and accessibility?</p>
|
<p>It is a great thing to do. For accessibility, for SEO, for standards, for good netiquette.<br />
You may want to make them slightly more descriptive though: title="Results of your Search" or "Results of Test #2"</p>
|
Controlling the execution of a Jython script from Java <p>I'm trying to control the execution of a Jython script from within Java and executed through a call to PythonInterpreter.exec(). The script contains calls to classes defined in Java. I'll call these classes "commands" for the discussion here. The commands can also be run on a different machine via RMI. </p>
<p>Since the commands take a while to complete, I want to check the progress of the commands' execution on the caller side, like at what percentage of the execution is complete. I can provide a getProgress() method to the classes but accessing this method seems to be impossible to do because PythonInterpreter doesn't allow the caller access to the command object running inside it.</p>
<p>Any ideas on how to do this?</p>
|
<p>my 0.10 Eur :
(ist not easy)</p>
<p>Build a Factory as descripted in</p>
<p><a href="http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1" rel="nofollow">http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1</a></p>
<p>and a Java-Interface that represents a script-class (IJScript)
(including run() and getProgress() methods)</p>
<p>your scripts should then look like this:</p>
<pre><code>class xyscript(IJScript) :
def __init__(self) :
...
def run(self) :
...
def getProgress(self) :
....
</code></pre>
<p>run your scripts in accessing the Interface IJScript (the Java Interface)
(look at the employee example)</p>
|
Should I include dependencies for my releases? <p>Should I include dependencies when I do releases for my common projects such as CommonUtils or should I simply specify which dependencies should be referenced when they are to be used?</p>
|
<p>You users do not want the work if figuring out your dependencies.</p>
<ul>
<li>What packages do I need?</li>
<li>What if it's not available? (dead server, provider out of business)</li>
<li>What version of each one do I need?</li>
<li>What if it's not available? (new version)</li>
<li>How do I download each one?</li>
<li>How do I install each one?</li>
</ul>
<p>Protect your software from disappearing/unavailable dependencies. Protect your users from the pain of figuring this stuff out.</p>
<p>Make your uninstaller do the right thing: remove things you installed, if they're not shared. (That can be hard).</p>
|
How to deal with multiple versions of dependencies? <p>Hi I have a problem with a dependency hierarchy I am unsure how to solve:</p>
<p>
<a href="http://img525.imageshack.us/my.php?image=56330713it2.jpg" rel="nofollow">http://img525.imageshack.us/my.php?image=56330713it2.jpg</a></p>
<p>The problem is with how I should reference these dependencies from MyProject project. I have built BaseProject and the CommonUtil(version 1.0) it was built with into assemblies. Now in MyProject I am using classes from CommonUtil and I am unsure if I should reference the CommonUtil.v.1.0 or if I could/should reference the current version of CommonUtil (v 2.0).</p>
<p>Which CommonUtils assembly should I reference from my MyProject?
I cannot reference both assemblies as VS tells me it cannot determine which assembly to use as they both contain some of the same methods. If I only reference v.1.0 I would perhaps not have everything I need from v.2.0 and If I only reference v.2.0 I would perhaps not have all capabilities in v.1.0 (which BaseProject) needs.</p>
|
<p>If you are using the classes that BaseProject returns directly within MyProject, you need to stick with the same version (1.0). But if BaseProject only uses those classes internally and does not share with MyProject, you can safely use the new version (2.0).</p>
<p>Best practice: strongly name your assemblies so that the compiler can help you out.</p>
|
Syntax highlighting when pasting into emails <p>Im in the situation that I often send small codesnippets and xml-snippets to coworkers and partners via my outlook.
Has anyone got a good idea or tool that I can use to have my pastes syntaxhighlighted before I paste them into an email.</p>
<p>I was thinking of an intermediate paste to "$fancytool" and then I would have something to copy that will htmlified so I can copy paste it into the "compose email" window.</p>
<p><em>Edit-More-info:</em></p>
<p>Im pasting from windows within a VMWare virtual Machine, it might be eclipse, xmlspy, logfiles and other programs</p>
<p><em>Even-more-info:</em></p>
<p>I've seen <a href="http://vim.wikia.com/wiki/Pasting_code_with_syntax_coloring_in_emails">this link</a> how to do it from Vim. Unfortunately it seldom from vim im copying Code, and my email machine hasnt got any vim. The vmware machines has gvim, but I was hoping for an easier way that pasting to vim, saving to file, opening in internetexplorer and then copy/paste</p>
|
<p>Late but I can give an answer that works.
You need 2 things</p>
<ol>
<li>putty</li>
<li>access to some Unix server (With vim)</li>
</ol>
<p>In putty options, Under window → selection , turn the check box on for </p>
<p><code>Paste in to clipboard in RTF as well as plain text</code>.</p>
<p>Log on to the server using putty.
start vim by typing vim
Paste your text (for example XML ) in to vim.
enter command mode (of vim by pressing <kbd>ESC</kbd>) and type
<code>:set syn=xml</code>.</p>
<p>Syntax highlighting kicks in.
Copy the text using mouse and paste it into your email.</p>
|
How do I "single-instance" an ASP.Net AJAX web portal? <p>Iâve been asked if we can optionally âsingle-instanceâ our web portal. See
<a href="http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx" rel="nofollow">this post on Hanselman's blog</a> for the same idea in a WinForms app.</p>
<p>Suppose we have 2 shortcuts on the same client machine:</p>
<p><a href="http://MyServer/MyWebPortal/Default.aspx?user=username&document=Foo" rel="nofollow">http://MyServer/MyWebPortal/Default.aspx?user=username&document=Foo</a>
<a href="http://MyServer/MyWebPortal/Default.aspx?user=username&document=Bar" rel="nofollow">http://MyServer/MyWebPortal/Default.aspx?user=username&document=Bar</a></p>
<p>Clicking on the first shortcut would launch our web portal, log in, and display the document âFooâ. Clicking on the second shortcut should display the document âBarâ in the running instance of the web portal.</p>
<p>My current approach is this: In the Page Load, for the first instance create a per-client Application variable. The second instance looks for the Application variable to see if the portal is running on the client. If it is, the second URL is recorded in another Application variable and the second instance is forcibly exited. Iâve tried creating a ASP.Net AJAX Timer to poll the Application variable for a document to display. This sort of works. In order to respond quickly to the second request Iâve set the Timer interval to 2 seconds. This makes the portal irritating to use because of the frequent postbacks.</p>
<p>Using my approach, is there a way for the second instance to notify the first instance to check the application variable without polling? Is there a better overall approach to this problem?</p>
<p>Thanks in advance</p>
|
<p>There is no way on the server side to control which browser instance your page opens up on the client. You can't force all requests to open in the same browser window.</p>
<p>Also, an Application scope variable is shared by <em>all users</em> of your application. At least make this a Session-scope variable - otherwise you would only be allowing one user to access your portal at a time!</p>
<p>Honestly this sounds like a silly request from someone who a) probably doesn't understand how these types of things work and b) is trying to do an end-around for users who aren't that bright and actually see a problem with having more than one instance of your portal open.</p>
|
Why use LabVIEW? <p>I am learning to use LabVIEW as part of my honours project, and was wondering what benefits the graphical programming language has over a textual one?</p>
|
<p>To me, the benefit of LabVIEW is not in graphical vs. textual.</p>
<p>It's dataflow vs. imperative.</p>
<p><a href="http://en.wikipedia.org/wiki/Dataflow_programming">Dataflow programming</a> lends itself to concurrency, because your execution is modeled as black boxes which execute when their inputs are valid, whose inputs / outputs are wired together. This as opposed to implicit state with a list of instructions on how to modify it. (Loosely paraphrasing 'kipedia, the article linked above is better.)</p>
<p>Each black box can run on a separate core/processor/node, which gives you, effectively, free concurrency if you organize your program the dataflow way.</p>
<p>Unfortunately (and this is a <em>crippling</em> downside to dataflow programming in general) the best way to visualize and edit dataflow programs is graphical, not textual. This makes using tools such as revision control and code generators very difficult.</p>
<p>The question is: Do the pros of dataflow outweigh the cons, for you and your project?</p>
|
How do I specify values in a properties file so they can be retrieved using ResourceBundle#getStringArray? <p>I am trying to use <code>ResourceBundle#getStringArray</code> to retrieve a <code>String[]</code> from a properties file. The description of this method in the documentation reads:</p>
<blockquote>
<p>Gets a string array for the given key from this resource bundle or one of its parents.</p>
</blockquote>
<p>However, I have attempted to store the values in the properties file as multiple individual key/value pairs:</p>
<pre><code>key=value1
key=value2
key=value3
</code></pre>
<p>and as a comma-delimited list:</p>
<pre><code>key=value1,value2,value3
</code></pre>
<p>but neither of these is retrievable using <code>ResourceBundle#getStringArray</code>.</p>
<p>How do you represent a set of key/value pairs in a properties file such that they can be retrieved using <code>ResourceBundle#getStringArray</code>?</p>
|
<p>A <code>Properties</code> object can hold <strong><code>Object</code>s</strong>, not just <code>String</code>s. That tends to be forgotten because they're overwhelmingly used to load .properties files, and so often will only contain <code>String</code>s. <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html#getStringArray(java.lang.String)">The documentation</a> indicates that calling <code>bundle.getStringArray(key)</code> is equivalent to calling <code>(String[]) bundle.getObject(key)</code>. That's the problem: the value isn't a <code>String[]</code>, it's a <code>String</code>.</p>
<p>I'd suggest storing it in comma-delimited format and calling <code>split()</code> on the value.</p>
|
What is your favorite User Interface? (web application) <p>I think it would be interesting to get a programmers viewpoint on UI design.</p>
<p>What is your favorite User Interface that you have come across in a web application?</p>
<p>If possible, say a little bit about why you like it.</p>
|
<p><a href="http://www.google.com" rel="nofollow">http://www.google.com</a> is my favorite. Can be considered a "lack of UI" ;)</p>
|
Eclipse class version bug <p>In eclipse 3.4 I'm trying to do some performance tests on a large product, one of the included libraries is the vecmath.jar (javax.vecmath package) from the Java3D project. Everything was working fine and then when trying to run it yesterday I get this exception/error not long after starting it up:</p>
<pre><code>java.lang.UnsupportedClassVersionError: javax/vecmath/Point2f (Unsupported major.minor version 49.0)
</code></pre>
<p>Which I believe means that I'm trying to load a java 1.5 class file into a 1.4 jvm which is unsupported. However when I went to the class file to check this I saw this in the eclipse class file viewer:</p>
<pre><code>Compiled from Point2f.java (version 1.2 : 46.0, super bit)
</code></pre>
<p>So the class loader says it is version 49.0 but the class file says its 46.0. I've tried cleaning and fully rebuilding the project, I've confirmed that the compiler version for the project is 1.4, the JRE is 1.4 and for the run configuration the 1.4 jvm is selected. I'm totally stuck on this, does anyone have any idea what might be causing this?</p>
<p>Thanks</p>
<p>===EDIT===</p>
<p>It turns out that a version of java3d which was incompatible with java 1.4.2 had been installed in C:\Program Files\java\j2re1.4.2_18\lib\ext. I installed a newer version of Java3D to play around with in java6 and i guess it installed the libs in all my JREs even the ones which were incompatible.</p>
|
<p>Could there be another javax.vecmath.Point2f on your classpath?</p>
|
Is there a way to make Crystal Reports include a constant in a join condition, without using a SQL command object? <p>What I want to do is an outer join to a table, where I exclude records from the joined table based on matching a constant, however keep records from the main table. For example:</p>
<pre><code>SELECT a.id, a.other, b.baz
FROM a
LEFT OUTER JOIN b
ON a.id = b.id
AND b.bar = 'foo'
</code></pre>
<p>Expected results:</p>
<pre>
id other baz
-- ---------- -------
1 Has foo Include
2 Has none (null)
3 Has foobar (null)
</pre>
<p>I can't get the same results by putting it in the filter condition. If I use the following:</p>
<pre><code>SELECT a.id, a.other, b.baz
FROM a
LEFT OUTER JOIN b
ON a.id = b.id
WHERE (b.bar IS NULL OR b.bar = 'foo')
</code></pre>
<p>I get these incorrect results:</p>
<pre>
id other baz
-- -------- -------
1 Has foo Include
2 Has none (null)
</pre>
<p>Where it excluded records of A that happen to match a record of B where bar = 'foobar'. I don't want that, I want A to be present, but B to be nulls in that case.</p>
<p>Table B will have multiple records that need excluding, so I don't think I can filter this on the Crystal side without doing a lot of messing around to avoid problems from duplicate records from table A.</p>
<p>I cannot use a SQL command object, as the third party application that we are running the reports from seems to choke on SQL command objects.</p>
<p>I cannot use views, as our support contract does not permit database modifications, and our vendor considers adding views a database modification.</p>
<p>I am working with Crystal Reports XI, specifically version 11.0.0.895. In case it makes a difference, I am running against a Progress 9.1E04 database using the SQL-92 ODBC driver.</p>
<p>The sample tables and data used in the examples can be created with the following:</p>
<pre><code>CREATE TABLE a (id INTEGER, other VARCHAR(32));
CREATE TABLE b (id INTEGER, bar VARCHAR(32), baz VARCHAR(32));
insert into A (id, other) values ('1', 'Has foo');
insert into A (id, other) values ('2', 'Has none');
insert into A (id, other) values ('3', 'Has foobar');
insert into B (id, bar, baz) values ('1', 'foo', 'Include');
insert into B (id, bar, baz) values ('1', 'foobar', 'Exclude');
insert into B (id, bar, baz) values ('1', 'another', 'Exclude');
insert into B (id, bar, baz) values ('1', 'More', 'Exclude');
insert into B (id, bar, baz) values ('3', 'foobar', 'Exclude');
</code></pre>
|
<p>Crystal reports can't generate that commonly used SQL statement based on its links and report selection criteria. You have to use a "command" or build a view.</p>
<p>In short, Crystal sucks. </p>
|
What TFS tool would you recommend? <p>I am mostly use to using Subversion for my source control. However, my current position has me using TFS. The UI of the TFS explorer and its integration with Visual Studio has me a little disoriented. I miss having tools like SmartSVN where I could see at a glance what I've modified and is pending checkin.</p>
<p>What tool sets do you recommend for use with TFS in general, and what tools do you know of that enable such visualizations? I know that the TFS explorer will show you pending checkins, but I miss having a separate tool that monitors file system changes and auto refreshes the list of files.</p>
|
<p>Checkout/modification information is available in the solution explorer. Checked out items have a check mark next to their name/icon. Checked in items have a lock. Items checked out to others have a person icon. You can also do a right click and view pending changes. I've found that this shows me all pending changes for all the projects I have loaded in team explorer and is thus a little cumbersome. I'd like it to be aware of my current project and only display files related to it.</p>
|
What do PHP stream contexts do in relation to file operations? <p>In the PHP manual, the file operations reference an optional context (e.g. for <a href="http://us3.php.net/copy" rel="nofollow">copy</a>). How do these contexts affect basic file operations?</p>
|
<p>As it turns out, stream contexts can contain both <a href="http://us2.php.net/manual/en/context.php" rel="nofollow">options</a> and <a href="http://us2.php.net/manual/en/function.stream-context-set-params.php" rel="nofollow">parameters</a>. At the current time, parameters are simply callback functions so that you can be notified at various points of the file operation. Options are wrapper-specific, and filesystem operations don't have any options. Some examples of options for the HTTP wrapper are method, proxy, etc.</p>
|
Looking for an OSX application that can do image processing using a webcam <p>I'm looking for an OSX (or Linux?) application that can recieve data from a webcam/video-input and let you do some image processing on the pixels in something similar to c or python or perl, not that bothered about the processing language.</p>
<p>I was considering throwing one together but figured I'd try and find one that exists already first before I start re-inventing the wheel.</p>
<p>Wanting to do some experiments with object detection and reading of dials and numbers.</p>
|
<p>If you're willing to do a little coding, you want to take a look at QTKit, the QuickTime framework for Cocoa. QTKit will let you easity set up an input source from the webcam (intro <a href="http://developer.apple.com/quicktime/qtkit.html" rel="nofollow">here</a>). You can also apply Core Image filters to the stream (demo code <a href="http://developer.apple.com/samplecode/MyMovieFilter/index.html" rel="nofollow">here</a>). If you want to use OpenGL to render or apply filters to the movie, check out Core Video (examples <a href="http://developer.apple.com/samplecode/QuickTime/idxCocoa-date.html" rel="nofollow">here</a>).</p>
<p>Using the<a href="http://developer.apple.com/samplecode/MyMovieFilter/index.html" rel="nofollow">MyMovieFilter</a> demo should get you up and running very quickly.</p>
|
C# Attribute to trigger an event on invoking a method <p>Is there a way in C# or .NET in general to create an attribute on a method which triggers an event when a method is invoked? Ideally, I would be able to run custom actions before and after the invocation of the method.</p>
<p>I mean something like this:</p>
<pre><code>[TriggersMyCustomAction()]
public void DoSomeStuff()
{
}
</code></pre>
<p>I am totally clueless how to do it or if it possible at all, but <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx">System.Diagnostic.ConditionalAttribute</a> might do a similar thing in the background. I am not sure though.</p>
<p><strong>EDIT</strong>: I forgot to mention that due to the circumstances of my specific case, performance is not really an issue.</p>
|
<p>The only way I know how to do this is with <a href="https://www.postsharp.net/" rel="nofollow">PostSharp</a>. It post-processes your IL and can do things like what you asked for.</p>
|
Semi-Tricky SQL Query <p>I am trying to write a query for SQL Server 2005 but I can't figure out how to do it. I have a table with the following fields:</p>
<p><strong>MessageID int<br/>
CategoryID int<br/>
Priority tinyint<br/>
MessageText NVARCHAR(MAX)<br/></strong></p>
<p>I need a query that will return * for each row that has the highest priority within a Category. For example, if I had the following data:</p>
<p><strong>MessageID, CategoryID, Priority, MessageText</strong><br/>
1, 100, 1, Error #1234 occurred<br/>
2, 100, 2, Error #243 occurred<br/>
3, 100, 3, Error #976 occurred<br/>
4, 200, 4, Error #194 occurred<br/>
5, 200, 1, Error #736 occurred<br/>
6, 300, 3, Error #54 occurred<br/>
7, 300, 2, Error #888 occurred<br/></p>
<p>then the result would be:</p>
<p><strong>MessageID, CategoryID, Priority, MessageText</strong><br/>
3, 100, 3, Error #976 occurred<br/>
4, 200, 4, Error #194 occurred<br/>
6, 300, 3, Error #54 occurred<br/></p>
<p>Notice that it returns one row per category, and that it is the row which had the highest priority for that Category.</p>
<p>Can anyone tell me how I can write this query?</p>
|
<p>Verified:</p>
<pre><code>SELECT
highest_priority_messages.*
FROM
(
SELECT
m.MessageID
, m.CategoryID
, m.Priority
, m.MessageText
, Rank() OVER
(PARTITION BY m.CategoryID ORDER BY m.Priority DESC) AS p_rank
FROM [Message] m
GROUP BY
m.CategoryID
, m.Priority
, m.MessageID
, m.MessageText
) highest_priority_messages
WHERE
p_rank = 1
</code></pre>
|
Django Forms - How to Use Prefix Parameter <p>Say I have a form like:</p>
<pre><code>class GeneralForm(forms.Form):
field1 = forms.IntegerField(required=False)
field2 = forms. IntegerField(required=False)
</code></pre>
<p>And I want to show it twice on a page within one form tag each time with a different prefix e.g.,:</p>
<pre><code>rest of page ...
<form ..>
GeneralForm(data,prefix="form1").as_table()
GeneralForm(data,prefix="form2").as_table()
<input type="submit" />
</form>
rest of page ...
</code></pre>
<p>When the user submits this, how do I get the submitted form back into two separate forms to do validation, and redisplay it?</p>
<p><a href="http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms">This was the only documentation</a> I could find and it's peckish.</p>
|
<p>You process each form as you normally would, ensuring that you create instances which have the same prefixes as those used to generate the form initially.</p>
<p>Here's a slightly awkward example using the form you've given, as I don't know what the exact use case is:</p>
<pre><code>def some_view(request):
if request.method == 'POST':
form1 = GeneralForm(request.POST, prefix='form1')
form2 = GeneralForm(request.POST, prefix='form2')
if all([form1.is_valid(), form2.is_valid()]):
pass # Do stuff with the forms
else:
form1 = GeneralForm(prefix='form1')
form2 = GeneralForm(prefix='form2')
return render_to_response('some_template.html', {
'form1': form1,
'form2': form2,
})
</code></pre>
<p>Here's some real-world sample code which demonstrates processing forms using the prefix:</p>
<p><a href="http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/">http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/</a></p>
|
What is the best tool for build automation for a one-man software shop? <p>I am building Windows apps for a few clients. I read Joel on Software and took the Joel Test and realized I don't quite measure up. One place I am lacking is automated builds. What should I use to have automated builds? I have Windows apps that use .NET 1.1, 2.0, and 3.5. Also, I need to be able to build my .vdproj to create MSI's. I am looking for something that is free and would work well for a one-man team.</p>
|
<p><a href="http://www.cruisecontrolnet.org/" rel="nofollow">CruiseControl.Net</a> and <a href="http://nant.sourceforge.net/" rel="nofollow">NAnt</a> are the standard tools (and open source too), so there will be a lot of community support available. <a href="https://github.com/Microsoft/msbuild" rel="nofollow">MSBuild</a> is now open source, too</p>
<p>It will be quite a lot of work to set it all up, but it will be very powerful and have lots of room for growth too.</p>
|
Migrating Java UNO code from OpenOffice 2.4 to 3.0 <p>I had a nifty small tool written to convert spreadsheets to plain text.
Since it was my private hacker tool, it relied on OpenOffice 2.x to read the files.</p>
<p>But when I installed <strong>OpenOffice 3</strong> and tried to get it get it to run, I failed miserably, because I'm either missing some JAR files or half the classes have been replaced.</p>
<p>I'm including all five JAR files from URE/Java (URE: <a href="http://en.wikipedia.org/wiki/Universal_Network_Objects" rel="nofollow">UNO</a>
Runtime Environment, a subset of OpenOffice.org hosting and
managing UNO components) and am still missing these classes:</p>
<pre><code>com.sun.star.frame.XComponentLoader
com.sun.star.frame.XController
com.sun.star.frame.XDesktop
com.sun.star.frame.XModel
com.sun.star.frame.XStorable
com.sun.star.sheet.XSpreadsheet
com.sun.star.sheet.XSpreadsheetDocument
com.sun.star.sheet.XSpreadsheetView
com.sun.star.text.XTextDocument
</code></pre>
<p>Any pointers?</p>
|
<p>I found what I was missing.</p>
<p>I had to include the following jars</p>
<pre><code>URE/java/juh.jar
URE/java/jurt.jar
URE/java/ridl.jar
Basis/program/classes/unoil.jar
</code></pre>
<p>The last one I was missing before - <em>note the German OOo version</em>.</p>
<p>And, something I didn't have to do before, I had to include the path to the OOo executables, e.g.</p>
<pre><code>c:/program/OpenOffice.org 3/program/
</code></pre>
<p>After that and without changing code it worked just like before.</p>
<p>So, Brian, UNO's API is stable even between major releases. It was just the classpath I had to fix.</p>
|
Why does Convert.ToDouble(string) round? <p>For example, Convert.ToDouble("0.1234567890123456789") = 0.123456789012346</p>
<p>What is the maximum number of significant figures? Couldn't find it in the docs.</p>
|
<p>Of course there's a maximum precision. It's the maximum that you can express with the bits used to store the double. For that string you might try Decimal instead.</p>
|
Silverlight 2 UI pattern <p>I have to build small (for now) admin app in Silverlight2, and would like to use some pattern for binding UI with my BL/DAL.<br />
I found view-model-viewmodel and mvp/mvc patterns, where first one (V/M/VM) is specially suited for WPF apps, because it uses rich capabilities of WPF data-binding options. What do you suggest? Can you write simple example of V/M/VM for SL2?</p>
|
<p>Nikhil Kothari has a great set of examples (with code) on M-V-VM in Silverlight as well as a framework built with some very nice extra features. You should definitely check them out.
<a href="http://nikhilk.net/Silverlight-ViewModel-Pattern.aspx" rel="nofollow" title="M-V-VM in Silverlight">M-V-VM in Silverlight</a></p>
|
Error when compiling with Windows DDK <p>Forgive me for being a complete newbie with Windows DDK.</p>
<p>I have create a simple file named <code>test.cpp</code>:</p>
<pre><code>#include <windows.h>
#define BAD_ADDRESS 0xBAADF00D
int __cdecl main(int argc, char* args[])
{
char* p =(char*)BAD_ADDRESS;
*p='A';
return 0;
}
</code></pre>
<p>In the same directory I created a <code>sources</code> file like this:</p>
<pre>
TARGETNAME=test
TARGETTYPE=PROGRAM
TARGETPATH=obj
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib
SOURCES= test.cpp
</pre>
<p>And a <code>makefile</code> like this:</p>
<pre>
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the components of Windows
#
!INCLUDE $(NTMAKEENV)\makefile.def
</pre>
<p>After launching the Windows XP Free Build Environment I browse to the directory with the three files (test.cpp, makefile and sources) and run the following command:</p>
<pre>F:\temp\debug\dir1>build -cZg</pre>
Which outputs:
<pre>
BUILD: Adding /Y to COPYCMD so xcopy ops won't hang.
BUILD: Using 2 child processes
BUILD: Object root set to: ==> objfre_wxp_x86
BUILD: Compile and Link for i386
BUILD: Examining f:\temp\debug\dir1 directory for files to compile.
BUILD: Compiling (NoSync) f:\temp\debug\dir1 directory
1>Compiling - test.cpp for i386
BUILD: Compiling f:\temp\debug\dir1 directory
BUILD: Linking f:\temp\debug\dir1 directory
1>Linking Executable - objfre_wxp_x86\i386\test.exe for i386
BUILD: Done
2 files compiled
1 executable built
</pre>
<p>The problem is that when I run the created executable <code>test.exe</code> it says:</p>
<pre>
F:\temp\debug\dir1\objfre_wxp_x86\i386>test
The F:\temp\debug\dir1\objfre_wxp_x86\i386\test.exe application cannot be run in Win32 mode.
</pre>
<p><strong>What am I missing here?</strong></p>
|
<p>You have compiled a 'native application' rather than a win32 one. The TARGET_TYPE definition controls this.</p>
<p>See '<a href="http://technet.microsoft.com/en-us/sysinternals/bb897447.aspx" rel="nofollow">Inside Native Applications</a>' for a discussion of using the DDK to generate a native application.</p>
|
How do you compile flex in Visual Studio 2005/2008? <p>I can't figure this one out. I can download a win32 binary of flex 2.5.4a from gnuwin32, but I'd like to build the latest version (2.5.35) using Visual Studio 2005. I suppose I could build in in cygwin, but where is the fun in that?</p>
<p><a href="http://flex.sourceforge.net/" rel="nofollow">http://flex.sourceforge.net/</a></p>
|
<p>Note that Flex is seriously out-of-date on Windows when it comes to generating C++ scanners. Recent Flex versions which are able to generate ISO C++ scanners do not support Win32 (MinGW or VS), so you're probably better of trying to generate a C scanner and call it from C++.</p>
|
How to sanity check a date in java <p>I find it curious that the most obvious way to create Date objects in Java has been deprecated and appears to have been "substituted" with not so obvious to use lenient calendar. So...</p>
<p>How do you check that a date given as a combination of day, month and year is a valid date? For instance a date 2008-02-31 (as in yyyy-mm-dd) would be invalid date. </p>
|
<p>Key is <strong>df.setLenient(false);</strong>. This is more than enough for simple cases. If you are looking for a more robust (I doubt) and/or alternate libraries like joda-time then look here (not the accepted answer but the answer from the user named "tardate"): <a href="http://stackoverflow.com/questions/226910/how-to-sanity-check-a-date-in-java">How to sanity check a date in java</a></p>
<pre><code>final static String DATE_FORMAT = "dd-MM-yyyy";
public static boolean isDateValid(String date)
{
try {
DateFormat df = new SimpleDateFormat(DATE_FORMAT);
df.setLenient(false);
df.parse(date);
return true;
} catch (ParseException e) {
return false;
}
}
</code></pre>
|
What's the best open source game to learn from? <blockquote>
<p>This question has been preserved for historical reasons, but it is not
considered on-topic, so don't use it as an excuse to post something
similar.</p>
<p>More info at <a href="http://stackoverflow.com/faq">http://stackoverflow.com/faq</a>.</p>
</blockquote>
<hr>
<p>For me to read code and learn, not to play...</p>
<p>...of course ;-)</p>
|
<p><a href="ftp://ftp.idsoftware.com/idstuff/source/">Quake</a> (1,2 and 3) and <a href="http://www.3drealms.com/downloads.html#duke3d">DukeNukem 3D</a> source code is available under the GPL.</p>
|
Google Maps API - GMarker.openInfoWindowHtml() stopped working <p>I have a Google Map that suddenly stopped working for no apparent reason (I hadn't touched the code for months, but the wrapper code from our CMS may have changed without Corporate telling me).</p>
<p><a href="http://www.democratandchronicle.com/section/builder" rel="nofollow">http://www.democratandchronicle.com/section/builder</a></p>
<p>(sorry about the nasty HTML outside the map, most of that comes from our corporate parent...)</p>
<p>I've narrowed it down to this part of my <code>drawMarker</code> function:</p>
<pre><code>GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html, { maxWidth: 500 });
});
</code></pre>
<p>Of note:</p>
<ul>
<li><code>alert(html);</code> displays the correct HTML for the infowindow.</li>
<li>The HTML in the html variable is indeed valid.</li>
<li>The click event is firing (confirmed by <code>alert('test');</code> within it)</li>
<li>Another map I host on the same site <a href="http://www.democratandchronicle.com/garagesales" rel="nofollow">works fine</a>, despite similar code.</li>
<li>No JavaScript errors in Firebug or IE that I can see.</li>
</ul>
<p>I've been bashing my head against this for a while. What am I missing?</p>
|
<p>I've had random problems with Google Maps API at times and more than once it has been fixed by going back one API version. i.e. if your google maps API javascript inclusion string is like this <code>http://maps.google.com/maps?file=api&v=2.xd&key=XXXXX</code>
change the <strong>2.x</strong> to something a few versions back (back when it was working) like <strong>2.132</strong> or something</p>
|
Is it acceptable to "borrow" dependency properties from unrelated classes? <p>I'm writing a class that renders some content in WPF, and I want to give the user control over how the content is rendered. The rendering is mostly stroking lines, so I decided to look to the System.Windows.Forms.Shapes.Line class to get an idea of what properties I might want to implement. This led me to implement most of the <code>StrokeXXXX</code> properties, and it's a lot of drudgework since each requires metadata to affect the rendering.</p>
<p>A colleague suggested that I just "borrow" the properties from Shape like this:</p>
<pre><code>Shape.StrokeThicknessProperty.AddOwner(typeof(MyType));
</code></pre>
<p>This seems like a pretty good idea. I thought that by doing this I'd lose the ability to set coercion and property changed callbacks, but it looks like the overload that takes a PropertyMetadata allows this. The only downside I can see is if the implementation of Shape changes, it will affect our class, but I'm uncertain how often I expect the .NET interfaces to change significantly.</p>
<p>What do you think? Is this a decent shortcut to defining properties when a well-known class has the behavior you want and a stable interface, or a sure-fire way to play with fire while in a gasoline bath?</p>
|
<p>It is very safe and useful to borrow DPs... Read the <a href="http://www.drwpf.com/blog/Home/tabid/36/EntryID/20/Default.aspx" rel="nofollow">following</a> post by Dr WPF about the subject!</p>
<p>Here is a few of the "tips" he provide:</p>
<ul>
<li>You should always know what the owner class does with any property you borrow. </li>
<li>You should pay attention to default values and inheritance. Sometimes you need a bool property with a default value of true... other times you may want a default value of false. Sometimes you need a property that inherits... other times you explicitly don't want inheritance. (Borrowing a property like TextElement.FontSize could really screw up things lower in the tree.)</li>
<li>The owner class may sometimes define a PropertyChangedCallback that will interfere with your ability to use the property as you wish. Always know what the owner class does with the property.</li>
<li>The owner class may provide a validation routine for the property that prevents you from entering the value you want to specify. Again, always know what the owner class does with the property.
The property may be registered in a manner that makes it costly perf-wise, such as FixedPage.Bottom which invalidates the parent's arrange anytime the property changes on an object. Sometimes you may explicitly want this behavior... other times it will just unnecessarily cause layout passes. Again, always know what the owner class does with the property.</li>
<li>If you use a property in a scenario where the framework itself is trying to use the property (such as TextSearch.TextPath on an ItemsControl), you are liable to find yourself in contention with the framework.</li>
</ul>
|
Hibernate returns invalid results with composite key <p>I'm getting the strangest results. I have a class with a composite key.
If i do the following query:</p>
<blockquote>
<p>from LOVEJB l order by l.canonicalId
desc</p>
</blockquote>
<p>my results are not ordered by the '<strong>canonicalId</strong>' column I asked for. Instead, the canonical id result is like:</p>
<blockquote>
<p>823 823 822 823 ,,,</p>
</blockquote>
<p>Can someone give me some pointers on how should I try to crack this? I already messed up with <em>hashcodes</em> and <em>equals</em>, I experimented with a new class, etc. to no avail.</p>
|
<p>I found out. My composite key had columns that were not part of the table's primary key. Thanks all.</p>
|
C# Speech Recognition - Is this what the user said? <p>I have need to write an application which uses a speech recognition engine -- either the built in vista one, or a third party one -- that can display a word or phrase, and recognise when the user reads it (or an approximation of it). I also need to be able to switch quickly between languages, without changing the language of the operating system.</p>
<p>The users will be using the system for very short periods. The application needs to work without the requirement of first training the recognition engine to the users' voices.</p>
<p>It would also be fantastic if this could work on Windows XP or lesser versions of Windows Vista.</p>
<p>Optionally, the system needs to be able to read information on the screen back to the user, in the user's selected language. I can work around this specification using pre-recorded voice-overs, but the preferred method would be to use a text-to-speech engine.</p>
<p>Can anyone recommend something for me?</p>
|
<p>A similar question was asked on Joel on Software a while back. You can use the <a href="http://msdn.microsoft.com/en-us/library/system.speech.recognition.aspx">System.Speech.Recognition</a> namespace to do this...with some limitations. Add System.Speech (should be in the GAC) to your project. Here's some sample code for a WinForms app:</p>
<pre><code>public partial class Form1 : Form
{
SpeechRecognizer rec = new SpeechRecognizer();
public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}
void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
lblLetter.Text = e.Result.Text;
}
void Form1_Load(object sender, EventArgs e)
{
var c = new Choices();
for (var i = 0; i <= 100; i++)
c.Add(i.ToString());
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}
</code></pre>
<p>This recognizes the numbers from 1 to 100, and displays the resulting number on the form. You'll need a form with a label called lblLetter on it.</p>
<p>System.Speech only works with a pre-defined list of words or phrases; it's not exactly NaturallySpeaking, either in versatility or in recognition quality. But you don't have to train it to the user's voice, and if you only have a few different things the user can say, it works reasonably well. And it's free! (if you have Visual Studio)</p>
<p>It won't work well if you use very short phrases; I made a program for my kid to say letters of the alphabet and see them on-screen, but it doesn't do that well since many of the letters sound alike (especially from the mouth of a four-year-old).</p>
<p>As for more flexible options...well, there's the aforementioned NaturallySpeaking, which has an SDK. But you have to contact sales to get any sort of access to it, and no pricing is listed, so it comes across as one of those "How much does it cost? Well, how much have you got?" kind of things. There doesn't seem to be a "download and play around with it" option. :(</p>
<p>As for text-to-speech, <a href="http://msdn.microsoft.com/en-us/library/system.speech.synthesis.aspx">System.Speech.Synthesis</a> does this. It's even easier than the speech recognition. I wrote a small program to let me type, hit Enter, and read the text aloud. My four-year-old gets mesmerized by it. :) ("Daddy, I wanna tawk to da wobot.")</p>
|
How to find number of lines changed between CVS versions? <p>I've spent most of the day making what are basically some housekeeping changes to the codebase of one of our projects (replacing all <code>System.out.println()</code> calls with log4j).</p>
<p>I'm kind of curious how many lines of code I've updated with this set of changes.</p>
<p>Is there anyway with <code>cvs diff</code> or another command to get an accurate count of how many lines have changed?</p>
<p>I've tried</p>
<pre><code>cvs diff -b -B -R
</code></pre>
<p>to get all of the changes in the working directory (and recursively the subdirectories), but for each file changed it also prints out file/version information, which makes just counting the lines of output useless.</p>
<p>Any ideas?</p>
|
<p>The <a href="http://invisible-island.net/diffstat/">diffstat</a> utility is a nice tool for getting some simple metrics from the output of cvs, svn or other diffs.</p>
|
Visual Studio Solution Explorer Locks Up <p>I have an issue with Visual Studio 2005 w/ TFS where, from time to time, the Solution Explorer will stop responding to interaction. Instead it does the beep, like I'm trying to click on a parent window with a modal dialog visible, but there isn't one. The only thing I've found to do so far, is to restart VS, but that's kind of a pain because our solution is rather large. And it's not even a guarantee... it might happen again when I load the solution.</p>
<p>I was curious if anyone else has had this problem and knows of a better solution that restarting VS until it goes away.</p>
<p>[Edit: 6-11-2010] I've since moved over to VS 2008 and haven't had this problem since.</p>
|
<p>If VS Editor lockdown is accompanied by creation of <strong>Setup.exe</strong> process that never finishes (visible in the task manager), then this is an issue with Microsoft Office 2007 components.</p>
<p>The solution that has worked for me - reinstalling Microsoft Office 2007. <a href="http://abdullin.com/journal/2009/5/12/visual-studio-2008-locks-or-freezes-in-aspx.html" rel="nofollow">More details</a>.</p>
|
Software protection by encryption <p>For our software we use hardware dongles to protect the software. No protection is perfect but this commercial solution is affordable and keeps honest people honest (as mentioned in another thread). The advantage is the 128 bit key that is stored 'unreadable' on the hardware dongle. </p>
<p>We want to remove this hardware dongle and start using software protection. Basically we can use a commercial product, but on the other hand that won't be unbreakable either. I don't know much about encryption and that's why I am posting this. How do I store a key on a Windows computer that will not be possible to read by using Reflector or something else? However I should be able to access the key for testing the license code.</p>
<p>I would just like a simple solution that can't be hacked by simply using Reflector.</p>
<p>Or am I asking a very stupid question?</p>
<hr>
<p>Thank you all for your very fast and useful replies. I don't want to use licensing over the internet, since the application is running not always on computers that are connected. I will then get probably more problems then solving them. We will now most probably go for a commercial solution. It seems that protection is not that trivial. </p>
<p>Thanks a lot!!</p>
|
<p>There is no way to completely secure the key. If it can be read by your program, then it can be read by another program.</p>
|
Best practice for a collection of generic classes <p>Consider the following code:</p>
<pre><code>abstract class SomeClassX<T>
{
// blah
}
class SomeClassY: SomeClassX<int>
{
// blah
}
class SomeClassZ: SomeClassX<long>
{
// blah
}
</code></pre>
<p>I want a collection of SomeClassX<T>'s, however, this isn't possible since SomeClassX<int> != SomeClassX<long> and List<SomeClassX<>> isn't allowed.</p>
<p>So my solution is to have SomeClassX<T> implement an interface and define my collection as, where ISomeClassX is the interface:</p>
<pre><code>class CollectionOfSomeClassX: List<ISomeClassX>
{
// blah
}
</code></pre>
<p>Is this the best way to do this, or is there better way?</p>
|
<p>I would either use the interface you suggested, or make SomeClassX inherit from another class. It really depends on what you need to do with the objects in your collection. Whatever functionality they are going to have in common should go in a base class, or interface if that seems more appropriate.</p>
|
Suggestions to improve VB.NET URL shortener? <p>Here is my function (<strong>updated</strong>):</p>
<pre><code>Public Shared Function shortenUrl(ByVal URL As String) As String
Return shortenUrl(URL, 32)
End Function
Public Shared Function shortenUrl(ByVal URL As String, ByVal maxLength As Integer) As String
If URL.Length > maxLength Then
String.Format("{0}...{1}", URL.Substring(0, (maxLength / 2)), URL.Substring(URL.Length - ((maxLength / 2) - 3)))
Else
Return URL
End If
End Function
</code></pre>
<p>I fixed the problem where it didn't return <code>maxLength</code> chars because it didn't take into account the ellipses.</p>
<p><hr /></p>
<p>It seems to me that it is too complicated; any suggestions, comments, concerns are more than welcome.</p>
|
<p>Why not do this?</p>
<pre><code>Public Shared Function shortenUrl(ByVal URL As String) As String
Return shortenUrl(URL, 29)
End Function
Public Shared Function shortenUrl(ByVal URL As String, ByVal maxLength As Integer) As String
If URL.Length > maxLength Then
Return String.Format("{0}...{1}", URL.Substring(0, maxLength / 2),URL.Substring(URL.Length - (maxLength / 2)))
Else
Return URL
End If
End Function
</code></pre>
<p>That at least gets rid of all of the tempoary declarations</p>
|
Select Box onClick - Rails <p>I have a Rails application that in the erb code, I use a select box. What I would like to do is reload the page passing the sort parameter. My controller already handles it, but I don't know how to reload the page with the selected value from my select box. Here is my code:</p>
<pre><code><% @options = {:latest => 'lastest' , :alphabetical => 'alphabetical', :pricelow => 'price-low', :pricehigh =>'pricehigh'} %>
<%= select_tag 'sort[]', options_for_select(@options), :include_blank => true,:onchange => "location.reload('location?sort='+this.value)"%>
</code></pre>
|
<p>Have you considered using an ajax call on your list box? If you have a method on your controller that returns just the sorted list, based on sort parameter, then you could do:</p>
<pre><code><% @options = {:latest => 'lastest' , :alphabetical => 'alphabetical', :pricelow => 'price-low', :pricehigh =>'pricehigh'} %>
<%= select_tag 'sort[]', options_for_select(@options), :include_blank => true,:onchange => remote_function(:url => {:controller => 'your_controller', :action => 'list_sort_method'}, :with => "'sort='+this.value", :update => "div_containing_list") %>
</code></pre>
|
Simple Search: Passing Form Variable to URI Using CodeIgniter <p>I have a search form on each of my pages. If I use form helper, it defaults to <code>$_POST</code>. I'd like the search term to show up in the URI:</p>
<pre><code>http://example.com/search/KEYWORD
</code></pre>
<p>I've been on Google for about an hour, but to no avail. I've only found articles on how <code>$_GET</code> is basically disabled, because of the native URI convention. I can't be the first person to want this kind of functionality, am I? Thanks in advance!</p>
|
<p>There's a better fix if you're dealing with people without JS enabled.</p>
<p><strong>View:</strong></p>
<pre><code><?php echo form_open('ad/pre_search');?>
<input type="text" name="keyword" />
</form>
</code></pre>
<p><strong>Controller</strong> </p>
<pre><code><?php
function pre_search()
{
redirect('ad/search/.'$this->input->post('keyword'));
}
function search()
{
// do stuff;
}
?>
</code></pre>
<p>I have used this a lot of times before.</p>
|
JSTL, Beans, and method calls <p>I'm working on a JSP where I need to call methods on object that come from a Bean. The previous version of the page does not use JSTL and it works properly. My new version has a set up like this:</p>
<pre><code><jsp:useBean id="pageBean" scope="request" type="com.epicentric.page.website.PageBean" />
<c:set var="pageDividers" value="<%= pageBean.getPageDividers() %>" />
<c:set var="numColumns" value="${pageDividers.size()}" />
</code></pre>
<p>The variable <code>pageDividers</code> is a <code>List</code> object.</p>
<p>I'm encountering this issue: when I ask for <code>pageDivider</code>'s size, an exception is thrown. I know this is a simple JTSL error -- what am I doing wrong?</p>
<p>The error message is:</p>
<blockquote>
<p>The function size must be used with a prefix when a default namespace is not specified</p>
</blockquote>
<p>How do I correctly access or call the methods of my <code>pageDividers</code> object?</p>
|
<p>When using the dot operator for property access in JSTL, <code>${pageDividers.size}</code> (no <strong>()</strong> needed) results in a call to a method named <code>getSize()</code>.<br />
Since java.util.List offers a method called <code>size()</code> (rather than <code>getSize()</code>) you won't be able to access the list length by using that code.</p>
<p><hr /></p>
<p>In order to access to a list size, JSTL offers the <strong>fn:length</strong> function, used like</p>
<pre><code>${fn:length(pageDividers)}
</code></pre>
<p>Note that in order to use the <strong>fn</strong> namespace, you should declare it as follows</p>
<pre><code><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
</code></pre>
<p>In addition, the same function can be used with any collection type, and with Strings too.</p>
|
How to Dynamically add menu items to master page in ASP.NET 3.5 MVC app <p>I want to dynamically add menuitems to my master page based on membership security login role. From what I've read RenderAction in the master page html could perhaps do this. Since I'm fumbling thru this I am not sure how it would look and how in the controller I check my current role. I am considering creating a table and relating the allowable menu items to role relationship so I can pass to the master page for rendering the dynamic menu items. Any suggestions answers or comments appreciated. Thanks - Mike</p>
|
<p>In the controller, I would create a MenuModel class or the like, that is the model for your menu. It would be a data only class. Create and populate it in the controller, taking into consideration the current user's access permissions. This will allow you to write unit tests that ensure your security code is correct.</p>
<p>Then I'd pass that to the view via ViewData. I'd combine that with a helper method that knows how to render the menu based on the MenuModel class.</p>
|
Unique identifier for an iPhone app <p>For an iPhone app that submits images to a server I need somehow to tie all the images from a particular phone together. With every submit I'd like to send some unique phone id. Looked at <pre>
[[UIDevice mainDevice] uniqueIdentifier]<br />
and
[[NSUserDefaults standardDefaults] stringForKey:@"SBFormattedPhoneNumber"]
</pre></p>
<p>but getting errors in the simulator.</p>
<p>Is there an Apple sanctioned way of doing this?</p>
|
<p>What errors are you getting? <code>[[UIDevice currentDevice] uniqueIdentifier]</code> (<i>edited to fix API, thanks Martin!</i>) is the officially recommended way of doing this.</p>
|
Question about skipping IDs in an identity column in MSSQL <p>Say I have an MSSQL table with two columns: an int ID column that's the identity column and some other datetime or whatever column. Say the table has 10 records with IDs 1-10. Now I delete the record with ID = 5.</p>
<p>Are there any scenarios where another record will "fill-in" that missing ID? I.e. when would a record be inserted and given an ID of 5?</p>
|
<p>No, unless you specifically enable identity inserts (typically done when copying tables with identity columns) and insert a row manually with the id of 5. SQLServer keeps track of the last identity inserted into each table with identity columns and increments the last inserted value to obtain the next value on insert.</p>
|
Apart from initial cost, are there any other benefits of using MySQL over MSQL server with .net? <p>I've used both and I've found MySql to have several frustrating bugs, limited support for: IDE integration, profiling, integration services, reporting, and even lack of a decent manager. Total cost of ownership of MSSQL Server is touted to be less than MySQL too (.net environment), but maintaining an open mind could someone point out any killer features of MySql?</p>
|
<p>I've used MySQL in the past and I'm using MSSQL lately but I can't remember anything that MySQL has and MSSQL can't do. </p>
<p>I think the most killer feature of MySQL it's the simplicity. For some projects you just don't need all the power you can have with a huge system like MSSQL. I have an UNIX heritage and find the simple configuration file like my.ini a killer feature of MySQL.</p>
<p>Also the security system of MySQL is much less robust but it makes the job right for most of applications. I believe MySQL it's killer itself from this point of view, and should stay that way, letting young users being introduced to RDBMS with a simple view first. If your project gets big enough that you are considering switch to a more robust system, then MSSQL can pop as a possibility. </p>
<p>That's what happened to me.</p>
|
Passing a list while retaining the original <p>So I'm teaching myself Python, and I'm having an issue with lists. I want to pass my function a list and pop items off it while retaining the original list. How do I make python "instance" the passed list rather that passing a pointer to the original one?</p>
<p>Example:</p>
<pre><code>def burninate(b):
c = []
for i in range(3):
c.append(b.pop())
return c
a = range(6)
d = burninate(a)
print a, d
</code></pre>
<p>Output: [0, 1, 2] [5, 4, 3]<br>
Desired output: [0, 1, 2, 3, 4, 5] [5, 4, 3]</p>
<p>Thanks!</p>
|
<p>As other answers have suggested, you can provide your function with a copy of the list.</p>
<p>As an alternative, your function could take a copy of the argument:</p>
<pre><code>def burninate(b):
c = []
b = list(b)
for i in range(3):
c.append(b.pop())
return c
</code></pre>
<p>Basically, you need to be clear in your mind (and in your documentation) whether your function will change its arguments. In my opinion, functions that return computed values should not change their arguments, and functions that change their arguments should not return anything. See python's [].sort(), [].extend(), {}.update(), etc. for examples. Obviously there are exceptions (like .pop()).</p>
<p>Also, depending on your particular case, you could rewrite the function to avoid using pop() or other functions that modify the argument. e.g.</p>
<pre><code>def burninante(b):
return b[:-4:-1] # return the last three elements in reverse order
</code></pre>
|
Why is it bad to use an iteration variable in a lambda expression <p>I was just writing some quick code and noticed this complier error </p>
<blockquote>
<p>Using the iteration variable in a lambda expression may have unexpected results.<br>
Instead, create a local variable within the loop and assign it the value of the iteration variable.</p>
</blockquote>
<p>I know what it means and I can easily fix it, not a big deal.<br>
But I was wondering why it is a bad idea to use a iteration variable in a lambda?<br>
What problems can I cause later on?</p>
|
<p>Consider this code:</p>
<pre><code>List<Action> actions = new List<Action>();
for (int i=0; i < 10; i++)
{
actions.Add(() => Console.WriteLine(i));
}
foreach (Action action in actions)
{
action();
}
</code></pre>
<p>What would you expect this to print? The obvious answer is 0...9 - but actually it prints 10, ten times. It's because there's just one variable which is captured by all the delegates. It's this kind of behaviour which is unexpected.</p>
<p>EDIT: I've just seen that you're talking about VB.NET rather than C#. I believe VB.NET has even more complicated rules, due to the way variables maintain their values across iterations. <a href="http://blogs.msdn.com/b/vbteam/archive/2007/07/26/closures-in-vb-part-5-looping.aspx">This post by Jared Parsons</a> gives some information about the kind of difficulties involved - although it's back from 2007, so the actual behaviour may have changed since then.</p>
|
Programatic Accent Reduction in JavaScript (aka text normalization or unaccenting) <p>I need to compare 2 strings as equal such as these:</p>
<blockquote>
<p>Lubeck == Lübeck</p>
</blockquote>
<p>In JavaScript.</p>
<p>Why? Well, I have an auto-completion field that's going out to a Java service using Lucene, where place names are stored naturally (as Lübeck), but also indexed as normalized text, </p>
<pre><code>import sun.text.Normalizer;
oDoc.setNameLC = Normalizer.normalize(oLocName, Normalizer.DECOMP, 0)
.toLowerCase().replaceAll("[^\\p{ASCII}]","");
</code></pre>
<p>This way some-one who doesn't know to type "Mèxico" can type "mexico" and get a match which returns "Mèxico" (among a lot of other possible hits, like "Café Mèxico, Dubai, UAE").</p>
<p>Now the thing is I don't have the ability to change the service to do any highlighting on the server side, therefore I am highlighting on the client JavaScript side with something like:</p>
<pre><code>return result.replace( input.replace(/[aeiou]/g,"."), "<b>$1</b>");
</code></pre>
<p>It's a little more fancy because I am escaping special regex characters in the input. This is fine for simple one word matches at the beginning of a hit, but it really breaks down if you suddenly wish to support multi-word matches like "london cafe":</p>
<pre><code>input = input.strip().toLowerCase(); //fyi prototype's strip is like trim
re = new RegEx(input.replace(/[aeiou]/g,".").replace(/\s+/g,"|"),"gi");
return result.replace(re, "<b>$1</b>");
</code></pre>
<p>This doesn't work for say "london ca" (was typing london cafe), because it would mark "Jack London Cabin, Dawson City, Canada" as: <code>"Ja<b>ck</b> <b>London</b> <b>ca</b>bin, Dawson <b>Ci</b>ty, <b>Ca<b/>nada"</code> [note the "ck" and "Ci" particularly]</p>
<p>Therefore I'm sort of looking for something that's not as crazy as:</p>
<pre><code>input = input.strip().toLowerCase();
input = input.replace(/a/g,"[Ãà ÃáÃâÃãÃäÃ
̴̾ÄÄÄÄÄÄ
]");
input = input.replace(/e/g,"[ÃèÃéÃêÃëÄÄÄÄÄÄÄÄÄÄ]");
// ditto for i, o, u, y, c, n, maybe also d, g, h, j, k, l, r, s, t, w, z
re = new RegEx(input.replace(/\s+/g,"|"),"gi");
return result.replace(re, "<b>$1</b>");
</code></pre>
<p>Is there a compiled table I can refer to mapping a range of characters which are accented versions of an other character to that character, by which I don't mean the plain unicode chart. And if so, could I avoid using weird, possibly slow, RegEx statements?</p>
<p><em>About the bounty:</em><br />
Before I started a bounty there were two answers, the one pointing me to doing it in Ruby, and <a href="http://stackoverflow.com/questions/227950/programatic-accent-reduction-in-javascript-aka-text-normalization-or-unaccenting/228006#228006">the one</a> that <a href="http://stackoverflow.com/users/22364/mizardx">MizzardX</a> wrote which was a completion of the basic form I'd put in my question. Now don't get me wrong, I really appreciate working it out as completely as he did, but I just wished that there might be another way. It seems so far that everyone who's dropped by to look at the question and answer has decided that MizzardX covers it just fine, or that they have no different approach. I would be interested in a different approach, and if it simply isn't available before the bounty closes, MizzardX will win the bounty (though in a cruel twist, his edits mad it a community wiki answer, so I'm not sure if he'll get the bounty!)</p>
|
<pre><code>/**
* Creates a RegExp that matches the words in the search string.
* Case and accent insensitive.
*/
function make_pattern(search_string) {
// escape meta characters
search_string = search_string.replace(/([|()[{.+*?^$\\])/g,"\\$1");
// split into words
var words = search_string.split(/\s+/);
// sort by length
var length_comp = function (a,b) {
return b.length - a.length;
};
words.sort(length_comp);
// replace characters by their compositors
var accent_replacer = function(chr) {
return accented[chr.toUpperCase()] || chr;
}
for (var i = 0; i < words.length; i++) {
words[i] = words[i].replace(/\S/g,accent_replacer);
}
// join as alternatives
var regexp = words.join("|");
return new RegExp(regexp,'g');
}
var accented = {
'A': '[Aa\xaa\xc0-\xc5\xe0-\xe5\u0100-\u0105\u01cd\u01ce\u0200-\u0203\u0226\u0227\u1d2c\u1d43\u1e00\u1e01\u1e9a\u1ea0-\u1ea3\u2090\u2100\u2101\u213b\u249c\u24b6\u24d0\u3371-\u3374\u3380-\u3384\u3388\u3389\u33a9-\u33af\u33c2\u33ca\u33df\u33ff\uff21\uff41]',
'B': '[Bb\u1d2e\u1d47\u1e02-\u1e07\u212c\u249d\u24b7\u24d1\u3374\u3385-\u3387\u33c3\u33c8\u33d4\u33dd\uff22\uff42]',
'C': '[Cc\xc7\xe7\u0106-\u010d\u1d9c\u2100\u2102\u2103\u2105\u2106\u212d\u216d\u217d\u249e\u24b8\u24d2\u3376\u3388\u3389\u339d\u33a0\u33a4\u33c4-\u33c7\uff23\uff43]',
'D': '[Dd\u010e\u010f\u01c4-\u01c6\u01f1-\u01f3\u1d30\u1d48\u1e0a-\u1e13\u2145\u2146\u216e\u217e\u249f\u24b9\u24d3\u32cf\u3372\u3377-\u3379\u3397\u33ad-\u33af\u33c5\u33c8\uff24\uff44]',
'E': '[Ee\xc8-\xcb\xe8-\xeb\u0112-\u011b\u0204-\u0207\u0228\u0229\u1d31\u1d49\u1e18-\u1e1b\u1eb8-\u1ebd\u2091\u2121\u212f\u2130\u2147\u24a0\u24ba\u24d4\u3250\u32cd\u32ce\uff25\uff45]',
'F': '[Ff\u1da0\u1e1e\u1e1f\u2109\u2131\u213b\u24a1\u24bb\u24d5\u338a-\u338c\u3399\ufb00-\ufb04\uff26\uff46]',
'G': '[Gg\u011c-\u0123\u01e6\u01e7\u01f4\u01f5\u1d33\u1d4d\u1e20\u1e21\u210a\u24a2\u24bc\u24d6\u32cc\u32cd\u3387\u338d-\u338f\u3393\u33ac\u33c6\u33c9\u33d2\u33ff\uff27\uff47]',
'H': '[Hh\u0124\u0125\u021e\u021f\u02b0\u1d34\u1e22-\u1e2b\u1e96\u210b-\u210e\u24a3\u24bd\u24d7\u32cc\u3371\u3390-\u3394\u33ca\u33cb\u33d7\uff28\uff48]',
'I': '[Ii\xcc-\xcf\xec-\xef\u0128-\u0130\u0132\u0133\u01cf\u01d0\u0208-\u020b\u1d35\u1d62\u1e2c\u1e2d\u1ec8-\u1ecb\u2071\u2110\u2111\u2139\u2148\u2160-\u2163\u2165-\u2168\u216a\u216b\u2170-\u2173\u2175-\u2178\u217a\u217b\u24a4\u24be\u24d8\u337a\u33cc\u33d5\ufb01\ufb03\uff29\uff49]',
'J': '[Jj\u0132-\u0135\u01c7-\u01cc\u01f0\u02b2\u1d36\u2149\u24a5\u24bf\u24d9\u2c7c\uff2a\uff4a]',
'K': '[Kk\u0136\u0137\u01e8\u01e9\u1d37\u1d4f\u1e30-\u1e35\u212a\u24a6\u24c0\u24da\u3384\u3385\u3389\u338f\u3391\u3398\u339e\u33a2\u33a6\u33aa\u33b8\u33be\u33c0\u33c6\u33cd-\u33cf\uff2b\uff4b]',
'L': '[Ll\u0139-\u0140\u01c7-\u01c9\u02e1\u1d38\u1e36\u1e37\u1e3a-\u1e3d\u2112\u2113\u2121\u216c\u217c\u24a7\u24c1\u24db\u32cf\u3388\u3389\u33d0-\u33d3\u33d5\u33d6\u33ff\ufb02\ufb04\uff2c\uff4c]',
'M': '[Mm\u1d39\u1d50\u1e3e-\u1e43\u2120\u2122\u2133\u216f\u217f\u24a8\u24c2\u24dc\u3377-\u3379\u3383\u3386\u338e\u3392\u3396\u3399-\u33a8\u33ab\u33b3\u33b7\u33b9\u33bd\u33bf\u33c1\u33c2\u33ce\u33d0\u33d4-\u33d6\u33d8\u33d9\u33de\u33df\uff2d\uff4d]',
'N': '[Nn\xd1\xf1\u0143-\u0149\u01ca-\u01cc\u01f8\u01f9\u1d3a\u1e44-\u1e4b\u207f\u2115\u2116\u24a9\u24c3\u24dd\u3381\u338b\u339a\u33b1\u33b5\u33bb\u33cc\u33d1\uff2e\uff4e]',
'O': '[Oo\xba\xd2-\xd6\xf2-\xf6\u014c-\u0151\u01a0\u01a1\u01d1\u01d2\u01ea\u01eb\u020c-\u020f\u022e\u022f\u1d3c\u1d52\u1ecc-\u1ecf\u2092\u2105\u2116\u2134\u24aa\u24c4\u24de\u3375\u33c7\u33d2\u33d6\uff2f\uff4f]',
'P': '[Pp\u1d3e\u1d56\u1e54-\u1e57\u2119\u24ab\u24c5\u24df\u3250\u3371\u3376\u3380\u338a\u33a9-\u33ac\u33b0\u33b4\u33ba\u33cb\u33d7-\u33da\uff30\uff50]',
'Q': '[Qq\u211a\u24ac\u24c6\u24e0\u33c3\uff31\uff51]',
'R': '[Rr\u0154-\u0159\u0210-\u0213\u02b3\u1d3f\u1d63\u1e58-\u1e5b\u1e5e\u1e5f\u20a8\u211b-\u211d\u24ad\u24c7\u24e1\u32cd\u3374\u33ad-\u33af\u33da\u33db\uff32\uff52]',
'S': '[Ss\u015a-\u0161\u017f\u0218\u0219\u02e2\u1e60-\u1e63\u20a8\u2101\u2120\u24ae\u24c8\u24e2\u33a7\u33a8\u33ae-\u33b3\u33db\u33dc\ufb06\uff33\uff53]',
'T': '[Tt\u0162-\u0165\u021a\u021b\u1d40\u1d57\u1e6a-\u1e71\u1e97\u2121\u2122\u24af\u24c9\u24e3\u3250\u32cf\u3394\u33cf\ufb05\ufb06\uff34\uff54]',
'U': '[Uu\xd9-\xdc\xf9-\xfc\u0168-\u0173\u01af\u01b0\u01d3\u01d4\u0214-\u0217\u1d41\u1d58\u1d64\u1e72-\u1e77\u1ee4-\u1ee7\u2106\u24b0\u24ca\u24e4\u3373\u337a\uff35\uff55]',
'V': '[Vv\u1d5b\u1d65\u1e7c-\u1e7f\u2163-\u2167\u2173-\u2177\u24b1\u24cb\u24e5\u2c7d\u32ce\u3375\u33b4-\u33b9\u33dc\u33de\uff36\uff56]',
'W': '[Ww\u0174\u0175\u02b7\u1d42\u1e80-\u1e89\u1e98\u24b2\u24cc\u24e6\u33ba-\u33bf\u33dd\uff37\uff57]',
'X': '[Xx\u02e3\u1e8a-\u1e8d\u2093\u213b\u2168-\u216b\u2178-\u217b\u24b3\u24cd\u24e7\u33d3\uff38\uff58]',
'Y': '[Yy\xdd\xfd\xff\u0176-\u0178\u0232\u0233\u02b8\u1e8e\u1e8f\u1e99\u1ef2-\u1ef9\u24b4\u24ce\u24e8\u33c9\uff39\uff59]',
'Z': '[Zz\u0179-\u017e\u01f1-\u01f3\u1dbb\u1e90-\u1e95\u2124\u2128\u24b5\u24cf\u24e9\u3390-\u3394\uff3a\uff5a]'
};
</code></pre>
|
Merge Facts from Different Sources? Or Load Separately? <p>We've got data with two different origins: some comes from a customer, some comes from different vendors. Currently, we physically "merge" this data into a massive table with almost a hundred columns, tens of thousands of rows and no formal separation of the two dimensions. Consequently, we can't actually use this table for much. </p>
<p>I'm going to redesign this mess into a proper, but small, star schema. </p>
<p>The two dimensions are obvious. One of them, for example, is time. </p>
<p>The customer-supplied data provides a number of fact values. Each vendor may (or may not) provide additional fact values that fit the same dimensions.</p>
<p>This fact data all has the same granularity. It can be called "sparse" because we don't often get information from all vendors.</p>
<p>Here's my dilemma.</p>
<p>Is this one fact table -- with some nulls -- populated from different sources?</p>
<p>Or is this <em>n</em>+1 fact tables -- one populated from the customer, the others populated from each vendor?</p>
<p>There are pros and cons to each design. I need some second opinions on the choice between "merge" or "load separately".</p>
<p><hr /></p>
<p>Customer supplies revenue, cost, counts, weights, and other things they know about their end of a transaction.</p>
<p>Vendor one supplies some additional details about some of the transactions -- weights, costs, durations. The other transactions will have no value from vendor one.</p>
<p>Vendor two supplies some additional details about some of the transactions -- volumes, durations, lengths, foreign currency rates. The other transactions will have no value for vendor two.</p>
<p>Some transactions will have both vendors. A few transactions will have neither vendor.</p>
<p>One table with nulls? Three tables?</p>
|
<p>I'd go for the single fact table. The highlight pro of this approach is that it leaves all the hard work at load time rather than at query time.</p>
|
Custom URI for HTTPListener? <p>Is there a way to add a custom prefix/URI that is not http or https? The HTTPListener.Prefixes.Add method only accepts http:// and https:// prefixes.</p>
<p>I just don't want to recreate the functionality of this class if I don't have to. </p>
|
<p>What did you have in mind? Mainly, I doubt it; besides, it will still only handle http[s], so why confuse things with a different scheme name? You can listen on a different port by adding it to the prefix list (eg "http://127.0.0.1:90/"), though. If a client connects on that port using the correct protocol (http vs https) then it would probably work - you'd just have a lot of work to do at the client to tell it how to handle that scheme.</p>
<p>I'm not sure I see a point, to be honest...</p>
|
Why is there not a register that contains the higher bytes of EAX? <p><code>%AX = (%AH + %AL)</code></p>
<p>So why not <code>%EAX = (%SOME_RESTIER + %AX)</code> for some register <code>%SOME_REGISTER</code>? </p>
|
<p>Just for some clarification. In the early microprocessor days of the 1970's, CPUs had only a small number of registers and a very limited instruction set. Typically, the arithmetic unit could only operate on a single CPU register, often referred to as the "accumulator". The accumulator on the 8 bit 8080 & Z80 processors was called "A". There were 6 other general purpose 8 bit registers: B, C, D, E, H & L. These six registers could be paired up to form 3 16 bit registers: BC, DE & HL. Internally, the accumulator was combined with the Flags register to form the AF 16 bit register.</p>
<p>When Intel developed the 16 bit 8086 family they wanted to be able to port 8080 code, so they kept the same basic register structure:</p>
<pre><code>8080/Z80 8086
A AX
BC BX
DE CX
HL DX
IX SI
IY DI
</code></pre>
<p>Because of the need to port 8 bit code they needed to be able to refer to the individual 8 bit parts of AX, BX, CX & DX. These are called AL, AH for the low & high bytes of AX and so on for BL/BH, CL/CH & DL/DH. IX & IY on the Z80 were only ever used as 16 bit pointer registers so there was no need to access the two halves of SI & DI.</p>
<p>When the 80386 was released in the mid 1980s they created "extended" versions of all the registers. So, AX became EAX, BX became EBX etc. There was no need to access to top 16 bits of these new extended registers, so they didn't create an EAXH pseudo register.</p>
<p>AMD applied the same trick when they produced the first 64 bit processors. The 64 bit version of the AX register is called RAX. So, now you have something that looks like this:</p>
<pre><code>|63..32|31..16|15-8|7-0|
|AH.|AL.|
|AX.....|
|EAX............|
|RAX...................|
</code></pre>
|
RegEx teaser <p>Let's say we have 2 php variables:</p>
<ul>
<li><strong>$name</strong> = 'caption';</li>
<li><strong>$url</strong> = '<a href="http://domain.com/photo.jpg" rel="nofollow">http://domain.com/photo.jpg</a>';</li>
</ul>
<p>The input string of <code>'{@url,<img src="," alt="{@name}" />}'</code> should return:</p>
<p><code>'<img src="http://domain.com/photo.jpg" alt="caption" />'</code></p>
<p>The <code>{tag}</code> takes up to 3 parameters: <code>{@variable[,text_before][,text_after]}</code>.</p>
<p>What regex would be needed to make this happen? The tricky part is that a <code>{@..}</code> tag is nested within another.</p>
|
<p>I think you've come across one of those situations where you <em>shouldn't</em> use regex.</p>
<p>much like this one.</p>
<p><a href="http://stackoverflow.com/questions/154708/multi-line-group-and-search-with-regex">http://stackoverflow.com/questions/154708/multi-line-group-and-search-with-regex</a>
<a href="http://stackoverflow.com/questions/154708/multi-line-group-and-search-with-regex#162194">http://stackoverflow.com/questions/154708/multi-line-group-and-search-with-regex#162194</a></p>
|
Removing file locks <p>I need to recover form an error case where a file gets left in a locked state. How can I in c# tell this file to reset it's locks? I need to add to this the file is opened by a 3rd party dll and I don't actually have access to the file handle.</p>
|
<p>Locking a file is the responsibility of the Operating System (on behalf of the program that opens it). If a file is left in a locked state, its really up to the OS to unlock. This typically happens automatically when the process that opened the file exits.</p>
<p>There is, however, a really cool utility that I came across that will help. It's called <a href="http://www.emptyloop.com/unlocker/" rel="nofollow">Unlocker</a>.</p>
|
Looking for alternatives or improvements to drop down lists/menus on websites <p>Drop-down lists, menus and combo boxes are all very common user interface elements. Users are accustomed to seeing these elements in native applications and sometimes web apps, but there are a few problems with them. </p>
<ol>
<li><p>You have to aim the mouse. Some menus collapse when you mouse out, and some have submenus that you have to aim at to expand.</p></li>
<li><p>You can't see the options without aiming the mouse first.</p></li>
</ol>
<p>These are the main things that trouble me, maybe other people notice other issues as well. I normally don't use drop-down menus at all if I can help it.</p>
<p>The problem is that I sometimes want to present a long list of options in limited space. Issue 2 is a sacrifice I'm willing to make, but I'm wanting to know if anyone has any tricks to make these drop menus easier to use. Maybe someone has invented a new style of list control.</p>
<p>I'm sure that if these types of controls annoy me, then they annoy users of my site more.</p>
|
<p>Hmm..one more thing which annoys me about the dropdown list is the inability to control their width as it expands with the text (or is their something which I am unaware of ?).</p>
<p>For an alternate, I think about a little popup which initially displays a list of available options in form of Alphabetic index and when the user clicks on an alphabet link, it displays the relevant options to select from. This will reduce the options to select from.</p>
<p>On the same terms, we can use ajax to build the options on the fly as user types in. </p>
|
What is the best method for getting a database connection/object into a function in PHP? <p>A couple of the options are:</p>
<pre><code>$connection = {my db connection/object};
function PassedIn($connection) { ... }
function PassedByReference(&$connection) { ... }
function UsingGlobal() {
global $connection;
...
}
</code></pre>
<p>So, passed in, passed by reference, or using global. I'm thinking in functions that are only used within 1 project that will only have 1 database connection. If there are multiple connections, the definitely passed in or passed by reference.</p>
<p>I'm thining passed by reference is not needed when you are in PHP5 using an object, so then passed in or using global are the 2 possibilities.</p>
<p>The reason I'm asking is because I'm getting tired of always putting in $connection into my function parameters.</p>
|
<p>I use a Singleton ResourceManager class to handle stuff like DB connections and config settings through a whole app:</p>
<pre><code>class ResourceManager {
private static $DB;
private static $Config;
public static function get($resource, $options = false) {
if (property_exists('ResourceManager', $resource)) {
if (empty(self::$$resource)) {
self::_init_resource($resource, $options);
}
if (!empty(self::$$resource)) {
return self::$$resource;
}
}
return null;
}
private static function _init_resource($resource, $options = null) {
if ($resource == 'DB') {
$dsn = 'mysql:host=localhost';
$username = 'my_username';
$password = 'p4ssw0rd';
try {
self::$DB = new PDO($dsn, $username, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
} elseif (class_exists($resource) && property_exists('ResourceManager', $resource)) {
self::$$resource = new $resource($options);
}
}
}
</code></pre>
<p>And then in functions / objects / where ever:</p>
<pre><code>function doDBThingy() {
$db = ResourceManager::get('DB');
if ($db) {
$stmt = $db->prepare('SELET * FROM `table`');
etc...
}
}
</code></pre>
<p>I use it to store messages, error messages and warnings, as well as global variables. There's an interesting question <a href="http://stackoverflow.com/questions/228164/on-design-patterns-when-to-use-the-singleton">here</a> on when to actually use this type of class.</p>
|
Garbage Collection in C++ -- why? <p>I keep hearing people complaining that C++ doesn't have garbage collection. I also hear that the C++ Standards Committee is looking at adding it to the language. I'm afraid I just don't see the point to it... using RAII with smart pointers eliminates the need for it, right?</p>
<p>My only experience with garbage collection was on a couple of cheap eighties home computers, where it meant that the system would freeze up for a few seconds every so often. I'm sure it has improved since then, but as you can guess, that didn't leave me with a high opinion of it.</p>
<p>What advantages could garbage collection offer an experienced C++ developer?</p>
|
<h2>I keep hearing people complaining that C++ doesn't have garbage collection.</h2>
<p>I am so sorry for them. Seriously.</p>
<p>C++ has RAII, and I always complain to find no RAII (or a castrated RAII) in Garbage Collected languages.</p>
<h2>What advantages could garbage collection offer an experienced C++ developer?</h2>
<p>Another tool.</p>
<p>Matt J wrote it quite right in his post (<a href="http://stackoverflow.com/questions/228620/garbage-collection-in-c-why#228640">Garbage Collection in C++ -- why?</a>): We don't need C++ features as most of them could be coded in C, and we don't need C features as most of them could coded in Assembly, etc.. <strong>C++ must evolve.</strong></p>
<p>As a developer: I don't care about GC. I tried both RAII and GC, and I find RAII vastly superior. As said by Greg Rogers in his post (<a href="http://stackoverflow.com/questions/228620/garbage-collection-in-c-why#228670">Garbage Collection in C++ -- why?</a>), memory leaks are not so terrible (at least in C++, where they are rare if C++ is really used) as to justify GC instead of RAII. GC has non deterministic deallocation/finalization and is just a way to <strong>write a code that just don't care with specific memory choices</strong>.</p>
<p>This last sentence is important: It is important to write code that "juste don't care". In the same way in C++ RAII we don't care about ressource freeing because RAII do it for us, or for object initialization because constructor do it for us, it is sometimes important to just code without caring about who is owner of what memory, and what kind pointer (shared, weak, etc.) we need for this or this piece of code. <strong>There seems to be a need for GC in C++.</strong> (even if I personaly fail to see it)</p>
<h2>An example of good GC use in C++</h2>
<p>Sometimes, in an app, you have "floating data". Imagine a tree-like structure of data, but no one is really "owner" of the data (and no one really cares about when exactly it will be destroyed). Multiple objects can use it, and then, discard it. You want it to be freed when no one is using it anymore.</p>
<p>The C++ approach is using a smart pointer. The boost::shared_ptr comes to mind. So each piece of data is owned by its own shared pointer. Cool. The problem is that when each piece of data can refer to another piece of data. You cannot use shared pointers because they are using a reference counter, which won't support circular references (A points to B, and B points to A). So you must know think a lot about where to use weak pointers (boost::weak_ptr), and when to use shared pointers.</p>
<p>With a GC, you just use the tree structured data.</p>
<p>The downside being that you must not care <strong>when</strong> the "floating data" will really be destroyed. Only that it <strong>will be</strong> destroyed.</p>
<h2>Conclusion</h2>
<p>So in the end, if done properly, and compatible with the current idioms of C++, GC would be a <strong>Yet Another Good Tool for C++</strong>.</p>
<p>C++ is a multiparadigm language: Adding a GC will perhaps make some C++ fanboys cry because of treason, but in the end, it could be a good idea, and I guess the C++ Standards Comitee won't let this kind of major feature break the language, so we can trust them to make the necessary work to enable a correct C++ GC that won't interfere with C++: <strong>As always in C++, if you don't need a feature, don't use it and it will cost you nothing.</strong></p>
|
How to Load More than 1 CSV File at a Time Via Excel VBA? <p>how does one import CSV files via Excel VBA in a set, in groups or in multiple individual files, rather than one at a time?</p>
|
<p>I am a bit puzzled in that most versions of Excel will open .csv files with out any problems.</p>
<pre><code>strPath = "C:\Docs\"
strFile = Dir(strPath & "*.csv")
Do While strFile <> ""
Workbooks.Open Filename:=strPath & strFile
ActiveWorkbook.SaveAs Filename:=strPath & Mid(strFile, 1, InStr(strFile, ".") - 1) _
& "Conv.xls", FileFormat:=xlNormal
strFile = Dir
Loop
</code></pre>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.